023-mcfv4e_cache_base_update.patch 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. From 3592cd3db82e5b010df590079f1e310b5d317248 Mon Sep 17 00:00:00 2001
  2. From: Kurt Mahan <[email protected]>
  3. Date: Mon, 3 Dec 2007 23:03:07 -0700
  4. Subject: [PATCH] Rewrite Coldfire cache code.
  5. LTIBName: mcfv4e-cache-base-update
  6. Signed-off-by: Kurt Mahan <[email protected]>
  7. ---
  8. arch/m68k/coldfire/cache.c | 196 +-------------
  9. arch/m68k/coldfire/head.S | 6 +-
  10. arch/m68k/coldfire/signal.c | 4 +-
  11. arch/m68k/kernel/sys_m68k.c | 16 ++
  12. arch/m68k/mm/cache.c | 31 +---
  13. arch/m68k/mm/memory.c | 76 +-----
  14. include/asm-m68k/cf_cacheflush.h | 525 +++++++++++++++++++++++++++++---------
  15. include/asm-m68k/cfcache.h | 95 ++++----
  16. 8 files changed, 495 insertions(+), 454 deletions(-)
  17. --- a/arch/m68k/coldfire/cache.c
  18. +++ b/arch/m68k/coldfire/cache.c
  19. @@ -1,7 +1,8 @@
  20. /*
  21. - * linux/arch/m68k/coldifre/cache.c
  22. + * linux/arch/m68k/coldfire/cache.c
  23. *
  24. * Matt Waddel [email protected]
  25. + * Kurt Mahan [email protected]
  26. * Copyright Freescale Semiconductor, Inc. 2007
  27. *
  28. * This program is free software; you can redistribute it and/or modify
  29. @@ -15,191 +16,13 @@
  30. #include <asm/coldfire.h>
  31. #include <asm/system.h>
  32. -#define _DCACHE_SIZE (2*16384)
  33. -#define _ICACHE_SIZE (2*16384)
  34. -
  35. -#define _SET_SHIFT 4
  36. -
  37. -/*
  38. - * Masks for cache sizes. Programming note: because the set size is a
  39. - * power of two, the mask is also the last address in the set.
  40. - */
  41. -
  42. -#define _DCACHE_SET_MASK ((_DCACHE_SIZE/64-1)<<_SET_SHIFT)
  43. -#define _ICACHE_SET_MASK ((_ICACHE_SIZE/64-1)<<_SET_SHIFT)
  44. -#define LAST_DCACHE_ADDR _DCACHE_SET_MASK
  45. -#define LAST_ICACHE_ADDR _ICACHE_SET_MASK
  46. -
  47. -/************************************************************
  48. - * Routine to cleanly flush the cache, pushing all lines and
  49. - * invalidating them.
  50. - *
  51. - * The is the flash-resident version, used after copying the .text
  52. - * segment from flash to ram.
  53. - *************************************************************/
  54. -void FLASHDcacheFlushInvalidate(void)
  55. - __attribute__ ((section (".text_loader")));
  56. -
  57. -void FLASHDcacheFlushInvalidate()
  58. -{
  59. - unsigned long set;
  60. - unsigned long start_set;
  61. - unsigned long end_set;
  62. -
  63. - start_set = 0;
  64. - end_set = (unsigned long)LAST_DCACHE_ADDR;
  65. -
  66. - for (set = start_set; set < end_set; set += (0x10 - 3))
  67. - asm volatile("cpushl %%dc,(%0)\n"
  68. - "\taddq%.l #1,%0\n"
  69. - "\tcpushl %%dc,(%0)\n"
  70. - "\taddq%.l #1,%0\n"
  71. - "\tcpushl %%dc,(%0)\n"
  72. - "\taddq%.l #1,%0\n"
  73. - "\tcpushl %%dc,(%0)" : : "a" (set));
  74. -}
  75. -
  76. -/************************************************************
  77. - * Routine to cleanly flush the cache, pushing all lines and
  78. - * invalidating them.
  79. - *
  80. - *************************************************************/
  81. -void DcacheFlushInvalidate()
  82. -{
  83. - unsigned long set;
  84. - unsigned long start_set;
  85. - unsigned long end_set;
  86. -
  87. - start_set = 0;
  88. - end_set = (unsigned long)LAST_DCACHE_ADDR;
  89. -
  90. - for (set = start_set; set < end_set; set += (0x10 - 3))
  91. - asm volatile("cpushl %%dc,(%0)\n"
  92. - "\taddq%.l #1,%0\n"
  93. - "\tcpushl %%dc,(%0)\n"
  94. - "\taddq%.l #1,%0\n"
  95. - "\tcpushl %%dc,(%0)\n"
  96. - "\taddq%.l #1,%0\n"
  97. - "\tcpushl %%dc,(%0)" : : "a" (set));
  98. -}
  99. -
  100. -
  101. -
  102. -/******************************************************************************
  103. - * Routine to cleanly flush the a block of cache, pushing all relevant lines
  104. - * and invalidating them.
  105. - *
  106. - ******************************************************************************/
  107. -void DcacheFlushInvalidateCacheBlock(void *start, unsigned long size)
  108. -{
  109. - unsigned long set;
  110. - unsigned long start_set;
  111. - unsigned long end_set;
  112. -
  113. - /* if size is bigger than the cache can store
  114. - * set the size to the maximum amount
  115. - */
  116. -
  117. - if (size > LAST_DCACHE_ADDR)
  118. - size = LAST_DCACHE_ADDR;
  119. -
  120. - start_set = ((unsigned long)start) & _DCACHE_SET_MASK;
  121. - end_set = ((unsigned long)(start+size-1)) & _DCACHE_SET_MASK;
  122. -
  123. - if (start_set > end_set) {
  124. - /* from the begining to the lowest address */
  125. - for (set = 0; set <= end_set; set += (0x10 - 3))
  126. - asm volatile("cpushl %%dc,(%0)\n"
  127. - "\taddq%.l #1,%0\n"
  128. - "\tcpushl %%dc,(%0)\n"
  129. - "\taddq%.l #1,%0\n"
  130. - "\tcpushl %%dc,(%0)\n"
  131. - "\taddq%.l #1,%0\n"
  132. - "\tcpushl %%dc,(%0)" : : "a" (set));
  133. -
  134. - /* next loop will finish the cache ie pass the hole */
  135. - end_set = LAST_DCACHE_ADDR;
  136. - }
  137. - for (set = start_set; set <= end_set; set += (0x10 - 3))
  138. - asm volatile("cpushl %%dc,(%0)\n"
  139. - "\taddq%.l #1,%0\n"
  140. - "\tcpushl %%dc,(%0)\n"
  141. - "\taddq%.l #1,%0\n"
  142. - "\tcpushl %%dc,(%0)\n"
  143. - "\taddq%.l #1,%0\n"
  144. - "\tcpushl %%dc,(%0)" : : "a" (set));
  145. -}
  146. -
  147. -
  148. -void IcacheInvalidateCacheBlock(void *start, unsigned long size)
  149. -{
  150. - unsigned long set;
  151. - unsigned long start_set;
  152. - unsigned long end_set;
  153. -
  154. - /* if size is bigger than the cache can store
  155. - * set the size to the maximum ammount
  156. - */
  157. -
  158. - if (size > LAST_ICACHE_ADDR)
  159. - size = LAST_ICACHE_ADDR;
  160. -
  161. - start_set = ((unsigned long)start) & _ICACHE_SET_MASK;
  162. - end_set = ((unsigned long)(start+size-1)) & _ICACHE_SET_MASK;
  163. -
  164. - if (start_set > end_set) {
  165. - /* from the begining to the lowest address */
  166. - for (set = 0; set <= end_set; set += (0x10 - 3))
  167. - asm volatile("cpushl %%ic,(%0)\n"
  168. - "\taddq%.l #1,%0\n"
  169. - "\tcpushl %%ic,(%0)\n"
  170. - "\taddq%.l #1,%0\n"
  171. - "\tcpushl %%ic,(%0)\n"
  172. - "\taddq%.l #1,%0\n"
  173. - "\tcpushl %%ic,(%0)" : : "a" (set));
  174. -
  175. - /* next loop will finish the cache ie pass the hole */
  176. - end_set = LAST_ICACHE_ADDR;
  177. - }
  178. - for (set = start_set; set <= end_set; set += (0x10 - 3))
  179. - asm volatile("cpushl %%ic,(%0)\n"
  180. - "\taddq%.l #1,%0\n"
  181. - "\tcpushl %%ic,(%0)\n"
  182. - "\taddq%.l #1,%0\n"
  183. - "\tcpushl %%ic,(%0)\n"
  184. - "\taddq%.l #1,%0\n"
  185. - "\tcpushl %%ic,(%0)" : : "a" (set));
  186. -}
  187. -
  188. -
  189. -/********************************************************************
  190. - * Disable the data cache completely
  191. - ********************************************************************/
  192. -void DcacheDisable(void)
  193. -{
  194. - int newValue;
  195. - unsigned long flags;
  196. -
  197. - local_save_flags(flags);
  198. - local_irq_disable();
  199. -
  200. - DcacheFlushInvalidate(); /* begin by flushing the cache */
  201. - newValue = CACHE_DISABLE_MODE; /* disable it */
  202. - cacr_set(newValue);
  203. - local_irq_restore(flags);
  204. -}
  205. -
  206. -/********************************************************************
  207. - * Unconditionally enable the data cache
  208. - ********************************************************************/
  209. -void DcacheEnable(void)
  210. -{
  211. - cacr_set(CACHE_INITIAL_MODE);
  212. -}
  213. -
  214. -
  215. +/* Cache Control Reg shadow reg */
  216. unsigned long shadow_cacr;
  217. +/**
  218. + * cacr_set - Set the Cache Control Register
  219. + * @x Value to set
  220. + */
  221. void cacr_set(unsigned long x)
  222. {
  223. shadow_cacr = x;
  224. @@ -209,6 +32,11 @@ void cacr_set(unsigned long x)
  225. : "r" (shadow_cacr));
  226. }
  227. +/**
  228. + * cacr_get - Get the current value of the Cache Control Register
  229. + *
  230. + * @return CACR value
  231. + */
  232. unsigned long cacr_get(void)
  233. {
  234. return shadow_cacr;
  235. --- a/arch/m68k/coldfire/head.S
  236. +++ b/arch/m68k/coldfire/head.S
  237. @@ -244,7 +244,7 @@ ENTRY(__start)
  238. /* Setup initial stack pointer */
  239. movel #0x40001000,%sp
  240. -/* Clear usp */
  241. +/* Setup usp */
  242. subl %a0,%a0
  243. movel %a0,%usp
  244. @@ -252,6 +252,10 @@ ENTRY(__start)
  245. movec %d0, %rambar1
  246. movew #0x2700,%sr
  247. +/* reset cache */
  248. + movel #(CF_CACR_ICINVA + CF_CACR_DCINVA),%d0
  249. + movecl %d0,%cacr
  250. +
  251. movel #(MMU_BASE+1),%d0
  252. movecl %d0,%mmubar
  253. movel #MMUOR_CA,%a0 /* Clear tlb entries */
  254. --- a/arch/m68k/coldfire/signal.c
  255. +++ b/arch/m68k/coldfire/signal.c
  256. @@ -37,6 +37,7 @@
  257. #include <asm/cf_pgtable.h>
  258. #include <asm/traps.h>
  259. #include <asm/ucontext.h>
  260. +#include <asm/cacheflush.h>
  261. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  262. @@ -605,10 +606,9 @@ static inline int rt_setup_ucontext(stru
  263. return err;
  264. }
  265. -extern void IcacheInvalidateCacheBlock(void *, unsigned long);
  266. static inline void push_cache(unsigned long vaddr)
  267. {
  268. - IcacheInvalidateCacheBlock((void *)vaddr, 8);
  269. + cf_cache_push(__pa(vaddr), 8);
  270. }
  271. static inline void __user *
  272. --- a/arch/m68k/kernel/sys_m68k.c
  273. +++ b/arch/m68k/kernel/sys_m68k.c
  274. @@ -29,6 +29,9 @@
  275. #include <asm/traps.h>
  276. #include <asm/page.h>
  277. #include <asm/unistd.h>
  278. +#ifdef CONFIG_COLDFIRE
  279. +#include <asm/cacheflush.h>
  280. +#endif
  281. /*
  282. * sys_pipe() is the normal C calling standard for creating
  283. @@ -257,6 +260,7 @@ asmlinkage int sys_ipc (uint call, int f
  284. return -EINVAL;
  285. }
  286. +#ifndef CONFIG_COLDFIRE
  287. /* Convert virtual (user) address VADDR to physical address PADDR */
  288. #define virt_to_phys_040(vaddr) \
  289. ({ \
  290. @@ -580,6 +584,7 @@ cache_flush_060 (unsigned long addr, int
  291. }
  292. return 0;
  293. }
  294. +#endif /* CONFIG_COLDFIRE */
  295. /* sys_cacheflush -- flush (part of) the processor cache. */
  296. asmlinkage int
  297. @@ -612,6 +617,7 @@ sys_cacheflush (unsigned long addr, int
  298. goto out;
  299. }
  300. +#ifndef CONFIG_COLDFIRE
  301. if (CPU_IS_020_OR_030) {
  302. if (scope == FLUSH_SCOPE_LINE && len < 256) {
  303. unsigned long cacr;
  304. @@ -656,6 +662,16 @@ sys_cacheflush (unsigned long addr, int
  305. ret = cache_flush_060 (addr, scope, cache, len);
  306. }
  307. }
  308. +#else /* CONFIG_COLDFIRE */
  309. + if ((cache & FLUSH_CACHE_INSN) && (cache & FLUSH_CACHE_DATA))
  310. + flush_bcache();
  311. + else if (cache & FLUSH_CACHE_INSN)
  312. + flush_icache();
  313. + else
  314. + flush_dcache();
  315. +
  316. + ret = 0;
  317. +#endif /* CONFIG_COLDFIRE */
  318. out:
  319. unlock_kernel();
  320. return ret;
  321. --- a/arch/m68k/mm/cache.c
  322. +++ b/arch/m68k/mm/cache.c
  323. @@ -81,36 +81,7 @@ static unsigned long virt_to_phys_slow(u
  324. void flush_icache_range(unsigned long address, unsigned long endaddr)
  325. {
  326. #ifdef CONFIG_COLDFIRE
  327. - unsigned long set;
  328. - unsigned long start_set;
  329. - unsigned long end_set;
  330. -
  331. - start_set = address & _ICACHE_SET_MASK;
  332. - end_set = endaddr & _ICACHE_SET_MASK;
  333. -
  334. - if (start_set > end_set) {
  335. - /* from the begining to the lowest address */
  336. - for (set = 0; set <= end_set; set += (0x10 - 3))
  337. - asm volatile ("cpushl %%ic,(%0)\n"
  338. - "\taddq%.l #1,%0\n"
  339. - "\tcpushl %%ic,(%0)\n"
  340. - "\taddq%.l #1,%0\n"
  341. - "\tcpushl %%ic,(%0)\n"
  342. - "\taddq%.l #1,%0\n"
  343. - "\tcpushl %%ic,(%0)" : : "a" (set));
  344. -
  345. - /* next loop will finish the cache ie pass the hole */
  346. - end_set = LAST_ICACHE_ADDR;
  347. - }
  348. - for (set = start_set; set <= end_set; set += (0x10 - 3))
  349. - asm volatile ("cpushl %%ic,(%0)\n"
  350. - "\taddq%.l #1,%0\n"
  351. - "\tcpushl %%ic,(%0)\n"
  352. - "\taddq%.l #1,%0\n"
  353. - "\tcpushl %%ic,(%0)\n"
  354. - "\taddq%.l #1,%0\n"
  355. - "\tcpushl %%ic,(%0)" : : "a" (set));
  356. -
  357. + cf_icache_flush_range(address, endaddr);
  358. #else /* !CONFIG_COLDFIRE */
  359. if (CPU_IS_040_OR_060) {
  360. --- a/arch/m68k/mm/memory.c
  361. +++ b/arch/m68k/mm/memory.c
  362. @@ -127,6 +127,7 @@ int free_pointer_table (pmd_t *ptable)
  363. return 0;
  364. }
  365. +#ifndef CONFIG_COLDFIRE
  366. /* invalidate page in both caches */
  367. static inline void clear040(unsigned long paddr)
  368. {
  369. @@ -173,6 +174,7 @@ static inline void pushcl040(unsigned lo
  370. clear040(paddr);
  371. local_irq_restore(flags);
  372. }
  373. +#endif /* CONFIG_COLDFIRE */
  374. /*
  375. * 040: Hit every page containing an address in the range paddr..paddr+len-1.
  376. @@ -203,38 +205,10 @@ static inline void pushcl040(unsigned lo
  377. void cache_clear (unsigned long paddr, int len)
  378. {
  379. - if (CPU_IS_CFV4E) {
  380. - unsigned long set;
  381. - unsigned long start_set;
  382. - unsigned long end_set;
  383. -
  384. - start_set = paddr & _ICACHE_SET_MASK;
  385. - end_set = (paddr+len-1) & _ICACHE_SET_MASK;
  386. -
  387. - if (start_set > end_set) {
  388. - /* from the begining to the lowest address */
  389. - for (set = 0; set <= end_set; set += (0x10 - 3))
  390. - asm volatile("cpushl %%bc,(%0)\n"
  391. - "\taddq%.l #1,%0\n"
  392. - "\tcpushl %%bc,(%0)\n"
  393. - "\taddq%.l #1,%0\n"
  394. - "\tcpushl %%bc,(%0)\n"
  395. - "\taddq%.l #1,%0\n"
  396. - "\tcpushl %%bc,(%0)" : : "a" (set));
  397. -
  398. - /* next loop will finish the cache ie pass the hole */
  399. - end_set = LAST_ICACHE_ADDR;
  400. - }
  401. - for (set = start_set; set <= end_set; set += (0x10 - 3))
  402. - asm volatile("cpushl %%bc,(%0)\n"
  403. - "\taddq%.l #1,%0\n"
  404. - "\tcpushl %%bc,(%0)\n"
  405. - "\taddq%.l #1,%0\n"
  406. - "\tcpushl %%bc,(%0)\n"
  407. - "\taddq%.l #1,%0\n"
  408. - "\tcpushl %%bc,(%0)" : : "a" (set));
  409. -
  410. - } else if (CPU_IS_040_OR_060) {
  411. +#ifdef CONFIG_COLDFIRE
  412. + cf_cache_clear(paddr, len);
  413. +#else
  414. + if (CPU_IS_040_OR_060) {
  415. int tmp;
  416. /*
  417. @@ -268,6 +242,7 @@ void cache_clear (unsigned long paddr, i
  418. if(mach_l2_flush)
  419. mach_l2_flush(0);
  420. #endif
  421. +#endif /* CONFIG_COLDFIRE */
  422. }
  423. EXPORT_SYMBOL(cache_clear);
  424. @@ -281,38 +256,10 @@ EXPORT_SYMBOL(cache_clear);
  425. void cache_push (unsigned long paddr, int len)
  426. {
  427. - if (CPU_IS_CFV4E) {
  428. - unsigned long set;
  429. - unsigned long start_set;
  430. - unsigned long end_set;
  431. -
  432. - start_set = paddr & _ICACHE_SET_MASK;
  433. - end_set = (paddr+len-1) & _ICACHE_SET_MASK;
  434. -
  435. - if (start_set > end_set) {
  436. - /* from the begining to the lowest address */
  437. - for (set = 0; set <= end_set; set += (0x10 - 3))
  438. - asm volatile("cpushl %%bc,(%0)\n"
  439. - "\taddq%.l #1,%0\n"
  440. - "\tcpushl %%bc,(%0)\n"
  441. - "\taddq%.l #1,%0\n"
  442. - "\tcpushl %%bc,(%0)\n"
  443. - "\taddq%.l #1,%0\n"
  444. - "\tcpushl %%bc,(%0)" : : "a" (set));
  445. -
  446. - /* next loop will finish the cache ie pass the hole */
  447. - end_set = LAST_ICACHE_ADDR;
  448. - }
  449. - for (set = start_set; set <= end_set; set += (0x10 - 3))
  450. - asm volatile("cpushl %%bc,(%0)\n"
  451. - "\taddq%.l #1,%0\n"
  452. - "\tcpushl %%bc,(%0)\n"
  453. - "\taddq%.l #1,%0\n"
  454. - "\tcpushl %%bc,(%0)\n"
  455. - "\taddq%.l #1,%0\n"
  456. - "\tcpushl %%bc,(%0)" : : "a" (set));
  457. -
  458. - } else if (CPU_IS_040_OR_060) {
  459. +#ifdef CONFIG_COLDFIRE
  460. + cf_cache_push(paddr, len);
  461. +#else
  462. + if (CPU_IS_040_OR_060) {
  463. int tmp = PAGE_SIZE;
  464. /*
  465. @@ -352,6 +299,7 @@ void cache_push (unsigned long paddr, in
  466. if(mach_l2_flush)
  467. mach_l2_flush(1);
  468. #endif
  469. +#endif /* CONFIG_COLDFIRE */
  470. }
  471. EXPORT_SYMBOL(cache_push);
  472. --- a/include/asm-m68k/cf_cacheflush.h
  473. +++ b/include/asm-m68k/cf_cacheflush.h
  474. @@ -1,160 +1,439 @@
  475. +/*
  476. + * include/asm-m68k/cf_cacheflush.h - Coldfire Cache
  477. + *
  478. + * Based on include/asm-m68k/cacheflush.h
  479. + *
  480. + * Coldfire pieces by:
  481. + * Kurt Mahan [email protected]
  482. + *
  483. + * Copyright Freescale Semiconductor, Inc. 2007
  484. + *
  485. + * This program is free software; you can redistribute it and/or modify it
  486. + * under the terms of the GNU General Public License as published by the
  487. + * Free Software Foundation; either version 2 of the License, or (at your
  488. + * option) any later version.
  489. + */
  490. #ifndef M68K_CF_CACHEFLUSH_H
  491. #define M68K_CF_CACHEFLUSH_H
  492. #include <asm/cfcache.h>
  493. /*
  494. - * Cache handling functions
  495. + * Coldfire Cache Model
  496. + *
  497. + * The Coldfire processors use a Harvard architecture cache configured
  498. + * as four-way set associative. The cache does not implement bus snooping
  499. + * so cache coherency with other masters must be maintained in software.
  500. + *
  501. + * The cache is managed via the CPUSHL instruction in conjunction with
  502. + * bits set in the CACR (cache control register). Currently the code
  503. + * uses the CPUSHL enhancement which adds the ability to
  504. + * invalidate/clear/push a cacheline by physical address. This feature
  505. + * is designated in the Hardware Configuration Register [D1-CPES].
  506. + *
  507. + * CACR Bits:
  508. + * DPI[28] cpushl invalidate disable for d-cache
  509. + * IDPI[12] cpushl invalidate disable for i-cache
  510. + * SPA[14] cpushl search by physical address
  511. + * IVO[20] cpushl invalidate only
  512. + *
  513. + * Random Terminology:
  514. + * * invalidate = reset the cache line's valid bit
  515. + * * push = generate a line-sized store of the data if its contents are marked
  516. + * as modifed (the modified flag is cleared after the store)
  517. + * * clear = push + invalidate
  518. */
  519. -#define flush_icache() \
  520. -({ \
  521. - unsigned long set; \
  522. - unsigned long start_set; \
  523. - unsigned long end_set; \
  524. - \
  525. - start_set = 0; \
  526. - end_set = (unsigned long)LAST_DCACHE_ADDR; \
  527. - \
  528. - for (set = start_set; set <= end_set; set += (0x10 - 3)) \
  529. - asm volatile("cpushl %%ic,(%0)\n" \
  530. - "\taddq%.l #1,%0\n" \
  531. - "\tcpushl %%ic,(%0)\n" \
  532. - "\taddq%.l #1,%0\n" \
  533. - "\tcpushl %%ic,(%0)\n" \
  534. - "\taddq%.l #1,%0\n" \
  535. - "\tcpushl %%ic,(%0)" : : "a" (set)); \
  536. -})
  537. +/**
  538. + * flush_icache - Flush all of the instruction cache
  539. + */
  540. +static inline void flush_icache(void)
  541. +{
  542. + asm volatile("nop\n"
  543. + "moveq%.l #0,%%d0\n"
  544. + "moveq%.l #0,%%d1\n"
  545. + "move%.l %%d0,%%a0\n"
  546. + "1:\n"
  547. + "cpushl %%ic,(%%a0)\n"
  548. + "add%.l #0x0010,%%a0\n"
  549. + "addq%.l #1,%%d1\n"
  550. + "cmpi%.l %0,%%d1\n"
  551. + "bne 1b\n"
  552. + "moveq%.l #0,%%d1\n"
  553. + "addq%.l #1,%%d0\n"
  554. + "move%.l %%d0,%%a0\n"
  555. + "cmpi%.l #4,%%d0\n"
  556. + "bne 1b\n"
  557. + : : "i" (CACHE_SETS)
  558. + : "a0", "d0", "d1");
  559. +}
  560. -/*
  561. - * invalidate the cache for the specified memory range.
  562. - * It starts at the physical address specified for
  563. - * the given number of bytes.
  564. +/**
  565. + * flush_dcache - Flush all of the data cache
  566. */
  567. -extern void cache_clear(unsigned long paddr, int len);
  568. -/*
  569. - * push any dirty cache in the specified memory range.
  570. - * It starts at the physical address specified for
  571. - * the given number of bytes.
  572. +static inline void flush_dcache(void)
  573. +{
  574. + asm volatile("nop\n"
  575. + "moveq%.l #0,%%d0\n"
  576. + "moveq%.l #0,%%d1\n"
  577. + "move%.l %%d0,%%a0\n"
  578. + "1:\n"
  579. + "cpushl %%dc,(%%a0)\n"
  580. + "add%.l #0x0010,%%a0\n"
  581. + "addq%.l #1,%%d1\n"
  582. + "cmpi%.l %0,%%d1\n"
  583. + "bne 1b\n"
  584. + "moveq%.l #0,%%d1\n"
  585. + "addq%.l #1,%%d0\n"
  586. + "move%.l %%d0,%%a0\n"
  587. + "cmpi%.l #4,%%d0\n"
  588. + "bne 1b\n"
  589. + : : "i" (CACHE_SETS)
  590. + : "a0", "d0", "d1");
  591. +}
  592. +
  593. +/**
  594. + * flush_bcache - Flush all of both caches
  595. */
  596. -extern void cache_push(unsigned long paddr, int len);
  597. +static inline void flush_bcache(void)
  598. +{
  599. + asm volatile("nop\n"
  600. + "moveq%.l #0,%%d0\n"
  601. + "moveq%.l #0,%%d1\n"
  602. + "move%.l %%d0,%%a0\n"
  603. + "1:\n"
  604. + "cpushl %%bc,(%%a0)\n"
  605. + "add%.l #0x0010,%%a0\n"
  606. + "addq%.l #1,%%d1\n"
  607. + "cmpi%.l %0,%%d1\n"
  608. + "bne 1b\n"
  609. + "moveq%.l #0,%%d1\n"
  610. + "addq%.l #1,%%d0\n"
  611. + "move%.l %%d0,%%a0\n"
  612. + "cmpi%.l #4,%%d0\n"
  613. + "bne 1b\n"
  614. + : : "i" (CACHE_SETS)
  615. + : "a0", "d0", "d1");
  616. +}
  617. -/*
  618. - * push and invalidate pages in the specified user virtual
  619. - * memory range.
  620. +/**
  621. + * cf_cache_clear - invalidate cache
  622. + * @paddr: starting physical address
  623. + * @len: number of bytes
  624. + *
  625. + * Invalidate cache lines starting at paddr for len bytes.
  626. + * Those lines are not pushed.
  627. + */
  628. +static inline void cf_cache_clear(unsigned long paddr, int len)
  629. +{
  630. + /* number of lines */
  631. + len = (len + (CACHE_LINE_SIZE-1)) / CACHE_LINE_SIZE;
  632. +
  633. + /* align on set boundary */
  634. + paddr &= 0xfffffff0;
  635. +
  636. + asm volatile("nop\n"
  637. + "move%.l %2,%%d0\n"
  638. + "or%.l %3,%%d0\n"
  639. + "movec %%d0,%%cacr\n"
  640. + "move%.l %0,%%a0\n"
  641. + "move%.l %1,%%d0\n"
  642. + "1:\n"
  643. + "cpushl %%bc,(%%a0)\n"
  644. + "lea 0x10(%%a0),%%a0\n"
  645. + "subq%.l #1,%%d0\n"
  646. + "bne%.b 1b\n"
  647. + "movec %2,%%cacr\n"
  648. + : : "a" (paddr), "r" (len),
  649. + "r" (shadow_cacr),
  650. + "i" (CF_CACR_SPA+CF_CACR_IVO)
  651. + : "a0", "d0");
  652. +}
  653. +
  654. +/**
  655. + * cf_cache_push - Push dirty cache out with no invalidate
  656. + * @paddr: starting physical address
  657. + * @len: number of bytes
  658. + *
  659. + * Push the any dirty lines starting at paddr for len bytes.
  660. + * Those lines are not invalidated.
  661. + */
  662. +static inline void cf_cache_push(unsigned long paddr, int len)
  663. +{
  664. + /* number of lines */
  665. + len = (len + (CACHE_LINE_SIZE-1)) / CACHE_LINE_SIZE;
  666. +
  667. + /* align on set boundary */
  668. + paddr &= 0xfffffff0;
  669. +
  670. + asm volatile("nop\n"
  671. + "move%.l %2,%%d0\n"
  672. + "or%.l %3,%%d0\n"
  673. + "movec %%d0,%%cacr\n"
  674. + "move%.l %0,%%a0\n"
  675. + "move%.l %1,%%d0\n"
  676. + "1:\n"
  677. + "cpushl %%bc,(%%a0)\n"
  678. + "lea 0x10(%%a0),%%a0\n"
  679. + "subq%.l #1,%%d0\n"
  680. + "bne.b 1b\n"
  681. + "movec %2,%%cacr\n"
  682. + : : "a" (paddr), "r" (len),
  683. + "r" (shadow_cacr),
  684. + "i" (CF_CACR_SPA+CF_CACR_DPI+CF_CACR_IDPI)
  685. + : "a0", "d0");
  686. +}
  687. +
  688. +/**
  689. + * cf_cache_flush - Push dirty cache out and invalidate
  690. + * @paddr: starting physical address
  691. + * @len: number of bytes
  692. + *
  693. + * Push the any dirty lines starting at paddr for len bytes and
  694. + * invalidate those lines.
  695. + */
  696. +static inline void cf_cache_flush(unsigned long paddr, int len)
  697. +{
  698. + /* number of lines */
  699. + len = (len + (CACHE_LINE_SIZE-1)) / CACHE_LINE_SIZE;
  700. +
  701. + /* align on set boundary */
  702. + paddr &= 0xfffffff0;
  703. +
  704. + asm volatile("nop\n"
  705. + "move%.l %2,%%d0\n"
  706. + "or%.l %3,%%d0\n"
  707. + "movec %%d0,%%cacr\n"
  708. + "move%.l %0,%%a0\n"
  709. + "move%.l %1,%%d0\n"
  710. + "1:\n"
  711. + "cpushl %%bc,(%%a0)\n"
  712. + "lea 0x10(%%a0),%%a0\n"
  713. + "subq%.l #1,%%d0\n"
  714. + "bne.b 1b\n"
  715. + "movec %2,%%cacr\n"
  716. + : : "a" (paddr), "r" (len),
  717. + "r" (shadow_cacr),
  718. + "i" (CF_CACR_SPA)
  719. + : "a0", "d0");
  720. +}
  721. +
  722. +/**
  723. + * cf_cache_flush_range - Push dirty data/inst cache in range out and invalidate
  724. + * @vstart - starting virtual address
  725. + * @vend: ending virtual address
  726. + *
  727. + * Push the any dirty data/instr lines starting at paddr for len bytes and
  728. + * invalidate those lines.
  729. + */
  730. +static inline void cf_cache_flush_range(unsigned long vstart, unsigned long vend)
  731. +{
  732. + int len;
  733. +
  734. + /* align on set boundary */
  735. + vstart &= 0xfffffff0;
  736. + vend = PAGE_ALIGN((vend + (CACHE_LINE_SIZE-1))) & 0xfffffff0;
  737. + len = vend - vstart;
  738. + vstart = __pa(vstart);
  739. + vend = vstart + len;
  740. +
  741. + asm volatile("nop\n"
  742. + "move%.l %2,%%d0\n"
  743. + "or%.l %3,%%d0\n"
  744. + "movec %%d0,%%cacr\n"
  745. + "move%.l %0,%%a0\n"
  746. + "move%.l %1,%%a1\n"
  747. + "1:\n"
  748. + "cpushl %%bc,(%%a0)\n"
  749. + "lea 0x10(%%a0),%%a0\n"
  750. + "cmpa%.l %%a0,%%a1\n"
  751. + "bne.b 1b\n"
  752. + "movec %2,%%cacr\n"
  753. + : /* no return */
  754. + : "a" (vstart), "a" (vend),
  755. + "r" (shadow_cacr),
  756. + "i" (CF_CACR_SPA)
  757. + : "a0", "a1", "d0");
  758. +}
  759. +
  760. +/**
  761. + * cf_dcache_flush_range - Push dirty data cache in range out and invalidate
  762. + * @vstart - starting virtual address
  763. + * @vend: ending virtual address
  764. + *
  765. + * Push the any dirty data lines starting at paddr for len bytes and
  766. + * invalidate those lines.
  767. + */
  768. +static inline void cf_dcache_flush_range(unsigned long vstart, unsigned long vend)
  769. +{
  770. + /* align on set boundary */
  771. + vstart &= 0xfffffff0;
  772. + vend = (vend + (CACHE_LINE_SIZE-1)) & 0xfffffff0;
  773. +
  774. + asm volatile("nop\n"
  775. + "move%.l %2,%%d0\n"
  776. + "or%.l %3,%%d0\n"
  777. + "movec %%d0,%%cacr\n"
  778. + "move%.l %0,%%a0\n"
  779. + "move%.l %1,%%a1\n"
  780. + "1:\n"
  781. + "cpushl %%dc,(%%a0)\n"
  782. + "lea 0x10(%%a0),%%a0\n"
  783. + "cmpa%.l %%a0,%%a1\n"
  784. + "bne.b 1b\n"
  785. + "movec %2,%%cacr\n"
  786. + : /* no return */
  787. + : "a" (__pa(vstart)), "a" (__pa(vend)),
  788. + "r" (shadow_cacr),
  789. + "i" (CF_CACR_SPA)
  790. + : "a0", "a1", "d0");
  791. +}
  792. +
  793. +/**
  794. + * cf_icache_flush_range - Push dirty inst cache in range out and invalidate
  795. + * @vstart - starting virtual address
  796. + * @vend: ending virtual address
  797. + *
  798. + * Push the any dirty instr lines starting at paddr for len bytes and
  799. + * invalidate those lines. This should just be an invalidate since you
  800. + * shouldn't be able to have dirty instruction cache.
  801. */
  802. -extern void cache_push_v(unsigned long vaddr, int len);
  803. +static inline void cf_icache_flush_range(unsigned long vstart, unsigned long vend)
  804. +{
  805. + /* align on set boundary */
  806. + vstart &= 0xfffffff0;
  807. + vend = (vend + (CACHE_LINE_SIZE-1)) & 0xfffffff0;
  808. +
  809. + asm volatile("nop\n"
  810. + "move%.l %2,%%d0\n"
  811. + "or%.l %3,%%d0\n"
  812. + "movec %%d0,%%cacr\n"
  813. + "move%.l %0,%%a0\n"
  814. + "move%.l %1,%%a1\n"
  815. + "1:\n"
  816. + "cpushl %%ic,(%%a0)\n"
  817. + "lea 0x10(%%a0),%%a0\n"
  818. + "cmpa%.l %%a0,%%a1\n"
  819. + "bne.b 1b\n"
  820. + "movec %2,%%cacr\n"
  821. + : /* no return */
  822. + : "a" (__pa(vstart)), "a" (__pa(vend)),
  823. + "r" (shadow_cacr),
  824. + "i" (CF_CACR_SPA)
  825. + : "a0", "a1", "d0");
  826. +}
  827. -/* This is needed whenever the virtual mapping of the current
  828. - process changes. */
  829. +/**
  830. + * flush_cache_mm - Flush an mm_struct
  831. + * @mm: mm_struct to flush
  832. + */
  833. +static inline void flush_cache_mm(struct mm_struct *mm)
  834. +{
  835. + if (mm == current->mm)
  836. + flush_bcache();
  837. +}
  838. +#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  839. -#define flush_cache_all() do { } while (0)
  840. -#define flush_cache_mm(mm) do { } while (0)
  841. -#define flush_cache_range(mm, a, b) do { } while (0)
  842. -#define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
  843. -
  844. -#define flush_dcache_range(paddr, len) do { } while (0)
  845. -
  846. -/* Push the page at kernel virtual address and clear the icache */
  847. -/* use cpush %bc instead of cpush %dc, cinv %ic */
  848. -#define flush_page_to_ram(page) __flush_page_to_ram((void *) page_address(page))
  849. -extern inline void __flush_page_to_ram(void *address)
  850. -{
  851. - unsigned long set;
  852. - unsigned long start_set;
  853. - unsigned long end_set;
  854. - unsigned long addr = (unsigned long) address;
  855. -
  856. - addr &= ~(PAGE_SIZE - 1); /* round down to page start address */
  857. -
  858. - start_set = addr & _ICACHE_SET_MASK;
  859. - end_set = (addr + PAGE_SIZE-1) & _ICACHE_SET_MASK;
  860. -
  861. - if (start_set > end_set) {
  862. - /* from the begining to the lowest address */
  863. - for (set = 0; set <= end_set; set += (0x10 - 3))
  864. - asm volatile("cpushl %%bc,(%0)\n"
  865. - "\taddq%.l #1,%0\n"
  866. - "\tcpushl %%bc,(%0)\n"
  867. - "\taddq%.l #1,%0\n"
  868. - "\tcpushl %%bc,(%0)\n"
  869. - "\taddq%.l #1,%0\n"
  870. - "\tcpushl %%bc,(%0)" : : "a" (set));
  871. -
  872. - /* next loop will finish the cache ie pass the hole */
  873. - end_set = LAST_ICACHE_ADDR;
  874. - }
  875. - for (set = start_set; set <= end_set; set += (0x10 - 3))
  876. - asm volatile("cpushl %%bc,(%0)\n"
  877. - "\taddq%.l #1,%0\n"
  878. - "\tcpushl %%bc,(%0)\n"
  879. - "\taddq%.l #1,%0\n"
  880. - "\tcpushl %%bc,(%0)\n"
  881. - "\taddq%.l #1,%0\n"
  882. - "\tcpushl %%bc,(%0)" : : "a" (set));
  883. -}
  884. -
  885. -#define flush_dcache_page(page) do { } while (0)
  886. -#define flush_icache_page(vma, pg) do { } while (0)
  887. -#define flush_icache_user_range(adr, len) do { } while (0)
  888. -/* NL */
  889. -#define flush_icache_user_page(vma, page, addr, len) do { } while (0)
  890. -
  891. -/* Push n pages at kernel virtual address and clear the icache */
  892. -/* use cpush %bc instead of cpush %dc, cinv %ic */
  893. -extern inline void flush_icache_range(unsigned long address,
  894. - unsigned long endaddr)
  895. -{
  896. - unsigned long set;
  897. - unsigned long start_set;
  898. - unsigned long end_set;
  899. -
  900. - start_set = address & _ICACHE_SET_MASK;
  901. - end_set = endaddr & _ICACHE_SET_MASK;
  902. -
  903. - if (start_set > end_set) {
  904. - /* from the begining to the lowest address */
  905. - for (set = 0; set <= end_set; set += (0x10 - 3))
  906. - asm volatile("cpushl %%ic,(%0)\n"
  907. - "\taddq%.l #1,%0\n"
  908. - "\tcpushl %%ic,(%0)\n"
  909. - "\taddq%.l #1,%0\n"
  910. - "\tcpushl %%ic,(%0)\n"
  911. - "\taddq%.l #1,%0\n"
  912. - "\tcpushl %%ic,(%0)" : : "a" (set));
  913. -
  914. - /* next loop will finish the cache ie pass the hole */
  915. - end_set = LAST_ICACHE_ADDR;
  916. - }
  917. - for (set = start_set; set <= end_set; set += (0x10 - 3))
  918. - asm volatile("cpushl %%ic,(%0)\n"
  919. - "\taddq%.l #1,%0\n"
  920. - "\tcpushl %%ic,(%0)\n"
  921. - "\taddq%.l #1,%0\n"
  922. - "\tcpushl %%ic,(%0)\n"
  923. - "\taddq%.l #1,%0\n"
  924. - "\tcpushl %%ic,(%0)" : : "a" (set));
  925. +/**
  926. + * flush_cache_range - Flush a cache range
  927. + * @vma: vma struct
  928. + * @start: Starting address
  929. + * @end: Ending address
  930. + *
  931. + * flush_cache_range must be a macro to avoid a dependency on
  932. + * linux/mm.h which includes this file.
  933. + */
  934. +static inline void flush_cache_range(struct vm_area_struct *vma,
  935. + unsigned long start, unsigned long end)
  936. +{
  937. + if (vma->vm_mm == current->mm)
  938. + cf_cache_flush_range(start, end);
  939. }
  940. +/**
  941. + * flush_cache_page - Flush a page of the cache
  942. + * @vma: vma struct
  943. + * @vmaddr:
  944. + * @pfn: page numer
  945. + *
  946. + * flush_cache_page must be a macro to avoid a dependency on
  947. + * linux/mm.h which includes this file.
  948. + */
  949. +static inline void flush_cache_page(struct vm_area_struct *vma,
  950. + unsigned long vmaddr, unsigned long pfn)
  951. +{
  952. + if (vma->vm_mm == current->mm)
  953. + cf_cache_flush_range(vmaddr, vmaddr+PAGE_SIZE);
  954. +}
  955. +
  956. +/**
  957. + * __flush_page_to_ram - Push a page out of the cache
  958. + * @vaddr: Virtual address at start of page
  959. + *
  960. + * Push the page at kernel virtual address *vaddr* and clear
  961. + * the icache.
  962. + */
  963. +static inline void __flush_page_to_ram(void *vaddr)
  964. +{
  965. + asm volatile("nop\n"
  966. + "move%.l %2,%%d0\n"
  967. + "or%.l %3,%%d0\n"
  968. + "movec %%d0,%%cacr\n"
  969. + "move%.l %0,%%d0\n"
  970. + "and%.l #0xfffffff0,%%d0\n"
  971. + "move%.l %%d0,%%a0\n"
  972. + "move%.l %1,%%d0\n"
  973. + "1:\n"
  974. + "cpushl %%bc,(%%a0)\n"
  975. + "lea 0x10(%%a0),%%a0\n"
  976. + "subq%.l #1,%%d0\n"
  977. + "bne.b 1b\n"
  978. + "movec %2,%%cacr\n"
  979. + : : "a" (__pa(vaddr)), "i" (PAGE_SIZE / CACHE_LINE_SIZE),
  980. + "r" (shadow_cacr), "i" (CF_CACR_SPA)
  981. + : "a0", "d0");
  982. +}
  983. +
  984. +/*
  985. + * Various defines for the kernel.
  986. + */
  987. +
  988. +extern void cache_clear(unsigned long paddr, int len);
  989. +extern void cache_push(unsigned long paddr, int len);
  990. +extern void flush_icache_range(unsigned long address, unsigned long endaddr);
  991. +
  992. +#define flush_cache_all() flush_bcache()
  993. +#define flush_cache_vmap(start, end) flush_bcache()
  994. +#define flush_cache_vunmap(start, end) flush_bcache()
  995. +
  996. +#define flush_dcache_range(vstart, vend) cf_dcache_flush_range(vstart, vend)
  997. +#define flush_dcache_page(page) __flush_page_to_ram(page_address(page))
  998. +#define flush_dcache_mmap_lock(mapping) do { } while (0)
  999. +#define flush_dcache_mmap_unlock(mapping) do { } while (0)
  1000. +
  1001. +#define flush_icache_page(vma, page) __flush_page_to_ram(page_address(page))
  1002. +
  1003. +/**
  1004. + * copy_to_user_page - Copy memory to user page
  1005. + */
  1006. static inline void copy_to_user_page(struct vm_area_struct *vma,
  1007. struct page *page, unsigned long vaddr,
  1008. void *dst, void *src, int len)
  1009. {
  1010. memcpy(dst, src, len);
  1011. - flush_icache_user_page(vma, page, vaddr, len);
  1012. + cf_cache_flush(page_to_phys(page), PAGE_SIZE);
  1013. }
  1014. +
  1015. +/**
  1016. + * copy_from_user_page - Copy memory from user page
  1017. + */
  1018. static inline void copy_from_user_page(struct vm_area_struct *vma,
  1019. struct page *page, unsigned long vaddr,
  1020. void *dst, void *src, int len)
  1021. {
  1022. + cf_cache_flush(page_to_phys(page), PAGE_SIZE);
  1023. memcpy(dst, src, len);
  1024. }
  1025. -#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  1026. -#define flush_cache_vmap(start, end) flush_cache_all()
  1027. -#define flush_cache_vunmap(start, end) flush_cache_all()
  1028. -#define flush_dcache_mmap_lock(mapping) do { } while (0)
  1029. -#define flush_dcache_mmap_unlock(mapping) do { } while (0)
  1030. -
  1031. #endif /* M68K_CF_CACHEFLUSH_H */
  1032. --- a/include/asm-m68k/cfcache.h
  1033. +++ b/include/asm-m68k/cfcache.h
  1034. @@ -1,19 +1,32 @@
  1035. /*
  1036. - * include/asm-m68k/cfcache.h
  1037. + * include/asm-m68k/cfcache.h - Coldfire Cache Controller
  1038. + *
  1039. + * Kurt Mahan [email protected]
  1040. + *
  1041. + * Copyright Freescale Semiconductor, Inc. 2007
  1042. + *
  1043. + * This program is free software; you can redistribute it and/or modify it
  1044. + * under the terms of the GNU General Public License as published by the
  1045. + * Free Software Foundation; either version 2 of the License, or (at your
  1046. + * option) any later version.
  1047. */
  1048. #ifndef CF_CFCACHE_H
  1049. #define CF_CFCACHE_H
  1050. +/*
  1051. + * CACR Cache Control Register
  1052. + */
  1053. #define CF_CACR_DEC (0x80000000) /* Data Cache Enable */
  1054. #define CF_CACR_DW (0x40000000) /* Data default Write-protect */
  1055. #define CF_CACR_DESB (0x20000000) /* Data Enable Store Buffer */
  1056. -#define CF_CACR_DDPI (0x10000000) /* Data Disable CPUSHL Invalidate */
  1057. +#define CF_CACR_DPI (0x10000000) /* Data Disable CPUSHL Invalidate */
  1058. #define CF_CACR_DHLCK (0x08000000) /* 1/2 Data Cache Lock Mode */
  1059. #define CF_CACR_DDCM_00 (0x00000000) /* Cacheable writethrough imprecise */
  1060. #define CF_CACR_DDCM_01 (0x02000000) /* Cacheable copyback */
  1061. #define CF_CACR_DDCM_10 (0x04000000) /* Noncacheable precise */
  1062. #define CF_CACR_DDCM_11 (0x06000000) /* Noncacheable imprecise */
  1063. #define CF_CACR_DCINVA (0x01000000) /* Data Cache Invalidate All */
  1064. +#define CF_CACR_DDSP (0x00800000) /* Data default supervisor-protect */
  1065. #define CF_CACR_IVO (0x00100000) /* Invalidate only */
  1066. #define CF_CACR_BEC (0x00080000) /* Branch Cache Enable */
  1067. #define CF_CACR_BCINVA (0x00040000) /* Branch Cache Invalidate All */
  1068. @@ -24,61 +37,43 @@
  1069. #define CF_CACR_IHLCK (0x00000800) /* 1/2 Instruction Cache Lock Mode */
  1070. #define CF_CACR_IDCM (0x00000400) /* Noncacheable Instr default mode */
  1071. #define CF_CACR_ICINVA (0x00000100) /* Instr Cache Invalidate All */
  1072. +#define CF_CACR_IDSP (0x00000080) /* Ins default supervisor-protect */
  1073. #define CF_CACR_EUSP (0x00000020) /* Switch stacks in user mode */
  1074. -#define DCACHE_LINE_SIZE 0x0010 /* bytes per line */
  1075. -#define DCACHE_WAY_SIZE 0x2000 /* words per cache block */
  1076. -#define CACHE_DISABLE_MODE (CF_CACR_DCINVA+CF_CACR_BCINVA+CF_CACR_ICINVA)
  1077. -#ifdef CONFIG_M5445X_DISABLE_CACHE
  1078. -/* disable cache for testing rev0 silicon */
  1079. -#define CACHE_INITIAL_MODE (CF_CACR_EUSP)
  1080. -#else
  1081. -#define CACHE_INITIAL_MODE (CF_CACR_DEC+CF_CACR_BEC+CF_CACR_IEC+CF_CACR_EUSP)
  1082. -#endif
  1083. -
  1084. -#define _DCACHE_SIZE (2*16384)
  1085. -#define _ICACHE_SIZE (2*16384)
  1086. -
  1087. -#define _SET_SHIFT 4
  1088. -
  1089. +#ifdef CONFIG_M54455
  1090. /*
  1091. - * Masks for cache sizes. Programming note: because the set size is a
  1092. - * power of two, the mask is also the last address in the set.
  1093. - * This may need to be #ifdef for other Coldfire processors.
  1094. + * M5445x Cache Configuration
  1095. + * - cache line size is 16 bytes
  1096. + * - cache is 4-way set associative
  1097. + * - each cache has 256 sets (64k / 16bytes / 4way)
  1098. + * - I-Cache size is 16KB
  1099. + * - D-Cache size is 16KB
  1100. */
  1101. +#define ICACHE_SIZE 0x4000 /* instruction - 16k */
  1102. +#define DCACHE_SIZE 0x4000 /* data - 16k */
  1103. -#define _DCACHE_SET_MASK ((_DCACHE_SIZE/64-1)<<_SET_SHIFT)
  1104. -#define _ICACHE_SET_MASK ((_ICACHE_SIZE/64-1)<<_SET_SHIFT)
  1105. -#define LAST_DCACHE_ADDR _DCACHE_SET_MASK
  1106. -#define LAST_ICACHE_ADDR _ICACHE_SET_MASK
  1107. -
  1108. +#define CACHE_LINE_SIZE 0x0010 /* 16 bytes */
  1109. +#define CACHE_SETS 0x0100 /* 256 sets */
  1110. +#define CACHE_WAYS 0x0004 /* 4 way */
  1111. +
  1112. +#define CACHE_DISABLE_MODE (CF_CACR_DCINVA+ \
  1113. + CF_CACR_BCINVA+ \
  1114. + CF_CACR_ICINVA)
  1115. +
  1116. +#ifndef CONFIG_M5445X_DISABLE_CACHE
  1117. +#define CACHE_INITIAL_MODE (CF_CACR_DEC+ \
  1118. + CF_CACR_BEC+ \
  1119. + CF_CACR_IEC+ \
  1120. + CF_CACR_EUSP)
  1121. +#else
  1122. +/* cache disabled for testing */
  1123. +#define CACHE_INITIAL_MODE (CF_CACR_EUSP)
  1124. +#endif /* CONFIG_M5445X_DISABLE_CACHE */
  1125. +#endif /* CONFIG_M54455 */
  1126. #ifndef __ASSEMBLY__
  1127. -extern void DcacheFlushInvalidate(void);
  1128. -
  1129. -extern void DcacheDisable(void);
  1130. -extern void DcacheEnable(void);
  1131. -
  1132. -/******************************************************************************/
  1133. -/*** Unimplemented Cache functionality ***/
  1134. -/******************************************************************************/
  1135. -#define preDcacheInvalidateBlockMark()
  1136. -#define postDcacheInvalidateBlockMark()
  1137. -#define DcacheZeroBlock(p, l) fast_bzero((char *)(p), (long)(l))
  1138. -#define loadDcacheInvalidateBlock() ASSERT(!"Not Implemented on V4e")
  1139. -#define IcacheInvalidateBlock() ASSERT(!"Not Implemented on V4e")
  1140. -
  1141. -/******************************************************************************/
  1142. -/*** Redundant Cache functionality on ColdFire ***/
  1143. -/******************************************************************************/
  1144. -#define DcacheInvalidateBlock(p, l) DcacheFlushInvalidateCacheBlock(p, l)
  1145. -#define DcacheFlushCacheBlock(p, l) DcacheFlushInvalidateCacheBlock(p, l)
  1146. -#define DcacheFlushBlock(p, l) DcacheFlushInvalidateCacheBlock(p, l)
  1147. -
  1148. -extern void DcacheFlushInvalidateCacheBlock(void *start, unsigned long size);
  1149. -extern void FLASHDcacheFlushInvalidate(void);
  1150. -
  1151. +extern unsigned long shadow_cacr;
  1152. extern void cacr_set(unsigned long x);
  1153. #endif /* !__ASSEMBLY__ */