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 (6.3 kb)"
13
//config: lspci is a utility for displaying information about PCI buses in the
14
//config: system and devices connected to them.
16
//config: This version uses sysfs (/sys/bus/pci/devices) only.
18
//applet:IF_LSPCI(APPLET_NOEXEC(lspci, lspci, BB_DIR_USR_BIN, BB_SUID_DROP, lspci))
20
//kbuild:lib-$(CONFIG_LSPCI) += lspci.o
22
//usage:#define lspci_trivial_usage
24
//usage:#define lspci_full_usage "\n\n"
25
//usage: "List all PCI devices"
27
//usage: "\n -m Parsable output"
28
//usage: "\n -k Show driver"
38
* PCI_SLOT_NAME PCI_CLASS: PCI_VID:PCI_DID [PCI_SUBSYS_VID:PCI_SUBSYS_DID] [DRIVER]
40
static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
42
struct stat *statbuf UNUSED_PARAM)
46
char *pci_slot_name = NULL, *driver = NULL;
47
int pci_class = 0, pci_vid = 0, pci_did = 0;
48
int pci_subsys_vid = 0, pci_subsys_did = 0;
50
char *uevent_filename = concat_path_file(fileName, "/uevent");
51
parser = config_open2(uevent_filename, fopen_for_read);
52
free(uevent_filename);
54
while (config_read(parser, tokens, 3, 2, "\0:=", PARSE_NORMAL)) {
55
if (strcmp(tokens[0], "DRIVER") == 0) {
56
driver = xstrdup(tokens[1]);
60
if (strcmp(tokens[0], "PCI_CLASS") == 0) {
61
pci_class = xstrtou(tokens[1], 16)>>8;
65
if (strcmp(tokens[0], "PCI_ID") == 0) {
66
pci_vid = xstrtou(tokens[1], 16);
67
pci_did = xstrtou(tokens[2], 16);
71
if (strcmp(tokens[0], "PCI_SUBSYS_ID") == 0) {
72
pci_subsys_vid = xstrtou(tokens[1], 16);
73
pci_subsys_did = xstrtou(tokens[2], 16);
77
if (strcmp(tokens[0], "PCI_SLOT_NAME") == 0) {
78
pci_slot_name = xstrdup(tokens[2]);
85
if (option_mask32 & OPT_m) {
86
printf("%s \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"",
87
pci_slot_name, pci_class, pci_vid, pci_did,
88
pci_subsys_vid, pci_subsys_did);
90
printf("%s Class %04x: %04x:%04x",
91
pci_slot_name, pci_class, pci_vid, pci_did);
94
if ((option_mask32 & OPT_k) && driver) {
95
if (option_mask32 & OPT_m) {
96
printf(" \"%s\"", driver);
98
printf(" %s", driver);
109
int lspci_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
110
int lspci_main(int argc UNUSED_PARAM, char **argv)
112
getopt32(argv, "m" /*non-compat:*/ "k" /*ignored:*/ "nv");
114
recursive_action("/sys/bus/pci/devices",
117
NULL, /* dirAction */