l2cache.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * (C) Copyright 2002 ELTEC Elektronik AG
  3. * Frank Gottschling <fgottschling@eltec.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #if defined(CFG_L2_BAB7xx)
  25. #include <pci.h>
  26. #include <mpc106.h>
  27. /* defines L2CR register for MPC750 */
  28. #define L2CR_E 0x80000000
  29. #define L2CR_256K 0x10000000
  30. #define L2CR_512K 0x20000000
  31. #define L2CR_1024K 0x30000000
  32. #define L2CR_I 0x00200000
  33. #define L2CR_SL 0x00008000
  34. #define L2CR_IP 0x00000001
  35. /*----------------------------------------------------------------------------*/
  36. static int dummy (int dummy)
  37. {
  38. return (dummy+1);
  39. }
  40. /*----------------------------------------------------------------------------*/
  41. int l2_cache_enable (int l2control)
  42. {
  43. if (l2control) /* BAB750 */
  44. {
  45. mtspr(SPRN_L2CR, l2control);
  46. mtspr(SPRN_L2CR, (l2control | L2CR_I));
  47. while (mfspr(SPRN_L2CR) & L2CR_IP)
  48. ;
  49. mtspr(SPRN_L2CR, (l2control | L2CR_E));
  50. return (0);
  51. }
  52. else /* BAB740 */
  53. {
  54. int picr1, picr2, mask;
  55. int picr2CacheSize, cacheSize;
  56. int *d;
  57. int devbusfn;
  58. u32 reg32;
  59. devbusfn = pci_find_device(PCI_VENDOR_ID_MOTOROLA,
  60. PCI_DEVICE_ID_MOTOROLA_MPC106, 0);
  61. if (devbusfn == -1)
  62. return (-1);
  63. pci_read_config_dword (devbusfn, PCI_PICR2, &reg32);
  64. reg32 &= ~PICR2_L2_EN;
  65. pci_write_config_dword (devbusfn, PCI_PICR2, reg32);
  66. /* cache size */
  67. if (*(volatile unsigned char *) (CFG_ISA_IO + 0x220) & 0x04)
  68. {
  69. /* cache size is 512 KB */
  70. picr2CacheSize = PICR2_L2_SIZE_512K;
  71. cacheSize = 0x80000;
  72. }
  73. else
  74. {
  75. /* cache size is 256 KB */
  76. picr2CacheSize = PICR2_L2_SIZE_256K;
  77. cacheSize = 0x40000;
  78. }
  79. /* setup PICR1 */
  80. mask =
  81. ~(PICR1_CF_BREAD_WS(1) |
  82. PICR1_CF_BREAD_WS(2) |
  83. PICR1_CF_CBA(0xff) |
  84. PICR1_CF_CACHE_1G |
  85. PICR1_CF_DPARK |
  86. PICR1_CF_APARK |
  87. PICR1_CF_L2_CACHE_MASK);
  88. picr1 =
  89. (PICR1_CF_CBA(0x3f) |
  90. PICR1_CF_CACHE_1G |
  91. PICR1_CF_APARK |
  92. PICR1_CF_DPARK |
  93. PICR1_CF_L2_COPY_BACK); /* PICR1_CF_L2_WRITE_THROUGH */
  94. pci_read_config_dword (devbusfn, PCI_PICR1, &reg32);
  95. reg32 &= mask;
  96. reg32 |= picr1;
  97. pci_write_config_dword (devbusfn, PCI_PICR1, reg32);
  98. /*
  99. * invalidate all L2 cache
  100. */
  101. picr2 =
  102. (PICR2_CF_INV_MODE |
  103. PICR2_CF_HIT_HIGH |
  104. PICR2_CF_MOD_HIGH |
  105. PICR2_CF_L2_HIT_DELAY(1) |
  106. PICR2_CF_APHASE_WS(1) |
  107. picr2CacheSize);
  108. pci_write_config_dword (devbusfn, PCI_PICR2, picr2);
  109. /*
  110. * dummy transactions
  111. */
  112. for (d=0; d<(int *)(2*cacheSize); d++)
  113. dummy(*d);
  114. pci_write_config_dword (devbusfn, PCI_PICR2,
  115. (picr2 | PICR2_CF_FLUSH_L2));
  116. /* setup PICR2 */
  117. picr2 =
  118. (PICR2_CF_FAST_CASTOUT |
  119. PICR2_CF_WDATA |
  120. PICR2_CF_ADDR_ONLY_DISABLE |
  121. PICR2_CF_HIT_HIGH |
  122. PICR2_CF_MOD_HIGH |
  123. PICR2_L2_UPDATE_EN |
  124. PICR2_L2_EN |
  125. PICR2_CF_APHASE_WS(1) |
  126. PICR2_CF_DATA_RAM_PBURST |
  127. PICR2_CF_L2_HIT_DELAY(1) |
  128. PICR2_CF_SNOOP_WS(2) |
  129. picr2CacheSize);
  130. pci_write_config_dword (devbusfn, PCI_PICR2, picr2);
  131. }
  132. return (0);
  133. }
  134. /*----------------------------------------------------------------------------*/
  135. #endif /* (CFG_L2_BAB7xx) */