From patchwork Thu Aug 13 02:09:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 506810 X-Patchwork-Delegate: sjg@chromium.org 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 DC5C41401B5 for ; Thu, 13 Aug 2015 12:10:25 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=CIKf6ivY; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3AB0C4B663; Thu, 13 Aug 2015 04:10:21 +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 E0Iuq_d2lDDc; Thu, 13 Aug 2015 04:10:21 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 35AED4B67B; Thu, 13 Aug 2015 04:10:14 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B63534B663 for ; Thu, 13 Aug 2015 04:10:10 +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 V8ENsGlHKQQ2 for ; Thu, 13 Aug 2015 04:10:10 +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 mail-io0-f171.google.com (mail-io0-f171.google.com [209.85.223.171]) by theia.denx.de (Postfix) with ESMTPS id 502A34B65D for ; Thu, 13 Aug 2015 04:10:06 +0200 (CEST) Received: by iodb91 with SMTP id b91so38750278iod.1 for ; Wed, 12 Aug 2015 19:10:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=cIHb6jl8i9xwAMdmtmcmXYj7zY5hCV8rHHUwzfKEZJs=; b=CIKf6ivYAx+Qd4Hs8cZ6tCwP3B/9sXwg9qwDZ+4i1IEJPRThlLWnJxJQQqgdDSJ6GP 6pxXe79qFaWC8M/qGSISdBaeeBjVQ2mdtnGJGMOhlIKcJi14JBPwn1GOuUnCAQg2PCJq ynYepOt5CD7xldxoakbHQebqKNllpZloTdqkKKSAfF02bsYrcYuCC5t6EzqY7RJ6XGuR DyiIeuT69jNojpn4/22D7YiwXKpCJEacPpYgi1Rh5kTrWsHDkCU11cbhygupJ6UEPXiu nC1Il5z9nJlihQ0SzDTBW4oNFsbV8WJGgiDWw8eAIvsNdKcLxcM/J9Alwg8rQYNEeWfO 5SsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=cIHb6jl8i9xwAMdmtmcmXYj7zY5hCV8rHHUwzfKEZJs=; b=buesDTkDHeWDAbuuYsg77uTBo6raQMd9IJ94odyg1R29AyewbFIrb+xk2r1Yw5r32Y /XxCXEVwq2m4ZSXK6juTk/1u+IYC30eppUzYRDjqdL742DxGiQOQVXYKahQxEj7Vf43x PqBtQVYgOhFZLJsru3NGoDq0c1908uTgI1Cl04bYCmiI4HDrS9B5bwu6GiXzrKcHHD54 0rLZ/7PU/QEcecdDt5WtA2sjOC9lwbaDBB/DH9C0RQPI82XTpeUKt68FdAlxvg38uKOH r6EI8SIpPu0JiQMQaQLlcAmTnpOYbV+sjvA9Dc5L3p/0/r87nHTgEWQUBsaMWyPZmkHY AaAQ== X-Gm-Message-State: ALoCoQnO/sY9Y9lR/5cO4rfSHZaHzWr9VLyl+0bVHucUC/X8hwQXdNLxlkQYTyXPi7/511RGIUd3 X-Received: by 10.107.38.68 with SMTP id m65mr34326786iom.135.1439431805445; Wed, 12 Aug 2015 19:10:05 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by smtp.gmail.com with ESMTPSA id pl8sm563721igb.8.2015.08.12.19.10.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Aug 2015 19:10:04 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 3CD2F220E3B; Wed, 12 Aug 2015 20:10:03 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 12 Aug 2015 20:09:32 -0600 Message-Id: <1439431779-16857-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.5.0.276.gf5e568e In-Reply-To: <1439431779-16857-1-git-send-email-sjg@chromium.org> References: <1439431779-16857-1-git-send-email-sjg@chromium.org> Cc: Tom Rini , Joe Hershberger , Andrew Bradford Subject: [U-Boot] [PATCH 03/10] dm: pci: Allow a PCI bus to be found without an alias 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At present, until a PCI bus is probed, it cannot be found by its sequence number unless it has an alias. This is the same with any device. However with PCI this is more annoying than usual, since bus 0 is always the same device. Add a function that tries a little harder to locate PCI bus 0. This means that PCI enumeration will happen automatically on the first access. Signed-off-by: Simon Glass --- drivers/pci/pci-uclass.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 7d41d56..a72e297 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -17,6 +17,22 @@ DECLARE_GLOBAL_DATA_PTR; +static int pci_get_bus(int busnum, struct udevice **busp) +{ + int ret; + + ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, busp); + + /* Since buses may not be numbered yet, try a little harder with bus 0*/ + if (ret == -ENODEV && !busnum) { + ret = uclass_first_device(UCLASS_PCI, busp); + if (!ret && (*busp)->seq != busnum) + return -ENODEV; + } + + return ret; +} + struct pci_controller *pci_bus_to_hose(int busnum) { struct udevice *bus; @@ -125,7 +141,7 @@ int pci_bus_find_bdf(pci_dev_t bdf, struct udevice **devp) struct udevice *bus; int ret; - ret = uclass_get_device_by_seq(UCLASS_PCI, PCI_BUS(bdf), &bus); + ret = pci_get_bus(PCI_BUS(bdf), &bus); if (ret) return ret; return pci_bus_find_devfn(bus, PCI_MASK_BUS(bdf), devp); @@ -203,7 +219,7 @@ int pci_write_config(pci_dev_t bdf, int offset, unsigned long value, struct udevice *bus; int ret; - ret = uclass_get_device_by_seq(UCLASS_PCI, PCI_BUS(bdf), &bus); + ret = pci_get_bus(PCI_BUS(bdf), &bus); if (ret) return ret; @@ -268,7 +284,7 @@ int pci_read_config(pci_dev_t bdf, int offset, unsigned long *valuep, struct udevice *bus; int ret; - ret = uclass_get_device_by_seq(UCLASS_PCI, PCI_BUS(bdf), &bus); + ret = pci_get_bus(PCI_BUS(bdf), &bus); if (ret) return ret;