~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to grub-core/commands/lspci.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

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