From patchwork Thu Nov 23 04:03:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "David E. Box" X-Patchwork-Id: 168696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp207828vqx; Wed, 22 Nov 2023 20:05:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFq9zF0UhsKQA3CgTIROmuUsUUkfbEkFRjj0ZamJnKAR9Bfk45NsCpbKagKRajF1kaGozPE X-Received: by 2002:a05:6870:f818:b0:1e9:d4fd:6554 with SMTP id fr24-20020a056870f81800b001e9d4fd6554mr5666103oab.39.1700712355625; Wed, 22 Nov 2023 20:05:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700712355; cv=none; d=google.com; s=arc-20160816; b=Qrr1A5Fwrrj1jmxRaXuwmpYwDgbhWcqTcCCZjziWbU0CACjkJxr9yE3FpVep9QA7s3 Op39sQMBE/L/UubnGIMp+N0EjQJ7o6/BjJeFjV8/2odPJDk2oTeW2FrwNsGULQhJRbYw OuS4hWrgV+FzlJsssDKw8IlPLGNpPLipyPyCEQ83CnN9VYEc0NcN8x8A2NF1UDRxbr43 qrlTF34wn2sP0FwdMibPu/24ftlo9+jvibUhq0KYRAfWR4y8KjVW8XeHfrwjTUN4ME6/ kGe+wEpb+95TXkP1p9Uffx/NAwBihZbfnZ5j1w76u8JLILPvoK3gYEg6kbxUj/DX7pgd mPlw== 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:to:from :dkim-signature; bh=LkRcd5aeRF8EW6ZjaO9qEjP4NM3qagmQzJgLJgROCgk=; fh=d9G4dsZtlI8UONIvGKwhW94hCYEPGxy6CqYeKEG646A=; b=jzMOdeEh47oZNEycAiJEhOvRrkKqR/9xqTqZjXU9Mb1G0MMwBdKDOrMsL4SjzGNeiC UlATjVCu50BJTS85exnlxMgH5190+WBQYyDla75rtu5Z1YqaGd9KsWs2msMpju9LBYoX GaOddveLPLLRaBl6eg0FG2LQ+czNiObiL4wUku9/jTr3VTmnwVvfQ2m+WxtNhCk41/Ln cJeST6t4AiiJZzbACgMRN56bQNsFYnvEWEygxuLvxbcYXDXJ4klqd+EeuJGSW4VmxfvP xKkqkniO9lXiaOH8hWWMdnLqry5aln8f81qArn7pwO1f28jcmNffAB6RGtoFVUvjqjnJ kPiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QGv/COj4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o6-20020a056a0015c600b006c33a1bdf92si476616pfu.307.2023.11.22.20.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 20:05:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QGv/COj4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0383F81EE2EC; Wed, 22 Nov 2023 20:05:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235228AbjKWEFT (ORCPT + 99 others); Wed, 22 Nov 2023 23:05:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbjKWEDy (ORCPT ); Wed, 22 Nov 2023 23:03:54 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D0E4D4F; Wed, 22 Nov 2023 20:04:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700712241; x=1732248241; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=bTY6oidySEMa0Nzt+g/YWkffDxzQYR8+KdRFdCrHSZ4=; b=QGv/COj45We6y58HSStyHJQGaK/f4d8EF9GwZj55NjffXL+cmGahIgtv xkAFgQ18+kn0qi+/szC3n1OucaP1eb5TL8+xPLdnCsKSw/aqD1U48Aq/Z I09Hgrfhl7xdq9XzbZCOB6MBHoPYPXq+Oy2T2JNtQ4uTqIrZEVFKpYI0X YoCE3fd637C13S3vmkalAlc8/gp6xxv9LX+DW1NU/31xT8OSam+y45iUr 4QRp/aYUT/rsq4oV/uAN1rfdbyw1bNt6IrTuXPTeopZza5jU/1uZuFJQR caRzDkqJhprmVtyuhtrULaGKkIFuHs9jFWzeYDEbA1Z17BPJsLOYVpEhF g==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="5334666" X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="5334666" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 20:03:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="837671156" X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="837671156" Received: from linux.intel.com ([10.54.29.200]) by fmsmga004.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 20:03:57 -0800 Received: from debox1-desk4.lan (snpatel1-mobl.amr.corp.intel.com [10.209.89.91]) by linux.intel.com (Postfix) with ESMTP id EB1E8580D7B; Wed, 22 Nov 2023 20:03:56 -0800 (PST) From: "David E. Box" To: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, rajvi.jingar@linux.intel.com Subject: [PATCH V5 13/20] platform/x86/intel/pmc: Cleanup SSRAM discovery Date: Wed, 22 Nov 2023 20:03:48 -0800 Message-Id: <20231123040355.82139-14-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231123040355.82139-1-david.e.box@linux.intel.com> References: <20231123040355.82139-1-david.e.box@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 22 Nov 2023 20:05:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783326158912031407 X-GMAIL-MSGID: 1783326158912031407 Clean up the code handling SSRAM discovery. Handle all resource allocation and cleanup in pmc_core_ssram_get_pmc(). Return the error status from this function but only fail the init if we fail to discover the primary PMC. Signed-off-by: David E. Box Reviewed-by: Ilpo Järvinen --- V5 - Use single function to handle SSRAM discovery of all PMCs. V4 - Add checking the return value from pmc_core_sram_init() to mtl.c - Use iounmap cleanup from io.h V3 - New patch split from previous PATCH 2 - Update changelog - Use cleanup.h to cleanup ioremap V2 - no change drivers/platform/x86/intel/pmc/core_ssram.c | 60 +++++++++++---------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/platform/x86/intel/pmc/core_ssram.c b/drivers/platform/x86/intel/pmc/core_ssram.c index 815950713e25..cb44394d88ce 100644 --- a/drivers/platform/x86/intel/pmc/core_ssram.c +++ b/drivers/platform/x86/intel/pmc/core_ssram.c @@ -8,6 +8,7 @@ * */ +#include #include #include @@ -65,44 +66,49 @@ pmc_core_pmc_add(struct pmc_dev *pmcdev, u64 pwrm_base, return 0; } -static void -pmc_core_ssram_get_pmc(struct pmc_dev *pmcdev, void __iomem *ssram, u32 offset, - int pmc_idx) +static int +pmc_core_ssram_get_pmc(struct pmc_dev *pmcdev, int pmc_idx, u32 offset) { - u64 pwrm_base; + struct pci_dev *ssram_pcidev = pmcdev->ssram_pcidev; + void __iomem __free(iounmap) *tmp_ssram = NULL; + void __iomem __free(iounmap) *ssram = NULL; + const struct pmc_reg_map *map; + u64 ssram_base, pwrm_base; u16 devid; - if (pmc_idx != PMC_IDX_SOC) { - u64 ssram_base = get_base(ssram, offset); + if (!pmcdev->regmap_list) + return -ENOENT; - if (!ssram_base) - return; + ssram_base = ssram_pcidev->resource[0].start; + tmp_ssram = ioremap(ssram_base, SSRAM_HDR_SIZE); + if (pmc_idx != PMC_IDX_MAIN) { + /* + * The secondary PMC BARS (which are behind hidden PCI devices) + * are read from fixed offsets in MMIO of the primary PMC BAR. + */ + ssram_base = get_base(tmp_ssram, offset); ssram = ioremap(ssram_base, SSRAM_HDR_SIZE); if (!ssram) - return; + return -ENOMEM; + + } else { + ssram = no_free_ptr(tmp_ssram); } pwrm_base = get_base(ssram, SSRAM_PWRM_OFFSET); devid = readw(ssram + SSRAM_DEVID_OFFSET); - if (pmcdev->regmap_list) { - const struct pmc_reg_map *map; + map = pmc_core_find_regmap(pmcdev->regmap_list, devid); + if (!map) + return -ENODEV; - map = pmc_core_find_regmap(pmcdev->regmap_list, devid); - if (map) - pmc_core_pmc_add(pmcdev, pwrm_base, map, pmc_idx); - } - - if (pmc_idx != PMC_IDX_SOC) - iounmap(ssram); + return pmc_core_pmc_add(pmcdev, pwrm_base, map, PMC_IDX_MAIN); } int pmc_core_ssram_init(struct pmc_dev *pmcdev) { - void __iomem *ssram; struct pci_dev *pcidev; - u64 ssram_base; int ret; pcidev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(20, 2)); @@ -113,18 +119,14 @@ int pmc_core_ssram_init(struct pmc_dev *pmcdev) if (ret) goto release_dev; - ssram_base = pcidev->resource[0].start; - ssram = ioremap(ssram_base, SSRAM_HDR_SIZE); - if (!ssram) - goto disable_dev; - pmcdev->ssram_pcidev = pcidev; - pmc_core_ssram_get_pmc(pmcdev, ssram, 0, PMC_IDX_SOC); - pmc_core_ssram_get_pmc(pmcdev, ssram, SSRAM_IOE_OFFSET, PMC_IDX_IOE); - pmc_core_ssram_get_pmc(pmcdev, ssram, SSRAM_PCH_OFFSET, PMC_IDX_PCH); + ret = pmc_core_ssram_get_pmc(pmcdev, PMC_IDX_MAIN, 0); + if (ret) + goto disable_dev; - iounmap(ssram); + pmc_core_ssram_get_pmc(pmcdev, PMC_IDX_IOE, SSRAM_IOE_OFFSET); + pmc_core_ssram_get_pmc(pmcdev, PMC_IDX_PCH, SSRAM_PCH_OFFSET); return 0;