smp_scu.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/arch/arm/kernel/smp_scu.c
  3. *
  4. * Copyright (C) 2002 ARM Ltd.
  5. * All Rights Reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <asm/smp_plat.h>
  14. #include <asm/smp_scu.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/cputype.h>
  17. #define SCU_CTRL 0x00
  18. #define SCU_ENABLE (1 << 0)
  19. #define SCU_STANDBY_ENABLE (1 << 5)
  20. #define SCU_CONFIG 0x04
  21. #define SCU_CPU_STATUS 0x08
  22. #define SCU_CPU_STATUS_MASK GENMASK(1, 0)
  23. #define SCU_INVALIDATE 0x0c
  24. #define SCU_FPGA_REVISION 0x10
  25. #ifdef CONFIG_SMP
  26. /*
  27. * Get the number of CPU cores from the SCU configuration
  28. */
  29. unsigned int __init scu_get_core_count(void __iomem *scu_base)
  30. {
  31. unsigned int ncores = readl_relaxed(scu_base + SCU_CONFIG);
  32. return (ncores & 0x03) + 1;
  33. }
  34. /*
  35. * Enable the SCU
  36. */
  37. void scu_enable(void __iomem *scu_base)
  38. {
  39. u32 scu_ctrl;
  40. #ifdef CONFIG_ARM_ERRATA_764369
  41. /* Cortex-A9 only */
  42. if ((read_cpuid_id() & 0xff0ffff0) == 0x410fc090) {
  43. scu_ctrl = readl_relaxed(scu_base + 0x30);
  44. if (!(scu_ctrl & 1))
  45. writel_relaxed(scu_ctrl | 0x1, scu_base + 0x30);
  46. }
  47. #endif
  48. scu_ctrl = readl_relaxed(scu_base + SCU_CTRL);
  49. /* already enabled? */
  50. if (scu_ctrl & SCU_ENABLE)
  51. return;
  52. scu_ctrl |= SCU_ENABLE;
  53. /* Cortex-A9 earlier than r2p0 has no standby bit in SCU */
  54. if ((read_cpuid_id() & 0xff0ffff0) == 0x410fc090 &&
  55. (read_cpuid_id() & 0x00f0000f) >= 0x00200000)
  56. scu_ctrl |= SCU_STANDBY_ENABLE;
  57. writel_relaxed(scu_ctrl, scu_base + SCU_CTRL);
  58. /*
  59. * Ensure that the data accessed by CPU0 before the SCU was
  60. * initialised is visible to the other CPUs.
  61. */
  62. flush_cache_all();
  63. }
  64. #endif
  65. static int scu_set_power_mode_internal(void __iomem *scu_base,
  66. unsigned int logical_cpu,
  67. unsigned int mode)
  68. {
  69. unsigned int val;
  70. int cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(logical_cpu), 0);
  71. if (mode > 3 || mode == 1 || cpu > 3)
  72. return -EINVAL;
  73. val = readb_relaxed(scu_base + SCU_CPU_STATUS + cpu);
  74. val &= ~SCU_CPU_STATUS_MASK;
  75. val |= mode;
  76. writeb_relaxed(val, scu_base + SCU_CPU_STATUS + cpu);
  77. return 0;
  78. }
  79. /*
  80. * Set the executing CPUs power mode as defined. This will be in
  81. * preparation for it executing a WFI instruction.
  82. *
  83. * This function must be called with preemption disabled, and as it
  84. * has the side effect of disabling coherency, caches must have been
  85. * flushed. Interrupts must also have been disabled.
  86. */
  87. int scu_power_mode(void __iomem *scu_base, unsigned int mode)
  88. {
  89. return scu_set_power_mode_internal(scu_base, smp_processor_id(), mode);
  90. }
  91. /*
  92. * Set the given (logical) CPU's power mode to SCU_PM_NORMAL.
  93. */
  94. int scu_cpu_power_enable(void __iomem *scu_base, unsigned int cpu)
  95. {
  96. return scu_set_power_mode_internal(scu_base, cpu, SCU_PM_NORMAL);
  97. }
  98. int scu_get_cpu_power_mode(void __iomem *scu_base, unsigned int logical_cpu)
  99. {
  100. unsigned int val;
  101. int cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(logical_cpu), 0);
  102. if (cpu > 3)
  103. return -EINVAL;
  104. val = readb_relaxed(scu_base + SCU_CPU_STATUS + cpu);
  105. val &= SCU_CPU_STATUS_MASK;
  106. return val;
  107. }