Skip to content

Commit eda0d04

Browse files
Shanker DonthineniMarc Zyngier
authored andcommitted
irqchip/gic-v3: Add support for Range Selector (RS) feature
A new feature Range Selector (RS) has been added to GIC specification in order to support more than 16 CPUs at affinity level 0. New fields are introduced in SGI system registers (ICC_SGI0R_EL1, ICC_SGI1R_EL1 and ICC_ASGI1R_EL1) to relax an artificial limit of 16 at level 0. - A new RSS field in ICC_CTLR_EL3, ICC_CTLR_EL1 and ICV_CTLR_EL1: [18] - Range Selector Support (RSS) 0b0 = Targeted SGIs with affinity level 0 values of 0-15 are supported. 0b1 = Targeted SGIs with affinity level 0 values of 0-255 are supported. - A new RS field in ICC_SGI0R_EL1, ICC_SGI1R_EL1 and ICC_ASGI1R_EL1: [47:44] - RangeSelector (RS) which group of 16 TargetList[n] field TargetList[n] represents aff0 value ((RS*16)+n) When ICC_CTLR_EL3.RSS==0 or ICC_CTLR_EL1.RSS==0, RS is RES0. - A new RSS field in GICD_TYPER: [26] - Range Selector Support (RSS) 0b0 = Targeted SGIs with affinity level 0 values of 0-15 are supported. 0b1 = Targeted SGIs with affinity level 0 values of 0-255 are supported. Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent c0ca726 commit eda0d04

4 files changed

Lines changed: 55 additions & 9 deletions

File tree

‎arch/arm/include/asm/arch_gicv3.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ static inline void gic_write_ctlr(u32 val)
196196
isb();
197197
}
198198

199+
static inline u32 gic_read_ctlr(void)
200+
{
201+
return read_sysreg(ICC_CTLR);
202+
}
203+
199204
static inline void gic_write_grpen1(u32 val)
200205
{
201206
write_sysreg(val, ICC_IGRPEN1);

‎arch/arm64/include/asm/arch_gicv3.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ static inline void gic_write_ctlr(u32 val)
8787
isb();
8888
}
8989

