spram.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * MIPS SPRAM support
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Copyright (C) 2007, 2008 MIPS Technologies, Inc.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/ptrace.h>
  14. #include <linux/stddef.h>
  15. #include <asm/fpu.h>
  16. #include <asm/mipsregs.h>
  17. #include <asm/r4kcache.h>
  18. #include <asm/hazards.h>
  19. /*
  20. * These definitions are correct for the 24K/34K/74K SPRAM sample
  21. * implementation. The 4KS interpreted the tags differently...
  22. */
  23. #define SPRAM_TAG0_ENABLE 0x00000080
  24. #define SPRAM_TAG0_PA_MASK 0xfffff000
  25. #define SPRAM_TAG1_SIZE_MASK 0xfffff000
  26. #define SPRAM_TAG_STRIDE 8
  27. #define ERRCTL_SPRAM (1 << 28)
  28. /* errctl access */
  29. #define read_c0_errctl(x) read_c0_ecc(x)
  30. #define write_c0_errctl(x) write_c0_ecc(x)
  31. /*
  32. * Different semantics to the set_c0_* function built by __BUILD_SET_C0
  33. */
  34. static __cpuinit unsigned int bis_c0_errctl(unsigned int set)
  35. {
  36. unsigned int res;
  37. res = read_c0_errctl();
  38. write_c0_errctl(res | set);
  39. return res;
  40. }
  41. static __cpuinit void ispram_store_tag(unsigned int offset, unsigned int data)
  42. {
  43. unsigned int errctl;
  44. /* enable SPRAM tag access */
  45. errctl = bis_c0_errctl(ERRCTL_SPRAM);
  46. ehb();
  47. write_c0_taglo(data);
  48. ehb();
  49. cache_op(Index_Store_Tag_I, CKSEG0|offset);
  50. ehb();
  51. write_c0_errctl(errctl);
  52. ehb();
  53. }
  54. static __cpuinit unsigned int ispram_load_tag(unsigned int offset)
  55. {
  56. unsigned int data;
  57. unsigned int errctl;
  58. /* enable SPRAM tag access */
  59. errctl = bis_c0_errctl(ERRCTL_SPRAM);
  60. ehb();
  61. cache_op(Index_Load_Tag_I, CKSEG0 | offset);
  62. ehb();
  63. data = read_c0_taglo();
  64. ehb();
  65. write_c0_errctl(errctl);
  66. ehb();
  67. return data;
  68. }
  69. static __cpuinit void dspram_store_tag(unsigned int offset, unsigned int data)
  70. {
  71. unsigned int errctl;
  72. /* enable SPRAM tag access */
  73. errctl = bis_c0_errctl(ERRCTL_SPRAM);
  74. ehb();
  75. write_c0_dtaglo(data);
  76. ehb();
  77. cache_op(Index_Store_Tag_D, CKSEG0 | offset);
  78. ehb();
  79. write_c0_errctl(errctl);
  80. ehb();
  81. }
  82. static __cpuinit unsigned int dspram_load_tag(unsigned int offset)
  83. {
  84. unsigned int data;
  85. unsigned int errctl;
  86. errctl = bis_c0_errctl(ERRCTL_SPRAM);
  87. ehb();
  88. cache_op(Index_Load_Tag_D, CKSEG0 | offset);
  89. ehb();
  90. data = read_c0_dtaglo();
  91. ehb();
  92. write_c0_errctl(errctl);
  93. ehb();
  94. return data;
  95. }
  96. static __cpuinit void probe_spram(char *type,
  97. unsigned int base,
  98. unsigned int (*read)(unsigned int),
  99. void (*write)(unsigned int, unsigned int))
  100. {
  101. unsigned int firstsize = 0, lastsize = 0;
  102. unsigned int firstpa = 0, lastpa = 0, pa = 0;
  103. unsigned int offset = 0;
  104. unsigned int size, tag0, tag1;
  105. unsigned int enabled;
  106. int i;
  107. /*
  108. * The limit is arbitrary but avoids the loop running away if
  109. * the SPRAM tags are implemented differently
  110. */
  111. for (i = 0; i < 8; i++) {
  112. tag0 = read(offset);
  113. tag1 = read(offset+SPRAM_TAG_STRIDE);
  114. pr_debug("DBG %s%d: tag0=%08x tag1=%08x\n",
  115. type, i, tag0, tag1);
  116. size = tag1 & SPRAM_TAG1_SIZE_MASK;
  117. if (size == 0)
  118. break;
  119. if (i != 0) {
  120. /* tags may repeat... */
  121. if ((pa == firstpa && size == firstsize) ||
  122. (pa == lastpa && size == lastsize))
  123. break;
  124. }
  125. /* Align base with size */
  126. base = (base + size - 1) & ~(size-1);
  127. /* reprogram the base address base address and enable */
  128. tag0 = (base & SPRAM_TAG0_PA_MASK) | SPRAM_TAG0_ENABLE;
  129. write(offset, tag0);
  130. base += size;
  131. /* reread the tag */
  132. tag0 = read(offset);
  133. pa = tag0 & SPRAM_TAG0_PA_MASK;
  134. enabled = tag0 & SPRAM_TAG0_ENABLE;
  135. if (i == 0) {
  136. firstpa = pa;
  137. firstsize = size;
  138. }
  139. lastpa = pa;
  140. lastsize = size;
  141. if (strcmp(type, "DSPRAM") == 0) {
  142. unsigned int *vp = (unsigned int *)(CKSEG1 | pa);
  143. unsigned int v;
  144. #define TDAT 0x5a5aa5a5
  145. vp[0] = TDAT;
  146. vp[1] = ~TDAT;
  147. mb();
  148. v = vp[0];
  149. if (v != TDAT)
  150. printk(KERN_ERR "vp=%p wrote=%08x got=%08x\n",
  151. vp, TDAT, v);
  152. v = vp[1];
  153. if (v != ~TDAT)
  154. printk(KERN_ERR "vp=%p wrote=%08x got=%08x\n",
  155. vp+1, ~TDAT, v);
  156. }
  157. pr_info("%s%d: PA=%08x,Size=%08x%s\n",
  158. type, i, pa, size, enabled ? ",enabled" : "");
  159. offset += 2 * SPRAM_TAG_STRIDE;
  160. }
  161. }
  162. void __cpuinit spram_config(void)
  163. {
  164. struct cpuinfo_mips *c = &current_cpu_data;
  165. unsigned int config0;
  166. switch (c->cputype) {
  167. case CPU_24K:
  168. case CPU_34K:
  169. case CPU_74K:
  170. case CPU_1004K:
  171. config0 = read_c0_config();
  172. /* FIXME: addresses are Malta specific */
  173. if (config0 & (1<<24)) {
  174. probe_spram("ISPRAM", 0x1c000000,
  175. &ispram_load_tag, &ispram_store_tag);
  176. }
  177. if (config0 & (1<<23))
  178. probe_spram("DSPRAM", 0x1c100000,
  179. &dspram_load_tag, &dspram_store_tag);
  180. }
  181. }