grub/grub-core/commands/acpi.c

791 lines
22 KiB
C
Raw Normal View History

/* acpi.c - modify acpi tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/extcmd.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/term.h>
#include <grub/misc.h>
#include <grub/acpi.h>
#include <grub/mm.h>
#include <grub/memory.h>
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
#include <grub/i18n.h>
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#include <grub/efi/api.h>
#endif
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 const struct grub_arg_option options[] = {
2009-06-10 21:04:23 +00:00
{"exclude", 'x', 0,
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
N_("Don't load host tables specified by comma-separated list."),
0, ARG_TYPE_STRING},
2009-06-10 21:04:23 +00:00
{"load-only", 'n', 0,
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
N_("Load only tables specified by comma-separated list."), 0, ARG_TYPE_STRING},
{"v1", '1', 0, N_("Export version 1 tables to the OS."), 0, ARG_TYPE_NONE},
{"v2", '2', 0, N_("Export version 2 and version 3 tables to the OS."), 0, ARG_TYPE_NONE},
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
{"oemid", 'o', 0, N_("Set OEMID of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING},
2009-06-10 21:04:23 +00:00
{"oemtable", 't', 0,
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
N_("Set OEMTABLE ID of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING},
2009-06-10 21:04:23 +00:00
{"oemtablerev", 'r', 0,
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
N_("Set OEMTABLE revision of RSDP, XSDT and RSDT."), 0, ARG_TYPE_INT},
2009-06-10 21:04:23 +00:00
{"oemtablecreator", 'c', 0,
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
N_("Set creator field of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING},
2009-06-10 21:04:23 +00:00
{"oemtablecreatorrev", 'd', 0,
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
N_("Set creator revision of RSDP, XSDT and RSDT."), 0, ARG_TYPE_INT},
/* TRANSLATORS: "hangs" here is a noun, not a verb. */
{"no-ebda", 'e', 0, N_("Don't update EBDA. May fix failures or hangs on some "
"BIOSes but makes it ineffective with OS not receiving RSDP from GRUB."),
0, ARG_TYPE_NONE},
{0, 0, 0, 0, 0, 0}
};
2009-06-10 21:04:23 +00:00
/* rev1 is 1 if ACPIv1 is to be generated, 0 otherwise.
rev2 contains the revision of ACPIv2+ to generate or 0 if none. */
static int rev1, rev2;
/* OEMID of RSDP, RSDT and XSDT. */
static char root_oemid[6];
/* OEMTABLE of the same tables. */
static char root_oemtable[8];
/* OEMREVISION of the same tables. */
static grub_uint32_t root_oemrev;
/* CreatorID of the same tables. */
static char root_creator_id[4];
/* CreatorRevision of the same tables. */
static grub_uint32_t root_creator_rev;
static struct grub_acpi_rsdp_v10 *rsdpv1_new = 0;
static struct grub_acpi_rsdp_v20 *rsdpv2_new = 0;
static char *playground = 0, *playground_ptr = 0;
static int playground_size = 0;
/* Linked list of ACPI tables. */
struct efiemu_acpi_table
{
void *addr;
grub_size_t size;
struct efiemu_acpi_table *next;
};
static struct efiemu_acpi_table *acpi_tables = 0;
/* DSDT isn't in RSDT. So treat it specially. */
static void *table_dsdt = 0;
/* Pointer to recreated RSDT. */
static void *rsdt_addr = 0;
/* Allocation handles for different tables. */
static grub_size_t dsdt_size = 0;
/* Address of original FACS. */
static grub_uint32_t facs_addr = 0;
struct grub_acpi_rsdp_v20 *
grub_acpi_get_rsdpv2 (void)
{
if (rsdpv2_new)
return rsdpv2_new;
if (rsdpv1_new)
return 0;
return grub_machine_acpi_get_rsdpv2 ();
}
struct grub_acpi_rsdp_v10 *
grub_acpi_get_rsdpv1 (void)
{
if (rsdpv1_new)
return rsdpv1_new;
if (rsdpv2_new)
return 0;
return grub_machine_acpi_get_rsdpv1 ();
}
2015-02-22 13:42:43 +00:00
#if defined (__i386__) || defined (__x86_64__)
2009-06-10 21:04:23 +00:00
static inline int
iszero (grub_uint8_t *reg, int size)
{
int i;
for (i = 0; i < size; i++)
if (reg[i])
return 0;
return 1;
}
Remove nested functions from memory map iterators. * grub-core/efiemu/mm.c (grub_efiemu_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/coreboot/mmap.c (grub_linuxbios_table_iterate): Likewise. (grub_machine_mmap_iterate: iterate_linuxbios_table): Make static instead of nested. (grub_machine_mmap_iterate): Add hook_data argument. * grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/pc/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/arc/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/loongson/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/efi/mmap.c (grub_efi_mmap_iterate): Likewise. (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/mmap.c (grub_mmap_iterate): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_mmap_iterate): Update prototype. * include/grub/memory.h (grub_memory_hook_t): Add data argument. Remove NESTED_FUNC_ATTR from here and from all users. (grub_mmap_iterate): Update prototype. (grub_efi_mmap_iterate): Update prototype. Update all callers to pass appropriate hook data. (grub_machine_mmap_iterate): Likewise. * grub-core/commands/acpi.c (grub_acpi_create_ebda: find_hook): Make static instead of nested. * grub-core/commands/lsmmap.c (grub_cmd_lsmmap: hook): Likewise. Rename to ... (lsmmap_hook): ... this. * grub-core/efiemu/mm.c (grub_efiemu_mmap_init: bounds_hook): Likewise. (grub_efiemu_mmap_fill: fill_hook): Likewise. * grub-core/kern/i386/coreboot/init.c (grub_machine_init: heap_init): Likewise. * grub-core/kern/i386/pc/init.c (grub_machine_init: hook): Likewise. Rename to ... (mmap_iterate_hook): ... this. * grub-core/kern/ieee1275/init.c (grub_claim_heap: heap_init): Likewise. * grub-core/lib/ieee1275/relocator.c (grub_relocator_firmware_get_max_events: count): Likewise. (grub_relocator_firmware_fill_events: fill): Likewise. Rename to ... (grub_relocator_firmware_fill_events_iter): ... this. * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align: hook): Likewise. Rename to ... (grub_relocator_alloc_chunk_align_iter): ... this. * grub-core/loader/i386/bsd.c (generate_e820_mmap: hook): Likewise. Rename to ... (generate_e820_mmap_iter): ... this. * grub-core/loader/i386/linux.c (find_mmap_size: hook): Likewise. Rename to ... (count_hook): ... this. (grub_linux_boot: hook): Likewise. Rename to ... (grub_linux_boot_mmap_find): ... this. (grub_linux_boot: hook_fill): Likewise. Rename to ... (grub_linux_boot_mmap_fill): ... this. * grub-core/loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/multiboot.c (grub_get_multiboot_mmap_count: hook): Likewise. Rename to ... (count_hook): ... this. * grub-core/loader/multiboot_mbi2.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_claimmap_iterate: alloc_mem): Likewise. * grub-core/loader/sparc64/ieee1275/linux.c (alloc_phys: choose): Likewise. Rename to ... (alloc_phys_choose): ... this. (determine_phys_base: get_physbase): Likewise. * grub-core/mmap/i386/mmap.c (grub_mmap_malign_and_register: find_hook): Likewise. * grub-core/mmap/i386/pc/mmap.c (preboot: fill_hook): Likewise. (malloc_hook: count_hook): Likewise. * grub-core/mmap/i386/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. (grub_mmap_get_post64: hook): Likewise. Rename to ... (post64_hook): ... this. * grub-core/mmap/mips/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. * grub-core/mmap/mmap.c (grub_mmap_iterate: count_hook): Likewise. (grub_mmap_iterate: fill_hook): Likewise. (fill_mask): Pass addr and mask within a single struct. (grub_cmd_badram: hook): Make static instead of nested. Rename to ... (badram_iter): ... this. (grub_cmd_cutmem: hook): Likewise. Rename to ... (cutmem_iter): ... this.
2013-01-15 12:02:35 +00:00
/* Context for grub_acpi_create_ebda. */
struct grub_acpi_create_ebda_ctx {
int ebda_len;
grub_uint64_t highestlow;
};
/* Helper for grub_acpi_create_ebda. */
static int
find_hook (grub_uint64_t start, grub_uint64_t size, grub_memory_type_t type,
void *data)
{
struct grub_acpi_create_ebda_ctx *ctx = data;
grub_uint64_t end = start + size;
if (type != GRUB_MEMORY_AVAILABLE)
return 0;
if (end > 0x100000)
end = 0x100000;
if (end > start + ctx->ebda_len
&& ctx->highestlow < ((end - ctx->ebda_len) & (~0xf)) )
ctx->highestlow = (end - ctx->ebda_len) & (~0xf);
return 0;
}
2009-06-10 21:04:23 +00:00
grub_err_t
grub_acpi_create_ebda (void)
{
Remove nested functions from memory map iterators. * grub-core/efiemu/mm.c (grub_efiemu_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/coreboot/mmap.c (grub_linuxbios_table_iterate): Likewise. (grub_machine_mmap_iterate: iterate_linuxbios_table): Make static instead of nested. (grub_machine_mmap_iterate): Add hook_data argument. * grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/pc/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/arc/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/loongson/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/efi/mmap.c (grub_efi_mmap_iterate): Likewise. (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/mmap.c (grub_mmap_iterate): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_mmap_iterate): Update prototype. * include/grub/memory.h (grub_memory_hook_t): Add data argument. Remove NESTED_FUNC_ATTR from here and from all users. (grub_mmap_iterate): Update prototype. (grub_efi_mmap_iterate): Update prototype. Update all callers to pass appropriate hook data. (grub_machine_mmap_iterate): Likewise. * grub-core/commands/acpi.c (grub_acpi_create_ebda: find_hook): Make static instead of nested. * grub-core/commands/lsmmap.c (grub_cmd_lsmmap: hook): Likewise. Rename to ... (lsmmap_hook): ... this. * grub-core/efiemu/mm.c (grub_efiemu_mmap_init: bounds_hook): Likewise. (grub_efiemu_mmap_fill: fill_hook): Likewise. * grub-core/kern/i386/coreboot/init.c (grub_machine_init: heap_init): Likewise. * grub-core/kern/i386/pc/init.c (grub_machine_init: hook): Likewise. Rename to ... (mmap_iterate_hook): ... this. * grub-core/kern/ieee1275/init.c (grub_claim_heap: heap_init): Likewise. * grub-core/lib/ieee1275/relocator.c (grub_relocator_firmware_get_max_events: count): Likewise. (grub_relocator_firmware_fill_events: fill): Likewise. Rename to ... (grub_relocator_firmware_fill_events_iter): ... this. * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align: hook): Likewise. Rename to ... (grub_relocator_alloc_chunk_align_iter): ... this. * grub-core/loader/i386/bsd.c (generate_e820_mmap: hook): Likewise. Rename to ... (generate_e820_mmap_iter): ... this. * grub-core/loader/i386/linux.c (find_mmap_size: hook): Likewise. Rename to ... (count_hook): ... this. (grub_linux_boot: hook): Likewise. Rename to ... (grub_linux_boot_mmap_find): ... this. (grub_linux_boot: hook_fill): Likewise. Rename to ... (grub_linux_boot_mmap_fill): ... this. * grub-core/loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/multiboot.c (grub_get_multiboot_mmap_count: hook): Likewise. Rename to ... (count_hook): ... this. * grub-core/loader/multiboot_mbi2.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_claimmap_iterate: alloc_mem): Likewise. * grub-core/loader/sparc64/ieee1275/linux.c (alloc_phys: choose): Likewise. Rename to ... (alloc_phys_choose): ... this. (determine_phys_base: get_physbase): Likewise. * grub-core/mmap/i386/mmap.c (grub_mmap_malign_and_register: find_hook): Likewise. * grub-core/mmap/i386/pc/mmap.c (preboot: fill_hook): Likewise. (malloc_hook: count_hook): Likewise. * grub-core/mmap/i386/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. (grub_mmap_get_post64: hook): Likewise. Rename to ... (post64_hook): ... this. * grub-core/mmap/mips/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. * grub-core/mmap/mmap.c (grub_mmap_iterate: count_hook): Likewise. (grub_mmap_iterate: fill_hook): Likewise. (fill_mask): Pass addr and mask within a single struct. (grub_cmd_badram: hook): Make static instead of nested. Rename to ... (badram_iter): ... this. (grub_cmd_cutmem: hook): Likewise. Rename to ... (cutmem_iter): ... this.
2013-01-15 12:02:35 +00:00
struct grub_acpi_create_ebda_ctx ctx = {
.highestlow = 0
};
int ebda_kb_len = 0;
int mmapregion = 0;
grub_uint8_t *ebda, *v1inebda = 0, *v2inebda = 0;
grub_uint8_t *targetebda, *target;
struct grub_acpi_rsdp_v10 *v1;
struct grub_acpi_rsdp_v20 *v2;
2009-06-10 21:04:23 +00:00
ebda = (grub_uint8_t *) (grub_addr_t) ((*((grub_uint16_t *)0x40e)) << 4);
grub_dprintf ("acpi", "EBDA @%p\n", ebda);
if (ebda)
ebda_kb_len = *(grub_uint16_t *) ebda;
grub_dprintf ("acpi", "EBDA length 0x%x\n", ebda_kb_len);
if (ebda_kb_len > 16)
ebda_kb_len = 0;
Remove nested functions from memory map iterators. * grub-core/efiemu/mm.c (grub_efiemu_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/coreboot/mmap.c (grub_linuxbios_table_iterate): Likewise. (grub_machine_mmap_iterate: iterate_linuxbios_table): Make static instead of nested. (grub_machine_mmap_iterate): Add hook_data argument. * grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/pc/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/arc/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/loongson/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/efi/mmap.c (grub_efi_mmap_iterate): Likewise. (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/mmap.c (grub_mmap_iterate): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_mmap_iterate): Update prototype. * include/grub/memory.h (grub_memory_hook_t): Add data argument. Remove NESTED_FUNC_ATTR from here and from all users. (grub_mmap_iterate): Update prototype. (grub_efi_mmap_iterate): Update prototype. Update all callers to pass appropriate hook data. (grub_machine_mmap_iterate): Likewise. * grub-core/commands/acpi.c (grub_acpi_create_ebda: find_hook): Make static instead of nested. * grub-core/commands/lsmmap.c (grub_cmd_lsmmap: hook): Likewise. Rename to ... (lsmmap_hook): ... this. * grub-core/efiemu/mm.c (grub_efiemu_mmap_init: bounds_hook): Likewise. (grub_efiemu_mmap_fill: fill_hook): Likewise. * grub-core/kern/i386/coreboot/init.c (grub_machine_init: heap_init): Likewise. * grub-core/kern/i386/pc/init.c (grub_machine_init: hook): Likewise. Rename to ... (mmap_iterate_hook): ... this. * grub-core/kern/ieee1275/init.c (grub_claim_heap: heap_init): Likewise. * grub-core/lib/ieee1275/relocator.c (grub_relocator_firmware_get_max_events: count): Likewise. (grub_relocator_firmware_fill_events: fill): Likewise. Rename to ... (grub_relocator_firmware_fill_events_iter): ... this. * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align: hook): Likewise. Rename to ... (grub_relocator_alloc_chunk_align_iter): ... this. * grub-core/loader/i386/bsd.c (generate_e820_mmap: hook): Likewise. Rename to ... (generate_e820_mmap_iter): ... this. * grub-core/loader/i386/linux.c (find_mmap_size: hook): Likewise. Rename to ... (count_hook): ... this. (grub_linux_boot: hook): Likewise. Rename to ... (grub_linux_boot_mmap_find): ... this. (grub_linux_boot: hook_fill): Likewise. Rename to ... (grub_linux_boot_mmap_fill): ... this. * grub-core/loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/multiboot.c (grub_get_multiboot_mmap_count: hook): Likewise. Rename to ... (count_hook): ... this. * grub-core/loader/multiboot_mbi2.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_claimmap_iterate: alloc_mem): Likewise. * grub-core/loader/sparc64/ieee1275/linux.c (alloc_phys: choose): Likewise. Rename to ... (alloc_phys_choose): ... this. (determine_phys_base: get_physbase): Likewise. * grub-core/mmap/i386/mmap.c (grub_mmap_malign_and_register: find_hook): Likewise. * grub-core/mmap/i386/pc/mmap.c (preboot: fill_hook): Likewise. (malloc_hook: count_hook): Likewise. * grub-core/mmap/i386/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. (grub_mmap_get_post64: hook): Likewise. Rename to ... (post64_hook): ... this. * grub-core/mmap/mips/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. * grub-core/mmap/mmap.c (grub_mmap_iterate: count_hook): Likewise. (grub_mmap_iterate: fill_hook): Likewise. (fill_mask): Pass addr and mask within a single struct. (grub_cmd_badram: hook): Make static instead of nested. Rename to ... (badram_iter): ... this. (grub_cmd_cutmem: hook): Likewise. Rename to ... (cutmem_iter): ... this.
2013-01-15 12:02:35 +00:00
ctx.ebda_len = (ebda_kb_len + 1) << 10;
/* FIXME: use low-memory mm allocation once it's available. */
Remove nested functions from memory map iterators. * grub-core/efiemu/mm.c (grub_efiemu_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/coreboot/mmap.c (grub_linuxbios_table_iterate): Likewise. (grub_machine_mmap_iterate: iterate_linuxbios_table): Make static instead of nested. (grub_machine_mmap_iterate): Add hook_data argument. * grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/pc/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/arc/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/loongson/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/efi/mmap.c (grub_efi_mmap_iterate): Likewise. (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/mmap.c (grub_mmap_iterate): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_mmap_iterate): Update prototype. * include/grub/memory.h (grub_memory_hook_t): Add data argument. Remove NESTED_FUNC_ATTR from here and from all users. (grub_mmap_iterate): Update prototype. (grub_efi_mmap_iterate): Update prototype. Update all callers to pass appropriate hook data. (grub_machine_mmap_iterate): Likewise. * grub-core/commands/acpi.c (grub_acpi_create_ebda: find_hook): Make static instead of nested. * grub-core/commands/lsmmap.c (grub_cmd_lsmmap: hook): Likewise. Rename to ... (lsmmap_hook): ... this. * grub-core/efiemu/mm.c (grub_efiemu_mmap_init: bounds_hook): Likewise. (grub_efiemu_mmap_fill: fill_hook): Likewise. * grub-core/kern/i386/coreboot/init.c (grub_machine_init: heap_init): Likewise. * grub-core/kern/i386/pc/init.c (grub_machine_init: hook): Likewise. Rename to ... (mmap_iterate_hook): ... this. * grub-core/kern/ieee1275/init.c (grub_claim_heap: heap_init): Likewise. * grub-core/lib/ieee1275/relocator.c (grub_relocator_firmware_get_max_events: count): Likewise. (grub_relocator_firmware_fill_events: fill): Likewise. Rename to ... (grub_relocator_firmware_fill_events_iter): ... this. * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align: hook): Likewise. Rename to ... (grub_relocator_alloc_chunk_align_iter): ... this. * grub-core/loader/i386/bsd.c (generate_e820_mmap: hook): Likewise. Rename to ... (generate_e820_mmap_iter): ... this. * grub-core/loader/i386/linux.c (find_mmap_size: hook): Likewise. Rename to ... (count_hook): ... this. (grub_linux_boot: hook): Likewise. Rename to ... (grub_linux_boot_mmap_find): ... this. (grub_linux_boot: hook_fill): Likewise. Rename to ... (grub_linux_boot_mmap_fill): ... this. * grub-core/loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/multiboot.c (grub_get_multiboot_mmap_count: hook): Likewise. Rename to ... (count_hook): ... this. * grub-core/loader/multiboot_mbi2.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_claimmap_iterate: alloc_mem): Likewise. * grub-core/loader/sparc64/ieee1275/linux.c (alloc_phys: choose): Likewise. Rename to ... (alloc_phys_choose): ... this. (determine_phys_base: get_physbase): Likewise. * grub-core/mmap/i386/mmap.c (grub_mmap_malign_and_register: find_hook): Likewise. * grub-core/mmap/i386/pc/mmap.c (preboot: fill_hook): Likewise. (malloc_hook: count_hook): Likewise. * grub-core/mmap/i386/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. (grub_mmap_get_post64: hook): Likewise. Rename to ... (post64_hook): ... this. * grub-core/mmap/mips/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. * grub-core/mmap/mmap.c (grub_mmap_iterate: count_hook): Likewise. (grub_mmap_iterate: fill_hook): Likewise. (fill_mask): Pass addr and mask within a single struct. (grub_cmd_badram: hook): Make static instead of nested. Rename to ... (badram_iter): ... this. (grub_cmd_cutmem: hook): Likewise. Rename to ... (cutmem_iter): ... this.
2013-01-15 12:02:35 +00:00
grub_mmap_iterate (find_hook, &ctx);
targetebda = (grub_uint8_t *) (grub_addr_t) ctx.highestlow;
grub_dprintf ("acpi", "creating ebda @%llx\n",
Remove nested functions from memory map iterators. * grub-core/efiemu/mm.c (grub_efiemu_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/coreboot/mmap.c (grub_linuxbios_table_iterate): Likewise. (grub_machine_mmap_iterate: iterate_linuxbios_table): Make static instead of nested. (grub_machine_mmap_iterate): Add hook_data argument. * grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/pc/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/arc/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/loongson/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/efi/mmap.c (grub_efi_mmap_iterate): Likewise. (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/mmap.c (grub_mmap_iterate): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_mmap_iterate): Update prototype. * include/grub/memory.h (grub_memory_hook_t): Add data argument. Remove NESTED_FUNC_ATTR from here and from all users. (grub_mmap_iterate): Update prototype. (grub_efi_mmap_iterate): Update prototype. Update all callers to pass appropriate hook data. (grub_machine_mmap_iterate): Likewise. * grub-core/commands/acpi.c (grub_acpi_create_ebda: find_hook): Make static instead of nested. * grub-core/commands/lsmmap.c (grub_cmd_lsmmap: hook): Likewise. Rename to ... (lsmmap_hook): ... this. * grub-core/efiemu/mm.c (grub_efiemu_mmap_init: bounds_hook): Likewise. (grub_efiemu_mmap_fill: fill_hook): Likewise. * grub-core/kern/i386/coreboot/init.c (grub_machine_init: heap_init): Likewise. * grub-core/kern/i386/pc/init.c (grub_machine_init: hook): Likewise. Rename to ... (mmap_iterate_hook): ... this. * grub-core/kern/ieee1275/init.c (grub_claim_heap: heap_init): Likewise. * grub-core/lib/ieee1275/relocator.c (grub_relocator_firmware_get_max_events: count): Likewise. (grub_relocator_firmware_fill_events: fill): Likewise. Rename to ... (grub_relocator_firmware_fill_events_iter): ... this. * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align: hook): Likewise. Rename to ... (grub_relocator_alloc_chunk_align_iter): ... this. * grub-core/loader/i386/bsd.c (generate_e820_mmap: hook): Likewise. Rename to ... (generate_e820_mmap_iter): ... this. * grub-core/loader/i386/linux.c (find_mmap_size: hook): Likewise. Rename to ... (count_hook): ... this. (grub_linux_boot: hook): Likewise. Rename to ... (grub_linux_boot_mmap_find): ... this. (grub_linux_boot: hook_fill): Likewise. Rename to ... (grub_linux_boot_mmap_fill): ... this. * grub-core/loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/multiboot.c (grub_get_multiboot_mmap_count: hook): Likewise. Rename to ... (count_hook): ... this. * grub-core/loader/multiboot_mbi2.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_claimmap_iterate: alloc_mem): Likewise. * grub-core/loader/sparc64/ieee1275/linux.c (alloc_phys: choose): Likewise. Rename to ... (alloc_phys_choose): ... this. (determine_phys_base: get_physbase): Likewise. * grub-core/mmap/i386/mmap.c (grub_mmap_malign_and_register: find_hook): Likewise. * grub-core/mmap/i386/pc/mmap.c (preboot: fill_hook): Likewise. (malloc_hook: count_hook): Likewise. * grub-core/mmap/i386/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. (grub_mmap_get_post64: hook): Likewise. Rename to ... (post64_hook): ... this. * grub-core/mmap/mips/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. * grub-core/mmap/mmap.c (grub_mmap_iterate: count_hook): Likewise. (grub_mmap_iterate: fill_hook): Likewise. (fill_mask): Pass addr and mask within a single struct. (grub_cmd_badram: hook): Make static instead of nested. Rename to ... (badram_iter): ... this. (grub_cmd_cutmem: hook): Likewise. Rename to ... (cutmem_iter): ... this.
2013-01-15 12:02:35 +00:00
(unsigned long long) ctx.highestlow);
if (! ctx.highestlow)
2009-06-10 21:04:23 +00:00
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't find space for the new EBDA");
Remove nested functions from memory map iterators. * grub-core/efiemu/mm.c (grub_efiemu_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/coreboot/mmap.c (grub_linuxbios_table_iterate): Likewise. (grub_machine_mmap_iterate: iterate_linuxbios_table): Make static instead of nested. (grub_machine_mmap_iterate): Add hook_data argument. * grub-core/kern/i386/multiboot_mmap.c (grub_machine_mmap_iterate): Add hook_data argument, passed to hook. * grub-core/kern/i386/pc/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/i386/qemu/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/ieee1275/mmap.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/arc/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/loongson/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/kern/mips/qemu_mips/init.c (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/efi/mmap.c (grub_efi_mmap_iterate): Likewise. (grub_machine_mmap_iterate): Likewise. * grub-core/mmap/mmap.c (grub_mmap_iterate): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_mmap_iterate): Update prototype. * include/grub/memory.h (grub_memory_hook_t): Add data argument. Remove NESTED_FUNC_ATTR from here and from all users. (grub_mmap_iterate): Update prototype. (grub_efi_mmap_iterate): Update prototype. Update all callers to pass appropriate hook data. (grub_machine_mmap_iterate): Likewise. * grub-core/commands/acpi.c (grub_acpi_create_ebda: find_hook): Make static instead of nested. * grub-core/commands/lsmmap.c (grub_cmd_lsmmap: hook): Likewise. Rename to ... (lsmmap_hook): ... this. * grub-core/efiemu/mm.c (grub_efiemu_mmap_init: bounds_hook): Likewise. (grub_efiemu_mmap_fill: fill_hook): Likewise. * grub-core/kern/i386/coreboot/init.c (grub_machine_init: heap_init): Likewise. * grub-core/kern/i386/pc/init.c (grub_machine_init: hook): Likewise. Rename to ... (mmap_iterate_hook): ... this. * grub-core/kern/ieee1275/init.c (grub_claim_heap: heap_init): Likewise. * grub-core/lib/ieee1275/relocator.c (grub_relocator_firmware_get_max_events: count): Likewise. (grub_relocator_firmware_fill_events: fill): Likewise. Rename to ... (grub_relocator_firmware_fill_events_iter): ... this. * grub-core/lib/relocator.c (grub_relocator_alloc_chunk_align: hook): Likewise. Rename to ... (grub_relocator_alloc_chunk_align_iter): ... this. * grub-core/loader/i386/bsd.c (generate_e820_mmap: hook): Likewise. Rename to ... (generate_e820_mmap_iter): ... this. * grub-core/loader/i386/linux.c (find_mmap_size: hook): Likewise. Rename to ... (count_hook): ... this. (grub_linux_boot: hook): Likewise. Rename to ... (grub_linux_boot_mmap_find): ... this. (grub_linux_boot: hook_fill): Likewise. Rename to ... (grub_linux_boot_mmap_fill): ... this. * grub-core/loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/multiboot.c (grub_get_multiboot_mmap_count: hook): Likewise. Rename to ... (count_hook): ... this. * grub-core/loader/multiboot_mbi2.c (grub_fill_multiboot_mmap: hook): Likewise. Rename to ... (grub_fill_multiboot_mmap_iter): ... this. * grub-core/loader/powerpc/ieee1275/linux.c (grub_linux_claimmap_iterate: alloc_mem): Likewise. * grub-core/loader/sparc64/ieee1275/linux.c (alloc_phys: choose): Likewise. Rename to ... (alloc_phys_choose): ... this. (determine_phys_base: get_physbase): Likewise. * grub-core/mmap/i386/mmap.c (grub_mmap_malign_and_register: find_hook): Likewise. * grub-core/mmap/i386/pc/mmap.c (preboot: fill_hook): Likewise. (malloc_hook: count_hook): Likewise. * grub-core/mmap/i386/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. (grub_mmap_get_post64: hook): Likewise. Rename to ... (post64_hook): ... this. * grub-core/mmap/mips/uppermem.c (grub_mmap_get_lower: hook): Likewise. Rename to ... (lower_hook): ... this. (grub_mmap_get_upper: hook): Likewise. Rename to ... (upper_hook): ... this. * grub-core/mmap/mmap.c (grub_mmap_iterate: count_hook): Likewise. (grub_mmap_iterate: fill_hook): Likewise. (fill_mask): Pass addr and mask within a single struct. (grub_cmd_badram: hook): Make static instead of nested. Rename to ... (badram_iter): ... this. (grub_cmd_cutmem: hook): Likewise. Rename to ... (cutmem_iter): ... this.
2013-01-15 12:02:35 +00:00
mmapregion = grub_mmap_register ((grub_addr_t) targetebda, ctx.ebda_len,
2010-09-04 15:10:10 +00:00
GRUB_MEMORY_RESERVED);
if (! mmapregion)
return grub_errno;
/* XXX: EBDA is unstandardized, so this implementation is heuristical. */
if (ebda_kb_len)
grub_memcpy (targetebda, ebda, 0x400);
else
grub_memset (targetebda, 0, 0x400);
*((grub_uint16_t *) targetebda) = ebda_kb_len + 1;
target = targetebda;
v1 = grub_acpi_get_rsdpv1 ();
v2 = grub_acpi_get_rsdpv2 ();
if (v2 && v2->length > 40)
v2 = 0;
2009-06-10 21:04:23 +00:00
/* First try to replace already existing rsdp. */
if (v2)
{
grub_dprintf ("acpi", "Scanning EBDA for old rsdpv2\n");
for (; target < targetebda + 0x400 - v2->length; target += 0x10)
if (grub_memcmp (target, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0
2009-06-10 21:04:23 +00:00
&& grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0
&& ((struct grub_acpi_rsdp_v10 *) target)->revision != 0
&& ((struct grub_acpi_rsdp_v20 *) target)->length <= v2->length)
{
grub_memcpy (target, v2, v2->length);
grub_dprintf ("acpi", "Copying rsdpv2 to %p\n", target);
v2inebda = target;
target += v2->length;
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v2 = 0;
break;
}
}
if (v1)
{
grub_dprintf ("acpi", "Scanning EBDA for old rsdpv1\n");
2009-06-10 21:04:23 +00:00
for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10)
if (grub_memcmp (target, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0
2009-06-10 21:04:23 +00:00
&& grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0)
{
grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10));
grub_dprintf ("acpi", "Copying rsdpv1 to %p\n", target);
v1inebda = target;
target += sizeof (struct grub_acpi_rsdp_v10);
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v1 = 0;
break;
}
}
target = targetebda + 0x100;
/* Try contiguous zeros. */
if (v2)
{
grub_dprintf ("acpi", "Scanning EBDA for block of zeros\n");
for (; target < targetebda + 0x400 - v2->length; target += 0x10)
if (iszero (target, v2->length))
{
grub_dprintf ("acpi", "Copying rsdpv2 to %p\n", target);
grub_memcpy (target, v2, v2->length);
v2inebda = target;
target += v2->length;
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v2 = 0;
break;
}
}
if (v1)
{
grub_dprintf ("acpi", "Scanning EBDA for block of zeros\n");
2009-06-10 21:04:23 +00:00
for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10)
if (iszero (target, sizeof (struct grub_acpi_rsdp_v10)))
{
grub_dprintf ("acpi", "Copying rsdpv1 to %p\n", target);
grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10));
v1inebda = target;
target += sizeof (struct grub_acpi_rsdp_v10);
target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16);
v1 = 0;
break;
}
}
if (v1 || v2)
{
grub_mmap_unregister (mmapregion);
2009-06-10 21:04:23 +00:00
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
2009-12-24 Carles Pina i Estany <carles@pina.cat> * bus/usb/usbhub.c: Fix capitalization, fullstop and newlines in grub_errno calls. * commands/acpi.c: Likewise. * commands/blocklist.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/loadenv.c: Likewise. * commands/memrw.c: Likewise. * commands/password.c: Likewise. * commands/videotest.c: Likewise. * disk/ata.c: Likewise. * disk/ata_pthru.c: Likewise. * disk/dmraid_nvidia.c: Likewise. * disk/ieee1275/nand.c: Likewise. * disk/ieee1275/ofdisk.c: Likewise. * disk/loopback.c: Likewise. * disk/lvm.c: Likewise. * disk/mdraid_linux.c: Likewise. * disk/raid.c: Likewise. * disk/raid6_recover.c: Likewise. * disk/scsi.c: Likewise. * efiemu/main.c: Likewise. * efiemu/mm.c: Likewise. * efiemu/pnvram.c: Likewise. * efiemu/symbols.c: Likewise. * font/font.c: Likewise. * fs/cpio.c: Likewise. * fs/hfsplus.c: Likewise. * fs/iso9660.c: Likewise. * fs/jfs.c: Likewise. * fs/minix.c: Likewise. * fs/ntfs.c: Likewise. * fs/ntfscomp.c: Likewise. * fs/reiserfs.c: Likewise. * fs/ufs.c: Likewise. * fs/xfs.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/auth.h: Likewise. * kern/elf.c: Likewise. * kern/file.c: Likewise. * kern/ieee1275/init.c: Likewise. * kern/ieee1275/mmap.c: Likewise. * kern/ieee1275/openfw.c: Likewise. * kern/powerpc/dl.c: Likewise. * kern/sparc64/dl.c: Likewise. * lib/arg.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/bsdXX.c: Likewise. * loader/i386/efi/linux.c: Likewise. * loader/i386/efi/xnu.c: Likewise. * loader/i386/ieee1275/linux.c: Likewise. * loader/i386/linux.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot2.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/ieee1275/multiboot2.c: Likewise. * loader/macho.c: Likewise. * loader/machoXX.c: Likewise. * loader/multiboot2.c: Likewise. * loader/multiboot_loader.c: Likewise. * loader/powerpc/ieee1275/linux.c: Likewise. * loader/sparc64/ieee1275/linux.c: Likewise. * loader/xnu.c: Likewise. * loader/xnu_resume.c: Likewise. * mmap/i386/pc/mmap.c: Likewise. * normal/menu_viewer.c: Likewise. * partmap/acorn.c: Likewise. * partmap/amiga.c: Likewise. * partmap/apple.c: Likewise. * script/lexer.c: Likewise. * term/gfxterm.c: Likewise. * term/i386/pc/serial.c: Likewise. * term/i386/pc/vga.c: Likewise. * term/ieee1275/ofconsole.c: Likewise. * term/terminfo.c: Likewise. * video/bitmap.c: Likewise. * video/efi_gop.c: Likewise. * video/efi_uga.c: Likewise. * video/fb/video_fb.c: Likewise. * video/i386/pc/vbe.c: Likewise. * video/readers/tga.c: Likewise. * video/video.c: Likewise.
2009-12-24 22:53:05 +00:00
"couldn't find suitable spot in EBDA");
}
/* Remove any other RSDT. */
2009-06-10 21:04:23 +00:00
for (target = targetebda;
target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10)
if (grub_memcmp (target, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0
2009-06-10 21:04:23 +00:00
&& grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0
&& target != v1inebda && target != v2inebda)
*target = 0;
grub_dprintf ("acpi", "Switching EBDA\n");
(*((grub_uint16_t *) 0x40e)) = ((grub_addr_t) targetebda) >> 4;
grub_dprintf ("acpi", "EBDA switched\n");
return GRUB_ERR_NONE;
}
#endif
/* Create tables common to ACPIv1 and ACPIv2+ */
static void
setup_common_tables (void)
{
struct efiemu_acpi_table *cur;
struct grub_acpi_table_header *rsdt;
grub_uint32_t *rsdt_entry;
int numoftables;
/* Treat DSDT. */
grub_memcpy (playground_ptr, table_dsdt, dsdt_size);
grub_free (table_dsdt);
table_dsdt = playground_ptr;
playground_ptr += dsdt_size;
2009-06-10 21:04:23 +00:00
/* Treat other tables. */
for (cur = acpi_tables; cur; cur = cur->next)
{
struct grub_acpi_fadt *fadt;
grub_memcpy (playground_ptr, cur->addr, cur->size);
grub_free (cur->addr);
cur->addr = playground_ptr;
playground_ptr += cur->size;
/* If it's FADT correct DSDT and FACS addresses. */
fadt = (struct grub_acpi_fadt *) cur->addr;
if (grub_memcmp (fadt->hdr.signature, GRUB_ACPI_FADT_SIGNATURE,
sizeof (fadt->hdr.signature)) == 0)
{
fadt->dsdt_addr = (grub_addr_t) table_dsdt;
fadt->facs_addr = facs_addr;
/* Does a revision 2 exist at all? */
if (fadt->hdr.revision >= 3)
{
fadt->dsdt_xaddr = (grub_addr_t) table_dsdt;
fadt->facs_xaddr = facs_addr;
}
/* Recompute checksum. */
fadt->hdr.checksum = 0;
fadt->hdr.checksum = 1 + ~grub_byte_checksum (fadt, fadt->hdr.length);
}
}
2009-06-10 21:04:23 +00:00
/* Fill RSDT entries. */
numoftables = 0;
for (cur = acpi_tables; cur; cur = cur->next)
numoftables++;
rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_table_header) + sizeof (grub_uint32_t) * numoftables;
rsdt_entry = (grub_uint32_t *) (rsdt + 1);
/* Fill RSDT header. */
grub_memcpy (&(rsdt->signature), "RSDT", 4);
rsdt->length = sizeof (struct grub_acpi_table_header) + sizeof (grub_uint32_t) * numoftables;
rsdt->revision = 1;
grub_memcpy (&(rsdt->oemid), root_oemid, sizeof (rsdt->oemid));
grub_memcpy (&(rsdt->oemtable), root_oemtable, sizeof (rsdt->oemtable));
rsdt->oemrev = root_oemrev;
grub_memcpy (&(rsdt->creator_id), root_creator_id, sizeof (rsdt->creator_id));
rsdt->creator_rev = root_creator_rev;
for (cur = acpi_tables; cur; cur = cur->next)
*(rsdt_entry++) = (grub_addr_t) cur->addr;
2009-06-10 21:04:23 +00:00
/* Recompute checksum. */
rsdt->checksum = 0;
rsdt->checksum = 1 + ~grub_byte_checksum (rsdt, rsdt->length);
}
/* Regenerate ACPIv1 RSDP */
static void
setv1table (void)
{
/* Create RSDP. */
rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_rsdp_v10);
grub_memcpy (&(rsdpv1_new->signature), GRUB_RSDP_SIGNATURE,
sizeof (rsdpv1_new->signature));
grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid));
rsdpv1_new->revision = 0;
rsdpv1_new->rsdt_addr = (grub_addr_t) rsdt_addr;
rsdpv1_new->checksum = 0;
2009-06-10 21:04:23 +00:00
rsdpv1_new->checksum = 1 + ~grub_byte_checksum (rsdpv1_new,
sizeof (*rsdpv1_new));
grub_dprintf ("acpi", "Generated ACPIv1 tables\n");
}
static void
setv2table (void)
{
struct grub_acpi_table_header *xsdt;
struct efiemu_acpi_table *cur;
grub_uint64_t *xsdt_entry;
int numoftables;
numoftables = 0;
for (cur = acpi_tables; cur; cur = cur->next)
numoftables++;
/* Create XSDT. */
xsdt = (struct grub_acpi_table_header *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_table_header) + sizeof (grub_uint64_t) * numoftables;
xsdt_entry = (grub_uint64_t *)(xsdt + 1);
for (cur = acpi_tables; cur; cur = cur->next)
*(xsdt_entry++) = (grub_addr_t) cur->addr;
grub_memcpy (&(xsdt->signature), "XSDT", 4);
xsdt->length = sizeof (struct grub_acpi_table_header) + sizeof (grub_uint64_t) * numoftables;
xsdt->revision = 1;
grub_memcpy (&(xsdt->oemid), root_oemid, sizeof (xsdt->oemid));
grub_memcpy (&(xsdt->oemtable), root_oemtable, sizeof (xsdt->oemtable));
xsdt->oemrev = root_oemrev;
grub_memcpy (&(xsdt->creator_id), root_creator_id, sizeof (xsdt->creator_id));
xsdt->creator_rev = root_creator_rev;
xsdt->checksum = 0;
xsdt->checksum = 1 + ~grub_byte_checksum (xsdt, xsdt->length);
/* Create RSDPv2. */
rsdpv2_new = (struct grub_acpi_rsdp_v20 *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_rsdp_v20);
grub_memcpy (&(rsdpv2_new->rsdpv1.signature), GRUB_RSDP_SIGNATURE,
sizeof (rsdpv2_new->rsdpv1.signature));
2009-06-10 21:04:23 +00:00
grub_memcpy (&(rsdpv2_new->rsdpv1.oemid), root_oemid,
sizeof (rsdpv2_new->rsdpv1.oemid));
rsdpv2_new->rsdpv1.revision = rev2;
rsdpv2_new->rsdpv1.rsdt_addr = (grub_addr_t) rsdt_addr;
rsdpv2_new->rsdpv1.checksum = 0;
2009-06-10 21:04:23 +00:00
rsdpv2_new->rsdpv1.checksum = 1 + ~grub_byte_checksum
(&(rsdpv2_new->rsdpv1), sizeof (rsdpv2_new->rsdpv1));
rsdpv2_new->length = sizeof (*rsdpv2_new);
rsdpv2_new->xsdt_addr = (grub_addr_t) xsdt;
rsdpv2_new->checksum = 0;
2009-06-10 21:04:23 +00:00
rsdpv2_new->checksum = 1 + ~grub_byte_checksum (rsdpv2_new,
rsdpv2_new->length);
grub_dprintf ("acpi", "Generated ACPIv2 tables\n");
}
static void
free_tables (void)
{
struct efiemu_acpi_table *cur, *t;
if (table_dsdt)
grub_free (table_dsdt);
for (cur = acpi_tables; cur;)
{
t = cur;
grub_free (cur->addr);
cur = cur->next;
grub_free (t);
}
acpi_tables = 0;
table_dsdt = 0;
}
static grub_err_t
2010-06-10 06:42:03 +00:00
grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
{
2010-06-10 06:42:03 +00:00
struct grub_arg_list *state = ctxt->state;
struct grub_acpi_rsdp_v10 *rsdp;
struct efiemu_acpi_table *cur, *t;
int i, mmapregion;
int numoftables;
2009-06-10 21:04:23 +00:00
/* Default values if no RSDP is found. */
rev1 = 1;
rev2 = 3;
facs_addr = 0;
playground = playground_ptr = 0;
playground_size = 0;
2009-06-10 21:04:23 +00:00
rsdp = (struct grub_acpi_rsdp_v10 *) grub_machine_acpi_get_rsdpv2 ();
if (! rsdp)
rsdp = grub_machine_acpi_get_rsdpv1 ();
grub_dprintf ("acpi", "RSDP @%p\n", rsdp);
if (rsdp)
{
grub_uint32_t *entry_ptr;
char *exclude = 0;
char *load_only = 0;
char *ptr;
/* RSDT consists of header and an array of 32-bit pointers. */
struct grub_acpi_table_header *rsdt;
exclude = state[0].set ? grub_strdup (state[0].arg) : 0;
if (exclude)
{
for (ptr = exclude; *ptr; ptr++)
*ptr = grub_tolower (*ptr);
}
load_only = state[1].set ? grub_strdup (state[1].arg) : 0;
if (load_only)
{
for (ptr = load_only; *ptr; ptr++)
*ptr = grub_tolower (*ptr);
}
/* Set revision variables to replicate the same version as host. */
rev1 = ! rsdp->revision;
rev2 = rsdp->revision;
rsdt = (struct grub_acpi_table_header *) (grub_addr_t) rsdp->rsdt_addr;
/* Load host tables. */
for (entry_ptr = (grub_uint32_t *) (rsdt + 1);
2009-06-10 21:04:23 +00:00
entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt)
+ rsdt->length);
entry_ptr++)
{
char signature[5];
struct efiemu_acpi_table *table;
2009-06-10 21:04:23 +00:00
struct grub_acpi_table_header *curtable
= (struct grub_acpi_table_header *) (grub_addr_t) *entry_ptr;
signature[4] = 0;
for (i = 0; i < 4;i++)
signature[i] = grub_tolower (curtable->signature[i]);
2009-06-10 21:04:23 +00:00
/* If it's FADT it contains addresses of DSDT and FACS. */
if (grub_strcmp (signature, "facp") == 0)
{
struct grub_acpi_table_header *dsdt;
struct grub_acpi_fadt *fadt = (struct grub_acpi_fadt *) curtable;
2009-06-10 21:04:23 +00:00
/* Set root header variables to the same values
as FADT by default. */
2009-06-10 21:04:23 +00:00
grub_memcpy (&root_oemid, &(fadt->hdr.oemid),
sizeof (root_oemid));
2009-06-10 21:04:23 +00:00
grub_memcpy (&root_oemtable, &(fadt->hdr.oemtable),
sizeof (root_oemtable));
root_oemrev = fadt->hdr.oemrev;
2009-06-10 21:04:23 +00:00
grub_memcpy (&root_creator_id, &(fadt->hdr.creator_id),
sizeof (root_creator_id));
root_creator_rev = fadt->hdr.creator_rev;
/* Load DSDT if not excluded. */
2009-06-10 21:04:23 +00:00
dsdt = (struct grub_acpi_table_header *)
(grub_addr_t) fadt->dsdt_addr;
if (dsdt && (! exclude || ! grub_strword (exclude, "dsdt"))
&& (! load_only || grub_strword (load_only, "dsdt"))
&& dsdt->length >= sizeof (*dsdt))
{
dsdt_size = dsdt->length;
table_dsdt = grub_malloc (dsdt->length);
if (! table_dsdt)
{
free_tables ();
grub_free (exclude);
grub_free (load_only);
return grub_errno;
}
grub_memcpy (table_dsdt, dsdt, dsdt->length);
}
/* Save FACS address. FACS shouldn't be overridden. */
facs_addr = fadt->facs_addr;
}
2009-06-10 21:04:23 +00:00
/* Skip excluded tables. */
if (exclude && grub_strword (exclude, signature))
continue;
if (load_only && ! grub_strword (load_only, signature))
continue;
/* Sanity check. */
if (curtable->length < sizeof (*curtable))
continue;
2009-06-10 21:04:23 +00:00
table = (struct efiemu_acpi_table *) grub_malloc
(sizeof (struct efiemu_acpi_table));
if (! table)
{
free_tables ();
grub_free (exclude);
grub_free (load_only);
return grub_errno;
}
table->size = curtable->length;
table->addr = grub_malloc (table->size);
playground_size += table->size;
if (! table->addr)
{
free_tables ();
grub_free (exclude);
grub_free (load_only);
grub_free (table);
return grub_errno;
}
table->next = acpi_tables;
acpi_tables = table;
grub_memcpy (table->addr, curtable, table->size);
}
grub_free (exclude);
2009-06-10 21:04:23 +00:00
grub_free (load_only);
}
/* Does user specify versions to generate? */
if (state[2].set || state[3].set)
{
rev1 = state[2].set;
if (state[3].set)
rev2 = rev2 ? : 2;
else
rev2 = 0;
}
/* Does user override root header information? */
if (state[4].set)
grub_strncpy (root_oemid, state[4].arg, sizeof (root_oemid));
if (state[5].set)
grub_strncpy (root_oemtable, state[5].arg, sizeof (root_oemtable));
if (state[6].set)
root_oemrev = grub_strtoul (state[6].arg, 0, 0);
if (state[7].set)
grub_strncpy (root_creator_id, state[7].arg, sizeof (root_creator_id));
if (state[8].set)
root_creator_rev = grub_strtoul (state[8].arg, 0, 0);
/* Load user tables */
for (i = 0; i < argc; i++)
{
grub_file_t file;
grub_size_t size;
char *buf;
file = grub_file_open (args[i], GRUB_FILE_TYPE_ACPI_TABLE);
if (! file)
{
free_tables ();
return grub_errno;
}
size = grub_file_size (file);
if (size < sizeof (struct grub_acpi_table_header))
{
grub_file_close (file);
free_tables ();
return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
args[i]);
}
buf = (char *) grub_malloc (size);
if (! buf)
{
grub_file_close (file);
free_tables ();
return grub_errno;
}
if (grub_file_read (file, buf, size) != (int) size)
{
grub_file_close (file);
free_tables ();
if (!grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
args[i]);
return grub_errno;
}
2009-06-10 21:04:23 +00:00
grub_file_close (file);
2009-06-10 21:04:23 +00:00
if (grub_memcmp (((struct grub_acpi_table_header *) buf)->signature,
"DSDT", 4) == 0)
{
grub_free (table_dsdt);
table_dsdt = buf;
dsdt_size = size;
}
else
{
struct efiemu_acpi_table *table;
2009-06-10 21:04:23 +00:00
table = (struct efiemu_acpi_table *) grub_malloc
(sizeof (struct efiemu_acpi_table));
if (! table)
{
free_tables ();
return grub_errno;
}
table->size = size;
table->addr = buf;
playground_size += table->size;
table->next = acpi_tables;
acpi_tables = table;
}
}
numoftables = 0;
for (cur = acpi_tables; cur; cur = cur->next)
numoftables++;
/* DSDT. */
playground_size += dsdt_size;
/* RSDT. */
playground_size += sizeof (struct grub_acpi_table_header) + sizeof (grub_uint32_t) * numoftables;
/* RSDPv1. */
playground_size += sizeof (struct grub_acpi_rsdp_v10);
/* XSDT. */
playground_size += sizeof (struct grub_acpi_table_header) + sizeof (grub_uint64_t) * numoftables;
/* RSDPv2. */
playground_size += sizeof (struct grub_acpi_rsdp_v20);
2009-06-10 21:04:23 +00:00
playground = playground_ptr
= grub_mmap_malign_and_register (1, playground_size, &mmapregion,
2010-09-04 15:10:10 +00:00
GRUB_MEMORY_ACPI, 0);
if (! playground)
{
free_tables ();
2009-06-10 21:04:23 +00:00
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
2009-12-24 Carles Pina i Estany <carles@pina.cat> * bus/usb/usbhub.c: Fix capitalization, fullstop and newlines in grub_errno calls. * commands/acpi.c: Likewise. * commands/blocklist.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/loadenv.c: Likewise. * commands/memrw.c: Likewise. * commands/password.c: Likewise. * commands/videotest.c: Likewise. * disk/ata.c: Likewise. * disk/ata_pthru.c: Likewise. * disk/dmraid_nvidia.c: Likewise. * disk/ieee1275/nand.c: Likewise. * disk/ieee1275/ofdisk.c: Likewise. * disk/loopback.c: Likewise. * disk/lvm.c: Likewise. * disk/mdraid_linux.c: Likewise. * disk/raid.c: Likewise. * disk/raid6_recover.c: Likewise. * disk/scsi.c: Likewise. * efiemu/main.c: Likewise. * efiemu/mm.c: Likewise. * efiemu/pnvram.c: Likewise. * efiemu/symbols.c: Likewise. * font/font.c: Likewise. * fs/cpio.c: Likewise. * fs/hfsplus.c: Likewise. * fs/iso9660.c: Likewise. * fs/jfs.c: Likewise. * fs/minix.c: Likewise. * fs/ntfs.c: Likewise. * fs/ntfscomp.c: Likewise. * fs/reiserfs.c: Likewise. * fs/ufs.c: Likewise. * fs/xfs.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/auth.h: Likewise. * kern/elf.c: Likewise. * kern/file.c: Likewise. * kern/ieee1275/init.c: Likewise. * kern/ieee1275/mmap.c: Likewise. * kern/ieee1275/openfw.c: Likewise. * kern/powerpc/dl.c: Likewise. * kern/sparc64/dl.c: Likewise. * lib/arg.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/bsdXX.c: Likewise. * loader/i386/efi/linux.c: Likewise. * loader/i386/efi/xnu.c: Likewise. * loader/i386/ieee1275/linux.c: Likewise. * loader/i386/linux.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot2.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/ieee1275/multiboot2.c: Likewise. * loader/macho.c: Likewise. * loader/machoXX.c: Likewise. * loader/multiboot2.c: Likewise. * loader/multiboot_loader.c: Likewise. * loader/powerpc/ieee1275/linux.c: Likewise. * loader/sparc64/ieee1275/linux.c: Likewise. * loader/xnu.c: Likewise. * loader/xnu_resume.c: Likewise. * mmap/i386/pc/mmap.c: Likewise. * normal/menu_viewer.c: Likewise. * partmap/acorn.c: Likewise. * partmap/amiga.c: Likewise. * partmap/apple.c: Likewise. * script/lexer.c: Likewise. * term/gfxterm.c: Likewise. * term/i386/pc/serial.c: Likewise. * term/i386/pc/vga.c: Likewise. * term/ieee1275/ofconsole.c: Likewise. * term/terminfo.c: Likewise. * video/bitmap.c: Likewise. * video/efi_gop.c: Likewise. * video/efi_uga.c: Likewise. * video/fb/video_fb.c: Likewise. * video/i386/pc/vbe.c: Likewise. * video/readers/tga.c: Likewise. * video/video.c: Likewise.
2009-12-24 22:53:05 +00:00
"couldn't allocate space for ACPI tables");
}
setup_common_tables ();
/* Request space for RSDPv1. */
if (rev1)
setv1table ();
/* Request space for RSDPv2+ and XSDT. */
if (rev2)
setv2table ();
for (cur = acpi_tables; cur;)
{
t = cur;
cur = cur->next;
grub_free (t);
}
acpi_tables = 0;
#if defined (__i386__) || defined (__x86_64__)
if (! state[9].set)
{
grub_err_t err;
err = grub_acpi_create_ebda ();
if (err)
{
rsdpv1_new = 0;
rsdpv2_new = 0;
grub_mmap_free_and_unregister (mmapregion);
return err;
}
}
#endif
#ifdef GRUB_MACHINE_EFI
{
struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table,
&acpi20, grub_acpi_get_rsdpv2 ());
efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table,
&acpi, grub_acpi_get_rsdpv1 ());
}
#endif
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(acpi)
{
cmd = grub_register_extcmd ("acpi", grub_cmd_acpi, 0,
N_("[-1|-2] [--exclude=TABLE1,TABLE2|"
"--load-only=TABLE1,TABLE2] FILE1"
" [FILE2] [...]"),
N_("Load host ACPI tables and tables "
2010-01-03 Carles Pina i Estany <carles@pina.cat> * commands/acpi.c: Gettextizze help strings and/or options. Include `grub/i18n.h' if needed. * commands/blocklist.c: Likewise. * commands/boot.c: Likewise. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/configfile.c: Likewise. * commands/crc.c: Likewise. * commands/date.c: Likewise. * commands/echo.c: Likewise. * commands/efi/fixvideo.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/gptsync.c: Likewise. * commands/halt.c: Likewise. * commands/handler.c: Likewise. * commands/hdparm.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/cpuid.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/pxecmd.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/i386/pc/vbetest.c: Likewise. * commands/ieee1275/suspend.c: Likewise. * commands/keystatus.c: Likewise. * commands/loadenv.c: Likewise. * commands/ls.c: Likewise. * commands/lsmmap.c: Likewise. * commands/lspci.c: Likewise. * commands/memrw.c: Likewise. * commands/minicmd.c: Likewise. * commands/parttool.c: Likewise. * commands/password.c: Likewise. * commands/probe.c: Likewise. * commands/read.c: Likewise. * commands/reboot.c: Likewise. * commands/search.c: Likewise. * commands/sleep.c: Likewise. * commands/test.c: Likewise. * commands/true.c: Likewise. * commands/usbtest.c: Likewise. * commands/videotest.c: Likewise. * commands/xnu_uuid.c: Likewise. * disk/loopback.c: Likewise. * hello/hello.c: Likewise. * loader/i386/bsd.c: Likewise. * term/i386/pc/serial.c: Likewise. * po/POTFILES: Add new files.
2010-01-03 18:24:22 +00:00
"specified by arguments."),
options);
}
GRUB_MOD_FINI(acpi)
{
grub_unregister_extcmd (cmd);
}