cache_4xx.S 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * (C) Copyright 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Author: Igor Lisitsin <igor@emcraft.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <config.h>
  26. #ifdef CONFIG_POST
  27. #include <post.h>
  28. #include <ppc_asm.tmpl>
  29. #include <ppc_defs.h>
  30. #include <asm/cache.h>
  31. #include <asm/mmu.h>
  32. #if CONFIG_POST & CFG_POST_CACHE
  33. .text
  34. /* void cache_post_disable (int tlb)
  35. */
  36. cache_post_disable:
  37. tlbre r0, r3, 0x0002
  38. ori r0, r0, TLB_WORD2_I_ENABLE@l
  39. tlbwe r0, r3, 0x0002
  40. sync
  41. isync
  42. blr
  43. /* void cache_post_wt (int tlb)
  44. */
  45. cache_post_wt:
  46. tlbre r0, r3, 0x0002
  47. ori r0, r0, TLB_WORD2_W_ENABLE@l
  48. andi. r0, r0, ~TLB_WORD2_I_ENABLE@l
  49. tlbwe r0, r3, 0x0002
  50. sync
  51. isync
  52. blr
  53. /* void cache_post_wb (int tlb)
  54. */
  55. cache_post_wb:
  56. tlbre r0, r3, 0x0002
  57. andi. r0, r0, ~TLB_WORD2_W_ENABLE@l
  58. andi. r0, r0, ~TLB_WORD2_I_ENABLE@l
  59. tlbwe r0, r3, 0x0002
  60. sync
  61. isync
  62. blr
  63. /* void cache_post_dinvalidate (void *p, int size)
  64. */
  65. cache_post_dinvalidate:
  66. dcbi r0, r3
  67. addi r3, r3, CFG_CACHELINE_SIZE
  68. subic. r4, r4, CFG_CACHELINE_SIZE
  69. bgt cache_post_dinvalidate
  70. sync
  71. blr
  72. /* void cache_post_dstore (void *p, int size)
  73. */
  74. cache_post_dstore:
  75. dcbst r0, r3
  76. addi r3, r3, CFG_CACHELINE_SIZE
  77. subic. r4, r4, CFG_CACHELINE_SIZE
  78. bgt cache_post_dstore
  79. sync
  80. blr
  81. /* void cache_post_dtouch (void *p, int size)
  82. */
  83. cache_post_dtouch:
  84. dcbt r0, r3
  85. addi r3, r3, CFG_CACHELINE_SIZE
  86. subic. r4, r4, CFG_CACHELINE_SIZE
  87. bgt cache_post_dtouch
  88. sync
  89. blr
  90. /* void cache_post_iinvalidate (void)
  91. */
  92. cache_post_iinvalidate:
  93. iccci r0, r0
  94. sync
  95. blr
  96. /* void cache_post_memset (void *p, int val, int size)
  97. */
  98. cache_post_memset:
  99. mtctr r5
  100. 1:
  101. stb r4, 0(r3)
  102. addi r3, r3, 1
  103. bdnz 1b
  104. blr
  105. /* int cache_post_check (void *p, int size)
  106. */
  107. cache_post_check:
  108. mtctr r4
  109. 1:
  110. lbz r0, 0(r3)
  111. addi r3, r3, 1
  112. cmpwi r0, 0xff
  113. bne 2f
  114. bdnz 1b
  115. li r3, 0
  116. blr
  117. 2:
  118. li r3, -1
  119. blr
  120. #define CACHE_POST_DISABLE() \
  121. mr r3, r10; \
  122. bl cache_post_disable
  123. #define CACHE_POST_WT() \
  124. mr r3, r10; \
  125. bl cache_post_wt
  126. #define CACHE_POST_WB() \
  127. mr r3, r10; \
  128. bl cache_post_wb
  129. #define CACHE_POST_DINVALIDATE() \
  130. mr r3, r11; \
  131. mr r4, r12; \
  132. bl cache_post_dinvalidate
  133. #define CACHE_POST_DFLUSH() \
  134. mr r3, r11; \
  135. mr r4, r12; \
  136. bl cache_post_dflush
  137. #define CACHE_POST_DSTORE() \
  138. mr r3, r11; \
  139. mr r4, r12; \
  140. bl cache_post_dstore
  141. #define CACHE_POST_DTOUCH() \
  142. mr r3, r11; \
  143. mr r4, r12; \
  144. bl cache_post_dtouch
  145. #define CACHE_POST_IINVALIDATE() \
  146. bl cache_post_iinvalidate
  147. #define CACHE_POST_MEMSET(val) \
  148. mr r3, r11; \
  149. li r4, val; \
  150. mr r5, r12; \
  151. bl cache_post_memset
  152. #define CACHE_POST_CHECK() \
  153. mr r3, r11; \
  154. mr r4, r12; \
  155. bl cache_post_check; \
  156. mr r13, r3
  157. /*
  158. * Write and read 0xff pattern with caching enabled.
  159. */
  160. .global cache_post_test1
  161. cache_post_test1:
  162. mflr r9
  163. mr r10, r3 /* tlb */
  164. mr r11, r4 /* p */
  165. mr r12, r5 /* size */
  166. CACHE_POST_WB()
  167. CACHE_POST_DINVALIDATE()
  168. /* Write the negative pattern to the test area */
  169. CACHE_POST_MEMSET(0xff)
  170. /* Read the test area */
  171. CACHE_POST_CHECK()
  172. CACHE_POST_DINVALIDATE()
  173. CACHE_POST_DISABLE()
  174. mr r3, r13
  175. mtlr r9
  176. blr
  177. /*
  178. * Write zeroes with caching enabled.
  179. * Write 0xff pattern with caching disabled.
  180. * Read 0xff pattern with caching enabled.
  181. */
  182. .global cache_post_test2
  183. cache_post_test2:
  184. mflr r9
  185. mr r10, r3 /* tlb */
  186. mr r11, r4 /* p */
  187. mr r12, r5 /* size */
  188. CACHE_POST_WB()
  189. CACHE_POST_DINVALIDATE()
  190. /* Write the zero pattern to the test area */
  191. CACHE_POST_MEMSET(0)
  192. CACHE_POST_DINVALIDATE()
  193. CACHE_POST_DISABLE()
  194. /* Write the negative pattern to the test area */
  195. CACHE_POST_MEMSET(0xff)
  196. CACHE_POST_WB()
  197. /* Read the test area */
  198. CACHE_POST_CHECK()
  199. CACHE_POST_DINVALIDATE()
  200. CACHE_POST_DISABLE()
  201. mr r3, r13
  202. mtlr r9
  203. blr
  204. /*
  205. * Write-through mode test.
  206. * Write zeroes, store the cache, write 0xff pattern.
  207. * Invalidate the cache.
  208. * Check that 0xff pattern is read.
  209. */
  210. .global cache_post_test3
  211. cache_post_test3:
  212. mflr r9
  213. mr r10, r3 /* tlb */
  214. mr r11, r4 /* p */
  215. mr r12, r5 /* size */
  216. CACHE_POST_WT()
  217. CACHE_POST_DINVALIDATE()
  218. /* Cache the test area */
  219. CACHE_POST_DTOUCH()
  220. /* Write the zero pattern to the test area */
  221. CACHE_POST_MEMSET(0)
  222. CACHE_POST_DSTORE()
  223. /* Write the negative pattern to the test area */
  224. CACHE_POST_MEMSET(0xff)
  225. CACHE_POST_DINVALIDATE()
  226. CACHE_POST_DISABLE()
  227. /* Read the test area */
  228. CACHE_POST_CHECK()
  229. mr r3, r13
  230. mtlr r9
  231. blr
  232. /*
  233. * Write-back mode test.
  234. * Write 0xff pattern, store the cache, write zeroes.
  235. * Invalidate the cache.
  236. * Check that 0xff pattern is read.
  237. */
  238. .global cache_post_test4
  239. cache_post_test4:
  240. mflr r9
  241. mr r10, r3 /* tlb */
  242. mr r11, r4 /* p */
  243. mr r12, r5 /* size */
  244. CACHE_POST_WB()
  245. CACHE_POST_DINVALIDATE()
  246. /* Cache the test area */
  247. CACHE_POST_DTOUCH()
  248. /* Write the negative pattern to the test area */
  249. CACHE_POST_MEMSET(0xff)
  250. CACHE_POST_DSTORE()
  251. /* Write the zero pattern to the test area */
  252. CACHE_POST_MEMSET(0)
  253. CACHE_POST_DINVALIDATE()
  254. CACHE_POST_DISABLE()
  255. /* Read the test area */
  256. CACHE_POST_CHECK()
  257. mr r3, r13
  258. mtlr r9
  259. blr
  260. /*
  261. * Load the test instructions into the instruction cache.
  262. * Replace the test instructions.
  263. * Check that the original instructions are executed.
  264. */
  265. .global cache_post_test5
  266. cache_post_test5:
  267. mflr r9
  268. mr r10, r3 /* tlb */
  269. mr r11, r4 /* p */
  270. mr r12, r5 /* size */
  271. CACHE_POST_WT()
  272. CACHE_POST_IINVALIDATE()
  273. /* Compute r13 = cache_post_test_inst */
  274. bl cache_post_test5_reloc
  275. cache_post_test5_reloc:
  276. mflr r13
  277. lis r0, (cache_post_test_inst - cache_post_test5_reloc)@h
  278. ori r0, r0, (cache_post_test_inst - cache_post_test5_reloc)@l
  279. add r13, r13, r0
  280. /* Copy the test instructions to the test area */
  281. lwz r0, 0(r13)
  282. stw r0, 0(r11)
  283. lwz r0, 8(r13)
  284. stw r0, 4(r11)
  285. sync
  286. /* Invalidate the cache line */
  287. icbi r0, r11
  288. sync
  289. isync
  290. /* Execute the test instructions */
  291. mtlr r11
  292. blrl
  293. /* Replace the test instruction */
  294. lwz r0, 4(r13)
  295. stw r0, 0(r11)
  296. sync
  297. /* Do not invalidate the cache line */
  298. isync
  299. /* Execute the test instructions */
  300. mtlr r11
  301. blrl
  302. mr r13, r3
  303. CACHE_POST_IINVALIDATE()
  304. CACHE_POST_DINVALIDATE()
  305. CACHE_POST_DISABLE()
  306. mr r3, r13
  307. mtlr r9
  308. blr
  309. /*
  310. * Load the test instructions into the instruction cache.
  311. * Replace the test instructions and invalidate the cache.
  312. * Check that the replaced instructions are executed.
  313. */
  314. .global cache_post_test6
  315. cache_post_test6:
  316. mflr r9
  317. mr r10, r3 /* tlb */
  318. mr r11, r4 /* p */
  319. mr r12, r5 /* size */
  320. CACHE_POST_WT()
  321. CACHE_POST_IINVALIDATE()
  322. /* Compute r13 = cache_post_test_inst */
  323. bl cache_post_test6_reloc
  324. cache_post_test6_reloc:
  325. mflr r13
  326. lis r0, (cache_post_test_inst - cache_post_test6_reloc)@h
  327. ori r0, r0, (cache_post_test_inst - cache_post_test6_reloc)@l
  328. add r13, r13, r0
  329. /* Copy the test instructions to the test area */
  330. lwz r0, 4(r13)
  331. stw r0, 0(r11)
  332. lwz r0, 8(r13)
  333. stw r0, 4(r11)
  334. sync
  335. /* Invalidate the cache line */
  336. icbi r0, r11
  337. sync
  338. isync
  339. /* Execute the test instructions */
  340. mtlr r11
  341. blrl
  342. /* Replace the test instruction */
  343. lwz r0, 0(r13)
  344. stw r0, 0(r11)
  345. sync
  346. /* Invalidate the cache line */
  347. icbi r0, r11
  348. sync
  349. isync
  350. /* Execute the test instructions */
  351. mtlr r11
  352. blrl
  353. mr r13, r3
  354. CACHE_POST_IINVALIDATE()
  355. CACHE_POST_DINVALIDATE()
  356. CACHE_POST_DISABLE()
  357. mr r3, r13
  358. mtlr r9
  359. blr
  360. /* Test instructions.
  361. */
  362. cache_post_test_inst:
  363. li r3, 0
  364. li r3, -1
  365. blr
  366. #endif /* CONFIG_POST & CFG_POST_CACHE */
  367. #endif /* CONFIG_POST */