Skip to contentSkip to conversation

xen/arm : emulation of arm's PSCI v0.2 standard

PATCH Superseded Parth Dixit 2 participants 3 messages Jul 25, 2014 – Jul 30, 2014

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 xen/arm : emulation of arm's PSCI v0.2 standard

Arm based virtual machines dom0/guest will request power related functionality from xen through PSCI interface. This patch implements version 0.2 of PSCI standard specified by arm for 64bit and 32 bit arm machines.

- removed arm_psci_fn_t
- implemented psci_cpu_on with additional error conditions
- added switch-case in do_trap_psci function
- added PSCI v0.2 macros in psci.h
- removed tables for PSCI v0.1 and v0.2
- implemented affinity_info
- moved do_common_cpu up in vpsci.c removed declaration
- removed PSCI_ARGS macro
- added new macro for 32 bit arguments
- added new function psci_mode_check
- modified cpu_suspend to return context_id
- added macros for checking powe_state

---
Changelog v6
- fixed indentation
- removed casting from error codes
- modified cpu_suspend to check power_state
- ignoring context_id in case of standby
- added comments for ignoring affinity
- added macro for checking power_state

Changelog v5
- removed PSCI_ARGS macro
- preload error value for calls that do not return
- added new macro for 32 bit arguments
- casting return calls to appropriate types
- added new function psci_mode_check
- added error checks for PSCI v0.2 function id's

Changelog v4
- added target_affinity_mask[] to local variable
- removed AFF3 masking for 64 bit cpu
- added do_common_cpu_on for PSCI v0.1 and v0.2
- moved cpu_on decision based on entry point
- removed vpsci_ver introduced in v3
- removed psci tables
- added new macro for selecting arguments
- do_trap_psci is now switch case based instead of tables

Changelog v3
- moved wfi helper to seperate patch
- replaced new wfi function in traps.c
- removed defining power_state variable using value directly
- added new line between declaration
- merged PSCI v0.1 and v0.2 cpu_on function to avoid duplication
- removed spurious change
- renamed PSCI return values to reflect v0.2 moved them to top
- removed PSCI v0.1 version declaration for now, will introduce it when needed
- removed hard tabs in the code lifted from linux
- removed PSCI_0_1_MAX
- did not retained copyright header from linux as most of functions are removed
- added two function tables for PSCI v0.1 and PSCI v0.2
- added compatibility string to libxl_arm to expose new functionality
- refactored affinity_info code
- added table for masking function
- removed definitions of unused PSCI v0.2 functions
- removed function id's of unused PSCI v0.2 functions
- renamed constant PSCI_0_2_TOS_MP ( multicore aware) as per spec

 tools/libxl/libxl_arm.c         |   2 +-
 xen/arch/arm/domain_build.c     |   5 +-
 xen/arch/arm/traps.c            | 127 +++++++++++++++++++++++++++----------
 xen/arch/arm/vpsci.c            | 137 ++++++++++++++++++++++++++++++++++++++--
 xen/include/asm-arm/processor.h |   3 +
 xen/include/asm-arm/psci.h      |  83 +++++++++++++++++++++---
 6 files changed, 309 insertions(+), 48 deletions(-)
tools/libxl/libxl_arm.c +1 -1
index 4f0f0e2..e8bcd05 100644
@@ -237,7 +237,7 @@ static int make_psci_node(libxl__gc *gc, void *fdt)
     res = fdt_begin_node(fdt, "psci");
     if (res) return res;
 
-    res = fdt_property_compat(gc, fdt, 1, "arm,psci");
+    res = fdt_property_compat(gc, fdt, 2, "arm,psci-0.2","arm,psci");
     if (res) return res;
 
     res = fdt_property_string(fdt, "method", "hvc");
