1 /*- 2 * Copyright (c) 2001 Michael Smith <msmith@freebsd.org> 3 * All rights reserved. 4 * 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. 13 * 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. 25 * 26 * $FreeBSD: src/sys/boot/i386/libi386/biosacpi.c,v 1.7 2003/08/25 23:28:31 obrien Exp $ 27 */ 28 29 #include <stand.h> 30 #include <machine/stdarg.h> 31 #include <bootstrap.h> 32 #include <btxv86.h> 33 #include "libi386.h" 34 35 #include "acpi.h" 36 37 /* 38 * Detect ACPI and export information about the ACPI BIOS into the 39 * environment. 40 */ 41 42 static ACPI_TABLE_RSDP *biosacpi_find_rsdp(void); 43 static ACPI_TABLE_RSDP *biosacpi_search_rsdp(char *base, int length); 44 45 #define RSDP_CHECKSUM_LENGTH 20 46 47 void 48 biosacpi_detect(void) 49 { 50 ACPI_TABLE_RSDP *rsdp; 51 char buf[160]; 52 int revision; 53 54 /* locate and validate the RSDP */ 55 if ((rsdp = biosacpi_find_rsdp()) == NULL) 56 return; 57 58 /* export values from the RSDP */ 59 sprintf(buf, "0x%08x", VTOP(rsdp)); 60 setenv("hint.acpi.0.rsdp", buf, 1); 61 revision = rsdp->Revision; 62 if (revision == 0) 63 revision = 1; 64 sprintf(buf, "%d", revision); 65 setenv("hint.acpi.0.revision", buf, 1); 66 strncpy(buf, rsdp->OemId, sizeof(rsdp->OemId)); 67 buf[sizeof(rsdp->OemId)] = '\0'; 68 setenv("hint.acpi.0.oem", buf, 1); 69 sprintf(buf, "0x%08x", rsdp->RsdtPhysicalAddress); 70 setenv("hint.acpi.0.rsdt", buf, 1); 71 if (revision >= 2) { 72 /* XXX extended checksum? */ 73 sprintf(buf, "0x%016jx", (uintmax_t)rsdp->XsdtPhysicalAddress); 74 setenv("hint.acpi.0.xsdt", buf, 1); 75 sprintf(buf, "%d", rsdp->Length); 76 setenv("hint.acpi.0.xsdt_length", buf, 1); 77 } 78 setenv("acpi_load", "YES", 1); 79 } 80 81 /* 82 * Find the RSDP in low memory. See "Finding the RSDP on IA-PC Systems" in 83 * the ACPI spec. 84 */ 85 static ACPI_TABLE_RSDP * 86 biosacpi_find_rsdp(void) 87 { 88 ACPI_TABLE_RSDP *rsdp; 89 uint16_t *addr; 90 91 /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40e. */ 92 addr = (uint16_t *)PTOV(ACPI_EBDA_PTR_LOCATION); 93 if ((rsdp = biosacpi_search_rsdp((char *)(*addr << 4), 94 ACPI_EBDA_WINDOW_SIZE)) != NULL) 95 return (rsdp); 96 97 /* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */ 98 if ((rsdp = biosacpi_search_rsdp((char *)ACPI_HI_RSDP_WINDOW_BASE, 99 ACPI_HI_RSDP_WINDOW_SIZE)) != NULL) 100 return (rsdp); 101 102 return (NULL); 103 } 104 105 static ACPI_TABLE_RSDP * 106 biosacpi_search_rsdp(char *base, int length) 107 { 108 ACPI_TABLE_RSDP *rsdp; 109 u_int8_t *cp, sum; 110 int ofs, idx; 111 112 /* search on 16-byte boundaries */ 113 for (ofs = 0; ofs < length; ofs += 16) { 114 rsdp = (ACPI_TABLE_RSDP *)PTOV(base + ofs); 115 116 /* compare signature, validate checksum */ 117 if (!strncmp(rsdp->Signature, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP))) { 118 cp = (u_int8_t *)rsdp; 119 sum = 0; 120 for (idx = 0; idx < RSDP_CHECKSUM_LENGTH; idx++) 121 sum += *(cp + idx); 122 if (sum != 0) 123 continue; 124 return(rsdp); 125 } 126 } 127 return(NULL); 128 } 129