fsl_pamu.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  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. /*
  37. * Table for matching compatible strings, for device tree
  38. * guts node, for QorIQ SOCs.
  39. * "fsl,qoriq-device-config-2.0" corresponds to T4 & B4
  40. * SOCs. For the older SOCs "fsl,qoriq-device-config-1.0"
  41. * string would be used.
  42. */
  43. static const struct of_device_id guts_device_ids[] = {
  44. { .compatible = "fsl,qoriq-device-config-1.0", },
  45. { .compatible = "fsl,qoriq-device-config-2.0", },
  46. {}
  47. };
  48. /*
  49. * Table for matching compatible strings, for device tree
  50. * L3 cache controller node.
  51. * "fsl,t4240-l3-cache-controller" corresponds to T4,
  52. * "fsl,b4860-l3-cache-controller" corresponds to B4 &
  53. * "fsl,p4080-l3-cache-controller" corresponds to other,
  54. * SOCs.
  55. */
  56. static const struct of_device_id l3_device_ids[] = {
  57. { .compatible = "fsl,t4240-l3-cache-controller", },
  58. { .compatible = "fsl,b4860-l3-cache-controller", },
  59. { .compatible = "fsl,p4080-l3-cache-controller", },
  60. {}
  61. };
  62. /* maximum subwindows permitted per liodn */
  63. static u32 max_subwindow_count;
  64. /* Pool for fspi allocation */
  65. static struct gen_pool *spaace_pool;
  66. /**
  67. * pamu_get_max_subwin_cnt() - Return the maximum supported
  68. * subwindow count per liodn.
  69. *
  70. */
  71. u32 pamu_get_max_subwin_cnt(void)
  72. {
  73. return max_subwindow_count;
  74. }
  75. /**
  76. * pamu_get_ppaace() - Return the primary PACCE
  77. * @liodn: liodn PAACT index for desired PAACE
  78. *
  79. * Returns the ppace pointer upon success else return
  80. * null.
  81. */
  82. static struct paace *pamu_get_ppaace(int liodn)
  83. {
  84. if (!ppaact || liodn >= PAACE_NUMBER_ENTRIES) {
  85. pr_debug("PPAACT doesn't exist\n");
  86. return NULL;
  87. }
  88. return &ppaact[liodn];
  89. }
  90. /**
  91. * pamu_enable_liodn() - Set valid bit of PACCE
  92. * @liodn: liodn PAACT index for desired PAACE
  93. *
  94. * Returns 0 upon success else error code < 0 returned
  95. */
  96. int pamu_enable_liodn(int liodn)
  97. {
  98. struct paace *ppaace;
  99. ppaace = pamu_get_ppaace(liodn);
  100. if (!ppaace) {
  101. pr_debug("Invalid primary paace entry\n");
  102. return -ENOENT;
  103. }
  104. if (!get_bf(ppaace->addr_bitfields, PPAACE_AF_WSE)) {
  105. pr_debug("liodn %d not configured\n", liodn);
  106. return -EINVAL;
  107. }
  108. /* Ensure that all other stores to the ppaace complete first */
  109. mb();
  110. set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_VALID);
  111. mb();
  112. return 0;
  113. }
  114. /**
  115. * pamu_disable_liodn() - Clears valid bit of PACCE
  116. * @liodn: liodn PAACT index for desired PAACE
  117. *
  118. * Returns 0 upon success else error code < 0 returned
  119. */
  120. int pamu_disable_liodn(int liodn)
  121. {
  122. struct paace *ppaace;
  123. ppaace = pamu_get_ppaace(liodn);
  124. if (!ppaace) {
  125. pr_debug("Invalid primary paace entry\n");
  126. return -ENOENT;
  127. }
  128. set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_INVALID);
  129. mb();
  130. return 0;
  131. }
  132. /* Derive the window size encoding for a particular PAACE entry */
  133. static unsigned int map_addrspace_size_to_wse(phys_addr_t addrspace_size)
  134. {
  135. /* Bug if not a power of 2 */
  136. BUG_ON(addrspace_size & (addrspace_size - 1));
  137. /* window size is 2^(WSE+1) bytes */
  138. return fls64(addrspace_size) - 2;
  139. }
  140. /* Derive the PAACE window count encoding for the subwindow count */
  141. static unsigned int map_subwindow_cnt_to_wce(u32 subwindow_cnt)
  142. {
  143. /* window count is 2^(WCE+1) bytes */
  144. return __ffs(subwindow_cnt) - 1;
  145. }
  146. /*
  147. * Set the PAACE type as primary and set the coherency required domain
  148. * attribute
  149. */
  150. static void pamu_init_ppaace(struct paace *ppaace)
  151. {
  152. set_bf(ppaace->addr_bitfields, PAACE_AF_PT, PAACE_PT_PRIMARY);
  153. set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  154. PAACE_M_COHERENCE_REQ);
  155. }
  156. /*
  157. * Set the PAACE type as secondary and set the coherency required domain
  158. * attribute.
  159. */
  160. static void pamu_init_spaace(struct paace *spaace)
  161. {
  162. set_bf(spaace->addr_bitfields, PAACE_AF_PT, PAACE_PT_SECONDARY);
  163. set_bf(spaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  164. PAACE_M_COHERENCE_REQ);
  165. }
  166. /*
  167. * Return the spaace (corresponding to the secondary window index)
  168. * for a particular ppaace.
  169. */
  170. static struct paace *pamu_get_spaace(struct paace *paace, u32 wnum)
  171. {
  172. u32 subwin_cnt;
  173. struct paace *spaace = NULL;
  174. subwin_cnt = 1UL << (get_bf(paace->impl_attr, PAACE_IA_WCE) + 1);
  175. if (wnum < subwin_cnt)
  176. spaace = &spaact[paace->fspi + wnum];
  177. else
  178. pr_debug("secondary paace out of bounds\n");
  179. return spaace;
  180. }
  181. /**
  182. * pamu_get_fspi_and_allocate() - Allocates fspi index and reserves subwindows
  183. * required for primary PAACE in the secondary
  184. * PAACE table.
  185. * @subwin_cnt: Number of subwindows to be reserved.
  186. *
  187. * A PPAACE entry may have a number of associated subwindows. A subwindow
  188. * corresponds to a SPAACE entry in the SPAACT table. Each PAACE entry stores
  189. * the index (fspi) of the first SPAACE entry in the SPAACT table. This
  190. * function returns the index of the first SPAACE entry. The remaining
  191. * SPAACE entries are reserved contiguously from that index.
  192. *
  193. * Returns a valid fspi index in the range of 0 - SPAACE_NUMBER_ENTRIES on success.
  194. * If no SPAACE entry is available or the allocator can not reserve the required
  195. * number of contiguous entries function returns ULONG_MAX indicating a failure.
  196. *
  197. */
  198. static unsigned long pamu_get_fspi_and_allocate(u32 subwin_cnt)
  199. {
  200. unsigned long spaace_addr;
  201. spaace_addr = gen_pool_alloc(spaace_pool, subwin_cnt * sizeof(struct paace));
  202. if (!spaace_addr)
  203. return ULONG_MAX;
  204. return (spaace_addr - (unsigned long)spaact) / (sizeof(struct paace));
  205. }
  206. /* Release the subwindows reserved for a particular LIODN */
  207. void pamu_free_subwins(int liodn)
  208. {
  209. struct paace *ppaace;
  210. u32 subwin_cnt, size;
  211. ppaace = pamu_get_ppaace(liodn);
  212. if (!ppaace) {
  213. pr_debug("Invalid liodn entry\n");
  214. return;
  215. }
  216. if (get_bf(ppaace->addr_bitfields, PPAACE_AF_MW)) {
  217. subwin_cnt = 1UL << (get_bf(ppaace->impl_attr, PAACE_IA_WCE) + 1);
  218. size = (subwin_cnt - 1) * sizeof(struct paace);
  219. gen_pool_free(spaace_pool, (unsigned long)&spaact[ppaace->fspi], size);
  220. set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0);
  221. }
  222. }
  223. /*
  224. * Function used for updating stash destination for the coressponding
  225. * LIODN.
  226. */
  227. int pamu_update_paace_stash(int liodn, u32 subwin, u32 value)
  228. {
  229. struct paace *paace;
  230. paace = pamu_get_ppaace(liodn);
  231. if (!paace) {
  232. pr_debug("Invalid liodn entry\n");
  233. return -ENOENT;
  234. }
  235. if (subwin) {
  236. paace = pamu_get_spaace(paace, subwin - 1);
  237. if (!paace)
  238. return -ENOENT;
  239. }
  240. set_bf(paace->impl_attr, PAACE_IA_CID, value);
  241. mb();
  242. return 0;
  243. }
  244. /* Disable a subwindow corresponding to the LIODN */
  245. int pamu_disable_spaace(int liodn, u32 subwin)
  246. {
  247. struct paace *paace;
  248. paace = pamu_get_ppaace(liodn);
  249. if (!paace) {
  250. pr_debug("Invalid liodn entry\n");
  251. return -ENOENT;
  252. }
  253. if (subwin) {
  254. paace = pamu_get_spaace(paace, subwin - 1);
  255. if (!paace)
  256. return -ENOENT;
  257. set_bf(paace->addr_bitfields, PAACE_AF_V, PAACE_V_INVALID);
  258. } else {
  259. set_bf(paace->addr_bitfields, PAACE_AF_AP,
  260. PAACE_AP_PERMS_DENIED);
  261. }
  262. mb();
  263. return 0;
  264. }
  265. /**
  266. * pamu_config_paace() - Sets up PPAACE entry for specified liodn
  267. *
  268. * @liodn: Logical IO device number
  269. * @win_addr: starting address of DSA window
  270. * @win-size: size of DSA window
  271. * @omi: Operation mapping index -- if ~omi == 0 then omi not defined
  272. * @rpn: real (true physical) page number
  273. * @stashid: cache stash id for associated cpu -- if ~stashid == 0 then
  274. * stashid not defined
  275. * @snoopid: snoop id for hardware coherency -- if ~snoopid == 0 then
  276. * snoopid not defined
  277. * @subwin_cnt: number of sub-windows
  278. * @prot: window permissions
  279. *
  280. * Returns 0 upon success else error code < 0 returned
  281. */
  282. int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size,
  283. u32 omi, unsigned long rpn, u32 snoopid, u32 stashid,
  284. u32 subwin_cnt, int prot)
  285. {
  286. struct paace *ppaace;
  287. unsigned long fspi;
  288. if ((win_size & (win_size - 1)) || win_size < PAMU_PAGE_SIZE) {
  289. pr_debug("window size too small or not a power of two %pa\n",
  290. &win_size);
  291. return -EINVAL;
  292. }
  293. if (win_addr & (win_size - 1)) {
  294. pr_debug("window address is not aligned with window size\n");
  295. return -EINVAL;
  296. }
  297. ppaace = pamu_get_ppaace(liodn);
  298. if (!ppaace)
  299. return -ENOENT;
  300. /* window size is 2^(WSE+1) bytes */
  301. set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE,
  302. map_addrspace_size_to_wse(win_size));
  303. pamu_init_ppaace(ppaace);
  304. ppaace->wbah = win_addr >> (PAMU_PAGE_SHIFT + 20);
  305. set_bf(ppaace->addr_bitfields, PPAACE_AF_WBAL,
  306. (win_addr >> PAMU_PAGE_SHIFT));
  307. /* set up operation mapping if it's configured */
  308. if (omi < OME_NUMBER_ENTRIES) {
  309. set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  310. ppaace->op_encode.index_ot.omi = omi;
  311. } else if (~omi != 0) {
  312. pr_debug("bad operation mapping index: %d\n", omi);
  313. return -EINVAL;
  314. }
  315. /* configure stash id */
  316. if (~stashid != 0)
  317. set_bf(ppaace->impl_attr, PAACE_IA_CID, stashid);
  318. /* configure snoop id */
  319. if (~snoopid != 0)
  320. ppaace->domain_attr.to_host.snpid = snoopid;
  321. if (subwin_cnt) {
  322. /* The first entry is in the primary PAACE instead */
  323. fspi = pamu_get_fspi_and_allocate(subwin_cnt - 1);
  324. if (fspi == ULONG_MAX) {
  325. pr_debug("spaace indexes exhausted\n");
  326. return -EINVAL;
  327. }
  328. /* window count is 2^(WCE+1) bytes */
  329. set_bf(ppaace->impl_attr, PAACE_IA_WCE,
  330. map_subwindow_cnt_to_wce(subwin_cnt));
  331. set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0x1);
  332. ppaace->fspi = fspi;
  333. } else {
  334. set_bf(ppaace->impl_attr, PAACE_IA_ATM, PAACE_ATM_WINDOW_XLATE);
  335. ppaace->twbah = rpn >> 20;
  336. set_bf(ppaace->win_bitfields, PAACE_WIN_TWBAL, rpn);
  337. set_bf(ppaace->addr_bitfields, PAACE_AF_AP, prot);
  338. set_bf(ppaace->impl_attr, PAACE_IA_WCE, 0);
  339. set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0);
  340. }
  341. mb();
  342. return 0;
  343. }
  344. /**
  345. * pamu_config_spaace() - Sets up SPAACE entry for specified subwindow
  346. *
  347. * @liodn: Logical IO device number
  348. * @subwin_cnt: number of sub-windows associated with dma-window
  349. * @subwin: subwindow index
  350. * @subwin_size: size of subwindow
  351. * @omi: Operation mapping index
  352. * @rpn: real (true physical) page number
  353. * @snoopid: snoop id for hardware coherency -- if ~snoopid == 0 then
  354. * snoopid not defined
  355. * @stashid: cache stash id for associated cpu
  356. * @enable: enable/disable subwindow after reconfiguration
  357. * @prot: sub window permissions
  358. *
  359. * Returns 0 upon success else error code < 0 returned
  360. */
  361. int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin,
  362. phys_addr_t subwin_size, u32 omi, unsigned long rpn,
  363. u32 snoopid, u32 stashid, int enable, int prot)
  364. {
  365. struct paace *paace;
  366. /* setup sub-windows */
  367. if (!subwin_cnt) {
  368. pr_debug("Invalid subwindow count\n");
  369. return -EINVAL;
  370. }
  371. paace = pamu_get_ppaace(liodn);
  372. if (subwin > 0 && subwin < subwin_cnt && paace) {
  373. paace = pamu_get_spaace(paace, subwin - 1);
  374. if (paace && !(paace->addr_bitfields & PAACE_V_VALID)) {
  375. pamu_init_spaace(paace);
  376. set_bf(paace->addr_bitfields, SPAACE_AF_LIODN, liodn);
  377. }
  378. }
  379. if (!paace) {
  380. pr_debug("Invalid liodn entry\n");
  381. return -ENOENT;
  382. }
  383. if ((subwin_size & (subwin_size - 1)) || subwin_size < PAMU_PAGE_SIZE) {
  384. pr_debug("subwindow size out of range, or not a power of 2\n");
  385. return -EINVAL;
  386. }
  387. if (rpn == ULONG_MAX) {
  388. pr_debug("real page number out of range\n");
  389. return -EINVAL;
  390. }
  391. /* window size is 2^(WSE+1) bytes */
  392. set_bf(paace->win_bitfields, PAACE_WIN_SWSE,
  393. map_addrspace_size_to_wse(subwin_size));
  394. set_bf(paace->impl_attr, PAACE_IA_ATM, PAACE_ATM_WINDOW_XLATE);
  395. paace->twbah = rpn >> 20;
  396. set_bf(paace->win_bitfields, PAACE_WIN_TWBAL, rpn);
  397. set_bf(paace->addr_bitfields, PAACE_AF_AP, prot);
  398. /* configure snoop id */
  399. if (~snoopid != 0)
  400. paace->domain_attr.to_host.snpid = snoopid;
  401. /* set up operation mapping if it's configured */
  402. if (omi < OME_NUMBER_ENTRIES) {
  403. set_bf(paace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  404. paace->op_encode.index_ot.omi = omi;
  405. } else if (~omi != 0) {
  406. pr_debug("bad operation mapping index: %d\n", omi);
  407. return -EINVAL;
  408. }
  409. if (~stashid != 0)
  410. set_bf(paace->impl_attr, PAACE_IA_CID, stashid);
  411. smp_wmb();
  412. if (enable)
  413. set_bf(paace->addr_bitfields, PAACE_AF_V, PAACE_V_VALID);
  414. mb();
  415. return 0;
  416. }
  417. /**
  418. * get_ome_index() - Returns the index in the operation mapping table
  419. * for device.
  420. * @*omi_index: pointer for storing the index value
  421. *
  422. */
  423. void get_ome_index(u32 *omi_index, struct device *dev)
  424. {
  425. if (of_device_is_compatible(dev->of_node, "fsl,qman-portal"))
  426. *omi_index = OMI_QMAN;
  427. if (of_device_is_compatible(dev->of_node, "fsl,qman"))
  428. *omi_index = OMI_QMAN_PRIV;
  429. }
  430. /**
  431. * get_stash_id - Returns stash destination id corresponding to a
  432. * cache type and vcpu.
  433. * @stash_dest_hint: L1, L2 or L3
  434. * @vcpu: vpcu target for a particular cache type.
  435. *
  436. * Returs stash on success or ~(u32)0 on failure.
  437. *
  438. */
  439. u32 get_stash_id(u32 stash_dest_hint, u32 vcpu)
  440. {
  441. const u32 *prop;
  442. struct device_node *node;
  443. u32 cache_level;
  444. int len, found = 0;
  445. int i;
  446. /* Fastpath, exit early if L3/CPC cache is target for stashing */
  447. if (stash_dest_hint == PAMU_ATTR_CACHE_L3) {
  448. node = of_find_matching_node(NULL, l3_device_ids);
  449. if (node) {
  450. prop = of_get_property(node, "cache-stash-id", NULL);
  451. if (!prop) {
  452. pr_debug("missing cache-stash-id at %s\n",
  453. node->full_name);
  454. of_node_put(node);
  455. return ~(u32)0;
  456. }
  457. of_node_put(node);
  458. return be32_to_cpup(prop);
  459. }
  460. return ~(u32)0;
  461. }
  462. for_each_node_by_type(node, "cpu") {
  463. prop = of_get_property(node, "reg", &len);
  464. for (i = 0; i < len / sizeof(u32); i++) {
  465. if (be32_to_cpup(&prop[i]) == vcpu) {
  466. found = 1;
  467. goto found_cpu_node;
  468. }
  469. }
  470. }
  471. found_cpu_node:
  472. /* find the hwnode that represents the cache */
  473. for (cache_level = PAMU_ATTR_CACHE_L1; (cache_level < PAMU_ATTR_CACHE_L3) && found; cache_level++) {
  474. if (stash_dest_hint == cache_level) {
  475. prop = of_get_property(node, "cache-stash-id", NULL);
  476. if (!prop) {
  477. pr_debug("missing cache-stash-id at %s\n",
  478. node->full_name);
  479. of_node_put(node);
  480. return ~(u32)0;
  481. }
  482. of_node_put(node);
  483. return be32_to_cpup(prop);
  484. }
  485. prop = of_get_property(node, "next-level-cache", NULL);
  486. if (!prop) {
  487. pr_debug("can't find next-level-cache at %s\n",
  488. node->full_name);
  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. pamu_regs = of_iomap(dev->of_node, 0);
  887. if (!pamu_regs) {
  888. dev_err(dev, "ioremap of PAMU node failed\n");
  889. return -ENOMEM;
  890. }
  891. of_get_address(dev->of_node, 0, &size, NULL);
  892. irq = irq_of_parse_and_map(dev->of_node, 0);
  893. if (irq == NO_IRQ) {
  894. dev_warn(dev, "no interrupts listed in PAMU node\n");
  895. goto error;
  896. }
  897. data = kzalloc(sizeof(*data), GFP_KERNEL);
  898. if (!data) {
  899. ret = -ENOMEM;
  900. goto error;
  901. }
  902. data->pamu_reg_base = pamu_regs;
  903. data->count = size / PAMU_OFFSET;
  904. /* The ISR needs access to the regs, so we won't iounmap them */
  905. ret = request_irq(irq, pamu_av_isr, 0, "pamu", data);
  906. if (ret < 0) {
  907. dev_err(dev, "error %i installing ISR for irq %i\n", ret, irq);
  908. goto error;
  909. }
  910. guts_node = of_find_matching_node(NULL, guts_device_ids);
  911. if (!guts_node) {
  912. dev_err(dev, "could not find GUTS node %s\n",
  913. dev->of_node->full_name);
  914. ret = -ENODEV;
  915. goto error;
  916. }
  917. guts_regs = of_iomap(guts_node, 0);
  918. of_node_put(guts_node);
  919. if (!guts_regs) {
  920. dev_err(dev, "ioremap of GUTS node failed\n");
  921. ret = -ENODEV;
  922. goto error;
  923. }
  924. /* read in the PAMU capability registers */
  925. get_pamu_cap_values((unsigned long)pamu_regs);
  926. /*
  927. * To simplify the allocation of a coherency domain, we allocate the
  928. * PAACT and the OMT in the same memory buffer. Unfortunately, this
  929. * wastes more memory compared to allocating the buffers separately.
  930. */
  931. /* Determine how much memory we need */
  932. mem_size = (PAGE_SIZE << get_order(PAACT_SIZE)) +
  933. (PAGE_SIZE << get_order(SPAACT_SIZE)) +
  934. (PAGE_SIZE << get_order(OMT_SIZE));
  935. order = get_order(mem_size);
  936. p = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
  937. if (!p) {
  938. dev_err(dev, "unable to allocate PAACT/SPAACT/OMT block\n");
  939. ret = -ENOMEM;
  940. goto error;
  941. }
  942. ppaact = page_address(p);
  943. ppaact_phys = page_to_phys(p);
  944. /* Make sure the memory is naturally aligned */
  945. if (ppaact_phys & ((PAGE_SIZE << order) - 1)) {
  946. dev_err(dev, "PAACT/OMT block is unaligned\n");
  947. ret = -ENOMEM;
  948. goto error;
  949. }
  950. spaact = (void *)ppaact + (PAGE_SIZE << get_order(PAACT_SIZE));
  951. omt = (void *)spaact + (PAGE_SIZE << get_order(SPAACT_SIZE));
  952. dev_dbg(dev, "ppaact virt=%p phys=%pa\n", ppaact, &ppaact_phys);
  953. /* Check to see if we need to implement the work-around on this SOC */
  954. /* Determine the Port ID for our coherence subdomain */
  955. for (i = 0; i < ARRAY_SIZE(port_id_map); i++) {
  956. if (port_id_map[i].svr == (mfspr(SPRN_SVR) & ~SVR_SECURITY)) {
  957. csd_port_id = port_id_map[i].port_id;
  958. dev_dbg(dev, "found matching SVR %08x\n",
  959. port_id_map[i].svr);
  960. break;
  961. }
  962. }
  963. if (csd_port_id) {
  964. dev_dbg(dev, "creating coherency subdomain at address %pa, size %zu, port id 0x%08x",
  965. &ppaact_phys, mem_size, csd_port_id);
  966. ret = create_csd(ppaact_phys, mem_size, csd_port_id);
  967. if (ret) {
  968. dev_err(dev, "could not create coherence subdomain\n");
  969. return ret;
  970. }
  971. }
  972. spaact_phys = virt_to_phys(spaact);
  973. omt_phys = virt_to_phys(omt);
  974. spaace_pool = gen_pool_create(ilog2(sizeof(struct paace)), -1);
  975. if (!spaace_pool) {
  976. ret = -ENOMEM;
  977. dev_err(dev, "Failed to allocate spaace gen pool\n");
  978. goto error;
  979. }
  980. ret = gen_pool_add(spaace_pool, (unsigned long)spaact, SPAACT_SIZE, -1);
  981. if (ret)
  982. goto error_genpool;
  983. pamubypenr = in_be32(&guts_regs->pamubypenr);
  984. for (pamu_reg_off = 0, pamu_counter = 0x80000000; pamu_reg_off < size;
  985. pamu_reg_off += PAMU_OFFSET, pamu_counter >>= 1) {
  986. pamu_reg_base = (unsigned long)pamu_regs + pamu_reg_off;
  987. setup_one_pamu(pamu_reg_base, pamu_reg_off, ppaact_phys,
  988. spaact_phys, omt_phys);
  989. /* Disable PAMU bypass for this PAMU */
  990. pamubypenr &= ~pamu_counter;
  991. }
  992. setup_omt(omt);
  993. /* Enable all relevant PAMU(s) */
  994. out_be32(&guts_regs->pamubypenr, pamubypenr);
  995. iounmap(guts_regs);
  996. /* Enable DMA for the LIODNs in the device tree */
  997. setup_liodns();
  998. return 0;
  999. error_genpool:
  1000. gen_pool_destroy(spaace_pool);
  1001. error:
  1002. if (irq != NO_IRQ)
  1003. free_irq(irq, data);
  1004. if (data) {
  1005. memset(data, 0, sizeof(struct pamu_isr_data));
  1006. kfree(data);
  1007. }
  1008. if (pamu_regs)
  1009. iounmap(pamu_regs);
  1010. if (guts_regs)
  1011. iounmap(guts_regs);
  1012. if (ppaact)
  1013. free_pages((unsigned long)ppaact, order);
  1014. ppaact = NULL;
  1015. return ret;
  1016. }
  1017. static struct platform_driver fsl_of_pamu_driver = {
  1018. .driver = {
  1019. .name = "fsl-of-pamu",
  1020. },
  1021. .probe = fsl_pamu_probe,
  1022. };
  1023. static __init int fsl_pamu_init(void)
  1024. {
  1025. struct platform_device *pdev = NULL;
  1026. struct device_node *np;
  1027. int ret;
  1028. /*
  1029. * The normal OF process calls the probe function at some
  1030. * indeterminate later time, after most drivers have loaded. This is
  1031. * too late for us, because PAMU clients (like the Qman driver)
  1032. * depend on PAMU being initialized early.
  1033. *
  1034. * So instead, we "manually" call our probe function by creating the
  1035. * platform devices ourselves.
  1036. */
  1037. /*
  1038. * We assume that there is only one PAMU node in the device tree. A
  1039. * single PAMU node represents all of the PAMU devices in the SOC
  1040. * already. Everything else already makes that assumption, and the
  1041. * binding for the PAMU nodes doesn't allow for any parent-child
  1042. * relationships anyway. In other words, support for more than one
  1043. * PAMU node would require significant changes to a lot of code.
  1044. */
  1045. np = of_find_compatible_node(NULL, NULL, "fsl,pamu");
  1046. if (!np) {
  1047. pr_err("could not find a PAMU node\n");
  1048. return -ENODEV;
  1049. }
  1050. ret = platform_driver_register(&fsl_of_pamu_driver);
  1051. if (ret) {
  1052. pr_err("could not register driver (err=%i)\n", ret);
  1053. goto error_driver_register;
  1054. }
  1055. pdev = platform_device_alloc("fsl-of-pamu", 0);
  1056. if (!pdev) {
  1057. pr_err("could not allocate device %s\n",
  1058. np->full_name);
  1059. ret = -ENOMEM;
  1060. goto error_device_alloc;
  1061. }
  1062. pdev->dev.of_node = of_node_get(np);
  1063. ret = pamu_domain_init();
  1064. if (ret)
  1065. goto error_device_add;
  1066. ret = platform_device_add(pdev);
  1067. if (ret) {
  1068. pr_err("could not add device %s (err=%i)\n",
  1069. np->full_name, 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);