Skip to contentSkip to conversation

Support RISC-V IOPMP

PATCH Superseded Ethan Chen via 1 participant 9 messages Jan 9, 2025

Subsystems (2)

v9 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v9 cover Support RISC-V IOPMP

When IOPMP is enabled, memory access to system memory from devices and the CPU will be checked by the IOPMP.

The issue of CPU access to non-CPU address space via IOMMU was previously mentioned by Jim Shu, who provided a patch[1] to fix it. IOPMP also requires this patch.

You can use a customized QEMU[2] to run bare-metal demo[3] to show IOPMP functionality. The modifications involve applying patch[1] and adding a simple DMA device along with a second IOPMP device to the virt machine. These additional devices are intended to demonstrate more complex scenarios for IOPMP.

[1] accel/tcg: Store section pointer in CPUTLBEntryFull

    https://patchew.org/QEMU/[email protected]/[email protected]/

[2] https://github.com/zhanyangch/qemu/tree/iopmp_patch_v9_test
[3] https://github.com/zhanyangch/iopmp-test

Ethan Chen (8):
hw/core: Add config stream
memory: Introduce memory region fetch operation system/physmem: Support IOMMU granularity smaller than TARGET_PAGE
size
target/riscv: Add support for IOPMP hw/misc/riscv_iopmp_txn_info: Add struct for transaction infomation hw/misc/riscv_iopmp: Add RISC-V IOPMP device hw/misc/riscv_iopmp_dispatcher: Device for redirect IOPMP transaction
infomation
hw/riscv/virt: Add IOPMP support

 accel/tcg/cputlb.c                       |   29 +-
 docs/system/riscv/virt.rst               |    7 +
 hw/Kconfig                               |    1 +
 hw/core/Kconfig                          |    3 +
 hw/core/meson.build                      |    2 +-
 hw/misc/Kconfig                          |    4 +
 hw/misc/meson.build                      |    2 +
 hw/misc/riscv_iopmp.c                    | 2180 ++++++++++++++++++++++
 hw/misc/riscv_iopmp_dispatcher.c         |  136 ++
 hw/misc/trace-events                     |    4 +
 hw/riscv/Kconfig                         |    1 +
 hw/riscv/virt.c                          |   75 +
 include/exec/memory.h                    |   27 +
 include/hw/misc/riscv_iopmp.h            |  191 ++
 include/hw/misc/riscv_iopmp_dispatcher.h |   61 +
 include/hw/misc/riscv_iopmp_txn_info.h   |   38 +
 include/hw/riscv/virt.h                  |    4 +
 system/memory.c                          |  104 ++
 system/physmem.c                         |    4 +
 system/trace-events                      |    2 +
 target/riscv/cpu.c                       |    3 +
 target/riscv/cpu_cfg.h                   |    2 +
 target/riscv/cpu_helper.c                |   18 +-
 23 files changed, 2888 insertions(+), 10 deletions(-)
 create mode 100644 hw/misc/riscv_iopmp.c
 create mode 100644 hw/misc/riscv_iopmp_dispatcher.c
 create mode 100644 include/hw/misc/riscv_iopmp.h
 create mode 100644 include/hw/misc/riscv_iopmp_dispatcher.h
 create mode 100644 include/hw/misc/riscv_iopmp_txn_info.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v9 1/8 hw/core: Add config stream

Make other device can use /hw/core/stream.c by select this config.

---
 hw/Kconfig          | 1 +
 hw/core/Kconfig     | 3 +++
 hw/core/meson.build | 2 +-
 3 files changed, 5 insertions(+), 1 deletion(-)
hw/Kconfig +1 -0
index 1b4e9bb07f..cb12b8c11b 100644
@@ -77,6 +77,7 @@ config XILINX
 config XILINX_AXI
     bool
     select PTIMER # for hw/dma/xilinx_axidma.c
+    select STREAM
 
 config XLNX_ZYNQMP
     bool
hw/core/Kconfig +3 -0
index d1bdf765ee..dffa9a1b01 100644
@@ -38,3 +38,6 @@ config SPLIT_IRQ
 config EIF
     bool
     depends on LIBCBOR && GNUTLS
