From nobody Tue Dec 16 03:19:50 2025 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 2922CCE7A8D for ; Fri, 22 Sep 2023 21:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230004AbjIVVap (ORCPT ); Fri, 22 Sep 2023 17:30:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbjIVVak (ORCPT ); Fri, 22 Sep 2023 17:30:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11467EE; Fri, 22 Sep 2023 14:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418234; x=1726954234; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=ehtzflnkXJ/6Zn26B3bD8kZ3gA8KPD3Ei24NzR5rzP8=; b=dXmyTGRM0lb+pGvV8g7RUB/B1KPlhJgeOf5KNaJ0O/7lp4ZENzj+EXqA IuLCizd62qSx2EFOOFW6aAq1f2KI5PiHWSBpM5mXghpjK+KO/kVSzsttr VWseVLMtW5LKT6S2fSYtbo+pCfIUV6BUjo5pNa5uRmD19ciWbIPJiBZ+B GqJ/kgqcBS+b3c7eWtFBg8yV3uAkzbjfeTpk+Iqvm5dWa9eSQ0YHuUz7u ptyYCOodUKu4Srqv3lg0c/l7urGuWQL+cYNcFbDa17+5fkKxniWzcGWau qXap/4wX7t66MObfYinNGgaDDJD70ibPfBYn+/iXQCHJig516WntB6kUF Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264686" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264686" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685309" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685309" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:32 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id A9D5C580DB2; Fri, 22 Sep 2023 14:30:32 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 01/11] platform/x86/intel/vsec: Add intel_vsec_register Date: Fri, 22 Sep 2023 14:30:22 -0700 Message-Id: <20230922213032.1770590-2-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 Add and export intel_vsec_register() to allow the registration of Intel extended capabilities from other drivers. Add check to look for memory conflicts before registering a new capability. Signed-off-by: Gayatri Kammela Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 2 +- drivers/platform/x86/intel/vsec.c | 58 ++++++++++---------------- drivers/platform/x86/intel/vsec.h | 42 ++++++++++++++++++- 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/= intel/pmt/class.c index f32a233470de..2ad91d2fd954 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_NS_GPL(intel_pmt_is_early_client_hw, INTEL_PMT); =20 diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel= /vsec.c index c1f9e4471b28..c5d0202068cf 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 const char *intel_vsec_name(enum intel_vsec_id id) { switch (id) { @@ -223,19 +188,28 @@ 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; else intel_vsec_dev->ida =3D &intel_vsec_ida; =20 - return intel_vsec_add_aux(pdev, NULL, intel_vsec_dev, + return intel_vsec_add_aux(pdev, info->parent, intel_vsec_dev, intel_vsec_name(header->id)); } =20 @@ -353,6 +327,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 0fd042c171ba..ab0f161f86c5 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -11,9 +11,45 @@ #define VSEC_CAP_SDSI BIT(3) #define VSEC_CAP_TPMI BIT(4) =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), @@ -33,6 +69,7 @@ enum intel_vsec_quirks { =20 /* Platform specific data */ struct intel_vsec_platform_info { + struct device *parent; struct intel_vsec_header **headers; unsigned long caps; unsigned long quirks; @@ -43,10 +80,10 @@ struct intel_vsec_device { struct pci_dev *pcidev; struct resource *resource; struct ida *ida; - struct intel_vsec_platform_info *info; 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, @@ -62,4 +99,7 @@ static inline struct intel_vsec_device *auxdev_to_ivdev(s= truct auxiliary_device { return container_of(auxdev, struct intel_vsec_device, auxdev); } + +void intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info); #endif --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 016FCCE7A8B for ; Fri, 22 Sep 2023 21:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbjIVVam (ORCPT ); Fri, 22 Sep 2023 17:30:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbjIVVaj (ORCPT ); Fri, 22 Sep 2023 17:30:39 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E88E6CA; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418233; x=1726954233; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=tNCrq0UCcwWZxRQu2a0ZKbXVzG5T9sXvN3JlA1Gge7Y=; b=bmkPyO4EIuf6pgqLjqfq5z3i2v837LXkJDzHHhmd8ZI/E8LlyLIPw5n/ GU17486UeqchkED5zd819mj8rL5nrVtvDzc/xwqJ9n0gOlZt7lBNFhvMS txNfA0NykuulMan9VWRGc+ZS4khHSzUfyHiBVOYIJUn9rbt3J61MYlm0Y TUrCzSIHOG8VN/35gtfYBXMCneCeo3mKKQYhxaf9ya82ZUQLu59eSWXn7 THDaJnTDLpgjIv2Pm2RUoTxNaIo97OWSScHdje2/JpMtbL0scx2RA9Pq7 oImMFvOVL11JZvCp7Cg0JRyI2GZEwG6J/mcU9YEslcg1XYxfXLb+xiyzZ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="379828416" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="379828416" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="813237844" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="813237844" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id D34C5580BB9; Fri, 22 Sep 2023 14:30:32 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 02/11] platform/x86/intel/vsec: Add base address field Date: Fri, 22 Sep 2023 14:30:23 -0700 Message-Id: <20230922213032.1770590-3-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 devices may emulate PCI VSEC capabilities in MMIO. In such cases the BAR is not readable from a config space. Provide a field for drivers to indicate the base address to be used. Signed-off-by: David E. Box Reviewed-by: Ilpo J=C3=A4rvinen --- 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 2ad91d2fd954..32608baaa56c 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -160,10 +160,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 /* @@ -215,6 +216,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 @@ -319,7 +327,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 c5d0202068cf..e0dd64dec9eb 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -150,6 +150,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)) @@ -178,14 +179,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 @@ -203,6 +208,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 ab0f161f86c5..bddd33e1c17e 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -73,6 +73,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 { @@ -84,6 +85,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 Tue Dec 16 03:19:50 2025 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 D6725CE7A86 for ; Fri, 22 Sep 2023 21:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbjIVVau (ORCPT ); Fri, 22 Sep 2023 17:30:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjIVVak (ORCPT ); Fri, 22 Sep 2023 17:30:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D76F7; Fri, 22 Sep 2023 14:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418234; x=1726954234; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=B3jXLZXwTJVzHRrKfu3fgGwj9H3NPlZpu7Vkx4l8KvA=; b=BMK4X/mJjCsIk+89i/9oA4yPsyILDlmdOU+mvYRemZo7bib0wwnjF9lL 8Bzf5vu2ahfZENHEs9NyTndYtE106gm0LrXNz9qes0gQRyAnly85iIY2h 0DRX8KDN3T0zbKbcTcisUs6fnoMWrOfxlfdSuNi0xanw4NWkqNPuaN40H K48DFTJOA+ecGeqrANumqFEwnvqRmG8AfwPVJwvUH1zUxlRcUz9gAzXZT OgcSt3DLr10k/tC7vzNCpQXun1E4T+QpjLQyLhASKzt+/RaROA2KvuJY9 +CRbxcWDFF4vaaMVDk/AVOo4J7Z8lDfODhHR08RxIN8UGX5A229TTkgNJ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264688" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264688" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685313" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685313" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id 03328580DB2; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 03/11] platform/x86/intel/pmt: Add header to struct intel_pmt_entry Date: Fri, 22 Sep 2023 14:30:24 -0700 Message-Id: <20230922213032.1770590-4-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 PMT header is passed to several functions. Instead, store the header in struct intel_pmt_entry which is also passed to these functions and shorten the argument list. This simplifies the calls in preparation for later changes. Signed-off-by: David E. Box Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/platform/x86/intel/pmt/class.c | 8 +++----- drivers/platform/x86/intel/pmt/class.h | 16 ++++++++-------- drivers/platform/x86/intel/pmt/crashlog.c | 2 +- drivers/platform/x86/intel/pmt/telemetry.c | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/= intel/pmt/class.c index 32608baaa56c..142a24e3727d 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -159,12 +159,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 /* @@ -313,7 +313,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 @@ -323,16 +322,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 db11d58867ce..e477a19f6700 100644 --- a/drivers/platform/x86/intel/pmt/class.h +++ b/drivers/platform/x86/intel/pmt/class.h @@ -18,7 +18,15 @@ #define GET_BIR(v) ((v) & GENMASK(2, 0)) #define GET_ADDRESS(v) ((v) & GENMASK(31, 3)) =20 +struct intel_pmt_header { + u32 base_offset; + u32 size; + u32 guid; + u8 access_type; +}; + struct intel_pmt_entry { + struct intel_pmt_header header; struct bin_attribute pmt_bin_attr; struct kobject *kobj; void __iomem *disc_table; @@ -29,19 +37,11 @@ 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); }; =20 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 39cbc87cc28a..f86080e8bebd 100644 --- a/drivers/platform/x86/intel/pmt/telemetry.c +++ b/drivers/platform/x86/intel/pmt/telemetry.c @@ -58,10 +58,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; --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 DEE16CE7A88 for ; Fri, 22 Sep 2023 21:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbjIVVbJ (ORCPT ); Fri, 22 Sep 2023 17:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229969AbjIVVam (ORCPT ); Fri, 22 Sep 2023 17:30:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30DC9CA; Fri, 22 Sep 2023 14:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418235; x=1726954235; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=4OP3qB1s+BaTbQnTwK/qKa//d9j2D36JVRHROV8N/nQ=; b=PHjjAVq7gTFHVp9Isi85Xcq9BqnaLKpFT9jmfnsUVmAdMy/VcBoNEDBO aSi/R3lPM6Bs/hvD+N2wL4kg2S58aqePia0t0frGVzVCrpsXObi2maGKQ JGqS/wT9H0Lgk4PDEFdnhnAirhQksSXiMncGYBxvsXx3d0CDGFDR9qT9Z WpqmCXOOUySRoyJ8L1x7og8ovVVXAIIvGd2vot2Y5Kc2hJ3qh3SO2sl0p 7FOv1/HuNWZFHySwbOu7zdp6CBqu8EGMKZGEfS+U7ElT9oLBIMJSn/XFq 3mqGHhXSVDVQXGqM2sAlcElXXJ15cIxRTNrLo66SPp6qOTPwAFRME4LXr A==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264689" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264689" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685317" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685317" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id 20820580BBE; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 04/11] platform/x86/intel/pmt: telemetry: Export API to read telemetry Date: Fri, 22 Sep 2023 14:30:25 -0700 Message-Id: <20230922213032.1770590-5-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 endpoint. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 21 ++- drivers/platform/x86/intel/pmt/class.h | 14 ++ drivers/platform/x86/intel/pmt/telemetry.c | 198 ++++++++++++++++++++- drivers/platform/x86/intel/pmt/telemetry.h | 129 ++++++++++++++ 4 files changed, 354 insertions(+), 8 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 142a24e3727d..4b53940a64e2 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 @@ -247,6 +247,7 @@ static int intel_pmt_dev_register(struct intel_pmt_entr= y *entry, struct intel_pmt_namespace *ns, struct device *parent) { + struct intel_vsec_device *ivdev =3D dev_to_ivdev(parent); struct resource res =3D {0}; struct device *dev; int ret; @@ -270,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 */ @@ -295,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_endpoint) { + ret =3D ns->pmt_add_endpoint(entry, ivdev->pcidev); + if (ret) + goto fail_add_endpoint; + } + + return 0; + +fail_add_endpoint: + 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); diff --git a/drivers/platform/x86/intel/pmt/class.h b/drivers/platform/x86/= intel/pmt/class.h index e477a19f6700..d23c63b73ab7 100644 --- a/drivers/platform/x86/intel/pmt/class.h +++ b/drivers/platform/x86/intel/pmt/class.h @@ -9,6 +9,7 @@ #include =20 #include "../vsec.h" +#include "telemetry.h" =20 /* PMT access types */ #define ACCESS_BARID 2 @@ -18,6 +19,16 @@ #define GET_BIR(v) ((v) & GENMASK(2, 0)) #define GET_ADDRESS(v) ((v) & GENMASK(31, 3)) =20 +struct pci_dev; + +struct telem_endpoint { + struct pci_dev *pcidev; + struct telem_header header; + void __iomem *base; + bool present; + struct kref kref; +}; + struct intel_pmt_header { u32 base_offset; u32 size; @@ -26,6 +37,7 @@ struct intel_pmt_header { }; =20 struct intel_pmt_entry { + struct telem_endpoint *ep; struct intel_pmt_header header; struct bin_attribute pmt_bin_attr; struct kobject *kobj; @@ -43,6 +55,8 @@ struct intel_pmt_namespace { const struct attribute_group *attr_grp; int (*pmt_header_decode)(struct intel_pmt_entry *entry, struct device *dev); + int (*pmt_add_endpoint)(struct intel_pmt_entry *entry, + struct pci_dev *pdev); }; =20 bool intel_pmt_is_early_client_hw(struct device *dev); diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/= x86/intel/pmt/telemetry.c index f86080e8bebd..8b099580cc2c 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(ep_lock); + enum telem_type { TELEM_TYPE_PUNIT =3D 0, TELEM_TYPE_CRASHLOG, @@ -84,21 +92,203 @@ static int pmt_telem_header_decode(struct intel_pmt_en= try *entry, return 0; } =20 +static int pmt_telem_add_endpoint(struct intel_pmt_entry *entry, + struct pci_dev *pdev) +{ + struct telem_endpoint *ep; + + /* + * Endpoint lifetimes are managed by kref, not devres. + */ + entry->ep =3D kzalloc(sizeof(*(entry->ep)), GFP_KERNEL); + if (!entry->ep) + return -ENOMEM; + + ep =3D entry->ep; + ep->pcidev =3D pdev; + ep->header.access_type =3D entry->header.access_type; + ep->header.guid =3D entry->header.guid; + ep->header.base_offset =3D entry->header.base_offset; + ep->header.size =3D entry->header.size; + ep->base =3D entry->base; + ep->present =3D true; + + kref_init(&ep->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_endpoint =3D pmt_telem_add_endpoint, }; =20 +/* Called when all users unregister and the device is removed */ +static void pmt_telem_ep_release(struct kref *kref) +{ + struct telem_endpoint *ep; + + ep =3D container_of(kref, struct telem_endpoint, kref); + kfree(ep); +} + +/* + * driver api + */ +int pmt_telem_get_next_endpoint(int start) +{ + struct intel_pmt_entry *entry; + unsigned long found_idx; + + mutex_lock(&ep_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(&ep_lock); + + return found_idx =3D=3D start ? 0 : found_idx; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_get_next_endpoint, INTEL_PMT_TELEMETRY); + +struct telem_endpoint *pmt_telem_register_endpoint(int devid) +{ + struct intel_pmt_entry *entry; + unsigned long index =3D devid; + + mutex_lock(&ep_lock); + entry =3D xa_find(&telem_array, &index, index, XA_PRESENT); + if (!entry) { + mutex_unlock(&ep_lock); + return ERR_PTR(-ENXIO); + } + + kref_get(&entry->ep->kref); + mutex_unlock(&ep_lock); + + return entry->ep; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_register_endpoint, INTEL_PMT_TELEMETRY); + +void pmt_telem_unregister_endpoint(struct telem_endpoint *ep) +{ + kref_put(&ep->kref, pmt_telem_ep_release); +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_unregister_endpoint, INTEL_PMT_TELEMETRY); + +int pmt_telem_get_endpoint_info(int devid, + struct telem_endpoint_info *info) +{ + struct intel_pmt_entry *entry; + unsigned long index =3D devid; + int err =3D 0; + + if (!info) + return -EINVAL; + + mutex_lock(&ep_lock); + entry =3D xa_find(&telem_array, &index, index, XA_PRESENT); + if (!entry) { + err =3D -ENXIO; + goto unlock; + } + + info->pdev =3D entry->ep->pcidev; + info->header =3D entry->ep->header; + +unlock: + mutex_unlock(&ep_lock); + return err; + +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_get_endpoint_info, INTEL_PMT_TELEMETRY); + +int +pmt_telem_read(struct telem_endpoint *ep, u32 id, u64 *data, u32 count) +{ + u32 offset, size; + + if (!ep->present) + return -ENODEV; + + offset =3D SAMPLE_ID_OFFSET(id); + size =3D ep->header.size; + + if ((offset + NUM_BYTES_QWORD(count)) > size) + return -EINVAL; + + memcpy_fromio(data, ep->base + offset, NUM_BYTES_QWORD(count)); + + return ep->present ? 0 : -EPIPE; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_read, INTEL_PMT_TELEMETRY); + +int +pmt_telem_read32(struct telem_endpoint *ep, u32 id, u32 *data, u32 count) +{ + u32 offset, size; + + if (!ep->present) + return -ENODEV; + + offset =3D SAMPLE_ID_OFFSET32(id); + size =3D ep->header.size; + + if ((offset + NUM_BYTES_DWORD(count)) > size) + return -EINVAL; + + memcpy_fromio(data, ep->base + offset, NUM_BYTES_DWORD(count)); + + return ep->present ? 0 : -EPIPE; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_read32, INTEL_PMT_TELEMETRY); + +struct telem_endpoint * +pmt_telem_find_and_register_endpoint(struct pci_dev *pcidev, u32 guid, u16= pos) +{ + int devid =3D 0; + int inst =3D 0; + int err =3D 0; + + while ((devid =3D pmt_telem_get_next_endpoint(devid))) { + struct telem_endpoint_info ep_info; + + err =3D pmt_telem_get_endpoint_info(devid, &ep_info); + if (err) + return ERR_PTR(err); + + if (ep_info.header.guid =3D=3D guid && ep_info.pdev =3D=3D pcidev) { + if (inst =3D=3D pos) + return pmt_telem_register_endpoint(devid); + ++inst; + } + } + + return ERR_PTR(-ENXIO); +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_find_and_register_endpoint, INTEL_PMT_TELEM= ETRY); + 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(&ep_lock); + for (i =3D 0; i < priv->num_entries; i++) { + struct intel_pmt_entry *entry =3D &priv->entry[i]; + + kref_put(&entry->ep->kref, pmt_telem_ep_release); + intel_pmt_dev_destroy(entry, &pmt_telem_ns); + } + mutex_unlock(&ep_lock); +}; =20 static int pmt_telem_probe(struct auxiliary_device *auxdev, const struct a= uxiliary_device_id *id) { @@ -117,7 +307,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(&ep_lock); ret =3D intel_pmt_dev_create(entry, &pmt_telem_ns, intel_vsec_dev, i); + mutex_unlock(&ep_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..a8cd64330438 --- /dev/null +++ b/drivers/platform/x86/intel/pmt/telemetry.h @@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TELEMETRY_H +#define _TELEMETRY_H + +/* Telemetry types */ +#define PMT_TELEM_TELEMETRY 0 +#define PMT_TELEM_CRASHLOG 1 + +struct telem_endpoint; +struct pci_dev; + +struct telem_header { + u8 access_type; + u16 size; + u32 guid; + u32 base_offset; +}; + +struct telem_endpoint_info { + struct pci_dev *pdev; + struct telem_header header; +}; + +/** + * pmt_telem_get_next_endpoint() - Get next device id for a telemetry endp= oint + * @start: starting devid to look from + * + * This functions can be used in a while loop predicate to retrieve the de= vid + * of all available telemetry endpoints. Functions pmt_telem_get_next_endp= oint() + * and pmt_telem_register_endpoint() can be used inside of the loop to exa= mine + * endpoint info and register to receive a pointer to the endpoint. The po= inter + * is then usable in the telemetry read calls to access the telemetry data. + * + * Return: + * * devid - devid of the next present endpoint from start + * * 0 - when no more endpoints are present after start + */ +int pmt_telem_get_next_endpoint(int start); + +/** + * pmt_telem_register_endpoint() - Register a telemetry endpoint + * @devid: device id/handle of the telemetry endpoint + * + * Increments the kref usage counter for the endpoint. + * + * Return: + * * endpoint - On success returns pointer to the telemetry endpoint + * * -ENXIO - telemetry endpoint not found + */ +struct telem_endpoint *pmt_telem_register_endpoint(int devid); + +/** + * pmt_telem_unregister_endpoint() - Unregister a telemetry endpoint + * @ep: ep structure to populate. + * + * Decrements the kref usage counter for the endpoint. + */ +void pmt_telem_unregister_endpoint(struct telem_endpoint *ep); + +/** + * pmt_telem_get_endpoint_info() - Get info for an endpoint from its devid + * @devid: device id/handle of the telemetry endpoint + * @info: Endpoint info structure to be populated + * + * Return: + * * 0 - Success + * * -ENXIO - telemetry endpoint not found for the devid + * * -EINVAL - @info is NULL + */ +int pmt_telem_get_endpoint_info(int devid, + struct telem_endpoint_info *info); + +/** + * pmt_telem_find_and_register_endpoint() - Get a telemetry endpoint from + * pci_dev device, guid and pos + * @pdev: PCI device inside the Intel vsec + * @guid: GUID of the telemetry space + * @pos: Instance of the guid + * + * Return: + * * endpoint - On success returns pointer to the telemetry endpoint + * * -ENXIO - telemetry endpoint not found + */ +struct telem_endpoint *pmt_telem_find_and_register_endpoint(struct pci_dev= *pcidev, + u32 guid, u16 pos); + +/** + * pmt_telem_read() - Read qwords from counter sram using sample id + * @ep: Telemetry endpoint to be read + * @id: The beginning sample id of the metric(s) to be read + * @data: Allocated qword buffer + * @count: Number of qwords requested + * + * Callers must ensure reads are aligned. When the call returns -ENODEV, + * the device has been removed and callers should unregister the telemetry + * endpoint. + * + * Return: + * * 0 - Success + * * -ENODEV - The device is not present. + * * -EINVAL - The offset is out bounds + * * -EPIPE - The device was removed during the read. Data written + * but should be considered invalid. + */ +int pmt_telem_read(struct telem_endpoint *ep, u32 id, u64 *data, + u32 count); + +/** + * pmt_telem_read32() - Read qwords from counter sram using sample id + * @ep: Telemetry endpoint to be read + * @id: The beginning sample id of the metric(s) to be read + * @data: Allocated dword buffer + * @count: Number of dwords requested + * + * Callers must ensure reads are aligned. When the call returns -ENODEV, + * the device has been removed and callers should unregister the telemetry + * endpoint. + * + * Return: + * * 0 - Success + * * -ENODEV - The device is not present. + * * -EINVAL - The offset is out bounds + * * -EPIPE - The device was removed during the read. Data written + * but should be considered invalid. + */ +int pmt_telem_read32(struct telem_endpoint *ep, u32 id, u32 *data, + u32 count); + +#endif --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 C96D4CE7A81 for ; Fri, 22 Sep 2023 21:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230056AbjIVVax (ORCPT ); Fri, 22 Sep 2023 17:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbjIVVal (ORCPT ); Fri, 22 Sep 2023 17:30:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62432EE; Fri, 22 Sep 2023 14:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418235; x=1726954235; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=8jyRmImkbZLW4wilZm2BJ3NQRTKpIJkExmJ9V/4NoyU=; b=Ph5m3TwmEwQ2K2B6TW0erPFKuIelev7TBhBKyXDfx9AiYWhJ4gMeNxYm X3lYsg8pK4H0rXN6PH1RVASnGxwg4hAtaQ1gU2l+UxaWgNLSnui4j/qPs Dq53mceB0aXol4l6yIxPS97SnO9Uf9qOJ12F0elrerQHJ7TJnOJRh8p+E 5an4rMCUa+JBjN8Dq+PB4EZ6dHeRnJllj3ClgxZhHptzsVvxlSXli1Z5B 98p4CWMW8yv8s98ffw0jsnFCy87LOxhTD77Ae77nA25mNpzRPQSv6s1iS e7dkQLmCFfSxzfwYtLHBE9fStQz13LEDDbzp7FE9FYgXHIFzwvqrUQ4XU g==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264692" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264692" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685319" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685319" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id 4AE93580E8B; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 05/11] platform/x86:intel/pmc: Move get_low_power_modes function Date: Fri, 22 Sep 2023 14:30:26 -0700 Message-Id: <20230922213032.1770590-6-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 Some platforms will have a need to retrieve the low power modes as part of their driver initialization. As such, make the function global and call it from the platform specific init code. 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 | 7 +++---- drivers/platform/x86/intel/pmc/core.h | 1 + drivers/platform/x86/intel/pmc/icl.c | 10 +++++++++- drivers/platform/x86/intel/pmc/mtl.c | 4 +++- drivers/platform/x86/intel/pmc/spt.c | 10 +++++++++- drivers/platform/x86/intel/pmc/tgl.c | 1 + 8 files changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/adl.c b/drivers/platform/x86/in= tel/pmc/adl.c index 5006008e01be..64c492391ede 100644 --- a/drivers/platform/x86/intel/pmc/adl.c +++ b/drivers/platform/x86/intel/pmc/adl.c @@ -319,6 +319,8 @@ int adl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; =20 + pmc_core_get_low_power_modes(pmcdev); + /* 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 420aaa1d7c76..59298f184d0e 100644 --- a/drivers/platform/x86/intel/pmc/cnp.c +++ b/drivers/platform/x86/intel/pmc/cnp.c @@ -214,6 +214,8 @@ int cnp_core_init(struct pmc_dev *pmcdev) if (ret) return ret; =20 + pmc_core_get_low_power_modes(pmcdev); + /* 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 5a36b3f77bc5..e58c8cc286a3 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -966,9 +966,8 @@ 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 pmc_dev *pmcdev) { - struct pmc_dev *pmcdev =3D platform_get_drvdata(pdev); struct pmc *pmc =3D pmcdev->pmcs[PMC_IDX_MAIN]; u8 pri_order[LPM_MAX_NUM_MODES] =3D LPM_DEFAULT_PRI; u8 mode_order[LPM_MAX_NUM_MODES]; @@ -1000,7 +999,8 @@ static void pmc_core_get_low_power_modes(struct platfo= rm_device *pdev) for (mode =3D 0; mode < LPM_MAX_NUM_MODES; mode++) pri_order[mode_order[mode]] =3D mode; else - dev_warn(&pdev->dev, "Assuming a default substate order for this platfor= m\n"); + dev_warn(&pmcdev->pdev->dev, + "Assuming a default substate order for this platform\n"); =20 /* * Loop through all modes from lowest to highest priority, @@ -1250,7 +1250,6 @@ static int pmc_core_probe(struct platform_device *pde= v) } =20 pmcdev->pmc_xram_read_bit =3D pmc_core_check_read_lock_bit(primary_pmc); - pmc_core_get_low_power_modes(pdev); pmc_core_do_dmi_quirks(primary_pmc); =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 0729f593c6a7..ccf24e0f5e50 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -490,6 +490,7 @@ extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmc= dev, u32 value); =20 int pmc_core_resume_common(struct pmc_dev *pmcdev); int get_primary_reg_base(struct pmc *pmc); +extern void pmc_core_get_low_power_modes(struct pmc_dev *pmcdev); =20 extern void pmc_core_ssram_init(struct pmc_dev *pmcdev); =20 diff --git a/drivers/platform/x86/intel/pmc/icl.c b/drivers/platform/x86/in= tel/pmc/icl.c index d08e3174230d..71b0fd6cb7d8 100644 --- a/drivers/platform/x86/intel/pmc/icl.c +++ b/drivers/platform/x86/intel/pmc/icl.c @@ -53,7 +53,15 @@ const struct pmc_reg_map icl_reg_map =3D { int icl_core_init(struct pmc_dev *pmcdev) { struct pmc *pmc =3D pmcdev->pmcs[PMC_IDX_MAIN]; + int ret; =20 pmc->map =3D &icl_reg_map; - return get_primary_reg_base(pmc); + + ret =3D get_primary_reg_base(pmc); + if (ret) + return ret; + + pmc_core_get_low_power_modes(pmcdev); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/in= tel/pmc/mtl.c index 2204bc666980..c3b5f4fe01d1 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -985,7 +985,7 @@ static int mtl_resume(struct pmc_dev *pmcdev) int mtl_core_init(struct pmc_dev *pmcdev) { struct pmc *pmc =3D pmcdev->pmcs[PMC_IDX_SOC]; - int ret =3D 0; + int ret; =20 mtl_d3_fixup(); =20 @@ -1002,6 +1002,8 @@ int mtl_core_init(struct pmc_dev *pmcdev) return ret; } =20 + pmc_core_get_low_power_modes(pmcdev); + /* 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 4b6f5cbda16c..ab993a69e33e 100644 --- a/drivers/platform/x86/intel/pmc/spt.c +++ b/drivers/platform/x86/intel/pmc/spt.c @@ -137,7 +137,15 @@ const struct pmc_reg_map spt_reg_map =3D { int spt_core_init(struct pmc_dev *pmcdev) { struct pmc *pmc =3D pmcdev->pmcs[PMC_IDX_MAIN]; + int ret; =20 pmc->map =3D &spt_reg_map; - return get_primary_reg_base(pmc); + + ret =3D get_primary_reg_base(pmc); + if (ret) + return ret; + + pmc_core_get_low_power_modes(pmcdev); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/tgl.c b/drivers/platform/x86/in= tel/pmc/tgl.c index 2449940102db..d5f1d2223c5a 100644 --- a/drivers/platform/x86/intel/pmc/tgl.c +++ b/drivers/platform/x86/intel/pmc/tgl.c @@ -263,6 +263,7 @@ int tgl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; =20 + pmc_core_get_low_power_modes(pmcdev); 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 Tue Dec 16 03:19:50 2025 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 D06DFCE7A86 for ; Fri, 22 Sep 2023 21:30:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbjIVVa4 (ORCPT ); Fri, 22 Sep 2023 17:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjIVVal (ORCPT ); Fri, 22 Sep 2023 17:30:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DB7EFB; Fri, 22 Sep 2023 14:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418235; x=1726954235; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=LTJvjLbkvuQx4wE/Sd6xPXoCn0gNEKM0z+EbfC949UM=; b=Nxuyt8IUn4OrG1JZrz74MVL2Wjj4CZ9c7MgbfD3D0rqyJZgHq5iEX+od 2yEmbO/XUZX1WTmAiTPX07RkuZD2qQ5iDJc4KavZXufnHQHTW2ySMiVMg ggoGUjd1v0HIuxs/SkfXETcnBp/OhipYosAEiN5H8BMGU5ePOPt3F/VjU 5LudrkK/klDIEQ01YBeDBgHoc4atCJ1Sr9BaA5IcnkmKwmla8YLyA9V6i VZrZLGJPCm0KjhqCPMHcwFlIW1YKowjlAQeCETZVi7/uU3sqQPciHJgPn RCy1Tn2EpzAU0VkOoo8W5EYduUnNAbZqGeDIK4B+OG9xNFem7mdD/DoLT g==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264694" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264694" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685324" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685324" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id 684BA580DB2; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 06/11] platform/x86/intel/pmc: Split pmc_core_ssram_get_pmc() Date: Fri, 22 Sep 2023 14:30:27 -0700 Message-Id: <20230922213032.1770590-7-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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" Each PMC has an associated SSRAM device for accessing additional counters. However, only the first is discoverable as a PCI device to the OS. The remaining devices are hidden but their BARs are still accessible and their addresses are stored in the BAR of the exposed device. Clean up the code handling the SSRAM discovery. Create two separate functions for finding the primary and secondary PMCs. Also changes the return type from void to allow returning an error when failing to find the primary PMC. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/core.h | 2 +- drivers/platform/x86/intel/pmc/core_ssram.c | 127 ++++++++++++++------ drivers/platform/x86/intel/pmc/mtl.c | 10 +- 3 files changed, 96 insertions(+), 43 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/i= ntel/pmc/core.h index ccf24e0f5e50..edaa70067e41 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -492,7 +492,7 @@ int pmc_core_resume_common(struct pmc_dev *pmcdev); int get_primary_reg_base(struct pmc *pmc); extern void pmc_core_get_low_power_modes(struct pmc_dev *pmcdev); =20 -extern void pmc_core_ssram_init(struct pmc_dev *pmcdev); +extern int pmc_core_ssram_init(struct pmc_dev *pmcdev); =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/core_ssram.c b/drivers/platform= /x86/intel/pmc/core_ssram.c index 13fa16f0d52e..ab5cc07fb177 100644 --- a/drivers/platform/x86/intel/pmc/core_ssram.c +++ b/drivers/platform/x86/intel/pmc/core_ssram.c @@ -35,20 +35,20 @@ static inline u64 get_base(void __iomem *addr, u32 offs= et) return lo_hi_readq(addr + offset) & GENMASK_ULL(63, 3); } =20 -static void +static int pmc_core_pmc_add(struct pmc_dev *pmcdev, u64 pwrm_base, const struct pmc_reg_map *reg_map, int pmc_index) { struct pmc *pmc =3D pmcdev->pmcs[pmc_index]; =20 if (!pwrm_base) - return; + return -ENODEV; =20 /* Memory for primary PMC has been allocated in core.c */ if (!pmc) { pmc =3D devm_kzalloc(&pmcdev->pdev->dev, sizeof(*pmc), GFP_KERNEL); if (!pmc) - return; + return -ENOMEM; } =20 pmc->map =3D reg_map; @@ -57,77 +57,128 @@ pmc_core_pmc_add(struct pmc_dev *pmcdev, u64 pwrm_base, =20 if (!pmc->regbase) { devm_kfree(&pmcdev->pdev->dev, pmc); - return; + return -ENOMEM; } =20 pmcdev->pmcs[pmc_index] =3D pmc; + + return 0; } =20 -static void -pmc_core_ssram_get_pmc(struct pmc_dev *pmcdev, void __iomem *ssram, u32 of= fset, - int pmc_idx) +static int +pmc_core_get_secondary_pmc(struct pmc_dev *pmcdev, int pmc_idx, u32 offset) { - u64 pwrm_base; + struct pci_dev *ssram_pcidev =3D pmcdev->ssram_pcidev; + const struct pmc_reg_map *map; + void __iomem *main_ssram, *secondary_ssram; + u64 ssram_base, pwrm_base; u16 devid; + int ret; + + if (!pmcdev->regmap_list) + return -ENOENT; =20 - if (pmc_idx !=3D PMC_IDX_SOC) { - u64 ssram_base =3D get_base(ssram, offset); + /* + * The secondary PMC BARS (which are behind hidden PCI devices) are read + * from fixed offsets in MMIO of the primary PMC BAR. + */ + ssram_base =3D ssram_pcidev->resource[0].start; + main_ssram =3D ioremap(ssram_base, SSRAM_HDR_SIZE); + if (!main_ssram) + return -ENOMEM; + + ssram_base =3D get_base(main_ssram, offset); + secondary_ssram =3D ioremap(ssram_base, SSRAM_HDR_SIZE); + if (!secondary_ssram) { + ret =3D -ENOMEM; + goto secondary_remap_fail; + } =20 - if (!ssram_base) - return; + pwrm_base =3D get_base(secondary_ssram, SSRAM_PWRM_OFFSET); + devid =3D readw(secondary_ssram + SSRAM_DEVID_OFFSET); =20 - ssram =3D ioremap(ssram_base, SSRAM_HDR_SIZE); - if (!ssram) - return; + map =3D pmc_core_find_regmap(pmcdev->regmap_list, devid); + if (!map) { + ret =3D -ENODEV; + goto find_regmap_fail; } =20 + ret =3D pmc_core_pmc_add(pmcdev, pwrm_base, map, pmc_idx); + +find_regmap_fail: + iounmap(secondary_ssram); +secondary_remap_fail: + iounmap(main_ssram); + + return ret; + +} + +static int +pmc_core_get_primary_pmc(struct pmc_dev *pmcdev) +{ + struct pci_dev *ssram_pcidev =3D pmcdev->ssram_pcidev; + const struct pmc_reg_map *map; + void __iomem *ssram; + u64 ssram_base, pwrm_base; + u16 devid; + int ret; + + if (!pmcdev->regmap_list) + return -ENOENT; + + /* The primary PMC (SOC die) BAR is BAR 0 in config space. */ + ssram_base =3D ssram_pcidev->resource[0].start; + ssram =3D ioremap(ssram_base, SSRAM_HDR_SIZE); + if (!ssram) + return -ENOMEM; + pwrm_base =3D get_base(ssram, SSRAM_PWRM_OFFSET); devid =3D readw(ssram + SSRAM_DEVID_OFFSET); =20 - if (pmcdev->regmap_list) { - const struct pmc_reg_map *map; - - map =3D pmc_core_find_regmap(pmcdev->regmap_list, devid); - if (map) - pmc_core_pmc_add(pmcdev, pwrm_base, map, pmc_idx); + map =3D pmc_core_find_regmap(pmcdev->regmap_list, devid); + if (!map) { + ret =3D -ENODEV; + goto find_regmap_fail; } =20 - if (pmc_idx !=3D PMC_IDX_SOC) - iounmap(ssram); + ret =3D pmc_core_pmc_add(pmcdev, pwrm_base, map, PMC_IDX_MAIN); + +find_regmap_fail: + iounmap(ssram); + + return ret; } =20 -void pmc_core_ssram_init(struct pmc_dev *pmcdev) +int pmc_core_ssram_init(struct pmc_dev *pmcdev) { - void __iomem *ssram; struct pci_dev *pcidev; - u64 ssram_base; int ret; =20 pcidev =3D pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(20, 2)); if (!pcidev) - goto out; + return -ENODEV; =20 ret =3D pcim_enable_device(pcidev); if (ret) goto release_dev; =20 - ssram_base =3D pcidev->resource[0].start; - ssram =3D ioremap(ssram_base, SSRAM_HDR_SIZE); - if (!ssram) - goto disable_dev; - pmcdev->ssram_pcidev =3D pcidev; =20 - pmc_core_ssram_get_pmc(pmcdev, ssram, 0, PMC_IDX_SOC); - pmc_core_ssram_get_pmc(pmcdev, ssram, SSRAM_IOE_OFFSET, PMC_IDX_IOE); - pmc_core_ssram_get_pmc(pmcdev, ssram, SSRAM_PCH_OFFSET, PMC_IDX_PCH); + ret =3D pmc_core_get_primary_pmc(pmcdev); + if (ret) + goto disable_dev; =20 - iounmap(ssram); -out: - return; + pmc_core_get_secondary_pmc(pmcdev, PMC_IDX_IOE, SSRAM_IOE_OFFSET); + pmc_core_get_secondary_pmc(pmcdev, PMC_IDX_PCH, SSRAM_PCH_OFFSET); + + return 0; =20 disable_dev: + pmcdev->ssram_pcidev =3D NULL; pci_disable_device(pcidev); release_dev: pci_dev_put(pcidev); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/in= tel/pmc/mtl.c index c3b5f4fe01d1..780874142a90 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -990,12 +990,14 @@ int mtl_core_init(struct pmc_dev *pmcdev) mtl_d3_fixup(); =20 pmcdev->resume =3D mtl_resume; - pmcdev->regmap_list =3D mtl_pmc_info_list; - pmc_core_ssram_init(pmcdev); =20 - /* If regbase not assigned, set map and discover using legacy method */ - if (!pmc->regbase) { + /* + * If ssram init fails use legacy method to at least get the + * primary PMC + */ + ret =3D pmc_core_ssram_init(pmcdev); + if (ret) { pmc->map =3D &mtl_socm_reg_map; ret =3D get_primary_reg_base(pmc); if (ret) --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 A9AA6CE7A81 for ; Fri, 22 Sep 2023 21:31:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbjIVVbO (ORCPT ); Fri, 22 Sep 2023 17:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjIVVam (ORCPT ); Fri, 22 Sep 2023 17:30:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B576F7; Fri, 22 Sep 2023 14:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418236; x=1726954236; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=tM4JJBMIkXbKSMqXfFcmrOXZSw4Fq/7w/bTUHxLxgmA=; b=S87kNyRaQ8XNDZGJSpizdwIG4Hs9N8xCwl0Ia+pnr1lQWfq0DJt2gzeZ m8dhwx7ltQRYVtmksfC4Nx227NOGr5/zilmP99F3DlbYJJfttf1uMUCCB 4s2Ay6vtVnI3ewYAtHK2ZA6J7LutLgyMddQ1uwVKypmOvIoZIwbvPtV0k zCgSR/xvdBpGHVajgWyH4wniETsXZUspteKolHQ0yT5ncocrsF7qtzq02 IdVfdz5PKavG0k+twziLQrmJY6KN0jZP4Rb0I5BHnv47ENY80EnCTfyRQ Ly3j3dYwlLPEePKSR5xxxVyu4uvXXVyisxXx1DZ1S2B/1Uui8LKxsa6dM w==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264697" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264697" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685327" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685327" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id 881D1580BBE; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 07/11] platform/x86/intel/pmc: Find and register PMC telemetry entries Date: Fri, 22 Sep 2023 14:30:28 -0700 Message-Id: <20230922213032.1770590-8-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 counters that are structured in Intel Platform Monitoring Technology (PMT) telemetry regions. Look for and register these telemetry regions from the driver so that they may be read using the Intel PMT ABI. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/Kconfig | 1 + drivers/platform/x86/intel/pmc/core_ssram.c | 52 +++++++++++++++++++++ 2 files changed, 53 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_ssram.c b/drivers/platform= /x86/intel/pmc/core_ssram.c index ab5cc07fb177..b2abaf106bc5 100644 --- a/drivers/platform/x86/intel/pmc/core_ssram.c +++ b/drivers/platform/x86/intel/pmc/core_ssram.c @@ -12,6 +12,8 @@ #include =20 #include "core.h" +#include "../vsec.h" +#include "../pmt/telemetry.h" =20 #define SSRAM_HDR_SIZE 0x100 #define SSRAM_PWRM_OFFSET 0x14 @@ -21,6 +23,49 @@ #define SSRAM_IOE_OFFSET 0x68 #define SSRAM_DEVID_OFFSET 0x70 =20 +static void +pmc_add_pmt(struct pmc_dev *pmcdev, u64 ssram_base, void __iomem *ssram) +{ + struct pci_dev *pcidev =3D pmcdev->ssram_pcidev; + struct intel_vsec_platform_info info =3D {}; + struct intel_vsec_header *headers[2] =3D {}; + struct intel_vsec_header header; + void __iomem *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; + info.parent =3D &pmcdev->pdev->dev; + + intel_vsec_register(pcidev, &info); +} + static const struct pmc_reg_map *pmc_core_find_regmap(struct pmc_info *lis= t, u16 devid) { for (; list->map; ++list) @@ -97,6 +142,9 @@ pmc_core_get_secondary_pmc(struct pmc_dev *pmcdev, int p= mc_idx, u32 offset) pwrm_base =3D get_base(secondary_ssram, SSRAM_PWRM_OFFSET); devid =3D readw(secondary_ssram + SSRAM_DEVID_OFFSET); =20 + /* Find and register and PMC telemetry entries */ + pmc_add_pmt(pmcdev, ssram_base, main_ssram); + map =3D pmc_core_find_regmap(pmcdev->regmap_list, devid); if (!map) { ret =3D -ENODEV; @@ -136,6 +184,9 @@ pmc_core_get_primary_pmc(struct pmc_dev *pmcdev) pwrm_base =3D get_base(ssram, SSRAM_PWRM_OFFSET); devid =3D readw(ssram + SSRAM_DEVID_OFFSET); =20 + /* Find and register and PMC telemetry entries */ + pmc_add_pmt(pmcdev, ssram_base, ssram); + map =3D pmc_core_find_regmap(pmcdev->regmap_list, devid); if (!map) { ret =3D -ENODEV; @@ -182,3 +233,4 @@ int pmc_core_ssram_init(struct pmc_dev *pmcdev) =20 return ret; } +MODULE_IMPORT_NS(INTEL_VSEC); --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 949EFCE7A81 for ; Fri, 22 Sep 2023 21:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbjIVVbK (ORCPT ); Fri, 22 Sep 2023 17:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbjIVVan (ORCPT ); Fri, 22 Sep 2023 17:30:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0EE1139; Fri, 22 Sep 2023 14:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418236; x=1726954236; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=yaRuwBmb+tc4pEFWxUAfPpjeX8AH4EOSultYUtUmsyM=; b=XUkMLe0o68Q/MMfBiUNTJimy0uXLqC7Nl7kZCP/tfK2fAxhqDx+1ylcj h9Yj7IqOnSMEOVU8ZnF9ehed3WP9qt3jgCUAabHd+2+YGn/PRqyQm5kIn g395/K1+P2M9TJuzpFcKon8/E0QNCXbx+Tq5c51zTMeP0ICXknLH7mCdS hs+uQ0AJv2OmqAt3KJ9yg/uY3tS7AJo4Aqu6D42awlKr1SmChlYWh3yI5 aXXZYieMRBGU1lAXDAaQ9agngA17AhwyvvcbiT7fCcgimB8zAX4lXdR0k X/NP7j3cbx8NQsD28o9hmsoTlO74Qq+QdixUj7dizArratgLh14N7V/za Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264699" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264699" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685331" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685331" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:33 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id A69EE580BB9; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 08/11] platform/x86/intel/pmc: Display LPM requirements for multiple PMCs Date: Fri, 22 Sep 2023 14:30:29 -0700 Message-Id: <20230922213032.1770590-9-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 Update the substate_requirements attribute to display the requirements for all the PMCs on a package. Signed-off-by: Rajvi Jingar --- drivers/platform/x86/intel/pmc/core.c | 129 ++++++++++++++------------ 1 file changed, 71 insertions(+), 58 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/i= ntel/pmc/core.c index e58c8cc286a3..df2bcead1723 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -728,7 +728,7 @@ static int pmc_core_substate_l_sts_regs_show(struct seq= _file *s, void *unused) } DEFINE_SHOW_ATTRIBUTE(pmc_core_substate_l_sts_regs); =20 -static void pmc_core_substate_req_header_show(struct seq_file *s) +static void pmc_core_substate_req_header_show(struct seq_file *s, int pmc_= index) { struct pmc_dev *pmcdev =3D s->private; int i, mode; @@ -743,68 +743,81 @@ static void pmc_core_substate_req_header_show(struct = seq_file *s) static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unuse= d) { struct pmc_dev *pmcdev =3D s->private; - struct pmc *pmc =3D pmcdev->pmcs[PMC_IDX_MAIN]; - const struct pmc_bit_map **maps =3D pmc->map->lpm_sts; - const struct pmc_bit_map *map; - const int num_maps =3D pmc->map->lpm_num_maps; - u32 sts_offset =3D pmc->map->lpm_status_offset; - u32 *lpm_req_regs =3D pmc->lpm_req_regs; - int mp; - - /* Display the header */ - pmc_core_substate_req_header_show(s); - - /* Loop over maps */ - for (mp =3D 0; mp < num_maps; mp++) { - u32 req_mask =3D 0; - u32 lpm_status; - int mode, idx, i, len =3D 32; - - /* - * Capture the requirements and create a mask so that we only - * show an element if it's required for at least one of the - * enabled low power modes - */ - pmc_for_each_mode(idx, mode, pmcdev) - req_mask |=3D lpm_req_regs[mp + (mode * num_maps)]; - - /* Get the last latched status for this map */ - lpm_status =3D pmc_core_reg_read(pmc, sts_offset + (mp * 4)); - - /* Loop over elements in this map */ - map =3D maps[mp]; - for (i =3D 0; map[i].name && i < len; i++) { - u32 bit_mask =3D map[i].bit_mask; - - if (!(bit_mask & req_mask)) - /* - * Not required for any enabled states - * so don't display - */ - continue; - - /* Display the element name in the first column */ - seq_printf(s, "%30s |", map[i].name); - - /* Loop over the enabled states and display if required */ - pmc_for_each_mode(idx, mode, pmcdev) { - if (lpm_req_regs[mp + (mode * num_maps)] & bit_mask) - seq_printf(s, " %9s |", - "Required"); + u32 sts_offset; + u32 *lpm_req_regs; + int num_maps, mp, pmc_index; + + for (pmc_index =3D 0; pmc_index < ARRAY_SIZE(pmcdev->pmcs); ++pmc_index) { + struct pmc *pmc =3D pmcdev->pmcs[pmc_index]; + const struct pmc_bit_map **maps; + + if (!pmc) + continue; + + maps =3D pmc->map->lpm_sts; + num_maps =3D pmc->map->lpm_num_maps; + sts_offset =3D pmc->map->lpm_status_offset; + lpm_req_regs =3D pmc->lpm_req_regs; + + if (!lpm_req_regs) + continue; + + /* Display the header */ + pmc_core_substate_req_header_show(s, pmc_index); + + /* Loop over maps */ + for (mp =3D 0; mp < num_maps; mp++) { + u32 req_mask =3D 0; + u32 lpm_status; + const struct pmc_bit_map *map; + int mode, idx, i, len =3D 32; + + /* + * Capture the requirements and create a mask so that we only + * show an element if it's required for at least one of the + * enabled low power modes + */ + pmc_for_each_mode(idx, mode, pmcdev) + req_mask |=3D lpm_req_regs[mp + (mode * num_maps)]; + + /* Get the last latched status for this map */ + lpm_status =3D pmc_core_reg_read(pmc, sts_offset + (mp * 4)); + + /* Loop over elements in this map */ + map =3D maps[mp]; + for (i =3D 0; map[i].name && i < len; i++) { + u32 bit_mask =3D map[i].bit_mask; + + if (!(bit_mask & req_mask)) { + /* + * Not required for any enabled states + * so don't display + */ + continue; + } + + /* Display the element name in the first column */ + seq_printf(s, "pmc%d: %26s |", pmc_index, map[i].name); + + /* Loop over the enabled states and display if required */ + pmc_for_each_mode(idx, mode, pmcdev) { + if (lpm_req_regs[mp + (mode * num_maps)] & bit_mask) + seq_printf(s, " %9s |", + "Required"); + else + seq_printf(s, " %9s |", " "); + } + + /* In Status column, show the last captured state of this agent */ + if (lpm_status & bit_mask) + seq_printf(s, " %9s |", "Yes"); else seq_printf(s, " %9s |", " "); + + seq_puts(s, "\n"); } - - /* In Status column, show the last captured state of this agent */ - if (lpm_status & bit_mask) - seq_printf(s, " %9s |", "Yes"); - else - seq_printf(s, " %9s |", " "); - - seq_puts(s, "\n"); } } - return 0; } DEFINE_SHOW_ATTRIBUTE(pmc_core_substate_req_regs); --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 E2E79CE7A81 for ; Fri, 22 Sep 2023 21:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbjIVVbB (ORCPT ); Fri, 22 Sep 2023 17:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbjIVVan (ORCPT ); Fri, 22 Sep 2023 17:30:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40C15194; Fri, 22 Sep 2023 14:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418237; x=1726954237; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=z8g8xnqJtSfXvsrjcjZTFejouzzcLQ07FywJr4k7Iy4=; b=A+FIVPgtUfwkYDtCvbWk74496Q4aOA1EdzpX9XMOYzZCVmv8jeMMZcLv FgpdYzpLbMnJ7LOp4aEjwv7Mu3ftnbd56MMD4M+Tp+pFizrFr8DqQzzG3 Ek1iTsK8y9mdKLRrq8I67no3c0H+sMejBIEXtdlRfZjAVv+EXSmxyT9Wp StnoYzE5CeurBECzTjDzzEcKVnMXgi2tX0uhnMHRcUMrlbdSKMctfZj0F EjCdh66o7Bao2t7pG28SHWaSwkJXGUuSda2piT/rhdur3ZhBqLPey9dav 6KPWH++G+H3DIUgbMA+Fbzt8qKrAuX3wCJbcjAyI6ySx2tp9HwvgxKNuT Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="371264701" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="371264701" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="747685334" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="747685334" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:34 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id C5DA0580BBE; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 09/11] platform/x86/intel/pmc: Retrieve LPM information using Intel PMT Date: Fri, 22 Sep 2023 14:30:30 -0700 Message-Id: <20230922213032.1770590-10-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 On supported platforms, the low power mode (LPM) requirements for entering each idle substate are described in Platform Monitoring Technology (PMT) telemetry entries. Provide a function for platform code to attempt to find and read the requirements from the telemetry entries. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/core.h | 3 + drivers/platform/x86/intel/pmc/core_ssram.c | 135 ++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/i= ntel/pmc/core.h index edaa70067e41..85b6f6ae4995 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -320,6 +320,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 /** @@ -329,6 +330,7 @@ struct pmc_reg_map { * specific attributes */ struct pmc_info { + u32 guid; u16 devid; const struct pmc_reg_map *map; }; @@ -486,6 +488,7 @@ extern const struct pmc_bit_map *mtl_ioem_lpm_maps[]; extern const struct pmc_reg_map mtl_ioem_reg_map; =20 extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev); +extern int pmc_core_ssram_get_lpm_reqs(struct pmc_dev *pmcdev); extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value); =20 int pmc_core_resume_common(struct pmc_dev *pmcdev); diff --git a/drivers/platform/x86/intel/pmc/core_ssram.c b/drivers/platform= /x86/intel/pmc/core_ssram.c index b2abaf106bc5..a0ce4e8b1b6d 100644 --- a/drivers/platform/x86/intel/pmc/core_ssram.c +++ b/drivers/platform/x86/intel/pmc/core_ssram.c @@ -23,6 +23,140 @@ #define SSRAM_IOE_OFFSET 0x68 #define SSRAM_DEVID_OFFSET 0x70 =20 +/* PCH query */ +#define LPM_HEADER_OFFSET 1 +#define LPM_REG_COUNT 28 +#define LPM_MODE_OFFSET 1 + +static u32 pmc_core_find_guid(struct pmc_info *list, const struct pmc_reg_= map *map) +{ + for (; list->map; ++list) + if (list->map =3D=3D map) + return list->guid; + + return 0; +} + +static int pmc_core_get_lpm_req(struct pmc_dev *pmcdev, struct pmc *pmc) +{ + struct telem_endpoint *ep; + const u8 *lpm_indices; + int num_maps, mode_offset =3D 0; + int ret, mode, i; + int lpm_size; + u32 guid; + + lpm_indices =3D pmc->map->lpm_reg_index; + num_maps =3D pmc->map->lpm_num_maps; + lpm_size =3D LPM_MAX_NUM_MODES * num_maps; + + guid =3D pmc_core_find_guid(pmcdev->regmap_list, pmc->map); + if (!guid) + return -ENXIO; + + ep =3D pmt_telem_find_and_register_endpoint(pmcdev->ssram_pcidev, guid, 0= ); + if (IS_ERR(ep)) { + dev_dbg(&pmcdev->pdev->dev, "couldn't get telem endpoint %ld", + PTR_ERR(ep)); + return -EPROBE_DEFER; + } + + pmc->lpm_req_regs =3D devm_kzalloc(&pmcdev->pdev->dev, + lpm_size * sizeof(u32), + GFP_KERNEL); + if (!pmc->lpm_req_regs) { + ret =3D -ENOMEM; + goto unregister_ep; + } + + /* + * PMC Low Power Mode (LPM) requirements table + * + * In telemetry space, the LPM table contains a 4 byte header followed + * by 8 consecutive mode blocks (one for each LPM mode). Each block + * has a 4 byte header followed by a set of registers that describe the + * IP state requirements for the given mode. The IP mapping is platform + * specific but the same for each block, making for easy analysis. + * Platforms only use a subset of the space to track the requirements + * for their IPs. Callers provide the requirement registers they use as + * a list of indices. Each requirement register is associated with an + * IP map that's maintained by the caller. + * + * Header + * +----+----------------------------+----------------------------+ + * | 0 | REVISION | ENABLED MODES | + * +----+--------------+-------------+-------------+--------------+ + * + * Low Power Mode 0 Block + * +----+--------------+-------------+-------------+--------------+ + * | 1 | SUB ID | SIZE | MAJOR | MINOR | + * +----+--------------+-------------+-------------+--------------+ + * | 2 | LPM0 Requirements 0 | + * +----+---------------------------------------------------------+ + * | | ... | + * +----+---------------------------------------------------------+ + * | 29 | LPM0 Requirements 27 | + * +----+---------------------------------------------------------+ + * + * ... + * + * Low Power Mode 7 Block + * +----+--------------+-------------+-------------+--------------+ + * | | SUB ID | SIZE | MAJOR | MINOR | + * +----+--------------+-------------+-------------+--------------+ + * | 60 | LPM7 Requirements 0 | + * +----+---------------------------------------------------------+ + * | | ... | + * +----+---------------------------------------------------------+ + * | 87 | LPM7 Requirements 27 | + * +----+---------------------------------------------------------+ + * + */ + mode_offset =3D LPM_HEADER_OFFSET + LPM_MODE_OFFSET; + pmc_for_each_mode(i, mode, pmcdev) { + u32 *req_offset =3D pmc->lpm_req_regs + (mode * num_maps); + int m; + + for (m =3D 0; m < num_maps; m++) { + u8 sample_id =3D lpm_indices[m] + mode_offset; + + ret =3D pmt_telem_read32(ep, sample_id, req_offset, 1); + if (ret) { + dev_err(&pmcdev->pdev->dev, + "couldn't read Low Power Mode requirements: %d\n", ret); + devm_kfree(&pmcdev->pdev->dev, pmc->lpm_req_regs); + goto unregister_ep; + } + ++req_offset; + } + mode_offset +=3D (LPM_REG_COUNT + LPM_MODE_OFFSET); + } + +unregister_ep: + pmt_telem_unregister_endpoint(ep); + + return ret; +} + +int pmc_core_ssram_get_lpm_reqs(struct pmc_dev *pmcdev) +{ + int ret, i; + + if (!pmcdev->ssram_pcidev) + return -ENODEV; + + for (i =3D 0; i < ARRAY_SIZE(pmcdev->pmcs); ++i) { + if (!pmcdev->pmcs[i]) + continue; + + ret =3D pmc_core_get_lpm_req(pmcdev, pmcdev->pmcs[i]); + if (ret) + return ret; + } + + return 0; +} + static void pmc_add_pmt(struct pmc_dev *pmcdev, u64 ssram_base, void __iomem *ssram) { @@ -234,3 +368,4 @@ int pmc_core_ssram_init(struct pmc_dev *pmcdev) return ret; } MODULE_IMPORT_NS(INTEL_VSEC); +MODULE_IMPORT_NS(INTEL_PMT_TELEMETRY); --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 784E1CE7A8B for ; Fri, 22 Sep 2023 21:30:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbjIVVas (ORCPT ); Fri, 22 Sep 2023 17:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbjIVVak (ORCPT ); Fri, 22 Sep 2023 17:30:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFC43C1; Fri, 22 Sep 2023 14:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418234; x=1726954234; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=ShdByvzHZrIatOiiLohtDB7ahuIepttl4FPmXc1tWd0=; b=L2kIgiJAHiWoqzcB+ojIgpaqg5V9hZNZcNXdEm4qW+js73H3Px64mLir xZSiKNvWQs0yJfHUN+bgefWZRU2hoCCFSjVz5bvDGjDoYnZQGujr8mArF sbJhTgMCY72FdyaOMQuj2V/vdTpUMeqvvj7Iwtsrd9ttDLJKOfcBzBKfh RAOt53x1PQoMQR77fAS7jbncgbvfU6PxNKC7RJf9eY0uEgxjkJNoB8K3k RIsT1PcMr3tzMttwrJKT0sqMYftaZ39EwjH7YYO9nePeCYBcJ99RqG26m ud7xhFt6peY5wYfj7SBAOp4WM30dOUD3cK1NRHC3N8YOBQTZ6KLwYUf2o g==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="379828421" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="379828421" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="813237856" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="813237856" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:34 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id E98B8580DB2; Fri, 22 Sep 2023 14:30:33 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 10/11] platform/x86/intel/pmc: Read low power mode requirements for MTL-M and MTL-P Date: Fri, 22 Sep 2023 14:30:31 -0700 Message-Id: <20230922213032.1770590-11-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 Add support to read the low power mode requirements for Meteor Lake M and Meteor Lake P. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/mtl.c | 39 +++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/in= tel/pmc/mtl.c index 780874142a90..c2ac50cfdd51 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -11,6 +11,13 @@ #include #include "core.h" =20 +/* PMC SSRAM PMT Telemetry GUIDS */ +#define SOCP_LPM_REQ_GUID 0x2625030 +#define IOEM_LPM_REQ_GUID 0x4357464 +#define IOEP_LPM_REQ_GUID 0x5077612 + +static const u8 MTL_LPM_REG_INDEX[] =3D {0, 4, 5, 6, 8, 9, 10, 11, 12, 13,= 14, 15, 16, 20}; + /* * Die Mapping to Product. * Product SOCDie IOEDie PCHDie @@ -465,6 +472,7 @@ const struct pmc_reg_map mtl_socm_reg_map =3D { .lpm_sts =3D mtl_socm_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 const struct pmc_bit_map mtl_ioep_pfear_map[] =3D { @@ -782,6 +790,13 @@ const struct pmc_reg_map mtl_ioep_reg_map =3D { .ltr_show_sts =3D mtl_ioep_ltr_show_map, .ltr_ignore_offset =3D CNP_PMC_LTR_IGNORE_OFFSET, .ltr_ignore_max =3D ADL_NUM_IP_IGN_ALLOWED, + .lpm_num_maps =3D ADL_LPM_NUM_MAPS, + .lpm_res_counter_step_x2 =3D TGL_PMC_LPM_RES_COUNTER_STEP_X2, + .lpm_residency_offset =3D MTL_LPM_RESIDENCY_OFFSET, + .lpm_priority_offset =3D MTL_LPM_PRI_OFFSET, + .lpm_en_offset =3D MTL_LPM_EN_OFFSET, + .lpm_sts_latch_en_offset =3D MTL_LPM_STATUS_LATCH_EN_OFFSET, + .lpm_reg_index =3D MTL_LPM_REG_INDEX, }; =20 const struct pmc_bit_map mtl_ioem_pfear_map[] =3D { @@ -922,6 +937,13 @@ const struct pmc_reg_map mtl_ioem_reg_map =3D { .ltr_show_sts =3D mtl_ioep_ltr_show_map, .ltr_ignore_offset =3D CNP_PMC_LTR_IGNORE_OFFSET, .ltr_ignore_max =3D ADL_NUM_IP_IGN_ALLOWED, + .lpm_sts_latch_en_offset =3D MTL_LPM_STATUS_LATCH_EN_OFFSET, + .lpm_num_maps =3D ADL_LPM_NUM_MAPS, + .lpm_priority_offset =3D MTL_LPM_PRI_OFFSET, + .lpm_en_offset =3D MTL_LPM_EN_OFFSET, + .lpm_res_counter_step_x2 =3D TGL_PMC_LPM_RES_COUNTER_STEP_X2, + .lpm_residency_offset =3D MTL_LPM_RESIDENCY_OFFSET, + .lpm_reg_index =3D MTL_LPM_REG_INDEX, }; =20 #define PMC_DEVID_SOCM 0x7e7f @@ -929,16 +951,19 @@ const struct pmc_reg_map mtl_ioem_reg_map =3D { #define PMC_DEVID_IOEM 0x7ebf static struct pmc_info mtl_pmc_info_list[] =3D { { - .devid =3D PMC_DEVID_SOCM, - .map =3D &mtl_socm_reg_map, + .guid =3D SOCP_LPM_REQ_GUID, + .devid =3D PMC_DEVID_SOCM, + .map =3D &mtl_socm_reg_map, }, { - .devid =3D PMC_DEVID_IOEP, - .map =3D &mtl_ioep_reg_map, + .guid =3D IOEP_LPM_REQ_GUID, + .devid =3D PMC_DEVID_IOEP, + .map =3D &mtl_ioep_reg_map, }, { - .devid =3D PMC_DEVID_IOEM, - .map =3D &mtl_ioem_reg_map + .guid =3D IOEM_LPM_REQ_GUID, + .devid =3D PMC_DEVID_IOEM, + .map =3D &mtl_ioem_reg_map }, {} }; @@ -1012,5 +1037,7 @@ int mtl_core_init(struct pmc_dev *pmcdev) dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); pmc_core_send_ltr_ignore(pmcdev, 3); =20 + ret =3D pmc_core_ssram_get_lpm_reqs(pmcdev); + return 0; } --=20 2.34.1 From nobody Tue Dec 16 03:19:50 2025 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 7FE3ECE7A81 for ; Fri, 22 Sep 2023 21:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230110AbjIVVbF (ORCPT ); Fri, 22 Sep 2023 17:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbjIVVam (ORCPT ); Fri, 22 Sep 2023 17:30:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C63A2136; Fri, 22 Sep 2023 14:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695418235; x=1726954235; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=WfK7ZHVA2wFzt1NZqESMIwsrJ1vJQnZD6txRV7FIyGI=; b=HfFO9EHJtDBYljpXsGJXFhqUlNEganL/pmOGKbf/juhRfApfV8pOx10u t376+q66TrsLiTpOl7GYLdrmb6mUh70vciPAPXg9783mWJxANOsBcgaBa tK5EcbSFgb7JAqctImFeiOLyX06FuSV2+toJOAslpyduf2jL6ko54SEnr fc6spoViR/CfOn0d/Qk59ru6WWya9+PPw4dJ4z3AnbfOBNcm5impDVXa6 hCbVRUqiL7qu6ePHJPeaU5Sv0cOeCABYba9mDPucdFJgoddUj+dyZ4B1H nBluroNBv2Pe0drVZdSZm52UdDzW7LuV8IdYRlNXzIeeqrd0SnuYPeHLu g==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="379828423" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="379828423" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="813237857" X-IronPort-AV: E=Sophos;i="6.03,169,1694761200"; d="scan'208";a="813237857" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 14:30:34 -0700 Received: from debox1-desk4.intel.com (unknown [10.212.188.234]) by linux.intel.com (Postfix) with ESMTP id 14989580BB9; Fri, 22 Sep 2023 14:30:34 -0700 (PDT) From: "David E. Box" To: linux-kernel@vger.kernel.org, david.e.box@linux.intel.com, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH 11/11] platform/x86/intel/pmc: Add debug attribute for Die C6 counter Date: Fri, 22 Sep 2023 14:30:32 -0700 Message-Id: <20230922213032.1770590-12-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922213032.1770590-1-david.e.box@linux.intel.com> References: <20230922213032.1770590-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 "die_c6_us_show" counter in debugs and add support for Meteor Lake. Reads the counter value using Intel Platform Monitoring Technology (PMT) driver API. This counter is useful for determining the idle residency of CPUs in the compute tile. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/core.c | 55 +++++++++++++++++++++++++++ drivers/platform/x86/intel/pmc/core.h | 4 ++ drivers/platform/x86/intel/pmc/mtl.c | 32 ++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/i= ntel/pmc/core.c index df2bcead1723..790ed9481529 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -27,6 +27,7 @@ #include =20 #include "core.h" +#include "../pmt/telemetry.h" =20 /* Maximum number of modes supported by platfoms that has low power mode c= apability */ const char *pmc_lpm_modes[] =3D { @@ -822,6 +823,48 @@ static int pmc_core_substate_req_regs_show(struct seq_= file *s, void *unused) } DEFINE_SHOW_ATTRIBUTE(pmc_core_substate_req_regs); =20 +static unsigned int pmc_core_get_crystal_freq(void) +{ + unsigned int eax_denominator, ebx_numerator, ecx_hz, edx; + + if (boot_cpu_data.cpuid_level < 0x15) + return 0; + + eax_denominator =3D ebx_numerator =3D ecx_hz =3D edx =3D 0; + + /* CPUID 15H TSC/Crystal ratio, plus optionally Crystal Hz */ + cpuid(0x15, &eax_denominator, &ebx_numerator, &ecx_hz, &edx); + + if (ebx_numerator =3D=3D 0 || eax_denominator =3D=3D 0) + return 0; + + return ecx_hz; +} + +static int pmc_core_die_c6_us_show(struct seq_file *s, void *unused) +{ + struct pmc_dev *pmcdev =3D s->private; + u64 die_c6_res, count; + int ret; + + if (!pmcdev->crystal_freq) { + dev_warn_once(&pmcdev->pdev->dev, "%s: Bad crystal frequency\n", + __func__); + return -EINVAL; + } + + ret =3D pmt_telem_read(pmcdev->punit_ep, pmcdev->die_c6_offset, + &count, 1); + if (ret) + return ret; + + die_c6_res =3D div64_u64(count * 1000000ULL, pmcdev->crystal_freq); + seq_printf(s, "%llu\n", die_c6_res); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(pmc_core_die_c6_us); + static int pmc_core_lpm_latch_mode_show(struct seq_file *s, void *unused) { struct pmc_dev *pmcdev =3D s->private; @@ -1118,6 +1161,12 @@ static void pmc_core_dbgfs_register(struct pmc_dev *= pmcdev) pmcdev->dbgfs_dir, pmcdev, &pmc_core_substate_req_regs_fops); } + + if (pmcdev->has_die_c6) { + debugfs_create_file("die_c6_us_show", 0444, + pmcdev->dbgfs_dir, pmcdev, + &pmc_core_die_c6_us_fops); + } } =20 static const struct x86_cpu_id intel_pmc_core_ids[] =3D { @@ -1212,6 +1261,10 @@ static void pmc_core_clean_structure(struct platform= _device *pdev) pci_dev_put(pmcdev->ssram_pcidev); pci_disable_device(pmcdev->ssram_pcidev); } + + if (pmcdev->punit_ep) + pmt_telem_unregister_endpoint(pmcdev->punit_ep); + platform_set_drvdata(pdev, NULL); mutex_destroy(&pmcdev->lock); } @@ -1232,6 +1285,8 @@ static int pmc_core_probe(struct platform_device *pde= v) if (!pmcdev) return -ENOMEM; =20 + pmcdev->crystal_freq =3D pmc_core_get_crystal_freq(); + platform_set_drvdata(pdev, pmcdev); pmcdev->pdev =3D pdev; =20 diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/i= ntel/pmc/core.h index 85b6f6ae4995..6d7673145f90 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -16,6 +16,8 @@ #include #include =20 +struct telem_endpoint; + #define SLP_S0_RES_COUNTER_MASK GENMASK(31, 0) =20 #define PMC_BASE_ADDR_DEFAULT 0xFE000000 @@ -357,6 +359,7 @@ struct pmc { * @devs: pointer to an array of pmc pointers * @pdev: pointer to platform_device struct * @ssram_pcidev: pointer to pci device struct for the PMC SSRAM + * @crystal_freq: crystal frequency from cpuid * @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 @@ -374,6 +377,7 @@ struct pmc_dev { struct dentry *dbgfs_dir; struct platform_device *pdev; struct pci_dev *ssram_pcidev; + unsigned int crystal_freq; 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 c2ac50cfdd51..d791d4894c9d 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -10,12 +10,17 @@ =20 #include #include "core.h" +#include "../pmt/telemetry.h" =20 /* PMC SSRAM PMT Telemetry GUIDS */ #define SOCP_LPM_REQ_GUID 0x2625030 #define IOEM_LPM_REQ_GUID 0x4357464 #define IOEP_LPM_REQ_GUID 0x5077612 =20 +/* Die C6 from PUNIT telemetry */ +#define MTL_PMT_DMU_DIE_C6_OFFSET 15 +#define MTL_PMT_DMU_GUID 0x1A067102 + static const u8 MTL_LPM_REG_INDEX[] =3D {0, 4, 5, 6, 8, 9, 10, 11, 12, 13,= 14, 15, 16, 20}; =20 /* @@ -968,6 +973,32 @@ static struct pmc_info mtl_pmc_info_list[] =3D { {} }; =20 +static void mtl_punit_pmt_init(struct pmc_dev *pmcdev) +{ + struct telem_endpoint *ep; + struct pci_dev *pcidev; + + pcidev =3D pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(10, 0)); + if (!pcidev) { + dev_err(&pmcdev->pdev->dev, "PUNIT PMT device not found."); + return; + } + + ep =3D pmt_telem_find_and_register_endpoint(pcidev, MTL_PMT_DMU_GUID, 0); + if (IS_ERR(ep)) { + dev_err(&pmcdev->pdev->dev, + "pmc_core: couldn't get DMU telem endpoint %ld", + PTR_ERR(ep)); + return; + } + + pci_dev_put(pcidev); + pmcdev->punit_ep =3D ep; + + pmcdev->has_die_c6 =3D true; + pmcdev->die_c6_offset =3D MTL_PMT_DMU_DIE_C6_OFFSET; +} + #define MTL_GNA_PCI_DEV 0x7e4c #define MTL_IPU_PCI_DEV 0x7d19 #define MTL_VPU_PCI_DEV 0x7d1d @@ -1030,6 +1061,7 @@ int mtl_core_init(struct pmc_dev *pmcdev) } =20 pmc_core_get_low_power_modes(pmcdev); + mtl_punit_pmt_init(pmcdev); =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