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