+
+config STREAM
+    bool
hw/core/meson.build +1 -1
index ce9dfa3f4b..2871639301 100644
@@ -22,7 +22,7 @@ system_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('platform-bus.c'))
 system_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c'))
 system_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c'))
 system_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c'))
-system_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c'))
+system_ss.add(when: 'CONFIG_STREAM', if_true: files('stream.c'))
 system_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c'))
 system_ss.add(when: 'CONFIG_EIF', if_true: [files('eif.c'), zlib, libcbor, gnutls])
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v9 2/8 memory: Introduce memory region fetch operation

In reply to Ethan Chen via

Allow memory regions to have different behaviors for read and fetch operations.

For example, the RISC-V IOPMP could raise an interrupt when the CPU tries to fetch from a non-executable region.

If the fetch operation for a memory region is not implemented, the read operation will still be used for fetch operations.

---
 accel/tcg/cputlb.c    |   9 +++-
 include/exec/memory.h |  27 +++++++++++
 system/memory.c       | 104 ++++++++++++++++++++++++++++++++++++++++++
 system/trace-events   |   2 +
 4 files changed, 140 insertions(+), 2 deletions(-)
accel/tcg/cputlb.c +7 -2
index b4ccf0cdcb..71c16a1ac1 100644
@@ -1947,8 +1947,13 @@ static uint64_t int_ld_mmio_beN(CPUState *cpu, CPUTLBEntryFull *full,
         this_size = 1 << this_mop;
         this_mop |= MO_BE;
 
-        r = memory_region_dispatch_read(mr, mr_offset, &val,
-                                        this_mop, full->attrs);
+        if (type == MMU_INST_FETCH) {
+            r = memory_region_dispatch_fetch(mr, mr_offset, &val,
+                                             this_mop, full->attrs);
+        } else {
+            r = memory_region_dispatch_read(mr, mr_offset, &val,
+                                            this_mop, full->attrs);
+        }
         if (unlikely(r != MEMTX_OK)) {
             io_failed(cpu, full, addr, this_size, type, mmu_idx, r, ra);
         }
include/exec/memory.h +27 -0
index 9458e2801d..ed15d99c3c 100644
@@ -273,6 +273,11 @@ struct MemoryRegionOps {
                   hwaddr addr,
                   uint64_t data,
                   unsigned size);
+    /* Fetch from the memory region. @addr is relative to @mr; @size is
+     * in bytes. */
+    uint64_t (*fetch)(void *opaque,
+                      hwaddr addr,
+                      unsigned size);
 
     MemTxResult (*read_with_attrs)(void *opaque,
                                    hwaddr addr,
@@ -284,6 +289,11 @@ struct MemoryRegionOps {
                                     uint64_t data,
                                     unsigned size,
                                     MemTxAttrs attrs);
+    MemTxResult (*fetch_with_attrs)(void *opaque,
+                                    hwaddr addr,
+                                    uint64_t *data,
+                                    unsigned size,
+                                    MemTxAttrs attrs);
 
     enum device_endian endianness;
     /* Guest-visible constraints: */
@@ -2605,6 +2615,23 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
                                          MemOp op,
                                          MemTxAttrs attrs);
 
+
+/**
+ * memory_region_dispatch_fetch: perform a fetch directly to the specified
+ * MemoryRegion.
+ *
+ * @mr: #MemoryRegion to access
+ * @addr: address within that region
+ * @pval: pointer to uint64_t which the data is written to
+ * @op: size, sign, and endianness of the memory operation
+ * @attrs: memory transaction attributes to use for the access
+ */
+MemTxResult memory_region_dispatch_fetch(MemoryRegion *mr,
+                                         hwaddr addr,
+                                         uint64_t *pval,
+                                         MemOp op,
+                                         MemTxAttrs attrs);
+
 /**
  * address_space_init: initializes an address space
  *
system/memory.c +104 -0

116 lines not on this page · raw message

system/trace-events +2 -0
index 5bbc3fbffa..4e78bb515b 100644
@@ -18,8 +18,10 @@ cpu_out(unsigned int addr, char size, unsigned int val) "addr 0x%x(%c) value %u"
 # memory.c
 memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size, const char *name) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u name '%s'"
 memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size, const char *name) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u name '%s'"
+memory_region_ops_fetch(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size, const char *name) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u name '%s'"
 memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u"
 memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u"
+memory_region_subpage_fetch(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u"
 memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u"
 memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u"
 memory_region_sync_dirty(const char *mr, const char *listener, int global) "mr '%s' listener '%s' synced (global=%d)"
Signature · 1 line
2.34.1
#3 lore raw

PATCH v9 3/8 system/physmem: Support IOMMU granularity smaller than TARGET_PAGE size

In reply to Ethan Chen via

If the IOMMU granularity is smaller than the TARGET_PAGE size, there may be
multiple entries within the same page. To obtain the correct result, pass
the original address to the IOMMU.

Similar to the RISC-V PMP solution, the TLB_INVALID_MASK will be set when there are multiple entries in the same page, ensuring that the IOMMU is checked on every access.

---
 accel/tcg/cputlb.c | 20 ++++++++++++++++----
 system/physmem.c   |  4 ++++
 2 files changed, 20 insertions(+), 4 deletions(-)
accel/tcg/cputlb.c +16 -4
index 71c16a1ac1..ed55f02eab 100644
@@ -1063,8 +1063,23 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx,
 
     prot = full->prot;
     asidx = cpu_asidx_from_attrs(cpu, full->attrs);
-    section = address_space_translate_for_iotlb(cpu, asidx, paddr_page,
+    section = address_space_translate_for_iotlb(cpu, asidx, full->phys_addr,
                                                 &xlat, &sz, full->attrs, &prot);
+    /* Update page size */
+    full->lg_page_size = ctz64(sz);
+    if (full->lg_page_size > TARGET_PAGE_BITS) {
+        full->lg_page_size = TARGET_PAGE_BITS;
+    } else {
+        sz = TARGET_PAGE_SIZE;
+    }
+
+    is_ram = memory_region_is_ram(section->mr);
+    is_romd = memory_region_is_romd(section->mr);
+    /* If the translated mr is ram/rom, make xlat align the TARGET_PAGE */
+    if (is_ram || is_romd) {
+        xlat &= TARGET_PAGE_MASK;
+    }
+
     assert(sz >= TARGET_PAGE_SIZE);
 
     tlb_debug("vaddr=%016" VADDR_PRIx " paddr=0x" HWADDR_FMT_plx
@@ -1077,9 +1092,6 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx,
         read_flags |= TLB_INVALID_MASK;
     }
 
-    is_ram = memory_region_is_ram(section->mr);
-    is_romd = memory_region_is_romd(section->mr);
-
     if (is_ram || is_romd) {
         /* RAM and ROMD both have associated host memory. */
         addend = (uintptr_t)memory_region_get_ram_ptr(section->mr) + xlat;
system/physmem.c +4 -0
index c76503aea8..d64543b413 100644
@@ -702,6 +702,10 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr,
         iotlb = imrc->translate(iommu_mr, addr, IOMMU_NONE, iommu_idx);
         addr = ((iotlb.translated_addr & ~iotlb.addr_mask)
                 | (addr & iotlb.addr_mask));
+        /* Update size */
+        if (iotlb.addr_mask != -1 && *plen > iotlb.addr_mask + 1) {
+            *plen = iotlb.addr_mask + 1;
+        }
         /* Update the caller's prot bits to remove permissions the IOMMU
          * is giving us a failure response for. If we get down to no
          * permissions left at all we can give up now.
Signature · 1 line
2.34.1
#4 lore raw

PATCH v9 4/8 target/riscv: Add support for IOPMP

In reply to Ethan Chen via
---
 target/riscv/cpu.c        |  3 +++
 target/riscv/cpu_cfg.h    |  2 ++
 target/riscv/cpu_helper.c | 18 +++++++++++++++---
 3 files changed, 20 insertions(+), 3 deletions(-)
target/riscv/cpu.c +3 -0
index b8d5120106..212e522ed7 100644
@@ -2798,6 +2798,9 @@ static const Property riscv_cpu_properties[] = {
      * it with -x and default to 'false'.
      */
     DEFINE_PROP_BOOL("x-misa-w", RISCVCPU, cfg.misa_w, false),
+
+    DEFINE_PROP_BOOL("iopmp", RISCVCPU, cfg.iopmp, false),
+    DEFINE_PROP_UINT32("iopmp_rrid", RISCVCPU, cfg.iopmp_rrid, 0),
 };
 
 #if defined(TARGET_RISCV64)
target/riscv/cpu_cfg.h +2 -0
index a1457ab4f4..c5d5e1a77d 100644
@@ -175,6 +175,8 @@ struct RISCVCPUConfig {
     bool pmp;
     bool debug;
     bool misa_w;
+    bool iopmp;
+    uint32_t iopmp_rrid;
 
     bool short_isa_string;
 
target/riscv/cpu_helper.c +15 -3
index f62b21e182..926ae38684 100644
@@ -1599,9 +1599,21 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
     }
 
     if (ret == TRANSLATE_SUCCESS) {
-        tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1),
-                     prot, mmu_idx, tlb_size);
-        return true;
+        if (cpu->cfg.iopmp) {
+            /*
+             * Do not align address on early stage because IOPMP needs origin
+             * address for permission check.
+             */
+            tlb_set_page_with_attrs(cs, address, pa,
+                                    (MemTxAttrs)
+                                        {
+                                          .requester_id = cpu->cfg.iopmp_rrid,
+                                        },
+                                    prot, mmu_idx, tlb_size);
+        } else {
+            tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1),
+                         prot, mmu_idx, tlb_size);
+        }
     } else if (probe) {
         return false;
     } else {
Signature · 1 line
2.34.1
#5 lore raw

PATCH v9 5/8 hw/misc/riscv_iopmp_txn_info: Add struct for transaction infomation

In reply to Ethan Chen via

The entire valid transaction must fit within a single IOPMP entry. However, during IOMMU translation, the transaction size is not available. This structure defines the transaction information required by the IOPMP.

---
 include/hw/misc/riscv_iopmp_txn_info.h | 38 ++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 include/hw/misc/riscv_iopmp_txn_info.h
include/hw/misc/riscv_iopmp_txn_info.h new file +38 -0
new file mode 100644
index 0000000000..98bd26b68b
@@ -0,0 +1,38 @@
+/*
+ * QEMU RISC-V IOPMP transaction information
+ *
+ * The transaction information structure provides the complete transaction
+ * length to the IOPMP device
+ *
+ * Copyright (c) 2023-2025 Andes Tech. Corp.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RISCV_IOPMP_TXN_INFO_H
+#define RISCV_IOPMP_TXN_INFO_H
+
+typedef struct {
+    /* The id of requestor */
+    uint32_t rrid:16;
+    /* The start address of transaction */
+    uint64_t start_addr;
+    /* The end address of transaction */
+    uint64_t end_addr;
+    /* The stage of cascading IOPMP */
+    uint32_t stage;
+} riscv_iopmp_txn_info;
+
+#endif
Signature · 1 line
2.34.1
#6 lore raw

