From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 619C4C74A5B for ; Wed, 15 Mar 2023 18:34:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231720AbjCOSeM (ORCPT ); Wed, 15 Mar 2023 14:34:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbjCOSeK (ORCPT ); Wed, 15 Mar 2023 14:34:10 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81FB928D34; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905248; x=1710441248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hHV55N0QiZMcT4V3m9CPVkpMG+H53YsJVo4BOQ9V6kk=; b=O2zr4KPgXKfEJTuZdo8iE4lUHCHMtrEfWJV4ZKnc99JHmjA6/Nyyff7M fWg/asdb3ikfVHuMkqRFjEMMU+iHQ0OFkvQ74K0nKXSVGGaizHHeN8xm2 pG2HZ+ePuWbAc/6aePz6gP979/YI+usoYwW5QIbUN39Ix7/uN6SlBXeIP maonZJ3QB0Bh7TLbsj1a/zdDstJ6zuAKL9FdbWdgAfd8saHMAy2yEaVdl FoyM25YYmlhga33ms0nmqis5tWTDzdtwxrp/9XT5E9Ets2qNgapUbcwLk WVZzzmOlpvz+vCm75lamY5YRgjDoLVO3u2lIqTNJm5TxqjTzbUtlfod5n w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154523" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154523" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435199" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435199" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:06 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 64DF3580BF2; Wed, 15 Mar 2023 11:34:06 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 01/11] platform/x86/intel/vsec: Add intel_vsec_register Date: Wed, 15 Mar 2023 11:33:55 -0700 Message-Id: <20230315183405.2465630-2-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Gayatri Kammela Intel PCIe VSEC capabilities may be emulated in the MMIO space of other Intel devices like the Power Management Controller (PMC) SSRAM device. Add and export intel_vsec_register to allow those capabilities to be registered by other drivers. Reuses the existing intel_vsec_walk_header function which already creates entries from device data in lieu of a config space (used by DG1). Add a check to ensure that the memory region is available before creating a VSEC auxiliary device. Signed-off-by: Gayatri Kammela Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 2 +- drivers/platform/x86/intel/pmt/class.h | 5 ++- drivers/platform/x86/intel/vsec.c | 56 +++++++++----------------- drivers/platform/x86/intel/vsec.h | 51 ++++++++++++++++++++++- 4 files changed, 73 insertions(+), 41 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/= intel/pmt/class.c index 46598dcb634a..9f505c6ef278 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -31,7 +31,7 @@ bool intel_pmt_is_early_client_hw(struct device *dev) * differences from the server platforms (which use the Out Of Band * Management Services Module OOBMSM). */ - return !!(ivdev->info->quirks & VSEC_QUIRK_EARLY_HW); + return !!(ivdev->quirks & VSEC_QUIRK_EARLY_HW); } EXPORT_SYMBOL_GPL(intel_pmt_is_early_client_hw); =20 diff --git a/drivers/platform/x86/intel/pmt/class.h b/drivers/platform/x86/= intel/pmt/class.h index db11d58867ce..17bc40b77efc 100644 --- a/drivers/platform/x86/intel/pmt/class.h +++ b/drivers/platform/x86/intel/pmt/class.h @@ -2,11 +2,10 @@ #ifndef _INTEL_PMT_CLASS_H #define _INTEL_PMT_CLASS_H =20 -#include -#include #include #include #include +#include =20 #include "../vsec.h" =20 @@ -18,6 +17,8 @@ #define GET_BIR(v) ((v) & GENMASK(2, 0)) #define GET_ADDRESS(v) ((v) & GENMASK(31, 3)) =20 +struct xarray; + struct intel_pmt_entry { struct bin_attribute pmt_bin_attr; struct kobject *kobj; diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel= /vsec.c index 13decf36c6de..a22354ee6ce3 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -24,13 +24,6 @@ =20 #include "vsec.h" =20 -/* Intel DVSEC offsets */ -#define INTEL_DVSEC_ENTRIES 0xA -#define INTEL_DVSEC_SIZE 0xB -#define INTEL_DVSEC_TABLE 0xC -#define INTEL_DVSEC_TABLE_BAR(x) ((x) & GENMASK(2, 0)) -#define INTEL_DVSEC_TABLE_OFFSET(x) ((x) & GENMASK(31, 3)) -#define TABLE_OFFSET_SHIFT 3 #define PMT_XA_START 0 #define PMT_XA_MAX INT_MAX #define PMT_XA_LIMIT XA_LIMIT(PMT_XA_START, PMT_XA_MAX) @@ -39,34 +32,6 @@ static DEFINE_IDA(intel_vsec_ida); static DEFINE_IDA(intel_vsec_sdsi_ida); static DEFINE_XARRAY_ALLOC(auxdev_array); =20 -/** - * struct intel_vsec_header - Common fields of Intel VSEC and DVSEC regist= ers. - * @rev: Revision ID of the VSEC/DVSEC register space - * @length: Length of the VSEC/DVSEC register space - * @id: ID of the feature - * @num_entries: Number of instances of the feature - * @entry_size: Size of the discovery table for each feature - * @tbir: BAR containing the discovery tables - * @offset: BAR offset of start of the first discovery table - */ -struct intel_vsec_header { - u8 rev; - u16 length; - u16 id; - u8 num_entries; - u8 entry_size; - u8 tbir; - u32 offset; -}; - -enum intel_vsec_id { - VSEC_ID_TELEMETRY =3D 2, - VSEC_ID_WATCHER =3D 3, - VSEC_ID_CRASHLOG =3D 4, - VSEC_ID_SDSI =3D 65, - VSEC_ID_TPMI =3D 66, -}; - static enum intel_vsec_id intel_vsec_allow_list[] =3D { VSEC_ID_TELEMETRY, VSEC_ID_WATCHER, @@ -241,12 +206,21 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, s= truct intel_vsec_header *he header->offset + i * (header->entry_size * sizeof(u32)); tmp->end =3D tmp->start + (header->entry_size * sizeof(u32)) - 1; tmp->flags =3D IORESOURCE_MEM; + + /* Check resource is not in use */ + if (!request_mem_region(tmp->start, resource_size(tmp), "")) { + kfree(res); + kfree(intel_vsec_dev); + return -EBUSY; + } + + release_mem_region(tmp->start, resource_size(tmp)); } =20 intel_vsec_dev->pcidev =3D pdev; intel_vsec_dev->resource =3D res; intel_vsec_dev->num_resources =3D header->num_entries; - intel_vsec_dev->info =3D info; + intel_vsec_dev->quirks =3D info->quirks; =20 if (header->id =3D=3D VSEC_ID_SDSI) intel_vsec_dev->ida =3D &intel_vsec_sdsi_ida; @@ -371,6 +345,16 @@ static bool intel_vsec_walk_vsec(struct pci_dev *pdev, return have_devices; } =20 +void intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info) +{ + if (!pdev || !info) + return; + + intel_vsec_walk_header(pdev, info); +} +EXPORT_SYMBOL_NS_GPL(intel_vsec_register, INTEL_VSEC); + static int intel_vsec_pci_probe(struct pci_dev *pdev, const struct pci_dev= ice_id *id) { struct intel_vsec_platform_info *info; diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel= /vsec.h index ae8fe92c5595..f600d6fe0830 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -1,13 +1,49 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _VSEC_H -#define _VSEC_H +#ifndef _INTEL_VSEC_H +#define _INTEL_VSEC_H =20 #include #include =20 +/* Intel DVSEC offsets */ +#define INTEL_DVSEC_ENTRIES 0xA +#define INTEL_DVSEC_SIZE 0xB +#define INTEL_DVSEC_TABLE 0xC +#define INTEL_DVSEC_TABLE_BAR(x) ((x) & GENMASK(2, 0)) +#define INTEL_DVSEC_TABLE_OFFSET(x) ((x) & GENMASK(31, 3)) +#define TABLE_OFFSET_SHIFT 3 + struct pci_dev; struct resource; =20 +enum intel_vsec_id { + VSEC_ID_TELEMETRY =3D 2, + VSEC_ID_WATCHER =3D 3, + VSEC_ID_CRASHLOG =3D 4, + VSEC_ID_SDSI =3D 65, + VSEC_ID_TPMI =3D 66, +}; + +/** + * struct intel_vsec_header - Common fields of Intel VSEC and DVSEC regist= ers. + * @rev: Revision ID of the VSEC/DVSEC register space + * @length: Length of the VSEC/DVSEC register space + * @id: ID of the feature + * @num_entries:Number of instances of the feature + * @entry_size: Size of the discovery table for each feature + * @tbir: BAR containing the discovery tables + * @offset: BAR offset of start of the first discovery table + */ +struct intel_vsec_header { + u8 rev; + u16 length; + u16 id; + u8 num_entries; + u8 entry_size; + u8 tbir; + u32 offset; +}; + enum intel_vsec_quirks { /* Watcher feature not supported */ VSEC_QUIRK_NO_WATCHER =3D BIT(0), @@ -40,6 +76,7 @@ struct intel_vsec_device { int num_resources; void *priv_data; size_t priv_data_size; + unsigned long quirks; }; =20 int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, @@ -55,4 +92,14 @@ static inline struct intel_vsec_device *auxdev_to_ivdev(= struct auxiliary_device { return container_of(auxdev, struct intel_vsec_device, auxdev); } + +#if IS_ENABLED(CONFIG_INTEL_VSEC) +void intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info); +#else +static inline void +intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info) {} +#endif + #endif --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43974C61DA4 for ; Wed, 15 Mar 2023 18:34:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232005AbjCOSeV (ORCPT ); Wed, 15 Mar 2023 14:34:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231725AbjCOSeM (ORCPT ); Wed, 15 Mar 2023 14:34:12 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F32ABDFB; Wed, 15 Mar 2023 11:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905250; x=1710441250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+M93RTmQljP8okVyTKg1YF0nbH2IJeJvC34zMCSMUuA=; b=TeS5Z0iIqGhZf5RvX8zIjroIlUrGZBp2uqc04cnbhLb927eF43az2FnC C8GKS6SoULy8tw2odpCVRPoNUrsqhRsW9UEiCfHjEfvybO/Os14ERmhhm M9RIkztLfrZt70nhY390B7iIZAt/5SsPzuUJeV0kHJbjPsgditShelh7w eh4bP6WbttxnZRUKQ8vA5mP3ksJ/oCfye6sb9cK2zILibIpZFVz7f1K1b Mg2CMmkexHJBGM3euRsgaSXbFZR+5FudFzQnRAIJrpR3cYTPps0FVikCD KiduWAbybgQTCGeWPla7xVCLp8bvlfi2LU2dmV6p9a8Po+pZJogaqUP2G w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154528" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154528" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435202" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435202" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:06 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id A01C5580D29; Wed, 15 Mar 2023 11:34:06 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 02/11] platform/x86/intel/vsec: Explicitly enable capabilities Date: Wed, 15 Mar 2023 11:33:56 -0700 Message-Id: <20230315183405.2465630-3-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Any discovered Intel VSEC/DVSEC capabilities are enabled by default and only get disabled by quirk. Instead, remove such quirks and only enable support for capabilities that have been explicitly added to a new capabilities field. While here, also reorder the device info structures alphabetically. Signed-off-by: David E. Box --- drivers/platform/x86/intel/vsec.c | 65 +++++++++++++------------------ drivers/platform/x86/intel/vsec.h | 11 +++++- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel= /vsec.c index a22354ee6ce3..0d5cf250e288 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -32,14 +32,6 @@ static DEFINE_IDA(intel_vsec_ida); static DEFINE_IDA(intel_vsec_sdsi_ida); static DEFINE_XARRAY_ALLOC(auxdev_array); =20 -static enum intel_vsec_id intel_vsec_allow_list[] =3D { - VSEC_ID_TELEMETRY, - VSEC_ID_WATCHER, - VSEC_ID_CRASHLOG, - VSEC_ID_SDSI, - VSEC_ID_TPMI, -}; - static const char *intel_vsec_name(enum intel_vsec_id id) { switch (id) { @@ -63,26 +55,19 @@ static const char *intel_vsec_name(enum intel_vsec_id i= d) } } =20 -static bool intel_vsec_allowed(u16 id) -{ - int i; - - for (i =3D 0; i < ARRAY_SIZE(intel_vsec_allow_list); i++) - if (intel_vsec_allow_list[i] =3D=3D id) - return true; - - return false; -} - -static bool intel_vsec_disabled(u16 id, unsigned long quirks) +static bool intel_vsec_supported(u16 id, unsigned long caps) { switch (id) { + case VSEC_ID_TELEMETRY: + return !!(caps & VSEC_CAP_TELEMETRY); case VSEC_ID_WATCHER: - return !!(quirks & VSEC_QUIRK_NO_WATCHER); - + return !!(caps & VSEC_CAP_WATCHER); case VSEC_ID_CRASHLOG: - return !!(quirks & VSEC_QUIRK_NO_CRASHLOG); - + return !!(caps & VSEC_CAP_CRASHLOG); + case VSEC_ID_SDSI: + return !!(caps & VSEC_CAP_SDSI); + case VSEC_ID_TPMI: + return !!(caps & VSEC_CAP_TPMI); default: return false; } @@ -170,7 +155,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, str= uct intel_vsec_header *he unsigned long quirks =3D info->quirks; int i; =20 - if (!intel_vsec_allowed(header->id) || intel_vsec_disabled(header->id, qu= irks)) + if (!intel_vsec_supported(header->id, info->caps)) return -EINVAL; =20 if (!header->num_entries) { @@ -234,14 +219,14 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, s= truct intel_vsec_header *he static bool intel_vsec_walk_header(struct pci_dev *pdev, struct intel_vsec_platform_info *info) { - struct intel_vsec_header **header =3D info->capabilities; + struct intel_vsec_header **header =3D info->headers; bool have_devices =3D false; int ret; =20 for ( ; *header; header++) { ret =3D intel_vsec_add_dev(pdev, *header, info); if (ret) - dev_info(&pdev->dev, "Could not add device for DVSEC id %d\n", + dev_info(&pdev->dev, "Could not add device for VSEC id %d\n", (*header)->id); else have_devices =3D true; @@ -386,12 +371,6 @@ static int intel_vsec_pci_probe(struct pci_dev *pdev, = const struct pci_device_id return 0; } =20 -/* TGL info */ -static const struct intel_vsec_platform_info tgl_info =3D { - .quirks =3D VSEC_QUIRK_NO_WATCHER | VSEC_QUIRK_NO_CRASHLOG | - VSEC_QUIRK_TABLE_SHIFT | VSEC_QUIRK_EARLY_HW, -}; - /* DG1 info */ static struct intel_vsec_header dg1_telemetry =3D { .length =3D 0x10, @@ -402,19 +381,31 @@ static struct intel_vsec_header dg1_telemetry =3D { .offset =3D 0x466000, }; =20 -static struct intel_vsec_header *dg1_capabilities[] =3D { +static struct intel_vsec_header *dg1_headers[] =3D { &dg1_telemetry, NULL }; =20 static const struct intel_vsec_platform_info dg1_info =3D { - .capabilities =3D dg1_capabilities, + .caps =3D VSEC_CAP_TELEMETRY, + .headers =3D dg1_headers, .quirks =3D VSEC_QUIRK_NO_DVSEC | VSEC_QUIRK_EARLY_HW, }; =20 /* MTL info */ static const struct intel_vsec_platform_info mtl_info =3D { - .quirks =3D VSEC_QUIRK_NO_WATCHER | VSEC_QUIRK_NO_CRASHLOG, + .caps =3D VSEC_CAP_TELEMETRY, +}; + +/* OOBMSM info */ +static const struct intel_vsec_platform_info oobmsm_info =3D { + .caps =3D VSEC_CAP_TELEMETRY | VSEC_CAP_SDSI | VSEC_CAP_TPMI, +}; + +/* TGL info */ +static const struct intel_vsec_platform_info tgl_info =3D { + .caps =3D VSEC_CAP_TELEMETRY, + .quirks =3D VSEC_QUIRK_TABLE_SHIFT | VSEC_QUIRK_EARLY_HW, }; =20 #define PCI_DEVICE_ID_INTEL_VSEC_ADL 0x467d @@ -429,7 +420,7 @@ static const struct pci_device_id intel_vsec_pci_ids[] = =3D { { PCI_DEVICE_DATA(INTEL, VSEC_DG1, &dg1_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_MTL_M, &mtl_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_MTL_S, &mtl_info) }, - { PCI_DEVICE_DATA(INTEL, VSEC_OOBMSM, &(struct intel_vsec_platform_info) = {}) }, + { PCI_DEVICE_DATA(INTEL, VSEC_OOBMSM, &oobmsm_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_RPL, &tgl_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_TGL, &tgl_info) }, { } diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel= /vsec.h index f600d6fe0830..54fdea93f762 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -61,9 +61,18 @@ enum intel_vsec_quirks { VSEC_QUIRK_EARLY_HW =3D BIT(4), }; =20 +enum intel_vsec_capabilities { + VSEC_CAP_TELEMETRY =3D BIT(0), + VSEC_CAP_WATCHER =3D BIT(1), + VSEC_CAP_CRASHLOG =3D BIT(2), + VSEC_CAP_SDSI =3D BIT(3), + VSEC_CAP_TPMI =3D BIT(4), +}; + /* Platform specific data */ struct intel_vsec_platform_info { - struct intel_vsec_header **capabilities; + struct intel_vsec_header **headers; + unsigned long caps; unsigned long quirks; }; =20 --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98698C61DA4 for ; Wed, 15 Mar 2023 18:34:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232049AbjCOSeY (ORCPT ); Wed, 15 Mar 2023 14:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231751AbjCOSeM (ORCPT ); Wed, 15 Mar 2023 14:34:12 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F55615CAB; Wed, 15 Mar 2023 11:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905250; x=1710441250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tiBxACl1aCLc9qaOAQl3+p3ktpJtGcq9KNcC9SlIB0c=; b=W+Ydu8WopGlDsAQbUOsq0rQsWlVnGIe9lCFf8d1lWshEIHMmprTOypS8 6cmHpYw0kO9E5qdV4Lcf05wwcf6dEkwDFSAjoDuAtXngYipL9BD0N+IB1 ZjgtSp+7HI3S0DKSOT8NsDhmbdLq/O9xJ1be0LRvLsOA2rBg06wnUby7p DjK4NWut8A82PoVxgGX+vI3/47I6X6eLn04Ht52HDVR9F1n7i43/L96pc 4XOT0cZWmlKy7Ex4enEbRI/n5amDnFpSAWNyniy3MapzuYU7/Jq1dIqCW odATeYIGcLAbmZ1/3hcz6OzMmbDboBSk6hx7wbVcm93oqYtlfOIgiwZ9l g==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154532" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154532" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435205" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435205" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id D3C8F580C6E; Wed, 15 Mar 2023 11:34:06 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 03/11] platform/x86/intel/vsec: Add base address field Date: Wed, 15 Mar 2023 11:33:57 -0700 Message-Id: <20230315183405.2465630-4-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some Intel PCIe VSEC capabilities may be emulated in MMIO. In such cases the BAR is not readable from config space. Provide a field for drivers to indicate the base address that is to be used. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 14 +++++++++++--- drivers/platform/x86/intel/vsec.c | 10 ++++++++-- drivers/platform/x86/intel/vsec.h | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/= intel/pmt/class.c index 9f505c6ef278..7136475d4ab5 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -161,10 +161,11 @@ static struct class intel_pmt_class =3D { =20 static int intel_pmt_populate_entry(struct intel_pmt_entry *entry, struct intel_pmt_header *header, - struct device *dev, + struct intel_vsec_device *ivdev, struct resource *disc_res) { - struct pci_dev *pci_dev =3D to_pci_dev(dev->parent); + struct pci_dev *pci_dev =3D ivdev->pcidev; + struct device *dev =3D &ivdev->auxdev.dev; u8 bir; =20 /* @@ -216,6 +217,13 @@ static int intel_pmt_populate_entry(struct intel_pmt_e= ntry *entry, =20 break; case ACCESS_BARID: + /* Use the provided base address if it exists */ + if (ivdev->base_addr) { + entry->base_addr =3D ivdev->base_addr + + GET_ADDRESS(header->base_offset); + break; + } + /* * If another BAR was specified then the base offset * represents the offset within that BAR. SO retrieve the @@ -320,7 +328,7 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry,= struct intel_pmt_namespa if (ret) return ret; =20 - ret =3D intel_pmt_populate_entry(entry, &header, dev, disc_res); + ret =3D intel_pmt_populate_entry(entry, &header, intel_vsec_dev, disc_res= ); if (ret) return ret; =20 diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel= /vsec.c index 0d5cf250e288..77063f699a1d 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -153,6 +153,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, str= uct intel_vsec_header *he struct intel_vsec_device *intel_vsec_dev; struct resource *res, *tmp; unsigned long quirks =3D info->quirks; + u64 base_addr; int i; =20 if (!intel_vsec_supported(header->id, info->caps)) @@ -181,14 +182,18 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, s= truct intel_vsec_header *he if (quirks & VSEC_QUIRK_TABLE_SHIFT) header->offset >>=3D TABLE_OFFSET_SHIFT; =20 + if (info->base_addr) + base_addr =3D info->base_addr; + else + base_addr =3D pdev->resource[header->tbir].start; + /* * The DVSEC/VSEC contains the starting offset and count for a block of * discovery tables. Create a resource array of these tables to the * auxiliary device driver. */ for (i =3D 0, tmp =3D res; i < header->num_entries; i++, tmp++) { - tmp->start =3D pdev->resource[header->tbir].start + - header->offset + i * (header->entry_size * sizeof(u32)); + tmp->start =3D base_addr + header->offset + i * (header->entry_size * si= zeof(u32)); tmp->end =3D tmp->start + (header->entry_size * sizeof(u32)) - 1; tmp->flags =3D IORESOURCE_MEM; =20 @@ -206,6 +211,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, str= uct intel_vsec_header *he intel_vsec_dev->resource =3D res; intel_vsec_dev->num_resources =3D header->num_entries; intel_vsec_dev->quirks =3D info->quirks; + intel_vsec_dev->base_addr =3D info->base_addr; =20 if (header->id =3D=3D VSEC_ID_SDSI) intel_vsec_dev->ida =3D &intel_vsec_sdsi_ida; diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel= /vsec.h index 54fdea93f762..4157ec546cd3 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -74,6 +74,7 @@ struct intel_vsec_platform_info { struct intel_vsec_header **headers; unsigned long caps; unsigned long quirks; + u64 base_addr; }; =20 struct intel_vsec_device { @@ -86,6 +87,7 @@ struct intel_vsec_device { void *priv_data; size_t priv_data_size; unsigned long quirks; + u64 base_addr; }; =20 int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E6F4C6FD1D for ; Wed, 15 Mar 2023 18:34:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbjCOSe1 (ORCPT ); Wed, 15 Mar 2023 14:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231769AbjCOSeM (ORCPT ); Wed, 15 Mar 2023 14:34:12 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE156AD28; Wed, 15 Mar 2023 11:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905250; x=1710441250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SLZM9Rd4ZbAV+HV63P8xQDOFKv2CzGBHIeab4YXE1bU=; b=SxtjaWDHZuGsebxR2EtzSIvWNRtT3D9kLv/51mbZlFikK/GdSGLAVNh/ 6BqrYbrqGbVzxfKXGWlXrjhYMFGlrfhQxDh0C2Z9LMQ+LLK0uDW4WzLso Yk+2hTylaHyOdtJOwzmp1AxCp6qxgC2VT6Whd2HlXnFsHk9HS0izX63Dy CuoBkpgicWpkukjuaM/s5zQVY/1kdgYKLl+eCoHLQ6QvFvfnr6shqqJPB VLBkTK+gUoIKe/dbO8hDV9M0G/SeEZR9R4h6r5PPPfD7Xb2p5rBN6OBYF 7gta8GwFKlrYHbMHdDpekiklzt2W183kH9kT52zAYAEoFRne80gbMV1jM A==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154538" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154538" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435208" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435208" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 19268580D2C; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 04/11] platform/x86/intel/pmt: Add INTEL_PMT module namespace Date: Wed, 15 Mar 2023 11:33:58 -0700 Message-Id: <20230315183405.2465630-5-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since the currently exported symbols in pmt_class are only used by other Intel PMT drivers, create an INTEL_PMT module namespace for them. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 6 +++--- drivers/platform/x86/intel/pmt/crashlog.c | 1 + drivers/platform/x86/intel/pmt/telemetry.c | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/= intel/pmt/class.c index 7136475d4ab5..acc96f0cc224 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -33,7 +33,7 @@ bool intel_pmt_is_early_client_hw(struct device *dev) */ return !!(ivdev->quirks & VSEC_QUIRK_EARLY_HW); } -EXPORT_SYMBOL_GPL(intel_pmt_is_early_client_hw); +EXPORT_SYMBOL_NS_GPL(intel_pmt_is_early_client_hw, INTEL_PMT); =20 static inline int pmt_memcpy64_fromio(void *to, const u64 __iomem *from, size_t count) @@ -335,7 +335,7 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry,= struct intel_pmt_namespa return intel_pmt_dev_register(entry, ns, dev); =20 } -EXPORT_SYMBOL_GPL(intel_pmt_dev_create); +EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_create, INTEL_PMT); =20 void intel_pmt_dev_destroy(struct intel_pmt_entry *entry, struct intel_pmt_namespace *ns) @@ -351,7 +351,7 @@ void intel_pmt_dev_destroy(struct intel_pmt_entry *entr= y, device_unregister(dev); xa_erase(ns->xa, entry->devid); } -EXPORT_SYMBOL_GPL(intel_pmt_dev_destroy); +EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_destroy, INTEL_PMT); =20 static int __init pmt_class_init(void) { diff --git a/drivers/platform/x86/intel/pmt/crashlog.c b/drivers/platform/x= 86/intel/pmt/crashlog.c index ace1239bc0a0..bbb3d61d09f4 100644 --- a/drivers/platform/x86/intel/pmt/crashlog.c +++ b/drivers/platform/x86/intel/pmt/crashlog.c @@ -328,3 +328,4 @@ module_exit(pmt_crashlog_exit); MODULE_AUTHOR("Alexander Duyck "); MODULE_DESCRIPTION("Intel PMT Crashlog driver"); MODULE_LICENSE("GPL v2"); +MODULE_IMPORT_NS(INTEL_PMT); diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/= x86/intel/pmt/telemetry.c index 5e4009c05ecf..71cdef42084a 100644 --- a/drivers/platform/x86/intel/pmt/telemetry.c +++ b/drivers/platform/x86/intel/pmt/telemetry.c @@ -160,3 +160,4 @@ module_exit(pmt_telem_exit); MODULE_AUTHOR("David E. Box "); MODULE_DESCRIPTION("Intel PMT Telemetry driver"); MODULE_LICENSE("GPL v2"); +MODULE_IMPORT_NS(INTEL_PMT); --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BB34C61DA4 for ; Wed, 15 Mar 2023 18:34:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232377AbjCOSek (ORCPT ); Wed, 15 Mar 2023 14:34:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbjCOSeP (ORCPT ); Wed, 15 Mar 2023 14:34:15 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97E096A4F; Wed, 15 Mar 2023 11:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905252; x=1710441252; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sZA92xYaQ0h8ypQ1+D2Khsxotdmw78gsyoPN7vgwzww=; b=k+ZTZ5EXH4L4AGvlKO0mLkIaxPLy8OiEjOd9xB5vxf80oca/p0VF/6eJ 5HDvIOtuzWyvqXgLHGL4RFSuchrvOhw4PhOgZoDCDOKcA4DN5Mw9iacHx 6YvypD+vf5KabPm2I3/VZExbhVMrfpdjMppBodJXZItiVAImsk7yEyvS+ 1UMCBJB+isAbvI8i/ucBIN5tyqOOlfjnkFlQMzMAkMOuSo0B+ZsEczQno 2XyHJS/+SJb/pUrBM0Q3VctSgViB9LZoE1k6kUQpcvSLVTA1pdrfzx0Hg UUaOujJSR8knEoUzJSBNESEBYQShiYgYUjimlO2a9ex7L+yL9A0t0BN0Y Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154543" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154543" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435211" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435211" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 4D801580BF2; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 05/11] platform/x86/intel/pmt: telemetry: Add telemetry read functions Date: Wed, 15 Mar 2023 11:33:59 -0700 Message-Id: <20230315183405.2465630-6-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Export symbols to allow access to Intel PMT Telemetry data on available devices. Provides APIs to search, register, and read telemetry using a kref managed pointer that serves as a handle to a telemetry entry. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 28 +-- drivers/platform/x86/intel/pmt/class.h | 30 +++- drivers/platform/x86/intel/pmt/crashlog.c | 2 +- drivers/platform/x86/intel/pmt/telemetry.c | 196 ++++++++++++++++++++- drivers/platform/x86/intel/pmt/telemetry.h | 120 +++++++++++++ 5 files changed, 353 insertions(+), 23 deletions(-) create mode 100644 drivers/platform/x86/intel/pmt/telemetry.h diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/= intel/pmt/class.c index acc96f0cc224..4fc8d48ef3be 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -17,7 +17,7 @@ #include "../vsec.h" #include "class.h" =20 -#define PMT_XA_START 0 +#define PMT_XA_START 1 #define PMT_XA_MAX INT_MAX #define PMT_XA_LIMIT XA_LIMIT(PMT_XA_START, PMT_XA_MAX) #define GUID_SPR_PUNIT 0x9956f43f @@ -160,12 +160,12 @@ static struct class intel_pmt_class =3D { }; =20 static int intel_pmt_populate_entry(struct intel_pmt_entry *entry, - struct intel_pmt_header *header, struct intel_vsec_device *ivdev, struct resource *disc_res) { struct pci_dev *pci_dev =3D ivdev->pcidev; struct device *dev =3D &ivdev->auxdev.dev; + struct intel_pmt_header *header =3D &entry->header; u8 bir; =20 /* @@ -271,7 +271,7 @@ static int intel_pmt_dev_register(struct intel_pmt_entr= y *entry, if (ns->attr_grp) { ret =3D sysfs_create_group(entry->kobj, ns->attr_grp); if (ret) - goto fail_sysfs; + goto fail_sysfs_create_group; } =20 /* if size is 0 assume no data buffer, so no file needed */ @@ -296,13 +296,23 @@ static int intel_pmt_dev_register(struct intel_pmt_en= try *entry, entry->pmt_bin_attr.size =3D entry->size; =20 ret =3D sysfs_create_bin_file(&dev->kobj, &entry->pmt_bin_attr); - if (!ret) - return 0; + if (ret) + goto fail_ioremap; =20 + if (ns->pmt_add_handle) { + ret =3D ns->pmt_add_handle(entry, parent); + if (ret) + goto fail_add_handle; + } + + return 0; + +fail_add_handle: + sysfs_remove_bin_file(entry->kobj, &entry->pmt_bin_attr); fail_ioremap: if (ns->attr_grp) sysfs_remove_group(entry->kobj, ns->attr_grp); -fail_sysfs: +fail_sysfs_create_group: device_unregister(dev); fail_dev_create: xa_erase(ns->xa, entry->devid); @@ -314,7 +324,6 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry,= struct intel_pmt_namespa struct intel_vsec_device *intel_vsec_dev, int idx) { struct device *dev =3D &intel_vsec_dev->auxdev.dev; - struct intel_pmt_header header; struct resource *disc_res; int ret; =20 @@ -324,16 +333,15 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entr= y, struct intel_pmt_namespa if (IS_ERR(entry->disc_table)) return PTR_ERR(entry->disc_table); =20 - ret =3D ns->pmt_header_decode(entry, &header, dev); + ret =3D ns->pmt_header_decode(entry, dev); if (ret) return ret; =20 - ret =3D intel_pmt_populate_entry(entry, &header, intel_vsec_dev, disc_res= ); + ret =3D intel_pmt_populate_entry(entry, intel_vsec_dev, disc_res); if (ret) return ret; =20 return intel_pmt_dev_register(entry, ns, dev); - } EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_create, INTEL_PMT); =20 diff --git a/drivers/platform/x86/intel/pmt/class.h b/drivers/platform/x86/= intel/pmt/class.h index 17bc40b77efc..7b730cdaed5a 100644 --- a/drivers/platform/x86/intel/pmt/class.h +++ b/drivers/platform/x86/intel/pmt/class.h @@ -8,6 +8,7 @@ #include =20 #include "../vsec.h" +#include "telemetry.h" =20 /* PMT access types */ #define ACCESS_BARID 2 @@ -18,8 +19,27 @@ #define GET_ADDRESS(v) ((v) & GENMASK(31, 3)) =20 struct xarray; +struct pci_dev; + +struct telem_handle { + struct pci_dev *parent; + struct telem_header header; + struct device *dev; + void __iomem *base; + bool present; + struct kref kref; +}; + +struct intel_pmt_header { + u32 base_offset; + u32 size; + u32 guid; + u8 access_type; +}; =20 struct intel_pmt_entry { + struct telem_handle *handle; + struct intel_pmt_header header; struct bin_attribute pmt_bin_attr; struct kobject *kobj; void __iomem *disc_table; @@ -30,20 +50,14 @@ struct intel_pmt_entry { int devid; }; =20 -struct intel_pmt_header { - u32 base_offset; - u32 size; - u32 guid; - u8 access_type; -}; - struct intel_pmt_namespace { const char *name; struct xarray *xa; const struct attribute_group *attr_grp; int (*pmt_header_decode)(struct intel_pmt_entry *entry, - struct intel_pmt_header *header, struct device *dev); + int (*pmt_add_handle)(struct intel_pmt_entry *entry, + struct device *dev); }; =20 bool intel_pmt_is_early_client_hw(struct device *dev); diff --git a/drivers/platform/x86/intel/pmt/crashlog.c b/drivers/platform/x= 86/intel/pmt/crashlog.c index bbb3d61d09f4..4014c02cafdb 100644 --- a/drivers/platform/x86/intel/pmt/crashlog.c +++ b/drivers/platform/x86/intel/pmt/crashlog.c @@ -223,10 +223,10 @@ static const struct attribute_group pmt_crashlog_grou= p =3D { }; =20 static int pmt_crashlog_header_decode(struct intel_pmt_entry *entry, - struct intel_pmt_header *header, struct device *dev) { void __iomem *disc_table =3D entry->disc_table; + struct intel_pmt_header *header =3D &entry->header; struct crashlog_entry *crashlog; =20 if (!pmt_crashlog_supported(entry)) diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/= x86/intel/pmt/telemetry.c index 71cdef42084a..39ec8d9fb5b1 100644 --- a/drivers/platform/x86/intel/pmt/telemetry.c +++ b/drivers/platform/x86/intel/pmt/telemetry.c @@ -30,6 +30,14 @@ /* Used by client hardware to identify a fixed telemetry entry*/ #define TELEM_CLIENT_FIXED_BLOCK_GUID 0x10000000 =20 +#define NUM_BYTES_QWORD(v) ((v) << 3) +#define SAMPLE_ID_OFFSET(v) ((v) << 3) + +#define NUM_BYTES_DWORD(v) ((v) << 2) +#define SAMPLE_ID_OFFSET32(v) ((v) << 2) + +static DEFINE_MUTEX(entry_lock); + enum telem_type { TELEM_TYPE_PUNIT =3D 0, TELEM_TYPE_CRASHLOG, @@ -58,10 +66,10 @@ static bool pmt_telem_region_overlaps(struct intel_pmt_= entry *entry, } =20 static int pmt_telem_header_decode(struct intel_pmt_entry *entry, - struct intel_pmt_header *header, struct device *dev) { void __iomem *disc_table =3D entry->disc_table; + struct intel_pmt_header *header =3D &entry->header; =20 if (pmt_telem_region_overlaps(entry, dev)) return 1; @@ -84,21 +92,199 @@ static int pmt_telem_header_decode(struct intel_pmt_en= try *entry, return 0; } =20 +static int pmt_telem_add_handle(struct intel_pmt_entry *entry, + struct device *dev) +{ + struct telem_handle *handle; + + entry->handle =3D kzalloc(sizeof(*(entry->handle)), GFP_KERNEL); + if (!entry->handle) + return -ENOMEM; + + handle =3D entry->handle; + handle->dev =3D dev; + handle->parent =3D to_pci_dev(dev->parent); + handle->header.access_type =3D entry->header.access_type; + handle->header.guid =3D entry->header.guid; + handle->header.base_offset =3D entry->header.base_offset; + handle->header.size =3D entry->header.size; + handle->base =3D entry->base; + handle->present =3D true; + + kref_init(&handle->kref); + + return 0; +} + static DEFINE_XARRAY_ALLOC(telem_array); static struct intel_pmt_namespace pmt_telem_ns =3D { .name =3D "telem", .xa =3D &telem_array, .pmt_header_decode =3D pmt_telem_header_decode, + .pmt_add_handle =3D pmt_telem_add_handle, }; =20 +static void pmt_telem_handle_release(struct kref *kref) +{ + struct telem_handle *handle; + + handle =3D container_of(kref, struct telem_handle, kref); + kfree(handle); +} + +/* + * driver api + */ +int pmt_telem_get_next_entry(int start) +{ + struct intel_pmt_entry *entry; + unsigned long found_idx; + + mutex_lock(&entry_lock); + xa_for_each_start(&telem_array, found_idx, entry, start) { + /* + * Return first found index after start. + * 0 is not valid id. + */ + if (found_idx > start) + break; + } + mutex_unlock(&entry_lock); + + return found_idx =3D=3D start ? 0 : found_idx; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_get_next_entry, INTEL_PMT); + +struct telem_handle *pmt_telem_register_handle(int devid) +{ + struct intel_pmt_entry *entry; + unsigned long index =3D devid; + + mutex_lock(&entry_lock); + entry =3D xa_find(&telem_array, &index, index, XA_PRESENT); + if (!entry) { + mutex_unlock(&entry_lock); + return ERR_PTR(-ENXIO); + } + + kref_get(&entry->handle->kref); + mutex_unlock(&entry_lock); + + return entry->handle; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_register_handle, INTEL_PMT); + +void pmt_telem_unregister_handle(struct telem_handle *handle) +{ + kref_put(&handle->kref, pmt_telem_handle_release); +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_unregister_handle, INTEL_PMT); + +int pmt_telem_get_devid_info(int devid, struct telem_entry_info *info) +{ + struct intel_pmt_entry *entry; + unsigned long index =3D devid; + int err =3D 0; + + if (!info) + return -EINVAL; + + mutex_lock(&entry_lock); + entry =3D xa_find(&telem_array, &index, index, XA_PRESENT); + if (!entry) { + err =3D -ENXIO; + goto unlock; + } + + info->pdev =3D entry->handle->parent; + info->header =3D entry->handle->header; + +unlock: + mutex_unlock(&entry_lock); + return err; + +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_get_devid_info, INTEL_PMT); + +int +pmt_telem_read(struct telem_handle *handle, u32 id, u64 *data, u32 count) +{ + u32 offset, size; + + if (!handle->present) + return -ENODEV; + + offset =3D SAMPLE_ID_OFFSET(id); + size =3D handle->header.size; + + if ((offset + NUM_BYTES_QWORD(count)) > size) + return -EINVAL; + + memcpy_fromio(data, handle->base + offset, NUM_BYTES_QWORD(count)); + + return handle->present ? 0 : -EPIPE; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_read, INTEL_PMT); + +int +pmt_telem_read32(struct telem_handle *handle, u32 id, u32 *data, u32 count) +{ + u32 offset, size; + + if (!handle->present) + return -ENODEV; + + offset =3D SAMPLE_ID_OFFSET32(id); + size =3D handle->header.size; + + if ((offset + NUM_BYTES_DWORD(count)) > size) + return -EINVAL; + + memcpy_fromio(data, handle->base + offset, NUM_BYTES_DWORD(count)); + + return handle->present ? 0 : -EPIPE; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_read32, INTEL_PMT); + +struct telem_handle * +pmt_telem_find_and_register_handle(struct pci_dev *pcidev, u32 guid, u16 p= os) +{ + int devid =3D 0; + int inst =3D 0; + int err =3D 0; + + while ((devid =3D pmt_telem_get_next_entry(devid))) { + struct telem_entry_info info; + + err =3D pmt_telem_get_devid_info(devid, &info); + if (err) + return ERR_PTR(err); + + if (info.header.guid =3D=3D guid && info.pdev =3D=3D pcidev) { + if (inst =3D=3D pos) + return pmt_telem_register_handle(devid); + ++inst; + } + } + + return ERR_PTR(-ENXIO); +} +EXPORT_SYMBOL_NS(pmt_telem_find_and_register_handle, INTEL_PMT); + static void pmt_telem_remove(struct auxiliary_device *auxdev) { struct pmt_telem_priv *priv =3D auxiliary_get_drvdata(auxdev); int i; =20 - for (i =3D 0; i < priv->num_entries; i++) - intel_pmt_dev_destroy(&priv->entry[i], &pmt_telem_ns); -} + mutex_lock(&entry_lock); + for (i =3D 0; i < priv->num_entries; i++) { + struct intel_pmt_entry *entry =3D &priv->entry[i]; + + kref_put(&entry->handle->kref, pmt_telem_handle_release); + intel_pmt_dev_destroy(entry, &pmt_telem_ns); + } + mutex_unlock(&entry_lock); +}; =20 static int pmt_telem_probe(struct auxiliary_device *auxdev, const struct a= uxiliary_device_id *id) { @@ -117,7 +303,9 @@ static int pmt_telem_probe(struct auxiliary_device *aux= dev, const struct auxilia for (i =3D 0; i < intel_vsec_dev->num_resources; i++) { struct intel_pmt_entry *entry =3D &priv->entry[priv->num_entries]; =20 + mutex_lock(&entry_lock); ret =3D intel_pmt_dev_create(entry, &pmt_telem_ns, intel_vsec_dev, i); + mutex_unlock(&entry_lock); if (ret < 0) goto abort_probe; if (ret) diff --git a/drivers/platform/x86/intel/pmt/telemetry.h b/drivers/platform/= x86/intel/pmt/telemetry.h new file mode 100644 index 000000000000..c78184f08d2e --- /dev/null +++ b/drivers/platform/x86/intel/pmt/telemetry.h @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _INTEL_PMT_TELEM_H +#define _INTEL_PMT_TELEM_H + +#include + +/* Telemetry types */ +#define PMT_TELEM_TELEMETRY 0 +#define PMT_TELEM_CRASHLOG 1 + +struct telem_handle; + +struct telem_header { + u8 access_type; + u16 size; + u32 guid; + u32 base_offset; +}; + +struct telem_entry_info { + struct pci_dev *pdev; + struct telem_header header; +}; + +struct pci_dev; + +/** + * pmt_telem_get_next_devid() - Get next devid for a telemetry entry + * @start: starting devid to look from + * + * Use in a while loop to retrieve the devid of all available telemetry + * entries. + * + * Return: + * * devid - devid of the next present handle from start + * * 0 - when no more handles are present after start + */ +int pmt_telem_get_next_entry(int start); + +/** + * pmt_telem_get_devid_info() - Get telemetry info for a telemetry entry f= rom + * its devid + * @devid: devid of the telemetry entry + * @info: Endpoint info structure to be populated + * + * Return: + * * 0 - Success + * * -ENXIO - devid no found + * * -EINVAL - info is NULL + */ +int pmt_telem_get_devid_info(int devid, struct telem_entry_info *info); + +/** + * pmt_telem_register_handle() - Register a telemetry handle + * @devid: devid of the telemetry entry + * + * Increments the kref usage counter for the handle. + * + * Return: + * * handle - On success returns pointer to the telemetry handle + * * -ENXIO - devid not found + */ +struct telem_handle *pmt_telem_register_handle(int devid); + +/** + * pmt_telem_unregister_handle() - Unregister a telemetry handle + * @handle: handle to unregister + * + * Decrements the kref usage counter for the handle. + */ +void pmt_telem_unregister_handle(struct telem_handle *handle); + +/** + * pmt_telem_find_and_register_handle() - Find and get a handle to a telem= etry + * entry + * @pdev: PCI device of the telemetry provider + * @guid: GUID of the telemetry space + * @pos: Instance of the guid in case of multiple instances + * + * Return: + * * handle - On success returns pointer to the telemetry handle + * * -ENXIO - Telemetry provider not found + */ +struct telem_handle *pmt_telem_find_and_register_handle(struct pci_dev *pc= idev, + u32 guid, u16 pos); + +/** + * pmt_telem_read() - Read telemetry sample(s) from handle + * @ep: Telemetry handle + * @id: Starting sample id + * @data: Allocated qword buffer + * @count: Number of consecutive samples/qwords to read + * + * Return: + * * 0 - Success + * * -ENODEV - Entry is not present + * * -EINVAL - The offset is out bounds of the sample space + * * -EPIPE - The device was removed during the read. Data written + * but should be considered invalid + */ +int pmt_telem_read(struct telem_handle *handle, u32 id, u64 *data, + u32 count); + +/** + * pmt_telem_read32() - Read dword samples from handle + * @ep: Telemetry handle + * @id: Starting sample id + * @data: Allocated dword buffer + * @count: Number of consecutive samples/dwords to read + * + * Return: + * * 0 - Success + * * -ENODEV - Entry is not present + * * -EINVAL - The offset is out bounds of the sample space + * * -EPIPE - The device was removed during the read. Data written + * but should be considered invalid. + */ +int pmt_telem_read32(struct telem_handle *handle, u32 id, u32 *data, + u32 count); +#endif --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57989C74A5B for ; Wed, 15 Mar 2023 18:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232113AbjCOSee (ORCPT ); Wed, 15 Mar 2023 14:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231779AbjCOSeO (ORCPT ); Wed, 15 Mar 2023 14:34:14 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1719D40D3; Wed, 15 Mar 2023 11:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905253; x=1710441253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L00M9MXhIWKlvY9DN1BY3XH1GCJuxFHrq9jz+q4X/hA=; b=GHurIbEE0omo52F9FiRAeAjQWpTIIaPr5lrVGdz+JV6U4xHNNtO62p7s +XNZFJP6oO+EYH1viByoweF3vtYoN06oDrZME/+hXve3sxtZ1i3J+RZGN 0d9dDQWyAkIjyU7Sy4kPPDfYTUMH5vz91OM2oIW0tAhe60scEmDY631my 4ldNxUPwQXkF1M0/ibMUGphAtF+ewOYqTr6mUszpV8u4NAMQu4RyTMRpo DfloH8lbkLrgbCseH+JaxeZetOBk1hR1ffqH+ogIPpw2IrbNRnWqeqvyL 5hetSJ02Xt3EMJ8IsVzx+erXBfaLr7/6TRW/kUT1sar482qxNg81WDJeF w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154549" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154549" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435213" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435213" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 8CD42580C6E; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 06/11] platform/x86/intel/pmt/telemetry: Add driver version Date: Wed, 15 Mar 2023 11:34:00 -0700 Message-Id: <20230315183405.2465630-7-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a driver version number to make it easier to track changes in backported kernels. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/telemetry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/= x86/intel/pmt/telemetry.c index 39ec8d9fb5b1..7593726e814d 100644 --- a/drivers/platform/x86/intel/pmt/telemetry.c +++ b/drivers/platform/x86/intel/pmt/telemetry.c @@ -19,6 +19,7 @@ #include "../vsec.h" #include "class.h" =20 +#define DRIVER_VERSION "1.0" #define TELEM_SIZE_OFFSET 0x0 #define TELEM_GUID_OFFSET 0x4 #define TELEM_BASE_OFFSET 0x8 @@ -348,4 +349,5 @@ module_exit(pmt_telem_exit); MODULE_AUTHOR("David E. Box "); MODULE_DESCRIPTION("Intel PMT Telemetry driver"); MODULE_LICENSE("GPL v2"); +MODULE_VERSION(DRIVER_VERSION); MODULE_IMPORT_NS(INTEL_PMT); --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17796C61DA4 for ; Wed, 15 Mar 2023 18:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232348AbjCOSeh (ORCPT ); Wed, 15 Mar 2023 14:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231875AbjCOSeP (ORCPT ); Wed, 15 Mar 2023 14:34:15 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A6E87DA5; Wed, 15 Mar 2023 11:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905254; x=1710441254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n16cQ4kymyynRY6n5R36txntCnbHvo09MUKHWcfcmk0=; b=BMtYe1nbaAgf5695fyjDZ3luVhYEZCd2/3SWosp/EWTpbdp++3PP3+w0 ROTHdEb+bm09ONRmRkwAp5bD4Y5IFDALe10mjxyp603UvnIOQt1ZbIL63 ejmsWax1H4ejggos+U9G7uRA6zMlReiJrkzpLyhPDFcaBbaX3FPZ3OXhg daxxOGz8FeyiVZz0EzsFHv8Fw1tDLIFQ6Iz1Pmrt3OiU3NQ2SdHXTMbq1 XhHfW8MW5J0e/ynurUfsm8hDaAK5tsN41s0B5itXln6bRQG+6yVatHv9I RXSGt2emayU50VGXpBC8pq5AuzdZhPBQFVw2KLvRILWhdLdps1HWAkzyG w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154556" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154556" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435217" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435217" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:08 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id CF8D1580BF6; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 07/11] platform/x86/intel/pmc: Alder Lake slp_s0_residency fix Date: Wed, 15 Mar 2023 11:34:01 -0700 Message-Id: <20230315183405.2465630-8-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rajvi Jingar For platforms with Alder Lake PCH (Alder Lake S and Raptor Lake S) the slp_s0_residency attribute has been reporting the wrong value. Unlike other platforms, ADL PCH does not have a counter for the time that the SLP_S0 signal was asserted. Instead, firmware uses the aggregate of the Low Power Mode (LPM) substate counters as the S0ix value. Since the LPM counters run at a different frequency, this lead to misreporting of the S0ix time. Add a check for Alder Lake PCH and adjust the frequency accordingly when display slp_s0_residency. Fixes: bbab31101f44 ("platform/x86/intel: pmc/core: Add Alderlake support t= o pmc core driver") Signed-off-by: Rajvi Jingar Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/i= ntel/pmc/core.c index e489d2175e42..61ca7c37fb02 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -66,7 +66,18 @@ static inline void pmc_core_reg_write(struct pmc_dev *pm= cdev, int reg_offset, =20 static inline u64 pmc_core_adjust_slp_s0_step(struct pmc_dev *pmcdev, u32 = value) { - return (u64)value * pmcdev->map->slp_s0_res_counter_step; + /* + * ADL PCH does not have the SLP_S0 counter and LPM Residency counters are + * used as a workaround which uses 30.5 usec tick. All other client + * programs have the legacy SLP_S0 residency counter that is using the 122 + * usec tick. + */ + const int lpm_adj_x2 =3D pmcdev->map->lpm_res_counter_step_x2; + + if (pmcdev->map =3D=3D &adl_reg_map) + return (u64)value * GET_X2_COUNTER((u64)lpm_adj_x2); + else + return (u64)value * pmcdev->map->slp_s0_res_counter_step; } =20 static int set_etr3(struct pmc_dev *pmcdev) --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AA7AC6FD1D for ; Wed, 15 Mar 2023 18:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232399AbjCOSen (ORCPT ); Wed, 15 Mar 2023 14:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232019AbjCOSeX (ORCPT ); Wed, 15 Mar 2023 14:34:23 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60E8AFF0E; Wed, 15 Mar 2023 11:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905254; x=1710441254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qeonfz7kPOnTnc23J/5nZOsk6/2p2FjL/PplnJo6pvk=; b=CHSngXhu2K90s7o4w6zGUgmviLe3m7g3gWRoR+dMbtwNOnWhHx79Q4nT +Uu/el8xyW+VeWSuAwfvp65PTmu7IDFpM+1iCipuFgVtE0HprWfgzATIZ rV0Q2hFhw7mQ/LaGMHvcCsoLOPJEDv9Ixd2lr+1qkhBwVfxSOcL/P704q oQwfhU+SES+XgAP5BUZ2MmmLGh9UHUYUs1T0mlbqKy/jgMEVlDmyUhXUH pRRJ0s2kwQCkDhlWZuJJm+9QmYzdkAd6wIADb4NIyKJYVhUNELTaANUCs e7PrFauvVsDIsPVQ4hPioUcL46UBPsZMG6dmDTge0gESdrj/I1tpJgShU w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154564" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154564" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435221" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435221" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:08 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 1F2A0580D29; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 08/11] platform/x86:intel/pmc: Combine core_init and core_configure function Date: Wed, 15 Mar 2023 11:34:02 -0700 Message-Id: <20230315183405.2465630-9-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xi Pardee core_init and core_configure functions can be combined to have a cleaner setup for platforms. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/adl.c | 15 +++++---- drivers/platform/x86/intel/pmc/cnp.c | 15 ++++++++- drivers/platform/x86/intel/pmc/core.c | 48 +++++++++++++++------------ drivers/platform/x86/intel/pmc/core.h | 20 +++++------ drivers/platform/x86/intel/pmc/icl.c | 3 +- drivers/platform/x86/intel/pmc/mtl.c | 15 +++++---- drivers/platform/x86/intel/pmc/spt.c | 3 +- drivers/platform/x86/intel/pmc/tgl.c | 15 +++++---- 8 files changed, 80 insertions(+), 54 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/adl.c b/drivers/platform/x86/in= tel/pmc/adl.c index 5cbd40979f2a..a6ceaf520fd5 100644 --- a/drivers/platform/x86/intel/pmc/adl.c +++ b/drivers/platform/x86/intel/pmc/adl.c @@ -309,17 +309,20 @@ const struct pmc_reg_map adl_reg_map =3D { .lpm_live_status_offset =3D ADL_LPM_LIVE_STATUS_OFFSET, }; =20 -void adl_core_configure(struct pmc_dev *pmcdev) +int adl_core_init(struct pmc_dev *pmcdev) { + int ret; + + pmcdev->map =3D &adl_reg_map; + ret =3D get_primary_reg_base(pmcdev); + if (ret) + return ret; + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); pmc_core_send_ltr_ignore(pmcdev, 3); -} =20 -void adl_core_init(struct pmc_dev *pmcdev) -{ - pmcdev->map =3D &adl_reg_map; - pmcdev->core_configure =3D adl_core_configure; + return ret; } diff --git a/drivers/platform/x86/intel/pmc/cnp.c b/drivers/platform/x86/in= tel/pmc/cnp.c index 7fb38815c4eb..fcd07a61f88d 100644 --- a/drivers/platform/x86/intel/pmc/cnp.c +++ b/drivers/platform/x86/intel/pmc/cnp.c @@ -204,7 +204,20 @@ const struct pmc_reg_map cnp_reg_map =3D { .etr3_offset =3D ETR3_OFFSET, }; =20 -void cnp_core_init(struct pmc_dev *pmcdev) +int cnp_core_init(struct pmc_dev *pmcdev) { + int ret; + pmcdev->map =3D &cnp_reg_map; + ret =3D get_primary_reg_base(pmcdev); + if (ret) + return ret; + + /* Due to a hardware limitation, the GBE LTR blocks PC10 + * when a cable is attached. Tell the PMC to ignore it. + */ + dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); + pmc_core_send_ltr_ignore(pmcdev, 3); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/i= ntel/pmc/core.c index 61ca7c37fb02..4769ce0b0fbe 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -948,6 +948,26 @@ static void pmc_core_get_low_power_modes(struct platfo= rm_device *pdev) } } =20 +int get_primary_reg_base(struct pmc_dev *pmcdev) +{ + u64 slp_s0_addr; + + if (lpit_read_residency_count_address(&slp_s0_addr)) { + pmcdev->base_addr =3D PMC_BASE_ADDR_DEFAULT; + + if (page_is_ram(PHYS_PFN(pmcdev->base_addr))) + return -ENODEV; + } else { + pmcdev->base_addr =3D slp_s0_addr - pmcdev->map->slp_s0_offset; + } + + pmcdev->regbase =3D ioremap(pmcdev->base_addr, + pmcdev->map->regmap_length); + if (!pmcdev->regbase) + return -ENOMEM; + return 0; +} + static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev) { debugfs_remove_recursive(pmcdev->dbgfs_dir); @@ -1100,8 +1120,8 @@ static int pmc_core_probe(struct platform_device *pde= v) static bool device_initialized; struct pmc_dev *pmcdev; const struct x86_cpu_id *cpu_id; - void (*core_init)(struct pmc_dev *pmcdev); - u64 slp_s0_addr; + int (*core_init)(struct pmc_dev *pmcdev); + int ret; =20 if (device_initialized) return -ENODEV; @@ -1117,7 +1137,7 @@ static int pmc_core_probe(struct platform_device *pde= v) if (!cpu_id) return -ENODEV; =20 - core_init =3D (void (*)(struct pmc_dev *))cpu_id->driver_data; + core_init =3D (int (*)(struct pmc_dev *))cpu_id->driver_data; =20 /* * Coffee Lake has CPU ID of Kaby Lake and Cannon Lake PCH. So here @@ -1128,26 +1148,12 @@ static int pmc_core_probe(struct platform_device *p= dev) core_init =3D cnp_core_init; =20 mutex_init(&pmcdev->lock); - core_init(pmcdev); - - - if (lpit_read_residency_count_address(&slp_s0_addr)) { - pmcdev->base_addr =3D PMC_BASE_ADDR_DEFAULT; - - if (page_is_ram(PHYS_PFN(pmcdev->base_addr))) - return -ENODEV; - } else { - pmcdev->base_addr =3D slp_s0_addr - pmcdev->map->slp_s0_offset; + ret =3D core_init(pmcdev); + if (ret) { + mutex_destroy(&pmcdev->lock); + return ret; } =20 - pmcdev->regbase =3D ioremap(pmcdev->base_addr, - pmcdev->map->regmap_length); - if (!pmcdev->regbase) - return -ENOMEM; - - if (pmcdev->core_configure) - pmcdev->core_configure(pmcdev); - pmcdev->pmc_xram_read_bit =3D pmc_core_check_read_lock_bit(pmcdev); pmc_core_get_low_power_modes(pdev); pmc_core_do_dmi_quirks(pmcdev); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/i= ntel/pmc/core.h index 810204d758ab..3ce83c837fdc 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -325,7 +325,6 @@ struct pmc_reg_map { * @num_lpm_modes: Count of enabled modes * @lpm_en_modes: Array of enabled modes from lowest to highest priority * @lpm_req_regs: List of substate requirements - * @core_configure: Function pointer to configure the platform * * pmc_dev contains info about power management controller device. */ @@ -344,7 +343,6 @@ struct pmc_dev { int num_lpm_modes; int lpm_en_modes[LPM_MAX_NUM_MODES]; u32 *lpm_req_regs; - void (*core_configure)(struct pmc_dev *pmcdev); }; =20 extern const struct pmc_bit_map msr_map[]; @@ -397,16 +395,14 @@ extern const struct pmc_reg_map mtl_reg_map; =20 extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev); extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value); - -void spt_core_init(struct pmc_dev *pmcdev); -void cnp_core_init(struct pmc_dev *pmcdev); -void icl_core_init(struct pmc_dev *pmcdev); -void tgl_core_init(struct pmc_dev *pmcdev); -void adl_core_init(struct pmc_dev *pmcdev); -void mtl_core_init(struct pmc_dev *pmcdev); -void tgl_core_configure(struct pmc_dev *pmcdev); -void adl_core_configure(struct pmc_dev *pmcdev); -void mtl_core_configure(struct pmc_dev *pmcdev); +extern int get_primary_reg_base(struct pmc_dev *pmcdev); + +int spt_core_init(struct pmc_dev *pmcdev); +int cnp_core_init(struct pmc_dev *pmcdev); +int icl_core_init(struct pmc_dev *pmcdev); +int tgl_core_init(struct pmc_dev *pmcdev); +int adl_core_init(struct pmc_dev *pmcdev); +int mtl_core_init(struct pmc_dev *pmcdev); =20 #define pmc_for_each_mode(i, mode, pmcdev) \ for (i =3D 0, mode =3D pmcdev->lpm_en_modes[i]; \ diff --git a/drivers/platform/x86/intel/pmc/icl.c b/drivers/platform/x86/in= tel/pmc/icl.c index 2f11b1a6daeb..a671d7e86431 100644 --- a/drivers/platform/x86/intel/pmc/icl.c +++ b/drivers/platform/x86/intel/pmc/icl.c @@ -50,7 +50,8 @@ const struct pmc_reg_map icl_reg_map =3D { .etr3_offset =3D ETR3_OFFSET, }; =20 -void icl_core_init(struct pmc_dev *pmcdev) +int icl_core_init(struct pmc_dev *pmcdev) { pmcdev->map =3D &icl_reg_map; + return get_primary_reg_base(pmcdev); } diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/in= tel/pmc/mtl.c index eeb3bd8c2502..96106ffbd367 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -36,17 +36,20 @@ const struct pmc_reg_map mtl_reg_map =3D { .lpm_live_status_offset =3D MTL_LPM_LIVE_STATUS_OFFSET, }; =20 -void mtl_core_configure(struct pmc_dev *pmcdev) +int mtl_core_init(struct pmc_dev *pmcdev) { + int ret; + + pmcdev->map =3D &mtl_reg_map; + ret =3D get_primary_reg_base(pmcdev); + if (ret) + return ret; + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); pmc_core_send_ltr_ignore(pmcdev, 3); -} =20 -void mtl_core_init(struct pmc_dev *pmcdev) -{ - pmcdev->map =3D &mtl_reg_map; - pmcdev->core_configure =3D mtl_core_configure; + return ret; } diff --git a/drivers/platform/x86/intel/pmc/spt.c b/drivers/platform/x86/in= tel/pmc/spt.c index e16982236778..f34015692bb8 100644 --- a/drivers/platform/x86/intel/pmc/spt.c +++ b/drivers/platform/x86/intel/pmc/spt.c @@ -134,7 +134,8 @@ const struct pmc_reg_map spt_reg_map =3D { .pm_vric1_offset =3D SPT_PMC_VRIC1_OFFSET, }; =20 -void spt_core_init(struct pmc_dev *pmcdev) +int spt_core_init(struct pmc_dev *pmcdev) { pmcdev->map =3D &spt_reg_map; + return get_primary_reg_base(pmcdev); } diff --git a/drivers/platform/x86/intel/pmc/tgl.c b/drivers/platform/x86/in= tel/pmc/tgl.c index c245ada849d0..c69f2672fb92 100644 --- a/drivers/platform/x86/intel/pmc/tgl.c +++ b/drivers/platform/x86/intel/pmc/tgl.c @@ -252,18 +252,21 @@ void pmc_core_get_tgl_lpm_reqs(struct platform_device= *pdev) ACPI_FREE(out_obj); } =20 -void tgl_core_configure(struct pmc_dev *pmcdev) +int tgl_core_init(struct pmc_dev *pmcdev) { + int ret; + + pmcdev->map =3D &tgl_reg_map; + ret =3D get_primary_reg_base(pmcdev); + if (ret) + return ret; + pmc_core_get_tgl_lpm_reqs(pmcdev->pdev); /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); pmc_core_send_ltr_ignore(pmcdev, 3); -} =20 -void tgl_core_init(struct pmc_dev *pmcdev) -{ - pmcdev->map =3D &tgl_reg_map; - pmcdev->core_configure =3D tgl_core_configure; + return ret; } --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81190C61DA4 for ; Wed, 15 Mar 2023 18:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232501AbjCOSev (ORCPT ); Wed, 15 Mar 2023 14:34:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbjCOSe0 (ORCPT ); Wed, 15 Mar 2023 14:34:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30640198F; Wed, 15 Mar 2023 11:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905255; x=1710441255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tqsEbmKGVD86TyjaK4FQ0KAEv5jaN0N9ShVwFwIiVJI=; b=dyEoCCeHkrgi7mV4oVIwdxumBp0uRx3/xKW2ocRt4FYozwVGBMVR1yMW YnOwl2F835xIt/5bd1aLD0aBtIQ7qSZEIEKHSYR3vjWmuTfQUQwPSTHqN p+AgNcDH/VdFcXXiPui7xUPDce8ZxMyKHAAymkZTxw2Vd/m4SMkdffEo6 B+4P1BSkD/fp/f22U7HfCC4Coa/zqdgzNT5WMbPQVfmuzVKY5x8t4oMQG uDoxtiV1C/IVTgGQCdHJpNkMvwR0GLG+OhsnpIOZ38CKI3/tRPYS86JVy tTqVdH9gh6KrzHcYQGG5c98Mb/vq7/m7ptQIXhcTziSnrtwjlonWO+Enc Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154571" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154571" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435224" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435224" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:08 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 6B9F9580C6E; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 09/11] platform/x86/intel/pmc: Add Intel PMT support for MTL PMC Date: Wed, 15 Mar 2023 11:34:03 -0700 Message-Id: <20230315183405.2465630-10-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The PMC SSRAM device contains PMC metrics that are structured in Intel Platform Monitoring Technology (PMT) telemetry regions. Register these telemetry regions from the driver so that they may be read using the Intel PMT API. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/Kconfig | 1 + drivers/platform/x86/intel/pmc/core.c | 6 ++ drivers/platform/x86/intel/pmc/core.h | 2 + drivers/platform/x86/intel/pmc/mtl.c | 106 +++++++++++++++++++++++++ 4 files changed, 115 insertions(+) diff --git a/drivers/platform/x86/intel/pmc/Kconfig b/drivers/platform/x86/= intel/pmc/Kconfig index b526597e4deb..d2f651fbec2c 100644 --- a/drivers/platform/x86/intel/pmc/Kconfig +++ b/drivers/platform/x86/intel/pmc/Kconfig @@ -7,6 +7,7 @@ config INTEL_PMC_CORE tristate "Intel PMC Core driver" depends on PCI depends on ACPI + depends on INTEL_PMT_TELEMETRY help The Intel Platform Controller Hub for Intel Core SoCs provides access to Power Management Controller registers via various interfaces. This diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/i= ntel/pmc/core.c index 4769ce0b0fbe..8f3a5a6fc874 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -1174,6 +1174,11 @@ static void pmc_core_remove(struct platform_device *= pdev) platform_set_drvdata(pdev, NULL); mutex_destroy(&pmcdev->lock); iounmap(pmcdev->regbase); + + if (pmcdev->ssram_pcidev) { + pci_dev_put(pmcdev->ssram_pcidev); + pci_disable_device(pmcdev->ssram_pcidev); + } } =20 static bool warn_on_s0ix_failures; @@ -1287,3 +1292,4 @@ module_platform_driver(pmc_core_driver); =20 MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Intel PMC Core Driver"); +MODULE_IMPORT_NS(INTEL_VSEC); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/i= ntel/pmc/core.h index 3ce83c837fdc..ba30db31f439 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -315,6 +315,7 @@ struct pmc_reg_map { * @map: pointer to pmc_reg_map struct that contains platform * specific attributes * @pdev: pointer to platform_device struct + * @ssram_pcidev: pointer to pci device struct for the PMC SSRAM * @dbgfs_dir: path to debugfs interface * @pmc_xram_read_bit: flag to indicate whether PMC XRAM shadow registers * used to read MPHY PG and PLL status are available @@ -334,6 +335,7 @@ struct pmc_dev { const struct pmc_reg_map *map; struct dentry *dbgfs_dir; struct platform_device *pdev; + struct pci_dev *ssram_pcidev; int pmc_xram_read_bit; struct mutex lock; /* generic mutex lock for PMC Core */ =20 diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/in= tel/pmc/mtl.c index 96106ffbd367..48c7ec094af8 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -8,7 +8,18 @@ * */ =20 +#include + #include "core.h" +#include "../vsec.h" +#include "../pmt/telemetry.h" + +#define SSRAM_HDR_SIZE 0x100 +#define SSRAM_PWRM_OFFSET 0x14 +#define SSRAM_DVSEC_OFFSET 0x1C +#define SSRAM_DVSEC_SIZE 0x10 +#define SSRAM_PCH_OFFSET 0x60 +#define SSRAM_IOE_OFFSET 0x68 =20 const struct pmc_reg_map mtl_reg_map =3D { .pfear_sts =3D ext_tgl_pfear_map, @@ -36,6 +47,99 @@ const struct pmc_reg_map mtl_reg_map =3D { .lpm_live_status_offset =3D MTL_LPM_LIVE_STATUS_OFFSET, }; =20 +static void +mtl_pmc_add_pmt(struct pmc_dev *pmcdev, struct pci_dev *pdev, u64 ssram_ba= se) +{ + struct intel_vsec_platform_info info =3D {}; + struct intel_vsec_header *headers[2] =3D {}; + struct intel_vsec_header header; + void __iomem *ssram, *dvsec; + u32 dvsec_offset; + u32 table, hdr; + + ssram =3D ioremap(ssram_base, SSRAM_HDR_SIZE); + if (!ssram) + return; + + dvsec_offset =3D readl(ssram + SSRAM_DVSEC_OFFSET); + iounmap(ssram); + + dvsec =3D ioremap(ssram_base + dvsec_offset, SSRAM_DVSEC_SIZE); + if (!dvsec) + return; + + hdr =3D readl(dvsec + PCI_DVSEC_HEADER1); + header.id =3D readw(dvsec + PCI_DVSEC_HEADER2); + header.rev =3D PCI_DVSEC_HEADER1_REV(hdr); + header.length =3D PCI_DVSEC_HEADER1_LEN(hdr); + header.num_entries =3D readb(dvsec + INTEL_DVSEC_ENTRIES); + header.entry_size =3D readb(dvsec + INTEL_DVSEC_SIZE); + + table =3D readl(dvsec + INTEL_DVSEC_TABLE); + header.tbir =3D INTEL_DVSEC_TABLE_BAR(table); + header.offset =3D INTEL_DVSEC_TABLE_OFFSET(table); + iounmap(dvsec); + + headers[0] =3D &header; + info.caps =3D VSEC_CAP_TELEMETRY; + info.headers =3D headers; + info.base_addr =3D ssram_base; + + intel_vsec_register(pdev, &info); +} + +static inline u64 get_ssram_base(void __iomem *addr, u32 offset) +{ + u64 low, high; + + low =3D readl(addr + offset) & GENMASK(31, 3); + high =3D readl(addr + offset + 4); + + return (high << 32) + low; +} + +static void mtl_pmc_ssram_init(struct pmc_dev *pmcdev) +{ + void __iomem *ssram; + struct pci_dev *pcidev; + u64 socs_ssram_base; + u64 ioe_ssram_base; + u64 pch_ssram_base; + int ret; + + pcidev =3D pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(20, 2)); + if (!pcidev) { + dev_err(&pmcdev->pdev->dev, "pci_dev is not found."); + return; + } + + ret =3D pcim_enable_device(pcidev); + if (ret) { + pci_dev_put(pcidev); + return; + } + + socs_ssram_base =3D pcidev->resource[0].start; + ssram =3D ioremap(socs_ssram_base, SSRAM_HDR_SIZE); + if (!ssram) { + pci_dev_put(pcidev); + pci_disable_device(pcidev); + return; + } + + pmcdev->ssram_pcidev =3D pcidev; + + ioe_ssram_base =3D get_ssram_base(ssram, SSRAM_IOE_OFFSET); + pch_ssram_base =3D get_ssram_base(ssram, SSRAM_PCH_OFFSET); + iounmap(ssram); + + mtl_pmc_add_pmt(pmcdev, pcidev, socs_ssram_base); + if (ioe_ssram_base) + mtl_pmc_add_pmt(pmcdev, pcidev, ioe_ssram_base); + if (pch_ssram_base) + mtl_pmc_add_pmt(pmcdev, pcidev, pch_ssram_base); +} + int mtl_core_init(struct pmc_dev *pmcdev) { int ret; @@ -45,6 +149,8 @@ int mtl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; =20 + mtl_pmc_ssram_init(pmcdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C0B8C6FD1D for ; Wed, 15 Mar 2023 18:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232421AbjCOSer (ORCPT ); Wed, 15 Mar 2023 14:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbjCOSe0 (ORCPT ); Wed, 15 Mar 2023 14:34:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31337E3BE; Wed, 15 Mar 2023 11:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905255; x=1710441255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hgPn91lasy9XxNu+0Ue+s0aleZeJjAiqqDGwHrAoS/A=; b=aFjSTzOsggk6Dtv7UA3wdbnONbY1FIw2qSe/jdsYKZSnFg9hmF6IOwbN tMMRS2LN0NgnTURbnubQNEDnzKUSmGB7Ivr/H83m3DS76FwT4gNaZz6uE tJ7Vm7LPqkcPEzelLEXSWjBQU84fcYKoCi6ZZN2t1OTGAHFTGhLmlecK/ UdFCKZGZAn8iamt8OgRwhv7EwG9wKQB74ekmPoD2ACkvliseg9qJsYwtD yqtLDywTtiTshfDQV9mrpDvZmvgxugBD55Wf4JsWwPyNuaGD/Che8Fyka DyvT54/4FqJFh3Fqvc4kNEhfIcg9JI70s2dnNSv3LQO+0Ua+E38WKNBgK g==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154578" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154578" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435227" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435227" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:09 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id B9FD8580BF2; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 10/11] platform/x86:intel/pmc: Move get_low_power_modes function Date: Wed, 15 Mar 2023 11:34:04 -0700 Message-Id: <20230315183405.2465630-11-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xi Pardee Move the pmc_core_get_low_power_modes function call from probe to init function. This is the preparation work for retrieving LPM information using Intel PMT API patch as available low power modes need to be known. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/adl.c | 2 ++ drivers/platform/x86/intel/pmc/cnp.c | 2 ++ drivers/platform/x86/intel/pmc/core.c | 3 +-- drivers/platform/x86/intel/pmc/core.h | 1 + drivers/platform/x86/intel/pmc/icl.c | 10 +++++++++- drivers/platform/x86/intel/pmc/mtl.c | 2 ++ drivers/platform/x86/intel/pmc/spt.c | 10 +++++++++- drivers/platform/x86/intel/pmc/tgl.c | 2 ++ 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/adl.c b/drivers/platform/x86/in= tel/pmc/adl.c index a6ceaf520fd5..6101c9c2aa9c 100644 --- a/drivers/platform/x86/intel/pmc/adl.c +++ b/drivers/platform/x86/intel/pmc/adl.c @@ -318,6 +318,8 @@ int adl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; =20 + pmc_core_get_low_power_modes(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ diff --git a/drivers/platform/x86/intel/pmc/cnp.c b/drivers/platform/x86/in= tel/pmc/cnp.c index fcd07a61f88d..68e7ac7f7a11 100644 --- a/drivers/platform/x86/intel/pmc/cnp.c +++ b/drivers/platform/x86/intel/pmc/cnp.c @@ -213,6 +213,8 @@ int cnp_core_init(struct pmc_dev *pmcdev) if (ret) return ret; =20 + pmc_core_get_low_power_modes(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/i= ntel/pmc/core.c index 8f3a5a6fc874..3833ea4a758e 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -898,7 +898,7 @@ static bool pmc_core_pri_verify(u32 lpm_pri, u8 *mode_o= rder) return true; } =20 -static void pmc_core_get_low_power_modes(struct platform_device *pdev) +void pmc_core_get_low_power_modes(struct platform_device *pdev) { struct pmc_dev *pmcdev =3D platform_get_drvdata(pdev); u8 pri_order[LPM_MAX_NUM_MODES] =3D LPM_DEFAULT_PRI; @@ -1155,7 +1155,6 @@ static int pmc_core_probe(struct platform_device *pde= v) } =20 pmcdev->pmc_xram_read_bit =3D pmc_core_check_read_lock_bit(pmcdev); - pmc_core_get_low_power_modes(pdev); pmc_core_do_dmi_quirks(pmcdev); =20 pmc_core_dbgfs_register(pmcdev); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/i= ntel/pmc/core.h index ba30db31f439..f4b69861c17b 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -398,6 +398,7 @@ extern const struct pmc_reg_map mtl_reg_map; extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev); extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value); extern int get_primary_reg_base(struct pmc_dev *pmcdev); +extern void pmc_core_get_low_power_modes(struct platform_device *pdev); =20 int spt_core_init(struct pmc_dev *pmcdev); int cnp_core_init(struct pmc_dev *pmcdev); diff --git a/drivers/platform/x86/intel/pmc/icl.c b/drivers/platform/x86/in= tel/pmc/icl.c index a671d7e86431..8315e6c90efa 100644 --- a/drivers/platform/x86/intel/pmc/icl.c +++ b/drivers/platform/x86/intel/pmc/icl.c @@ -52,6 +52,14 @@ const struct pmc_reg_map icl_reg_map =3D { =20 int icl_core_init(struct pmc_dev *pmcdev) { + int ret; + pmcdev->map =3D &icl_reg_map; - return get_primary_reg_base(pmcdev); + ret =3D get_primary_reg_base(pmcdev); + if (ret) + return ret; + + pmc_core_get_low_power_modes(pmcdev->pdev); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/in= tel/pmc/mtl.c index 48c7ec094af8..74f1f4c44812 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -151,6 +151,8 @@ int mtl_core_init(struct pmc_dev *pmcdev) =20 mtl_pmc_ssram_init(pmcdev); =20 + pmc_core_get_low_power_modes(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ diff --git a/drivers/platform/x86/intel/pmc/spt.c b/drivers/platform/x86/in= tel/pmc/spt.c index f34015692bb8..1f6bcd40ba76 100644 --- a/drivers/platform/x86/intel/pmc/spt.c +++ b/drivers/platform/x86/intel/pmc/spt.c @@ -136,6 +136,14 @@ const struct pmc_reg_map spt_reg_map =3D { =20 int spt_core_init(struct pmc_dev *pmcdev) { + int ret; + pmcdev->map =3D &spt_reg_map; - return get_primary_reg_base(pmcdev); + ret =3D get_primary_reg_base(pmcdev); + if (ret) + return ret; + + pmc_core_get_low_power_modes(pmcdev->pdev); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/tgl.c b/drivers/platform/x86/in= tel/pmc/tgl.c index c69f2672fb92..05b7cc6f59a0 100644 --- a/drivers/platform/x86/intel/pmc/tgl.c +++ b/drivers/platform/x86/intel/pmc/tgl.c @@ -261,7 +261,9 @@ int tgl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; =20 + pmc_core_get_low_power_modes(pmcdev->pdev); pmc_core_get_tgl_lpm_reqs(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ --=20 2.34.1 From nobody Wed Feb 11 10:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A206FC7618D for ; Wed, 15 Mar 2023 18:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232589AbjCOSe4 (ORCPT ); Wed, 15 Mar 2023 14:34:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232108AbjCOSe0 (ORCPT ); Wed, 15 Mar 2023 14:34:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160601715F; Wed, 15 Mar 2023 11:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905256; x=1710441256; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w54rzDIFvclAC/9zKRmf3nOrZJbpqYh8AxeBdQIJTS0=; b=hGsxbOcjbmAfJ6fU00AZXNz9shc3g/OE4WJsDAWczNnn2B87f86GTF3F 6VnFgSacDuWQPNCy9irU2uiosQLOZUKnQr/ytXATgtoCABFKwe7dEDvIG lxNr3sZz9TUqwIuPghRr5wnWO+PQniw87B+RWxF+rcQJPfpplkXzkYK4/ 553w8uds46rLgHJZnvcPNg04oi/ezFIffLlLJBZrz74GBtzrYfv+Z/EOn MCFXTNptYJIAWsCV3LxRpPZmjjvY7P4qgpQ/jO+ci4WxAMnu2bxMg2JlI Dz7CpM/YigEhcNVQrevwVMLKoZCPN4R8kjshECqQJYOZ7iu/RUXkT7XpR w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154584" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154584" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435229" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435229" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:09 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 0C6C3580BF6; Wed, 15 Mar 2023 11:34:09 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 11/11] platform/x86/intel/pmc/mtl: get LPM information using Intel PMT Date: Wed, 15 Mar 2023 11:34:05 -0700 Message-Id: <20230315183405.2465630-12-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xi Pardee For Meteor Lake, retrieve the PMC Lower Power Mode (LPM) information using Intel PMT Telemetry API. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/core.c | 1 + drivers/platform/x86/intel/pmc/core.h | 1 + drivers/platform/x86/intel/pmc/mtl.c | 64 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/i= ntel/pmc/core.c index 3833ea4a758e..2e4a9ca1be62 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -1291,4 +1291,5 @@ module_platform_driver(pmc_core_driver); =20 MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Intel PMC Core Driver"); +MODULE_IMPORT_NS(INTEL_PMT); MODULE_IMPORT_NS(INTEL_VSEC); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/i= ntel/pmc/core.h index f4b69861c17b..e5d33999c865 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -306,6 +306,7 @@ struct pmc_reg_map { const u32 lpm_status_offset; const u32 lpm_live_status_offset; const u32 etr3_offset; + const u8 *lpm_reg_index; }; =20 /** diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/in= tel/pmc/mtl.c index 74f1f4c44812..d51ec35e085d 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -21,6 +21,13 @@ #define SSRAM_PCH_OFFSET 0x60 #define SSRAM_IOE_OFFSET 0x68 =20 +#define SOCS_LPM_REQ_GUID 0x2625030 +#define LPM_REG_INDEX_OFFSET 2 +#define LPM_REG_NUM 28 +#define LPM_SUBSTATE_NUM 1 + +static const u8 MTL_LPM_REG_INDEX[] =3D {0, 4, 5, 6, 8, 9, 10, 11, 12, 13,= 14, 15, 16, 20}; + const struct pmc_reg_map mtl_reg_map =3D { .pfear_sts =3D ext_tgl_pfear_map, .slp_s0_offset =3D CNP_PMC_SLP_S0_RES_COUNTER_OFFSET, @@ -45,8 +52,60 @@ const struct pmc_reg_map mtl_reg_map =3D { .lpm_sts =3D adl_lpm_maps, .lpm_status_offset =3D MTL_LPM_STATUS_OFFSET, .lpm_live_status_offset =3D MTL_LPM_LIVE_STATUS_OFFSET, + .lpm_reg_index =3D MTL_LPM_REG_INDEX, }; =20 +/* + * Only return error EPROBE_DEFER when telem handle is not yet available, + * otherwise returns 0. + */ +static int pmc_core_get_mtl_lpm_reqs(struct pmc_dev *pmcdev) +{ + const u8 *reg_index =3D pmcdev->map->lpm_reg_index; + const int num_maps =3D pmcdev->map->lpm_num_maps; + struct pci_dev *pcidev =3D pmcdev->ssram_pcidev; + u32 lpm_size =3D LPM_MAX_NUM_MODES * num_maps; + struct telem_handle *handle; + int i, j, map_offset =3D 0; + u32 *lpm_req_regs; + + if (!pcidev) + return 0; + + handle =3D pmt_telem_find_and_register_handle(pcidev, SOCS_LPM_REQ_GUID, = 0); + if (IS_ERR(handle)) { + dev_err(&pmcdev->pdev->dev, + "pmc_core: couldn't get telem handle %ld", PTR_ERR(handle)); + return -EPROBE_DEFER; + } + + lpm_req_regs =3D devm_kzalloc(&pmcdev->pdev->dev, lpm_size * sizeof(u32), + GFP_KERNEL); + + for (j =3D 0; j < pmcdev->num_lpm_modes; j++) { + int mode =3D pmcdev->lpm_en_modes[j]; + u32 *ptr =3D lpm_req_regs + mode * num_maps; + + for (i =3D 0; i < num_maps; ++i) { + u8 index =3D reg_index[i] + LPM_REG_INDEX_OFFSET + map_offset; + int err; + + err =3D pmt_telem_read32(handle, index, ptr, 1); + if (err) { + dev_err(&pmcdev->pdev->dev, "pmt_telem read failed: %d", err); + pmt_telem_unregister_handle(handle); + return 0; + } + ++ptr; + } + map_offset +=3D LPM_REG_NUM + LPM_SUBSTATE_NUM; + } + pmcdev->lpm_req_regs =3D lpm_req_regs; + pmt_telem_unregister_handle(handle); + + return 0; +} + static void mtl_pmc_add_pmt(struct pmc_dev *pmcdev, struct pci_dev *pdev, u64 ssram_ba= se) { @@ -152,6 +211,11 @@ int mtl_core_init(struct pmc_dev *pmcdev) mtl_pmc_ssram_init(pmcdev); =20 pmc_core_get_low_power_modes(pmcdev->pdev); + ret =3D pmc_core_get_mtl_lpm_reqs(pmcdev); + if (ret) { + iounmap(pmcdev->regbase); + return ret; + } =20 /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. --=20 2.34.1