Skip to contentSkip to conversation

xen/arm: Add support for PSCI v1.0

PATCH Applied Julien Grall 2 participants 8 messages Oct 12, 2015 – Oct 23, 2015

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arm: Add support for PSCI v1.0

Hi all,

This small patch series allow Xen to boot on platform where the firmware is only supporting PSCI v1.0.

Sincerely yours,

Julien Grall (2):
xen/arm: Add support of PSCI v1.0 for the host xen/arm: Replace XEN_PSCI_* by PSCI_VERSION(major, minor)

 xen/arch/arm/psci.c        | 23 ++++++++++++++++-------
 xen/arch/arm/vpsci.c       | 15 ++++++++-------
 xen/include/asm-arm/psci.h | 17 +++++++++++++----
 3 files changed, 37 insertions(+), 18 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/2 xen/arm: Add support of PSCI v1.0 for the host

Quoted 1 line

From Xen point of view, PSCI v0.2 and PSCI v1.0 are very similar. All

the PSCI calls used within Xen (PSCI_VERSION, CPU_ON, SYSTEM_OFF and SYSTEM_RESET) behaves exactly the same.

Furthermore, based on the spec (5.3.1 DEN0022C), any 1.y version must be compatible with 1.x when y > x for any functions existing in 1.x.

So check the presence of the new compatible string [1] and allow Xen to boot on any platform using PSCI 1.x.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/374547.html

---

Cc Andre Przywara <[email protected]>
Cc Mark Rutland <[email protected]>

Changes in v2:
- Update the commit message
- Allow Xen to boot on any PSCI 1.x
- Update the error message

---
 xen/arch/arm/psci.c        | 17 +++++++++++++----
 xen/include/asm-arm/psci.h | 13 +++++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