PATCH v9 6/8 hw/misc/riscv_iopmp: Add RISC-V IOPMP device

In reply to Ethan Chen via

Support IOPMP specification v0.9.2RC3.
The specification url:
https://github.com/riscv-non-isa/iopmp-spec/releases/tag/v0.9.2-RC3

The IOPMP checks whether memory access from a device or CPU is valid. This implementation uses an IOMMU to modify the address space accessed by the device.

For device access with IOMMUAccessFlags specifying read or write (IOMMU_RO or IOMMU_WO), the IOPMP checks the permission in iopmp_translate. If the access is valid, the target address space is downstream_as. If the access is blocked, it will be redirected to blocked_rwx_as.

For CPU access with IOMMUAccessFlags not specifying read or write (IOMMU_NONE), the IOPMP translates the access to the corresponding address space based on the permission. If the access has full permission (rwx), the target address space is downstream_as. If the access has limited permission, the target address space is blocked_ followed by the lacked permissions.

The operation of a blocked region can trigger an IOPMP interrupt, a bus error, or it can respond with success and fabricated data, depending on the value of the IOPMP ERR_CFG register.

Support Properties and Default Values of the IOPMP Device
The following are the supported properties and their default values for the IOPMP device. If a property has no description here, please refer to the IOPMP specification for details:

