mips-cpc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-cm.h>
  14. #include <asm/mips-cpc.h>
  15. void __iomem *mips_cpc_base;
  16. static DEFINE_PER_CPU_ALIGNED(spinlock_t, cpc_core_lock);
  17. static DEFINE_PER_CPU_ALIGNED(unsigned long, cpc_core_lock_flags);
  18. phys_addr_t __weak mips_cpc_default_phys_base(void)
  19. {
  20. return 0;
  21. }
  22. /**
  23. * mips_cpc_phys_base - retrieve the physical base address of the CPC
  24. *
  25. * This function returns the physical base address of the Cluster Power
  26. * Controller memory mapped registers, or 0 if no Cluster Power Controller
  27. * is present.
  28. */
  29. static phys_addr_t mips_cpc_phys_base(void)
  30. {
  31. unsigned long cpc_base;
  32. if (!mips_cm_present())
  33. return 0;
  34. if (!(read_gcr_cpc_status() & CM_GCR_CPC_STATUS_EX_MSK))
  35. return 0;
  36. /* If the CPC is already enabled, leave it so */
  37. cpc_base = read_gcr_cpc_base();
  38. if (cpc_base & CM_GCR_CPC_BASE_CPCEN_MSK)
  39. return cpc_base & CM_GCR_CPC_BASE_CPCBASE_MSK;
  40. /* Otherwise, use the default address */
  41. cpc_base = mips_cpc_default_phys_base();
  42. if (!cpc_base)
  43. return cpc_base;
  44. /* Enable the CPC, mapped at the default address */
  45. write_gcr_cpc_base(cpc_base | CM_GCR_CPC_BASE_CPCEN_MSK);
  46. return cpc_base;
  47. }
  48. int mips_cpc_probe(void)
  49. {
  50. phys_addr_t addr;
  51. unsigned int cpu;
  52. for_each_possible_cpu(cpu)
  53. spin_lock_init(&per_cpu(cpc_core_lock, cpu));
  54. addr = mips_cpc_phys_base();
  55. if (!addr)
  56. return -ENODEV;
  57. mips_cpc_base = ioremap_nocache(addr, 0x8000);
  58. if (!mips_cpc_base)
  59. return -ENXIO;
  60. return 0;
  61. }
  62. void mips_cpc_lock_other(unsigned int core)
  63. {
  64. unsigned int curr_core;
  65. if (mips_cm_revision() >= CM_REV_CM3)
  66. /* Systems with CM >= 3 lock the CPC via mips_cm_lock_other */
  67. return;
  68. preempt_disable();
  69. curr_core = current_cpu_data.core;
  70. spin_lock_irqsave(&per_cpu(cpc_core_lock, curr_core),
  71. per_cpu(cpc_core_lock_flags, curr_core));
  72. write_cpc_cl_other(core << CPC_Cx_OTHER_CORENUM_SHF);
  73. /*
  74. * Ensure the core-other region reflects the appropriate core &
  75. * VP before any accesses to it occur.
  76. */
  77. mb();
  78. }
  79. void mips_cpc_unlock_other(void)
  80. {
  81. unsigned int curr_core;
  82. if (mips_cm_revision() >= CM_REV_CM3)
  83. /* Systems with CM >= 3 lock the CPC via mips_cm_lock_other */
  84. return;
  85. curr_core = current_cpu_data.core;
  86. spin_unlock_irqrestore(&per_cpu(cpc_core_lock, curr_core),
  87. per_cpu(cpc_core_lock_flags, curr_core));
  88. preempt_enable();
  89. }