Skip to contentSkip to conversation

reserved-memory regions/CMA in devicetree, again

RFC PATCH New Josh Cartwright 1 participant 5 messages Jan 22, 2014

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

cover reserved-memory regions/CMA in devicetree, again

Hey Marek-

What is the current status of the reserved-memory/CMA device tree support series? It looks like it's stalled out a bit since the revert[2]. Hopefully this series is a push in the right direction?

---
This set is an adaptation of Marek's original patchset posted here[1], and then subsequently reverted here[2]. In [3], Grant proposed a new set of bindings after discussion in Edinburgh.

This is a partially complete implementation of these proposed bindings.

It's functionality is now split into two pieces, the first of which implements a default/fallback behavior for reserved-memory nodes; that is, reserved memory nodes describing fixed-address static regions will be unconditionally reserved, regardless of their intended use. In addition, it provides an interface for adding additional reserved-memory types, using a method similar to CLOCKSOURCE_OF_DECLARE().

The second piece uses the above method to provide support for reserved-memory nodes whose compatible = "shared-dma-pool". It makes use of CMA when available, and when a describing node has the 'reusable' property.

There is basic support for dynamic allocation of memory reserved regions, however, noticeably missing is support for additional restrictions (use of alignment and alloc-ranges properties).

[1]: http://lkml.kernel.org/g/[email protected]
[2]: http://lkml.kernel.org/g/[email protected]
[3]: http://lkml.kernel.org/g/[email protected]

Grant Likely (1):
of: document bindings for reserved-memory nodes

Josh Cartwright (1):
drivers: of: implement reserved-memory handling for dma

Marek Szyprowski (2):
drivers: of: add initialization code for reserved memory
ARM: init: add support for reserved memory defined by device tree

 .../bindings/reserved-memory/reserved-memory.txt   | 137 +++++++++++++++
 arch/arm/mm/init.c                                 |   3 +
 drivers/of/Kconfig                                 |  13 ++
 drivers/of/Makefile                                |   2 +
 drivers/of/of_reserved_mem.c                       | 188 +++++++++++++++++++++
 drivers/of/of_reserved_mem_dma.c                   | 178 +++++++++++++++++++
 drivers/of/platform.c                              |   4 +
 include/asm-generic/vmlinux.lds.h                  |  11 ++
 include/linux/of_reserved_mem.h                    |  61 +++++++
 9 files changed, 597 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
 create mode 100644 drivers/of/of_reserved_mem.c
 create mode 100644 drivers/of/of_reserved_mem_dma.c
 create mode 100644 include/linux/of_reserved_mem.h
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#1 lore raw

RFC PATCH 1/4 drivers: of: add initialization code for reserved memory

From: Marek Szyprowski <[email protected]>

This patch adds device tree support for contiguous and reserved memory regions defined in device tree.

Large memory blocks can be reliably reserved only during early boot. This must happen before the whole memory management subsystem is initialized, because we need to ensure that the given contiguous blocks are not yet allocated by kernel. Also it must happen before kernel mappings for the whole low memory are created, to ensure that there will be no mappings (for reserved blocks) or mapping with special properties can be created (for CMA blocks). This all happens before device tree structures are unflattened, so we need to get reserved memory layout directly from fdt.

Later, those reserved memory regions are assigned to devices on each device structure initialization.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Laura Abbott <[email protected]>

[joshc: rework to implement new DT binding, provide mechanism for
plugging in new reserved-memory node handlers via RESERVEDMEM_OF_DECLARE]

---
 drivers/of/Kconfig                |   6 ++
 drivers/of/Makefile               |   1 +
 drivers/of/of_reserved_mem.c      | 188 ++++++++++++++++++++++++++++++++++++++
 drivers/of/platform.c             |   4 +
 include/asm-generic/vmlinux.lds.h |  11 +++
 include/linux/of_reserved_mem.h   |  61 +++++++++++++
 6 files changed, 271 insertions(+)
 create mode 100644 drivers/of/of_reserved_mem.c
 create mode 100644 include/linux/of_reserved_mem.h
drivers/of/Kconfig +6 -0
index c6973f1..aba13df 100644
@@ -75,4 +75,10 @@ config OF_MTD
 	depends on MTD
 	def_bool y
 
+config OF_RESERVED_MEM
+	depends on HAVE_MEMBLOCK
+	def_bool y
+	help
+	  Helpers to allow for reservation of memory regions
+
 endmenu # OF
drivers/of/Makefile +1 -0
index efd0510..ed9660a 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
 obj-$(CONFIG_OF_MTD)	+= of_mtd.o
+obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
drivers/of/of_reserved_mem.c new file +188 -0

188 lines not on this page · raw message

