Skip to contentSkip to conversation

zynqmp: Add forwarding of platform specific firmware calls

RFC Superseded Edgar E. Iglesias 2 participants 8 messages Jan 30, 2017 – Jan 31, 2017 Arm/Zynq architecture

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover zynqmp: Add forwarding of platform specific firmware calls

From: "Edgar E. Iglesias" <[email protected]>

The ZynqMP software stack has an extensive Firmware API. Software at EL1 is increasingly dependant on this API. In fact, a large set of use-cases for Linux already require access to firmware. In a couple of months, we expect that most setups will need it, so this is becoming somewhat urgent.

Services provided by the API, among other things include:
* Clock Management
* PHY Configuration
* Power Management
* FPGA configuration
* etc

Adding support for accessing firmware comes in two steps.

1. Allow the hw domain (dom0) to call into firmware. This enables all devices to work with PV setups.

2. Allow other guests to use the Firmware API. This will be needed to fully support Device pass-through.
We cannot give un-supervised access to unprivileged guests, so the idea is to mediate these calls in Xen or preferably in dom0. Mediation mainly consists of ref-counting and filtering.

This RFC patch series implements step #1.

There are quite a few options on how to implement step #2, e.g:
1. Trap HVC/SMC calls from unpriv guests and handle them in dom0. This could be done in a user-space agent.
2. Add a PV protocol carrying these calls. This is similar to #1.
3. Add several generic PV protocols carrying a set of platform independent generic calls that get translated or mapped to firmware calls in dom0. E.g PV-Clock, PV-Power, PV-FPGA.
4. Others??

A benefit with #1 is that we could support unmodified bare-metal guests. Such guests would continue to issue SMC calls from EL1 just as if they were running without a hypervisor.

Best regards,
Edgar

Edgar E. Iglesias (6):
xen/arm: traps: Reorder early overwrite of FID xen/arm: Introduce platform_hvc
xen/arm: Allow platform_hvc to handle guest SMC calls xen/arm: Introduce call_smcc64
xen/arm: zynqmp: Forward plaform specific firmware calls xen/arm: zynqmp: Remove blacklist of ZynqMP's PM node

 xen/arch/arm/platform.c                |  8 ++++
 xen/arch/arm/platforms/xilinx-zynqmp.c | 67 +++++++++++++++++++++++++++++++---
 xen/arch/arm/traps.c                   | 13 ++++++-
 xen/include/asm-arm/platform.h         |  5 +++
 xen/include/asm-arm/processor.h        | 40 ++++++++++++++++++++
 5 files changed, 125 insertions(+), 8 deletions(-)
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

RFC 1/6 xen/arm: traps: Reorder early overwrite of FID

From: "Edgar E. Iglesias" <[email protected]>

Move the early setting of PSCI_RESULT_REG to a later stage avoiding the early override of the FID that's stored in the same register.

No functional change.

---
 xen/arch/arm/traps.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/arm/traps.c +5 -2
