From patchwork Tue Sep 30 18:02:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 5005761 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AC5739F3EC for ; Tue, 30 Sep 2014 18:03:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA23E20166 for ; Tue, 30 Sep 2014 18:03:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7426C20204 for ; Tue, 30 Sep 2014 18:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751967AbaI3SDT (ORCPT ); Tue, 30 Sep 2014 14:03:19 -0400 Received: from mga11.intel.com ([192.55.52.93]:24098 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753918AbaI3SDI (ORCPT ); Tue, 30 Sep 2014 14:03:08 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 30 Sep 2014 11:03:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,628,1406617200"; d="scan'208";a="607702908" Received: from brhill-mobl1.amr.corp.intel.com (HELO thog) ([10.254.110.5]) by fmsmga002.fm.intel.com with ESMTP; 30 Sep 2014 11:02:53 -0700 Received: from willy by thog with local (Exim 4.84) (envelope-from ) id 1XZ1lE-0004zx-8e; Tue, 30 Sep 2014 14:02:52 -0400 Date: Tue, 30 Sep 2014 14:02:52 -0400 From: Matthew Wilcox To: Matthew Wilcox Cc: Martin Mares , linux-pci@vger.kernel.org, Matthew Wilcox Subject: Re: [PATCH] lspci: Add ability to filter by class code Message-ID: <20140930180252.GD5098@wil.cx> References: <1412099436-18899-1-git-send-email-matthew.r.wilcox@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1412099436-18899-1-git-send-email-matthew.r.wilcox@intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Sep 30, 2014 at 01:50:36PM -0400, Matthew Wilcox wrote: Sorry, forgot to update the documentation in two places. Try this patch instead: From b7aa6b8d6006405e954120e29849a9b34e1432ac Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Tue, 30 Sep 2014 13:41:07 -0400 Subject: [PATCH] lspci: Add ability to filter by class code Extend the 'filter by device ID' functionality to allow optional specification of a device ID. For example, to list all USB controllers in the system made by Intel, specify: lspci -d 8086::0c03 Signed-off-by: Matthew Wilcox --- lib/filter.c | 22 +++++++++++++++++++--- lib/pci.h | 2 +- lspci.c | 2 +- lspci.man | 7 ++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/filter.c b/lib/filter.c index f321b0f..fab0025 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -15,7 +15,7 @@ void pci_filter_init(struct pci_access *a UNUSED, struct pci_filter *f) { f->domain = f->bus = f->slot = f->func = -1; - f->vendor = f->device = -1; + f->vendor = f->device = f->class = -1; } /* Slot filter syntax: [[[domain]:][bus]:][slot][.[func]] */ @@ -74,12 +74,12 @@ pci_filter_parse_slot(struct pci_filter *f, char *str) return NULL; } -/* ID filter syntax: [vendor]:[device] */ +/* ID filter syntax: [vendor]:[device][:class] */ char * pci_filter_parse_id(struct pci_filter *f, char *str) { - char *s, *e; + char *s, *c, *e; if (!*str) return NULL; @@ -94,6 +94,9 @@ pci_filter_parse_id(struct pci_filter *f, char *str) return "Invalid vendor ID"; f->vendor = x; } + c = strchr(s, ':'); + if (c) + *c++ = 0; if (s[0] && strcmp(s, "*")) { long int x = strtol(s, &e, 16); @@ -101,6 +104,13 @@ pci_filter_parse_id(struct pci_filter *f, char *str) return "Invalid device ID"; f->device = x; } + if (c && c[0] && strcmp(s, "*")) + { + long int x = strtol(c, &e, 16); + if ((e && *e) || (x < 0 || x > 0xffff)) + return "Invalid class code"; + f->class = x; + } return NULL; } @@ -119,5 +129,11 @@ pci_filter_match(struct pci_filter *f, struct pci_dev *d) (f->vendor >= 0 && f->vendor != d->vendor_id)) return 0; } + if (f->class >= 0) + { + pci_fill_info(d, PCI_FILL_CLASS); + if (f->class != d->device_class) + return 0; + } return 1; } diff --git a/lib/pci.h b/lib/pci.h index 38e2e99..b0bf1aa 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -193,7 +193,7 @@ struct pci_cap *pci_find_cap(struct pci_dev *, unsigned int id, unsigned int typ struct pci_filter { int domain, bus, slot, func; /* -1 = ANY */ - int vendor, device; + int vendor, device, class; }; void pci_filter_init(struct pci_access *, struct pci_filter *) PCI_ABI; diff --git a/lspci.c b/lspci.c index dbba678..372e4de 100644 --- a/lspci.c +++ b/lspci.c @@ -60,7 +60,7 @@ static char help_msg[] = "\n" "Selection of devices:\n" "-s [[[[]:]]:][][.[]]\tShow only devices in selected slots\n" -"-d []:[]\t\t\tShow only devices with specified ID's\n" +"-d []:[][:]\t\tShow only devices with specified ID's\n" "\n" "Other options:\n" "-i \tUse specified ID database instead of %s\n" diff --git a/lspci.man b/lspci.man index 601a48a..2303ab8 100644 --- a/lspci.man +++ b/lspci.man @@ -136,9 +136,10 @@ hexadecimal. E.g., "0:" means all devices on bus 0, "0" means all functions of on any bus, "0.3" selects third function of device 0 on all buses and ".4" shows only the fourth function of each device. .TP -.B -d []:[] -Show only devices with specified vendor and device ID. Both ID's are given in -hexadecimal and may be omitted or given as "*", both meaning "any value". +.B -d []:[][:] +Show only devices with specified vendor, device and class ID. The ID's are +given in hexadecimal and may be omitted or given as "*", both meaning +"any value". .SS Other options .TP