2 * Copyright (c) 2001 Michael Smith <msmith@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include <machine/stdarg.h>
32 #include <bootstrap.h>
36 #include "platform/acfreebsd.h"
38 #define ACPI_SYSTEM_XFACE
43 * Detect ACPI and export information about the ACPI BIOS into the
47 static ACPI_TABLE_RSDP *biosacpi_find_rsdp(void);
48 static ACPI_TABLE_RSDP *biosacpi_search_rsdp(char *base, int length);
50 #define RSDP_CHECKSUM_LENGTH 20
55 ACPI_TABLE_RSDP *rsdp;
59 /* locate and validate the RSDP */
60 if ((rsdp = biosacpi_find_rsdp()) == NULL)
64 * Report the RSDP to the kernel. While this can be found with
65 * a BIOS boot, the RSDP may be elsewhere when booted from UEFI.
66 * The old code used the 'hints' method to communite this to
67 * the kernel. However, while convenient, the 'hints' method
68 * is fragile and does not work when static hints are compiled
69 * into the kernel. Instead, move to setting different tunables
70 * that start with acpi. The old 'hints' can be removed before
71 * we branch for FreeBSD 12.
73 sprintf(buf, "0x%08x", VTOP(rsdp));
74 setenv("hint.acpi.0.rsdp", buf, 1);
75 setenv("acpi.rsdp", buf, 1);
76 revision = rsdp->Revision;
79 sprintf(buf, "%d", revision);
80 setenv("hint.acpi.0.revision", buf, 1);
81 setenv("acpi.revision", buf, 1);
82 strncpy(buf, rsdp->OemId, sizeof(rsdp->OemId));
83 buf[sizeof(rsdp->OemId)] = '\0';
84 setenv("hint.acpi.0.oem", buf, 1);
85 setenv("acpi.oem", buf, 1);
86 sprintf(buf, "0x%08x", rsdp->RsdtPhysicalAddress);
87 setenv("hint.acpi.0.rsdt", buf, 1);
88 setenv("acpi.rsdt", buf, 1);
90 /* XXX extended checksum? */
91 sprintf(buf, "0x%016llx", rsdp->XsdtPhysicalAddress);
92 setenv("hint.acpi.0.xsdt", buf, 1);
93 setenv("acpi.xsdt", buf, 1);
94 sprintf(buf, "%d", rsdp->Length);
95 setenv("hint.acpi.0.xsdt_length", buf, 1);
96 setenv("acpi.xsdt_length", buf, 1);
101 * Find the RSDP in low memory. See section 5.2.2 of the ACPI spec.
103 static ACPI_TABLE_RSDP *
104 biosacpi_find_rsdp(void)
106 ACPI_TABLE_RSDP *rsdp;
109 /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */
110 addr = (uint16_t *)PTOV(0x40E);
111 if ((rsdp = biosacpi_search_rsdp((char *)(*addr << 4), 0x400)) != NULL)
114 /* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */
115 if ((rsdp = biosacpi_search_rsdp((char *)0xe0000, 0x20000)) != NULL)
121 static ACPI_TABLE_RSDP *
122 biosacpi_search_rsdp(char *base, int length)
124 ACPI_TABLE_RSDP *rsdp;
128 /* search on 16-byte boundaries */
129 for (ofs = 0; ofs < length; ofs += 16) {
130 rsdp = (ACPI_TABLE_RSDP *)PTOV(base + ofs);
132 /* compare signature, validate checksum */
133 if (!strncmp(rsdp->Signature, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP))) {
134 cp = (uint8_t *)rsdp;
136 for (idx = 0; idx < RSDP_CHECKSUM_LENGTH; idx++)