Import Tristan Gingold's ia64 port

(based on patch sent to grub-devel by Tristan in 2008-01-28)
This commit is contained in:
Robert Millan 2010-01-18 14:17:47 +00:00
parent 11cc30ac40
commit 2c40cc7868
32 changed files with 3791 additions and 38 deletions

193
commands/efi/acpi.c Normal file
View file

@ -0,0 +1,193 @@
/* acpi.c - Display acpi. */
/*
* 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>
static grub_uint32_t read16 (grub_uint8_t *p)
{
return p[0] | (p[1] << 8);
}
static grub_uint32_t read32 (grub_uint8_t *p)
{
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}
static grub_uint64_t read64 (grub_uint8_t *p)
{
grub_uint32_t l, h;
l = read32(p);
h = read32(p + 4);
return l | (((grub_uint64_t)h) << 32);
}
static void
disp_acpi_table (grub_uint8_t *t)
{
int i;
grub_printf ("%c%c%c%c %4dB rev=%d OEM=", t[0], t[1], t[2], t[3],
read32 (t + 4), t[8]);
for (i = 0; i < 6; i++)
grub_printf ("%c", t[10 + i]);
grub_printf (" ");
for (i = 0; i < 8; i++)
grub_printf ("%c", t[16 + i]);
grub_printf (" V=%08lx ", read32 (t + 24));
for (i = 0; i < 4; i++)
grub_printf ("%c", t[28 + i]);
grub_printf (" %08lx\n", read32 (t + 32));
}
static void
disp_acpi_apic_table (grub_uint8_t *t)
{
grub_uint8_t *d;
grub_uint32_t len;
grub_uint32_t flags;
disp_acpi_table (t);
grub_printf ("Local APIC=%08lx Flags=%08lx\n",
read32 (t + 36), read32 (t + 40));
len = read32 (t + 4);
len -= 44;
d = t + 44;
while (len > 0)
{
grub_uint32_t l = d[1];
grub_printf (" type=%x l=%d ", d[0], l);
switch (d[0])
{
case 2:
grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x",
d[2], d[3], read32 (d + 4), read16 (d + 8));
break;
case 6:
grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016llx",
d[2], read32 (d + 4), read64 (d + 8));
break;
case 7:
flags = read32 (d + 8);
grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
d[2], d[3], d[4], flags);
if (flags & 1)
grub_printf (" Enabled");
else
grub_printf (" Disabled");
if (l >= 17)
grub_printf ("\n"
" UID val=%08x, Str=%s", read32 (d + 12), d + 16);
break;
case 8:
grub_printf ("Platform INT flags=%04x type=%02x (",
read16 (d + 2), d[4]);
if (d[4] <= 3)
{
static const char * const platint_type[4] =
{"Nul", "PMI", "INIT", "CPEI"};
grub_printf ("%s", platint_type[d[4]]);
}
else
grub_printf ("??");
grub_printf (") ID=%02x EID=%02x\n", d[5], d[6]);
grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x",
d[7], read32 (d + 8), read32 (d + 12));
break;
default:
grub_printf (" ??");
}
grub_printf ("\n");
d += l;
len -= l;
}
}
static void
disp_acpi_xsdt_table (grub_uint8_t *t)
{
grub_uint32_t len;
grub_uint8_t *desc;
disp_acpi_table (t);
len = read32 (t + 4) - 36;
desc = t + 36;
while (len > 0)
{
t = read64 (desc);
if (t[0] == 'A' && t[1] == 'P' && t[2] == 'I' && t[3] == 'C')
disp_acpi_apic_table (t);
else
disp_acpi_table (t);
desc += 8;
len -= 8;
}
}
static void
disp_acpi_rsdt_table (grub_uint8_t *t)
{
grub_uint32_t len;
grub_uint8_t *desc;
disp_acpi_table (t);
len = read32 (t + 4) - 36;
desc = t + 36;
while (len > 0)
{
t = read32 (desc);
if (t != NULL)
disp_acpi_table (t);
desc += 4;
len -= 4;
}
}
void
disp_acpi_rsdp_table (grub_uint8_t *rsdp)
{
grub_uint8_t *t = rsdp;
int i;
grub_uint8_t *xsdt;
grub_printf ("RSDP signature:");
for (i = 0; i < 8; i++)
grub_printf ("%c", t[i]);
grub_printf (" chksum:%02x, OEM-ID: ", t[8]);
for (i = 0; i < 6; i++)
grub_printf ("%c", t[9 + i]);
grub_printf (" rev=%d\n", t[15]);
grub_printf ("RSDT=%08lx", read32 (t + 16));
if (t[15] == 2)
{
xsdt = read64 (t + 24);
grub_printf (" len=%d XSDT=%016llx\n", read32 (t + 20), xsdt);
grub_printf ("\n");
disp_acpi_xsdt_table (xsdt);
}
else
{
grub_printf ("\n");
disp_acpi_rsdt_table (read32 (t + 16));
}
}

143
commands/efi/memmap.c Normal file
View file

@ -0,0 +1,143 @@
/* memmap.c - Display memory map. */
/*
* 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/efi/api.h>
#include <grub/efi/efi.h>
#define ADD_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
static grub_err_t
grub_cmd_memmap (struct grub_arg_list *state, int argc, char **args)
{
grub_efi_uintn_t map_size;
grub_efi_memory_descriptor_t *memory_map;
grub_efi_memory_descriptor_t *memory_map_end;
grub_efi_memory_descriptor_t *desc;
grub_efi_uintn_t desc_size;
map_size = 0;
if (grub_efi_get_memory_map (&map_size, NULL, NULL, &desc_size, 0) < 0)
return 0;
memory_map = grub_malloc (map_size);
if (memory_map == NULL)
return 0;
if (grub_efi_get_memory_map (&map_size, memory_map, NULL, &desc_size, 0) < 0)
goto fail;
grub_set_more (1);
grub_printf
("Type Physical start - end #Pages "
" Size Attributes\n");
memory_map_end = ADD_MEMORY_DESCRIPTOR(memory_map, map_size);
for (desc = memory_map;
desc < memory_map_end;
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
{
grub_efi_uintn_t size;
grub_efi_uint64_t attr;
static const char types_str[][9] =
{
"reserved",
"ldr-code",
"ldr-data",
"BS-code ",
"BS-data ",
"RT-code ",
"RT-data ",
"conv-mem",
"unusable",
"ACPI-rec",
"ACPI-nvs",
"MMIO ",
"IO-ports",
"PAL-code"
};
if (desc->type < sizeof (types_str) / sizeof (types_str[0]))
grub_printf ("%s ", types_str[desc->type]);
else
grub_printf ("Unk %02x ", desc->type);
grub_printf (" %016llx-%016llx %08lx",
desc->physical_start,
desc->physical_start + (desc->num_pages << 12) - 1,
desc->num_pages);
size = desc->num_pages << (12 - 10);
if (size < 1024)
grub_printf (" %4uKB", size);
else
{
size /= 1024;
if (size < 1024)
grub_printf (" %4uMB", size);
else
{
size /= 1024;
grub_printf (" %4uGB", size);
}
}
attr = desc->attribute;
if (attr & GRUB_EFI_MEMORY_RUNTIME)
grub_printf (" RT");
if (attr & GRUB_EFI_MEMORY_UC)
grub_printf (" UC");
if (attr & GRUB_EFI_MEMORY_WC)
grub_printf (" WC");
if (attr & GRUB_EFI_MEMORY_WT)
grub_printf (" WT");
if (attr & GRUB_EFI_MEMORY_WB)
grub_printf (" WB");
if (attr & GRUB_EFI_MEMORY_UCE)
grub_printf (" UCE");
if (attr & GRUB_EFI_MEMORY_WP)
grub_printf (" WP");
if (attr & GRUB_EFI_MEMORY_RP)
grub_printf (" RP");
if (attr & GRUB_EFI_MEMORY_XP)
grub_printf (" XP");
grub_printf ("\n");
}
grub_set_more (0);
fail:
grub_free (memory_map);
return 0;
}
GRUB_MOD_INIT(memmap)
{
(void)mod; /* To stop warning. */
grub_register_command ("memmap", grub_cmd_memmap, GRUB_COMMAND_FLAG_BOTH,
"memmap",
"Display memory map.", NULL);
}
GRUB_MOD_FINI(memmap)
{
grub_unregister_command ("memmap");
}

