From: "David E. Box" <david.e.box@linux.intel.com>
To: linux-kernel@vger.kernel.org,
platform-driver-x86@vger.kernel.org, david.e.box@linux.intel.com,
srinivas.pandruvada@linux.intel.com,
andriy.shevchenko@linux.intel.com, ilpo.jarvinen@linux.intel.com,
tony.luck@intel.com, xi.pardee@linux.intel.com
Cc: hdegoede@redhat.com
Subject: [PATCH V2] platform/x86/intel/pmt/telemetry: Add API to retrieve telemetry regions by feature
Date: Mon, 16 Jun 2025 18:40:38 -0700 [thread overview]
Message-ID: <20250617014041.2861032-15-david.e.box@linux.intel.com> (raw)
In-Reply-To: <20250617014041.2861032-1-david.e.box@linux.intel.com>
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@linux.intel.com>
---
Changes in v2:
- In pmt_telem_get_endpoint_info() use __free() for feature_group
- Add missing header for ERR_PTR()
- Split static inline function into multiple lines
drivers/platform/x86/intel/pmt/telemetry.c | 89 +++++++++++++++++++++-
include/linux/intel_vsec.h | 18 +++++
2 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/x86/intel/pmt/telemetry.c
index 58d06749e417..a4dfca6cac19 100644
--- a/drivers/platform/x86/intel/pmt/telemetry.c
+++ b/drivers/platform/x86/intel/pmt/telemetry.c
@@ -9,16 +9,21 @@
*/
#include <linux/auxiliary_bus.h>
+#include <linux/bitops.h>
+#include <linux/cleanup.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 +214,87 @@ 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 __free(kfree) = NULL;
+ 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)
+ return ERR_PTR(ret);
+
+ region++;
+ }
+
+ kref_init(&feature_group->kref);
+
+ return no_free_ptr(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@linux.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..0d127d3a18b3 100644
--- a/include/linux/intel_vsec.h
+++ b/include/linux/intel_vsec.h
@@ -4,6 +4,7 @@
#include <linux/auxiliary_bus.h>
#include <linux/bits.h>
+#include <linux/err.h>
#include <linux/intel_pmt_features.h>
/*
@@ -220,4 +221,21 @@ 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);
+}
+
+static inline void
+intel_pmt_put_feature_group(struct pmt_feature_group *feature_group) {}
+#endif
+
#endif
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
prerequisite-patch-id: b38c42e1e0ad4a9d7c2bad26bafc44e4710b221e
prerequisite-patch-id: 8c78f389183292e444aea2450bbd9c49cbd2b276
prerequisite-patch-id: cde36b6a28c7c6b8fce58aecfef7f442ff6d1e50
prerequisite-patch-id: 0657fb342c016c1aa47501c17a69e78178371c02
prerequisite-patch-id: a9d8e0500e5eda1146a3203d70375ae2b2b25a9d
prerequisite-patch-id: c8b1a9d4e48c13353cc41b815b69141118b3d457
prerequisite-patch-id: 6f676b5e6d90b87fb8e39154998cc06f0cd99914
prerequisite-patch-id: 4aa05c3ad0e61fe133ee82d84831a451ec551f5d
prerequisite-patch-id: d92f2986c580d720420a371923f788265d22dc02
prerequisite-patch-id: f281f452c8cdc2545abc881f4761a79b633b2847
prerequisite-patch-id: 01215266d8d3e0450ed991feb1d17a9b54ed771b
prerequisite-patch-id: ee9f8ca9f1357aebd5f240a1b089be1f0e3258e9
prerequisite-patch-id: 82ee7c3801bca82569d1cf8febcab7ded56e5bd1
--
2.43.0
next prev parent reply other threads:[~2025-06-17 1:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 1:40 [PATCH V2 00/15] Intel VSEC/PMT: Introduce Discovery Driver David E. Box
2025-06-17 1:40 ` [PATCH V2 01/15] MAINTAINERS: Add link to documentation of Intel PMT ABI David E. Box
2025-06-17 1:40 ` [PATCH V2 02/15] platform/x86/intel/vsec: Add private data for per-device data David E. Box
2025-06-17 1:40 ` [PATCH V2 03/15] platform/x86/intel/vsec: Create wrapper to walk PCI config space David E. Box
2025-06-30 12:02 ` Ilpo Järvinen
2025-06-30 20:51 ` David Box
2025-06-17 1:40 ` [PATCH V2 04/15] platform/x86/intel/vsec: Add device links to enforce dependencies David E. Box
2025-06-30 12:06 ` Ilpo Järvinen
2025-06-30 20:47 ` David Box
2025-06-17 1:40 ` [PATCH V2 05/15] platform/x86/intel/vsec: Skip absent features during initialization David E. Box
2025-06-17 1:40 ` [PATCH V2 06/15] platform/x86/intel/vsec: Skip driverless features David E. Box
2025-06-17 1:40 ` [PATCH V2 07/15] platform/x86/intel/vsec: Add new Discovery feature David E. Box
2025-06-17 1:40 ` [PATCH V2 08/15] platform/x86/intel/pmt: Add PMT Discovery driver David E. Box
2025-06-17 1:40 ` [PATCH V2 09/15] docs: Add ABI documentation for intel_pmt feature directories David E. Box
2025-06-17 1:40 ` [PATCH V2 10/15] platform/x86/intel/tpmi: Relocate platform info to intel_vsec.h David E. Box
2025-06-17 1:40 ` [PATCH V2 11/15] platform/x86/intel/vsec: Set OOBMSM to CPU mapping David E. Box
2025-06-30 11:55 ` Ilpo Järvinen
2025-06-30 20:56 ` David Box
2025-06-17 1:40 ` [PATCH V2 12/15] platform/x86/intel/tpmi: Get OOBMSM CPU mapping from TPMI David E. Box
2025-06-17 1:40 ` [PATCH V2 13/15] platform/x86/intel/pmt/discovery: Get telemetry attributes David E. Box
2025-06-17 1:40 ` David E. Box [this message]
2025-06-30 12:08 ` [PATCH V2] platform/x86/intel/pmt/telemetry: Add API to retrieve telemetry regions by feature Ilpo Järvinen
2025-06-17 1:40 ` [PATCH V2 15/15] platform/x86/intel/pmt: KUNIT test for PMT Enhanced Discovery API David E. Box
2025-06-25 20:22 ` [PATCH V2 00/15] Intel VSEC/PMT: Introduce Discovery Driver Luck, Tony
2025-06-27 19:08 ` David Box
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250617014041.2861032-15-david.e.box@linux.intel.com \
--to=david.e.box@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=tony.luck@intel.com \
--cc=xi.pardee@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).