xen/arch/arm/psci.c +13 -4
index 172c6e7..44ccc2f 100644
@@ -109,10 +109,16 @@ int __init psci_init_0_1(void)
 
 int __init psci_init_0_2(void)
 {
+    static const struct dt_device_match psci_ids[] __initconst =
+    {
+        DT_MATCH_COMPATIBLE("arm,psci-0.2"),
+        DT_MATCH_COMPATIBLE("arm,psci-1.0"),
+        { /* sentinel */ },
+    };
     int ret;
     const struct dt_device_node *psci;
 
-    psci = dt_find_compatible_node(NULL, NULL, "arm,psci-0.2");
+    psci = dt_find_matching_node(NULL, psci_ids);
     if ( !psci )
         return -EOPNOTSUPP;
 
@@ -122,15 +128,18 @@ int __init psci_init_0_2(void)
 
     psci_ver = call_smc(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
 
-    if ( psci_ver != XEN_PSCI_V_0_2 )
+    /* For the moment, we only support PSCI 0.2 and PSCI 1.x */
+    if ( psci_ver != PSCI_VERSION(0, 2) && PSCI_VERSION_MAJOR(psci_ver != 1) )
     {
-        printk("Error: PSCI version %#x is not supported.\n", psci_ver);
+        printk("Error: Unrecognized PSCI version %u.%u\n",
+               PSCI_VERSION_MAJOR(psci_ver), PSCI_VERSION_MINOR(psci_ver));
         return -EOPNOTSUPP;
     }
 
     psci_cpu_on_nr = PSCI_0_2_FN_NATIVE(CPU_ON);
 
-    printk(XENLOG_INFO "Using PSCI-0.2 for SMP bringup\n");
+    printk(XENLOG_INFO "Using PSCI-%u.%u for SMP bringup\n",
+           PSCI_VERSION_MAJOR(psci_ver), PSCI_VERSION_MINOR(psci_ver));
 
     return 0;
 }
xen/include/asm-arm/psci.h +13 -0
index 5d17ee3..d8a109f 100644
@@ -87,6 +87,19 @@ void do_psci_0_2_system_reset(void);
 #define PSCI_0_2_POWER_STATE_TYPE_MASK      \
                     (0x1 << PSCI_0_2_POWER_STATE_TYPE_SHIFT)
 
+/* PSCI version decoding (independent of PSCI version) */
+#define PSCI_VERSION_MAJOR_SHIFT            16
+#define PSCI_VERSION_MINOR_MASK             \
+        ((1U << PSCI_VERSION_MAJOR_SHIFT) - 1)
+#define PSCI_VERSION_MAJOR_MASK             ~PSCI_VERSION_MINOR_MASK
+#define PSCI_VERSION_MAJOR(ver)             \
+        (((ver) & PSCI_VERSION_MAJOR_MASK) >> PSCI_VERSION_MAJOR_SHIFT)
+#define PSCI_VERSION_MINOR(ver)             \
+        ((ver) & PSCI_VERSION_MINOR_MASK)
+
+#define PSCI_VERSION(major, minor)          \
+    (((major) << PSCI_VERSION_MAJOR_SHIFT) | (minor))
+
 #endif /* __ASM_PSCI_H__ */
 
 /*
Signature · 1 line
2.1.4
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] xen/arm: Add support of PSCI v1.0 for the host

On Mon, 2015-10-12 at 16:39 +0100, Julien Grall wrote:

Subject: support PSCI v1.0 for the host.

Quoted 1 line

From Xen point of view, PSCI v0.2 and PSCI v1.0 are very similar. All

Xen's

Quoted 2 lines

the PSCI calls used within Xen (PSCI_VERSION, CPU_ON, SYSTEM_OFF and SYSTEM_RESET) behaves exactly the same.

behave

Quoted 10 lines

Furthermore, based on the spec (5.3.1 DEN0022C), any 1.y version must be compatible with 1.x when y > x for any functions existing in 1.x.

So check the presence of the new compatible string [1] and allow Xen to boot on any platform using PSCI 1.x.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/37
4547.html

#3 lore raw

Re: [PATCH v2 1/2] xen/arm: Add support of PSCI v1.0 for the host

Hi,

Quoted 18 lines · Ian Campbell

On Mon, 2015-10-12 at 16:39 +0100, Julien Grall wrote:

Subject: support PSCI v1.0 for the host.

Quoted 1 line

From Xen point of view, PSCI v0.2 and PSCI v1.0 are very similar. All

Xen's

Quoted 2 lines

the PSCI calls used within Xen (PSCI_VERSION, CPU_ON, SYSTEM_OFF and SYSTEM_RESET) behaves exactly the same.

behave

Quoted 6 lines

Furthermore, based on the spec (5.3.1 DEN0022C), any 1.y version must be compatible with 1.x when y > x for any functions existing in 1.x.

So check the presence of the new compatible string [1] and allow Xen to boot on any platform using PSCI 1.x.

Quoted 6 lines
Quoted 4 lines

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/37
4547.html

Shall I resend a new version with those typos fixed? Or do you plan to do it when you'll commit the patch?

Regards,

Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v2 1/2] xen/arm: Add support of PSCI v1.0 for the host

Quoted 27 lines · Julien Grall

Hi,

Quoted 24 lines · Ian Campbell

On Mon, 2015-10-12 at 16:39 +0100, Julien Grall wrote:

Subject: support PSCI v1.0 for the host.

Quoted 1 line

From Xen point of view, PSCI v0.2 and PSCI v1.0 are very similar. All

Xen's

Quoted 2 lines

the PSCI calls used within Xen (PSCI_VERSION, CPU_ON, SYSTEM_OFF and SYSTEM_RESET) behaves exactly the same.

behave

Quoted 12 lines

Furthermore, based on the spec (5.3.1 DEN0022C), any 1.y version must be
compatible with 1.x when y > x for any functions existing in 1.x.

So check the presence of the new compatible string [1] and allow Xen to
boot on any platform using PSCI 1.x.

[1]
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/37
4547.html

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Shall I resend a new version with those typos fixed? Or do you plan to do it when you'll commit the patch?

Looks like those are the only changes required, so assuming you are are happy with them I'll just do them on commit.

#5 lore raw

Re: [PATCH v2 1/2] xen/arm: Add support of PSCI v1.0 for the host

Quoted 30 lines · Ian Campbell
Quoted 29 lines · Julien Grall

Hi,

Quoted 26 lines · Ian Campbell

On Mon, 2015-10-12 at 16:39 +0100, Julien Grall wrote:

Subject: support PSCI v1.0 for the host.

Quoted 1 line

From Xen point of view, PSCI v0.2 and PSCI v1.0 are very similar. All

Xen's

Quoted 2 lines

the PSCI calls used within Xen (PSCI_VERSION, CPU_ON, SYSTEM_OFF and SYSTEM_RESET) behaves exactly the same.

behave

Quoted 13 lines

Furthermore, based on the spec (5.3.1 DEN0022C), any 1.y version must be
compatible with 1.x when y > x for any functions existing in 1.x.

So check the presence of the new compatible string [1] and allow Xen to
boot on any platform using PSCI 1.x.

[1]
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/37
4547.html

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Shall I resend a new version with those typos fixed? Or do you plan to do it when you'll commit the patch?

Looks like those are the only changes required, so assuming you are are happy with them I'll just do them on commit.

I'm fine with that.

Thank you!

Signature · 1 line
Julien Grall
Applied
#6 lore raw

Re: [PATCH v2 1/2] xen/arm: Add support of PSCI v1.0 for the host

Quoted 38 lines · Julien Grall
Quoted 37 lines · Ian Campbell
Quoted 36 lines · Julien Grall

Hi,

Quoted 32 lines · Ian Campbell

On Mon, 2015-10-12 at 16:39 +0100, Julien Grall wrote:

Subject: support PSCI v1.0 for the host.

Quoted 2 lines

From Xen point of view, PSCI v0.2 and PSCI v1.0 are very similar. All

Xen's

Quoted 3 lines

the PSCI calls used within Xen (PSCI_VERSION, CPU_ON, SYSTEM_OFF and
SYSTEM_RESET) behaves exactly the same.

behave

Quoted 10 lines

Furthermore, based on the spec (5.3.1 DEN0022C), any 1.y version must
be
compatible with 1.x when y > x for any functions existing in 1.x.

So check the presence of the new compatible string [1] and allow Xen
to
boot on any platform using PSCI 1.x.

Quoted 6 lines

[1]
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-Octobe
r/37
4547.html

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Shall I resend a new version with those typos fixed? Or do you plan to
do it when you'll commit the patch?

Looks like those are the only changes required, so assuming you are are happy with them I'll just do them on commit.

I'm fine with that.

Applied, thanks.

#7 lore raw

PATCH v2 2/2 xen/arm: Replace XEN_PSCI_* by PSCI_VERSION(major, minor)

In reply to Julien Grall

It will avoid to introduce a new XEN_PSCI_* define every time we support a new version of PSCI in Xen.

Also fix the coding style in modified place.

---
Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/psci.c        |  6 +++---
 xen/arch/arm/vpsci.c       | 15 ++++++++-------
 xen/include/asm-arm/psci.h |  4 ----
 3 files changed, 11 insertions(+), 14 deletions(-)
xen/arch/arm/psci.c +3 -3
index 44ccc2f..d800cb6 100644
@@ -46,13 +46,13 @@ int call_psci_cpu_on(int cpu)
 
 void call_psci_system_off(void)
 {
-    if ( psci_ver > XEN_PSCI_V_0_1 )
+    if ( psci_ver > PSCI_VERSION(0, 1) )
         call_smc(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
 }
 
 void call_psci_system_reset(void)
 {
-    if ( psci_ver > XEN_PSCI_V_0_1 )
+    if ( psci_ver > PSCI_VERSION(0, 1) )
         call_smc(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
 }
 
@@ -100,7 +100,7 @@ int __init psci_init_0_1(void)
         return -ENOENT;
     }
 
-    psci_ver = XEN_PSCI_V_0_1;
+    psci_ver = PSCI_VERSION(0, 1);
 
     printk(XENLOG_INFO "Using PSCI-0.1 for SMP bringup\n");
 
xen/arch/arm/vpsci.c +8 -7
index aebe1e2..0e024f7 100644
@@ -41,8 +41,8 @@ static int do_common_cpu_on(register_t target_cpu, register_t entry_point,
     if ( is_64bit_domain(d) && is_thumb )
         return PSCI_INVALID_PARAMETERS;
 
-    if( ( ver == XEN_PSCI_V_0_2 ) &&
-            ( !test_bit(_VPF_down, &v->pause_flags) ) )
+    if ( (ver == PSCI_VERSION(0, 2)) &&
+            !test_bit(_VPF_down, &v->pause_flags) )
         return PSCI_ALREADY_ON;
 
     if ( (ctxt = alloc_vcpu_guest_context()) == NULL )
@@ -59,14 +59,14 @@ static int do_common_cpu_on(register_t target_cpu, register_t entry_point,
     if ( is_32bit_domain(d) )
     {
         ctxt->user_regs.cpsr = PSR_GUEST32_INIT;
-        if( ver == XEN_PSCI_V_0_2 )
+        if ( ver == PSCI_VERSION(0, 2) )
             ctxt->user_regs.r0_usr = context_id;
     }
 #ifdef CONFIG_ARM_64
     else
     {
         ctxt->user_regs.cpsr = PSR_GUEST64_INIT;
-        if( ver == XEN_PSCI_V_0_2 )
+        if ( ver == PSCI_VERSION(0, 2) )
             ctxt->user_regs.x0 = context_id;
     }
 #endif
@@ -94,7 +94,7 @@ static int do_common_cpu_on(register_t target_cpu, register_t entry_point,
 
 int32_t do_psci_cpu_on(uint32_t vcpuid, register_t entry_point)
 {
-    return do_common_cpu_on(vcpuid,entry_point,0,XEN_PSCI_V_0_1);
+    return do_common_cpu_on(vcpuid, entry_point, 0 , PSCI_VERSION(0, 1));
 }
 
 int32_t do_psci_cpu_off(uint32_t power_state)
@@ -107,7 +107,7 @@ int32_t do_psci_cpu_off(uint32_t power_state)
 
 uint32_t do_psci_0_2_version(void)
 {
-    return XEN_PSCI_V_0_2;
+    return PSCI_VERSION(0, 2);
 }
 
 register_t do_psci_0_2_cpu_suspend(uint32_t power_state, register_t entry_point,
@@ -132,7 +132,8 @@ int32_t do_psci_0_2_cpu_off(void)
 int32_t do_psci_0_2_cpu_on(register_t target_cpu, register_t entry_point,
                        register_t context_id)
 {
-    return do_common_cpu_on(target_cpu,entry_point,context_id,XEN_PSCI_V_0_2);
+    return do_common_cpu_on(target_cpu, entry_point, context_id,
+                            PSCI_VERSION(0, 2));
 }
 
 static const unsigned long target_affinity_mask[] = {
xen/include/asm-arm/psci.h +0 -4
index d8a109f..be2458a 100644
@@ -41,10 +41,6 @@ register_t do_psci_0_2_migrate_info_up_cpu(void);
 void do_psci_0_2_system_off(void);
 void do_psci_0_2_system_reset(void);
 
-/* PSCI version */
-#define XEN_PSCI_V_0_1 1
-#define XEN_PSCI_V_0_2 2
-
 /* PSCI v0.2 interface */
 #define PSCI_0_2_FN_BASE        0x84000000
 #define PSCI_0_2_FN(n)          (PSCI_0_2_FN_BASE + (n))
Signature · 1 line
2.1.4