Re: [External] [PATCH RFC v2 13/17] acpi: pptt: Add helper to find a cache from id

yunhui cui <[email protected]>
Newsgroups dev.linux.lists.acpica-devel,org.infradead.lists.linux-riscv,org.kernel.vger.linux-acpi,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel
Message-ID <CAEEQ3wka26n8koB3tErRE=rgE1Bxnn7PDCjnXp2j67gdkp-=Zg@mail.gmail.com>
Hi Drew,

On Thu, Jan 29, 2026 at 4:28 AM Drew Fustini <[email protected]> wrote:
>
> Add function to find the pointer to an instance of acpi_pptt_cache.
>
> find_acpi_cache_from_id() is based on find_acpi_cache_level_from_id()
> from commit c4170570cc7f ("ACPI / PPTT: Find PPTT cache level by ID") in
> the morse/mpam/snapshot/v6.14-rc1 branch.
>
> TODO: find_acpi_cache_level_from_id() has changed since then so this
> function should be updated. In additon, there may be a simpler way for
> acpi_parse_rqsc() than adding this function to get a pointer to
> acpi_pptt_cache.
>
> Signed-off-by: Drew Fustini <[email protected]>
> ---
>  drivers/acpi/pptt.c  | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/acpi.h |  8 +++++++
>  2 files changed, 71 insertions(+)
>
> diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c
> index de5f8c018333..d1002673dc39 100644
> --- a/drivers/acpi/pptt.c
> +++ b/drivers/acpi/pptt.c
> @@ -1063,3 +1063,66 @@ int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id, cpumask_t *cpus)
>
>         return 0;
>  }
> +
> +/*
> + * find_acpi_cache_from_id() is adapted from find_acpi_cache_level_from_id()
> + * introduced by c4170570cc7f ("ACPI / PPTT: Find PPTT cache level by ID")
> + * in the morse/mpam/snapshot/v6.14-rc1 branch.
> + *
> + * TODO: find_acpi_cache_level_from_id() has changed since then so this
> + * function should be updated. In additon, there may be a simpler way for
> + * acpi_parse_rqsc() than adding this function to get a pointer to
> + * acpi_pptt_cache.
> + */
> +struct acpi_pptt_cache *find_acpi_cache_from_id(u32 cache_id)
> +{
> +       u32 acpi_cpu_id;
> +       acpi_status status;
> +       int level, cpu, num_levels;
> +       struct acpi_pptt_cache *cache;
> +       struct acpi_table_header *table;
> +       struct acpi_pptt_cache_v1 *cache_v1;
> +       struct acpi_pptt_processor *cpu_node;
> +
> +       status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
> +       if (ACPI_FAILURE(status)) {
> +               acpi_pptt_warn_missing();
> +               return NULL;
> +       }
> +
> +       if (table->revision < 3) {
> +               acpi_put_table(table);
> +               return NULL;
> +       }
> +
> +       for_each_possible_cpu(cpu) {
> +               num_levels = 0;
> +               acpi_cpu_id = get_acpi_id_for_cpu(cpu);
> +
> +               cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
> +               if (!cpu_node)
> +                       break;

break or continue?


> +               num_levels = acpi_count_levels(table, cpu_node, NULL);
> +
> +               for (level = 1; level <= num_levels; level++) {
> +                       cache = acpi_find_cache_node(table, acpi_cpu_id,
> +                                                    ACPI_PPTT_CACHE_TYPE_UNIFIED,
> +                                                    level, &cpu_node);
> +                       if (!cache)
> +                               continue;
> +
> +                       cache_v1 = ACPI_ADD_PTR(struct acpi_pptt_cache_v1,
> +                                               cache,
> +                                               sizeof(struct acpi_pptt_cache));
> +
> +                       if (cache->flags & ACPI_PPTT_CACHE_ID_VALID &&
> +                           cache_v1->cache_id == cache_id) {
> +                               acpi_put_table(table);
> +                               return cache;
> +                       }
> +               }
> +       }
> +
> +       acpi_put_table(table);
> +       return NULL;
> +}
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index fbf0c3a65f59..fee6a5059a46 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -1546,6 +1546,7 @@ int find_acpi_cpu_topology_package(unsigned int cpu);
>  int find_acpi_cpu_topology_hetero_id(unsigned int cpu);
>  void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, cpumask_t *cpus);
>  int find_acpi_cache_level_from_id(u32 cache_id);
> +struct acpi_pptt_cache *find_acpi_cache_from_id(u32 cache_id);
>  int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id, cpumask_t *cpus);
>  #else
>  static inline int acpi_pptt_cpu_is_thread(unsigned int cpu)
> @@ -1570,10 +1571,17 @@ static inline int find_acpi_cpu_topology_hetero_id(unsigned int cpu)
>  }
>  static inline void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id,
>                                                      cpumask_t *cpus) { }
> +
>  static inline int find_acpi_cache_level_from_id(u32 cache_id)
>  {
>         return -ENOENT;
>  }
> +
> +static inline struct acpi_pptt_cache *find_acpi_cache_from_id(u32 cache_id)
> +{
> +       return NULL;
> +}
> +
>  static inline int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id,
>                                                       cpumask_t *cpus)
>  {
>
> --
> 2.43.0
>

Thanks,
Yunhui
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.