2009-12-22 Vladimir Serbinenko <phcoder@gmail.com>

* commands/lspci.c (grub_pci_classes): Add "USB Controller".
	(options): New variable.
	(iospace): Likewise.
	(grub_lspci_iter): List IO spaces if "-i" was given.
	(grub_cmd_lspci): Parse options.
	(GRUB_MOD_INIT(lspci)): Use extcmd.
	(GRUB_MOD_FINI(lspci)): Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-12-22 10:41:53 +01:00
commit dc77a79959
2 changed files with 74 additions and 6 deletions

View file

@ -1,3 +1,13 @@
2009-12-22 Vladimir Serbinenko <phcoder@gmail.com>
* commands/lspci.c (grub_pci_classes): Add "USB Controller".
(options): New variable.
(iospace): Likewise.
(grub_lspci_iter): List IO spaces if "-i" was given.
(grub_cmd_lspci): Parse options.
(GRUB_MOD_INIT(lspci)): Use extcmd.
(GRUB_MOD_FINI(lspci)): Likewise.
2009-12-22 Felix Zielcke <fzielcke@z-51.de> 2009-12-22 Felix Zielcke <fzielcke@z-51.de>
* util/grub.d/30_os-prober.in (osx_entry): Remove non POSIX compliant * util/grub.d/30_os-prober.in (osx_entry): Remove non POSIX compliant

View file

@ -20,7 +20,7 @@
#include <grub/pci.h> #include <grub/pci.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/command.h> #include <grub/extcmd.h>
struct grub_pci_classname struct grub_pci_classname
{ {
@ -84,6 +84,7 @@ static const struct grub_pci_classname grub_pci_classes[] =
{ 11, 0x30, "MIPS Processor" }, { 11, 0x30, "MIPS Processor" },
{ 11, 0x40, "Co-Processor" }, { 11, 0x40, "Co-Processor" },
{ 11, 0x80, "Unknown Processor" }, { 11, 0x80, "Unknown Processor" },
{ 12, 3, "USB Controller" },
{ 12, 0x80, "Serial Bus Controller" }, { 12, 0x80, "Serial Bus Controller" },
{ 13, 0x80, "Wireless Controller" }, { 13, 0x80, "Wireless Controller" },
{ 14, 0, "I2O" }, { 14, 0, "I2O" },
@ -114,12 +115,21 @@ grub_pci_get_class (int class, int subclass)
return 0; return 0;
} }
static const struct grub_arg_option options[] =
{
{"iospace", 'i', 0, "show I/O spaces", 0, 0},
{0, 0, 0, 0, 0, 0}
};
static int iospace;
static int NESTED_FUNC_ATTR static int NESTED_FUNC_ATTR
grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid) grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
{ {
grub_uint32_t class; grub_uint32_t class;
const char *sclass; const char *sclass;
grub_pci_address_t addr; grub_pci_address_t addr;
int reg;
grub_printf ("%02x:%02x.%x %04x:%04x", grub_pci_get_bus (dev), grub_printf ("%02x:%02x.%x %04x:%04x", grub_pci_get_bus (dev),
grub_pci_get_device (dev), grub_pci_get_function (dev), grub_pci_get_device (dev), grub_pci_get_function (dev),
@ -143,27 +153,75 @@ grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
grub_printf ("\n"); grub_printf ("\n");
if (iospace)
{
reg = 4;
while (reg < 10)
{
grub_uint64_t space;
addr = grub_pci_make_address (dev, reg);
space = grub_pci_read (addr);
reg++;
if (space == 0)
continue;
switch (space & GRUB_PCI_ADDR_SPACE_MASK)
{
case GRUB_PCI_ADDR_SPACE_IO:
grub_printf ("\tIO space %d at 0x%llx\n", (reg - 1) - 4,
(unsigned long long)
(space & GRUB_PCI_ADDR_IO_MASK));
break;
case GRUB_PCI_ADDR_SPACE_MEMORY:
if ((space & GRUB_PCI_ADDR_MEM_TYPE_MASK)
== GRUB_PCI_ADDR_MEM_TYPE_64)
{
addr = grub_pci_make_address (dev, reg);
space |= ((grub_uint64_t) grub_pci_read (addr)) << 32;
reg++;
grub_printf ("\t64-bit memory space %d at 0x%016llx [%s]\n",
(reg - 2) - 4, (unsigned long long)
(space & GRUB_PCI_ADDR_MEM_MASK),
space & GRUB_PCI_ADDR_MEM_PREFETCH
? "prefetchable" : "non-prefetchable");
}
else
grub_printf ("\t32-bit memory space %d at 0x%016llx [%s]\n",
(reg - 1) - 4, (unsigned long long)
(space & GRUB_PCI_ADDR_MEM_MASK),
space & GRUB_PCI_ADDR_MEM_PREFETCH
? "prefetchable" : "non-prefetchable");
break;
}
}
}
return 0; return 0;
} }
static grub_err_t static grub_err_t
grub_cmd_lspci (grub_command_t cmd __attribute__ ((unused)), grub_cmd_lspci (grub_extcmd_t cmd,
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
iospace = cmd->state[0].set;
grub_pci_iterate (grub_lspci_iter); grub_pci_iterate (grub_lspci_iter);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
static grub_command_t cmd; static grub_extcmd_t cmd;
GRUB_MOD_INIT(lspci) GRUB_MOD_INIT(lspci)
{ {
cmd = grub_register_command ("lspci", grub_cmd_lspci, cmd = grub_register_extcmd ("lspci", grub_cmd_lspci, GRUB_COMMAND_FLAG_BOTH,
0, "List PCI devices."); "lspci [-i]", "List PCI devices.", options);
} }
GRUB_MOD_FINI(lspci) GRUB_MOD_FINI(lspci)
{ {
grub_unregister_command (cmd); grub_unregister_extcmd (cmd);
} }