ACPI 6.3 adds additional fields to the MADT GICC structure to describe SPE PPI's. We pick these out of the cached reference to the madt_gicc structure similarly to the core PMU code. We then create a platform device referring to the IRQ and let the user/module loader decide whether to load the SPE driver. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> --- arch/arm64/include/asm/acpi.h | 3 ++ drivers/perf/arm_pmu_acpi.c | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 7628efbe6c12..d10399b9f998 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -41,6 +41,9 @@ (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \ (unsigned long)(entry) + (entry)->header.length > (end)) +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct acpi_madt_generic_interrupt, \ + spe_interrupt) + sizeof(u16)) + /* Basic configuration for ACPI */ #ifdef CONFIG_ACPI pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c index 0f197516d708..a2418108eab2 100644 --- a/drivers/perf/arm_pmu_acpi.c +++ b/drivers/perf/arm_pmu_acpi.c @@ -74,6 +74,73 @@ static void arm_pmu_acpi_unregister_irq(int cpu) acpi_unregister_gsi(gsi); } +static struct resource spe_resources[] = { + { + /* irq */ + .flags = IORESOURCE_IRQ, + } +}; + +static struct platform_device spe_dev = { + .name = "arm,spe-v1", + .id = -1, + .resource = spe_resources, + .num_resources = ARRAY_SIZE(spe_resources) +}; + +/* + * For lack of a better place, hook the normal PMU MADT walk + * and create a SPE device if we detect a recent MADT with + * a homogeneous PPI mapping. + */ +static int arm_spe_acpi_parse_irqs(void) +{ + int cpu, ret, irq; + int hetid; + u16 gsi = 0; + bool first = true; + + struct acpi_madt_generic_interrupt *gicc; + + /* + * sanity check all the GICC tables for the same interrupt number + * for now we only support homogeneous ACPI/SPE machines. + */ + for_each_possible_cpu(cpu) { + gicc = acpi_cpu_get_madt_gicc(cpu); + + if (gicc->header.length < ACPI_MADT_GICC_SPE) + return -ENODEV; + if (first) { + gsi = gicc->spe_interrupt; + if (!gsi) + return -ENODEV; + hetid = find_acpi_cpu_topology_hetero_id(cpu); + first = false; + } else if ((gsi != gicc->spe_interrupt) || + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { + pr_warn("ACPI: SPE must be homogeneous\n"); + return -EINVAL; + } + } + + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, + ACPI_ACTIVE_HIGH); + if (irq < 0) { + pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); + return irq; + } + + spe_resources[0].start = irq; + ret = platform_device_register(&spe_dev); + if (ret < 0) { + pr_warn("ACPI: SPE: Unable to register device\n"); + acpi_unregister_gsi(gsi); + } + + return ret; +} + static int arm_pmu_acpi_parse_irqs(void) { int irq, cpu, irq_cpu, err; @@ -279,6 +346,8 @@ static int arm_pmu_acpi_init(void) if (acpi_disabled) return 0; + arm_spe_acpi_parse_irqs(); /* failures are expected */ + ret = arm_pmu_acpi_parse_irqs(); if (ret) return ret; -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On 26/03/2019 22:39, Jeremy Linton wrote: > ACPI 6.3 adds additional fields to the MADT GICC > structure to describe SPE PPI's. We pick these out > of the cached reference to the madt_gicc structure > similarly to the core PMU code. We then create a platform > device referring to the IRQ and let the user/module loader > decide whether to load the SPE driver. > > Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> > --- > arch/arm64/include/asm/acpi.h | 3 ++ > drivers/perf/arm_pmu_acpi.c | 69 +++++++++++++++++++++++++++++++++++ > 2 files changed, 72 insertions(+) > > diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h > index 7628efbe6c12..d10399b9f998 100644 > --- a/arch/arm64/include/asm/acpi.h > +++ b/arch/arm64/include/asm/acpi.h > @@ -41,6 +41,9 @@ > (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \ > (unsigned long)(entry) + (entry)->header.length > (end)) > > +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct acpi_madt_generic_interrupt, \ > + spe_interrupt) + sizeof(u16)) > + > /* Basic configuration for ACPI */ > #ifdef CONFIG_ACPI > pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); > diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c > index 0f197516d708..a2418108eab2 100644 > --- a/drivers/perf/arm_pmu_acpi.c > +++ b/drivers/perf/arm_pmu_acpi.c > @@ -74,6 +74,73 @@ static void arm_pmu_acpi_unregister_irq(int cpu) > acpi_unregister_gsi(gsi); > } > > +static struct resource spe_resources[] = { > + { > + /* irq */ > + .flags = IORESOURCE_IRQ, > + } > +}; > + > +static struct platform_device spe_dev = { > + .name = "arm,spe-v1", > + .id = -1, > + .resource = spe_resources, > + .num_resources = ARRAY_SIZE(spe_resources) > +}; > + > +/* > + * For lack of a better place, It seems that the kernel Image size can now increase due to this part of SPE support even if ARM_SPE_PMU config is disabled. And I don't even think that ARM_SPE_PMU depends on ARM_PMU (which ARM_PMU_ACPI depends on). Thanks, John hook the normal PMU MADT walk > + * and create a SPE device if we detect a recent MADT with > + * a homogeneous PPI mapping. > + */ > +static int arm_spe_acpi_parse_irqs(void) > +{ > + int cpu, ret, irq; > + int hetid; > + u16 gsi = 0; > + bool first = true; > + > + struct acpi_madt_generic_interrupt *gicc; > + > + /* > + * sanity check all the GICC tables for the same interrupt number > + * for now we only support homogeneous ACPI/SPE machines. > + */ > + for_each_possible_cpu(cpu) { > + gicc = acpi_cpu_get_madt_gicc(cpu); > + > + if (gicc->header.length < ACPI_MADT_GICC_SPE) > + return -ENODEV; > + if (first) { > + gsi = gicc->spe_interrupt; > + if (!gsi) > + return -ENODEV; > + hetid = find_acpi_cpu_topology_hetero_id(cpu); > + first = false; > + } else if ((gsi != gicc->spe_interrupt) || > + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { > + pr_warn("ACPI: SPE must be homogeneous\n"); > + return -EINVAL; > + } > + } > + > + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, > + ACPI_ACTIVE_HIGH); > + if (irq < 0) { > + pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); > + return irq; > + } > + > + spe_resources[0].start = irq; > + ret = platform_device_register(&spe_dev); > + if (ret < 0) { > + pr_warn("ACPI: SPE: Unable to register device\n"); > + acpi_unregister_gsi(gsi); > + } > + > + return ret; > +} > + > static int arm_pmu_acpi_parse_irqs(void) > { > int irq, cpu, irq_cpu, err; > @@ -279,6 +346,8 @@ static int arm_pmu_acpi_init(void) > if (acpi_disabled) > return 0; > > + arm_spe_acpi_parse_irqs(); /* failures are expected */ > + > ret = arm_pmu_acpi_parse_irqs(); > if (ret) > return ret; > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi, First thanks for taking a look at this, second sorry about the delay... On 3/28/19 7:40 AM, John Garry wrote: > On 26/03/2019 22:39, Jeremy Linton wrote: >> ACPI 6.3 adds additional fields to the MADT GICC >> structure to describe SPE PPI's. We pick these out >> of the cached reference to the madt_gicc structure >> similarly to the core PMU code. We then create a platform >> device referring to the IRQ and let the user/module loader >> decide whether to load the SPE driver. >> >> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> >> --- >> arch/arm64/include/asm/acpi.h | 3 ++ >> drivers/perf/arm_pmu_acpi.c | 69 +++++++++++++++++++++++++++++++++++ >> 2 files changed, 72 insertions(+) >> >> diff --git a/arch/arm64/include/asm/acpi.h >> b/arch/arm64/include/asm/acpi.h >> index 7628efbe6c12..d10399b9f998 100644 >> --- a/arch/arm64/include/asm/acpi.h >> +++ b/arch/arm64/include/asm/acpi.h >> @@ -41,6 +41,9 @@ >> (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \ >> (unsigned long)(entry) + (entry)->header.length > (end)) >> >> +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct >> acpi_madt_generic_interrupt, \ >> + spe_interrupt) + sizeof(u16)) >> + >> /* Basic configuration for ACPI */ >> #ifdef CONFIG_ACPI >> pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); >> diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c >> index 0f197516d708..a2418108eab2 100644 >> --- a/drivers/perf/arm_pmu_acpi.c >> +++ b/drivers/perf/arm_pmu_acpi.c >> @@ -74,6 +74,73 @@ static void arm_pmu_acpi_unregister_irq(int cpu) >> acpi_unregister_gsi(gsi); >> } >> >> +static struct resource spe_resources[] = { >> + { >> + /* irq */ >> + .flags = IORESOURCE_IRQ, >> + } >> +}; >> + >> +static struct platform_device spe_dev = { >> + .name = "arm,spe-v1", >> + .id = -1, >> + .resource = spe_resources, >> + .num_resources = ARRAY_SIZE(spe_resources) >> +}; >> + >> +/* >> + * For lack of a better place, > > It seems that the kernel Image size can now increase due to this part of > SPE support even if ARM_SPE_PMU config is disabled. That is true, but it should be fairly small. > > And I don't even think that ARM_SPE_PMU depends on ARM_PMU (which > ARM_PMU_ACPI depends on). Well I don't think we want the generic SPE_PMU dependent on ACPI. So this chunk of code could be wrapped in a SPE_PMU_ACPI block, and made dependent on PMU_ACPI. OTOH, It seems a little trivial for that, and maybe just tweaking the PMU_ACPI documentation to mention that it also enables ACPI/SPE is a better plan. Opinions? > > Thanks, > John > > hook the normal PMU MADT walk >> + * and create a SPE device if we detect a recent MADT with >> + * a homogeneous PPI mapping. >> + */ >> +static int arm_spe_acpi_parse_irqs(void) >> +{ >> + int cpu, ret, irq; >> + int hetid; >> + u16 gsi = 0; >> + bool first = true; >> + >> + struct acpi_madt_generic_interrupt *gicc; >> + >> + /* >> + * sanity check all the GICC tables for the same interrupt number >> + * for now we only support homogeneous ACPI/SPE machines. >> + */ >> + for_each_possible_cpu(cpu) { >> + gicc = acpi_cpu_get_madt_gicc(cpu); >> + >> + if (gicc->header.length < ACPI_MADT_GICC_SPE) >> + return -ENODEV; >> + if (first) { >> + gsi = gicc->spe_interrupt; >> + if (!gsi) >> + return -ENODEV; >> + hetid = find_acpi_cpu_topology_hetero_id(cpu); >> + first = false; >> + } else if ((gsi != gicc->spe_interrupt) || >> + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { >> + pr_warn("ACPI: SPE must be homogeneous\n"); >> + return -EINVAL; >> + } >> + } >> + >> + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, >> + ACPI_ACTIVE_HIGH); >> + if (irq < 0) { >> + pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); >> + return irq; >> + } >> + >> + spe_resources[0].start = irq; >> + ret = platform_device_register(&spe_dev); >> + if (ret < 0) { >> + pr_warn("ACPI: SPE: Unable to register device\n"); >> + acpi_unregister_gsi(gsi); >> + } >> + >> + return ret; >> +} >> + >> static int arm_pmu_acpi_parse_irqs(void) >> { >> int irq, cpu, irq_cpu, err; >> @@ -279,6 +346,8 @@ static int arm_pmu_acpi_init(void) >> if (acpi_disabled) >> return 0; >> >> + arm_spe_acpi_parse_irqs(); /* failures are expected */ >> + >> ret = arm_pmu_acpi_parse_irqs(); >> if (ret) >> return ret; >> > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On 02/04/2019 20:14, Jeremy Linton wrote: > Hi, > > First thanks for taking a look at this, second sorry about the delay... > > On 3/28/19 7:40 AM, John Garry wrote: >> On 26/03/2019 22:39, Jeremy Linton wrote: >>> ACPI 6.3 adds additional fields to the MADT GICC >>> structure to describe SPE PPI's. We pick these out >>> of the cached reference to the madt_gicc structure >>> similarly to the core PMU code. We then create a platform >>> device referring to the IRQ and let the user/module loader >>> decide whether to load the SPE driver. >>> >>> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> >>> --- >>> arch/arm64/include/asm/acpi.h | 3 ++ >>> drivers/perf/arm_pmu_acpi.c | 69 +++++++++++++++++++++++++++++++++++ >>> 2 files changed, 72 insertions(+) >>> >>> diff --git a/arch/arm64/include/asm/acpi.h >>> b/arch/arm64/include/asm/acpi.h >>> index 7628efbe6c12..d10399b9f998 100644 >>> --- a/arch/arm64/include/asm/acpi.h >>> +++ b/arch/arm64/include/asm/acpi.h >>> @@ -41,6 +41,9 @@ >>> (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH >>> || \ >>> (unsigned long)(entry) + (entry)->header.length > (end)) >>> >>> +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct >>> acpi_madt_generic_interrupt, \ >>> + spe_interrupt) + sizeof(u16)) >>> + >>> /* Basic configuration for ACPI */ >>> #ifdef CONFIG_ACPI >>> pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); >>> diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c >>> index 0f197516d708..a2418108eab2 100644 >>> --- a/drivers/perf/arm_pmu_acpi.c >>> +++ b/drivers/perf/arm_pmu_acpi.c >>> @@ -74,6 +74,73 @@ static void arm_pmu_acpi_unregister_irq(int cpu) >>> acpi_unregister_gsi(gsi); >>> } >>> >>> +static struct resource spe_resources[] = { >>> + { >>> + /* irq */ >>> + .flags = IORESOURCE_IRQ, >>> + } >>> +}; >>> + >>> +static struct platform_device spe_dev = { >>> + .name = "arm,spe-v1", >>> + .id = -1, >>> + .resource = spe_resources, >>> + .num_resources = ARRAY_SIZE(spe_resources) >>> +}; >>> + >>> +/* >>> + * For lack of a better place, >> >> It seems that the kernel Image size can now increase due to this part >> of SPE support even if ARM_SPE_PMU config is disabled. > > That is true, but it should be fairly small. > >> >> And I don't even think that ARM_SPE_PMU depends on ARM_PMU (which >> ARM_PMU_ACPI depends on). > > Well I don't think we want the generic SPE_PMU dependent on ACPI. Relevant code in the SPE driver could still be built under CONFIG_ACPI. It seems that the real problem is that some necessary ACPI-related symbols used in arm_spe_acpi_parse_irqs() are not exported, while the SPE driver can be a loadable module. So > this chunk of code could be wrapped in a SPE_PMU_ACPI block, and made > dependent on PMU_ACPI. OTOH, It seems a little trivial for that, and > maybe just tweaking the PMU_ACPI documentation to mention that it also > enables ACPI/SPE is a better plan. > > Opinions? > > >> >> >> hook the normal PMU MADT walk >>> + * and create a SPE device if we detect a recent MADT with >>> + * a homogeneous PPI mapping. >>> + */ >>> +static int arm_spe_acpi_parse_irqs(void) nit: it's doing a bit more than parsing IRQs >>> +{ >>> + int cpu, ret, irq; >>> + int hetid; >>> + u16 gsi = 0; >>> + bool first = true; Thanks, John >>> + >>> + struct acpi_madt_generic_interrupt *gicc; >>> + >>> + /* >>> + * sanity check all the GICC tables for the same interrupt number >>> + * for now we only support homogeneous ACPI/SPE machines. >>> + */ >>> + for_each_possible_cpu(cpu) { >>> + gicc = acpi_cpu_get_madt_gicc(cpu); >>> + >>> + if (gicc->header.length < ACPI_MADT_GICC_SPE) >>> + return -ENODEV; >>> + if (first) { >>> + gsi = gicc->spe_interrupt; >>> + if (!gsi) >>> + return -ENODEV; >>> + hetid = find_acpi_cpu_topology_hetero_id(cpu); >>> + first = false; >>> + } else if ((gsi != gicc->spe_interrupt) || >>> + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { >>> + pr_warn("ACPI: SPE must be homogeneous\n"); >>> + return -EINVAL; >>> + } >>> + } >>> + >>> + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, >>> + ACPI_ACTIVE_HIGH); >>> + if (irq < 0) { >>> + pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); >>> + return irq; >>> + } >>> + >>> + spe_resources[0].start = irq; >>> + ret = platform_device_register(&spe_dev); >>> + if (ret < 0) { >>> + pr_warn("ACPI: SPE: Unable to register device\n"); >>> + acpi_unregister_gsi(gsi); >>> + } >>> + >>> + return ret; >>> +} >>> + >>> static int arm_pmu_acpi_parse_irqs(void) >>> { >>> int irq, cpu, irq_cpu, err; >>> @@ -279,6 +346,8 @@ static int arm_pmu_acpi_init(void) >>> if (acpi_disabled) >>> return 0; >>> >>> + arm_spe_acpi_parse_irqs(); /* failures are expected */ >>> + >>> ret = arm_pmu_acpi_parse_irqs(); >>> if (ret) >>> return ret; >>> >> >> > > > . > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
This patch series enables the Arm Statistical Profiling Extension (SPE) on ACPI platforms. This is possible because ACPI 6.3 uses a previously reserved field in the MADT to store the SPE interrupt number, similarly to how the normal PMU is described. If a consistent valid interrupt exists across all the cores in the system, a platform device is registered. That then triggers the SPE module, which runs as normal. We also add the ability to parse the PPTT for IDENTICAL cores. We then use this to sanity check the single SPE device we create. This creates a bit of a problem with respect to the specification though. The specification says that its legal for multiple tree's to exist in the PPTT. We handle this fine, but what happens in the case of multiple tree's is that the lack of a common node with IDENTICAL set forces us to assume that there are multiple non-IDENTICAL cores in the machine. v3->v4: Rebase to 5.2. Minor formatting, patch rearrangement. Add missing `inline` in static header definition. Drop ARM_SPE_ACPI and just use ARM_SPE_PMU. v2->v3: Previously a function pointer was being used to handle the more complex node checking required by the IDENTICAL flag. This version simply checks for the IDENTICAL flag and calls flag_identical() to preform the revision and next node checks. (I think after reading Raphael's comments for the Nth time, this is actually what he was suggesting, which I initially miss interpreted). Modify subject of first patch so that its clear a that its a capitalization change rather, than a logical C 'case' change. v1->v2: Wrap the code which creates the SPE device in a new CONFIG_ARM_SPE_ACPI ifdef. Move arm,spe-v1 device name into common header file Some comment/case sensitivity/function name changes. Jeremy Linton (4): ACPI/PPTT: Modify node flag detection to find last IDENTICAL ACPI/PPTT: Add function to return ACPI 6.3 Identical tokens arm_pmu: acpi: spe: Add initial MADT/SPE probing perf: arm_spe: Enable ACPI/Platform automatic module loading arch/arm64/include/asm/acpi.h | 3 ++ drivers/acpi/pptt.c | 61 +++++++++++++++++++++++++--- drivers/perf/arm_pmu_acpi.c | 75 +++++++++++++++++++++++++++++++++++ drivers/perf/arm_spe_pmu.c | 12 +++++- include/linux/acpi.h | 5 +++ include/linux/perf/arm_pmu.h | 2 + 6 files changed, 150 insertions(+), 8 deletions(-) -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
The ACPI specification implies that the IDENTICAL flag should be set on all non leaf nodes where the children are identical. This means that we need to be searching for the last node with the identical flag set rather than the first one. Since this flag is also dependent on the table revision, we need to add a bit of extra code to verify the table revision, and the next node's state in the traversal. Since we want to avoid function pointers here, lets just special case the IDENTICAL flag. Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> --- drivers/acpi/pptt.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c index b72e6afaa8fb..05344413f199 100644 --- a/drivers/acpi/pptt.c +++ b/drivers/acpi/pptt.c @@ -432,17 +432,40 @@ static void cache_setup_acpi_cpu(struct acpi_table_header *table, } } +static bool flag_identical(struct acpi_table_header *table_hdr, + struct acpi_pptt_processor *cpu) +{ + struct acpi_pptt_processor *next; + + /* heterogeneous machines must use PPTT revision > 1 */ + if (table_hdr->revision < 2) + return false; + + /* Locate the last node in the tree with IDENTICAL set */ + if (cpu->flags & ACPI_PPTT_ACPI_IDENTICAL) { + next = fetch_pptt_node(table_hdr, cpu->parent); + if (!(next && next->flags & ACPI_PPTT_ACPI_IDENTICAL)) + return true; + } + + return false; +} + /* Passing level values greater than this will result in search termination */ #define PPTT_ABORT_PACKAGE 0xFF -static struct acpi_pptt_processor *acpi_find_processor_package_id(struct acpi_table_header *table_hdr, - struct acpi_pptt_processor *cpu, - int level, int flag) +static struct acpi_pptt_processor *acpi_find_processor_tag(struct acpi_table_header *table_hdr, + struct acpi_pptt_processor *cpu, + int level, int flag) { struct acpi_pptt_processor *prev_node; while (cpu && level) { - if (cpu->flags & flag) + /* special case the identical flag to find last identical */ + if (flag == ACPI_PPTT_ACPI_IDENTICAL) { + if (flag_identical(table_hdr, cpu)) + break; + } else if (cpu->flags & flag) break; pr_debug("level %d\n", level); prev_node = fetch_pptt_node(table_hdr, cpu->parent); @@ -480,8 +503,8 @@ static int topology_get_acpi_cpu_tag(struct acpi_table_header *table, cpu_node = acpi_find_processor_node(table, acpi_cpu_id); if (cpu_node) { - cpu_node = acpi_find_processor_package_id(table, cpu_node, - level, flag); + cpu_node = acpi_find_processor_tag(table, cpu_node, + level, flag); /* * As per specification if the processor structure represents * an actual processor, then ACPI processor ID must be valid. -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
ACPI 6.3 adds a flag to indicate that child nodes are all identical cores. This is useful to authoritatively determine if a set of (possibly offline) cores are identical or not. Since the flag doesn't give us a unique id we can generate one and use it to create bitmaps of sibling nodes, or simply in a loop to determine if a subset of cores are identical. Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> --- drivers/acpi/pptt.c | 26 ++++++++++++++++++++++++++ include/linux/acpi.h | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c index 05344413f199..1e7ac0bd0d3a 100644 --- a/drivers/acpi/pptt.c +++ b/drivers/acpi/pptt.c @@ -683,3 +683,29 @@ int find_acpi_cpu_topology_package(unsigned int cpu) return find_acpi_cpu_topology_tag(cpu, PPTT_ABORT_PACKAGE, ACPI_PPTT_PHYSICAL_PACKAGE); } + +/** + * find_acpi_cpu_topology_hetero_id() - Get a core architecture tag + * @cpu: Kernel logical CPU number + * + * Determine a unique heterogeneous tag for the given CPU. CPUs with the same + * implementation should have matching tags. + * + * The returned tag can be used to group peers with identical implementation. + * + * The search terminates when a level is found with the identical implementation + * flag set or we reach a root node. + * + * Due to limitations in the PPTT data structure, there may be rare situations + * where two cores in a heterogeneous machine may be identical, but won't have + * the same tag. + * + * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found. + * Otherwise returns a value which represents a group of identical cores + * similar to this CPU. + */ +int find_acpi_cpu_topology_hetero_id(unsigned int cpu) +{ + return find_acpi_cpu_topology_tag(cpu, PPTT_ABORT_PACKAGE, + ACPI_PPTT_ACPI_IDENTICAL); +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index d315d86844e4..5bcd23e5ccd6 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1303,6 +1303,7 @@ static inline int lpit_read_residency_count_address(u64 *address) #ifdef CONFIG_ACPI_PPTT int find_acpi_cpu_topology(unsigned int cpu, int level); int find_acpi_cpu_topology_package(unsigned int cpu); +int find_acpi_cpu_topology_hetero_id(unsigned int cpu); int find_acpi_cpu_cache_topology(unsigned int cpu, int level); #else static inline int find_acpi_cpu_topology(unsigned int cpu, int level) @@ -1313,6 +1314,10 @@ static inline int find_acpi_cpu_topology_package(unsigned int cpu) { return -EINVAL; } +static inline int find_acpi_cpu_topology_hetero_id(unsigned int cpu) +{ + return -EINVAL; +} static inline int find_acpi_cpu_cache_topology(unsigned int cpu, int level) { return -EINVAL; -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
ACPI 6.3 adds additional fields to the MADT GICC structure to describe SPE PPI's. We pick these out of the cached reference to the madt_gicc structure similarly to the core PMU code. We then create a platform device referring to the IRQ and let the user/module loader decide whether to load the SPE driver. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> --- arch/arm64/include/asm/acpi.h | 3 ++ drivers/perf/arm_pmu_acpi.c | 75 +++++++++++++++++++++++++++++++++++ include/linux/perf/arm_pmu.h | 2 + 3 files changed, 80 insertions(+) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 7628efbe6c12..d10399b9f998 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -41,6 +41,9 @@ (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \ (unsigned long)(entry) + (entry)->header.length > (end)) +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct acpi_madt_generic_interrupt, \ + spe_interrupt) + sizeof(u16)) + /* Basic configuration for ACPI */ #ifdef CONFIG_ACPI pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c index 0f197516d708..f5df100bc4f4 100644 --- a/drivers/perf/arm_pmu_acpi.c +++ b/drivers/perf/arm_pmu_acpi.c @@ -74,6 +74,79 @@ static void arm_pmu_acpi_unregister_irq(int cpu) acpi_unregister_gsi(gsi); } +#if IS_ENABLED(CONFIG_ARM_SPE_PMU) +static struct resource spe_resources[] = { + { + /* irq */ + .flags = IORESOURCE_IRQ, + } +}; + +static struct platform_device spe_dev = { + .name = ARMV8_SPE_PDEV_NAME, + .id = -1, + .resource = spe_resources, + .num_resources = ARRAY_SIZE(spe_resources) +}; + +/* + * For lack of a better place, hook the normal PMU MADT walk + * and create a SPE device if we detect a recent MADT with + * a homogeneous PPI mapping. + */ +static int arm_spe_acpi_register_device(void) +{ + int cpu, hetid, irq, ret; + bool first = true; + u16 gsi = 0; + + /* + * sanity check all the GICC tables for the same interrupt number + * for now we only support homogeneous ACPI/SPE machines. + */ + for_each_possible_cpu(cpu) { + struct acpi_madt_generic_interrupt *gicc; + + gicc = acpi_cpu_get_madt_gicc(cpu); + if (gicc->header.length < ACPI_MADT_GICC_SPE) + return -ENODEV; + + if (first) { + gsi = gicc->spe_interrupt; + if (!gsi) + return -ENODEV; + hetid = find_acpi_cpu_topology_hetero_id(cpu); + first = false; + } else if ((gsi != gicc->spe_interrupt) || + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { + pr_warn("ACPI: SPE must be homogeneous\n"); + return -EINVAL; + } + } + + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, + ACPI_ACTIVE_HIGH); + if (irq < 0) { + pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); + return irq; + } + + spe_resources[0].start = irq; + ret = platform_device_register(&spe_dev); + if (ret < 0) { + pr_warn("ACPI: SPE: Unable to register device\n"); + acpi_unregister_gsi(gsi); + } + + return ret; +} +#else +static inline int arm_spe_acpi_register_device(void) +{ + return -ENODEV; +} +#endif /* CONFIG_ARM_SPE_PMU */ + static int arm_pmu_acpi_parse_irqs(void) { int irq, cpu, irq_cpu, err; @@ -279,6 +352,8 @@ static int arm_pmu_acpi_init(void) if (acpi_disabled) return 0; + arm_spe_acpi_register_device(); /* failures are expected */ + ret = arm_pmu_acpi_parse_irqs(); if (ret) return ret; diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 4641e850b204..784bc58f165a 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -175,4 +175,6 @@ void armpmu_free_irq(int irq, int cpu); #endif /* CONFIG_ARM_PMU */ +#define ARMV8_SPE_PDEV_NAME "arm,spe-v1" + #endif /* __ARM_PMU_H__ */ -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Lets add the MODULE_TABLE and platform id_table entries so that the SPE driver can attach to the ACPI platform device created by the core pmu code. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> --- drivers/perf/arm_spe_pmu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index e120f933412a..4fb65c61c8ea 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -38,6 +38,7 @@ #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/perf_event.h> +#include <linux/perf/arm_pmu.h> #include <linux/platform_device.h> #include <linux/printk.h> #include <linux/slab.h> @@ -1168,7 +1169,13 @@ static const struct of_device_id arm_spe_pmu_of_match[] = { }; MODULE_DEVICE_TABLE(of, arm_spe_pmu_of_match); -static int arm_spe_pmu_device_dt_probe(struct platform_device *pdev) +static const struct platform_device_id arm_spe_match[] = { + { ARMV8_SPE_PDEV_NAME, 0}, + { } +}; +MODULE_DEVICE_TABLE(platform, arm_spe_match); + +static int arm_spe_pmu_device_probe(struct platform_device *pdev) { int ret; struct arm_spe_pmu *spe_pmu; @@ -1228,11 +1235,12 @@ static int arm_spe_pmu_device_remove(struct platform_device *pdev) } static struct platform_driver arm_spe_pmu_driver = { + .id_table = arm_spe_match, .driver = { .name = DRVNAME, .of_match_table = of_match_ptr(arm_spe_pmu_of_match), }, - .probe = arm_spe_pmu_device_dt_probe, + .probe = arm_spe_pmu_device_probe, .remove = arm_spe_pmu_device_remove, }; -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On 2019/6/15 9:09, Jeremy Linton wrote: > This patch series enables the Arm Statistical Profiling > Extension (SPE) on ACPI platforms. > > This is possible because ACPI 6.3 uses a previously > reserved field in the MADT to store the SPE interrupt > number, similarly to how the normal PMU is described. > If a consistent valid interrupt exists across all the > cores in the system, a platform device is registered. > That then triggers the SPE module, which runs as normal. > > We also add the ability to parse the PPTT for IDENTICAL > cores. We then use this to sanity check the single SPE > device we create. This creates a bit of a problem with > respect to the specification though. The specification > says that its legal for multiple tree's to exist in the > PPTT. We handle this fine, but what happens in the > case of multiple tree's is that the lack of a common > node with IDENTICAL set forces us to assume that there > are multiple non-IDENTICAL cores in the machine. > > v3->v4: Rebase to 5.2. > Minor formatting, patch rearrangement. > Add missing `inline` in static header definition. > Drop ARM_SPE_ACPI and just use ARM_SPE_PMU. Tested on top of 5.2-rc1, I can see in the boot log: arm_spe_pmu arm,spe-v1: probed for CPUs 0-95 [max_record_sz 128, align 4, features 0x7] and I also tested perf record, and works as expected, Tested-by: Hanjun Guo <guohanjun@huawei.com> Thanks Hanjun _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, Jun 14, 2019 at 08:09:06PM -0500, Jeremy Linton wrote: > This patch series enables the Arm Statistical Profiling > Extension (SPE) on ACPI platforms. > > This is possible because ACPI 6.3 uses a previously > reserved field in the MADT to store the SPE interrupt > number, similarly to how the normal PMU is described. > If a consistent valid interrupt exists across all the > cores in the system, a platform device is registered. > That then triggers the SPE module, which runs as normal. > > We also add the ability to parse the PPTT for IDENTICAL > cores. We then use this to sanity check the single SPE > device we create. This creates a bit of a problem with > respect to the specification though. The specification > says that its legal for multiple tree's to exist in the > PPTT. We handle this fine, but what happens in the > case of multiple tree's is that the lack of a common > node with IDENTICAL set forces us to assume that there > are multiple non-IDENTICAL cores in the machine. > > v3->v4: Rebase to 5.2. > Minor formatting, patch rearrangement. > Add missing `inline` in static header definition. > Drop ARM_SPE_ACPI and just use ARM_SPE_PMU. I'm happy to take this via the arm64 perf tree for 5.3, but I'll need Acks from Raphael on the first two patches and an Ack from Lorenzo on patch 3. Cheers, Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, Jun 14, 2019 at 08:09:09PM -0500, Jeremy Linton wrote: > ACPI 6.3 adds additional fields to the MADT GICC > structure to describe SPE PPI's. We pick these out > of the cached reference to the madt_gicc structure > similarly to the core PMU code. We then create a platform > device referring to the IRQ and let the user/module loader > decide whether to load the SPE driver. > > Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> > --- > arch/arm64/include/asm/acpi.h | 3 ++ > drivers/perf/arm_pmu_acpi.c | 75 +++++++++++++++++++++++++++++++++++ > include/linux/perf/arm_pmu.h | 2 + > 3 files changed, 80 insertions(+) > > diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h > index 7628efbe6c12..d10399b9f998 100644 > --- a/arch/arm64/include/asm/acpi.h > +++ b/arch/arm64/include/asm/acpi.h > @@ -41,6 +41,9 @@ > (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \ > (unsigned long)(entry) + (entry)->header.length > (end)) > > +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct acpi_madt_generic_interrupt, \ > + spe_interrupt) + sizeof(u16)) > + > /* Basic configuration for ACPI */ > #ifdef CONFIG_ACPI > pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); > diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c > index 0f197516d708..f5df100bc4f4 100644 > --- a/drivers/perf/arm_pmu_acpi.c > +++ b/drivers/perf/arm_pmu_acpi.c > @@ -74,6 +74,79 @@ static void arm_pmu_acpi_unregister_irq(int cpu) > acpi_unregister_gsi(gsi); > } > > +#if IS_ENABLED(CONFIG_ARM_SPE_PMU) > +static struct resource spe_resources[] = { > + { > + /* irq */ > + .flags = IORESOURCE_IRQ, > + } > +}; > + > +static struct platform_device spe_dev = { > + .name = ARMV8_SPE_PDEV_NAME, > + .id = -1, > + .resource = spe_resources, > + .num_resources = ARRAY_SIZE(spe_resources) > +}; > + > +/* > + * For lack of a better place, hook the normal PMU MADT walk > + * and create a SPE device if we detect a recent MADT with > + * a homogeneous PPI mapping. > + */ > +static int arm_spe_acpi_register_device(void) > +{ > + int cpu, hetid, irq, ret; > + bool first = true; > + u16 gsi = 0; > + > + /* > + * sanity check all the GICC tables for the same interrupt number > + * for now we only support homogeneous ACPI/SPE machines. > + */ > + for_each_possible_cpu(cpu) { > + struct acpi_madt_generic_interrupt *gicc; > + > + gicc = acpi_cpu_get_madt_gicc(cpu); > + if (gicc->header.length < ACPI_MADT_GICC_SPE) > + return -ENODEV; > + > + if (first) { > + gsi = gicc->spe_interrupt; > + if (!gsi) > + return -ENODEV; > + hetid = find_acpi_cpu_topology_hetero_id(cpu); > + first = false; > + } else if ((gsi != gicc->spe_interrupt) || > + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { OK, after checking ACPI specification again and checking with people involved in dynamic ACPI table generation, I think my earlier concerns can be addressed by having a root node in any system(including multi-socket ones) with IDENTICAL flag set in that root node. With that note for archiving reasons so that we can refer people to in future, Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> -- Regards, Sudeep _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, Jun 14, 2019 at 08:09:09PM -0500, Jeremy Linton wrote: > ACPI 6.3 adds additional fields to the MADT GICC > structure to describe SPE PPI's. We pick these out > of the cached reference to the madt_gicc structure > similarly to the core PMU code. We then create a platform > device referring to the IRQ and let the user/module loader > decide whether to load the SPE driver. > > Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> > --- > arch/arm64/include/asm/acpi.h | 3 ++ > drivers/perf/arm_pmu_acpi.c | 75 +++++++++++++++++++++++++++++++++++ > include/linux/perf/arm_pmu.h | 2 + > 3 files changed, 80 insertions(+) > > diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h > index 7628efbe6c12..d10399b9f998 100644 > --- a/arch/arm64/include/asm/acpi.h > +++ b/arch/arm64/include/asm/acpi.h > @@ -41,6 +41,9 @@ > (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \ > (unsigned long)(entry) + (entry)->header.length > (end)) > > +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct acpi_madt_generic_interrupt, \ > + spe_interrupt) + sizeof(u16)) > + Nit: Do we really need this to be in a header file ? > /* Basic configuration for ACPI */ > #ifdef CONFIG_ACPI > pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); > diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c > index 0f197516d708..f5df100bc4f4 100644 > --- a/drivers/perf/arm_pmu_acpi.c > +++ b/drivers/perf/arm_pmu_acpi.c > @@ -74,6 +74,79 @@ static void arm_pmu_acpi_unregister_irq(int cpu) > acpi_unregister_gsi(gsi); > } > > +#if IS_ENABLED(CONFIG_ARM_SPE_PMU) > +static struct resource spe_resources[] = { > + { > + /* irq */ > + .flags = IORESOURCE_IRQ, > + } > +}; > + > +static struct platform_device spe_dev = { > + .name = ARMV8_SPE_PDEV_NAME, > + .id = -1, > + .resource = spe_resources, > + .num_resources = ARRAY_SIZE(spe_resources) > +}; > + > +/* > + * For lack of a better place, hook the normal PMU MADT walk > + * and create a SPE device if we detect a recent MADT with > + * a homogeneous PPI mapping. > + */ > +static int arm_spe_acpi_register_device(void) > +{ > + int cpu, hetid, irq, ret; > + bool first = true; > + u16 gsi = 0; > + > + /* > + * sanity check all the GICC tables for the same interrupt number > + * for now we only support homogeneous ACPI/SPE machines. > + */ > + for_each_possible_cpu(cpu) { > + struct acpi_madt_generic_interrupt *gicc; > + > + gicc = acpi_cpu_get_madt_gicc(cpu); > + if (gicc->header.length < ACPI_MADT_GICC_SPE) > + return -ENODEV; > + > + if (first) { > + gsi = gicc->spe_interrupt; > + if (!gsi) > + return -ENODEV; > + hetid = find_acpi_cpu_topology_hetero_id(cpu); > + first = false; > + } else if ((gsi != gicc->spe_interrupt) || > + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { > + pr_warn("ACPI: SPE must be homogeneous\n"); > + return -EINVAL; > + } > + } > + > + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, > + ACPI_ACTIVE_HIGH); > + if (irq < 0) { > + pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); > + return irq; > + } > + > + spe_resources[0].start = irq; > + ret = platform_device_register(&spe_dev); > + if (ret < 0) { > + pr_warn("ACPI: SPE: Unable to register device\n"); > + acpi_unregister_gsi(gsi); > + } > + > + return ret; > +} > +#else > +static inline int arm_spe_acpi_register_device(void) > +{ > + return -ENODEV; > +} > +#endif /* CONFIG_ARM_SPE_PMU */ > + > static int arm_pmu_acpi_parse_irqs(void) > { > int irq, cpu, irq_cpu, err; > @@ -279,6 +352,8 @@ static int arm_pmu_acpi_init(void) > if (acpi_disabled) > return 0; > > + arm_spe_acpi_register_device(); /* failures are expected */ Sounds ominous and it is false, ACPI never fails :) Nit: if we don't check the return value what's the point of returning it. Nothing problematic, if you manage to update the code before merging it is a plus. Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> > ret = arm_pmu_acpi_parse_irqs(); > if (ret) > return ret; > diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h > index 4641e850b204..784bc58f165a 100644 > --- a/include/linux/perf/arm_pmu.h > +++ b/include/linux/perf/arm_pmu.h > @@ -175,4 +175,6 @@ void armpmu_free_irq(int irq, int cpu); > > #endif /* CONFIG_ARM_PMU */ > > +#define ARMV8_SPE_PDEV_NAME "arm,spe-v1" > + > #endif /* __ARM_PMU_H__ */ > -- > 2.21.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi, Thanks for taking a look at this. On 6/18/19 12:36 PM, Lorenzo Pieralisi wrote: > On Fri, Jun 14, 2019 at 08:09:09PM -0500, Jeremy Linton wrote: >> ACPI 6.3 adds additional fields to the MADT GICC >> structure to describe SPE PPI's. We pick these out >> of the cached reference to the madt_gicc structure >> similarly to the core PMU code. We then create a platform >> device referring to the IRQ and let the user/module loader >> decide whether to load the SPE driver. >> >> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> >> --- >> arch/arm64/include/asm/acpi.h | 3 ++ >> drivers/perf/arm_pmu_acpi.c | 75 +++++++++++++++++++++++++++++++++++ >> include/linux/perf/arm_pmu.h | 2 + >> 3 files changed, 80 insertions(+) >> >> diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h >> index 7628efbe6c12..d10399b9f998 100644 >> --- a/arch/arm64/include/asm/acpi.h >> +++ b/arch/arm64/include/asm/acpi.h >> @@ -41,6 +41,9 @@ >> (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \ >> (unsigned long)(entry) + (entry)->header.length > (end)) >> >> +#define ACPI_MADT_GICC_SPE (ACPI_OFFSET(struct acpi_madt_generic_interrupt, \ >> + spe_interrupt) + sizeof(u16)) >> + > > Nit: Do we really need this to be in a header file ? Probably not, but its potentially useful as a MADT "version" check. It made sense to me to keep it close to ACPI_MADT_GICC_MIN_LENGTH for that purpose. > >> /* Basic configuration for ACPI */ >> #ifdef CONFIG_ACPI >> pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); >> diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c >> index 0f197516d708..f5df100bc4f4 100644 >> --- a/drivers/perf/arm_pmu_acpi.c >> +++ b/drivers/perf/arm_pmu_acpi.c >> @@ -74,6 +74,79 @@ static void arm_pmu_acpi_unregister_irq(int cpu) >> acpi_unregister_gsi(gsi); >> } >> >> +#if IS_ENABLED(CONFIG_ARM_SPE_PMU) >> +static struct resource spe_resources[] = { >> + { >> + /* irq */ >> + .flags = IORESOURCE_IRQ, >> + } >> +}; >> + >> +static struct platform_device spe_dev = { >> + .name = ARMV8_SPE_PDEV_NAME, >> + .id = -1, >> + .resource = spe_resources, >> + .num_resources = ARRAY_SIZE(spe_resources) >> +}; >> + >> +/* >> + * For lack of a better place, hook the normal PMU MADT walk >> + * and create a SPE device if we detect a recent MADT with >> + * a homogeneous PPI mapping. >> + */ >> +static int arm_spe_acpi_register_device(void) >> +{ >> + int cpu, hetid, irq, ret; >> + bool first = true; >> + u16 gsi = 0; >> + >> + /* >> + * sanity check all the GICC tables for the same interrupt number >> + * for now we only support homogeneous ACPI/SPE machines. >> + */ >> + for_each_possible_cpu(cpu) { >> + struct acpi_madt_generic_interrupt *gicc; >> + >> + gicc = acpi_cpu_get_madt_gicc(cpu); >> + if (gicc->header.length < ACPI_MADT_GICC_SPE) >> + return -ENODEV; >> + >> + if (first) { >> + gsi = gicc->spe_interrupt; >> + if (!gsi) >> + return -ENODEV; >> + hetid = find_acpi_cpu_topology_hetero_id(cpu); >> + first = false; >> + } else if ((gsi != gicc->spe_interrupt) || >> + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { >> + pr_warn("ACPI: SPE must be homogeneous\n"); >> + return -EINVAL; >> + } >> + } >> + >> + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, >> + ACPI_ACTIVE_HIGH); >> + if (irq < 0) { >> + pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); >> + return irq; >> + } >> + >> + spe_resources[0].start = irq; >> + ret = platform_device_register(&spe_dev); >> + if (ret < 0) { >> + pr_warn("ACPI: SPE: Unable to register device\n"); >> + acpi_unregister_gsi(gsi); >> + } >> + >> + return ret; >> +} >> +#else >> +static inline int arm_spe_acpi_register_device(void) >> +{ >> + return -ENODEV; >> +} >> +#endif /* CONFIG_ARM_SPE_PMU */ >> + >> static int arm_pmu_acpi_parse_irqs(void) >> { >> int irq, cpu, irq_cpu, err; >> @@ -279,6 +352,8 @@ static int arm_pmu_acpi_init(void) >> if (acpi_disabled) >> return 0; >> >> + arm_spe_acpi_register_device(); /* failures are expected */ > > Sounds ominous and it is false, ACPI never fails :) > > Nit: if we don't check the return value what's the point of > returning it. Dead code? It seems like we should be returning those errors, but what to do with them isn't clear. Making it hard to justify why its not just void. OTOH, if SPE were common on arm64/ACPI machines tossing a messages along the lines of "Platform doesn't support SPE" could be useful depending on how worried one is about cluttering the boot log. > > Nothing problematic, if you manage to update the code before > merging it is a plus. > > Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> > >> ret = arm_pmu_acpi_parse_irqs(); >> if (ret) >> return ret; >> diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h >> index 4641e850b204..784bc58f165a 100644 >> --- a/include/linux/perf/arm_pmu.h >> +++ b/include/linux/perf/arm_pmu.h >> @@ -175,4 +175,6 @@ void armpmu_free_irq(int irq, int cpu); >> >> #endif /* CONFIG_ARM_PMU */ >> >> +#define ARMV8_SPE_PDEV_NAME "arm,spe-v1" >> + >> #endif /* __ARM_PMU_H__ */ >> -- >> 2.21.0 >> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel