18c2ecf20Sopenharmony_ciThis document describes the generic device tree binding for IOMMUs and their
28c2ecf20Sopenharmony_cimaster(s).
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciIOMMU device node:
68c2ecf20Sopenharmony_ci==================
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciAn IOMMU can provide the following services:
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci* Remap address space to allow devices to access physical memory ranges that
118c2ecf20Sopenharmony_ci  they otherwise wouldn't be capable of accessing.
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci  Example: 32-bit DMA to 64-bit physical addresses
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci* Implement scatter-gather at page level granularity so that the device does
168c2ecf20Sopenharmony_ci  not have to.
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci* Provide system protection against "rogue" DMA by forcing all accesses to go
198c2ecf20Sopenharmony_ci  through the IOMMU and faulting when encountering accesses to unmapped
208c2ecf20Sopenharmony_ci  address regions.
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci* Provide address space isolation between multiple contexts.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci  Example: Virtualization
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciDevice nodes compatible with this binding represent hardware with some of the
278c2ecf20Sopenharmony_ciabove capabilities.
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciIOMMUs can be single-master or multiple-master. Single-master IOMMU devices
308c2ecf20Sopenharmony_citypically have a fixed association to the master device, whereas multiple-
318c2ecf20Sopenharmony_cimaster IOMMU devices can translate accesses from more than one master.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciThe device tree node of the IOMMU device's parent bus must contain a valid
348c2ecf20Sopenharmony_ci"dma-ranges" property that describes how the physical address space of the
358c2ecf20Sopenharmony_ciIOMMU maps to memory. An empty "dma-ranges" property means that there is a
368c2ecf20Sopenharmony_ci1:1 mapping from IOMMU to memory.
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciRequired properties:
398c2ecf20Sopenharmony_ci--------------------
408c2ecf20Sopenharmony_ci- #iommu-cells: The number of cells in an IOMMU specifier needed to encode an
418c2ecf20Sopenharmony_ci  address.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThe meaning of the IOMMU specifier is defined by the device tree binding of
448c2ecf20Sopenharmony_cithe specific IOMMU. Below are a few examples of typical use-cases:
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci- #iommu-cells = <0>: Single master IOMMU devices are not configurable and
478c2ecf20Sopenharmony_ci  therefore no additional information needs to be encoded in the specifier.
488c2ecf20Sopenharmony_ci  This may also apply to multiple master IOMMU devices that do not allow the
498c2ecf20Sopenharmony_ci  association of masters to be configured. Note that an IOMMU can by design
508c2ecf20Sopenharmony_ci  be multi-master yet only expose a single master in a given configuration.
518c2ecf20Sopenharmony_ci  In such cases the number of cells will usually be 1 as in the next case.
528c2ecf20Sopenharmony_ci- #iommu-cells = <1>: Multiple master IOMMU devices may need to be configured
538c2ecf20Sopenharmony_ci  in order to enable translation for a given master. In such cases the single
548c2ecf20Sopenharmony_ci  address cell corresponds to the master device's ID. In some cases more than
558c2ecf20Sopenharmony_ci  one cell can be required to represent a single master ID.
568c2ecf20Sopenharmony_ci- #iommu-cells = <4>: Some IOMMU devices allow the DMA window for masters to
578c2ecf20Sopenharmony_ci  be configured. The first cell of the address in this may contain the master
588c2ecf20Sopenharmony_ci  device's ID for example, while the second cell could contain the start of
598c2ecf20Sopenharmony_ci  the DMA window for the given device. The length of the DMA window is given
608c2ecf20Sopenharmony_ci  by the third and fourth cells.
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciNote that these are merely examples and real-world use-cases may use different
638c2ecf20Sopenharmony_cidefinitions to represent their individual needs. Always refer to the specific
648c2ecf20Sopenharmony_ciIOMMU binding for the exact meaning of the cells that make up the specifier.
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciIOMMU master node:
688c2ecf20Sopenharmony_ci==================
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciDevices that access memory through an IOMMU are called masters. A device can
718c2ecf20Sopenharmony_cihave multiple master interfaces (to one or more IOMMU devices).
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciRequired properties:
748c2ecf20Sopenharmony_ci--------------------
758c2ecf20Sopenharmony_ci- iommus: A list of phandle and IOMMU specifier pairs that describe the IOMMU
768c2ecf20Sopenharmony_ci  master interfaces of the device. One entry in the list describes one master
778c2ecf20Sopenharmony_ci  interface of the device.
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciWhen an "iommus" property is specified in a device tree node, the IOMMU will
808c2ecf20Sopenharmony_cibe used for address translation. If a "dma-ranges" property exists in the
818c2ecf20Sopenharmony_cidevice's parent node it will be ignored. An exception to this rule is if the
828c2ecf20Sopenharmony_cireferenced IOMMU is disabled, in which case the "dma-ranges" property of the
838c2ecf20Sopenharmony_ciparent shall take effect. Note that merely disabling a device tree node does
848c2ecf20Sopenharmony_cinot guarantee that the IOMMU is really disabled since the hardware may not
858c2ecf20Sopenharmony_cihave a means to turn off translation. But it is invalid in such cases to
868c2ecf20Sopenharmony_cidisable the IOMMU's device tree node in the first place because it would
878c2ecf20Sopenharmony_ciprevent any driver from properly setting up the translations.
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciOptional properties:
908c2ecf20Sopenharmony_ci--------------------
918c2ecf20Sopenharmony_ci- pasid-num-bits: Some masters support multiple address spaces for DMA, by
928c2ecf20Sopenharmony_ci  tagging DMA transactions with an address space identifier. By default,
938c2ecf20Sopenharmony_ci  this is 0, which means that the device only has one address space.
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ciNotes:
978c2ecf20Sopenharmony_ci======
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciOne possible extension to the above is to use an "iommus" property along with
1008c2ecf20Sopenharmony_cia "dma-ranges" property in a bus device node (such as PCI host bridges). This
1018c2ecf20Sopenharmony_cican be useful to describe how children on the bus relate to the IOMMU if they
1028c2ecf20Sopenharmony_ciare not explicitly listed in the device tree (e.g. PCI devices). However, the
1038c2ecf20Sopenharmony_cirequirements of that use-case haven't been fully determined yet. Implementing
1048c2ecf20Sopenharmony_cithis is therefore not recommended without further discussion and extension of
1058c2ecf20Sopenharmony_cithis binding.
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciExamples:
1098c2ecf20Sopenharmony_ci=========
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ciSingle-master IOMMU:
1128c2ecf20Sopenharmony_ci--------------------
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	iommu {
1158c2ecf20Sopenharmony_ci		#iommu-cells = <0>;
1168c2ecf20Sopenharmony_ci	};
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	master {
1198c2ecf20Sopenharmony_ci		iommus = <&{/iommu}>;
1208c2ecf20Sopenharmony_ci	};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ciMultiple-master IOMMU with fixed associations:
1238c2ecf20Sopenharmony_ci----------------------------------------------
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/* multiple-master IOMMU */
1268c2ecf20Sopenharmony_ci	iommu {
1278c2ecf20Sopenharmony_ci		/*
1288c2ecf20Sopenharmony_ci		 * Masters are statically associated with this IOMMU and share
1298c2ecf20Sopenharmony_ci		 * the same address translations because the IOMMU does not
1308c2ecf20Sopenharmony_ci		 * have sufficient information to distinguish between masters.
1318c2ecf20Sopenharmony_ci		 *
1328c2ecf20Sopenharmony_ci		 * Consequently address translation is always on or off for
1338c2ecf20Sopenharmony_ci		 * all masters at any given point in time.
1348c2ecf20Sopenharmony_ci		 */
1358c2ecf20Sopenharmony_ci		#iommu-cells = <0>;
1368c2ecf20Sopenharmony_ci	};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	/* static association with IOMMU */
1398c2ecf20Sopenharmony_ci	master@1 {
1408c2ecf20Sopenharmony_ci		reg = <1>;
1418c2ecf20Sopenharmony_ci		iommus = <&{/iommu}>;
1428c2ecf20Sopenharmony_ci	};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/* static association with IOMMU */
1458c2ecf20Sopenharmony_ci	master@2 {
1468c2ecf20Sopenharmony_ci		reg = <2>;
1478c2ecf20Sopenharmony_ci		iommus = <&{/iommu}>;
1488c2ecf20Sopenharmony_ci	};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciMultiple-master IOMMU:
1518c2ecf20Sopenharmony_ci----------------------
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	iommu {
1548c2ecf20Sopenharmony_ci		/* the specifier represents the ID of the master */
1558c2ecf20Sopenharmony_ci		#iommu-cells = <1>;
1568c2ecf20Sopenharmony_ci	};
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	master@1 {
1598c2ecf20Sopenharmony_ci		/* device has master ID 42 in the IOMMU */
1608c2ecf20Sopenharmony_ci		iommus = <&{/iommu} 42>;
1618c2ecf20Sopenharmony_ci	};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	master@2 {
1648c2ecf20Sopenharmony_ci		/* device has master IDs 23 and 24 in the IOMMU */
1658c2ecf20Sopenharmony_ci		iommus = <&{/iommu} 23>, <&{/iommu} 24>;
1668c2ecf20Sopenharmony_ci	};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ciMultiple-master IOMMU with configurable DMA window:
1698c2ecf20Sopenharmony_ci---------------------------------------------------
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	/ {
1728c2ecf20Sopenharmony_ci		iommu {
1738c2ecf20Sopenharmony_ci			/*
1748c2ecf20Sopenharmony_ci			 * One cell for the master ID and one cell for the
1758c2ecf20Sopenharmony_ci			 * address of the DMA window. The length of the DMA
1768c2ecf20Sopenharmony_ci			 * window is encoded in two cells.
1778c2ecf20Sopenharmony_ci			 *
1788c2ecf20Sopenharmony_ci			 * The DMA window is the range addressable by the
1798c2ecf20Sopenharmony_ci			 * master (i.e. the I/O virtual address space).
1808c2ecf20Sopenharmony_ci			 */
1818c2ecf20Sopenharmony_ci			#iommu-cells = <4>;
1828c2ecf20Sopenharmony_ci		};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci		master {
1858c2ecf20Sopenharmony_ci			/* master ID 42, 4 GiB DMA window starting at 0 */
1868c2ecf20Sopenharmony_ci			iommus = <&{/iommu}  42  0  0x1 0x0>;
1878c2ecf20Sopenharmony_ci		};
1888c2ecf20Sopenharmony_ci	};
189