xref: /netbsd-src/sys/dev/acpi/acpica/OsdMisc.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: OsdMisc.c,v 1.5 2006/11/16 01:32:47 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.5 2006/11/16 01:32:47 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 #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 		const char *info = Info;
119 
120 		printf("%s\n", info);
121 #if defined(DDB)
122 		Debugger();
123 #else
124 		printf("ACPI: WARNING: DDB not configured into kernel.\n");
125 		return AE_NOT_EXIST;
126 #endif
127 		break;
128 	    }
129 
130 	default:
131 		return AE_BAD_PARAMETER;
132 	}
133 
134 	return AE_OK;
135 }
136 
137 ACPI_STATUS
138 AcpiOsGetLine(char *Buffer)
139 {
140 #if defined(DDB)
141 	char *cp;
142 
143 	db_readline(Buffer, 80);
144 	for (cp = Buffer; *cp != 0; cp++)
145 		if (*cp == '\n' || *cp == '\r')
146 			*cp = 0;
147 	db_output_line = 0;
148 	return AE_OK;
149 #else
150 	printf("ACPI: WARNING: DDB not configured into kernel.\n");
151 	return AE_NOT_EXIST;
152 #endif
153 }
154 
155 ACPI_STATUS
156 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
157 		    ACPI_TABLE_HEADER **NewTable)
158 {
159 #ifndef ACPI_DSDT_OVERRIDE
160 	*NewTable = NULL;
161 #else
162 	if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0)
163 		*NewTable = (ACPI_TABLE_HEADER *)AmlCode;
164 	else
165 		*NewTable = NULL;
166 #endif
167 	return AE_OK;
168 }
169 
170 ACPI_STATUS
171 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
172 			 ACPI_STRING *NewVal)
173 {
174 	if (!InitVal || !NewVal)
175 		return AE_BAD_PARAMETER;
176 
177 	*NewVal = NULL;
178 	return AE_OK;
179 }
180 
181 /*
182  * acpi_osd_debugger:
183  *
184  *	Enter the ACPICA debugger.
185  */
186 void
187 acpi_osd_debugger(void)
188 {
189 #ifdef ACPI_DEBUGGER
190 	static int beenhere;
191 	ACPI_PARSE_OBJECT obj;
192 	label_t	acpi_jmpbuf;
193 	label_t	*savejmp;
194 
195 	if (beenhere == 0) {
196 		printf("Initializing ACPICA debugger...\n");
197 		AcpiDbInitialize();
198 		beenhere = 1;
199 	}
200 
201 	printf("Entering ACPICA debugger...\n");
202 	savejmp = db_recover;
203 	setjmp(&acpi_jmpbuf);
204 	db_recover = &acpi_jmpbuf;
205 
206 	acpi_indebugger = 1;
207 	AcpiDbUserCommands('A', &obj);
208 	acpi_indebugger = 0;
209 
210 	db_recover = savejmp;
211 #else
212 	printf("ACPI: WARNING: ACPICA debugger not present.\n");
213 #endif
214 }
215