Get rid of 4.x-derived acpi code:
[dragonfly.git] / sys / boot / pc32 / libi386 / biosacpi.c
blob82595f9b32799ca0ce4a60ac9ce476335c8853fb
1 /*-
2 * Copyright (c) 2001 Michael Smith <msmith@freebsd.org>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
24 * SUCH DAMAGE.
26 * $FreeBSD: src/sys/boot/i386/libi386/biosacpi.c,v 1.7 2003/08/25 23:28:31 obrien Exp $
27 * $DragonFly: src/sys/boot/pc32/libi386/biosacpi.c,v 1.4 2005/08/16 10:31:35 y0netan1 Exp $
30 #include <stand.h>
31 #include <machine/stdarg.h>
32 #include <bootstrap.h>
34 #include "acdragonfly.h"
35 #include "acconfig.h"
36 #define ACPI_SYSTEM_XFACE
37 #include "actypes.h"
38 #include "actbl.h"
41 * Detect ACPI and export information about the APCI BIOS into the
42 * environment.
45 static RSDP_DESCRIPTOR *biosacpi_find_rsdp(void);
46 static RSDP_DESCRIPTOR *biosacpi_search_rsdp(char *base, int length);
48 #define RSDP_CHECKSUM_LENGTH 20
50 void
51 biosacpi_detect(void)
53 RSDP_DESCRIPTOR *rsdp;
54 char buf[160];
55 int revision;
57 /* XXX check the BIOS datestamp */
59 /* locate and validate the RSDP */
60 if ((rsdp = biosacpi_find_rsdp()) == NULL)
61 return;
63 /* export values from the RSDP */
64 revision = rsdp->Revision;
65 if (revision == 0)
66 revision = 1;
67 sprintf(buf, "%d", revision);
68 setenv("hint.acpi.0.revision", buf, 1);
69 strncpy(buf, rsdp->OemId, sizeof(rsdp->OemId));
70 buf[sizeof(rsdp->OemId)] = '\0';
71 setenv("hint.acpi.0.oem", buf, 1);
72 sprintf(buf, "0x%08x", rsdp->RsdtPhysicalAddress);
73 setenv("hint.acpi.0.rsdt", buf, 1);
74 if (revision >= 2) {
75 /* XXX extended checksum? */
76 sprintf(buf, "0x%016llx", rsdp->XsdtPhysicalAddress);
77 setenv("hint.acpi.0.xsdt", buf, 1);
78 sprintf(buf, "%d", rsdp->Length);
79 setenv("hint.acpi.0.xsdt_length", buf, 1);
81 /* XXX other tables? */
83 setenv("acpi_load", "YES", 1);
87 * Find the RSDP in low memory. See section 5.2.2 of the ACPI spec.
89 static RSDP_DESCRIPTOR *
90 biosacpi_find_rsdp(void)
92 RSDP_DESCRIPTOR *rsdp;
93 uint16_t *addr;
95 /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */
96 addr = (uint16_t *)0x40E;
97 if ((rsdp = biosacpi_search_rsdp((char *)(*addr << 4), 0x400)) != NULL)
98 return (rsdp);
100 /* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */
101 if ((rsdp = biosacpi_search_rsdp((char *)0xe0000, 0x20000)) != NULL)
102 return (rsdp);
104 return (NULL);
107 static RSDP_DESCRIPTOR *
108 biosacpi_search_rsdp(char *base, int length)
110 RSDP_DESCRIPTOR *rsdp;
111 u_int8_t *cp, sum;
112 int ofs, idx;
114 /* search on 16-byte boundaries */
115 for (ofs = 0; ofs < length; ofs += 16) {
116 rsdp = (RSDP_DESCRIPTOR *)(base + ofs);
118 /* compare signature, validate checksum */
119 if (!strncmp(rsdp->Signature, RSDP_SIG, strlen(RSDP_SIG))) {
120 cp = (u_int8_t *)rsdp;
121 sum = 0;
122 for (idx = 0; idx < RSDP_CHECKSUM_LENGTH; idx++)
123 sum += *(cp + idx);
124 if (sum != 0) {
125 printf("acpi: bad RSDP checksum (%d)\n", sum);
126 continue;
128 return(rsdp);
131 return(NULL);