1 /* lspci.c - List PCI devices. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008, 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
22 #include <grub/misc.h>
23 #include <grub/command.h>
25 struct grub_pci_classname
32 static const struct grub_pci_classname grub_pci_classes
[] =
35 { 1, 0, "SCSI Controller" },
36 { 1, 1, "IDE Controller" },
37 { 1, 2, "Floppy Controller" },
38 { 1, 3, "IPI Controller" },
39 { 1, 4, "RAID Controller" },
40 { 1, 6, "SATA Controller" },
41 { 1, 0x80, "Mass storage Controller" },
42 { 2, 0, "Ethernet Controller" },
43 { 2, 1, "Token Ring Controller" },
44 { 2, 2, "FDDI Controller" },
45 { 2, 3, "ATM Controller" },
46 { 2, 4, "ISDN Controller" },
47 { 2, 0x80, "Network controller" },
48 { 3, 0, "VGA Controller" },
49 { 3, 1, "XGA Controller" },
50 { 3, 2, "3D Controller" },
51 { 3, 0x80, "Display Controller" },
52 { 4, 0, "Multimedia Video Device" },
53 { 4, 1, "Multimedia Audio Device" },
54 { 4, 2, "Multimedia Telephony Device" },
55 { 4, 0x80, "Multimedia device" },
56 { 5, 0, "RAM Controller" },
57 { 5, 1, "Flash Memory Controller" },
58 { 5, 0x80, "Memory Controller" },
59 { 6, 0, "Host Bridge" },
60 { 6, 1, "ISA Bridge" },
61 { 6, 2, "EISA Bride" },
62 { 6, 3, "MCA Bridge" },
63 { 6, 4, "PCI-PCI Bridge" },
64 { 6, 5, "PCMCIA Bridge" },
65 { 6, 6, "NuBus Bridge" },
66 { 6, 7, "CardBus Bridge" },
67 { 6, 8, "Raceway Bridge" },
68 { 6, 0x80, "Unknown Bridge" },
69 { 7, 0x80, "Communication controller" },
70 { 8, 0x80, "System hardware" },
71 { 9, 0, "Keyboard Controller" },
72 { 9, 1, "Digitizer" },
73 { 9, 2, "Mouse Controller" },
74 { 9, 3, "Scanner Controller" },
75 { 9, 4, "Gameport Controller" },
76 { 9, 0x80, "Unknown Input Device" },
77 { 10, 0, "Generic Docking Station" },
78 { 10, 0x80, "Unknown Docking Station" },
79 { 11, 0, "80386 Processor" },
80 { 11, 1, "80486 Processor" },
81 { 11, 2, "Pentium Processor" },
82 { 11, 0x10, "Alpha Processor" },
83 { 11, 0x20, "PowerPC Processor" },
84 { 11, 0x30, "MIPS Processor" },
85 { 11, 0x40, "Co-Processor" },
86 { 11, 0x80, "Unknown Processor" },
87 { 12, 0x80, "Serial Bus Controller" },
88 { 13, 0x80, "Wireless Controller" },
90 { 15, 0, "IrDA Controller" },
91 { 15, 1, "Consumer IR" },
92 { 15, 0x10, "RF-Controller" },
93 { 15, 0x80, "Satellite Communication Controller" },
94 { 16, 0, "Network Decryption" },
95 { 16, 1, "Entertainment Decryption" },
96 { 16, 0x80, "Unknown Decryption Controller" },
97 { 17, 0, "Digital IO Module" },
98 { 17, 0x80, "Unknown Data Input System" },
103 grub_pci_get_class (int class, int subclass
)
105 const struct grub_pci_classname
*curr
= grub_pci_classes
;
109 if (curr
->class == class && curr
->subclass
== subclass
)
117 static int NESTED_FUNC_ATTR
118 grub_lspci_iter (int bus
, int dev
, int func
, grub_pci_id_t pciid
)
122 grub_pci_address_t addr
;
124 grub_printf ("%02x:%02x.%x %04x:%04x", bus
, dev
, func
, pciid
& 0xFFFF,
126 addr
= grub_pci_make_address (bus
, dev
, func
, 2);
127 class = grub_pci_read (addr
);
129 /* Lookup the class name, if there isn't a specific one,
130 retry with 0x80 to get the generic class name. */
131 sclass
= grub_pci_get_class (class >> 24, (class >> 16) & 0xFF);
133 sclass
= grub_pci_get_class (class >> 24, 0x80);
137 grub_printf (" [%04x] %s", (class >> 16) & 0xffff, sclass
);
139 grub_uint8_t pi
= (class >> 8) & 0xff;
141 grub_printf (" [PI %02x]", pi
);
149 grub_cmd_lspci (grub_command_t cmd
__attribute__ ((unused
)),
150 int argc
__attribute__ ((unused
)),
151 char **args
__attribute__ ((unused
)))
153 grub_pci_iterate (grub_lspci_iter
);
154 return GRUB_ERR_NONE
;
157 static grub_command_t cmd
;
161 cmd
= grub_register_command ("lspci", grub_cmd_lspci
,
162 0, "List PCI devices");
167 grub_unregister_command (cmd
);