Previous article: https://msyksphinz-en.hatenablog.com/entry/2024/10/30/040000msyksphinz-en.hatenablog.com
Notes for getting a rough understanding of the RISC-V IOMMU architecture.
I've given up on reading it several times before, so this time I'm going to try reading it properly once more.
The process of translating an IOVA uses the hardware IDs (device_id and process_id) to identify the device context and the process context. The Device-context and Process-context provide the root PPN of the page table, PSCID, GSCID, and other control parameters that affect the address translation and protection process. If an address translation cache (???) is implemented, the translation process can use GSCID and PSCID to associate cached translations with that address space.
The process of translating an IOVA is as follows:
- If
ddtp.iommu_mode == Off, stop and report "All inbound transactions disallowed" (cause = 256). - If
ddtp.iommu_mode == Bareand any of the following conditions hold, stop and report "Transaction type disallowed" (cause = 260).- The transaction type is a Translated request (read, write/AMO, read-for-execute) or a PCIe ATS Translation request.
- If
capabilities.MSI_FLATis 0, the IOMMU uses the base-format device context. LetDDI[0]bedevice_id[6:0],DDI[1]bedevice_id[15:7], andDDI[2]bedevice_id[23:16]. - If
capabilities.MSI_FLATis 1, the IOMMU uses the extended-format device context. LetDDI[0]bedevice_id[5:0],DDI[1]bedevice_id[14:6], andDDI[2]bedevice_id[23:15]. - If the
device_idis wider than what the IOMMU mode supports, as determined by the following checks, stop and report "Transaction type disallowed" (cause = 260).ddtp.iommu_modeis2LVLandDDI[2]is not 0.ddtp.iommu_modeis1LVLand eitherDDI[2]is not 0 orDDI[1]is not 0
- Use the
device_idto find the device context (DC) as specified in ???. - If any of the following conditions hold, stop and report "Transaction type disallowed" (cause = 260).
- The transaction type is a Translated request (read, write/AMO, read-for-execute) or a PCIe ATS Translation request, and
DC.tc.EN_ATSis 0. - The transaction has a valid
process_idandDC.tc.PDTVis 0. - The transaction has a valid
process_id,DC.tc.PDTVis 1, and theprocess_idis wider than whatpdtp.MODEsupports. - The transaction type is not supported by the IOMMU.
- The transaction type is a Translated request (read, write/AMO, read-for-execute) or a PCIe ATS Translation request, and
- If the request is a Translated request and
DC.tc.T2GPAis 0, the translation process is complete. Go to step 20. - If the request is a Translated request and
DC.tc.T2GPAis 1, the IOVA is a GPA. Go to step 17 with the following page table information:- Let A be the IOVA (the IOVA is a GPA).
- Let
iosatp.MODEbeBare.- The
PSCIDvalue is not used when the first stage isBare.
- The
- Let
iohgatpbe the value of theDC.iohgatpfield.
- If DC.tc.PDTV is set to 0, go to step 17 with the following page table information:
- Let
iosatp.MODEbe the value of theDC.fsc.MODEfield. - Let
iosatp.PPNbe the value of theDC.fsc.PPNfield. - Let
PSCIDbe the value of theDC.ta.PSCIDfield. - Let
iohgatpbe the value of theDC.iohgatpfield.
- Let
- If DPE is 1 and there is no
process_idassociated with the transaction, letprocess_idbe the default value of 0.- If DPE is 0 and there is no
process_idassociated with the transaction, go to step 17 with the following page table information: - Let
iosatp.MODEbeBare.- The
PSCIDvalue is not used when the first stage isBare.
- The
- Let
iohgatpbe the value of theDC.iohgatpfield.
- If DPE is 0 and there is no
- If
DC.fsc.pdtp.MODE = Bare, go to step 17 with the following page table information:- Let
iosatp.MODEbeBare.- The
PSCIDvalue is not used when the first stage isBare.
- The
- Let
iohgatpbe the value of theDC.iohgatpfield.
- Let
- Find the process context (
PC) as specified in ???. - If any of the following conditions hold, stop and report "Transaction type disallowed" (cause = 260).
- The transaction requests supervisor privilege, but
PC.ta.ENSis not set.
- The transaction requests supervisor privilege, but
- Go to step 17 with the following page table information:
- Let
iosatp.MODEbe the value of thePC.fsc.MODEfield. - Let
iosatp.PPNbe the value of thePC.fsc.PPNfield. - Let
PSCIDbe the value of thePC.ta.PSCIDfield. - Let
iohgatpbe the value of theDC.iohgatpfield.
- Let
- To determine the GPA accessed by the transaction, use the process specified in the section "Two-Stage Address Translation" of the RISC-V Privileged specification [4]. If a fault is detected in the first-stage address translation process, stop and report that fault. If the translation process completes successfully, let A be the translated GPA.
- If MSI address translation using the MSI page table is enabled (that is,
DC.msiptp.MODE != Off), the MSI address translation process specified in ??? is invoked. If the GPA A is not determined to be the address of a virtual interrupt file, the process continues at step 19. If a fault is detected by the MSI address translation process, stop and report the fault; otherwise the process continues at step 20. - To translate the GPA A and determine the SPA accessed by the transaction, use the second-stage address translation process specified in the section "Two-Stage Address Translation" of the RISC-V Privileged specification [4]. If a fault is detected by the address translation process, stop and report that fault.
- Translation process complete.
When the U bit is checked in a second-stage PTE, the transaction is treated as not requesting supervisor privilege. The pte.xwr=010 encoding specified by the Zicfiss [5] extension for the shadow stack page type
in single-stage and VS-stage page tables remains an encoding reserved for IO transactions.
If the translation process reports a fault and the request is an Untranslated request or a Translated request, the IOMMU asks the IO bridge to abort the transaction. Guidelines for handling faulting transactions at the IO bridge are described in ???. Faults are reported using the fault/event reporting mechanism and fault-recording format specified in ???.
If a fault is detected by a PCIe ATS Translation Request, then instead of reporting the fault to software or causing an abort, the IOMMU can provide a response as defined by the PCIe protocol. The handling of PCIe ATS Translation Requests that incur a fault is specified in ???.
This is an English translation of the original Japanese post: RISC-V IOMMU の構成についてマニュアルを読んでまとめる (10. IOVA の変換プロセス)