From patchwork Thu Nov 4 11:00:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuesong Chen X-Patchwork-Id: 12602847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3F76C433F5 for ; Thu, 4 Nov 2021 11:01:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 77E3161108 for ; Thu, 4 Nov 2021 11:01:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 77E3161108 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GD/2Fx75JIA3GQpYtHLOk+ad24+B/gq6cB6msooITqI=; b=i4BArKN98h02Rz U+6qn7BJ4V7PPHnAHEOi2pa2qdMblpED4PgLIxrswk3Zc2jGgJQFHimdkhzNkIVH5QiQFGiP1t5VD aO0h/KUSAsRKDjh9t+I+Ti+KqAsGIQcQ52jiHciYlxKDw7qSqpL+jCH838nP4Hz8scxQw8cy53gFi Xhe1KypAjPFrrXgrGtgG4sBRYqzOqkCV8hfnDLUhyFidl7jOXJDZpZZiE1Kekejiu9kpyUHofUQNV loE6UE12b0NQp0z73q4N/p8GNI1TiaWW/uI5XccfnTJReLB1Te6wj0Bu8iBx5sCA/7DRjU5VvgvJj YK8yGeVnPrNbPYKCHpXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1miaTq-008dCI-Nc; Thu, 04 Nov 2021 11:00:26 +0000 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1miaTm-008dAn-GW for linux-arm-kernel@lists.infradead.org; Thu, 04 Nov 2021 11:00:24 +0000 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R491e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04395; MF=xuesong.chen@linux.alibaba.com; NM=1; PH=DS; RN=17; SR=0; TI=SMTPD_---0Uv1Jbk7_1636023618; Received: from localhost.localdomain(mailfrom:xuesong.chen@linux.alibaba.com fp:SMTPD_---0Uv1Jbk7_1636023618) by smtp.aliyun-inc.com(127.0.0.1); Thu, 04 Nov 2021 19:00:19 +0800 From: Xuesong Chen To: helgaas@kernel.org Cc: catalin.marinas@arm.com, lorenzo.pieralisi@arm.com, james.morse@arm.com, will@kernel.org, rafael@kernel.org, tony.luck@intel.com, bp@alien8.de, mingo@kernel.org, bhelgaas@google.com, ying.huang@intel.com, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, xuesong.chen@linux.alibaba.com Subject: [PATCH v5 3/4] ACPI: APEI: Reserve the MCFG address for quirk ECAM implementation Date: Thu, 4 Nov 2021 19:00:13 +0800 Message-Id: <20211104110013.47719-1-xuesong.chen@linux.alibaba.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20211104105715.47396-1-xuesong.chen@linux.alibaba.com> References: <20211104105715.47396-1-xuesong.chen@linux.alibaba.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211104_040022_743071_B8CDB297 X-CRM114-Status: GOOD ( 17.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On some platforms, the hardware ECAM implementiation is not generic as expected, which will make the PCI configuration access atomic primitive lost. In this case, we need to reserve those quirk MCFG address regions when filtering the normal MCFG resource to make sure the mutual exclusion still works between the MCFG configuration access and EINJ's operation. Signed-off-by: Xuesong Chen --- drivers/acpi/apei/apei-base.c | 25 ++++++++++++++++++++++++- drivers/acpi/pci_mcfg.c | 8 ++++++++ drivers/pci/quirks.c | 2 ++ include/linux/pci.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/apei/apei-base.c b/drivers/acpi/apei/apei-base.c index daae75a..dbb0fa4 100644 --- a/drivers/acpi/apei/apei-base.c +++ b/drivers/acpi/apei/apei-base.c @@ -450,6 +450,23 @@ static int apei_get_nvs_resources(struct apei_resources *resources) } #ifdef CONFIG_PCI +static int remove_quirk_mcfg_res(struct apei_resources *mcfg_res) +{ +#ifdef CONFIG_PCI_QUIRKS + int rc = 0; + struct apei_resources quirk_res; + + apei_resources_init(&quirk_res); + rc = apei_res_add(&quirk_res.iomem, pci_quirk_mcfg_res.start, + resource_size(&pci_quirk_mcfg_res)); + if (rc) + return rc; + + return apei_resources_sub(mcfg_res, &quirk_res); +#else + return 0; +#endif +} extern struct list_head pci_mmcfg_list; static int apei_filter_mcfg_addr(struct apei_resources *res, struct apei_resources *mcfg_res) @@ -462,11 +479,17 @@ static int apei_filter_mcfg_addr(struct apei_resources *res, apei_resources_init(mcfg_res); list_for_each_entry(cfg, &pci_mmcfg_list, list) { - rc = apei_res_add(&mcfg_res->iomem, cfg->res.start, resource_size(&cfg->res)); + rc = apei_res_add(&mcfg_res->iomem, cfg->res.start, + resource_size(&cfg->res)); if (rc) return rc; } + /* remove the pci quirk mcfg resource if any from the mcfg_res */ + rc = remove_quirk_mcfg_res(mcfg_res); + if (rc) + return rc; + /* filter the mcfg resource from current APEI's */ return apei_resources_sub(res, mcfg_res); } diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c index 6ce467f..b5ab866 100644 --- a/drivers/acpi/pci_mcfg.c +++ b/drivers/acpi/pci_mcfg.c @@ -26,6 +26,8 @@ struct mcfg_fixup { struct resource cfgres; }; +static bool pci_quirk_matched; + #define MCFG_BUS_RANGE(start, end) DEFINE_RES_NAMED((start), \ ((end) - (start) + 1), \ NULL, IORESOURCE_BUS) @@ -195,6 +197,7 @@ static void pci_mcfg_apply_quirks(struct acpi_pci_root *root, for (i = 0, f = mcfg_quirks; i < ARRAY_SIZE(mcfg_quirks); i++, f++) { if (pci_mcfg_quirk_matches(f, segment, bus_range)) { + pci_quirk_matched = true; if (f->cfgres.start) *cfgres = f->cfgres; if (f->ops) @@ -251,6 +254,11 @@ int pci_mcfg_lookup(struct acpi_pci_root *root, struct resource *cfgres, *cfgres = res; *ecam_ops = ops; +#ifdef CONFIG_PCI_QUIRKS + if (pci_quirk_matched) + pci_quirk_mcfg_res = res; +#endif + return 0; } diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 1dd426f..1e2fa1c 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -32,6 +32,8 @@ #include /* isa_dma_bridge_buggy */ #include "pci.h" +struct resource pci_quirk_mcfg_res; + static ktime_t fixup_debug_start(struct pci_dev *dev, void (*fn)(struct pci_dev *dev)) { diff --git a/include/linux/pci.h b/include/linux/pci.h index af8dcc8..763a1b2 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2104,6 +2104,7 @@ enum pci_fixup_pass { suspend_late##hook, vendor, device, PCI_ANY_ID, 0, hook) #ifdef CONFIG_PCI_QUIRKS +extern struct resource pci_quirk_mcfg_res; void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev); #else static inline void pci_fixup_device(enum pci_fixup_pass pass,