fsl_pamu.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright (C) 2013 Freescale Semiconductor, Inc.
  16. *
  17. */
  18. #define pr_fmt(fmt) "fsl-pamu: %s: " fmt, __func__
  19. #include "fsl_pamu.h"
  20. #include <linux/fsl/guts.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/genalloc.h>
  23. #include <asm/mpc85xx.h>
  24. /* define indexes for each operation mapping scenario */
  25. #define OMI_QMAN 0x00
  26. #define OMI_FMAN 0x01
  27. #define OMI_QMAN_PRIV 0x02
  28. #define OMI_CAAM 0x03
  29. #define make64(high, low) (((u64)(high) << 32) | (low))
  30. struct pamu_isr_data {
  31. void __iomem *pamu_reg_base; /* Base address of PAMU regs */
  32. unsigned int count; /* The number of PAMUs */
  33. };
  34. static struct paace *ppaact;
  35. static struct paace *spaact;
  36. static bool probed; /* Has PAMU been probed? */
  37. /*
  38. * Table for matching compatible strings, for device tree
  39. * guts node, for QorIQ SOCs.
  40. * "fsl,qoriq-device-config-2.0" corresponds to T4 & B4
  41. * SOCs. For the older SOCs "fsl,qoriq-device-config-1.0"
  42. * string would be used.
  43. */
  44. static const struct of_device_id guts_device_ids[] = {
  45. { .compatible = "fsl,qoriq-device-config-1.0", },
  46. { .compatible = "fsl,qoriq-device-config-2.0", },
  47. {}
  48. };
  49. /*
  50. * Table for matching compatible strings, for device tree
  51. * L3 cache controller node.
  52. * "fsl,t4240-l3-cache-controller" corresponds to T4,
  53. * "fsl,b4860-l3-cache-controller" corresponds to B4 &
  54. * "fsl,p4080-l3-cache-controller" corresponds to other,
  55. * SOCs.
  56. */
  57. static const struct of_device_id l3_device_ids[] = {
  58. { .compatible = "fsl,t4240-l3-cache-controller", },
  59. { .compatible = "fsl,b4860-l3-cache-controller", },
  60. { .compatible = "fsl,p4080-l3-cache-controller", },
  61. {}
  62. };
  63. /* maximum subwindows permitted per liodn */
  64. static u32 max_subwindow_count;
  65. /* Pool for fspi allocation */
  66. static struct gen_pool *spaace_pool;
  67. /**
  68. * pamu_get_max_subwin_cnt() - Return the maximum supported
  69. * subwindow count per liodn.
  70. *
  71. */
  72. u32 pamu_get_max_subwin_cnt(void)
  73. {
  74. return max_subwindow_count;
  75. }
  76. /**
  77. * pamu_get_ppaace() - Return the primary PACCE
  78. * @liodn: liodn PAACT index for desired PAACE
  79. *
  80. * Returns the ppace pointer upon success else return
  81. * null.
  82. */
  83. static struct paace *pamu_get_ppaace(int liodn)
  84. {
  85. if (!ppaact || liodn >= PAACE_NUMBER_ENTRIES) {
  86. pr_debug("PPAACT doesn't exist\n");
  87. return NULL;
  88. }
  89. return &ppaact[liodn];
  90. }
  91. /**
  92. * pamu_enable_liodn() - Set valid bit of PACCE
  93. * @liodn: liodn PAACT index for desired PAACE
  94. *
  95. * Returns 0 upon success else error code < 0 returned
  96. */
  97. int pamu_enable_liodn(int liodn)
  98. {
  99. struct paace *ppaace;
  100. ppaace = pamu_get_ppaace(liodn);
  101. if (!ppaace) {
  102. pr_debug("Invalid primary paace entry\n");
  103. return -ENOENT;
  104. }
  105. if (!get_bf(ppaace->addr_bitfields, PPAACE_AF_WSE)) {
  106. pr_debug("liodn %d not configured\n", liodn);
  107. return -EINVAL;
  108. }
  109. /* Ensure that all other stores to the ppaace complete first */
  110. mb();
  111. set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_VALID);
  112. mb();
  113. return 0;
  114. }
  115. /**
  116. * pamu_disable_liodn() - Clears valid bit of PACCE
  117. * @liodn: liodn PAACT index for desired PAACE
  118. *
  119. * Returns 0 upon success else error code < 0 returned
  120. */
  121. int pamu_disable_liodn(int liodn)
  122. {
  123. struct paace *ppaace;
  124. ppaace = pamu_get_ppaace(liodn);
  125. if (!ppaace) {
  126. pr_debug("Invalid primary paace entry\n");
  127. return -ENOENT;
  128. }
  129. set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_INVALID);
  130. mb();
  131. return 0;
  132. }
  133. /* Derive the window size encoding for a particular PAACE entry */
  134. static unsigned int map_addrspace_size_to_wse(phys_addr_t addrspace_size)
  135. {
  136. /* Bug if not a power of 2 */
  137. BUG_ON(addrspace_size & (addrspace_size - 1));
  138. /* window size is 2^(WSE+1) bytes */
  139. return fls64(addrspace_size) - 2;
  140. }
  141. /* Derive the PAACE window count encoding for the subwindow count */
  142. static unsigned int map_subwindow_cnt_to_wce(u32 subwindow_cnt)
  143. {
  144. /* window count is 2^(WCE+1) bytes */
  145. return __ffs(subwindow_cnt) - 1;
  146. }
  147. /*
  148. * Set the PAACE type as primary and set the coherency required domain
  149. * attribute
  150. */
  151. static void pamu_init_ppaace(struct paace *ppaace)
  152. {
  153. set_bf(ppaace->addr_bitfields, PAACE_AF_PT, PAACE_PT_PRIMARY);
  154. set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  155. PAACE_M_COHERENCE_REQ);
  156. }
  157. /*
  158. * Set the PAACE type as secondary and set the coherency required domain
  159. * attribute.
  160. */
  161. static void pamu_init_spaace(struct paace *spaace)
  162. {
  163. set_bf(spaace->addr_bitfields, PAACE_AF_PT, PAACE_PT_SECONDARY);
  164. set_bf(spaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  165. PAACE_M_COHERENCE_REQ);
  166. }
  167. /*
  168. * Return the spaace (corresponding to the secondary window index)
  169. * for a particular ppaace.
  170. */
  171. static struct paace *pamu_get_spaace(struct paace *paace, u32 wnum)
  172. {
  173. u32 subwin_cnt;
  174. struct paace *spaace = NULL;
  175. subwin_cnt = 1UL << (get_bf(paace->impl_attr, PAACE_IA_WCE) + 1);
  176. if (wnum < subwin_cnt)
  177. spaace = &spaact[paace->fspi + wnum];
  178. else
  179. pr_debug("secondary paace out of bounds\n");
  180. return spaace;
  181. }
  182. /**
  183. * pamu_get_fspi_and_allocate() - Allocates fspi index and reserves subwindows
  184. * required for primary PAACE in the secondary
  185. * PAACE table.
  186. * @subwin_cnt: Number of subwindows to be reserved.
  187. *
  188. * A PPAACE entry may have a number of associated subwindows. A subwindow
  189. * corresponds to a SPAACE entry in the SPAACT table. Each PAACE entry stores
  190. * the index (fspi) of the first SPAACE entry in the SPAACT table. This
  191. * function returns the index of the first SPAACE entry. The remaining
  192. * SPAACE entries are reserved contiguously from that index.
  193. *
  194. * Returns a valid fspi index in the range of 0 - SPAACE_NUMBER_ENTRIES on success.
  195. * If no SPAACE entry is available or the allocator can not reserve the required
  196. * number of contiguous entries function returns ULONG_MAX indicating a failure.
  197. *
  198. */
  199. static unsigned long pamu_get_fspi_and_allocate(u32 subwin_cnt)
  200. {
  201. unsigned long spaace_addr;
  202. spaace_addr = gen_pool_alloc(spaace_pool, subwin_cnt * sizeof(struct paace));
  203. if (!spaace_addr)
  204. return ULONG_MAX;
  205. return (spaace_addr - (unsigned long)spaact) / (sizeof(struct paace));
  206. }
  207. /* Release the subwindows reserved for a particular LIODN */
  208. void pamu_free_subwins(int liodn)
  209. {
  210. struct paace *ppaace;
  211. u32 subwin_cnt, size;
  212. ppaace = pamu_get_ppaace(liodn);
  213. if (!ppaace) {
  214. pr_debug("Invalid liodn entry\n");
  215. return;
  216. }
  217. if (get_bf(ppaace->addr_bitfields, PPAACE_AF_MW)) {
  218. subwin_cnt = 1UL << (get_bf(ppaace->impl_attr, PAACE_IA_WCE) + 1);
  219. size = (subwin_cnt - 1) * sizeof(struct paace);
  220. gen_pool_free(spaace_pool, (unsigned long)&spaact[ppaace->fspi], size);
  221. set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0);
  222. }
  223. }
  224. /*
  225. * Function used for updating stash destination for the coressponding
  226. * LIODN.
  227. */
  228. int pamu_update_paace_stash(int liodn, u32 subwin, u32 value)
  229. {
  230. struct paace *paace;
  231. paace = pamu_get_ppaace(liodn);
  232. if (!paace) {
  233. pr_debug("Invalid liodn entry\n");
  234. return -ENOENT;
  235. }
  236. if (subwin) {
  237. paace = pamu_get_spaace(paace, subwin - 1);
  238. if (!paace)
  239. return -ENOENT;
  240. }
  241. set_bf(paace->impl_attr, PAACE_IA_CID, value);
  242. mb();
  243. return 0;
  244. }
  245. /* Disable a subwindow corresponding to the LIODN */
  246. int pamu_disable_spaace(int liodn, u32 subwin)
  247. {
  248. struct paace *paace;
  249. paace = pamu_get_ppaace(liodn);
  250. if (!paace) {
  251. pr_debug("Invalid liodn entry\n");
  252. return -ENOENT;
  253. }
  254. if (subwin) {
  255. paace = pamu_get_spaace(paace, subwin - 1);
  256. if (!paace)
  257. return -ENOENT;
  258. set_bf(paace->addr_bitfields, PAACE_AF_V, PAACE_V_INVALID);
  259. } else {
  260. set_bf(paace->addr_bitfields, PAACE_AF_AP,
  261. PAACE_AP_PERMS_DENIED);
  262. }
  263. mb();
  264. return 0;
  265. }
  266. /**
  267. * pamu_config_paace() - Sets up PPAACE entry for specified liodn
  268. *
  269. * @liodn: Logical IO device number
  270. * @win_addr: starting address of DSA window
  271. * @win-size: size of DSA window
  272. * @omi: Operation mapping index -- if ~omi == 0 then omi not defined
  273. * @rpn: real (true physical) page number
  274. * @stashid: cache stash id for associated cpu -- if ~stashid == 0 then
  275. * stashid not defined
  276. * @snoopid: snoop id for hardware coherency -- if ~snoopid == 0 then
  277. * snoopid not defined
  278. * @subwin_cnt: number of sub-windows
  279. * @prot: window permissions
  280. *
  281. * Returns 0 upon success else error code < 0 returned
  282. */
  283. int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size,
  284. u32 omi, unsigned long rpn, u32 snoopid, u32 stashid,
  285. u32 subwin_cnt, int prot)
  286. {
  287. struct paace *ppaace;
  288. unsigned long fspi;
  289. if ((win_size & (win_size - 1)) || win_size < PAMU_PAGE_SIZE) {
  290. pr_debug("window size too small or not a power of two %pa\n",
  291. &win_size);
  292. return -EINVAL;
  293. }
  294. if (win_addr & (win_size - 1)) {
  295. pr_debug("window address is not aligned with window size\n");
  296. return -EINVAL;
  297. }
  298. ppaace = pamu_get_ppaace(liodn);
  299. if (!ppaace)
  300. return -ENOENT;
  301. /* window size is 2^(WSE+1) bytes */
  302. set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE,
  303. map_addrspace_size_to_wse(win_size));
  304. pamu_init_ppaace(ppaace);
  305. ppaace->wbah = win_addr >> (PAMU_PAGE_SHIFT + 20);
  306. set_bf(ppaace->addr_bitfields, PPAACE_AF_WBAL,
  307. (win_addr >> PAMU_PAGE_SHIFT));
  308. /* set up operation mapping if it's configured */
  309. if (omi < OME_NUMBER_ENTRIES) {
  310. set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  311. ppaace->op_encode.index_ot.omi = omi;
  312. } else if (~omi != 0) {
  313. pr_debug("bad operation mapping index: %d\n", omi);
  314. return -EINVAL;
  315. }
  316. /* configure stash id */
  317. if (~stashid != 0)
  318. set_bf(ppaace->impl_attr, PAACE_IA_CID, stashid);
  319. /* configure snoop id */
  320. if (~snoopid != 0)
  321. ppaace->domain_attr.to_host.snpid = snoopid;
  322. if (subwin_cnt) {
  323. /* The first entry is in the primary PAACE instead */
  324. fspi = pamu_get_fspi_and_allocate(subwin_cnt - 1);
  325. if (fspi == ULONG_MAX) {
  326. pr_debug("spaace indexes exhausted\n");
  327. return -EINVAL;
  328. }
  329. /* window count is 2^(WCE+1) bytes */
  330. set_bf(ppaace->impl_attr, PAACE_IA_WCE,
  331. map_subwindow_cnt_to_wce(subwin_cnt));
  332. set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0x1);
  333. ppaace->fspi = fspi;
  334. } else {
  335. set_bf(ppaace->impl_attr, PAACE_IA_ATM, PAACE_ATM_WINDOW_XLATE);
  336. ppaace->twbah = rpn >> 20;
  337. set_bf(ppaace->win_bitfields, PAACE_WIN_TWBAL, rpn);
  338. set_bf(ppaace->addr_bitfields, PAACE_AF_AP, prot);
  339. set_bf(ppaace->impl_attr, PAACE_IA_WCE, 0);
  340. set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0);
  341. }
  342. mb();
  343. return 0;
  344. }
  345. /**
  346. * pamu_config_spaace() - Sets up SPAACE entry for specified subwindow
  347. *
  348. * @liodn: Logical IO device number
  349. * @subwin_cnt: number of sub-windows associated with dma-window
  350. * @subwin: subwindow index
  351. * @subwin_size: size of subwindow
  352. * @omi: Operation mapping index
  353. * @rpn: real (true physical) page number
  354. * @snoopid: snoop id for hardware coherency -- if ~snoopid == 0 then
  355. * snoopid not defined
  356. * @stashid: cache stash id for associated cpu
  357. * @enable: enable/disable subwindow after reconfiguration
  358. * @prot: sub window permissions
  359. *
  360. * Returns 0 upon success else error code < 0 returned
  361. */
  362. int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin,
  363. phys_addr_t subwin_size, u32 omi, unsigned long rpn,
  364. u32 snoopid, u32 stashid, int enable, int prot)
  365. {
  366. struct paace *paace;
  367. /* setup sub-windows */
  368. if (!subwin_cnt) {
  369. pr_debug("Invalid subwindow count\n");
  370. return -EINVAL;
  371. }
  372. paace = pamu_get_ppaace(liodn);
  373. if (subwin > 0 && subwin < subwin_cnt && paace) {
  374. paace = pamu_get_spaace(paace, subwin - 1);
  375. if (paace && !(paace->addr_bitfields & PAACE_V_VALID)) {
  376. pamu_init_spaace(paace);
  377. set_bf(paace->addr_bitfields, SPAACE_AF_LIODN, liodn);
  378. }
  379. }
  380. if (!paace) {
  381. pr_debug("Invalid liodn entry\n");
  382. return -ENOENT;
  383. }
  384. if ((subwin_size & (subwin_size - 1)) || subwin_size < PAMU_PAGE_SIZE) {
  385. pr_debug("subwindow size out of range, or not a power of 2\n");
  386. return -EINVAL;
  387. }
  388. if (rpn == ULONG_MAX) {
  389. pr_debug("real page number out of range\n");
  390. return -EINVAL;
  391. }
  392. /* window size is 2^(WSE+1) bytes */
  393. set_bf(paace->win_bitfields, PAACE_WIN_SWSE,
  394. map_addrspace_size_to_wse(subwin_size));
  395. set_bf(paace->impl_attr, PAACE_IA_ATM, PAACE_ATM_WINDOW_XLATE);
  396. paace->twbah = rpn >> 20;
  397. set_bf(paace->win_bitfields, PAACE_WIN_TWBAL, rpn);
  398. set_bf(paace->addr_bitfields, PAACE_AF_AP, prot);
  399. /* configure snoop id */
  400. if (~snoopid != 0)
  401. paace->domain_attr.to_host.snpid = snoopid;
  402. /* set up operation mapping if it's configured */
  403. if (omi < OME_NUMBER_ENTRIES) {
  404. set_bf(paace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  405. paace->op_encode.index_ot.omi = omi;
  406. } else if (~omi != 0) {
  407. pr_debug("bad operation mapping index: %d\n", omi);
  408. return -EINVAL;
  409. }
  410. if (~stashid != 0)
  411. set_bf(paace->impl_attr, PAACE_IA_CID, stashid);
  412. smp_wmb();
  413. if (enable)
  414. set_bf(paace->addr_bitfields, PAACE_AF_V, PAACE_V_VALID);
  415. mb();
  416. return 0;
  417. }
  418. /**
  419. * get_ome_index() - Returns the index in the operation mapping table
  420. * for device.
  421. * @*omi_index: pointer for storing the index value
  422. *
  423. */
  424. void get_ome_index(u32 *omi_index, struct device *dev)
  425. {
  426. if (of_device_is_compatible(dev->of_node, "fsl,qman-portal"))
  427. *omi_index = OMI_QMAN;
  428. if (of_device_is_compatible(dev->of_node, "fsl,qman"))
  429. *omi_index = OMI_QMAN_PRIV;
  430. }
  431. /**
  432. * get_stash_id - Returns stash destination id corresponding to a
  433. * cache type and vcpu.
  434. * @stash_dest_hint: L1, L2 or L3
  435. * @vcpu: vpcu target for a particular cache type.
  436. *
  437. * Returs stash on success or ~(u32)0 on failure.
  438. *
  439. */
  440. u32 get_stash_id(u32 stash_dest_hint, u32 vcpu)
  441. {
  442. const u32 *prop;
  443. struct device_node *node;
  444. u32 cache_level;
  445. int len, found = 0;
  446. int i;
  447. /* Fastpath, exit early if L3/CPC cache is target for stashing */
  448. if (stash_dest_hint == PAMU_ATTR_CACHE_L3) {
  449. node = of_find_matching_node(NULL, l3_device_ids);
  450. if (node) {
  451. prop = of_get_property(node, "cache-stash-id", NULL);
  452. if (!prop) {
  453. pr_debug("missing cache-stash-id at %pOF\n",
  454. node);
  455. of_node_put(node);
  456. return ~(u32)0;
  457. }
  458. of_node_put(node);
  459. return be32_to_cpup(prop);
  460. }
  461. return ~(u32)0;
  462. }
  463. for_each_node_by_type(node, "cpu") {
  464. prop = of_get_property(node, "reg", &len);
  465. for (i = 0; i < len / sizeof(u32); i++) {
  466. if (be32_to_cpup(&prop[i]) == vcpu) {
  467. found = 1;
  468. goto found_cpu_node;
  469. }
  470. }
  471. }
  472. found_cpu_node:
  473. /* find the hwnode that represents the cache */
  474. for (cache_level = PAMU_ATTR_CACHE_L1; (cache_level < PAMU_ATTR_CACHE_L3) && found; cache_level++) {
  475. if (stash_dest_hint == cache_level) {
  476. prop = of_get_property(node, "cache-stash-id", NULL);
  477. if (!prop) {
  478. pr_debug("missing cache-stash-id at %pOF\n",
  479. node);
  480. of_node_put(node);
  481. return ~(u32)0;
  482. }
  483. of_node_put(node);
  484. return be32_to_cpup(prop);
  485. }
  486. prop = of_get_property(node, "next-level-cache", NULL);
  487. if (!prop) {
  488. pr_debug("can't find next-level-cache at %pOF\n", node);
  489. of_node_put(node);
  490. return ~(u32)0; /* can't traverse any further */
  491. }
  492. of_node_put(node);
  493. /* advance to next node in cache hierarchy */
  494. node = of_find_node_by_phandle(*prop);
  495. if (!node) {
  496. pr_debug("Invalid node for cache hierarchy\n");
  497. return ~(u32)0;
  498. }
  499. }
  500. pr_debug("stash dest not found for %d on vcpu %d\n",
  501. stash_dest_hint, vcpu);
  502. return ~(u32)0;
  503. }
  504. /* Identify if the PAACT table entry belongs to QMAN, BMAN or QMAN Portal */
  505. #define QMAN_PAACE 1
  506. #define QMAN_PORTAL_PAACE 2
  507. #define BMAN_PAACE 3
  508. /**
  509. * Setup operation mapping and stash destinations for QMAN and QMAN portal.
  510. * Memory accesses to QMAN and BMAN private memory need not be coherent, so
  511. * clear the PAACE entry coherency attribute for them.
  512. */
  513. static void setup_qbman_paace(struct paace *ppaace, int paace_type)
  514. {
  515. switch (paace_type) {
  516. case QMAN_PAACE:
  517. set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  518. ppaace->op_encode.index_ot.omi = OMI_QMAN_PRIV;
  519. /* setup QMAN Private data stashing for the L3 cache */
  520. set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0));
  521. set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  522. 0);
  523. break;
  524. case QMAN_PORTAL_PAACE:
  525. set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  526. ppaace->op_encode.index_ot.omi = OMI_QMAN;
  527. /* Set DQRR and Frame stashing for the L3 cache */
  528. set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0));
  529. break;
  530. case BMAN_PAACE:
  531. set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  532. 0);
  533. break;
  534. }
  535. }
  536. /**
  537. * Setup the operation mapping table for various devices. This is a static
  538. * table where each table index corresponds to a particular device. PAMU uses
  539. * this table to translate device transaction to appropriate corenet
  540. * transaction.
  541. */
  542. static void setup_omt(struct ome *omt)
  543. {
  544. struct ome *ome;
  545. /* Configure OMI_QMAN */
  546. ome = &omt[OMI_QMAN];
  547. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READ;
  548. ome->moe[IOE_EREAD0_IDX] = EOE_VALID | EOE_RSA;
  549. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  550. ome->moe[IOE_EWRITE0_IDX] = EOE_VALID | EOE_WWSAO;
  551. ome->moe[IOE_DIRECT0_IDX] = EOE_VALID | EOE_LDEC;
  552. ome->moe[IOE_DIRECT1_IDX] = EOE_VALID | EOE_LDECPE;
  553. /* Configure OMI_FMAN */
  554. ome = &omt[OMI_FMAN];
  555. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READI;
  556. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  557. /* Configure OMI_QMAN private */
  558. ome = &omt[OMI_QMAN_PRIV];
  559. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READ;
  560. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  561. ome->moe[IOE_EREAD0_IDX] = EOE_VALID | EOE_RSA;
  562. ome->moe[IOE_EWRITE0_IDX] = EOE_VALID | EOE_WWSA;
  563. /* Configure OMI_CAAM */
  564. ome = &omt[OMI_CAAM];
  565. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READI;
  566. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  567. }
  568. /*
  569. * Get the maximum number of PAACT table entries
  570. * and subwindows supported by PAMU
  571. */
  572. static void get_pamu_cap_values(unsigned long pamu_reg_base)
  573. {
  574. u32 pc_val;
  575. pc_val = in_be32((u32 *)(pamu_reg_base + PAMU_PC3));
  576. /* Maximum number of subwindows per liodn */
  577. max_subwindow_count = 1 << (1 + PAMU_PC3_MWCE(pc_val));
  578. }
  579. /* Setup PAMU registers pointing to PAACT, SPAACT and OMT */
  580. static int setup_one_pamu(unsigned long pamu_reg_base, unsigned long pamu_reg_size,
  581. phys_addr_t ppaact_phys, phys_addr_t spaact_phys,
  582. phys_addr_t omt_phys)
  583. {
  584. u32 *pc;
  585. struct pamu_mmap_regs *pamu_regs;
  586. pc = (u32 *) (pamu_reg_base + PAMU_PC);
  587. pamu_regs = (struct pamu_mmap_regs *)
  588. (pamu_reg_base + PAMU_MMAP_REGS_BASE);
  589. /* set up pointers to corenet control blocks */
  590. out_be32(&pamu_regs->ppbah, upper_32_bits(ppaact_phys));
  591. out_be32(&pamu_regs->ppbal, lower_32_bits(ppaact_phys));
  592. ppaact_phys = ppaact_phys + PAACT_SIZE;
  593. out_be32(&pamu_regs->pplah, upper_32_bits(ppaact_phys));
  594. out_be32(&pamu_regs->pplal, lower_32_bits(ppaact_phys));
  595. out_be32(&pamu_regs->spbah, upper_32_bits(spaact_phys));
  596. out_be32(&pamu_regs->spbal, lower_32_bits(spaact_phys));
  597. spaact_phys = spaact_phys + SPAACT_SIZE;
  598. out_be32(&pamu_regs->splah, upper_32_bits(spaact_phys));
  599. out_be32(&pamu_regs->splal, lower_32_bits(spaact_phys));
  600. out_be32(&pamu_regs->obah, upper_32_bits(omt_phys));
  601. out_be32(&pamu_regs->obal, lower_32_bits(omt_phys));
  602. omt_phys = omt_phys + OMT_SIZE;
  603. out_be32(&pamu_regs->olah, upper_32_bits(omt_phys));
  604. out_be32(&pamu_regs->olal, lower_32_bits(omt_phys));
  605. /*
  606. * set PAMU enable bit,
  607. * allow ppaact & omt to be cached
  608. * & enable PAMU access violation interrupts.
  609. */
  610. out_be32((u32 *)(pamu_reg_base + PAMU_PICS),
  611. PAMU_ACCESS_VIOLATION_ENABLE);
  612. out_be32(pc, PAMU_PC_PE | PAMU_PC_OCE | PAMU_PC_SPCC | PAMU_PC_PPCC);
  613. return 0;
  614. }
  615. /* Enable all device LIODNS */
  616. static void setup_liodns(void)
  617. {
  618. int i, len;
  619. struct paace *ppaace;
  620. struct device_node *node = NULL;
  621. const u32 *prop;
  622. for_each_node_with_property(node, "fsl,liodn") {
  623. prop = of_get_property(node, "fsl,liodn", &len);
  624. for (i = 0; i < len / sizeof(u32); i++) {
  625. int liodn;
  626. liodn = be32_to_cpup(&prop[i]);
  627. if (liodn >= PAACE_NUMBER_ENTRIES) {
  628. pr_debug("Invalid LIODN value %d\n", liodn);
  629. continue;
  630. }
  631. ppaace = pamu_get_ppaace(liodn);
  632. pamu_init_ppaace(ppaace);
  633. /* window size is 2^(WSE+1) bytes */
  634. set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE, 35);
  635. ppaace->wbah = 0;
  636. set_bf(ppaace->addr_bitfields, PPAACE_AF_WBAL, 0);
  637. set_bf(ppaace->impl_attr, PAACE_IA_ATM,
  638. PAACE_ATM_NO_XLATE);
  639. set_bf(ppaace->addr_bitfields, PAACE_AF_AP,
  640. PAACE_AP_PERMS_ALL);
  641. if (of_device_is_compatible(node, "fsl,qman-portal"))
  642. setup_qbman_paace(ppaace, QMAN_PORTAL_PAACE);
  643. if (of_device_is_compatible(node, "fsl,qman"))
  644. setup_qbman_paace(ppaace, QMAN_PAACE);
  645. if (of_device_is_compatible(node, "fsl,bman"))
  646. setup_qbman_paace(ppaace, BMAN_PAACE);
  647. mb();
  648. pamu_enable_liodn(liodn);
  649. }
  650. }
  651. }
  652. static irqreturn_t pamu_av_isr(int irq, void *arg)
  653. {
  654. struct pamu_isr_data *data = arg;
  655. phys_addr_t phys;
  656. unsigned int i, j, ret;
  657. pr_emerg("access violation interrupt\n");
  658. for (i = 0; i < data->count; i++) {
  659. void __iomem *p = data->pamu_reg_base + i * PAMU_OFFSET;
  660. u32 pics = in_be32(p + PAMU_PICS);
  661. if (pics & PAMU_ACCESS_VIOLATION_STAT) {
  662. u32 avs1 = in_be32(p + PAMU_AVS1);
  663. struct paace *paace;
  664. pr_emerg("POES1=%08x\n", in_be32(p + PAMU_POES1));
  665. pr_emerg("POES2=%08x\n", in_be32(p + PAMU_POES2));
  666. pr_emerg("AVS1=%08x\n", avs1);
  667. pr_emerg("AVS2=%08x\n", in_be32(p + PAMU_AVS2));
  668. pr_emerg("AVA=%016llx\n",
  669. make64(in_be32(p + PAMU_AVAH),
  670. in_be32(p + PAMU_AVAL)));
  671. pr_emerg("UDAD=%08x\n", in_be32(p + PAMU_UDAD));
  672. pr_emerg("POEA=%016llx\n",
  673. make64(in_be32(p + PAMU_POEAH),
  674. in_be32(p + PAMU_POEAL)));
  675. phys = make64(in_be32(p + PAMU_POEAH),
  676. in_be32(p + PAMU_POEAL));
  677. /* Assume that POEA points to a PAACE */
  678. if (phys) {
  679. u32 *paace = phys_to_virt(phys);
  680. /* Only the first four words are relevant */
  681. for (j = 0; j < 4; j++)
  682. pr_emerg("PAACE[%u]=%08x\n",
  683. j, in_be32(paace + j));
  684. }
  685. /* clear access violation condition */
  686. out_be32(p + PAMU_AVS1, avs1 & PAMU_AV_MASK);
  687. paace = pamu_get_ppaace(avs1 >> PAMU_AVS1_LIODN_SHIFT);
  688. BUG_ON(!paace);
  689. /* check if we got a violation for a disabled LIODN */
  690. if (!get_bf(paace->addr_bitfields, PAACE_AF_V)) {
  691. /*
  692. * As per hardware erratum A-003638, access
  693. * violation can be reported for a disabled
  694. * LIODN. If we hit that condition, disable
  695. * access violation reporting.
  696. */
  697. pics &= ~PAMU_ACCESS_VIOLATION_ENABLE;
  698. } else {
  699. /* Disable the LIODN */
  700. ret = pamu_disable_liodn(avs1 >> PAMU_AVS1_LIODN_SHIFT);
  701. BUG_ON(ret);
  702. pr_emerg("Disabling liodn %x\n",
  703. avs1 >> PAMU_AVS1_LIODN_SHIFT);
  704. }
  705. out_be32((p + PAMU_PICS), pics);
  706. }
  707. }
  708. return IRQ_HANDLED;
  709. }
  710. #define LAWAR_EN 0x80000000
  711. #define LAWAR_TARGET_MASK 0x0FF00000
  712. #define LAWAR_TARGET_SHIFT 20
  713. #define LAWAR_SIZE_MASK 0x0000003F
  714. #define LAWAR_CSDID_MASK 0x000FF000
  715. #define LAWAR_CSDID_SHIFT 12
  716. #define LAW_SIZE_4K 0xb
  717. struct ccsr_law {
  718. u32 lawbarh; /* LAWn base address high */
  719. u32 lawbarl; /* LAWn base address low */
  720. u32 lawar; /* LAWn attributes */
  721. u32 reserved;
  722. };
  723. /*
  724. * Create a coherence subdomain for a given memory block.
  725. */
  726. static int create_csd(phys_addr_t phys, size_t size, u32 csd_port_id)
  727. {
  728. struct device_node *np;
  729. const __be32 *iprop;
  730. void __iomem *lac = NULL; /* Local Access Control registers */
  731. struct ccsr_law __iomem *law;
  732. void __iomem *ccm = NULL;
  733. u32 __iomem *csdids;
  734. unsigned int i, num_laws, num_csds;
  735. u32 law_target = 0;
  736. u32 csd_id = 0;
  737. int ret = 0;
  738. np = of_find_compatible_node(NULL, NULL, "fsl,corenet-law");
  739. if (!np)
  740. return -ENODEV;
  741. iprop = of_get_property(np, "fsl,num-laws", NULL);
  742. if (!iprop) {
  743. ret = -ENODEV;
  744. goto error;
  745. }
  746. num_laws = be32_to_cpup(iprop);
  747. if (!num_laws) {
  748. ret = -ENODEV;
  749. goto error;
  750. }
  751. lac = of_iomap(np, 0);
  752. if (!lac) {
  753. ret = -ENODEV;
  754. goto error;
  755. }
  756. /* LAW registers are at offset 0xC00 */
  757. law = lac + 0xC00;
  758. of_node_put(np);
  759. np = of_find_compatible_node(NULL, NULL, "fsl,corenet-cf");
  760. if (!np) {
  761. ret = -ENODEV;
  762. goto error;
  763. }
  764. iprop = of_get_property(np, "fsl,ccf-num-csdids", NULL);
  765. if (!iprop) {
  766. ret = -ENODEV;
  767. goto error;
  768. }
  769. num_csds = be32_to_cpup(iprop);
  770. if (!num_csds) {
  771. ret = -ENODEV;
  772. goto error;
  773. }
  774. ccm = of_iomap(np, 0);
  775. if (!ccm) {
  776. ret = -ENOMEM;
  777. goto error;
  778. }
  779. /* The undocumented CSDID registers are at offset 0x600 */
  780. csdids = ccm + 0x600;
  781. of_node_put(np);
  782. np = NULL;
  783. /* Find an unused coherence subdomain ID */
  784. for (csd_id = 0; csd_id < num_csds; csd_id++) {
  785. if (!csdids[csd_id])
  786. break;
  787. }
  788. /* Store the Port ID in the (undocumented) proper CIDMRxx register */
  789. csdids[csd_id] = csd_port_id;
  790. /* Find the DDR LAW that maps to our buffer. */
  791. for (i = 0; i < num_laws; i++) {
  792. if (law[i].lawar & LAWAR_EN) {
  793. phys_addr_t law_start, law_end;
  794. law_start = make64(law[i].lawbarh, law[i].lawbarl);
  795. law_end = law_start +
  796. (2ULL << (law[i].lawar & LAWAR_SIZE_MASK));
  797. if (law_start <= phys && phys < law_end) {
  798. law_target = law[i].lawar & LAWAR_TARGET_MASK;
  799. break;
  800. }
  801. }
  802. }
  803. if (i == 0 || i == num_laws) {
  804. /* This should never happen */
  805. ret = -ENOENT;
  806. goto error;
  807. }
  808. /* Find a free LAW entry */
  809. while (law[--i].lawar & LAWAR_EN) {
  810. if (i == 0) {
  811. /* No higher priority LAW slots available */
  812. ret = -ENOENT;
  813. goto error;
  814. }
  815. }
  816. law[i].lawbarh = upper_32_bits(phys);
  817. law[i].lawbarl = lower_32_bits(phys);
  818. wmb();
  819. law[i].lawar = LAWAR_EN | law_target | (csd_id << LAWAR_CSDID_SHIFT) |
  820. (LAW_SIZE_4K + get_order(size));
  821. wmb();
  822. error:
  823. if (ccm)
  824. iounmap(ccm);
  825. if (lac)
  826. iounmap(lac);
  827. if (np)
  828. of_node_put(np);
  829. return ret;
  830. }
  831. /*
  832. * Table of SVRs and the corresponding PORT_ID values. Port ID corresponds to a
  833. * bit map of snoopers for a given range of memory mapped by a LAW.
  834. *
  835. * All future CoreNet-enabled SOCs will have this erratum(A-004510) fixed, so this
  836. * table should never need to be updated. SVRs are guaranteed to be unique, so
  837. * there is no worry that a future SOC will inadvertently have one of these
  838. * values.
  839. */
  840. static const struct {
  841. u32 svr;
  842. u32 port_id;
  843. } port_id_map[] = {
  844. {(SVR_P2040 << 8) | 0x10, 0xFF000000}, /* P2040 1.0 */
  845. {(SVR_P2040 << 8) | 0x11, 0xFF000000}, /* P2040 1.1 */
  846. {(SVR_P2041 << 8) | 0x10, 0xFF000000}, /* P2041 1.0 */
  847. {(SVR_P2041 << 8) | 0x11, 0xFF000000}, /* P2041 1.1 */
  848. {(SVR_P3041 << 8) | 0x10, 0xFF000000}, /* P3041 1.0 */
  849. {(SVR_P3041 << 8) | 0x11, 0xFF000000}, /* P3041 1.1 */
  850. {(SVR_P4040 << 8) | 0x20, 0xFFF80000}, /* P4040 2.0 */
  851. {(SVR_P4080 << 8) | 0x20, 0xFFF80000}, /* P4080 2.0 */
  852. {(SVR_P5010 << 8) | 0x10, 0xFC000000}, /* P5010 1.0 */
  853. {(SVR_P5010 << 8) | 0x20, 0xFC000000}, /* P5010 2.0 */
  854. {(SVR_P5020 << 8) | 0x10, 0xFC000000}, /* P5020 1.0 */
  855. {(SVR_P5021 << 8) | 0x10, 0xFF800000}, /* P5021 1.0 */
  856. {(SVR_P5040 << 8) | 0x10, 0xFF800000}, /* P5040 1.0 */
  857. };
  858. #define SVR_SECURITY 0x80000 /* The Security (E) bit */
  859. static int fsl_pamu_probe(struct platform_device *pdev)
  860. {
  861. struct device *dev = &pdev->dev;
  862. void __iomem *pamu_regs = NULL;
  863. struct ccsr_guts __iomem *guts_regs = NULL;
  864. u32 pamubypenr, pamu_counter;
  865. unsigned long pamu_reg_off;
  866. unsigned long pamu_reg_base;
  867. struct pamu_isr_data *data = NULL;
  868. struct device_node *guts_node;
  869. u64 size;
  870. struct page *p;
  871. int ret = 0;
  872. int irq;
  873. phys_addr_t ppaact_phys;
  874. phys_addr_t spaact_phys;
  875. struct ome *omt;
  876. phys_addr_t omt_phys;
  877. size_t mem_size = 0;
  878. unsigned int order = 0;
  879. u32 csd_port_id = 0;
  880. unsigned i;
  881. /*
  882. * enumerate all PAMUs and allocate and setup PAMU tables
  883. * for each of them,
  884. * NOTE : All PAMUs share the same LIODN tables.
  885. */
  886. if (WARN_ON(probed))
  887. return -EBUSY;
  888. pamu_regs = of_iomap(dev->of_node, 0);
  889. if (!pamu_regs) {
  890. dev_err(dev, "ioremap of PAMU node failed\n");
  891. return -ENOMEM;
  892. }
  893. of_get_address(dev->of_node, 0, &size, NULL);
  894. irq = irq_of_parse_and_map(dev->of_node, 0);
  895. if (irq == NO_IRQ) {
  896. dev_warn(dev, "no interrupts listed in PAMU node\n");
  897. goto error;
  898. }
  899. data = kzalloc(sizeof(*data), GFP_KERNEL);
  900. if (!data) {
  901. ret = -ENOMEM;
  902. goto error;
  903. }
  904. data->pamu_reg_base = pamu_regs;
  905. data->count = size / PAMU_OFFSET;
  906. /* The ISR needs access to the regs, so we won't iounmap them */
  907. ret = request_irq(irq, pamu_av_isr, 0, "pamu", data);
  908. if (ret < 0) {
  909. dev_err(dev, "error %i installing ISR for irq %i\n", ret, irq);
  910. goto error;
  911. }
  912. guts_node = of_find_matching_node(NULL, guts_device_ids);
  913. if (!guts_node) {
  914. dev_err(dev, "could not find GUTS node %pOF\n", dev->of_node);
  915. ret = -ENODEV;
  916. goto error;
  917. }
  918. guts_regs = of_iomap(guts_node, 0);
  919. of_node_put(guts_node);
  920. if (!guts_regs) {
  921. dev_err(dev, "ioremap of GUTS node failed\n");
  922. ret = -ENODEV;
  923. goto error;
  924. }
  925. /* read in the PAMU capability registers */
  926. get_pamu_cap_values((unsigned long)pamu_regs);
  927. /*
  928. * To simplify the allocation of a coherency domain, we allocate the
  929. * PAACT and the OMT in the same memory buffer. Unfortunately, this
  930. * wastes more memory compared to allocating the buffers separately.
  931. */
  932. /* Determine how much memory we need */
  933. mem_size = (PAGE_SIZE << get_order(PAACT_SIZE)) +
  934. (PAGE_SIZE << get_order(SPAACT_SIZE)) +
  935. (PAGE_SIZE << get_order(OMT_SIZE));
  936. order = get_order(mem_size);
  937. p = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
  938. if (!p) {
  939. dev_err(dev, "unable to allocate PAACT/SPAACT/OMT block\n");
  940. ret = -ENOMEM;
  941. goto error;
  942. }
  943. ppaact = page_address(p);
  944. ppaact_phys = page_to_phys(p);
  945. /* Make sure the memory is naturally aligned */
  946. if (ppaact_phys & ((PAGE_SIZE << order) - 1)) {
  947. dev_err(dev, "PAACT/OMT block is unaligned\n");
  948. ret = -ENOMEM;
  949. goto error;
  950. }
  951. spaact = (void *)ppaact + (PAGE_SIZE << get_order(PAACT_SIZE));
  952. omt = (void *)spaact + (PAGE_SIZE << get_order(SPAACT_SIZE));
  953. dev_dbg(dev, "ppaact virt=%p phys=%pa\n", ppaact, &ppaact_phys);
  954. /* Check to see if we need to implement the work-around on this SOC */
  955. /* Determine the Port ID for our coherence subdomain */
  956. for (i = 0; i < ARRAY_SIZE(port_id_map); i++) {
  957. if (port_id_map[i].svr == (mfspr(SPRN_SVR) & ~SVR_SECURITY)) {
  958. csd_port_id = port_id_map[i].port_id;
  959. dev_dbg(dev, "found matching SVR %08x\n",
  960. port_id_map[i].svr);
  961. break;
  962. }
  963. }
  964. if (csd_port_id) {
  965. dev_dbg(dev, "creating coherency subdomain at address %pa, size %zu, port id 0x%08x",
  966. &ppaact_phys, mem_size, csd_port_id);
  967. ret = create_csd(ppaact_phys, mem_size, csd_port_id);
  968. if (ret) {
  969. dev_err(dev, "could not create coherence subdomain\n");
  970. return ret;
  971. }
  972. }
  973. spaact_phys = virt_to_phys(spaact);
  974. omt_phys = virt_to_phys(omt);
  975. spaace_pool = gen_pool_create(ilog2(sizeof(struct paace)), -1);
  976. if (!spaace_pool) {
  977. ret = -ENOMEM;
  978. dev_err(dev, "Failed to allocate spaace gen pool\n");
  979. goto error;
  980. }
  981. ret = gen_pool_add(spaace_pool, (unsigned long)spaact, SPAACT_SIZE, -1);
  982. if (ret)
  983. goto error_genpool;
  984. pamubypenr = in_be32(&guts_regs->pamubypenr);
  985. for (pamu_reg_off = 0, pamu_counter = 0x80000000; pamu_reg_off < size;
  986. pamu_reg_off += PAMU_OFFSET, pamu_counter >>= 1) {
  987. pamu_reg_base = (unsigned long)pamu_regs + pamu_reg_off;
  988. setup_one_pamu(pamu_reg_base, pamu_reg_off, ppaact_phys,
  989. spaact_phys, omt_phys);
  990. /* Disable PAMU bypass for this PAMU */
  991. pamubypenr &= ~pamu_counter;
  992. }
  993. setup_omt(omt);
  994. /* Enable all relevant PAMU(s) */
  995. out_be32(&guts_regs->pamubypenr, pamubypenr);
  996. iounmap(guts_regs);
  997. /* Enable DMA for the LIODNs in the device tree */
  998. setup_liodns();
  999. probed = true;
  1000. return 0;
  1001. error_genpool:
  1002. gen_pool_destroy(spaace_pool);
  1003. error:
  1004. if (irq != NO_IRQ)
  1005. free_irq(irq, data);
  1006. if (data) {
  1007. memset(data, 0, sizeof(struct pamu_isr_data));
  1008. kfree(data);
  1009. }
  1010. if (pamu_regs)
  1011. iounmap(pamu_regs);
  1012. if (guts_regs)
  1013. iounmap(guts_regs);
  1014. if (ppaact)
  1015. free_pages((unsigned long)ppaact, order);
  1016. ppaact = NULL;
  1017. return ret;
  1018. }
  1019. static struct platform_driver fsl_of_pamu_driver = {
  1020. .driver = {
  1021. .name = "fsl-of-pamu",
  1022. },
  1023. .probe = fsl_pamu_probe,
  1024. };
  1025. static __init int fsl_pamu_init(void)
  1026. {
  1027. struct platform_device *pdev = NULL;
  1028. struct device_node *np;
  1029. int ret;
  1030. /*
  1031. * The normal OF process calls the probe function at some
  1032. * indeterminate later time, after most drivers have loaded. This is
  1033. * too late for us, because PAMU clients (like the Qman driver)
  1034. * depend on PAMU being initialized early.
  1035. *
  1036. * So instead, we "manually" call our probe function by creating the
  1037. * platform devices ourselves.
  1038. */
  1039. /*
  1040. * We assume that there is only one PAMU node in the device tree. A
  1041. * single PAMU node represents all of the PAMU devices in the SOC
  1042. * already. Everything else already makes that assumption, and the
  1043. * binding for the PAMU nodes doesn't allow for any parent-child
  1044. * relationships anyway. In other words, support for more than one
  1045. * PAMU node would require significant changes to a lot of code.
  1046. */
  1047. np = of_find_compatible_node(NULL, NULL, "fsl,pamu");
  1048. if (!np) {
  1049. pr_err("could not find a PAMU node\n");
  1050. return -ENODEV;
  1051. }
  1052. ret = platform_driver_register(&fsl_of_pamu_driver);
  1053. if (ret) {
  1054. pr_err("could not register driver (err=%i)\n", ret);
  1055. goto error_driver_register;
  1056. }
  1057. pdev = platform_device_alloc("fsl-of-pamu", 0);
  1058. if (!pdev) {
  1059. pr_err("could not allocate device %pOF\n", np);
  1060. ret = -ENOMEM;
  1061. goto error_device_alloc;
  1062. }
  1063. pdev->dev.of_node = of_node_get(np);
  1064. ret = pamu_domain_init();
  1065. if (ret)
  1066. goto error_device_add;
  1067. ret = platform_device_add(pdev);
  1068. if (ret) {
  1069. pr_err("could not add device %pOF (err=%i)\n", np, ret);
  1070. goto error_device_add;
  1071. }
  1072. return 0;
  1073. error_device_add:
  1074. of_node_put(pdev->dev.of_node);
  1075. pdev->dev.of_node = NULL;
  1076. platform_device_put(pdev);
  1077. error_device_alloc:
  1078. platform_driver_unregister(&fsl_of_pamu_driver);
  1079. error_driver_register:
  1080. of_node_put(np);
  1081. return ret;
  1082. }
  1083. arch_initcall(fsl_pamu_init);