From patchwork Fri Jan 21 13:57:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1582578 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=U+L0Gxkw; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4JgLZ1414pz9t2p for ; Sat, 22 Jan 2022 00:58:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350745AbiAUN6P (ORCPT ); Fri, 21 Jan 2022 08:58:15 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:48318 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350794AbiAUN6P (ORCPT ); Fri, 21 Jan 2022 08:58:15 -0500 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 8D30D6175E for ; Fri, 21 Jan 2022 13:58:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD476C340E4; Fri, 21 Jan 2022 13:58:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773494; bh=tZD9Kt2oqV3x+ucieG7rcKrQel3qU6fgABWWF2uxhjk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U+L0GxkwuwxF5tE0jXIbkU3q782FODZ46dpAZtjQ0rw0UGChJhPlJzilwaygZvUpK sIn9yw6w6HQasjc/FI4rS6IiGcfSy4YXdQMijPgPLtzeFWHAQu5M/FYK1hMWCSBTxW RD2tM5MZYhDhMLHvo1nv0YZClxHNzyXITKSaeTJGMjrjJxkRVb25K0I2Pi09t9xYWR an+nHrn0tcrktuhTs8zJWYkwKkClp8Ty8+0ykTv1i/xZfbiytPonof93DAbyyqC39N jqimYLvk1MXunO44lkNt6+9Az5luPUCLblWhnwwUTM0JRHR0kRUJWgMCXfhI59S24A VFw1CV6I+XFQQ== Received: by pali.im (Postfix) id A203FB8A; Fri, 21 Jan 2022 14:58:11 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Martin Mares , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Matthew Wilcox , linux-pci@vger.kernel.org Subject: [PATCH pciutils 1/5] libpci: Add new options for pci_fill_info: PROGIF, REVID and SUBSYS Date: Fri, 21 Jan 2022 14:57:14 +0100 Message-Id: <20220121135718.27172-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121135718.27172-1-pali@kernel.org> References: <20220121135718.27172-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This change extends libpci library and allows providers to fill these informations (Programming interface, Revision id and Subsystem ids) via native system APIs, which sometimes may differs from what is stored in PCI config space. Programming interface is part of 24-bit Device Class number but apparently libpci exports only high 16-bit of this number via device_class member. --- lib/pci.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/pci.h b/lib/pci.h index b9fd9bfb9b5b..8c3c11b9ebeb 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -145,6 +145,9 @@ struct pci_dev { pciaddr_t bridge_base_addr[4]; /* Bridge base addresses (without flags) */ pciaddr_t bridge_size[4]; /* Bridge sizes */ pciaddr_t bridge_flags[4]; /* PCI_IORESOURCE_* flags for bridge addresses */ + u8 prog_if; /* Programming interface for device_class */ + u8 rev_id; /* Revision id */ + u16 subsys_vendor_id, subsys_id; /* Subsystem vendor id and subsystem id */ /* Fields used internally */ struct pci_access *access; @@ -210,6 +213,9 @@ char *pci_get_string_property(struct pci_dev *d, u32 prop) PCI_ABI; #define PCI_FILL_IOMMU_GROUP 0x4000 #define PCI_FILL_BRIDGE_BASES 0x8000 #define PCI_FILL_RESCAN 0x00010000 +#define PCI_FILL_PROGIF 0x00020000 +#define PCI_FILL_REVID 0x00040000 +#define PCI_FILL_SUBSYS 0x00080000 void pci_setup_cache(struct pci_dev *, u8 *cache, int len) PCI_ABI; From patchwork Fri Jan 21 13:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1582583 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=B3qCtUOR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4JgLZ33GfTz9t3b for ; Sat, 22 Jan 2022 00:58:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380779AbiAUN6S (ORCPT ); Fri, 21 Jan 2022 08:58:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380770AbiAUN6S (ORCPT ); Fri, 21 Jan 2022 08:58:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDFDBC061574 for ; Fri, 21 Jan 2022 05:58:17 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 9A6DDB81FC5 for ; Fri, 21 Jan 2022 13:58:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31278C340E3; Fri, 21 Jan 2022 13:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773495; bh=BzA91MyN+EGBFQfWvrsnhbePTPNuL0lesT/LXWw9F1A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=B3qCtUORrhv95udgbKRY8xvy9ffMEEmcYQ7PAK6VwpjuASc6EeBRUc045+wBCJBs8 PmXqiW76caI5JYkH78//ihmyfiZVdrMh1itZKBnD3QLz8t+lFvfhnoRkv+pYkhhIBR 7cxKyJTiZmEYSV61pGRPBi0Z485wgIPSDfCqpqnRovClui/A2ZUzqAixK4cLaVQUsO zuibFlr1bd6vM9ugdbHfqz2gbfXgtd5xugaB89PV9b9PlCHwaYxRzixVUDpRqqITLt e0HQ9M3Mm3Tre/83bOvo5DiztipnLmkSz4m++mnybY9T4m01AKrXcLzHcvg9YlG17v ViQAUYRlddb9g== Received: by pali.im (Postfix) id C9CADC83; Fri, 21 Jan 2022 14:58:12 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Martin Mares , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Matthew Wilcox , linux-pci@vger.kernel.org Subject: [PATCH pciutils 2/5] libpci: generic: Implement PROGIF, REVID and SUBSYS support Date: Fri, 21 Jan 2022 14:57:15 +0100 Message-Id: <20220121135718.27172-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121135718.27172-1-pali@kernel.org> References: <20220121135718.27172-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org PCI_FILL_SUBSYS is implemented only for PCI_HEADER_TYPE_NORMAL and PCI_HEADER_TYPE_CARDBUS like in lspci. --- lib/generic.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/generic.c b/lib/generic.c index ef9e2a34b4f4..f4b6918cb55b 100644 --- a/lib/generic.c +++ b/lib/generic.c @@ -80,7 +80,7 @@ pci_generic_fill_info(struct pci_dev *d, unsigned int flags) struct pci_access *a = d->access; unsigned int done = 0; - if ((flags & (PCI_FILL_BASES | PCI_FILL_ROM_BASE)) && d->hdrtype < 0) + if ((flags & (PCI_FILL_SUBSYS | PCI_FILL_BASES | PCI_FILL_ROM_BASE)) && d->hdrtype < 0) d->hdrtype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f; if (flags & PCI_FILL_IDENT) @@ -96,6 +96,35 @@ pci_generic_fill_info(struct pci_dev *d, unsigned int flags) done |= PCI_FILL_CLASS; } + if (flags & PCI_FILL_PROGIF) + { + d->prog_if = pci_read_byte(d, PCI_CLASS_PROG); + done |= PCI_FILL_PROGIF; + } + + if (flags & PCI_FILL_REVID) + { + d->rev_id = pci_read_byte(d, PCI_REVISION_ID); + done |= PCI_FILL_REVID; + } + + if (flags & PCI_FILL_SUBSYS) + { + switch (d->hdrtype) + { + case PCI_HEADER_TYPE_NORMAL: + d->subsys_vendor_id = pci_read_word(d, PCI_SUBSYSTEM_VENDOR_ID); + d->subsys_id = pci_read_word(d, PCI_SUBSYSTEM_ID); + done |= PCI_FILL_SUBSYS; + break; + case PCI_HEADER_TYPE_CARDBUS: + d->subsys_vendor_id = pci_read_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID); + d->subsys_id = pci_read_word(d, PCI_CB_SUBSYSTEM_ID); + done |= PCI_FILL_SUBSYS; + break; + } + } + if (flags & PCI_FILL_IRQ) { d->irq = pci_read_byte(d, PCI_INTERRUPT_LINE); From patchwork Fri Jan 21 13:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1582579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=MsoZbRtc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4JgLZ16lCcz9t3b for ; Sat, 22 Jan 2022 00:58:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380762AbiAUN6R (ORCPT ); Fri, 21 Jan 2022 08:58:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350790AbiAUN6P (ORCPT ); Fri, 21 Jan 2022 08:58:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F662C061574 for ; Fri, 21 Jan 2022 05:58:15 -0800 (PST) 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 F1BB061768 for ; Fri, 21 Jan 2022 13:58:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F9D6C340E9; Fri, 21 Jan 2022 13:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773494; bh=drIeb53okjVD8/6YcT79Iyn0qNZaI0YaMxW/nQREYGw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MsoZbRtcYOJh81plZuwP7vglamXIsFBJUJWxMXvB70X2IvVJNuWndRiyLvcsbSQ0S MsAw4sKH71wLhQ2DMLzQ18SI2T/I6oVwZAeQDjqqxAAIrdD7Cn5aJJLXVGKNXqCZCa PILsCrLAcJYoOFKVCA+tzJDbcDxL2ormNef98ksA39dbR2jdeV3rP8zNxrnQ54m/nP JvPAtHVj47VOWH0aGAijIEA/FB8CFErKhlAtBYTD4Xb7P0r2X9fGSKODaqpbx5swZ8 EahgZ2TMaRlmULI8g0Z2ryhj2fCksN03topZD84Dx9CVi/RW1onZdmBYYoc15SG/nn DQqbs0JOSD6EQ== Received: by pali.im (Postfix) id ED2F4857; Fri, 21 Jan 2022 14:58:13 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Martin Mares , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Matthew Wilcox , linux-pci@vger.kernel.org Subject: [PATCH pciutils 3/5] libpci: generic: Implement SUBSYS also for PCI_HEADER_TYPE_BRIDGE Date: Fri, 21 Jan 2022 14:57:16 +0100 Message-Id: <20220121135718.27172-4-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121135718.27172-1-pali@kernel.org> References: <20220121135718.27172-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Subsystem ids for PCI Bridges are stored in extended capability PCI_CAP_ID_SSVID. --- lib/generic.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/generic.c b/lib/generic.c index f4b6918cb55b..2cdb7956754c 100644 --- a/lib/generic.c +++ b/lib/generic.c @@ -117,6 +117,30 @@ pci_generic_fill_info(struct pci_dev *d, unsigned int flags) d->subsys_id = pci_read_word(d, PCI_SUBSYSTEM_ID); done |= PCI_FILL_SUBSYS; break; + case PCI_HEADER_TYPE_BRIDGE: + if (pci_read_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST) + { + byte been_there[256]; + int where, id; + + memset(been_there, 0, 256); + where = pci_read_byte(d, PCI_CAPABILITY_LIST) & ~3; + while (where && !been_there[where]++) + { + id = pci_read_byte(d, where + PCI_CAP_LIST_ID); + if (id == PCI_CAP_ID_SSVID) + { + d->subsys_vendor_id = pci_read_word(d, where + PCI_SSVID_VENDOR); + d->subsys_id = pci_read_word(d, where + PCI_SSVID_DEVICE); + done |= PCI_FILL_SUBSYS; + break; + } + if (id == 0xff) + break; + where = pci_read_byte(d, where + PCI_CAP_LIST_NEXT) & ~3; + } + } + break; case PCI_HEADER_TYPE_CARDBUS: d->subsys_vendor_id = pci_read_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID); d->subsys_id = pci_read_word(d, PCI_CB_SUBSYSTEM_ID); From patchwork Fri Jan 21 13:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1582580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=A1NmU4mW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4JgLZ22HVrz9t56 for ; Sat, 22 Jan 2022 00:58:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350790AbiAUN6R (ORCPT ); Fri, 21 Jan 2022 08:58:17 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:48358 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350794AbiAUN6Q (ORCPT ); Fri, 21 Jan 2022 08:58:16 -0500 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 1970661774 for ; Fri, 21 Jan 2022 13:58:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FB0DC340E4; Fri, 21 Jan 2022 13:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773495; bh=ZGC6gqtt42W9gw5ryIcyecAu6nsWPJd2lgiaehTcKHM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=A1NmU4mWjTGKQoOFY/evGRivOnRh+F7D4MNhqPxZR7Hu64NzD0TfGlRjXl8kt+97O N8EQdljiL/Y/KqNfn5k9faAh/Vvi8GFA5YoiSQy1cFOWl52FcvRkJd3J/O9ADGN3vU wRzMB2Y2eYSwEGeeZY0UQUwaPfghuwaMBjZE4nuvVlZNmxviuDlWeyXq7KO0daZlKd EaB5+pkDWLg9CFoYbKq32uLCbcOQd0TmMICOBw5QZicaMhtYzR/9Y6J07g5myhdCHq TqAZmygFXzLMRV1qVDhL3PvndlueoNU/1QN8amnkuLMYyZcDSERF5HV0DFfIhAOPNZ vWSUOuUe39Hmg== Received: by pali.im (Postfix) id 16A30857; Fri, 21 Jan 2022 14:58:15 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Martin Mares , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Matthew Wilcox , linux-pci@vger.kernel.org Subject: [PATCH pciutils 4/5] libpci: sysfs: Implement PROGIF, REVID and SUBSYS support Date: Fri, 21 Jan 2022 14:57:17 +0100 Message-Id: <20220121135718.27172-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121135718.27172-1-pali@kernel.org> References: <20220121135718.27172-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In sysfs there are optional nodes with this information. --- lib/sysfs.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index 7c157a2688ad..7714607f66a0 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -329,6 +329,7 @@ static unsigned int sysfs_fill_info(struct pci_dev *d, unsigned int flags) { unsigned int done = 0; + int value; if (!d->access->buscentric) { @@ -343,10 +344,42 @@ sysfs_fill_info(struct pci_dev *d, unsigned int flags) d->device_id = sysfs_get_value(d, "device", 1); done |= PCI_FILL_IDENT; } - if (flags & PCI_FILL_CLASS) + if (flags & (PCI_FILL_CLASS | PCI_FILL_PROGIF)) { - d->device_class = sysfs_get_value(d, "class", 1) >> 8; - done |= PCI_FILL_CLASS; + value = sysfs_get_value(d, "class", 1); + if (flags & PCI_FILL_CLASS) + { + d->device_class = value >> 8; + done |= PCI_FILL_CLASS; + } + if (flags & PCI_FILL_PROGIF) + { + d->prog_if = value & 0xff; + done |= PCI_FILL_PROGIF; + } + } + if (flags & PCI_FILL_REVID) + { + value = sysfs_get_value(d, "revision", 0); + if (value >= 0) + { + d->rev_id = value; + done |= PCI_FILL_REVID; + } + } + if (flags & PCI_FILL_SUBSYS) + { + value = sysfs_get_value(d, "subsystem_vendor", 0); + if (value >= 0) + { + d->subsys_vendor_id = value; + value = sysfs_get_value(d, "subsystem_device", 0); + if (value >= 0) + { + d->subsys_id = value; + done |= PCI_FILL_SUBSYS; + } + } } if (flags & PCI_FILL_IRQ) { From patchwork Fri Jan 21 13:57:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1582582 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=hrwWjQgg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4JgLZ30PC0z9t2p for ; Sat, 22 Jan 2022 00:58:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350807AbiAUN6S (ORCPT ); Fri, 21 Jan 2022 08:58:18 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:48388 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350819AbiAUN6R (ORCPT ); Fri, 21 Jan 2022 08:58:17 -0500 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 6FE47616EF for ; Fri, 21 Jan 2022 13:58:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AA31C340E1; Fri, 21 Jan 2022 13:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773496; bh=4eFw+xbE0ci8Liopx+oxuiae+HjMtMQKDb79VueiBWk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hrwWjQggv5fl3suY8vCvHi+as+k7qhI8Sl7YIY2Cc5aMAr/O/rvlUWR8kBheN5TR5 UWi2eHfx5bnMikb9jOBt2vcEtZM/fpA+wmwuVTjWEODYEXm86QmP0tQa23F27R2D9v lAWULkRitwktB87f4lLzpm5ONUfLmqZkeKzOk0vPMzAKdsueljgnEIsF0CyvGvhUa+ NS0jpnpl2MO2L+REcP8kLuQbEEHsaM2zog1Dg5J4F/F4KYoPJGPWQIxtQiWNl5xjIL NPFSBw9PphQG5tHj7pkYP4C4w58iuacYTMjaKKGGMADagbDY8+JkNkSQeUBGTWHVyp eOW5pWNKb73Tg== Received: by pali.im (Postfix) id 42AB2857; Fri, 21 Jan 2022 14:58:16 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Martin Mares , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Matthew Wilcox , linux-pci@vger.kernel.org Subject: [PATCH pciutils 5/5] lspci: Retrieve prog if, subsystem ids and revision id via libpci Date: Fri, 21 Jan 2022 14:57:18 +0100 Message-Id: <20220121135718.27172-6-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121135718.27172-1-pali@kernel.org> References: <20220121135718.27172-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Use pci_fill_info with PROGIF, REVID and SUBSYS to fill this information. lspci in some places reads class from what libpci provider fills in dev->device_class and in some other places it reads directly from config space. In dev->device_class is stored class possible different class as in config space (e.g. if kernel is fixing class because device has bogus information stored in config space). With this change is class always read from dev->device_class which reflects and respects lspci -b option (Bus-centric view). Same applies for subsystem ids and revision id (note that prog if is part of class). --- ls-kernel.c | 8 +++--- lspci.c | 70 ++++++++++++++++++----------------------------------- lspci.h | 2 -- 3 files changed, 27 insertions(+), 53 deletions(-) diff --git a/ls-kernel.c b/ls-kernel.c index ecacd0e65dce..2284b4625b12 100644 --- a/ls-kernel.c +++ b/ls-kernel.c @@ -174,16 +174,14 @@ static int match_pcimap(struct device *d, struct pcimap_entry *e) { struct pci_dev *dev = d->dev; - unsigned int class = get_conf_long(d, PCI_REVISION_ID) >> 8; - word subv, subd; + unsigned int class = (((unsigned int)dev->device_class << 8) | dev->prog_if); #define MATCH(x, y) ((y) > 0xffff || (x) == (y)) - get_subid(d, &subv, &subd); return MATCH(dev->vendor_id, e->vendor) && MATCH(dev->device_id, e->device) && - MATCH(subv, e->subvendor) && - MATCH(subd, e->subdevice) && + MATCH(dev->subsys_vendor_id, e->subvendor) && + MATCH(dev->subsys_id, e->subdevice) && (class & e->class_mask) == e->class; #undef MATCH } diff --git a/lspci.c b/lspci.c index d14d1b9185d6..c4e6c93bc67a 100644 --- a/lspci.c +++ b/lspci.c @@ -143,7 +143,7 @@ scan_device(struct pci_dev *p) d->config_cached += 64; } pci_setup_cache(p, d->config, d->config_cached); - pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS); + pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_PROGIF | PCI_FILL_REVID | PCI_FILL_SUBSYS); return d; } @@ -285,25 +285,6 @@ show_slot_name(struct device *d) show_slot_path(d); } -void -get_subid(struct device *d, word *subvp, word *subdp) -{ - byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f; - - if (htype == PCI_HEADER_TYPE_NORMAL) - { - *subvp = get_conf_word(d, PCI_SUBSYSTEM_VENDOR_ID); - *subdp = get_conf_word(d, PCI_SUBSYSTEM_ID); - } - else if (htype == PCI_HEADER_TYPE_CARDBUS && d->config_cached >= 128) - { - *subvp = get_conf_word(d, PCI_CB_SUBSYSTEM_VENDOR_ID); - *subdp = get_conf_word(d, PCI_CB_SUBSYSTEM_ID); - } - else - *subvp = *subdp = 0xffff; -} - static void show_terse(struct device *d) { @@ -319,12 +300,12 @@ show_terse(struct device *d) pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id)); - if (c = get_conf_byte(d, PCI_REVISION_ID)) - printf(" (rev %02x)", c); + if ((p->known_fields & PCI_FILL_REVID) && p->rev_id) + printf(" (rev %02x)", p->rev_id); if (verbose) { char *x; - c = get_conf_byte(d, PCI_CLASS_PROG); + c = (p->known_fields & PCI_FILL_PROGIF) ? p->prog_if : 0; x = pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS, p->device_class, c); @@ -340,19 +321,18 @@ show_terse(struct device *d) if (verbose || opt_kernel) { - word subsys_v, subsys_d; char ssnamebuf[256]; pci_fill_info(p, PCI_FILL_LABEL); if (p->label) printf("\tDeviceName: %s", p->label); - get_subid(d, &subsys_v, &subsys_d); - if (subsys_v && subsys_v != 0xffff) + if ((p->known_fields & PCI_FILL_SUBSYS) && + p->subsys_vendor_id && p->subsys_vendor_id != 0xffff) printf("\tSubsystem: %s\n", pci_lookup_name(pacc, ssnamebuf, sizeof(ssnamebuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, - p->vendor_id, p->device_id, subsys_v, subsys_d)); + p->vendor_id, p->device_id, p->subsys_vendor_id, p->subsys_id)); } } @@ -766,7 +746,7 @@ show_verbose(struct device *d) pci_fill_info(p, PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES | PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE | PCI_FILL_IOMMU_GROUP | - PCI_FILL_BRIDGE_BASES); + PCI_FILL_BRIDGE_BASES | PCI_FILL_PROGIF | PCI_FILL_REVID | PCI_FILL_SUBSYS); irq = p->irq; switch (htype) @@ -947,13 +927,9 @@ static void show_machine(struct device *d) { struct pci_dev *p = d->dev; - int c; - word sv_id, sd_id; char classbuf[128], vendbuf[128], devbuf[128], svbuf[128], sdbuf[128]; char *dt_node, *iommu_group; - get_subid(d, &sv_id, &sd_id); - if (verbose) { pci_fill_info(p, PCI_FILL_PHYS_SLOT | PCI_FILL_NUMA_NODE | PCI_FILL_DT_NODE | PCI_FILL_IOMMU_GROUP); @@ -966,19 +942,20 @@ show_machine(struct device *d) pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id)); printf("Device:\t%s\n", pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id)); - if (sv_id && sv_id != 0xffff) + if ((p->known_fields & PCI_FILL_SUBSYS) && + p->subsys_vendor_id && p->subsys_vendor_id != 0xffff) { printf("SVendor:\t%s\n", - pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id)); + pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->subsys_vendor_id)); printf("SDevice:\t%s\n", - pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id)); + pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, p->subsys_vendor_id, p->subsys_id)); } if (p->phy_slot) printf("PhySlot:\t%s\n", p->phy_slot); - if (c = get_conf_byte(d, PCI_REVISION_ID)) - printf("Rev:\t%02x\n", c); - if (c = get_conf_byte(d, PCI_CLASS_PROG)) - printf("ProgIf:\t%02x\n", c); + if ((p->known_fields & PCI_FILL_REVID) && p->rev_id) + printf("Rev:\t%02x\n", p->rev_id); + if (p->known_fields & PCI_FILL_PROGIF) + printf("ProgIf:\t%02x\n", p->prog_if); if (opt_kernel) show_kernel_machine(d); if (p->numa_node != -1) @@ -994,14 +971,15 @@ show_machine(struct device *d) print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class)); print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id)); print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id)); - if (c = get_conf_byte(d, PCI_REVISION_ID)) - printf(" -r%02x", c); - if (c = get_conf_byte(d, PCI_CLASS_PROG)) - printf(" -p%02x", c); - if (sv_id && sv_id != 0xffff) + if ((p->known_fields & PCI_FILL_REVID) && p->rev_id) + printf(" -r%02x", p->rev_id); + if (p->known_fields & PCI_FILL_PROGIF) + printf(" -p%02x", p->prog_if); + if ((p->known_fields & PCI_FILL_SUBSYS) && + p->subsys_vendor_id && p->subsys_vendor_id != 0xffff) { - print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id)); - print_shell_escaped(pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id)); + print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, p->subsys_vendor_id)); + print_shell_escaped(pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, p->subsys_vendor_id, p->subsys_id)); } else printf(" \"\" \"\""); diff --git a/lspci.h b/lspci.h index 352177fcce7b..6e0bb2492fd5 100644 --- a/lspci.h +++ b/lspci.h @@ -55,8 +55,6 @@ u32 get_conf_long(struct device *d, unsigned int pos); word get_conf_word(struct device *d, unsigned int pos); byte get_conf_byte(struct device *d, unsigned int pos); -void get_subid(struct device *d, word *subvp, word *subdp); - /* Useful macros for decoding of bits and bit fields */ #define FLAG(x,y) ((x & y) ? '+' : '-')