0026-sunxi-psci-Avoid-hanging-when-CPU-0-is-hot-unplugged.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. From ca1e6f4491981432c3e88441131c8e25067da95e Mon Sep 17 00:00:00 2001
  2. From: Samuel Holland <[email protected]>
  3. Date: Sat, 9 Oct 2021 22:00:22 -0500
  4. Subject: [PATCH 26/90] sunxi: psci: Avoid hanging when CPU 0 is hot-unplugged
  5. Do not try to send an SGI from CPU 0 to itself. Since FIQs are masked
  6. when entering monitor mode, this will hang. Plus, CPU 0 cannot fully
  7. power itself off anyway. Instead, have it turn FIQs back on and continue
  8. servicing SGIs from other cores.
  9. Signed-off-by: Samuel Holland <[email protected]>
  10. ---
  11. arch/arm/cpu/armv7/sunxi/psci.c | 20 +++++++++++++++++---
  12. 1 file changed, 17 insertions(+), 3 deletions(-)
  13. --- a/arch/arm/cpu/armv7/sunxi/psci.c
  14. +++ b/arch/arm/cpu/armv7/sunxi/psci.c
  15. @@ -38,6 +38,15 @@
  16. #define SUN8I_R40_PWR_CLAMP(cpu) (0x120 + (cpu) * 0x4)
  17. #define SUN8I_R40_SRAMC_SOFT_ENTRY_REG0 (0xbc)
  18. +static inline u32 __secure cp15_read_mpidr(void)
  19. +{
  20. + u32 val;
  21. +
  22. + asm volatile ("mrc p15, 0, %0, c0, c0, 5" : "=r" (val));
  23. +
  24. + return val;
  25. +}
  26. +
  27. static void __secure cp15_write_cntp_tval(u32 tval)
  28. {
  29. asm volatile ("mcr p15, 0, %0, c14, c2, 0" : : "r" (tval));
  30. @@ -281,9 +290,14 @@ s32 __secure psci_cpu_off(void)
  31. {
  32. psci_cpu_off_common();
  33. - /* Ask CPU0 via SGI15 to pull the rug... */
  34. - writel(BIT(16) | 15, GICD_BASE + GICD_SGIR);
  35. - dsb();
  36. + if (cp15_read_mpidr() & 3) {
  37. + /* Ask CPU0 via SGI15 to pull the rug... */
  38. + writel(BIT(16) | 15, GICD_BASE + GICD_SGIR);
  39. + dsb();
  40. + } else {
  41. + /* Unmask FIQs to service SGI15. */
  42. + asm volatile ("cpsie f");
  43. + }
  44. /* Wait to be turned off */
  45. while (1)