258
commands/efi/systab.c Normal file
View file

@ -0,0 +1,258 @@
/* systab.c - Display EFI systab. */
/*
* 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/efi/api.h>
#include <grub/efi/efi.h>
#define ACPI_20_TABLE_GUID \
{0x8868e871,0xe4f1,0x11d3,{0xbc,0x22,0x0,0x80,0xc7,0x3c,0x88,0x81}}
#define ACPI_TABLE_GUID \
{0xeb9d2d30,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
#define SAL_SYSTEM_TABLE_GUID \
{0xeb9d2d32,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
#define SMBIOS_TABLE_GUID \
{0xeb9d2d31,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
#define MPS_TABLE_GUID \
{0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
#define HCDP_TABLE_GUID \
{0xf951938d,0x620b,0x42ef,{0x82,0x79,0xa8,0x4b,0x79,0x61,0x78,0x98}}
struct guid_mapping
{
grub_efi_guid_t guid;
const char *name;
void (*disp)(struct guid_mapping *map, void *table);
};
static void disp_sal (struct guid_mapping *map, void *table);
static void disp_acpi (struct guid_mapping *map, void *table);
static const struct guid_mapping guid_mappings[] =
{
{ ACPI_20_TABLE_GUID, "ACPI-2.0", disp_acpi},
{ ACPI_TABLE_GUID, "ACPI-1.0", disp_acpi},
{ SAL_SYSTEM_TABLE_GUID, "SAL", disp_sal},
{ SMBIOS_TABLE_GUID, "SMBIOS",NULL},
{ MPS_TABLE_GUID, "MPS", NULL},
{ HCDP_TABLE_GUID, "HCDP", NULL}
};
struct sal_system_table
{
grub_uint32_t signature;
grub_uint32_t total_table_len;
grub_uint16_t sal_rev;
grub_uint16_t entry_count;
grub_uint8_t checksum;
grub_uint8_t reserved1[7];
grub_uint16_t sal_a_version;
grub_uint16_t sal_b_version;
grub_uint8_t oem_id[32];
grub_uint8_t product_id[32];
grub_uint8_t reserved2[8];
};
static void
disp_sal (struct guid_mapping *map, void *table)
{
struct sal_system_table *t = table;
grub_uint8_t *desc = table;
grub_uint32_t len, l;
grub_printf ("SAL rev: %02x, signature: %x, len:%x\n",
t->sal_rev, t->signature, t->total_table_len);
grub_printf ("nbr entry: %d, chksum: %02x, SAL version A: %02x B: %02x\n",
t->entry_count, t->checksum,
t->sal_a_version, t->sal_b_version);
grub_printf ("OEM-ID: %-32s\n", t->oem_id);
grub_printf ("Product-ID: %-32s\n", t->product_id);
desc += sizeof (struct sal_system_table);
len = t->total_table_len - sizeof (struct sal_system_table);
while (len > 0)
{
switch (*desc)
{
case 0:
l = 48;
grub_printf (" Entry point: PAL=%016lx SAL=%016lx GP=%016lx\n",
*(grub_uint64_t*)(desc + 8),
*(grub_uint64_t*)(desc + 16),
*(grub_uint64_t*)(desc + 24));
break;
case 1:
l = 32;
grub_printf (" Memory descriptor entry addr=%016llx len=%uKB\n",
*(grub_uint64_t*)(desc + 8),
*(grub_uint32_t*)(desc + 16) * 4);
grub_printf (" sal_used=%d attr=%x AR=%x attr_mask=%x "
"type=%x usage=%x\n",
desc[1], desc[2], desc[3], desc[4], desc[5], desc[6]);
break;
case 2:
l = 16;
grub_printf (" Platform features: %02x", desc[1]);
if (desc[1] & 0x01)
grub_printf (" BusLock");
if (desc[1] & 0x02)
grub_printf (" IrqRedirect");
if (desc[1] & 0x04)
grub_printf (" IPIRedirect");
grub_printf ("\n");
break;
case 3:
l = 32;
grub_printf (" TR type=%d num=%d va=%016llx pte=%016llx\n",
desc[1], desc[2],
*(grub_uint64_t *)(desc + 8),
*(grub_uint64_t *)(desc + 16));
break;
case 4:
l = 16;
grub_printf (" PTC coherence nbr=%d addr=%016llx\n",
desc[1], *(grub_uint64_t *)(desc + 8));
break;
case 5:
l = 16;
grub_printf (" AP wake-up: mec=%d vect=%x\n",
desc[1], *(grub_uint64_t *)(desc + 8));
break;
default:
grub_printf (" unknown entry %d\n", *desc);
return;
}
desc += l;
len -= l;
}
}
static void
disp_acpi (struct guid_mapping *map, void *table)
{
disp_acpi_rsdp_table (table);
}
static void
disp_systab (void)
{
grub_efi_char16_t *vendor;
const grub_efi_system_table_t *st = grub_efi_system_table;
grub_efi_configuration_table_t *t;
unsigned int i;
grub_printf ("Signature: %016llx revision: %08x\n",
st->hdr.signature, st->hdr.revision);
grub_printf ("Vendor: ");
for (vendor = st->firmware_vendor; *vendor; vendor++)
grub_printf ("%c", *vendor);
grub_printf (", Version=%x\n", st->firmware_revision);
grub_printf ("%ld tables:\n", st->num_table_entries);
t = st->configuration_table;
for (i = 0; i < st->num_table_entries; i++)
{
unsigned int j;
grub_printf ("%016llx ", (grub_uint64_t)t->vendor_table);
grub_printf ("%08x-%04x-%04x-",
t->vendor_guid.data1, t->vendor_guid.data2,
t->vendor_guid.data3);
for (j = 0; j < 8; j++)
grub_printf ("%02x", t->vendor_guid.data4[j]);
for (j = 0; j < sizeof (guid_mappings)/sizeof(guid_mappings[0]); j++)
if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
sizeof (grub_efi_guid_t)) == 0)
grub_printf (" %s", guid_mappings[j].name);
grub_printf ("\n");
t++;
}
}
static void
disp_systab_entry (const char *name)
{
const grub_efi_system_table_t *st = grub_efi_system_table;
grub_efi_configuration_table_t *t;
unsigned int i;
struct guid_mapping *map;
map = NULL;
for (i = 0; i < sizeof (guid_mappings)/sizeof(guid_mappings[0]); i++)
if (grub_strcmp (guid_mappings[i].name, name) == 0)
{
map = &guid_mappings[i];
break;
}
if (map == NULL)
{
grub_printf ("System table '%s' unknown\n", name);
return;
}
if (map->disp == NULL)
{
grub_printf ("Don't know how to display table '%s'\n", name);
return;
}
t = st->configuration_table;
for (i = 0; i < st->num_table_entries; i++)
{
if (grub_memcmp (&map->guid, &t->vendor_guid,
sizeof (grub_efi_guid_t)) == 0)
{
grub_set_more (1);
(*map->disp)(map, t->vendor_table);
grub_set_more (0);
return;
}
t++;
}
grub_printf ("Systab '%s' not found\n", map->name);
}
static grub_err_t
grub_cmd_systab (struct grub_arg_list *state, int argc, char **args)
{
int i;
if (argc == 0)
disp_systab ();
else
for (i = 0; i < argc; i++)
disp_systab_entry (args[i]);
return 0;
}
GRUB_MOD_INIT(systab)
{
(void)mod; /* To stop warning. */
grub_register_command ("systab", grub_cmd_systab, GRUB_COMMAND_FLAG_BOTH,
"systab [NAME]",
"Display EFI system table.", NULL);
}
GRUB_MOD_FINI(systab)
{
grub_unregister_command ("systab");
}