caches.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * operations on all memory data or unified caches, a no-op cache,
  3. * and an l1-only cache ops cache.
  4. * i-caches are not handled here.
  5. *
  6. * there are only three cache operations that we care about:
  7. * force cache contents to memory (before dma out or shutdown),
  8. * ignore cache contents in favour of memory (initialisation, after dma in),
  9. * both (update page tables and force cpu to read new contents).
  10. */
  11. #include "u.h"
  12. #include "../port/lib.h"
  13. #include "mem.h"
  14. #include "dat.h"
  15. #include "fns.h"
  16. #include "io.h"
  17. #include "../port/error.h"
  18. static Cacheimpl allcaches, nullcaches, l1caches;
  19. void
  20. cachesinfo(Memcache *cp)
  21. {
  22. memset(cp, 0, sizeof *cp);
  23. cp->setsways = Cara | Cawa | Cawt | Cawb;
  24. cp->l1ip = 3<<14; /* PIPT */
  25. cp->log2linelen = log2(CACHELINESZ);
  26. }
  27. void
  28. allcacheson(void)
  29. {
  30. l2pl310init();
  31. allcache = &allcaches;
  32. nocache = &nullcaches;
  33. l1cache = &l1caches;
  34. }
  35. void
  36. cachesoff(void)
  37. {
  38. l2cache->off();
  39. }
  40. void
  41. cachesinvse(void *va, int bytes)
  42. {
  43. int s;
  44. s = splhi();
  45. l2cache->invse(va, bytes);
  46. cachedinvse(va, bytes);
  47. splx(s);
  48. }
  49. void
  50. cacheswbse(void *va, int bytes)
  51. {
  52. int s;
  53. s = splhi();
  54. cachedwbse(va, bytes);
  55. l2cache->wbse(va, bytes);
  56. splx(s);
  57. }
  58. void
  59. cacheswbinvse(void *va, int bytes)
  60. {
  61. int s;
  62. s = splhi();
  63. cachedwbse(va, bytes);
  64. l2cache->wbinvse(va, bytes);
  65. cachedwbinvse(va, bytes);
  66. splx(s);
  67. }
  68. void
  69. cachesinv(void)
  70. {
  71. int s;
  72. s = splhi();
  73. l2cache->inv();
  74. cachedinv();
  75. splx(s);
  76. }
  77. void
  78. cacheswb(void)
  79. {
  80. int s;
  81. s = splhi();
  82. cachedwb();
  83. l2cache->wb();
  84. splx(s);
  85. }
  86. void
  87. cacheswbinv(void)
  88. {
  89. int s;
  90. s = splhi();
  91. cachedwb();
  92. l2cache->wbinv();
  93. cachedwbinv();
  94. splx(s);
  95. }
  96. static Cacheimpl allcaches = {
  97. .info = cachesinfo,
  98. .on = allcacheson,
  99. .off = cachesoff,
  100. .inv = cachesinv,
  101. .wb = cacheswb,
  102. .wbinv = cacheswbinv,
  103. .invse = cachesinvse,
  104. .wbse = cacheswbse,
  105. .wbinvse= cacheswbinvse,
  106. };
  107. /*
  108. * null cache ops
  109. */
  110. void
  111. nullinfo(Memcache *cp)
  112. {
  113. memset(cp, 0, sizeof *cp);
  114. cp->log2linelen = 2;
  115. }
  116. void
  117. nullon(void)
  118. {
  119. nocache = &nullcaches;
  120. }
  121. void
  122. nullop(void)
  123. {
  124. }
  125. void
  126. nullse(void *, int)
  127. {
  128. }
  129. static Cacheimpl nullcaches = {
  130. .info = nullinfo,
  131. .on = nullon,
  132. .off = nullop,
  133. .inv = nullop,
  134. .wb = nullop,
  135. .wbinv = nullop,
  136. .invse = nullse,
  137. .wbse = nullse,
  138. .wbinvse= nullse,
  139. };
  140. /*
  141. * l1-only ops
  142. */
  143. void
  144. l1cachesinfo(Memcache *)
  145. {
  146. }
  147. void
  148. l1cacheson(void)
  149. {
  150. l1cache = &l1caches;
  151. }
  152. static Cacheimpl l1caches = {
  153. .info = l1cachesinfo,
  154. .on = l1cacheson,
  155. .off = nullop,
  156. .inv = cachedinv,
  157. .wb = cachedwb,
  158. .wbinv = cachedwbinv,
  159. .invse = cachedinvse,
  160. .wbse = cachedwbse,
  161. .wbinvse= cachedwbinvse,
  162. };