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 //usage:#define lspci_trivial_usage
12 //usage:#define lspci_full_usage "\n\n"
13 //usage: "List all PCI devices"
15 //usage: "\n -m Parsable output"
16 //usage: "\n -k Show driver"
26 * PCI_SLOT_NAME PCI_CLASS: PCI_VID:PCI_DID [PCI_SUBSYS_VID:PCI_SUBSYS_DID] [DRIVER]
28 static int FAST_FUNC fileAction(
30 struct stat *statbuf UNUSED_PARAM,
31 void *userData UNUSED_PARAM,
32 int depth UNUSED_PARAM)
36 char *pci_slot_name = NULL, *driver = NULL;
37 int pci_class = 0, pci_vid = 0, pci_did = 0;
38 int pci_subsys_vid = 0, pci_subsys_did = 0;
40 char *uevent_filename = concat_path_file(fileName, "/uevent");
41 parser = config_open2(uevent_filename, fopen_for_read);
42 free(uevent_filename);
44 while (config_read(parser, tokens, 3, 2, "\0:=", PARSE_NORMAL)) {
45 if (strcmp(tokens[0], "DRIVER") == 0) {
46 driver = xstrdup(tokens[1]);
50 if (strcmp(tokens[0], "PCI_CLASS") == 0) {
51 pci_class = xstrtou(tokens[1], 16)>>8;
55 if (strcmp(tokens[0], "PCI_ID") == 0) {
56 pci_vid = xstrtou(tokens[1], 16);
57 pci_did = xstrtou(tokens[2], 16);
61 if (strcmp(tokens[0], "PCI_SUBSYS_ID") == 0) {
62 pci_subsys_vid = xstrtou(tokens[1], 16);
63 pci_subsys_did = xstrtou(tokens[2], 16);
67 if (strcmp(tokens[0], "PCI_SLOT_NAME") == 0) {
68 pci_slot_name = xstrdup(tokens[2]);
75 if (option_mask32 & OPT_m) {
76 printf("%s \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"",
77 pci_slot_name, pci_class, pci_vid, pci_did,
78 pci_subsys_vid, pci_subsys_did);
80 printf("%s Class %04x: %04x:%04x",
81 pci_slot_name, pci_class, pci_vid, pci_did);
84 if ((option_mask32 & OPT_k) && driver) {
85 if (option_mask32 & OPT_m) {
86 printf(" \"%s\"", driver);
88 printf(" %s", driver);
99 int lspci_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
100 int lspci_main(int argc UNUSED_PARAM, char **argv)
102 getopt32(argv, "m" /*non-compat:*/ "k" /*ignored:*/ "nv");
104 recursive_action("/sys/bus/pci/devices",
107 NULL, /* dirAction */