index 35d8e8b..a5fbf1e 100644
@@ -1334,8 +1334,6 @@ static void do_trap_psci(struct cpu_user_regs *regs)
 {
     register_t fid = PSCI_ARG(regs,0);
 
-    /* preloading in case psci_mode_check fails */
-    PSCI_RESULT_REG(regs) = PSCI_INVALID_PARAMETERS;
     switch( fid )
     {
     case PSCI_cpu_off:
@@ -1368,6 +1366,7 @@ static void do_trap_psci(struct cpu_user_regs *regs)
     case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
     case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU:
         perfc_incr(vpsci_migrate_info_up_cpu);
+        PSCI_RESULT_REG(regs) = PSCI_INVALID_PARAMETERS;
         if ( psci_mode_check(current->domain, fid) )
             PSCI_RESULT_REG(regs) = do_psci_0_2_migrate_info_up_cpu();
         break;
@@ -1384,6 +1383,7 @@ static void do_trap_psci(struct cpu_user_regs *regs)
     case PSCI_0_2_FN_CPU_ON:
     case PSCI_0_2_FN64_CPU_ON:
         perfc_incr(vpsci_cpu_on);
+        PSCI_RESULT_REG(regs) = PSCI_INVALID_PARAMETERS;
         if ( psci_mode_check(current->domain, fid) )
         {
             register_t vcpuid = PSCI_ARG(regs,1);
@@ -1396,6 +1396,7 @@ static void do_trap_psci(struct cpu_user_regs *regs)
     case PSCI_0_2_FN_CPU_SUSPEND:
     case PSCI_0_2_FN64_CPU_SUSPEND:
         perfc_incr(vpsci_cpu_suspend);
+        PSCI_RESULT_REG(regs) = PSCI_INVALID_PARAMETERS;
         if ( psci_mode_check(current->domain, fid) )
         {
             uint32_t pstate = PSCI_ARG32(regs,1);
@@ -1408,6 +1409,7 @@ static void do_trap_psci(struct cpu_user_regs *regs)
     case PSCI_0_2_FN_AFFINITY_INFO:
     case PSCI_0_2_FN64_AFFINITY_INFO:
         perfc_incr(vpsci_cpu_affinity_info);
+        PSCI_RESULT_REG(regs) = PSCI_INVALID_PARAMETERS;
         if ( psci_mode_check(current->domain, fid) )
         {
             register_t taff = PSCI_ARG(regs,1);
@@ -1419,6 +1421,7 @@ static void do_trap_psci(struct cpu_user_regs *regs)
     case PSCI_0_2_FN_MIGRATE:
     case PSCI_0_2_FN64_MIGRATE:
         perfc_incr(vpsci_cpu_migrate);
+        PSCI_RESULT_REG(regs) = PSCI_INVALID_PARAMETERS;
         if ( psci_mode_check(current->domain, fid) )
         {
             uint32_t tcpu = PSCI_ARG32(regs,1);
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

RFC 2/6 xen/arm: Introduce platform_hvc

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Introduce platform_hvc as a way to handle hypercalls that Xen does not know about in a platform specific way. This is particularly useful for implementing the SiP (SoC implementation specific) service calls.

---
 xen/arch/arm/platform.c        | 8 ++++++++
 xen/arch/arm/traps.c           | 3 +++
 xen/include/asm-arm/platform.h | 5 +++++
 3 files changed, 16 insertions(+)
xen/arch/arm/platform.c +8 -0
index 0af6d57..90ea6b8 100644
@@ -127,6 +127,14 @@ void platform_poweroff(void)
         platform->poweroff();
 }
 
+bool platform_hvc(struct cpu_user_regs *regs)
+{
+    if ( platform && platform->hvc )
+        return platform->hvc(regs);
+
+    return false;
+}
+
 bool_t platform_has_quirk(uint32_t quirk)
 {
     uint32_t quirks = 0;
xen/arch/arm/traps.c +3 -0
index a5fbf1e..e8cd111 100644
@@ -43,6 +43,7 @@
 #include <asm/cpufeature.h>
 #include <asm/flushtlb.h>
 #include <asm/monitor.h>
+#include <asm/platform.h>
 
 #include "decode.h"
 #include "vtimer.h"
@@ -1429,6 +1430,8 @@ static void do_trap_psci(struct cpu_user_regs *regs)
         }
         break;
     default:
+        if ( platform_hvc(regs) )
+                return;
         domain_crash_synchronous();
         return;
     }
xen/include/asm-arm/platform.h +5 -0
index 08010ba..4d51f0a 100644
@@ -26,6 +26,10 @@ struct platform_desc {
     void (*reset)(void);
     /* Platform power-off */
     void (*poweroff)(void);
+    /* Platform specific HVC handler.
+     * Returns true if the call was handled and false if not.
+     */
+    bool (*hvc)(struct cpu_user_regs *regs);
     /*
      * Platform quirks
      * Defined has a function because a platform can support multiple
@@ -55,6 +59,7 @@ int platform_cpu_up(int cpu);
 #endif
 void platform_reset(void);
 void platform_poweroff(void);
+bool platform_hvc(struct cpu_user_regs *regs);
 bool_t platform_has_quirk(uint32_t quirk);
 bool_t platform_device_is_blacklisted(const struct dt_device_node *node);
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

RFC 3/6 xen/arm: Allow platform_hvc to handle guest SMC calls

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Allow platform_hvc to handle guest SMC calls (as well as HVC calls) in a platform specific way.

---
 xen/arch/arm/traps.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/arm/traps.c +3 -0
index e8cd111..1925122 100644
@@ -2622,6 +2622,9 @@ static void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr)
     if ( current->domain->arch.monitor.privileged_call_enabled )
         rc = monitor_smc();
 
+    if ( platform_hvc(regs) )
+        rc = 1;
+
     if ( rc != 1 )
         inject_undef_exception(regs, hsr);
 }
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

RFC 4/6 xen/arm: Introduce call_smcc64

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Introduce call_smcc64, a helper function to issue 64-bit SMC calls that follow the SMC Calling Convention. This includes returning up to 4 64-bit values.

---
 xen/include/asm-arm/processor.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
xen/include/asm-arm/processor.h +40 -0
index afc0e9a..a604f8c 100644
@@ -706,6 +706,46 @@ void vcpu_regs_user_to_hyp(struct vcpu *vcpu,
 int call_smc(register_t function_id, register_t arg0, register_t arg1,
              register_t arg2);
 
+/*
+ * Helper to issue a 64-bit SMC according to the SMC Calling Convention.
+ *
+ * @fid:      Function Identifier
+ * @a0 - a5:  6 arguments
+ * @ret:      Pointer to 4 register_t carrying return values
+ */
+static inline register_t call_smcc64(register_t fid,
+                                     register_t a0,
+                                     register_t a1,
+                                     register_t a2,
+                                     register_t a3,
+                                     register_t a4,
+                                     register_t a5,
+                                     register_t *ret)
+{
+    register register_t x0 asm("x0") = fid;
+    register register_t x1 asm("x1") = a0;
+    register register_t x2 asm("x2") = a1;
+    register register_t x3 asm("x3") = a2;
+    register register_t x4 asm("x4") = a3;
+    register register_t x5 asm("x5") = a4;
+    register register_t x6 asm("x6") = a5;
+
+    asm volatile ("smc #0\n"
+                  : "+r" (x0), "+r" (x1), "+r" (x2), "+r" (x3),
+                    "+r" (x4), "+r" (x5), "+r" (x6)
+                  :
+                  : "x7", "x8", "x9", "x10", "x11", "x12",
+                    "x13", "x14", "x15", "x16", "x17" );
+
+    if (ret) {
+        ret[0] = x0;
+        ret[1] = x1;
+        ret[2] = x2;
+        ret[3] = x3;
+    }
+    return x0;
+}
+
 void do_trap_guest_error(struct cpu_user_regs *regs);
 
 #endif /* __ASSEMBLY__ */
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

RFC 5/6 xen/arm: zynqmp: Forward plaform specific firmware calls

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Forward platform specific firmware calls from the hardware domain to firmware.

---
 xen/arch/arm/platforms/xilinx-zynqmp.c | 63 ++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
xen/arch/arm/platforms/xilinx-zynqmp.c +63 -0
index 2adee91..bde7f52 100644
@@ -19,6 +19,46 @@
 
 #include <asm/platform.h>
 
+/* Service calls.  */
+#define SVC_MASK             0x3F000000
+#define SVC_SIP              0x02000000    /* SoC Implementation Specific.  */
+
+/* SMC function IDs for SiP Service queries */
+#define ZYNQMP_SIP_SVC_CALL_COUNT       0xff00
+#define ZYNQMP_SIP_SVC_UID              0xff01
+#define ZYNQMP_SIP_SVC_VERSION          0xff03
+
+enum pm_api_id {
+    /* Miscellaneous API functions: */
+    GET_API_VERSION = 1,
+    SET_CONFIGURATION,
+    GET_NODE_STATUS,
+    GET_OPERATING_CHARACTERISTIC,
+    REGISTER_NOTIFIER,
+    /* API for suspending of PUs: */
+    REQUEST_SUSPEND,
+    SELF_SUSPEND,
+    FORCE_POWERDOWN,
+    ABORT_SUSPEND,
+    REQUEST_WAKEUP,
+    SET_WAKEUP_SOURCE,
+    SYSTEM_SHUTDOWN,
+    /* API for managing PM slaves: */
+    REQUEST_NODE,
+    RELEASE_NODE,
+    SET_REQUIREMENT,
+    SET_MAX_LATENCY,
+    /* Direct control API functions: */
+    RESET_ASSERT,
+    RESET_GET_STATUS,
+    MMIO_WRITE,
+    MMIO_READ,
+    PM_INIT,
+    FPGA_LOAD,
+    FPGA_GET_STATUS,
+    GET_CHIPID,
+};
+
 static const char * const zynqmp_dt_compat[] __initconst =
 {
     "xlnx,zynqmp",
@@ -32,8 +72,31 @@ static const struct dt_device_match zynqmp_blacklist_dev[] __initconst =
     { /* sentinel */ },
 };
 
+bool zynqmp_hvc(struct cpu_user_regs *regs)
+{
+    uint32_t fid = regs->x0;
+    uint32_t svc = fid & SVC_MASK;
+    register_t ret[4];
+
+    /* We only forward SiP service calls from the hw domain to firmware.  */
+    if ( svc != SVC_SIP || !is_hardware_domain(current->domain) )
+        return false;
+
+    /* Forward the call.  */
+    call_smcc64(regs->x0, regs->x1, regs->x2, regs->x3,
+                regs->x4, regs->x5, regs->x6, ret);
+
+    /* Transfer return values into guest registers.  */
+    regs->x0 = ret[0];
+    regs->x1 = ret[1];
+    regs->x2 = ret[2];
+    regs->x3 = ret[3];
+    return true;
+}
+
 PLATFORM_START(xgene_storm, "Xilinx ZynqMP")
     .compatible = zynqmp_dt_compat,
+    .hvc = zynqmp_hvc,
     .blacklist_dev = zynqmp_blacklist_dev,
 PLATFORM_END
 
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

Re: [RFC v1 5/6] xen/arm: zynqmp: Forward plaform specific firmware calls

Quoted 21 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Forward platform specific firmware calls from the hardware domain to firmware.

---
 xen/arch/arm/platforms/xilinx-zynqmp.c | 63 ++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
xen/arch/arm/platforms/xilinx-zynqmp.c +3 -0
index 2adee91..bde7f52 100644
@@ -19,6 +19,46 @@
 
 #include <asm/platform.h>
 
+/* Service calls.  */
+#define SVC_MASK             0x3F000000
+#define SVC_SIP              0x02000000    /* SoC Implementation Specific.  */

xen/arch/arm/platforms/xilinx-zynqmp.c line 34

Quoted 10 lines
xen/arch/arm/platforms/xilinx-zynqmp.c +10 -0
+
+/* SMC function IDs for SiP Service queries */
+#define ZYNQMP_SIP_SVC_CALL_COUNT       0xff00
+#define ZYNQMP_SIP_SVC_UID              0xff01
+#define ZYNQMP_SIP_SVC_VERSION          0xff03
+
+enum pm_api_id {
+    /* Miscellaneous API functions: */
+    GET_API_VERSION = 1,
+    SET_CONFIGURATION,

These pm_api_id enums are a left over and not needed, I'll remove them from future versions of this patch.

Cheers,
Edgar

Quoted 65 lines
xen/arch/arm/platforms/xilinx-zynqmp.c +50 -0
+    GET_NODE_STATUS,
+    GET_OPERATING_CHARACTERISTIC,
+    REGISTER_NOTIFIER,
+    /* API for suspending of PUs: */
+    REQUEST_SUSPEND,
+    SELF_SUSPEND,
+    FORCE_POWERDOWN,
+    ABORT_SUSPEND,
+    REQUEST_WAKEUP,
+    SET_WAKEUP_SOURCE,
+    SYSTEM_SHUTDOWN,
+    /* API for managing PM slaves: */
+    REQUEST_NODE,
+    RELEASE_NODE,
+    SET_REQUIREMENT,
+    SET_MAX_LATENCY,
+    /* Direct control API functions: */
+    RESET_ASSERT,
+    RESET_GET_STATUS,
+    MMIO_WRITE,
+    MMIO_READ,
+    PM_INIT,
+    FPGA_LOAD,
+    FPGA_GET_STATUS,
+    GET_CHIPID,
+};
+
 static const char * const zynqmp_dt_compat[] __initconst =
 {
     "xlnx,zynqmp",
@@ -32,8 +72,31 @@ static const struct dt_device_match zynqmp_blacklist_dev[] __initconst =
     { /* sentinel */ },
 };
 
+bool zynqmp_hvc(struct cpu_user_regs *regs)
+{
+    uint32_t fid = regs->x0;
+    uint32_t svc = fid & SVC_MASK;
+    register_t ret[4];
+
+    /* We only forward SiP service calls from the hw domain to firmware.  */
+    if ( svc != SVC_SIP || !is_hardware_domain(current->domain) )
+        return false;
+
+    /* Forward the call.  */
+    call_smcc64(regs->x0, regs->x1, regs->x2, regs->x3,
+                regs->x4, regs->x5, regs->x6, ret);
+
+    /* Transfer return values into guest registers.  */
+    regs->x0 = ret[0];
+    regs->x1 = ret[1];
+    regs->x2 = ret[2];
+    regs->x3 = ret[3];
+    return true;
+}
+
 PLATFORM_START(xgene_storm, "Xilinx ZynqMP")
     .compatible = zynqmp_dt_compat,
+    .hvc = zynqmp_hvc,
     .blacklist_dev = zynqmp_blacklist_dev,
 PLATFORM_END
 
Signature · 1 line
2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

RFC 6/6 xen/arm: zynqmp: Remove blacklist of ZynqMP's PM node

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Stop blacklisting ZynqMP's power management node. This is now possible since we allow the hardware domain to issue HVC/SMC calls to firmware.

---
 xen/arch/arm/platforms/xilinx-zynqmp.c | 8 --------
 1 file changed, 8 deletions(-)
xen/arch/arm/platforms/xilinx-zynqmp.c +0 -8
index bde7f52..d21bd87 100644
@@ -65,13 +65,6 @@ static const char * const zynqmp_dt_compat[] __initconst =
     NULL
 };
 
-static const struct dt_device_match zynqmp_blacklist_dev[] __initconst =
-{
-    /* Power management is not yet supported.  */
-    DT_MATCH_COMPATIBLE("xlnx,zynqmp-pm"),
-    { /* sentinel */ },
-};
-
 bool zynqmp_hvc(struct cpu_user_regs *regs)
 {
     uint32_t fid = regs->x0;
@@ -97,7 +90,6 @@ bool zynqmp_hvc(struct cpu_user_regs *regs)
 PLATFORM_START(xgene_storm, "Xilinx ZynqMP")
     .compatible = zynqmp_dt_compat,
     .hvc = zynqmp_hvc,
-    .blacklist_dev = zynqmp_blacklist_dev,
 PLATFORM_END
 
 /*
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel