Home | History | Annotate | Line # | Download | only in acpica
OsdMisc.c revision 1.5.52.2
      1 /*	$NetBSD: OsdMisc.c,v 1.5.52.2 2009/08/19 18:47:04 yamt 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.52.2 2009/08/19 18:47:04 yamt 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 <external/intel-public/acpica/dist/include/accommon.h>
     62 #include <external/intel-public/acpica/dist/include/acdebug.h>
     63 /*
     64  * for debugging DSDT (try this at your own risk!):
     65  *
     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
     76  *
     77  * (*1) /usr/pkgsrc/sysutils/acpidump
     78  * (*2) /usr/pkgsrc/sysutils/acpi-iasl
     79  */
     80 
     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
     87 
     88 int acpi_indebugger;
     89 
     90 /*
     91  * AcpiOsSignal:
     92  *
     93  *	Break to the debugger or display a breakpoint message.
     94  */
     95 ACPI_STATUS
     96 AcpiOsSignal(UINT32 Function, void *Info)
     97 {
     98 	/*
     99 	 * the upper layer might call with Info = NULL,
    100 	 * which makes little sense.
    101 	 */
    102 	if (Info == NULL)
    103 		return AE_NO_MEMORY;
    104 
    105 	switch (Function) {
    106 	case ACPI_SIGNAL_FATAL:
    107 	    {
    108 		ACPI_SIGNAL_FATAL_INFO *info = Info;
    109 
    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;
    115 	    }
    116 
    117 	case ACPI_SIGNAL_BREAKPOINT:
    118 	    {
    119 #ifdef ACPI_BREAKPOINT
    120 		char *info = Info;
    121 
    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;
    131 	    }
    132 
    133 	default:
    134 		return AE_BAD_PARAMETER;
    135 	}
    136 
    137 	return AE_OK;
    138 }
    139 
    140 ACPI_STATUS
    141 AcpiOsGetLine(char *Buffer)
    142 {
    143 #if defined(DDB)
    144 	char *cp;
    145 
    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
    156 }
    157 
    158 ACPI_STATUS
    159 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
    160 		    ACPI_TABLE_HEADER **NewTable)
    161 {
    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;
    171 }
    172 
    173 ACPI_STATUS
    174 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
    175 			 ACPI_STRING *NewVal)
    176 {
    177 	if (!InitVal || !NewVal)
    178 		return AE_BAD_PARAMETER;
    179 
    180 	*NewVal = NULL;
    181 	return AE_OK;
    182 }
    183 
    184 /*
    185  * acpi_osd_debugger:
    186  *
    187  *	Enter the ACPICA debugger.
    188  */
    189 void
    190 acpi_osd_debugger(void)
    191 {
    192 #ifdef ACPI_DEBUGGER
    193 	static int beenhere;
    194 	ACPI_PARSE_OBJECT obj;
    195 	label_t	acpi_jmpbuf;
    196 	label_t	*savejmp;
    197 
    198 	if (beenhere == 0) {
    199 		printf("Initializing ACPICA debugger...\n");
    200 		AcpiDbInitialize();
    201 		beenhere = 1;
    202 	}
    203 
    204 	printf("Entering ACPICA debugger...\n");
    205 	savejmp = db_recover;
    206 	setjmp(&acpi_jmpbuf);
    207 	db_recover = &acpi_jmpbuf;
    208 
    209 	acpi_indebugger = 1;
    210 	AcpiDbUserCommands('A', &obj);
    211 	acpi_indebugger = 0;
    212 
    213 	db_recover = savejmp;
    214 #else
    215 	printf("ACPI: WARNING: ACPICA debugger not present.\n");
    216 #endif
    217 }
    218