Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2617915imm; Thu, 9 Aug 2018 16:49:41 -0700 (PDT) X-Google-Smtp-Source: AA+uWPy/hQT9RNza6uo59LskClhFzNlJPv7T32fnrAErIwEw4XZwjd0Zt+72gjdPfGQcU735mnPr X-Received: by 2002:a62:e00a:: with SMTP id f10-v6mr4471078pfh.208.1533858581312; Thu, 09 Aug 2018 16:49:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533858581; cv=none; d=google.com; s=arc-20160816; b=x/dlYKyJuKzn3f0BzmLGt8Ktzb9qBMnirCtEQSrYp/98Ardy88prWhkTR922W789v4 9e5PkDe5uQoo3VUBUeCg2jAeRIMjjRHea5AQ+Cm/R+Hkn+7RMXys9V//+b612oeJylxW 9QxxhLIDC88O/cVIRzGpvbYLeLfcFveVnfK6K1etLXry91pWEB1kEOVRHZvrg6xE5zsz vjAwBFHYbYGWugnbn4JbcyURL2yf2Ka43E9Sx+xlYRGvHK9BcTgC5c0RFLGsSWNMFZab rVyCUGtHIm0+traDf8sd7jpM9i41Lbe166NM69OB3VYuM8MGJXQgs6W5IHmLeKGYcKlB VtZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=LVUaWYcaApGxJChngQDSBJ2QAeg0uBEbOZnrUDNIV5c=; b=prUYEiBr3A8TikXb+48y6bGZl/waUEO9Oh8BJj6ycOqSUcxn/pOAiLDfMqoX0fxezv UMfTtlZt/ZIfcqwvKuchDAUyjuI/dw/0ENsAmDlQL8hW0t2+2BzVWQqDzJhErhM+IyA7 WxljxQQS9mXc4Y+8GFX4sQLKxdpIsAFW28B8cCKPoFtHAWNB5WSPxFRkpWaAgscKDtu8 TDCEUR+P82cKouJArSe2xVXvxU4RzrPC/uDAbYgZ9xLPKYfULvSy5Jt0ZXM0d54IBr55 ZQqiLIpAd2dmhB3HDnJP3IN31mJjor20Vhr4qJovHz8DFwF8YOaMPHljXhG7/6wW9Akk dqVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=psmA6d5I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r29-v6si8060371pff.24.2018.08.09.16.49.25; Thu, 09 Aug 2018 16:49:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=psmA6d5I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbeHJCPs (ORCPT + 99 others); Thu, 9 Aug 2018 22:15:48 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35946 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727218AbeHJCPs (ORCPT ); Thu, 9 Aug 2018 22:15:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LVUaWYcaApGxJChngQDSBJ2QAeg0uBEbOZnrUDNIV5c=; b=psmA6d5IpGA66ieHl59agLqP2 XM2yv454x4EEvbVlBTbNubuS3T76yZXkTJstxnRgJssKjQK4F4R5y1qUJLAp7dAyD2aMqCgDLZY3H CajLfAghFnvZ1RKdhiE7Hm6SeKBlDeND7guZurvTHqoP8fLGkzjXK/Th29lxrIJBkiqLXD91LAvWU bsEotbbFDg5r4X7sb2W9EiCQkH0c9Jy8GQfUYTeH867yb6fAoDal6KqRI6zBTDOhMSn122QOXJCc2 YFfReblygu3l3HkqocXM1IV1xNMg4F29bTdRJhBw11ynUlHlAUY2XPeSUyh/RvmMkrj4PGrwODJyk Tql21riFA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fnufO-0008Qw-CE; Thu, 09 Aug 2018 23:48:30 +0000 Date: Thu, 9 Aug 2018 16:48:30 -0700 From: Matthew Wilcox To: Martin Mares , Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-doc@vger.kernel.org, Stephen Bates , Christoph Hellwig , Bjorn Helgaas , Jonathan Corbet , Ingo Molnar , Thomas Gleixner , "Paul E. McKenney" , Marc Zyngier , Kai-Heng Feng , Frederic Weisbecker , Dan Williams , =?iso-8859-1?B?Suly9G1l?= Glisse , Benjamin Herrenschmidt , Alex Williamson , Christian =?iso-8859-1?Q?K=F6nig?= Subject: Re: lspci: Display path to device Message-ID: <20180809234830.GA30835@bombadil.infradead.org> References: <20180717170204.30470-1-logang@deltatee.com> <20180717203900.GA1771@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180717203900.GA1771@bombadil.infradead.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Martin? Bjorn's looking to merge this soon and it'd be nice to have the support in lspci too. On Tue, Jul 17, 2018 at 01:39:00PM -0700, Matthew Wilcox wrote: > On Tue, Jul 17, 2018 at 11:02:00AM -0600, Logan Gunthorpe wrote: > > The second patch expands the new helper to optionally take a path of > > PCI devfns. This is to address Alex's renumbering concern when using > > simple bus-devfns. The implementation is essentially how he described it and > > similar to the Intel VT-d spec (Section 8.3.1). > > I don't like telling the user to grovel around lspci -t by hand. It's > not many lines of code to add a new -P option to lspci to show the path > to each device instead of bus:dev.fn > > Here's three examples, first without, then with -P. > > (my laptop): > 6d:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM961/PM961 > 00:1d.0/00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM961/PM961 > > (tests/PCI-X-bridges-and-domains): > 0002:42:00.0 Ethernet controller: Trident Microsystems 4DWave DX (rev 26) > 0002:00:02.4/01.0/00.0 Ethernet controller: Trident Microsystems 4DWave DX (rev 26) > > (my Nehalem system): > 04:00.0 Serial Attached SCSI controller: LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon] (rev 02) > 00:03.0/00.0/00.0/00.0 Serial Attached SCSI controller: LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon] (rev 02) > > The Nehalem system makes an interesting testcase because it exposes some > registers in fake PCIe devices that aren't behind the root ports. eg: > > ff:06.3 Host bridge: Intel Corporation Xeon 5500/Core i7 Integrated Memory Controller Channel 2 Thermal Control Registers (rev 04) > > Martin, what do you think to this patch? Also, I'm happy to send you > the lspci -xxxx from the Nehalem system to add to tests/ > > diff --git a/lspci.c b/lspci.c > index 3bf1925..ae0fdd2 100644 > --- a/lspci.c > +++ b/lspci.c > @@ -19,6 +19,7 @@ int verbose; /* Show detailed information */ > static int opt_hex; /* Show contents of config space as hexadecimal numbers */ > struct pci_filter filter; /* Device filter */ > static int opt_tree; /* Show bus tree */ > +static int opt_path; /* Show bridge path */ > static int opt_machine; /* Generate machine-readable output */ > static int opt_map_mode; /* Bus mapping mode enabled */ > static int opt_domains; /* Show domain numbers (0=disabled, 1=auto-detected, 2=requested) */ > @@ -29,7 +30,7 @@ char *opt_pcimap; /* Override path to Linux modules.pcimap */ > > const char program_name[] = "lspci"; > > -static char options[] = "nvbxs:d:ti:mgp:qkMDQ" GENERIC_OPTIONS ; > +static char options[] = "nvbxs:d:tPi:mgp:qkMDQ" GENERIC_OPTIONS ; > > static char help_msg[] = > "Usage: lspci []\n" > @@ -247,6 +248,34 @@ sort_them(void) > > /*** Normal output ***/ > > +static void > +show_slot_path(struct pci_dev *p) > +{ > + struct pci_dev *d = NULL; > + > + if (opt_path && p->bus) > + { > + for (d = p->access->devices; d; d = d->next) { > + if (d->hdrtype == -1) > + d->hdrtype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f; > + if (d->hdrtype != PCI_HEADER_TYPE_BRIDGE && > + d->hdrtype != PCI_HEADER_TYPE_CARDBUS) > + continue; > + if (pci_read_byte(d, PCI_SECONDARY_BUS) > p->bus) > + continue; > + if (pci_read_byte(d, PCI_SUBORDINATE_BUS) < p->bus) > + continue; > + show_slot_path(d); > + break; > + } > + } > + > + if (d) > + printf("/%02x.%d", p->dev, p->func); > + else > + printf("%02x:%02x.%d", p->bus, p->dev, p->func); > +} > + > static void > show_slot_name(struct device *d) > { > @@ -254,7 +283,7 @@ show_slot_name(struct device *d) > > if (!opt_machine ? opt_domains : (p->domain || opt_domains >= 2)) > printf("%04x:", p->domain); > - printf("%02x:%02x.%d", p->bus, p->dev, p->func); > + show_slot_path(p); > } > > void > @@ -989,6 +1018,9 @@ main(int argc, char **argv) > case 'x': > opt_hex++; > break; > + case 'P': > + opt_path++; > + break; > case 't': > opt_tree++; > break; > diff --git a/lspci.man b/lspci.man > index 35b3620..565dd5b 100644 > --- a/lspci.man > +++ b/lspci.man > @@ -95,6 +95,9 @@ PCI bus instead of as seen by the kernel. > .B -D > Always show PCI domain numbers. By default, lspci suppresses them on machines which > have only domain 0. > +.TP > +.B -P > +Name PCI devices by path through each bridge, instead of by bus number. > > .SS Options to control resolving ID's to names > .TP > -- > To unsubscribe from this list: send the line "unsubscribe linux-doc" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html