]> git.proxmox.com Git - grub2.git/blame - grub-core/commands/lspci.c
wildcard: Mark unused argument as such.
[grub2.git] / grub-core / commands / lspci.c
CommitLineData
58c69220 1/* lspci.c - List PCI devices. */
2/*
3 * GRUB -- GRand Unified Bootloader
353976ac 4 * Copyright (C) 2008, 2009 Free Software Foundation, Inc.
58c69220 5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include <grub/pci.h>
21#include <grub/dl.h>
58c69220 22#include <grub/misc.h>
d65f6db1 23#include <grub/extcmd.h>
77a79592 24#include <grub/i18n.h>
ca3a7446 25#include <grub/mm.h>
58c69220 26
e745cf0c
VS
27GRUB_MOD_LICENSE ("GPLv3+");
28
58c69220 29struct grub_pci_classname
30{
31 int class;
32 int subclass;
bf3a3857 33 const char *desc;
58c69220 34};
35
36static const struct grub_pci_classname grub_pci_classes[] =
37 {
38 { 0, 0, "" },
4f657021 39 { 1, 0, "SCSI Controller" },
58c69220 40 { 1, 1, "IDE Controller" },
41 { 1, 2, "Floppy Controller" },
42 { 1, 3, "IPI Controller" },
43 { 1, 4, "RAID Controller" },
353976ac 44 { 1, 6, "SATA Controller" },
58c69220 45 { 1, 0x80, "Mass storage Controller" },
46 { 2, 0, "Ethernet Controller" },
47 { 2, 1, "Token Ring Controller" },
48 { 2, 2, "FDDI Controller" },
49 { 2, 3, "ATM Controller" },
50 { 2, 4, "ISDN Controller" },
51 { 2, 0x80, "Network controller" },
52 { 3, 0, "VGA Controller" },
53 { 3, 1, "XGA Controller" },
54 { 3, 2, "3D Controller" },
55 { 3, 0x80, "Display Controller" },
56 { 4, 0, "Multimedia Video Device" },
57 { 4, 1, "Multimedia Audio Device" },
58 { 4, 2, "Multimedia Telephony Device" },
59 { 4, 0x80, "Multimedia device" },
60 { 5, 0, "RAM Controller" },
61 { 5, 1, "Flash Memory Controller" },
62 { 5, 0x80, "Memory Controller" },
63 { 6, 0, "Host Bridge" },
64 { 6, 1, "ISA Bridge" },
65 { 6, 2, "EISA Bride" },
66 { 6, 3, "MCA Bridge" },
67 { 6, 4, "PCI-PCI Bridge" },
68 { 6, 5, "PCMCIA Bridge" },
69 { 6, 6, "NuBus Bridge" },
70 { 6, 7, "CardBus Bridge" },
71 { 6, 8, "Raceway Bridge" },
72 { 6, 0x80, "Unknown Bridge" },
73 { 7, 0x80, "Communication controller" },
74 { 8, 0x80, "System hardware" },
75 { 9, 0, "Keyboard Controller" },
76 { 9, 1, "Digitizer" },
77 { 9, 2, "Mouse Controller" },
78 { 9, 3, "Scanner Controller" },
79 { 9, 4, "Gameport Controller" },
80 { 9, 0x80, "Unknown Input Device" },
81 { 10, 0, "Generic Docking Station" },
4f657021 82 { 10, 0x80, "Unknown Docking Station" },
58c69220 83 { 11, 0, "80386 Processor" },
84 { 11, 1, "80486 Processor" },
85 { 11, 2, "Pentium Processor" },
86 { 11, 0x10, "Alpha Processor" },
87 { 11, 0x20, "PowerPC Processor" },
88 { 11, 0x30, "MIPS Processor" },
89 { 11, 0x40, "Co-Processor" },
4f657021 90 { 11, 0x80, "Unknown Processor" },
cdef0f7f 91 { 12, 3, "USB Controller" },
58c69220 92 { 12, 0x80, "Serial Bus Controller" },
93 { 13, 0x80, "Wireless Controller" },
94 { 14, 0, "I2O" },
4f657021 95 { 15, 0, "IrDA Controller" },
58c69220 96 { 15, 1, "Consumer IR" },
97 { 15, 0x10, "RF-Controller" },
98 { 15, 0x80, "Satellite Communication Controller" },
99 { 16, 0, "Network Decryption" },
100 { 16, 1, "Entertainment Decryption" },
4f657021 101 { 16, 0x80, "Unknown Decryption Controller" },
58c69220 102 { 17, 0, "Digital IO Module" },
4f657021 103 { 17, 0x80, "Unknown Data Input System" },
58c69220 104 { 0, 0, 0 },
105 };
106
107static const char *
108grub_pci_get_class (int class, int subclass)
109{
110 const struct grub_pci_classname *curr = grub_pci_classes;
111
112 while (curr->desc)
113 {
114 if (curr->class == class && curr->subclass == subclass)
115 return curr->desc;
116 curr++;
117 }
118
119 return 0;
120}
121
9b0a46a1
VS
122static const struct grub_arg_option options[] =
123 {
124 {"iospace", 'i', 0, "show I/O spaces", 0, 0},
125 {0, 0, 0, 0, 0, 0}
126 };
127
128static int iospace;
129
ca3a7446
CW
130static int
131grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
132 void *data __attribute__ ((unused)))
58c69220 133{
134 grub_uint32_t class;
135 const char *sclass;
136 grub_pci_address_t addr;
dc77a799 137 int reg;
58c69220 138
3affd0ec 139 grub_printf ("%02x:%02x.%x %04x:%04x", grub_pci_get_bus (dev),
140 grub_pci_get_device (dev), grub_pci_get_function (dev),
141 pciid & 0xFFFF, pciid >> 16);
fbb8a887 142 addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
58c69220 143 class = grub_pci_read (addr);
353976ac 144
58c69220 145 /* Lookup the class name, if there isn't a specific one,
146 retry with 0x80 to get the generic class name. */
147 sclass = grub_pci_get_class (class >> 24, (class >> 16) & 0xFF);
148 if (! sclass)
149 sclass = grub_pci_get_class (class >> 24, 0x80);
150 if (! sclass)
151 sclass = "";
152
353976ac 153 grub_printf (" [%04x] %s", (class >> 16) & 0xffff, sclass);
154
155 grub_uint8_t pi = (class >> 8) & 0xff;
156 if (pi)
157 grub_printf (" [PI %02x]", pi);
158
159 grub_printf ("\n");
58c69220 160
9b0a46a1 161 if (iospace)
cdef0f7f 162 {
fbb8a887
VS
163 reg = GRUB_PCI_REG_ADDRESSES;
164 while (reg < GRUB_PCI_REG_CIS_POINTER)
cdef0f7f 165 {
9b0a46a1
VS
166 grub_uint64_t space;
167 addr = grub_pci_make_address (dev, reg);
168 space = grub_pci_read (addr);
169
fbb8a887 170 reg += sizeof (grub_uint32_t);
f7fcb23c 171
9b0a46a1
VS
172 if (space == 0)
173 continue;
a2c1332b 174
9b0a46a1 175 switch (space & GRUB_PCI_ADDR_SPACE_MASK)
cdef0f7f 176 {
9b0a46a1 177 case GRUB_PCI_ADDR_SPACE_IO:
fbb8a887 178 grub_printf ("\tIO space %d at 0x%llx\n",
dccad194 179 (unsigned) ((reg - GRUB_PCI_REG_ADDRESSES)
fbb8a887 180 / sizeof (grub_uint32_t)) - 1,
dc77a799 181 (unsigned long long)
9b0a46a1
VS
182 (space & GRUB_PCI_ADDR_IO_MASK));
183 break;
184 case GRUB_PCI_ADDR_SPACE_MEMORY:
a2c1332b 185 if ((space & GRUB_PCI_ADDR_MEM_TYPE_MASK)
9b0a46a1
VS
186 == GRUB_PCI_ADDR_MEM_TYPE_64)
187 {
7d991d17
VS
188 addr = grub_pci_make_address (dev, reg);
189 space |= ((grub_uint64_t) grub_pci_read (addr)) << 32;
fbb8a887 190 reg += sizeof (grub_uint32_t);
d65f6db1 191 grub_printf ("\t64-bit memory space %d at 0x%016llx [%s]\n",
dccad194 192 (unsigned) ((reg - GRUB_PCI_REG_ADDRESSES)
fbb8a887
VS
193 / sizeof (grub_uint32_t)) - 2,
194 (unsigned long long)
9b0a46a1
VS
195 (space & GRUB_PCI_ADDR_MEM_MASK),
196 space & GRUB_PCI_ADDR_MEM_PREFETCH
197 ? "prefetchable" : "non-prefetchable");
a2c1332b 198
9b0a46a1
VS
199 }
200 else
dc77a799 201 grub_printf ("\t32-bit memory space %d at 0x%016llx [%s]\n",
dccad194 202 (unsigned) ((reg - GRUB_PCI_REG_ADDRESSES)
fbb8a887
VS
203 / sizeof (grub_uint32_t)) - 1,
204 (unsigned long long)
9b0a46a1
VS
205 (space & GRUB_PCI_ADDR_MEM_MASK),
206 space & GRUB_PCI_ADDR_MEM_PREFETCH
207 ? "prefetchable" : "non-prefetchable");
208 break;
cdef0f7f 209 }
cdef0f7f
VS
210 }
211 }
212
213
58c69220 214 return 0;
215}
216
217static grub_err_t
28be0e94 218grub_cmd_lspci (grub_extcmd_context_t ctxt,
58c69220 219 int argc __attribute__ ((unused)),
220 char **args __attribute__ ((unused)))
221{
28be0e94 222 iospace = ctxt->state[0].set;
ca3a7446 223 grub_pci_iterate (grub_lspci_iter, NULL);
58c69220 224 return GRUB_ERR_NONE;
225}
226
9b0a46a1 227static grub_extcmd_t cmd;
58c69220 228
325c8258 229GRUB_MOD_INIT(lspci)
58c69220 230{
ed80f7d5
VS
231 cmd = grub_register_extcmd ("lspci", grub_cmd_lspci, 0, "[-i]",
232 N_("List PCI devices."), options);
58c69220 233}
234
325c8258 235GRUB_MOD_FINI(lspci)
58c69220 236{
9b0a46a1 237 grub_unregister_extcmd (cmd);
58c69220 238}