[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230220173403.avvggi4qhsxgismo@orel>
Date: Mon, 20 Feb 2023 18:34:03 +0100
From: Andrew Jones <ajones@...tanamicro.com>
To: Sunil V L <sunilvl@...tanamicro.com>
Cc: Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Paul Walmsley <paul.walmsley@...ive.com>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Len Brown <lenb@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Marc Zyngier <maz@...nel.org>,
Jonathan Corbet <corbet@....net>,
linux-riscv@...ts.infradead.org, linux-acpi@...r.kernel.org,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
Conor Dooley <conor.dooley@...rochip.com>,
Anup Patel <apatel@...tanamicro.com>,
Atish Patra <atishp@...osinc.com>,
"Rafael J . Wysocki" <rafael.j.wysocki@...el.com>
Subject: Re: [PATCH V2 11/21] RISC-V: ACPI: Add a function to retrieve the
hartid
On Thu, Feb 16, 2023 at 11:50:33PM +0530, Sunil V L wrote:
> The hartid is in the RINTC structure of the MADT table. Instead of
> parsing the ACPI table every time, cache it and provide a function
> to read it.
>
> Signed-off-by: Sunil V L <sunilvl@...tanamicro.com>
> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
> ---
> arch/riscv/include/asm/acpi.h | 8 +++++
> arch/riscv/kernel/acpi.c | 55 +++++++++++++++++++++++++++++++++++
> 2 files changed, 63 insertions(+)
>
> diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h
> index 3c3a8ac3b37a..b9d7b713fb43 100644
> --- a/arch/riscv/include/asm/acpi.h
> +++ b/arch/riscv/include/asm/acpi.h
> @@ -67,6 +67,9 @@ int acpi_numa_get_nid(unsigned int cpu);
> static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
> #endif /* CONFIG_ACPI_NUMA */
>
> +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
> +
> +u32 get_acpi_id_for_cpu(int cpu);
> #else
> static inline int acpi_get_riscv_isa(struct acpi_table_header *table,
> unsigned int cpu, const char **isa)
> @@ -74,6 +77,11 @@ static inline int acpi_get_riscv_isa(struct acpi_table_header *table,
> return -EINVAL;
> }
>
> +static inline u32 get_acpi_id_for_cpu(int cpu)
> +{
> + return -1;
> +}
> +
> #endif /* CONFIG_ACPI */
>
> #endif /*_ASM_ACPI_H*/
> diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c
> index 81d448c41714..13b26c87c136 100644
> --- a/arch/riscv/kernel/acpi.c
> +++ b/arch/riscv/kernel/acpi.c
> @@ -24,6 +24,61 @@ EXPORT_SYMBOL(acpi_disabled);
> int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */
> EXPORT_SYMBOL(acpi_pci_disabled);
>
> +static unsigned int intc_count;
> +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS];
> +
> +static int acpi_parse_madt_rintc(union acpi_subtable_headers *header, const unsigned long end)
> +{
> + struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header;
> +
> + if (!(rintc->flags & ACPI_MADT_ENABLED))
> + return 0;
> +
> + cpu_madt_rintc[intc_count++] = *rintc;
> +
> + return 0;
> +}
> +
> +static int acpi_init_rintc_array(void)
> +{
> + if (acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0) > 0)
> + return 0;
> +
> + pr_info("No valid RINTC entries exist\n");
This pr_info() could be dropped or turned into a comment and the pr_err()
below moved up here.
> + return -ENODEV;
> +}
> +
> +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
> +{
> + static bool rintc_init_done;
> + unsigned int i;
> +
> + if (!rintc_init_done) {
> + if (acpi_init_rintc_array()) {
> + pr_err("Failed to initialize RINTC array\n");
> + return NULL;
> + }
> + rintc_init_done = true;
> + }
> +
> + for (i = 0; i < intc_count; i++) {
> + if (cpu_madt_rintc[i].hart_id == cpuid_to_hartid_map(cpu))
> + return &cpu_madt_rintc[i];
> + }
Maybe I'll see the reason in later patches, but it seems odd that this
patch says we want to cache the cpuid to acpi_processor_id mapping, but
then we cache each RINTC instead and still have to do a linear search of
them to determine which one to use.
> +
> + return NULL;
> +}
> +
> +u32 get_acpi_id_for_cpu(int cpu)
> +{
> + struct acpi_madt_rintc *rintc = acpi_cpu_get_madt_rintc(cpu);
> +
> + if (!rintc)
> + return -1;
> +
> + return rintc->uid;
^ extra blank here
> +}
> +
> /*
> * __acpi_map_table() will be called before paging_init(), so early_ioremap()
> * or early_memremap() should be called here to for ACPI table mapping.
> --
> 2.34.1
>
Thanks,
drew
Powered by blists - more mailing lists