/* lspci.c - List PCI devices. */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include VAS_EBOOT_MOD_LICENSE ("GPLv3+"); struct iter_cxt { VasEBoot_uint32_t pciid_check_mask, pciid_check_value; int bus, device, function; int check_bus, check_device, check_function; }; static const struct VasEBoot_arg_option options[] = { {0, 'd', 0, N_("Select device by vendor and device IDs."), N_("[vendor]:[device]"), ARG_TYPE_STRING}, {0, 's', 0, N_("Select device by its position on the bus."), N_("[bus]:[slot][.func]"), ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; static int VasEBoot_pcidump_iter (VasEBoot_pci_device_t dev, VasEBoot_pci_id_t pciid, void *data) { struct iter_cxt *ctx = data; VasEBoot_pci_address_t addr; int i; if ((pciid & ctx->pciid_check_mask) != ctx->pciid_check_value) return 0; if (ctx->check_bus && VasEBoot_pci_get_bus (dev) != ctx->bus) return 0; if (ctx->check_device && VasEBoot_pci_get_device (dev) != ctx->device) return 0; if (ctx->check_function && VasEBoot_pci_get_function (dev) != ctx->function) return 0; for (i = 0; i < 256; i += 4) { addr = VasEBoot_pci_make_address (dev, i); VasEBoot_printf ("%08x ", VasEBoot_pci_read (addr)); if ((i & 0xc) == 0xc) VasEBoot_printf ("\n"); } return 0; } static VasEBoot_err_t VasEBoot_cmd_pcidump (VasEBoot_extcmd_context_t ctxt, int argc __attribute__ ((unused)), char **argv __attribute__ ((unused))) { const char *ptr; 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; ctx.pciid_check_value |= (VasEBoot_strtoul (ptr, &ptr, 16) & 0xffff); if (VasEBoot_errno == VAS_EBOOT_ERR_BAD_NUMBER) { VasEBoot_errno = VAS_EBOOT_ERR_NONE; ptr = ctxt->state[0].arg; } else ctx.pciid_check_mask |= 0xffff; if (VasEBoot_errno) return VasEBoot_errno; if (*ptr != ':') return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); ptr++; ctx.pciid_check_value |= (VasEBoot_strtoul (ptr, &ptr, 16) & 0xffff) << 16; if (VasEBoot_errno == VAS_EBOOT_ERR_BAD_NUMBER) VasEBoot_errno = VAS_EBOOT_ERR_NONE; else ctx.pciid_check_mask |= 0xffff0000; } ctx.pciid_check_value &= ctx.pciid_check_mask; if (ctxt->state[1].set) { const char *optr; ptr = ctxt->state[1].arg; optr = ptr; ctx.bus = VasEBoot_strtoul (ptr, &ptr, 16); if (VasEBoot_errno == VAS_EBOOT_ERR_BAD_NUMBER) { VasEBoot_errno = VAS_EBOOT_ERR_NONE; ptr = optr; } else ctx.check_bus = 1; if (VasEBoot_errno) return VasEBoot_errno; if (*ptr != ':') return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); ptr++; optr = ptr; ctx.device = VasEBoot_strtoul (ptr, &ptr, 16); if (VasEBoot_errno == VAS_EBOOT_ERR_BAD_NUMBER) { VasEBoot_errno = VAS_EBOOT_ERR_NONE; ptr = optr; } else ctx.check_device = 1; if (*ptr == '.') { ptr++; ctx.function = VasEBoot_strtoul (ptr, &ptr, 16); if (VasEBoot_errno) return VasEBoot_errno; ctx.check_function = 1; } } VasEBoot_pci_iterate (VasEBoot_pcidump_iter, &ctx); return VAS_EBOOT_ERR_NONE; } static VasEBoot_extcmd_t cmd; VAS_EBOOT_MOD_INIT(pcidump) { cmd = VasEBoot_register_extcmd ("pcidump", VasEBoot_cmd_pcidump, 0, N_("[-s POSITION] [-d DEVICE]"), N_("Show raw dump of the PCI configuration space."), options); } VAS_EBOOT_MOD_FINI(pcidump) { VasEBoot_unregister_extcmd (cmd); }