From patchwork Wed Mar 15 07:49:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 9625017 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 780086048C for ; Wed, 15 Mar 2017 08:01:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69EC328422 for ; Wed, 15 Mar 2017 08:01:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EA70285FC; Wed, 15 Mar 2017 08:01:37 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D3BC728422 for ; Wed, 15 Mar 2017 08:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=g2hO4Hv+RD3UjLxexUvZPkNLDIrdxlqT+EUYt6/JwHY=; b=G/mCYvFqeEczfTYTg3t5VqxSJS UNJ5vDPpr/IeezokiXh5uD1pVL9nc7sBMF4x3coFWnUUHdpdcp8pWjrL5qF9EIzgHHyHIKMZLFPb1 SUI9ComvK0yDMQJfrUZih+tAg12qOs+m8/YQo9lBiXkCZgBVCFO51+UF1Nsv/Y9H78zrd+JmAYVoh ClviO6And1q2K5xJWvqxSwzYuH8BufgK/ORh6DH9TpqIo/LxGMHfC7FhA1GtyciiERGN5b9eex6gN rF1qxilgsCZsUzjntUNwcZ8deKdZ12/Gx/UT3nLlElcd+dBfTAIqkHMnCET5yOljYihladwa1oKUx C+NFp+Bg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1co3sF-0003v8-5y; Wed, 15 Mar 2017 08:01:35 +0000 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1co3hS-0006ew-Fi for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2017 07:51:42 +0000 Received: by mail-lf0-x22b.google.com with SMTP id a6so3384066lfa.0 for ; Wed, 15 Mar 2017 00:50:06 -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=+y3HB0s/rCbBdrzuBekFbOVbP2GkdEDf6EPFmyUXkj0=; b=gjdhlMYVioG4bE7Mb1SXfTnaNbRjH3MHQ/XxQznh47TIvY56AQDXcP98XGKjVk7AuD iACbqrh05Ba+0YEjnJHAX4U61NNr9V6NdKmHShE4ZC+i9swPGjBsLXCPznaTDBgCxKg+ nQmFrzT+RQNOu/PP74tPzhoOg9tAYrNw9A9Uc0P5olmty//ccptuvrD2MKULq91pkuQe 3eApCWT2Phwg/W4gK5f9OXVLRSaRZK1awvxVKEXofLzT4SDhQNVbh2N0opGUvltSQn0F /vLFeqqqAs0Tt+aFWPwZspiUd5M9NwVYVKgGA9O9dThzEBx2pfEePSaV7U1mjcIzRxR/ bMxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+y3HB0s/rCbBdrzuBekFbOVbP2GkdEDf6EPFmyUXkj0=; b=o8s7qG4lzuyzQCDt1hjN4y6pdMhzV5X1Q2lZaM8k5+gwyUhi2tEhm2waa6MvTCa7gB i4+QcD6+C420Xy3F4lAMPtle5EBOzN5qgEg5sd9p2QoCQW4WVdbYi22uxr4Qpef3DniE Cyc8T9vbs4uAAT/YVVc5uGewWBJmnUeRuj5SL+i8o4AZA/hzQX4t1IEj5PKkEPD7ukgx /rnl+GIC777s4ncIs2HP9MtCGsYpZa7NboJZju19lkKEdIA0d/Y+QYiYIJ/vmhn6/ohd y+9xuvFZdq84glSFNug0gf4aAqRJYJzYai79LmlEJZsrV4XYiO7LCXu3FWApyYJQw5n/ fIEQ== X-Gm-Message-State: AFeK/H3hQiyFrrLUaIzX9w/EIXP/EfsxfR0c4gRcFwRTYNyjtMD0vNQ4oAYIo7VaVwxdxw== X-Received: by 10.25.21.37 with SMTP id l37mr545478lfi.146.1489564204320; Wed, 15 Mar 2017 00:50:04 -0700 (PDT) Received: from tn-desktop.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id u26sm192710ljd.40.2017.03.15.00.50.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Mar 2017 00:50:03 -0700 (PDT) From: Tomasz Nowicki To: helgaas@kernel.org, Lorenzo.Pieralisi@arm.com, robert.richter@caviumnetworks.com, ddaney@caviumnetworks.com, Vadim.Lomovtsev@caviumnetworks.com, rafael@kernel.org Subject: [PATCH 2/2] PCI: Add legacy firmware support for Cavium ThunderX host controller Date: Wed, 15 Mar 2017 08:49:15 +0100 Message-Id: <1489564155-3881-3-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489564155-3881-1-git-send-email-tn@semihalf.com> References: <1489564155-3881-1-git-send-email-tn@semihalf.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170315_005026_789010_DD2FF7D9 X-CRM114-Status: GOOD ( 13.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sunil.Goutham@cavium.com, linux-pci@vger.kernel.org, geethasowjanya.akula@gmail.com, linux-acpi@vger.kernel.org, linu.cherian@cavium.com, Tomasz Nowicki , 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-Virus-Scanned: ClamAV using ClamSMTP During early days of PCI quirks support ThunderX firmware did not provide PNP0c02 node with PCI configuration space and PEM-specific register ranges. This means that for legacy FW we are not reserving these resources and cannot gather PEM-specific resources for further PEM initialization. In order to support already deployed legacy FW calculate PEM-specific ranges and provide resources reservation as fallback scenario into PEM driver when we could not gather PEM reg base from ACPI tables. Signed-off-by: Tomasz Nowicki Signed-off-by: Vadim Lomovtsev Tested-by: Robert Richter Acked-by: Robert Richter --- drivers/pci/host/pci-thunder-pem.c | 56 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/pci/host/pci-thunder-pem.c b/drivers/pci/host/pci-thunder-pem.c index e354010..e0aa194 100644 --- a/drivers/pci/host/pci-thunder-pem.c +++ b/drivers/pci/host/pci-thunder-pem.c @@ -14,6 +14,7 @@ * Copyright (C) 2015 - 2016 Cavium, Inc. */ +#include #include #include #include @@ -319,6 +320,50 @@ static int thunder_pem_init(struct device *dev, struct pci_config_window *cfg, #if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) +#define PEM_RES_BASE 0x87e0c0000000UL +#define PEM_NODE_MASK GENMASK(45, 44) +#define PEM_INDX_MASK GENMASK(26, 24) +#define PEM_MIN_DOM_IN_NODE 4 +#define PEM_MAX_DOM_IN_NODE 10 + +static void thunder_pem_reserve_range(struct device *dev, int seg, + struct resource *r) +{ + resource_size_t start = r->start, end = r->end; + struct resource *res; + const char *regionid; + + regionid = kasprintf(GFP_KERNEL, "PEM RC:%d", seg); + if (!regionid) + return; + + res = request_mem_region(start, end - start + 1, regionid); + if (res) + res->flags &= ~IORESOURCE_BUSY; + else + kfree(regionid); + + dev_info(dev, "%pR %s reserved\n", r, + res ? "has been" : "could not be"); +} + +static void thunder_pem_legacy_fw(struct acpi_pci_root *root, + struct resource *res_pem) +{ + int node = acpi_get_node(root->device->handle); + int index; + + if (node == NUMA_NO_NODE) + node = 0; + + index = root->segment - PEM_MIN_DOM_IN_NODE; + index -= node * PEM_MAX_DOM_IN_NODE; + res_pem->start = PEM_RES_BASE | FIELD_PREP(PEM_NODE_MASK, node) | + FIELD_PREP(PEM_INDX_MASK, index); + res_pem->end = res_pem->start + SZ_16M - 1; + res_pem->flags = IORESOURCE_MEM; +} + static int thunder_pem_acpi_init(struct pci_config_window *cfg) { struct device *dev = cfg->parent; @@ -332,9 +377,16 @@ static int thunder_pem_acpi_init(struct pci_config_window *cfg) return -ENOMEM; ret = acpi_get_rc_resources(dev, "CAVA02B", root->segment, res_pem); + + /* + * If we fail to gather resources it means that we run with old + * FW where we need to calculate PEM-specific resources manually. + */ if (ret) { - dev_err(dev, "can't get rc base address\n"); - return ret; + thunder_pem_legacy_fw(root, res_pem); + /* Reserve PEM specific resources and PCI configuration space */ + thunder_pem_reserve_range(dev, root->segment, res_pem); + thunder_pem_reserve_range(dev, root->segment, &cfg->res); } return thunder_pem_init(dev, cfg, res_pem);