* Shrikanth Hegde <[email protected]> [2026-11-18 22:06:36]:
> PowerPC device trees commonly describe a unified cache using d-cache-*
> properties.
>
> For example, Power11 L2 and L3 cache nodes have cache-unified together
> with properties such as:
>
> d-cache-size
> d-cache-line-size
> d-cache-sets
> ---
> drivers/base/cacheinfo.c | 24 +++++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
> index 10a9bbce899e..4a23377e9312 100644
> --- a/drivers/base/cacheinfo.c
> +++ b/drivers/base/cacheinfo.c
> @@ -148,11 +148,21 @@ static const struct cache_type_info cache_type_info[] =
> {
> },
> };
>
> -static inline int get_cacheinfo_idx(enum cache_type type)
> +static inline int get_cacheinfo_idx(enum cache_type type, struct device_node
> *np)
> {
> - if (type == CACHE_TYPE_UNIFIED)
> - return 0;
> - return type;
> + if (type != CACHE_TYPE_UNIFIED)
> + return type;
> +
> + /*
> + * Some device-tree bindings describe unified caches using
> + * d-cache-* properties. Select the data-cache property set
> + * without changing the cache leaf type.
> + */
> + if (!of_property_present(np, "cache-size") &&
Is it better to check if the device node np is NULL before doing the
of_property_present?
> + of_property_present(np, "d-cache-size"))
> + return CACHE_TYPE_DATA;
> +
> + return 0;
> }
>
> static void cache_size(struct cacheinfo *this_leaf, struct device_node *np)
> @@ -160,7 +170,7 @@ static void cache_size(struct cacheinfo *this_leaf,
> struct device_node *np)
> const char *propname;
> int ct_idx;
>
> - ct_idx = get_cacheinfo_idx(this_leaf->type);
> + ct_idx = get_cacheinfo_idx(this_leaf->type, np);
> propname = cache_type_info[ct_idx].size_prop;
>
> of_property_read_u32(np, propname, &this_leaf->size);
> @@ -172,7 +182,7 @@ static void cache_get_line_size(struct cacheinfo
> *this_leaf,
> {
> int i, lim, ct_idx;
>
> - ct_idx = get_cacheinfo_idx(this_leaf->type);
> + ct_idx = get_cacheinfo_idx(this_leaf->type, np);
> lim = ARRAY_SIZE(cache_type_info[ct_idx].line_size_props);
>
> for (i = 0; i < lim; i++) {
> @@ -194,7 +204,7 @@ static void cache_nr_sets(struct cacheinfo *this_leaf,
> struct device_node *np)
> const char *propname;
> int ct_idx;
>
> - ct_idx = get_cacheinfo_idx(this_leaf->type);
> + ct_idx = get_cacheinfo_idx(this_leaf->type, np);
> propname = cache_type_info[ct_idx].nr_sets_prop;
>
> of_property_read_u32(np, propname, &this_leaf->number_of_sets);
> --
> 2.54.0
>
--
Thanks and Regards
Srikar Dronamraju