162306a36Sopenharmony_ciThis document describes the generic device tree binding for IOMMUs and their
262306a36Sopenharmony_cimaster(s).
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciIOMMU device node:
662306a36Sopenharmony_ci==================
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciAn IOMMU can provide the following services:
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci* Remap address space to allow devices to access physical memory ranges that
1162306a36Sopenharmony_ci  they otherwise wouldn't be capable of accessing.
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci  Example: 32-bit DMA to 64-bit physical addresses
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci* Implement scatter-gather at page level granularity so that the device does
1662306a36Sopenharmony_ci  not have to.
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci* Provide system protection against "rogue" DMA by forcing all accesses to go
1962306a36Sopenharmony_ci  through the IOMMU and faulting when encountering accesses to unmapped
2062306a36Sopenharmony_ci  address regions.
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci* Provide address space isolation between multiple contexts.
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci  Example: Virtualization
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciDevice nodes compatible with this binding represent hardware with some of the
2762306a36Sopenharmony_ciabove capabilities.
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciIOMMUs can be single-master or multiple-master. Single-master IOMMU devices
3062306a36Sopenharmony_citypically have a fixed association to the master device, whereas multiple-
3162306a36Sopenharmony_cimaster IOMMU devices can translate accesses from more than one master.
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciThe device tree node of the IOMMU device's parent bus must contain a valid
3462306a36Sopenharmony_ci"dma-ranges" property that describes how the physical address space of the
3562306a36Sopenharmony_ciIOMMU maps to memory. An empty "dma-ranges" property means that there is a
3662306a36Sopenharmony_ci1:1 mapping from IOMMU to memory.
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciRequired properties:
3962306a36Sopenharmony_ci--------------------
4062306a36Sopenharmony_ci- #iommu-cells: The number of cells in an IOMMU specifier needed to encode an
4162306a36Sopenharmony_ci  address.
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ciThe meaning of the IOMMU specifier is defined by the device tree binding of
4462306a36Sopenharmony_cithe specific IOMMU. Below are a few examples of typical use-cases:
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci- #iommu-cells = <0>: Single master IOMMU devices are not configurable and
4762306a36Sopenharmony_ci  therefore no additional information needs to be encoded in the specifier.
4862306a36Sopenharmony_ci  This may also apply to multiple master IOMMU devices that do not allow the
4962306a36Sopenharmony_ci  association of masters to be configured. Note that an IOMMU can by design
5062306a36Sopenharmony_ci  be multi-master yet only expose a single master in a given configuration.
5162306a36Sopenharmony_ci  In such cases the number of cells will usually be 1 as in the next case.
5262306a36Sopenharmony_ci- #iommu-cells = <1>: Multiple master IOMMU devices may need to be configured
5362306a36Sopenharmony_ci  in order to enable translation for a given master. In such cases the single
5462306a36Sopenharmony_ci  address cell corresponds to the master device's ID. In some cases more than
5562306a36Sopenharmony_ci  one cell can be required to represent a single master ID.
5662306a36Sopenharmony_ci- #iommu-cells = <4>: Some IOMMU devices allow the DMA window for masters to
5762306a36Sopenharmony_ci  be configured. The first cell of the address in this may contain the master
5862306a36Sopenharmony_ci  device's ID for example, while the second cell could contain the start of
5962306a36Sopenharmony_ci  the DMA window for the given device. The length of the DMA window is given
6062306a36Sopenharmony_ci  by the third and fourth cells.
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciNote that these are merely examples and real-world use-cases may use different
6362306a36Sopenharmony_cidefinitions to represent their individual needs. Always refer to the specific
6462306a36Sopenharmony_ciIOMMU binding for the exact meaning of the cells that make up the specifier.
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ciIOMMU master node:
6862306a36Sopenharmony_ci==================
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ciDevices that access memory through an IOMMU are called masters. A device can
7162306a36Sopenharmony_cihave multiple master interfaces (to one or more IOMMU devices).
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ciRequired properties:
7462306a36Sopenharmony_ci--------------------
7562306a36Sopenharmony_ci- iommus: A list of phandle and IOMMU specifier pairs that describe the IOMMU
7662306a36Sopenharmony_ci  master interfaces of the device. One entry in the list describes one master
7762306a36Sopenharmony_ci  interface of the device.
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciWhen an "iommus" property is specified in a device tree node, the IOMMU will
8062306a36Sopenharmony_cibe used for address translation. If a "dma-ranges" property exists in the
8162306a36Sopenharmony_cidevice's parent node it will be ignored. An exception to this rule is if the
8262306a36Sopenharmony_cireferenced IOMMU is disabled, in which case the "dma-ranges" property of the
8362306a36Sopenharmony_ciparent shall take effect. Note that merely disabling a device tree node does
8462306a36Sopenharmony_cinot guarantee that the IOMMU is really disabled since the hardware may not
8562306a36Sopenharmony_cihave a means to turn off translation. But it is invalid in such cases to
8662306a36Sopenharmony_cidisable the IOMMU's device tree node in the first place because it would
8762306a36Sopenharmony_ciprevent any driver from properly setting up the translations.
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciOptional properties:
9062306a36Sopenharmony_ci--------------------
9162306a36Sopenharmony_ci- pasid-num-bits: Some masters support multiple address spaces for DMA, by
9262306a36Sopenharmony_ci  tagging DMA transactions with an address space identifier. By default,
9362306a36Sopenharmony_ci  this is 0, which means that the device only has one address space.
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci- dma-can-stall: When present, the master can wait for a transaction to
9662306a36Sopenharmony_ci  complete for an indefinite amount of time. Upon translation fault some
9762306a36Sopenharmony_ci  IOMMUs, instead of aborting the translation immediately, may first
9862306a36Sopenharmony_ci  notify the driver and keep the transaction in flight. This allows the OS
9962306a36Sopenharmony_ci  to inspect the fault and, for example, make physical pages resident
10062306a36Sopenharmony_ci  before updating the mappings and completing the transaction. Such IOMMU
10162306a36Sopenharmony_ci  accepts a limited number of simultaneous stalled transactions before
10262306a36Sopenharmony_ci  having to either put back-pressure on the master, or abort new faulting
10362306a36Sopenharmony_ci  transactions.
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci  Firmware has to opt-in stalling, because most buses and masters don't
10662306a36Sopenharmony_ci  support it. In particular it isn't compatible with PCI, where
10762306a36Sopenharmony_ci  transactions have to complete before a time limit. More generally it
10862306a36Sopenharmony_ci  won't work in systems and masters that haven't been designed for
10962306a36Sopenharmony_ci  stalling. For example the OS, in order to handle a stalled transaction,
11062306a36Sopenharmony_ci  may attempt to retrieve pages from secondary storage in a stalled
11162306a36Sopenharmony_ci  domain, leading to a deadlock.
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ciNotes:
11562306a36Sopenharmony_ci======
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciOne possible extension to the above is to use an "iommus" property along with
11862306a36Sopenharmony_cia "dma-ranges" property in a bus device node (such as PCI host bridges). This
11962306a36Sopenharmony_cican be useful to describe how children on the bus relate to the IOMMU if they
12062306a36Sopenharmony_ciare not explicitly listed in the device tree (e.g. PCI devices). However, the
12162306a36Sopenharmony_cirequirements of that use-case haven't been fully determined yet. Implementing
12262306a36Sopenharmony_cithis is therefore not recommended without further discussion and extension of
12362306a36Sopenharmony_cithis binding.
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciExamples:
12762306a36Sopenharmony_ci=========
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciSingle-master IOMMU:
13062306a36Sopenharmony_ci--------------------
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci	iommu {
13362306a36Sopenharmony_ci		#iommu-cells = <0>;
13462306a36Sopenharmony_ci	};
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	master {
13762306a36Sopenharmony_ci		iommus = <&{/iommu}>;
13862306a36Sopenharmony_ci	};
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ciMultiple-master IOMMU with fixed associations:
14162306a36Sopenharmony_ci----------------------------------------------
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci	/* multiple-master IOMMU */
14462306a36Sopenharmony_ci	iommu {
14562306a36Sopenharmony_ci		/*
14662306a36Sopenharmony_ci		 * Masters are statically associated with this IOMMU and share
14762306a36Sopenharmony_ci		 * the same address translations because the IOMMU does not
14862306a36Sopenharmony_ci		 * have sufficient information to distinguish between masters.
14962306a36Sopenharmony_ci		 *
15062306a36Sopenharmony_ci		 * Consequently address translation is always on or off for
15162306a36Sopenharmony_ci		 * all masters at any given point in time.
15262306a36Sopenharmony_ci		 */
15362306a36Sopenharmony_ci		#iommu-cells = <0>;
15462306a36Sopenharmony_ci	};
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci	/* static association with IOMMU */
15762306a36Sopenharmony_ci	master@1 {
15862306a36Sopenharmony_ci		reg = <1>;
15962306a36Sopenharmony_ci		iommus = <&{/iommu}>;
16062306a36Sopenharmony_ci	};
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci	/* static association with IOMMU */
16362306a36Sopenharmony_ci	master@2 {
16462306a36Sopenharmony_ci		reg = <2>;
16562306a36Sopenharmony_ci		iommus = <&{/iommu}>;
16662306a36Sopenharmony_ci	};
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ciMultiple-master IOMMU:
16962306a36Sopenharmony_ci----------------------
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci	iommu {
17262306a36Sopenharmony_ci		/* the specifier represents the ID of the master */
17362306a36Sopenharmony_ci		#iommu-cells = <1>;
17462306a36Sopenharmony_ci	};
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci	master@1 {
17762306a36Sopenharmony_ci		/* device has master ID 42 in the IOMMU */
17862306a36Sopenharmony_ci		iommus = <&{/iommu} 42>;
17962306a36Sopenharmony_ci	};
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci	master@2 {
18262306a36Sopenharmony_ci		/* device has master IDs 23 and 24 in the IOMMU */
18362306a36Sopenharmony_ci		iommus = <&{/iommu} 23>, <&{/iommu} 24>;
18462306a36Sopenharmony_ci	};
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ciMultiple-master IOMMU with configurable DMA window:
18762306a36Sopenharmony_ci---------------------------------------------------
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci	/ {
19062306a36Sopenharmony_ci		iommu {
19162306a36Sopenharmony_ci			/*
19262306a36Sopenharmony_ci			 * One cell for the master ID and one cell for the
19362306a36Sopenharmony_ci			 * address of the DMA window. The length of the DMA
19462306a36Sopenharmony_ci			 * window is encoded in two cells.
19562306a36Sopenharmony_ci			 *
19662306a36Sopenharmony_ci			 * The DMA window is the range addressable by the
19762306a36Sopenharmony_ci			 * master (i.e. the I/O virtual address space).
19862306a36Sopenharmony_ci			 */
19962306a36Sopenharmony_ci			#iommu-cells = <4>;
20062306a36Sopenharmony_ci		};
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci		master {
20362306a36Sopenharmony_ci			/* master ID 42, 4 GiB DMA window starting at 0 */
20462306a36Sopenharmony_ci			iommus = <&{/iommu}  42  0  0x1 0x0>;
20562306a36Sopenharmony_ci		};
20662306a36Sopenharmony_ci	};
207