--- pmtools/acpidump/acpidump.c.orig 2010-12-21 17:25:51.000000000 -0500 +++ pmtools/acpidump/acpidump.c 2011-03-31 16:36:27.000000000 -0400 @@ -37,6 +37,10 @@ #include #include #include +#ifdef __FreeBSD__ +#include +#include +#endif #include #include #include @@ -63,6 +67,23 @@ static unsigned long psz, addr, length; static int print, connect, skip; static u8 select_sig[4]; +#ifdef __FreeBSD__ +static unsigned long acpi_find_rsd_ptr(void) +{ + char buf[20]; + size_t len; + + /* Attempt to use kenv or sysctl to find RSD PTR record. */ + if (kenv(KENV_GET, "hint.acpi.0.rsdp", buf, 20) == 0) + addr = strtoul(buf, NULL, 0); + if (addr == 0) { + len = sizeof(addr); + if (sysctlbyname("machdep.acpi_root", &addr, &len, NULL, 0) != 0) + addr = 0; + } + return addr; +} +#else static unsigned long read_efi_systab( void ) { char buffer[80]; @@ -77,6 +98,7 @@ static unsigned long read_efi_systab( vo } return 0; } +#endif static u8 *acpi_map_memory(unsigned long where, unsigned length) { @@ -88,7 +110,12 @@ static u8 *acpi_map_memory(unsigned long exit(1); } offset = where % psz; - there = mmap(NULL, length + offset, PROT_READ, MAP_PRIVATE, + there = mmap(NULL, length + offset, PROT_READ, +#ifdef __FreeBSD__ + MAP_SHARED, +#else + MAP_PRIVATE, +#endif fd, where - offset); close(fd); if (there == MAP_FAILED) return 0; @@ -101,7 +128,7 @@ static void acpi_unmap_memory(u8 * there munmap(there - offset, length + offset); } -static struct acpi_table_header *acpi_map_table(unsigned long where, char *sig) +static struct acpi_table_header *acpi_user_map_table(unsigned long where, char *sig) { unsigned size; struct acpi_table_header *tbl = (struct acpi_table_header *) @@ -112,7 +139,7 @@ static struct acpi_table_header *acpi_ma return (struct acpi_table_header *)acpi_map_memory(where, size); } -static void acpi_unmap_table(struct acpi_table_header *tbl) +static void acpi_user_unmap_table(struct acpi_table_header *tbl) { acpi_unmap_memory((u8 *)tbl, tbl->length); } @@ -225,12 +252,12 @@ static void acpi_dump_FADT(int fd, struc fprintf(stderr, "No DSDT in FADT!\n"); goto no_dsdt; } - tbl = acpi_map_table(addr, DSDT_SIG); + tbl = acpi_user_map_table(addr, DSDT_SIG); if (!tbl) goto no_dsdt; if (checksum((u8 *)tbl, tbl->length)) fprintf(stderr, "Wrong checksum for DSDT!\n"); write_table(fd, tbl, addr); - acpi_unmap_table(tbl); + acpi_user_unmap_table(tbl); no_dsdt: if (x.header.length >= 140 && x.xfirmware_ctrl) { addr = (unsigned long)x.xfirmware_ctrl; @@ -246,11 +273,11 @@ no_dsdt: fprintf(stderr, "No FACS in FADT!\n"); goto no_facs; } - tbl = acpi_map_table(addr, FACS_SIG); + tbl = acpi_user_map_table(addr, FACS_SIG); if (!tbl) goto no_facs; /* do not checksum FACS */ write_table(fd, tbl, addr); - acpi_unmap_table(tbl); + acpi_user_unmap_table(tbl); no_facs: write_table(fd, (struct acpi_table_header *)&x, xaddr); } @@ -262,16 +289,16 @@ static int acpi_dump_SDT(int fd, struct char *offset; unsigned long addr; if (rsdp->revision > 1 && rsdp->xsdt_physical_address) { - tbl = acpi_map_table(rsdp->xsdt_physical_address, "XSDT"); + tbl = acpi_user_map_table(rsdp->xsdt_physical_address, "XSDT"); } if (!tbl && rsdp->rsdt_physical_address) { xsdt = 0; - tbl = acpi_map_table(rsdp->rsdt_physical_address, "RSDT"); + tbl = acpi_user_map_table(rsdp->rsdt_physical_address, "RSDT"); } if (!tbl) return 0; sdt = malloc(tbl->length); memcpy(sdt, tbl, tbl->length); - acpi_unmap_table(tbl); + acpi_user_unmap_table(tbl); if (checksum((u8 *)sdt, sdt->length)) fprintf(stderr, "Wrong checksum for %s!\n", (xsdt)?"XSDT":"RSDT"); num = (sdt->length - sizeof(struct acpi_table_header))/((xsdt)?sizeof(u64):sizeof(u32)); @@ -280,7 +307,7 @@ static int acpi_dump_SDT(int fd, struct addr = (xsdt) ? (unsigned long)(*(u64 *)offset): (unsigned long)(*(u32 *)offset); if (!addr) continue; - tbl = acpi_map_table(addr, 0); + tbl = acpi_user_map_table(addr, 0); if (!tbl) continue; if (!memcmp(tbl->signature, FADT_SIG, 4)) { acpi_dump_FADT(fd, tbl, addr); @@ -289,7 +316,7 @@ static int acpi_dump_SDT(int fd, struct fprintf(stderr, "Wrong checksum for generic table!\n"); write_table(fd, tbl, addr); } - acpi_unmap_table(tbl); + acpi_user_unmap_table(tbl); if (connect) { if (xsdt) (*(u64*)offset) = lseek(fd, 0, SEEK_CUR); @@ -497,7 +524,11 @@ int main(int argc, char **argv) length = sizeof(struct acpi_rsdp_descriptor); if (!addr) { +#ifdef __FreeBSD__ + addr = acpi_find_rsd_ptr(); +#else addr = read_efi_systab(); +#endif if (!addr) { addr = ACPI_HI_RSDP_WINDOW_BASE; length = ACPI_HI_RSDP_WINDOW_SIZE; --- pmtools/include/acpi/platform/acfreebsd.h.orig 2011-03-31 16:17:36.000000000 -0400 +++ pmtools/include/acpi/platform/acfreebsd.h 2011-03-31 16:17:36.000000000 -0400 @@ -0,0 +1,105 @@ +/****************************************************************************** + * + * Name: acfreebsd.h - OS specific defines, etc. + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2011, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef __ACFREEBSD_H__ +#define __ACFREEBSD_H__ + + +/* FreeBSD uses GCC */ + +#include "acgcc.h" +#include +#include + +#define ACPI_UINTPTR_T uintptr_t + +#define ACPI_USE_DO_WHILE_0 +#define ACPI_USE_LOCAL_CACHE +#define ACPI_USE_SYSTEM_CLIBRARY + +#ifdef _KERNEL + +#include +#include +#include +#include +#include + +#include "opt_acpi.h" + +#define ACPI_MUTEX_TYPE ACPI_OSL_MUTEX + +#ifdef ACPI_DEBUG +#define ACPI_DEBUG_OUTPUT /* for backward compatibility */ +#define ACPI_DISASSEMBLER +#endif + +#ifdef ACPI_DEBUG_OUTPUT +#include "opt_ddb.h" +#ifdef DDB +#define ACPI_DEBUGGER +#endif /* DDB */ +#endif /* ACPI_DEBUG_OUTPUT */ + +#ifdef DEBUGGER_THREADING +#undef DEBUGGER_THREADING +#endif /* DEBUGGER_THREADING */ + +#define DEBUGGER_THREADING 0 /* integrated with DDB */ + +#else /* _KERNEL */ + +#if __STDC_HOSTED__ +#include +#endif + +#define ACPI_CAST_PTHREAD_T(pthread) ((ACPI_THREAD_ID) ACPI_TO_INTEGER (pthread)) + +#define ACPI_USE_STANDARD_HEADERS + +#define ACPI_FLUSH_CPU_CACHE() +#define __cdecl + +#endif /* _KERNEL */ + +#endif /* __ACFREEBSD_H__ */