cache_4xx.S 8.7 KB

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