grub/grub-core/commands/lsacpi.c

259 lines
6.9 KiB
C
Raw Normal View History

/* acpi.c - Display acpi tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc.
*
* GRUB 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.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/normal.h>
#include <grub/acpi.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/dl.h>
Increase warning level. * conf/Makefile.common (CFLAGS_GNULIB): Add -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-old-style-definition. * configure.ac (HOST_CFLAGS): Add bunch of -W arguments. (TARGET_CFLAGS): Likewise. (HOST_CFLAGS): Add -Werror unless --disable-werror is activated. * grub-core/Makefile.core.def (decompressor_xz): Add -Wno-unreachable-code. (normal): Add -Wno-redundant-decls. (xzio): Add -Wno-unreachable-code. (lzopio): Add -Wno-redundant-decls -Wno-error. * grub-core/commands/acpi.c: Add exception to -Wcast-align. * grub-core/commands/lsacpi.c: Add exception to -Wcast-align. * grub-core/gensymlist.sh: Add exception to -Wmissing-format-attribute. * grub-core/kern/dl.c: Add exception to -Wcast-align. * grub-core/kern/efi/efi.c (grub_efi_modules_addr): Likewise. * grub-core/kern/i386/coreboot/init.c: Add exception to -Wsuggest-attribute=noreturn. * grub-core/kern/ia64/dl.c: Add exception to -Wcast-align. * grub-core/kern/ia64/dl_helper.c: Likewise. * grub-core/kern/mips/dl.c: Likewise. * grub-core/kern/sparc64/dl.c: Likewise. * grub-core/lib/LzmaEnc.c: Add exception to -Wshadow. * grub-core/lib/libgcrypt_wrap/cipher_wrap.h (memcpy): Likewise. (memcmp): Likewise. * grub-core/lib/pbkdf2.c: Add exception to -Wunreachable-code. * grub-core/loader/ia64/efi/linux.c: Add exception to -Wcast-align. * grub-core/loader/mips/linux.c: Likewise. * grub-core/loader/multiboot_elfxx.c: Likewise. * grub-core/script/parser.y: Add exception to -Wunreachable-code. * grub-core/video/sm712.c: Add exception to -Wcast-align. * util/import_gcry.py: Add -Wno-cast-align to modules checked by hand. * grub-core/font/font.c (grub_font_loader_init): Add explicit cast and fixme. * grub-core/fs/iso9660.c (grub_iso9660_iterate_dir): Likewise. * grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_init): Fix prototype.
2012-02-10 15:48:48 +00:00
#pragma GCC diagnostic ignored "-Wcast-align"
GRUB_MOD_LICENSE ("GPLv3+");
static void
print_strn (grub_uint8_t *str, grub_size_t len)
{
for (; *str && len; str++, len--)
grub_printf ("%c", *str);
for (len++; len; len--)
grub_printf (" ");
}
#define print_field(x) print_strn(x, sizeof (x))
static void
disp_acpi_table (struct grub_acpi_table_header *t)
{
print_field (t->signature);
grub_printf ("%4" PRIuGRUB_UINT32_T "B rev=%u OEM=", t->length, t->revision);
print_field (t->oemid);
print_field (t->oemtable);
grub_printf ("OEMrev=%08" PRIxGRUB_UINT32_T " ", t->oemrev);
print_field (t->creator_id);
grub_printf (" %08" PRIxGRUB_UINT32_T "\n", t->creator_rev);
}
static void
disp_madt_table (struct grub_acpi_madt *t)
{
struct grub_acpi_madt_entry_header *d;
grub_uint32_t len;
disp_acpi_table (&t->hdr);
grub_printf ("Local APIC=%08" PRIxGRUB_UINT32_T " Flags=%08"
PRIxGRUB_UINT32_T "\n",
t->lapic_addr, t->flags);
len = t->hdr.length - sizeof (struct grub_acpi_madt);
d = t->entries;
for (;len > 0; len -= d->len, d = (void *) ((grub_uint8_t *) d + d->len))
{
grub_printf (" type=%x l=%u ", d->type, d->len);
switch (d->type)
{
case GRUB_ACPI_MADT_ENTRY_TYPE_INTERRUPT_OVERRIDE:
{
struct grub_acpi_madt_entry_interrupt_override *dt = (void *) d;
grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x\n",
dt->bus, dt->source, dt->global_sys_interrupt,
dt->flags);
}
break;
case GRUB_ACPI_MADT_ENTRY_TYPE_SAPIC:
{
struct grub_acpi_madt_entry_sapic *dt = (void *) d;
grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016" PRIxGRUB_UINT64_T
"\n",
dt->id, dt->global_sys_interrupt_base,
dt->addr);
}
break;
case GRUB_ACPI_MADT_ENTRY_TYPE_LSAPIC:
{
struct grub_acpi_madt_entry_lsapic *dt = (void *) d;
grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
dt->cpu_id, dt->id, dt->eid, dt->flags);
if (dt->flags & GRUB_ACPI_MADT_ENTRY_SAPIC_FLAGS_ENABLED)
grub_printf (" Enabled\n");
else
grub_printf (" Disabled\n");
if (d->len > sizeof (struct grub_acpi_madt_entry_sapic))
grub_printf (" UID val=%08x, Str=%s\n", dt->cpu_uid,
dt->cpu_uid_str);
}
break;
case GRUB_ACPI_MADT_ENTRY_TYPE_PLATFORM_INT_SOURCE:
{
struct grub_acpi_madt_entry_platform_int_source *dt = (void *) d;
static const char * const platint_type[] =
{"Nul", "PMI", "INIT", "CPEI"};
grub_printf ("Platform INT flags=%04x type=%02x (%s)"
" ID=%02x EID=%02x\n",
dt->flags, dt->inttype,
(dt->inttype < ARRAY_SIZE (platint_type))
? platint_type[dt->inttype] : "??", dt->cpu_id,
dt->cpu_eid);
grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x\n",
dt->sapic_vector, dt->global_sys_int, dt->src_flags);
}
break;
default:
grub_printf (" ??\n");
}
}
}
static void
disp_acpi_xsdt_table (struct grub_acpi_table_header *t)
{
grub_uint32_t len;
grub_uint64_t *desc;
disp_acpi_table (t);
len = t->length - sizeof (*t);
desc = (grub_uint64_t *) (t + 1);
for (; len >= sizeof (*desc); desc++, len -= sizeof (*desc))
{
#if GRUB_CPU_SIZEOF_VOID_P == 4
if (*desc >= (1ULL << 32))
{
grub_printf ("Unreachable table\n");
continue;
}
#endif
t = (struct grub_acpi_table_header *) (grub_addr_t) *desc;
if (t == NULL)
continue;
if (grub_memcmp (t->signature, GRUB_ACPI_MADT_SIGNATURE,
sizeof (t->signature)) == 0)
disp_madt_table ((struct grub_acpi_madt *) t);
else
disp_acpi_table (t);
}
}
static void
disp_acpi_rsdt_table (struct grub_acpi_table_header *t)
{
grub_uint32_t len;
grub_uint32_t *desc;
disp_acpi_table (t);
len = t->length - sizeof (*t);
desc = (grub_uint32_t *) (t + 1);
for (; len >= sizeof (*desc); desc++, len -= sizeof (*desc))
{
t = (struct grub_acpi_table_header *) (grub_addr_t) *desc;
if (t == NULL)
continue;
if (grub_memcmp (t->signature, GRUB_ACPI_MADT_SIGNATURE,
sizeof (t->signature)) == 0)
disp_madt_table ((struct grub_acpi_madt *) t);
else
disp_acpi_table (t);
}
}
static void
disp_acpi_rsdpv1 (struct grub_acpi_rsdp_v10 *rsdp)
{
print_field (rsdp->signature);
grub_printf ("chksum:%02x, OEM-ID: ", rsdp->checksum);
print_field (rsdp->oemid);
grub_printf ("rev=%d\n", rsdp->revision);
grub_printf ("RSDT=%08" PRIxGRUB_UINT32_T "\n", rsdp->rsdt_addr);
}
static void
disp_acpi_rsdpv2 (struct grub_acpi_rsdp_v20 *rsdp)
{
disp_acpi_rsdpv1 (&rsdp->rsdpv1);
grub_printf ("len=%d XSDT=%016" PRIxGRUB_UINT64_T "\n", rsdp->length,
rsdp->xsdt_addr);
}
static const struct grub_arg_option options[] = {
{"v1", '1', 0, N_("Show version 1 tables only."), 0, ARG_TYPE_NONE},
{"v2", '2', 0, N_("Show version 2 and version 3 tables only."), 0, ARG_TYPE_NONE}
};
static grub_err_t
grub_cmd_lsacpi (struct grub_extcmd_context *ctxt,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
if (!ctxt->state[1].set)
{
struct grub_acpi_rsdp_v10 *rsdp1 = grub_acpi_get_rsdpv1 ();
if (!rsdp1)
grub_printf ("No RSDPv1\n");
else
{
grub_printf ("RSDPv1 signature:");
disp_acpi_rsdpv1 (rsdp1);
disp_acpi_rsdt_table ((void *) (grub_addr_t) rsdp1->rsdt_addr);
}
}
if (!ctxt->state[0].set)
{
struct grub_acpi_rsdp_v20 *rsdp2 = grub_acpi_get_rsdpv2 ();
if (!rsdp2)
grub_printf ("No RSDPv2\n");
else
{
#if GRUB_CPU_SIZEOF_VOID_P == 4
if (rsdp2->xsdt_addr >= (1ULL << 32))
grub_printf ("Unreachable RSDPv2\n");
else
#endif
{
grub_printf ("RSDPv2 signature:");
disp_acpi_rsdpv2 (rsdp2);
disp_acpi_xsdt_table ((void *) (grub_addr_t) rsdp2->xsdt_addr);
grub_printf ("\n");
}
}
}
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(lsapi)
{
Clarify and unify messages. * grub-core/commands/hashsum.c (options): Unify messages. * grub-core/commands/keystatus.c (GRUB_MOD_INIT): Don't mark a literal-only message as translatable. * grub-core/commands/lsacpi.c (GRUB_MOD_INIT): Likewise. * grub-core/loader/ia64/efi/linux.c (GRUB_MOD_INIT): Likewise. * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Add quoting around commands. * grub-core/commands/menuentry.c (options): Clarify that it's a keyboard key, not the key used to unlock. Clarify what it's used for. * grub-core/kern/emu/hostdisk.c (read_device_map): Unify error message. * grub-core/loader/xnu.c (grub_xnu_load_driver): Remove erroneous colon. * grub-core/script/main.c (GRUB_MOD_INIT): Clarify [n] to be [NUM]. * util/grub-editenv.c (options): Unify "verbose" message. * util/grub-fstest.c (read_file): Unify error message. (fstest): Add quotes around commands. (options): Unify "verbose" message. * util/grub-install.in: Add quotes around variable name. * util/grub-kbdcomp.in: Unify error message. * util/grub-mkfont.c (main): Likewise. * util/grub-mkrescue.in: Likewise. * util/grub-mklayout.c (options): Unify "verbose" message. * util/grub-mkstandalone.in: Unify help and verbose messages. * util/grub-mount.c (options): Unify "verbose" message. * util/grub-probe.c (options): Likewise. * util/grub-script-check.c (options): Likewise. * util/grub-setup.c (setup): Unify no-terminator message. (options): Use DEVICE and not DEV. Unify "verbose" message. * util/ieee1275/ofpath.c (xrealpath): Unify error message.
2012-02-05 10:23:47 +00:00
cmd = grub_register_extcmd ("lsacpi", grub_cmd_lsacpi, 0, "[-1|-2]",
N_("Show ACPI information."), options);
}
GRUB_MOD_FINI(lsacpi)
{
grub_unregister_extcmd (cmd);
}