OsdDebug.c revision 167573
167760Smsmith/*-
267760Smsmith * Copyright (c) 2000 Michael Smith
367760Smsmith * Copyright (c) 2000 BSDi
467760Smsmith * All rights reserved.
567760Smsmith *
667760Smsmith * Redistribution and use in source and binary forms, with or without
767760Smsmith * modification, are permitted provided that the following conditions
867760Smsmith * are met:
967760Smsmith * 1. Redistributions of source code must retain the above copyright
1067760Smsmith *    notice, this list of conditions and the following disclaimer.
1167760Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1267760Smsmith *    notice, this list of conditions and the following disclaimer in the
1367760Smsmith *    documentation and/or other materials provided with the distribution.
1467760Smsmith *
1567760Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1667760Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1767760Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1867760Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1967760Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2067760Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2167760Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2267760Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2367760Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2467760Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2567760Smsmith * SUCH DAMAGE.
2667760Smsmith */
2767760Smsmith
2867760Smsmith/*
2967760Smsmith * 6.8 : Debugging support
3067760Smsmith */
3167760Smsmith
32148318Snjl#include <sys/cdefs.h>
33148318Snjl__FBSDID("$FreeBSD: head/sys/dev/acpica/Osd/OsdDebug.c 167573 2007-03-14 19:56:10Z njl $");
34148318Snjl
3567760Smsmith#include "opt_ddb.h"
3667760Smsmith#include <sys/param.h>
37131910Smarcel#include <sys/kdb.h>
3867760Smsmith#include <sys/kernel.h>
3967760Smsmith#include <sys/bus.h>
4067760Smsmith#include <machine/bus.h>
41128240Snjl#include <ddb/ddb.h>
42128240Snjl#include <ddb/db_output.h>
4367760Smsmith
44150003Sobrien#include <contrib/dev/acpica/acpi.h>
45150003Sobrien#include <contrib/dev/acpica/acdebug.h>
4667760Smsmith#include <dev/acpica/acpivar.h>
4767760Smsmith
4867760SmsmithUINT32
49114246SnjlAcpiOsGetLine(char *Buffer)
5067760Smsmith{
5167760Smsmith#ifdef DDB
5267760Smsmith    char	*cp;
5367760Smsmith
5467760Smsmith    db_readline(Buffer, 80);
5567760Smsmith    for (cp = Buffer; *cp != 0; cp++)
5667760Smsmith	if (*cp == '\n')
5767760Smsmith	    *cp = 0;
58128225Snjl    return (AE_OK);
5967760Smsmith#else
6067760Smsmith    printf("AcpiOsGetLine called but no input support");
61128225Snjl    return (AE_NOT_EXIST);
62128225Snjl#endif /* DDB */
6367760Smsmith}
6467760Smsmith
6567760Smsmithvoid
66128225SnjlAcpiOsDbgAssert(void *FailedAssertion, void *FileName, UINT32 LineNumber,
67128225Snjl    char *Message)
6867760Smsmith{
6967760Smsmith    printf("ACPI: %s:%d - %s\n", (char *)FileName, LineNumber, Message);
7067760Smsmith    printf("ACPI: assertion  %s\n", (char *)FailedAssertion);
7167760Smsmith}
7267760Smsmith
7380071SmsmithACPI_STATUS
74128225SnjlAcpiOsSignal(UINT32 Function, void *Info)
7580071Smsmith{
7680071Smsmith    ACPI_SIGNAL_FATAL_INFO	*fatal;
77134628Snjl
78128225Snjl    switch (Function) {
7980071Smsmith    case ACPI_SIGNAL_FATAL:
8080071Smsmith	fatal = (ACPI_SIGNAL_FATAL_INFO *)Info;
81167573Snjl	printf("ACPI fatal signal, type 0x%x code 0x%x argument 0x%x",
8280071Smsmith	      fatal->Type, fatal->Code, fatal->Argument);
83167573Snjl#ifdef ACPI_DEBUG
84131910Smarcel	kdb_enter("AcpiOsSignal");
85167573Snjl#endif
8680071Smsmith	break;
87134628Snjl
8880071Smsmith    case ACPI_SIGNAL_BREAKPOINT:
89134628Snjl#ifdef ACPI_DEBUG
90134628Snjl	kdb_enter((char *)Info);
91134628Snjl#endif
9280071Smsmith	break;
9380071Smsmith
9480071Smsmith    default:
95128225Snjl	return (AE_BAD_PARAMETER);
9680071Smsmith    }
97128225Snjl
98128225Snjl    return (AE_OK);
9980071Smsmith}
10080071Smsmith
101102553Siwasaki#ifdef ACPI_DEBUGGER
10267760Smsmithvoid
10367760Smsmithacpi_EnterDebugger(void)
10467760Smsmith{
10567760Smsmith    ACPI_PARSE_OBJECT	obj;
10667760Smsmith    static int		initted = 0;
10767760Smsmith
10867760Smsmith    if (!initted) {
10967760Smsmith	printf("Initialising ACPICA debugger...\n");
11067760Smsmith	AcpiDbInitialize();
11167760Smsmith	initted = 1;
11267760Smsmith    }
11367760Smsmith
11467760Smsmith    printf("Entering ACPICA debugger...\n");
11567760Smsmith    AcpiDbUserCommands('A', &obj);
11667760Smsmith}
117128225Snjl#endif /* ACPI_DEBUGGER */
118