cache-l2x0.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  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_cpu_enable_flz(struct notifier_block *nb, unsigned long act, void *data)
  514. {
  515. switch (act & ~CPU_TASKS_FROZEN) {
  516. case CPU_STARTING:
  517. set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
  518. break;
  519. case CPU_DYING:
  520. set_auxcr(get_auxcr() & ~(BIT(3) | BIT(2) | BIT(1)));
  521. break;
  522. }
  523. return NOTIFY_OK;
  524. }
  525. static void __init l2c310_enable(void __iomem *base, unsigned num_lock)
  526. {
  527. unsigned rev = readl_relaxed(base + L2X0_CACHE_ID) & L2X0_CACHE_ID_RTL_MASK;
  528. bool cortex_a9 = read_cpuid_part() == ARM_CPU_PART_CORTEX_A9;
  529. u32 aux = l2x0_saved_regs.aux_ctrl;
  530. if (rev >= L310_CACHE_ID_RTL_R2P0) {
  531. if (cortex_a9) {
  532. aux |= L310_AUX_CTRL_EARLY_BRESP;
  533. pr_info("L2C-310 enabling early BRESP for Cortex-A9\n");
  534. } else if (aux & L310_AUX_CTRL_EARLY_BRESP) {
  535. pr_warn("L2C-310 early BRESP only supported with Cortex-A9\n");
  536. aux &= ~L310_AUX_CTRL_EARLY_BRESP;
  537. }
  538. }
  539. if (cortex_a9) {
  540. u32 aux_cur = readl_relaxed(base + L2X0_AUX_CTRL);
  541. u32 acr = get_auxcr();
  542. pr_debug("Cortex-A9 ACR=0x%08x\n", acr);
  543. if (acr & BIT(3) && !(aux_cur & L310_AUX_CTRL_FULL_LINE_ZERO))
  544. pr_err("L2C-310: full line of zeros enabled in Cortex-A9 but not L2C-310 - invalid\n");
  545. if (aux & L310_AUX_CTRL_FULL_LINE_ZERO && !(acr & BIT(3)))
  546. pr_err("L2C-310: enabling full line of zeros but not enabled in Cortex-A9\n");
  547. if (!(aux & L310_AUX_CTRL_FULL_LINE_ZERO) && !outer_cache.write_sec) {
  548. aux |= L310_AUX_CTRL_FULL_LINE_ZERO;
  549. pr_info("L2C-310 full line of zeros enabled for Cortex-A9\n");
  550. }
  551. } else if (aux & (L310_AUX_CTRL_FULL_LINE_ZERO | L310_AUX_CTRL_EARLY_BRESP)) {
  552. pr_err("L2C-310: disabling Cortex-A9 specific feature bits\n");
  553. aux &= ~(L310_AUX_CTRL_FULL_LINE_ZERO | L310_AUX_CTRL_EARLY_BRESP);
  554. }
  555. /* r3p0 or later has power control register */
  556. if (rev >= L310_CACHE_ID_RTL_R3P0)
  557. l2x0_saved_regs.pwr_ctrl = L310_DYNAMIC_CLK_GATING_EN |
  558. L310_STNDBY_MODE_EN;
  559. /*
  560. * Always enable non-secure access to the lockdown registers -
  561. * we write to them as part of the L2C enable sequence so they
  562. * need to be accessible.
  563. */
  564. l2x0_saved_regs.aux_ctrl = aux | L310_AUX_CTRL_NS_LOCKDOWN;
  565. l2c_enable(base, num_lock);
  566. /* Read back resulting AUX_CTRL value as it could have been altered. */
  567. aux = readl_relaxed(base + L2X0_AUX_CTRL);
  568. if (aux & (L310_AUX_CTRL_DATA_PREFETCH | L310_AUX_CTRL_INSTR_PREFETCH)) {
  569. u32 prefetch = readl_relaxed(base + L310_PREFETCH_CTRL);
  570. pr_info("L2C-310 %s%s prefetch enabled, offset %u lines\n",
  571. aux & L310_AUX_CTRL_INSTR_PREFETCH ? "I" : "",
  572. aux & L310_AUX_CTRL_DATA_PREFETCH ? "D" : "",
  573. 1 + (prefetch & L310_PREFETCH_CTRL_OFFSET_MASK));
  574. }
  575. /* r3p0 or later has power control register */
  576. if (rev >= L310_CACHE_ID_RTL_R3P0) {
  577. u32 power_ctrl;
  578. power_ctrl = readl_relaxed(base + L310_POWER_CTRL);
  579. pr_info("L2C-310 dynamic clock gating %sabled, standby mode %sabled\n",
  580. power_ctrl & L310_DYNAMIC_CLK_GATING_EN ? "en" : "dis",
  581. power_ctrl & L310_STNDBY_MODE_EN ? "en" : "dis");
  582. }
  583. if (aux & L310_AUX_CTRL_FULL_LINE_ZERO) {
  584. set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
  585. cpu_notifier(l2c310_cpu_enable_flz, 0);
  586. }
  587. }
  588. static void __init l2c310_fixup(void __iomem *base, u32 cache_id,
  589. struct outer_cache_fns *fns)
  590. {
  591. unsigned revision = cache_id & L2X0_CACHE_ID_RTL_MASK;
  592. const char *errata[8];
  593. unsigned n = 0;
  594. if (IS_ENABLED(CONFIG_PL310_ERRATA_588369) &&
  595. revision < L310_CACHE_ID_RTL_R2P0 &&
  596. /* For bcm compatibility */
  597. fns->inv_range == l2c210_inv_range) {
  598. fns->inv_range = l2c310_inv_range_erratum;
  599. fns->flush_range = l2c310_flush_range_erratum;
  600. errata[n++] = "588369";
  601. }
  602. if (IS_ENABLED(CONFIG_PL310_ERRATA_727915) &&
  603. revision >= L310_CACHE_ID_RTL_R2P0 &&
  604. revision < L310_CACHE_ID_RTL_R3P1) {
  605. fns->flush_all = l2c310_flush_all_erratum;
  606. errata[n++] = "727915";
  607. }
  608. if (revision >= L310_CACHE_ID_RTL_R3P0 &&
  609. revision < L310_CACHE_ID_RTL_R3P2) {
  610. u32 val = l2x0_saved_regs.prefetch_ctrl;
  611. /* I don't think bit23 is required here... but iMX6 does so */
  612. if (val & (BIT(30) | BIT(23))) {
  613. val &= ~(BIT(30) | BIT(23));
  614. l2x0_saved_regs.prefetch_ctrl = val;
  615. errata[n++] = "752271";
  616. }
  617. }
  618. if (IS_ENABLED(CONFIG_PL310_ERRATA_753970) &&
  619. revision == L310_CACHE_ID_RTL_R3P0) {
  620. sync_reg_offset = L2X0_DUMMY_REG;
  621. errata[n++] = "753970";
  622. }
  623. if (IS_ENABLED(CONFIG_PL310_ERRATA_769419))
  624. errata[n++] = "769419";
  625. if (n) {
  626. unsigned i;
  627. pr_info("L2C-310 errat%s", n > 1 ? "a" : "um");
  628. for (i = 0; i < n; i++)
  629. pr_cont(" %s", errata[i]);
  630. pr_cont(" enabled\n");
  631. }
  632. }
  633. static void l2c310_disable(void)
  634. {
  635. /*
  636. * If full-line-of-zeros is enabled, we must first disable it in the
  637. * Cortex-A9 auxiliary control register before disabling the L2 cache.
  638. */
  639. if (l2x0_saved_regs.aux_ctrl & L310_AUX_CTRL_FULL_LINE_ZERO)
  640. set_auxcr(get_auxcr() & ~(BIT(3) | BIT(2) | BIT(1)));
  641. l2c_disable();
  642. }
  643. static void l2c310_resume(void)
  644. {
  645. l2c_resume();
  646. /* Re-enable full-line-of-zeros for Cortex-A9 */
  647. if (l2x0_saved_regs.aux_ctrl & L310_AUX_CTRL_FULL_LINE_ZERO)
  648. set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
  649. }
  650. static void l2c310_unlock(void __iomem *base, unsigned num_lock)
  651. {
  652. if (readl_relaxed(base + L2X0_AUX_CTRL) & L310_AUX_CTRL_NS_LOCKDOWN)
  653. l2c_unlock(base, num_lock);
  654. }
  655. static const struct l2c_init_data l2c310_init_fns __initconst = {
  656. .type = "L2C-310",
  657. .way_size_0 = SZ_8K,
  658. .num_lock = 8,
  659. .enable = l2c310_enable,
  660. .fixup = l2c310_fixup,
  661. .save = l2c310_save,
  662. .configure = l2c310_configure,
  663. .unlock = l2c310_unlock,
  664. .outer_cache = {
  665. .inv_range = l2c210_inv_range,
  666. .clean_range = l2c210_clean_range,
  667. .flush_range = l2c210_flush_range,
  668. .flush_all = l2c210_flush_all,
  669. .disable = l2c310_disable,
  670. .sync = l2c210_sync,
  671. .resume = l2c310_resume,
  672. },
  673. };
  674. static int __init __l2c_init(const struct l2c_init_data *data,
  675. u32 aux_val, u32 aux_mask, u32 cache_id)
  676. {
  677. struct outer_cache_fns fns;
  678. unsigned way_size_bits, ways;
  679. u32 aux, old_aux;
  680. /*
  681. * Save the pointer globally so that callbacks which do not receive
  682. * context from callers can access the structure.
  683. */
  684. l2x0_data = kmemdup(data, sizeof(*data), GFP_KERNEL);
  685. if (!l2x0_data)
  686. return -ENOMEM;
  687. /*
  688. * Sanity check the aux values. aux_mask is the bits we preserve
  689. * from reading the hardware register, and aux_val is the bits we
  690. * set.
  691. */
  692. if (aux_val & aux_mask)
  693. pr_alert("L2C: platform provided aux values permit register corruption.\n");
  694. old_aux = aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  695. aux &= aux_mask;
  696. aux |= aux_val;
  697. if (old_aux != aux)
  698. pr_warn("L2C: DT/platform modifies aux control register: 0x%08x -> 0x%08x\n",
  699. old_aux, aux);
  700. /* Determine the number of ways */
  701. switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
  702. case L2X0_CACHE_ID_PART_L310:
  703. if ((aux_val | ~aux_mask) & (L2C_AUX_CTRL_WAY_SIZE_MASK | L310_AUX_CTRL_ASSOCIATIVITY_16))
  704. pr_warn("L2C: DT/platform tries to modify or specify cache size\n");
  705. if (aux & (1 << 16))
  706. ways = 16;
  707. else
  708. ways = 8;
  709. break;
  710. case L2X0_CACHE_ID_PART_L210:
  711. case L2X0_CACHE_ID_PART_L220:
  712. ways = (aux >> 13) & 0xf;
  713. break;
  714. case AURORA_CACHE_ID:
  715. ways = (aux >> 13) & 0xf;
  716. ways = 2 << ((ways + 1) >> 2);
  717. break;
  718. default:
  719. /* Assume unknown chips have 8 ways */
  720. ways = 8;
  721. break;
  722. }
  723. l2x0_way_mask = (1 << ways) - 1;
  724. /*
  725. * way_size_0 is the size that a way_size value of zero would be
  726. * given the calculation: way_size = way_size_0 << way_size_bits.
  727. * So, if way_size_bits=0 is reserved, but way_size_bits=1 is 16k,
  728. * then way_size_0 would be 8k.
  729. *
  730. * L2 cache size = number of ways * way size.
  731. */
  732. way_size_bits = (aux & L2C_AUX_CTRL_WAY_SIZE_MASK) >>
  733. L2C_AUX_CTRL_WAY_SIZE_SHIFT;
  734. l2x0_size = ways * (data->way_size_0 << way_size_bits);
  735. fns = data->outer_cache;
  736. fns.write_sec = outer_cache.write_sec;
  737. fns.configure = outer_cache.configure;
  738. if (data->fixup)
  739. data->fixup(l2x0_base, cache_id, &fns);
  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);
  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. ret = l2x0_cache_size_of_parse(np, aux_val, aux_mask, &assoc, SZ_256K);
  901. if (ret)
  902. return;
  903. if (assoc > 8) {
  904. pr_err("l2x0 of: cache setting yield too high associativity\n");
  905. pr_err("l2x0 of: %d calculated, max 8\n", assoc);
  906. } else {
  907. mask |= L2X0_AUX_CTRL_ASSOC_MASK;
  908. val |= (assoc << L2X0_AUX_CTRL_ASSOC_SHIFT);
  909. }
  910. *aux_val &= ~mask;
  911. *aux_val |= val;
  912. *aux_mask &= ~mask;
  913. }
  914. static const struct l2c_init_data of_l2c210_data __initconst = {
  915. .type = "L2C-210",
  916. .way_size_0 = SZ_8K,
  917. .num_lock = 1,
  918. .of_parse = l2x0_of_parse,
  919. .enable = l2c_enable,
  920. .save = l2c_save,
  921. .configure = l2c_configure,
  922. .unlock = l2c_unlock,
  923. .outer_cache = {
  924. .inv_range = l2c210_inv_range,
  925. .clean_range = l2c210_clean_range,
  926. .flush_range = l2c210_flush_range,
  927. .flush_all = l2c210_flush_all,
  928. .disable = l2c_disable,
  929. .sync = l2c210_sync,
  930. .resume = l2c_resume,
  931. },
  932. };
  933. static const struct l2c_init_data of_l2c220_data __initconst = {
  934. .type = "L2C-220",
  935. .way_size_0 = SZ_8K,
  936. .num_lock = 1,
  937. .of_parse = l2x0_of_parse,
  938. .enable = l2c220_enable,
  939. .save = l2c_save,
  940. .configure = l2c_configure,
  941. .unlock = l2c220_unlock,
  942. .outer_cache = {
  943. .inv_range = l2c220_inv_range,
  944. .clean_range = l2c220_clean_range,
  945. .flush_range = l2c220_flush_range,
  946. .flush_all = l2c220_flush_all,
  947. .disable = l2c_disable,
  948. .sync = l2c220_sync,
  949. .resume = l2c_resume,
  950. },
  951. };
  952. static void __init l2c310_of_parse(const struct device_node *np,
  953. u32 *aux_val, u32 *aux_mask)
  954. {
  955. u32 data[3] = { 0, 0, 0 };
  956. u32 tag[3] = { 0, 0, 0 };
  957. u32 filter[2] = { 0, 0 };
  958. u32 assoc;
  959. u32 prefetch;
  960. u32 val;
  961. int ret;
  962. of_property_read_u32_array(np, "arm,tag-latency", tag, ARRAY_SIZE(tag));
  963. if (tag[0] && tag[1] && tag[2])
  964. l2x0_saved_regs.tag_latency =
  965. L310_LATENCY_CTRL_RD(tag[0] - 1) |
  966. L310_LATENCY_CTRL_WR(tag[1] - 1) |
  967. L310_LATENCY_CTRL_SETUP(tag[2] - 1);
  968. of_property_read_u32_array(np, "arm,data-latency",
  969. data, ARRAY_SIZE(data));
  970. if (data[0] && data[1] && data[2])
  971. l2x0_saved_regs.data_latency =
  972. L310_LATENCY_CTRL_RD(data[0] - 1) |
  973. L310_LATENCY_CTRL_WR(data[1] - 1) |
  974. L310_LATENCY_CTRL_SETUP(data[2] - 1);
  975. of_property_read_u32_array(np, "arm,filter-ranges",
  976. filter, ARRAY_SIZE(filter));
  977. if (filter[1]) {
  978. l2x0_saved_regs.filter_end =
  979. ALIGN(filter[0] + filter[1], SZ_1M);
  980. l2x0_saved_regs.filter_start = (filter[0] & ~(SZ_1M - 1))
  981. | L310_ADDR_FILTER_EN;
  982. }
  983. ret = l2x0_cache_size_of_parse(np, aux_val, aux_mask, &assoc, SZ_512K);
  984. if (!ret) {
  985. switch (assoc) {
  986. case 16:
  987. *aux_val &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  988. *aux_val |= L310_AUX_CTRL_ASSOCIATIVITY_16;
  989. *aux_mask &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  990. break;
  991. case 8:
  992. *aux_val &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  993. *aux_mask &= ~L2X0_AUX_CTRL_ASSOC_MASK;
  994. break;
  995. default:
  996. pr_err("L2C-310 OF cache associativity %d invalid, only 8 or 16 permitted\n",
  997. assoc);
  998. break;
  999. }
  1000. }
  1001. if (of_property_read_bool(np, "arm,shared-override")) {
  1002. *aux_val |= L2C_AUX_CTRL_SHARED_OVERRIDE;
  1003. *aux_mask &= ~L2C_AUX_CTRL_SHARED_OVERRIDE;
  1004. }
  1005. prefetch = l2x0_saved_regs.prefetch_ctrl;
  1006. ret = of_property_read_u32(np, "arm,double-linefill", &val);
  1007. if (ret == 0) {
  1008. if (val)
  1009. prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL;
  1010. else
  1011. prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL;
  1012. } else if (ret != -EINVAL) {
  1013. pr_err("L2C-310 OF arm,double-linefill property value is missing\n");
  1014. }
  1015. ret = of_property_read_u32(np, "arm,double-linefill-incr", &val);
  1016. if (ret == 0) {
  1017. if (val)
  1018. prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL_INCR;
  1019. else
  1020. prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL_INCR;
  1021. } else if (ret != -EINVAL) {
  1022. pr_err("L2C-310 OF arm,double-linefill-incr property value is missing\n");
  1023. }
  1024. ret = of_property_read_u32(np, "arm,double-linefill-wrap", &val);
  1025. if (ret == 0) {
  1026. if (!val)
  1027. prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL_WRAP;
  1028. else
  1029. prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL_WRAP;
  1030. } else if (ret != -EINVAL) {
  1031. pr_err("L2C-310 OF arm,double-linefill-wrap property value is missing\n");
  1032. }
  1033. ret = of_property_read_u32(np, "arm,prefetch-drop", &val);
  1034. if (ret == 0) {
  1035. if (val)
  1036. prefetch |= L310_PREFETCH_CTRL_PREFETCH_DROP;
  1037. else
  1038. prefetch &= ~L310_PREFETCH_CTRL_PREFETCH_DROP;
  1039. } else if (ret != -EINVAL) {
  1040. pr_err("L2C-310 OF arm,prefetch-drop property value is missing\n");
  1041. }
  1042. ret = of_property_read_u32(np, "arm,prefetch-offset", &val);
  1043. if (ret == 0) {
  1044. prefetch &= ~L310_PREFETCH_CTRL_OFFSET_MASK;
  1045. prefetch |= val & L310_PREFETCH_CTRL_OFFSET_MASK;
  1046. } else if (ret != -EINVAL) {
  1047. pr_err("L2C-310 OF arm,prefetch-offset property value is missing\n");
  1048. }
  1049. ret = of_property_read_u32(np, "prefetch-data", &val);
  1050. if (ret == 0) {
  1051. if (val)
  1052. prefetch |= L310_PREFETCH_CTRL_DATA_PREFETCH;
  1053. else
  1054. prefetch &= ~L310_PREFETCH_CTRL_DATA_PREFETCH;
  1055. } else if (ret != -EINVAL) {
  1056. pr_err("L2C-310 OF prefetch-data property value is missing\n");
  1057. }
  1058. ret = of_property_read_u32(np, "prefetch-instr", &val);
  1059. if (ret == 0) {
  1060. if (val)
  1061. prefetch |= L310_PREFETCH_CTRL_INSTR_PREFETCH;
  1062. else
  1063. prefetch &= ~L310_PREFETCH_CTRL_INSTR_PREFETCH;
  1064. } else if (ret != -EINVAL) {
  1065. pr_err("L2C-310 OF prefetch-instr property value is missing\n");
  1066. }
  1067. l2x0_saved_regs.prefetch_ctrl = prefetch;
  1068. }
  1069. static const struct l2c_init_data of_l2c310_data __initconst = {
  1070. .type = "L2C-310",
  1071. .way_size_0 = SZ_8K,
  1072. .num_lock = 8,
  1073. .of_parse = l2c310_of_parse,
  1074. .enable = l2c310_enable,
  1075. .fixup = l2c310_fixup,
  1076. .save = l2c310_save,
  1077. .configure = l2c310_configure,
  1078. .unlock = l2c310_unlock,
  1079. .outer_cache = {
  1080. .inv_range = l2c210_inv_range,
  1081. .clean_range = l2c210_clean_range,
  1082. .flush_range = l2c210_flush_range,
  1083. .flush_all = l2c210_flush_all,
  1084. .disable = l2c310_disable,
  1085. .sync = l2c210_sync,
  1086. .resume = l2c310_resume,
  1087. },
  1088. };
  1089. /*
  1090. * This is a variant of the of_l2c310_data with .sync set to
  1091. * NULL. Outer sync operations are not needed when the system is I/O
  1092. * coherent, and potentially harmful in certain situations (PCIe/PL310
  1093. * deadlock on Armada 375/38x due to hardware I/O coherency). The
  1094. * other operations are kept because they are infrequent (therefore do
  1095. * not cause the deadlock in practice) and needed for secondary CPU
  1096. * boot and other power management activities.
  1097. */
  1098. static const struct l2c_init_data of_l2c310_coherent_data __initconst = {
  1099. .type = "L2C-310 Coherent",
  1100. .way_size_0 = SZ_8K,
  1101. .num_lock = 8,
  1102. .of_parse = l2c310_of_parse,
  1103. .enable = l2c310_enable,
  1104. .fixup = l2c310_fixup,
  1105. .save = l2c310_save,
  1106. .configure = l2c310_configure,
  1107. .unlock = l2c310_unlock,
  1108. .outer_cache = {
  1109. .inv_range = l2c210_inv_range,
  1110. .clean_range = l2c210_clean_range,
  1111. .flush_range = l2c210_flush_range,
  1112. .flush_all = l2c210_flush_all,
  1113. .disable = l2c310_disable,
  1114. .resume = l2c310_resume,
  1115. },
  1116. };
  1117. /*
  1118. * Note that the end addresses passed to Linux primitives are
  1119. * noninclusive, while the hardware cache range operations use
  1120. * inclusive start and end addresses.
  1121. */
  1122. static unsigned long aurora_range_end(unsigned long start, unsigned long end)
  1123. {
  1124. /*
  1125. * Limit the number of cache lines processed at once,
  1126. * since cache range operations stall the CPU pipeline
  1127. * until completion.
  1128. */
  1129. if (end > start + MAX_RANGE_SIZE)
  1130. end = start + MAX_RANGE_SIZE;
  1131. /*
  1132. * Cache range operations can't straddle a page boundary.
  1133. */
  1134. if (end > PAGE_ALIGN(start+1))
  1135. end = PAGE_ALIGN(start+1);
  1136. return end;
  1137. }
  1138. static void aurora_pa_range(unsigned long start, unsigned long end,
  1139. unsigned long offset)
  1140. {
  1141. void __iomem *base = l2x0_base;
  1142. unsigned long range_end;
  1143. unsigned long flags;
  1144. /*
  1145. * round start and end adresses up to cache line size
  1146. */
  1147. start &= ~(CACHE_LINE_SIZE - 1);
  1148. end = ALIGN(end, CACHE_LINE_SIZE);
  1149. /*
  1150. * perform operation on all full cache lines between 'start' and 'end'
  1151. */
  1152. while (start < end) {
  1153. range_end = aurora_range_end(start, end);
  1154. raw_spin_lock_irqsave(&l2x0_lock, flags);
  1155. writel_relaxed(start, base + AURORA_RANGE_BASE_ADDR_REG);
  1156. writel_relaxed(range_end - CACHE_LINE_SIZE, base + offset);
  1157. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  1158. writel_relaxed(0, base + AURORA_SYNC_REG);
  1159. start = range_end;
  1160. }
  1161. }
  1162. static void aurora_inv_range(unsigned long start, unsigned long end)
  1163. {
  1164. aurora_pa_range(start, end, AURORA_INVAL_RANGE_REG);
  1165. }
  1166. static void aurora_clean_range(unsigned long start, unsigned long end)
  1167. {
  1168. /*
  1169. * If L2 is forced to WT, the L2 will always be clean and we
  1170. * don't need to do anything here.
  1171. */
  1172. if (!l2_wt_override)
  1173. aurora_pa_range(start, end, AURORA_CLEAN_RANGE_REG);
  1174. }
  1175. static void aurora_flush_range(unsigned long start, unsigned long end)
  1176. {
  1177. if (l2_wt_override)
  1178. aurora_pa_range(start, end, AURORA_INVAL_RANGE_REG);
  1179. else
  1180. aurora_pa_range(start, end, AURORA_FLUSH_RANGE_REG);
  1181. }
  1182. static void aurora_flush_all(void)
  1183. {
  1184. void __iomem *base = l2x0_base;
  1185. unsigned long flags;
  1186. /* clean all ways */
  1187. raw_spin_lock_irqsave(&l2x0_lock, flags);
  1188. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  1189. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  1190. writel_relaxed(0, base + AURORA_SYNC_REG);
  1191. }
  1192. static void aurora_cache_sync(void)
  1193. {
  1194. writel_relaxed(0, l2x0_base + AURORA_SYNC_REG);
  1195. }
  1196. static void aurora_disable(void)
  1197. {
  1198. void __iomem *base = l2x0_base;
  1199. unsigned long flags;
  1200. raw_spin_lock_irqsave(&l2x0_lock, flags);
  1201. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  1202. writel_relaxed(0, base + AURORA_SYNC_REG);
  1203. l2c_write_sec(0, base, L2X0_CTRL);
  1204. dsb(st);
  1205. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  1206. }
  1207. static void aurora_save(void __iomem *base)
  1208. {
  1209. l2x0_saved_regs.ctrl = readl_relaxed(base + L2X0_CTRL);
  1210. l2x0_saved_regs.aux_ctrl = readl_relaxed(base + L2X0_AUX_CTRL);
  1211. }
  1212. /*
  1213. * For Aurora cache in no outer mode, enable via the CP15 coprocessor
  1214. * broadcasting of cache commands to L2.
  1215. */
  1216. static void __init aurora_enable_no_outer(void __iomem *base,
  1217. unsigned num_lock)
  1218. {
  1219. u32 u;
  1220. asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
  1221. u |= AURORA_CTRL_FW; /* Set the FW bit */
  1222. asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
  1223. isb();
  1224. l2c_enable(base, num_lock);
  1225. }
  1226. static void __init aurora_fixup(void __iomem *base, u32 cache_id,
  1227. struct outer_cache_fns *fns)
  1228. {
  1229. sync_reg_offset = AURORA_SYNC_REG;
  1230. }
  1231. static void __init aurora_of_parse(const struct device_node *np,
  1232. u32 *aux_val, u32 *aux_mask)
  1233. {
  1234. u32 val = AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU;
  1235. u32 mask = AURORA_ACR_REPLACEMENT_MASK;
  1236. of_property_read_u32(np, "cache-id-part",
  1237. &cache_id_part_number_from_dt);
  1238. /* Determine and save the write policy */
  1239. l2_wt_override = of_property_read_bool(np, "wt-override");
  1240. if (l2_wt_override) {
  1241. val |= AURORA_ACR_FORCE_WRITE_THRO_POLICY;
  1242. mask |= AURORA_ACR_FORCE_WRITE_POLICY_MASK;
  1243. }
  1244. *aux_val &= ~mask;
  1245. *aux_val |= val;
  1246. *aux_mask &= ~mask;
  1247. }
  1248. static const struct l2c_init_data of_aurora_with_outer_data __initconst = {
  1249. .type = "Aurora",
  1250. .way_size_0 = SZ_4K,
  1251. .num_lock = 4,
  1252. .of_parse = aurora_of_parse,
  1253. .enable = l2c_enable,
  1254. .fixup = aurora_fixup,
  1255. .save = aurora_save,
  1256. .configure = l2c_configure,
  1257. .unlock = l2c_unlock,
  1258. .outer_cache = {
  1259. .inv_range = aurora_inv_range,
  1260. .clean_range = aurora_clean_range,
  1261. .flush_range = aurora_flush_range,
  1262. .flush_all = aurora_flush_all,
  1263. .disable = aurora_disable,
  1264. .sync = aurora_cache_sync,
  1265. .resume = l2c_resume,
  1266. },
  1267. };
  1268. static const struct l2c_init_data of_aurora_no_outer_data __initconst = {
  1269. .type = "Aurora",
  1270. .way_size_0 = SZ_4K,
  1271. .num_lock = 4,
  1272. .of_parse = aurora_of_parse,
  1273. .enable = aurora_enable_no_outer,
  1274. .fixup = aurora_fixup,
  1275. .save = aurora_save,
  1276. .configure = l2c_configure,
  1277. .unlock = l2c_unlock,
  1278. .outer_cache = {
  1279. .resume = l2c_resume,
  1280. },
  1281. };
  1282. /*
  1283. * For certain Broadcom SoCs, depending on the address range, different offsets
  1284. * need to be added to the address before passing it to L2 for
  1285. * invalidation/clean/flush
  1286. *
  1287. * Section Address Range Offset EMI
  1288. * 1 0x00000000 - 0x3FFFFFFF 0x80000000 VC
  1289. * 2 0x40000000 - 0xBFFFFFFF 0x40000000 SYS
  1290. * 3 0xC0000000 - 0xFFFFFFFF 0x80000000 VC
  1291. *
  1292. * When the start and end addresses have crossed two different sections, we
  1293. * need to break the L2 operation into two, each within its own section.
  1294. * For example, if we need to invalidate addresses starts at 0xBFFF0000 and
  1295. * ends at 0xC0001000, we need do invalidate 1) 0xBFFF0000 - 0xBFFFFFFF and 2)
  1296. * 0xC0000000 - 0xC0001000
  1297. *
  1298. * Note 1:
  1299. * By breaking a single L2 operation into two, we may potentially suffer some
  1300. * performance hit, but keep in mind the cross section case is very rare
  1301. *
  1302. * Note 2:
  1303. * We do not need to handle the case when the start address is in
  1304. * Section 1 and the end address is in Section 3, since it is not a valid use
  1305. * case
  1306. *
  1307. * Note 3:
  1308. * Section 1 in practical terms can no longer be used on rev A2. Because of
  1309. * that the code does not need to handle section 1 at all.
  1310. *
  1311. */
  1312. #define BCM_SYS_EMI_START_ADDR 0x40000000UL
  1313. #define BCM_VC_EMI_SEC3_START_ADDR 0xC0000000UL
  1314. #define BCM_SYS_EMI_OFFSET 0x40000000UL
  1315. #define BCM_VC_EMI_OFFSET 0x80000000UL
  1316. static inline int bcm_addr_is_sys_emi(unsigned long addr)
  1317. {
  1318. return (addr >= BCM_SYS_EMI_START_ADDR) &&
  1319. (addr < BCM_VC_EMI_SEC3_START_ADDR);
  1320. }
  1321. static inline unsigned long bcm_l2_phys_addr(unsigned long addr)
  1322. {
  1323. if (bcm_addr_is_sys_emi(addr))
  1324. return addr + BCM_SYS_EMI_OFFSET;
  1325. else
  1326. return addr + BCM_VC_EMI_OFFSET;
  1327. }
  1328. static void bcm_inv_range(unsigned long start, unsigned long end)
  1329. {
  1330. unsigned long new_start, new_end;
  1331. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1332. if (unlikely(end <= start))
  1333. return;
  1334. new_start = bcm_l2_phys_addr(start);
  1335. new_end = bcm_l2_phys_addr(end);
  1336. /* normal case, no cross section between start and end */
  1337. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1338. l2c210_inv_range(new_start, new_end);
  1339. return;
  1340. }
  1341. /* They cross sections, so it can only be a cross from section
  1342. * 2 to section 3
  1343. */
  1344. l2c210_inv_range(new_start,
  1345. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1346. l2c210_inv_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1347. new_end);
  1348. }
  1349. static void bcm_clean_range(unsigned long start, unsigned long end)
  1350. {
  1351. unsigned long new_start, new_end;
  1352. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1353. if (unlikely(end <= start))
  1354. return;
  1355. new_start = bcm_l2_phys_addr(start);
  1356. new_end = bcm_l2_phys_addr(end);
  1357. /* normal case, no cross section between start and end */
  1358. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1359. l2c210_clean_range(new_start, new_end);
  1360. return;
  1361. }
  1362. /* They cross sections, so it can only be a cross from section
  1363. * 2 to section 3
  1364. */
  1365. l2c210_clean_range(new_start,
  1366. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1367. l2c210_clean_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1368. new_end);
  1369. }
  1370. static void bcm_flush_range(unsigned long start, unsigned long end)
  1371. {
  1372. unsigned long new_start, new_end;
  1373. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1374. if (unlikely(end <= start))
  1375. return;
  1376. if ((end - start) >= l2x0_size) {
  1377. outer_cache.flush_all();
  1378. return;
  1379. }
  1380. new_start = bcm_l2_phys_addr(start);
  1381. new_end = bcm_l2_phys_addr(end);
  1382. /* normal case, no cross section between start and end */
  1383. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1384. l2c210_flush_range(new_start, new_end);
  1385. return;
  1386. }
  1387. /* They cross sections, so it can only be a cross from section
  1388. * 2 to section 3
  1389. */
  1390. l2c210_flush_range(new_start,
  1391. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1392. l2c210_flush_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1393. new_end);
  1394. }
  1395. /* Broadcom L2C-310 start from ARMs R3P2 or later, and require no fixups */
  1396. static const struct l2c_init_data of_bcm_l2x0_data __initconst = {
  1397. .type = "BCM-L2C-310",
  1398. .way_size_0 = SZ_8K,
  1399. .num_lock = 8,
  1400. .of_parse = l2c310_of_parse,
  1401. .enable = l2c310_enable,
  1402. .save = l2c310_save,
  1403. .configure = l2c310_configure,
  1404. .unlock = l2c310_unlock,
  1405. .outer_cache = {
  1406. .inv_range = bcm_inv_range,
  1407. .clean_range = bcm_clean_range,
  1408. .flush_range = bcm_flush_range,
  1409. .flush_all = l2c210_flush_all,
  1410. .disable = l2c310_disable,
  1411. .sync = l2c210_sync,
  1412. .resume = l2c310_resume,
  1413. },
  1414. };
  1415. static void __init tauros3_save(void __iomem *base)
  1416. {
  1417. l2c_save(base);
  1418. l2x0_saved_regs.aux2_ctrl =
  1419. readl_relaxed(base + TAUROS3_AUX2_CTRL);
  1420. l2x0_saved_regs.prefetch_ctrl =
  1421. readl_relaxed(base + L310_PREFETCH_CTRL);
  1422. }
  1423. static void tauros3_configure(void __iomem *base)
  1424. {
  1425. l2c_configure(base);
  1426. writel_relaxed(l2x0_saved_regs.aux2_ctrl,
  1427. base + TAUROS3_AUX2_CTRL);
  1428. writel_relaxed(l2x0_saved_regs.prefetch_ctrl,
  1429. base + L310_PREFETCH_CTRL);
  1430. }
  1431. static const struct l2c_init_data of_tauros3_data __initconst = {
  1432. .type = "Tauros3",
  1433. .way_size_0 = SZ_8K,
  1434. .num_lock = 8,
  1435. .enable = l2c_enable,
  1436. .save = tauros3_save,
  1437. .configure = tauros3_configure,
  1438. .unlock = l2c_unlock,
  1439. /* Tauros3 broadcasts L1 cache operations to L2 */
  1440. .outer_cache = {
  1441. .resume = l2c_resume,
  1442. },
  1443. };
  1444. #define L2C_ID(name, fns) { .compatible = name, .data = (void *)&fns }
  1445. static const struct of_device_id l2x0_ids[] __initconst = {
  1446. L2C_ID("arm,l210-cache", of_l2c210_data),
  1447. L2C_ID("arm,l220-cache", of_l2c220_data),
  1448. L2C_ID("arm,pl310-cache", of_l2c310_data),
  1449. L2C_ID("brcm,bcm11351-a2-pl310-cache", of_bcm_l2x0_data),
  1450. L2C_ID("marvell,aurora-outer-cache", of_aurora_with_outer_data),
  1451. L2C_ID("marvell,aurora-system-cache", of_aurora_no_outer_data),
  1452. L2C_ID("marvell,tauros3-cache", of_tauros3_data),
  1453. /* Deprecated IDs */
  1454. L2C_ID("bcm,bcm11351-a2-pl310-cache", of_bcm_l2x0_data),
  1455. {}
  1456. };
  1457. int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
  1458. {
  1459. const struct l2c_init_data *data;
  1460. struct device_node *np;
  1461. struct resource res;
  1462. u32 cache_id, old_aux;
  1463. u32 cache_level = 2;
  1464. np = of_find_matching_node(NULL, l2x0_ids);
  1465. if (!np)
  1466. return -ENODEV;
  1467. if (of_address_to_resource(np, 0, &res))
  1468. return -ENODEV;
  1469. l2x0_base = ioremap(res.start, resource_size(&res));
  1470. if (!l2x0_base)
  1471. return -ENOMEM;
  1472. l2x0_saved_regs.phy_base = res.start;
  1473. data = of_match_node(l2x0_ids, np)->data;
  1474. if (of_device_is_compatible(np, "arm,pl310-cache") &&
  1475. of_property_read_bool(np, "arm,io-coherent"))
  1476. data = &of_l2c310_coherent_data;
  1477. old_aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  1478. if (old_aux != ((old_aux & aux_mask) | aux_val)) {
  1479. pr_warn("L2C: platform modifies aux control register: 0x%08x -> 0x%08x\n",
  1480. old_aux, (old_aux & aux_mask) | aux_val);
  1481. } else if (aux_mask != ~0U && aux_val != 0) {
  1482. pr_alert("L2C: platform provided aux values match the hardware, so have no effect. Please remove them.\n");
  1483. }
  1484. /* All L2 caches are unified, so this property should be specified */
  1485. if (!of_property_read_bool(np, "cache-unified"))
  1486. pr_err("L2C: device tree omits to specify unified cache\n");
  1487. if (of_property_read_u32(np, "cache-level", &cache_level))
  1488. pr_err("L2C: device tree omits to specify cache-level\n");
  1489. if (cache_level != 2)
  1490. pr_err("L2C: device tree specifies invalid cache level\n");
  1491. /* Read back current (default) hardware configuration */
  1492. if (data->save)
  1493. data->save(l2x0_base);
  1494. /* L2 configuration can only be changed if the cache is disabled */
  1495. if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN))
  1496. if (data->of_parse)
  1497. data->of_parse(np, &aux_val, &aux_mask);
  1498. if (cache_id_part_number_from_dt)
  1499. cache_id = cache_id_part_number_from_dt;
  1500. else
  1501. cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID);
  1502. return __l2c_init(data, aux_val, aux_mask, cache_id);
  1503. }
  1504. #endif