Skip to content

Commit 3c65cbb

Browse files
author
Marc Zyngier
committed
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: Marc Zyngier <maz@kernel.org>
1 parent cddb536 commit 3c65cbb

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

drivers/irqchip/irq-gic-v3.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,9 @@ static int gic_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu)
656656
return 0;
657657
}
658658

659-
static u64 gic_mpidr_to_affinity(unsigned long mpidr)
659+
static u64 gic_cpu_to_affinity(int cpu)
660660
{
661+
u64 mpidr = cpu_logical_map(cpu);
661662
u64 aff;
662663

663664
aff = ((u64)MPIDR_AFFINITY_LEVEL(mpidr, 3) << 32 |
@@ -914,7 +915,7 @@ static void __init gic_dist_init(void)
914915
* Set all global interrupts to the boot CPU only. ARE must be
915916
* enabled.
916917
*/
917-
affinity = gic_mpidr_to_affinity(cpu_logical_map(smp_processor_id()));
918+
affinity = gic_cpu_to_affinity(smp_processor_id());
918919
for (i = 32; i < GIC_LINE_NR; i++)
919920
gic_write_irouter(affinity, base + GICD_IROUTER + i * 8);
920921

@@ -963,14 +964,16 @@ static int gic_iterate_rdists(int (*fn)(struct redist_region *, void __iomem *))
963964

964965
static int __gic_populate_rdist(struct redist_region *region, void __iomem *ptr)
965966
{
966-
unsigned long mpidr = cpu_logical_map(smp_processor_id());
967+
unsigned long mpidr;
967968
u64 typer;
968969
u32 aff;
969970

970971
/*
971972
* Convert affinity to a 32bit value that can be matched to
972973
* GICR_TYPER bits [63:32].
973974
*/
975+
mpidr = gic_cpu_to_affinity(smp_processor_id());
976+
974977
aff = (MPIDR_AFFINITY_LEVEL(mpidr, 3) << 24 |
975978
MPIDR_AFFINITY_LEVEL(mpidr, 2) << 16 |
976979
MPIDR_AFFINITY_LEVEL(mpidr, 1) << 8 |
@@ -1084,7 +1087,7 @@ static inline bool gic_dist_security_disabled(void)
10841087
static void gic_cpu_sys_reg_init(void)
10851088
{
10861089
int i, cpu = smp_processor_id();
1087-
u64 mpidr = cpu_logical_map(cpu);
1090+
u64 mpidr = gic_cpu_to_affinity(cpu);
10881091
u64 need_rss = MPIDR_RS(mpidr);
10891092
bool group0;
10901093
u32 pribits;
@@ -1183,11 +1186,11 @@ static void gic_cpu_sys_reg_init(void)
11831186
for_each_online_cpu(i) {
11841187
bool have_rss = per_cpu(has_rss, i) && per_cpu(has_rss, cpu);
11851188

1186-
need_rss |= MPIDR_RS(cpu_logical_map(i));
1189+
need_rss |= MPIDR_RS(gic_cpu_to_affinity(i));
11871190
if (need_rss && (!have_rss))
11881191
pr_crit("CPU%d (%lx) can't SGI CPU%d (%lx), no RSS\n",
11891192
cpu, (unsigned long)mpidr,
1190-
i, (unsigned long)cpu_logical_map(i));
1193+
i, (unsigned long)gic_cpu_to_affinity(i));
11911194
}
11921195

11931196
/**
@@ -1263,9 +1266,11 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
12631266
unsigned long cluster_id)
12641267
{
12651268
int next_cpu, cpu = *base_cpu;
1266-
unsigned long mpidr = cpu_logical_map(cpu);
1269+
unsigned long mpidr;
12671270
u16 tlist = 0;
12681271

1272+
mpidr = gic_cpu_to_affinity(cpu);
1273+
12691274
while (cpu < nr_cpu_ids) {
12701275
tlist |= 1 << (mpidr & 0xf);
12711276

@@ -1274,7 +1279,7 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
12741279
goto out;
12751280
cpu = next_cpu;
12761281

1277-
mpidr = cpu_logical_map(cpu);
1282+
mpidr = gic_cpu_to_affinity(cpu);
12781283

12791284
if (cluster_id != MPIDR_TO_SGI_CLUSTER_ID(mpidr)) {
12801285
cpu--;
@@ -1319,7 +1324,7 @@ static void gic_ipi_send_mask(struct irq_data *d, const struct cpumask *mask)
13191324
dsb(ishst);
13201325

13211326
for_each_cpu(cpu, mask) {
1322-
u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(cpu_logical_map(cpu));
1327+
u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(gic_cpu_to_affinity(cpu));
13231328
u16 tlist;
13241329

13251330
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,
13771382

13781383
offset = convert_offset_index(d, GICD_IROUTER, &index);
13791384
reg = gic_dist_base(d) + offset + (index * 8);
1380-
val = gic_mpidr_to_affinity(cpu_logical_map(cpu));
1385+
val = gic_cpu_to_affinity(cpu);
13811386

13821387
gic_write_irouter(val, reg);
13831388

0 commit comments

Comments
 (0)