1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019 Broadcom.
7 #include <asm/gic-v3.h>
9 #include <linux/bitops.h>
10 #include <linux/sizes.h>
12 static u32 lpi_id_bits;
14 #define LPI_NRBITS lpi_id_bits
15 #define LPI_PROPBASE_SZ ALIGN(BIT(LPI_NRBITS), SZ_64K)
16 #define LPI_PENDBASE_SZ ALIGN(BIT(LPI_NRBITS) / 8, SZ_64K)
19 * Program the GIC LPI configuration tables for all
20 * the re-distributors and enable the LPI table
21 * base: Configuration table address
22 * num_redist: number of redistributors
24 int gic_lpi_tables_init(u64 base, u32 num_redist)
31 u64 pend_base = GICR_BASE + GICR_PENDBASER;
33 gicd_typer = readl(GICD_BASE + GICD_TYPER);
35 /* GIC support for Locality specific peripheral interrupts (LPI's) */
36 if (!(gicd_typer & GICD_TYPER_LPIS)) {
37 pr_err("GIC implementation does not support LPI's\n");
42 * Check for LPI is disabled for all the redistributors.
43 * Once the LPI table is enabled, can not program the
44 * LPI configuration tables again, unless the GIC is reset.
46 for (i = 0; i < num_redist; i++) {
47 u32 offset = i * GIC_REDISTRIBUTOR_OFFSET;
49 if ((readl((uintptr_t)(GICR_BASE + offset))) &
50 GICR_CTLR_ENABLE_LPIS) {
51 pr_err("Re-Distributor %d LPI is already enabled\n",
57 /* lpi_id_bits to get LPI_PENDBASE_SZ and LPi_PROPBASE_SZ */
58 lpi_id_bits = min_t(u32, GICD_TYPER_ID_BITS(gicd_typer),
63 GICR_PROPBASER_INNERSHAREABLE |
64 GICR_PROPBASER_RAWAWB |
65 ((LPI_NRBITS - 1) & GICR_PROPBASER_IDBITS_MASK));
67 writeq(val, (GICR_BASE + GICR_PROPBASER));
68 tmp = readl(GICR_BASE + GICR_PROPBASER);
69 if ((tmp ^ val) & GICR_PROPBASER_SHAREABILITY_MASK) {
70 if (!(tmp & GICR_PROPBASER_SHAREABILITY_MASK)) {
71 val &= ~(GICR_PROPBASER_SHAREABILITY_MASK |
72 GICR_PROPBASER_CACHEABILITY_MASK);
73 val |= GICR_PROPBASER_NC;
74 writeq(val, (GICR_BASE + GICR_PROPBASER));
78 redist_lpi_base = base + LPI_PROPBASE_SZ;
80 for (i = 0; i < num_redist; i++) {
81 u32 offset = i * GIC_REDISTRIBUTOR_OFFSET;
83 val = ((redist_lpi_base + (i * LPI_PENDBASE_SZ)) |
84 GICR_PENDBASER_INNERSHAREABLE |
85 GICR_PENDBASER_RAWAWB);
87 writeq(val, (uintptr_t)(pend_base + offset));
88 tmp = readq((uintptr_t)(pend_base + offset));
89 if (!(tmp & GICR_PENDBASER_SHAREABILITY_MASK)) {
90 val &= ~(GICR_PENDBASER_SHAREABILITY_MASK |
91 GICR_PENDBASER_CACHEABILITY_MASK);
92 val |= GICR_PENDBASER_NC;
93 writeq(val, (uintptr_t)(pend_base + offset));
96 /* Enable LPI for the redistributor */
97 writel(GICR_CTLR_ENABLE_LPIS, (uintptr_t)(GICR_BASE + offset));