2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2007,2008 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/machine/memory.h>
2N/A#include <grub/machine/lbio.h>
2N/A#include <grub/types.h>
2N/A#include <grub/err.h>
2N/A#include <grub/misc.h>
2N/A
2N/Astatic grub_err_t
2N/Agrub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t))
2N/A{
2N/A grub_linuxbios_table_header_t table_header;
2N/A grub_linuxbios_table_item_t table_item;
2N/A
2N/A auto int check_signature (grub_linuxbios_table_header_t);
2N/A int check_signature (grub_linuxbios_table_header_t tbl_header)
2N/A {
2N/A if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
2N/A return 1;
2N/A
2N/A return 0;
2N/A }
2N/A
2N/A /* Assuming table_header is aligned to its size (8 bytes). */
2N/A
2N/A for (table_header = (grub_linuxbios_table_header_t) 0x500;
2N/A table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++)
2N/A if (check_signature (table_header))
2N/A goto signature_found;
2N/A
2N/A for (table_header = (grub_linuxbios_table_header_t) 0xf0000;
2N/A table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++)
2N/A if (check_signature (table_header))
2N/A goto signature_found;
2N/A
2N/A grub_fatal ("Could not find coreboot table\n");
2N/A
2N/Asignature_found:
2N/A
2N/A table_item =
2N/A (grub_linuxbios_table_item_t) ((long) table_header +
2N/A (long) table_header->size);
2N/A for (; table_item->size;
2N/A table_item = (grub_linuxbios_table_item_t) ((long) table_item + (long) table_item->size))
2N/A {
2N/A if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
2N/A && check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
2N/A *(grub_uint64_t *) (table_item + 1)))
2N/A {
2N/A table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
2N/A *(grub_uint64_t *) (table_item + 1);
2N/A goto signature_found;
2N/A }
2N/A if (hook (table_item))
2N/A return 1;
2N/A }
2N/A
2N/A return 0;
2N/A}
2N/A
2N/Agrub_err_t
2N/Agrub_machine_mmap_iterate (grub_memory_hook_t hook)
2N/A{
2N/A mem_region_t mem_region;
2N/A
2N/A auto int iterate_linuxbios_table (grub_linuxbios_table_item_t);
2N/A int iterate_linuxbios_table (grub_linuxbios_table_item_t table_item)
2N/A {
2N/A if (table_item->tag != GRUB_LINUXBIOS_MEMBER_MEMORY)
2N/A return 0;
2N/A
2N/A mem_region =
2N/A (mem_region_t) ((long) table_item +
2N/A sizeof (struct grub_linuxbios_table_item));
2N/A while ((long) mem_region < (long) table_item + (long) table_item->size)
2N/A {
2N/A if (hook (mem_region->addr, mem_region->size,
2N/A /* Multiboot mmaps match with the coreboot mmap definition.
2N/A Therefore, we can just pass type through. */
2N/A mem_region->type))
2N/A return 1;
2N/A
2N/A mem_region++;
2N/A }
2N/A
2N/A return 0;
2N/A }
2N/A
2N/A grub_linuxbios_table_iterate (iterate_linuxbios_table);
2N/A
2N/A return 0;
2N/A}