1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2013 Freescale Semiconductor, Inc.
7 #define pr_fmt(fmt) "fsl-pamu: %s: " fmt, __func__
11 #include <linux/fsl/guts.h>
12 #include <linux/interrupt.h>
13 #include <linux/genalloc.h>
15 #include <asm/mpc85xx.h>
17 /* define indexes for each operation mapping scenario */
20 #define OMI_QMAN_PRIV 0x02
23 #define make64(high, low) (((u64)(high) << 32) | (low))
25 struct pamu_isr_data {
26 void __iomem *pamu_reg_base; /* Base address of PAMU regs */
27 unsigned int count; /* The number of PAMUs */
30 static struct paace *ppaact;
31 static struct paace *spaact;
33 static bool probed; /* Has PAMU been probed? */
36 * Table for matching compatible strings, for device tree
37 * guts node, for QorIQ SOCs.
38 * "fsl,qoriq-device-config-2.0" corresponds to T4 & B4
39 * SOCs. For the older SOCs "fsl,qoriq-device-config-1.0"
40 * string would be used.
42 static const struct of_device_id guts_device_ids[] = {
43 { .compatible = "fsl,qoriq-device-config-1.0", },
44 { .compatible = "fsl,qoriq-device-config-2.0", },
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,
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", },
63 /* maximum subwindows permitted per liodn */
64 static u32 max_subwindow_count;
67 * pamu_get_ppaace() - Return the primary PACCE
68 * @liodn: liodn PAACT index for desired PAACE
70 * Returns the ppace pointer upon success else return
73 static struct paace *pamu_get_ppaace(int liodn)
75 if (!ppaact || liodn >= PAACE_NUMBER_ENTRIES) {
76 pr_debug("PPAACT doesn't exist\n");
80 return &ppaact[liodn];
84 * pamu_enable_liodn() - Set valid bit of PACCE
85 * @liodn: liodn PAACT index for desired PAACE
87 * Returns 0 upon success else error code < 0 returned
89 int pamu_enable_liodn(int liodn)
93 ppaace = pamu_get_ppaace(liodn);
95 pr_debug("Invalid primary paace entry\n");
99 if (!get_bf(ppaace->addr_bitfields, PPAACE_AF_WSE)) {
100 pr_debug("liodn %d not configured\n", liodn);
104 /* Ensure that all other stores to the ppaace complete first */
107 set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_VALID);
114 * pamu_disable_liodn() - Clears valid bit of PACCE
115 * @liodn: liodn PAACT index for desired PAACE
117 * Returns 0 upon success else error code < 0 returned
119 int pamu_disable_liodn(int liodn)
121 struct paace *ppaace;
123 ppaace = pamu_get_ppaace(liodn);
125 pr_debug("Invalid primary paace entry\n");
129 set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_INVALID);
135 /* Derive the window size encoding for a particular PAACE entry */
136 static unsigned int map_addrspace_size_to_wse(phys_addr_t addrspace_size)
138 /* Bug if not a power of 2 */
139 BUG_ON(addrspace_size & (addrspace_size - 1));
141 /* window size is 2^(WSE+1) bytes */
142 return fls64(addrspace_size) - 2;
146 * Set the PAACE type as primary and set the coherency required domain
149 static void pamu_init_ppaace(struct paace *ppaace)
151 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);
158 * Function used for updating stash destination for the coressponding
161 int pamu_update_paace_stash(int liodn, u32 value)
165 paace = pamu_get_ppaace(liodn);
167 pr_debug("Invalid liodn entry\n");
170 set_bf(paace->impl_attr, PAACE_IA_CID, value);
178 * pamu_config_paace() - Sets up PPAACE entry for specified liodn
180 * @liodn: Logical IO device number
181 * @omi: Operation mapping index -- if ~omi == 0 then omi not defined
182 * @stashid: cache stash id for associated cpu -- if ~stashid == 0 then
183 * stashid not defined
184 * @prot: window permissions
186 * Returns 0 upon success else error code < 0 returned
188 int pamu_config_ppaace(int liodn, u32 omi, u32 stashid, int prot)
190 struct paace *ppaace;
192 ppaace = pamu_get_ppaace(liodn);
196 /* window size is 2^(WSE+1) bytes */
197 set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE,
198 map_addrspace_size_to_wse(1ULL << 36));
200 pamu_init_ppaace(ppaace);
203 set_bf(ppaace->addr_bitfields, PPAACE_AF_WBAL, 0);
205 /* set up operation mapping if it's configured */
206 if (omi < OME_NUMBER_ENTRIES) {
207 set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
208 ppaace->op_encode.index_ot.omi = omi;
209 } else if (~omi != 0) {
210 pr_debug("bad operation mapping index: %d\n", omi);
214 /* configure stash id */
216 set_bf(ppaace->impl_attr, PAACE_IA_CID, stashid);
218 set_bf(ppaace->impl_attr, PAACE_IA_ATM, PAACE_ATM_WINDOW_XLATE);
220 set_bf(ppaace->win_bitfields, PAACE_WIN_TWBAL, 0);
221 set_bf(ppaace->addr_bitfields, PAACE_AF_AP, prot);
222 set_bf(ppaace->impl_attr, PAACE_IA_WCE, 0);
223 set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0);
230 * get_ome_index() - Returns the index in the operation mapping table
232 * @*omi_index: pointer for storing the index value
235 void get_ome_index(u32 *omi_index, struct device *dev)
237 if (of_device_is_compatible(dev->of_node, "fsl,qman-portal"))
238 *omi_index = OMI_QMAN;
239 if (of_device_is_compatible(dev->of_node, "fsl,qman"))
240 *omi_index = OMI_QMAN_PRIV;
244 * get_stash_id - Returns stash destination id corresponding to a
245 * cache type and vcpu.
246 * @stash_dest_hint: L1, L2 or L3
247 * @vcpu: vpcu target for a particular cache type.
249 * Returs stash on success or ~(u32)0 on failure.
252 u32 get_stash_id(u32 stash_dest_hint, u32 vcpu)
255 struct device_node *node;
260 /* Fastpath, exit early if L3/CPC cache is target for stashing */
261 if (stash_dest_hint == PAMU_ATTR_CACHE_L3) {
262 node = of_find_matching_node(NULL, l3_device_ids);
264 prop = of_get_property(node, "cache-stash-id", NULL);
266 pr_debug("missing cache-stash-id at %pOF\n",
272 return be32_to_cpup(prop);
277 for_each_of_cpu_node(node) {
278 prop = of_get_property(node, "reg", &len);
279 for (i = 0; i < len / sizeof(u32); i++) {
280 if (be32_to_cpup(&prop[i]) == vcpu) {
288 /* find the hwnode that represents the cache */
289 for (cache_level = PAMU_ATTR_CACHE_L1; (cache_level < PAMU_ATTR_CACHE_L3) && found; cache_level++) {
290 if (stash_dest_hint == cache_level) {
291 prop = of_get_property(node, "cache-stash-id", NULL);
293 pr_debug("missing cache-stash-id at %pOF\n",
299 return be32_to_cpup(prop);
302 prop = of_get_property(node, "next-level-cache", NULL);
304 pr_debug("can't find next-level-cache at %pOF\n", node);
306 return ~(u32)0; /* can't traverse any further */
310 /* advance to next node in cache hierarchy */
311 node = of_find_node_by_phandle(*prop);
313 pr_debug("Invalid node for cache hierarchy\n");
318 pr_debug("stash dest not found for %d on vcpu %d\n",
319 stash_dest_hint, vcpu);
323 /* Identify if the PAACT table entry belongs to QMAN, BMAN or QMAN Portal */
325 #define QMAN_PORTAL_PAACE 2
329 * Setup operation mapping and stash destinations for QMAN and QMAN portal.
330 * Memory accesses to QMAN and BMAN private memory need not be coherent, so
331 * clear the PAACE entry coherency attribute for them.
333 static void setup_qbman_paace(struct paace *ppaace, int paace_type)
335 switch (paace_type) {
337 set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
338 ppaace->op_encode.index_ot.omi = OMI_QMAN_PRIV;
339 /* setup QMAN Private data stashing for the L3 cache */
340 set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0));
341 set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
344 case QMAN_PORTAL_PAACE:
345 set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
346 ppaace->op_encode.index_ot.omi = OMI_QMAN;
347 /* Set DQRR and Frame stashing for the L3 cache */
348 set_bf(ppaace->impl_attr, PAACE_IA_CID, get_stash_id(PAMU_ATTR_CACHE_L3, 0));
351 set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
358 * Setup the operation mapping table for various devices. This is a static
359 * table where each table index corresponds to a particular device. PAMU uses
360 * this table to translate device transaction to appropriate corenet
363 static void setup_omt(struct ome *omt)
367 /* Configure OMI_QMAN */
368 ome = &omt[OMI_QMAN];
370 ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READ;
371 ome->moe[IOE_EREAD0_IDX] = EOE_VALID | EOE_RSA;
372 ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
373 ome->moe[IOE_EWRITE0_IDX] = EOE_VALID | EOE_WWSAO;
375 ome->moe[IOE_DIRECT0_IDX] = EOE_VALID | EOE_LDEC;
376 ome->moe[IOE_DIRECT1_IDX] = EOE_VALID | EOE_LDECPE;
378 /* Configure OMI_FMAN */
379 ome = &omt[OMI_FMAN];
380 ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READI;
381 ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
383 /* Configure OMI_QMAN private */
384 ome = &omt[OMI_QMAN_PRIV];
385 ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READ;
386 ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
387 ome->moe[IOE_EREAD0_IDX] = EOE_VALID | EOE_RSA;
388 ome->moe[IOE_EWRITE0_IDX] = EOE_VALID | EOE_WWSA;
390 /* Configure OMI_CAAM */
391 ome = &omt[OMI_CAAM];
392 ome->moe[IOE_READ_IDX] = EOE_VALID | EOE_READI;
393 ome->moe[IOE_WRITE_IDX] = EOE_VALID | EOE_WRITE;
397 * Get the maximum number of PAACT table entries
398 * and subwindows supported by PAMU
400 static void get_pamu_cap_values(unsigned long pamu_reg_base)
404 pc_val = in_be32((u32 *)(pamu_reg_base + PAMU_PC3));
405 /* Maximum number of subwindows per liodn */
406 max_subwindow_count = 1 << (1 + PAMU_PC3_MWCE(pc_val));
409 /* Setup PAMU registers pointing to PAACT, SPAACT and OMT */
410 static int setup_one_pamu(unsigned long pamu_reg_base, unsigned long pamu_reg_size,
411 phys_addr_t ppaact_phys, phys_addr_t spaact_phys,
412 phys_addr_t omt_phys)
415 struct pamu_mmap_regs *pamu_regs;
417 pc = (u32 *) (pamu_reg_base + PAMU_PC);
418 pamu_regs = (struct pamu_mmap_regs *)
419 (pamu_reg_base + PAMU_MMAP_REGS_BASE);
421 /* set up pointers to corenet control blocks */
423 out_be32(&pamu_regs->ppbah, upper_32_bits(ppaact_phys));
424 out_be32(&pamu_regs->ppbal, lower_32_bits(ppaact_phys));
425 ppaact_phys = ppaact_phys + PAACT_SIZE;
426 out_be32(&pamu_regs->pplah, upper_32_bits(ppaact_phys));
427 out_be32(&pamu_regs->pplal, lower_32_bits(ppaact_phys));
429 out_be32(&pamu_regs->spbah, upper_32_bits(spaact_phys));
430 out_be32(&pamu_regs->spbal, lower_32_bits(spaact_phys));
431 spaact_phys = spaact_phys + SPAACT_SIZE;
432 out_be32(&pamu_regs->splah, upper_32_bits(spaact_phys));
433 out_be32(&pamu_regs->splal, lower_32_bits(spaact_phys));
435 out_be32(&pamu_regs->obah, upper_32_bits(omt_phys));
436 out_be32(&pamu_regs->obal, lower_32_bits(omt_phys));
437 omt_phys = omt_phys + OMT_SIZE;
438 out_be32(&pamu_regs->olah, upper_32_bits(omt_phys));
439 out_be32(&pamu_regs->olal, lower_32_bits(omt_phys));
442 * set PAMU enable bit,
443 * allow ppaact & omt to be cached
444 * & enable PAMU access violation interrupts.
447 out_be32((u32 *)(pamu_reg_base + PAMU_PICS),
448 PAMU_ACCESS_VIOLATION_ENABLE);
449 out_be32(pc, PAMU_PC_PE | PAMU_PC_OCE | PAMU_PC_SPCC | PAMU_PC_PPCC);
453 /* Enable all device LIODNS */
454 static void setup_liodns(void)
457 struct paace *ppaace;
458 struct device_node *node = NULL;
461 for_each_node_with_property(node, "fsl,liodn") {
462 prop = of_get_property(node, "fsl,liodn", &len);
463 for (i = 0; i < len / sizeof(u32); i++) {
466 liodn = be32_to_cpup(&prop[i]);
467 if (liodn >= PAACE_NUMBER_ENTRIES) {
468 pr_debug("Invalid LIODN value %d\n", liodn);
471 ppaace = pamu_get_ppaace(liodn);
472 pamu_init_ppaace(ppaace);
473 /* window size is 2^(WSE+1) bytes */
474 set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE, 35);
476 set_bf(ppaace->addr_bitfields, PPAACE_AF_WBAL, 0);
477 set_bf(ppaace->impl_attr, PAACE_IA_ATM,
479 set_bf(ppaace->addr_bitfields, PAACE_AF_AP,
481 if (of_device_is_compatible(node, "fsl,qman-portal"))
482 setup_qbman_paace(ppaace, QMAN_PORTAL_PAACE);
483 if (of_device_is_compatible(node, "fsl,qman"))
484 setup_qbman_paace(ppaace, QMAN_PAACE);
485 if (of_device_is_compatible(node, "fsl,bman"))
486 setup_qbman_paace(ppaace, BMAN_PAACE);
488 pamu_enable_liodn(liodn);
493 static irqreturn_t pamu_av_isr(int irq, void *arg)
495 struct pamu_isr_data *data = arg;
497 unsigned int i, j, ret;
499 pr_emerg("access violation interrupt\n");
501 for (i = 0; i < data->count; i++) {
502 void __iomem *p = data->pamu_reg_base + i * PAMU_OFFSET;
503 u32 pics = in_be32(p + PAMU_PICS);
505 if (pics & PAMU_ACCESS_VIOLATION_STAT) {
506 u32 avs1 = in_be32(p + PAMU_AVS1);
509 pr_emerg("POES1=%08x\n", in_be32(p + PAMU_POES1));
510 pr_emerg("POES2=%08x\n", in_be32(p + PAMU_POES2));
511 pr_emerg("AVS1=%08x\n", avs1);
512 pr_emerg("AVS2=%08x\n", in_be32(p + PAMU_AVS2));
513 pr_emerg("AVA=%016llx\n",
514 make64(in_be32(p + PAMU_AVAH),
515 in_be32(p + PAMU_AVAL)));
516 pr_emerg("UDAD=%08x\n", in_be32(p + PAMU_UDAD));
517 pr_emerg("POEA=%016llx\n",
518 make64(in_be32(p + PAMU_POEAH),
519 in_be32(p + PAMU_POEAL)));
521 phys = make64(in_be32(p + PAMU_POEAH),
522 in_be32(p + PAMU_POEAL));
524 /* Assume that POEA points to a PAACE */
526 u32 *paace = phys_to_virt(phys);
528 /* Only the first four words are relevant */
529 for (j = 0; j < 4; j++)
530 pr_emerg("PAACE[%u]=%08x\n",
531 j, in_be32(paace + j));
534 /* clear access violation condition */
535 out_be32(p + PAMU_AVS1, avs1 & PAMU_AV_MASK);
536 paace = pamu_get_ppaace(avs1 >> PAMU_AVS1_LIODN_SHIFT);
538 /* check if we got a violation for a disabled LIODN */
539 if (!get_bf(paace->addr_bitfields, PAACE_AF_V)) {
541 * As per hardware erratum A-003638, access
542 * violation can be reported for a disabled
543 * LIODN. If we hit that condition, disable
544 * access violation reporting.
546 pics &= ~PAMU_ACCESS_VIOLATION_ENABLE;
548 /* Disable the LIODN */
549 ret = pamu_disable_liodn(avs1 >> PAMU_AVS1_LIODN_SHIFT);
551 pr_emerg("Disabling liodn %x\n",
552 avs1 >> PAMU_AVS1_LIODN_SHIFT);
554 out_be32((p + PAMU_PICS), pics);
561 #define LAWAR_EN 0x80000000
562 #define LAWAR_TARGET_MASK 0x0FF00000
563 #define LAWAR_TARGET_SHIFT 20
564 #define LAWAR_SIZE_MASK 0x0000003F
565 #define LAWAR_CSDID_MASK 0x000FF000
566 #define LAWAR_CSDID_SHIFT 12
568 #define LAW_SIZE_4K 0xb
571 u32 lawbarh; /* LAWn base address high */
572 u32 lawbarl; /* LAWn base address low */
573 u32 lawar; /* LAWn attributes */
578 * Create a coherence subdomain for a given memory block.
580 static int create_csd(phys_addr_t phys, size_t size, u32 csd_port_id)
582 struct device_node *np;
584 void __iomem *lac = NULL; /* Local Access Control registers */
585 struct ccsr_law __iomem *law;
586 void __iomem *ccm = NULL;
588 unsigned int i, num_laws, num_csds;
593 np = of_find_compatible_node(NULL, NULL, "fsl,corenet-law");
597 iprop = of_get_property(np, "fsl,num-laws", NULL);
603 num_laws = be32_to_cpup(iprop);
609 lac = of_iomap(np, 0);
615 /* LAW registers are at offset 0xC00 */
620 np = of_find_compatible_node(NULL, NULL, "fsl,corenet-cf");
626 iprop = of_get_property(np, "fsl,ccf-num-csdids", NULL);
632 num_csds = be32_to_cpup(iprop);
638 ccm = of_iomap(np, 0);
644 /* The undocumented CSDID registers are at offset 0x600 */
645 csdids = ccm + 0x600;
650 /* Find an unused coherence subdomain ID */
651 for (csd_id = 0; csd_id < num_csds; csd_id++) {
656 /* Store the Port ID in the (undocumented) proper CIDMRxx register */
657 csdids[csd_id] = csd_port_id;
659 /* Find the DDR LAW that maps to our buffer. */
660 for (i = 0; i < num_laws; i++) {
661 if (law[i].lawar & LAWAR_EN) {
662 phys_addr_t law_start, law_end;
664 law_start = make64(law[i].lawbarh, law[i].lawbarl);
665 law_end = law_start +
666 (2ULL << (law[i].lawar & LAWAR_SIZE_MASK));
668 if (law_start <= phys && phys < law_end) {
669 law_target = law[i].lawar & LAWAR_TARGET_MASK;
675 if (i == 0 || i == num_laws) {
676 /* This should never happen */
681 /* Find a free LAW entry */
682 while (law[--i].lawar & LAWAR_EN) {
684 /* No higher priority LAW slots available */
690 law[i].lawbarh = upper_32_bits(phys);
691 law[i].lawbarl = lower_32_bits(phys);
693 law[i].lawar = LAWAR_EN | law_target | (csd_id << LAWAR_CSDID_SHIFT) |
694 (LAW_SIZE_4K + get_order(size));
711 * Table of SVRs and the corresponding PORT_ID values. Port ID corresponds to a
712 * bit map of snoopers for a given range of memory mapped by a LAW.
714 * All future CoreNet-enabled SOCs will have this erratum(A-004510) fixed, so this
715 * table should never need to be updated. SVRs are guaranteed to be unique, so
716 * there is no worry that a future SOC will inadvertently have one of these
719 static const struct {
723 {(SVR_P2040 << 8) | 0x10, 0xFF000000}, /* P2040 1.0 */
724 {(SVR_P2040 << 8) | 0x11, 0xFF000000}, /* P2040 1.1 */
725 {(SVR_P2041 << 8) | 0x10, 0xFF000000}, /* P2041 1.0 */
726 {(SVR_P2041 << 8) | 0x11, 0xFF000000}, /* P2041 1.1 */
727 {(SVR_P3041 << 8) | 0x10, 0xFF000000}, /* P3041 1.0 */
728 {(SVR_P3041 << 8) | 0x11, 0xFF000000}, /* P3041 1.1 */
729 {(SVR_P4040 << 8) | 0x20, 0xFFF80000}, /* P4040 2.0 */
730 {(SVR_P4080 << 8) | 0x20, 0xFFF80000}, /* P4080 2.0 */
731 {(SVR_P5010 << 8) | 0x10, 0xFC000000}, /* P5010 1.0 */
732 {(SVR_P5010 << 8) | 0x20, 0xFC000000}, /* P5010 2.0 */
733 {(SVR_P5020 << 8) | 0x10, 0xFC000000}, /* P5020 1.0 */
734 {(SVR_P5021 << 8) | 0x10, 0xFF800000}, /* P5021 1.0 */
735 {(SVR_P5040 << 8) | 0x10, 0xFF800000}, /* P5040 1.0 */
738 #define SVR_SECURITY 0x80000 /* The Security (E) bit */
740 static int fsl_pamu_probe(struct platform_device *pdev)
742 struct device *dev = &pdev->dev;
743 void __iomem *pamu_regs = NULL;
744 struct ccsr_guts __iomem *guts_regs = NULL;
745 u32 pamubypenr, pamu_counter;
746 unsigned long pamu_reg_off;
747 unsigned long pamu_reg_base;
748 struct pamu_isr_data *data = NULL;
749 struct device_node *guts_node;
754 phys_addr_t ppaact_phys;
755 phys_addr_t spaact_phys;
757 phys_addr_t omt_phys;
759 unsigned int order = 0;
763 * enumerate all PAMUs and allocate and setup PAMU tables
765 * NOTE : All PAMUs share the same LIODN tables.
771 pamu_regs = of_iomap(dev->of_node, 0);
773 dev_err(dev, "ioremap of PAMU node failed\n");
776 of_get_address(dev->of_node, 0, &size, NULL);
778 irq = irq_of_parse_and_map(dev->of_node, 0);
780 dev_warn(dev, "no interrupts listed in PAMU node\n");
784 data = kzalloc(sizeof(*data), GFP_KERNEL);
789 data->pamu_reg_base = pamu_regs;
790 data->count = size / PAMU_OFFSET;
792 /* The ISR needs access to the regs, so we won't iounmap them */
793 ret = request_irq(irq, pamu_av_isr, 0, "pamu", data);
795 dev_err(dev, "error %i installing ISR for irq %i\n", ret, irq);
799 guts_node = of_find_matching_node(NULL, guts_device_ids);
801 dev_err(dev, "could not find GUTS node %pOF\n", dev->of_node);
806 guts_regs = of_iomap(guts_node, 0);
807 of_node_put(guts_node);
809 dev_err(dev, "ioremap of GUTS node failed\n");
814 /* read in the PAMU capability registers */
815 get_pamu_cap_values((unsigned long)pamu_regs);
817 * To simplify the allocation of a coherency domain, we allocate the
818 * PAACT and the OMT in the same memory buffer. Unfortunately, this
819 * wastes more memory compared to allocating the buffers separately.
821 /* Determine how much memory we need */
822 mem_size = (PAGE_SIZE << get_order(PAACT_SIZE)) +
823 (PAGE_SIZE << get_order(SPAACT_SIZE)) +
824 (PAGE_SIZE << get_order(OMT_SIZE));
825 order = get_order(mem_size);
827 p = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
829 dev_err(dev, "unable to allocate PAACT/SPAACT/OMT block\n");
834 ppaact = page_address(p);
835 ppaact_phys = page_to_phys(p);
837 /* Make sure the memory is naturally aligned */
838 if (ppaact_phys & ((PAGE_SIZE << order) - 1)) {
839 dev_err(dev, "PAACT/OMT block is unaligned\n");
844 spaact = (void *)ppaact + (PAGE_SIZE << get_order(PAACT_SIZE));
845 omt = (void *)spaact + (PAGE_SIZE << get_order(SPAACT_SIZE));
847 dev_dbg(dev, "ppaact virt=%p phys=%pa\n", ppaact, &ppaact_phys);
849 /* Check to see if we need to implement the work-around on this SOC */
851 /* Determine the Port ID for our coherence subdomain */
852 for (i = 0; i < ARRAY_SIZE(port_id_map); i++) {
853 if (port_id_map[i].svr == (mfspr(SPRN_SVR) & ~SVR_SECURITY)) {
854 csd_port_id = port_id_map[i].port_id;
855 dev_dbg(dev, "found matching SVR %08x\n",
862 dev_dbg(dev, "creating coherency subdomain at address %pa, size %zu, port id 0x%08x",
863 &ppaact_phys, mem_size, csd_port_id);
865 ret = create_csd(ppaact_phys, mem_size, csd_port_id);
867 dev_err(dev, "could not create coherence subdomain\n");
872 spaact_phys = virt_to_phys(spaact);
873 omt_phys = virt_to_phys(omt);
875 pamubypenr = in_be32(&guts_regs->pamubypenr);
877 for (pamu_reg_off = 0, pamu_counter = 0x80000000; pamu_reg_off < size;
878 pamu_reg_off += PAMU_OFFSET, pamu_counter >>= 1) {
880 pamu_reg_base = (unsigned long)pamu_regs + pamu_reg_off;
881 setup_one_pamu(pamu_reg_base, pamu_reg_off, ppaact_phys,
882 spaact_phys, omt_phys);
883 /* Disable PAMU bypass for this PAMU */
884 pamubypenr &= ~pamu_counter;
889 /* Enable all relevant PAMU(s) */
890 out_be32(&guts_regs->pamubypenr, pamubypenr);
894 /* Enable DMA for the LIODNs in the device tree */
906 kfree_sensitive(data);
915 free_pages((unsigned long)ppaact, order);
922 static struct platform_driver fsl_of_pamu_driver = {
924 .name = "fsl-of-pamu",
926 .probe = fsl_pamu_probe,
929 static __init int fsl_pamu_init(void)
931 struct platform_device *pdev = NULL;
932 struct device_node *np;
936 * The normal OF process calls the probe function at some
937 * indeterminate later time, after most drivers have loaded. This is
938 * too late for us, because PAMU clients (like the Qman driver)
939 * depend on PAMU being initialized early.
941 * So instead, we "manually" call our probe function by creating the
942 * platform devices ourselves.
946 * We assume that there is only one PAMU node in the device tree. A
947 * single PAMU node represents all of the PAMU devices in the SOC
948 * already. Everything else already makes that assumption, and the
949 * binding for the PAMU nodes doesn't allow for any parent-child
950 * relationships anyway. In other words, support for more than one
951 * PAMU node would require significant changes to a lot of code.
954 np = of_find_compatible_node(NULL, NULL, "fsl,pamu");
956 pr_err("could not find a PAMU node\n");
960 ret = platform_driver_register(&fsl_of_pamu_driver);
962 pr_err("could not register driver (err=%i)\n", ret);
963 goto error_driver_register;
966 pdev = platform_device_alloc("fsl-of-pamu", 0);
968 pr_err("could not allocate device %pOF\n", np);
970 goto error_device_alloc;
972 pdev->dev.of_node = of_node_get(np);
974 ret = pamu_domain_init();
976 goto error_device_add;
978 ret = platform_device_add(pdev);
980 pr_err("could not add device %pOF (err=%i)\n", np, ret);
981 goto error_device_add;
987 of_node_put(pdev->dev.of_node);
988 pdev->dev.of_node = NULL;
990 platform_device_put(pdev);
993 platform_driver_unregister(&fsl_of_pamu_driver);
995 error_driver_register:
1000 arch_initcall(fsl_pamu_init);