mips-cm.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <asm/mips-cm.h>
  12. #include <asm/mipsregs.h>
  13. void __iomem *mips_cm_base;
  14. void __iomem *mips_cm_l2sync_base;
  15. phys_addr_t __mips_cm_phys_base(void)
  16. {
  17. u32 config3 = read_c0_config3();
  18. u32 cmgcr;
  19. /* Check the CMGCRBase register is implemented */
  20. if (!(config3 & MIPS_CONF3_CMGCR))
  21. return 0;
  22. /* Read the address from CMGCRBase */
  23. cmgcr = read_c0_cmgcrbase();
  24. return (cmgcr & MIPS_CMGCRF_BASE) << (36 - 32);
  25. }
  26. phys_addr_t mips_cm_phys_base(void)
  27. __attribute__((weak, alias("__mips_cm_phys_base")));
  28. phys_addr_t __mips_cm_l2sync_phys_base(void)
  29. {
  30. u32 base_reg;
  31. /*
  32. * If the L2-only sync region is already enabled then leave it at it's
  33. * current location.
  34. */
  35. base_reg = read_gcr_l2_only_sync_base();
  36. if (base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN_MSK)
  37. return base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE_MSK;
  38. /* Default to following the CM */
  39. return mips_cm_phys_base() + MIPS_CM_GCR_SIZE;
  40. }
  41. phys_addr_t mips_cm_l2sync_phys_base(void)
  42. __attribute__((weak, alias("__mips_cm_l2sync_phys_base")));
  43. static void mips_cm_probe_l2sync(void)
  44. {
  45. unsigned major_rev;
  46. phys_addr_t addr;
  47. /* L2-only sync was introduced with CM major revision 6 */
  48. major_rev = (read_gcr_rev() & CM_GCR_REV_MAJOR_MSK) >>
  49. CM_GCR_REV_MAJOR_SHF;
  50. if (major_rev < 6)
  51. return;
  52. /* Find a location for the L2 sync region */
  53. addr = mips_cm_l2sync_phys_base();
  54. BUG_ON((addr & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE_MSK) != addr);
  55. if (!addr)
  56. return;
  57. /* Set the region base address & enable it */
  58. write_gcr_l2_only_sync_base(addr | CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN_MSK);
  59. /* Map the region */
  60. mips_cm_l2sync_base = ioremap_nocache(addr, MIPS_CM_L2SYNC_SIZE);
  61. }
  62. int mips_cm_probe(void)
  63. {
  64. phys_addr_t addr;
  65. u32 base_reg;
  66. addr = mips_cm_phys_base();
  67. BUG_ON((addr & CM_GCR_BASE_GCRBASE_MSK) != addr);
  68. if (!addr)
  69. return -ENODEV;
  70. mips_cm_base = ioremap_nocache(addr, MIPS_CM_GCR_SIZE);
  71. if (!mips_cm_base)
  72. return -ENXIO;
  73. /* sanity check that we're looking at a CM */
  74. base_reg = read_gcr_base();
  75. if ((base_reg & CM_GCR_BASE_GCRBASE_MSK) != addr) {
  76. pr_err("GCRs appear to have been moved (expected them at 0x%08lx)!\n",
  77. (unsigned long)addr);
  78. mips_cm_base = NULL;
  79. return -ENODEV;
  80. }
  81. /* set default target to memory */
  82. base_reg &= ~CM_GCR_BASE_CMDEFTGT_MSK;
  83. base_reg |= CM_GCR_BASE_CMDEFTGT_MEM;
  84. write_gcr_base(base_reg);
  85. /* disable CM regions */
  86. write_gcr_reg0_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  87. write_gcr_reg0_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  88. write_gcr_reg1_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  89. write_gcr_reg1_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  90. write_gcr_reg2_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  91. write_gcr_reg2_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  92. write_gcr_reg3_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  93. write_gcr_reg3_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  94. /* probe for an L2-only sync region */
  95. mips_cm_probe_l2sync();
  96. return 0;
  97. }