From patchwork Thu Jun 2 08:41:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 9149557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 053D36074E for ; Thu, 2 Jun 2016 08:43:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E92732679B for ; Thu, 2 Jun 2016 08:43:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD87F271FD; Thu, 2 Jun 2016 08:43:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 6799A263DC for ; Thu, 2 Jun 2016 08:43:56 +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 1b8OCp-0004nj-46; Thu, 02 Jun 2016 08:42:19 +0000 Received: from mail-lf0-x22a.google.com ([2a00:1450:4010:c07::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8OCl-0004m3-N3 for linux-arm-kernel@lists.infradead.org; Thu, 02 Jun 2016 08:42:16 +0000 Received: by mail-lf0-x22a.google.com with SMTP id b73so29112315lfb.3 for ; Thu, 02 Jun 2016 01:41:57 -0700 (PDT) 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=wzByaX+2kbXKEJod4XXdUV/OIxggLwAMl7vXFvPiNEM=; b=JUbjd7idmX6v+ai2EP9dac5NmSmt6/56SuL53Wzjc9JKezXouzVWs8LLSSFCdGEWnV Tgn9v6dh2xo/XTO5VjyjBD4F9WhHUmxw8p2VHq/mYWknXrGBL0nAfkSS48mFWJYyw6P9 UdjXniBpPtD+6BRv13XftZLuCu9GkKLkiSSvq6xQRG3rXEJA+8T3w14EaLND5J/g4Mk2 3jWmQixuhipurxMxyDgqr06+tpkFvjDiRQeN0A2i0rwjjcA4CTIUaaEYdlqSSVlbeoLE bVzRBYnq9DmGIuFH8OqV0Rh2y6H0H8Vzx4GtKxroeegzYV590H70W3ak2uNNp0heD4Zi sulA== 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=wzByaX+2kbXKEJod4XXdUV/OIxggLwAMl7vXFvPiNEM=; b=A80nS0Wp9Q/ttrhPyLPAgNB7KYdgeWlbtilTTFbWiKDxfzW0Cx3Ha/ShQi4TgE2FuV q9wN2ypQXKOsNfbCNqWVfSrMSeuzmz5I3e2DVt2WeW8nC9KDJsXpx0UMpBhi32BW3s1x QfFs5zi9JhHl+XdVWnR1VdsVV2Sj2BF6Tg+KGSJrQiqcrOum8lCCVlrbiGEoxemK2EED FQOOTuwmx7J90Nu1sN3/vVONC0uFMDQPzjnPsqaCx+aiTR31mftLkCFbThxdcSXMowy8 4FSsk6iET3ZEmJSROBLQ0xbWqJBiQ6bfvmbdfyXr+1ZQpjfFa2jJeQiuHLj2CfbJ05/X 1+YQ== X-Gm-Message-State: ALyK8tJEG6nuC+NPYknocjPq1xr60924M6Umaim6F70+DXIKmTi4nNMQCOU66hBlFX5qvQ== X-Received: by 10.25.44.144 with SMTP id s138mr3602125lfs.146.1464856916264; Thu, 02 Jun 2016 01:41:56 -0700 (PDT) Received: from tn-HP-4.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id h23sm3972815lji.23.2016.06.02.01.41.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jun 2016 01:41:55 -0700 (PDT) From: Tomasz Nowicki To: helgaas@kernel.org, arnd@arndb.de, will.deacon@arm.com, catalin.marinas@arm.com, rafael@kernel.org, hanjun.guo@linaro.org, Lorenzo.Pieralisi@arm.com, okaya@codeaurora.org, jchandra@broadcom.com Subject: [RFC PATCH 1/3] pci, acpi: Match PCI config space accessors against platfrom specific ECAM quirks. Date: Thu, 2 Jun 2016 10:41:01 +0200 Message-Id: <1464856864-18049-2-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464856864-18049-1-git-send-email-tn@semihalf.com> References: <1464856864-18049-1-git-send-email-tn@semihalf.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160602_014216_129054_F3919631 X-CRM114-Status: GOOD ( 15.22 ) 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: jcm@redhat.com, linaro-acpi@lists.linaro.org, linux-pci@vger.kernel.org, dhdang@apm.com, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com, jeremy.linton@arm.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, robert.richter@caviumnetworks.com, cov@codeaurora.org, Suravee.Suthikulpanit@amd.com, msalter@redhat.com, wangyijing@huawei.com, Tomasz Nowicki , mw@semihalf.com, andrea.gallo@linaro.org, linux-arm-kernel@lists.infradead.org, liudongdong3@huawei.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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. Algorithm traverses available quirk list, matches against tuple and returns corresponding PCI config ops. oem_id and oem_rev come from MCFG table standard header. All quirks can be defined using DECLARE_ACPI_MCFG_FIXUP() macro and kept self contained. Example: /* Custom PCI config ops */ static struct pci_generic_ecam_ops foo_pci_ops = { .bus_shift = 24, .pci_ops = { .map_bus = pci_ecam_map_bus, .read = foo_ecam_config_read, .write = foo_ecam_config_write, } }; DECLARE_ACPI_MCFG_FIXUP(&foo_pci_ops, , , , ); Signed-off-by: Tomasz Nowicki --- drivers/acpi/pci_mcfg.c | 32 ++++++++++++++++++++++++++++++++ include/asm-generic/vmlinux.lds.h | 7 +++++++ include/linux/pci-acpi.h | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c index 1847f74..f3d4570 100644 --- a/drivers/acpi/pci_mcfg.c +++ b/drivers/acpi/pci_mcfg.c @@ -22,11 +22,43 @@ #include #include #include +#include /* Root pointer to the mapped MCFG table */ static struct acpi_table_mcfg *mcfg_table; static int mcfg_entries; +extern struct pci_cfg_fixup __start_acpi_mcfg_fixups[]; +extern struct pci_cfg_fixup __end_acpi_mcfg_fixups[]; + +struct pci_ecam_ops *pci_mcfg_get_ops(struct acpi_pci_root *root) +{ + int bus_num = root->secondary.start; + int domain = root->segment; + struct pci_cfg_fixup *f; + + if (!mcfg_table) + return &pci_generic_ecam_ops; + + /* + * Match against platform specific quirks and return corresponding + * CAM ops. + * + * First match against PCI topology then use OEM ID and + * OEM revision from MCFG table standard header. + */ + for (f = __start_acpi_mcfg_fixups; f < __end_acpi_mcfg_fixups; f++) { + if ((f->domain == domain || f->domain == PCI_MCFG_DOMAIN_ANY) && + (f->bus_num == bus_num || f->bus_num == PCI_MCFG_BUS_ANY) && + (!strncmp(f->oem_id, mcfg_table->header.oem_id, + ACPI_OEM_ID_SIZE)) && + (f->oem_revision == mcfg_table->header.oem_revision)) + return f->ops; + } + /* No quirks, use ECAM */ + return &pci_generic_ecam_ops; +} + int pci_mcfg_lookup(struct acpi_pci_root *root) { struct acpi_mcfg_allocation *mptr, *entry = NULL; diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 6a67ab9..43604fc 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -300,6 +300,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/pci-acpi.h b/include/linux/pci-acpi.h index e0e6dfc..b4e8106 100644 --- a/include/linux/pci-acpi.h +++ b/include/linux/pci-acpi.h @@ -25,6 +25,7 @@ static inline acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev) extern phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle); extern int pci_mcfg_lookup(struct acpi_pci_root *root); +extern struct pci_ecam_ops *pci_mcfg_get_ops(struct acpi_pci_root *root); static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev) { @@ -72,6 +73,24 @@ struct acpi_pci_root_ops { int (*prepare_resources)(struct acpi_pci_root_info *info); }; +struct pci_cfg_fixup { + struct pci_ecam_ops *ops; + char *oem_id; + u32 oem_revision; + int domain; + int bus_num; +}; + +#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(ops, oem_id, rev, dom, bus) \ + static const struct pci_cfg_fixup __mcfg_fixup_##system##dom##bus\ + __used __attribute__((__section__(".acpi_fixup_mcfg"), \ + aligned((sizeof(void *))))) = \ + { ops, oem_id, rev, dom, bus }; + extern int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info); extern struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, struct acpi_pci_root_ops *ops,