Skip to contentSkip to conversation

misc: sram: Add dma-heap-export reserved SRAM area type

RFC PATCH New Andrew F. Davis 1 participant 1 message Mar 21, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 misc: sram: Add dma-heap-export reserved SRAM area type

This new export type exposes to userspace the SRAM area as a DMA-Heap, this allows for allocations as DMA-BUFs that can be consumed by various DMA-BUF supporting devices.

---

Hello all,

This is an example user of the currently RFC DMA-HEAP framework. It exports a defined SRAM area showing how various memory presenting devices can use the DMA-HEAP framework to provide DMA-BUF allocations to userspace and other devices.

It has a couple problems still, one being that the SRAM subsystem probes before the DMA-BUF subsystem, can the SRAM driver be changed from postcore_initcall to subsys_initcall or even device_initcall?

Thanks,
Andrew

 .../devicetree/bindings/sram/sram.txt         |   7 +-
 drivers/misc/Kconfig                          |   7 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/sram-dma-heap.c                  | 235 ++++++++++++++++++
 drivers/misc/sram.c                           |  20 +-
 drivers/misc/sram.h                           |  17 ++
 6 files changed, 282 insertions(+), 5 deletions(-)
 create mode 100644 drivers/misc/sram-dma-heap.c
Documentation/devicetree/bindings/sram/sram.txt +6 -1
index e98908bd4227..c5584f1f6ae8 100644
@@ -43,11 +43,16 @@ Optional properties in the area nodes:
 - export : indicates that the reserved SRAM area may be accessed outside
            of the kernel, e.g. by bootloader or userspace
 - protect-exec : Same as 'pool' above but with the additional
-		 constraint that code wil be run from the region and
+		 constraint that code will be run from the region and
 		 that the memory is maintained as read-only, executable
 		 during code execution. NOTE: This region must be page
 		 aligned on start and end in order to properly allow
 		 manipulation of the page attributes.
+- dma-heap-export : Similar to 'pool' and 'export' this region will be
+		    exported for use by drivers, devices, and userspace
+		    using the DMA-Heaps framework. NOTE: This region must
+		    be page aligned on start and end in order to properly
+		    allow manipulation of the page attributes.
 - label : the name for the reserved partition, if omitted, the label
           is taken from the node name excluding the unit address.
 - clocks : a list of phandle and clock specifier pair that controls the
drivers/misc/Kconfig +7 -0
index 42ab8ec92a04..5e655890458d 100644
@@ -487,6 +487,13 @@ config SRAM
 config SRAM_EXEC
 	bool
 
+config SRAM_DMA_HEAP
+	bool "Export on-chip SRAM pools using DMA-Heaps"
+	depends on SRAM
+	help
+	  This driver allows the export of on-chip SRAM marked as exportable
+	  to userspace using the DMA-Heaps interface.
+
 config VEXPRESS_SYSCFG
 	bool "Versatile Express System Configuration driver"
 	depends on VEXPRESS_CONFIG
drivers/misc/Makefile +1 -0
index d5b7d3404dc7..f9db5326e0f7 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_VMWARE_VMCI)	+= vmw_vmci/
 obj-$(CONFIG_LATTICE_ECP3_CONFIG)	+= lattice-ecp3-config.o
 obj-$(CONFIG_SRAM)		+= sram.o
 obj-$(CONFIG_SRAM_EXEC)		+= sram-exec.o
+obj-$(CONFIG_SRAM_DMA_HEAP)	+= sram-dma-heap.o
 obj-y				+= mic/
 obj-$(CONFIG_GENWQE)		+= genwqe/
 obj-$(CONFIG_ECHO)		+= echo/
drivers/misc/sram-dma-heap.c new file +235 -0

235 lines not on this page · raw message

drivers/misc/sram.c +16 -4
index 80d8cbe8c01a..d11a3ab7b9b2 100644
@@ -122,6 +122,15 @@ static int sram_add_partition(struct sram_dev *sram, struct sram_reserve *block,
 		if (ret)
 			return ret;
 	}
+	if (block->dma_heap_export) {
+		ret = sram_add_pool(sram, block, start, part);
+		if (ret)
+			return ret;
+
+		ret = sram_dma_heap_export(sram, block, start, part);
+		if (ret)
+			return ret;
+	}
 	if (block->protect_exec) {
 		ret = sram_check_protect_exec(sram, block, part);
 		if (ret)
@@ -222,8 +231,11 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)
 		if (of_find_property(child, "protect-exec", NULL))
 			block->protect_exec = true;
 
-		if ((block->export || block->pool || block->protect_exec) &&
-		    block->size) {
+		if (of_find_property(child, "dma-heap-export", NULL))
+			block->dma_heap_export = true;
+
+		if ((block->export || block->pool || block->protect_exec ||
+		     block->dma_heap_export) && block->size) {
 			exports++;
 
 			label = NULL;
@@ -285,8 +297,8 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)
 			goto err_chunks;
 		}
 
-		if ((block->export || block->pool || block->protect_exec) &&
-		    block->size) {
+		if ((block->export || block->pool || block->protect_exec ||
+		     block->dma_heap_export) && block->size) {
 			ret = sram_add_partition(sram, block,
 						 res->start + block->start);
 			if (ret) {
drivers/misc/sram.h +17 -0
index c181ce4c8fca..c1eef4c32152 100644
@@ -35,6 +35,7 @@ struct sram_reserve {
 	bool export;
 	bool pool;
 	bool protect_exec;
+	bool dma_heap_export;
 	const char *label;
 };
 
@@ -55,4 +56,20 @@ static inline int sram_add_protect_exec(struct sram_partition *part)
 	return -ENODEV;
 }
 #endif /* CONFIG_SRAM_EXEC */
+
+#ifdef CONFIG_SRAM_DMA_HEAP
+int sram_dma_heap_export(struct sram_dev *sram,
+			 struct sram_reserve *block,
+			 phys_addr_t start,
+			 struct sram_partition *part);
+#else
+static inline int sram_dma_heap_export(struct sram_dev *sram,
+				       struct sram_reserve *block,
+				       phys_addr_t start,
+				       struct sram_partition *part)
+{
+	return 0;
+}
+#endif /* CONFIG_SRAM_DMA_HEAP */
+
 #endif /* __SRAM_H */
Signature · 1 line
2.21.0