1 | /* $NetBSD: OsdMisc.c,v 1.15 2016/01/09 21:14:42 christos 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.15 2016/01/09 21:14:42 christos 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 | #ifdef ACPI_DEBUG |
62 | #include <external/bsd/acpica/dist/include/acdebug.h> |
63 | #endif |
64 | |
65 | #ifdef ACPI_DSDT_OVERRIDE |
66 | #ifndef ACPI_DSDT_FILE |
67 | #define ACPI_DSDT_FILE "dsdt.hex" |
68 | #endif |
69 | #include ACPI_DSDT_FILE |
70 | #endif |
71 | |
72 | int acpi_indebugger; |
73 | |
74 | /* |
75 | * AcpiOsSignal: |
76 | * |
77 | * Break to the debugger or display a breakpoint message. |
78 | */ |
79 | ACPI_STATUS |
80 | AcpiOsSignal(UINT32 Function, void *Info) |
81 | { |
82 | /* |
83 | * the upper layer might call with Info = NULL, |
84 | * which makes little sense. |
85 | */ |
86 | if (Info == NULL) |
87 | return AE_NO_MEMORY; |
88 | |
89 | switch (Function) { |
90 | case ACPI_SIGNAL_FATAL: |
91 | { |
92 | ACPI_SIGNAL_FATAL_INFO *info = Info; |
93 | |
94 | panic("ACPI fatal signal: " |
95 | "Type 0x%08x, Code 0x%08x, Argument 0x%08x" , |
96 | info->Type, info->Code, info->Argument); |
97 | /* NOTREACHED */ |
98 | break; |
99 | } |
100 | |
101 | case ACPI_SIGNAL_BREAKPOINT: |
102 | { |
103 | #ifdef ACPI_BREAKPOINT |
104 | char *info = Info; |
105 | |
106 | printf("%s\n" , info); |
107 | # if defined(DDB) |
108 | Debugger(); |
109 | # else |
110 | printf("ACPI: WARNING: DDB not configured into kernel.\n" ); |
111 | return AE_NOT_EXIST; |
112 | # endif |
113 | #endif |
114 | break; |
115 | } |
116 | |
117 | default: |
118 | return AE_BAD_PARAMETER; |
119 | } |
120 | |
121 | return AE_OK; |
122 | } |
123 | |
124 | ACPI_STATUS |
125 | AcpiOsGetLine(char *Buffer, UINT32 BufferLength, UINT32 *BytesRead) |
126 | { |
127 | #if defined(DDB) |
128 | char *cp; |
129 | |
130 | db_readline(Buffer, 80); |
131 | for (cp = Buffer; *cp != 0; cp++) |
132 | if (*cp == '\n' || *cp == '\r') |
133 | *cp = 0; |
134 | db_output_line = 0; |
135 | return AE_OK; |
136 | #else |
137 | printf("ACPI: WARNING: DDB not configured into kernel.\n" ); |
138 | return AE_NOT_EXIST; |
139 | #endif |
140 | } |
141 | |
142 | ACPI_STATUS |
143 | AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable, |
144 | ACPI_TABLE_HEADER **NewTable) |
145 | { |
146 | #ifndef ACPI_DSDT_OVERRIDE |
147 | *NewTable = NULL; |
148 | #else |
149 | if (strncmp(ExistingTable->Signature, "DSDT" , 4) == 0) |
150 | *NewTable = (ACPI_TABLE_HEADER *)AmlCode; |
151 | else |
152 | *NewTable = NULL; |
153 | #endif |
154 | return AE_OK; |
155 | } |
156 | |
157 | ACPI_STATUS |
158 | AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal, |
159 | ACPI_STRING *NewVal) |
160 | { |
161 | if (!InitVal || !NewVal) |
162 | return AE_BAD_PARAMETER; |
163 | |
164 | *NewVal = NULL; |
165 | return AE_OK; |
166 | } |
167 | |
168 | |
169 | /* |
170 | * AcpiOsPhysicalTableOverride: |
171 | * |
172 | * ExistingTable - Header of current table (probably firmware) |
173 | * NewAddress - Where new table address is returned |
174 | * (Physical address) |
175 | * NewTableLength - Where new table length is returned |
176 | * |
177 | * RETURN: Status, address/length of new table. Null pointer returned |
178 | * if no table is available to override. |
179 | * |
180 | * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. |
181 | */ |
182 | ACPI_STATUS |
183 | AcpiOsPhysicalTableOverride ( |
184 | ACPI_TABLE_HEADER *ExistingTable, |
185 | ACPI_PHYSICAL_ADDRESS *NewAddress, |
186 | UINT32 *NewTableLength) |
187 | { |
188 | |
189 | return AE_SUPPORT; |
190 | } |
191 | |
192 | /* |
193 | * acpi_osd_debugger: |
194 | * |
195 | * Enter the ACPICA debugger. |
196 | */ |
197 | void |
198 | acpi_osd_debugger(void) |
199 | { |
200 | #ifdef ACPI_DEBUG |
201 | ACPI_PARSE_OBJECT obj; |
202 | label_t acpi_jmpbuf; |
203 | label_t *savejmp; |
204 | |
205 | printf("Entering ACPICA debugger...\n" ); |
206 | savejmp = db_recover; |
207 | setjmp(&acpi_jmpbuf); |
208 | db_recover = &acpi_jmpbuf; |
209 | |
210 | acpi_indebugger = 1; |
211 | AcpiDbUserCommands('A', &obj); |
212 | acpi_indebugger = 0; |
213 | |
214 | db_recover = savejmp; |
215 | #else |
216 | printf("ACPI: WARNING: ACPICA debugger not present.\n" ); |
217 | #endif |
218 | } |
219 | |