From patchwork Thu Jun 2 08:41:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 9149561 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 849C46074E for ; Thu, 2 Jun 2016 08:44:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54A082679B for ; Thu, 2 Jun 2016 08:44:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 490C02823A; Thu, 2 Jun 2016 08:44:02 +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 91A872679B for ; Thu, 2 Jun 2016 08:44:01 +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 1b8ODC-0004uY-11; Thu, 02 Jun 2016 08:42:42 +0000 Received: from mail-lf0-x236.google.com ([2a00:1450:4010:c07::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8OCt-0004m5-OR for linux-arm-kernel@lists.infradead.org; Thu, 02 Jun 2016 08:42:24 +0000 Received: by mail-lf0-x236.google.com with SMTP id k98so29197674lfi.1 for ; Thu, 02 Jun 2016 01:42:03 -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=uMFEW0dxfmxtlv1m4oQ39ElsyZG0sWhb2t4Ii9ST3gc=; b=xg2qMmg4u8rHRFQNQimmRE2HVB9GYPGKp7MB85y0lUEy/gjLRz1Z6JrxeehInSfQLw BQEMFYEpUY9Y2PSaBBfEjWyU2hVe6NMWYS0e27j5hwEU92OrumkYH50OKJmfh/4HLkIr uws/IodHajo2q2SImVPACcsVf32Lggxz9A3rUX1IAflQaDuC+MZze6DvJavuWwP4OxG7 LGYgMZqKHzXgVddOG0YZ0NTxk75/KWMWK0KuwvWCc9/stq8TE7lHmMDAMwPfM3fr6bka lG/qX6ymtKkRH+YhzSh5G2YRhdiC9OWKfHeiX8j01IMte1/RqP2hdfI+UUgaHlVoe0zD o4MQ== 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=uMFEW0dxfmxtlv1m4oQ39ElsyZG0sWhb2t4Ii9ST3gc=; b=gODsnbrOBKq6tNKW4G+BQQUhnfQq9uIQKppaor8BZAANmdY6l2fsx0j0lgcTGqr1Qc egWcFxOWvpBeQzzfafYv+vRoNblLzNw7I1kH6WW13OVBXeAqVVvCUJysN69ZK99HKB3x n0ADq4fjfCzKFrEY8DBo2JbEpqVMW70Z/GRpdtilJFv8tsli7YHIvYQMzJFzpZL0o0Ur HEYXILRcSiBM6nC+emU1KvgBR+Qot+8jpxRKGLKzL99iAeLac+7rH0DffZ6CBwZ8JKjk YYKjT5ozXZAleXyDIQU2tHTgG18sMC0xRoHQpvMqS/sLqJv+TdSd047bQTBHIamIZtP3 q8VQ== X-Gm-Message-State: ALyK8tJfUMv11QjIuUxJOnhJEUuojo9hCKQfMuw0nADFgU5PbYeSFamtipkyouRl2pFYSA== X-Received: by 10.25.156.213 with SMTP id f204mr3852822lfe.51.1464856921860; Thu, 02 Jun 2016 01:42:01 -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.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jun 2016 01:42:00 -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 3/3] pci, pci-thunder-pem: Add ACPI support for ThunderX PEM. Date: Thu, 2 Jun 2016 10:41:03 +0200 Message-Id: <1464856864-18049-4-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_014224_177658_0DC9DF3A X-CRM114-Status: GOOD ( 16.07 ) 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 This patch uses DECLARE_ACPI_MCFG_FIXUP to overwrite PCI config accessors. Also, it provides alternative way to find additional configuration region: thunder_pem_get_acpi_res is looking for host bridge's child (_HID "THRX0001") which contains mentioned configuration region description. See example below: Device (PEM0) { Name (_HID, EISAID ("PNP0A08")) Name (_CID, EISAID ("PNP0A03")) [...] Device (CFG0) { Name (_HID, "THRX0001") // PEM configuration space resources Name (_CRS, ResourceTemplate () { QWordMemory(ResourceConsumer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite, 0, 0x87e0c5000000, 0x87E0C5FFFFFF, 0, 0x01000000) }) } } Signed-off-by: Tomasz Nowicki --- drivers/pci/host/pci-thunder-pem.c | 132 +++++++++++++++++++++++++++++++++---- 1 file changed, 119 insertions(+), 13 deletions(-) diff --git a/drivers/pci/host/pci-thunder-pem.c b/drivers/pci/host/pci-thunder-pem.c index 91f6fc6..8f002ef 100644 --- a/drivers/pci/host/pci-thunder-pem.c +++ b/drivers/pci/host/pci-thunder-pem.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -284,6 +285,83 @@ static int thunder_pem_config_write(struct pci_bus *bus, unsigned int devfn, return pci_generic_config_write(bus, devfn, where, size, val); } +#ifdef CONFIG_ACPI + +struct pem_acpi_res { + struct resource resource; + int found; +}; + +static acpi_status +thunder_pem_cfg(struct acpi_resource *resource, void *ctx) +{ + struct pem_acpi_res *pem_ctx = ctx; + struct resource *res = &pem_ctx->resource; + + if ((resource->type != ACPI_RESOURCE_TYPE_ADDRESS64) || + (resource->data.address32.resource_type != ACPI_MEMORY_RANGE)) + return AE_OK; + + res->start = resource->data.address64.address.minimum; + res->end = resource->data.address64.address.maximum; + res->flags = IORESOURCE_MEM; + + pem_ctx->found++; + return AE_OK; +} + +static acpi_status +thunder_pem_find_dev(acpi_handle handle, u32 level, void *ctx, void **ret) +{ + struct pem_acpi_res *pem_ctx = ctx; + struct acpi_device_info *info; + acpi_status status = AE_OK; + + status = acpi_get_object_info(handle, &info); + if (ACPI_FAILURE(status)) + return AE_OK; + + if (strncmp(info->hardware_id.string, "THRX0001", 8) != 0) + goto out; + + pem_ctx->found = 0; + status = acpi_walk_resources(handle, METHOD_NAME__CRS, thunder_pem_cfg, + pem_ctx); + if (ACPI_FAILURE(status)) + goto out; + + if (pem_ctx->found) + status = AE_CTRL_TERMINATE; +out: + kfree(info); + return status; +} + +static struct resource *thunder_pem_get_acpi_res(struct device *dev) +{ + struct acpi_device *adev = to_acpi_device(dev); + acpi_handle handle = acpi_device_handle(adev); + struct pem_acpi_res *pem_ctx; + acpi_status status; + + pem_ctx = devm_kzalloc(dev, sizeof(*pem_ctx), GFP_KERNEL); + if (!pem_ctx) + return NULL; + + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, + thunder_pem_find_dev, NULL, pem_ctx, NULL); + if (ACPI_FAILURE(status) || !pem_ctx->found) + return NULL; + + return &pem_ctx->resource; +} +#else +static struct resource *thunder_pem_get_acpi_res(struct device *dev) +{ + return NULL; +} +#endif + static int thunder_pem_init(struct pci_config_window *cfg) { struct device *dev = cfg->parent; @@ -292,24 +370,24 @@ static int thunder_pem_init(struct pci_config_window *cfg) struct thunder_pem_pci *pem_pci; struct platform_device *pdev; - /* Only OF support for now */ - if (!dev->of_node) - return -EINVAL; - pem_pci = devm_kzalloc(dev, sizeof(*pem_pci), GFP_KERNEL); if (!pem_pci) return -ENOMEM; - pdev = to_platform_device(dev); - - /* - * The second register range is the PEM bridge to the PCIe - * bus. It has a different config access method than those - * devices behind the bridge. - */ - res_pem = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (acpi_disabled) { + pdev = to_platform_device(dev); + + /* + * The second register range is the PEM bridge to the PCIe + * bus. It has a different config access method than those + * devices behind the bridge. + */ + res_pem = platform_get_resource(pdev, IORESOURCE_MEM, 1); + } else { + res_pem = thunder_pem_get_acpi_res(dev); + } if (!res_pem) { - dev_err(dev, "missing \"reg[1]\"property\n"); + dev_err(dev, "missing configuration region\n"); return -EINVAL; } @@ -362,5 +440,33 @@ static struct platform_driver thunder_pem_driver = { }; module_platform_driver(thunder_pem_driver); +#ifdef CONFIG_ACPI + +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 4, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 5, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 6, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 7, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 8, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 9, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 14, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 15, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 16, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 17, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 18, PCI_MCFG_BUS_ANY); +DECLARE_ACPI_MCFG_FIXUP(&pci_thunder_pem_ops, "CAVIUM", 1, + 19, PCI_MCFG_BUS_ANY); +#endif + MODULE_DESCRIPTION("Thunder PEM PCIe host driver"); MODULE_LICENSE("GPL v2");