From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BAF64C433F5 for ; Mon, 17 Jan 2022 15:40:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2CF2D837E7; Mon, 17 Jan 2022 16:39:48 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="cFguaspK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DAE2B837C7; Mon, 17 Jan 2022 16:39:35 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C7686837C5 for ; Mon, 17 Jan 2022 16:39:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4395B60FAD; Mon, 17 Jan 2022 15:39:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B69DAC36AE3; Mon, 17 Jan 2022 15:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642433964; bh=tsfz9O6d2z1GxwGIJK8MgkU4jqQCcKZ1zvPygcUJXRk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cFguaspKC7YZy6O8dTPVpFGzsV9U2dhyi6lGHoPUB/Sr2tVlH76pxfBpTn297Bdml N8q4HEyj372W0pdswTM5gQrPsVVzcmglcER7V71tMDUzEKnnaTIDQKYv++TE0xeNxR TCCGsD1r+bZzJGjt8ZWa9icevDCf+W3xMZAewLM72YYDsgruLNbpMnIIVA4AHtcpEJ +BVhPS2Xq1GoXFZigVEjIwgiVIlrcHIuWC3KfFJwGzOs1AepegeR0PcTZCYJDKvbYN AMditElJ5Jh/m2B59sO29IREvHmri7f3x8SlPQc4A+VSZOFiQeuxgjRjwsXB/QTOMb RnLnLnkOj/X9A== Received: by pali.im (Postfix) id 71330871; Mon, 17 Jan 2022 16:39:23 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Bin Meng , Simon Glass , Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= Cc: u-boot@lists.denx.de Subject: [PATCH 4/4] pci: Extend 'pci' command with bus option '*' Date: Mon, 17 Jan 2022 16:38:40 +0100 Message-Id: <20220117153840.31173-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220117153840.31173-1-pali@kernel.org> References: <20220117153840.31173-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.2 at phobos.denx.de X-Virus-Status: Clean Allow to call 'pci' and 'pci regions' commands with bus option '*' which cause pci to process all buses. PCIe is point-to-point HW and so on each bus is maximally one physical device. Therefore for PCIe it is common to have multiple buses. This change allows to easily print all available PCIe devices in system. Make '*' as default option when no bus argument is specified. Signed-off-by: Pali Rohár --- cmd/pci.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/cmd/pci.c b/cmd/pci.c index 8d2c0c4b43dd..4415feb2225b 100644 --- a/cmd/pci.c +++ b/cmd/pci.c @@ -256,10 +256,8 @@ static void pci_header_show(struct udevice *dev) } } -static void pciinfo_header(int busnum, bool short_listing) +static void pciinfo_header(bool short_listing) { - printf("Scanning PCI devices on bus %d\n", busnum); - if (short_listing) { printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n"); printf("_____________________________________________________________\n"); @@ -288,11 +286,15 @@ static void pci_header_show_brief(struct udevice *dev) pci_class_str(class), subclass); } -static void pciinfo(struct udevice *bus, bool short_listing) +static void pciinfo(struct udevice *bus, bool short_listing, bool multi) { struct udevice *dev; - pciinfo_header(dev_seq(bus), short_listing); + if (!multi) + printf("Scanning PCI devices on bus %d\n", dev_seq(bus)); + + if (!multi || dev_seq(bus) == 0) + pciinfo_header(short_listing); for (device_find_first_child(bus, &dev); dev; @@ -483,10 +485,11 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) ulong addr = 0, value = 0, cmd_size = 0; enum pci_size_t size = PCI_SIZE_32; struct udevice *dev, *bus; - int busnum = 0; + int busnum = -1; pci_dev_t bdf = 0; char cmd = 's'; int ret = 0; + char *endp; if (argc > 1) cmd = argv[1][0]; @@ -522,7 +525,11 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) argc--; } if (argc > 2 || (argc > 1 && cmd != 'r' && argv[1][0] != 's')) { - busnum = hextoul(argv[argc - 1], NULL); + if (argv[argc - 1][0] != '*') { + busnum = hextoul(argv[argc - 1], &endp); + if (*endp) + goto usage; + } argc--; } if (cmd == 'r' && argc > 2) @@ -530,6 +537,24 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) else if (cmd != 'r' && (argc > 2 || (argc == 2 && argv[1][0] != 's'))) goto usage; } + if (busnum == -1) { + if (cmd != 'r') { + for (busnum = 0; + uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0; + busnum++) + pciinfo(bus, value, true); + } else { + for (busnum = 0; + uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0; + busnum++) { + /* Regions are controller specific so skip non-root buses */ + if (device_is_on_pci_bus(bus)) + continue; + pci_show_regions(bus); + } + } + return 0; + } ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus); if (ret) { printf("No such bus\n"); @@ -538,7 +563,7 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (cmd == 'r') pci_show_regions(bus); else - pciinfo(bus, value); + pciinfo(bus, value, false); return 0; } @@ -585,7 +610,7 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) #ifdef CONFIG_SYS_LONGHELP static char pci_help_text[] = - "[bus] [long]\n" + "[bus|*] [long]\n" " - short or long list of PCI devices on bus 'bus'\n" "pci enum\n" " - Enumerate PCI buses\n" @@ -593,7 +618,7 @@ static char pci_help_text[] = " - show header of PCI device 'bus.device.function'\n" "pci bar b.d.f\n" " - show BARs base and size for device b.d.f'\n" - "pci regions [bus]\n" + "pci regions [bus|*]\n" " - show PCI regions\n" "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n" " - display PCI configuration space (CFG)\n" -- 2.20.1