OsdMisc.c revision 1.5.68.1 1 /* $NetBSD: OsdMisc.c,v 1.5.68.1 2009/07/23 23:31:45 jym 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.5.68.1 2009/07/23 23:31:45 jym 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 <dist/acpica/acdebug.h>
62 /*
63 * for debugging DSDT (try this at your own risk!):
64 *
65 * 1. dump your raw DSDT (with acpidump(*1) etc.)
66 * 2. disassemble with iasl -d (*2)
67 * 3. modify the ASL file
68 * 4. compile it with iasl -tc
69 * 5. copy *.hex to src/sys/dev/acpi/acpica/Osd/dsdt.hex
70 * -or-
71 * options ACPI_DSDT_FILE="\"yourdsdt.hex\"" in
72 * your config file and yourdsdt.hex in the build directory
73 * 6. options ACPI_DSDT_OVERRIDE in your kernel config file
74 * and rebuild the kernel
75 *
76 * (*1) /usr/pkgsrc/sysutils/acpidump
77 * (*2) /usr/pkgsrc/sysutils/acpi-iasl
78 */
79
80 #ifdef ACPI_DSDT_OVERRIDE
81 #ifndef ACPI_DSDT_FILE
82 #define ACPI_DSDT_FILE "dsdt.hex"
83 #endif
84 #include ACPI_DSDT_FILE
85 #endif
86
87 int acpi_indebugger;
88
89 /*
90 * AcpiOsSignal:
91 *
92 * Break to the debugger or display a breakpoint message.
93 */
94 ACPI_STATUS
95 AcpiOsSignal(UINT32 Function, const void *Info)
96 {
97 /*
98 * the upper layer might call with Info = NULL,
99 * which makes little sense.
100 */
101 if (Info == NULL)
102 return AE_NO_MEMORY;
103
104 switch (Function) {
105 case ACPI_SIGNAL_FATAL:
106 {
107 const ACPI_SIGNAL_FATAL_INFO *info = Info;
108
109 panic("ACPI fatal signal: "
110 "Type 0x%08x, Code 0x%08x, Argument 0x%08x",
111 info->Type, info->Code, info->Argument);
112 /* NOTREACHED */
113 break;
114 }
115
116 case ACPI_SIGNAL_BREAKPOINT:
117 {
118 #ifdef ACPI_BREAKPOINT
119 const char *info = Info;
120
121 printf("%s\n", info);
122 # if defined(DDB)
123 Debugger();
124 # else
125 printf("ACPI: WARNING: DDB not configured into kernel.\n");
126 return AE_NOT_EXIST;
127 # endif
128 #endif
129 break;
130 }
131
132 default:
133 return AE_BAD_PARAMETER;
134 }
135
136 return AE_OK;
137 }
138
139 ACPI_STATUS
140 AcpiOsGetLine(char *Buffer)
141 {
142 #if defined(DDB)
143 char *cp;
144
145 db_readline(Buffer, 80);
146 for (cp = Buffer; *cp != 0; cp++)
147 if (*cp == '\n' || *cp == '\r')
148 *cp = 0;
149 db_output_line = 0;
150 return AE_OK;
151 #else
152 printf("ACPI: WARNING: DDB not configured into kernel.\n");
153 return AE_NOT_EXIST;
154 #endif
155 }
156
157 ACPI_STATUS
158 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
159 ACPI_TABLE_HEADER **NewTable)
160 {
161 #ifndef ACPI_DSDT_OVERRIDE
162 *NewTable = NULL;
163 #else
164 if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0)
165 *NewTable = (ACPI_TABLE_HEADER *)AmlCode;
166 else
167 *NewTable = NULL;
168 #endif
169 return AE_OK;
170 }
171
172 ACPI_STATUS
173 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
174 ACPI_STRING *NewVal)
175 {
176 if (!InitVal || !NewVal)
177 return AE_BAD_PARAMETER;
178
179 *NewVal = NULL;
180 return AE_OK;
181 }
182
183 /*
184 * acpi_osd_debugger:
185 *
186 * Enter the ACPICA debugger.
187 */
188 void
189 acpi_osd_debugger(void)
190 {
191 #ifdef ACPI_DEBUGGER
192 static int beenhere;
193 ACPI_PARSE_OBJECT obj;
194 label_t acpi_jmpbuf;
195 label_t *savejmp;
196
197 if (beenhere == 0) {
198 printf("Initializing ACPICA debugger...\n");
199 AcpiDbInitialize();
200 beenhere = 1;
201 }
202
203 printf("Entering ACPICA debugger...\n");
204 savejmp = db_recover;
205 setjmp(&acpi_jmpbuf);
206 db_recover = &acpi_jmpbuf;
207
208 acpi_indebugger = 1;
209 AcpiDbUserCommands('A', &obj);
210 acpi_indebugger = 0;
211
212 db_recover = savejmp;
213 #else
214 printf("ACPI: WARNING: ACPICA debugger not present.\n");
215 #endif
216 }
217