soc.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * IBM/AMCC PPC4xx SoC setup code
  4. *
  5. * Copyright 2008 DENX Software Engineering, Stefan Roese <[email protected]>
  6. *
  7. * L2 cache routines cloned from arch/ppc/syslib/ibm440gx_common.c which is:
  8. * Eugene Surovegin <[email protected]> or <[email protected]>
  9. * Copyright (c) 2003 - 2006 Zultys Technologies
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/irq.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/of_platform.h>
  19. #include <asm/dcr.h>
  20. #include <asm/dcr-regs.h>
  21. #include <asm/reg.h>
  22. static u32 dcrbase_l2c;
  23. /*
  24. * L2-cache
  25. */
  26. /* Issue L2C diagnostic command */
  27. static inline u32 l2c_diag(u32 addr)
  28. {
  29. mtdcr(dcrbase_l2c + DCRN_L2C0_ADDR, addr);
  30. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_DIAG);
  31. while (!(mfdcr(dcrbase_l2c + DCRN_L2C0_SR) & L2C_SR_CC))
  32. ;
  33. return mfdcr(dcrbase_l2c + DCRN_L2C0_DATA);
  34. }
  35. static irqreturn_t l2c_error_handler(int irq, void *dev)
  36. {
  37. u32 sr = mfdcr(dcrbase_l2c + DCRN_L2C0_SR);
  38. if (sr & L2C_SR_CPE) {
  39. /* Read cache trapped address */
  40. u32 addr = l2c_diag(0x42000000);
  41. printk(KERN_EMERG "L2C: Cache Parity Error, addr[16:26] = 0x%08x\n",
  42. addr);
  43. }
  44. if (sr & L2C_SR_TPE) {
  45. /* Read tag trapped address */
  46. u32 addr = l2c_diag(0x82000000) >> 16;
  47. printk(KERN_EMERG "L2C: Tag Parity Error, addr[16:26] = 0x%08x\n",
  48. addr);
  49. }
  50. /* Clear parity errors */
  51. if (sr & (L2C_SR_CPE | L2C_SR_TPE)){
  52. mtdcr(dcrbase_l2c + DCRN_L2C0_ADDR, 0);
  53. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_CCP | L2C_CMD_CTE);
  54. } else {
  55. printk(KERN_EMERG "L2C: LRU error\n");
  56. }
  57. return IRQ_HANDLED;
  58. }
  59. static int __init ppc4xx_l2c_probe(void)
  60. {
  61. struct device_node *np;
  62. u32 r;
  63. unsigned long flags;
  64. int irq;
  65. const u32 *dcrreg;
  66. u32 dcrbase_isram;
  67. int len;
  68. const u32 *prop;
  69. u32 l2_size;
  70. np = of_find_compatible_node(NULL, NULL, "ibm,l2-cache");
  71. if (!np)
  72. return 0;
  73. /* Get l2 cache size */
  74. prop = of_get_property(np, "cache-size", NULL);
  75. if (prop == NULL) {
  76. printk(KERN_ERR "%pOF: Can't get cache-size!\n", np);
  77. of_node_put(np);
  78. return -ENODEV;
  79. }
  80. l2_size = prop[0];
  81. /* Map DCRs */
  82. dcrreg = of_get_property(np, "dcr-reg", &len);
  83. if (!dcrreg || (len != 4 * sizeof(u32))) {
  84. printk(KERN_ERR "%pOF: Can't get DCR register base !", np);
  85. of_node_put(np);
  86. return -ENODEV;
  87. }
  88. dcrbase_isram = dcrreg[0];
  89. dcrbase_l2c = dcrreg[2];
  90. /* Get and map irq number from device tree */
  91. irq = irq_of_parse_and_map(np, 0);
  92. if (!irq) {
  93. printk(KERN_ERR "irq_of_parse_and_map failed\n");
  94. of_node_put(np);
  95. return -ENODEV;
  96. }
  97. /* Install error handler */
  98. if (request_irq(irq, l2c_error_handler, 0, "L2C", 0) < 0) {
  99. printk(KERN_ERR "Cannot install L2C error handler"
  100. ", cache is not enabled\n");
  101. of_node_put(np);
  102. return -ENODEV;
  103. }
  104. local_irq_save(flags);
  105. asm volatile ("sync" ::: "memory");
  106. /* Disable SRAM */
  107. mtdcr(dcrbase_isram + DCRN_SRAM0_DPC,
  108. mfdcr(dcrbase_isram + DCRN_SRAM0_DPC) & ~SRAM_DPC_ENABLE);
  109. mtdcr(dcrbase_isram + DCRN_SRAM0_SB0CR,
  110. mfdcr(dcrbase_isram + DCRN_SRAM0_SB0CR) & ~SRAM_SBCR_BU_MASK);
  111. mtdcr(dcrbase_isram + DCRN_SRAM0_SB1CR,
  112. mfdcr(dcrbase_isram + DCRN_SRAM0_SB1CR) & ~SRAM_SBCR_BU_MASK);
  113. mtdcr(dcrbase_isram + DCRN_SRAM0_SB2CR,
  114. mfdcr(dcrbase_isram + DCRN_SRAM0_SB2CR) & ~SRAM_SBCR_BU_MASK);
  115. mtdcr(dcrbase_isram + DCRN_SRAM0_SB3CR,
  116. mfdcr(dcrbase_isram + DCRN_SRAM0_SB3CR) & ~SRAM_SBCR_BU_MASK);
  117. /* Enable L2_MODE without ICU/DCU */
  118. r = mfdcr(dcrbase_l2c + DCRN_L2C0_CFG) &
  119. ~(L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_SS_MASK);
  120. r |= L2C_CFG_L2M | L2C_CFG_SS_256;
  121. mtdcr(dcrbase_l2c + DCRN_L2C0_CFG, r);
  122. mtdcr(dcrbase_l2c + DCRN_L2C0_ADDR, 0);
  123. /* Hardware Clear Command */
  124. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_HCC);
  125. while (!(mfdcr(dcrbase_l2c + DCRN_L2C0_SR) & L2C_SR_CC))
  126. ;
  127. /* Clear Cache Parity and Tag Errors */
  128. mtdcr(dcrbase_l2c + DCRN_L2C0_CMD, L2C_CMD_CCP | L2C_CMD_CTE);
  129. /* Enable 64G snoop region starting at 0 */
  130. r = mfdcr(dcrbase_l2c + DCRN_L2C0_SNP0) &
  131. ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  132. r |= L2C_SNP_SSR_32G | L2C_SNP_ESR;
  133. mtdcr(dcrbase_l2c + DCRN_L2C0_SNP0, r);
  134. r = mfdcr(dcrbase_l2c + DCRN_L2C0_SNP1) &
  135. ~(L2C_SNP_BA_MASK | L2C_SNP_SSR_MASK);
  136. r |= 0x80000000 | L2C_SNP_SSR_32G | L2C_SNP_ESR;
  137. mtdcr(dcrbase_l2c + DCRN_L2C0_SNP1, r);
  138. asm volatile ("sync" ::: "memory");
  139. /* Enable ICU/DCU ports */
  140. r = mfdcr(dcrbase_l2c + DCRN_L2C0_CFG);
  141. r &= ~(L2C_CFG_DCW_MASK | L2C_CFG_PMUX_MASK | L2C_CFG_PMIM
  142. | L2C_CFG_TPEI | L2C_CFG_CPEI | L2C_CFG_NAM | L2C_CFG_NBRM);
  143. r |= L2C_CFG_ICU | L2C_CFG_DCU | L2C_CFG_TPC | L2C_CFG_CPC | L2C_CFG_FRAN
  144. | L2C_CFG_CPIM | L2C_CFG_TPIM | L2C_CFG_LIM | L2C_CFG_SMCM;
  145. /* Check for 460EX/GT special handling */
  146. if (of_device_is_compatible(np, "ibm,l2-cache-460ex") ||
  147. of_device_is_compatible(np, "ibm,l2-cache-460gt"))
  148. r |= L2C_CFG_RDBW;
  149. mtdcr(dcrbase_l2c + DCRN_L2C0_CFG, r);
  150. asm volatile ("sync; isync" ::: "memory");
  151. local_irq_restore(flags);
  152. printk(KERN_INFO "%dk L2-cache enabled\n", l2_size >> 10);
  153. of_node_put(np);
  154. return 0;
  155. }
  156. arch_initcall(ppc4xx_l2c_probe);
  157. /*
  158. * Apply a system reset. Alternatively a board specific value may be
  159. * provided via the "reset-type" property in the cpu node.
  160. */
  161. void ppc4xx_reset_system(char *cmd)
  162. {
  163. struct device_node *np;
  164. u32 reset_type = DBCR0_RST_SYSTEM;
  165. const u32 *prop;
  166. np = of_get_cpu_node(0, NULL);
  167. if (np) {
  168. prop = of_get_property(np, "reset-type", NULL);
  169. /*
  170. * Check if property exists and if it is in range:
  171. * 1 - PPC4xx core reset
  172. * 2 - PPC4xx chip reset
  173. * 3 - PPC4xx system reset (default)
  174. */
  175. if ((prop) && ((prop[0] >= 1) && (prop[0] <= 3)))
  176. reset_type = prop[0] << 28;
  177. }
  178. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | reset_type);
  179. while (1)
  180. ; /* Just in case the reset doesn't work */
  181. }