Module Name: src
Committed By: riastradh
Date: Mon Aug 27 15:32:20 UTC 2018
Modified Files:
src/sys/external/bsd/drm2/include/drm: bus_dma_hacks.h
Log Message:
Implement BUS_DMA_TO_PHYS/PHYS_TO_BUS_DMA on arm respecting ranges.
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 \
src/sys/external/bsd/drm2/include/drm/bus_dma_hacks.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/external/bsd/drm2/include/drm/bus_dma_hacks.h
diff -u src/sys/external/bsd/drm2/include/drm/bus_dma_hacks.h:1.15 src/sys/external/bsd/drm2/include/drm/bus_dma_hacks.h:1.16
--- src/sys/external/bsd/drm2/include/drm/bus_dma_hacks.h:1.15 Mon Aug 27 15:29:31 2018
+++ src/sys/external/bsd/drm2/include/drm/bus_dma_hacks.h Mon Aug 27 15:32:20 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma_hacks.h,v 1.15 2018/08/27 15:29:31 riastradh Exp $ */
+/* $NetBSD: bus_dma_hacks.h,v 1.16 2018/08/27 15:32:20 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -46,8 +46,33 @@
# define PHYS_TO_BUS_MEM(dmat, paddr) ((bus_addr_t)(paddr))
# define BUS_MEM_TO_PHYS(dmat, baddr) ((paddr_t)(baddr))
#elif defined(__arm__) || defined(__aarch64__)
-# define PHYS_TO_BUS_MEM(dmat, paddr) ((bus_addr_t)(paddr))
-# define BUS_MEM_TO_PHYS(dmat, baddr) ((paddr_t)(baddr))
+static inline bus_addr_t
+PHYS_TO_BUS_MEM(bus_dma_tag_t dmat, paddr_t pa)
+{
+ unsigned i;
+
+ for (i = 0; i < dmat->_nranges; i++) {
+ const struct arm32_dma_range *dr = &dmat->_ranges[i];
+
+ if (dr->dr_sysbase <= pa && pa - dr->dr_sysbase <= dr->dr_len)
+ return dr->dr_busbase + (dr->dr_sysbase - pa);
+ }
+ panic("paddr has no bus address in dma tag %p: %"PRIxPADDR, dmat, pa);
+}
+static inline paddr_t
+BUS_MEM_TO_PHYS(bus_dma_tag_t dmat, bus_addr_t ba)
+{
+ unsigned i;
+
+ for (i = 0; i < dmat->_nranges; i++) {
+ const struct arm32_dma_range *dr = &dmat->_ranges[i];
+
+ if (dr->dr_busbase <= ba && ba - dr->dr_busbase <= dr->dr_len)
+ return dr->dr_sysbase + (dr->dr_busbase - ba);
+ }
+ panic("bus addr has no bus address in dma tag %p: %"PRIxPADDR, dmat,
+ ba);
+}
#elif defined(__sparc__) || defined(__sparc64__)
# define PHYS_TO_BUS_MEM(dmat, paddr) ((bus_addr_t)(paddr))
# define BUS_MEM_TO_PHYS(dmat, baddr) ((paddr_t)(baddr))