* mdcfg_fmt: 1 (Options: 0/1/2)
* srcmd_fmt: 0 (Options: 0/1/2)
* tor_en: true (Options: true/false)
* sps_en: false (Options: true/false)
* prient_prog: true (Options: true/false)
* rrid_transl_en: false (Options: true/false)
* rrid_transl_prog: false (Options: true/false)
* chk_x: true (Options: true/false)
* no_x: false (Options: true/false)
* no_w: false (Options: true/false)
* stall_en: false (Options: true/false)
* peis: true (Options: true/false)
* pees: true (Options: true/false)
* mfr_en: true (Options: true/false)
* md_entry_num: 5 (IMP: Valid only for mdcfg_fmt 1/2)
* md_num: 8 (Range: 0-63)
* rrid_num: 16 (Range: srcmd_fmt ≠ 2: 0-65535, srcmd_fmt = 2: 0-32)
* entry_num: 48
(Range: 0-IMP. For mdcfg_fmt = 1, it is fixed as md_num * (md_entry_num + 1).
Entry registers must not overlap with other registers.)
* prio_entry: 65535
(Range: 0-IMP. If prio_entry > entry_num, it will be set to entry_num.)
* rrid_transl: 0x0 (Range: 0-65535)
* entry_offset: 0x4000
(IMP: Entry registers must not overlap with other registers.)
* err_rdata: 0x0
(uint32. Specifies the value used in responses to read transactions when
errors are suppressed)
* msi_en: false (Options: true/false)
* msidata: 12 (Range: 1-1023)
* stall_violation_en: true (Options: true/false)
* err_msiaddr: 0x24000000 (low-part 32-bit address)
* err_msiaddrh: 0x0 (high-part 32-bit address)
* msi_rrid: 0
(Range: 0-65535. Specifies the rrid used by the IOPMP to send the MSI.)

