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