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