Reading the Manual and Summarizing the RISC-V IOMMU Architecture (10. The IOVA Translation Process)

Previous article: https://msyksphinz-en.hatenablog.com/entry/2024/10/30/040000msyksphinz-en.hatenablog.com

github.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:

  1. If ddtp.iommu_mode == Off, stop and report "All inbound transactions disallowed" (cause = 256).
  2. If ddtp.iommu_mode == Bare and any of the following conditions hold, stop and report "Transaction type disallowed" (cause = 260).
    1. The transaction type is a Translated request (read, write/AMO, read-for-execute) or a PCIe ATS Translation request.
  3. If capabilities.MSI_FLAT is 0, the IOMMU uses the base-format device context. Let DDI[0] be device_id[6:0], DDI[1] be device_id[15:7], and DDI[2] be device_id[23:16].
  4. If capabilities.MSI_FLAT is 1, the IOMMU uses the extended-format device context. Let DDI[0] be device_id[5:0], DDI[1] be device_id[14:6], and DDI[2] be device_id[23:15].
  5. If the device_id is wider than what the IOMMU mode supports, as determined by the following checks, stop and report "Transaction type disallowed" (cause = 260).
    1. ddtp.iommu_mode is 2LVL and DDI[2] is not 0.
    2. ddtp.iommu_mode is 1LVL and either DDI[2] is not 0 or DDI[1] is not 0
  6. Use the device_id to find the device context (DC) as specified in ???.
  7. If any of the following conditions hold, stop and report "Transaction type disallowed" (cause = 260).
    1. The transaction type is a Translated request (read, write/AMO, read-for-execute) or a PCIe ATS Translation request, and DC.tc.EN_ATS is 0.
    2. The transaction has a valid process_id and DC.tc.PDTV is 0.
    3. The transaction has a valid process_id, DC.tc.PDTV is 1, and the process_id is wider than what pdtp.MODE supports.
    4. The transaction type is not supported by the IOMMU.
  8. If the request is a Translated request and DC.tc.T2GPA is 0, the translation process is complete. Go to step 20.
  9. If the request is a Translated request and DC.tc.T2GPA is 1, the IOVA is a GPA. Go to step 17 with the following page table information:
    1. Let A be the IOVA (the IOVA is a GPA).
    2. Let iosatp.MODE be Bare.
      1. The PSCID value is not used when the first stage is Bare.
    3. Let iohgatp be the value of the DC.iohgatp field.
  10. If DC.tc.PDTV is set to 0, go to step 17 with the following page table information:
    1. Let iosatp.MODE be the value of the DC.fsc.MODE field.
    2. Let iosatp.PPN be the value of the DC.fsc.PPN field.
    3. Let PSCID be the value of the DC.ta.PSCID field.
    4. Let iohgatp be the value of the DC.iohgatp field.
  11. If DPE is 1 and there is no process_id associated with the transaction, let process_id be the default value of 0.
    1. If DPE is 0 and there is no process_id associated with the transaction, go to step 17 with the following page table information:
    2. Let iosatp.MODE be Bare.
      1. The PSCID value is not used when the first stage is Bare.
    3. Let iohgatp be the value of the DC.iohgatp field.
  12. If DC.fsc.pdtp.MODE = Bare, go to step 17 with the following page table information:
    1. Let iosatp.MODE be Bare.
      1. The PSCID value is not used when the first stage is Bare.
    2. Let iohgatp be the value of the DC.iohgatp field.
  13. Find the process context (PC) as specified in ???.
  14. If any of the following conditions hold, stop and report "Transaction type disallowed" (cause = 260).
    1. The transaction requests supervisor privilege, but PC.ta.ENS is not set.
  15. Go to step 17 with the following page table information:
    1. Let iosatp.MODE be the value of the PC.fsc.MODE field.
    2. Let iosatp.PPN be the value of the PC.fsc.PPN field.
    3. Let PSCID be the value of the PC.ta.PSCID field.
    4. Let iohgatp be the value of the DC.iohgatp field.
  16. 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.
  17. 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.
  18. 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.
  19. 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 の変換プロセス)