Home | History | Annotate | Line # | Download | only in acpica
OsdMisc.c revision 1.10
      1 /*	$NetBSD: OsdMisc.c,v 1.10 2011/02/17 07:34:42 jruoho 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.10 2011/02/17 07:34:42 jruoho 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_DSDT_OVERRIDE
     62 #ifndef ACPI_DSDT_FILE
     63 #define ACPI_DSDT_FILE "dsdt.hex"
     64 #endif
     65 #include ACPI_DSDT_FILE
     66 #endif
     67 
     68 int acpi_indebugger;
     69 
     70 /*
     71  * AcpiOsSignal:
     72  *
     73  *	Break to the debugger or display a breakpoint message.
     74  */
     75 ACPI_STATUS
     76 AcpiOsSignal(UINT32 Function, void *Info)
     77 {
     78 	/*
     79 	 * the upper layer might call with Info = NULL,
     80 	 * which makes little sense.
     81 	 */
     82 	if (Info == NULL)
     83 		return AE_NO_MEMORY;
     84 
     85 	switch (Function) {
     86 	case ACPI_SIGNAL_FATAL:
     87 	    {
     88 		ACPI_SIGNAL_FATAL_INFO *info = Info;
     89 
     90 		panic("ACPI fatal signal: "
     91 		    "Type 0x%08x, Code 0x%08x, Argument 0x%08x",
     92 		    info->Type, info->Code, info->Argument);
     93 		/* NOTREACHED */
     94 		break;
     95 	    }
     96 
     97 	case ACPI_SIGNAL_BREAKPOINT:
     98 	    {
     99 #ifdef ACPI_BREAKPOINT
    100 		char *info = Info;
    101 
    102 		printf("%s\n", info);
    103 #  if defined(DDB)
    104 		Debugger();
    105 #  else
    106 		printf("ACPI: WARNING: DDB not configured into kernel.\n");
    107 		return AE_NOT_EXIST;
    108 #  endif
    109 #endif
    110 		break;
    111 	    }
    112 
    113 	default:
    114 		return AE_BAD_PARAMETER;
    115 	}
    116 
    117 	return AE_OK;
    118 }
    119 
    120 ACPI_STATUS
    121 AcpiOsGetLine(char *Buffer)
    122 {
    123 #if defined(DDB)
    124 	char *cp;
    125 
    126 	db_readline(Buffer, 80);
    127 	for (cp = Buffer; *cp != 0; cp++)
    128 		if (*cp == '\n' || *cp == '\r')
    129 			*cp = 0;
    130 	db_output_line = 0;
    131 	return AE_OK;
    132 #else
    133 	printf("ACPI: WARNING: DDB not configured into kernel.\n");
    134 	return AE_NOT_EXIST;
    135 #endif
    136 }
    137 
    138 ACPI_STATUS
    139 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
    140 		    ACPI_TABLE_HEADER **NewTable)
    141 {
    142 #ifndef ACPI_DSDT_OVERRIDE
    143 	*NewTable = NULL;
    144 #else
    145 	if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0)
    146 		*NewTable = (ACPI_TABLE_HEADER *)AmlCode;
    147 	else
    148 		*NewTable = NULL;
    149 #endif
    150 	return AE_OK;
    151 }
    152 
    153 ACPI_STATUS
    154 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
    155 			 ACPI_STRING *NewVal)
    156 {
    157 	if (!InitVal || !NewVal)
    158 		return AE_BAD_PARAMETER;
    159 
    160 	*NewVal = NULL;
    161 	return AE_OK;
    162 }
    163 
    164 /*
    165  * acpi_osd_debugger:
    166  *
    167  *	Enter the ACPICA debugger.
    168  */
    169 void
    170 acpi_osd_debugger(void)
    171 {
    172 #ifdef ACPI_DEBUGGER
    173 	static int beenhere;
    174 	ACPI_PARSE_OBJECT obj;
    175 	label_t	acpi_jmpbuf;
    176 	label_t	*savejmp;
    177 
    178 	if (beenhere == 0) {
    179 		printf("Initializing ACPICA debugger...\n");
    180 		AcpiDbInitialize();
    181 		beenhere = 1;
    182 	}
    183 
    184 	printf("Entering ACPICA debugger...\n");
    185 	savejmp = db_recover;
    186 	setjmp(&acpi_jmpbuf);
    187 	db_recover = &acpi_jmpbuf;
    188 
    189 	acpi_indebugger = 1;
    190 	AcpiDbUserCommands('A', &obj);
    191 	acpi_indebugger = 0;
    192 
    193 	db_recover = savejmp;
    194 #else
    195 	printf("ACPI: WARNING: ACPICA debugger not present.\n");
    196 #endif
    197 }
    198