flush.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* flush.S - low level cache flushing routines
  2. * Copyright (C) 2003-2007 Analog Devices Inc.
  3. * Licensed under the GPL-2 or later.
  4. */
  5. #include <config.h>
  6. #include <asm/blackfin.h>
  7. #include <asm/cplb.h>
  8. #include <asm/mach-common/bits/mpu.h>
  9. .text
  10. /* This is an external function being called by the user
  11. * application through __flush_cache_all. Currently this function
  12. * serves the purpose of flushing all the pending writes in
  13. * in the data cache.
  14. */
  15. ENTRY(_flush_data_cache)
  16. [--SP] = ( R7:6, P5:4 );
  17. LINK 12;
  18. SP += -12;
  19. P5.H = HI(DCPLB_ADDR0);
  20. P5.L = LO(DCPLB_ADDR0);
  21. P4.H = HI(DCPLB_DATA0);
  22. P4.L = LO(DCPLB_DATA0);
  23. R7 = CPLB_VALID | CPLB_L1_CHBL | CPLB_DIRTY (Z);
  24. R6 = 16;
  25. .Lnext: R0 = [P5++];
  26. R1 = [P4++];
  27. CC = BITTST(R1, 14); /* Is it write-through?*/
  28. IF CC JUMP .Lskip; /* If so, ignore it.*/
  29. R2 = R1 & R7; /* Is it a dirty, cached page?*/
  30. CC = R2;
  31. IF !CC JUMP .Lskip; /* If not, ignore it.*/
  32. [--SP] = RETS;
  33. CALL _dcplb_flush; /* R0 = page, R1 = data*/
  34. RETS = [SP++];
  35. .Lskip: R6 += -1;
  36. CC = R6;
  37. IF CC JUMP .Lnext;
  38. SSYNC;
  39. SP += 12;
  40. UNLINK;
  41. ( R7:6, P5:4 ) = [SP++];
  42. RTS;
  43. ENDPROC(_flush_data_cache)
  44. /* This is an internal function to flush all pending
  45. * writes in the cache associated with a particular DCPLB.
  46. *
  47. * R0 - page's start address
  48. * R1 - CPLB's data field.
  49. */
  50. .align 2
  51. ENTRY(_dcplb_flush)
  52. [--SP] = ( R7:0, P5:0 );
  53. [--SP] = LC0;
  54. [--SP] = LT0;
  55. [--SP] = LB0;
  56. [--SP] = LC1;
  57. [--SP] = LT1;
  58. [--SP] = LB1;
  59. /* If it's a 1K or 4K page, then it's quickest to
  60. * just systematically flush all the addresses in
  61. * the page, regardless of whether they're in the
  62. * cache, or dirty. If it's a 1M or 4M page, there
  63. * are too many addresses, and we have to search the
  64. * cache for lines corresponding to the page.
  65. */
  66. CC = BITTST(R1, 17); /* 1MB or 4MB */
  67. IF !CC JUMP .Ldflush_whole_page;
  68. /* We're only interested in the page's size, so extract
  69. * this from the CPLB (bits 17:16), and scale to give an
  70. * offset into the page_size and page_prefix tables.
  71. */
  72. R1 <<= 14;
  73. R1 >>= 30;
  74. R1 <<= 2;
  75. /* The page could be mapped into Bank A or Bank B, depending
  76. * on (a) whether both banks are configured as cache, and
  77. * (b) on whether address bit A[x] is set. x is determined
  78. * by DCBS in DMEM_CONTROL
  79. */
  80. R2 = 0; /* Default to Bank A (Bank B would be 1)*/
  81. P0.L = LO(DMEM_CONTROL);
  82. P0.H = HI(DMEM_CONTROL);
  83. R3 = [P0]; /* If Bank B is not enabled as cache*/
  84. CC = BITTST(R3, 2); /* then Bank A is our only option.*/
  85. IF CC JUMP .Lbank_chosen;
  86. R4 = 1<<14; /* If DCBS==0, use A[14].*/
  87. R5 = R4 << 7; /* If DCBS==1, use A[23];*/
  88. CC = BITTST(R3, 4);
  89. IF CC R4 = R5; /* R4 now has either bit 14 or bit 23 set.*/
  90. R5 = R0 & R4; /* Use it to test the Page address*/
  91. CC = R5; /* and if that bit is set, we use Bank B,*/
  92. R2 = CC; /* else we use Bank A.*/
  93. R2 <<= 23; /* The Bank selection's at posn 23.*/
  94. .Lbank_chosen:
  95. /* We can also determine the sub-bank used, because this is
  96. * taken from bits 13:12 of the address.
  97. */
  98. R3 = ((12<<8)|2); /* Extraction pattern */
  99. nop; /*Anamoly 05000209*/
  100. R4 = EXTRACT(R0, R3.L) (Z); /* Extract bits*/
  101. /* Save in extraction pattern for later deposit.*/
  102. R3.H = R4.L << 0;
  103. /* So:
  104. * R0 = Page start
  105. * R1 = Page length (actually, offset into size/prefix tables)
  106. * R2 = Bank select mask
  107. * R3 = sub-bank deposit values
  108. *
  109. * The cache has 2 Ways, and 64 sets, so we iterate through
  110. * the sets, accessing the tag for each Way, for our Bank and
  111. * sub-bank, looking for dirty, valid tags that match our
  112. * address prefix.
  113. */
  114. P5.L = LO(DTEST_COMMAND);
  115. P5.H = HI(DTEST_COMMAND);
  116. P4.L = LO(DTEST_DATA0);
  117. P4.H = HI(DTEST_DATA0);
  118. P0.L = page_prefix_table;
  119. P0.H = page_prefix_table;
  120. P1 = R1;
  121. R5 = 0; /* Set counter*/
  122. P0 = P1 + P0;
  123. R4 = [P0]; /* This is the address prefix*/
  124. /* We're reading (bit 1==0) the tag (bit 2==0), and we
  125. * don't care about which double-word, since we're only
  126. * fetching tags, so we only have to set Set, Bank,
  127. * Sub-bank and Way.
  128. */
  129. P2 = 2;
  130. LSETUP (.Lfs1, .Lfe1) LC1 = P2;
  131. .Lfs1: P0 = 64; /* iterate over all sets*/
  132. LSETUP (.Lfs0, .Lfe0) LC0 = P0;
  133. .Lfs0: R6 = R5 << 5; /* Combine set*/
  134. R6.H = R3.H << 0 ; /* and sub-bank*/
  135. R6 = R6 | R2; /* and Bank. Leave Way==0 at first.*/
  136. BITSET(R6,14);
  137. [P5] = R6; /* Issue Command*/
  138. SSYNC;
  139. R7 = [P4]; /* and read Tag.*/
  140. CC = BITTST(R7, 0); /* Check if valid*/
  141. IF !CC JUMP .Lfskip; /* and skip if not.*/
  142. CC = BITTST(R7, 1); /* Check if dirty*/
  143. IF !CC JUMP .Lfskip; /* and skip if not.*/
  144. /* Compare against the page address. First, plant bits 13:12
  145. * into the tag, since those aren't part of the returned data.
  146. */
  147. R7 = DEPOSIT(R7, R3); /* set 13:12*/
  148. R1 = R7 & R4; /* Mask off lower bits*/
  149. CC = R1 == R0; /* Compare against page start.*/
  150. IF !CC JUMP .Lfskip; /* Skip it if it doesn't match.*/
  151. /* Tag address matches against page, so this is an entry
  152. * we must flush.
  153. */
  154. R7 >>= 10; /* Mask off the non-address bits*/
  155. R7 <<= 10;
  156. P3 = R7;
  157. SSYNC;
  158. FLUSHINV [P3]; /* And flush the entry*/
  159. .Lfskip:
  160. .Lfe0: R5 += 1; /* Advance to next Set*/
  161. .Lfe1: BITSET(R2, 26); /* Go to next Way.*/
  162. .Ldfinished:
  163. SSYNC; /* Ensure the data gets out to mem.*/
  164. /*Finished. Restore context.*/
  165. LB1 = [SP++];
  166. LT1 = [SP++];
  167. LC1 = [SP++];
  168. LB0 = [SP++];
  169. LT0 = [SP++];
  170. LC0 = [SP++];
  171. ( R7:0, P5:0 ) = [SP++];
  172. RTS;
  173. .Ldflush_whole_page:
  174. /* It's a 1K or 4K page, so quicker to just flush the
  175. * entire page.
  176. */
  177. P1 = 32; /* For 1K pages*/
  178. P2 = P1 << 2; /* For 4K pages*/
  179. P0 = R0; /* Start of page*/
  180. CC = BITTST(R1, 16); /* Whether 1K or 4K*/
  181. IF CC P1 = P2;
  182. P1 += -1; /* Unroll one iteration*/
  183. SSYNC;
  184. FLUSHINV [P0++]; /* because CSYNC can't end loops.*/
  185. LSETUP (.Leall, .Leall) LC0 = P1;
  186. .Leall: FLUSHINV [P0++];
  187. SSYNC;
  188. JUMP .Ldfinished;
  189. ENDPROC(_dcplb_flush)
  190. .align 4;
  191. page_prefix_table:
  192. .byte4 0xFFFFFC00; /* 1K */
  193. .byte4 0xFFFFF000; /* 4K */
  194. .byte4 0xFFF00000; /* 1M */
  195. .byte4 0xFFC00000; /* 4M */
  196. .page_prefix_table.end: