Home | History | Annotate | Line # | Download | only in acpica
      1  1.16  christos /*	$NetBSD: OsdMisc.c,v 1.16 2017/01/25 13:38:40 christos 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.16  christos  * Copyright (C) 2000 - 2017, Intel Corp.
     40  1.16  christos  * All rights reserved.
     41  1.16  christos  *
     42  1.16  christos  * Redistribution and use in source and binary forms, with or without
     43  1.16  christos  * modification, are permitted provided that the following conditions
     44  1.16  christos  * are met:
     45  1.16  christos  * 1. Redistributions of source code must retain the above copyright
     46  1.16  christos  *    notice, this list of conditions, and the following disclaimer,
     47  1.16  christos  *    without modification.
     48  1.16  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     49  1.16  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     50  1.16  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     51  1.16  christos  *    including a substantially similar Disclaimer requirement for further
     52  1.16  christos  *    binary redistribution.
     53  1.16  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     54  1.16  christos  *    of any contributors may be used to endorse or promote products derived
     55  1.16  christos  *    from this software without specific prior written permission.
     56  1.16  christos  *
     57  1.16  christos  * Alternatively, this software may be distributed under the terms of the
     58  1.16  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     59  1.16  christos  * Software Foundation.
     60  1.16  christos  *
     61  1.16  christos  * NO WARRANTY
     62  1.16  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     63  1.16  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     64  1.16  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     65  1.16  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     66  1.16  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67  1.16  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68  1.16  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69  1.16  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     70  1.16  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     71  1.16  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     72  1.16  christos  * POSSIBILITY OF SUCH DAMAGES.
     73  1.16  christos  */
     74  1.16  christos 
     75  1.16  christos /*
     76   1.1     kochi  * OS Services Layer
     77   1.1     kochi  *
     78   1.1     kochi  * 6.10: Miscellaneous
     79   1.1     kochi  */
     80   1.1     kochi 
     81   1.1     kochi #include <sys/cdefs.h>
     82  1.16  christos __KERNEL_RCSID(0, "$NetBSD: OsdMisc.c,v 1.16 2017/01/25 13:38:40 christos Exp $");
     83   1.1     kochi 
     84   1.1     kochi #include "opt_acpi.h"
     85   1.1     kochi #include "opt_ddb.h"
     86   1.1     kochi 
     87   1.1     kochi #include <sys/param.h>
     88   1.1     kochi #include <sys/systm.h>
     89   1.1     kochi 
     90   1.1     kochi #include <machine/db_machdep.h>
     91   1.1     kochi 
     92   1.1     kochi #include <ddb/db_extern.h>
     93   1.1     kochi #include <ddb/db_output.h>
     94   1.1     kochi 
     95   1.1     kochi #include <dev/acpi/acpica.h>
     96   1.1     kochi #include <dev/acpi/acpi_osd.h>
     97   1.1     kochi 
     98  1.11    jruoho #ifdef ACPI_DEBUG
     99  1.16  christos #include <external/bsd/acpica/dist/include/acpi.h>
    100  1.16  christos #include <external/bsd/acpica/dist/include/accommon.h>
    101  1.11    jruoho #include <external/bsd/acpica/dist/include/acdebug.h>
    102  1.11    jruoho #endif
    103  1.11    jruoho 
    104   1.1     kochi #ifdef ACPI_DSDT_OVERRIDE
    105   1.1     kochi #ifndef ACPI_DSDT_FILE
    106   1.1     kochi #define ACPI_DSDT_FILE "dsdt.hex"
    107   1.1     kochi #endif
    108   1.1     kochi #include ACPI_DSDT_FILE
    109   1.1     kochi #endif
    110   1.1     kochi 
    111   1.1     kochi int acpi_indebugger;
    112   1.1     kochi 
    113   1.1     kochi /*
    114   1.1     kochi  * AcpiOsSignal:
    115   1.1     kochi  *
    116   1.1     kochi  *	Break to the debugger or display a breakpoint message.
    117   1.1     kochi  */
    118   1.1     kochi ACPI_STATUS
    119   1.7  jmcneill AcpiOsSignal(UINT32 Function, void *Info)
    120   1.1     kochi {
    121   1.3     kochi 	/*
    122   1.3     kochi 	 * the upper layer might call with Info = NULL,
    123   1.3     kochi 	 * which makes little sense.
    124   1.3     kochi 	 */
    125   1.3     kochi 	if (Info == NULL)
    126   1.3     kochi 		return AE_NO_MEMORY;
    127   1.1     kochi 
    128   1.1     kochi 	switch (Function) {
    129   1.1     kochi 	case ACPI_SIGNAL_FATAL:
    130   1.1     kochi 	    {
    131   1.7  jmcneill 		ACPI_SIGNAL_FATAL_INFO *info = Info;
    132   1.1     kochi 
    133   1.1     kochi 		panic("ACPI fatal signal: "
    134   1.1     kochi 		    "Type 0x%08x, Code 0x%08x, Argument 0x%08x",
    135   1.1     kochi 		    info->Type, info->Code, info->Argument);
    136   1.1     kochi 		/* NOTREACHED */
    137   1.1     kochi 		break;
    138   1.1     kochi 	    }
    139   1.1     kochi 
    140   1.1     kochi 	case ACPI_SIGNAL_BREAKPOINT:
    141   1.1     kochi 	    {
    142   1.6     joerg #ifdef ACPI_BREAKPOINT
    143   1.7  jmcneill 		char *info = Info;
    144   1.1     kochi 
    145   1.1     kochi 		printf("%s\n", info);
    146   1.6     joerg #  if defined(DDB)
    147   1.1     kochi 		Debugger();
    148   1.6     joerg #  else
    149   1.1     kochi 		printf("ACPI: WARNING: DDB not configured into kernel.\n");
    150   1.1     kochi 		return AE_NOT_EXIST;
    151   1.6     joerg #  endif
    152   1.1     kochi #endif
    153   1.1     kochi 		break;
    154   1.1     kochi 	    }
    155   1.1     kochi 
    156   1.1     kochi 	default:
    157   1.1     kochi 		return AE_BAD_PARAMETER;
    158   1.1     kochi 	}
    159   1.1     kochi 
    160   1.1     kochi 	return AE_OK;
    161   1.1     kochi }
    162   1.1     kochi 
    163   1.1     kochi ACPI_STATUS
    164  1.12    jruoho AcpiOsGetLine(char *Buffer, UINT32 BufferLength, UINT32 *BytesRead)
    165   1.1     kochi {
    166   1.1     kochi #if defined(DDB)
    167   1.1     kochi 	char *cp;
    168   1.1     kochi 
    169   1.1     kochi 	db_readline(Buffer, 80);
    170   1.1     kochi 	for (cp = Buffer; *cp != 0; cp++)
    171   1.1     kochi 		if (*cp == '\n' || *cp == '\r')
    172   1.1     kochi 			*cp = 0;
    173   1.1     kochi 	db_output_line = 0;
    174   1.1     kochi 	return AE_OK;
    175   1.1     kochi #else
    176   1.1     kochi 	printf("ACPI: WARNING: DDB not configured into kernel.\n");
    177   1.1     kochi 	return AE_NOT_EXIST;
    178   1.1     kochi #endif
    179   1.1     kochi }
    180   1.1     kochi 
    181   1.1     kochi ACPI_STATUS
    182   1.5  christos AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
    183   1.1     kochi 		    ACPI_TABLE_HEADER **NewTable)
    184   1.1     kochi {
    185   1.1     kochi #ifndef ACPI_DSDT_OVERRIDE
    186   1.1     kochi 	*NewTable = NULL;
    187   1.1     kochi #else
    188   1.1     kochi 	if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0)
    189   1.1     kochi 		*NewTable = (ACPI_TABLE_HEADER *)AmlCode;
    190   1.1     kochi 	else
    191   1.1     kochi 		*NewTable = NULL;
    192   1.1     kochi #endif
    193   1.1     kochi 	return AE_OK;
    194   1.1     kochi }
    195   1.1     kochi 
    196   1.1     kochi ACPI_STATUS
    197   1.1     kochi AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
    198   1.1     kochi 			 ACPI_STRING *NewVal)
    199   1.1     kochi {
    200   1.1     kochi 	if (!InitVal || !NewVal)
    201   1.1     kochi 		return AE_BAD_PARAMETER;
    202   1.1     kochi 
    203   1.1     kochi 	*NewVal = NULL;
    204   1.1     kochi 	return AE_OK;
    205   1.1     kochi }
    206   1.1     kochi 
    207  1.13  christos 
    208  1.13  christos /*
    209  1.13  christos  * AcpiOsPhysicalTableOverride:
    210  1.13  christos  *
    211  1.13  christos  * ExistingTable       - Header of current table (probably firmware)
    212  1.13  christos  * NewAddress          - Where new table address is returned
    213  1.13  christos  *                       (Physical address)
    214  1.13  christos  * NewTableLength      - Where new table length is returned
    215  1.13  christos  *
    216  1.13  christos  * RETURN:      Status, address/length of new table. Null pointer returned
    217  1.13  christos  *              if no table is available to override.
    218  1.13  christos  *
    219  1.13  christos  * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
    220  1.13  christos  */
    221  1.13  christos ACPI_STATUS
    222  1.13  christos AcpiOsPhysicalTableOverride (
    223  1.13  christos     ACPI_TABLE_HEADER       *ExistingTable,
    224  1.13  christos     ACPI_PHYSICAL_ADDRESS   *NewAddress,
    225  1.13  christos     UINT32                  *NewTableLength)
    226  1.13  christos {
    227  1.13  christos 
    228  1.13  christos 	return AE_SUPPORT;
    229  1.13  christos }
    230  1.13  christos 
    231  1.16  christos /******************************************************************************
    232  1.16  christos  *
    233  1.16  christos  * FUNCTION:    AcpiOsEnterSleep
    234  1.16  christos  *
    235  1.16  christos  * PARAMETERS:  SleepState          - Which sleep state to enter
    236  1.16  christos  *              RegaValue           - Register A value
    237  1.16  christos  *              RegbValue           - Register B value
    238  1.16  christos  *
    239  1.16  christos  * RETURN:      Status
    240  1.16  christos  *
    241  1.16  christos  * DESCRIPTION: A hook before writing sleep registers to enter the sleep
    242  1.16  christos  *              state. Return AE_CTRL_TERMINATE to skip further sleep register
    243  1.16  christos  *              writes.
    244  1.16  christos  *
    245  1.16  christos  *****************************************************************************/
    246  1.16  christos 
    247  1.16  christos ACPI_STATUS
    248  1.16  christos AcpiOsEnterSleep (
    249  1.16  christos     UINT8                   SleepState,
    250  1.16  christos     UINT32                  RegaValue,
    251  1.16  christos     UINT32                  RegbValue)
    252  1.16  christos {
    253  1.16  christos 
    254  1.16  christos     return AE_OK;
    255  1.16  christos }
    256  1.16  christos 
    257  1.16  christos 
    258   1.1     kochi /*
    259   1.1     kochi  * acpi_osd_debugger:
    260   1.1     kochi  *
    261   1.1     kochi  *	Enter the ACPICA debugger.
    262   1.1     kochi  */
    263   1.1     kochi void
    264   1.1     kochi acpi_osd_debugger(void)
    265   1.1     kochi {
    266  1.14  christos #ifdef ACPI_DEBUG
    267   1.1     kochi 	label_t	acpi_jmpbuf;
    268   1.1     kochi 	label_t	*savejmp;
    269   1.1     kochi 
    270   1.1     kochi 	printf("Entering ACPICA debugger...\n");
    271   1.1     kochi 	savejmp = db_recover;
    272   1.1     kochi 	setjmp(&acpi_jmpbuf);
    273   1.1     kochi 	db_recover = &acpi_jmpbuf;
    274   1.1     kochi 
    275   1.1     kochi 	acpi_indebugger = 1;
    276  1.16  christos 	AcpiDbUserCommands();
    277   1.1     kochi 	acpi_indebugger = 0;
    278   1.1     kochi 
    279   1.1     kochi 	db_recover = savejmp;
    280   1.1     kochi #else
    281   1.1     kochi 	printf("ACPI: WARNING: ACPICA debugger not present.\n");
    282   1.1     kochi #endif
    283   1.1     kochi }
    284  1.16  christos 
    285  1.16  christos #ifdef ACPI_DEBUG
    286  1.16  christos 
    287  1.16  christos #define _COMPONENT          ACPI_CA_DEBUGGER
    288  1.16  christos         ACPI_MODULE_NAME    ("osnetbsdbg")
    289  1.16  christos 
    290  1.16  christos 
    291  1.16  christos /******************************************************************************
    292  1.16  christos  *
    293  1.16  christos  * FUNCTION:    AcpiOsWaitCommandReady
    294  1.16  christos  *
    295  1.16  christos  * PARAMETERS:  None
    296  1.16  christos  *
    297  1.16  christos  * RETURN:      Status
    298  1.16  christos  *
    299  1.16  christos  * DESCRIPTION: Negotiate with the debugger foreground thread (the user
    300  1.16  christos  *              thread) to wait the readiness of a command.
    301  1.16  christos  *
    302  1.16  christos  *****************************************************************************/
    303  1.16  christos 
    304  1.16  christos ACPI_STATUS
    305  1.16  christos AcpiOsWaitCommandReady (
    306  1.16  christos     void)
    307  1.16  christos {
    308  1.16  christos     ACPI_STATUS             Status;
    309  1.16  christos     /* Force output to console until a command is entered */
    310  1.16  christos 
    311  1.16  christos     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
    312  1.16  christos 
    313  1.16  christos     /* Different prompt if method is executing */
    314  1.16  christos 
    315  1.16  christos     if (!AcpiGbl_MethodExecuting)
    316  1.16  christos     {
    317  1.16  christos 	AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_COMMAND_PROMPT);
    318  1.16  christos     }
    319  1.16  christos     else
    320  1.16  christos     {
    321  1.16  christos 	AcpiOsPrintf ("%1c ", ACPI_DEBUGGER_EXECUTE_PROMPT);
    322  1.16  christos     }
    323  1.16  christos 
    324  1.16  christos     /* Get the user input line */
    325  1.16  christos 
    326  1.16  christos     Status = AcpiOsGetLine (AcpiGbl_DbLineBuf,
    327  1.16  christos 	ACPI_DB_LINE_BUFFER_SIZE, NULL);
    328  1.16  christos 
    329  1.16  christos     if (ACPI_FAILURE (Status) && Status != AE_CTRL_TERMINATE)
    330  1.16  christos     {
    331  1.16  christos         ACPI_EXCEPTION ((AE_INFO, Status,
    332  1.16  christos             "While parsing/handling command line"));
    333  1.16  christos     }
    334  1.16  christos     return (Status);
    335  1.16  christos }
    336  1.16  christos 
    337  1.16  christos 
    338  1.16  christos /******************************************************************************
    339  1.16  christos  *
    340  1.16  christos  * FUNCTION:    AcpiOsNotifyCommandComplete
    341  1.16  christos  *
    342  1.16  christos  * PARAMETERS:  void
    343  1.16  christos  *
    344  1.16  christos  * RETURN:      Status
    345  1.16  christos  *
    346  1.16  christos  * DESCRIPTION: Negotiate with the debugger foreground thread (the user
    347  1.16  christos  *              thread) to notify the completion of a command.
    348  1.16  christos  *
    349  1.16  christos  *****************************************************************************/
    350  1.16  christos 
    351  1.16  christos ACPI_STATUS
    352  1.16  christos AcpiOsNotifyCommandComplete (
    353  1.16  christos     void)
    354  1.16  christos {
    355  1.16  christos 
    356  1.16  christos     return AE_OK;
    357  1.16  christos }
    358  1.16  christos 
    359  1.16  christos 
    360  1.16  christos /******************************************************************************
    361  1.16  christos  *
    362  1.16  christos  * FUNCTION:    AcpiOsInitializeDebugger
    363  1.16  christos  *
    364  1.16  christos  * PARAMETERS:  None
    365  1.16  christos  *
    366  1.16  christos  * RETURN:      Status
    367  1.16  christos  *
    368  1.16  christos  * DESCRIPTION: Initialize OSPM specific part of the debugger
    369  1.16  christos  *
    370  1.16  christos  *****************************************************************************/
    371  1.16  christos 
    372  1.16  christos ACPI_STATUS
    373  1.16  christos AcpiOsInitializeDebugger (
    374  1.16  christos     void)
    375  1.16  christos {
    376  1.16  christos     return AE_OK;
    377  1.16  christos }
    378  1.16  christos 
    379  1.16  christos 
    380  1.16  christos /******************************************************************************
    381  1.16  christos  *
    382  1.16  christos  * FUNCTION:    AcpiOsTerminateDebugger
    383  1.16  christos  *
    384  1.16  christos  * PARAMETERS:  None
    385  1.16  christos  *
    386  1.16  christos  * RETURN:      None
    387  1.16  christos  *
    388  1.16  christos  * DESCRIPTION: Terminate signals used by the multi-threading debugger
    389  1.16  christos  *
    390  1.16  christos  *****************************************************************************/
    391  1.16  christos 
    392  1.16  christos void
    393  1.16  christos AcpiOsTerminateDebugger (
    394  1.16  christos     void)
    395  1.16  christos {
    396  1.16  christos }
    397  1.16  christos 
    398  1.16  christos 
    399  1.16  christos /******************************************************************************
    400  1.16  christos  *
    401  1.16  christos  * FUNCTION:    AcpiRunDebugger
    402  1.16  christos  *
    403  1.16  christos  * PARAMETERS:  BatchBuffer         - Buffer containing commands running in
    404  1.16  christos  *                                    the batch mode
    405  1.16  christos  *
    406  1.16  christos  * RETURN:      None
    407  1.16  christos  *
    408  1.16  christos  * DESCRIPTION: Run a local/remote debugger
    409  1.16  christos  *
    410  1.16  christos  *****************************************************************************/
    411  1.16  christos 
    412  1.16  christos void
    413  1.16  christos AcpiRunDebugger (
    414  1.16  christos     char                    *BatchBuffer)
    415  1.16  christos {
    416  1.16  christos         AcpiDbUserCommands ();
    417  1.16  christos }
    418  1.16  christos 
    419  1.16  christos ACPI_EXPORT_SYMBOL (AcpiRunDebugger)
    420  1.16  christos #endif
    421