Add the secure-impl property and advertise the resolved value through
S_IDR1.SECURE_IMPL. The default auto mode follows the availability of
the Secure memory address space, allowing the SMMU to follow the
machine's Secure configuration without a separate global override.

Resolve auto and validate the result in smmu_validate_property(). Reject
secure-impl=on without Secure memory or stage-1 translation support.
Select the available IRQ outputs after resolving the property.

Document the relationship to virt Secure configuration and explicit
arm-smmuv3 device creation.

Signed-off-by: Tao Tang <[email protected]>
Reviewed-by: Pierrick Bouvier <[email protected]>
Reviewed-by: Jim MacArthur <[email protected]>
---
 docs/system/arm/virt.rst | 11 +++++++++++
 include/hw/arm/smmuv3.h  |  2 ++
 hw/arm/smmuv3.c          | 37 ++++++++++++++++++++++++++++++++++++-
 hw/core/machine.c        |  1 +
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst
index 5f6dd179786..1876fb02e88 100644
--- a/docs/system/arm/virt.rst
+++ b/docs/system/arm/virt.rst
@@ -289,6 +289,17 @@ User-creatable SMMUv3 devices
       -device pxb-pcie,id=pcie.1,numa_node=1
       -device arm-smmuv3,primary-bus=pcie.1,id=smmuv3.1
 
+  ``secure-impl`` accepts ``on``, ``off``, or the default ``auto``. In
+  ``auto`` mode, the ``secure-memory`` link determines whether the Secure
+  programming interface is enabled. On virt, this link is controlled by the
+  machine's ``secure`` option. Secure support requires Secure memory and
+  Stage 1 support. Secure Stage 2 is not supported.
+
+  This property also applies to user-created devices, for example::
+
+      -M virt,secure=on
+      -device arm-smmuv3,primary-bus=pcie.0,secure-impl=on
+
   *Accelerated SMMUv3 (nested translation)*
 
   The ``accel=on`` option enables hardware-accelerated nested translation
diff --git a/include/hw/arm/smmuv3.h b/include/hw/arm/smmuv3.h
index cb05cb19e32..b7574107038 100644
--- a/include/hw/arm/smmuv3.h
+++ b/include/hw/arm/smmuv3.h
@@ -89,6 +89,8 @@ struct SMMUv3State {
     OnOffAuto ats;
     OasMode oas;
     SsidSizeMode ssidsize;
+    OnOffAuto secure_impl;
+
     /* SMMU CMDQV extension */
     OnOffAuto cmdqv;
 
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index b37b388c75e..6a00f6b99fa 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -354,6 +354,8 @@ static void smmuv3_init_id_regs(SMMUv3State *s)
 
     sbank->idr[1] = FIELD_DP32(sbank->idr[1], S_IDR1, S_SIDSIZE,
                                SMMU_IDR1_SIDSIZE);
+    sbank->idr[1] = FIELD_DP32(sbank->idr[1], S_IDR1, SECURE_IMPL,
+                               s->secure_impl == ON_OFF_AUTO_ON);
     smmuv3_accel_idr_override(s);
 }
 
@@ -2409,7 +2411,7 @@ static const MemoryRegionOps smmu_mem_ops = {
 
 int smmuv3_get_num_irqs(SMMUv3State *s)
 {
-    return SMMU_IRQ_NUM;
+    return s->secure_impl == ON_OFF_AUTO_ON ? SMMU_IRQ_NUM : SMMU_IRQ_NUM_NS;
 }
 
 static void smmu_init_irq(SMMUv3State *s, SysBusDevice *dev)
@@ -2442,6 +2444,32 @@ static void smmu_reset_exit(Object *obj, ResetType type)
 
 static bool smmu_validate_property(SMMUv3State *s, Error **errp)
 {
+    SMMUState *bs = ARM_SMMU(s);
+    bool secure_as_available = bs->secure_memory != NULL;
+
+    if (s->secure_impl == ON_OFF_AUTO_AUTO) {
+        s->secure_impl = secure_as_available ? ON_OFF_AUTO_ON
+                                             : ON_OFF_AUTO_OFF;
+    }
+
+    if (s->secure_impl == ON_OFF_AUTO_ON && !secure_as_available) {
+        error_setg(errp,
+                   "secure-impl=on requires a secure-memory address space");
+        return false;
+    }
+
+    /*
+     * When SECURE_IMPL == 1, stage 1 must be supported according to
+     * (IHI 0070G.b) 6.3.53 SMMU_S_IDR1, Page 442.
+     */
+    if (s->secure_impl == ON_OFF_AUTO_ON &&
+        s->stage && !strcmp(s->stage, "2")) {
+        error_setg(errp,
+                    "secure-impl=on requires stage=1 or stage=nested");
+        return false;
+    }
+
+
     if (s->oas != OAS_MODE_44 && s->oas != OAS_MODE_48 &&
         s->oas != OAS_MODE_AUTO) {
         error_setg(errp, "QEMU SMMUv3 model only implements auto, "
@@ -2626,6 +2654,13 @@ static const Property smmuv3_properties[] = {
     DEFINE_PROP_SSIDSIZE_MODE("ssidsize", SMMUv3State, ssidsize,
                               SSID_SIZE_MODE_AUTO),
     DEFINE_PROP_ON_OFF_AUTO("cmdqv", SMMUv3State, cmdqv, ON_OFF_AUTO_AUTO),
+    /*
+     * SECURE_IMPL field in S_IDR1 register.
+     * Indicates whether Secure state is implemented.
+     * Defaults to auto.
+     */
+    DEFINE_PROP_ON_OFF_AUTO("secure-impl", SMMUv3State, secure_impl,
+                            ON_OFF_AUTO_AUTO),
 };
 
 static void smmuv3_instance_init(Object *obj)
diff --git a/hw/core/machine.c b/hw/core/machine.c
index ed9bf8f5008..cd69f1d9159 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -46,6 +46,7 @@ GlobalProperty hw_compat_11_1[] = {
     { "pci-ehci-usb", "x-migrate-fetch-addr-64bit", "off" },
     { "pcie-root-port", "speed", "16" },
     { "virtio-blk-device", "fua", "off" },
+    { TYPE_ARM_SMMUV3, "secure-impl", "off" },
 };
 const size_t hw_compat_11_1_len = G_N_ELEMENTS(hw_compat_11_1);
 
-- 
2.34.1


Reply via email to