ppc4xx_soc.c 5.4 KB

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