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: 9149555 X-Patchwork-Delegate: bhelgaas@google.com 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 6AE646074E for ; Thu, 2 Jun 2016 08:43:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BF17263DC for ; Thu, 2 Jun 2016 08:43:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5091B2679B; Thu, 2 Jun 2016 08:43:21 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3F4F271FD for ; Thu, 2 Jun 2016 08:43:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932220AbcFBImz (ORCPT ); Thu, 2 Jun 2016 04:42:55 -0400 Received: from mail-lf0-f45.google.com ([209.85.215.45]:34665 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752508AbcFBIl6 (ORCPT ); Thu, 2 Jun 2016 04:41:58 -0400 Received: by mail-lf0-f45.google.com with SMTP id k98so29196106lfi.1 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=gC3K762ncdb1KOLxbFu0Pp8P8JZxWqNoQkLOGijAYzXcjCTs5zJcHZ76LqxlxnD1ac c8ts8yFc5Q1hK+dK7Eh/nCsmUpTAdJn4idQvklGmU+t1ZVnU2utWllHzHBoLgWK1OQcQ lpiO/faJP+RpsgSSQ/gwpBoiWcBRiaA0GtHR6UwIw9vHZns8aJvor9+twtPJCnIXUYeI Cf7pUXZ+IpxuSnwgHimSA1r1ubbCnKwl5RahmxE19g427XEKKDeUjPA1tOMRslimQB/f ODnfsgBSJKfMJ2PYqYaciZUcZdTxyCL/yYpfdkjDd9BOODgSTTNSJi6VXHNlqablRsZG v0SA== X-Gm-Message-State: ALyK8tLV5RtGjyMZoKDmY0iGY60Y9tDaJ4ieGcNkJB4UsVjjhg6ki1orGQvZeUL06hxtnQ== 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 Cc: robert.richter@caviumnetworks.com, mw@semihalf.com, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com, wangyijing@huawei.com, Suravee.Suthikulpanit@amd.com, msalter@redhat.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, jcm@redhat.com, andrea.gallo@linaro.org, dhdang@apm.com, jeremy.linton@arm.com, liudongdong3@huawei.com, cov@codeaurora.org, Tomasz Nowicki 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> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.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. 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,