xen/arch/arm/domain_build.c +4 -1
index c424793..ebd4170 100644
@@ -388,6 +388,9 @@ static int make_hypervisor_node(struct domain *d,
 static int make_psci_node(void *fdt, const struct dt_device_node *parent)
 {
     int res;
+    const char compat[] =
+        "arm,psci-0.2""\0"
+        "arm,psci";
 
     DPRINT("Create PSCI node\n");
 
@@ -396,7 +399,7 @@ static int make_psci_node(void *fdt, const struct dt_device_node *parent)
     if ( res )
         return res;
 
-    res = fdt_property_string(fdt, "compatible", "arm,psci");
+    res = fdt_property(fdt, "compatible", compat, sizeof(compat));
     if ( res )
         return res;
 
xen/arch/arm/traps.c +94 -33

151 lines not on this page · raw message

xen/arch/arm/vpsci.c +132 -5

179 lines not on this page · raw message

xen/include/asm-arm/processor.h +3 -0
index 9267c1b..8a237c4 100644
@@ -16,6 +16,9 @@
 #define MPIDR_AFF0_MASK     (_AC(0xff,U) << MPIDR_AFF0_SHIFT)
 #define MPIDR_HWID_MASK     _AC(0xffffff,U)
 #define MPIDR_INVALID       (~MPIDR_HWID_MASK)
+#define MPIDR_LEVEL_BITS    (8)
+#define AFFINITY_MASK(level)    ~((_AC(0x1,U) << ((level) * MPIDR_LEVEL_BITS)) - 1)
+
 
 /* TTBCR Translation Table Base Control Register */
 #define TTBCR_EAE    _AC(0x80000000,U)
xen/include/asm-arm/psci.h +75 -8

95 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1091

Quoted 4 lines · Parth Dixit
xen/arch/arm/traps.c +4 -0
+    case PSCI_cpu_off:
+        {
+            uint32_t pstate = PSCI_ARG32(regs,1);
+            PSCI_RESULT_REG(regs) = (int32_t) do_psci_cpu_off(pstate);

do_psci_cpu_off returns int32_t, so no need for this cast. The same is true of all of the helpers, I think. Except perhaps MIGRATE_INFO_UP_CPU which differs between 32- and 64-bit.

IOW I think this...

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1113

Quoted 4 lines
xen/arch/arm/traps.c +4 -0
+    case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
+        if ( psci_mode_check(current->domain, fid) )
+            PSCI_RESULT_REG(regs) =
+               (uint32_t) do_psci_0_2_migrate_info_up_cpu();

... is the only cast which might need to remain, and even there I'm not sure.

do_psci_0_2_migrate_info_up_cpu() returns a register_t, which given the currently trivial implementation I think is likely to be sufficient without the cast.

Quoted 5 lines
xen/arch/arm/vpsci.c +5 -0
+register_t do_psci_0_2_cpu_suspend(uint32_t power_state, register_t entry_point,
+                            register_t context_id)
+{
+    struct vcpu *v = current;
+

xen/arch/arm/vpsci.c int do_psci_cpu_off(uint32_t power_state) · line 131

Quoted 10 lines
xen/arch/arm/vpsci.c +10 -0
+    /* affinity values are ignored in this implementation as
+     * at present xen does not supports affinity level greater
+     * than 0, for all  affinity values passed we power down/ standby
+     * the current core */
+
+    vcpu_block_unless_event_pending(v);
+
+    /* if power down is requested context_id must be returned in x0/r0
+     * as the function return will be written in x0/r0 we return context_id
+     * instead os success value */

The spec isn't clear on this, but I don't think this can be correct.

I expect the requirement is that you either return PSCI_SUCCESS to the instruction after the smc or you return to entry_point with x0==context_id. I don't think it makes sense to return after the smc with the x0==context_id. This is implied by section 5.4.2 bullet #4 which talks about handling PSCI return codes.

I'm going to ask ARM for clarification, please stand by.

Ian.

#2 lore raw
Quoted 18 lines · Ian Campbell
Quoted 5 lines
xen/arch/arm/vpsci.c +5 -0
+register_t do_psci_0_2_cpu_suspend(uint32_t power_state, register_t entry_point,
+                            register_t context_id)
+{
+    struct vcpu *v = current;
+

xen/arch/arm/vpsci.c int do_psci_cpu_off(uint32_t power_state) · line 131

Quoted 10 lines
xen/arch/arm/vpsci.c +10 -0
+    /* affinity values are ignored in this implementation as
+     * at present xen does not supports affinity level greater
+     * than 0, for all  affinity values passed we power down/ standby
+     * the current core */
+
+    vcpu_block_unless_event_pending(v);
+
+    /* if power down is requested context_id must be returned in x0/r0
+     * as the function return will be written in x0/r0 we return context_id
+     * instead os success value */

The spec isn't clear on this, but I don't think this can be correct.

Quoted 7 lines

I expect the requirement is that you either return PSCI_SUCCESS to the instruction after the smc or you return to entry_point with x0==context_id. I don't think it makes sense to return after the smc with the x0==context_id. This is implied by section 5.4.2 bullet #4 which talks about handling PSCI return codes.

I'm going to ask ARM for clarification, please stand by.

ARM have confirmed. If you are returning to the instruction after the smc then you should return a PSCI error code in x0, not context_id.

Ian.