Merge tag 'cxl-for-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl
[linux-2.6-microblaze.git] / Documentation / devicetree / bindings / reserved-memory / reserved-memory.txt
1 *** Reserved memory regions ***
2
3 Reserved memory is specified as a node under the /reserved-memory node.
4 The operating system shall exclude reserved memory from normal usage
5 one can create child nodes describing particular reserved (excluded from
6 normal use) memory regions. Such memory regions are usually designed for
7 the special usage by various device drivers.
8
9 Parameters for each memory region can be encoded into the device tree
10 with 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
16 ranges (required) - standard definition
17     - Should be empty
18
19 /reserved-memory/ child nodes
20 -----------------------------
21 Each child of the reserved-memory node specifies one or more regions of
22 reserved memory. Each child node may either use a 'reg' property to
23 specify a specific range of reserved memory, or a 'size' property with
24 optional constraints to request a dynamically allocated block of memory.
25
26 Following the generic-names recommended practice, node names should
27 reflect the purpose of the node (ie. "framebuffer" or "dma-pool"). Unit
28 address (@<address>) should be appended to the name if the node is a
29 static allocation.
30
31 Properties:
32 Requires either a) or b) below.
33 a) static allocation
34    reg (required) - standard definition
35 b) 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
44 If both reg and size are present, then the reg property takes precedence
45 and size is ignored.
46
47 Additional properties:
48 compatible (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>
72 no-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.
77 reusable (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
84 A node must not carry both the no-map and the reusable property as these are
85 logically contradictory.
86
87 Linux 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
94 Device node references to reserved memory
95 -----------------------------------------
96 Regions in the /reserved-memory node may be referenced by other device
97 nodes by adding a memory-region property to the device node.
98
99 memory-region (optional) - phandle, specifier pairs to children of /reserved-memory
100 memory-region-names (optional) - a list of names, one for each corresponding
101   entry in the memory-region property
102
103 Example
104 -------
105 This example defines 4 contiguous regions for Linux kernel:
106 one default of all device drivers (named linux,cma@72000000 and 64MiB in size),
107 one dedicated to the framebuffer device (named framebuffer@78000000, 8MiB),
108 one for multimedia processing (named multimedia-memory@77000000, 64MiB), and
109 one 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 };