[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8433cbaf-253b-cc7f-77d4-fa48142aa603@linux.intel.com>
Date: Tue, 20 May 2025 18:05:50 +0300 (EEST)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: "David E. Box" <david.e.box@...ux.intel.com>
cc: LKML <linux-kernel@...r.kernel.org>, platform-driver-x86@...r.kernel.org,
srinivas.pandruvada@...ux.intel.com,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>, tony.luck@...el.com,
xi.pardee@...ux.intel.com, Hans de Goede <hdegoede@...hat.com>
Subject: Re: [PATCH 14/15] platform/x86/intel/pmt/telemetry: Add API to
retrieve telemetry regions by feature
On Wed, 30 Apr 2025, David E. Box wrote:
> Introduce a new API, intel_pmt_get_regions_by_feature(), that gathers
> telemetry regions based on a provided capability flag. This API enables
> retrieval of regions with various capabilities (for example, RMID-based
> telemetry) and provides a unified interface for accessing them. Resource
> management is handled via reference counting using
> intel_pmt_put_feature_group().
>
> Signed-off-by: David E. Box <david.e.box@...ux.intel.com>
> ---
> drivers/platform/x86/intel/pmt/telemetry.c | 89 +++++++++++++++++++++-
> include/linux/intel_vsec.h | 15 ++++
> 2 files changed, 103 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/x86/intel/pmt/telemetry.c
> index 58d06749e417..d071dca4a689 100644
> --- a/drivers/platform/x86/intel/pmt/telemetry.c
> +++ b/drivers/platform/x86/intel/pmt/telemetry.c
> @@ -9,16 +9,20 @@
> */
>
> #include <linux/auxiliary_bus.h>
> +#include <linux/bitops.h>
> +#include <linux/err.h>
> #include <linux/intel_pmt_features.h>
> #include <linux/intel_vsec.h>
> #include <linux/kernel.h>
> #include <linux/kref.h>
> #include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/overflow.h>
> #include <linux/pci.h>
> #include <linux/slab.h>
> #include <linux/types.h>
> #include <linux/uaccess.h>
> -#include <linux/overflow.h>
> +#include <linux/xarray.h>
>
> #include "class.h"
>
> @@ -209,6 +213,88 @@ int pmt_telem_get_endpoint_info(int devid, struct telem_endpoint_info *info)
> }
> EXPORT_SYMBOL_NS_GPL(pmt_telem_get_endpoint_info, "INTEL_PMT_TELEMETRY");
>
> +static int pmt_copy_region(struct telemetry_region *region,
> + struct intel_pmt_entry *entry)
> +{
> +
> + struct oobmsm_plat_info *plat_info;
> +
> + plat_info = intel_vsec_get_mapping(entry->ep->pcidev);
> + if (IS_ERR(plat_info))
> + return PTR_ERR(plat_info);
> +
> + region->plat_info = *plat_info;
> + region->guid = entry->guid;
> + region->addr = entry->ep->base;
> + region->size = entry->size;
> + region->num_rmids = entry->num_rmids;
> +
> + return 0;
> +}
> +
> +static void pmt_feature_group_release(struct kref *kref)
> +{
> + struct pmt_feature_group *feature_group;
> +
> + feature_group = container_of(kref, struct pmt_feature_group, kref);
> + kfree(feature_group);
> +}
> +
> +struct pmt_feature_group *intel_pmt_get_regions_by_feature(enum pmt_feature_id id)
> +{
> + struct pmt_feature_group *feature_group;
> + struct telemetry_region *region;
> + struct intel_pmt_entry *entry;
> + unsigned long idx;
> + int count = 0;
> + size_t size;
> +
> + if (!pmt_feature_id_is_valid(id))
> + return ERR_PTR(-EINVAL);
> +
> + guard(mutex)(&ep_lock);
> + xa_for_each(&telem_array, idx, entry) {
> + if (entry->feature_flags & BIT(id))
> + count++;
> + }
> +
> + if (!count)
> + return ERR_PTR(-ENOENT);
> +
> + size = struct_size(feature_group, regions, count);
> + feature_group = kzalloc(size, GFP_KERNEL);
> + if (!feature_group)
> + return ERR_PTR(-ENOMEM);
> +
> + feature_group->count = count;
> +
> + region = feature_group->regions;
> + xa_for_each(&telem_array, idx, entry) {
> + int ret;
> +
> + if (!(entry->feature_flags & BIT(id)))
> + continue;
> +
> + ret = pmt_copy_region(region, entry);
> + if (ret) {
> + kfree(feature_group);
Use __free() instead.
> + return ERR_PTR(ret);
> + }
> + region++;
> + }
> +
> + kref_init(&feature_group->kref);
> +
> + return feature_group;
> +}
> +EXPORT_SYMBOL(intel_pmt_get_regions_by_feature);
> +
> +void intel_pmt_put_feature_group(struct pmt_feature_group *feature_group)
> +{
> + kref_put(&feature_group->kref, pmt_feature_group_release);
> +}
> +EXPORT_SYMBOL(intel_pmt_put_feature_group);
> +
> int pmt_telem_read(struct telem_endpoint *ep, u32 id, u64 *data, u32 count)
> {
> u32 offset, size;
> @@ -353,3 +439,4 @@ MODULE_AUTHOR("David E. Box <david.e.box@...ux.intel.com>");
> MODULE_DESCRIPTION("Intel PMT Telemetry driver");
> MODULE_LICENSE("GPL v2");
> MODULE_IMPORT_NS("INTEL_PMT");
> +MODULE_IMPORT_NS("INTEL_VSEC");
> diff --git a/include/linux/intel_vsec.h b/include/linux/intel_vsec.h
> index f63e67398a8e..f41d2ec974fd 100644
> --- a/include/linux/intel_vsec.h
> +++ b/include/linux/intel_vsec.h
> @@ -220,4 +220,19 @@ static inline struct oobmsm_plat_info *intel_vsec_get_mapping(struct pci_dev *pd
> return ERR_PTR(-ENODEV);
> }
> #endif
> +
> +#if IS_ENABLED(CONFIG_INTEL_PMT_TELEMETRY)
> +struct pmt_feature_group *
> +intel_pmt_get_regions_by_feature(enum pmt_feature_id id);
> +
> +void intel_pmt_put_feature_group(struct pmt_feature_group *feature_group);
> +#else
> +static inline struct pmt_feature_group *
> +intel_pmt_get_regions_by_feature(enum pmt_feature_id id)
> +{ return ERR_PTR(-ENODEV); }
Please add include for ERR_PTR().
Change this to follow the normal function coding style even if it takes
2 lines more that way. :-)
> +
> +static inline void
> +intel_pmt_put_feature_group(struct pmt_feature_group *feature_group) {}
> +#endif
> +
> #endif
>
--
i.
Powered by blists - more mailing lists