1*** Reserved memory regions *** 2 3Reserved memory is specified as a node under the /reserved-memory node. 4The operating system shall exclude reserved memory from normal usage 5one can create child nodes describing particular reserved (excluded from 6normal use) memory regions. Such memory regions are usually designed for 7the special usage by various device drivers. 8 9Parameters for each memory region can be encoded into the device tree 10with the following nodes: 11 12/reserved-memory node 13--------------------- 14#address-cells, #size-cells (required) - standard definition 15 - Should use the same values as the root node 16ranges (required) - standard definition 17 - Should be empty 18 19/reserved-memory/ child nodes 20----------------------------- 21Each child of the reserved-memory node specifies one or more regions of 22reserved memory. Each child node may either use a 'reg' property to 23specify a specific range of reserved memory, or a 'size' property with 24optional constraints to request a dynamically allocated block of memory. 25 26Following the generic-names recommended practice, node names should 27reflect the purpose of the node (ie. "framebuffer" or "dma-pool"). Unit 28address (@<address>) should be appended to the name if the node is a 29static allocation. 30 31Properties: 32Requires either a) or b) below. 33a) static allocation 34 reg (required) - standard definition 35b) dynamic allocation 36 size (required) - length based on parent's #size-cells 37 - Size in bytes of memory to reserve. 38 alignment (optional) - length based on parent's #size-cells 39 - Address boundary for alignment of allocation. 40 alloc-ranges (optional) - prop-encoded-array (address, length pairs). 41 - Specifies regions of memory that are 42 acceptable to allocate from. 43 44If both reg and size are present, then the reg property takes precedence 45and size is ignored. 46 47Additional properties: 48compatible (optional) - standard definition 49 - may contain the following strings: 50 - shared-dma-pool: This indicates a region of memory meant to be 51 used as a shared pool of DMA buffers for a set of devices. It can 52 be used by an operating system to instantiate the necessary pool 53 management subsystem if necessary. 54 - restricted-dma-pool: This indicates a region of memory meant to be 55 used as a pool of restricted DMA buffers for a set of devices. The 56 memory region would be the only region accessible to those devices. 57 When using this, the no-map and reusable properties must not be set, 58 so the operating system can create a virtual mapping that will be used 59 for synchronization. The main purpose for restricted DMA is to 60 mitigate the lack of DMA access control on systems without an IOMMU, 61 which could result in the DMA accessing the system memory at 62 unexpected times and/or unexpected addresses, possibly leading to data 63 leakage or corruption. The feature on its own provides a basic level 64 of protection against the DMA overwriting buffer contents at 65 unexpected times. However, to protect against general data leakage and 66 system memory corruption, the system needs to provide way to lock down 67 the memory access, e.g., MPU. Note that since coherent allocation 68 needs remapping, one must set up another device coherent pool by 69 shared-dma-pool and use dma_alloc_from_dev_coherent instead for atomic 70 coherent allocation. 71 - vendor specific string in the form <vendor>,[<device>-]<usage> 72no-map (optional) - empty property 73 - Indicates the operating system must not create a virtual mapping 74 of the region as part of its standard mapping of system memory, 75 nor permit speculative access to it under any circumstances other 76 than under the control of the device driver using the region. 77reusable (optional) - empty property 78 - The operating system can use the memory in this region with the 79 limitation that the device driver(s) owning the region need to be 80 able to reclaim it back. Typically that means that the operating 81 system can use that region to store volatile or cached data that 82 can be otherwise regenerated or migrated elsewhere. 83 84A node must not carry both the no-map and the reusable property as these are 85logically contradictory. 86 87Linux implementation note: 88- If a "linux,cma-default" property is present, then Linux will use the 89 region for the default pool of the contiguous memory allocator. 90 91- If a "linux,dma-default" property is present, then Linux will use the 92 region for the default pool of the consistent DMA allocator. 93 94Device node references to reserved memory 95----------------------------------------- 96Regions in the /reserved-memory node may be referenced by other device 97nodes by adding a memory-region property to the device node. 98 99memory-region (optional) - phandle, specifier pairs to children of /reserved-memory 100memory-region-names (optional) - a list of names, one for each corresponding 101 entry in the memory-region property 102 103Example 104------- 105This example defines 4 contiguous regions for Linux kernel: 106one default of all device drivers (named linux,cma@72000000 and 64MiB in size), 107one dedicated to the framebuffer device (named framebuffer@78000000, 8MiB), 108one for multimedia processing (named multimedia-memory@77000000, 64MiB), and 109one for restricted dma pool (named restricted_dma_reserved@0x50000000, 64MiB). 110 111/ { 112 #address-cells = <1>; 113 #size-cells = <1>; 114 115 memory { 116 reg = <0x40000000 0x40000000>; 117 }; 118 119 reserved-memory { 120 #address-cells = <1>; 121 #size-cells = <1>; 122 ranges; 123 124 /* global autoconfigured region for contiguous allocations */ 125 linux,cma { 126 compatible = "shared-dma-pool"; 127 reusable; 128 size = <0x4000000>; 129 alignment = <0x2000>; 130 linux,cma-default; 131 }; 132 133 display_reserved: framebuffer@78000000 { 134 reg = <0x78000000 0x800000>; 135 }; 136 137 multimedia_reserved: multimedia@77000000 { 138 compatible = "acme,multimedia-memory"; 139 reg = <0x77000000 0x4000000>; 140 }; 141 142 restricted_dma_reserved: restricted_dma_reserved { 143 compatible = "restricted-dma-pool"; 144 reg = <0x50000000 0x4000000>; 145 }; 146 }; 147 148 /* ... */ 149 150 fb0: video@12300000 { 151 memory-region = <&display_reserved>; 152 /* ... */ 153 }; 154 155 scaler: scaler@12500000 { 156 memory-region = <&multimedia_reserved>; 157 /* ... */ 158 }; 159 160 codec: codec@12600000 { 161 memory-region = <&multimedia_reserved>; 162 /* ... */ 163 }; 164 165 pcie_device: pcie_device@0,0 { 166 reg = <0x83010000 0x0 0x00000000 0x0 0x00100000 167 0x83010000 0x0 0x00100000 0x0 0x00100000>; 168 memory-region = <&restricted_dma_reserved>; 169 /* ... */ 170 }; 171}; 172