From patchwork Fri Jan 21 14:03:48 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: 12719764 X-Patchwork-Delegate: bhelgaas@google.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF97AC433EF for ; Fri, 21 Jan 2022 14:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380958AbiAUOFL (ORCPT ); Fri, 21 Jan 2022 09:05:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344855AbiAUOFJ (ORCPT ); Fri, 21 Jan 2022 09:05:09 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1B45C061401 for ; Fri, 21 Jan 2022 06:05:09 -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 sin.source.kernel.org (Postfix) with ESMTPS id 1DF17CE2384 for ; Fri, 21 Jan 2022 14:05:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FD21C340E4; Fri, 21 Jan 2022 14:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773906; bh=rvMVY9A63H/33e8AFufw38J9LCcyJH1/j9FcSxn2e8I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jfitE6IZqaG3ENrIckdiDghOjcjB0jiDeLSmJ3zMgOATMlz7n8Etjlh6tlVS4D8R8 M64BhdNp051Chmkulz8ee+MtqCYyBWje88WX3BcT+Nu+IwT+XR1yV99FBzLs/vrwKa oA73baAQKf1ky8UTVxx9x+YR+RqMSzfYwfm4Q4d6DylW2BqS0TeRtUNs2vhLsd7Jfy ZOhNZ2NnJRd2yiHfdWJ4Uc6hD/YZv2owZs3AfIFMrb6LPLVWOKphUymFqsgHihWau+ 6ku/NXjzT2rr0DxUCvZ7RGrKi2bumYiIqcsZD8RIbiWVQhXErQ72G6VRGwZ+czKtBE I80AnvHH4vheA== Received: by pali.im (Postfix) id 350A4B8A; Fri, 21 Jan 2022 15:05:04 +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/4] libpci: Define new string property PCI_FILL_DRIVER Date: Fri, 21 Jan 2022 15:03:48 +0100 Message-Id: <20220121140351.27382-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121140351.27382-1-pali@kernel.org> References: <20220121140351.27382-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 PCI_FILL_DRIVER via native system APIs. As it is string property there is no need to increase ABI version. Intended usage in application is just: const char *driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER); --- lib/pci.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pci.h b/lib/pci.h index 8c3c11b9ebeb..c13387e2b4b1 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -216,6 +216,7 @@ char *pci_get_string_property(struct pci_dev *d, u32 prop) PCI_ABI; #define PCI_FILL_PROGIF 0x00020000 #define PCI_FILL_REVID 0x00040000 #define PCI_FILL_SUBSYS 0x00080000 +#define PCI_FILL_DRIVER 0x00100000 void pci_setup_cache(struct pci_dev *, u8 *cache, int len) PCI_ABI; From patchwork Fri Jan 21 14:03:49 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: 12719763 X-Patchwork-Delegate: bhelgaas@google.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C29F8C433FE for ; Fri, 21 Jan 2022 14:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380888AbiAUOFK (ORCPT ); Fri, 21 Jan 2022 09:05:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381015AbiAUOFI (ORCPT ); Fri, 21 Jan 2022 09:05:08 -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 9ADFCC061574 for ; Fri, 21 Jan 2022 06:05:08 -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 373CF6177B for ; Fri, 21 Jan 2022 14:05:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76D9EC340E3; Fri, 21 Jan 2022 14:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773907; bh=nDCynboh8mnhqqPXz4Xcod8SOBX3JS9uy/dozeoYPyg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jPLOL2rZvVsKo8LskeN/RwOnt1nWx5FWlGKqwoM6UTtdmDEJwOHR4kvSm3DDZmxOA qBWfTA4vILNi2syi+o9oLP1YMolbMFxL9v+qiSBBw7SAkZa2Xd1kzoSgZ/MfX5MeGx uymnjwgTnrgycOTy0mTmaX+4/i4WJ4ZS0hNDTOKiVn7hWpTs4S9YToTmsVxOlM2h5/ Kvd7esRfVgYHDxJYMH1AY7Y3rQAOhDyC2Z8eQIQm99XQZuh6WK7qNiwlSjeudq637z 4MdN9uMS0l5cygSjbWcuYKmjcaSW9/J+7hnRasjpS5uTXdIJ0L00t/dde3jrMwt53L H+z7X5MGhvVUg== Received: by pali.im (Postfix) id 498AAC83; Fri, 21 Jan 2022 15:05:05 +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/4] libpci: proc: Implement support for PCI_FILL_DRIVER Date: Fri, 21 Jan 2022 15:03:49 +0100 Message-Id: <20220121140351.27382-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121140351.27382-1-pali@kernel.org> References: <20220121140351.27382-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org File /proc/bus/pci/devices contains optional driver name in the last 18th field. --- lib/proc.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/proc.c b/lib/proc.c index cb9d08d17768..9b33863e69e6 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -69,9 +70,11 @@ proc_scan(struct pci_access *a) { struct pci_dev *d = pci_alloc_dev(a); unsigned int dfn, vend, cnt, known; + char *driver; + int offset; #define F " " PCIADDR_T_FMT - cnt = sscanf(buf, "%x %x %x" F F F F F F F F F F F F F F, + cnt = sscanf(buf, "%x %x %x" F F F F F F F F F F F F F F "%n", &dfn, &vend, &d->irq, @@ -88,7 +91,8 @@ proc_scan(struct pci_access *a) &d->size[3], &d->size[4], &d->size[5], - &d->rom_size); + &d->rom_size, + &offset); #undef F if (cnt != 9 && cnt != 10 && cnt != 17) a->error("proc: parse error (read only %d items)", cnt); @@ -106,6 +110,20 @@ proc_scan(struct pci_access *a) if (cnt >= 17) known |= PCI_FILL_SIZES; } + if (cnt >= 17) + { + while (buf[offset] && isspace(buf[offset])) + ++offset; + driver = &buf[offset]; + while (buf[offset] && !isspace(buf[offset])) + ++offset; + buf[offset] = '\0'; + if (driver[0]) + { + pci_set_property(d, PCI_FILL_DRIVER, driver); + known |= PCI_FILL_DRIVER; + } + } d->known_fields = known; pci_link_dev(a, d); } From patchwork Fri Jan 21 14:03:50 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: 12719766 X-Patchwork-Delegate: bhelgaas@google.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDFE8C433F5 for ; Fri, 21 Jan 2022 14:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348550AbiAUOFM (ORCPT ); Fri, 21 Jan 2022 09:05:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350899AbiAUOFK (ORCPT ); Fri, 21 Jan 2022 09:05:10 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E9F8C061746 for ; Fri, 21 Jan 2022 06:05:10 -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 sin.source.kernel.org (Postfix) with ESMTPS id 84460CE2380 for ; Fri, 21 Jan 2022 14:05:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D084CC340E8; Fri, 21 Jan 2022 14:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773907; bh=sAKY1TpYTFaQfEDL5XqTWgX7eWD/m7B5OgJyKzXNW+E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kofe4ZqiOE1pyd1jK67tb07oJimg+6Oi5Y73Bm5Kb4/kMekEAnpCKQ2hLsRvm4ZmX c7KvAXDeJ0awILfXboazRp9CSQdFxtOcXAKOfQxT2zPG1Iq2+xzCHdaXFf5yMNoB/T aQDuD5whUa+S3VYC3FbrRwB5/4WHABGye+33PKRddFUou8XXBcQNX2I0CTjUw1Ipig KCr4VkpoxQzUEHQ8B9KF0xMkngU9Mcs1GSqoXqV2k4KMQ7VX+y6N4/WxpZOuzs87HD 6Fj1rZMEOFYXVjC9hbdKa0KzN4NixSBmJtOEKLzxakxNY8rQcjqPSuj7WX4VWbhyMJ i638Q66U+Llqg== Received: by pali.im (Postfix) id 8AA0A857; Fri, 21 Jan 2022 15:05:06 +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/4] libpci: sysfs: Implement support for PCI_FILL_DRIVER Date: Fri, 21 Jan 2022 15:03:50 +0100 Message-Id: <20220121140351.27382-4-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121140351.27382-1-pali@kernel.org> References: <20220121140351.27382-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In sysfs is driver name stored as symlink path of "driver" node. --- lib/sysfs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/sysfs.c b/lib/sysfs.c index 7714607f66a0..0dbd127ff53b 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -445,6 +445,19 @@ sysfs_fill_info(struct pci_dev *d, unsigned int flags) done |= PCI_FILL_DT_NODE; } + if (flags & PCI_FILL_DRIVER) + { + char *driver_path = sysfs_deref_link(d, "driver"); + if (driver_path) + { + char *driver = strrchr(driver_path, '/'); + driver = driver ? driver+1 : driver_path; + pci_set_property(d, PCI_FILL_DRIVER, driver); + free(driver_path); + } + done |= PCI_FILL_DRIVER; + } + return done | pci_generic_fill_info(d, flags & ~done); } From patchwork Fri Jan 21 14:03:51 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: 12719762 X-Patchwork-Delegate: bhelgaas@google.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DE32C433F5 for ; Fri, 21 Jan 2022 14:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381018AbiAUOFJ (ORCPT ); Fri, 21 Jan 2022 09:05:09 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:51660 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381016AbiAUOFJ (ORCPT ); Fri, 21 Jan 2022 09:05:09 -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 C5A0361792 for ; Fri, 21 Jan 2022 14:05:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 168B7C340E1; Fri, 21 Jan 2022 14:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642773908; bh=HioImQrg33h3GwYnOxwxENQO0LgCnPbH9UzRK7c1SB8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jrc3oPz7FN+ft6qUdbPwuf7fvzHRkcXwZobSy9YqeCtEy9c2Z3vL7FgBFeO2Ad2SN KTUF5heR0LQq9SMDiVLkviiqM5+CGvqwgmiKVw+TqZeHEUqXVxsFukuVhifHV8vJX8 FCeYS4q0+Y49PMgmJsc+cVM6coF7hyu2GFswYjPBL1YKNS51nKATjfPG8TyttKvhxO J8zi351AGfMPrMZ5q50nMzsVsXQoa5wumPMZmbGArN7FDxTCnxSxecnM1CD8LwoV5j lh8ezUldQ0A4X2IfysUUKZIpjYmPkTXEPaFH6D9yOXucbxRlH/K59ZLYk6l4PO/CaO 0dlpwQ6Vp2jEw== Received: by pali.im (Postfix) id C1FDA857; Fri, 21 Jan 2022 15:05:07 +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/4] lspci: Replace find_driver() via libpci PCI_FILL_DRIVER Date: Fri, 21 Jan 2022 15:03:51 +0100 Message-Id: <20220121140351.27382-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220121140351.27382-1-pali@kernel.org> References: <20220121140351.27382-1-pali@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org And implement this show_kernel() and show_kernel_machine() for all platforms. --- ls-kernel.c | 56 +++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/ls-kernel.c b/ls-kernel.c index 2284b4625b12..3c484af7a9e0 100644 --- a/ls-kernel.c +++ b/ls-kernel.c @@ -212,40 +212,6 @@ show_kernel_cleanup(void) #endif -#define DRIVER_BUF_SIZE 1024 - -static char * -find_driver(struct device *d, char *buf) -{ - struct pci_dev *dev = d->dev; - char name[1024], *drv, *base; - int n; - - if (dev->access->method != PCI_ACCESS_SYS_BUS_PCI) - return NULL; - - base = pci_get_param(dev->access, "sysfs.path"); - if (!base || !base[0]) - return NULL; - - n = snprintf(name, sizeof(name), "%s/devices/%04x:%02x:%02x.%d/driver", - base, dev->domain, dev->bus, dev->dev, dev->func); - if (n < 0 || n >= (int)sizeof(name)) - die("show_driver: sysfs device name too long, why?"); - - n = readlink(name, buf, DRIVER_BUF_SIZE); - if (n < 0) - return NULL; - if (n >= DRIVER_BUF_SIZE) - return ""; - buf[n] = 0; - - if (drv = strrchr(buf, '/')) - return drv+1; - else - return buf; -} - static const char * next_module_filtered(struct device *d) { @@ -268,10 +234,10 @@ next_module_filtered(struct device *d) void show_kernel(struct device *d) { - char buf[DRIVER_BUF_SIZE]; const char *driver, *module; - if (driver = find_driver(d, buf)) + pci_fill_info(d->dev, PCI_FILL_DRIVER); + if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER)) printf("\tKernel driver in use: %s\n", driver); if (!show_kernel_init()) @@ -287,10 +253,10 @@ show_kernel(struct device *d) void show_kernel_machine(struct device *d) { - char buf[DRIVER_BUF_SIZE]; const char *driver, *module; - if (driver = find_driver(d, buf)) + pci_fill_info(d->dev, PCI_FILL_DRIVER); + if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER)) printf("Driver:\t%s\n", driver); if (!show_kernel_init()) @@ -303,13 +269,23 @@ show_kernel_machine(struct device *d) #else void -show_kernel(struct device *d UNUSED) +show_kernel(struct device *d) { + const char *driver; + + pci_fill_info(d->dev, PCI_FILL_DRIVER); + if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER)) + printf("\tDriver in use: %s\n", driver); } void -show_kernel_machine(struct device *d UNUSED) +show_kernel_machine(struct device *d) { + const char *driver; + + pci_fill_info(d->dev, PCI_FILL_DRIVER); + if (driver = pci_get_string_property(d->dev, PCI_FILL_DRIVER)) + printf("Driver:\t%s\n", driver); } void