1 /* $NetBSD: OsdMisc.c,v 1.9 2010/04/11 08:58:43 jruoho Exp $ */ 2 3 /* 4 * Copyright 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 /* 39 * OS Services Layer 40 * 41 * 6.10: Miscellaneous 42 */ 43 44 #include <sys/cdefs.h> 45 __KERNEL_RCSID(0, "$NetBSD: OsdMisc.c,v 1.9 2010/04/11 08:58:43 jruoho Exp $"); 46 47 #include "opt_acpi.h" 48 #include "opt_ddb.h" 49 50 #include <sys/param.h> 51 #include <sys/systm.h> 52 53 #include <machine/db_machdep.h> 54 55 #include <ddb/db_extern.h> 56 #include <ddb/db_output.h> 57 58 #include <dev/acpi/acpica.h> 59 #include <dev/acpi/acpi_osd.h> 60 61 #include <external/intel-public/acpica/dist/include/accommon.h> 62 #include <external/intel-public/acpica/dist/include/acdebug.h> 63 64 #ifdef ACPI_DSDT_OVERRIDE 65 #ifndef ACPI_DSDT_FILE 66 #define ACPI_DSDT_FILE "dsdt.hex" 67 #endif 68 #include ACPI_DSDT_FILE 69 #endif 70 71 int acpi_indebugger; 72 73 /* 74 * AcpiOsSignal: 75 * 76 * Break to the debugger or display a breakpoint message. 77 */ 78 ACPI_STATUS 79 AcpiOsSignal(UINT32 Function, void *Info) 80 { 81 /* 82 * the upper layer might call with Info = NULL, 83 * which makes little sense. 84 */ 85 if (Info == NULL) 86 return AE_NO_MEMORY; 87 88 switch (Function) { 89 case ACPI_SIGNAL_FATAL: 90 { 91 ACPI_SIGNAL_FATAL_INFO *info = Info; 92 93 panic("ACPI fatal signal: " 94 "Type 0x%08x, Code 0x%08x, Argument 0x%08x", 95 info->Type, info->Code, info->Argument); 96 /* NOTREACHED */ 97 break; 98 } 99 100 case ACPI_SIGNAL_BREAKPOINT: 101 { 102 #ifdef ACPI_BREAKPOINT 103 char *info = Info; 104 105 printf("%s\n", info); 106 # if defined(DDB) 107 Debugger(); 108 # else 109 printf("ACPI: WARNING: DDB not configured into kernel.\n"); 110 return AE_NOT_EXIST; 111 # endif 112 #endif 113 break; 114 } 115 116 default: 117 return AE_BAD_PARAMETER; 118 } 119 120 return AE_OK; 121 } 122 123 ACPI_STATUS 124 AcpiOsGetLine(char *Buffer) 125 { 126 #if defined(DDB) 127 char *cp; 128 129 db_readline(Buffer, 80); 130 for (cp = Buffer; *cp != 0; cp++) 131 if (*cp == '\n' || *cp == '\r') 132 *cp = 0; 133 db_output_line = 0; 134 return AE_OK; 135 #else 136 printf("ACPI: WARNING: DDB not configured into kernel.\n"); 137 return AE_NOT_EXIST; 138 #endif 139 } 140 141 ACPI_STATUS 142 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable, 143 ACPI_TABLE_HEADER **NewTable) 144 { 145 #ifndef ACPI_DSDT_OVERRIDE 146 *NewTable = NULL; 147 #else 148 if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0) 149 *NewTable = (ACPI_TABLE_HEADER *)AmlCode; 150 else 151 *NewTable = NULL; 152 #endif 153 return AE_OK; 154 } 155 156 ACPI_STATUS 157 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal, 158 ACPI_STRING *NewVal) 159 { 160 if (!InitVal || !NewVal) 161 return AE_BAD_PARAMETER; 162 163 *NewVal = NULL; 164 return AE_OK; 165 } 166 167 /* 168 * acpi_osd_debugger: 169 * 170 * Enter the ACPICA debugger. 171 */ 172 void 173 acpi_osd_debugger(void) 174 { 175 #ifdef ACPI_DEBUGGER 176 static int beenhere; 177 ACPI_PARSE_OBJECT obj; 178 label_t acpi_jmpbuf; 179 label_t *savejmp; 180 181 if (beenhere == 0) { 182 printf("Initializing ACPICA debugger...\n"); 183 AcpiDbInitialize(); 184 beenhere = 1; 185 } 186 187 printf("Entering ACPICA debugger...\n"); 188 savejmp = db_recover; 189 setjmp(&acpi_jmpbuf); 190 db_recover = &acpi_jmpbuf; 191 192 acpi_indebugger = 1; 193 AcpiDbUserCommands('A', &obj); 194 acpi_indebugger = 0; 195 196 db_recover = savejmp; 197 #else 198 printf("ACPI: WARNING: ACPICA debugger not present.\n"); 199 #endif 200 } 201