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