|
25 | 25 | #include <linux/irqchip.h> |
26 | 26 | #include <linux/irqchip/arm-gic-common.h> |
27 | 27 | #include <linux/irqchip/arm-gic-v3.h> |
| 28 | +#include <linux/irqchip/arm-gic-v3-prio.h> |
28 | 29 | #include <linux/irqchip/irq-partition-percpu.h> |
29 | 30 | #include <linux/bitfield.h> |
30 | 31 | #include <linux/bits.h> |
|
37 | 38 |
|
38 | 39 | #include "irq-gic-common.h" |
39 | 40 |
|
40 | | -static u8 dist_prio_irq __ro_after_init = GICD_INT_DEF_PRI; |
41 | | -static u8 dist_prio_nmi __ro_after_init = GICD_INT_DEF_PRI & ~0x80; |
| 41 | +static u8 dist_prio_irq __ro_after_init = GICV3_PRIO_IRQ; |
| 42 | +static u8 dist_prio_nmi __ro_after_init = GICV3_PRIO_NMI; |
42 | 43 |
|
43 | 44 | #define FLAGS_WORKAROUND_GICR_WAKER_MSM8996 (1ULL << 0) |
44 | 45 | #define FLAGS_WORKAROUND_CAVIUM_ERRATUM_38539 (1ULL << 1) |
@@ -110,30 +111,6 @@ static DEFINE_STATIC_KEY_TRUE(supports_deactivate_key); |
110 | 111 | */ |
111 | 112 | static DEFINE_STATIC_KEY_FALSE(supports_pseudo_nmis); |
112 | 113 |
|
113 | | -DEFINE_STATIC_KEY_FALSE(gic_nonsecure_priorities); |
114 | | -EXPORT_SYMBOL(gic_nonsecure_priorities); |
115 | | - |
116 | | -/* |
117 | | - * When the Non-secure world has access to group 0 interrupts (as a |
118 | | - * consequence of SCR_EL3.FIQ == 0), reading the ICC_RPR_EL1 register will |
119 | | - * return the Distributor's view of the interrupt priority. |
120 | | - * |
121 | | - * When GIC security is enabled (GICD_CTLR.DS == 0), the interrupt priority |
122 | | - * written by software is moved to the Non-secure range by the Distributor. |
123 | | - * |
124 | | - * If both are true (which is when gic_nonsecure_priorities gets enabled), |
125 | | - * we need to shift down the priority programmed by software to match it |
126 | | - * against the value returned by ICC_RPR_EL1. |
127 | | - */ |
128 | | -#define GICD_INT_RPR_PRI(priority) \ |
129 | | - ({ \ |
130 | | - u32 __priority = (priority); \ |
131 | | - if (static_branch_unlikely(&gic_nonsecure_priorities)) \ |
132 | | - __priority = 0x80 | (__priority >> 1); \ |
133 | | - \ |
134 | | - __priority; \ |
135 | | - }) |
136 | | - |
137 | 114 | static u32 gic_get_pribits(void) |
138 | 115 | { |
139 | 116 | u32 pribits; |
@@ -185,6 +162,41 @@ static void __init gic_prio_init(void) |
185 | 162 | cpus_have_security_disabled = gic_dist_security_disabled(); |
186 | 163 | cpus_have_group0 = gic_has_group0(); |
187 | 164 |
|
| 165 | + /* |
| 166 | + * How priority values are used by the GIC depends on two things: |
| 167 | + * the security state of the GIC (controlled by the GICD_CTRL.DS bit) |
| 168 | + * and if Group 0 interrupts can be delivered to Linux in the non-secure |
| 169 | + * world as FIQs (controlled by the SCR_EL3.FIQ bit). These affect the |
| 170 | + * way priorities are presented in ICC_PMR_EL1 and in the distributor: |
| 171 | + * |
| 172 | + * GICD_CTRL.DS | SCR_EL3.FIQ | ICC_PMR_EL1 | Distributor |
| 173 | + * ------------------------------------------------------- |
| 174 | + * 1 | - | unchanged | unchanged |
| 175 | + * ------------------------------------------------------- |
| 176 | + * 0 | 1 | non-secure | non-secure |
| 177 | + * ------------------------------------------------------- |
| 178 | + * 0 | 0 | unchanged | non-secure |
| 179 | + * |
| 180 | + * In the non-secure view reads and writes are modified: |
| 181 | + * |
| 182 | + * - A value written is right-shifted by one and the MSB is set, |
| 183 | + * forcing the priority into the non-secure range. |
| 184 | + * |
| 185 | + * - A value read is left-shifted by one. |
| 186 | + * |
| 187 | + * In the first two cases, where ICC_PMR_EL1 and the interrupt priority |
| 188 | + * are both either modified or unchanged, we can use the same set of |
| 189 | + * priorities. |
| 190 | + * |
| 191 | + * In the last case, where only the interrupt priorities are modified to |
| 192 | + * be in the non-secure range, we program the non-secure values into |
| 193 | + * the distributor to match the PMR values we want. |
| 194 | + */ |
| 195 | + if (cpus_have_group0 & !cpus_have_security_disabled) { |
| 196 | + dist_prio_irq = __gicv3_prio_to_ns(dist_prio_irq); |
| 197 | + dist_prio_nmi = __gicv3_prio_to_ns(dist_prio_nmi); |
| 198 | + } |
| 199 | + |
188 | 200 | pr_info("GICD_CTRL.DS=%d, SCR_EL3.FIQ=%d\n", |
189 | 201 | cpus_have_security_disabled, |
190 | 202 | !cpus_have_group0); |
@@ -811,7 +823,7 @@ static bool gic_rpr_is_nmi_prio(void) |
811 | 823 | if (!gic_supports_nmi()) |
812 | 824 | return false; |
813 | 825 |
|
814 | | - return unlikely(gic_read_rpr() == GICD_INT_RPR_PRI(dist_prio_nmi)); |
| 826 | + return unlikely(gic_read_rpr() == GICV3_PRIO_NMI); |
815 | 827 | } |
816 | 828 |
|
817 | 829 | static bool gic_irqnr_is_special(u32 irqnr) |
@@ -1960,36 +1972,6 @@ static void gic_enable_nmi_support(void) |
1960 | 1972 | pr_info("Pseudo-NMIs enabled using %s ICC_PMR_EL1 synchronisation\n", |
1961 | 1973 | gic_has_relaxed_pmr_sync() ? "relaxed" : "forced"); |
1962 | 1974 |
|
1963 | | - /* |
1964 | | - * How priority values are used by the GIC depends on two things: |
1965 | | - * the security state of the GIC (controlled by the GICD_CTRL.DS bit) |
1966 | | - * and if Group 0 interrupts can be delivered to Linux in the non-secure |
1967 | | - * world as FIQs (controlled by the SCR_EL3.FIQ bit). These affect the |
1968 | | - * ICC_PMR_EL1 register and the priority that software assigns to |
1969 | | - * interrupts: |
1970 | | - * |
1971 | | - * GICD_CTRL.DS | SCR_EL3.FIQ | ICC_PMR_EL1 | Group 1 priority |
1972 | | - * ----------------------------------------------------------- |
1973 | | - * 1 | - | unchanged | unchanged |
1974 | | - * ----------------------------------------------------------- |
1975 | | - * 0 | 1 | non-secure | non-secure |
1976 | | - * ----------------------------------------------------------- |
1977 | | - * 0 | 0 | unchanged | non-secure |
1978 | | - * |
1979 | | - * where non-secure means that the value is right-shifted by one and the |
1980 | | - * MSB bit set, to make it fit in the non-secure priority range. |
1981 | | - * |
1982 | | - * In the first two cases, where ICC_PMR_EL1 and the interrupt priority |
1983 | | - * are both either modified or unchanged, we can use the same set of |
1984 | | - * priorities. |
1985 | | - * |
1986 | | - * In the last case, where only the interrupt priorities are modified to |
1987 | | - * be in the non-secure range, we use a different PMR value to mask IRQs |
1988 | | - * and the rest of the values that we use remain unchanged. |
1989 | | - */ |
1990 | | - if (gic_has_group0() && !gic_dist_security_disabled()) |
1991 | | - static_branch_enable(&gic_nonsecure_priorities); |
1992 | | - |
1993 | 1975 | static_branch_enable(&supports_pseudo_nmis); |
1994 | 1976 |
|
1995 | 1977 | if (static_branch_likely(&supports_deactivate_key)) |
|
0 commit comments