cache_4xx.S 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. /*
  35. * All 44x variants deal with cache management differently
  36. * because they have the address translation always enabled.
  37. * The 40x ppc's don't use address translation in U-Boot at all,
  38. * so we have to distinguish here between 40x and 44x.
  39. */
  40. #ifdef CONFIG_440
  41. /* void cache_post_disable (int tlb)
  42. */
  43. cache_post_disable:
  44. tlbre r0, r3, 0x0002
  45. ori r0, r0, TLB_WORD2_I_ENABLE@l
  46. tlbwe r0, r3, 0x0002
  47. sync
  48. isync
  49. blr
  50. /* void cache_post_wt (int tlb)
  51. */
  52. cache_post_wt:
  53. tlbre r0, r3, 0x0002
  54. ori r0, r0, TLB_WORD2_W_ENABLE@l
  55. andi. r0, r0, ~TLB_WORD2_I_ENABLE@l
  56. tlbwe r0, r3, 0x0002
  57. sync
  58. isync
  59. blr
  60. /* void cache_post_wb (int tlb)
  61. */
  62. cache_post_wb:
  63. tlbre r0, r3, 0x0002
  64. andi. r0, r0, ~TLB_WORD2_W_ENABLE@l
  65. andi. r0, r0, ~TLB_WORD2_I_ENABLE@l
  66. tlbwe r0, r3, 0x0002
  67. sync
  68. isync
  69. blr
  70. #else
  71. /* void cache_post_disable (int tlb)
  72. */
  73. cache_post_disable:
  74. lis r0, 0x0000
  75. ori r0, r0, 0x0000
  76. mtdccr r0
  77. sync
  78. isync
  79. blr
  80. /* void cache_post_wt (int tlb)
  81. */
  82. cache_post_wt:
  83. lis r0, 0x8000
  84. ori r0, r0, 0x0000
  85. mtdccr r0
  86. lis r0, 0x8000
  87. ori r0, r0, 0x0000
  88. mtdcwr r0
  89. sync
  90. isync
  91. blr
  92. /* void cache_post_wb (int tlb)
  93. */
  94. cache_post_wb:
  95. lis r0, 0x8000
  96. ori r0, r0, 0x0000
  97. mtdccr r0
  98. lis r0, 0x0000
  99. ori r0, r0, 0x0000
  100. mtdcwr r0
  101. sync
  102. isync
  103. blr
  104. #endif
  105. /* void cache_post_dinvalidate (void *p, int size)
  106. */
  107. cache_post_dinvalidate:
  108. dcbi r0, r3
  109. addi r3, r3, CFG_CACHELINE_SIZE
  110. subic. r4, r4, CFG_CACHELINE_SIZE
  111. bgt cache_post_dinvalidate
  112. sync
  113. blr
  114. /* void cache_post_dstore (void *p, int size)
  115. */
  116. cache_post_dstore:
  117. dcbst r0, r3
  118. addi r3, r3, CFG_CACHELINE_SIZE
  119. subic. r4, r4, CFG_CACHELINE_SIZE
  120. bgt cache_post_dstore
  121. sync
  122. blr
  123. /* void cache_post_dtouch (void *p, int size)
  124. */
  125. cache_post_dtouch:
  126. dcbt r0, r3
  127. addi r3, r3, CFG_CACHELINE_SIZE
  128. subic. r4, r4, CFG_CACHELINE_SIZE
  129. bgt cache_post_dtouch
  130. sync
  131. blr
  132. /* void cache_post_iinvalidate (void)
  133. */
  134. cache_post_iinvalidate:
  135. iccci r0, r0
  136. sync
  137. blr
  138. /* void cache_post_memset (void *p, int val, int size)
  139. */
  140. cache_post_memset:
  141. mtctr r5
  142. 1:
  143. stb r4, 0(r3)
  144. addi r3, r3, 1
  145. bdnz 1b
  146. blr
  147. /* int cache_post_check (void *p, int size)
  148. */
  149. cache_post_check:
  150. mtctr r4
  151. 1:
  152. lbz r0, 0(r3)
  153. addi r3, r3, 1
  154. cmpwi r0, 0xff
  155. bne 2f
  156. bdnz 1b
  157. li r3, 0
  158. blr
  159. 2:
  160. li r3, -1
  161. blr
  162. #define CACHE_POST_DISABLE() \
  163. mr r3, r10; \
  164. bl cache_post_disable
  165. #define CACHE_POST_WT() \
  166. mr r3, r10; \
  167. bl cache_post_wt
  168. #define CACHE_POST_WB() \
  169. mr r3, r10; \
  170. bl cache_post_wb
  171. #define CACHE_POST_DINVALIDATE() \
  172. mr r3, r11; \
  173. mr r4, r12; \
  174. bl cache_post_dinvalidate
  175. #define CACHE_POST_DFLUSH() \
  176. mr r3, r11; \
  177. mr r4, r12; \
  178. bl cache_post_dflush
  179. #define CACHE_POST_DSTORE() \
  180. mr r3, r11; \
  181. mr r4, r12; \
  182. bl cache_post_dstore
  183. #define CACHE_POST_DTOUCH() \
  184. mr r3, r11; \
  185. mr r4, r12; \
  186. bl cache_post_dtouch
  187. #define CACHE_POST_IINVALIDATE() \
  188. bl cache_post_iinvalidate
  189. #define CACHE_POST_MEMSET(val) \
  190. mr r3, r11; \
  191. li r4, val; \
  192. mr r5, r12; \
  193. bl cache_post_memset
  194. #define CACHE_POST_CHECK() \
  195. mr r3, r11; \
  196. mr r4, r12; \
  197. bl cache_post_check; \
  198. mr r13, r3
  199. /*
  200. * Write and read 0xff pattern with caching enabled.
  201. */
  202. .global cache_post_test1
  203. cache_post_test1:
  204. mflr r9
  205. mr r10, r3 /* tlb */
  206. mr r11, r4 /* p */
  207. mr r12, r5 /* size */
  208. CACHE_POST_WB()
  209. CACHE_POST_DINVALIDATE()
  210. /* Write the negative pattern to the test area */
  211. CACHE_POST_MEMSET(0xff)
  212. /* Read the test area */
  213. CACHE_POST_CHECK()
  214. CACHE_POST_DINVALIDATE()
  215. CACHE_POST_DISABLE()
  216. mr r3, r13
  217. mtlr r9
  218. blr
  219. /*
  220. * Write zeroes with caching enabled.
  221. * Write 0xff pattern with caching disabled.
  222. * Read 0xff pattern with caching enabled.
  223. */
  224. .global cache_post_test2
  225. cache_post_test2:
  226. mflr r9
  227. mr r10, r3 /* tlb */
  228. mr r11, r4 /* p */
  229. mr r12, r5 /* size */
  230. CACHE_POST_WB()
  231. CACHE_POST_DINVALIDATE()
  232. /* Write the zero pattern to the test area */
  233. CACHE_POST_MEMSET(0)
  234. CACHE_POST_DINVALIDATE()
  235. CACHE_POST_DISABLE()
  236. /* Write the negative pattern to the test area */
  237. CACHE_POST_MEMSET(0xff)
  238. CACHE_POST_WB()
  239. /* Read the test area */
  240. CACHE_POST_CHECK()
  241. CACHE_POST_DINVALIDATE()
  242. CACHE_POST_DISABLE()
  243. mr r3, r13
  244. mtlr r9
  245. blr
  246. /*
  247. * Write-through mode test.
  248. * Write zeroes, store the cache, write 0xff pattern.
  249. * Invalidate the cache.
  250. * Check that 0xff pattern is read.
  251. */
  252. .global cache_post_test3
  253. cache_post_test3:
  254. mflr r9
  255. mr r10, r3 /* tlb */
  256. mr r11, r4 /* p */
  257. mr r12, r5 /* size */
  258. CACHE_POST_WT()
  259. CACHE_POST_DINVALIDATE()
  260. /* Cache the test area */
  261. CACHE_POST_DTOUCH()
  262. /* Write the zero pattern to the test area */
  263. CACHE_POST_MEMSET(0)
  264. CACHE_POST_DSTORE()
  265. /* Write the negative pattern to the test area */
  266. CACHE_POST_MEMSET(0xff)
  267. CACHE_POST_DINVALIDATE()
  268. CACHE_POST_DISABLE()
  269. /* Read the test area */
  270. CACHE_POST_CHECK()
  271. mr r3, r13
  272. mtlr r9
  273. blr
  274. /*
  275. * Write-back mode test.
  276. * Write 0xff pattern, store the cache, write zeroes.
  277. * Invalidate the cache.
  278. * Check that 0xff pattern is read.
  279. */
  280. .global cache_post_test4
  281. cache_post_test4:
  282. mflr r9
  283. mr r10, r3 /* tlb */
  284. mr r11, r4 /* p */
  285. mr r12, r5 /* size */
  286. CACHE_POST_WB()
  287. CACHE_POST_DINVALIDATE()
  288. /* Cache the test area */
  289. CACHE_POST_DTOUCH()
  290. /* Write the negative pattern to the test area */
  291. CACHE_POST_MEMSET(0xff)
  292. CACHE_POST_DSTORE()
  293. /* Write the zero pattern to the test area */
  294. CACHE_POST_MEMSET(0)
  295. CACHE_POST_DINVALIDATE()
  296. CACHE_POST_DISABLE()
  297. /* Read the test area */
  298. CACHE_POST_CHECK()
  299. mr r3, r13
  300. mtlr r9
  301. blr
  302. /*
  303. * Load the test instructions into the instruction cache.
  304. * Replace the test instructions.
  305. * Check that the original instructions are executed.
  306. */
  307. .global cache_post_test5
  308. cache_post_test5:
  309. mflr r9
  310. mr r10, r3 /* tlb */
  311. mr r11, r4 /* p */
  312. mr r12, r5 /* size */
  313. CACHE_POST_WT()
  314. CACHE_POST_IINVALIDATE()
  315. /* Compute r13 = cache_post_test_inst */
  316. bl cache_post_test5_reloc
  317. cache_post_test5_reloc:
  318. mflr r13
  319. lis r0, (cache_post_test_inst - cache_post_test5_reloc)@h
  320. ori r0, r0, (cache_post_test_inst - cache_post_test5_reloc)@l
  321. add r13, r13, r0
  322. /* Copy the test instructions to the test area */
  323. lwz r0, 0(r13)
  324. stw r0, 0(r11)
  325. lwz r0, 8(r13)
  326. stw r0, 4(r11)
  327. sync
  328. /* Invalidate the cache line */
  329. icbi r0, r11
  330. sync
  331. isync
  332. /* Execute the test instructions */
  333. mtlr r11
  334. blrl
  335. /* Replace the test instruction */
  336. lwz r0, 4(r13)
  337. stw r0, 0(r11)
  338. sync
  339. /* Do not invalidate the cache line */
  340. isync
  341. /* Execute the test instructions */
  342. mtlr r11
  343. blrl
  344. mr r13, r3
  345. CACHE_POST_IINVALIDATE()
  346. CACHE_POST_DINVALIDATE()
  347. CACHE_POST_DISABLE()
  348. mr r3, r13
  349. mtlr r9
  350. blr
  351. /*
  352. * Load the test instructions into the instruction cache.
  353. * Replace the test instructions and invalidate the cache.
  354. * Check that the replaced instructions are executed.
  355. */
  356. .global cache_post_test6
  357. cache_post_test6:
  358. mflr r9
  359. mr r10, r3 /* tlb */
  360. mr r11, r4 /* p */
  361. mr r12, r5 /* size */
  362. CACHE_POST_WT()
  363. CACHE_POST_IINVALIDATE()
  364. /* Compute r13 = cache_post_test_inst */
  365. bl cache_post_test6_reloc
  366. cache_post_test6_reloc:
  367. mflr r13
  368. lis r0, (cache_post_test_inst - cache_post_test6_reloc)@h
  369. ori r0, r0, (cache_post_test_inst - cache_post_test6_reloc)@l
  370. add r13, r13, r0
  371. /* Copy the test instructions to the test area */
  372. lwz r0, 4(r13)
  373. stw r0, 0(r11)
  374. lwz r0, 8(r13)
  375. stw r0, 4(r11)
  376. sync
  377. /* Invalidate the cache line */
  378. icbi r0, r11
  379. sync
  380. isync
  381. /* Execute the test instructions */
  382. mtlr r11
  383. blrl
  384. /* Replace the test instruction */
  385. lwz r0, 0(r13)
  386. stw r0, 0(r11)
  387. sync
  388. /* Invalidate the cache line */
  389. icbi r0, r11
  390. sync
  391. isync
  392. /* Execute the test instructions */
  393. mtlr r11
  394. blrl
  395. mr r13, r3
  396. CACHE_POST_IINVALIDATE()
  397. CACHE_POST_DINVALIDATE()
  398. CACHE_POST_DISABLE()
  399. mr r3, r13
  400. mtlr r9
  401. blr
  402. /* Test instructions.
  403. */
  404. cache_post_test_inst:
  405. li r3, 0
  406. li r3, -1
  407. blr
  408. #endif /* CONFIG_POST & CFG_POST_CACHE */
  409. #endif /* CONFIG_POST */