---
 hw/misc/Kconfig               |    4 +
 hw/misc/meson.build           |    1 +
 hw/misc/riscv_iopmp.c         | 2180 +++++++++++++++++++++++++++++++++
 hw/misc/trace-events          |    4 +
 include/hw/misc/riscv_iopmp.h |  191 +++
 5 files changed, 2380 insertions(+)
 create mode 100644 hw/misc/riscv_iopmp.c
 create mode 100644 include/hw/misc/riscv_iopmp.h
hw/misc/Kconfig +4 -0
index 8f9ce2f68c..e4ad9cf9fe 100644
@@ -220,4 +220,8 @@ config IOSB
 config XLNX_VERSAL_TRNG
     bool
 
+config RISCV_IOPMP
+    bool
+    select STREAM
+
 source macio/Kconfig
hw/misc/meson.build +1 -0
index 55f493521b..88f2bb6b88 100644
@@ -34,6 +34,7 @@ system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c'))
+specific_ss.add(when: 'CONFIG_RISCV_IOPMP', if_true: files('riscv_iopmp.c'))
 
 subdir('macio')
 
hw/misc/riscv_iopmp.c new file +2180 -0

2,180 lines not on this page · raw message

hw/misc/trace-events +4 -0
index 0f5d2b5666..965bf7ffc6 100644
@@ -384,3 +384,7 @@ ivshmem_flat_read_write_mmr_invalid(uint64_t addr_offset) "No ivshmem register m
 ivshmem_flat_interrupt_invalid_peer(uint16_t peer_id) "Can't interrupt non-existing peer %u"
 ivshmem_flat_write_mmr(uint64_t addr_offset) "Write access at offset %"PRIu64
 ivshmem_flat_interrupt_peer(uint16_t peer_id, uint16_t vector_id) "Interrupting peer ID %u, vector %u..."
+
+# riscv_iopmp.c
+iopmp_read(uint64_t addr, uint32_t val) "addr 0x%"PRIx64" val 0x%x"
+iopmp_write(uint64_t addr, uint32_t val) "addr 0x%"PRIx64" val 0x%x"
include/hw/misc/riscv_iopmp.h new file +191 -0

