1 /* vi: set sw=4 ts=4: */
3 * lspci implementation for busybox
5 * Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //config: bool "lspci"
12 //config: #select PLATFORM_LINUX
14 //config: lspci is a utility for displaying information about PCI buses in the
15 //config: system and devices connected to them.
17 //config: This version uses sysfs (/sys/bus/pci/devices) only.
19 //applet:IF_LSPCI(APPLET(lspci, BB_DIR_USR_BIN, BB_SUID_DROP))
21 //kbuild:lib-$(CONFIG_LSPCI) += lspci.o
23 //usage:#define lspci_trivial_usage
25 //usage:#define lspci_full_usage "\n\n"
26 //usage: "List all PCI devices"
28 //usage: "\n -m Parsable output"
29 //usage: "\n -k Show driver"
39 * PCI_SLOT_NAME PCI_CLASS: PCI_VID:PCI_DID [PCI_SUBSYS_VID:PCI_SUBSYS_DID] [DRIVER]
41 static int FAST_FUNC fileAction(
43 struct stat *statbuf UNUSED_PARAM,
44 void *userData UNUSED_PARAM,
45 int depth UNUSED_PARAM)
49 char *pci_slot_name = NULL, *driver = NULL;
50 int pci_class = 0, pci_vid = 0, pci_did = 0;
51 int pci_subsys_vid = 0, pci_subsys_did = 0;
53 char *uevent_filename = concat_path_file(fileName, "/uevent");
54 parser = config_open2(uevent_filename, fopen_for_read);
55 free(uevent_filename);
57 while (config_read(parser, tokens, 3, 2, "\0:=", PARSE_NORMAL)) {
58 if (strcmp(tokens[0], "DRIVER") == 0) {
59 driver = xstrdup(tokens[1]);
63 if (strcmp(tokens[0], "PCI_CLASS") == 0) {
64 pci_class = xstrtou(tokens[1], 16)>>8;
68 if (strcmp(tokens[0], "PCI_ID") == 0) {
69 pci_vid = xstrtou(tokens[1], 16);
70 pci_did = xstrtou(tokens[2], 16);
74 if (strcmp(tokens[0], "PCI_SUBSYS_ID") == 0) {
75 pci_subsys_vid = xstrtou(tokens[1], 16);
76 pci_subsys_did = xstrtou(tokens[2], 16);
80 if (strcmp(tokens[0], "PCI_SLOT_NAME") == 0) {
81 pci_slot_name = xstrdup(tokens[2]);
88 if (option_mask32 & OPT_m) {
89 printf("%s \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"",
90 pci_slot_name, pci_class, pci_vid, pci_did,
91 pci_subsys_vid, pci_subsys_did);
93 printf("%s Class %04x: %04x:%04x",
94 pci_slot_name, pci_class, pci_vid, pci_did);
97 if ((option_mask32 & OPT_k) && driver) {
98 if (option_mask32 & OPT_m) {
99 printf(" \"%s\"", driver);
101 printf(" %s", driver);
112 int lspci_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
113 int lspci_main(int argc UNUSED_PARAM, char **argv)
115 getopt32(argv, "m" /*non-compat:*/ "k" /*ignored:*/ "nv");
117 recursive_action("/sys/bus/pci/devices",
120 NULL, /* dirAction */