spram.c 4.7 KB

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