From patchwork Tue Mar 28 19:21:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 9650365 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 E631B601D7 for ; Tue, 28 Mar 2017 19:23:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF55728358 for ; Tue, 28 Mar 2017 19:23:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D396F28405; Tue, 28 Mar 2017 19:23:03 +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 5D6CC28358 for ; Tue, 28 Mar 2017 19:23:03 +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=x3UdgLBhn4V6jtkFP8pm+SvfgW26wbeWe0WZNRcFOhg=; b=JoDyhAYK9AIL7OtkDg/G7/1Eas qM08nFdoBYB8XMO5Km+uLOBQpymbgAnr9Fr3XL2tS4t6f57HlSBW3qlDYT0aWptAPRX89UFnioin3 IZXzZTfid+frr56d+0C7JYyq7HQuWuos9aLmazLojgQBGavgXzM+Y4wpQFDlcU2+cR/KgkufSURyt otVl2mbXas7sOGkRqzSghYy3u13XBreMHCqve5xFTbZacjD/0GfrN++AaPk4WpJTIJ3Lo0mYe4YUA sUefixxR8zmXrxK04FvFlUThMLPoU5wyW5mJd+vL3/V2GRMpbKqym77g2jdumxz2iH2Il58OUyHyl 2n0Qk6qA==; 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 1cswhr-0006nv-0v; Tue, 28 Mar 2017 19:23:03 +0000 Received: from mail-lf0-x229.google.com ([2a00:1450:4010:c07::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cswhm-0006m9-Rw for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2017 19:23:00 +0000 Received: by mail-lf0-x229.google.com with SMTP id x137so43394092lff.3 for ; Tue, 28 Mar 2017 12:22:36 -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=cwys9N0LQ8w9wuplrP3NwVGbzXGWRpFNJ5k9rcJz+e4=; b=WPduedF/7MFf+98drr2f0MeccUSaxZwKYpazKOvC0fCsb2lkWe1/HOKifoGXWjZ9WJ SQwVG8YP/p9AEXE0ApGxNzZhzRnvS3vX1o35R/wS9vQWFcOU3Ud7zrPDvInoyBAQic7g sSdb45jsZSTBdIA1VrmhPa9h+ibO6fHreHqsBXMKTM9ihR9f93nufvsEmEIrPkCICKx7 NM40oPFDWRFf2ghpZlgK0G07U5FdPxFGLUx7MNMxNzAf7sXBzIOKC1WIbBCDuTb7alNf Wb9LgB3HZrxLh/nwhDMQE1jMnJaaVQPH8+hKXQercnxlexESKo5lMKbfB21u/JSO7KQC n4Kw== 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=cwys9N0LQ8w9wuplrP3NwVGbzXGWRpFNJ5k9rcJz+e4=; b=nV3ON6hPQNkO48N6ACGW5FbkJNwJB17P3krScHkUn+7+F+X0ELCm0VXFaDZBwJ9DE1 78rIkHVpRGI7XhhnkKkABuNlwiXyZy7ztui9Z2WCPXOXEyf9XFYML3xD+RLCBGkyuAAQ n9agUSB+ujjFD4zQtpsJgUI2ySdX0UTVGhiAV836zO535nAYeYB6BmTu4L2h9kt/aOY5 beb15d/WBYmGJhYpITEaHS5EWp7+sZxgbk5lgSNPdd7fKDGPZevI19TyLGAVR8e+m1YR QJ0l9zt65e7LA/63YsNOyl0WM6/WKWi97VKNmDPcxhp5+BZQzZzy+yHxjZ0s0DmZqc4c 7WTw== X-Gm-Message-State: AFeK/H1/R/gQ13CL4ePm3hHb5p0txqDg7RfS8FE24Lh6n3LCr2zwf8kLjtuvqE2oJ9iraQ== X-Received: by 10.46.75.2 with SMTP id y2mr2320227lja.103.1490728954994; Tue, 28 Mar 2017 12:22:34 -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 26sm848953ljg.37.2017.03.28.12.22.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Mar 2017 12:22:34 -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: Tue, 28 Mar 2017 21:21:36 +0200 Message-Id: <1490728896-30520-1-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489564155-3881-3-git-send-email-tn@semihalf.com> References: <1489564155-3881-3-git-send-email-tn@semihalf.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170328_122259_142412_5690D931 X-CRM114-Status: GOOD ( 14.84 ) 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 --- drivers/pci/host/pci-thunder-pem.c | 62 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/drivers/pci/host/pci-thunder-pem.c b/drivers/pci/host/pci-thunder-pem.c index e354010..cea5814 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,49 @@ 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->flags = IORESOURCE_MEM; +} + static int thunder_pem_acpi_init(struct pci_config_window *cfg) { struct device *dev = cfg->parent; @@ -332,9 +376,23 @@ 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 64K size PEM specific resources. The full 16M range + * size is required for thunder_pem_init() call. + */ + res_pem->end = res_pem->start + SZ_64K - 1; + thunder_pem_reserve_range(dev, root->segment, res_pem); + res_pem->end = res_pem->start + SZ_16M - 1; + + /* Reserve PCI configuration space as well. */ + thunder_pem_reserve_range(dev, root->segment, &cfg->res); } return thunder_pem_init(dev, cfg, res_pem);