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