From patchwork Thu Dec 14 13:45:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 848552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cPu18bmf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yyFGT5LPRz9t2f for ; Fri, 15 Dec 2017 00:46:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753018AbdLNNqF (ORCPT ); Thu, 14 Dec 2017 08:46:05 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:44706 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752909AbdLNNqA (ORCPT ); Thu, 14 Dec 2017 08:46:00 -0500 Received: by mail-qt0-f195.google.com with SMTP id m59so7916327qte.11; Thu, 14 Dec 2017 05:46:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jRusb0P9/fhmE0pdN4K1+Rm0IJFiKHhJcqPwzSLb1z8=; b=cPu18bmfbUq53U0CBoKhR/ucCfp4w45a0/5vdtM0Ucr0Us8O8BCj1ZXxKCbxhR8TsC LN/+DhPiVvAUWQNrOOEsGj7FU19OC/KlKzQwfefDYjDZXEy9vg8kndCFLZbkdt4hJjqE qSLgwsib7uHIjriH3lavPDYMX9F6czKUD3kReVPCwiwE2noP6j2NbBATnaKoVw9dJlHq CNu/yAlxrjKmBWNfwh3RyqJPUuelTmkoia29faTt2Nq35Qd72dz0X8pz8yG8iG1Mr3ar t2HSp/xXB3q3hSRYUoUwOZOU4yNMEGZqmNm/RxbnpUQfSLvOjnC2ghuH/eYScCqzHViY aeIQ== 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=jRusb0P9/fhmE0pdN4K1+Rm0IJFiKHhJcqPwzSLb1z8=; b=PmQRQBltg/uf2sCD/hN8d8YPtQGDtf8zgd1Y+r8QgvJXgBNkl9vEbrbICL1X3ih3hI a8emdDhz6kNruh1lsF8fI1/xVvvKC6mgNnggxsligm5603DGi+Cuq5bWPtaHuPlecV94 KUWo4isL9XaWcoHil84xDKazNy4v4AiegJP+dtyIelUj78AjjShiP+Nowbr0cFS6A8Pt +jP2jPphYXOVzRMDw2TW+JKu67En8FwfuzGeyTPnoTusK7xwDc/iS0Wfmgq4W7nJ63Pm WoeWbv76S1JnIg3gtC8Z1lEF98FJjZrAA4u4ujgn7IymA6vEKIsFp+2xuiBE+wQ/Tdii YLcA== X-Gm-Message-State: AKGB3mJ4yLgEElCkUaTobT+8Z6bM1gwqYX96khJVew523xlTuWwrZUpu WaYIZl1rCUOZ0qFJ8src/8c= X-Google-Smtp-Source: ACJfBoug1om0BF6kw2WqwSs9sWRKr/87515beBSxCmz0k3wgYVSF2OS/XRXol02XLwF8xBK/L9buCw== X-Received: by 10.237.54.4 with SMTP id e4mr16496255qtb.67.1513259159750; Thu, 14 Dec 2017 05:45:59 -0800 (PST) Received: from localhost (p200300E41F200F003F65F430A8AE2E44.dip0.t-ipconnect.de. [2003:e4:1f20:f00:3f65:f430:a8ae:2e44]) by smtp.gmail.com with ESMTPSA id b140sm2556885qkc.0.2017.12.14.05.45.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Dec 2017 05:45:59 -0800 (PST) From: Thierry Reding To: Lorenzo Pieralisi , Bjorn Helgaas Cc: Jonathan Hunter , Vidya Saga , Manikanta Maddireddy , linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH 4/4] PCI: tegra: Remove artificial mapping restriction Date: Thu, 14 Dec 2017 14:45:45 +0100 Message-Id: <20171214134545.11143-5-thierry.reding@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171214134545.11143-1-thierry.reding@gmail.com> References: <20171214134545.11143-1-thierry.reding@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Thierry Reding The current code restricts the location of the 4 KiB configuration space mapping region. This is unnecessary if the AFI_FPCI_BAR0 register is used to move the 4 KiB window into the FPCI address map. Doing this will allow all generations of Tegra to be handled in a unified way. Signed-off-by: Thierry Reding --- drivers/pci/host/pci-tegra.c | 46 +++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c index 7f8a81e17db6..2e7bea127120 100644 --- a/drivers/pci/host/pci-tegra.c +++ b/drivers/pci/host/pci-tegra.c @@ -257,7 +257,6 @@ struct tegra_pcie_soc { bool has_gen2; bool force_pca_enable; bool program_uphy; - bool use_4k_conf_space; }; static inline struct tegra_msi *to_tegra_msi(struct msi_controller *chip) @@ -274,7 +273,7 @@ struct tegra_pcie { int irq; struct list_head buses; - struct resource *cs; + struct resource cs; struct resource io; struct resource pio; @@ -418,8 +417,6 @@ static void __iomem *tegra_pcie_map_bus(struct pci_bus *bus, struct pci_host_bridge *host = pci_find_host_bridge(bus); struct tegra_pcie *pcie = pci_host_bridge_priv(host); void __iomem *addr = NULL; - u32 val = 0; - u32 offset = 0; if (bus->number == 0) { unsigned int slot = PCI_SLOT(devfn); @@ -432,11 +429,17 @@ static void __iomem *tegra_pcie_map_bus(struct pci_bus *bus, } } } else { + unsigned int offset; + u32 base; + offset = tegra_pcie_conf_offset(bus->number, devfn, where); + + /* move 4 KiB window to offset within the FPCI region */ + base = 0xfe100000 + ((offset & ~(SZ_4K - 1)) >> 8); + afi_writel(pcie, base, AFI_FPCI_BAR0); + + /* move to correct offset within the 4 KiB page */ addr = pcie->cfg + (offset & (SZ_4K - 1)); - val = offset & ~(SZ_4K - 1); - afi_writel(pcie, pcie->cs->start - val, AFI_AXI_BAR0_START); - afi_writel(pcie, (val + SZ_4K) >> 12, AFI_AXI_BAR0_SZ); } return addr; @@ -689,8 +692,9 @@ static void tegra_pcie_setup_translations(struct tegra_pcie *pcie) u32 fpci_bar, size, axi_address; /* Bar 0: type 1 extended configuration space */ - fpci_bar = 0xfe100000; - afi_writel(pcie, fpci_bar, AFI_FPCI_BAR0); + size = resource_size(&pcie->cs); + afi_writel(pcie, pcie->cs.start, AFI_AXI_BAR0_START); + afi_writel(pcie, size >> 12, AFI_AXI_BAR0_SZ); /* Bar 1: downstream IO bar */ fpci_bar = 0xfdfc0000; @@ -1246,7 +1250,6 @@ static int tegra_pcie_get_resources(struct tegra_pcie *pcie) struct platform_device *pdev = to_platform_device(dev); struct resource *pads, *afi, *res; const struct tegra_pcie_soc *soc = pcie->soc; - u32 axi_addr = 0; int err; err = tegra_pcie_clocks_get(pcie); @@ -1296,18 +1299,14 @@ static int tegra_pcie_get_resources(struct tegra_pcie *pcie) goto poweroff; } - axi_addr = pcie->soc->use_4k_conf_space ? - res->start : res->end - SZ_4K + 1; - pcie->cs = devm_request_mem_region(dev, axi_addr, SZ_4K, res->name); - if (!pcie->cs) { - err = -EADDRNOTAVAIL; - goto poweroff; - } + pcie->cs = *res; - pcie->cfg = devm_ioremap(dev, pcie->cs.start, SZ_4K); - if (!pcie->cfg) { - dev_err(pcie->dev, "failed to ioremap config space\n"); - err = -EADDRNOTAVAIL; + /* constrain configuration space to 4 KiB */ + pcie->cs.end = pcie->cs.start + SZ_4K - 1; + + pcie->cfg = devm_ioremap_resource(dev, &pcie->cs); + if (IS_ERR(pcie->cfg)) { + err = PTR_ERR(pcie->cfg); goto poweroff; } @@ -2120,7 +2119,6 @@ static const struct tegra_pcie_soc tegra20_pcie = { .has_gen2 = false, .force_pca_enable = false, .program_uphy = true, - .use_4k_conf_space = true, }; static const struct tegra_pcie_soc tegra30_pcie = { @@ -2138,7 +2136,6 @@ static const struct tegra_pcie_soc tegra30_pcie = { .has_gen2 = false, .force_pca_enable = false, .program_uphy = true, - .use_4k_conf_space = false, }; static const struct tegra_pcie_soc tegra124_pcie = { @@ -2155,7 +2152,6 @@ static const struct tegra_pcie_soc tegra124_pcie = { .has_gen2 = true, .force_pca_enable = false, .program_uphy = true, - .use_4k_conf_space = false, }; static const struct tegra_pcie_soc tegra210_pcie = { @@ -2172,7 +2168,6 @@ static const struct tegra_pcie_soc tegra210_pcie = { .has_gen2 = true, .force_pca_enable = true, .program_uphy = true, - .use_4k_conf_space = false, }; static const struct tegra_pcie_soc tegra186_pcie = { @@ -2190,7 +2185,6 @@ static const struct tegra_pcie_soc tegra186_pcie = { .has_gen2 = true, .force_pca_enable = false, .program_uphy = false, - .use_4k_conf_space = true, }; static const struct of_device_id tegra_pcie_of_match[] = {