l2cache.c 3.8 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(CONFIG_SYS_L2_BAB7xx)
  25. #include <pci.h>
  26. #include <mpc106.h>
  27. #include <asm/processor.h>
  28. /* defines L2CR register for MPC750 */
  29. #define L2CR_E 0x80000000
  30. #define L2CR_256K 0x10000000
  31. #define L2CR_512K 0x20000000
  32. #define L2CR_1024K 0x30000000
  33. #define L2CR_I 0x00200000
  34. #define L2CR_SL 0x00008000
  35. #define L2CR_IP 0x00000001
  36. /*----------------------------------------------------------------------------*/
  37. static int dummy (int dummy)
  38. {
  39. return (dummy+1);
  40. }
  41. /*----------------------------------------------------------------------------*/
  42. int l2_cache_enable (int l2control)
  43. {
  44. if (l2control) /* BAB750 */
  45. {
  46. mtspr(SPRN_L2CR, l2control);
  47. mtspr(SPRN_L2CR, (l2control | L2CR_I));
  48. while (mfspr(SPRN_L2CR) & L2CR_IP)
  49. ;
  50. mtspr(SPRN_L2CR, (l2control | L2CR_E));
  51. return (0);
  52. }
  53. else /* BAB740 */
  54. {
  55. int picr1, picr2, mask;
  56. int picr2CacheSize, cacheSize;
  57. int *d;
  58. int devbusfn;
  59. u32 reg32;
  60. devbusfn = pci_find_device(PCI_VENDOR_ID_MOTOROLA,
  61. PCI_DEVICE_ID_MOTOROLA_MPC106, 0);
  62. if (devbusfn == -1)
  63. return (-1);
  64. pci_read_config_dword (devbusfn, PCI_PICR2, &reg32);
  65. reg32 &= ~PICR2_L2_EN;
  66. pci_write_config_dword (devbusfn, PCI_PICR2, reg32);
  67. /* cache size */
  68. if (*(volatile unsigned char *) (CONFIG_SYS_ISA_IO + 0x220) & 0x04)
  69. {
  70. /* cache size is 512 KB */
  71. picr2CacheSize = PICR2_L2_SIZE_512K;
  72. cacheSize = 0x80000;
  73. }
  74. else
  75. {
  76. /* cache size is 256 KB */
  77. picr2CacheSize = PICR2_L2_SIZE_256K;
  78. cacheSize = 0x40000;
  79. }
  80. /* setup PICR1 */
  81. mask =
  82. ~(PICR1_CF_BREAD_WS(1) |
  83. PICR1_CF_BREAD_WS(2) |
  84. PICR1_CF_CBA(0xff) |
  85. PICR1_CF_CACHE_1G |
  86. PICR1_CF_DPARK |
  87. PICR1_CF_APARK |
  88. PICR1_CF_L2_CACHE_MASK);
  89. picr1 =
  90. (PICR1_CF_CBA(0x3f) |
  91. PICR1_CF_CACHE_1G |
  92. PICR1_CF_APARK |
  93. PICR1_CF_DPARK |
  94. PICR1_CF_L2_COPY_BACK); /* PICR1_CF_L2_WRITE_THROUGH */
  95. pci_read_config_dword (devbusfn, PCI_PICR1, &reg32);
  96. reg32 &= mask;
  97. reg32 |= picr1;
  98. pci_write_config_dword (devbusfn, PCI_PICR1, reg32);
  99. /*
  100. * invalidate all L2 cache
  101. */
  102. picr2 =
  103. (PICR2_CF_INV_MODE |
  104. PICR2_CF_HIT_HIGH |
  105. PICR2_CF_MOD_HIGH |
  106. PICR2_CF_L2_HIT_DELAY(1) |
  107. PICR2_CF_APHASE_WS(1) |
  108. picr2CacheSize);
  109. pci_write_config_dword (devbusfn, PCI_PICR2, picr2);
  110. /*
  111. * dummy transactions
  112. */
  113. for (d=0; d<(int *)(2*cacheSize); d++)
  114. dummy(*d);
  115. pci_write_config_dword (devbusfn, PCI_PICR2,
  116. (picr2 | PICR2_CF_FLUSH_L2));
  117. /* setup PICR2 */
  118. picr2 =
  119. (PICR2_CF_FAST_CASTOUT |
  120. PICR2_CF_WDATA |
  121. PICR2_CF_ADDR_ONLY_DISABLE |
  122. PICR2_CF_HIT_HIGH |
  123. PICR2_CF_MOD_HIGH |
  124. PICR2_L2_UPDATE_EN |
  125. PICR2_L2_EN |
  126. PICR2_CF_APHASE_WS(1) |
  127. PICR2_CF_DATA_RAM_PBURST |
  128. PICR2_CF_L2_HIT_DELAY(1) |
  129. PICR2_CF_SNOOP_WS(2) |
  130. picr2CacheSize);
  131. pci_write_config_dword (devbusfn, PCI_PICR2, picr2);
  132. }
  133. return (0);
  134. }
  135. /*----------------------------------------------------------------------------*/
  136. #endif /* (CONFIG_SYS_L2_BAB7xx) */