smp_scu.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_CONFIG 0x04
  19. #define SCU_CPU_STATUS 0x08
  20. #define SCU_INVALIDATE 0x0c
  21. #define SCU_FPGA_REVISION 0x10
  22. #ifdef CONFIG_SMP
  23. /*
  24. * Get the number of CPU cores from the SCU configuration
  25. */
  26. unsigned int __init scu_get_core_count(void __iomem *scu_base)
  27. {
  28. unsigned int ncores = __raw_readl(scu_base + SCU_CONFIG);
  29. return (ncores & 0x03) + 1;
  30. }
  31. /*
  32. * Enable the SCU
  33. */
  34. void scu_enable(void __iomem *scu_base)
  35. {
  36. u32 scu_ctrl;
  37. #ifdef CONFIG_ARM_ERRATA_764369
  38. /* Cortex-A9 only */
  39. if ((read_cpuid(CPUID_ID) & 0xff0ffff0) == 0x410fc090) {
  40. scu_ctrl = __raw_readl(scu_base + 0x30);
  41. if (!(scu_ctrl & 1))
  42. __raw_writel(scu_ctrl | 0x1, scu_base + 0x30);
  43. }
  44. #endif
  45. scu_ctrl = __raw_readl(scu_base + SCU_CTRL);
  46. /* already enabled? */
  47. if (scu_ctrl & 1)
  48. return;
  49. scu_ctrl |= 1;
  50. __raw_writel(scu_ctrl, scu_base + SCU_CTRL);
  51. /*
  52. * Ensure that the data accessed by CPU0 before the SCU was
  53. * initialised is visible to the other CPUs.
  54. */
  55. flush_cache_all();
  56. }
  57. #endif
  58. /*
  59. * Set the executing CPUs power mode as defined. This will be in
  60. * preparation for it executing a WFI instruction.
  61. *
  62. * This function must be called with preemption disabled, and as it
  63. * has the side effect of disabling coherency, caches must have been
  64. * flushed. Interrupts must also have been disabled.
  65. */
  66. int scu_power_mode(void __iomem *scu_base, unsigned int mode)
  67. {
  68. unsigned int val;
  69. int cpu = cpu_logical_map(smp_processor_id());
  70. if (mode > 3 || mode == 1 || cpu > 3)
  71. return -EINVAL;
  72. val = __raw_readb(scu_base + SCU_CPU_STATUS + cpu) & ~0x03;
  73. val |= mode;
  74. __raw_writeb(val, scu_base + SCU_CPU_STATUS + cpu);
  75. return 0;
  76. }