drivers/of/platform.c +4 -0
index 404d1da..b6d3cea 100644
@@ -21,6 +21,7 @@
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
 
 const struct of_device_id of_default_bus_match_table[] = {
@@ -220,6 +221,8 @@ static struct platform_device *of_platform_device_create_pdata(
 	dev->dev.bus = &platform_bus_type;
 	dev->dev.platform_data = platform_data;
 
+	of_reserved_mem_device_init(dev);
+
 	/* We do not fill the DMA ops for platform devices by default.
 	 * This is currently the responsibility of the platform code
 	 * to do such, possibly using a device notifier
@@ -227,6 +230,7 @@ static struct platform_device *of_platform_device_create_pdata(
 
 	if (of_device_add(dev) != 0) {
 		platform_device_put(dev);
+		of_reserved_mem_device_release(dev);
 		return NULL;
 	}
 
include/asm-generic/vmlinux.lds.h +11 -0
index bc2121f..f10f64f 100644
@@ -167,6 +167,16 @@
 #define CLK_OF_TABLES()
 #endif
 
+#ifdef CONFIG_OF_RESERVED_MEM
+#define RESERVEDMEM_OF_TABLES()				\
+	. = ALIGN(8);					\
+	VMLINUX_SYMBOL(__reservedmem_of_table) = .;	\
+	*(__reservedmem_of_table)			\
+	*(__reservedmem_of_table_end)
+#else
+#define RESERVEDMEM_OF_TABLES()
+#endif
+
 #define KERNEL_DTB()							\
 	STRUCT_ALIGN();							\
 	VMLINUX_SYMBOL(__dtb_start) = .;				\
@@ -490,6 +500,7 @@
 	TRACE_SYSCALLS()						\
 	MEM_DISCARD(init.rodata)					\
 	CLK_OF_TABLES()							\
+	RESERVEDMEM_OF_TABLES()						\
 	CLKSRC_OF_TABLES()						\
 	KERNEL_DTB()							\
 	IRQCHIP_OF_MATCH_TABLE()
include/linux/of_reserved_mem.h new file +61 -0

61 lines not on this page · raw message

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#2 lore raw

RFC PATCH 2/4 drivers: of: implement reserved-memory handling for dma

In reply to Josh Cartwright

Add support for handling 'shared-dma-pool' reserved-memory nodes.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Marek Szyprowski <[email protected]>
---
 drivers/of/Kconfig               |   7 ++
 drivers/of/Makefile              |   1 +
 drivers/of/of_reserved_mem_dma.c | 178 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 drivers/of/of_reserved_mem_dma.c
drivers/of/Kconfig +7 -0
index aba13df..ca58fb3e 100644
@@ -81,4 +81,11 @@ config OF_RESERVED_MEM
 	help
 	  Helpers to allow for reservation of memory regions
 
+config OF_RESERVED_MEM_DMA
+	depends on OF_RESERVED_MEM
+	depends on DMA_CMA || HAVE_GENERIC_DMA_COHERENT
+	def_bool y
+	help
+	  Helpers for reserving memory regions for DMA use
+
 endmenu # OF
drivers/of/Makefile +1 -0
index ed9660a..6142227 100644
@@ -10,3 +10,4 @@ obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
 obj-$(CONFIG_OF_MTD)	+= of_mtd.o
 obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
+obj-$(CONFIG_OF_RESERVED_MEM_DMA) += of_reserved_mem_dma.o
drivers/of/of_reserved_mem_dma.c new file +178 -0

178 lines not on this page · raw message

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#3 lore raw

RFC PATCH 3/4 ARM: init: add support for reserved memory defined by device tree

In reply to Josh Cartwright

From: Marek Szyprowski <[email protected]>

Enable reserved memory initialization from device tree.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Laura Abbott <[email protected]>
---
 arch/arm/mm/init.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mm/init.c +3 -0
index 403ba90..5efe0b4 100644
@@ -17,6 +17,7 @@
 #include <linux/nodemask.h>
 #include <linux/initrd.h>
 #include <linux/of_fdt.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/highmem.h>
 #include <linux/gfp.h>
 #include <linux/memblock.h>
@@ -323,6 +324,8 @@ void __init arm_memblock_init(struct meminfo *mi,
 	if (mdesc->reserve)
 		mdesc->reserve();
 
+	early_init_dt_scan_reserved_mem();
+
 	/*
 	 * reserve memory for DMA contigouos allocations,
 	 * must come from DMA area inside low memory
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#4 lore raw

RFC PATCH 4/4 of: document bindings for reserved-memory nodes

In reply to Josh Cartwright

From: Grant Likely <[email protected]>

Reserved memory nodes allow for the reservation of static (fixed address) regions, or dynamically allocated regions for a specific purpose.

[joshc: Based on binding document proposed (in non-patch form) here:
http://lkml.kernel.org/g/20131030134702.19B57C402A0 at trevor.secretlab.ca adapted to support #memory-region-cells]

Cc Marek Szyprowski <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Laura Abbott <[email protected]>

---
Hey Grant-

Seeing as you are the primary author of this binding, with only a few minor changes on my part, I've marked you as the commit author. Let me know if that's a problem.

Josh

 .../bindings/reserved-memory/reserved-memory.txt   | 137 +++++++++++++++++++++
 1 file changed, 137 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt new file +137 -0
new file mode 100644
index 0000000..7cd7829
@@ -0,0 +1,137 @@
+*** Reserved memory regions ***
+
+Reserved memory is specified as a node under the /reserved-memory node.
+The operating system shall exclude reserved memory from normal usage
+one can create child nodes describing particular reserved (excluded from
+normal use) memory regions. Such memory regions are usually designed for
+the special usage by various device drivers.
+
+Parameters for each memory region can be encoded into the device tree
+with the following nodes:
+
+/reserved-memory node
+---------------------
+#address-cells, #size-cells (required) - standard definition
+    - Should use the same values as the root node
+#memory-region-cells (required) - dictates number of cells used in the child
+                                  nodes memory-region specifier
+ranges (required) - standard definition
+    - Should be empty
+
+/reserved-memory/ child nodes
+-----------------------------
+Each child of the reserved-memory node specifies one or more regions of
+reserved memory. Each child node may either use a 'reg' property to
+specify a specific range of reserved memory, or a 'size' property with
+optional constraints to request a dynamically allocated block of memory.
+
+Following the generic-names recommended practice, node names should
+reflect the purpose of the node (ie. "framebuffer" or "dma-pool"). Unit
+address (@<address>) should be appended to the name if the node is a
+static allocation.
+
+Properties:
+Requires either a) or b) below.
+a) static allocation
+   reg (required) - standard definition
+b) dynamic allocation
+   size (required) - length based on parent's #size-cells
+                   - Size in bytes of memory to reserve.
+   alignment (optional) - length based on parent's #size-cells
+                        - Address boundary for alignment of allocation.
+   alloc-ranges (optional) - prop-encoded-array (address, length pairs).
+                           - Specifies regions of memory that are
+                             acceptable to allocate from.
+
+If both reg and size are present, then the reg property takes precedence
+and size is ignored.
+
+Additional properties:
+compatible (optional) - standard definition
+    - may contain the following strings:
+        - shared-dma-pool: This indicates a region of memory meant to be
+          used as a shared pool of DMA buffers for a set of devices. It can
+          be used by an operating system to instanciate the necessary pool
+          management subsystem if necessary.
+        - vendor specific string in the form <vendor>,[<device>-]<usage>
+no-map (optional) - empty property
+    - Indicates the operating system must not create a virtual mapping
+      of the region as part of its standard mapping of system memory,
+      nor permit speculative access to it under any circumstances other
+      than under the control of the device driver using the region.
+reusable (optional) - empty property
+    - The operating system can use the memory in this region with the
+      limitation that the device driver(s) owning the region need to be
+      able to reclaim it back. Typically that means that the operating
+      system can use that region to store volatile or cached data that
+      can be otherwise regenerated or migrated elsewhere.
+
+Linux implementation note:
+- If a "linux,cma-default" property is present, then Linux will use the
+  region for the default pool of the contiguous memory allocator.
+
+Device node references to reserved memory
+-----------------------------------------
+Regions in the /reserved-memory node may be referenced by other device
+nodes by adding a memory-region property to the device node.
+
+memory-region (optional) - phandle, specifier pairs to children of /reserved-memory
+
+Example
+-------
+This example defines 3 contiguous regions are defined for Linux kernel:
+one default of all device drivers (named linux,cma at 72000000 and 64MiB in size),
+one dedicated to the framebuffer device (named framebuffer at 78000000, 8MiB), and
+one for multimedia processing (named multimedia-memory at 77000000, 64MiB).
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	memory {
+		reg = <0x40000000 0x40000000>;
+	};
+
+	reserved-memory {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		/* global autoconfigured region for contiguous allocations */
+		linux,cma {
+			compatible = "shared-dma-pool";
+			#memory-region-cells = <0>;
+			size = <0x4000000>;
+			alignment = <0x2000>;
+			linux,cma-default;
+		};
+
+		display_reserved: framebuffer at 78000000 {
+			#memory-region-cells = <0>;
+			reg = <0x78000000 0x800000>;
+		};
+
+		multimedia_reserved: multimedia at 77000000 {
+			compatible = "acme,multimedia-memory";
+			#memory-region-cells = <1>;
+			reg = <0x77000000 0x4000000>;
+		};
+	};
+
+	/* ... */
+
+	fb0: video at 12300000 {
+		memory-region = <&display_reserved>;
+		/* ... */
+	};
+
+	scaler: scaler at 12500000 {
+		memory-region = <&multimedia_reserved 0xdeadbeef>;
+		/* ... */
+	};
+
+	codec: codec at 12600000 {
+		memory-region = <&multimedia_reserved 0xfeebdaed>;
+		/* ... */
+	};
+};
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation