Home | History | Annotate | Line # | Download | only in acpica
OsdMisc.c revision 1.2.2.2
      1  1.2.2.2  tron /*	$NetBSD: OsdMisc.c,v 1.2.2.2 2006/03/28 09:42:03 tron Exp $	*/
      2  1.2.2.2  tron 
      3  1.2.2.2  tron /*
      4  1.2.2.2  tron  * Copyright 2001 Wasabi Systems, Inc.
      5  1.2.2.2  tron  * All rights reserved.
      6  1.2.2.2  tron  *
      7  1.2.2.2  tron  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.2.2.2  tron  *
      9  1.2.2.2  tron  * Redistribution and use in source and binary forms, with or without
     10  1.2.2.2  tron  * modification, are permitted provided that the following conditions
     11  1.2.2.2  tron  * are met:
     12  1.2.2.2  tron  * 1. Redistributions of source code must retain the above copyright
     13  1.2.2.2  tron  *    notice, this list of conditions and the following disclaimer.
     14  1.2.2.2  tron  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.2.2.2  tron  *    notice, this list of conditions and the following disclaimer in the
     16  1.2.2.2  tron  *    documentation and/or other materials provided with the distribution.
     17  1.2.2.2  tron  * 3. All advertising materials mentioning features or use of this software
     18  1.2.2.2  tron  *    must display the following acknowledgement:
     19  1.2.2.2  tron  *	This product includes software developed for the NetBSD Project by
     20  1.2.2.2  tron  *	Wasabi Systems, Inc.
     21  1.2.2.2  tron  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.2.2.2  tron  *    or promote products derived from this software without specific prior
     23  1.2.2.2  tron  *    written permission.
     24  1.2.2.2  tron  *
     25  1.2.2.2  tron  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.2.2.2  tron  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.2.2.2  tron  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.2.2.2  tron  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.2.2.2  tron  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.2.2.2  tron  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.2.2.2  tron  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.2.2.2  tron  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.2.2.2  tron  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.2.2.2  tron  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.2.2.2  tron  * POSSIBILITY OF SUCH DAMAGE.
     36  1.2.2.2  tron  */
     37  1.2.2.2  tron 
     38  1.2.2.2  tron /*
     39  1.2.2.2  tron  * OS Services Layer
     40  1.2.2.2  tron  *
     41  1.2.2.2  tron  * 6.10: Miscellaneous
     42  1.2.2.2  tron  */
     43  1.2.2.2  tron 
     44  1.2.2.2  tron #include <sys/cdefs.h>
     45  1.2.2.2  tron __KERNEL_RCSID(0, "$NetBSD: OsdMisc.c,v 1.2.2.2 2006/03/28 09:42:03 tron Exp $");
     46  1.2.2.2  tron 
     47  1.2.2.2  tron #include "opt_acpi.h"
     48  1.2.2.2  tron #include "opt_ddb.h"
     49  1.2.2.2  tron 
     50  1.2.2.2  tron #include <sys/param.h>
     51  1.2.2.2  tron #include <sys/systm.h>
     52  1.2.2.2  tron 
     53  1.2.2.2  tron #include <machine/db_machdep.h>
     54  1.2.2.2  tron 
     55  1.2.2.2  tron #include <ddb/db_extern.h>
     56  1.2.2.2  tron #include <ddb/db_output.h>
     57  1.2.2.2  tron 
     58  1.2.2.2  tron #include <dev/acpi/acpica.h>
     59  1.2.2.2  tron #include <dev/acpi/acpi_osd.h>
     60  1.2.2.2  tron 
     61  1.2.2.2  tron #include <dist/acpica/acdebug.h>
     62  1.2.2.2  tron /*
     63  1.2.2.2  tron  * for debugging DSDT (try this at your own risk!):
     64  1.2.2.2  tron  *
     65  1.2.2.2  tron  * 1. dump your raw DSDT (with acpidump(*1) etc.)
     66  1.2.2.2  tron  * 2. disassemble with iasl -d (*2)
     67  1.2.2.2  tron  * 3. modify the ASL file
     68  1.2.2.2  tron  * 4. compile it with iasl -tc
     69  1.2.2.2  tron  * 5. copy *.hex to src/sys/dev/acpi/acpica/Osd/dsdt.hex
     70  1.2.2.2  tron  *    -or-
     71  1.2.2.2  tron  *    options ACPI_DSDT_FILE="\"yourdsdt.hex\"" in
     72  1.2.2.2  tron  *    your config file and yourdsdt.hex in the build directory
     73  1.2.2.2  tron  * 6. options ACPI_DSDT_OVERRIDE in your kernel config file
     74  1.2.2.2  tron  *    and rebuild the kernel
     75  1.2.2.2  tron  *
     76  1.2.2.2  tron  * (*1) /usr/pkgsrc/sysutils/acpidump
     77  1.2.2.2  tron  * (*2) /usr/pkgsrc/sysutils/acpi-iasl
     78  1.2.2.2  tron  */
     79  1.2.2.2  tron 
     80  1.2.2.2  tron #ifdef ACPI_DSDT_OVERRIDE
     81  1.2.2.2  tron #ifndef ACPI_DSDT_FILE
     82  1.2.2.2  tron #define ACPI_DSDT_FILE "dsdt.hex"
     83  1.2.2.2  tron #endif
     84  1.2.2.2  tron #include ACPI_DSDT_FILE
     85  1.2.2.2  tron #endif
     86  1.2.2.2  tron 
     87  1.2.2.2  tron int acpi_indebugger;
     88  1.2.2.2  tron 
     89  1.2.2.2  tron /*
     90  1.2.2.2  tron  * AcpiOsSignal:
     91  1.2.2.2  tron  *
     92  1.2.2.2  tron  *	Break to the debugger or display a breakpoint message.
     93  1.2.2.2  tron  */
     94  1.2.2.2  tron ACPI_STATUS
     95  1.2.2.2  tron AcpiOsSignal(UINT32 Function, const void *Info)
     96  1.2.2.2  tron {
     97  1.2.2.2  tron 
     98  1.2.2.2  tron 	switch (Function) {
     99  1.2.2.2  tron 	case ACPI_SIGNAL_FATAL:
    100  1.2.2.2  tron 	    {
    101  1.2.2.2  tron 		const ACPI_SIGNAL_FATAL_INFO *info = Info;
    102  1.2.2.2  tron 
    103  1.2.2.2  tron 		panic("ACPI fatal signal: "
    104  1.2.2.2  tron 		    "Type 0x%08x, Code 0x%08x, Argument 0x%08x",
    105  1.2.2.2  tron 		    info->Type, info->Code, info->Argument);
    106  1.2.2.2  tron 		/* NOTREACHED */
    107  1.2.2.2  tron 		break;
    108  1.2.2.2  tron 	    }
    109  1.2.2.2  tron 
    110  1.2.2.2  tron 	case ACPI_SIGNAL_BREAKPOINT:
    111  1.2.2.2  tron 	    {
    112  1.2.2.2  tron 		const char *info = Info;
    113  1.2.2.2  tron 
    114  1.2.2.2  tron 		printf("%s\n", info);
    115  1.2.2.2  tron #if defined(DDB)
    116  1.2.2.2  tron 		Debugger();
    117  1.2.2.2  tron #else
    118  1.2.2.2  tron 		printf("ACPI: WARNING: DDB not configured into kernel.\n");
    119  1.2.2.2  tron 		return AE_NOT_EXIST;
    120  1.2.2.2  tron #endif
    121  1.2.2.2  tron 		break;
    122  1.2.2.2  tron 	    }
    123  1.2.2.2  tron 
    124  1.2.2.2  tron 	default:
    125  1.2.2.2  tron 		return AE_BAD_PARAMETER;
    126  1.2.2.2  tron 	}
    127  1.2.2.2  tron 
    128  1.2.2.2  tron 	return AE_OK;
    129  1.2.2.2  tron }
    130  1.2.2.2  tron 
    131  1.2.2.2  tron ACPI_STATUS
    132  1.2.2.2  tron AcpiOsGetLine(char *Buffer)
    133  1.2.2.2  tron {
    134  1.2.2.2  tron #if defined(DDB)
    135  1.2.2.2  tron 	char *cp;
    136  1.2.2.2  tron 
    137  1.2.2.2  tron 	db_readline(Buffer, 80);
    138  1.2.2.2  tron 	for (cp = Buffer; *cp != 0; cp++)
    139  1.2.2.2  tron 		if (*cp == '\n' || *cp == '\r')
    140  1.2.2.2  tron 			*cp = 0;
    141  1.2.2.2  tron 	db_output_line = 0;
    142  1.2.2.2  tron 	return AE_OK;
    143  1.2.2.2  tron #else
    144  1.2.2.2  tron 	printf("ACPI: WARNING: DDB not configured into kernel.\n");
    145  1.2.2.2  tron 	return AE_NOT_EXIST;
    146  1.2.2.2  tron #endif
    147  1.2.2.2  tron }
    148  1.2.2.2  tron 
    149  1.2.2.2  tron ACPI_STATUS
    150  1.2.2.2  tron AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
    151  1.2.2.2  tron 		    ACPI_TABLE_HEADER **NewTable)
    152  1.2.2.2  tron {
    153  1.2.2.2  tron #ifndef ACPI_DSDT_OVERRIDE
    154  1.2.2.2  tron 	*NewTable = NULL;
    155  1.2.2.2  tron #else
    156  1.2.2.2  tron 	if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0)
    157  1.2.2.2  tron 		*NewTable = (ACPI_TABLE_HEADER *)AmlCode;
    158  1.2.2.2  tron 	else
    159  1.2.2.2  tron 		*NewTable = NULL;
    160  1.2.2.2  tron #endif
    161  1.2.2.2  tron 	return AE_OK;
    162  1.2.2.2  tron }
    163  1.2.2.2  tron 
    164  1.2.2.2  tron ACPI_STATUS
    165  1.2.2.2  tron AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
    166  1.2.2.2  tron 			 ACPI_STRING *NewVal)
    167  1.2.2.2  tron {
    168  1.2.2.2  tron 	if (!InitVal || !NewVal)
    169  1.2.2.2  tron 		return AE_BAD_PARAMETER;
    170  1.2.2.2  tron 
    171  1.2.2.2  tron 	*NewVal = NULL;
    172  1.2.2.2  tron 	return AE_OK;
    173  1.2.2.2  tron }
    174  1.2.2.2  tron 
    175  1.2.2.2  tron /*
    176  1.2.2.2  tron  * acpi_osd_debugger:
    177  1.2.2.2  tron  *
    178  1.2.2.2  tron  *	Enter the ACPICA debugger.
    179  1.2.2.2  tron  */
    180  1.2.2.2  tron void
    181  1.2.2.2  tron acpi_osd_debugger(void)
    182  1.2.2.2  tron {
    183  1.2.2.2  tron #ifdef ACPI_DEBUGGER
    184  1.2.2.2  tron 	static int beenhere;
    185  1.2.2.2  tron 	ACPI_PARSE_OBJECT obj;
    186  1.2.2.2  tron 	label_t	acpi_jmpbuf;
    187  1.2.2.2  tron 	label_t	*savejmp;
    188  1.2.2.2  tron 
    189  1.2.2.2  tron 	if (beenhere == 0) {
    190  1.2.2.2  tron 		printf("Initializing ACPICA debugger...\n");
    191  1.2.2.2  tron 		AcpiDbInitialize();
    192  1.2.2.2  tron 		beenhere = 1;
    193  1.2.2.2  tron 	}
    194  1.2.2.2  tron 
    195  1.2.2.2  tron 	printf("Entering ACPICA debugger...\n");
    196  1.2.2.2  tron 	savejmp = db_recover;
    197  1.2.2.2  tron 	setjmp(&acpi_jmpbuf);
    198  1.2.2.2  tron 	db_recover = &acpi_jmpbuf;
    199  1.2.2.2  tron 
    200  1.2.2.2  tron 	acpi_indebugger = 1;
    201  1.2.2.2  tron 	AcpiDbUserCommands('A', &obj);
    202  1.2.2.2  tron 	acpi_indebugger = 0;
    203  1.2.2.2  tron 
    204  1.2.2.2  tron 	db_recover = savejmp;
    205  1.2.2.2  tron #else
    206  1.2.2.2  tron 	printf("ACPI: WARNING: ACPICA debugger not present.\n");
    207  1.2.2.2  tron #endif
    208  1.2.2.2  tron }
    209