90+
static inline u32 gic_read_ctlr(void)
91+
{
92+
return read_sysreg_s(SYS_ICC_CTLR_EL1);
93+
}
94+
9095
static inline void gic_write_grpen1(u32 val)
9196
{
9297
write_sysreg_s(val, SYS_ICC_IGRPEN1_EL1);

‎drivers/irqchip/irq-gic-v3.c‎

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct gic_chip_data {
5555
struct irq_domain *domain;
5656
u64 redist_stride;
5757
u32 nr_redist_regions;
58+
bool has_rss;
5859
unsigned int irq_nr;
5960
struct partition_desc *ppi_descs[16];
6061
};
@@ -63,7 +64,9 @@ static struct gic_chip_data gic_data __read_mostly;
6364
static struct static_key supports_deactivate = STATIC_KEY_INIT_TRUE;
6465

6566
static struct gic_kvm_info gic_v3_kvm_info;
67+
static DEFINE_PER_CPU(bool, has_rss);
6668

69+
#define MPIDR_RS(mpidr) (((mpidr) & 0xF0UL) >> 4)
6770
#define gic_data_rdist() (this_cpu_ptr(gic_data.rdists.rdist))
6871
#define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base)
6972
#define gic_data_rdist_sgi_base() (gic_data_rdist_rd_base() + SZ_64K)
@@ -526,6 +529,10 @@ static void gic_update_vlpi_properties(void)
526529

527530
static void gic_cpu_sys_reg_init(void)
528531
{
532+
int i, cpu = smp_processor_id();
533+
u64 mpidr = cpu_logical_map(cpu);
534+
u64 need_rss = MPIDR_RS(mpidr);
535+
529536
/*
530537
* Need to check that the SRE bit has actually been set. If
531538
* not, it means that SRE is disabled at EL2. We're going to
@@ -557,6 +564,30 @@ static void gic_cpu_sys_reg_init(void)
557564

558565
/* ... and let's hit the road... */
559566
gic_write_grpen1(1);
567+
568+
/* Keep the RSS capability status in per_cpu variable */
569+
per_cpu(has_rss, cpu) = !!(gic_read_ctlr() & ICC_CTLR_EL1_RSS);
570+
571+
/* Check all the CPUs have capable of sending SGIs to other CPUs */
572+
for_each_online_cpu(i) {
573+
bool have_rss = per_cpu(has_rss, i) && per_cpu(has_rss, cpu);
574+
575+
need_rss |= MPIDR_RS(cpu_logical_map(i));
576+
if (need_rss && (!have_rss))
577+
pr_crit("CPU%d (%lx) can't SGI CPU%d (%lx), no RSS\n",
578+
cpu, (unsigned long)mpidr,
579+
i, (unsigned long)cpu_logical_map(i));
580+
}
581+
582+
/**
583+
* GIC spec says, when ICC_CTLR_EL1.RSS==1 and GICD_TYPER.RSS==0,
584+
* writing ICC_ASGI1R_EL1 register with RS != 0 is a CONSTRAINED
585+
* UNPREDICTABLE choice of :
586+
* - The write is ignored.
587+
* - The RS field is treated as 0.
588+
*/
589+
if (need_rss && (!gic_data.has_rss))
590+
pr_crit_once("RSS is required but GICD doesn't support it\n");
560591
}
561592

562593
static int gic_dist_supports_lpis(void)
@@ -591,6 +622,9 @@ static void gic_cpu_init(void)
591622

592623
#ifdef CONFIG_SMP
593624

625+
#define MPIDR_TO_SGI_RS(mpidr) (MPIDR_RS(mpidr) << ICC_SGI1R_RS_SHIFT)
626+
#define MPIDR_TO_SGI_CLUSTER_ID(mpidr) ((mpidr) & ~0xFUL)
627+
594628
static int gic_starting_cpu(unsigned int cpu)
595629
{
596630
gic_cpu_init();
@@ -605,13 +639,6 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
605639
u16 tlist = 0;
606640

607641
while (cpu < nr_cpu_ids) {
608-
/*
609-
* If we ever get a cluster of more than 16 CPUs, just
610-
* scream and skip that CPU.
611-
*/
612-
if (WARN_ON((mpidr & 0xff) >= 16))
613-
goto out;
614-
615642
tlist |= 1 << (mpidr & 0xf);
616643

617644
next_cpu = cpumask_next(cpu, mask);
@@ -621,7 +648,7 @@ static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
621648

622649
mpidr = cpu_logical_map(cpu);
623650

624-
if (cluster_id != (mpidr & ~0xffUL)) {
651+
if (cluster_id != MPIDR_TO_SGI_CLUSTER_ID(mpidr)) {
625652
cpu--;
626653
goto out;
627654
}
@@ -643,6 +670,7 @@ static void gic_send_sgi(u64 cluster_id, u16 tlist, unsigned int irq)
643670
MPIDR_TO_SGI_AFFINITY(cluster_id, 2) |
644671
irq << ICC_SGI1R_SGI_ID_SHIFT |
645672
MPIDR_TO_SGI_AFFINITY(cluster_id, 1) |
673+
MPIDR_TO_SGI_RS(cluster_id) |
646674
tlist << ICC_SGI1R_TARGET_LIST_SHIFT);
647675

648676
pr_debug("CPU%d: ICC_SGI1R_EL1 %llx\n", smp_processor_id(), val);
@@ -663,7 +691,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
663691
smp_wmb();
664692

665693
for_each_cpu(cpu, mask) {
666-
unsigned long cluster_id = cpu_logical_map(cpu) & ~0xffUL;
694+
u64 cluster_id = MPIDR_TO_SGI_CLUSTER_ID(cpu_logical_map(cpu));
667695
u16 tlist;
668696

669697
tlist = gic_compute_target_list(&cpu, mask, cluster_id);
@@ -1007,6 +1035,10 @@ static int __init gic_init_bases(void __iomem *dist_base,
10071035
goto out_free;
10081036
}
10091037

1038+
gic_data.has_rss = !!(typer & GICD_TYPER_RSS);
1039+
pr_info("Distributor has %sRange Selector support\n",
1040+
gic_data.has_rss ? "" : "no ");
1041+
10101042
set_handle_irq(gic_handle_irq);
10111043

10121044
gic_update_vlpi_properties();

‎include/linux/irqchip/arm-gic-v3.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#define GICD_CTLR_ENABLE_SS_G1 (1U << 1)
6969
#define GICD_CTLR_ENABLE_SS_G0 (1U << 0)
7070

71+
#define GICD_TYPER_RSS (1U << 26)
7172
#define GICD_TYPER_LPIS (1U << 17)
7273
#define GICD_TYPER_MBIS (1U << 16)
7374

@@ -459,6 +460,7 @@
459460
#define ICC_CTLR_EL1_SEIS_MASK (0x1 << ICC_CTLR_EL1_SEIS_SHIFT)
460461
#define ICC_CTLR_EL1_A3V_SHIFT 15
461462
#define ICC_CTLR_EL1_A3V_MASK (0x1 << ICC_CTLR_EL1_A3V_SHIFT)
463+
#define ICC_CTLR_EL1_RSS (0x1 << 18)
462464
#define ICC_PMR_EL1_SHIFT 0
463465
#define ICC_PMR_EL1_MASK (0xff << ICC_PMR_EL1_SHIFT)
464466
#define ICC_BPR0_EL1_SHIFT 0
@@ -547,6 +549,8 @@
547549
#define ICC_SGI1R_AFFINITY_2_SHIFT 32
548550
#define ICC_SGI1R_AFFINITY_2_MASK (0xffULL << ICC_SGI1R_AFFINITY_2_SHIFT)
549551
#define ICC_SGI1R_IRQ_ROUTING_MODE_BIT 40
552+
#define ICC_SGI1R_RS_SHIFT 44
553+
#define ICC_SGI1R_RS_MASK (0xfULL << ICC_SGI1R_RS_SHIFT)
550554
#define ICC_SGI1R_AFFINITY_3_SHIFT 48
551555
#define ICC_SGI1R_AFFINITY_3_MASK (0xffULL << ICC_SGI1R_AFFINITY_3_SHIFT)
552556

0 commit comments

Comments
 (0)