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: 9625009 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 7414B60424 for ; Wed, 15 Mar 2017 07:50:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 662FB285F0 for ; Wed, 15 Mar 2017 07:50:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AB86285FB; Wed, 15 Mar 2017 07:50:25 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham 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 C7DB1285F0 for ; Wed, 15 Mar 2017 07:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751145AbdCOHuT (ORCPT ); Wed, 15 Mar 2017 03:50:19 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:34960 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdCOHuG (ORCPT ); Wed, 15 Mar 2017 03:50:06 -0400 Received: by mail-lf0-f44.google.com with SMTP id j90so3366206lfk.2 for ; Wed, 15 Mar 2017 00:50:05 -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=MAgFniUrS+JmzI580uctsC5gq5Oui//qdCWzdqGjsolqwbB6XJM6pVC4fNl75OmENV f4p/2X3ZLQla4b9sPsHnpHwl0ptEn0h7V40hkny0soJNe5z6TQpxOs8NQWaX4314DJga i2yznHd9DzOgK0Aue9DPzF6kGmclB8bjd9wqqJyYRPQTKuIiOvbry/5A9Js6wW6KdAEk QDb2PE/8ck75kglzVq8/C5zDsJ1d1WscLp2Vpsa4ZaRI1voSOVrWit1wvkuMoVrAZ6QO KZ08hA3sr11OXKeY20dz8gOpHJdG2vxaMbH6Fli/33u+ApVwBYMeer33w3gbRo3BAu0V HBNw== X-Gm-Message-State: AFeK/H13CTlPk+Z3ktwY6LHYpUpqsAwYDuflFPQ13ez6owDlGlFAhRf7RY4yMHKoErt66w== 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 Cc: Sunil.Goutham@cavium.com, geethasowjanya.akula@gmail.com, linu.cherian@cavium.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, Tomasz Nowicki 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> 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 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);