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: 9650363 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 E85FB601D7 for ; Tue, 28 Mar 2017 19:22:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E175028358 for ; Tue, 28 Mar 2017 19:22:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D538728405; Tue, 28 Mar 2017 19:22:40 +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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 5D65D283C9 for ; Tue, 28 Mar 2017 19:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755171AbdC1TWi (ORCPT ); Tue, 28 Mar 2017 15:22:38 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:33660 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753263AbdC1TWh (ORCPT ); Tue, 28 Mar 2017 15:22:37 -0400 Received: by mail-lf0-f44.google.com with SMTP id h125so43344494lfe.0 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=U8CzEng6ecLBEfSUXGqoV3KIXVYig2cN2JOOf0NTIC0/8l1Vi6QSfV2fdsVkfDv02/ M6CcmJXqe41s/sV+8+t6Lwgp8mRKXqsLTIhTng88a7L4p+dpf0uTQfMW4I4k8YIK6cun Tk/GBG5QcMMTa+jkUiXNf2K4oiFMcE/+l29HrIHEqK+t0Yzzyb5VeOdyh5QTlkN61mxc 9awBjBYFHp/mobuLNY/VCYzC4mRblSxqSXW9gd4zGdFEJw5QyMLzQ0CpCZqZa+Tw1+Cd 5yqTUefJ4PLytEiCpYb1tyNi9kCl7W6mAWS6V4WZH1hkxcI5kOpqIIWuPZRkCx+ouk+8 mvVQ== X-Gm-Message-State: AFeK/H2O4QW6AfahTbYXe9aZUybt0tegUu8LZxuxcXCP2suGG+iJ5YxjmhyABk8phJ7wlw== 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 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: 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> 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 --- 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);