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/interrupt.h>
  21. #include <linux/genalloc.h>
  22. #include <asm/mpc85xx.h>
  23. #include <asm/fsl_guts.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 struct ome *omt __initdata;
  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[] __initconst = {
  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 %s\n",
  454. node->full_name);
  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 %s\n",
  479. node->full_name);
  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 %s\n",
  489. node->full_name);
  490. of_node_put(node);
  491. return ~(u32)0; /* can't traverse any further */
  492. }
  493. of_node_put(node);
  494. /* advance to next node in cache hierarchy */
  495. node = of_find_node_by_phandle(*prop);
  496. if (!node) {
  497. pr_debug("Invalid node for cache hierarchy\n");
  498. return ~(u32)0;
  499. }
  500. }
  501. pr_debug("stash dest not found for %d on vcpu %d\n",
  502. stash_dest_hint, vcpu);
  503. return ~(u32)0;
  504. }
  505. /* Identify if the PAACT table entry belongs to QMAN, BMAN or QMAN Portal */
  506. #define QMAN_PAACE 1
  507. #define QMAN_PORTAL_PAACE 2
  508. #define BMAN_PAACE 3
  509. /**
  510. * Setup operation mapping and stash destinations for QMAN and QMAN portal.
  511. * Memory accesses to QMAN and BMAN private memory need not be coherent, so
  512. * clear the PAACE entry coherency attribute for them.
  513. */
  514. static void __init setup_qbman_paace(struct paace *ppaace, int paace_type)
  515. {
  516. switch (paace_type) {
  517. case QMAN_PAACE:
  518. set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  519. ppaace->op_encode.index_ot.omi = OMI_QMAN_PRIV;
  520. /* setup QMAN Private data stashing for the L3 cache */
  521. set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0));
  522. set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  523. 0);
  524. break;
  525. case QMAN_PORTAL_PAACE:
  526. set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
  527. ppaace->op_encode.index_ot.omi = OMI_QMAN;
  528. /* Set DQRR and Frame stashing for the L3 cache */
  529. set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0));
  530. break;
  531. case BMAN_PAACE:
  532. set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
  533. 0);
  534. break;
  535. }
  536. }
  537. /**
  538. * Setup the operation mapping table for various devices. This is a static
  539. * table where each table index corresponds to a particular device. PAMU uses
  540. * this table to translate device transaction to appropriate corenet
  541. * transaction.
  542. */
  543. static void __init setup_omt(struct ome *omt)
  544. {
  545. struct ome *ome;
  546. /* Configure OMI_QMAN */
  547. ome = &omt[OMI_QMAN];
  548. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READ;
  549. ome->moe[IOE_EREAD0_IDX] = EOE_VALID | EOE_RSA;
  550. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  551. ome->moe[IOE_EWRITE0_IDX] = EOE_VALID | EOE_WWSAO;
  552. ome->moe[IOE_DIRECT0_IDX] = EOE_VALID | EOE_LDEC;
  553. ome->moe[IOE_DIRECT1_IDX] = EOE_VALID | EOE_LDECPE;
  554. /* Configure OMI_FMAN */
  555. ome = &omt[OMI_FMAN];
  556. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READI;
  557. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  558. /* Configure OMI_QMAN private */
  559. ome = &omt[OMI_QMAN_PRIV];
  560. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READ;
  561. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  562. ome->moe[IOE_EREAD0_IDX] = EOE_VALID | EOE_RSA;
  563. ome->moe[IOE_EWRITE0_IDX] = EOE_VALID | EOE_WWSA;
  564. /* Configure OMI_CAAM */
  565. ome = &omt[OMI_CAAM];
  566. ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READI;
  567. ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
  568. }
  569. /*
  570. * Get the maximum number of PAACT table entries
  571. * and subwindows supported by PAMU
  572. */
  573. static void __init get_pamu_cap_values(unsigned long pamu_reg_base)
  574. {
  575. u32 pc_val;
  576. pc_val = in_be32((u32 *)(pamu_reg_base + PAMU_PC3));
  577. /* Maximum number of subwindows per liodn */
  578. max_subwindow_count = 1 << (1 + PAMU_PC3_MWCE(pc_val));
  579. }
  580. /* Setup PAMU registers pointing to PAACT, SPAACT and OMT */
  581. static int __init setup_one_pamu(unsigned long pamu_reg_base, unsigned long pamu_reg_size,
  582. phys_addr_t ppaact_phys, phys_addr_t spaact_phys,
  583. phys_addr_t omt_phys)
  584. {
  585. u32 *pc;
  586. struct pamu_mmap_regs *pamu_regs;
  587. pc = (u32 *) (pamu_reg_base + PAMU_PC);
  588. pamu_regs = (struct pamu_mmap_regs *)
  589. (pamu_reg_base + PAMU_MMAP_REGS_BASE);
  590. /* set up pointers to corenet control blocks */
  591. out_be32(&pamu_regs->ppbah, upper_32_bits(ppaact_phys));
  592. out_be32(&pamu_regs->ppbal, lower_32_bits(ppaact_phys));
  593. ppaact_phys = ppaact_phys + PAACT_SIZE;
  594. out_be32(&pamu_regs->pplah, upper_32_bits(ppaact_phys));
  595. out_be32(&pamu_regs->pplal, lower_32_bits(ppaact_phys));
  596. out_be32(&pamu_regs->spbah, upper_32_bits(spaact_phys));
  597. out_be32(&pamu_regs->spbal, lower_32_bits(spaact_phys));
  598. spaact_phys = spaact_phys + SPAACT_SIZE;
  599. out_be32(&pamu_regs->splah, upper_32_bits(spaact_phys));
  600. out_be32(&pamu_regs->splal, lower_32_bits(spaact_phys));
  601. out_be32(&pamu_regs->obah, upper_32_bits(omt_phys));
  602. out_be32(&pamu_regs->obal, lower_32_bits(omt_phys));
  603. omt_phys = omt_phys + OMT_SIZE;
  604. out_be32(&pamu_regs->olah, upper_32_bits(omt_phys));
  605. out_be32(&pamu_regs->olal, lower_32_bits(omt_phys));
  606. /*
  607. * set PAMU enable bit,
  608. * allow ppaact & omt to be cached
  609. * & enable PAMU access violation interrupts.
  610. */
  611. out_be32((u32 *)(pamu_reg_base + PAMU_PICS),
  612. PAMU_ACCESS_VIOLATION_ENABLE);
  613. out_be32(pc, PAMU_PC_PE | PAMU_PC_OCE | PAMU_PC_SPCC | PAMU_PC_PPCC);
  614. return 0;
  615. }
  616. /* Enable all device LIODNS */
  617. static void __init setup_liodns(void)
  618. {
  619. int i, len;
  620. struct paace *ppaace;
  621. struct device_node *node = NULL;
  622. const u32 *prop;
  623. for_each_node_with_property(node, "fsl,liodn") {
  624. prop = of_get_property(node, "fsl,liodn", &len);
  625. for (i = 0; i < len / sizeof(u32); i++) {
  626. int liodn;
  627. liodn = be32_to_cpup(&prop[i]);
  628. if (liodn >= PAACE_NUMBER_ENTRIES) {
  629. pr_debug("Invalid LIODN value %d\n", liodn);
  630. continue;
  631. }
  632. ppaace = pamu_get_ppaace(liodn);
  633. pamu_init_ppaace(ppaace);
  634. /* window size is 2^(WSE+1) bytes */
  635. set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE, 35);
  636. ppaace->wbah = 0;
  637. set_bf(ppaace->addr_bitfields, PPAACE_AF_WBAL, 0);
  638. set_bf(ppaace->impl_attr, PAACE_IA_ATM,
  639. PAACE_ATM_NO_XLATE);
  640. set_bf(ppaace->addr_bitfields, PAACE_AF_AP,
  641. PAACE_AP_PERMS_ALL);
  642. if (of_device_is_compatible(node, "fsl,qman-portal"))
  643. setup_qbman_paace(ppaace, QMAN_PORTAL_PAACE);
  644. if (of_device_is_compatible(node, "fsl,qman"))
  645. setup_qbman_paace(ppaace, QMAN_PAACE);
  646. if (of_device_is_compatible(node, "fsl,bman"))
  647. setup_qbman_paace(ppaace, BMAN_PAACE);
  648. mb();
  649. pamu_enable_liodn(liodn);
  650. }
  651. }
  652. }
  653. static irqreturn_t pamu_av_isr(int irq, void *arg)
  654. {
  655. struct pamu_isr_data *data = arg;
  656. phys_addr_t phys;
  657. unsigned int i, j, ret;
  658. pr_emerg("access violation interrupt\n");
  659. for (i = 0; i < data->count; i++) {
  660. void __iomem *p = data->pamu_reg_base + i * PAMU_OFFSET;
  661. u32 pics = in_be32(p + PAMU_PICS);
  662. if (pics & PAMU_ACCESS_VIOLATION_STAT) {
  663. u32 avs1 = in_be32(p + PAMU_AVS1);
  664. struct paace *paace;
  665. pr_emerg("POES1=%08x\n", in_be32(p + PAMU_POES1));
  666. pr_emerg("POES2=%08x\n", in_be32(p + PAMU_POES2));
  667. pr_emerg("AVS1=%08x\n", avs1);
  668. pr_emerg("AVS2=%08x\n", in_be32(p + PAMU_AVS2));
  669. pr_emerg("AVA=%016llx\n",
  670. make64(in_be32(p + PAMU_AVAH),
  671. in_be32(p + PAMU_AVAL)));
  672. pr_emerg("UDAD=%08x\n", in_be32(p + PAMU_UDAD));
  673. pr_emerg("POEA=%016llx\n",
  674. make64(in_be32(p + PAMU_POEAH),
  675. in_be32(p + PAMU_POEAL)));
  676. phys = make64(in_be32(p + PAMU_POEAH),
  677. in_be32(p + PAMU_POEAL));
  678. /* Assume that POEA points to a PAACE */
  679. if (phys) {
  680. u32 *paace = phys_to_virt(phys);
  681. /* Only the first four words are relevant */
  682. for (j = 0; j < 4; j++)
  683. pr_emerg("PAACE[%u]=%08x\n",
  684. j, in_be32(paace + j));
  685. }
  686. /* clear access violation condition */
  687. out_be32(p + PAMU_AVS1, avs1 & PAMU_AV_MASK);
  688. paace = pamu_get_ppaace(avs1 >> PAMU_AVS1_LIODN_SHIFT);
  689. BUG_ON(!paace);
  690. /* check if we got a violation for a disabled LIODN */
  691. if (!get_bf(paace->addr_bitfields, PAACE_AF_V)) {
  692. /*
  693. * As per hardware erratum A-003638, access
  694. * violation can be reported for a disabled
  695. * LIODN. If we hit that condition, disable
  696. * access violation reporting.
  697. */
  698. pics &= ~PAMU_ACCESS_VIOLATION_ENABLE;
  699. } else {
  700. /* Disable the LIODN */
  701. ret = pamu_disable_liodn(avs1 >> PAMU_AVS1_LIODN_SHIFT);
  702. BUG_ON(ret);
  703. pr_emerg("Disabling liodn %x\n",
  704. avs1 >> PAMU_AVS1_LIODN_SHIFT);
  705. }
  706. out_be32((p + PAMU_PICS), pics);
  707. }
  708. }
  709. return IRQ_HANDLED;
  710. }
  711. #define LAWAR_EN 0x80000000
  712. #define LAWAR_TARGET_MASK 0x0FF00000
  713. #define LAWAR_TARGET_SHIFT 20
  714. #define LAWAR_SIZE_MASK 0x0000003F
  715. #define LAWAR_CSDID_MASK 0x000FF000
  716. #define LAWAR_CSDID_SHIFT 12
  717. #define LAW_SIZE_4K 0xb
  718. struct ccsr_law {
  719. u32 lawbarh; /* LAWn base address high */
  720. u32 lawbarl; /* LAWn base address low */
  721. u32 lawar; /* LAWn attributes */
  722. u32 reserved;
  723. };
  724. /*
  725. * Create a coherence subdomain for a given memory block.
  726. */
  727. static int __init create_csd(phys_addr_t phys, size_t size, u32 csd_port_id)
  728. {
  729. struct device_node *np;
  730. const __be32 *iprop;
  731. void __iomem *lac = NULL; /* Local Access Control registers */
  732. struct ccsr_law __iomem *law;
  733. void __iomem *ccm = NULL;
  734. u32 __iomem *csdids;
  735. unsigned int i, num_laws, num_csds;
  736. u32 law_target = 0;
  737. u32 csd_id = 0;
  738. int ret = 0;
  739. np = of_find_compatible_node(NULL, NULL, "fsl,corenet-law");
  740. if (!np)
  741. return -ENODEV;
  742. iprop = of_get_property(np, "fsl,num-laws", NULL);
  743. if (!iprop) {
  744. ret = -ENODEV;
  745. goto error;
  746. }
  747. num_laws = be32_to_cpup(iprop);
  748. if (!num_laws) {
  749. ret = -ENODEV;
  750. goto error;
  751. }
  752. lac = of_iomap(np, 0);
  753. if (!lac) {
  754. ret = -ENODEV;
  755. goto error;
  756. }
  757. /* LAW registers are at offset 0xC00 */
  758. law = lac + 0xC00;
  759. of_node_put(np);
  760. np = of_find_compatible_node(NULL, NULL, "fsl,corenet-cf");
  761. if (!np) {
  762. ret = -ENODEV;
  763. goto error;
  764. }
  765. iprop = of_get_property(np, "fsl,ccf-num-csdids", NULL);
  766. if (!iprop) {
  767. ret = -ENODEV;
  768. goto error;
  769. }
  770. num_csds = be32_to_cpup(iprop);
  771. if (!num_csds) {
  772. ret = -ENODEV;
  773. goto error;
  774. }
  775. ccm = of_iomap(np, 0);
  776. if (!ccm) {
  777. ret = -ENOMEM;
  778. goto error;
  779. }
  780. /* The undocumented CSDID registers are at offset 0x600 */
  781. csdids = ccm + 0x600;
  782. of_node_put(np);
  783. np = NULL;
  784. /* Find an unused coherence subdomain ID */
  785. for (csd_id = 0; csd_id < num_csds; csd_id++) {
  786. if (!csdids[csd_id])
  787. break;
  788. }
  789. /* Store the Port ID in the (undocumented) proper CIDMRxx register */
  790. csdids[csd_id] = csd_port_id;
  791. /* Find the DDR LAW that maps to our buffer. */
  792. for (i = 0; i < num_laws; i++) {
  793. if (law[i].lawar & LAWAR_EN) {
  794. phys_addr_t law_start, law_end;
  795. law_start = make64(law[i].lawbarh, law[i].lawbarl);
  796. law_end = law_start +
  797. (2ULL << (law[i].lawar & LAWAR_SIZE_MASK));
  798. if (law_start <= phys && phys < law_end) {
  799. law_target = law[i].lawar & LAWAR_TARGET_MASK;
  800. break;
  801. }
  802. }
  803. }
  804. if (i == 0 || i == num_laws) {
  805. /* This should never happen */
  806. ret = -ENOENT;
  807. goto error;
  808. }
  809. /* Find a free LAW entry */
  810. while (law[--i].lawar & LAWAR_EN) {
  811. if (i == 0) {
  812. /* No higher priority LAW slots available */
  813. ret = -ENOENT;
  814. goto error;
  815. }
  816. }
  817. law[i].lawbarh = upper_32_bits(phys);
  818. law[i].lawbarl = lower_32_bits(phys);
  819. wmb();
  820. law[i].lawar = LAWAR_EN | law_target | (csd_id << LAWAR_CSDID_SHIFT) |
  821. (LAW_SIZE_4K + get_order(size));
  822. wmb();
  823. error:
  824. if (ccm)
  825. iounmap(ccm);
  826. if (lac)
  827. iounmap(lac);
  828. if (np)
  829. of_node_put(np);
  830. return ret;
  831. }
  832. /*
  833. * Table of SVRs and the corresponding PORT_ID values. Port ID corresponds to a
  834. * bit map of snoopers for a given range of memory mapped by a LAW.
  835. *
  836. * All future CoreNet-enabled SOCs will have this erratum(A-004510) fixed, so this
  837. * table should never need to be updated. SVRs are guaranteed to be unique, so
  838. * there is no worry that a future SOC will inadvertently have one of these
  839. * values.
  840. */
  841. static const struct {
  842. u32 svr;
  843. u32 port_id;
  844. } port_id_map[] __initconst = {
  845. {(SVR_P2040 << 8) | 0x10, 0xFF000000}, /* P2040 1.0 */
  846. {(SVR_P2040 << 8) | 0x11, 0xFF000000}, /* P2040 1.1 */
  847. {(SVR_P2041 << 8) | 0x10, 0xFF000000}, /* P2041 1.0 */
  848. {(SVR_P2041 << 8) | 0x11, 0xFF000000}, /* P2041 1.1 */
  849. {(SVR_P3041 << 8) | 0x10, 0xFF000000}, /* P3041 1.0 */
  850. {(SVR_P3041 << 8) | 0x11, 0xFF000000}, /* P3041 1.1 */
  851. {(SVR_P4040 << 8) | 0x20, 0xFFF80000}, /* P4040 2.0 */
  852. {(SVR_P4080 << 8) | 0x20, 0xFFF80000}, /* P4080 2.0 */
  853. {(SVR_P5010 << 8) | 0x10, 0xFC000000}, /* P5010 1.0 */
  854. {(SVR_P5010 << 8) | 0x20, 0xFC000000}, /* P5010 2.0 */
  855. {(SVR_P5020 << 8) | 0x10, 0xFC000000}, /* P5020 1.0 */
  856. {(SVR_P5021 << 8) | 0x10, 0xFF800000}, /* P5021 1.0 */
  857. {(SVR_P5040 << 8) | 0x10, 0xFF800000}, /* P5040 1.0 */
  858. };
  859. #define SVR_SECURITY 0x80000 /* The Security (E) bit */
  860. static int __init fsl_pamu_probe(struct platform_device *pdev)
  861. {
  862. struct device *dev = &pdev->dev;
  863. void __iomem *pamu_regs = NULL;
  864. struct ccsr_guts __iomem *guts_regs = NULL;
  865. u32 pamubypenr, pamu_counter;
  866. unsigned long pamu_reg_off;
  867. unsigned long pamu_reg_base;
  868. struct pamu_isr_data *data = NULL;
  869. struct device_node *guts_node;
  870. u64 size;
  871. struct page *p;
  872. int ret = 0;
  873. int irq;
  874. phys_addr_t ppaact_phys;
  875. phys_addr_t spaact_phys;
  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 __initdata = {
  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);