Home | History | Annotate | Line # | Download | only in acpica
OsdMisc.c revision 1.2
      1 /*	$NetBSD: OsdMisc.c,v 1.2 2006/03/23 13:45:11 kochi 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.2 2006/03/23 13:45:11 kochi 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 	switch (Function) {
     99 	case ACPI_SIGNAL_FATAL:
    100 	    {
    101 		const ACPI_SIGNAL_FATAL_INFO *info = Info;
    102 
    103 		panic("ACPI fatal signal: "
    104 		    "Type 0x%08x, Code 0x%08x, Argument 0x%08x",
    105 		    info->Type, info->Code, info->Argument);
    106 		/* NOTREACHED */
    107 		break;
    108 	    }
    109 
    110 	case ACPI_SIGNAL_BREAKPOINT:
    111 	    {
    112 		const char *info = Info;
    113 
    114 		printf("%s\n", info);
    115 #if defined(DDB)
    116 		Debugger();
    117 #else
    118 		printf("ACPI: WARNING: DDB not configured into kernel.\n");
    119 		return AE_NOT_EXIST;
    120 #endif
    121 		break;
    122 	    }
    123 
    124 	default:
    125 		return AE_BAD_PARAMETER;
    126 	}
    127 
    128 	return AE_OK;
    129 }
    130 
    131 ACPI_STATUS
    132 AcpiOsGetLine(char *Buffer)
    133 {
    134 #if defined(DDB)
    135 	char *cp;
    136 
    137 	db_readline(Buffer, 80);
    138 	for (cp = Buffer; *cp != 0; cp++)
    139 		if (*cp == '\n' || *cp == '\r')
    140 			*cp = 0;
    141 	db_output_line = 0;
    142 	return AE_OK;
    143 #else
    144 	printf("ACPI: WARNING: DDB not configured into kernel.\n");
    145 	return AE_NOT_EXIST;
    146 #endif
    147 }
    148 
    149 ACPI_STATUS
    150 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
    151 		    ACPI_TABLE_HEADER **NewTable)
    152 {
    153 #ifndef ACPI_DSDT_OVERRIDE
    154 	*NewTable = NULL;
    155 #else
    156 	if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0)
    157 		*NewTable = (ACPI_TABLE_HEADER *)AmlCode;
    158 	else
    159 		*NewTable = NULL;
    160 #endif
    161 	return AE_OK;
    162 }
    163 
    164 ACPI_STATUS
    165 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
    166 			 ACPI_STRING *NewVal)
    167 {
    168 	if (!InitVal || !NewVal)
    169 		return AE_BAD_PARAMETER;
    170 
    171 	*NewVal = NULL;
    172 	return AE_OK;
    173 }
    174 
    175 /*
    176  * acpi_osd_debugger:
    177  *
    178  *	Enter the ACPICA debugger.
    179  */
    180 void
    181 acpi_osd_debugger(void)
    182 {
    183 #ifdef ACPI_DEBUGGER
    184 	static int beenhere;
    185 	ACPI_PARSE_OBJECT obj;
    186 	label_t	acpi_jmpbuf;
    187 	label_t	*savejmp;
    188 
    189 	if (beenhere == 0) {
    190 		printf("Initializing ACPICA debugger...\n");
    191 		AcpiDbInitialize();
    192 		beenhere = 1;
    193 	}
    194 
    195 	printf("Entering ACPICA debugger...\n");
    196 	savejmp = db_recover;
    197 	setjmp(&acpi_jmpbuf);
    198 	db_recover = &acpi_jmpbuf;
    199 
    200 	acpi_indebugger = 1;
    201 	AcpiDbUserCommands('A', &obj);
    202 	acpi_indebugger = 0;
    203 
    204 	db_recover = savejmp;
    205 #else
    206 	printf("ACPI: WARNING: ACPICA debugger not present.\n");
    207 #endif
    208 }
    209