biosacpi.c revision 114246
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: head/sys/boot/i386/libi386/biosacpi.c 114246 2003-04-29 18:50:34Z njl $ 27 */ 28 29#include <stand.h> 30#include <machine/stdarg.h> 31#include <bootstrap.h> 32 33#include "acfreebsd.h" 34#define ACPI_SYSTEM_XFACE 35#include "actypes.h" 36#include "actbl.h" 37 38/* 39 * Detect ACPI and export information about the APCI BIOS into the 40 * environment. 41 */ 42 43static RSDP_DESCRIPTOR *biosacpi_find_rsdp(void); 44static RSDP_DESCRIPTOR *biosacpi_search_rsdp(char *base, int length); 45 46#define RSDP_CHECKSUM_LENGTH 20 47 48void 49biosacpi_detect(void) 50{ 51 RSDP_DESCRIPTOR *rsdp; 52 char buf[16]; 53 int revision; 54 55 /* XXX check the BIOS datestamp */ 56 57 /* locate and validate the RSDP */ 58 if ((rsdp = biosacpi_find_rsdp()) == NULL) 59 return; 60 61 /* export values from the RSDP */ 62 revision = rsdp->Revision; 63 if (revision == 0) 64 revision = 1; 65 sprintf(buf, "%d", revision); 66 setenv("hint.acpi.0.revision", buf, 1); 67 sprintf(buf, "%6s", rsdp->OemId); 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%016llx", 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 /* XXX other tables? */ 79 80 setenv("acpi_load", "YES", 1); 81} 82 83/* 84 * Find the RSDP in low memory. 85 */ 86static RSDP_DESCRIPTOR * 87biosacpi_find_rsdp(void) 88{ 89 RSDP_DESCRIPTOR *rsdp; 90 91 /* search the EBDA */ 92 if ((rsdp = biosacpi_search_rsdp((char *)0, 0x400)) != NULL) 93 return(rsdp); 94 95 /* search the BIOS space */ 96 if ((rsdp = biosacpi_search_rsdp((char *)0xe0000, 0x20000)) != NULL) 97 return(rsdp); 98 99 return(NULL); 100} 101 102static RSDP_DESCRIPTOR * 103biosacpi_search_rsdp(char *base, int length) 104{ 105 RSDP_DESCRIPTOR *rsdp; 106 u_int8_t *cp, sum; 107 int ofs, idx; 108 109 /* search on 16-byte boundaries */ 110 for (ofs = 0; ofs < length; ofs += 16) { 111 rsdp = (RSDP_DESCRIPTOR *)(base + ofs); 112 113 /* compare signature, validate checksum */ 114 if (!strncmp(rsdp->Signature, RSDP_SIG, strlen(RSDP_SIG))) { 115 cp = (u_int8_t *)rsdp; 116 sum = 0; 117 for (idx = 0; idx < RSDP_CHECKSUM_LENGTH; idx++) 118 sum += *(cp + idx); 119 if (sum != 0) { 120 printf("acpi: bad RSDP checksum (%d)\n", sum); 121 continue; 122 } 123 return(rsdp); 124 } 125 } 126 return(NULL); 127} 128