Commit 3c65cbb7 authored by Marc Zyngier's avatar Marc Zyngier

irqchip/gic-v3: Improve affinity helper

The GICv3 driver uses multiple formats for the affinity, all
derived from a reading of MPDR_EL1 on one CPU or another.

Simplify the handling of these affinity by moving the access
to the CPU affinity via cpu_logical_map() inside the helper,
and rename it accordingly.

This will be helpful to support some more broken hardware.
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent cddb536a
...@@ -656,8 +656,9 @@ static int gic_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu) ...@@ -656,8 +656,9 @@ static int gic_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu)
return 0; return 0;
} }
static u64 gic_mpidr_to_affinity(unsigned long mpidr) static u64 gic_cpu_to_affinity(int cpu)
{ {
u64 mpidr = cpu_logical_map(cpu);
u64 aff; u64 aff;
aff = ((u64)MPIDR_AFFINITY_LEVEL(mpidr, 3) << 32 | aff = ((u64)MPIDR_AFFINITY_LEVEL(mpidr, 3) << 32 |
...@@ -914,7 +915,7 @@ static void __init gic_dist_init(void) ...@@ -914,7 +915,7 @@ static void __init gic_dist_init(void)
* Set all global interrupts to the boot CPU only. ARE must be * Set all global interrupts to the boot CPU only. ARE must be
* enabled. * enabled.
*/ */
affinity = gic_mpidr_to_affinity(cpu_logical_map(smp_processor_id())); affinity = gic_cpu_to_affinity(smp_processor_id());
for (i = 32; i < GIC_LINE_NR; i++) for (i = 32; i < GIC_LINE_NR; i++)
gic_write_irouter(affinity, base + GICD_IROUTER + i * 8); gic_write_irouter(affinity, base + GICD_IROUTER + i * 8);
...@@ -963,7 +964,7 @@ static int gic_iterate_rdists(int (*fn)(struct redist_region *, void __iomem *)) ...@@ -963,7 +964,7 @@ static int gic_iterate_rdists(int (*fn)(struct redist_region *, void __iomem *))
static int __gic_populate_rdist(struct redist_region *region, void __iomem *ptr) static int __gic_populate_rdist(struct redist_region *region, void __iomem *ptr)
{ {
unsigned long mpidr = cpu_logical_map(smp_processor_id()); unsigned long mpidr;
u64 typer; u64 typer;
u32 aff; u32 aff;
...@@ -971,6 +972,8 @@ static int __gic_populate_rdist(struct redist_region *region, void __iomem *ptr) ...@@ -971,6 +972,8 @@ static int __gic_populate_rdist(struct redist_region *region, void __iomem *ptr)
* Convert affinity to a 32bit value that can be matched to * Convert affinity to a 32bit value that can be matched to
* GICR_TYPER bits [63:32]. * GICR_TYPER bits [63:32].
*/ */
mpidr = gic_cpu_to_affinity(smp_processor_id());
aff = (MPIDR_AFFINITY_LEVEL(mpidr, 3) << 24 | aff = (MPIDR_AFFINITY_LEVEL(mpidr, 3) << 24 |
MPIDR_AFFINITY_LEVEL(mpidr, 2) << 16 | MPIDR_AFFINITY_LEVEL(mpidr, 2) << 16 |
MPIDR_AFFINITY_LEVEL(mpidr, 1) << 8 | MPIDR_AFFINITY_LEVEL(mpidr, 1) << 8 |
...@@ -1084,7 +1087,7 @@ static inline bool gic_dist_security_disabled(void) ...@@ -1084,7 +1087,7 @@ static inline bool gic_dist_security_disabled(void)
static void gic_cpu_sys_reg_init(void) static void gic_cpu_sys_reg_init(void)
{ {
int i, cpu = smp_processor_id(); int i, cpu = smp_processor_id();
u64 mpidr = cpu_logical_map(cpu); u64 mpidr = gic_cpu_to_affinity(cpu);
u64 need_rss = MPIDR_RS(mpidr); u64 need_rss = MPIDR_RS(mpidr);
bool group0; bool group0;
u32 pribits; u32 pribits;
...@@ -1183,11 +1186,11 @@ static void gic_cpu_sys_reg_init(void) ...@@ -1183,11 +1186,11 @@ static void gic_cpu_sys_reg_init(void)
for_each_online_cpu(i) { for_each_online_cpu(i) {
bool have_rss = per_cpu(has_rss, i) && per_cpu(has_rss, cpu); bool have_rss = per_cpu(has_rss, i) && per_cpu(has_rss, cpu);
need_rss |= MPIDR_RS(cpu_logical_map(i)); need_rss |= MPIDR_RS(gic_cpu_to_affinity(i));
if (need_rss && (!have_rss)) if (need_rss && (!have_rss))
pr_crit("CPU%d (%lx) can't SGI CPU%d (%lx), no RSS\n", pr_crit("CPU%d (%lx) can't SGI CPU%d (%lx), no RSS\n",
cpu, (unsigned long)mpidr, cpu, (unsigned long)mpidr,
i, (unsigned long)cpu_logical_map(i)); i, (unsigned long)gic_cpu_to_affinity(i));
} }
/** /**
...@@ -1263,9 +1266,11 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask, ...@@ -1263,9 +1266,11 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
unsigned long cluster_id) unsigned long cluster_id)
{ {
int next_cpu, cpu = *base_cpu; int next_cpu, cpu = *base_cpu;
unsigned long mpidr = cpu_logical_map(cpu); unsigned long mpidr;
u16 tlist = 0; u16 tlist = 0;
mpidr = gic_cpu_to_affinity(cpu);
while (cpu < nr_cpu_ids) { while (cpu < nr_cpu_ids) {
tlist |= 1 << (mpidr & 0xf); tlist |= 1 << (mpidr & 0xf);
...@@ -1274,7 +1279,7 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask, ...@@ -1274,7 +1279,7 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
goto out; goto out;
cpu = next_cpu; cpu = next_cpu;
mpidr = cpu_logical_map(cpu); mpidr = gic_cpu_to_affinity(cpu);
if (cluster_id != MPIDR_TO_SGI_CLUSTER_ID(mpidr)) { if (cluster_id != MPIDR_TO_SGI_CLUSTER_ID(mpidr)) {
cpu--; cpu--;
...@@ -1319,7 +1324,7 @@ static void gic_ipi_send_mask(struct irq_data *d, const struct cpumask *mask) ...@@ -1319,7 +1324,7 @@ static void gic_ipi_send_mask(struct irq_data *d, const struct cpumask *mask)
dsb(ishst); dsb(ishst);
for_each_cpu(cpu, mask) { for_each_cpu(cpu, mask) {
u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(cpu_logical_map(cpu)); u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(gic_cpu_to_affinity(cpu));
u16 tlist; u16 tlist;
tlist = gic_compute_target_list(&cpu, mask, cluster_id); tlist = gic_compute_target_list(&cpu, mask, cluster_id);
...@@ -1377,7 +1382,7 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, ...@@ -1377,7 +1382,7 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
offset = convert_offset_index(d, GICD_IROUTER, &index); offset = convert_offset_index(d, GICD_IROUTER, &index);
reg = gic_dist_base(d) + offset + (index * 8); reg = gic_dist_base(d) + offset + (index * 8);
val = gic_mpidr_to_affinity(cpu_logical_map(cpu)); val = gic_cpu_to_affinity(cpu);
gic_write_irouter(val, reg); gic_write_irouter(val, reg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment