From patchwork Fri Mar 13 11:04:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1254348 X-Patchwork-Delegate: priyanka.jain@nxp.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fIoleORa; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48f2sC42Lzz9sQx for ; Fri, 13 Mar 2020 22:04:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 06EA880592; Fri, 13 Mar 2020 12:04:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fIoleORa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 02D0680E9F; Fri, 13 Mar 2020 12:04:39 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 24195804CD for ; Fri, 13 Mar 2020 12:04:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olteanv@gmail.com Received: by mail-wm1-x344.google.com with SMTP id f7so9795399wml.4 for ; Fri, 13 Mar 2020 04:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=kAV2B6g0xc4rvP68Wuib/Je0SfqgwZ7o1ZQNE+JWcsk=; b=fIoleORaEFLk3/MDdssLpoGeG8EMNnyordkSmC7GeK3Ph97GcUKuUzegQGsa1cGgdA Npp/xiKbUSxtytawsqFDHdtpk3Lsxktm/KhxwXPQYqxMbFwBmoYBexhdHt6Am6uDrock 8LM8Til0jGxNl4hn9m2KS5TYr6+FDLOTuLlGlWxKJcA1hAbbggPXiLrsijZkdGj89C+j C4uettc2K0au6xAFYo9GfpOBbvOwMlMBkyyjXGTzrH1iLeOLfQegnc57QbWEmBmSAy3Q Xd6KLxIDBkn0UcdW/boFg8RjwT2ArBXY0pUfBsvGmOs+d+edAxqsJoa3UnVvb+AapFMD oiOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=kAV2B6g0xc4rvP68Wuib/Je0SfqgwZ7o1ZQNE+JWcsk=; b=NPJ6K3FvfWwUXSYwaojZHE/54C7/gYhT3ZF2Rupk74SDU3RtXOcVLhPWtQX4RSCodb qLgmwK1AyjOt9gWvpgQxM/e8YbKm+qIkCjwn0PwBjlLYsj9Go1RsFN3cZ2wehJLp18BQ AYS73psochLxESOFXpyKlx3kB3PIrlNSvsDJa9NdBXUMvepopHKbcLRxv3m6MsNoBPe2 N+FhQdFJ2AhXT8YYw5BaalGxM2YYwacL+WwoSFkEdbaUZve5KXt81G4UzAcqTAkW525p xaCqZOHv22JQbDV9QOqm1j5XeCwwUfVN6L+gACot2CfzS+5k3pB/AfBVTJeGc4OH8beu pjwg== X-Gm-Message-State: ANhLgQ2R+g6U/uKncpOgbwoVrbf3CDIe4p8pl6MaYPG7Xoeq/58mxrjb 9gmNNIW9xRZ6o9rg8gS45HA= X-Google-Smtp-Source: ADFU+vuxPWPoYVs8I/jg849NQx//18EHoeC5HPzHwnueTh1GvKIKT31IoPuG22XW0JBH3apE2EiTTw== X-Received: by 2002:a7b:cd0e:: with SMTP id f14mr6843112wmj.21.1584097475643; Fri, 13 Mar 2020 04:04:35 -0700 (PDT) Received: from localhost.localdomain ([79.115.60.40]) by smtp.gmail.com with ESMTPSA id g5sm12643984wrr.57.2020.03.13.04.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 04:04:35 -0700 (PDT) From: Vladimir Oltean To: bmeng.cn@gmail.com, sjg@chromium.org, tuomas.tynkkynen@iki.fi, alexandru.marginean@nxp.com, u-boot@lists.denx.de Subject: [PATCH] pci-host-ecam-generic: access config space independent of system-wide bus id Date: Fri, 13 Mar 2020 13:04:25 +0200 Message-Id: <20200313110425.22996-1-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean From: Vladimir Oltean The pci-host-ecam-generic code assumes that the ECAM is the first PCI bus in the system to be probed. Therefore, the system-wide bus number allocated by U-Boot in sequence for it is going to be zero, which corresponds to the memory-mapped config spaces found within it. Reuse the logic from other PCI bus drivers, and assume that U-Boot will allocate bus numbers in sequence for all buses within the current ECAM. So the base number of the bus needs to be subtracted when indexing the correct config space. Fixes: 3675cb044e68 ("PCI: Add driver for a 'pci-host-ecam-generic' host controller") Signed-off-by: Vladimir Oltean Reviewed-by: Alex Marginean --- drivers/pci/pcie_ecam_generic.c | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pcie_ecam_generic.c b/drivers/pci/pcie_ecam_generic.c index 00644edd2646..190919d26a67 100644 --- a/drivers/pci/pcie_ecam_generic.c +++ b/drivers/pci/pcie_ecam_generic.c @@ -19,6 +19,8 @@ */ struct generic_ecam_pcie { void *cfg_base; + pci_size_t size; + int first_busno; }; /** @@ -42,7 +44,7 @@ static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf, void *addr; addr = pcie->cfg_base; - addr += PCI_BUS(bdf) << 20; + addr += (PCI_BUS(bdf) - pcie->first_busno) << 20; addr += PCI_DEV(bdf) << 15; addr += PCI_FUNC(bdf) << 12; addr += offset; @@ -51,6 +53,15 @@ static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf, return 0; } +static bool pci_generic_ecam_addr_valid(struct udevice *bus, pci_dev_t bdf) +{ + struct generic_ecam_pcie *pcie = dev_get_priv(bus); + int num_buses = DIV_ROUND_UP(pcie->size, 1 << 16); + + return (PCI_BUS(bdf) >= pcie->first_busno && + PCI_BUS(bdf) < pcie->first_busno + num_buses); +} + /** * pci_generic_ecam_read_config() - Read from configuration space * @bus: Pointer to the PCI bus @@ -67,6 +78,11 @@ static int pci_generic_ecam_read_config(struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { + if (!pci_generic_ecam_addr_valid(bus, bdf)) { + *valuep = pci_get_ff(size); + return 0; + } + return pci_generic_mmap_read_config(bus, pci_generic_ecam_conf_address, bdf, offset, valuep, size); } @@ -87,6 +103,9 @@ static int pci_generic_ecam_write_config(struct udevice *bus, pci_dev_t bdf, uint offset, ulong value, enum pci_size_t size) { + if (!pci_generic_ecam_addr_valid(bus, bdf)) + return 0; + return pci_generic_mmap_write_config(bus, pci_generic_ecam_conf_address, bdf, offset, value, size); } @@ -115,9 +134,17 @@ static int pci_generic_ecam_ofdata_to_platdata(struct udevice *dev) return err; } - pcie->cfg_base = map_physmem(reg_res.start, - fdt_resource_size(®_res), - MAP_NOCACHE); + pcie->size = fdt_resource_size(®_res); + pcie->cfg_base = map_physmem(reg_res.start, pcie->size, MAP_NOCACHE); + + return 0; +} + +static int pci_generic_ecam_probe(struct udevice *dev) +{ + struct generic_ecam_pcie *pcie = dev_get_priv(dev); + + pcie->first_busno = dev->seq; return 0; } @@ -137,6 +164,7 @@ U_BOOT_DRIVER(pci_generic_ecam) = { .id = UCLASS_PCI, .of_match = pci_generic_ecam_ids, .ops = &pci_generic_ecam_ops, + .probe = pci_generic_ecam_probe, .ofdata_to_platdata = pci_generic_ecam_ofdata_to_platdata, .priv_auto_alloc_size = sizeof(struct generic_ecam_pcie), };