cache_arc700.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * ARC700 VIPT Cache Management
  3. *
  4. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * vineetg: May 2011: for Non-aliasing VIPT D-cache following can be NOPs
  11. * -flush_cache_dup_mm (fork)
  12. * -likewise for flush_cache_mm (exit/execve)
  13. * -likewise for flush_cache_range,flush_cache_page (munmap, exit, COW-break)
  14. *
  15. * vineetg: Apr 2011
  16. * -Now that MMU can support larger pg sz (16K), the determiniation of
  17. * aliasing shd not be based on assumption of 8k pg
  18. *
  19. * vineetg: Mar 2011
  20. * -optimised version of flush_icache_range( ) for making I/D coherent
  21. * when vaddr is available (agnostic of num of aliases)
  22. *
  23. * vineetg: Mar 2011
  24. * -Added documentation about I-cache aliasing on ARC700 and the way it
  25. * was handled up until MMU V2.
  26. * -Spotted a three year old bug when killing the 4 aliases, which needs
  27. * bottom 2 bits, so we need to do paddr | {0x00, 0x01, 0x02, 0x03}
  28. * instead of paddr | {0x00, 0x01, 0x10, 0x11}
  29. * (Rajesh you owe me one now)
  30. *
  31. * vineetg: Dec 2010
  32. * -Off-by-one error when computing num_of_lines to flush
  33. * This broke signal handling with bionic which uses synthetic sigret stub
  34. *
  35. * vineetg: Mar 2010
  36. * -GCC can't generate ZOL for core cache flush loops.
  37. * Conv them into iterations based as opposed to while (start < end) types
  38. *
  39. * Vineetg: July 2009
  40. * -In I-cache flush routine we used to chk for aliasing for every line INV.
  41. * Instead now we setup routines per cache geometry and invoke them
  42. * via function pointers.
  43. *
  44. * Vineetg: Jan 2009
  45. * -Cache Line flush routines used to flush an extra line beyond end addr
  46. * because check was while (end >= start) instead of (end > start)
  47. * =Some call sites had to work around by doing -1, -4 etc to end param
  48. * =Some callers didnt care. This was spec bad in case of INV routines
  49. * which would discard valid data (cause of the horrible ext2 bug
  50. * in ARC IDE driver)
  51. *
  52. * vineetg: June 11th 2008: Fixed flush_icache_range( )
  53. * -Since ARC700 caches are not coherent (I$ doesnt snoop D$) both need
  54. * to be flushed, which it was not doing.
  55. * -load_module( ) passes vmalloc addr (Kernel Virtual Addr) to the API,
  56. * however ARC cache maintenance OPs require PHY addr. Thus need to do
  57. * vmalloc_to_phy.
  58. * -Also added optimisation there, that for range > PAGE SIZE we flush the
  59. * entire cache in one shot rather than line by line. For e.g. a module
  60. * with Code sz 600k, old code flushed 600k worth of cache (line-by-line),
  61. * while cache is only 16 or 32k.
  62. */
  63. #include <linux/module.h>
  64. #include <linux/mm.h>
  65. #include <linux/sched.h>
  66. #include <linux/cache.h>
  67. #include <linux/mmu_context.h>
  68. #include <linux/syscalls.h>
  69. #include <linux/uaccess.h>
  70. #include <asm/cacheflush.h>
  71. #include <asm/cachectl.h>
  72. #include <asm/setup.h>
  73. char *arc_cache_mumbojumbo(int cpu_id, char *buf, int len)
  74. {
  75. int n = 0;
  76. unsigned int c = smp_processor_id();
  77. #define PR_CACHE(p, enb, str) \
  78. { \
  79. if (!(p)->ver) \
  80. n += scnprintf(buf + n, len - n, str"\t\t: N/A\n"); \
  81. else \
  82. n += scnprintf(buf + n, len - n, \
  83. str"\t\t: (%uK) VIPT, %dway set-asc, %ub Line %s\n", \
  84. TO_KB((p)->sz), (p)->assoc, (p)->line_len, \
  85. enb ? "" : "DISABLED (kernel-build)"); \
  86. }
  87. PR_CACHE(&cpuinfo_arc700[c].icache, __CONFIG_ARC_HAS_ICACHE, "I-Cache");
  88. PR_CACHE(&cpuinfo_arc700[c].dcache, __CONFIG_ARC_HAS_DCACHE, "D-Cache");
  89. return buf;
  90. }
  91. /*
  92. * Read the Cache Build Confuration Registers, Decode them and save into
  93. * the cpuinfo structure for later use.
  94. * No Validation done here, simply read/convert the BCRs
  95. */
  96. void __cpuinit read_decode_cache_bcr(void)
  97. {
  98. struct bcr_cache ibcr, dbcr;
  99. struct cpuinfo_arc_cache *p_ic, *p_dc;
  100. unsigned int cpu = smp_processor_id();
  101. p_ic = &cpuinfo_arc700[cpu].icache;
  102. READ_BCR(ARC_REG_IC_BCR, ibcr);
  103. if (ibcr.config == 0x3)
  104. p_ic->assoc = 2;
  105. p_ic->line_len = 8 << ibcr.line_len;
  106. p_ic->sz = 0x200 << ibcr.sz;
  107. p_ic->ver = ibcr.ver;
  108. p_dc = &cpuinfo_arc700[cpu].dcache;
  109. READ_BCR(ARC_REG_DC_BCR, dbcr);
  110. if (dbcr.config == 0x2)
  111. p_dc->assoc = 4;
  112. p_dc->line_len = 16 << dbcr.line_len;
  113. p_dc->sz = 0x200 << dbcr.sz;
  114. p_dc->ver = dbcr.ver;
  115. }
  116. /*
  117. * 1. Validate the Cache Geomtery (compile time config matches hardware)
  118. * 2. If I-cache suffers from aliasing, setup work arounds (difft flush rtn)
  119. * (aliasing D-cache configurations are not supported YET)
  120. * 3. Enable the Caches, setup default flush mode for D-Cache
  121. * 3. Calculate the SHMLBA used by user space
  122. */
  123. void __cpuinit arc_cache_init(void)
  124. {
  125. unsigned int temp;
  126. unsigned int cpu = smp_processor_id();
  127. struct cpuinfo_arc_cache *ic = &cpuinfo_arc700[cpu].icache;
  128. struct cpuinfo_arc_cache *dc = &cpuinfo_arc700[cpu].dcache;
  129. int way_pg_ratio = way_pg_ratio;
  130. char str[256];
  131. printk(arc_cache_mumbojumbo(0, str, sizeof(str)));
  132. if (!ic->ver)
  133. goto chk_dc;
  134. #ifdef CONFIG_ARC_HAS_ICACHE
  135. /* 1. Confirm some of I-cache params which Linux assumes */
  136. if ((ic->assoc != ARC_ICACHE_WAYS) ||
  137. (ic->line_len != ARC_ICACHE_LINE_LEN)) {
  138. panic("Cache H/W doesn't match kernel Config");
  139. }
  140. #if (CONFIG_ARC_MMU_VER > 2)
  141. if (ic->ver != 3) {
  142. if (running_on_hw)
  143. panic("Cache ver doesn't match MMU ver\n");
  144. /* For ISS - suggest the toggles to use */
  145. pr_err("Use -prop=icache_version=3,-prop=dcache_version=3\n");
  146. }
  147. #endif
  148. #endif
  149. /* Enable/disable I-Cache */
  150. temp = read_aux_reg(ARC_REG_IC_CTRL);
  151. #ifdef CONFIG_ARC_HAS_ICACHE
  152. temp &= ~IC_CTRL_CACHE_DISABLE;
  153. #else
  154. temp |= IC_CTRL_CACHE_DISABLE;
  155. #endif
  156. write_aux_reg(ARC_REG_IC_CTRL, temp);
  157. chk_dc:
  158. if (!dc->ver)
  159. return;
  160. #ifdef CONFIG_ARC_HAS_DCACHE
  161. if ((dc->assoc != ARC_DCACHE_WAYS) ||
  162. (dc->line_len != ARC_DCACHE_LINE_LEN)) {
  163. panic("Cache H/W doesn't match kernel Config");
  164. }
  165. /* check for D-Cache aliasing */
  166. if ((dc->sz / ARC_DCACHE_WAYS) > PAGE_SIZE)
  167. panic("D$ aliasing not handled right now\n");
  168. #endif
  169. /* Set the default Invalidate Mode to "simpy discard dirty lines"
  170. * as this is more frequent then flush before invalidate
  171. * Ofcourse we toggle this default behviour when desired
  172. */
  173. temp = read_aux_reg(ARC_REG_DC_CTRL);
  174. temp &= ~DC_CTRL_INV_MODE_FLUSH;
  175. #ifdef CONFIG_ARC_HAS_DCACHE
  176. /* Enable D-Cache: Clear Bit 0 */
  177. write_aux_reg(ARC_REG_DC_CTRL, temp & ~IC_CTRL_CACHE_DISABLE);
  178. #else
  179. /* Flush D cache */
  180. write_aux_reg(ARC_REG_DC_FLSH, 0x1);
  181. /* Disable D cache */
  182. write_aux_reg(ARC_REG_DC_CTRL, temp | IC_CTRL_CACHE_DISABLE);
  183. #endif
  184. return;
  185. }
  186. #define OP_INV 0x1
  187. #define OP_FLUSH 0x2
  188. #define OP_FLUSH_N_INV 0x3
  189. #ifdef CONFIG_ARC_HAS_DCACHE
  190. /***************************************************************
  191. * Machine specific helpers for Entire D-Cache or Per Line ops
  192. */
  193. static inline void wait_for_flush(void)
  194. {
  195. while (read_aux_reg(ARC_REG_DC_CTRL) & DC_CTRL_FLUSH_STATUS)
  196. ;
  197. }
  198. /*
  199. * Operation on Entire D-Cache
  200. * @cacheop = {OP_INV, OP_FLUSH, OP_FLUSH_N_INV}
  201. * Note that constant propagation ensures all the checks are gone
  202. * in generated code
  203. */
  204. static inline void __dc_entire_op(const int cacheop)
  205. {
  206. unsigned long flags, tmp = tmp;
  207. int aux;
  208. local_irq_save(flags);
  209. if (cacheop == OP_FLUSH_N_INV) {
  210. /* Dcache provides 2 cmd: FLUSH or INV
  211. * INV inturn has sub-modes: DISCARD or FLUSH-BEFORE
  212. * flush-n-inv is achieved by INV cmd but with IM=1
  213. * Default INV sub-mode is DISCARD, which needs to be toggled
  214. */
  215. tmp = read_aux_reg(ARC_REG_DC_CTRL);
  216. write_aux_reg(ARC_REG_DC_CTRL, tmp | DC_CTRL_INV_MODE_FLUSH);
  217. }
  218. if (cacheop & OP_INV) /* Inv or flush-n-inv use same cmd reg */
  219. aux = ARC_REG_DC_IVDC;
  220. else
  221. aux = ARC_REG_DC_FLSH;
  222. write_aux_reg(aux, 0x1);
  223. if (cacheop & OP_FLUSH) /* flush / flush-n-inv both wait */
  224. wait_for_flush();
  225. /* Switch back the DISCARD ONLY Invalidate mode */
  226. if (cacheop == OP_FLUSH_N_INV)
  227. write_aux_reg(ARC_REG_DC_CTRL, tmp & ~DC_CTRL_INV_MODE_FLUSH);
  228. local_irq_restore(flags);
  229. }
  230. /*
  231. * Per Line Operation on D-Cache
  232. * Doesn't deal with type-of-op/IRQ-disabling/waiting-for-flush-to-complete
  233. * It's sole purpose is to help gcc generate ZOL
  234. */
  235. static inline void __dc_line_loop(unsigned long start, unsigned long sz,
  236. int aux_reg)
  237. {
  238. int num_lines, slack;
  239. /* Ensure we properly floor/ceil the non-line aligned/sized requests
  240. * and have @start - aligned to cache line and integral @num_lines.
  241. * This however can be avoided for page sized since:
  242. * -@start will be cache-line aligned already (being page aligned)
  243. * -@sz will be integral multiple of line size (being page sized).
  244. */
  245. if (!(__builtin_constant_p(sz) && sz == PAGE_SIZE)) {
  246. slack = start & ~DCACHE_LINE_MASK;
  247. sz += slack;
  248. start -= slack;
  249. }
  250. num_lines = DIV_ROUND_UP(sz, ARC_DCACHE_LINE_LEN);
  251. while (num_lines-- > 0) {
  252. #if (CONFIG_ARC_MMU_VER > 2)
  253. /*
  254. * Just as for I$, in MMU v3, D$ ops also require
  255. * "tag" bits in DC_PTAG, "index" bits in FLDL,IVDL ops
  256. * But we pass phy addr for both. This works since Linux
  257. * doesn't support aliasing configs for D$, yet.
  258. * Thus paddr is enough to provide both tag and index.
  259. */
  260. write_aux_reg(ARC_REG_DC_PTAG, start);
  261. #endif
  262. write_aux_reg(aux_reg, start);
  263. start += ARC_DCACHE_LINE_LEN;
  264. }
  265. }
  266. /*
  267. * D-Cache : Per Line INV (discard or wback+discard) or FLUSH (wback)
  268. */
  269. static inline void __dc_line_op(unsigned long start, unsigned long sz,
  270. const int cacheop)
  271. {
  272. unsigned long flags, tmp = tmp;
  273. int aux;
  274. local_irq_save(flags);
  275. if (cacheop == OP_FLUSH_N_INV) {
  276. /*
  277. * Dcache provides 2 cmd: FLUSH or INV
  278. * INV inturn has sub-modes: DISCARD or FLUSH-BEFORE
  279. * flush-n-inv is achieved by INV cmd but with IM=1
  280. * Default INV sub-mode is DISCARD, which needs to be toggled
  281. */
  282. tmp = read_aux_reg(ARC_REG_DC_CTRL);
  283. write_aux_reg(ARC_REG_DC_CTRL, tmp | DC_CTRL_INV_MODE_FLUSH);
  284. }
  285. if (cacheop & OP_INV) /* Inv / flush-n-inv use same cmd reg */
  286. aux = ARC_REG_DC_IVDL;
  287. else
  288. aux = ARC_REG_DC_FLDL;
  289. __dc_line_loop(start, sz, aux);
  290. if (cacheop & OP_FLUSH) /* flush / flush-n-inv both wait */
  291. wait_for_flush();
  292. /* Switch back the DISCARD ONLY Invalidate mode */
  293. if (cacheop == OP_FLUSH_N_INV)
  294. write_aux_reg(ARC_REG_DC_CTRL, tmp & ~DC_CTRL_INV_MODE_FLUSH);
  295. local_irq_restore(flags);
  296. }
  297. #else
  298. #define __dc_entire_op(cacheop)
  299. #define __dc_line_op(start, sz, cacheop)
  300. #endif /* CONFIG_ARC_HAS_DCACHE */
  301. #ifdef CONFIG_ARC_HAS_ICACHE
  302. /*
  303. * I-Cache Aliasing in ARC700 VIPT caches
  304. *
  305. * ARC VIPT I-cache uses vaddr to index into cache and paddr to match the tag.
  306. * The orig Cache Management Module "CDU" only required paddr to invalidate a
  307. * certain line since it sufficed as index in Non-Aliasing VIPT cache-geometry.
  308. * Infact for distinct V1,V2,P: all of {V1-P},{V2-P},{P-P} would end up fetching
  309. * the exact same line.
  310. *
  311. * However for larger Caches (way-size > page-size) - i.e. in Aliasing config,
  312. * paddr alone could not be used to correctly index the cache.
  313. *
  314. * ------------------
  315. * MMU v1/v2 (Fixed Page Size 8k)
  316. * ------------------
  317. * The solution was to provide CDU with these additonal vaddr bits. These
  318. * would be bits [x:13], x would depend on cache-geometry, 13 comes from
  319. * standard page size of 8k.
  320. * H/w folks chose [17:13] to be a future safe range, and moreso these 5 bits
  321. * of vaddr could easily be "stuffed" in the paddr as bits [4:0] since the
  322. * orig 5 bits of paddr were anyways ignored by CDU line ops, as they
  323. * represent the offset within cache-line. The adv of using this "clumsy"
  324. * interface for additional info was no new reg was needed in CDU programming
  325. * model.
  326. *
  327. * 17:13 represented the max num of bits passable, actual bits needed were
  328. * fewer, based on the num-of-aliases possible.
  329. * -for 2 alias possibility, only bit 13 needed (32K cache)
  330. * -for 4 alias possibility, bits 14:13 needed (64K cache)
  331. *
  332. * ------------------
  333. * MMU v3
  334. * ------------------
  335. * This ver of MMU supports variable page sizes (1k-16k): although Linux will
  336. * only support 8k (default), 16k and 4k.
  337. * However from hardware perspective, smaller page sizes aggrevate aliasing
  338. * meaning more vaddr bits needed to disambiguate the cache-line-op ;
  339. * the existing scheme of piggybacking won't work for certain configurations.
  340. * Two new registers IC_PTAG and DC_PTAG inttoduced.
  341. * "tag" bits are provided in PTAG, index bits in existing IVIL/IVDL/FLDL regs
  342. */
  343. /***********************************************************
  344. * Machine specific helper for per line I-Cache invalidate.
  345. */
  346. static void __ic_line_inv_vaddr(unsigned long phy_start, unsigned long vaddr,
  347. unsigned long sz)
  348. {
  349. unsigned long flags;
  350. int num_lines, slack;
  351. unsigned int addr;
  352. /*
  353. * Ensure we properly floor/ceil the non-line aligned/sized requests:
  354. * However page sized flushes can be compile time optimised.
  355. * -@phy_start will be cache-line aligned already (being page aligned)
  356. * -@sz will be integral multiple of line size (being page sized).
  357. */
  358. if (!(__builtin_constant_p(sz) && sz == PAGE_SIZE)) {
  359. slack = phy_start & ~ICACHE_LINE_MASK;
  360. sz += slack;
  361. phy_start -= slack;
  362. }
  363. num_lines = DIV_ROUND_UP(sz, ARC_ICACHE_LINE_LEN);
  364. #if (CONFIG_ARC_MMU_VER > 2)
  365. vaddr &= ~ICACHE_LINE_MASK;
  366. addr = phy_start;
  367. #else
  368. /* bits 17:13 of vaddr go as bits 4:0 of paddr */
  369. addr = phy_start | ((vaddr >> 13) & 0x1F);
  370. #endif
  371. local_irq_save(flags);
  372. while (num_lines-- > 0) {
  373. #if (CONFIG_ARC_MMU_VER > 2)
  374. /* tag comes from phy addr */
  375. write_aux_reg(ARC_REG_IC_PTAG, addr);
  376. /* index bits come from vaddr */
  377. write_aux_reg(ARC_REG_IC_IVIL, vaddr);
  378. vaddr += ARC_ICACHE_LINE_LEN;
  379. #else
  380. /* paddr contains stuffed vaddrs bits */
  381. write_aux_reg(ARC_REG_IC_IVIL, addr);
  382. #endif
  383. addr += ARC_ICACHE_LINE_LEN;
  384. }
  385. local_irq_restore(flags);
  386. }
  387. #else
  388. #define __ic_line_inv_vaddr(pstart, vstart, sz)
  389. #endif /* CONFIG_ARC_HAS_ICACHE */
  390. /***********************************************************
  391. * Exported APIs
  392. */
  393. void flush_dcache_page(struct page *page)
  394. {
  395. /* Make a note that dcache is not yet flushed for this page */
  396. set_bit(PG_arch_1, &page->flags);
  397. }
  398. EXPORT_SYMBOL(flush_dcache_page);
  399. void dma_cache_wback_inv(unsigned long start, unsigned long sz)
  400. {
  401. __dc_line_op(start, sz, OP_FLUSH_N_INV);
  402. }
  403. EXPORT_SYMBOL(dma_cache_wback_inv);
  404. void dma_cache_inv(unsigned long start, unsigned long sz)
  405. {
  406. __dc_line_op(start, sz, OP_INV);
  407. }
  408. EXPORT_SYMBOL(dma_cache_inv);
  409. void dma_cache_wback(unsigned long start, unsigned long sz)
  410. {
  411. __dc_line_op(start, sz, OP_FLUSH);
  412. }
  413. EXPORT_SYMBOL(dma_cache_wback);
  414. /*
  415. * This is API for making I/D Caches consistent when modifying
  416. * kernel code (loadable modules, kprobes, kgdb...)
  417. * This is called on insmod, with kernel virtual address for CODE of
  418. * the module. ARC cache maintenance ops require PHY address thus we
  419. * need to convert vmalloc addr to PHY addr
  420. */
  421. void flush_icache_range(unsigned long kstart, unsigned long kend)
  422. {
  423. unsigned int tot_sz, off, sz;
  424. unsigned long phy, pfn;
  425. /* printk("Kernel Cache Cohenercy: %lx to %lx\n",kstart, kend); */
  426. /* This is not the right API for user virtual address */
  427. if (kstart < TASK_SIZE) {
  428. BUG_ON("Flush icache range for user virtual addr space");
  429. return;
  430. }
  431. /* Shortcut for bigger flush ranges.
  432. * Here we don't care if this was kernel virtual or phy addr
  433. */
  434. tot_sz = kend - kstart;
  435. if (tot_sz > PAGE_SIZE) {
  436. flush_cache_all();
  437. return;
  438. }
  439. /* Case: Kernel Phy addr (0x8000_0000 onwards) */
  440. if (likely(kstart > PAGE_OFFSET)) {
  441. /*
  442. * The 2nd arg despite being paddr will be used to index icache
  443. * This is OK since no alternate virtual mappings will exist
  444. * given the callers for this case: kprobe/kgdb in built-in
  445. * kernel code only.
  446. */
  447. __sync_icache_dcache(kstart, kstart, kend - kstart);
  448. return;
  449. }
  450. /*
  451. * Case: Kernel Vaddr (0x7000_0000 to 0x7fff_ffff)
  452. * (1) ARC Cache Maintenance ops only take Phy addr, hence special
  453. * handling of kernel vaddr.
  454. *
  455. * (2) Despite @tot_sz being < PAGE_SIZE (bigger cases handled already),
  456. * it still needs to handle a 2 page scenario, where the range
  457. * straddles across 2 virtual pages and hence need for loop
  458. */
  459. while (tot_sz > 0) {
  460. off = kstart % PAGE_SIZE;
  461. pfn = vmalloc_to_pfn((void *)kstart);
  462. phy = (pfn << PAGE_SHIFT) + off;
  463. sz = min_t(unsigned int, tot_sz, PAGE_SIZE - off);
  464. __sync_icache_dcache(phy, kstart, sz);
  465. kstart += sz;
  466. tot_sz -= sz;
  467. }
  468. }
  469. /*
  470. * General purpose helper to make I and D cache lines consistent.
  471. * @paddr is phy addr of region
  472. * @vaddr is typically user or kernel vaddr (vmalloc)
  473. * Howver in one instance, flush_icache_range() by kprobe (for a breakpt in
  474. * builtin kernel code) @vaddr will be paddr only, meaning CDU operation will
  475. * use a paddr to index the cache (despite VIPT). This is fine since since a
  476. * built-in kernel page will not have any virtual mappings (not even kernel)
  477. * kprobe on loadable module is different as it will have kvaddr.
  478. */
  479. void __sync_icache_dcache(unsigned long paddr, unsigned long vaddr, int len)
  480. {
  481. unsigned long flags;
  482. local_irq_save(flags);
  483. __ic_line_inv_vaddr(paddr, vaddr, len);
  484. __dc_line_op(paddr, len, OP_FLUSH);
  485. local_irq_restore(flags);
  486. }
  487. /* wrapper to compile time eliminate alignment checks in flush loop */
  488. void __inv_icache_page(unsigned long paddr, unsigned long vaddr)
  489. {
  490. __ic_line_inv_vaddr(paddr, vaddr, PAGE_SIZE);
  491. }
  492. void __flush_dcache_page(unsigned long paddr)
  493. {
  494. __dc_line_op(paddr, PAGE_SIZE, OP_FLUSH_N_INV);
  495. }
  496. void flush_icache_all(void)
  497. {
  498. unsigned long flags;
  499. local_irq_save(flags);
  500. write_aux_reg(ARC_REG_IC_IVIC, 1);
  501. /* lr will not complete till the icache inv operation is not over */
  502. read_aux_reg(ARC_REG_IC_CTRL);
  503. local_irq_restore(flags);
  504. }
  505. noinline void flush_cache_all(void)
  506. {
  507. unsigned long flags;
  508. local_irq_save(flags);
  509. flush_icache_all();
  510. __dc_entire_op(OP_FLUSH_N_INV);
  511. local_irq_restore(flags);
  512. }
  513. /**********************************************************************
  514. * Explicit Cache flush request from user space via syscall
  515. * Needed for JITs which generate code on the fly
  516. */
  517. SYSCALL_DEFINE3(cacheflush, uint32_t, start, uint32_t, sz, uint32_t, flags)
  518. {
  519. /* TBD: optimize this */
  520. flush_cache_all();
  521. return 0;
  522. }