cache-l2x0.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. /*
  2. * arch/arm/mm/cache-l2x0.c - L210/L220 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/err.h>
  20. #include <linux/init.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/io.h>
  23. #include <linux/of.h>
  24. #include <linux/of_address.h>
  25. #include <asm/cacheflush.h>
  26. #include <asm/hardware/cache-l2x0.h>
  27. #include "cache-tauros3.h"
  28. #include "cache-aurora-l2.h"
  29. struct l2c_init_data {
  30. const char *type;
  31. unsigned num_lock;
  32. void (*of_parse)(const struct device_node *, u32 *, u32 *);
  33. void (*enable)(void __iomem *, u32, unsigned);
  34. void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
  35. void (*save)(void __iomem *);
  36. struct outer_cache_fns outer_cache;
  37. };
  38. #define CACHE_LINE_SIZE 32
  39. static void __iomem *l2x0_base;
  40. static DEFINE_RAW_SPINLOCK(l2x0_lock);
  41. static u32 l2x0_way_mask; /* Bitmask of active ways */
  42. static u32 l2x0_size;
  43. static unsigned long sync_reg_offset = L2X0_CACHE_SYNC;
  44. struct l2x0_regs l2x0_saved_regs;
  45. /*
  46. * Common code for all cache controllers.
  47. */
  48. static inline void l2c_wait_mask(void __iomem *reg, unsigned long mask)
  49. {
  50. /* wait for cache operation by line or way to complete */
  51. while (readl_relaxed(reg) & mask)
  52. cpu_relax();
  53. }
  54. /*
  55. * This should only be called when we have a requirement that the
  56. * register be written due to a work-around, as platforms running
  57. * in non-secure mode may not be able to access this register.
  58. */
  59. static inline void l2c_set_debug(void __iomem *base, unsigned long val)
  60. {
  61. outer_cache.set_debug(val);
  62. }
  63. static void __l2c_op_way(void __iomem *reg)
  64. {
  65. writel_relaxed(l2x0_way_mask, reg);
  66. l2c_wait_mask(reg, l2x0_way_mask);
  67. }
  68. static inline void l2c_unlock(void __iomem *base, unsigned num)
  69. {
  70. unsigned i;
  71. for (i = 0; i < num; i++) {
  72. writel_relaxed(0, base + L2X0_LOCKDOWN_WAY_D_BASE +
  73. i * L2X0_LOCKDOWN_STRIDE);
  74. writel_relaxed(0, base + L2X0_LOCKDOWN_WAY_I_BASE +
  75. i * L2X0_LOCKDOWN_STRIDE);
  76. }
  77. }
  78. /*
  79. * Enable the L2 cache controller. This function must only be
  80. * called when the cache controller is known to be disabled.
  81. */
  82. static void l2c_enable(void __iomem *base, u32 aux, unsigned num_lock)
  83. {
  84. unsigned long flags;
  85. /* Only write the aux register if it needs changing */
  86. if (readl_relaxed(base + L2X0_AUX_CTRL) != aux)
  87. writel_relaxed(aux, base + L2X0_AUX_CTRL);
  88. l2c_unlock(base, num_lock);
  89. local_irq_save(flags);
  90. __l2c_op_way(base + L2X0_INV_WAY);
  91. writel_relaxed(0, base + sync_reg_offset);
  92. l2c_wait_mask(base + sync_reg_offset, 1);
  93. local_irq_restore(flags);
  94. writel_relaxed(L2X0_CTRL_EN, base + L2X0_CTRL);
  95. }
  96. static void l2c_disable(void)
  97. {
  98. void __iomem *base = l2x0_base;
  99. outer_cache.flush_all();
  100. writel_relaxed(0, base + L2X0_CTRL);
  101. dsb(st);
  102. }
  103. #ifdef CONFIG_CACHE_PL310
  104. static inline void cache_wait(void __iomem *reg, unsigned long mask)
  105. {
  106. /* cache operations by line are atomic on PL310 */
  107. }
  108. #else
  109. #define cache_wait l2c_wait_mask
  110. #endif
  111. static inline void cache_sync(void)
  112. {
  113. void __iomem *base = l2x0_base;
  114. writel_relaxed(0, base + sync_reg_offset);
  115. cache_wait(base + L2X0_CACHE_SYNC, 1);
  116. }
  117. #if defined(CONFIG_PL310_ERRATA_588369) || defined(CONFIG_PL310_ERRATA_727915)
  118. static inline void debug_writel(unsigned long val)
  119. {
  120. if (outer_cache.set_debug)
  121. l2c_set_debug(l2x0_base, val);
  122. }
  123. #else
  124. /* Optimised out for non-errata case */
  125. static inline void debug_writel(unsigned long val)
  126. {
  127. }
  128. #endif
  129. static void l2x0_cache_sync(void)
  130. {
  131. unsigned long flags;
  132. raw_spin_lock_irqsave(&l2x0_lock, flags);
  133. cache_sync();
  134. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  135. }
  136. static void __l2x0_flush_all(void)
  137. {
  138. debug_writel(0x03);
  139. __l2c_op_way(l2x0_base + L2X0_CLEAN_INV_WAY);
  140. cache_sync();
  141. debug_writel(0x00);
  142. }
  143. static void l2x0_flush_all(void)
  144. {
  145. unsigned long flags;
  146. /* clean all ways */
  147. raw_spin_lock_irqsave(&l2x0_lock, flags);
  148. __l2x0_flush_all();
  149. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  150. }
  151. static void l2x0_disable(void)
  152. {
  153. unsigned long flags;
  154. raw_spin_lock_irqsave(&l2x0_lock, flags);
  155. __l2x0_flush_all();
  156. writel_relaxed(0, l2x0_base + L2X0_CTRL);
  157. dsb(st);
  158. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  159. }
  160. /*
  161. * L2C-210 specific code.
  162. *
  163. * The L2C-2x0 PA, set/way and sync operations are atomic, but we must
  164. * ensure that no background operation is running. The way operations
  165. * are all background tasks.
  166. *
  167. * While a background operation is in progress, any new operation is
  168. * ignored (unspecified whether this causes an error.) Thankfully, not
  169. * used on SMP.
  170. *
  171. * Never has a different sync register other than L2X0_CACHE_SYNC, but
  172. * we use sync_reg_offset here so we can share some of this with L2C-310.
  173. */
  174. static void __l2c210_cache_sync(void __iomem *base)
  175. {
  176. writel_relaxed(0, base + sync_reg_offset);
  177. }
  178. static void __l2c210_op_pa_range(void __iomem *reg, unsigned long start,
  179. unsigned long end)
  180. {
  181. while (start < end) {
  182. writel_relaxed(start, reg);
  183. start += CACHE_LINE_SIZE;
  184. }
  185. }
  186. static void l2c210_inv_range(unsigned long start, unsigned long end)
  187. {
  188. void __iomem *base = l2x0_base;
  189. if (start & (CACHE_LINE_SIZE - 1)) {
  190. start &= ~(CACHE_LINE_SIZE - 1);
  191. writel_relaxed(start, base + L2X0_CLEAN_INV_LINE_PA);
  192. start += CACHE_LINE_SIZE;
  193. }
  194. if (end & (CACHE_LINE_SIZE - 1)) {
  195. end &= ~(CACHE_LINE_SIZE - 1);
  196. writel_relaxed(end, base + L2X0_CLEAN_INV_LINE_PA);
  197. }
  198. __l2c210_op_pa_range(base + L2X0_INV_LINE_PA, start, end);
  199. __l2c210_cache_sync(base);
  200. }
  201. static void l2c210_clean_range(unsigned long start, unsigned long end)
  202. {
  203. void __iomem *base = l2x0_base;
  204. start &= ~(CACHE_LINE_SIZE - 1);
  205. __l2c210_op_pa_range(base + L2X0_CLEAN_LINE_PA, start, end);
  206. __l2c210_cache_sync(base);
  207. }
  208. static void l2c210_flush_range(unsigned long start, unsigned long end)
  209. {
  210. void __iomem *base = l2x0_base;
  211. start &= ~(CACHE_LINE_SIZE - 1);
  212. __l2c210_op_pa_range(base + L2X0_CLEAN_INV_LINE_PA, start, end);
  213. __l2c210_cache_sync(base);
  214. }
  215. static void l2c210_flush_all(void)
  216. {
  217. void __iomem *base = l2x0_base;
  218. BUG_ON(!irqs_disabled());
  219. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  220. __l2c210_cache_sync(base);
  221. }
  222. static void l2c210_sync(void)
  223. {
  224. __l2c210_cache_sync(l2x0_base);
  225. }
  226. static void l2c210_resume(void)
  227. {
  228. void __iomem *base = l2x0_base;
  229. if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN))
  230. l2c_enable(base, l2x0_saved_regs.aux_ctrl, 1);
  231. }
  232. static const struct l2c_init_data l2c210_data __initconst = {
  233. .type = "L2C-210",
  234. .num_lock = 1,
  235. .enable = l2c_enable,
  236. .outer_cache = {
  237. .inv_range = l2c210_inv_range,
  238. .clean_range = l2c210_clean_range,
  239. .flush_range = l2c210_flush_range,
  240. .flush_all = l2c210_flush_all,
  241. .disable = l2c_disable,
  242. .sync = l2c210_sync,
  243. .resume = l2c210_resume,
  244. },
  245. };
  246. /*
  247. * L2C-220 specific code.
  248. *
  249. * All operations are background operations: they have to be waited for.
  250. * Conflicting requests generate a slave error (which will cause an
  251. * imprecise abort.) Never uses sync_reg_offset, so we hard-code the
  252. * sync register here.
  253. *
  254. * However, we can re-use the l2c210_resume call.
  255. */
  256. static inline void __l2c220_cache_sync(void __iomem *base)
  257. {
  258. writel_relaxed(0, base + L2X0_CACHE_SYNC);
  259. l2c_wait_mask(base + L2X0_CACHE_SYNC, 1);
  260. }
  261. static void l2c220_op_way(void __iomem *base, unsigned reg)
  262. {
  263. unsigned long flags;
  264. raw_spin_lock_irqsave(&l2x0_lock, flags);
  265. __l2c_op_way(base + reg);
  266. __l2c220_cache_sync(base);
  267. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  268. }
  269. static unsigned long l2c220_op_pa_range(void __iomem *reg, unsigned long start,
  270. unsigned long end, unsigned long flags)
  271. {
  272. raw_spinlock_t *lock = &l2x0_lock;
  273. while (start < end) {
  274. unsigned long blk_end = start + min(end - start, 4096UL);
  275. while (start < blk_end) {
  276. l2c_wait_mask(reg, 1);
  277. writel_relaxed(start, reg);
  278. start += CACHE_LINE_SIZE;
  279. }
  280. if (blk_end < end) {
  281. raw_spin_unlock_irqrestore(lock, flags);
  282. raw_spin_lock_irqsave(lock, flags);
  283. }
  284. }
  285. return flags;
  286. }
  287. static void l2c220_inv_range(unsigned long start, unsigned long end)
  288. {
  289. void __iomem *base = l2x0_base;
  290. unsigned long flags;
  291. raw_spin_lock_irqsave(&l2x0_lock, flags);
  292. if ((start | end) & (CACHE_LINE_SIZE - 1)) {
  293. if (start & (CACHE_LINE_SIZE - 1)) {
  294. start &= ~(CACHE_LINE_SIZE - 1);
  295. writel_relaxed(start, base + L2X0_CLEAN_INV_LINE_PA);
  296. start += CACHE_LINE_SIZE;
  297. }
  298. if (end & (CACHE_LINE_SIZE - 1)) {
  299. end &= ~(CACHE_LINE_SIZE - 1);
  300. l2c_wait_mask(base + L2X0_CLEAN_INV_LINE_PA, 1);
  301. writel_relaxed(end, base + L2X0_CLEAN_INV_LINE_PA);
  302. }
  303. }
  304. flags = l2c220_op_pa_range(base + L2X0_INV_LINE_PA,
  305. start, end, flags);
  306. l2c_wait_mask(base + L2X0_INV_LINE_PA, 1);
  307. __l2c220_cache_sync(base);
  308. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  309. }
  310. static void l2c220_clean_range(unsigned long start, unsigned long end)
  311. {
  312. void __iomem *base = l2x0_base;
  313. unsigned long flags;
  314. start &= ~(CACHE_LINE_SIZE - 1);
  315. if ((end - start) >= l2x0_size) {
  316. l2c220_op_way(base, L2X0_CLEAN_WAY);
  317. return;
  318. }
  319. raw_spin_lock_irqsave(&l2x0_lock, flags);
  320. flags = l2c220_op_pa_range(base + L2X0_CLEAN_LINE_PA,
  321. start, end, flags);
  322. l2c_wait_mask(base + L2X0_CLEAN_INV_LINE_PA, 1);
  323. __l2c220_cache_sync(base);
  324. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  325. }
  326. static void l2c220_flush_range(unsigned long start, unsigned long end)
  327. {
  328. void __iomem *base = l2x0_base;
  329. unsigned long flags;
  330. start &= ~(CACHE_LINE_SIZE - 1);
  331. if ((end - start) >= l2x0_size) {
  332. l2c220_op_way(base, L2X0_CLEAN_INV_WAY);
  333. return;
  334. }
  335. raw_spin_lock_irqsave(&l2x0_lock, flags);
  336. flags = l2c220_op_pa_range(base + L2X0_CLEAN_INV_LINE_PA,
  337. start, end, flags);
  338. l2c_wait_mask(base + L2X0_CLEAN_INV_LINE_PA, 1);
  339. __l2c220_cache_sync(base);
  340. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  341. }
  342. static void l2c220_flush_all(void)
  343. {
  344. l2c220_op_way(l2x0_base, L2X0_CLEAN_INV_WAY);
  345. }
  346. static void l2c220_sync(void)
  347. {
  348. unsigned long flags;
  349. raw_spin_lock_irqsave(&l2x0_lock, flags);
  350. __l2c220_cache_sync(l2x0_base);
  351. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  352. }
  353. static const struct l2c_init_data l2c220_data = {
  354. .type = "L2C-220",
  355. .num_lock = 1,
  356. .enable = l2c_enable,
  357. .outer_cache = {
  358. .inv_range = l2c220_inv_range,
  359. .clean_range = l2c220_clean_range,
  360. .flush_range = l2c220_flush_range,
  361. .flush_all = l2c220_flush_all,
  362. .disable = l2c_disable,
  363. .sync = l2c220_sync,
  364. .resume = l2c210_resume,
  365. },
  366. };
  367. /*
  368. * L2C-310 specific code.
  369. *
  370. * Very similar to L2C-210, the PA, set/way and sync operations are atomic,
  371. * and the way operations are all background tasks. However, issuing an
  372. * operation while a background operation is in progress results in a
  373. * SLVERR response. We can reuse:
  374. *
  375. * __l2c210_cache_sync (using sync_reg_offset)
  376. * l2c210_sync
  377. * l2c210_inv_range (if 588369 is not applicable)
  378. * l2c210_clean_range
  379. * l2c210_flush_range (if 588369 is not applicable)
  380. * l2c210_flush_all (if 727915 is not applicable)
  381. *
  382. * Errata:
  383. * 588369: PL310 R0P0->R1P0, fixed R2P0.
  384. * Affects: all clean+invalidate operations
  385. * clean and invalidate skips the invalidate step, so we need to issue
  386. * separate operations. We also require the above debug workaround
  387. * enclosing this code fragment on affected parts. On unaffected parts,
  388. * we must not use this workaround without the debug register writes
  389. * to avoid exposing a problem similar to 727915.
  390. *
  391. * 727915: PL310 R2P0->R3P0, fixed R3P1.
  392. * Affects: clean+invalidate by way
  393. * clean and invalidate by way runs in the background, and a store can
  394. * hit the line between the clean operation and invalidate operation,
  395. * resulting in the store being lost.
  396. *
  397. * 753970: PL310 R3P0, fixed R3P1.
  398. * Affects: sync
  399. * prevents merging writes after the sync operation, until another L2C
  400. * operation is performed (or a number of other conditions.)
  401. *
  402. * 769419: PL310 R0P0->R3P1, fixed R3P2.
  403. * Affects: store buffer
  404. * store buffer is not automatically drained.
  405. */
  406. static void l2c310_set_debug(unsigned long val)
  407. {
  408. writel_relaxed(val, l2x0_base + L2X0_DEBUG_CTRL);
  409. }
  410. static void l2c310_inv_range_erratum(unsigned long start, unsigned long end)
  411. {
  412. void __iomem *base = l2x0_base;
  413. if ((start | end) & (CACHE_LINE_SIZE - 1)) {
  414. unsigned long flags;
  415. /* Erratum 588369 for both clean+invalidate operations */
  416. raw_spin_lock_irqsave(&l2x0_lock, flags);
  417. l2c_set_debug(base, 0x03);
  418. if (start & (CACHE_LINE_SIZE - 1)) {
  419. start &= ~(CACHE_LINE_SIZE - 1);
  420. writel_relaxed(start, base + L2X0_CLEAN_LINE_PA);
  421. writel_relaxed(start, base + L2X0_INV_LINE_PA);
  422. start += CACHE_LINE_SIZE;
  423. }
  424. if (end & (CACHE_LINE_SIZE - 1)) {
  425. end &= ~(CACHE_LINE_SIZE - 1);
  426. writel_relaxed(end, base + L2X0_CLEAN_LINE_PA);
  427. writel_relaxed(end, base + L2X0_INV_LINE_PA);
  428. }
  429. l2c_set_debug(base, 0x00);
  430. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  431. }
  432. __l2c210_op_pa_range(base + L2X0_INV_LINE_PA, start, end);
  433. __l2c210_cache_sync(base);
  434. }
  435. static void l2c310_flush_range_erratum(unsigned long start, unsigned long end)
  436. {
  437. raw_spinlock_t *lock = &l2x0_lock;
  438. unsigned long flags;
  439. void __iomem *base = l2x0_base;
  440. raw_spin_lock_irqsave(lock, flags);
  441. while (start < end) {
  442. unsigned long blk_end = start + min(end - start, 4096UL);
  443. l2c_set_debug(base, 0x03);
  444. while (start < blk_end) {
  445. writel_relaxed(start, base + L2X0_CLEAN_LINE_PA);
  446. writel_relaxed(start, base + L2X0_INV_LINE_PA);
  447. start += CACHE_LINE_SIZE;
  448. }
  449. l2c_set_debug(base, 0x00);
  450. if (blk_end < end) {
  451. raw_spin_unlock_irqrestore(lock, flags);
  452. raw_spin_lock_irqsave(lock, flags);
  453. }
  454. }
  455. raw_spin_unlock_irqrestore(lock, flags);
  456. __l2c210_cache_sync(base);
  457. }
  458. static void l2c310_flush_all_erratum(void)
  459. {
  460. void __iomem *base = l2x0_base;
  461. unsigned long flags;
  462. raw_spin_lock_irqsave(&l2x0_lock, flags);
  463. l2c_set_debug(base, 0x03);
  464. __l2c_op_way(base + L2X0_CLEAN_INV_WAY);
  465. l2c_set_debug(base, 0x00);
  466. __l2c210_cache_sync(base);
  467. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  468. }
  469. static void __init l2c310_save(void __iomem *base)
  470. {
  471. unsigned revision;
  472. l2x0_saved_regs.tag_latency = readl_relaxed(base +
  473. L2X0_TAG_LATENCY_CTRL);
  474. l2x0_saved_regs.data_latency = readl_relaxed(base +
  475. L2X0_DATA_LATENCY_CTRL);
  476. l2x0_saved_regs.filter_end = readl_relaxed(base +
  477. L2X0_ADDR_FILTER_END);
  478. l2x0_saved_regs.filter_start = readl_relaxed(base +
  479. L2X0_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. L2X0_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. L2X0_POWER_CTRL);
  490. }
  491. static void l2c310_resume(void)
  492. {
  493. void __iomem *base = l2x0_base;
  494. if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN)) {
  495. unsigned revision;
  496. /* restore pl310 setup */
  497. writel_relaxed(l2x0_saved_regs.tag_latency,
  498. base + L2X0_TAG_LATENCY_CTRL);
  499. writel_relaxed(l2x0_saved_regs.data_latency,
  500. base + L2X0_DATA_LATENCY_CTRL);
  501. writel_relaxed(l2x0_saved_regs.filter_end,
  502. base + L2X0_ADDR_FILTER_END);
  503. writel_relaxed(l2x0_saved_regs.filter_start,
  504. base + L2X0_ADDR_FILTER_START);
  505. revision = readl_relaxed(base + L2X0_CACHE_ID) &
  506. L2X0_CACHE_ID_RTL_MASK;
  507. if (revision >= L310_CACHE_ID_RTL_R2P0)
  508. writel_relaxed(l2x0_saved_regs.prefetch_ctrl,
  509. base + L2X0_PREFETCH_CTRL);
  510. if (revision >= L310_CACHE_ID_RTL_R3P0)
  511. writel_relaxed(l2x0_saved_regs.pwr_ctrl,
  512. base + L2X0_POWER_CTRL);
  513. l2c_enable(base, l2x0_saved_regs.aux_ctrl, 8);
  514. }
  515. }
  516. static void __init l2c310_fixup(void __iomem *base, u32 cache_id,
  517. struct outer_cache_fns *fns)
  518. {
  519. unsigned revision = cache_id & L2X0_CACHE_ID_RTL_MASK;
  520. const char *errata[4];
  521. unsigned n = 0;
  522. /* For compatibility */
  523. if (revision <= L310_CACHE_ID_RTL_R3P0)
  524. fns->set_debug = l2c310_set_debug;
  525. if (IS_ENABLED(CONFIG_PL310_ERRATA_588369) &&
  526. revision < L310_CACHE_ID_RTL_R2P0 &&
  527. /* For bcm compatibility */
  528. fns->inv_range == l2c210_inv_range) {
  529. fns->inv_range = l2c310_inv_range_erratum;
  530. fns->flush_range = l2c310_flush_range_erratum;
  531. errata[n++] = "588369";
  532. }
  533. if (IS_ENABLED(CONFIG_PL310_ERRATA_727915) &&
  534. revision >= L310_CACHE_ID_RTL_R2P0 &&
  535. revision < L310_CACHE_ID_RTL_R3P1) {
  536. fns->flush_all = l2c310_flush_all_erratum;
  537. errata[n++] = "727915";
  538. }
  539. if (IS_ENABLED(CONFIG_PL310_ERRATA_753970) &&
  540. revision == L310_CACHE_ID_RTL_R3P0) {
  541. sync_reg_offset = L2X0_DUMMY_REG;
  542. errata[n++] = "753970";
  543. }
  544. if (IS_ENABLED(CONFIG_PL310_ERRATA_769419))
  545. errata[n++] = "769419";
  546. if (n) {
  547. unsigned i;
  548. pr_info("L2C-310 errat%s", n > 1 ? "a" : "um");
  549. for (i = 0; i < n; i++)
  550. pr_cont(" %s", errata[i]);
  551. pr_cont(" enabled\n");
  552. }
  553. }
  554. static const struct l2c_init_data l2c310_init_fns __initconst = {
  555. .type = "L2C-310",
  556. .num_lock = 8,
  557. .enable = l2c_enable,
  558. .fixup = l2c310_fixup,
  559. .save = l2c310_save,
  560. .outer_cache = {
  561. .inv_range = l2c210_inv_range,
  562. .clean_range = l2c210_clean_range,
  563. .flush_range = l2c210_flush_range,
  564. .flush_all = l2c210_flush_all,
  565. .disable = l2c_disable,
  566. .sync = l2c210_sync,
  567. .set_debug = l2c310_set_debug,
  568. .resume = l2c310_resume,
  569. },
  570. };
  571. static void __init __l2c_init(const struct l2c_init_data *data,
  572. u32 aux_val, u32 aux_mask, u32 cache_id)
  573. {
  574. struct outer_cache_fns fns;
  575. u32 aux;
  576. u32 way_size = 0;
  577. int ways;
  578. int way_size_shift = L2X0_WAY_SIZE_SHIFT;
  579. /*
  580. * It is strange to save the register state before initialisation,
  581. * but hey, this is what the DT implementations decided to do.
  582. */
  583. if (data->save)
  584. data->save(l2x0_base);
  585. aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  586. aux &= aux_mask;
  587. aux |= aux_val;
  588. /* Determine the number of ways */
  589. switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
  590. case L2X0_CACHE_ID_PART_L310:
  591. if (aux & (1 << 16))
  592. ways = 16;
  593. else
  594. ways = 8;
  595. break;
  596. case L2X0_CACHE_ID_PART_L210:
  597. case L2X0_CACHE_ID_PART_L220:
  598. ways = (aux >> 13) & 0xf;
  599. break;
  600. case AURORA_CACHE_ID:
  601. ways = (aux >> 13) & 0xf;
  602. ways = 2 << ((ways + 1) >> 2);
  603. way_size_shift = AURORA_WAY_SIZE_SHIFT;
  604. break;
  605. default:
  606. /* Assume unknown chips have 8 ways */
  607. ways = 8;
  608. break;
  609. }
  610. l2x0_way_mask = (1 << ways) - 1;
  611. /*
  612. * L2 cache Size = Way size * Number of ways
  613. */
  614. way_size = (aux & L2X0_AUX_CTRL_WAY_SIZE_MASK) >> 17;
  615. way_size = 1 << (way_size + way_size_shift);
  616. l2x0_size = ways * way_size * SZ_1K;
  617. fns = data->outer_cache;
  618. if (data->fixup)
  619. data->fixup(l2x0_base, cache_id, &fns);
  620. /*
  621. * Check if l2x0 controller is already enabled. If we are booting
  622. * in non-secure mode accessing the below registers will fault.
  623. */
  624. if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN))
  625. data->enable(l2x0_base, aux, data->num_lock);
  626. /* Re-read it in case some bits are reserved. */
  627. aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
  628. /* Save the value for resuming. */
  629. l2x0_saved_regs.aux_ctrl = aux;
  630. outer_cache = fns;
  631. pr_info("%s cache controller enabled, %d ways, %d kB\n",
  632. data->type, ways, l2x0_size >> 10);
  633. pr_info("%s: CACHE_ID 0x%08x, AUX_CTRL 0x%08x\n",
  634. data->type, cache_id, aux);
  635. }
  636. void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
  637. {
  638. const struct l2c_init_data *data;
  639. u32 cache_id;
  640. l2x0_base = base;
  641. cache_id = readl_relaxed(base + L2X0_CACHE_ID);
  642. switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
  643. default:
  644. case L2X0_CACHE_ID_PART_L210:
  645. data = &l2c210_data;
  646. break;
  647. case L2X0_CACHE_ID_PART_L220:
  648. data = &l2c220_data;
  649. break;
  650. case L2X0_CACHE_ID_PART_L310:
  651. data = &l2c310_init_fns;
  652. break;
  653. }
  654. __l2c_init(data, aux_val, aux_mask, cache_id);
  655. }
  656. #ifdef CONFIG_OF
  657. static int l2_wt_override;
  658. /* Aurora don't have the cache ID register available, so we have to
  659. * pass it though the device tree */
  660. static u32 cache_id_part_number_from_dt;
  661. static void __init l2x0_of_parse(const struct device_node *np,
  662. u32 *aux_val, u32 *aux_mask)
  663. {
  664. u32 data[2] = { 0, 0 };
  665. u32 tag = 0;
  666. u32 dirty = 0;
  667. u32 val = 0, mask = 0;
  668. of_property_read_u32(np, "arm,tag-latency", &tag);
  669. if (tag) {
  670. mask |= L2X0_AUX_CTRL_TAG_LATENCY_MASK;
  671. val |= (tag - 1) << L2X0_AUX_CTRL_TAG_LATENCY_SHIFT;
  672. }
  673. of_property_read_u32_array(np, "arm,data-latency",
  674. data, ARRAY_SIZE(data));
  675. if (data[0] && data[1]) {
  676. mask |= L2X0_AUX_CTRL_DATA_RD_LATENCY_MASK |
  677. L2X0_AUX_CTRL_DATA_WR_LATENCY_MASK;
  678. val |= ((data[0] - 1) << L2X0_AUX_CTRL_DATA_RD_LATENCY_SHIFT) |
  679. ((data[1] - 1) << L2X0_AUX_CTRL_DATA_WR_LATENCY_SHIFT);
  680. }
  681. of_property_read_u32(np, "arm,dirty-latency", &dirty);
  682. if (dirty) {
  683. mask |= L2X0_AUX_CTRL_DIRTY_LATENCY_MASK;
  684. val |= (dirty - 1) << L2X0_AUX_CTRL_DIRTY_LATENCY_SHIFT;
  685. }
  686. *aux_val &= ~mask;
  687. *aux_val |= val;
  688. *aux_mask &= ~mask;
  689. }
  690. static const struct l2c_init_data of_l2c210_data __initconst = {
  691. .type = "L2C-210",
  692. .num_lock = 1,
  693. .of_parse = l2x0_of_parse,
  694. .enable = l2c_enable,
  695. .outer_cache = {
  696. .inv_range = l2c210_inv_range,
  697. .clean_range = l2c210_clean_range,
  698. .flush_range = l2c210_flush_range,
  699. .flush_all = l2c210_flush_all,
  700. .disable = l2c_disable,
  701. .sync = l2c210_sync,
  702. .resume = l2c210_resume,
  703. },
  704. };
  705. static const struct l2c_init_data of_l2c220_data __initconst = {
  706. .type = "L2C-220",
  707. .num_lock = 1,
  708. .of_parse = l2x0_of_parse,
  709. .enable = l2c_enable,
  710. .outer_cache = {
  711. .inv_range = l2c220_inv_range,
  712. .clean_range = l2c220_clean_range,
  713. .flush_range = l2c220_flush_range,
  714. .flush_all = l2c220_flush_all,
  715. .disable = l2c_disable,
  716. .sync = l2c220_sync,
  717. .resume = l2c210_resume,
  718. },
  719. };
  720. static void __init l2c310_of_parse(const struct device_node *np,
  721. u32 *aux_val, u32 *aux_mask)
  722. {
  723. u32 data[3] = { 0, 0, 0 };
  724. u32 tag[3] = { 0, 0, 0 };
  725. u32 filter[2] = { 0, 0 };
  726. of_property_read_u32_array(np, "arm,tag-latency", tag, ARRAY_SIZE(tag));
  727. if (tag[0] && tag[1] && tag[2])
  728. writel_relaxed(
  729. ((tag[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) |
  730. ((tag[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) |
  731. ((tag[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT),
  732. l2x0_base + L2X0_TAG_LATENCY_CTRL);
  733. of_property_read_u32_array(np, "arm,data-latency",
  734. data, ARRAY_SIZE(data));
  735. if (data[0] && data[1] && data[2])
  736. writel_relaxed(
  737. ((data[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) |
  738. ((data[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) |
  739. ((data[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT),
  740. l2x0_base + L2X0_DATA_LATENCY_CTRL);
  741. of_property_read_u32_array(np, "arm,filter-ranges",
  742. filter, ARRAY_SIZE(filter));
  743. if (filter[1]) {
  744. writel_relaxed(ALIGN(filter[0] + filter[1], SZ_1M),
  745. l2x0_base + L2X0_ADDR_FILTER_END);
  746. writel_relaxed((filter[0] & ~(SZ_1M - 1)) | L2X0_ADDR_FILTER_EN,
  747. l2x0_base + L2X0_ADDR_FILTER_START);
  748. }
  749. }
  750. static const struct l2c_init_data of_l2c310_data __initconst = {
  751. .type = "L2C-310",
  752. .num_lock = 8,
  753. .of_parse = l2c310_of_parse,
  754. .enable = l2c_enable,
  755. .fixup = l2c310_fixup,
  756. .save = l2c310_save,
  757. .outer_cache = {
  758. .inv_range = l2c210_inv_range,
  759. .clean_range = l2c210_clean_range,
  760. .flush_range = l2c210_flush_range,
  761. .flush_all = l2c210_flush_all,
  762. .disable = l2c_disable,
  763. .sync = l2c210_sync,
  764. .set_debug = l2c310_set_debug,
  765. .resume = l2c310_resume,
  766. },
  767. };
  768. /*
  769. * Note that the end addresses passed to Linux primitives are
  770. * noninclusive, while the hardware cache range operations use
  771. * inclusive start and end addresses.
  772. */
  773. static unsigned long calc_range_end(unsigned long start, unsigned long end)
  774. {
  775. /*
  776. * Limit the number of cache lines processed at once,
  777. * since cache range operations stall the CPU pipeline
  778. * until completion.
  779. */
  780. if (end > start + MAX_RANGE_SIZE)
  781. end = start + MAX_RANGE_SIZE;
  782. /*
  783. * Cache range operations can't straddle a page boundary.
  784. */
  785. if (end > PAGE_ALIGN(start+1))
  786. end = PAGE_ALIGN(start+1);
  787. return end;
  788. }
  789. /*
  790. * Make sure 'start' and 'end' reference the same page, as L2 is PIPT
  791. * and range operations only do a TLB lookup on the start address.
  792. */
  793. static void aurora_pa_range(unsigned long start, unsigned long end,
  794. unsigned long offset)
  795. {
  796. unsigned long flags;
  797. raw_spin_lock_irqsave(&l2x0_lock, flags);
  798. writel_relaxed(start, l2x0_base + AURORA_RANGE_BASE_ADDR_REG);
  799. writel_relaxed(end, l2x0_base + offset);
  800. raw_spin_unlock_irqrestore(&l2x0_lock, flags);
  801. cache_sync();
  802. }
  803. static void aurora_inv_range(unsigned long start, unsigned long end)
  804. {
  805. /*
  806. * round start and end adresses up to cache line size
  807. */
  808. start &= ~(CACHE_LINE_SIZE - 1);
  809. end = ALIGN(end, CACHE_LINE_SIZE);
  810. /*
  811. * Invalidate all full cache lines between 'start' and 'end'.
  812. */
  813. while (start < end) {
  814. unsigned long range_end = calc_range_end(start, end);
  815. aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
  816. AURORA_INVAL_RANGE_REG);
  817. start = range_end;
  818. }
  819. }
  820. static void aurora_clean_range(unsigned long start, unsigned long end)
  821. {
  822. /*
  823. * If L2 is forced to WT, the L2 will always be clean and we
  824. * don't need to do anything here.
  825. */
  826. if (!l2_wt_override) {
  827. start &= ~(CACHE_LINE_SIZE - 1);
  828. end = ALIGN(end, CACHE_LINE_SIZE);
  829. while (start != end) {
  830. unsigned long range_end = calc_range_end(start, end);
  831. aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
  832. AURORA_CLEAN_RANGE_REG);
  833. start = range_end;
  834. }
  835. }
  836. }
  837. static void aurora_flush_range(unsigned long start, unsigned long end)
  838. {
  839. start &= ~(CACHE_LINE_SIZE - 1);
  840. end = ALIGN(end, CACHE_LINE_SIZE);
  841. while (start != end) {
  842. unsigned long range_end = calc_range_end(start, end);
  843. /*
  844. * If L2 is forced to WT, the L2 will always be clean and we
  845. * just need to invalidate.
  846. */
  847. if (l2_wt_override)
  848. aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
  849. AURORA_INVAL_RANGE_REG);
  850. else
  851. aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
  852. AURORA_FLUSH_RANGE_REG);
  853. start = range_end;
  854. }
  855. }
  856. static void aurora_save(void __iomem *base)
  857. {
  858. l2x0_saved_regs.ctrl = readl_relaxed(base + L2X0_CTRL);
  859. l2x0_saved_regs.aux_ctrl = readl_relaxed(base + L2X0_AUX_CTRL);
  860. }
  861. static void aurora_resume(void)
  862. {
  863. void __iomem *base = l2x0_base;
  864. if (!(readl(base + L2X0_CTRL) & L2X0_CTRL_EN)) {
  865. writel_relaxed(l2x0_saved_regs.aux_ctrl, base + L2X0_AUX_CTRL);
  866. writel_relaxed(l2x0_saved_regs.ctrl, base + L2X0_CTRL);
  867. }
  868. }
  869. /*
  870. * For Aurora cache in no outer mode, enable via the CP15 coprocessor
  871. * broadcasting of cache commands to L2.
  872. */
  873. static void __init aurora_enable_no_outer(void __iomem *base, u32 aux,
  874. unsigned num_lock)
  875. {
  876. u32 u;
  877. asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
  878. u |= AURORA_CTRL_FW; /* Set the FW bit */
  879. asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
  880. isb();
  881. l2c_enable(base, aux, num_lock);
  882. }
  883. static void __init aurora_fixup(void __iomem *base, u32 cache_id,
  884. struct outer_cache_fns *fns)
  885. {
  886. sync_reg_offset = AURORA_SYNC_REG;
  887. }
  888. static void __init aurora_of_parse(const struct device_node *np,
  889. u32 *aux_val, u32 *aux_mask)
  890. {
  891. u32 val = AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU;
  892. u32 mask = AURORA_ACR_REPLACEMENT_MASK;
  893. of_property_read_u32(np, "cache-id-part",
  894. &cache_id_part_number_from_dt);
  895. /* Determine and save the write policy */
  896. l2_wt_override = of_property_read_bool(np, "wt-override");
  897. if (l2_wt_override) {
  898. val |= AURORA_ACR_FORCE_WRITE_THRO_POLICY;
  899. mask |= AURORA_ACR_FORCE_WRITE_POLICY_MASK;
  900. }
  901. *aux_val &= ~mask;
  902. *aux_val |= val;
  903. *aux_mask &= ~mask;
  904. }
  905. static const struct l2c_init_data of_aurora_with_outer_data __initconst = {
  906. .type = "Aurora",
  907. .num_lock = 4,
  908. .of_parse = aurora_of_parse,
  909. .enable = l2c_enable,
  910. .fixup = aurora_fixup,
  911. .save = aurora_save,
  912. .outer_cache = {
  913. .inv_range = aurora_inv_range,
  914. .clean_range = aurora_clean_range,
  915. .flush_range = aurora_flush_range,
  916. .flush_all = l2x0_flush_all,
  917. .disable = l2x0_disable,
  918. .sync = l2x0_cache_sync,
  919. .resume = aurora_resume,
  920. },
  921. };
  922. static const struct l2c_init_data of_aurora_no_outer_data __initconst = {
  923. .type = "Aurora",
  924. .num_lock = 4,
  925. .of_parse = aurora_of_parse,
  926. .enable = aurora_enable_no_outer,
  927. .fixup = aurora_fixup,
  928. .save = aurora_save,
  929. .outer_cache = {
  930. .resume = aurora_resume,
  931. },
  932. };
  933. /*
  934. * For certain Broadcom SoCs, depending on the address range, different offsets
  935. * need to be added to the address before passing it to L2 for
  936. * invalidation/clean/flush
  937. *
  938. * Section Address Range Offset EMI
  939. * 1 0x00000000 - 0x3FFFFFFF 0x80000000 VC
  940. * 2 0x40000000 - 0xBFFFFFFF 0x40000000 SYS
  941. * 3 0xC0000000 - 0xFFFFFFFF 0x80000000 VC
  942. *
  943. * When the start and end addresses have crossed two different sections, we
  944. * need to break the L2 operation into two, each within its own section.
  945. * For example, if we need to invalidate addresses starts at 0xBFFF0000 and
  946. * ends at 0xC0001000, we need do invalidate 1) 0xBFFF0000 - 0xBFFFFFFF and 2)
  947. * 0xC0000000 - 0xC0001000
  948. *
  949. * Note 1:
  950. * By breaking a single L2 operation into two, we may potentially suffer some
  951. * performance hit, but keep in mind the cross section case is very rare
  952. *
  953. * Note 2:
  954. * We do not need to handle the case when the start address is in
  955. * Section 1 and the end address is in Section 3, since it is not a valid use
  956. * case
  957. *
  958. * Note 3:
  959. * Section 1 in practical terms can no longer be used on rev A2. Because of
  960. * that the code does not need to handle section 1 at all.
  961. *
  962. */
  963. #define BCM_SYS_EMI_START_ADDR 0x40000000UL
  964. #define BCM_VC_EMI_SEC3_START_ADDR 0xC0000000UL
  965. #define BCM_SYS_EMI_OFFSET 0x40000000UL
  966. #define BCM_VC_EMI_OFFSET 0x80000000UL
  967. static inline int bcm_addr_is_sys_emi(unsigned long addr)
  968. {
  969. return (addr >= BCM_SYS_EMI_START_ADDR) &&
  970. (addr < BCM_VC_EMI_SEC3_START_ADDR);
  971. }
  972. static inline unsigned long bcm_l2_phys_addr(unsigned long addr)
  973. {
  974. if (bcm_addr_is_sys_emi(addr))
  975. return addr + BCM_SYS_EMI_OFFSET;
  976. else
  977. return addr + BCM_VC_EMI_OFFSET;
  978. }
  979. static void bcm_inv_range(unsigned long start, unsigned long end)
  980. {
  981. unsigned long new_start, new_end;
  982. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  983. if (unlikely(end <= start))
  984. return;
  985. new_start = bcm_l2_phys_addr(start);
  986. new_end = bcm_l2_phys_addr(end);
  987. /* normal case, no cross section between start and end */
  988. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  989. l2c210_inv_range(new_start, new_end);
  990. return;
  991. }
  992. /* They cross sections, so it can only be a cross from section
  993. * 2 to section 3
  994. */
  995. l2c210_inv_range(new_start,
  996. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  997. l2c210_inv_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  998. new_end);
  999. }
  1000. static void bcm_clean_range(unsigned long start, unsigned long end)
  1001. {
  1002. unsigned long new_start, new_end;
  1003. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1004. if (unlikely(end <= start))
  1005. return;
  1006. new_start = bcm_l2_phys_addr(start);
  1007. new_end = bcm_l2_phys_addr(end);
  1008. /* normal case, no cross section between start and end */
  1009. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1010. l2c210_clean_range(new_start, new_end);
  1011. return;
  1012. }
  1013. /* They cross sections, so it can only be a cross from section
  1014. * 2 to section 3
  1015. */
  1016. l2c210_clean_range(new_start,
  1017. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1018. l2c210_clean_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1019. new_end);
  1020. }
  1021. static void bcm_flush_range(unsigned long start, unsigned long end)
  1022. {
  1023. unsigned long new_start, new_end;
  1024. BUG_ON(start < BCM_SYS_EMI_START_ADDR);
  1025. if (unlikely(end <= start))
  1026. return;
  1027. if ((end - start) >= l2x0_size) {
  1028. outer_cache.flush_all();
  1029. return;
  1030. }
  1031. new_start = bcm_l2_phys_addr(start);
  1032. new_end = bcm_l2_phys_addr(end);
  1033. /* normal case, no cross section between start and end */
  1034. if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
  1035. l2c210_flush_range(new_start, new_end);
  1036. return;
  1037. }
  1038. /* They cross sections, so it can only be a cross from section
  1039. * 2 to section 3
  1040. */
  1041. l2c210_flush_range(new_start,
  1042. bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
  1043. l2c210_flush_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
  1044. new_end);
  1045. }
  1046. /* Broadcom L2C-310 start from ARMs R3P2 or later, and require no fixups */
  1047. static const struct l2c_init_data of_bcm_l2x0_data __initconst = {
  1048. .type = "BCM-L2C-310",
  1049. .num_lock = 8,
  1050. .of_parse = l2c310_of_parse,
  1051. .enable = l2c_enable,
  1052. .save = l2c310_save,
  1053. .outer_cache = {
  1054. .inv_range = bcm_inv_range,
  1055. .clean_range = bcm_clean_range,
  1056. .flush_range = bcm_flush_range,
  1057. .flush_all = l2c210_flush_all,
  1058. .disable = l2c_disable,
  1059. .sync = l2c210_sync,
  1060. .resume = l2c310_resume,
  1061. },
  1062. };
  1063. static void __init tauros3_save(void __iomem *base)
  1064. {
  1065. l2x0_saved_regs.aux2_ctrl =
  1066. readl_relaxed(base + TAUROS3_AUX2_CTRL);
  1067. l2x0_saved_regs.prefetch_ctrl =
  1068. readl_relaxed(base + L2X0_PREFETCH_CTRL);
  1069. }
  1070. static void tauros3_resume(void)
  1071. {
  1072. void __iomem *base = l2x0_base;
  1073. if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN)) {
  1074. writel_relaxed(l2x0_saved_regs.aux2_ctrl,
  1075. base + TAUROS3_AUX2_CTRL);
  1076. writel_relaxed(l2x0_saved_regs.prefetch_ctrl,
  1077. base + L2X0_PREFETCH_CTRL);
  1078. l2c_enable(base, l2x0_saved_regs.aux_ctrl, 8);
  1079. }
  1080. }
  1081. static const struct l2c_init_data of_tauros3_data __initconst = {
  1082. .type = "Tauros3",
  1083. .num_lock = 8,
  1084. .enable = l2c_enable,
  1085. .save = tauros3_save,
  1086. /* Tauros3 broadcasts L1 cache operations to L2 */
  1087. .outer_cache = {
  1088. .resume = tauros3_resume,
  1089. },
  1090. };
  1091. #define L2C_ID(name, fns) { .compatible = name, .data = (void *)&fns }
  1092. static const struct of_device_id l2x0_ids[] __initconst = {
  1093. L2C_ID("arm,l210-cache", of_l2c210_data),
  1094. L2C_ID("arm,l220-cache", of_l2c220_data),
  1095. L2C_ID("arm,pl310-cache", of_l2c310_data),
  1096. L2C_ID("brcm,bcm11351-a2-pl310-cache", of_bcm_l2x0_data),
  1097. L2C_ID("marvell,aurora-outer-cache", of_aurora_with_outer_data),
  1098. L2C_ID("marvell,aurora-system-cache", of_aurora_no_outer_data),
  1099. L2C_ID("marvell,tauros3-cache", of_tauros3_data),
  1100. /* Deprecated IDs */
  1101. L2C_ID("bcm,bcm11351-a2-pl310-cache", of_bcm_l2x0_data),
  1102. {}
  1103. };
  1104. int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
  1105. {
  1106. const struct l2c_init_data *data;
  1107. struct device_node *np;
  1108. struct resource res;
  1109. u32 cache_id;
  1110. np = of_find_matching_node(NULL, l2x0_ids);
  1111. if (!np)
  1112. return -ENODEV;
  1113. if (of_address_to_resource(np, 0, &res))
  1114. return -ENODEV;
  1115. l2x0_base = ioremap(res.start, resource_size(&res));
  1116. if (!l2x0_base)
  1117. return -ENOMEM;
  1118. l2x0_saved_regs.phy_base = res.start;
  1119. data = of_match_node(l2x0_ids, np)->data;
  1120. /* L2 configuration can only be changed if the cache is disabled */
  1121. if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN))
  1122. if (data->of_parse)
  1123. data->of_parse(np, &aux_val, &aux_mask);
  1124. if (cache_id_part_number_from_dt)
  1125. cache_id = cache_id_part_number_from_dt;
  1126. else
  1127. cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID);
  1128. __l2c_init(data, aux_val, aux_mask, cache_id);
  1129. return 0;
  1130. }
  1131. #endif