From patchwork Wed Mar 15 18:33:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57571wrt; Wed, 15 Mar 2023 11:39:41 -0700 (PDT) X-Google-Smtp-Source: AK7set8wTN3XEqV3rV1l+Xw7NFUTs/ire6Tp4SYZaXzWJLlOFzhogC4pRJ431AoWrL5HTRFUIkhn X-Received: by 2002:a05:6a20:4295:b0:cb:6e9e:e6df with SMTP id o21-20020a056a20429500b000cb6e9ee6dfmr976330pzj.14.1678905581042; Wed, 15 Mar 2023 11:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905581; cv=none; d=google.com; s=arc-20160816; b=dGRwoTbcTycVT3PlGLEVwkwhIk8Xe1q/Ug8KSg2HFRtz75CjsKnaQMJD0CDONUlxtR NIk9zodZmKHWXVeq3D1KVsYC/tROXFYIZjLgmCttNJllLY3zHLGhtKSM1k6TkPlR3t00 baRuy2eivqiGudpoGdyhLK7ni1VXvZ6eI0jXbM8tEBJciRGrsiK6DUZxxZkSJEB28OAn LF2A72DIJZPOEPEOstuDgmcga+YFl84ZTJ6WovP2jyNqaNN3p2V8krr/tBDgCry0RyMn lMUvxcKlGwtxyLt5SHC27CLNQAusx0ETGAMSM1Bn5e3EA7RvrMenzCGtCULgq1jM94pJ en5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bys7EHaABGroWq7a5z/DX3n6Wm1v76reI0wKfu4GczA=; b=SAjzxAe/OulYwCEkKt3d4mG9d3dWEQLVn08wiYs40oIuPjqkzX7NRtQnPS0U4C6fcu ln17tTL1hBiTEh5jrre+yum9nxz2VdZjEb8ObkEeei2chhkMQ2Ol4E9d3Qq1ae43GHqu FfL+zUX0Ukr9BtWZxfpRKvEOLI7Xsw1q+yqbZ9Uq5fYoYy5xeuSTzQHSc8Yd6oNOkE1i 3aDN3IyZ/2gb350zgUr0DK2wd93fWr7jNgSSvr2omh0VmmI1Fx6G6mQBYE3H897UYHLs GAYSCRlx8dz+OeCU27rqhDwzkKsluzR3QZw/pDXQRz0fS3eNbzniVqbYsY011nbCqw6j +MEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O2zr4KPg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a056a00218300b00625d5128683si831093pfi.15.2023.03.15.11.39.26; Wed, 15 Mar 2023 11:39:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O2zr4KPg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231631AbjCOSeL (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbjCOSeK (ORCPT ); Wed, 15 Mar 2023 14:34:10 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81FB928D34; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905248; x=1710441248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hHV55N0QiZMcT4V3m9CPVkpMG+H53YsJVo4BOQ9V6kk=; b=O2zr4KPgXKfEJTuZdo8iE4lUHCHMtrEfWJV4ZKnc99JHmjA6/Nyyff7M fWg/asdb3ikfVHuMkqRFjEMMU+iHQ0OFkvQ74K0nKXSVGGaizHHeN8xm2 pG2HZ+ePuWbAc/6aePz6gP979/YI+usoYwW5QIbUN39Ix7/uN6SlBXeIP maonZJ3QB0Bh7TLbsj1a/zdDstJ6zuAKL9FdbWdgAfd8saHMAy2yEaVdl FoyM25YYmlhga33ms0nmqis5tWTDzdtwxrp/9XT5E9Ets2qNgapUbcwLk WVZzzmOlpvz+vCm75lamY5YRgjDoLVO3u2lIqTNJm5TxqjTzbUtlfod5n w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154523" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154523" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435199" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435199" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:06 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 64DF3580BF2; Wed, 15 Mar 2023 11:34:06 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 01/11] platform/x86/intel/vsec: Add intel_vsec_register Date: Wed, 15 Mar 2023 11:33:55 -0700 Message-Id: <20230315183405.2465630-2-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460098264934125?= X-GMAIL-MSGID: =?utf-8?q?1760460098264934125?= From: Gayatri Kammela Intel PCIe VSEC capabilities may be emulated in the MMIO space of other Intel devices like the Power Management Controller (PMC) SSRAM device. Add and export intel_vsec_register to allow those capabilities to be registered by other drivers. Reuses the existing intel_vsec_walk_header function which already creates entries from device data in lieu of a config space (used by DG1). Add a check to ensure that the memory region is available before creating a VSEC auxiliary device. Signed-off-by: Gayatri Kammela Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 2 +- drivers/platform/x86/intel/pmt/class.h | 5 ++- drivers/platform/x86/intel/vsec.c | 56 +++++++++----------------- drivers/platform/x86/intel/vsec.h | 51 ++++++++++++++++++++++- 4 files changed, 73 insertions(+), 41 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c index 46598dcb634a..9f505c6ef278 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -31,7 +31,7 @@ bool intel_pmt_is_early_client_hw(struct device *dev) * differences from the server platforms (which use the Out Of Band * Management Services Module OOBMSM). */ - return !!(ivdev->info->quirks & VSEC_QUIRK_EARLY_HW); + return !!(ivdev->quirks & VSEC_QUIRK_EARLY_HW); } EXPORT_SYMBOL_GPL(intel_pmt_is_early_client_hw); diff --git a/drivers/platform/x86/intel/pmt/class.h b/drivers/platform/x86/intel/pmt/class.h index db11d58867ce..17bc40b77efc 100644 --- a/drivers/platform/x86/intel/pmt/class.h +++ b/drivers/platform/x86/intel/pmt/class.h @@ -2,11 +2,10 @@ #ifndef _INTEL_PMT_CLASS_H #define _INTEL_PMT_CLASS_H -#include -#include #include #include #include +#include #include "../vsec.h" @@ -18,6 +17,8 @@ #define GET_BIR(v) ((v) & GENMASK(2, 0)) #define GET_ADDRESS(v) ((v) & GENMASK(31, 3)) +struct xarray; + struct intel_pmt_entry { struct bin_attribute pmt_bin_attr; struct kobject *kobj; diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index 13decf36c6de..a22354ee6ce3 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -24,13 +24,6 @@ #include "vsec.h" -/* 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); -/** - * struct intel_vsec_header - Common fields of Intel VSEC and DVSEC registers. - * @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 = 2, - VSEC_ID_WATCHER = 3, - VSEC_ID_CRASHLOG = 4, - VSEC_ID_SDSI = 65, - VSEC_ID_TPMI = 66, -}; - static enum intel_vsec_id intel_vsec_allow_list[] = { VSEC_ID_TELEMETRY, VSEC_ID_WATCHER, @@ -241,12 +206,21 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he header->offset + i * (header->entry_size * sizeof(u32)); tmp->end = tmp->start + (header->entry_size * sizeof(u32)) - 1; tmp->flags = 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)); } intel_vsec_dev->pcidev = pdev; intel_vsec_dev->resource = res; intel_vsec_dev->num_resources = header->num_entries; - intel_vsec_dev->info = info; + intel_vsec_dev->quirks = info->quirks; if (header->id == VSEC_ID_SDSI) intel_vsec_dev->ida = &intel_vsec_sdsi_ida; @@ -371,6 +345,16 @@ static bool intel_vsec_walk_vsec(struct pci_dev *pdev, return have_devices; } +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_device_id *id) { struct intel_vsec_platform_info *info; diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel/vsec.h index ae8fe92c5595..f600d6fe0830 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -1,13 +1,49 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _VSEC_H -#define _VSEC_H +#ifndef _INTEL_VSEC_H +#define _INTEL_VSEC_H #include #include +/* 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; +enum intel_vsec_id { + VSEC_ID_TELEMETRY = 2, + VSEC_ID_WATCHER = 3, + VSEC_ID_CRASHLOG = 4, + VSEC_ID_SDSI = 65, + VSEC_ID_TPMI = 66, +}; + +/** + * struct intel_vsec_header - Common fields of Intel VSEC and DVSEC registers. + * @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 = BIT(0), @@ -40,6 +76,7 @@ struct intel_vsec_device { int num_resources; void *priv_data; size_t priv_data_size; + unsigned long quirks; }; int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, @@ -55,4 +92,14 @@ static inline struct intel_vsec_device *auxdev_to_ivdev(struct auxiliary_device { return container_of(auxdev, struct intel_vsec_device, auxdev); } + +#if IS_ENABLED(CONFIG_INTEL_VSEC) +void intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info); +#else +static inline void +intel_vsec_register(struct pci_dev *pdev, + struct intel_vsec_platform_info *info) {} +#endif + #endif From patchwork Wed Mar 15 18:33:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57040wrt; Wed, 15 Mar 2023 11:38:25 -0700 (PDT) X-Google-Smtp-Source: AK7set+0kr3YohanOfZ7qc0mdfwwtANrXmSys6+np0trBsLQzLYMhJ3lLfQ5FHze0ClvMGeVXv16 X-Received: by 2002:aa7:968f:0:b0:625:6e00:210d with SMTP id f15-20020aa7968f000000b006256e00210dmr424195pfk.21.1678905505428; Wed, 15 Mar 2023 11:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905505; cv=none; d=google.com; s=arc-20160816; b=lzFrc8TR3SftezNdLC66wvkoYVriYwmWvM8inL0NRw0g83CZpjzXNJBMLYVdjV39Iz XSLpcYajXpyGibJBBkxMEyrcxrLksZL6obWcSsNOSh991nMTd8FZqrdt0mMH4QIB+x6H i7jaijdeq2Alr9+11CxrV9hBJ3jF8sMNBmdU+VoLFqDz+X7O/UqZii7dViLmybDQX5iT tLbPWPGlsMUor9gJ18+m19LFMzeoYXn5sM+m01YgD1ou44pEVpRImRK4wRxgFdouWd10 mi1jbV/XVNeucolpX2V0M3CyM0y/SUm+aS0RmxhV8nZOcPBYXbmqNwxQJ3GjLxA5Knps yozQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Zc2Yd3r+tDBaozoGoO4IpavhbgliqpJsVWMrfAaTV1A=; b=d9ovjLEPMYCbVMHzZ7eD+tRASkyYWP0/zCnbXIJXwmFeWA+FE+9cNmQrfVT9DN8w6y D4rT+2Yp1oMj2sV0yYYW+7YgAtcAJCEznfEQ0/jLkMaDnEUhI/WJIjo107OpB64M/7Se uwkHYeUJpxT0+SXDUwLSbbDwZHJaRBgYVOlWQP/eDA80x2BdNhHMwZZy4Yw4Xc5hhr9I Frt2rQEBtchLyqTqW8ngbhr1cPG396GKqENA2dsfeNJblkFJwQR4rK1T/vbna2oHpZAc NcJThIarh+pIsGaHUtvNqf9KrnS8qfwPiwMVRzCmcTxRu15MqRJU2Gvll1g9juaIv+4C 2U/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TeS5Z0iI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q20-20020a631f54000000b00502fd16cd1csi5423048pgm.367.2023.03.15.11.38.09; Wed, 15 Mar 2023 11:38:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TeS5Z0iI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231984AbjCOSeU (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231725AbjCOSeM (ORCPT ); Wed, 15 Mar 2023 14:34:12 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F32ABDFB; Wed, 15 Mar 2023 11:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905250; x=1710441250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+M93RTmQljP8okVyTKg1YF0nbH2IJeJvC34zMCSMUuA=; b=TeS5Z0iIqGhZf5RvX8zIjroIlUrGZBp2uqc04cnbhLb927eF43az2FnC C8GKS6SoULy8tw2odpCVRPoNUrsqhRsW9UEiCfHjEfvybO/Os14ERmhhm M9RIkztLfrZt70nhY390B7iIZAt/5SsPzuUJeV0kHJbjPsgditShelh7w eh4bP6WbttxnZRUKQ8vA5mP3ksJ/oCfye6sb9cK2zILibIpZFVz7f1K1b Mg2CMmkexHJBGM3euRsgaSXbFZR+5FudFzQnRAIJrpR3cYTPps0FVikCD KiduWAbybgQTCGeWPla7xVCLp8bvlfi2LU2dmV6p9a8Po+pZJogaqUP2G w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154528" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154528" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435202" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435202" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:06 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id A01C5580D29; Wed, 15 Mar 2023 11:34:06 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 02/11] platform/x86/intel/vsec: Explicitly enable capabilities Date: Wed, 15 Mar 2023 11:33:56 -0700 Message-Id: <20230315183405.2465630-3-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460019281826143?= X-GMAIL-MSGID: =?utf-8?q?1760460019281826143?= Any discovered Intel VSEC/DVSEC capabilities are enabled by default and only get disabled by quirk. Instead, remove such quirks and only enable support for capabilities that have been explicitly added to a new capabilities field. While here, also reorder the device info structures alphabetically. Signed-off-by: David E. Box --- drivers/platform/x86/intel/vsec.c | 65 +++++++++++++------------------ drivers/platform/x86/intel/vsec.h | 11 +++++- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index a22354ee6ce3..0d5cf250e288 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -32,14 +32,6 @@ static DEFINE_IDA(intel_vsec_ida); static DEFINE_IDA(intel_vsec_sdsi_ida); static DEFINE_XARRAY_ALLOC(auxdev_array); -static enum intel_vsec_id intel_vsec_allow_list[] = { - VSEC_ID_TELEMETRY, - VSEC_ID_WATCHER, - VSEC_ID_CRASHLOG, - VSEC_ID_SDSI, - VSEC_ID_TPMI, -}; - static const char *intel_vsec_name(enum intel_vsec_id id) { switch (id) { @@ -63,26 +55,19 @@ static const char *intel_vsec_name(enum intel_vsec_id id) } } -static bool intel_vsec_allowed(u16 id) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(intel_vsec_allow_list); i++) - if (intel_vsec_allow_list[i] == id) - return true; - - return false; -} - -static bool intel_vsec_disabled(u16 id, unsigned long quirks) +static bool intel_vsec_supported(u16 id, unsigned long caps) { switch (id) { + case VSEC_ID_TELEMETRY: + return !!(caps & VSEC_CAP_TELEMETRY); case VSEC_ID_WATCHER: - return !!(quirks & VSEC_QUIRK_NO_WATCHER); - + return !!(caps & VSEC_CAP_WATCHER); case VSEC_ID_CRASHLOG: - return !!(quirks & VSEC_QUIRK_NO_CRASHLOG); - + return !!(caps & VSEC_CAP_CRASHLOG); + case VSEC_ID_SDSI: + return !!(caps & VSEC_CAP_SDSI); + case VSEC_ID_TPMI: + return !!(caps & VSEC_CAP_TPMI); default: return false; } @@ -170,7 +155,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he unsigned long quirks = info->quirks; int i; - if (!intel_vsec_allowed(header->id) || intel_vsec_disabled(header->id, quirks)) + if (!intel_vsec_supported(header->id, info->caps)) return -EINVAL; if (!header->num_entries) { @@ -234,14 +219,14 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he static bool intel_vsec_walk_header(struct pci_dev *pdev, struct intel_vsec_platform_info *info) { - struct intel_vsec_header **header = info->capabilities; + struct intel_vsec_header **header = info->headers; bool have_devices = false; int ret; for ( ; *header; header++) { ret = intel_vsec_add_dev(pdev, *header, info); if (ret) - dev_info(&pdev->dev, "Could not add device for DVSEC id %d\n", + dev_info(&pdev->dev, "Could not add device for VSEC id %d\n", (*header)->id); else have_devices = true; @@ -386,12 +371,6 @@ static int intel_vsec_pci_probe(struct pci_dev *pdev, const struct pci_device_id return 0; } -/* TGL info */ -static const struct intel_vsec_platform_info tgl_info = { - .quirks = VSEC_QUIRK_NO_WATCHER | VSEC_QUIRK_NO_CRASHLOG | - VSEC_QUIRK_TABLE_SHIFT | VSEC_QUIRK_EARLY_HW, -}; - /* DG1 info */ static struct intel_vsec_header dg1_telemetry = { .length = 0x10, @@ -402,19 +381,31 @@ static struct intel_vsec_header dg1_telemetry = { .offset = 0x466000, }; -static struct intel_vsec_header *dg1_capabilities[] = { +static struct intel_vsec_header *dg1_headers[] = { &dg1_telemetry, NULL }; static const struct intel_vsec_platform_info dg1_info = { - .capabilities = dg1_capabilities, + .caps = VSEC_CAP_TELEMETRY, + .headers = dg1_headers, .quirks = VSEC_QUIRK_NO_DVSEC | VSEC_QUIRK_EARLY_HW, }; /* MTL info */ static const struct intel_vsec_platform_info mtl_info = { - .quirks = VSEC_QUIRK_NO_WATCHER | VSEC_QUIRK_NO_CRASHLOG, + .caps = VSEC_CAP_TELEMETRY, +}; + +/* OOBMSM info */ +static const struct intel_vsec_platform_info oobmsm_info = { + .caps = VSEC_CAP_TELEMETRY | VSEC_CAP_SDSI | VSEC_CAP_TPMI, +}; + +/* TGL info */ +static const struct intel_vsec_platform_info tgl_info = { + .caps = VSEC_CAP_TELEMETRY, + .quirks = VSEC_QUIRK_TABLE_SHIFT | VSEC_QUIRK_EARLY_HW, }; #define PCI_DEVICE_ID_INTEL_VSEC_ADL 0x467d @@ -429,7 +420,7 @@ static const struct pci_device_id intel_vsec_pci_ids[] = { { PCI_DEVICE_DATA(INTEL, VSEC_DG1, &dg1_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_MTL_M, &mtl_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_MTL_S, &mtl_info) }, - { PCI_DEVICE_DATA(INTEL, VSEC_OOBMSM, &(struct intel_vsec_platform_info) {}) }, + { PCI_DEVICE_DATA(INTEL, VSEC_OOBMSM, &oobmsm_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_RPL, &tgl_info) }, { PCI_DEVICE_DATA(INTEL, VSEC_TGL, &tgl_info) }, { } diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel/vsec.h index f600d6fe0830..54fdea93f762 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -61,9 +61,18 @@ enum intel_vsec_quirks { VSEC_QUIRK_EARLY_HW = BIT(4), }; +enum intel_vsec_capabilities { + VSEC_CAP_TELEMETRY = BIT(0), + VSEC_CAP_WATCHER = BIT(1), + VSEC_CAP_CRASHLOG = BIT(2), + VSEC_CAP_SDSI = BIT(3), + VSEC_CAP_TPMI = BIT(4), +}; + /* Platform specific data */ struct intel_vsec_platform_info { - struct intel_vsec_header **capabilities; + struct intel_vsec_header **headers; + unsigned long caps; unsigned long quirks; }; From patchwork Wed Mar 15 18:33:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70361 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp55700wrt; Wed, 15 Mar 2023 11:35:07 -0700 (PDT) X-Google-Smtp-Source: AK7set+uJPORP1E7yO6MJr6Yq5domDDWIB+hGUElwhb83YlXSqdaclTs390aPWZ4ka2+EtNUlxx8 X-Received: by 2002:a05:6a20:3cab:b0:d0:4361:9720 with SMTP id b43-20020a056a203cab00b000d043619720mr717962pzj.61.1678905306998; Wed, 15 Mar 2023 11:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905306; cv=none; d=google.com; s=arc-20160816; b=ThYID57KjvK9al6YOqInP5gvQERtINrxmbE0yyp6WaW575hKE/8I9nfNMT0Mcry5TM H7cTyhpgoq95Z1o6reVcs79CeANzkji9QUYvs1RBrQn0wRuVAP2HlBZ6S/yXhYy362QO 5nXvgzNGPJvJhdF4sE6/TgA3NTtnZ8Cmh/KQjMa16RdfdEnEfg69Iq7+bFuU27CztwnF UMDGqMbpPMQcMpYIm0yoYIr8E3SpuyVWYi9RqErSi5gynGHn1mH4q+GhxjiUNDvJXAXi QWgOnhH0SavOkzkXhk9zfIgtLaI9l/ECfdFBLUoi+zYLHfofdDjtqi3GXDv8HBdl9m58 1UXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qm1yMVKxYeTqhJEdjGerH+AnICC4CT/px9OjhBxxghU=; b=xF+AlDxpR6tQ+f3vaIJPjkzsoRq4vR/iL47L1SE80fry9DwXwefoA/XUSxsdBEwlFu JW401nEnDt0RTnv+fWU5Pr49BY6vUV0A3nAy/amLTRap5hx4PbWsRO8r+oPNj/Few7m+ fG60YSa3SawTcfHw4jenjoWDfNghDyZzrjOL8zJS3KsS24LJeJ8EsI46Eb3+Q5lITJTl 7ZJOu9FxI9L1f3B3FfAc+9azEliLwTd2Gaydw6Vk3M78VHqHwQ3RhYlhuN6Lv4c5TZt6 45B+8pciwSNfO0OOe2QbuoP2doboCuLgu9qUGhgCNKqIbvSO4dz1hOjQFx1+TlfuLxJN a6pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W+Ydu8Wo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a654889000000b00503a2ab161dsi5593319pgs.534.2023.03.15.11.34.52; Wed, 15 Mar 2023 11:35:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W+Ydu8Wo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232029AbjCOSeX (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231751AbjCOSeM (ORCPT ); Wed, 15 Mar 2023 14:34:12 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F55615CAB; Wed, 15 Mar 2023 11:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905250; x=1710441250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tiBxACl1aCLc9qaOAQl3+p3ktpJtGcq9KNcC9SlIB0c=; b=W+Ydu8WopGlDsAQbUOsq0rQsWlVnGIe9lCFf8d1lWshEIHMmprTOypS8 6cmHpYw0kO9E5qdV4Lcf05wwcf6dEkwDFSAjoDuAtXngYipL9BD0N+IB1 ZjgtSp+7HI3S0DKSOT8NsDhmbdLq/O9xJ1be0LRvLsOA2rBg06wnUby7p DjK4NWut8A82PoVxgGX+vI3/47I6X6eLn04Ht52HDVR9F1n7i43/L96pc 4XOT0cZWmlKy7Ex4enEbRI/n5amDnFpSAWNyniy3MapzuYU7/Jq1dIqCW odATeYIGcLAbmZ1/3hcz6OzMmbDboBSk6hx7wbVcm93oqYtlfOIgiwZ9l g==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154532" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154532" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435205" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435205" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id D3C8F580C6E; Wed, 15 Mar 2023 11:34:06 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 03/11] platform/x86/intel/vsec: Add base address field Date: Wed, 15 Mar 2023 11:33:57 -0700 Message-Id: <20230315183405.2465630-4-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760459811243215994?= X-GMAIL-MSGID: =?utf-8?q?1760459811243215994?= Some Intel PCIe VSEC capabilities may be emulated in MMIO. In such cases the BAR is not readable from config space. Provide a field for drivers to indicate the base address that is to be used. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 14 +++++++++++--- drivers/platform/x86/intel/vsec.c | 10 ++++++++-- drivers/platform/x86/intel/vsec.h | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c index 9f505c6ef278..7136475d4ab5 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -161,10 +161,11 @@ static struct class intel_pmt_class = { 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 = to_pci_dev(dev->parent); + struct pci_dev *pci_dev = ivdev->pcidev; + struct device *dev = &ivdev->auxdev.dev; u8 bir; /* @@ -216,6 +217,13 @@ static int intel_pmt_populate_entry(struct intel_pmt_entry *entry, break; case ACCESS_BARID: + /* Use the provided base address if it exists */ + if (ivdev->base_addr) { + entry->base_addr = ivdev->base_addr + + GET_ADDRESS(header->base_offset); + break; + } + /* * If another BAR was specified then the base offset * represents the offset within that BAR. SO retrieve the @@ -320,7 +328,7 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry, struct intel_pmt_namespa if (ret) return ret; - ret = intel_pmt_populate_entry(entry, &header, dev, disc_res); + ret = intel_pmt_populate_entry(entry, &header, intel_vsec_dev, disc_res); if (ret) return ret; diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c index 0d5cf250e288..77063f699a1d 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -153,6 +153,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he struct intel_vsec_device *intel_vsec_dev; struct resource *res, *tmp; unsigned long quirks = info->quirks; + u64 base_addr; int i; if (!intel_vsec_supported(header->id, info->caps)) @@ -181,14 +182,18 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he if (quirks & VSEC_QUIRK_TABLE_SHIFT) header->offset >>= TABLE_OFFSET_SHIFT; + if (info->base_addr) + base_addr = info->base_addr; + else + base_addr = 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 = 0, tmp = res; i < header->num_entries; i++, tmp++) { - tmp->start = pdev->resource[header->tbir].start + - header->offset + i * (header->entry_size * sizeof(u32)); + tmp->start = base_addr + header->offset + i * (header->entry_size * sizeof(u32)); tmp->end = tmp->start + (header->entry_size * sizeof(u32)) - 1; tmp->flags = IORESOURCE_MEM; @@ -206,6 +211,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he intel_vsec_dev->resource = res; intel_vsec_dev->num_resources = header->num_entries; intel_vsec_dev->quirks = info->quirks; + intel_vsec_dev->base_addr = info->base_addr; if (header->id == VSEC_ID_SDSI) intel_vsec_dev->ida = &intel_vsec_sdsi_ida; diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel/vsec.h index 54fdea93f762..4157ec546cd3 100644 --- a/drivers/platform/x86/intel/vsec.h +++ b/drivers/platform/x86/intel/vsec.h @@ -74,6 +74,7 @@ struct intel_vsec_platform_info { struct intel_vsec_header **headers; unsigned long caps; unsigned long quirks; + u64 base_addr; }; struct intel_vsec_device { @@ -86,6 +87,7 @@ struct intel_vsec_device { void *priv_data; size_t priv_data_size; unsigned long quirks; + u64 base_addr; }; int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, From patchwork Wed Mar 15 18:33:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57114wrt; Wed, 15 Mar 2023 11:38:36 -0700 (PDT) X-Google-Smtp-Source: AK7set+xftkhZK7Zu4o7fWDkxCuGTesTpx1PCjTuD7obg2hbkl7vEjHWo2gEAR5yBGFjMbUXg9SU X-Received: by 2002:a17:903:2449:b0:19f:3cdc:56dc with SMTP id l9-20020a170903244900b0019f3cdc56dcmr423132pls.33.1678905516256; Wed, 15 Mar 2023 11:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905516; cv=none; d=google.com; s=arc-20160816; b=IEVfzS3R65VQ5vjfwwmmEiFH9adbUmhk+riHq5VyzvQEK42pMRDtAM4/6QyJMsP21H 5Z7fEJDpACUhUEzu1LoQud0qN6hplwJirF2pgZd8zMdMu+CU5NXe1RXZMR6gGV0H5L1w CGT+P7tgefL5fjqE6sxJs4fHlhO8DEEeDOUp9Dq4W6khBbh30WjclxvaoA/FQPxQJ9oq Hv2ANc2/y88jDVhKFjSmcrE/a1iEUJKX4XLonQRgpcx+04tq0kBU6KvpUJbbLAYb3X3W qc1SWB4Lm6NI+qorCKeb0pzOpqYeqsW9bEeDf3ozqOxLOAe0qTgUzVb0WXz8bRMrFFVc L43w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y1JSFidqKtKuHuvQjlPvcZalLBwZL4lectbpMkn8YWU=; b=twF/EkDosFoLCDnUqf9xx6sE2DYEACcSLGvJ9I0StyeQTZjPYAs6zURzTa+LppfK+B +bLFrRaPOotY+EuBCBGlZflfjcOUAUGKjGo1yCyhJ+z4wTPrWUaRldwTqLG3nPZFtHQf OIOL0k5YY+NVvpAha6Son2B2ko6X8/VoyI4IveY2go3A9T1SeI2eg+qkke8NqkwpG9b3 vbe0BbpZO1ohJKeS+9AB6fxugtKAwIdBpHuY3qrORd8rWVKuPhGjKZ4bFpnLYjpYQnOa DOOGqcq8O9pfW8g8EQVDm9pdg94OPySLTx/IM9ac/ueaEVgsBSDEDWbahXcwojmXL2Wx lTbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SxtjaWDH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a170902c94c00b0019f269f06fbsi1292631pla.3.2023.03.15.11.38.21; Wed, 15 Mar 2023 11:38:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SxtjaWDH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232111AbjCOSe0 (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231769AbjCOSeM (ORCPT ); Wed, 15 Mar 2023 14:34:12 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE156AD28; Wed, 15 Mar 2023 11:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905250; x=1710441250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SLZM9Rd4ZbAV+HV63P8xQDOFKv2CzGBHIeab4YXE1bU=; b=SxtjaWDHZuGsebxR2EtzSIvWNRtT3D9kLv/51mbZlFikK/GdSGLAVNh/ 6BqrYbrqGbVzxfKXGWlXrjhYMFGlrfhQxDh0C2Z9LMQ+LLK0uDW4WzLso Yk+2hTylaHyOdtJOwzmp1AxCp6qxgC2VT6Whd2HlXnFsHk9HS0izX63Dy CuoBkpgicWpkukjuaM/s5zQVY/1kdgYKLl+eCoHLQ6QvFvfnr6shqqJPB VLBkTK+gUoIKe/dbO8hDV9M0G/SeEZR9R4h6r5PPPfD7Xb2p5rBN6OBYF 7gta8GwFKlrYHbMHdDpekiklzt2W183kH9kT52zAYAEoFRne80gbMV1jM A==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154538" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154538" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435208" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435208" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 19268580D2C; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 04/11] platform/x86/intel/pmt: Add INTEL_PMT module namespace Date: Wed, 15 Mar 2023 11:33:58 -0700 Message-Id: <20230315183405.2465630-5-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460030782046464?= X-GMAIL-MSGID: =?utf-8?q?1760460030782046464?= Since the currently exported symbols in pmt_class are only used by other Intel PMT drivers, create an INTEL_PMT module namespace for them. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 6 +++--- drivers/platform/x86/intel/pmt/crashlog.c | 1 + drivers/platform/x86/intel/pmt/telemetry.c | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c index 7136475d4ab5..acc96f0cc224 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -33,7 +33,7 @@ bool intel_pmt_is_early_client_hw(struct device *dev) */ return !!(ivdev->quirks & VSEC_QUIRK_EARLY_HW); } -EXPORT_SYMBOL_GPL(intel_pmt_is_early_client_hw); +EXPORT_SYMBOL_NS_GPL(intel_pmt_is_early_client_hw, INTEL_PMT); static inline int pmt_memcpy64_fromio(void *to, const u64 __iomem *from, size_t count) @@ -335,7 +335,7 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry, struct intel_pmt_namespa return intel_pmt_dev_register(entry, ns, dev); } -EXPORT_SYMBOL_GPL(intel_pmt_dev_create); +EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_create, INTEL_PMT); void intel_pmt_dev_destroy(struct intel_pmt_entry *entry, struct intel_pmt_namespace *ns) @@ -351,7 +351,7 @@ void intel_pmt_dev_destroy(struct intel_pmt_entry *entry, device_unregister(dev); xa_erase(ns->xa, entry->devid); } -EXPORT_SYMBOL_GPL(intel_pmt_dev_destroy); +EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_destroy, INTEL_PMT); static int __init pmt_class_init(void) { diff --git a/drivers/platform/x86/intel/pmt/crashlog.c b/drivers/platform/x86/intel/pmt/crashlog.c index ace1239bc0a0..bbb3d61d09f4 100644 --- a/drivers/platform/x86/intel/pmt/crashlog.c +++ b/drivers/platform/x86/intel/pmt/crashlog.c @@ -328,3 +328,4 @@ module_exit(pmt_crashlog_exit); MODULE_AUTHOR("Alexander Duyck "); MODULE_DESCRIPTION("Intel PMT Crashlog driver"); MODULE_LICENSE("GPL v2"); +MODULE_IMPORT_NS(INTEL_PMT); diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/x86/intel/pmt/telemetry.c index 5e4009c05ecf..71cdef42084a 100644 --- a/drivers/platform/x86/intel/pmt/telemetry.c +++ b/drivers/platform/x86/intel/pmt/telemetry.c @@ -160,3 +160,4 @@ module_exit(pmt_telem_exit); MODULE_AUTHOR("David E. Box "); MODULE_DESCRIPTION("Intel PMT Telemetry driver"); MODULE_LICENSE("GPL v2"); +MODULE_IMPORT_NS(INTEL_PMT); From patchwork Wed Mar 15 18:33:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57536wrt; Wed, 15 Mar 2023 11:39:38 -0700 (PDT) X-Google-Smtp-Source: AK7set+tSaaZazhtKsZRLooKqOFnqcCyJgg+9tf55C0UxMQYq3zNBn1F7vPmC+5X1lym3VbfPEfp X-Received: by 2002:a17:90b:384e:b0:23d:384c:d503 with SMTP id nl14-20020a17090b384e00b0023d384cd503mr747378pjb.28.1678905577949; Wed, 15 Mar 2023 11:39:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905577; cv=none; d=google.com; s=arc-20160816; b=rmEfZNAYD3J7EXuF3cFcwDLOay9+9GOvTT7084kZag1cwPxBMUhxVWCw0m/EAcTj74 Wr3o5YxvslalEWvGAF6AXbmtE572YnXUw0XpsOjTg/8ZhD5RuCKMdVB67huGCx63v1w4 iiqn/5GgGl2vUfIVTeFHD7gBZefhauthigAtKl6XYYauat9C2XiiDvROCG1hU8HDkq8J YtRQjvEKiaHZcxqovaFrREiysQbnNusBxoz4Dplcoupk32jCdsZgaBrLQCdZmFToKnmC XatZ3VB+j+KeOJ8e/6xou4WRerpOhkK7O061iukJa5m5HkFKogiEJojpQU2buaAM0m3r tw2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Dq9sm+R7L+Jy2ISxGqu919/VBIFv7FhGUZ5HfF1LDKY=; b=BF/172YGmYuF59xPRsy6pPrKeC+AcMfwqe8fa/hiA6b3G47BlDePawfSDtV6q/MrYM HLZs0jdnC87JjOrYyBNZBX9sUkn+8XkcHu2Ara5ojhz/Af7ueOH9UZ4e6Cp8Op9alPzo TrK/oB7AbBefs/aFaL/lxn5AatnKi22A6EC81oWHxhQKChVGlVwhTwiWuHjXC0wbbB8+ v5xRJe7GZhNgjZisEeK1kLyL4HxmSJ76deYQO38UwMs4SR3m/iDUN/A65Oq4iSW8Uad8 oeNAa+ETKwpt+z3/t8kxvBgGVcXS0CzF4zJQZHg1zx6xSOtTzLKP7+SWcl0LY7cImsN6 Pb0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k+ZTZ5EX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot2-20020a17090b3b4200b0023495f71234si2517837pjb.67.2023.03.15.11.39.22; Wed, 15 Mar 2023 11:39:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k+ZTZ5EX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232365AbjCOSej (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbjCOSeP (ORCPT ); Wed, 15 Mar 2023 14:34:15 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97E096A4F; Wed, 15 Mar 2023 11:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905252; x=1710441252; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sZA92xYaQ0h8ypQ1+D2Khsxotdmw78gsyoPN7vgwzww=; b=k+ZTZ5EXH4L4AGvlKO0mLkIaxPLy8OiEjOd9xB5vxf80oca/p0VF/6eJ 5HDvIOtuzWyvqXgLHGL4RFSuchrvOhw4PhOgZoDCDOKcA4DN5Mw9iacHx 6YvypD+vf5KabPm2I3/VZExbhVMrfpdjMppBodJXZItiVAImsk7yEyvS+ 1UMCBJB+isAbvI8i/ucBIN5tyqOOlfjnkFlQMzMAkMOuSo0B+ZsEczQno 2XyHJS/+SJb/pUrBM0Q3VctSgViB9LZoE1k6kUQpcvSLVTA1pdrfzx0Hg UUaOujJSR8knEoUzJSBNESEBYQShiYgYUjimlO2a9ex7L+yL9A0t0BN0Y Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154543" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154543" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435211" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435211" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 4D801580BF2; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 05/11] platform/x86/intel/pmt: telemetry: Add telemetry read functions Date: Wed, 15 Mar 2023 11:33:59 -0700 Message-Id: <20230315183405.2465630-6-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460094901230546?= X-GMAIL-MSGID: =?utf-8?q?1760460094901230546?= Export symbols to allow access to Intel PMT Telemetry data on available devices. Provides APIs to search, register, and read telemetry using a kref managed pointer that serves as a handle to a telemetry entry. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/class.c | 28 +-- drivers/platform/x86/intel/pmt/class.h | 30 +++- drivers/platform/x86/intel/pmt/crashlog.c | 2 +- drivers/platform/x86/intel/pmt/telemetry.c | 196 ++++++++++++++++++++- drivers/platform/x86/intel/pmt/telemetry.h | 120 +++++++++++++ 5 files changed, 353 insertions(+), 23 deletions(-) create mode 100644 drivers/platform/x86/intel/pmt/telemetry.h diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c index acc96f0cc224..4fc8d48ef3be 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -17,7 +17,7 @@ #include "../vsec.h" #include "class.h" -#define PMT_XA_START 0 +#define PMT_XA_START 1 #define PMT_XA_MAX INT_MAX #define PMT_XA_LIMIT XA_LIMIT(PMT_XA_START, PMT_XA_MAX) #define GUID_SPR_PUNIT 0x9956f43f @@ -160,12 +160,12 @@ static struct class intel_pmt_class = { }; 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 = ivdev->pcidev; struct device *dev = &ivdev->auxdev.dev; + struct intel_pmt_header *header = &entry->header; u8 bir; /* @@ -271,7 +271,7 @@ static int intel_pmt_dev_register(struct intel_pmt_entry *entry, if (ns->attr_grp) { ret = sysfs_create_group(entry->kobj, ns->attr_grp); if (ret) - goto fail_sysfs; + goto fail_sysfs_create_group; } /* if size is 0 assume no data buffer, so no file needed */ @@ -296,13 +296,23 @@ static int intel_pmt_dev_register(struct intel_pmt_entry *entry, entry->pmt_bin_attr.size = entry->size; ret = sysfs_create_bin_file(&dev->kobj, &entry->pmt_bin_attr); - if (!ret) - return 0; + if (ret) + goto fail_ioremap; + if (ns->pmt_add_handle) { + ret = ns->pmt_add_handle(entry, parent); + if (ret) + goto fail_add_handle; + } + + return 0; + +fail_add_handle: + sysfs_remove_bin_file(entry->kobj, &entry->pmt_bin_attr); fail_ioremap: if (ns->attr_grp) sysfs_remove_group(entry->kobj, ns->attr_grp); -fail_sysfs: +fail_sysfs_create_group: device_unregister(dev); fail_dev_create: xa_erase(ns->xa, entry->devid); @@ -314,7 +324,6 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry, struct intel_pmt_namespa struct intel_vsec_device *intel_vsec_dev, int idx) { struct device *dev = &intel_vsec_dev->auxdev.dev; - struct intel_pmt_header header; struct resource *disc_res; int ret; @@ -324,16 +333,15 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry, struct intel_pmt_namespa if (IS_ERR(entry->disc_table)) return PTR_ERR(entry->disc_table); - ret = ns->pmt_header_decode(entry, &header, dev); + ret = ns->pmt_header_decode(entry, dev); if (ret) return ret; - ret = intel_pmt_populate_entry(entry, &header, intel_vsec_dev, disc_res); + ret = intel_pmt_populate_entry(entry, intel_vsec_dev, disc_res); if (ret) return ret; return intel_pmt_dev_register(entry, ns, dev); - } EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_create, INTEL_PMT); diff --git a/drivers/platform/x86/intel/pmt/class.h b/drivers/platform/x86/intel/pmt/class.h index 17bc40b77efc..7b730cdaed5a 100644 --- a/drivers/platform/x86/intel/pmt/class.h +++ b/drivers/platform/x86/intel/pmt/class.h @@ -8,6 +8,7 @@ #include #include "../vsec.h" +#include "telemetry.h" /* PMT access types */ #define ACCESS_BARID 2 @@ -18,8 +19,27 @@ #define GET_ADDRESS(v) ((v) & GENMASK(31, 3)) struct xarray; +struct pci_dev; + +struct telem_handle { + struct pci_dev *parent; + struct telem_header header; + struct device *dev; + void __iomem *base; + bool present; + struct kref kref; +}; + +struct intel_pmt_header { + u32 base_offset; + u32 size; + u32 guid; + u8 access_type; +}; struct intel_pmt_entry { + struct telem_handle *handle; + struct intel_pmt_header header; struct bin_attribute pmt_bin_attr; struct kobject *kobj; void __iomem *disc_table; @@ -30,20 +50,14 @@ struct intel_pmt_entry { int devid; }; -struct intel_pmt_header { - u32 base_offset; - u32 size; - u32 guid; - u8 access_type; -}; - struct intel_pmt_namespace { const char *name; struct xarray *xa; const struct attribute_group *attr_grp; int (*pmt_header_decode)(struct intel_pmt_entry *entry, - struct intel_pmt_header *header, struct device *dev); + int (*pmt_add_handle)(struct intel_pmt_entry *entry, + struct device *dev); }; bool intel_pmt_is_early_client_hw(struct device *dev); diff --git a/drivers/platform/x86/intel/pmt/crashlog.c b/drivers/platform/x86/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_group = { }; static int pmt_crashlog_header_decode(struct intel_pmt_entry *entry, - struct intel_pmt_header *header, struct device *dev) { void __iomem *disc_table = entry->disc_table; + struct intel_pmt_header *header = &entry->header; struct crashlog_entry *crashlog; if (!pmt_crashlog_supported(entry)) diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/x86/intel/pmt/telemetry.c index 71cdef42084a..39ec8d9fb5b1 100644 --- a/drivers/platform/x86/intel/pmt/telemetry.c +++ b/drivers/platform/x86/intel/pmt/telemetry.c @@ -30,6 +30,14 @@ /* Used by client hardware to identify a fixed telemetry entry*/ #define TELEM_CLIENT_FIXED_BLOCK_GUID 0x10000000 +#define NUM_BYTES_QWORD(v) ((v) << 3) +#define SAMPLE_ID_OFFSET(v) ((v) << 3) + +#define NUM_BYTES_DWORD(v) ((v) << 2) +#define SAMPLE_ID_OFFSET32(v) ((v) << 2) + +static DEFINE_MUTEX(entry_lock); + enum telem_type { TELEM_TYPE_PUNIT = 0, TELEM_TYPE_CRASHLOG, @@ -58,10 +66,10 @@ static bool pmt_telem_region_overlaps(struct intel_pmt_entry *entry, } static int pmt_telem_header_decode(struct intel_pmt_entry *entry, - struct intel_pmt_header *header, struct device *dev) { void __iomem *disc_table = entry->disc_table; + struct intel_pmt_header *header = &entry->header; if (pmt_telem_region_overlaps(entry, dev)) return 1; @@ -84,21 +92,199 @@ static int pmt_telem_header_decode(struct intel_pmt_entry *entry, return 0; } +static int pmt_telem_add_handle(struct intel_pmt_entry *entry, + struct device *dev) +{ + struct telem_handle *handle; + + entry->handle = kzalloc(sizeof(*(entry->handle)), GFP_KERNEL); + if (!entry->handle) + return -ENOMEM; + + handle = entry->handle; + handle->dev = dev; + handle->parent = to_pci_dev(dev->parent); + handle->header.access_type = entry->header.access_type; + handle->header.guid = entry->header.guid; + handle->header.base_offset = entry->header.base_offset; + handle->header.size = entry->header.size; + handle->base = entry->base; + handle->present = true; + + kref_init(&handle->kref); + + return 0; +} + static DEFINE_XARRAY_ALLOC(telem_array); static struct intel_pmt_namespace pmt_telem_ns = { .name = "telem", .xa = &telem_array, .pmt_header_decode = pmt_telem_header_decode, + .pmt_add_handle = pmt_telem_add_handle, }; +static void pmt_telem_handle_release(struct kref *kref) +{ + struct telem_handle *handle; + + handle = container_of(kref, struct telem_handle, kref); + kfree(handle); +} + +/* + * driver api + */ +int pmt_telem_get_next_entry(int start) +{ + struct intel_pmt_entry *entry; + unsigned long found_idx; + + mutex_lock(&entry_lock); + xa_for_each_start(&telem_array, found_idx, entry, start) { + /* + * Return first found index after start. + * 0 is not valid id. + */ + if (found_idx > start) + break; + } + mutex_unlock(&entry_lock); + + return found_idx == start ? 0 : found_idx; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_get_next_entry, INTEL_PMT); + +struct telem_handle *pmt_telem_register_handle(int devid) +{ + struct intel_pmt_entry *entry; + unsigned long index = devid; + + mutex_lock(&entry_lock); + entry = xa_find(&telem_array, &index, index, XA_PRESENT); + if (!entry) { + mutex_unlock(&entry_lock); + return ERR_PTR(-ENXIO); + } + + kref_get(&entry->handle->kref); + mutex_unlock(&entry_lock); + + return entry->handle; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_register_handle, INTEL_PMT); + +void pmt_telem_unregister_handle(struct telem_handle *handle) +{ + kref_put(&handle->kref, pmt_telem_handle_release); +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_unregister_handle, INTEL_PMT); + +int pmt_telem_get_devid_info(int devid, struct telem_entry_info *info) +{ + struct intel_pmt_entry *entry; + unsigned long index = devid; + int err = 0; + + if (!info) + return -EINVAL; + + mutex_lock(&entry_lock); + entry = xa_find(&telem_array, &index, index, XA_PRESENT); + if (!entry) { + err = -ENXIO; + goto unlock; + } + + info->pdev = entry->handle->parent; + info->header = entry->handle->header; + +unlock: + mutex_unlock(&entry_lock); + return err; + +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_get_devid_info, INTEL_PMT); + +int +pmt_telem_read(struct telem_handle *handle, u32 id, u64 *data, u32 count) +{ + u32 offset, size; + + if (!handle->present) + return -ENODEV; + + offset = SAMPLE_ID_OFFSET(id); + size = handle->header.size; + + if ((offset + NUM_BYTES_QWORD(count)) > size) + return -EINVAL; + + memcpy_fromio(data, handle->base + offset, NUM_BYTES_QWORD(count)); + + return handle->present ? 0 : -EPIPE; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_read, INTEL_PMT); + +int +pmt_telem_read32(struct telem_handle *handle, u32 id, u32 *data, u32 count) +{ + u32 offset, size; + + if (!handle->present) + return -ENODEV; + + offset = SAMPLE_ID_OFFSET32(id); + size = handle->header.size; + + if ((offset + NUM_BYTES_DWORD(count)) > size) + return -EINVAL; + + memcpy_fromio(data, handle->base + offset, NUM_BYTES_DWORD(count)); + + return handle->present ? 0 : -EPIPE; +} +EXPORT_SYMBOL_NS_GPL(pmt_telem_read32, INTEL_PMT); + +struct telem_handle * +pmt_telem_find_and_register_handle(struct pci_dev *pcidev, u32 guid, u16 pos) +{ + int devid = 0; + int inst = 0; + int err = 0; + + while ((devid = pmt_telem_get_next_entry(devid))) { + struct telem_entry_info info; + + err = pmt_telem_get_devid_info(devid, &info); + if (err) + return ERR_PTR(err); + + if (info.header.guid == guid && info.pdev == pcidev) { + if (inst == pos) + return pmt_telem_register_handle(devid); + ++inst; + } + } + + return ERR_PTR(-ENXIO); +} +EXPORT_SYMBOL_NS(pmt_telem_find_and_register_handle, INTEL_PMT); + static void pmt_telem_remove(struct auxiliary_device *auxdev) { struct pmt_telem_priv *priv = auxiliary_get_drvdata(auxdev); int i; - for (i = 0; i < priv->num_entries; i++) - intel_pmt_dev_destroy(&priv->entry[i], &pmt_telem_ns); -} + mutex_lock(&entry_lock); + for (i = 0; i < priv->num_entries; i++) { + struct intel_pmt_entry *entry = &priv->entry[i]; + + kref_put(&entry->handle->kref, pmt_telem_handle_release); + intel_pmt_dev_destroy(entry, &pmt_telem_ns); + } + mutex_unlock(&entry_lock); +}; static int pmt_telem_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id) { @@ -117,7 +303,9 @@ static int pmt_telem_probe(struct auxiliary_device *auxdev, const struct auxilia for (i = 0; i < intel_vsec_dev->num_resources; i++) { struct intel_pmt_entry *entry = &priv->entry[priv->num_entries]; + mutex_lock(&entry_lock); ret = intel_pmt_dev_create(entry, &pmt_telem_ns, intel_vsec_dev, i); + mutex_unlock(&entry_lock); if (ret < 0) goto abort_probe; if (ret) diff --git a/drivers/platform/x86/intel/pmt/telemetry.h b/drivers/platform/x86/intel/pmt/telemetry.h new file mode 100644 index 000000000000..c78184f08d2e --- /dev/null +++ b/drivers/platform/x86/intel/pmt/telemetry.h @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _INTEL_PMT_TELEM_H +#define _INTEL_PMT_TELEM_H + +#include + +/* Telemetry types */ +#define PMT_TELEM_TELEMETRY 0 +#define PMT_TELEM_CRASHLOG 1 + +struct telem_handle; + +struct telem_header { + u8 access_type; + u16 size; + u32 guid; + u32 base_offset; +}; + +struct telem_entry_info { + struct pci_dev *pdev; + struct telem_header header; +}; + +struct pci_dev; + +/** + * pmt_telem_get_next_devid() - Get next devid for a telemetry entry + * @start: starting devid to look from + * + * Use in a while loop to retrieve the devid of all available telemetry + * entries. + * + * Return: + * * devid - devid of the next present handle from start + * * 0 - when no more handles are present after start + */ +int pmt_telem_get_next_entry(int start); + +/** + * pmt_telem_get_devid_info() - Get telemetry info for a telemetry entry from + * its devid + * @devid: devid of the telemetry entry + * @info: Endpoint info structure to be populated + * + * Return: + * * 0 - Success + * * -ENXIO - devid no found + * * -EINVAL - info is NULL + */ +int pmt_telem_get_devid_info(int devid, struct telem_entry_info *info); + +/** + * pmt_telem_register_handle() - Register a telemetry handle + * @devid: devid of the telemetry entry + * + * Increments the kref usage counter for the handle. + * + * Return: + * * handle - On success returns pointer to the telemetry handle + * * -ENXIO - devid not found + */ +struct telem_handle *pmt_telem_register_handle(int devid); + +/** + * pmt_telem_unregister_handle() - Unregister a telemetry handle + * @handle: handle to unregister + * + * Decrements the kref usage counter for the handle. + */ +void pmt_telem_unregister_handle(struct telem_handle *handle); + +/** + * pmt_telem_find_and_register_handle() - Find and get a handle to a telemetry + * entry + * @pdev: PCI device of the telemetry provider + * @guid: GUID of the telemetry space + * @pos: Instance of the guid in case of multiple instances + * + * Return: + * * handle - On success returns pointer to the telemetry handle + * * -ENXIO - Telemetry provider not found + */ +struct telem_handle *pmt_telem_find_and_register_handle(struct pci_dev *pcidev, + u32 guid, u16 pos); + +/** + * pmt_telem_read() - Read telemetry sample(s) from handle + * @ep: Telemetry handle + * @id: Starting sample id + * @data: Allocated qword buffer + * @count: Number of consecutive samples/qwords to read + * + * Return: + * * 0 - Success + * * -ENODEV - Entry is not present + * * -EINVAL - The offset is out bounds of the sample space + * * -EPIPE - The device was removed during the read. Data written + * but should be considered invalid + */ +int pmt_telem_read(struct telem_handle *handle, u32 id, u64 *data, + u32 count); + +/** + * pmt_telem_read32() - Read dword samples from handle + * @ep: Telemetry handle + * @id: Starting sample id + * @data: Allocated dword buffer + * @count: Number of consecutive samples/dwords to read + * + * Return: + * * 0 - Success + * * -ENODEV - Entry is not present + * * -EINVAL - The offset is out bounds of the sample space + * * -EPIPE - The device was removed during the read. Data written + * but should be considered invalid. + */ +int pmt_telem_read32(struct telem_handle *handle, u32 id, u32 *data, + u32 count); +#endif From patchwork Wed Mar 15 18:34:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70363 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57022wrt; Wed, 15 Mar 2023 11:38:22 -0700 (PDT) X-Google-Smtp-Source: AK7set8YswSKp/doMbdNrfKsiinP+hcTN07vkFOTiXq0j7+HaZmn8273zSJpNS+NSUus4DEFiXFN X-Received: by 2002:a17:902:e30c:b0:1a0:422f:39d9 with SMTP id q12-20020a170902e30c00b001a0422f39d9mr333742plc.39.1678905502419; Wed, 15 Mar 2023 11:38:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905502; cv=none; d=google.com; s=arc-20160816; b=PXKEX/EC1hwkK9OSGPSh+5nQ/DGOEBaDhk5rvEh7J3ZQ75wJ8SCZnTx10XJUkQCs6W Miwuf+wOerkvG4MNrWpSlAlMWF7ZRh+3cPb7SJ8LXIdaVPsLIhytEWLosS0tVtdQFi+D GIwTKEWnblpXyHMYDfXw8eX004lyZwxfqZvmokDRYNvisOpBo3FYaWrHxNyTTPYbL99i T0kCU5oKhkpQl0glIGjFyuTjJxyhhxe04ANHTocPcxltzfRkIOWAbmHPtWIPSTu6Q2O8 s8X5t8dodZgZXxsGdB+WdGCG/K5HY1iril46f+JOEszQqvn5bZMIwXF1Su33ozJQSTcY y0IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0DYrP/mwKJQLHULnETSbEBaMH6upl6FPTDEJbyxDPUk=; b=LIRQerbR1rsRGhvTYvEckCR37Xy1Yz1T57vesoR4UU1yvWKjwOPnU3wHxlx6xFd7H8 d/bXHPI5tGUxTt5qjKYn6vkl+f2xKS+FM5H0s8yWDbtzZvLk1pfst9ivM6j3T7mnUyeo amY/7sCvWtrF2qmwJLh/nG2UccOzr6e10FBf8M3QezAoivtyzO+dPzpyY3IDtOeCdlz/ OHVaH9bJXjgqfPSN1Dh9f1LqS8d6GzDg9RON+/IuF70zgRRuqnaTomCYtiwmIc0j+01G nCX/NIQcMxc93uPszkuy8GYmjC4vGbrRdHu/LmGlWrY+b9Hkh946t2XjnpWYgNspu6sx i6ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GHurIbEE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ik26-20020a170902ab1a00b0019a95ab6b66si5414243plb.33.2023.03.15.11.38.07; Wed, 15 Mar 2023 11:38:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GHurIbEE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232276AbjCOSed (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231779AbjCOSeO (ORCPT ); Wed, 15 Mar 2023 14:34:14 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1719D40D3; Wed, 15 Mar 2023 11:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905253; x=1710441253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L00M9MXhIWKlvY9DN1BY3XH1GCJuxFHrq9jz+q4X/hA=; b=GHurIbEE0omo52F9FiRAeAjQWpTIIaPr5lrVGdz+JV6U4xHNNtO62p7s +XNZFJP6oO+EYH1viByoweF3vtYoN06oDrZME/+hXve3sxtZ1i3J+RZGN 0d9dDQWyAkIjyU7Sy4kPPDfYTUMH5vz91OM2oIW0tAhe60scEmDY631my 4ldNxUPwQXkF1M0/ibMUGphAtF+ewOYqTr6mUszpV8u4NAMQu4RyTMRpo DfloH8lbkLrgbCseH+JaxeZetOBk1hR1ffqH+ogIPpw2IrbNRnWqeqvyL 5hetSJ02Xt3EMJ8IsVzx+erXBfaLr7/6TRW/kUT1sar482qxNg81WDJeF w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154549" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154549" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435213" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435213" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:07 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 8CD42580C6E; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 06/11] platform/x86/intel/pmt/telemetry: Add driver version Date: Wed, 15 Mar 2023 11:34:00 -0700 Message-Id: <20230315183405.2465630-7-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460016402816519?= X-GMAIL-MSGID: =?utf-8?q?1760460016402816519?= Add a driver version number to make it easier to track changes in backported kernels. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmt/telemetry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/x86/intel/pmt/telemetry.c index 39ec8d9fb5b1..7593726e814d 100644 --- a/drivers/platform/x86/intel/pmt/telemetry.c +++ b/drivers/platform/x86/intel/pmt/telemetry.c @@ -19,6 +19,7 @@ #include "../vsec.h" #include "class.h" +#define DRIVER_VERSION "1.0" #define TELEM_SIZE_OFFSET 0x0 #define TELEM_GUID_OFFSET 0x4 #define TELEM_BASE_OFFSET 0x8 @@ -348,4 +349,5 @@ module_exit(pmt_telem_exit); MODULE_AUTHOR("David E. Box "); MODULE_DESCRIPTION("Intel PMT Telemetry driver"); MODULE_LICENSE("GPL v2"); +MODULE_VERSION(DRIVER_VERSION); MODULE_IMPORT_NS(INTEL_PMT); From patchwork Wed Mar 15 18:34:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57066wrt; Wed, 15 Mar 2023 11:38:31 -0700 (PDT) X-Google-Smtp-Source: AK7set8zyXRiLpKBJCDtv7H6604R13hrvmHINmM88G4ez3LKMragY1YIUhrlvdumX0EW3TdI7UEZ X-Received: by 2002:a05:6a20:548f:b0:d5:10ca:5264 with SMTP id i15-20020a056a20548f00b000d510ca5264mr862935pzk.59.1678905510739; Wed, 15 Mar 2023 11:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905510; cv=none; d=google.com; s=arc-20160816; b=q7m2XX8IDxswz3Pp4JjT7xEFEYK7irnI3dExMtVddr1TZF03BGI/egZppUG8iAAXm0 YpubyLYLGhAn1cLbiHFIE8Xte7jafQ0YzK6moXz6F5j1un3AW63CPi861rqo91UUaDgb Mry0QFBvFiGzW/RNAKr7URJO9DtSDxfvlVERbLPX38CjrO3AiXw6fQqgHBIlRAm5e6Hs bxCnNza001ATMIpQKBtIGGbqoDB+KHvcVh2fTapGTgrX16XSjt7DSL1KQqzYg8N+v9od 1C7fJ0wqD40Qh8kYX+xX1cTgyqMcIqN0dWEZp0Th3jRDcHv7nobLGxGDVqYOV415Od/W 5YlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3Lg4fZbMssG8jcBtSAZMSnPrO1OzJEvxuIuM/sBPgSY=; b=VwnepfJCiskbh4y07KzMKNnFIil5ddNF2bp/MnHHr3ZN42VxCIXQuN2og0NS32FwKg X2bqqdvfuvfCYo4mpDnrU7nth+/TJExfLlYHRQMAULdHq2M1869KhIYNrT0dE9S9oPgY bj3EqpHIzOHcfhXauARfUfJjWvc5bQ1QWIZXbabottVaRYXkMZAlBXYLxfT7i9ryo8Wp be9N74H4TX9sEXqYLsqjqLWkwBYi1AycvQBtYVUXmqfwBp9zp7dMaf3LjmaGTudU/iJ8 1qaMc+o/Oyc5maUtGTXyqrFE5494esqkcoP7rE4VGSsb6XGcjm3zUUjIyC+WbvTL5f8X +pig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BMtYe1nb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a24-20020aa795b8000000b0058bcb6283edsi5280980pfk.288.2023.03.15.11.38.16; Wed, 15 Mar 2023 11:38:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BMtYe1nb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232143AbjCOSeg (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231875AbjCOSeP (ORCPT ); Wed, 15 Mar 2023 14:34:15 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A6E87DA5; Wed, 15 Mar 2023 11:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905254; x=1710441254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n16cQ4kymyynRY6n5R36txntCnbHvo09MUKHWcfcmk0=; b=BMtYe1nbaAgf5695fyjDZ3luVhYEZCd2/3SWosp/EWTpbdp++3PP3+w0 ROTHdEb+bm09ONRmRkwAp5bD4Y5IFDALe10mjxyp603UvnIOQt1ZbIL63 ejmsWax1H4ejggos+U9G7uRA6zMlReiJrkzpLyhPDFcaBbaX3FPZ3OXhg daxxOGz8FeyiVZz0EzsFHv8Fw1tDLIFQ6Iz1Pmrt3OiU3NQ2SdHXTMbq1 XhHfW8MW5J0e/ynurUfsm8hDaAK5tsN41s0B5itXln6bRQG+6yVatHv9I RXSGt2emayU50VGXpBC8pq5AuzdZhPBQFVw2KLvRILWhdLdps1HWAkzyG w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154556" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154556" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435217" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435217" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:08 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id CF8D1580BF6; Wed, 15 Mar 2023 11:34:07 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 07/11] platform/x86/intel/pmc: Alder Lake slp_s0_residency fix Date: Wed, 15 Mar 2023 11:34:01 -0700 Message-Id: <20230315183405.2465630-8-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460024884828842?= X-GMAIL-MSGID: =?utf-8?q?1760460024884828842?= From: Rajvi Jingar For platforms with Alder Lake PCH (Alder Lake S and Raptor Lake S) the slp_s0_residency attribute has been reporting the wrong value. Unlike other platforms, ADL PCH does not have a counter for the time that the SLP_S0 signal was asserted. Instead, firmware uses the aggregate of the Low Power Mode (LPM) substate counters as the S0ix value. Since the LPM counters run at a different frequency, this lead to misreporting of the S0ix time. Add a check for Alder Lake PCH and adjust the frequency accordingly when display slp_s0_residency. Fixes: bbab31101f44 ("platform/x86/intel: pmc/core: Add Alderlake support to pmc core driver") Signed-off-by: Rajvi Jingar Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c index e489d2175e42..61ca7c37fb02 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -66,7 +66,18 @@ static inline void pmc_core_reg_write(struct pmc_dev *pmcdev, int reg_offset, static inline u64 pmc_core_adjust_slp_s0_step(struct pmc_dev *pmcdev, u32 value) { - return (u64)value * pmcdev->map->slp_s0_res_counter_step; + /* + * ADL PCH does not have the SLP_S0 counter and LPM Residency counters are + * used as a workaround which uses 30.5 usec tick. All other client + * programs have the legacy SLP_S0 residency counter that is using the 122 + * usec tick. + */ + const int lpm_adj_x2 = pmcdev->map->lpm_res_counter_step_x2; + + if (pmcdev->map == &adl_reg_map) + return (u64)value * GET_X2_COUNTER((u64)lpm_adj_x2); + else + return (u64)value * pmcdev->map->slp_s0_res_counter_step; } static int set_etr3(struct pmc_dev *pmcdev) From patchwork Wed Mar 15 18:34:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp55918wrt; Wed, 15 Mar 2023 11:35:35 -0700 (PDT) X-Google-Smtp-Source: AK7set+KMo07d00gscc8t5gk9FpD+ZCCYEgjuT6Mw7Id3H65M3Dl5ubTSbx5BR0y+CXNaTmKD9qw X-Received: by 2002:a05:6a20:12c6:b0:d4:686:4a92 with SMTP id v6-20020a056a2012c600b000d406864a92mr787152pzg.34.1678905335624; Wed, 15 Mar 2023 11:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905335; cv=none; d=google.com; s=arc-20160816; b=vBj3XV1miOc85pJRzdmVpNI9arPlHNWN5sagArpjnmBCyxaXkvt2504xVaZ8drzY3T 6ZqIhL2iNAZ208zn6d50uAR6QSGG7FnvH68lF+iNH1fJnckgh6oBFTdviwHv22ZBly6U 5dkgrLBo/RHToHAi56hx4uWKWrhsurM+Pr01ns82lXxPyhuwkIUYSs3FopuH/m0wcLRf Np/xDmEtQT1YiWtaDWMw9Fu5Lhchchh59tirRdyP90vaZtrr4cN4SMhvDau4ILdxAgSk 9KcFNW0srXskbqEbtjnAogL5DOjCqm4ioDqKu+YLjR5UwWpUJNsl2SuVHVq99kU1ekAh 1MnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5dC1GwwoTuCpOR3Tehe3w8gxE+TGlR8xB01H/iSHWTk=; b=OtxFGsLnVar2QZVqRlspDw88n5NB8hnyAhJrQlsQgBHqm6eY09Ks6uRD6U1i2aQyfI u0dFSfuhQRpR/DYfV1/BYYjIkWkE0OhjlcHY4Z/h95t/Y6KZQ3jflbiBn4Md7O59Jxep wtbm0PptziOob9T+6+9hzmVnbxoHEfzahNsVoeamHaIaM/hgldtzkwbGu6fJ/XZV3VpL NrZugit0MPuU3hulz7d7yTztHLDn4yuSVvj9ifRB2WBcd6ggnAXReiXx2z+oJDU4VIDt AcR2qCVzep1t29/UTcyDAoyR6QI5qLbnFuOtoCr8R+w1nBUIFIJGgl8r7D1+CHE7VCHo 6eMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CHSngXhu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p20-20020a635b14000000b0050bcb8e3dc7si5210691pgb.15.2023.03.15.11.35.20; Wed, 15 Mar 2023 11:35:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CHSngXhu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232398AbjCOSem (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232019AbjCOSeX (ORCPT ); Wed, 15 Mar 2023 14:34:23 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60E8AFF0E; Wed, 15 Mar 2023 11:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905254; x=1710441254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qeonfz7kPOnTnc23J/5nZOsk6/2p2FjL/PplnJo6pvk=; b=CHSngXhu2K90s7o4w6zGUgmviLe3m7g3gWRoR+dMbtwNOnWhHx79Q4nT +Uu/el8xyW+VeWSuAwfvp65PTmu7IDFpM+1iCipuFgVtE0HprWfgzATIZ rV0Q2hFhw7mQ/LaGMHvcCsoLOPJEDv9Ixd2lr+1qkhBwVfxSOcL/P704q oQwfhU+SES+XgAP5BUZ2MmmLGh9UHUYUs1T0mlbqKy/jgMEVlDmyUhXUH pRRJ0s2kwQCkDhlWZuJJm+9QmYzdkAd6wIADb4NIyKJYVhUNELTaANUCs e7PrFauvVsDIsPVQ4hPioUcL46UBPsZMG6dmDTge0gESdrj/I1tpJgShU w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154564" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154564" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435221" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435221" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:08 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 1F2A0580D29; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 08/11] platform/x86:intel/pmc: Combine core_init and core_configure function Date: Wed, 15 Mar 2023 11:34:02 -0700 Message-Id: <20230315183405.2465630-9-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760459840928146333?= X-GMAIL-MSGID: =?utf-8?q?1760459840928146333?= From: Xi Pardee core_init and core_configure functions can be combined to have a cleaner setup for platforms. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/adl.c | 15 +++++---- drivers/platform/x86/intel/pmc/cnp.c | 15 ++++++++- drivers/platform/x86/intel/pmc/core.c | 48 +++++++++++++++------------ drivers/platform/x86/intel/pmc/core.h | 20 +++++------ drivers/platform/x86/intel/pmc/icl.c | 3 +- drivers/platform/x86/intel/pmc/mtl.c | 15 +++++---- drivers/platform/x86/intel/pmc/spt.c | 3 +- drivers/platform/x86/intel/pmc/tgl.c | 15 +++++---- 8 files changed, 80 insertions(+), 54 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/adl.c b/drivers/platform/x86/intel/pmc/adl.c index 5cbd40979f2a..a6ceaf520fd5 100644 --- a/drivers/platform/x86/intel/pmc/adl.c +++ b/drivers/platform/x86/intel/pmc/adl.c @@ -309,17 +309,20 @@ const struct pmc_reg_map adl_reg_map = { .lpm_live_status_offset = ADL_LPM_LIVE_STATUS_OFFSET, }; -void adl_core_configure(struct pmc_dev *pmcdev) +int adl_core_init(struct pmc_dev *pmcdev) { + int ret; + + pmcdev->map = &adl_reg_map; + ret = get_primary_reg_base(pmcdev); + if (ret) + return ret; + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); pmc_core_send_ltr_ignore(pmcdev, 3); -} -void adl_core_init(struct pmc_dev *pmcdev) -{ - pmcdev->map = &adl_reg_map; - pmcdev->core_configure = adl_core_configure; + return ret; } diff --git a/drivers/platform/x86/intel/pmc/cnp.c b/drivers/platform/x86/intel/pmc/cnp.c index 7fb38815c4eb..fcd07a61f88d 100644 --- a/drivers/platform/x86/intel/pmc/cnp.c +++ b/drivers/platform/x86/intel/pmc/cnp.c @@ -204,7 +204,20 @@ const struct pmc_reg_map cnp_reg_map = { .etr3_offset = ETR3_OFFSET, }; -void cnp_core_init(struct pmc_dev *pmcdev) +int cnp_core_init(struct pmc_dev *pmcdev) { + int ret; + pmcdev->map = &cnp_reg_map; + ret = get_primary_reg_base(pmcdev); + if (ret) + return ret; + + /* Due to a hardware limitation, the GBE LTR blocks PC10 + * when a cable is attached. Tell the PMC to ignore it. + */ + dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); + pmc_core_send_ltr_ignore(pmcdev, 3); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c index 61ca7c37fb02..4769ce0b0fbe 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -948,6 +948,26 @@ static void pmc_core_get_low_power_modes(struct platform_device *pdev) } } +int get_primary_reg_base(struct pmc_dev *pmcdev) +{ + u64 slp_s0_addr; + + if (lpit_read_residency_count_address(&slp_s0_addr)) { + pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT; + + if (page_is_ram(PHYS_PFN(pmcdev->base_addr))) + return -ENODEV; + } else { + pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset; + } + + pmcdev->regbase = ioremap(pmcdev->base_addr, + pmcdev->map->regmap_length); + if (!pmcdev->regbase) + return -ENOMEM; + return 0; +} + static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev) { debugfs_remove_recursive(pmcdev->dbgfs_dir); @@ -1100,8 +1120,8 @@ static int pmc_core_probe(struct platform_device *pdev) static bool device_initialized; struct pmc_dev *pmcdev; const struct x86_cpu_id *cpu_id; - void (*core_init)(struct pmc_dev *pmcdev); - u64 slp_s0_addr; + int (*core_init)(struct pmc_dev *pmcdev); + int ret; if (device_initialized) return -ENODEV; @@ -1117,7 +1137,7 @@ static int pmc_core_probe(struct platform_device *pdev) if (!cpu_id) return -ENODEV; - core_init = (void (*)(struct pmc_dev *))cpu_id->driver_data; + core_init = (int (*)(struct pmc_dev *))cpu_id->driver_data; /* * Coffee Lake has CPU ID of Kaby Lake and Cannon Lake PCH. So here @@ -1128,26 +1148,12 @@ static int pmc_core_probe(struct platform_device *pdev) core_init = cnp_core_init; mutex_init(&pmcdev->lock); - core_init(pmcdev); - - - if (lpit_read_residency_count_address(&slp_s0_addr)) { - pmcdev->base_addr = PMC_BASE_ADDR_DEFAULT; - - if (page_is_ram(PHYS_PFN(pmcdev->base_addr))) - return -ENODEV; - } else { - pmcdev->base_addr = slp_s0_addr - pmcdev->map->slp_s0_offset; + ret = core_init(pmcdev); + if (ret) { + mutex_destroy(&pmcdev->lock); + return ret; } - pmcdev->regbase = ioremap(pmcdev->base_addr, - pmcdev->map->regmap_length); - if (!pmcdev->regbase) - return -ENOMEM; - - if (pmcdev->core_configure) - pmcdev->core_configure(pmcdev); - pmcdev->pmc_xram_read_bit = pmc_core_check_read_lock_bit(pmcdev); pmc_core_get_low_power_modes(pdev); pmc_core_do_dmi_quirks(pmcdev); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/intel/pmc/core.h index 810204d758ab..3ce83c837fdc 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -325,7 +325,6 @@ struct pmc_reg_map { * @num_lpm_modes: Count of enabled modes * @lpm_en_modes: Array of enabled modes from lowest to highest priority * @lpm_req_regs: List of substate requirements - * @core_configure: Function pointer to configure the platform * * pmc_dev contains info about power management controller device. */ @@ -344,7 +343,6 @@ struct pmc_dev { int num_lpm_modes; int lpm_en_modes[LPM_MAX_NUM_MODES]; u32 *lpm_req_regs; - void (*core_configure)(struct pmc_dev *pmcdev); }; extern const struct pmc_bit_map msr_map[]; @@ -397,16 +395,14 @@ extern const struct pmc_reg_map mtl_reg_map; extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev); extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value); - -void spt_core_init(struct pmc_dev *pmcdev); -void cnp_core_init(struct pmc_dev *pmcdev); -void icl_core_init(struct pmc_dev *pmcdev); -void tgl_core_init(struct pmc_dev *pmcdev); -void adl_core_init(struct pmc_dev *pmcdev); -void mtl_core_init(struct pmc_dev *pmcdev); -void tgl_core_configure(struct pmc_dev *pmcdev); -void adl_core_configure(struct pmc_dev *pmcdev); -void mtl_core_configure(struct pmc_dev *pmcdev); +extern int get_primary_reg_base(struct pmc_dev *pmcdev); + +int spt_core_init(struct pmc_dev *pmcdev); +int cnp_core_init(struct pmc_dev *pmcdev); +int icl_core_init(struct pmc_dev *pmcdev); +int tgl_core_init(struct pmc_dev *pmcdev); +int adl_core_init(struct pmc_dev *pmcdev); +int mtl_core_init(struct pmc_dev *pmcdev); #define pmc_for_each_mode(i, mode, pmcdev) \ for (i = 0, mode = pmcdev->lpm_en_modes[i]; \ diff --git a/drivers/platform/x86/intel/pmc/icl.c b/drivers/platform/x86/intel/pmc/icl.c index 2f11b1a6daeb..a671d7e86431 100644 --- a/drivers/platform/x86/intel/pmc/icl.c +++ b/drivers/platform/x86/intel/pmc/icl.c @@ -50,7 +50,8 @@ const struct pmc_reg_map icl_reg_map = { .etr3_offset = ETR3_OFFSET, }; -void icl_core_init(struct pmc_dev *pmcdev) +int icl_core_init(struct pmc_dev *pmcdev) { pmcdev->map = &icl_reg_map; + return get_primary_reg_base(pmcdev); } diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/intel/pmc/mtl.c index eeb3bd8c2502..96106ffbd367 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -36,17 +36,20 @@ const struct pmc_reg_map mtl_reg_map = { .lpm_live_status_offset = MTL_LPM_LIVE_STATUS_OFFSET, }; -void mtl_core_configure(struct pmc_dev *pmcdev) +int mtl_core_init(struct pmc_dev *pmcdev) { + int ret; + + pmcdev->map = &mtl_reg_map; + ret = get_primary_reg_base(pmcdev); + if (ret) + return ret; + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); pmc_core_send_ltr_ignore(pmcdev, 3); -} -void mtl_core_init(struct pmc_dev *pmcdev) -{ - pmcdev->map = &mtl_reg_map; - pmcdev->core_configure = mtl_core_configure; + return ret; } diff --git a/drivers/platform/x86/intel/pmc/spt.c b/drivers/platform/x86/intel/pmc/spt.c index e16982236778..f34015692bb8 100644 --- a/drivers/platform/x86/intel/pmc/spt.c +++ b/drivers/platform/x86/intel/pmc/spt.c @@ -134,7 +134,8 @@ const struct pmc_reg_map spt_reg_map = { .pm_vric1_offset = SPT_PMC_VRIC1_OFFSET, }; -void spt_core_init(struct pmc_dev *pmcdev) +int spt_core_init(struct pmc_dev *pmcdev) { pmcdev->map = &spt_reg_map; + return get_primary_reg_base(pmcdev); } diff --git a/drivers/platform/x86/intel/pmc/tgl.c b/drivers/platform/x86/intel/pmc/tgl.c index c245ada849d0..c69f2672fb92 100644 --- a/drivers/platform/x86/intel/pmc/tgl.c +++ b/drivers/platform/x86/intel/pmc/tgl.c @@ -252,18 +252,21 @@ void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev) ACPI_FREE(out_obj); } -void tgl_core_configure(struct pmc_dev *pmcdev) +int tgl_core_init(struct pmc_dev *pmcdev) { + int ret; + + pmcdev->map = &tgl_reg_map; + ret = get_primary_reg_base(pmcdev); + if (ret) + return ret; + pmc_core_get_tgl_lpm_reqs(pmcdev->pdev); /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ dev_dbg(&pmcdev->pdev->dev, "ignoring GBE LTR\n"); pmc_core_send_ltr_ignore(pmcdev, 3); -} -void tgl_core_init(struct pmc_dev *pmcdev) -{ - pmcdev->map = &tgl_reg_map; - pmcdev->core_configure = tgl_core_configure; + return ret; } From patchwork Wed Mar 15 18:34:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57685wrt; Wed, 15 Mar 2023 11:39:57 -0700 (PDT) X-Google-Smtp-Source: AK7set/fyN2QwpWkgqGx6Xa/ZkKM6tjux+lj6wZzVtLw5+vk4Gvlh08a3aiz2zm8sBlYTWHlk3dx X-Received: by 2002:a05:6a20:728d:b0:ce:c188:68af with SMTP id o13-20020a056a20728d00b000cec18868afmr936937pzk.17.1678905596936; Wed, 15 Mar 2023 11:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905596; cv=none; d=google.com; s=arc-20160816; b=j1OCY8e+8JKJP+GWIWODNTHftFuB7YxQf6hnOVdy76vSTGCL2Hy7kF4T1j05b5eY81 1sRk7PIaUFQGDD84Kb59Lj+snrhMIK5TuLTAOeV0BCQJXIDIsNl1Kj5CoTqkuDHnU3Zm VhWsk1N8BUsqxpqbcmbfMsUfbJRvEz5wpt3EC2fgZa6p9YbF5MTTo3Han0ElABUoDBC8 uYp8AhflTDlrkUZ5DwbRMz2K1nSXx+GDJ4B5r7eqn2/dIpuOifnP1b9SHhWLkfRJ1EPc I1oePXWzKkfPBHzSAFeHitsJ2L/UB1kpujhKm7ghZJCzBUql6TYf1glsxzD56/f4VzBC 0O3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dnDtP8o3YUT69VpkUwMnim3aPIN+3JN7f4/ZAKlcRxM=; b=onklGfF3BJz/+loQzdAAQbIirHIdk0/fgrwrdSN88beO3h+pphrljC98PvTCrkqJXg ieb78xP233SMm8OW6BiF2dUyTEYpWfFNjGWkUGPLlTU1X1Tfa8DBnrcgXWFgjWD9wau1 /TsS6U8zGvCUE2NFd29zZWomhZpXMCbFagHJvrslzZcCTVMZUWk4k/fvMT3oFucT1x8W pA/sVbC+lzG34tBkCUjHpFkQ3qhUyzyVbvd93z7jFe+DSwFNb+B6EumzwZeFx60/sjRN sAoh5pPZlkBLJYJp0jxFpr2cTHSjUimcu67JvAs5JmtzIlrpBupcL4IVVQKEs5QEp8wx 9G5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dyEoCCeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a632c09000000b004fc274006ddsi5578886pgs.670.2023.03.15.11.39.42; Wed, 15 Mar 2023 11:39:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dyEoCCeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232464AbjCOSeu (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbjCOSe0 (ORCPT ); Wed, 15 Mar 2023 14:34:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30640198F; Wed, 15 Mar 2023 11:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905255; x=1710441255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tqsEbmKGVD86TyjaK4FQ0KAEv5jaN0N9ShVwFwIiVJI=; b=dyEoCCeHkrgi7mV4oVIwdxumBp0uRx3/xKW2ocRt4FYozwVGBMVR1yMW YnOwl2F835xIt/5bd1aLD0aBtIQ7qSZEIEKHSYR3vjWmuTfQUQwPSTHqN p+AgNcDH/VdFcXXiPui7xUPDce8ZxMyKHAAymkZTxw2Vd/m4SMkdffEo6 B+4P1BSkD/fp/f22U7HfCC4Coa/zqdgzNT5WMbPQVfmuzVKY5x8t4oMQG uDoxtiV1C/IVTgGQCdHJpNkMvwR0GLG+OhsnpIOZ38CKI3/tRPYS86JVy tTqVdH9gh6KrzHcYQGG5c98Mb/vq7/m7ptQIXhcTziSnrtwjlonWO+Enc Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154571" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154571" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435224" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435224" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:08 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 6B9F9580C6E; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 09/11] platform/x86/intel/pmc: Add Intel PMT support for MTL PMC Date: Wed, 15 Mar 2023 11:34:03 -0700 Message-Id: <20230315183405.2465630-10-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460114957576571?= X-GMAIL-MSGID: =?utf-8?q?1760460114957576571?= The PMC SSRAM device contains PMC metrics that are structured in Intel Platform Monitoring Technology (PMT) telemetry regions. Register these telemetry regions from the driver so that they may be read using the Intel PMT API. Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/Kconfig | 1 + drivers/platform/x86/intel/pmc/core.c | 6 ++ drivers/platform/x86/intel/pmc/core.h | 2 + drivers/platform/x86/intel/pmc/mtl.c | 106 +++++++++++++++++++++++++ 4 files changed, 115 insertions(+) diff --git a/drivers/platform/x86/intel/pmc/Kconfig b/drivers/platform/x86/intel/pmc/Kconfig index b526597e4deb..d2f651fbec2c 100644 --- a/drivers/platform/x86/intel/pmc/Kconfig +++ b/drivers/platform/x86/intel/pmc/Kconfig @@ -7,6 +7,7 @@ config INTEL_PMC_CORE tristate "Intel PMC Core driver" depends on PCI depends on ACPI + depends on INTEL_PMT_TELEMETRY help The Intel Platform Controller Hub for Intel Core SoCs provides access to Power Management Controller registers via various interfaces. This diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c index 4769ce0b0fbe..8f3a5a6fc874 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -1174,6 +1174,11 @@ static void pmc_core_remove(struct platform_device *pdev) platform_set_drvdata(pdev, NULL); mutex_destroy(&pmcdev->lock); iounmap(pmcdev->regbase); + + if (pmcdev->ssram_pcidev) { + pci_dev_put(pmcdev->ssram_pcidev); + pci_disable_device(pmcdev->ssram_pcidev); + } } static bool warn_on_s0ix_failures; @@ -1287,3 +1292,4 @@ module_platform_driver(pmc_core_driver); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Intel PMC Core Driver"); +MODULE_IMPORT_NS(INTEL_VSEC); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/intel/pmc/core.h index 3ce83c837fdc..ba30db31f439 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -315,6 +315,7 @@ struct pmc_reg_map { * @map: pointer to pmc_reg_map struct that contains platform * specific attributes * @pdev: pointer to platform_device struct + * @ssram_pcidev: pointer to pci device struct for the PMC SSRAM * @dbgfs_dir: path to debugfs interface * @pmc_xram_read_bit: flag to indicate whether PMC XRAM shadow registers * used to read MPHY PG and PLL status are available @@ -334,6 +335,7 @@ struct pmc_dev { const struct pmc_reg_map *map; struct dentry *dbgfs_dir; struct platform_device *pdev; + struct pci_dev *ssram_pcidev; int pmc_xram_read_bit; struct mutex lock; /* generic mutex lock for PMC Core */ diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/intel/pmc/mtl.c index 96106ffbd367..48c7ec094af8 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -8,7 +8,18 @@ * */ +#include + #include "core.h" +#include "../vsec.h" +#include "../pmt/telemetry.h" + +#define SSRAM_HDR_SIZE 0x100 +#define SSRAM_PWRM_OFFSET 0x14 +#define SSRAM_DVSEC_OFFSET 0x1C +#define SSRAM_DVSEC_SIZE 0x10 +#define SSRAM_PCH_OFFSET 0x60 +#define SSRAM_IOE_OFFSET 0x68 const struct pmc_reg_map mtl_reg_map = { .pfear_sts = ext_tgl_pfear_map, @@ -36,6 +47,99 @@ const struct pmc_reg_map mtl_reg_map = { .lpm_live_status_offset = MTL_LPM_LIVE_STATUS_OFFSET, }; +static void +mtl_pmc_add_pmt(struct pmc_dev *pmcdev, struct pci_dev *pdev, u64 ssram_base) +{ + struct intel_vsec_platform_info info = {}; + struct intel_vsec_header *headers[2] = {}; + struct intel_vsec_header header; + void __iomem *ssram, *dvsec; + u32 dvsec_offset; + u32 table, hdr; + + ssram = ioremap(ssram_base, SSRAM_HDR_SIZE); + if (!ssram) + return; + + dvsec_offset = readl(ssram + SSRAM_DVSEC_OFFSET); + iounmap(ssram); + + dvsec = ioremap(ssram_base + dvsec_offset, SSRAM_DVSEC_SIZE); + if (!dvsec) + return; + + hdr = readl(dvsec + PCI_DVSEC_HEADER1); + header.id = readw(dvsec + PCI_DVSEC_HEADER2); + header.rev = PCI_DVSEC_HEADER1_REV(hdr); + header.length = PCI_DVSEC_HEADER1_LEN(hdr); + header.num_entries = readb(dvsec + INTEL_DVSEC_ENTRIES); + header.entry_size = readb(dvsec + INTEL_DVSEC_SIZE); + + table = readl(dvsec + INTEL_DVSEC_TABLE); + header.tbir = INTEL_DVSEC_TABLE_BAR(table); + header.offset = INTEL_DVSEC_TABLE_OFFSET(table); + iounmap(dvsec); + + headers[0] = &header; + info.caps = VSEC_CAP_TELEMETRY; + info.headers = headers; + info.base_addr = ssram_base; + + intel_vsec_register(pdev, &info); +} + +static inline u64 get_ssram_base(void __iomem *addr, u32 offset) +{ + u64 low, high; + + low = readl(addr + offset) & GENMASK(31, 3); + high = readl(addr + offset + 4); + + return (high << 32) + low; +} + +static void mtl_pmc_ssram_init(struct pmc_dev *pmcdev) +{ + void __iomem *ssram; + struct pci_dev *pcidev; + u64 socs_ssram_base; + u64 ioe_ssram_base; + u64 pch_ssram_base; + int ret; + + pcidev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(20, 2)); + if (!pcidev) { + dev_err(&pmcdev->pdev->dev, "pci_dev is not found."); + return; + } + + ret = pcim_enable_device(pcidev); + if (ret) { + pci_dev_put(pcidev); + return; + } + + socs_ssram_base = pcidev->resource[0].start; + ssram = ioremap(socs_ssram_base, SSRAM_HDR_SIZE); + if (!ssram) { + pci_dev_put(pcidev); + pci_disable_device(pcidev); + return; + } + + pmcdev->ssram_pcidev = pcidev; + + ioe_ssram_base = get_ssram_base(ssram, SSRAM_IOE_OFFSET); + pch_ssram_base = get_ssram_base(ssram, SSRAM_PCH_OFFSET); + iounmap(ssram); + + mtl_pmc_add_pmt(pmcdev, pcidev, socs_ssram_base); + if (ioe_ssram_base) + mtl_pmc_add_pmt(pmcdev, pcidev, ioe_ssram_base); + if (pch_ssram_base) + mtl_pmc_add_pmt(pmcdev, pcidev, pch_ssram_base); +} + int mtl_core_init(struct pmc_dev *pmcdev) { int ret; @@ -45,6 +149,8 @@ int mtl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; + mtl_pmc_ssram_init(pmcdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ From patchwork Wed Mar 15 18:34:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57672wrt; Wed, 15 Mar 2023 11:39:55 -0700 (PDT) X-Google-Smtp-Source: AK7set9R5eDFaaDBSpKmwZHJxvEvHXXm626xoo8SBekAHWyWpbLqelhWVzeeuINvMGKOaBC6z9ah X-Received: by 2002:a05:6a20:6a0a:b0:d4:156f:45ad with SMTP id p10-20020a056a206a0a00b000d4156f45admr712044pzk.58.1678905595576; Wed, 15 Mar 2023 11:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905595; cv=none; d=google.com; s=arc-20160816; b=NLFHP/ye9savYw+sF+cHeIzxNfXrNZi7mUGYKqOxl2NowieT+sGhomCDHpDIXzIv40 nq+b06m8cq+QDK/SsD4xCkwygTGu/cQpLyCAsDT8nDD1jCsIfIWf2G/1cc3Ay37Fe4VO GN8vNx7UlWkNooEwOQw6D6D3ghu6kV0goH+7VyLOPvLBlR8QBB0BiEoQZYX+QQdy8NtK ajeUhhv5Jj09HGciPz6Q+CREdsPBiwqNlNP56m8yNzdQf5cImW9Ard0NG+3Fl+mEzh6h V7jKS8WXbyZ9yCNZ17+B6yksy3AJflTpod7RimQhA6CGpNwbWOyT0SZZnGZd3b/nW2+k /enQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VRmoJuuxKJaggb+d5QJ8PceIA/YEUu/0fyijViQarCE=; b=mk/dnCuxlzK1uCe9wYDbPuViUMg3fJbXTTb3/tVeWApvjg4li8iz18xs7FumFmV9B5 npwF+AYdS23wuft0RYQXTYg0ovQEqNgVhQ6Wtnphy/wlAa2tIYaSohuJebPBLVtAXp77 Hx8Uv7BfPXsYFhHs3wpQoe+zi4hlW0CuH9EpEPhC2ufdLS7lZdzahtKxmNEjMo8ARd1h gT7xSKvtOm1M4f9pyInbswy4DWjzNd1T8ncT6kqsSVyo1keHLGJVBZCuzI1A0PsqLWB7 b6wzVyXypwoHVTitxBuuzLDTDN6GmBVAziCCLk6V60wqFven/RKuQC2wdQ5FIaw5XOni DNuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aFjSTzOs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r22-20020a632b16000000b004fc1f5e387esi5504259pgr.817.2023.03.15.11.39.41; Wed, 15 Mar 2023 11:39:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aFjSTzOs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232412AbjCOSeq (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbjCOSe0 (ORCPT ); Wed, 15 Mar 2023 14:34:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31337E3BE; Wed, 15 Mar 2023 11:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905255; x=1710441255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hgPn91lasy9XxNu+0Ue+s0aleZeJjAiqqDGwHrAoS/A=; b=aFjSTzOsggk6Dtv7UA3wdbnONbY1FIw2qSe/jdsYKZSnFg9hmF6IOwbN tMMRS2LN0NgnTURbnubQNEDnzKUSmGB7Ivr/H83m3DS76FwT4gNaZz6uE tJ7Vm7LPqkcPEzelLEXSWjBQU84fcYKoCi6ZZN2t1OTGAHFTGhLmlecK/ UdFCKZGZAn8iamt8OgRwhv7EwG9wKQB74ekmPoD2ACkvliseg9qJsYwtD yqtLDywTtiTshfDQV9mrpDvZmvgxugBD55Wf4JsWwPyNuaGD/Che8Fyka DyvT54/4FqJFh3Fqvc4kNEhfIcg9JI70s2dnNSv3LQO+0Ua+E38WKNBgK g==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154578" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154578" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435227" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435227" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:09 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id B9FD8580BF2; Wed, 15 Mar 2023 11:34:08 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 10/11] platform/x86:intel/pmc: Move get_low_power_modes function Date: Wed, 15 Mar 2023 11:34:04 -0700 Message-Id: <20230315183405.2465630-11-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460113915816880?= X-GMAIL-MSGID: =?utf-8?q?1760460113915816880?= From: Xi Pardee Move the pmc_core_get_low_power_modes function call from probe to init function. This is the preparation work for retrieving LPM information using Intel PMT API patch as available low power modes need to be known. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/adl.c | 2 ++ drivers/platform/x86/intel/pmc/cnp.c | 2 ++ drivers/platform/x86/intel/pmc/core.c | 3 +-- drivers/platform/x86/intel/pmc/core.h | 1 + drivers/platform/x86/intel/pmc/icl.c | 10 +++++++++- drivers/platform/x86/intel/pmc/mtl.c | 2 ++ drivers/platform/x86/intel/pmc/spt.c | 10 +++++++++- drivers/platform/x86/intel/pmc/tgl.c | 2 ++ 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/adl.c b/drivers/platform/x86/intel/pmc/adl.c index a6ceaf520fd5..6101c9c2aa9c 100644 --- a/drivers/platform/x86/intel/pmc/adl.c +++ b/drivers/platform/x86/intel/pmc/adl.c @@ -318,6 +318,8 @@ int adl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; + pmc_core_get_low_power_modes(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ diff --git a/drivers/platform/x86/intel/pmc/cnp.c b/drivers/platform/x86/intel/pmc/cnp.c index fcd07a61f88d..68e7ac7f7a11 100644 --- a/drivers/platform/x86/intel/pmc/cnp.c +++ b/drivers/platform/x86/intel/pmc/cnp.c @@ -213,6 +213,8 @@ int cnp_core_init(struct pmc_dev *pmcdev) if (ret) return ret; + pmc_core_get_low_power_modes(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c index 8f3a5a6fc874..3833ea4a758e 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -898,7 +898,7 @@ static bool pmc_core_pri_verify(u32 lpm_pri, u8 *mode_order) return true; } -static void pmc_core_get_low_power_modes(struct platform_device *pdev) +void pmc_core_get_low_power_modes(struct platform_device *pdev) { struct pmc_dev *pmcdev = platform_get_drvdata(pdev); u8 pri_order[LPM_MAX_NUM_MODES] = LPM_DEFAULT_PRI; @@ -1155,7 +1155,6 @@ static int pmc_core_probe(struct platform_device *pdev) } pmcdev->pmc_xram_read_bit = pmc_core_check_read_lock_bit(pmcdev); - pmc_core_get_low_power_modes(pdev); pmc_core_do_dmi_quirks(pmcdev); pmc_core_dbgfs_register(pmcdev); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/intel/pmc/core.h index ba30db31f439..f4b69861c17b 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -398,6 +398,7 @@ extern const struct pmc_reg_map mtl_reg_map; extern void pmc_core_get_tgl_lpm_reqs(struct platform_device *pdev); extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value); extern int get_primary_reg_base(struct pmc_dev *pmcdev); +extern void pmc_core_get_low_power_modes(struct platform_device *pdev); int spt_core_init(struct pmc_dev *pmcdev); int cnp_core_init(struct pmc_dev *pmcdev); diff --git a/drivers/platform/x86/intel/pmc/icl.c b/drivers/platform/x86/intel/pmc/icl.c index a671d7e86431..8315e6c90efa 100644 --- a/drivers/platform/x86/intel/pmc/icl.c +++ b/drivers/platform/x86/intel/pmc/icl.c @@ -52,6 +52,14 @@ const struct pmc_reg_map icl_reg_map = { int icl_core_init(struct pmc_dev *pmcdev) { + int ret; + pmcdev->map = &icl_reg_map; - return get_primary_reg_base(pmcdev); + ret = get_primary_reg_base(pmcdev); + if (ret) + return ret; + + pmc_core_get_low_power_modes(pmcdev->pdev); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/intel/pmc/mtl.c index 48c7ec094af8..74f1f4c44812 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -151,6 +151,8 @@ int mtl_core_init(struct pmc_dev *pmcdev) mtl_pmc_ssram_init(pmcdev); + pmc_core_get_low_power_modes(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ diff --git a/drivers/platform/x86/intel/pmc/spt.c b/drivers/platform/x86/intel/pmc/spt.c index f34015692bb8..1f6bcd40ba76 100644 --- a/drivers/platform/x86/intel/pmc/spt.c +++ b/drivers/platform/x86/intel/pmc/spt.c @@ -136,6 +136,14 @@ const struct pmc_reg_map spt_reg_map = { int spt_core_init(struct pmc_dev *pmcdev) { + int ret; + pmcdev->map = &spt_reg_map; - return get_primary_reg_base(pmcdev); + ret = get_primary_reg_base(pmcdev); + if (ret) + return ret; + + pmc_core_get_low_power_modes(pmcdev->pdev); + + return ret; } diff --git a/drivers/platform/x86/intel/pmc/tgl.c b/drivers/platform/x86/intel/pmc/tgl.c index c69f2672fb92..05b7cc6f59a0 100644 --- a/drivers/platform/x86/intel/pmc/tgl.c +++ b/drivers/platform/x86/intel/pmc/tgl.c @@ -261,7 +261,9 @@ int tgl_core_init(struct pmc_dev *pmcdev) if (ret) return ret; + pmc_core_get_low_power_modes(pmcdev->pdev); pmc_core_get_tgl_lpm_reqs(pmcdev->pdev); + /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it. */ From patchwork Wed Mar 15 18:34:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 70367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp57199wrt; Wed, 15 Mar 2023 11:38:47 -0700 (PDT) X-Google-Smtp-Source: AK7set+5XgCbHke82tkw0sXavHXzz3X3eyK5Ee9rDhgKHv86fUgqg+okxA6jtXIMTe2sXuPfMp2r X-Received: by 2002:a17:903:11c5:b0:19c:ea4d:5995 with SMTP id q5-20020a17090311c500b0019cea4d5995mr434484plh.68.1678905527633; Wed, 15 Mar 2023 11:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678905527; cv=none; d=google.com; s=arc-20160816; b=UC4B6hpeQiJcD7XG8T5g/312vMU/jAZgBY7DMbxexRiIrUZXdUg9sCH+nc+52WU9jY Adz/qfvR6SE2fv17+5TuEmK5z3WDTTjzsXp/LLLlsAs6MmJF0i42G835pvOXAjEW8nTp naG6i63LNyFTTsheVvqvvsV9uQjv4AjvuOZkFsAWe8a1mxj+f4EdLaOCdciuK77ir2/l EBVevd0KTWTWmDti/b7cjCVSUek4J2yE0NnBPb4z2GEXftN2esGWaSMqyusXnIizrZSj PXFLC16rB5/ypmzkFfEN6TV20GbsudXz7pb6gWVXO/3GexaFbo/tQNDLhrK4FJy2pOw3 5RXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kwLn+xTJnNA81+Icf6yElejSOqdX2AHX2PWvnifZlUE=; b=ciB4lZlBVKk0QhUjX3QBjKvQUhVxaE+gywjnApzdw3LzizPaul2EpKu8jnB7hyiC+f HrSvzUjVhdiI2kkTL0okN/EWllpdJv4YhJsYLlutp73aMsonamQEw64hWlHL4H/F/+7K OW6TXSurFvRYpjsTOEHKzxrCp02V2ysmeVyFJ38pBx1xR2YrIV4CJID7mb1Q9BF4Ale6 9/O8Uq6mHnG80mXzStUCla3CtV0RCTlv8ahn+7h0BmJQrt6H0A56vn1CUrYhxi5ZH0vI A3JF+FDhdOl9sYUJpp42OUBOfLLuxIUbMmNTQ+MW7Qxw49pulOm2qN81DeLjGPlyRsE3 IdkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hGsxbOcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj21-20020a170903049500b0019a88f51635si5365896plb.534.2023.03.15.11.38.32; Wed, 15 Mar 2023 11:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hGsxbOcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232561AbjCOSez (ORCPT + 99 others); Wed, 15 Mar 2023 14:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232108AbjCOSe0 (ORCPT ); Wed, 15 Mar 2023 14:34:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160601715F; Wed, 15 Mar 2023 11:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678905256; x=1710441256; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w54rzDIFvclAC/9zKRmf3nOrZJbpqYh8AxeBdQIJTS0=; b=hGsxbOcjbmAfJ6fU00AZXNz9shc3g/OE4WJsDAWczNnn2B87f86GTF3F 6VnFgSacDuWQPNCy9irU2uiosQLOZUKnQr/ytXATgtoCABFKwe7dEDvIG lxNr3sZz9TUqwIuPghRr5wnWO+PQniw87B+RWxF+rcQJPfpplkXzkYK4/ 553w8uds46rLgHJZnvcPNg04oi/ezFIffLlLJBZrz74GBtzrYfv+Z/EOn MCFXTNptYJIAWsCV3LxRpPZmjjvY7P4qgpQ/jO+ci4WxAMnu2bxMg2JlI Dz7CpM/YigEhcNVQrevwVMLKoZCPN4R8kjshECqQJYOZ7iu/RUXkT7XpR w==; X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="340154584" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340154584" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 11:34:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10650"; a="925435229" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925435229" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 15 Mar 2023 11:34:09 -0700 Received: from debox1-desk4.intel.com (unknown [10.209.75.205]) by linux.intel.com (Postfix) with ESMTP id 0C6C3580BF6; Wed, 15 Mar 2023 11:34:09 -0700 (PDT) From: "David E. Box" To: irenic.rajneesh@gmail.com, david.e.box@linux.intel.com, hdegoede@redhat.com, markgross@kernel.org, andy.shevchenko@gmail.com, rajvi.jingar@linux.intel.com, xi.pardee@intel.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 11/11] platform/x86/intel/pmc/mtl: get LPM information using Intel PMT Date: Wed, 15 Mar 2023 11:34:05 -0700 Message-Id: <20230315183405.2465630-12-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315183405.2465630-1-david.e.box@linux.intel.com> References: <20230315183405.2465630-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760460042716509293?= X-GMAIL-MSGID: =?utf-8?q?1760460042716509293?= From: Xi Pardee For Meteor Lake, retrieve the PMC Lower Power Mode (LPM) information using Intel PMT Telemetry API. Signed-off-by: Xi Pardee Signed-off-by: David E. Box --- drivers/platform/x86/intel/pmc/core.c | 1 + drivers/platform/x86/intel/pmc/core.h | 1 + drivers/platform/x86/intel/pmc/mtl.c | 64 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c index 3833ea4a758e..2e4a9ca1be62 100644 --- a/drivers/platform/x86/intel/pmc/core.c +++ b/drivers/platform/x86/intel/pmc/core.c @@ -1291,4 +1291,5 @@ module_platform_driver(pmc_core_driver); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Intel PMC Core Driver"); +MODULE_IMPORT_NS(INTEL_PMT); MODULE_IMPORT_NS(INTEL_VSEC); diff --git a/drivers/platform/x86/intel/pmc/core.h b/drivers/platform/x86/intel/pmc/core.h index f4b69861c17b..e5d33999c865 100644 --- a/drivers/platform/x86/intel/pmc/core.h +++ b/drivers/platform/x86/intel/pmc/core.h @@ -306,6 +306,7 @@ struct pmc_reg_map { const u32 lpm_status_offset; const u32 lpm_live_status_offset; const u32 etr3_offset; + const u8 *lpm_reg_index; }; /** diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/intel/pmc/mtl.c index 74f1f4c44812..d51ec35e085d 100644 --- a/drivers/platform/x86/intel/pmc/mtl.c +++ b/drivers/platform/x86/intel/pmc/mtl.c @@ -21,6 +21,13 @@ #define SSRAM_PCH_OFFSET 0x60 #define SSRAM_IOE_OFFSET 0x68 +#define SOCS_LPM_REQ_GUID 0x2625030 +#define LPM_REG_INDEX_OFFSET 2 +#define LPM_REG_NUM 28 +#define LPM_SUBSTATE_NUM 1 + +static const u8 MTL_LPM_REG_INDEX[] = {0, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20}; + const struct pmc_reg_map mtl_reg_map = { .pfear_sts = ext_tgl_pfear_map, .slp_s0_offset = CNP_PMC_SLP_S0_RES_COUNTER_OFFSET, @@ -45,8 +52,60 @@ const struct pmc_reg_map mtl_reg_map = { .lpm_sts = adl_lpm_maps, .lpm_status_offset = MTL_LPM_STATUS_OFFSET, .lpm_live_status_offset = MTL_LPM_LIVE_STATUS_OFFSET, + .lpm_reg_index = MTL_LPM_REG_INDEX, }; +/* + * Only return error EPROBE_DEFER when telem handle is not yet available, + * otherwise returns 0. + */ +static int pmc_core_get_mtl_lpm_reqs(struct pmc_dev *pmcdev) +{ + const u8 *reg_index = pmcdev->map->lpm_reg_index; + const int num_maps = pmcdev->map->lpm_num_maps; + struct pci_dev *pcidev = pmcdev->ssram_pcidev; + u32 lpm_size = LPM_MAX_NUM_MODES * num_maps; + struct telem_handle *handle; + int i, j, map_offset = 0; + u32 *lpm_req_regs; + + if (!pcidev) + return 0; + + handle = pmt_telem_find_and_register_handle(pcidev, SOCS_LPM_REQ_GUID, 0); + if (IS_ERR(handle)) { + dev_err(&pmcdev->pdev->dev, + "pmc_core: couldn't get telem handle %ld", PTR_ERR(handle)); + return -EPROBE_DEFER; + } + + lpm_req_regs = devm_kzalloc(&pmcdev->pdev->dev, lpm_size * sizeof(u32), + GFP_KERNEL); + + for (j = 0; j < pmcdev->num_lpm_modes; j++) { + int mode = pmcdev->lpm_en_modes[j]; + u32 *ptr = lpm_req_regs + mode * num_maps; + + for (i = 0; i < num_maps; ++i) { + u8 index = reg_index[i] + LPM_REG_INDEX_OFFSET + map_offset; + int err; + + err = pmt_telem_read32(handle, index, ptr, 1); + if (err) { + dev_err(&pmcdev->pdev->dev, "pmt_telem read failed: %d", err); + pmt_telem_unregister_handle(handle); + return 0; + } + ++ptr; + } + map_offset += LPM_REG_NUM + LPM_SUBSTATE_NUM; + } + pmcdev->lpm_req_regs = lpm_req_regs; + pmt_telem_unregister_handle(handle); + + return 0; +} + static void mtl_pmc_add_pmt(struct pmc_dev *pmcdev, struct pci_dev *pdev, u64 ssram_base) { @@ -152,6 +211,11 @@ int mtl_core_init(struct pmc_dev *pmcdev) mtl_pmc_ssram_init(pmcdev); pmc_core_get_low_power_modes(pmcdev->pdev); + ret = pmc_core_get_mtl_lpm_reqs(pmcdev); + if (ret) { + iounmap(pmcdev->regbase); + return ret; + } /* Due to a hardware limitation, the GBE LTR blocks PC10 * when a cable is attached. Tell the PMC to ignore it.