mips-cpc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2013 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/errno.h>
  11. #include <linux/percpu.h>
  12. #include <linux/spinlock.h>
  13. #include <asm/mips-cps.h>
  14. void __iomem *mips_cpc_base;
  15. static DEFINE_PER_CPU_ALIGNED(spinlock_t, cpc_core_lock);
  16. static DEFINE_PER_CPU_ALIGNED(unsigned long, cpc_core_lock_flags);
  17. phys_addr_t __weak mips_cpc_default_phys_base(void)
  18. {
  19. return 0;
  20. }
  21. /**
  22. * mips_cpc_phys_base - retrieve the physical base address of the CPC
  23. *
  24. * This function returns the physical base address of the Cluster Power
  25. * Controller memory mapped registers, or 0 if no Cluster Power Controller
  26. * is present.
  27. */
  28. static phys_addr_t mips_cpc_phys_base(void)
  29. {
  30. unsigned long cpc_base;
  31. if (!mips_cm_present())
  32. return 0;
  33. if (!(read_gcr_cpc_status() & CM_GCR_CPC_STATUS_EX))
  34. return 0;
  35. /* If the CPC is already enabled, leave it so */
  36. cpc_base = read_gcr_cpc_base();
  37. if (cpc_base & CM_GCR_CPC_BASE_CPCEN)
  38. return cpc_base & CM_GCR_CPC_BASE_CPCBASE;
  39. /* Otherwise, use the default address */
  40. cpc_base = mips_cpc_default_phys_base();
  41. if (!cpc_base)
  42. return cpc_base;
  43. /* Enable the CPC, mapped at the default address */
  44. write_gcr_cpc_base(cpc_base | CM_GCR_CPC_BASE_CPCEN);
  45. return cpc_base;
  46. }
  47. int mips_cpc_probe(void)
  48. {
  49. phys_addr_t addr;
  50. unsigned int cpu;
  51. for_each_possible_cpu(cpu)
  52. spin_lock_init(&per_cpu(cpc_core_lock, cpu));
  53. addr = mips_cpc_phys_base();
  54. if (!addr)
  55. return -ENODEV;
  56. mips_cpc_base = ioremap_nocache(addr, 0x8000);
  57. if (!mips_cpc_base)
  58. return -ENXIO;
  59. return 0;
  60. }
  61. void mips_cpc_lock_other(unsigned int core)
  62. {
  63. unsigned int curr_core;
  64. if (mips_cm_revision() >= CM_REV_CM3)
  65. /* Systems with CM >= 3 lock the CPC via mips_cm_lock_other */
  66. return;
  67. preempt_disable();
  68. curr_core = cpu_core(&current_cpu_data);
  69. spin_lock_irqsave(&per_cpu(cpc_core_lock, curr_core),
  70. per_cpu(cpc_core_lock_flags, curr_core));
  71. write_cpc_cl_other(core << __ffs(CPC_Cx_OTHER_CORENUM));
  72. /*
  73. * Ensure the core-other region reflects the appropriate core &
  74. * VP before any accesses to it occur.
  75. */
  76. mb();
  77. }
  78. void mips_cpc_unlock_other(void)
  79. {
  80. unsigned int curr_core;
  81. if (mips_cm_revision() >= CM_REV_CM3)
  82. /* Systems with CM >= 3 lock the CPC via mips_cm_lock_other */
  83. return;
  84. curr_core = cpu_core(&current_cpu_data);
  85. spin_unlock_irqrestore(&per_cpu(cpc_core_lock, curr_core),
  86. per_cpu(cpc_core_lock_flags, curr_core));
  87. preempt_enable();
  88. }