Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / acpi / acpica / OsdMisc.c
blob6190eb2ceb4cf562c729c4d339feef85914dbf02
1 /* $NetBSD: OsdMisc.c,v 1.6 2009/07/06 12:36:31 joerg Exp $ */
3 /*
4 * Copyright 2001 Wasabi Systems, Inc.
5 * All rights reserved.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
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.
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.
39 * OS Services Layer
41 * 6.10: Miscellaneous
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: OsdMisc.c,v 1.6 2009/07/06 12:36:31 joerg Exp $");
47 #include "opt_acpi.h"
48 #include "opt_ddb.h"
50 #include <sys/param.h>
51 #include <sys/systm.h>
53 #include <machine/db_machdep.h>
55 #include <ddb/db_extern.h>
56 #include <ddb/db_output.h>
58 #include <dev/acpi/acpica.h>
59 #include <dev/acpi/acpi_osd.h>
61 #include <external/intel-public/acpica/dist/include/accommon.h>
62 #include <external/intel-public/acpica/dist/include/acdebug.h>
64 * for debugging DSDT (try this at your own risk!):
66 * 1. dump your raw DSDT (with acpidump(*1) etc.)
67 * 2. disassemble with iasl -d (*2)
68 * 3. modify the ASL file
69 * 4. compile it with iasl -tc
70 * 5. copy *.hex to src/sys/dev/acpi/acpica/Osd/dsdt.hex
71 * -or-
72 * options ACPI_DSDT_FILE="\"yourdsdt.hex\"" in
73 * your config file and yourdsdt.hex in the build directory
74 * 6. options ACPI_DSDT_OVERRIDE in your kernel config file
75 * and rebuild the kernel
77 * (*1) /usr/pkgsrc/sysutils/acpidump
78 * (*2) /usr/pkgsrc/sysutils/acpi-iasl
81 #ifdef ACPI_DSDT_OVERRIDE
82 #ifndef ACPI_DSDT_FILE
83 #define ACPI_DSDT_FILE "dsdt.hex"
84 #endif
85 #include ACPI_DSDT_FILE
86 #endif
88 int acpi_indebugger;
91 * AcpiOsSignal:
93 * Break to the debugger or display a breakpoint message.
95 ACPI_STATUS
96 AcpiOsSignal(UINT32 Function, void *Info)
99 * the upper layer might call with Info = NULL,
100 * which makes little sense.
102 if (Info == NULL)
103 return AE_NO_MEMORY;
105 switch (Function) {
106 case ACPI_SIGNAL_FATAL:
108 ACPI_SIGNAL_FATAL_INFO *info = Info;
110 panic("ACPI fatal signal: "
111 "Type 0x%08x, Code 0x%08x, Argument 0x%08x",
112 info->Type, info->Code, info->Argument);
113 /* NOTREACHED */
114 break;
117 case ACPI_SIGNAL_BREAKPOINT:
119 #ifdef ACPI_BREAKPOINT
120 char *info = Info;
122 printf("%s\n", info);
123 # if defined(DDB)
124 Debugger();
125 # else
126 printf("ACPI: WARNING: DDB not configured into kernel.\n");
127 return AE_NOT_EXIST;
128 # endif
129 #endif
130 break;
133 default:
134 return AE_BAD_PARAMETER;
137 return AE_OK;
140 ACPI_STATUS
141 AcpiOsGetLine(char *Buffer)
143 #if defined(DDB)
144 char *cp;
146 db_readline(Buffer, 80);
147 for (cp = Buffer; *cp != 0; cp++)
148 if (*cp == '\n' || *cp == '\r')
149 *cp = 0;
150 db_output_line = 0;
151 return AE_OK;
152 #else
153 printf("ACPI: WARNING: DDB not configured into kernel.\n");
154 return AE_NOT_EXIST;
155 #endif
158 ACPI_STATUS
159 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
160 ACPI_TABLE_HEADER **NewTable)
162 #ifndef ACPI_DSDT_OVERRIDE
163 *NewTable = NULL;
164 #else
165 if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0)
166 *NewTable = (ACPI_TABLE_HEADER *)AmlCode;
167 else
168 *NewTable = NULL;
169 #endif
170 return AE_OK;
173 ACPI_STATUS
174 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
175 ACPI_STRING *NewVal)
177 if (!InitVal || !NewVal)
178 return AE_BAD_PARAMETER;
180 *NewVal = NULL;
181 return AE_OK;
185 * acpi_osd_debugger:
187 * Enter the ACPICA debugger.
189 void
190 acpi_osd_debugger(void)
192 #ifdef ACPI_DEBUGGER
193 static int beenhere;
194 ACPI_PARSE_OBJECT obj;
195 label_t acpi_jmpbuf;
196 label_t *savejmp;
198 if (beenhere == 0) {
199 printf("Initializing ACPICA debugger...\n");
200 AcpiDbInitialize();
201 beenhere = 1;
204 printf("Entering ACPICA debugger...\n");
205 savejmp = db_recover;
206 setjmp(&acpi_jmpbuf);
207 db_recover = &acpi_jmpbuf;
209 acpi_indebugger = 1;
210 AcpiDbUserCommands('A', &obj);
211 acpi_indebugger = 0;
213 db_recover = savejmp;
214 #else
215 printf("ACPI: WARNING: ACPICA debugger not present.\n");
216 #endif