From patchwork Wed Dec 16 15:16:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 7863081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DAFC7BEEE1 for ; Wed, 16 Dec 2015 15:31:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DF61220382 for ; Wed, 16 Dec 2015 15:31:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8B642037F for ; Wed, 16 Dec 2015 15:31:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a9E1H-0003vZ-Dw; Wed, 16 Dec 2015 15:29:35 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a9Dqi-0000q3-TI for linux-arm-kernel@lists.infradead.org; Wed, 16 Dec 2015 15:18:45 +0000 Received: by mail-wm0-x22b.google.com with SMTP id p187so5624979wmp.0 for ; Wed, 16 Dec 2015 07:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=usgbDsm6XX2MyMv1BmanURpPTQOTGYOZRxpT3BLb8OQ=; b=s4cBYaGPN2m57erYOvnlQWvGB2KGJzSdflbOUmyoHUvXv3lG3UwmuugvxSTWCPQRSl XL+fh8cgUUh7oOs4ZMB0tDHdhe/cVN9Bg72G+LcEsQk+i49tJTpZn9+NVHMsx6RgvZFl o9JO8cYwgF6v+M7tz7f9xd9Yb5dToX8+nrQqYFYa7MEtRBtpKbzOfcdUc3s9sxxCbDRw JHgKnhj4Gw/qsl06x7UzsNTyGTLugk9ccQKlyIEi5NNu+Nv+ETrLmjJ7KABBCUiglZ1s GjnTYuiriAMNqSlvfa9A6wgpCXEUgYxdkDvZvNsqE20R/OX+riPFZLdBXmRbk0Nz7g/c WAvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=usgbDsm6XX2MyMv1BmanURpPTQOTGYOZRxpT3BLb8OQ=; b=feMD9jLbFGI/RWL7j0drkghj1bKrvfJ0LB8gsuV9Sy/ZPteroqALAj6mEcuqrWcj7+ 6hiChfwKneDjcPcbmPaf2b8c1Jf56wgmEi4x723l96zBwpVAPa8VYTkqPrw1DiAVjabY 31VhgdIsJRVyOROkBZi9fwsfcUwzt44Rb6QW042nO8sSjlamJGw/HnjMIOWQEP/bfIz6 +HytaEz/x7nUeTxpj+Q1f6rJ+AouXCwtfbce28LbI1Z1pwx/bHzEXniK/dziY++iyhj+ HkRxf/Y+konT1nU9qd5kEe423cLWdewflOqG0iWJHUIhHxsTr9vX7OAzvYiG3+zllVuI SHDw== X-Gm-Message-State: ALoCoQnPgzIY5ScFQslA8/aYdy8mRU9s/faF0KHD39vCrMS5umw8vM36kLbxmVBpLyjhQKPwRwF9+sp3Qi8oayc4UQOsfx2LRw== X-Received: by 10.194.243.103 with SMTP id wx7mr23949363wjc.136.1450279099076; Wed, 16 Dec 2015 07:18:19 -0800 (PST) Received: from tn-HP-4.semihalf.local ([80.82.22.190]) by smtp.gmail.com with ESMTPSA id z17sm6438761wjq.1.2015.12.16.07.18.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Dec 2015 07:18:18 -0800 (PST) From: Tomasz Nowicki To: bhelgaas@google.com, arnd@arndb.de, will.deacon@arm.com, catalin.marinas@arm.com, rjw@rjwysocki.net, hanjun.guo@linaro.org, Lorenzo.Pieralisi@arm.com, okaya@codeaurora.org, jiang.liu@linux.intel.com, Stefano.Stabellini@eu.citrix.com Subject: [PATCH V2 22/23] pci, acpi: Match PCI config space accessors against platfrom specific quirks. Date: Wed, 16 Dec 2015 16:16:32 +0100 Message-Id: <1450278993-12664-23-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450278993-12664-1-git-send-email-tn@semihalf.com> References: <1450278993-12664-1-git-send-email-tn@semihalf.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151216_071841_527266_B6DD3596 X-CRM114-Status: GOOD ( 16.22 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jchandra@broadcom.com, jcm@redhat.com, linaro-acpi@lists.linaro.org, linux-pci@vger.kernel.org, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, robert.richter@caviumnetworks.com, Suravee.Suthikulpanit@amd.com, msalter@redhat.com, wangyijing@huawei.com, Tomasz Nowicki , tglx@linutronix.de, mw@semihalf.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some platforms may not be fully compliant with generic set of PCI config accessors. For these cases we implement the way to overwrite accessors set before PCI buses enumeration. Algorithm that overwrite accessors matches against platform ID (DMI), domain and bus number, hopefully enough for all cases. All quirks can be defined using: DECLARE_ACPI_MCFG_FIXUP() and keep self contained. example: static const struct dmi_system_id yyy[] = { { .ident = "", .callback = , .matches = { DMI_MATCH(DMI_SYS_VENDOR, ""), DMI_MATCH(DMI_PRODUCT_NAME, ""), DMI_MATCH(DMI_PRODUCT_VERSION, "product version"), }, }, { } }; static struct pci_ops ecam_pci_ops = { .map_bus = pci_mcfg_dev_base, .read = xxxx_ecam_config_read, .write = xxxx_ecam_config_write, }; DECLARE_ACPI_MCFG_FIXUP(yyy, &ecam_pci_ops, , ); Note, that more custom actions can be done via DMI callback hook. Signed-off-by: Tomasz Nowicki --- drivers/acpi/mcfg.c | 35 +++++++++++++++++++++++++++++++++-- include/asm-generic/vmlinux.lds.h | 7 +++++++ include/linux/ecam.h | 17 +++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/mcfg.c b/drivers/acpi/mcfg.c index a9b2231..6d0194d 100644 --- a/drivers/acpi/mcfg.c +++ b/drivers/acpi/mcfg.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -34,6 +35,31 @@ int __weak raw_pci_write(unsigned int domain, unsigned int bus, return PCIBIOS_DEVICE_NOT_FOUND; } +extern struct pci_mcfg_fixup __start_acpi_mcfg_fixups[]; +extern struct pci_mcfg_fixup __end_acpi_mcfg_fixups[]; + +static struct pci_ops *pci_mcfg_check_quirks(int domain, int bus_number) +{ + struct pci_mcfg_fixup *fixup; + + fixup = __start_acpi_mcfg_fixups; + while (fixup < __end_acpi_mcfg_fixups) { + if (dmi_check_system(fixup->system) && + (fixup->domain == domain || + fixup->domain == PCI_MCFG_DOMAIN_ANY) && + (fixup->bus_number == bus_number || + fixup->bus_number == PCI_MCFG_BUS_ANY)) { + pr_info(PREFIX "Fixup applied: Platform [%s] domain [%d] bus number [%d]\n", + fixup->system->ident, fixup->domain, + fixup->bus_number); + return fixup->ops; + } + ++fixup; + } + + return NULL; +} + void __iomem * pci_mcfg_dev_base(struct pci_bus *bus, unsigned int devfn, int offset) { @@ -56,10 +82,15 @@ static struct pci_ops default_pci_mcfg_ops = { struct pci_ops *pci_mcfg_get_ops(int domain, int bus) { + struct pci_ops *pci_mcfg_ops_quirk; + /* - * TODO: Match against platform specific quirks and return - * corresponding PCI config space accessor set. + * Match against platform specific quirks and return corresponding + * PCI config space accessor set. */ + pci_mcfg_ops_quirk = pci_mcfg_check_quirks(domain, bus); + if (pci_mcfg_ops_quirk) + return pci_mcfg_ops_quirk; return &default_pci_mcfg_ops; } diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index c4bd0e2..c93fc97 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -298,6 +298,13 @@ VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .; \ } \ \ + /* ACPI MCFG quirks */ \ + .acpi_fixup : AT(ADDR(.acpi_fixup) - LOAD_OFFSET) { \ + VMLINUX_SYMBOL(__start_acpi_mcfg_fixups) = .; \ + *(.acpi_fixup_mcfg) \ + VMLINUX_SYMBOL(__end_acpi_mcfg_fixups) = .; \ + } \ + \ /* Built-in firmware blobs */ \ .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \ VMLINUX_SYMBOL(__start_builtin_fw) = .; \ diff --git a/include/linux/ecam.h b/include/linux/ecam.h index e0f322e..1319fa8 100644 --- a/include/linux/ecam.h +++ b/include/linux/ecam.h @@ -20,6 +20,23 @@ struct pci_mmcfg_region { bool hot_added; }; +struct pci_mcfg_fixup { + const struct dmi_system_id *system; + struct pci_ops *ops; + int domain; + int bus_number; +}; + +#define PCI_MCFG_DOMAIN_ANY -1 +#define PCI_MCFG_BUS_ANY -1 + +/* Designate a routine to fix up buggy MCFG */ +#define DECLARE_ACPI_MCFG_FIXUP(system, ops, dom, bus) \ + static const struct pci_mcfg_fixup __mcfg_fixup_##system##dom##bus\ + __used __attribute__((__section__(".acpi_fixup_mcfg"), \ + aligned((sizeof(void *))))) = \ + { system, ops, dom, bus }; + struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus); struct pci_mmcfg_region *pci_mmconfig_alloc(int segment, int start, int end, u64 addr);