diff options
Diffstat (limited to 'source/tools/examples/examples.c')
-rw-r--r-- | source/tools/examples/examples.c | 164 |
1 files changed, 99 insertions, 65 deletions
diff --git a/source/tools/examples/examples.c b/source/tools/examples/examples.c index d90715d..ad31945 100644 --- a/source/tools/examples/examples.c +++ b/source/tools/examples/examples.c @@ -1,6 +1,6 @@ /****************************************************************************** * - * Module Name: examples - Example ACPICA code + * Module Name: examples - Example ACPICA initialization and execution code * *****************************************************************************/ @@ -41,18 +41,8 @@ * POSSIBILITY OF SUCH DAMAGES. */ - -/* Set the ACPICA application type for use in include/platform/acenv.h */ - -#ifndef WIN32 -#define WIN32 -#endif - -#define ACPI_DEBUG_OUTPUT - -/* ACPICA public headers */ - -#include "acpi.h" +#define __EXAMPLES_C__ +#include "examples.h" #define _COMPONENT ACPI_EXAMPLE ACPI_MODULE_NAME ("examples") @@ -81,22 +71,35 @@ * *****************************************************************************/ -/* Standard Clib headers */ - -#include <stdio.h> -#include <string.h> /* Local Prototypes */ -ACPI_STATUS -InitializeFullAcpi (void); +static ACPI_STATUS +InitializeFullAcpica (void); -ACPI_STATUS +static ACPI_STATUS InstallHandlers (void); -void +static void +NotifyHandler ( + ACPI_HANDLE Device, + UINT32 Value, + void *Context); + +static void +ExecuteMAIN (void); + +static void ExecuteOSI (void); +ACPI_STATUS +InitializeAcpiTables ( + void); + +ACPI_STATUS +InitializeAcpi ( + void); + /****************************************************************************** * @@ -116,26 +119,28 @@ main ( int argc, char **argv) { - ACPI_FUNCTION_NAME (Examples-main); - ACPI_DEBUG_INITIALIZE (); /* For debug version only */ - InitializeFullAcpi (); - /* Enable debug output, example debug print */ + printf (ACPI_COMMON_SIGNON ("ACPI Example Code")); + + /* Initialize the local ACPI tables (RSDP/RSDT/XSDT/FADT/DSDT/FACS) */ - AcpiDbgLayer = ACPI_EXAMPLE; - AcpiDbgLevel = ACPI_LV_INIT; - ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Example Debug output\n")); + ExInitializeAcpiTables (); + + /* Initialize the ACPICA subsystem */ + + InitializeFullAcpica (); /* Example warning and error output */ - ACPI_INFO ((AE_INFO, "ACPICA example info message")); - ACPI_WARNING ((AE_INFO, "ACPICA example warning message")); - ACPI_ERROR ((AE_INFO, "ACPICA example error message")); - ACPI_EXCEPTION ((AE_INFO, AE_AML_OPERAND_TYPE, "Example exception message")); + ACPI_INFO ((AE_INFO, "Example ACPICA info message")); + ACPI_WARNING ((AE_INFO, "Example ACPICA warning message")); + ACPI_ERROR ((AE_INFO, "Example ACPICA error message")); + ACPI_EXCEPTION ((AE_INFO, AE_AML_OPERAND_TYPE, "Example ACPICA exception message")); ExecuteOSI (); + ExecuteMAIN (); return (0); } @@ -147,8 +152,8 @@ main ( * *****************************************************************************/ -ACPI_STATUS -InitializeFullAcpi (void) +static ACPI_STATUS +InitializeFullAcpica (void) { ACPI_STATUS Status; @@ -164,6 +169,8 @@ InitializeFullAcpi (void) /* Initialize the ACPICA Table Manager and get all ACPI tables */ + ACPI_INFO ((AE_INFO, "Loading ACPI tables")); + Status = AcpiInitializeTables (NULL, 16, FALSE); if (ACPI_FAILURE (Status)) { @@ -233,7 +240,8 @@ static ACPI_TABLE_DESC TableArray[ACPI_MAX_INIT_TABLES]; * is called, all ACPI tables are available to the host. */ ACPI_STATUS -InitializeAcpiTables (void) +InitializeAcpiTables ( + void) { ACPI_STATUS Status; @@ -251,7 +259,8 @@ InitializeAcpiTables (void) * the ACPICA subsystem. */ ACPI_STATUS -InitializeAcpi (void) +InitializeAcpi ( + void) { ACPI_STATUS Status; @@ -315,7 +324,7 @@ InitializeAcpi (void) * *****************************************************************************/ -void +static void NotifyHandler ( ACPI_HANDLE Device, UINT32 Value, @@ -326,7 +335,7 @@ NotifyHandler ( } -ACPI_STATUS +static ACPI_STATUS InstallHandlers (void) { ACPI_STATUS Status; @@ -348,7 +357,7 @@ InstallHandlers (void) /****************************************************************************** * - * Example control method execution. + * Examples of control method execution. * * _OSI is a predefined method that is implemented internally within ACPICA. * @@ -362,7 +371,7 @@ InstallHandlers (void) * *****************************************************************************/ -void +static void ExecuteOSI (void) { ACPI_STATUS Status; @@ -372,7 +381,7 @@ ExecuteOSI (void) ACPI_OBJECT *Object; - ACPI_INFO ((AE_INFO, "Executing OSI method")); + ACPI_INFO ((AE_INFO, "Executing _OSI reserved method")); /* Setup input argument */ @@ -400,7 +409,7 @@ ExecuteOSI (void) { AcpiOsPrintf ("Return value from _OSI method too small, %.8X\n", ReturnValue.Length); - return; + goto ErrorExit; } /* Expect an integer return value from execution of _OSI */ @@ -412,39 +421,64 @@ ExecuteOSI (void) } ACPI_INFO ((AE_INFO, "_OSI returned 0x%8.8X", (UINT32) Object->Integer.Value)); - AcpiOsFree (Object); - return; + + +ErrorExit: + + /* Free a buffer created via ACPI_ALLOCATE_BUFFER */ + + AcpiOsFree (ReturnValue.Pointer); } /****************************************************************************** * - * OSL support (only needed to link to the windows OSL) + * Execute an actual control method in the DSDT (MAIN) * *****************************************************************************/ -FILE *AcpiGbl_DebugFile; - -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void) +static void +ExecuteMAIN (void) { + ACPI_STATUS Status; + ACPI_OBJECT_LIST ArgList; + ACPI_OBJECT Arg[1]; + ACPI_BUFFER ReturnValue; + ACPI_OBJECT *Object; - return (0); -} -ACPI_THREAD_ID -AcpiOsGetThreadId ( - void) -{ - return (0xFFFF); -} + ACPI_INFO ((AE_INFO, "Executing MAIN method")); -ACPI_STATUS -AcpiOsExecute ( - ACPI_EXECUTE_TYPE Type, - ACPI_OSD_EXEC_CALLBACK Function, - void *Context) -{ - return (AE_SUPPORT); + /* Setup input argument */ + + ArgList.Count = 1; + ArgList.Pointer = Arg; + + Arg[0].Type = ACPI_TYPE_STRING; + Arg[0].String.Pointer = "Method [MAIN] is executing"; + Arg[0].String.Length = strlen (Arg[0].String.Pointer); + + /* Ask ACPICA to allocate space for the return object */ + + ReturnValue.Length = ACPI_ALLOCATE_BUFFER; + + Status = AcpiEvaluateObject (NULL, "\\MAIN", &ArgList, &ReturnValue); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While executing MAIN")); + return; + } + + if (ReturnValue.Pointer) + { + /* Obtain and validate the returned ACPI_OBJECT */ + + Object = ReturnValue.Pointer; + if (Object->Type == ACPI_TYPE_STRING) + { + AcpiOsPrintf ("Method [MAIN] returned: \"%s\"\n", Object->String.Pointer); + } + + ACPI_FREE (ReturnValue.Pointer); + } } |