From patchwork Mon Sep 26 18:29:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 675282 X-Patchwork-Delegate: daniel.schwierzeck@googlemail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3sjXbz61pJz9s3T for ; Tue, 27 Sep 2016 04:31:27 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4D08EA7580; Mon, 26 Sep 2016 20:31:09 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 91klaAL-1UKb; Mon, 26 Sep 2016 20:31:08 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6BC11A7577; Mon, 26 Sep 2016 20:31:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 76B1EA7599 for ; Mon, 26 Sep 2016 20:31:05 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BK_-lgiSL3st for ; Mon, 26 Sep 2016 20:31:05 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mailapp01.imgtec.com (mailapp02.imgtec.com [217.156.133.132]) by theia.denx.de (Postfix) with ESMTP id 3371BA7577 for ; Mon, 26 Sep 2016 20:31:03 +0200 (CEST) Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id CC419C390F9A2; Mon, 26 Sep 2016 19:30:58 +0100 (IST) Received: from localhost (10.100.200.111) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 26 Sep 2016 19:31:01 +0100 From: Paul Burton To: , Daniel Schwierzeck Date: Mon, 26 Sep 2016 19:29:00 +0100 Message-ID: <20160926182917.27531-7-paul.burton@imgtec.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20160926182917.27531-1-paul.burton@imgtec.com> References: <20160926182917.27531-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.100.200.111] Subject: [U-Boot] [PATCH 06/23] pci: Set of_offset for devices not probed via DT compatible strings X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" A PCI device may be probed through standard PCI config space probing but still be represented in a device tree. However U-Boot would not previously set the of_offset field of the struct udevice for such PCI devices. Fix this by searching for a DT node based upon its "reg" property after binding a PCI device that wasn't already seen in the DT. Signed-off-by: Paul Burton --- drivers/pci/pci-uclass.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 3b00e6a..415c632 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -670,6 +670,33 @@ error: return ret; } +static int find_pci_of_offset(struct udevice *bus, struct udevice *dev, + pci_dev_t bdf) +{ + struct fdt_pci_addr addr; + int offset, err; + + if (bus->of_offset == -1) + return -ENOENT; + + fdt_for_each_subnode(gd->fdt_blob, offset, bus->of_offset) { + err = fdtdec_get_pci_addr(gd->fdt_blob, offset, + FDT_PCI_SPACE_CONFIG, "reg", &addr); + if (err == -ENOENT) + continue; + if (err) + return err; + + if (bdf != (addr.phys_hi & 0xffff00)) + continue; + + dev->of_offset = offset; + return 0; + } + + return -ENOENT; +} + int pci_bind_bus_devices(struct udevice *bus) { ulong vendor, device; @@ -731,6 +758,11 @@ int pci_bind_bus_devices(struct udevice *bus) } ret = pci_find_and_bind_driver(bus, &find_id, bdf, &dev); + if (!ret) { + ret = find_pci_of_offset(bus, dev, bdf); + if (ret == -ENOENT) + ret = 0; + } } if (ret == -EPERM) continue;