120 lines
3.5 KiB
C
120 lines
3.5 KiB
C
/*
|
|
* VasEBoot -- GRand Unified Bootloader
|
|
* Copyright (C) 2012 Free Software Foundation, Inc.
|
|
*
|
|
* VasEBoot 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.
|
|
*
|
|
* VasEBoot 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 VasEBoot. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <VasEBoot/types.h>
|
|
#include <VasEBoot/time.h>
|
|
#include <VasEBoot/misc.h>
|
|
#include <VasEBoot/acpi.h>
|
|
|
|
/* Simple checksum by summing all bytes. Used by ACPI and SMBIOS. */
|
|
VasEBoot_uint8_t
|
|
VasEBoot_byte_checksum (void *base, VasEBoot_size_t size)
|
|
{
|
|
VasEBoot_uint8_t *ptr;
|
|
VasEBoot_uint8_t ret = 0;
|
|
for (ptr = (VasEBoot_uint8_t *) base; ptr < ((VasEBoot_uint8_t *) base) + size;
|
|
ptr++)
|
|
ret += *ptr;
|
|
return ret;
|
|
}
|
|
|
|
static void *
|
|
VasEBoot_acpi_rsdt_find_table (struct VasEBoot_acpi_table_header *rsdt, const char *sig)
|
|
{
|
|
VasEBoot_size_t s;
|
|
VasEBoot_unaligned_uint32_t *ptr;
|
|
|
|
if (!rsdt)
|
|
return 0;
|
|
|
|
if (VasEBoot_memcmp (rsdt->signature, "RSDT", 4) != 0)
|
|
return 0;
|
|
|
|
ptr = (VasEBoot_unaligned_uint32_t *) (rsdt + 1);
|
|
s = (rsdt->length - sizeof (*rsdt)) / sizeof (VasEBoot_uint32_t);
|
|
for (; s; s--, ptr++)
|
|
{
|
|
struct VasEBoot_acpi_table_header *tbl;
|
|
tbl = (struct VasEBoot_acpi_table_header *) (VasEBoot_addr_t) ptr->val;
|
|
if (VasEBoot_memcmp (tbl->signature, sig, 4) == 0)
|
|
return tbl;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void *
|
|
VasEBoot_acpi_xsdt_find_table (struct VasEBoot_acpi_table_header *xsdt, const char *sig)
|
|
{
|
|
VasEBoot_size_t s;
|
|
VasEBoot_unaligned_uint64_t *ptr;
|
|
|
|
if (!xsdt)
|
|
return 0;
|
|
|
|
if (VasEBoot_memcmp (xsdt->signature, "XSDT", 4) != 0)
|
|
return 0;
|
|
|
|
ptr = (VasEBoot_unaligned_uint64_t *) (xsdt + 1);
|
|
s = (xsdt->length - sizeof (*xsdt)) / sizeof (VasEBoot_uint32_t);
|
|
for (; s; s--, ptr++)
|
|
{
|
|
struct VasEBoot_acpi_table_header *tbl;
|
|
#if VasEBoot_CPU_SIZEOF_VOID_P != 8
|
|
if (ptr->val >> 32)
|
|
continue;
|
|
#endif
|
|
tbl = (struct VasEBoot_acpi_table_header *) (VasEBoot_addr_t) ptr->val;
|
|
if (VasEBoot_memcmp (tbl->signature, sig, 4) == 0)
|
|
return tbl;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct VasEBoot_acpi_fadt *
|
|
VasEBoot_acpi_find_fadt (void)
|
|
{
|
|
struct VasEBoot_acpi_fadt *fadt = 0;
|
|
struct VasEBoot_acpi_rsdp_v10 *rsdpv1;
|
|
struct VasEBoot_acpi_rsdp_v20 *rsdpv2;
|
|
rsdpv1 = VasEBoot_machine_acpi_get_rsdpv1 ();
|
|
if (rsdpv1)
|
|
fadt = VasEBoot_acpi_rsdt_find_table ((struct VasEBoot_acpi_table_header *)
|
|
(VasEBoot_addr_t) rsdpv1->rsdt_addr,
|
|
VasEBoot_ACPI_FADT_SIGNATURE);
|
|
if (fadt)
|
|
return fadt;
|
|
rsdpv2 = VasEBoot_machine_acpi_get_rsdpv2 ();
|
|
if (rsdpv2)
|
|
fadt = VasEBoot_acpi_rsdt_find_table ((struct VasEBoot_acpi_table_header *)
|
|
(VasEBoot_addr_t) rsdpv2->rsdpv1.rsdt_addr,
|
|
VasEBoot_ACPI_FADT_SIGNATURE);
|
|
if (fadt)
|
|
return fadt;
|
|
if (rsdpv2
|
|
#if VasEBoot_CPU_SIZEOF_VOID_P != 8
|
|
&& !(rsdpv2->xsdt_addr >> 32)
|
|
#endif
|
|
)
|
|
fadt = VasEBoot_acpi_xsdt_find_table ((struct VasEBoot_acpi_table_header *)
|
|
(VasEBoot_addr_t) rsdpv2->xsdt_addr,
|
|
VasEBoot_ACPI_FADT_SIGNATURE);
|
|
if (fadt)
|
|
return fadt;
|
|
return 0;
|
|
}
|