cache-l2x0.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805
  1. /*
  2. * arch/arm/mm/cache-l2x0.c - L210/L220/L310 cache controller support
  3. *
  4. * Copyright (C) 2007 ARM Limited
  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. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/cpu.h>
  20. #include <linux/err.h>
  21. #include <linux/init.h>
  22. #include <linux/smp.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/log2.h>
  25. #include <linux/io.h>
  26. #include <linux/of.h>
  27. #include <linux/of_address.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/cp15.h>
  30. #include <asm/cputype.h>
  31. #include <asm/hardware/cache-l2x0.h>
  32. #include "cache-tauros3.h"
  33. #include "cache-aurora-l2.h"
  34. struct l2c_init_data {
  35. const char *type;
  36. unsigned way_size_0;
  37. unsigned num_lock;
  38. void (*of_parse)(const struct device_node *, u32 *, u32 *);
  39. void (*enable)(void __iomem *, unsigned);
  40. void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
  41. void (*save)(void __iomem *);
  42. void (*configure)(void __iomem *);
  43. void (*unlock)(void __iomem *, unsigned);
  44. struct outer_cache_fns outer_cache;
  45. };
  46. #define CACHE_LINE_SIZE 32
  47. static void __iomem *l2x0_base;
  48. static const struct l2c_init_data *l2x0_data;
  49. static DEFINE_RAW_SPINLOCK(l2x0_lock);
  50. static u32 l2x0_way_mask; /* Bitmask of active ways */
  51. static u32 l2x0_size;
  52. static unsigned long sync_reg_offset = L2X0_CACHE_SYNC;
  53. struct l2x0_regs l2x0_saved_regs;
  54. /*
  55. * Common code for all cache controllers.
  56. */
  57. static inline void l2c_wait_mask(void __iomem *reg, unsigned long mask)
  58. {
  59. /* wait for cache operation by line or way to complete */
  60. while (readl_relaxed(reg) & mask)
  61. cpu_relax();
  62. }
  63. /*
  64. * By default, we write directly to secure registers. Platforms must
  65. * override this if they are running non-secure.
  66. */
  67. static void l2c_write_sec(unsigned long val, void __iomem *base, unsigned reg)
  68. {
  69. if (val == readl_relaxed(base + reg))
  70. return;
  71. if (outer_cache.write_sec)
  72. outer_cache.write_sec(val, reg);
  73. else
  74. writel_relaxed(val, base + reg);
  75. }
  76. /*
  77. * This should only be called when we have a requirement that the
  78. * register be written due to a work-around, as platforms running
  79. * in non-secure mode may not be able to access this register.
  80. */
  81. static inline void l2c_set_debug(void __iomem *base, unsigned long val)
  82. {
  83. l2c_write_sec(val, base, L2X0_DEBUG_CTRL);
  84. }
  85. static void __l2c_op_way(void __iomem *reg)
  86. {
  87. writel_relaxed(l2x0_way_mask, reg);
  88. l2c_wait_mask(reg, l2x0_way_mask);
  89. }
  90. static inline void l2c_unlock(void __iomem *base, unsigned num)
  91. {
  92. unsigned i;
  93. for (i = 0; i < num; i++) {
  94. writel_relaxed(0, base + L2X0_LOCKDOWN_WAY_D_BASE +
  95. i * L2X0_LOCKDOWN_STRIDE);
  96. writel_relaxed(0, base + L2X0_LOCKDOWN_WAY_I_BASE +
  97. i * L2X0_LOCKDOWN_STRIDE);
  98. }
  99. }
  100. static void l2c_configure(void __iomem *base)
  101. {
  102. l2c_write_sec(l2x0_saved_regs.aux_ctrl, base, L2X0_AUX_CTRL);
  103. }
  104. /*
  105. * Enable the L2 cache controller. This function must only be
  106. * called when the cache controller is known to be disabled.
  107. */
  108. static void l2c_enable(void __iomem *base, unsigned num_lock)
  109. {
  110. unsigned long flags;
  111. if (outer_cache.configure)
  112. outer_cache.configure(&l2x0_saved_regs);
  113. else
  114. l2x0_data->configure(base);
  115. l2x0_data->unlock(base, num_lock);
  116. local_irq_save(flags);
  117. __l2c_op_way(base + L2X0_INV_WAY);
  118. writel_relaxed(0, base + sync_reg_offset);
  119. l2c_wait_mask(base + sync_reg_offset, 1);
  120. local_irq_restore(flags);
  121. l2c_write_sec(L2X0_CTRL_EN, base, L2X0_CTRL);
  122. }
  123. static void l2c_disable(void)
  124. {
  125. void __iomem *base = l2x0_base;
  126. outer_cache.flush_all();
  127. l2c_write_sec(0, base, L2X0_CTRL);
  128. dsb(st);
  129. }
  130. static void l2c_save(void __iomem *base)
  131. {
  132. l2x0_saved_regs.aux_ctrl = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  133. }
  134. static void l2c_resume(void)
  135. {
  136. void __iomem *base = l2x0_base;
  137. /* Do not touch the controller if already enabled. */
  138. if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN))
  139. l2c_enable(base, l2x0_data->num_lock);
  140. }
  141. /*
  142. * L2C-210 specific code.
  143. *
  144. * The L2C-2x0 PA, set/way and sync operations are atomic, but we must
  145. * ensure that no background operation is running. The way operations
  146. * are all background tasks.
  147. *
  148. * While a background operation is in progress, any new operation is
  149. * ignored (unspecified whether this causes an error.) Thankfully, not
  150. * used on SMP.
  151. *
  152. * Never has a different sync register other than L2X0_CACHE_SYNC, but
  153. * we use sync_reg_offset here so we can share some of this with L2C-310.
  154. */
  155. static void __l2c210_cache_sync(void __iomem *base)
  156. {
  157. writel_relaxed(0, base + sync_reg_offset);
  158. }
  159. static void __l2c210_op_pa_range(void __iomem *reg, unsigned long start,
  160. unsigned long end)
  161. {
  162. while (start < end) {
  163. writel_relaxed(start, reg);
  164. start += CACHE_LINE_SIZE;
  165. }
  166. }
  167. static void l2c210_inv_range(unsigned long start, unsigned long end)
  168. {
  169. void __iomem *base = l2x0_base;
  170. if (start & (CACHE_LINE_SIZE - 1)) {
  171. start &= ~(CACHE_LINE_SIZE - 1);
  172. writel_relaxed(start, base + L2X0_CLEAN_INV_LINE_PA);
  173. start += CACHE_LINE_SIZE;
  174. }
  175. if (end & (CACHE_LINE_SIZE - 1)) {
  176. end &= ~(CACHE_LINE_SIZE - 1);
  177. writel_relaxed(end, base + L2X0_CLEAN_INV_LINE_PA);
  178. }
  179. __l2c210_op_pa_range(base + L2X0_INV_LINE_PA, start, end);
  180. __l2c210_cache_sync(base);
  181. }
  182. static void l2c210_clean_range(unsigned long start, unsigned long end)
  183. {
  184. void __iomem *base = l2x0_base;
  185. start &= ~(CACHE_LINE_SIZE - 1);
  186. __l2c210_op_pa_range(base + L2X0_CLEAN_LINE_PA, start, end);
  187. __l2c210_cache_sync(base);
  188. }
  189. static void l2c210_flush_range(unsigned long start, unsigned long end)
  190. {
  191. void __iomem *base = l2x0_base;
  192. start &= ~(CACHE_LINE_SIZE - 1);
  193. __l2c210_op_pa_range(base + L2X0_CLEAN_INV_LINE_PA, start, end);
  194. __l2c210_cache_sync(base);
  195. }
  196. static void l2c210_flush_all(void)
  197. {
  198. void __iomem *base = l2x0_base;
  199. BUG_ON(!irqs_disabled());
  200. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  201. __l2c210_cache_sync(base);
  202. }
  203. static void l2c210_sync(void)
  204. {
  205. __l2c210_cache_sync(l2x0_base);
  206. }
  207. static const struct l2c_init_data l2c210_data __initconst = {
  208. .type = "L2C-210",
  209. .way_size_0 = SZ_8K,
  210. .num_lock = 1,
  211. .enable = l2c_enable,
  212. .save = l2c_save,
  213. .configure = l2c_configure,
  214. .unlock = l2c_unlock,
  215. .outer_cache = {
  216. .inv_range = l2c210_inv_range,
  217. .clean_range = l2c210_clean_range,
  218. .flush_range = l2c210_flush_range,
  219. .flush_all = l2c210_flush_all,
  220. .disable = l2c_disable,
  221. .sync = l2c210_sync,
  222. .resume = l2c_resume,
  223. },
  224. };
  225. /*
  226. * L2C-220 specific code.
  227. *
  228. * All operations are background operations: they have to be waited for.
  229. * Conflicting requests generate a slave error (which will cause an
  230. * imprecise abort.) Never uses sync_reg_offset, so we hard-code the
  231. * sync register here.
  232. *
  233. * However, we can re-use the l2c210_resume call.
  234. */
  235. static inline void __l2c220_cache_sync(void __iomem *base)
  236. {
  237. writel_relaxed(0, base + L2X0_CACHE_SYNC);
  238. l2c_wait_mask(base + L2X0_CACHE_SYNC, 1);
  239. }
  240. static void l2c220_op_way(void __iomem *base, unsigned reg)
  241. {
  242. unsigned long flags;
  243. raw_spin_lock_irqsave(&l2x0_lock, flags);
  244. __l2c_op_way(base + reg);
  245. __l2c220_cache_sync(base);
  246. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  247. }
  248. static unsigned long l2c220_op_pa_range(void __iomem *reg, unsigned long start,
  249. unsigned long end, unsigned long flags)
  250. {
  251. raw_spinlock_t *lock = &l2x0_lock;
  252. while (start < end) {
  253. unsigned long blk_end = start + min(end - start, 4096UL);
  254. while (start < blk_end) {
  255. l2c_wait_mask(reg, 1);
  256. writel_relaxed(start, reg);
  257. start += CACHE_LINE_SIZE;
  258. }
  259. if (blk_end < end) {
  260. raw_spin_unlock_irqrestore(lock, flags);
  261. raw_spin_lock_irqsave(lock, flags);
  262. }
  263. }
  264. return flags;
  265. }
  266. static void l2c220_inv_range(unsigned long start, unsigned long end)
  267. {
  268. void __iomem *base = l2x0_base;
  269. unsigned long flags;
  270. raw_spin_lock_irqsave(&l2x0_lock, flags);
  271. if ((start | end) & (CACHE_LINE_SIZE - 1)) {
  272. if (start & (CACHE_LINE_SIZE - 1)) {
  273. start &= ~(CACHE_LINE_SIZE - 1);
  274. writel_relaxed(start, base + L2X0_CLEAN_INV_LINE_PA);
  275. start += CACHE_LINE_SIZE;
  276. }
  277. if (end & (CACHE_LINE_SIZE - 1)) {
  278. end &= ~(CACHE_LINE_SIZE - 1);
  279. l2c_wait_mask(base + L2X0_CLEAN_INV_LINE_PA, 1);
  280. writel_relaxed(end, base + L2X0_CLEAN_INV_LINE_PA);
  281. }
  282. }
  283. flags = l2c220_op_pa_range(base + L2X0_INV_LINE_PA,
  284. start, end, flags);
  285. l2c_wait_mask(base + L2X0_INV_LINE_PA, 1);
  286. __l2c220_cache_sync(base);
  287. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  288. }
  289. static void l2c220_clean_range(unsigned long start, unsigned long end)
  290. {
  291. void __iomem *base = l2x0_base;
  292. unsigned long flags;
  293. start &= ~(CACHE_LINE_SIZE - 1);
  294. if ((end - start) >= l2x0_size) {
  295. l2c220_op_way(base, L2X0_CLEAN_WAY);
  296. return;
  297. }
  298. raw_spin_lock_irqsave(&l2x0_lock, flags);
  299. flags = l2c220_op_pa_range(base + L2X0_CLEAN_LINE_PA,
  300. start, end, flags);
  301. l2c_wait_mask(base + L2X0_CLEAN_INV_LINE_PA, 1);
  302. __l2c220_cache_sync(base);
  303. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  304. }
  305. static void l2c220_flush_range(unsigned long start, unsigned long end)
  306. {
  307. void __iomem *base = l2x0_base;
  308. unsigned long flags;
  309. start &= ~(CACHE_LINE_SIZE - 1);
  310. if ((end - start) >= l2x0_size) {
  311. l2c220_op_way(base, L2X0_CLEAN_INV_WAY);
  312. return;
  313. }
  314. raw_spin_lock_irqsave(&l2x0_lock, flags);
  315. flags = l2c220_op_pa_range(base + L2X0_CLEAN_INV_LINE_PA,
  316. start, end, flags);
  317. l2c_wait_mask(base + L2X0_CLEAN_INV_LINE_PA, 1);
  318. __l2c220_cache_sync(base);
  319. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  320. }
  321. static void l2c220_flush_all(void)
  322. {
  323. l2c220_op_way(l2x0_base, L2X0_CLEAN_INV_WAY);
  324. }
  325. static void l2c220_sync(void)
  326. {
  327. unsigned long flags;
  328. raw_spin_lock_irqsave(&l2x0_lock, flags);
  329. __l2c220_cache_sync(l2x0_base);
  330. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  331. }
  332. static void l2c220_enable(void __iomem *base, unsigned num_lock)
  333. {
  334. /*
  335. * Always enable non-secure access to the lockdown registers -
  336. * we write to them as part of the L2C enable sequence so they
  337. * need to be accessible.
  338. */
  339. l2x0_saved_regs.aux_ctrl |= L220_AUX_CTRL_NS_LOCKDOWN;
  340. l2c_enable(base, num_lock);
  341. }
  342. static void l2c220_unlock(void __iomem *base, unsigned num_lock)
  343. {
  344. if (readl_relaxed(base + L2X0_AUX_CTRL) & L220_AUX_CTRL_NS_LOCKDOWN)
  345. l2c_unlock(base, num_lock);
  346. }
  347. static const struct l2c_init_data l2c220_data = {
  348. .type = "L2C-220",
  349. .way_size_0 = SZ_8K,
  350. .num_lock = 1,
  351. .enable = l2c220_enable,
  352. .save = l2c_save,
  353. .configure = l2c_configure,
  354. .unlock = l2c220_unlock,
  355. .outer_cache = {
  356. .inv_range = l2c220_inv_range,
  357. .clean_range = l2c220_clean_range,
  358. .flush_range = l2c220_flush_range,
  359. .flush_all = l2c220_flush_all,
  360. .disable = l2c_disable,
  361. .sync = l2c220_sync,
  362. .resume = l2c_resume,
  363. },
  364. };
  365. /*
  366. * L2C-310 specific code.
  367. *
  368. * Very similar to L2C-210, the PA, set/way and sync operations are atomic,
  369. * and the way operations are all background tasks. However, issuing an
  370. * operation while a background operation is in progress results in a
  371. * SLVERR response. We can reuse:
  372. *
  373. * __l2c210_cache_sync (using sync_reg_offset)
  374. * l2c210_sync
  375. * l2c210_inv_range (if 588369 is not applicable)
  376. * l2c210_clean_range
  377. * l2c210_flush_range (if 588369 is not applicable)
  378. * l2c210_flush_all (if 727915 is not applicable)
  379. *
  380. * Errata:
  381. * 588369: PL310 R0P0->R1P0, fixed R2P0.
  382. * Affects: all clean+invalidate operations
  383. * clean and invalidate skips the invalidate step, so we need to issue
  384. * separate operations. We also require the above debug workaround
  385. * enclosing this code fragment on affected parts. On unaffected parts,
  386. * we must not use this workaround without the debug register writes
  387. * to avoid exposing a problem similar to 727915.
  388. *
  389. * 727915: PL310 R2P0->R3P0, fixed R3P1.
  390. * Affects: clean+invalidate by way
  391. * clean and invalidate by way runs in the background, and a store can
  392. * hit the line between the clean operation and invalidate operation,
  393. * resulting in the store being lost.
  394. *
  395. * 752271: PL310 R3P0->R3P1-50REL0, fixed R3P2.
  396. * Affects: 8x64-bit (double fill) line fetches
  397. * double fill line fetches can fail to cause dirty data to be evicted
  398. * from the cache before the new data overwrites the second line.
  399. *
  400. * 753970: PL310 R3P0, fixed R3P1.
  401. * Affects: sync
  402. * prevents merging writes after the sync operation, until another L2C
  403. * operation is performed (or a number of other conditions.)
  404. *
  405. * 769419: PL310 R0P0->R3P1, fixed R3P2.
  406. * Affects: store buffer
  407. * store buffer is not automatically drained.
  408. */
  409. static void l2c310_inv_range_erratum(unsigned long start, unsigned long end)
  410. {
  411. void __iomem *base = l2x0_base;
  412. if ((start | end) & (CACHE_LINE_SIZE - 1)) {
  413. unsigned long flags;
  414. /* Erratum 588369 for both clean+invalidate operations */
  415. raw_spin_lock_irqsave(&l2x0_lock, flags);
  416. l2c_set_debug(base, 0x03);
  417. if (start & (CACHE_LINE_SIZE - 1)) {
  418. start &= ~(CACHE_LINE_SIZE - 1);
  419. writel_relaxed(start, base + L2X0_CLEAN_LINE_PA);
  420. writel_relaxed(start, base + L2X0_INV_LINE_PA);
  421. start += CACHE_LINE_SIZE;
  422. }
  423. if (end & (CACHE_LINE_SIZE - 1)) {
  424. end &= ~(CACHE_LINE_SIZE - 1);
  425. writel_relaxed(end, base + L2X0_CLEAN_LINE_PA);
  426. writel_relaxed(end, base + L2X0_INV_LINE_PA);
  427. }
  428. l2c_set_debug(base, 0x00);
  429. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  430. }
  431. __l2c210_op_pa_range(base + L2X0_INV_LINE_PA, start, end);
  432. __l2c210_cache_sync(base);
  433. }
  434. static void l2c310_flush_range_erratum(unsigned long start, unsigned long end)
  435. {
  436. raw_spinlock_t *lock = &l2x0_lock;
  437. unsigned long flags;
  438. void __iomem *base = l2x0_base;
  439. raw_spin_lock_irqsave(lock, flags);
  440. while (start < end) {
  441. unsigned long blk_end = start + min(end - start, 4096UL);
  442. l2c_set_debug(base, 0x03);
  443. while (start < blk_end) {
  444. writel_relaxed(start, base + L2X0_CLEAN_LINE_PA);
  445. writel_relaxed(start, base + L2X0_INV_LINE_PA);
  446. start += CACHE_LINE_SIZE;
  447. }
  448. l2c_set_debug(base, 0x00);
  449. if (blk_end < end) {
  450. raw_spin_unlock_irqrestore(lock, flags);
  451. raw_spin_lock_irqsave(lock, flags);
  452. }
  453. }
  454. raw_spin_unlock_irqrestore(lock, flags);
  455. __l2c210_cache_sync(base);
  456. }
  457. static void l2c310_flush_all_erratum(void)
  458. {
  459. void __iomem *base = l2x0_base;
  460. unsigned long flags;
  461. raw_spin_lock_irqsave(&l2x0_lock, flags);
  462. l2c_set_debug(base, 0x03);
  463. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  464. l2c_set_debug(base, 0x00);
  465. __l2c210_cache_sync(base);
  466. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  467. }
  468. static void __init l2c310_save(void __iomem *base)
  469. {
  470. unsigned revision;
  471. l2c_save(base);
  472. l2x0_saved_regs.tag_latency = readl_relaxed(base +
  473. L310_TAG_LATENCY_CTRL);
  474. l2x0_saved_regs.data_latency = readl_relaxed(base +
  475. L310_DATA_LATENCY_CTRL);
  476. l2x0_saved_regs.filter_end = readl_relaxed(base +
  477. L310_ADDR_FILTER_END);
  478. l2x0_saved_regs.filter_start = readl_relaxed(base +
  479. L310_ADDR_FILTER_START);
  480. revision = readl_relaxed(base + L2X0_CACHE_ID) &
  481. L2X0_CACHE_ID_RTL_MASK;
  482. /* From r2p0, there is Prefetch offset/control register */
  483. if (revision >= L310_CACHE_ID_RTL_R2P0)
  484. l2x0_saved_regs.prefetch_ctrl = readl_relaxed(base +
  485. L310_PREFETCH_CTRL);
  486. /* From r3p0, there is Power control register */
  487. if (revision >= L310_CACHE_ID_RTL_R3P0)
  488. l2x0_saved_regs.pwr_ctrl = readl_relaxed(base +
  489. L310_POWER_CTRL);
  490. }
  491. static void l2c310_configure(void __iomem *base)
  492. {
  493. unsigned revision;
  494. l2c_configure(base);
  495. /* restore pl310 setup */
  496. l2c_write_sec(l2x0_saved_regs.tag_latency, base,
  497. L310_TAG_LATENCY_CTRL);
  498. l2c_write_sec(l2x0_saved_regs.data_latency, base,
  499. L310_DATA_LATENCY_CTRL);
  500. l2c_write_sec(l2x0_saved_regs.filter_end, base,
  501. L310_ADDR_FILTER_END);
  502. l2c_write_sec(l2x0_saved_regs.filter_start, base,
  503. L310_ADDR_FILTER_START);
  504. revision = readl_relaxed(base + L2X0_CACHE_ID) &
  505. L2X0_CACHE_ID_RTL_MASK;
  506. if (revision >= L310_CACHE_ID_RTL_R2P0)
  507. l2c_write_sec(l2x0_saved_regs.prefetch_ctrl, base,
  508. L310_PREFETCH_CTRL);
  509. if (revision >= L310_CACHE_ID_RTL_R3P0)
  510. l2c_write_sec(l2x0_saved_regs.pwr_ctrl, base,
  511. L310_POWER_CTRL);
  512. }
  513. static int l2c310_starting_cpu(unsigned int cpu)
  514. {
  515. set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
  516. return 0;
  517. }
  518. static int l2c310_dying_cpu(unsigned int cpu)
  519. {
  520. set_auxcr(get_auxcr() & ~(BIT(3) | BIT(2) | BIT(1)));
  521. return 0;
  522. }
  523. static void __init l2c310_enable(void __iomem *base, unsigned num_lock)
  524. {
  525. unsigned rev = readl_relaxed(base + L2X0_CACHE_ID) & L2X0_CACHE_ID_RTL_MASK;
  526. bool cortex_a9 = read_cpuid_part() == ARM_CPU_PART_CORTEX_A9;
  527. u32 aux = l2x0_saved_regs.aux_ctrl;
  528. if (rev >= L310_CACHE_ID_RTL_R2P0) {
  529. if (cortex_a9) {
  530. aux |= L310_AUX_CTRL_EARLY_BRESP;
  531. pr_info("L2C-310 enabling early BRESP for Cortex-A9\n");
  532. } else if (aux & L310_AUX_CTRL_EARLY_BRESP) {
  533. pr_warn("L2C-310 early BRESP only supported with Cortex-A9\n");
  534. aux &= ~L310_AUX_CTRL_EARLY_BRESP;
  535. }
  536. }
  537. if (cortex_a9) {
  538. u32 aux_cur = readl_relaxed(base + L2X0_AUX_CTRL);
  539. u32 acr = get_auxcr();
  540. pr_debug("Cortex-A9 ACR=0x%08x\n", acr);
  541. if (acr & BIT(3) && !(aux_cur & L310_AUX_CTRL_FULL_LINE_ZERO))
  542. pr_err("L2C-310: full line of zeros enabled in Cortex-A9 but not L2C-310 - invalid\n");
  543. if (aux & L310_AUX_CTRL_FULL_LINE_ZERO && !(acr & BIT(3)))
  544. pr_err("L2C-310: enabling full line of zeros but not enabled in Cortex-A9\n");
  545. if (!(aux & L310_AUX_CTRL_FULL_LINE_ZERO) && !outer_cache.write_sec) {
  546. aux |= L310_AUX_CTRL_FULL_LINE_ZERO;
  547. pr_info("L2C-310 full line of zeros enabled for Cortex-A9\n");
  548. }
  549. } else if (aux & (L310_AUX_CTRL_FULL_LINE_ZERO | L310_AUX_CTRL_EARLY_BRESP)) {
  550. pr_err("L2C-310: disabling Cortex-A9 specific feature bits\n");
  551. aux &= ~(L310_AUX_CTRL_FULL_LINE_ZERO | L310_AUX_CTRL_EARLY_BRESP);
  552. }
  553. /*
  554. * Always enable non-secure access to the lockdown registers -
  555. * we write to them as part of the L2C enable sequence so they
  556. * need to be accessible.
  557. */
  558. l2x0_saved_regs.aux_ctrl = aux | L310_AUX_CTRL_NS_LOCKDOWN;
  559. l2c_enable(base, num_lock);
  560. /* Read back resulting AUX_CTRL value as it could have been altered. */
  561. aux = readl_relaxed(base + L2X0_AUX_CTRL);
  562. if (aux & (L310_AUX_CTRL_DATA_PREFETCH | L310_AUX_CTRL_INSTR_PREFETCH)) {
  563. u32 prefetch = readl_relaxed(base + L310_PREFETCH_CTRL);
  564. pr_info("L2C-310 %s%s prefetch enabled, offset %u lines\n",
  565. aux & L310_AUX_CTRL_INSTR_PREFETCH ? "I" : "",
  566. aux & L310_AUX_CTRL_DATA_PREFETCH ? "D" : "",
  567. 1 + (prefetch & L310_PREFETCH_CTRL_OFFSET_MASK));
  568. }
  569. /* r3p0 or later has power control register */
  570. if (rev >= L310_CACHE_ID_RTL_R3P0) {
  571. u32 power_ctrl;
  572. power_ctrl = readl_relaxed(base + L310_POWER_CTRL);
  573. pr_info("L2C-310 dynamic clock gating %sabled, standby mode %sabled\n",
  574. power_ctrl & L310_DYNAMIC_CLK_GATING_EN ? "en" : "dis",
  575. power_ctrl & L310_STNDBY_MODE_EN ? "en" : "dis");
  576. }
  577. if (aux & L310_AUX_CTRL_FULL_LINE_ZERO)
  578. cpuhp_setup_state(CPUHP_AP_ARM_L2X0_STARTING,
  579. "AP_ARM_L2X0_STARTING", l2c310_starting_cpu,
  580. l2c310_dying_cpu);
  581. }
  582. static void __init l2c310_fixup(void __iomem *base, u32 cache_id,
  583. struct outer_cache_fns *fns)
  584. {
  585. unsigned revision = cache_id & L2X0_CACHE_ID_RTL_MASK;
  586. const char *errata[8];
  587. unsigned n = 0;
  588. if (IS_ENABLED(CONFIG_PL310_ERRATA_588369) &&
  589. revision < L310_CACHE_ID_RTL_R2P0 &&
  590. /* For bcm compatibility */
  591. fns->inv_range == l2c210_inv_range) {
  592. fns->inv_range = l2c310_inv_range_erratum;
  593. fns->flush_range = l2c310_flush_range_erratum;
  594. errata[n++] = "588369";
  595. }
  596. if (IS_ENABLED(CONFIG_PL310_ERRATA_727915) &&
  597. revision >= L310_CACHE_ID_RTL_R2P0 &&
  598. revision < L310_CACHE_ID_RTL_R3P1) {
  599. fns->flush_all = l2c310_flush_all_erratum;
  600. errata[n++] = "727915";
  601. }
  602. if (revision >= L310_CACHE_ID_RTL_R3P0 &&
  603. revision < L310_CACHE_ID_RTL_R3P2) {
  604. u32 val = l2x0_saved_regs.prefetch_ctrl;
  605. /* I don't think bit23 is required here... but iMX6 does so */
  606. if (val & (L310_PREFETCH_CTRL_DBL_LINEFILL |
  607. L310_PREFETCH_CTRL_DBL_LINEFILL_INCR)) {
  608. val &= ~(L310_PREFETCH_CTRL_DBL_LINEFILL |
  609. L310_PREFETCH_CTRL_DBL_LINEFILL_INCR);
  610. l2x0_saved_regs.prefetch_ctrl = val;
  611. errata[n++] = "752271";
  612. }
  613. }
  614. if (IS_ENABLED(CONFIG_PL310_ERRATA_753970) &&
  615. revision == L310_CACHE_ID_RTL_R3P0) {
  616. sync_reg_offset = L2X0_DUMMY_REG;
  617. errata[n++] = "753970";
  618. }
  619. if (IS_ENABLED(CONFIG_PL310_ERRATA_769419))
  620. errata[n++] = "769419";
  621. if (n) {
  622. unsigned i;
  623. pr_info("L2C-310 errat%s", n > 1 ? "a" : "um");
  624. for (i = 0; i < n; i++)
  625. pr_cont(" %s", errata[i]);
  626. pr_cont(" enabled\n");
  627. }
  628. }
  629. static void l2c310_disable(void)
  630. {
  631. /*
  632. * If full-line-of-zeros is enabled, we must first disable it in the
  633. * Cortex-A9 auxiliary control register before disabling the L2 cache.
  634. */
  635. if (l2x0_saved_regs.aux_ctrl & L310_AUX_CTRL_FULL_LINE_ZERO)
  636. set_auxcr(get_auxcr() & ~(BIT(3) | BIT(2) | BIT(1)));
  637. l2c_disable();
  638. }
  639. static void l2c310_resume(void)
  640. {
  641. l2c_resume();
  642. /* Re-enable full-line-of-zeros for Cortex-A9 */
  643. if (l2x0_saved_regs.aux_ctrl & L310_AUX_CTRL_FULL_LINE_ZERO)
  644. set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
  645. }
  646. static void l2c310_unlock(void __iomem *base, unsigned num_lock)
  647. {
  648. if (readl_relaxed(base + L2X0_AUX_CTRL) & L310_AUX_CTRL_NS_LOCKDOWN)
  649. l2c_unlock(base, num_lock);
  650. }
  651. static const struct l2c_init_data l2c310_init_fns __initconst = {
  652. .type = "L2C-310",
  653. .way_size_0 = SZ_8K,
  654. .num_lock = 8,
  655. .enable = l2c310_enable,
  656. .fixup = l2c310_fixup,
  657. .save = l2c310_save,
  658. .configure = l2c310_configure,
  659. .unlock = l2c310_unlock,
  660. .outer_cache = {
  661. .inv_range = l2c210_inv_range,
  662. .clean_range = l2c210_clean_range,
  663. .flush_range = l2c210_flush_range,
  664. .flush_all = l2c210_flush_all,
  665. .disable = l2c310_disable,
  666. .sync = l2c210_sync,
  667. .resume = l2c310_resume,
  668. },
  669. };
  670. static int __init __l2c_init(const struct l2c_init_data *data,
  671. u32 aux_val, u32 aux_mask, u32 cache_id, bool nosync)
  672. {
  673. struct outer_cache_fns fns;
  674. unsigned way_size_bits, ways;
  675. u32 aux, old_aux;
  676. /*
  677. * Save the pointer globally so that callbacks which do not receive
  678. * context from callers can access the structure.
  679. */
  680. l2x0_data = kmemdup(data, sizeof(*data), GFP_KERNEL);
  681. if (!l2x0_data)
  682. return -ENOMEM;
  683. /*
  684. * Sanity check the aux values. aux_mask is the bits we preserve
  685. * from reading the hardware register, and aux_val is the bits we
  686. * set.
  687. */
  688. if (aux_val & aux_mask)
  689. pr_alert("L2C: platform provided aux values permit register corruption.\n");
  690. old_aux = aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  691. aux &= aux_mask;
  692. aux |= aux_val;
  693. if (old_aux != aux)
  694. pr_warn("L2C: DT/platform modifies aux control register: 0x%08x -> 0x%08x\n",
  695. old_aux, aux);
  696. /* Determine the number of ways */
  697. switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
  698. case L2X0_CACHE_ID_PART_L310:
  699. if ((aux_val | ~aux_mask) & (L2C_AUX_CTRL_WAY_SIZE_MASK | L310_AUX_CTRL_ASSOCIATIVITY_16))
  700. pr_warn("L2C: DT/platform tries to modify or specify cache size\n");
  701. if (aux & (1 << 16))
  702. ways = 16;
  703. else
  704. ways = 8;
  705. break;
  706. case L2X0_CACHE_ID_PART_L210:
  707. case L2X0_CACHE_ID_PART_L220:
  708. ways = (aux >> 13) & 0xf;
  709. break;
  710. case AURORA_CACHE_ID:
  711. ways = (aux >> 13) & 0xf;
  712. ways = 2 << ((ways + 1) >> 2);
  713. break;
  714. default:
  715. /* Assume unknown chips have 8 ways */
  716. ways = 8;
  717. break;
  718. }
  719. l2x0_way_mask = (1 << ways) - 1;
  720. /*
  721. * way_size_0 is the size that a way_size value of zero would be
  722. * given the calculation: way_size = way_size_0 << way_size_bits.
  723. * So, if way_size_bits=0 is reserved, but way_size_bits=1 is 16k,
  724. * then way_size_0 would be 8k.
  725. *
  726. * L2 cache size = number of ways * way size.
  727. */
  728. way_size_bits = (aux & L2C_AUX_CTRL_WAY_SIZE_MASK) >>
  729. L2C_AUX_CTRL_WAY_SIZE_SHIFT;
  730. l2x0_size = ways * (data->way_size_0 << way_size_bits);
  731. fns = data->outer_cache;
  732. fns.write_sec = outer_cache.write_sec;
  733. fns.configure = outer_cache.configure;
  734. if (data->fixup)
  735. data->fixup(l2x0_base, cache_id, &fns);
  736. if (nosync) {
  737. pr_info("L2C: disabling outer sync\n");
  738. fns.sync = NULL;
  739. }
  740. /*
  741. * Check if l2x0 controller is already enabled. If we are booting
  742. * in non-secure mode accessing the below registers will fault.
  743. */
  744. if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN)) {
  745. l2x0_saved_regs.aux_ctrl = aux;
  746. data->enable(l2x0_base, data->num_lock);
  747. }
  748. outer_cache = fns;
  749. /*
  750. * It is strange to save the register state before initialisation,
  751. * but hey, this is what the DT implementations decided to do.
  752. */
  753. if (data->save)
  754. data->save(l2x0_base);
  755. /* Re-read it in case some bits are reserved. */
  756. aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  757. pr_info("%s cache controller enabled, %d ways, %d kB\n",
  758. data->type, ways, l2x0_size >> 10);
  759. pr_info("%s: CACHE_ID 0x%08x, AUX_CTRL 0x%08x\n",
  760. data->type, cache_id, aux);
  761. return 0;
  762. }
  763. void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
  764. {
  765. const struct l2c_init_data *data;
  766. u32 cache_id;
  767. l2x0_base = base;
  768. cache_id = readl_relaxed(base + L2X0_CACHE_ID);
  769. switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
  770. default:
  771. case L2X0_CACHE_ID_PART_L210:
  772. data = &l2c210_data;
  773. break;
  774. case L2X0_CACHE_ID_PART_L220:
  775. data = &l2c220_data;
  776. break;
  777. case L2X0_CACHE_ID_PART_L310:
  778. data = &l2c310_init_fns;
  779. break;
  780. }
  781. /* Read back current (default) hardware configuration */
  782. if (data->save)
  783. data->save(l2x0_base);
  784. __l2c_init(data, aux_val, aux_mask, cache_id, false);
  785. }
  786. #ifdef CONFIG_OF
  787. static int l2_wt_override;
  788. /* Aurora don't have the cache ID register available, so we have to
  789. * pass it though the device tree */
  790. static u32 cache_id_part_number_from_dt;
  791. /**
  792. * l2x0_cache_size_of_parse() - read cache size parameters from DT
  793. * @np: the device tree node for the l2 cache
  794. * @aux_val: pointer to machine-supplied auxilary register value, to
  795. * be augmented by the call (bits to be set to 1)
  796. * @aux_mask: pointer to machine-supplied auxilary register mask, to
  797. * be augmented by the call (bits to be set to 0)
  798. * @associativity: variable to return the calculated associativity in
  799. * @max_way_size: the maximum size in bytes for the cache ways
  800. */
  801. static int __init l2x0_cache_size_of_parse(const struct device_node *np,
  802. u32 *aux_val, u32 *aux_mask,
  803. u32 *associativity,
  804. u32 max_way_size)
  805. {
  806. u32 mask = 0, val = 0;
  807. u32 cache_size = 0, sets = 0;
  808. u32 way_size_bits = 1;
  809. u32 way_size = 0;
  810. u32 block_size = 0;
  811. u32 line_size = 0;
  812. of_property_read_u32(np, "cache-size", &cache_size);
  813. of_property_read_u32(np, "cache-sets", &sets);
  814. of_property_read_u32(np, "cache-block-size", &block_size);
  815. of_property_read_u32(np, "cache-line-size", &line_size);
  816. if (!cache_size || !sets)
  817. return -ENODEV;
  818. /* All these l2 caches have the same line = block size actually */
  819. if (!line_size) {
  820. if (block_size) {
  821. /* If linesize is not given, it is equal to blocksize */
  822. line_size = block_size;
  823. } else {
  824. /* Fall back to known size */
  825. pr_warn("L2C OF: no cache block/line size given: "
  826. "falling back to default size %d bytes\n",
  827. CACHE_LINE_SIZE);
  828. line_size = CACHE_LINE_SIZE;
  829. }
  830. }
  831. if (line_size != CACHE_LINE_SIZE)
  832. pr_warn("L2C OF: DT supplied line size %d bytes does "
  833. "not match hardware line size of %d bytes\n",
  834. line_size,
  835. CACHE_LINE_SIZE);
  836. /*
  837. * Since:
  838. * set size = cache size / sets
  839. * ways = cache size / (sets * line size)
  840. * way size = cache size / (cache size / (sets * line size))
  841. * way size = sets * line size
  842. * associativity = ways = cache size / way size
  843. */
  844. way_size = sets * line_size;
  845. *associativity = cache_size / way_size;
  846. if (way_size > max_way_size) {
  847. pr_err("L2C OF: set size %dKB is too large\n", way_size);
  848. return -EINVAL;
  849. }
  850. pr_info("L2C OF: override cache size: %d bytes (%dKB)\n",
  851. cache_size, cache_size >> 10);
  852. pr_info("L2C OF: override line size: %d bytes\n", line_size);
  853. pr_info("L2C OF: override way size: %d bytes (%dKB)\n",
  854. way_size, way_size >> 10);
  855. pr_info("L2C OF: override associativity: %d\n", *associativity);
  856. /*
  857. * Calculates the bits 17:19 to set for way size:
  858. * 512KB -> 6, 256KB -> 5, ... 16KB -> 1
  859. */
  860. way_size_bits = ilog2(way_size >> 10) - 3;
  861. if (way_size_bits < 1 || way_size_bits > 6) {
  862. pr_err("L2C OF: cache way size illegal: %dKB is not mapped\n",
  863. way_size);
  864. return -EINVAL;
  865. }
  866. mask |= L2C_AUX_CTRL_WAY_SIZE_MASK;
  867. val |= (way_size_bits << L2C_AUX_CTRL_WAY_SIZE_SHIFT);
  868. *aux_val &= ~mask;
  869. *aux_val |= val;
  870. *aux_mask &= ~mask;
  871. return 0;
  872. }
  873. static void __init l2x0_of_parse(const struct device_node *np,
  874. u32 *aux_val, u32 *aux_mask)
  875. {
  876. u32 data[2] = { 0, 0 };
  877. u32 tag = 0;
  878. u32 dirty = 0;
  879. u32 val = 0, mask = 0;
  880. u32 assoc;
  881. int ret;
  882. of_property_read_u32(np, "arm,tag-latency", &tag);
  883. if (tag) {
  884. mask |= L2X0_AUX_CTRL_TAG_LATENCY_MASK;
  885. val |= (tag - 1) << L2X0_AUX_CTRL_TAG_LATENCY_SHIFT;
  886. }
  887. of_property_read_u32_array(np, "arm,data-latency",
  888. data, ARRAY_SIZE(data));
  889. if (data[0] && data[1]) {
  890. mask |= L2X0_AUX_CTRL_DATA_RD_LATENCY_MASK |
  891. L2X0_AUX_CTRL_DATA_WR_LATENCY_MASK;
  892. val |= ((data[0] - 1) << L2X0_AUX_CTRL_DATA_RD_LATENCY_SHIFT) |
  893. ((data[1] - 1) << L2X0_AUX_CTRL_DATA_WR_LATENCY_SHIFT);
  894. }
  895. of_property_read_u32(np, "arm,dirty-latency", &dirty);
  896. if (dirty) {
  897. mask |= L2X0_AUX_CTRL_DIRTY_LATENCY_MASK;
  898. val |= (dirty - 1) << L2X0_AUX_CTRL_DIRTY_LATENCY_SHIFT;
  899. }
  900. if (of_property_read_bool(np, "arm,parity-enable")) {
  901. mask &= ~L2C_AUX_CTRL_PARITY_ENABLE;
  902. val |= L2C_AUX_CTRL_PARITY_ENABLE;
  903. } else if (of_property_read_bool(np, "arm,parity-disable")) {
  904. mask &= ~L2C_AUX_CTRL_PARITY_ENABLE;
  905. }
  906. if (of_property_read_bool(np, "arm,shared-override")) {
  907. mask &= ~L2C_AUX_CTRL_SHARED_OVERRIDE;
  908. val |= L2C_AUX_CTRL_SHARED_OVERRIDE;
  909. }
  910. ret = l2x0_cache_size_of_parse(np, aux_val, aux_mask, &assoc, SZ_256K);
  911. if (ret)
  912. return;
  913. if (assoc > 8) {
  914. pr_err("l2x0 of: cache setting yield too high associativity\n");
  915. pr_err("l2x0 of: %d calculated, max 8\n", assoc);
  916. } else {
  917. mask |= L2X0_AUX_CTRL_ASSOC_MASK;
  918. val |= (assoc << L2X0_AUX_CTRL_ASSOC_SHIFT);
  919. }
  920. *aux_val &= ~mask;
  921. *aux_val |= val;
  922. *aux_mask &= ~mask;
  923. }
  924. static const struct l2c_init_data of_l2c210_data __initconst = {
  925. .type = "L2C-210",
  926. .way_size_0 = SZ_8K,
  927. .num_lock = 1,
  928. .of_parse = l2x0_of_parse,
  929. .enable = l2c_enable,
  930. .save = l2c_save,
  931. .configure = l2c_configure,
  932. .unlock = l2c_unlock,
  933. .outer_cache = {
  934. .inv_range = l2c210_inv_range,
  935. .clean_range = l2c210_clean_range,
  936. .flush_range = l2c210_flush_range,
  937. .flush_all = l2c210_flush_all,
  938. .disable = l2c_disable,
  939. .sync = l2c210_sync,
  940. .resume = l2c_resume,
  941. },
  942. };
  943. static const struct l2c_init_data of_l2c220_data __initconst = {
  944. .type = "L2C-220",
  945. .way_size_0 = SZ_8K,
  946. .num_lock = 1,
  947. .of_parse = l2x0_of_parse,
  948. .enable = l2c220_enable,
  949. .save = l2c_save,
  950. .configure = l2c_configure,
  951. .unlock = l2c220_unlock,
  952. .outer_cache = {
  953. .inv_range = l2c220_inv_range,
  954. .clean_range = l2c220_clean_range,
  955. .flush_range = l2c220_flush_range,
  956. .flush_all = l2c220_flush_all,
  957. .disable = l2c_disable,
  958. .sync = l2c220_sync,
  959. .resume = l2c_resume,
  960. },
  961. };
  962. static void __init l2c310_of_parse(const struct device_node *np,
  963. u32 *aux_val, u32 *aux_mask)
  964. {
  965. u32 data[3] = { 0, 0, 0 };
  966. u32 tag[3] = { 0, 0, 0 };
  967. u32 filter[2] = { 0, 0 };
  968. u32 assoc;
  969. u32 prefetch;
  970. u32 power;
  971. u32 val;
  972. int ret;
  973. of_property_read_u32_array(np, "arm,tag-latency", tag, ARRAY_SIZE(tag));
  974. if (tag[0] && tag[1] && tag[2])
  975. l2x0_saved_regs.tag_latency =
  976. L310_LATENCY_CTRL_RD(tag[0] - 1) |
  977. L310_LATENCY_CTRL_WR(tag[1] - 1) |
  978. L310_LATENCY_CTRL_SETUP(tag[2] - 1);
  979. of_property_read_u32_array(np, "arm,data-latency",
  980. data, ARRAY_SIZE(data));
  981. if (data[0] && data[1] && data[2])
  982. l2x0_saved_regs.data_latency =
  983. L310_LATENCY_CTRL_RD(data[0] - 1) |
  984. L310_LATENCY_CTRL_WR(data[1] - 1) |
  985. L310_LATENCY_CTRL_SETUP(data[2] - 1);
  986. of_property_read_u32_array(np, "arm,filter-ranges",
  987. filter, ARRAY_SIZE(filter));
  988. if (filter[1]) {
  989. l2x0_saved_regs.filter_end =
  990. ALIGN(filter[0] + filter[1], SZ_1M);
  991. l2x0_saved_regs.filter_start = (filter[0] & ~(SZ_1M - 1))
  992. | L310_ADDR_FILTER_EN;
  993. }
  994. ret = l2x0_cache_size_of_parse(np, aux_val, aux_mask, &assoc, SZ_512K);
  995. if (!ret) {
  996. switch (assoc) {
  997. case 16:
  998. *aux_val &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  999. *aux_val |= L310_AUX_CTRL_ASSOCIATIVITY_16;
  1000. *aux_mask &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  1001. break;
  1002. case 8:
  1003. *aux_val &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  1004. *aux_mask &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  1005. break;
  1006. default:
  1007. pr_err("L2C-310 OF cache associativity %d invalid, only 8 or 16 permitted\n",
  1008. assoc);
  1009. break;
  1010. }
  1011. }
  1012. if (of_property_read_bool(np, "arm,shared-override")) {
  1013. *aux_val |= L2C_AUX_CTRL_SHARED_OVERRIDE;
  1014. *aux_mask &= ~L2C_AUX_CTRL_SHARED_OVERRIDE;
  1015. }
  1016. if (of_property_read_bool(np, "arm,parity-enable")) {
  1017. *aux_val |= L2C_AUX_CTRL_PARITY_ENABLE;
  1018. *aux_mask &= ~L2C_AUX_CTRL_PARITY_ENABLE;
  1019. } else if (of_property_read_bool(np, "arm,parity-disable")) {
  1020. *aux_val &= ~L2C_AUX_CTRL_PARITY_ENABLE;
  1021. *aux_mask &= ~L2C_AUX_CTRL_PARITY_ENABLE;
  1022. }
  1023. prefetch = l2x0_saved_regs.prefetch_ctrl;
  1024. ret = of_property_read_u32(np, "arm,double-linefill", &val);
  1025. if (ret == 0) {
  1026. if (val)
  1027. prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL;
  1028. else
  1029. prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL;
  1030. } else if (ret != -EINVAL) {
  1031. pr_err("L2C-310 OF arm,double-linefill property value is missing\n");
  1032. }
  1033. ret = of_property_read_u32(np, "arm,double-linefill-incr", &val);
  1034. if (ret == 0) {
  1035. if (val)
  1036. prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL_INCR;
  1037. else
  1038. prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL_INCR;
  1039. } else if (ret != -EINVAL) {
  1040. pr_err("L2C-310 OF arm,double-linefill-incr property value is missing\n");
  1041. }
  1042. ret = of_property_read_u32(np, "arm,double-linefill-wrap", &val);
  1043. if (ret == 0) {
  1044. if (!val)
  1045. prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL_WRAP;
  1046. else
  1047. prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL_WRAP;
  1048. } else if (ret != -EINVAL) {
  1049. pr_err("L2C-310 OF arm,double-linefill-wrap property value is missing\n");
  1050. }
  1051. ret = of_property_read_u32(np, "arm,prefetch-drop", &val);
  1052. if (ret == 0) {
  1053. if (val)
  1054. prefetch |= L310_PREFETCH_CTRL_PREFETCH_DROP;
  1055. else
  1056. prefetch &= ~L310_PREFETCH_CTRL_PREFETCH_DROP;
  1057. } else if (ret != -EINVAL) {
  1058. pr_err("L2C-310 OF arm,prefetch-drop property value is missing\n");
  1059. }
  1060. ret = of_property_read_u32(np, "arm,prefetch-offset", &val);
  1061. if (ret == 0) {
  1062. prefetch &= ~L310_PREFETCH_CTRL_OFFSET_MASK;
  1063. prefetch |= val & L310_PREFETCH_CTRL_OFFSET_MASK;
  1064. } else if (ret != -EINVAL) {
  1065. pr_err("L2C-310 OF arm,prefetch-offset property value is missing\n");
  1066. }
  1067. ret = of_property_read_u32(np, "prefetch-data", &val);
  1068. if (ret == 0) {
  1069. if (val)
  1070. prefetch |= L310_PREFETCH_CTRL_DATA_PREFETCH;
  1071. else
  1072. prefetch &= ~L310_PREFETCH_CTRL_DATA_PREFETCH;
  1073. } else if (ret != -EINVAL) {
  1074. pr_err("L2C-310 OF prefetch-data property value is missing\n");
  1075. }
  1076. ret = of_property_read_u32(np, "prefetch-instr", &val);
  1077. if (ret == 0) {
  1078. if (val)
  1079. prefetch |= L310_PREFETCH_CTRL_INSTR_PREFETCH;
  1080. else
  1081. prefetch &= ~L310_PREFETCH_CTRL_INSTR_PREFETCH;
  1082. } else if (ret != -EINVAL) {
  1083. pr_err("L2C-310 OF prefetch-instr property value is missing\n");
  1084. }
  1085. l2x0_saved_regs.prefetch_ctrl = prefetch;
  1086. power = l2x0_saved_regs.pwr_ctrl |
  1087. L310_DYNAMIC_CLK_GATING_EN | L310_STNDBY_MODE_EN;
  1088. ret = of_property_read_u32(np, "arm,dynamic-clock-gating", &val);
  1089. if (!ret) {
  1090. if (!val)
  1091. power &= ~L310_DYNAMIC_CLK_GATING_EN;
  1092. } else if (ret != -EINVAL) {
  1093. pr_err("L2C-310 OF dynamic-clock-gating property value is missing or invalid\n");
  1094. }
  1095. ret = of_property_read_u32(np, "arm,standby-mode", &val);
  1096. if (!ret) {
  1097. if (!val)
  1098. power &= ~L310_STNDBY_MODE_EN;
  1099. } else if (ret != -EINVAL) {
  1100. pr_err("L2C-310 OF standby-mode property value is missing or invalid\n");
  1101. }
  1102. l2x0_saved_regs.pwr_ctrl = power;
  1103. }
  1104. static const struct l2c_init_data of_l2c310_data __initconst = {
  1105. .type = "L2C-310",
  1106. .way_size_0 = SZ_8K,
  1107. .num_lock = 8,
  1108. .of_parse = l2c310_of_parse,
  1109. .enable = l2c310_enable,
  1110. .fixup = l2c310_fixup,
  1111. .save = l2c310_save,
  1112. .configure = l2c310_configure,
  1113. .unlock = l2c310_unlock,
  1114. .outer_cache = {
  1115. .inv_range = l2c210_inv_range,
  1116. .clean_range = l2c210_clean_range,
  1117. .flush_range = l2c210_flush_range,
  1118. .flush_all = l2c210_flush_all,
  1119. .disable = l2c310_disable,
  1120. .sync = l2c210_sync,
  1121. .resume = l2c310_resume,
  1122. },
  1123. };
  1124. /*
  1125. * This is a variant of the of_l2c310_data with .sync set to
  1126. * NULL. Outer sync operations are not needed when the system is I/O
  1127. * coherent, and potentially harmful in certain situations (PCIe/PL310
  1128. * deadlock on Armada 375/38x due to hardware I/O coherency). The
  1129. * other operations are kept because they are infrequent (therefore do
  1130. * not cause the deadlock in practice) and needed for secondary CPU
  1131. * boot and other power management activities.
  1132. */
  1133. static const struct l2c_init_data of_l2c310_coherent_data __initconst = {
  1134. .type = "L2C-310 Coherent",
  1135. .way_size_0 = SZ_8K,
  1136. .num_lock = 8,
  1137. .of_parse = l2c310_of_parse,
  1138. .enable = l2c310_enable,
  1139. .fixup = l2c310_fixup,
  1140. .save = l2c310_save,
  1141. .configure = l2c310_configure,
  1142. .unlock = l2c310_unlock,
  1143. .outer_cache = {
  1144. .inv_range = l2c210_inv_range,
  1145. .clean_range = l2c210_clean_range,
  1146. .flush_range = l2c210_flush_range,
  1147. .flush_all = l2c210_flush_all,
  1148. .disable = l2c310_disable,
  1149. .resume = l2c310_resume,
  1150. },
  1151. };
  1152. /*
  1153. * Note that the end addresses passed to Linux primitives are
  1154. * noninclusive, while the hardware cache range operations use
  1155. * inclusive start and end addresses.
  1156. */
  1157. static unsigned long aurora_range_end(unsigned long start, unsigned long end)
  1158. {
  1159. /*
  1160. * Limit the number of cache lines processed at once,
  1161. * since cache range operations stall the CPU pipeline
  1162. * until completion.
  1163. */
  1164. if (end > start + MAX_RANGE_SIZE)
  1165. end = start + MAX_RANGE_SIZE;
  1166. /*
  1167. * Cache range operations can't straddle a page boundary.
  1168. */
  1169. if (end > PAGE_ALIGN(start+1))
  1170. end = PAGE_ALIGN(start+1);
  1171. return end;
  1172. }
  1173. static void aurora_pa_range(unsigned long start, unsigned long end,
  1174. unsigned long offset)
  1175. {
  1176. void __iomem *base = l2x0_base;
  1177. unsigned long range_end;
  1178. unsigned long flags;
  1179. /*
  1180. * round start and end adresses up to cache line size
  1181. */
  1182. start &= ~(CACHE_LINE_SIZE - 1);
  1183. end = ALIGN(end, CACHE_LINE_SIZE);
  1184. /*
  1185. * perform operation on all full cache lines between 'start' and 'end'
  1186. */
  1187. while (start < end) {
  1188. range_end = aurora_range_end(start, end);
  1189. raw_spin_lock_irqsave(&l2x0_lock, flags);
  1190. writel_relaxed(start, base + AURORA_RANGE_BASE_ADDR_REG);
  1191. writel_relaxed(range_end - CACHE_LINE_SIZE, base + offset);
  1192. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  1193. writel_relaxed(0, base + AURORA_SYNC_REG);
  1194. start = range_end;
  1195. }
  1196. }
  1197. static void aurora_inv_range(unsigned long start, unsigned long end)
  1198. {
  1199. aurora_pa_range(start, end, AURORA_INVAL_RANGE_REG);
  1200. }
  1201. static void aurora_clean_range(unsigned long start, unsigned long end)
  1202. {
  1203. /*
  1204. * If L2 is forced to WT, the L2 will always be clean and we
  1205. * don't need to do anything here.
  1206. */
  1207. if (!l2_wt_override)
  1208. aurora_pa_range(start, end, AURORA_CLEAN_RANGE_REG);
  1209. }
  1210. static void aurora_flush_range(unsigned long start, unsigned long end)
  1211. {
  1212. if (l2_wt_override)
  1213. aurora_pa_range(start, end, AURORA_INVAL_RANGE_REG);
  1214. else
  1215. aurora_pa_range(start, end, AURORA_FLUSH_RANGE_REG);
  1216. }
  1217. static void aurora_flush_all(void)
  1218. {
  1219. void __iomem *base = l2x0_base;
  1220. unsigned long flags;
  1221. /* clean all ways */
  1222. raw_spin_lock_irqsave(&l2x0_lock, flags);
  1223. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  1224. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  1225. writel_relaxed(0, base + AURORA_SYNC_REG);
  1226. }
  1227. static void aurora_cache_sync(void)
  1228. {
  1229. writel_relaxed(0, l2x0_base + AURORA_SYNC_REG);
  1230. }
  1231. static void aurora_disable(void)
  1232. {
  1233. void __iomem *base = l2x0_base;
  1234. unsigned long flags;
  1235. raw_spin_lock_irqsave(&l2x0_lock, flags);
  1236. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  1237. writel_relaxed(0, base + AURORA_SYNC_REG);
  1238. l2c_write_sec(0, base, L2X0_CTRL);
  1239. dsb(st);
  1240. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  1241. }
  1242. static void aurora_save(void __iomem *base)
  1243. {
  1244. l2x0_saved_regs.ctrl = readl_relaxed(base + L2X0_CTRL);
  1245. l2x0_saved_regs.aux_ctrl = readl_relaxed(base + L2X0_AUX_CTRL);
  1246. }
  1247. /*
  1248. * For Aurora cache in no outer mode, enable via the CP15 coprocessor
  1249. * broadcasting of cache commands to L2.
  1250. */
  1251. static void __init aurora_enable_no_outer(void __iomem *base,
  1252. unsigned num_lock)
  1253. {
  1254. u32 u;
  1255. asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
  1256. u |= AURORA_CTRL_FW; /* Set the FW bit */
  1257. asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
  1258. isb();
  1259. l2c_enable(base, num_lock);
  1260. }
  1261. static void __init aurora_fixup(void __iomem *base, u32 cache_id,
  1262. struct outer_cache_fns *fns)
  1263. {
  1264. sync_reg_offset = AURORA_SYNC_REG;
  1265. }
  1266. static void __init aurora_of_parse(const struct device_node *np,
  1267. u32 *aux_val, u32 *aux_mask)
  1268. {
  1269. u32 val = AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU;
  1270. u32 mask = AURORA_ACR_REPLACEMENT_MASK;
  1271. of_property_read_u32(np, "cache-id-part",
  1272. &cache_id_part_number_from_dt);
  1273. /* Determine and save the write policy */
  1274. l2_wt_override = of_property_read_bool(np, "wt-override");
  1275. if (l2_wt_override) {
  1276. val |= AURORA_ACR_FORCE_WRITE_THRO_POLICY;
  1277. mask |= AURORA_ACR_FORCE_WRITE_POLICY_MASK;
  1278. }
  1279. *aux_val &= ~mask;
  1280. *aux_val |= val;
  1281. *aux_mask &= ~mask;
  1282. }
  1283. static const struct l2c_init_data of_aurora_with_outer_data __initconst = {
  1284. .type = "Aurora",
  1285. .way_size_0 = SZ_4K,
  1286. .num_lock = 4,
  1287. .of_parse = aurora_of_parse,
  1288. .enable = l2c_enable,
  1289. .fixup = aurora_fixup,
  1290. .save = aurora_save,
  1291. .configure = l2c_configure,
  1292. .unlock = l2c_unlock,
  1293. .outer_cache = {
  1294. .inv_range = aurora_inv_range,
  1295. .clean_range = aurora_clean_range,
  1296. .flush_range = aurora_flush_range,
  1297. .flush_all = aurora_flush_all,
  1298. .disable = aurora_disable,
  1299. .sync = aurora_cache_sync,
  1300. .resume = l2c_resume,
  1301. },
  1302. };
  1303. static const struct l2c_init_data of_aurora_no_outer_data __initconst = {
  1304. .type = "Aurora",
  1305. .way_size_0 = SZ_4K,
  1306. .num_lock = 4,
  1307. .of_parse = aurora_of_parse,
  1308. .enable = aurora_enable_no_outer,
  1309. .fixup = aurora_fixup,
  1310. .save = aurora_save,
  1311. .configure = l2c_configure,
  1312. .unlock = l2c_unlock,
  1313. .outer_cache = {
  1314. .resume = l2c_resume,
  1315. },
  1316. };
  1317. /*
  1318. * For certain Broadcom SoCs, depending on the address range, different offsets
  1319. * need to be added to the address before passing it to L2 for
  1320. * invalidation/clean/flush
  1321. *
  1322. * Section Address Range Offset EMI
  1323. * 1 0x00000000 - 0x3FFFFFFF 0x80000000 VC
  1324. * 2 0x40000000 - 0xBFFFFFFF 0x40000000 SYS
  1325. * 3 0xC0000000 - 0xFFFFFFFF 0x80000000 VC
  1326. *
  1327. * When the start and end addresses have crossed two different sections, we
  1328. * need to break the L2 operation into two, each within its own section.
  1329. * For example, if we need to invalidate addresses starts at 0xBFFF0000 and
  1330. * ends at 0xC0001000, we need do invalidate 1) 0xBFFF0000 - 0xBFFFFFFF and 2)
  1331. * 0xC0000000 - 0xC0001000
  1332. *
  1333. * Note 1:
  1334. * By breaking a single L2 operation into two, we may potentially suffer some
  1335. * performance hit, but keep in mind the cross section case is very rare
  1336. *
  1337. * Note 2:
  1338. * We do not need to handle the case when the start address is in
  1339. * Section 1 and the end address is in Section 3, since it is not a valid use
  1340. * case
  1341. *
  1342. * Note 3:
  1343. * Section 1 in practical terms can no longer be used on rev A2. Because of
  1344. * that the code does not need to handle section 1 at all.
  1345. *
  1346. */
  1347. #define BCM_SYS_EMI_START_ADDR 0x40000000UL
  1348. #define BCM_VC_EMI_SEC3_START_ADDR 0xC0000000UL
  1349. #define BCM_SYS_EMI_OFFSET 0x40000000UL
  1350. #define BCM_VC_EMI_OFFSET 0x80000000UL
  1351. static inline int bcm_addr_is_sys_emi(unsigned long addr)
  1352. {
  1353. return (addr >= BCM_SYS_EMI_START_ADDR) &&
  1354. (addr < BCM_VC_EMI_SEC3_START_ADDR);
  1355. }
  1356. static inline unsigned long bcm_l2_phys_addr(unsigned long addr)
  1357. {
  1358. if (bcm_addr_is_sys_emi(addr))
  1359. return addr + BCM_SYS_EMI_OFFSET;
  1360. else
  1361. return addr + BCM_VC_EMI_OFFSET;
  1362. }
  1363. static void bcm_inv_range(unsigned long start, unsigned long end)
  1364. {
  1365. unsigned long new_start, new_end;
  1366. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1367. if (unlikely(end <= start))
  1368. return;
  1369. new_start = bcm_l2_phys_addr(start);
  1370. new_end = bcm_l2_phys_addr(end);
  1371. /* normal case, no cross section between start and end */
  1372. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1373. l2c210_inv_range(new_start, new_end);
  1374. return;
  1375. }
  1376. /* They cross sections, so it can only be a cross from section
  1377. * 2 to section 3
  1378. */
  1379. l2c210_inv_range(new_start,
  1380. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1381. l2c210_inv_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1382. new_end);
  1383. }
  1384. static void bcm_clean_range(unsigned long start, unsigned long end)
  1385. {
  1386. unsigned long new_start, new_end;
  1387. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1388. if (unlikely(end <= start))
  1389. return;
  1390. new_start = bcm_l2_phys_addr(start);
  1391. new_end = bcm_l2_phys_addr(end);
  1392. /* normal case, no cross section between start and end */
  1393. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1394. l2c210_clean_range(new_start, new_end);
  1395. return;
  1396. }
  1397. /* They cross sections, so it can only be a cross from section
  1398. * 2 to section 3
  1399. */
  1400. l2c210_clean_range(new_start,
  1401. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1402. l2c210_clean_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1403. new_end);
  1404. }
  1405. static void bcm_flush_range(unsigned long start, unsigned long end)
  1406. {
  1407. unsigned long new_start, new_end;
  1408. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1409. if (unlikely(end <= start))
  1410. return;
  1411. if ((end - start) >= l2x0_size) {
  1412. outer_cache.flush_all();
  1413. return;
  1414. }
  1415. new_start = bcm_l2_phys_addr(start);
  1416. new_end = bcm_l2_phys_addr(end);
  1417. /* normal case, no cross section between start and end */
  1418. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1419. l2c210_flush_range(new_start, new_end);
  1420. return;
  1421. }
  1422. /* They cross sections, so it can only be a cross from section
  1423. * 2 to section 3
  1424. */
  1425. l2c210_flush_range(new_start,
  1426. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1427. l2c210_flush_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1428. new_end);
  1429. }
  1430. /* Broadcom L2C-310 start from ARMs R3P2 or later, and require no fixups */
  1431. static const struct l2c_init_data of_bcm_l2x0_data __initconst = {
  1432. .type = "BCM-L2C-310",
  1433. .way_size_0 = SZ_8K,
  1434. .num_lock = 8,
  1435. .of_parse = l2c310_of_parse,
  1436. .enable = l2c310_enable,
  1437. .save = l2c310_save,
  1438. .configure = l2c310_configure,
  1439. .unlock = l2c310_unlock,
  1440. .outer_cache = {
  1441. .inv_range = bcm_inv_range,
  1442. .clean_range = bcm_clean_range,
  1443. .flush_range = bcm_flush_range,
  1444. .flush_all = l2c210_flush_all,
  1445. .disable = l2c310_disable,
  1446. .sync = l2c210_sync,
  1447. .resume = l2c310_resume,
  1448. },
  1449. };
  1450. static void __init tauros3_save(void __iomem *base)
  1451. {
  1452. l2c_save(base);
  1453. l2x0_saved_regs.aux2_ctrl =
  1454. readl_relaxed(base + TAUROS3_AUX2_CTRL);
  1455. l2x0_saved_regs.prefetch_ctrl =
  1456. readl_relaxed(base + L310_PREFETCH_CTRL);
  1457. }
  1458. static void tauros3_configure(void __iomem *base)
  1459. {
  1460. l2c_configure(base);
  1461. writel_relaxed(l2x0_saved_regs.aux2_ctrl,
  1462. base + TAUROS3_AUX2_CTRL);
  1463. writel_relaxed(l2x0_saved_regs.prefetch_ctrl,
  1464. base + L310_PREFETCH_CTRL);
  1465. }
  1466. static const struct l2c_init_data of_tauros3_data __initconst = {
  1467. .type = "Tauros3",
  1468. .way_size_0 = SZ_8K,
  1469. .num_lock = 8,
  1470. .enable = l2c_enable,
  1471. .save = tauros3_save,
  1472. .configure = tauros3_configure,
  1473. .unlock = l2c_unlock,
  1474. /* Tauros3 broadcasts L1 cache operations to L2 */
  1475. .outer_cache = {
  1476. .resume = l2c_resume,
  1477. },
  1478. };
  1479. #define L2C_ID(name, fns) { .compatible = name, .data = (void *)&fns }
  1480. static const struct of_device_id l2x0_ids[] __initconst = {
  1481. L2C_ID("arm,l210-cache", of_l2c210_data),
  1482. L2C_ID("arm,l220-cache", of_l2c220_data),
  1483. L2C_ID("arm,pl310-cache", of_l2c310_data),
  1484. L2C_ID("brcm,bcm11351-a2-pl310-cache", of_bcm_l2x0_data),
  1485. L2C_ID("marvell,aurora-outer-cache", of_aurora_with_outer_data),
  1486. L2C_ID("marvell,aurora-system-cache", of_aurora_no_outer_data),
  1487. L2C_ID("marvell,tauros3-cache", of_tauros3_data),
  1488. /* Deprecated IDs */
  1489. L2C_ID("bcm,bcm11351-a2-pl310-cache", of_bcm_l2x0_data),
  1490. {}
  1491. };
  1492. int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
  1493. {
  1494. const struct l2c_init_data *data;
  1495. struct device_node *np;
  1496. struct resource res;
  1497. u32 cache_id, old_aux;
  1498. u32 cache_level = 2;
  1499. bool nosync = false;
  1500. np = of_find_matching_node(NULL, l2x0_ids);
  1501. if (!np)
  1502. return -ENODEV;
  1503. if (of_address_to_resource(np, 0, &res))
  1504. return -ENODEV;
  1505. l2x0_base = ioremap(res.start, resource_size(&res));
  1506. if (!l2x0_base)
  1507. return -ENOMEM;
  1508. l2x0_saved_regs.phy_base = res.start;
  1509. data = of_match_node(l2x0_ids, np)->data;
  1510. if (of_device_is_compatible(np, "arm,pl310-cache") &&
  1511. of_property_read_bool(np, "arm,io-coherent"))
  1512. data = &of_l2c310_coherent_data;
  1513. old_aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  1514. if (old_aux != ((old_aux & aux_mask) | aux_val)) {
  1515. pr_warn("L2C: platform modifies aux control register: 0x%08x -> 0x%08x\n",
  1516. old_aux, (old_aux & aux_mask) | aux_val);
  1517. } else if (aux_mask != ~0U && aux_val != 0) {
  1518. pr_alert("L2C: platform provided aux values match the hardware, so have no effect. Please remove them.\n");
  1519. }
  1520. /* All L2 caches are unified, so this property should be specified */
  1521. if (!of_property_read_bool(np, "cache-unified"))
  1522. pr_err("L2C: device tree omits to specify unified cache\n");
  1523. if (of_property_read_u32(np, "cache-level", &cache_level))
  1524. pr_err("L2C: device tree omits to specify cache-level\n");
  1525. if (cache_level != 2)
  1526. pr_err("L2C: device tree specifies invalid cache level\n");
  1527. nosync = of_property_read_bool(np, "arm,outer-sync-disable");
  1528. /* Read back current (default) hardware configuration */
  1529. if (data->save)
  1530. data->save(l2x0_base);
  1531. /* L2 configuration can only be changed if the cache is disabled */
  1532. if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN))
  1533. if (data->of_parse)
  1534. data->of_parse(np, &aux_val, &aux_mask);
  1535. if (cache_id_part_number_from_dt)
  1536. cache_id = cache_id_part_number_from_dt;
  1537. else
  1538. cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID);
  1539. return __l2c_init(data, aux_val, aux_mask, cache_id, nosync);
  1540. }
  1541. #endif