* grub-core/commands/pcidump.c: Remove static variables.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-07-11 16:11:03 +02:00
parent c6a61bda9b
commit 139072b83a
2 changed files with 41 additions and 27 deletions

View file

@ -1,3 +1,7 @@
2013-07-11 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/pcidump.c: Remove static variables.
2013-07-11 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/sleep.c: Refresh screen before sleeping.

View file

@ -27,9 +27,12 @@
GRUB_MOD_LICENSE ("GPLv3+");
static grub_uint32_t pciid_check_mask, pciid_check_value;
static int bus, device, function;
static int check_bus, check_device, check_function;
struct iter_cxt
{
grub_uint32_t pciid_check_mask, pciid_check_value;
int bus, device, function;
int check_bus, check_device, check_function;
};
static const struct grub_arg_option options[] =
{
@ -42,21 +45,22 @@ static const struct grub_arg_option options[] =
static int
grub_pcidump_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
void *data __attribute__ ((unused)))
void *data)
{
struct iter_cxt *ctx = data;
grub_pci_address_t addr;
int i;
if ((pciid & pciid_check_mask) != pciid_check_value)
if ((pciid & ctx->pciid_check_mask) != ctx->pciid_check_value)
return 0;
if (check_bus && grub_pci_get_bus (dev) != bus)
if (ctx->check_bus && grub_pci_get_bus (dev) != ctx->bus)
return 0;
if (check_device && grub_pci_get_device (dev) != device)
if (ctx->check_device && grub_pci_get_device (dev) != ctx->device)
return 0;
if (check_function && grub_pci_get_function (dev) != function)
if (ctx->check_function && grub_pci_get_function (dev) != ctx->function)
return 0;
for (i = 0; i < 256; i += 4)
@ -76,37 +80,43 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt,
char **argv __attribute__ ((unused)))
{
const char *ptr;
pciid_check_value = 0;
pciid_check_mask = 0;
struct iter_cxt ctx =
{
.pciid_check_value = 0,
.pciid_check_mask = 0,
.check_bus = 0,
.check_device = 0,
.check_function = 0,
.bus = 0,
.function = 0,
.device = 0
};
if (ctxt->state[0].set)
{
ptr = ctxt->state[0].arg;
pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff);
ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
grub_errno = GRUB_ERR_NONE;
ptr = ctxt->state[0].arg;
}
else
pciid_check_mask |= 0xffff;
ctx.pciid_check_mask |= 0xffff;
if (grub_errno)
return grub_errno;
if (*ptr != ':')
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':');
ptr++;
pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff)
ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff)
<< 16;
if (grub_errno == GRUB_ERR_BAD_NUMBER)
grub_errno = GRUB_ERR_NONE;
else
pciid_check_mask |= 0xffff0000;
ctx.pciid_check_mask |= 0xffff0000;
}
pciid_check_value &= pciid_check_mask;
check_bus = check_device = check_function = 0;
ctx.pciid_check_value &= ctx.pciid_check_mask;
if (ctxt->state[1].set)
{
@ -114,52 +124,52 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt,
ptr = ctxt->state[1].arg;
optr = ptr;
bus = grub_strtoul (ptr, (char **) &ptr, 16);
ctx.bus = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
grub_errno = GRUB_ERR_NONE;
ptr = optr;
}
else
check_bus = 1;
ctx.check_bus = 1;
if (grub_errno)
return grub_errno;
if (*ptr != ':')
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':');
ptr++;
optr = ptr;
device = grub_strtoul (ptr, (char **) &ptr, 16);
ctx.device = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
grub_errno = GRUB_ERR_NONE;
ptr = optr;
}
else
check_device = 1;
ctx.check_device = 1;
if (*ptr == '.')
{
ptr++;
function = grub_strtoul (ptr, (char **) &ptr, 16);
ctx.function = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno)
return grub_errno;
check_function = 1;
ctx.check_function = 1;
}
}
grub_pci_iterate (grub_pcidump_iter, NULL);
grub_pci_iterate (grub_pcidump_iter, &ctx);
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(setpci)
GRUB_MOD_INIT(pcidump)
{
cmd = grub_register_extcmd ("pcidump", grub_cmd_pcidump, 0,
N_("[-s POSITION] [-d DEVICE]"),
N_("Dump PCI configuration space."), options);
}
GRUB_MOD_FINI(setpci)
GRUB_MOD_FINI(pcidump)
{
grub_unregister_extcmd (cmd);
}