191 lines not on this page · raw message

Signature · 1 line
2.34.1
#7 lore raw

PATCH v9 7/8 hw/misc/riscv_iopmp_dispatcher: Device for redirect IOPMP transaction infomation

In reply to Ethan Chen via

This device determines the target IOPMP device for forwarding information based on:
* Address: For parallel IOPMP devices
* Stage: For cascading IOPMP devices

---
 hw/misc/meson.build                      |   1 +
 hw/misc/riscv_iopmp_dispatcher.c         | 136 +++++++++++++++++++++++
 include/hw/misc/riscv_iopmp_dispatcher.h |  61 ++++++++++
 3 files changed, 198 insertions(+)
 create mode 100644 hw/misc/riscv_iopmp_dispatcher.c
 create mode 100644 include/hw/misc/riscv_iopmp_dispatcher.h
hw/misc/meson.build +1 -0
index 88f2bb6b88..497f83637f 100644
@@ -35,6 +35,7 @@ system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c'))
 specific_ss.add(when: 'CONFIG_RISCV_IOPMP', if_true: files('riscv_iopmp.c'))
+specific_ss.add(when: 'CONFIG_RISCV_IOPMP', if_true: files('riscv_iopmp_dispatcher.c'))
 
 subdir('macio')
 
hw/misc/riscv_iopmp_dispatcher.c new file +136 -0

136 lines not on this page · raw message

include/hw/misc/riscv_iopmp_dispatcher.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

PATCH v9 8/8 hw/riscv/virt: Add IOPMP support

In reply to Ethan Chen via

- Add 'iopmp=on' option to enable IOPMP. It adds iopmp devices virt machine to protect all regions of system memory.

---
 docs/system/riscv/virt.rst |  7 ++++
 hw/riscv/Kconfig           |  1 +
 hw/riscv/virt.c            | 75 ++++++++++++++++++++++++++++++++++++++
 include/hw/riscv/virt.h    |  4 ++
 4 files changed, 87 insertions(+)
docs/system/riscv/virt.rst +7 -0
index 60850970ce..6b5fc1d37d 100644
@@ -146,6 +146,13 @@ The following machine-specific options are supported:
 
   Enables the riscv-iommu-sys platform device. Defaults to 'off'.
 
+- iopmp=[on|off]
+
+  When this option is "on", IOPMP devices are added to machine. IOPMP checks
+  memory transcations in system memory. This option is assumed to be "off". To
+  enable the CPU to perform transactions with a specified RRID, use the CPU
+  option "-cpu <cpu>,iopmp=true,iopmp_rrid=<rrid>"
+
 Running Linux kernel
 --------------------
 
hw/riscv/Kconfig +1 -0
index e6a0ac1fa1..637438af2c 100644
@@ -68,6 +68,7 @@ config RISCV_VIRT
     select PLATFORM_BUS
     select ACPI
     select ACPI_PCI
+    select RISCV_IOPMP
 
 config SHAKTI_C
     bool
hw/riscv/virt.c +75 -0

129 lines not on this page · raw message

include/hw/riscv/virt.h +4 -0
index 48a14bea2e..77dcbd5450 100644
@@ -55,6 +55,7 @@ struct RISCVVirtState {
 
     int fdt_size;
     bool have_aclint;
+    bool have_iopmp;
     RISCVVirtAIAType aia_type;
     int aia_guests;
     char *oem_id;
@@ -87,11 +88,14 @@ enum {
     VIRT_PLATFORM_BUS,
     VIRT_PCIE_ECAM,
     VIRT_IOMMU_SYS,
+    VIRT_IOPMP,
 };
 
 enum {
     UART0_IRQ = 10,
     RTC_IRQ = 11,
+    IOPMP_IRQ = 12,
+    DMA_IRQ = 13,
     VIRTIO_IRQ = 1, /* 1 to 8 */
     VIRTIO_COUNT = 8,
     PCIE_IRQ = 0x20, /* 32 to 35 */
Signature · 1 line
2.34.1