xref: /OK3568_Linux_fs/kernel/Documentation/devicetree/bindings/iommu/iommu.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunThis document describes the generic device tree binding for IOMMUs and their
2*4882a593Smuzhiyunmaster(s).
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunIOMMU device node:
6*4882a593Smuzhiyun==================
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunAn IOMMU can provide the following services:
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun* Remap address space to allow devices to access physical memory ranges that
11*4882a593Smuzhiyun  they otherwise wouldn't be capable of accessing.
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun  Example: 32-bit DMA to 64-bit physical addresses
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun* Implement scatter-gather at page level granularity so that the device does
16*4882a593Smuzhiyun  not have to.
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun* Provide system protection against "rogue" DMA by forcing all accesses to go
19*4882a593Smuzhiyun  through the IOMMU and faulting when encountering accesses to unmapped
20*4882a593Smuzhiyun  address regions.
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun* Provide address space isolation between multiple contexts.
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun  Example: Virtualization
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunDevice nodes compatible with this binding represent hardware with some of the
27*4882a593Smuzhiyunabove capabilities.
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunIOMMUs can be single-master or multiple-master. Single-master IOMMU devices
30*4882a593Smuzhiyuntypically have a fixed association to the master device, whereas multiple-
31*4882a593Smuzhiyunmaster IOMMU devices can translate accesses from more than one master.
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunThe device tree node of the IOMMU device's parent bus must contain a valid
34*4882a593Smuzhiyun"dma-ranges" property that describes how the physical address space of the
35*4882a593SmuzhiyunIOMMU maps to memory. An empty "dma-ranges" property means that there is a
36*4882a593Smuzhiyun1:1 mapping from IOMMU to memory.
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunRequired properties:
39*4882a593Smuzhiyun--------------------
40*4882a593Smuzhiyun- #iommu-cells: The number of cells in an IOMMU specifier needed to encode an
41*4882a593Smuzhiyun  address.
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunThe meaning of the IOMMU specifier is defined by the device tree binding of
44*4882a593Smuzhiyunthe specific IOMMU. Below are a few examples of typical use-cases:
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun- #iommu-cells = <0>: Single master IOMMU devices are not configurable and
47*4882a593Smuzhiyun  therefore no additional information needs to be encoded in the specifier.
48*4882a593Smuzhiyun  This may also apply to multiple master IOMMU devices that do not allow the
49*4882a593Smuzhiyun  association of masters to be configured. Note that an IOMMU can by design
50*4882a593Smuzhiyun  be multi-master yet only expose a single master in a given configuration.
51*4882a593Smuzhiyun  In such cases the number of cells will usually be 1 as in the next case.
52*4882a593Smuzhiyun- #iommu-cells = <1>: Multiple master IOMMU devices may need to be configured
53*4882a593Smuzhiyun  in order to enable translation for a given master. In such cases the single
54*4882a593Smuzhiyun  address cell corresponds to the master device's ID. In some cases more than
55*4882a593Smuzhiyun  one cell can be required to represent a single master ID.
56*4882a593Smuzhiyun- #iommu-cells = <4>: Some IOMMU devices allow the DMA window for masters to
57*4882a593Smuzhiyun  be configured. The first cell of the address in this may contain the master
58*4882a593Smuzhiyun  device's ID for example, while the second cell could contain the start of
59*4882a593Smuzhiyun  the DMA window for the given device. The length of the DMA window is given
60*4882a593Smuzhiyun  by the third and fourth cells.
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunNote that these are merely examples and real-world use-cases may use different
63*4882a593Smuzhiyundefinitions to represent their individual needs. Always refer to the specific
64*4882a593SmuzhiyunIOMMU binding for the exact meaning of the cells that make up the specifier.
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun
67*4882a593SmuzhiyunIOMMU master node:
68*4882a593Smuzhiyun==================
69*4882a593Smuzhiyun
70*4882a593SmuzhiyunDevices that access memory through an IOMMU are called masters. A device can
71*4882a593Smuzhiyunhave multiple master interfaces (to one or more IOMMU devices).
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunRequired properties:
74*4882a593Smuzhiyun--------------------
75*4882a593Smuzhiyun- iommus: A list of phandle and IOMMU specifier pairs that describe the IOMMU
76*4882a593Smuzhiyun  master interfaces of the device. One entry in the list describes one master
77*4882a593Smuzhiyun  interface of the device.
78*4882a593Smuzhiyun
79*4882a593SmuzhiyunWhen an "iommus" property is specified in a device tree node, the IOMMU will
80*4882a593Smuzhiyunbe used for address translation. If a "dma-ranges" property exists in the
81*4882a593Smuzhiyundevice's parent node it will be ignored. An exception to this rule is if the
82*4882a593Smuzhiyunreferenced IOMMU is disabled, in which case the "dma-ranges" property of the
83*4882a593Smuzhiyunparent shall take effect. Note that merely disabling a device tree node does
84*4882a593Smuzhiyunnot guarantee that the IOMMU is really disabled since the hardware may not
85*4882a593Smuzhiyunhave a means to turn off translation. But it is invalid in such cases to
86*4882a593Smuzhiyundisable the IOMMU's device tree node in the first place because it would
87*4882a593Smuzhiyunprevent any driver from properly setting up the translations.
88*4882a593Smuzhiyun
89*4882a593SmuzhiyunOptional properties:
90*4882a593Smuzhiyun--------------------
91*4882a593Smuzhiyun- pasid-num-bits: Some masters support multiple address spaces for DMA, by
92*4882a593Smuzhiyun  tagging DMA transactions with an address space identifier. By default,
93*4882a593Smuzhiyun  this is 0, which means that the device only has one address space.
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun
96*4882a593SmuzhiyunNotes:
97*4882a593Smuzhiyun======
98*4882a593Smuzhiyun
99*4882a593SmuzhiyunOne possible extension to the above is to use an "iommus" property along with
100*4882a593Smuzhiyuna "dma-ranges" property in a bus device node (such as PCI host bridges). This
101*4882a593Smuzhiyuncan be useful to describe how children on the bus relate to the IOMMU if they
102*4882a593Smuzhiyunare not explicitly listed in the device tree (e.g. PCI devices). However, the
103*4882a593Smuzhiyunrequirements of that use-case haven't been fully determined yet. Implementing
104*4882a593Smuzhiyunthis is therefore not recommended without further discussion and extension of
105*4882a593Smuzhiyunthis binding.
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun
108*4882a593SmuzhiyunExamples:
109*4882a593Smuzhiyun=========
110*4882a593Smuzhiyun
111*4882a593SmuzhiyunSingle-master IOMMU:
112*4882a593Smuzhiyun--------------------
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun	iommu {
115*4882a593Smuzhiyun		#iommu-cells = <0>;
116*4882a593Smuzhiyun	};
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun	master {
119*4882a593Smuzhiyun		iommus = <&{/iommu}>;
120*4882a593Smuzhiyun	};
121*4882a593Smuzhiyun
122*4882a593SmuzhiyunMultiple-master IOMMU with fixed associations:
123*4882a593Smuzhiyun----------------------------------------------
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun	/* multiple-master IOMMU */
126*4882a593Smuzhiyun	iommu {
127*4882a593Smuzhiyun		/*
128*4882a593Smuzhiyun		 * Masters are statically associated with this IOMMU and share
129*4882a593Smuzhiyun		 * the same address translations because the IOMMU does not
130*4882a593Smuzhiyun		 * have sufficient information to distinguish between masters.
131*4882a593Smuzhiyun		 *
132*4882a593Smuzhiyun		 * Consequently address translation is always on or off for
133*4882a593Smuzhiyun		 * all masters at any given point in time.
134*4882a593Smuzhiyun		 */
135*4882a593Smuzhiyun		#iommu-cells = <0>;
136*4882a593Smuzhiyun	};
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun	/* static association with IOMMU */
139*4882a593Smuzhiyun	master@1 {
140*4882a593Smuzhiyun		reg = <1>;
141*4882a593Smuzhiyun		iommus = <&{/iommu}>;
142*4882a593Smuzhiyun	};
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun	/* static association with IOMMU */
145*4882a593Smuzhiyun	master@2 {
146*4882a593Smuzhiyun		reg = <2>;
147*4882a593Smuzhiyun		iommus = <&{/iommu}>;
148*4882a593Smuzhiyun	};
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunMultiple-master IOMMU:
151*4882a593Smuzhiyun----------------------
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun	iommu {
154*4882a593Smuzhiyun		/* the specifier represents the ID of the master */
155*4882a593Smuzhiyun		#iommu-cells = <1>;
156*4882a593Smuzhiyun	};
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun	master@1 {
159*4882a593Smuzhiyun		/* device has master ID 42 in the IOMMU */
160*4882a593Smuzhiyun		iommus = <&{/iommu} 42>;
161*4882a593Smuzhiyun	};
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun	master@2 {
164*4882a593Smuzhiyun		/* device has master IDs 23 and 24 in the IOMMU */
165*4882a593Smuzhiyun		iommus = <&{/iommu} 23>, <&{/iommu} 24>;
166*4882a593Smuzhiyun	};
167*4882a593Smuzhiyun
168*4882a593SmuzhiyunMultiple-master IOMMU with configurable DMA window:
169*4882a593Smuzhiyun---------------------------------------------------
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun	/ {
172*4882a593Smuzhiyun		iommu {
173*4882a593Smuzhiyun			/*
174*4882a593Smuzhiyun			 * One cell for the master ID and one cell for the
175*4882a593Smuzhiyun			 * address of the DMA window. The length of the DMA
176*4882a593Smuzhiyun			 * window is encoded in two cells.
177*4882a593Smuzhiyun			 *
178*4882a593Smuzhiyun			 * The DMA window is the range addressable by the
179*4882a593Smuzhiyun			 * master (i.e. the I/O virtual address space).
180*4882a593Smuzhiyun			 */
181*4882a593Smuzhiyun			#iommu-cells = <4>;
182*4882a593Smuzhiyun		};
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun		master {
185*4882a593Smuzhiyun			/* master ID 42, 4 GiB DMA window starting at 0 */
186*4882a593Smuzhiyun			iommus = <&{/iommu}  42  0  0x1 0x0>;
187*4882a593Smuzhiyun		};
188*4882a593Smuzhiyun	};
189