|
|
f96e0b |
From d08c1b02d9227c5ac0e335736f93e4e06b305b80 Mon Sep 17 00:00:00 2001
|
|
|
f96e0b |
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
Date: Wed, 16 Jan 2013 20:44:11 +0100
|
|
|
f96e0b |
Subject: [PATCH 112/482] Add new command pcidump.
|
|
|
f96e0b |
|
|
|
f96e0b |
---
|
|
|
f96e0b |
ChangeLog | 4 ++
|
|
|
f96e0b |
grub-core/Makefile.core.def | 6 ++
|
|
|
f96e0b |
grub-core/commands/pcidump.c | 165 +++++++++++++++++++++++++++++++++++++++++++
|
|
|
f96e0b |
grub-core/commands/setpci.c | 2 +-
|
|
|
f96e0b |
4 files changed, 176 insertions(+), 1 deletion(-)
|
|
|
f96e0b |
create mode 100644 grub-core/commands/pcidump.c
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/ChangeLog b/ChangeLog
|
|
|
f96e0b |
index f1c53e3..9922c06 100644
|
|
|
f96e0b |
--- a/ChangeLog
|
|
|
f96e0b |
+++ b/ChangeLog
|
|
|
f96e0b |
@@ -1,5 +1,9 @@
|
|
|
f96e0b |
2013-01-16 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
|
|
|
f96e0b |
+ Add new command pcidump.
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+2013-01-16 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
New terminal outputs using serial: morse and spkmodem.
|
|
|
f96e0b |
|
|
|
f96e0b |
2013-01-16 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
|
|
|
f96e0b |
index baf80b8..4609a4b 100644
|
|
|
f96e0b |
--- a/grub-core/Makefile.core.def
|
|
|
f96e0b |
+++ b/grub-core/Makefile.core.def
|
|
|
f96e0b |
@@ -828,6 +828,12 @@ module = {
|
|
|
f96e0b |
};
|
|
|
f96e0b |
|
|
|
f96e0b |
module = {
|
|
|
f96e0b |
+ name = pcidump;
|
|
|
f96e0b |
+ common = commands/pcidump.c;
|
|
|
f96e0b |
+ enable = pci;
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+module = {
|
|
|
f96e0b |
name = sleep;
|
|
|
f96e0b |
common = commands/sleep.c;
|
|
|
f96e0b |
};
|
|
|
f96e0b |
diff --git a/grub-core/commands/pcidump.c b/grub-core/commands/pcidump.c
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..a49cf93
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/grub-core/commands/pcidump.c
|
|
|
f96e0b |
@@ -0,0 +1,165 @@
|
|
|
f96e0b |
+/* lspci.c - List PCI devices. */
|
|
|
f96e0b |
+/*
|
|
|
f96e0b |
+ * GRUB -- GRand Unified Bootloader
|
|
|
f96e0b |
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is free software: you can redistribute it and/or modify
|
|
|
f96e0b |
+ * it under the terms of the GNU General Public License as published by
|
|
|
f96e0b |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
f96e0b |
+ * (at your option) any later version.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * GRUB is distributed in the hope that it will be useful,
|
|
|
f96e0b |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f96e0b |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
f96e0b |
+ * GNU General Public License for more details.
|
|
|
f96e0b |
+ *
|
|
|
f96e0b |
+ * You should have received a copy of the GNU General Public License
|
|
|
f96e0b |
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
f96e0b |
+ */
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+#include <grub/pci.h>
|
|
|
f96e0b |
+#include <grub/dl.h>
|
|
|
f96e0b |
+#include <grub/misc.h>
|
|
|
f96e0b |
+#include <grub/extcmd.h>
|
|
|
f96e0b |
+#include <grub/env.h>
|
|
|
f96e0b |
+#include <grub/mm.h>
|
|
|
f96e0b |
+#include <grub/i18n.h>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static grub_uint32_t pciid_check_mask, pciid_check_value;
|
|
|
f96e0b |
+static int bus, device, function;
|
|
|
f96e0b |
+static int check_bus, check_device, check_function;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static const struct grub_arg_option options[] =
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ {0, 'd', 0, N_("Select device by vendor and device IDs."),
|
|
|
f96e0b |
+ N_("[vendor]:[device]"), ARG_TYPE_STRING},
|
|
|
f96e0b |
+ {0, 's', 0, N_("Select device by its position on the bus."),
|
|
|
f96e0b |
+ N_("[bus]:[slot][.func]"), ARG_TYPE_STRING},
|
|
|
f96e0b |
+ {0, 0, 0, 0, 0, 0}
|
|
|
f96e0b |
+ };
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static int
|
|
|
f96e0b |
+grub_pcidump_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
|
|
|
f96e0b |
+ void *data __attribute__ ((unused)))
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ grub_pci_address_t addr;
|
|
|
f96e0b |
+ int i;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if ((pciid & pciid_check_mask) != pciid_check_value)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (check_bus && grub_pci_get_bus (dev) != bus)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (check_device && grub_pci_get_device (dev) != device)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (check_function && grub_pci_get_function (dev) != function)
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ for (i = 0; i < 256; i += 4)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ addr = grub_pci_make_address (dev, i);
|
|
|
f96e0b |
+ grub_printf ("%08x ", grub_pci_read (addr));
|
|
|
f96e0b |
+ if ((i & 0xc) == 0xc)
|
|
|
f96e0b |
+ grub_printf ("\n");
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ return 0;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static grub_err_t
|
|
|
f96e0b |
+grub_cmd_pcidump (grub_extcmd_context_t ctxt,
|
|
|
f96e0b |
+ int argc __attribute__ ((unused)),
|
|
|
f96e0b |
+ char **argv __attribute__ ((unused)))
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ const char *ptr;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ pciid_check_value = 0;
|
|
|
f96e0b |
+ pciid_check_mask = 0;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (ctxt->state[0].set)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ ptr = ctxt->state[0].arg;
|
|
|
f96e0b |
+ pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff);
|
|
|
f96e0b |
+ if (grub_errno == GRUB_ERR_BAD_NUMBER)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_errno = GRUB_ERR_NONE;
|
|
|
f96e0b |
+ ptr = ctxt->state[0].arg;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ pciid_check_mask |= 0xffff;
|
|
|
f96e0b |
+ if (grub_errno)
|
|
|
f96e0b |
+ return grub_errno;
|
|
|
f96e0b |
+ if (*ptr != ':')
|
|
|
f96e0b |
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':');
|
|
|
f96e0b |
+ ptr++;
|
|
|
f96e0b |
+ pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff)
|
|
|
f96e0b |
+ << 16;
|
|
|
f96e0b |
+ if (grub_errno == GRUB_ERR_BAD_NUMBER)
|
|
|
f96e0b |
+ grub_errno = GRUB_ERR_NONE;
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ pciid_check_mask |= 0xffff0000;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ pciid_check_value &= pciid_check_mask;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ check_bus = check_device = check_function = 0;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ if (ctxt->state[1].set)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ const char *optr;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ ptr = ctxt->state[1].arg;
|
|
|
f96e0b |
+ optr = ptr;
|
|
|
f96e0b |
+ bus = grub_strtoul (ptr, (char **) &ptr, 16);
|
|
|
f96e0b |
+ if (grub_errno == GRUB_ERR_BAD_NUMBER)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_errno = GRUB_ERR_NONE;
|
|
|
f96e0b |
+ ptr = optr;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ check_bus = 1;
|
|
|
f96e0b |
+ if (grub_errno)
|
|
|
f96e0b |
+ return grub_errno;
|
|
|
f96e0b |
+ if (*ptr != ':')
|
|
|
f96e0b |
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':');
|
|
|
f96e0b |
+ ptr++;
|
|
|
f96e0b |
+ optr = ptr;
|
|
|
f96e0b |
+ device = grub_strtoul (ptr, (char **) &ptr, 16);
|
|
|
f96e0b |
+ if (grub_errno == GRUB_ERR_BAD_NUMBER)
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ grub_errno = GRUB_ERR_NONE;
|
|
|
f96e0b |
+ ptr = optr;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ check_device = 1;
|
|
|
f96e0b |
+ if (*ptr == '.')
|
|
|
f96e0b |
+ {
|
|
|
f96e0b |
+ ptr++;
|
|
|
f96e0b |
+ function = grub_strtoul (ptr, (char **) &ptr, 16);
|
|
|
f96e0b |
+ if (grub_errno)
|
|
|
f96e0b |
+ return grub_errno;
|
|
|
f96e0b |
+ check_function = 1;
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+ }
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+ grub_pci_iterate (grub_pcidump_iter, NULL);
|
|
|
f96e0b |
+ return GRUB_ERR_NONE;
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+static grub_extcmd_t cmd;
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+GRUB_MOD_INIT(setpci)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ cmd = grub_register_extcmd ("pcidump", grub_cmd_pcidump, 0,
|
|
|
f96e0b |
+ N_("[-s POSITION] [-d DEVICE]"),
|
|
|
f96e0b |
+ N_("Dump PCI configuration space."), options);
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+GRUB_MOD_FINI(setpci)
|
|
|
f96e0b |
+{
|
|
|
f96e0b |
+ grub_unregister_extcmd (cmd);
|
|
|
f96e0b |
+}
|
|
|
f96e0b |
diff --git a/grub-core/commands/setpci.c b/grub-core/commands/setpci.c
|
|
|
f96e0b |
index 6fdf0e0..4eaba7c 100644
|
|
|
f96e0b |
--- a/grub-core/commands/setpci.c
|
|
|
f96e0b |
+++ b/grub-core/commands/setpci.c
|
|
|
f96e0b |
@@ -331,7 +331,7 @@ GRUB_MOD_INIT(setpci)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
cmd = grub_register_extcmd ("setpci", grub_cmd_setpci, 0,
|
|
|
f96e0b |
N_("[-s POSITION] [-d DEVICE] [-v VAR] "
|
|
|
f96e0b |
- "[REGISTER][=VALUE[:MASK]]"),
|
|
|
f96e0b |
+ "REGISTER[=VALUE[:MASK]]"),
|
|
|
f96e0b |
N_("Manipulate PCI devices."), options);
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
--
|
|
|
f96e0b |
1.8.2.1
|
|
|
f96e0b |
|