cache.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. /*
  2. * ARC Cache Management
  3. *
  4. * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
  5. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/mm.h>
  13. #include <linux/sched.h>
  14. #include <linux/cache.h>
  15. #include <linux/mmu_context.h>
  16. #include <linux/syscalls.h>
  17. #include <linux/uaccess.h>
  18. #include <linux/pagemap.h>
  19. #include <asm/cacheflush.h>
  20. #include <asm/cachectl.h>
  21. #include <asm/setup.h>
  22. #ifdef CONFIG_ISA_ARCV2
  23. #define USE_RGN_FLSH 1
  24. #endif
  25. static int l2_line_sz;
  26. static int ioc_exists;
  27. int slc_enable = 1, ioc_enable = 1;
  28. unsigned long perip_base = ARC_UNCACHED_ADDR_SPACE; /* legacy value for boot */
  29. unsigned long perip_end = 0xFFFFFFFF; /* legacy value */
  30. void (*_cache_line_loop_ic_fn)(phys_addr_t paddr, unsigned long vaddr,
  31. unsigned long sz, const int op, const int full_page);
  32. void (*__dma_cache_wback_inv)(phys_addr_t start, unsigned long sz);
  33. void (*__dma_cache_inv)(phys_addr_t start, unsigned long sz);
  34. void (*__dma_cache_wback)(phys_addr_t start, unsigned long sz);
  35. char *arc_cache_mumbojumbo(int c, char *buf, int len)
  36. {
  37. int n = 0;
  38. struct cpuinfo_arc_cache *p;
  39. #define PR_CACHE(p, cfg, str) \
  40. if (!(p)->line_len) \
  41. n += scnprintf(buf + n, len - n, str"\t\t: N/A\n"); \
  42. else \
  43. n += scnprintf(buf + n, len - n, \
  44. str"\t\t: %uK, %dway/set, %uB Line, %s%s%s\n", \
  45. (p)->sz_k, (p)->assoc, (p)->line_len, \
  46. (p)->vipt ? "VIPT" : "PIPT", \
  47. (p)->alias ? " aliasing" : "", \
  48. IS_USED_CFG(cfg));
  49. PR_CACHE(&cpuinfo_arc700[c].icache, CONFIG_ARC_HAS_ICACHE, "I-Cache");
  50. PR_CACHE(&cpuinfo_arc700[c].dcache, CONFIG_ARC_HAS_DCACHE, "D-Cache");
  51. p = &cpuinfo_arc700[c].slc;
  52. if (p->line_len)
  53. n += scnprintf(buf + n, len - n,
  54. "SLC\t\t: %uK, %uB Line%s\n",
  55. p->sz_k, p->line_len, IS_USED_RUN(slc_enable));
  56. n += scnprintf(buf + n, len - n, "Peripherals\t: %#lx%s%s\n",
  57. perip_base,
  58. IS_AVAIL3(ioc_exists, ioc_enable, ", IO-Coherency "));
  59. return buf;
  60. }
  61. /*
  62. * Read the Cache Build Confuration Registers, Decode them and save into
  63. * the cpuinfo structure for later use.
  64. * No Validation done here, simply read/convert the BCRs
  65. */
  66. static void read_decode_cache_bcr_arcv2(int cpu)
  67. {
  68. struct cpuinfo_arc_cache *p_slc = &cpuinfo_arc700[cpu].slc;
  69. struct bcr_generic sbcr;
  70. struct bcr_slc_cfg {
  71. #ifdef CONFIG_CPU_BIG_ENDIAN
  72. unsigned int pad:24, way:2, lsz:2, sz:4;
  73. #else
  74. unsigned int sz:4, lsz:2, way:2, pad:24;
  75. #endif
  76. } slc_cfg;
  77. struct bcr_clust_cfg {
  78. #ifdef CONFIG_CPU_BIG_ENDIAN
  79. unsigned int pad:7, c:1, num_entries:8, num_cores:8, ver:8;
  80. #else
  81. unsigned int ver:8, num_cores:8, num_entries:8, c:1, pad:7;
  82. #endif
  83. } cbcr;
  84. struct bcr_volatile {
  85. #ifdef CONFIG_CPU_BIG_ENDIAN
  86. unsigned int start:4, limit:4, pad:22, order:1, disable:1;
  87. #else
  88. unsigned int disable:1, order:1, pad:22, limit:4, start:4;
  89. #endif
  90. } vol;
  91. READ_BCR(ARC_REG_SLC_BCR, sbcr);
  92. if (sbcr.ver) {
  93. READ_BCR(ARC_REG_SLC_CFG, slc_cfg);
  94. p_slc->sz_k = 128 << slc_cfg.sz;
  95. l2_line_sz = p_slc->line_len = (slc_cfg.lsz == 0) ? 128 : 64;
  96. }
  97. READ_BCR(ARC_REG_CLUSTER_BCR, cbcr);
  98. if (cbcr.c)
  99. ioc_exists = 1;
  100. else
  101. ioc_enable = 0;
  102. /* HS 2.0 didn't have AUX_VOL */
  103. if (cpuinfo_arc700[cpu].core.family > 0x51) {
  104. READ_BCR(AUX_VOL, vol);
  105. perip_base = vol.start << 28;
  106. /* HS 3.0 has limit and strict-ordering fields */
  107. if (cpuinfo_arc700[cpu].core.family > 0x52)
  108. perip_end = (vol.limit << 28) - 1;
  109. }
  110. }
  111. void read_decode_cache_bcr(void)
  112. {
  113. struct cpuinfo_arc_cache *p_ic, *p_dc;
  114. unsigned int cpu = smp_processor_id();
  115. struct bcr_cache {
  116. #ifdef CONFIG_CPU_BIG_ENDIAN
  117. unsigned int pad:12, line_len:4, sz:4, config:4, ver:8;
  118. #else
  119. unsigned int ver:8, config:4, sz:4, line_len:4, pad:12;
  120. #endif
  121. } ibcr, dbcr;
  122. p_ic = &cpuinfo_arc700[cpu].icache;
  123. READ_BCR(ARC_REG_IC_BCR, ibcr);
  124. if (!ibcr.ver)
  125. goto dc_chk;
  126. if (ibcr.ver <= 3) {
  127. BUG_ON(ibcr.config != 3);
  128. p_ic->assoc = 2; /* Fixed to 2w set assoc */
  129. } else if (ibcr.ver >= 4) {
  130. p_ic->assoc = 1 << ibcr.config; /* 1,2,4,8 */
  131. }
  132. p_ic->line_len = 8 << ibcr.line_len;
  133. p_ic->sz_k = 1 << (ibcr.sz - 1);
  134. p_ic->vipt = 1;
  135. p_ic->alias = p_ic->sz_k/p_ic->assoc/TO_KB(PAGE_SIZE) > 1;
  136. dc_chk:
  137. p_dc = &cpuinfo_arc700[cpu].dcache;
  138. READ_BCR(ARC_REG_DC_BCR, dbcr);
  139. if (!dbcr.ver)
  140. goto slc_chk;
  141. if (dbcr.ver <= 3) {
  142. BUG_ON(dbcr.config != 2);
  143. p_dc->assoc = 4; /* Fixed to 4w set assoc */
  144. p_dc->vipt = 1;
  145. p_dc->alias = p_dc->sz_k/p_dc->assoc/TO_KB(PAGE_SIZE) > 1;
  146. } else if (dbcr.ver >= 4) {
  147. p_dc->assoc = 1 << dbcr.config; /* 1,2,4,8 */
  148. p_dc->vipt = 0;
  149. p_dc->alias = 0; /* PIPT so can't VIPT alias */
  150. }
  151. p_dc->line_len = 16 << dbcr.line_len;
  152. p_dc->sz_k = 1 << (dbcr.sz - 1);
  153. slc_chk:
  154. if (is_isa_arcv2())
  155. read_decode_cache_bcr_arcv2(cpu);
  156. }
  157. /*
  158. * Line Operation on {I,D}-Cache
  159. */
  160. #define OP_INV 0x1
  161. #define OP_FLUSH 0x2
  162. #define OP_FLUSH_N_INV 0x3
  163. #define OP_INV_IC 0x4
  164. /*
  165. * I-Cache Aliasing in ARC700 VIPT caches (MMU v1-v3)
  166. *
  167. * ARC VIPT I-cache uses vaddr to index into cache and paddr to match the tag.
  168. * The orig Cache Management Module "CDU" only required paddr to invalidate a
  169. * certain line since it sufficed as index in Non-Aliasing VIPT cache-geometry.
  170. * Infact for distinct V1,V2,P: all of {V1-P},{V2-P},{P-P} would end up fetching
  171. * the exact same line.
  172. *
  173. * However for larger Caches (way-size > page-size) - i.e. in Aliasing config,
  174. * paddr alone could not be used to correctly index the cache.
  175. *
  176. * ------------------
  177. * MMU v1/v2 (Fixed Page Size 8k)
  178. * ------------------
  179. * The solution was to provide CDU with these additonal vaddr bits. These
  180. * would be bits [x:13], x would depend on cache-geometry, 13 comes from
  181. * standard page size of 8k.
  182. * H/w folks chose [17:13] to be a future safe range, and moreso these 5 bits
  183. * of vaddr could easily be "stuffed" in the paddr as bits [4:0] since the
  184. * orig 5 bits of paddr were anyways ignored by CDU line ops, as they
  185. * represent the offset within cache-line. The adv of using this "clumsy"
  186. * interface for additional info was no new reg was needed in CDU programming
  187. * model.
  188. *
  189. * 17:13 represented the max num of bits passable, actual bits needed were
  190. * fewer, based on the num-of-aliases possible.
  191. * -for 2 alias possibility, only bit 13 needed (32K cache)
  192. * -for 4 alias possibility, bits 14:13 needed (64K cache)
  193. *
  194. * ------------------
  195. * MMU v3
  196. * ------------------
  197. * This ver of MMU supports variable page sizes (1k-16k): although Linux will
  198. * only support 8k (default), 16k and 4k.
  199. * However from hardware perspective, smaller page sizes aggravate aliasing
  200. * meaning more vaddr bits needed to disambiguate the cache-line-op ;
  201. * the existing scheme of piggybacking won't work for certain configurations.
  202. * Two new registers IC_PTAG and DC_PTAG inttoduced.
  203. * "tag" bits are provided in PTAG, index bits in existing IVIL/IVDL/FLDL regs
  204. */
  205. static inline
  206. void __cache_line_loop_v2(phys_addr_t paddr, unsigned long vaddr,
  207. unsigned long sz, const int op, const int full_page)
  208. {
  209. unsigned int aux_cmd;
  210. int num_lines;
  211. if (op == OP_INV_IC) {
  212. aux_cmd = ARC_REG_IC_IVIL;
  213. } else {
  214. /* d$ cmd: INV (discard or wback-n-discard) OR FLUSH (wback) */
  215. aux_cmd = op & OP_INV ? ARC_REG_DC_IVDL : ARC_REG_DC_FLDL;
  216. }
  217. /* Ensure we properly floor/ceil the non-line aligned/sized requests
  218. * and have @paddr - aligned to cache line and integral @num_lines.
  219. * This however can be avoided for page sized since:
  220. * -@paddr will be cache-line aligned already (being page aligned)
  221. * -@sz will be integral multiple of line size (being page sized).
  222. */
  223. if (!full_page) {
  224. sz += paddr & ~CACHE_LINE_MASK;
  225. paddr &= CACHE_LINE_MASK;
  226. vaddr &= CACHE_LINE_MASK;
  227. }
  228. num_lines = DIV_ROUND_UP(sz, L1_CACHE_BYTES);
  229. /* MMUv2 and before: paddr contains stuffed vaddrs bits */
  230. paddr |= (vaddr >> PAGE_SHIFT) & 0x1F;
  231. while (num_lines-- > 0) {
  232. write_aux_reg(aux_cmd, paddr);
  233. paddr += L1_CACHE_BYTES;
  234. }
  235. }
  236. /*
  237. * For ARC700 MMUv3 I-cache and D-cache flushes
  238. * - ARC700 programming model requires paddr and vaddr be passed in seperate
  239. * AUX registers (*_IV*L and *_PTAG respectively) irrespective of whether the
  240. * caches actually alias or not.
  241. * - For HS38, only the aliasing I-cache configuration uses the PTAG reg
  242. * (non aliasing I-cache version doesn't; while D-cache can't possibly alias)
  243. */
  244. static inline
  245. void __cache_line_loop_v3(phys_addr_t paddr, unsigned long vaddr,
  246. unsigned long sz, const int op, const int full_page)
  247. {
  248. unsigned int aux_cmd, aux_tag;
  249. int num_lines;
  250. if (op == OP_INV_IC) {
  251. aux_cmd = ARC_REG_IC_IVIL;
  252. aux_tag = ARC_REG_IC_PTAG;
  253. } else {
  254. aux_cmd = op & OP_INV ? ARC_REG_DC_IVDL : ARC_REG_DC_FLDL;
  255. aux_tag = ARC_REG_DC_PTAG;
  256. }
  257. /* Ensure we properly floor/ceil the non-line aligned/sized requests
  258. * and have @paddr - aligned to cache line and integral @num_lines.
  259. * This however can be avoided for page sized since:
  260. * -@paddr will be cache-line aligned already (being page aligned)
  261. * -@sz will be integral multiple of line size (being page sized).
  262. */
  263. if (!full_page) {
  264. sz += paddr & ~CACHE_LINE_MASK;
  265. paddr &= CACHE_LINE_MASK;
  266. vaddr &= CACHE_LINE_MASK;
  267. }
  268. num_lines = DIV_ROUND_UP(sz, L1_CACHE_BYTES);
  269. /*
  270. * MMUv3, cache ops require paddr in PTAG reg
  271. * if V-P const for loop, PTAG can be written once outside loop
  272. */
  273. if (full_page)
  274. write_aux_reg(aux_tag, paddr);
  275. /*
  276. * This is technically for MMU v4, using the MMU v3 programming model
  277. * Special work for HS38 aliasing I-cache configuration with PAE40
  278. * - upper 8 bits of paddr need to be written into PTAG_HI
  279. * - (and needs to be written before the lower 32 bits)
  280. * Note that PTAG_HI is hoisted outside the line loop
  281. */
  282. if (is_pae40_enabled() && op == OP_INV_IC)
  283. write_aux_reg(ARC_REG_IC_PTAG_HI, (u64)paddr >> 32);
  284. while (num_lines-- > 0) {
  285. if (!full_page) {
  286. write_aux_reg(aux_tag, paddr);
  287. paddr += L1_CACHE_BYTES;
  288. }
  289. write_aux_reg(aux_cmd, vaddr);
  290. vaddr += L1_CACHE_BYTES;
  291. }
  292. }
  293. #ifndef USE_RGN_FLSH
  294. /*
  295. * In HS38x (MMU v4), I-cache is VIPT (can alias), D-cache is PIPT
  296. * Here's how cache ops are implemented
  297. *
  298. * - D-cache: only paddr needed (in DC_IVDL/DC_FLDL)
  299. * - I-cache Non Aliasing: Despite VIPT, only paddr needed (in IC_IVIL)
  300. * - I-cache Aliasing: Both vaddr and paddr needed (in IC_IVIL, IC_PTAG
  301. * respectively, similar to MMU v3 programming model, hence
  302. * __cache_line_loop_v3() is used)
  303. *
  304. * If PAE40 is enabled, independent of aliasing considerations, the higher bits
  305. * needs to be written into PTAG_HI
  306. */
  307. static inline
  308. void __cache_line_loop_v4(phys_addr_t paddr, unsigned long vaddr,
  309. unsigned long sz, const int op, const int full_page)
  310. {
  311. unsigned int aux_cmd;
  312. int num_lines;
  313. if (op == OP_INV_IC) {
  314. aux_cmd = ARC_REG_IC_IVIL;
  315. } else {
  316. /* d$ cmd: INV (discard or wback-n-discard) OR FLUSH (wback) */
  317. aux_cmd = op & OP_INV ? ARC_REG_DC_IVDL : ARC_REG_DC_FLDL;
  318. }
  319. /* Ensure we properly floor/ceil the non-line aligned/sized requests
  320. * and have @paddr - aligned to cache line and integral @num_lines.
  321. * This however can be avoided for page sized since:
  322. * -@paddr will be cache-line aligned already (being page aligned)
  323. * -@sz will be integral multiple of line size (being page sized).
  324. */
  325. if (!full_page) {
  326. sz += paddr & ~CACHE_LINE_MASK;
  327. paddr &= CACHE_LINE_MASK;
  328. }
  329. num_lines = DIV_ROUND_UP(sz, L1_CACHE_BYTES);
  330. /*
  331. * For HS38 PAE40 configuration
  332. * - upper 8 bits of paddr need to be written into PTAG_HI
  333. * - (and needs to be written before the lower 32 bits)
  334. */
  335. if (is_pae40_enabled()) {
  336. if (op == OP_INV_IC)
  337. /*
  338. * Non aliasing I-cache in HS38,
  339. * aliasing I-cache handled in __cache_line_loop_v3()
  340. */
  341. write_aux_reg(ARC_REG_IC_PTAG_HI, (u64)paddr >> 32);
  342. else
  343. write_aux_reg(ARC_REG_DC_PTAG_HI, (u64)paddr >> 32);
  344. }
  345. while (num_lines-- > 0) {
  346. write_aux_reg(aux_cmd, paddr);
  347. paddr += L1_CACHE_BYTES;
  348. }
  349. }
  350. #else
  351. /*
  352. * optimized flush operation which takes a region as opposed to iterating per line
  353. */
  354. static inline
  355. void __cache_line_loop_v4(phys_addr_t paddr, unsigned long vaddr,
  356. unsigned long sz, const int op, const int full_page)
  357. {
  358. unsigned int s, e;
  359. /* Only for Non aliasing I-cache in HS38 */
  360. if (op == OP_INV_IC) {
  361. s = ARC_REG_IC_IVIR;
  362. e = ARC_REG_IC_ENDR;
  363. } else {
  364. s = ARC_REG_DC_STARTR;
  365. e = ARC_REG_DC_ENDR;
  366. }
  367. if (!full_page) {
  368. /* for any leading gap between @paddr and start of cache line */
  369. sz += paddr & ~CACHE_LINE_MASK;
  370. paddr &= CACHE_LINE_MASK;
  371. /*
  372. * account for any trailing gap to end of cache line
  373. * this is equivalent to DIV_ROUND_UP() in line ops above
  374. */
  375. sz += L1_CACHE_BYTES - 1;
  376. }
  377. if (is_pae40_enabled()) {
  378. /* TBD: check if crossing 4TB boundary */
  379. if (op == OP_INV_IC)
  380. write_aux_reg(ARC_REG_IC_PTAG_HI, (u64)paddr >> 32);
  381. else
  382. write_aux_reg(ARC_REG_DC_PTAG_HI, (u64)paddr >> 32);
  383. }
  384. /* ENDR needs to be set ahead of START */
  385. write_aux_reg(e, paddr + sz); /* ENDR is exclusive */
  386. write_aux_reg(s, paddr);
  387. /* caller waits on DC_CTRL.FS */
  388. }
  389. #endif
  390. #if (CONFIG_ARC_MMU_VER < 3)
  391. #define __cache_line_loop __cache_line_loop_v2
  392. #elif (CONFIG_ARC_MMU_VER == 3)
  393. #define __cache_line_loop __cache_line_loop_v3
  394. #elif (CONFIG_ARC_MMU_VER > 3)
  395. #define __cache_line_loop __cache_line_loop_v4
  396. #endif
  397. #ifdef CONFIG_ARC_HAS_DCACHE
  398. /***************************************************************
  399. * Machine specific helpers for Entire D-Cache or Per Line ops
  400. */
  401. #ifndef USE_RGN_FLSH
  402. /*
  403. * this version avoids extra read/write of DC_CTRL for flush or invalid ops
  404. * in the non region flush regime (such as for ARCompact)
  405. */
  406. static inline void __before_dc_op(const int op)
  407. {
  408. if (op == OP_FLUSH_N_INV) {
  409. /* Dcache provides 2 cmd: FLUSH or INV
  410. * INV inturn has sub-modes: DISCARD or FLUSH-BEFORE
  411. * flush-n-inv is achieved by INV cmd but with IM=1
  412. * So toggle INV sub-mode depending on op request and default
  413. */
  414. const unsigned int ctl = ARC_REG_DC_CTRL;
  415. write_aux_reg(ctl, read_aux_reg(ctl) | DC_CTRL_INV_MODE_FLUSH);
  416. }
  417. }
  418. #else
  419. static inline void __before_dc_op(const int op)
  420. {
  421. const unsigned int ctl = ARC_REG_DC_CTRL;
  422. unsigned int val = read_aux_reg(ctl);
  423. if (op == OP_FLUSH_N_INV) {
  424. val |= DC_CTRL_INV_MODE_FLUSH;
  425. }
  426. if (op != OP_INV_IC) {
  427. /*
  428. * Flush / Invalidate is provided by DC_CTRL.RNG_OP 0 or 1
  429. * combined Flush-n-invalidate uses DC_CTRL.IM = 1 set above
  430. */
  431. val &= ~DC_CTRL_RGN_OP_MSK;
  432. if (op & OP_INV)
  433. val |= DC_CTRL_RGN_OP_INV;
  434. }
  435. write_aux_reg(ctl, val);
  436. }
  437. #endif
  438. static inline void __after_dc_op(const int op)
  439. {
  440. if (op & OP_FLUSH) {
  441. const unsigned int ctl = ARC_REG_DC_CTRL;
  442. unsigned int reg;
  443. /* flush / flush-n-inv both wait */
  444. while ((reg = read_aux_reg(ctl)) & DC_CTRL_FLUSH_STATUS)
  445. ;
  446. /* Switch back to default Invalidate mode */
  447. if (op == OP_FLUSH_N_INV)
  448. write_aux_reg(ctl, reg & ~DC_CTRL_INV_MODE_FLUSH);
  449. }
  450. }
  451. /*
  452. * Operation on Entire D-Cache
  453. * @op = {OP_INV, OP_FLUSH, OP_FLUSH_N_INV}
  454. * Note that constant propagation ensures all the checks are gone
  455. * in generated code
  456. */
  457. static inline void __dc_entire_op(const int op)
  458. {
  459. int aux;
  460. __before_dc_op(op);
  461. if (op & OP_INV) /* Inv or flush-n-inv use same cmd reg */
  462. aux = ARC_REG_DC_IVDC;
  463. else
  464. aux = ARC_REG_DC_FLSH;
  465. write_aux_reg(aux, 0x1);
  466. __after_dc_op(op);
  467. }
  468. static inline void __dc_disable(void)
  469. {
  470. const int r = ARC_REG_DC_CTRL;
  471. __dc_entire_op(OP_FLUSH_N_INV);
  472. write_aux_reg(r, read_aux_reg(r) | DC_CTRL_DIS);
  473. }
  474. static void __dc_enable(void)
  475. {
  476. const int r = ARC_REG_DC_CTRL;
  477. write_aux_reg(r, read_aux_reg(r) & ~DC_CTRL_DIS);
  478. }
  479. /* For kernel mappings cache operation: index is same as paddr */
  480. #define __dc_line_op_k(p, sz, op) __dc_line_op(p, p, sz, op)
  481. /*
  482. * D-Cache Line ops: Per Line INV (discard or wback+discard) or FLUSH (wback)
  483. */
  484. static inline void __dc_line_op(phys_addr_t paddr, unsigned long vaddr,
  485. unsigned long sz, const int op)
  486. {
  487. const int full_page = __builtin_constant_p(sz) && sz == PAGE_SIZE;
  488. unsigned long flags;
  489. local_irq_save(flags);
  490. __before_dc_op(op);
  491. __cache_line_loop(paddr, vaddr, sz, op, full_page);
  492. __after_dc_op(op);
  493. local_irq_restore(flags);
  494. }
  495. #else
  496. #define __dc_entire_op(op)
  497. #define __dc_disable()
  498. #define __dc_enable()
  499. #define __dc_line_op(paddr, vaddr, sz, op)
  500. #define __dc_line_op_k(paddr, sz, op)
  501. #endif /* CONFIG_ARC_HAS_DCACHE */
  502. #ifdef CONFIG_ARC_HAS_ICACHE
  503. static inline void __ic_entire_inv(void)
  504. {
  505. write_aux_reg(ARC_REG_IC_IVIC, 1);
  506. read_aux_reg(ARC_REG_IC_CTRL); /* blocks */
  507. }
  508. static inline void
  509. __ic_line_inv_vaddr_local(phys_addr_t paddr, unsigned long vaddr,
  510. unsigned long sz)
  511. {
  512. const int full_page = __builtin_constant_p(sz) && sz == PAGE_SIZE;
  513. unsigned long flags;
  514. local_irq_save(flags);
  515. (*_cache_line_loop_ic_fn)(paddr, vaddr, sz, OP_INV_IC, full_page);
  516. local_irq_restore(flags);
  517. }
  518. #ifndef CONFIG_SMP
  519. #define __ic_line_inv_vaddr(p, v, s) __ic_line_inv_vaddr_local(p, v, s)
  520. #else
  521. struct ic_inv_args {
  522. phys_addr_t paddr, vaddr;
  523. int sz;
  524. };
  525. static void __ic_line_inv_vaddr_helper(void *info)
  526. {
  527. struct ic_inv_args *ic_inv = info;
  528. __ic_line_inv_vaddr_local(ic_inv->paddr, ic_inv->vaddr, ic_inv->sz);
  529. }
  530. static void __ic_line_inv_vaddr(phys_addr_t paddr, unsigned long vaddr,
  531. unsigned long sz)
  532. {
  533. struct ic_inv_args ic_inv = {
  534. .paddr = paddr,
  535. .vaddr = vaddr,
  536. .sz = sz
  537. };
  538. on_each_cpu(__ic_line_inv_vaddr_helper, &ic_inv, 1);
  539. }
  540. #endif /* CONFIG_SMP */
  541. #else /* !CONFIG_ARC_HAS_ICACHE */
  542. #define __ic_entire_inv()
  543. #define __ic_line_inv_vaddr(pstart, vstart, sz)
  544. #endif /* CONFIG_ARC_HAS_ICACHE */
  545. noinline void slc_op(phys_addr_t paddr, unsigned long sz, const int op)
  546. {
  547. #ifdef CONFIG_ISA_ARCV2
  548. /*
  549. * SLC is shared between all cores and concurrent aux operations from
  550. * multiple cores need to be serialized using a spinlock
  551. * A concurrent operation can be silently ignored and/or the old/new
  552. * operation can remain incomplete forever (lockup in SLC_CTRL_BUSY loop
  553. * below)
  554. */
  555. static DEFINE_SPINLOCK(lock);
  556. unsigned long flags;
  557. unsigned int ctrl;
  558. phys_addr_t end;
  559. spin_lock_irqsave(&lock, flags);
  560. /*
  561. * The Region Flush operation is specified by CTRL.RGN_OP[11..9]
  562. * - b'000 (default) is Flush,
  563. * - b'001 is Invalidate if CTRL.IM == 0
  564. * - b'001 is Flush-n-Invalidate if CTRL.IM == 1
  565. */
  566. ctrl = read_aux_reg(ARC_REG_SLC_CTRL);
  567. /* Don't rely on default value of IM bit */
  568. if (!(op & OP_FLUSH)) /* i.e. OP_INV */
  569. ctrl &= ~SLC_CTRL_IM; /* clear IM: Disable flush before Inv */
  570. else
  571. ctrl |= SLC_CTRL_IM;
  572. if (op & OP_INV)
  573. ctrl |= SLC_CTRL_RGN_OP_INV; /* Inv or flush-n-inv */
  574. else
  575. ctrl &= ~SLC_CTRL_RGN_OP_INV;
  576. write_aux_reg(ARC_REG_SLC_CTRL, ctrl);
  577. /*
  578. * Lower bits are ignored, no need to clip
  579. * END needs to be setup before START (latter triggers the operation)
  580. * END can't be same as START, so add (l2_line_sz - 1) to sz
  581. */
  582. end = paddr + sz + l2_line_sz - 1;
  583. if (is_pae40_enabled())
  584. write_aux_reg(ARC_REG_SLC_RGN_END1, upper_32_bits(end));
  585. write_aux_reg(ARC_REG_SLC_RGN_END, lower_32_bits(end));
  586. if (is_pae40_enabled())
  587. write_aux_reg(ARC_REG_SLC_RGN_START1, upper_32_bits(paddr));
  588. write_aux_reg(ARC_REG_SLC_RGN_START, lower_32_bits(paddr));
  589. /* Make sure "busy" bit reports correct stataus, see STAR 9001165532 */
  590. read_aux_reg(ARC_REG_SLC_CTRL);
  591. while (read_aux_reg(ARC_REG_SLC_CTRL) & SLC_CTRL_BUSY);
  592. spin_unlock_irqrestore(&lock, flags);
  593. #endif
  594. }
  595. noinline static void slc_entire_op(const int op)
  596. {
  597. unsigned int ctrl, r = ARC_REG_SLC_CTRL;
  598. ctrl = read_aux_reg(r);
  599. if (!(op & OP_FLUSH)) /* i.e. OP_INV */
  600. ctrl &= ~SLC_CTRL_IM; /* clear IM: Disable flush before Inv */
  601. else
  602. ctrl |= SLC_CTRL_IM;
  603. write_aux_reg(r, ctrl);
  604. write_aux_reg(ARC_REG_SLC_INVALIDATE, 1);
  605. /* Make sure "busy" bit reports correct stataus, see STAR 9001165532 */
  606. read_aux_reg(r);
  607. /* Important to wait for flush to complete */
  608. while (read_aux_reg(r) & SLC_CTRL_BUSY);
  609. }
  610. static inline void arc_slc_disable(void)
  611. {
  612. const int r = ARC_REG_SLC_CTRL;
  613. slc_entire_op(OP_FLUSH_N_INV);
  614. write_aux_reg(r, read_aux_reg(r) | SLC_CTRL_DIS);
  615. }
  616. static inline void arc_slc_enable(void)
  617. {
  618. const int r = ARC_REG_SLC_CTRL;
  619. write_aux_reg(r, read_aux_reg(r) & ~SLC_CTRL_DIS);
  620. }
  621. /***********************************************************
  622. * Exported APIs
  623. */
  624. /*
  625. * Handle cache congruency of kernel and userspace mappings of page when kernel
  626. * writes-to/reads-from
  627. *
  628. * The idea is to defer flushing of kernel mapping after a WRITE, possible if:
  629. * -dcache is NOT aliasing, hence any U/K-mappings of page are congruent
  630. * -U-mapping doesn't exist yet for page (finalised in update_mmu_cache)
  631. * -In SMP, if hardware caches are coherent
  632. *
  633. * There's a corollary case, where kernel READs from a userspace mapped page.
  634. * If the U-mapping is not congruent to to K-mapping, former needs flushing.
  635. */
  636. void flush_dcache_page(struct page *page)
  637. {
  638. struct address_space *mapping;
  639. if (!cache_is_vipt_aliasing()) {
  640. clear_bit(PG_dc_clean, &page->flags);
  641. return;
  642. }
  643. /* don't handle anon pages here */
  644. mapping = page_mapping(page);
  645. if (!mapping)
  646. return;
  647. /*
  648. * pagecache page, file not yet mapped to userspace
  649. * Make a note that K-mapping is dirty
  650. */
  651. if (!mapping_mapped(mapping)) {
  652. clear_bit(PG_dc_clean, &page->flags);
  653. } else if (page_mapcount(page)) {
  654. /* kernel reading from page with U-mapping */
  655. phys_addr_t paddr = (unsigned long)page_address(page);
  656. unsigned long vaddr = page->index << PAGE_SHIFT;
  657. if (addr_not_cache_congruent(paddr, vaddr))
  658. __flush_dcache_page(paddr, vaddr);
  659. }
  660. }
  661. EXPORT_SYMBOL(flush_dcache_page);
  662. /*
  663. * DMA ops for systems with L1 cache only
  664. * Make memory coherent with L1 cache by flushing/invalidating L1 lines
  665. */
  666. static void __dma_cache_wback_inv_l1(phys_addr_t start, unsigned long sz)
  667. {
  668. __dc_line_op_k(start, sz, OP_FLUSH_N_INV);
  669. }
  670. static void __dma_cache_inv_l1(phys_addr_t start, unsigned long sz)
  671. {
  672. __dc_line_op_k(start, sz, OP_INV);
  673. }
  674. static void __dma_cache_wback_l1(phys_addr_t start, unsigned long sz)
  675. {
  676. __dc_line_op_k(start, sz, OP_FLUSH);
  677. }
  678. /*
  679. * DMA ops for systems with both L1 and L2 caches, but without IOC
  680. * Both L1 and L2 lines need to be explicitly flushed/invalidated
  681. */
  682. static void __dma_cache_wback_inv_slc(phys_addr_t start, unsigned long sz)
  683. {
  684. __dc_line_op_k(start, sz, OP_FLUSH_N_INV);
  685. slc_op(start, sz, OP_FLUSH_N_INV);
  686. }
  687. static void __dma_cache_inv_slc(phys_addr_t start, unsigned long sz)
  688. {
  689. __dc_line_op_k(start, sz, OP_INV);
  690. slc_op(start, sz, OP_INV);
  691. }
  692. static void __dma_cache_wback_slc(phys_addr_t start, unsigned long sz)
  693. {
  694. __dc_line_op_k(start, sz, OP_FLUSH);
  695. slc_op(start, sz, OP_FLUSH);
  696. }
  697. /*
  698. * DMA ops for systems with IOC
  699. * IOC hardware snoops all DMA traffic keeping the caches consistent with
  700. * memory - eliding need for any explicit cache maintenance of DMA buffers
  701. */
  702. static void __dma_cache_wback_inv_ioc(phys_addr_t start, unsigned long sz) {}
  703. static void __dma_cache_inv_ioc(phys_addr_t start, unsigned long sz) {}
  704. static void __dma_cache_wback_ioc(phys_addr_t start, unsigned long sz) {}
  705. /*
  706. * Exported DMA API
  707. */
  708. void dma_cache_wback_inv(phys_addr_t start, unsigned long sz)
  709. {
  710. __dma_cache_wback_inv(start, sz);
  711. }
  712. EXPORT_SYMBOL(dma_cache_wback_inv);
  713. void dma_cache_inv(phys_addr_t start, unsigned long sz)
  714. {
  715. __dma_cache_inv(start, sz);
  716. }
  717. EXPORT_SYMBOL(dma_cache_inv);
  718. void dma_cache_wback(phys_addr_t start, unsigned long sz)
  719. {
  720. __dma_cache_wback(start, sz);
  721. }
  722. EXPORT_SYMBOL(dma_cache_wback);
  723. /*
  724. * This is API for making I/D Caches consistent when modifying
  725. * kernel code (loadable modules, kprobes, kgdb...)
  726. * This is called on insmod, with kernel virtual address for CODE of
  727. * the module. ARC cache maintenance ops require PHY address thus we
  728. * need to convert vmalloc addr to PHY addr
  729. */
  730. void flush_icache_range(unsigned long kstart, unsigned long kend)
  731. {
  732. unsigned int tot_sz;
  733. WARN(kstart < TASK_SIZE, "%s() can't handle user vaddr", __func__);
  734. /* Shortcut for bigger flush ranges.
  735. * Here we don't care if this was kernel virtual or phy addr
  736. */
  737. tot_sz = kend - kstart;
  738. if (tot_sz > PAGE_SIZE) {
  739. flush_cache_all();
  740. return;
  741. }
  742. /* Case: Kernel Phy addr (0x8000_0000 onwards) */
  743. if (likely(kstart > PAGE_OFFSET)) {
  744. /*
  745. * The 2nd arg despite being paddr will be used to index icache
  746. * This is OK since no alternate virtual mappings will exist
  747. * given the callers for this case: kprobe/kgdb in built-in
  748. * kernel code only.
  749. */
  750. __sync_icache_dcache(kstart, kstart, kend - kstart);
  751. return;
  752. }
  753. /*
  754. * Case: Kernel Vaddr (0x7000_0000 to 0x7fff_ffff)
  755. * (1) ARC Cache Maintenance ops only take Phy addr, hence special
  756. * handling of kernel vaddr.
  757. *
  758. * (2) Despite @tot_sz being < PAGE_SIZE (bigger cases handled already),
  759. * it still needs to handle a 2 page scenario, where the range
  760. * straddles across 2 virtual pages and hence need for loop
  761. */
  762. while (tot_sz > 0) {
  763. unsigned int off, sz;
  764. unsigned long phy, pfn;
  765. off = kstart % PAGE_SIZE;
  766. pfn = vmalloc_to_pfn((void *)kstart);
  767. phy = (pfn << PAGE_SHIFT) + off;
  768. sz = min_t(unsigned int, tot_sz, PAGE_SIZE - off);
  769. __sync_icache_dcache(phy, kstart, sz);
  770. kstart += sz;
  771. tot_sz -= sz;
  772. }
  773. }
  774. EXPORT_SYMBOL(flush_icache_range);
  775. /*
  776. * General purpose helper to make I and D cache lines consistent.
  777. * @paddr is phy addr of region
  778. * @vaddr is typically user vaddr (breakpoint) or kernel vaddr (vmalloc)
  779. * However in one instance, when called by kprobe (for a breakpt in
  780. * builtin kernel code) @vaddr will be paddr only, meaning CDU operation will
  781. * use a paddr to index the cache (despite VIPT). This is fine since since a
  782. * builtin kernel page will not have any virtual mappings.
  783. * kprobe on loadable module will be kernel vaddr.
  784. */
  785. void __sync_icache_dcache(phys_addr_t paddr, unsigned long vaddr, int len)
  786. {
  787. __dc_line_op(paddr, vaddr, len, OP_FLUSH_N_INV);
  788. __ic_line_inv_vaddr(paddr, vaddr, len);
  789. }
  790. /* wrapper to compile time eliminate alignment checks in flush loop */
  791. void __inv_icache_page(phys_addr_t paddr, unsigned long vaddr)
  792. {
  793. __ic_line_inv_vaddr(paddr, vaddr, PAGE_SIZE);
  794. }
  795. /*
  796. * wrapper to clearout kernel or userspace mappings of a page
  797. * For kernel mappings @vaddr == @paddr
  798. */
  799. void __flush_dcache_page(phys_addr_t paddr, unsigned long vaddr)
  800. {
  801. __dc_line_op(paddr, vaddr & PAGE_MASK, PAGE_SIZE, OP_FLUSH_N_INV);
  802. }
  803. noinline void flush_cache_all(void)
  804. {
  805. unsigned long flags;
  806. local_irq_save(flags);
  807. __ic_entire_inv();
  808. __dc_entire_op(OP_FLUSH_N_INV);
  809. local_irq_restore(flags);
  810. }
  811. #ifdef CONFIG_ARC_CACHE_VIPT_ALIASING
  812. void flush_cache_mm(struct mm_struct *mm)
  813. {
  814. flush_cache_all();
  815. }
  816. void flush_cache_page(struct vm_area_struct *vma, unsigned long u_vaddr,
  817. unsigned long pfn)
  818. {
  819. unsigned int paddr = pfn << PAGE_SHIFT;
  820. u_vaddr &= PAGE_MASK;
  821. __flush_dcache_page(paddr, u_vaddr);
  822. if (vma->vm_flags & VM_EXEC)
  823. __inv_icache_page(paddr, u_vaddr);
  824. }
  825. void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  826. unsigned long end)
  827. {
  828. flush_cache_all();
  829. }
  830. void flush_anon_page(struct vm_area_struct *vma, struct page *page,
  831. unsigned long u_vaddr)
  832. {
  833. /* TBD: do we really need to clear the kernel mapping */
  834. __flush_dcache_page(page_address(page), u_vaddr);
  835. __flush_dcache_page(page_address(page), page_address(page));
  836. }
  837. #endif
  838. void copy_user_highpage(struct page *to, struct page *from,
  839. unsigned long u_vaddr, struct vm_area_struct *vma)
  840. {
  841. void *kfrom = kmap_atomic(from);
  842. void *kto = kmap_atomic(to);
  843. int clean_src_k_mappings = 0;
  844. /*
  845. * If SRC page was already mapped in userspace AND it's U-mapping is
  846. * not congruent with K-mapping, sync former to physical page so that
  847. * K-mapping in memcpy below, sees the right data
  848. *
  849. * Note that while @u_vaddr refers to DST page's userspace vaddr, it is
  850. * equally valid for SRC page as well
  851. *
  852. * For !VIPT cache, all of this gets compiled out as
  853. * addr_not_cache_congruent() is 0
  854. */
  855. if (page_mapcount(from) && addr_not_cache_congruent(kfrom, u_vaddr)) {
  856. __flush_dcache_page((unsigned long)kfrom, u_vaddr);
  857. clean_src_k_mappings = 1;
  858. }
  859. copy_page(kto, kfrom);
  860. /*
  861. * Mark DST page K-mapping as dirty for a later finalization by
  862. * update_mmu_cache(). Although the finalization could have been done
  863. * here as well (given that both vaddr/paddr are available).
  864. * But update_mmu_cache() already has code to do that for other
  865. * non copied user pages (e.g. read faults which wire in pagecache page
  866. * directly).
  867. */
  868. clear_bit(PG_dc_clean, &to->flags);
  869. /*
  870. * if SRC was already usermapped and non-congruent to kernel mapping
  871. * sync the kernel mapping back to physical page
  872. */
  873. if (clean_src_k_mappings) {
  874. __flush_dcache_page((unsigned long)kfrom, (unsigned long)kfrom);
  875. set_bit(PG_dc_clean, &from->flags);
  876. } else {
  877. clear_bit(PG_dc_clean, &from->flags);
  878. }
  879. kunmap_atomic(kto);
  880. kunmap_atomic(kfrom);
  881. }
  882. void clear_user_page(void *to, unsigned long u_vaddr, struct page *page)
  883. {
  884. clear_page(to);
  885. clear_bit(PG_dc_clean, &page->flags);
  886. }
  887. /**********************************************************************
  888. * Explicit Cache flush request from user space via syscall
  889. * Needed for JITs which generate code on the fly
  890. */
  891. SYSCALL_DEFINE3(cacheflush, uint32_t, start, uint32_t, sz, uint32_t, flags)
  892. {
  893. /* TBD: optimize this */
  894. flush_cache_all();
  895. return 0;
  896. }
  897. /*
  898. * IO-Coherency (IOC) setup rules:
  899. *
  900. * 1. Needs to be at system level, so only once by Master core
  901. * Non-Masters need not be accessing caches at that time
  902. * - They are either HALT_ON_RESET and kick started much later or
  903. * - if run on reset, need to ensure that arc_platform_smp_wait_to_boot()
  904. * doesn't perturb caches or coherency unit
  905. *
  906. * 2. caches (L1 and SLC) need to be purged (flush+inv) before setting up IOC,
  907. * otherwise any straggler data might behave strangely post IOC enabling
  908. *
  909. * 3. All Caches need to be disabled when setting up IOC to elide any in-flight
  910. * Coherency transactions
  911. */
  912. noinline void __init arc_ioc_setup(void)
  913. {
  914. unsigned int ap_sz;
  915. /* Flush + invalidate + disable L1 dcache */
  916. __dc_disable();
  917. /* Flush + invalidate SLC */
  918. if (read_aux_reg(ARC_REG_SLC_BCR))
  919. slc_entire_op(OP_FLUSH_N_INV);
  920. /* IOC Aperture start: TDB: handle non default CONFIG_LINUX_LINK_BASE */
  921. write_aux_reg(ARC_REG_IO_COH_AP0_BASE, 0x80000);
  922. /*
  923. * IOC Aperture size:
  924. * decoded as 2 ^ (SIZE + 2) KB: so setting 0x11 implies 512M
  925. * TBD: fix for PGU + 1GB of low mem
  926. * TBD: fix for PAE
  927. */
  928. ap_sz = order_base_2(arc_get_mem_sz()/1024) - 2;
  929. write_aux_reg(ARC_REG_IO_COH_AP0_SIZE, ap_sz);
  930. write_aux_reg(ARC_REG_IO_COH_PARTIAL, 1);
  931. write_aux_reg(ARC_REG_IO_COH_ENABLE, 1);
  932. /* Re-enable L1 dcache */
  933. __dc_enable();
  934. }
  935. /*
  936. * Cache related boot time checks/setups only needed on master CPU:
  937. * - Geometry checks (kernel build and hardware agree: e.g. L1_CACHE_BYTES)
  938. * Assume SMP only, so all cores will have same cache config. A check on
  939. * one core suffices for all
  940. * - IOC setup / dma callbacks only need to be done once
  941. */
  942. void __init arc_cache_init_master(void)
  943. {
  944. unsigned int __maybe_unused cpu = smp_processor_id();
  945. if (IS_ENABLED(CONFIG_ARC_HAS_ICACHE)) {
  946. struct cpuinfo_arc_cache *ic = &cpuinfo_arc700[cpu].icache;
  947. if (!ic->line_len)
  948. panic("cache support enabled but non-existent cache\n");
  949. if (ic->line_len != L1_CACHE_BYTES)
  950. panic("ICache line [%d] != kernel Config [%d]",
  951. ic->line_len, L1_CACHE_BYTES);
  952. /*
  953. * In MMU v4 (HS38x) the aliasing icache config uses IVIL/PTAG
  954. * pair to provide vaddr/paddr respectively, just as in MMU v3
  955. */
  956. if (is_isa_arcv2() && ic->alias)
  957. _cache_line_loop_ic_fn = __cache_line_loop_v3;
  958. else
  959. _cache_line_loop_ic_fn = __cache_line_loop;
  960. }
  961. if (IS_ENABLED(CONFIG_ARC_HAS_DCACHE)) {
  962. struct cpuinfo_arc_cache *dc = &cpuinfo_arc700[cpu].dcache;
  963. if (!dc->line_len)
  964. panic("cache support enabled but non-existent cache\n");
  965. if (dc->line_len != L1_CACHE_BYTES)
  966. panic("DCache line [%d] != kernel Config [%d]",
  967. dc->line_len, L1_CACHE_BYTES);
  968. /* check for D-Cache aliasing on ARCompact: ARCv2 has PIPT */
  969. if (is_isa_arcompact()) {
  970. int handled = IS_ENABLED(CONFIG_ARC_CACHE_VIPT_ALIASING);
  971. int num_colors = dc->sz_k/dc->assoc/TO_KB(PAGE_SIZE);
  972. if (dc->alias) {
  973. if (!handled)
  974. panic("Enable CONFIG_ARC_CACHE_VIPT_ALIASING\n");
  975. if (CACHE_COLORS_NUM != num_colors)
  976. panic("CACHE_COLORS_NUM not optimized for config\n");
  977. } else if (!dc->alias && handled) {
  978. panic("Disable CONFIG_ARC_CACHE_VIPT_ALIASING\n");
  979. }
  980. }
  981. }
  982. /* Note that SLC disable not formally supported till HS 3.0 */
  983. if (is_isa_arcv2() && l2_line_sz && !slc_enable)
  984. arc_slc_disable();
  985. if (is_isa_arcv2() && ioc_enable)
  986. arc_ioc_setup();
  987. if (is_isa_arcv2() && ioc_enable) {
  988. __dma_cache_wback_inv = __dma_cache_wback_inv_ioc;
  989. __dma_cache_inv = __dma_cache_inv_ioc;
  990. __dma_cache_wback = __dma_cache_wback_ioc;
  991. } else if (is_isa_arcv2() && l2_line_sz && slc_enable) {
  992. __dma_cache_wback_inv = __dma_cache_wback_inv_slc;
  993. __dma_cache_inv = __dma_cache_inv_slc;
  994. __dma_cache_wback = __dma_cache_wback_slc;
  995. } else {
  996. __dma_cache_wback_inv = __dma_cache_wback_inv_l1;
  997. __dma_cache_inv = __dma_cache_inv_l1;
  998. __dma_cache_wback = __dma_cache_wback_l1;
  999. }
  1000. }
  1001. void __ref arc_cache_init(void)
  1002. {
  1003. unsigned int __maybe_unused cpu = smp_processor_id();
  1004. char str[256];
  1005. printk(arc_cache_mumbojumbo(0, str, sizeof(str)));
  1006. if (!cpu)
  1007. arc_cache_init_master();
  1008. /*
  1009. * In PAE regime, TLB and cache maintenance ops take wider addresses
  1010. * And even if PAE is not enabled in kernel, the upper 32-bits still need
  1011. * to be zeroed to keep the ops sane.
  1012. * As an optimization for more common !PAE enabled case, zero them out
  1013. * once at init, rather than checking/setting to 0 for every runtime op
  1014. */
  1015. if (is_isa_arcv2() && pae40_exist_but_not_enab()) {
  1016. if (IS_ENABLED(CONFIG_ARC_HAS_ICACHE))
  1017. write_aux_reg(ARC_REG_IC_PTAG_HI, 0);
  1018. if (IS_ENABLED(CONFIG_ARC_HAS_DCACHE))
  1019. write_aux_reg(ARC_REG_DC_PTAG_HI, 0);
  1020. if (l2_line_sz) {
  1021. write_aux_reg(ARC_REG_SLC_RGN_END1, 0);
  1022. write_aux_reg(ARC_REG_SLC_RGN_START1, 0);
  1023. }
  1024. }
  1025. }