Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / common / boot / grub2 / commands / lspci.c
blob0f52cf5dfdce9aaff26ae2f31d3a104a57aee695
1 /* lspci.c - List PCI devices. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008 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/>.
20 #include <grub/pci.h>
21 #include <grub/dl.h>
22 #include <grub/normal.h>
23 #include <grub/misc.h>
25 struct grub_pci_classname
27 int class;
28 int subclass;
29 char *desc;
32 static const struct grub_pci_classname grub_pci_classes[] =
34 { 0, 0, "" },
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, 0x80, "Mass storage Controller" },
41 { 2, 0, "Ethernet Controller" },
42 { 2, 1, "Token Ring Controller" },
43 { 2, 2, "FDDI Controller" },
44 { 2, 3, "ATM Controller" },
45 { 2, 4, "ISDN Controller" },
46 { 2, 0x80, "Network controller" },
47 { 3, 0, "VGA Controller" },
48 { 3, 1, "XGA Controller" },
49 { 3, 2, "3D Controller" },
50 { 3, 0x80, "Display Controller" },
51 { 4, 0, "Multimedia Video Device" },
52 { 4, 1, "Multimedia Audio Device" },
53 { 4, 2, "Multimedia Telephony Device" },
54 { 4, 0x80, "Multimedia device" },
55 { 5, 0, "RAM Controller" },
56 { 5, 1, "Flash Memory Controller" },
57 { 5, 0x80, "Memory Controller" },
58 { 6, 0, "Host Bridge" },
59 { 6, 1, "ISA Bridge" },
60 { 6, 2, "EISA Bride" },
61 { 6, 3, "MCA Bridge" },
62 { 6, 4, "PCI-PCI Bridge" },
63 { 6, 5, "PCMCIA Bridge" },
64 { 6, 6, "NuBus Bridge" },
65 { 6, 7, "CardBus Bridge" },
66 { 6, 8, "Raceway Bridge" },
67 { 6, 0x80, "Unknown Bridge" },
68 { 7, 0x80, "Communication controller" },
69 { 8, 0x80, "System hardware" },
70 { 9, 0, "Keyboard Controller" },
71 { 9, 1, "Digitizer" },
72 { 9, 2, "Mouse Controller" },
73 { 9, 3, "Scanner Controller" },
74 { 9, 4, "Gameport Controller" },
75 { 9, 0x80, "Unknown Input Device" },
76 { 10, 0, "Generic Docking Station" },
77 { 10, 0x80, "Unknown Docking Station" },
78 { 11, 0, "80386 Processor" },
79 { 11, 1, "80486 Processor" },
80 { 11, 2, "Pentium Processor" },
81 { 11, 0x10, "Alpha Processor" },
82 { 11, 0x20, "PowerPC Processor" },
83 { 11, 0x30, "MIPS Processor" },
84 { 11, 0x40, "Co-Processor" },
85 { 11, 0x80, "Unknown Processor" },
86 { 12, 0x80, "Serial Bus Controller" },
87 { 13, 0x80, "Wireless Controller" },
88 { 14, 0, "I2O" },
89 { 15, 0, "IrDA Controller" },
90 { 15, 1, "Consumer IR" },
91 { 15, 0x10, "RF-Controller" },
92 { 15, 0x80, "Satellite Communication Controller" },
93 { 16, 0, "Network Decryption" },
94 { 16, 1, "Entertainment Decryption" },
95 { 16, 0x80, "Unknown Decryption Controller" },
96 { 17, 0, "Digital IO Module" },
97 { 17, 0x80, "Unknown Data Input System" },
98 { 0, 0, 0 },
101 static const char *
102 grub_pci_get_class (int class, int subclass)
104 const struct grub_pci_classname *curr = grub_pci_classes;
106 while (curr->desc)
108 if (curr->class == class && curr->subclass == subclass)
109 return curr->desc;
110 curr++;
113 return 0;
116 static int
117 grub_lspci_iter (int bus, int dev, int func, grub_pci_id_t pciid)
119 grub_uint32_t class;
120 const char *sclass;
121 grub_pci_address_t addr;
123 grub_printf ("%02x:%02x.%x %04x:%04x", bus, dev, func, pciid & 0xFFFF,
124 pciid >> 16);
125 addr = grub_pci_make_address (bus, dev, func, 2);
126 class = grub_pci_read (addr);
128 /* Lookup the class name, if there isn't a specific one,
129 retry with 0x80 to get the generic class name. */
130 sclass = grub_pci_get_class (class >> 24, (class >> 16) & 0xFF);
131 if (! sclass)
132 sclass = grub_pci_get_class (class >> 24, 0x80);
133 if (! sclass)
134 sclass = "";
136 grub_printf (" %s\n", sclass);
138 return 0;
141 static grub_err_t
142 grub_cmd_lspci (struct grub_arg_list *state __attribute__ ((unused)),
143 int argc __attribute__ ((unused)),
144 char **args __attribute__ ((unused)))
146 grub_pci_iterate (grub_lspci_iter);
147 return GRUB_ERR_NONE;
153 GRUB_MOD_INIT(pci)
155 (void) mod; /* To stop warning. */
156 grub_register_command ("lspci", grub_cmd_lspci, GRUB_COMMAND_FLAG_BOTH,
157 "lspci", "List PCI devices", 0);
161 GRUB_MOD_FINI(pci)
163 grub_unregister_command ("lspci");