examples.c revision 1.1.1.5 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1.1.4 christos * Module Name: examples - Example ACPICA initialization and execution code
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.5 christos * Copyright (C) 2000 - 2014, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1.1.4 christos #define __EXAMPLES_C__
45 1.1.1.4 christos #include "examples.h"
46 1.1 jruoho
47 1.1 jruoho #define _COMPONENT ACPI_EXAMPLE
48 1.1 jruoho ACPI_MODULE_NAME ("examples")
49 1.1 jruoho
50 1.1 jruoho
51 1.1 jruoho /******************************************************************************
52 1.1 jruoho *
53 1.1 jruoho * ACPICA Example Code
54 1.1 jruoho *
55 1.1 jruoho * This module contains examples of how the host OS should interface to the
56 1.1 jruoho * ACPICA subsystem.
57 1.1 jruoho *
58 1.1 jruoho * 1) How to use the platform/acenv.h file and how to set configuration
59 1.1 jruoho * options.
60 1.1 jruoho *
61 1.1 jruoho * 2) main - using the debug output mechanism and the error/warning output
62 1.1 jruoho * macros.
63 1.1 jruoho *
64 1.1 jruoho * 3) Two examples of the ACPICA initialization sequence. The first is a
65 1.1 jruoho * initialization with no "early" ACPI table access. The second shows
66 1.1 jruoho * how to use ACPICA to obtain the tables very early during kernel
67 1.1 jruoho * initialization, even before dynamic memory is available.
68 1.1 jruoho *
69 1.1 jruoho * 4) How to invoke a control method, including argument setup and how to
70 1.1 jruoho * access the return value.
71 1.1 jruoho *
72 1.1 jruoho *****************************************************************************/
73 1.1 jruoho
74 1.1 jruoho
75 1.1 jruoho /* Local Prototypes */
76 1.1 jruoho
77 1.1.1.4 christos static ACPI_STATUS
78 1.1.1.4 christos InitializeFullAcpica (void);
79 1.1 jruoho
80 1.1.1.4 christos static ACPI_STATUS
81 1.1 jruoho InstallHandlers (void);
82 1.1 jruoho
83 1.1.1.4 christos static void
84 1.1.1.4 christos NotifyHandler (
85 1.1.1.4 christos ACPI_HANDLE Device,
86 1.1.1.4 christos UINT32 Value,
87 1.1.1.4 christos void *Context);
88 1.1.1.4 christos
89 1.1.1.5 christos static ACPI_STATUS
90 1.1.1.5 christos RegionHandler (
91 1.1.1.5 christos UINT32 Function,
92 1.1.1.5 christos ACPI_PHYSICAL_ADDRESS Address,
93 1.1.1.5 christos UINT32 BitWidth,
94 1.1.1.5 christos UINT64 *Value,
95 1.1.1.5 christos void *HandlerContext,
96 1.1.1.5 christos void *RegionContext);
97 1.1.1.5 christos
98 1.1.1.5 christos static ACPI_STATUS
99 1.1.1.5 christos RegionInit (
100 1.1.1.5 christos ACPI_HANDLE RegionHandle,
101 1.1.1.5 christos UINT32 Function,
102 1.1.1.5 christos void *HandlerContext,
103 1.1.1.5 christos void **RegionContext);
104 1.1.1.5 christos
105 1.1.1.4 christos static void
106 1.1.1.4 christos ExecuteMAIN (void);
107 1.1.1.4 christos
108 1.1.1.4 christos static void
109 1.1 jruoho ExecuteOSI (void);
110 1.1 jruoho
111 1.1.1.4 christos ACPI_STATUS
112 1.1.1.4 christos InitializeAcpiTables (
113 1.1.1.4 christos void);
114 1.1.1.4 christos
115 1.1.1.4 christos ACPI_STATUS
116 1.1.1.4 christos InitializeAcpi (
117 1.1.1.4 christos void);
118 1.1.1.4 christos
119 1.1 jruoho
120 1.1 jruoho /******************************************************************************
121 1.1 jruoho *
122 1.1 jruoho * FUNCTION: main
123 1.1 jruoho *
124 1.1 jruoho * PARAMETERS: argc, argv
125 1.1 jruoho *
126 1.1 jruoho * RETURN: Status
127 1.1 jruoho *
128 1.1 jruoho * DESCRIPTION: Main routine. Shows the use of the various output macros, as
129 1.1 jruoho * well as the use of the debug layer/level globals.
130 1.1 jruoho *
131 1.1 jruoho *****************************************************************************/
132 1.1 jruoho
133 1.1 jruoho int ACPI_SYSTEM_XFACE
134 1.1 jruoho main (
135 1.1 jruoho int argc,
136 1.1 jruoho char **argv)
137 1.1 jruoho {
138 1.1 jruoho
139 1.1.1.4 christos ACPI_DEBUG_INITIALIZE (); /* For debug version only */
140 1.1.1.4 christos
141 1.1.1.4 christos printf (ACPI_COMMON_SIGNON ("ACPI Example Code"));
142 1.1 jruoho
143 1.1.1.4 christos /* Initialize the local ACPI tables (RSDP/RSDT/XSDT/FADT/DSDT/FACS) */
144 1.1 jruoho
145 1.1.1.4 christos ExInitializeAcpiTables ();
146 1.1 jruoho
147 1.1.1.4 christos /* Initialize the ACPICA subsystem */
148 1.1.1.4 christos
149 1.1.1.4 christos InitializeFullAcpica ();
150 1.1 jruoho
151 1.1 jruoho /* Example warning and error output */
152 1.1 jruoho
153 1.1.1.4 christos ACPI_INFO ((AE_INFO, "Example ACPICA info message"));
154 1.1.1.4 christos ACPI_WARNING ((AE_INFO, "Example ACPICA warning message"));
155 1.1.1.4 christos ACPI_ERROR ((AE_INFO, "Example ACPICA error message"));
156 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, AE_AML_OPERAND_TYPE, "Example ACPICA exception message"));
157 1.1 jruoho
158 1.1 jruoho ExecuteOSI ();
159 1.1.1.4 christos ExecuteMAIN ();
160 1.1 jruoho return (0);
161 1.1 jruoho }
162 1.1 jruoho
163 1.1 jruoho
164 1.1 jruoho /******************************************************************************
165 1.1 jruoho *
166 1.1 jruoho * Example ACPICA initialization code. This shows a full initialization with
167 1.1 jruoho * no early ACPI table access.
168 1.1 jruoho *
169 1.1 jruoho *****************************************************************************/
170 1.1 jruoho
171 1.1.1.4 christos static ACPI_STATUS
172 1.1.1.4 christos InitializeFullAcpica (void)
173 1.1 jruoho {
174 1.1 jruoho ACPI_STATUS Status;
175 1.1 jruoho
176 1.1 jruoho
177 1.1 jruoho /* Initialize the ACPICA subsystem */
178 1.1 jruoho
179 1.1 jruoho Status = AcpiInitializeSubsystem ();
180 1.1 jruoho if (ACPI_FAILURE (Status))
181 1.1 jruoho {
182 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While initializing ACPICA"));
183 1.1 jruoho return (Status);
184 1.1 jruoho }
185 1.1 jruoho
186 1.1 jruoho /* Initialize the ACPICA Table Manager and get all ACPI tables */
187 1.1 jruoho
188 1.1.1.4 christos ACPI_INFO ((AE_INFO, "Loading ACPI tables"));
189 1.1.1.4 christos
190 1.1 jruoho Status = AcpiInitializeTables (NULL, 16, FALSE);
191 1.1 jruoho if (ACPI_FAILURE (Status))
192 1.1 jruoho {
193 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While initializing Table Manager"));
194 1.1 jruoho return (Status);
195 1.1 jruoho }
196 1.1 jruoho
197 1.1 jruoho /* Create the ACPI namespace from ACPI tables */
198 1.1 jruoho
199 1.1 jruoho Status = AcpiLoadTables ();
200 1.1 jruoho if (ACPI_FAILURE (Status))
201 1.1 jruoho {
202 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While loading ACPI tables"));
203 1.1 jruoho return (Status);
204 1.1 jruoho }
205 1.1 jruoho
206 1.1 jruoho /* Install local handlers */
207 1.1 jruoho
208 1.1 jruoho Status = InstallHandlers ();
209 1.1 jruoho if (ACPI_FAILURE (Status))
210 1.1 jruoho {
211 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While installing handlers"));
212 1.1 jruoho return (Status);
213 1.1 jruoho }
214 1.1 jruoho
215 1.1 jruoho /* Initialize the ACPI hardware */
216 1.1 jruoho
217 1.1 jruoho Status = AcpiEnableSubsystem (ACPI_FULL_INITIALIZATION);
218 1.1 jruoho if (ACPI_FAILURE (Status))
219 1.1 jruoho {
220 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While enabling ACPICA"));
221 1.1 jruoho return (Status);
222 1.1 jruoho }
223 1.1 jruoho
224 1.1 jruoho /* Complete the ACPI namespace object initialization */
225 1.1 jruoho
226 1.1 jruoho Status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION);
227 1.1 jruoho if (ACPI_FAILURE (Status))
228 1.1 jruoho {
229 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While initializing ACPICA objects"));
230 1.1 jruoho return (Status);
231 1.1 jruoho }
232 1.1 jruoho
233 1.1 jruoho return (AE_OK);
234 1.1 jruoho }
235 1.1 jruoho
236 1.1 jruoho
237 1.1 jruoho /******************************************************************************
238 1.1 jruoho *
239 1.1 jruoho * Example ACPICA initialization code with early ACPI table access. This shows
240 1.1 jruoho * an initialization that requires early access to ACPI tables (before
241 1.1 jruoho * kernel dynamic memory is available)
242 1.1 jruoho *
243 1.1 jruoho *****************************************************************************/
244 1.1 jruoho
245 1.1 jruoho /*
246 1.1 jruoho * The purpose of this static table array is to avoid the use of kernel
247 1.1 jruoho * dynamic memory which may not be available during early ACPI table
248 1.1 jruoho * access.
249 1.1 jruoho */
250 1.1 jruoho #define ACPI_MAX_INIT_TABLES 16
251 1.1 jruoho static ACPI_TABLE_DESC TableArray[ACPI_MAX_INIT_TABLES];
252 1.1 jruoho
253 1.1 jruoho
254 1.1 jruoho /*
255 1.1 jruoho * This function would be called early in kernel initialization. After this
256 1.1 jruoho * is called, all ACPI tables are available to the host.
257 1.1 jruoho */
258 1.1 jruoho ACPI_STATUS
259 1.1.1.4 christos InitializeAcpiTables (
260 1.1.1.4 christos void)
261 1.1 jruoho {
262 1.1 jruoho ACPI_STATUS Status;
263 1.1 jruoho
264 1.1 jruoho
265 1.1 jruoho /* Initialize the ACPICA Table Manager and get all ACPI tables */
266 1.1 jruoho
267 1.1 jruoho Status = AcpiInitializeTables (TableArray, ACPI_MAX_INIT_TABLES, TRUE);
268 1.1 jruoho return (Status);
269 1.1 jruoho }
270 1.1 jruoho
271 1.1 jruoho
272 1.1 jruoho /*
273 1.1 jruoho * This function would be called after the kernel is initialized and
274 1.1 jruoho * dynamic/virtual memory is available. It completes the initialization of
275 1.1 jruoho * the ACPICA subsystem.
276 1.1 jruoho */
277 1.1 jruoho ACPI_STATUS
278 1.1.1.4 christos InitializeAcpi (
279 1.1.1.4 christos void)
280 1.1 jruoho {
281 1.1 jruoho ACPI_STATUS Status;
282 1.1 jruoho
283 1.1 jruoho
284 1.1 jruoho /* Initialize the ACPICA subsystem */
285 1.1 jruoho
286 1.1 jruoho Status = AcpiInitializeSubsystem ();
287 1.1 jruoho if (ACPI_FAILURE (Status))
288 1.1 jruoho {
289 1.1 jruoho return (Status);
290 1.1 jruoho }
291 1.1 jruoho
292 1.1 jruoho /* Copy the root table list to dynamic memory */
293 1.1 jruoho
294 1.1 jruoho Status = AcpiReallocateRootTable ();
295 1.1 jruoho if (ACPI_FAILURE (Status))
296 1.1 jruoho {
297 1.1 jruoho return (Status);
298 1.1 jruoho }
299 1.1 jruoho
300 1.1 jruoho /* Create the ACPI namespace from ACPI tables */
301 1.1 jruoho
302 1.1 jruoho Status = AcpiLoadTables ();
303 1.1 jruoho if (ACPI_FAILURE (Status))
304 1.1 jruoho {
305 1.1 jruoho return (Status);
306 1.1 jruoho }
307 1.1 jruoho
308 1.1 jruoho /* Install local handlers */
309 1.1 jruoho
310 1.1 jruoho Status = InstallHandlers ();
311 1.1 jruoho if (ACPI_FAILURE (Status))
312 1.1 jruoho {
313 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While installing handlers"));
314 1.1 jruoho return (Status);
315 1.1 jruoho }
316 1.1 jruoho
317 1.1 jruoho /* Initialize the ACPI hardware */
318 1.1 jruoho
319 1.1 jruoho Status = AcpiEnableSubsystem (ACPI_FULL_INITIALIZATION);
320 1.1 jruoho if (ACPI_FAILURE (Status))
321 1.1 jruoho {
322 1.1 jruoho return (Status);
323 1.1 jruoho }
324 1.1 jruoho
325 1.1 jruoho /* Complete the ACPI namespace object initialization */
326 1.1 jruoho
327 1.1 jruoho Status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION);
328 1.1 jruoho if (ACPI_FAILURE (Status))
329 1.1 jruoho {
330 1.1 jruoho return (Status);
331 1.1 jruoho }
332 1.1 jruoho
333 1.1 jruoho return (AE_OK);
334 1.1 jruoho }
335 1.1 jruoho
336 1.1 jruoho
337 1.1 jruoho /******************************************************************************
338 1.1 jruoho *
339 1.1 jruoho * Example ACPICA handler and handler installation
340 1.1 jruoho *
341 1.1 jruoho *****************************************************************************/
342 1.1 jruoho
343 1.1.1.4 christos static void
344 1.1 jruoho NotifyHandler (
345 1.1 jruoho ACPI_HANDLE Device,
346 1.1 jruoho UINT32 Value,
347 1.1 jruoho void *Context)
348 1.1 jruoho {
349 1.1 jruoho
350 1.1 jruoho ACPI_INFO ((AE_INFO, "Received a notify 0x%X", Value));
351 1.1 jruoho }
352 1.1 jruoho
353 1.1 jruoho
354 1.1.1.4 christos static ACPI_STATUS
355 1.1.1.5 christos RegionInit (
356 1.1.1.5 christos ACPI_HANDLE RegionHandle,
357 1.1.1.5 christos UINT32 Function,
358 1.1.1.5 christos void *HandlerContext,
359 1.1.1.5 christos void **RegionContext)
360 1.1.1.5 christos {
361 1.1.1.5 christos
362 1.1.1.5 christos if (Function == ACPI_REGION_DEACTIVATE)
363 1.1.1.5 christos {
364 1.1.1.5 christos *RegionContext = NULL;
365 1.1.1.5 christos }
366 1.1.1.5 christos else
367 1.1.1.5 christos {
368 1.1.1.5 christos *RegionContext = RegionHandle;
369 1.1.1.5 christos }
370 1.1.1.5 christos
371 1.1.1.5 christos return (AE_OK);
372 1.1.1.5 christos }
373 1.1.1.5 christos
374 1.1.1.5 christos
375 1.1.1.5 christos static ACPI_STATUS
376 1.1.1.5 christos RegionHandler (
377 1.1.1.5 christos UINT32 Function,
378 1.1.1.5 christos ACPI_PHYSICAL_ADDRESS Address,
379 1.1.1.5 christos UINT32 BitWidth,
380 1.1.1.5 christos UINT64 *Value,
381 1.1.1.5 christos void *HandlerContext,
382 1.1.1.5 christos void *RegionContext)
383 1.1.1.5 christos {
384 1.1.1.5 christos
385 1.1.1.5 christos ACPI_INFO ((AE_INFO, "Received a region access"));
386 1.1.1.5 christos
387 1.1.1.5 christos return (AE_OK);
388 1.1.1.5 christos }
389 1.1.1.5 christos
390 1.1.1.5 christos
391 1.1.1.5 christos static ACPI_STATUS
392 1.1 jruoho InstallHandlers (void)
393 1.1 jruoho {
394 1.1 jruoho ACPI_STATUS Status;
395 1.1 jruoho
396 1.1 jruoho
397 1.1 jruoho /* Install global notify handler */
398 1.1 jruoho
399 1.1 jruoho Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
400 1.1 jruoho NotifyHandler, NULL);
401 1.1 jruoho if (ACPI_FAILURE (Status))
402 1.1 jruoho {
403 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While installing Notify handler"));
404 1.1 jruoho return (Status);
405 1.1 jruoho }
406 1.1 jruoho
407 1.1.1.5 christos Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_MEMORY,
408 1.1.1.5 christos RegionHandler, RegionInit, NULL);
409 1.1.1.5 christos if (ACPI_FAILURE (Status))
410 1.1.1.5 christos {
411 1.1.1.5 christos ACPI_EXCEPTION ((AE_INFO, Status, "While installing an OpRegion handler"));
412 1.1.1.5 christos return (Status);
413 1.1.1.5 christos }
414 1.1.1.5 christos
415 1.1 jruoho return (AE_OK);
416 1.1 jruoho }
417 1.1 jruoho
418 1.1 jruoho
419 1.1 jruoho /******************************************************************************
420 1.1 jruoho *
421 1.1.1.4 christos * Examples of control method execution.
422 1.1 jruoho *
423 1.1 jruoho * _OSI is a predefined method that is implemented internally within ACPICA.
424 1.1 jruoho *
425 1.1 jruoho * Shows the following elements:
426 1.1 jruoho *
427 1.1 jruoho * 1) How to setup a control method argument and argument list
428 1.1 jruoho * 2) How to setup the return value object
429 1.1 jruoho * 3) How to invoke AcpiEvaluateObject
430 1.1 jruoho * 4) How to check the returned ACPI_STATUS
431 1.1 jruoho * 5) How to analyze the return value
432 1.1 jruoho *
433 1.1 jruoho *****************************************************************************/
434 1.1 jruoho
435 1.1.1.4 christos static void
436 1.1 jruoho ExecuteOSI (void)
437 1.1 jruoho {
438 1.1 jruoho ACPI_STATUS Status;
439 1.1 jruoho ACPI_OBJECT_LIST ArgList;
440 1.1 jruoho ACPI_OBJECT Arg[1];
441 1.1 jruoho ACPI_BUFFER ReturnValue;
442 1.1 jruoho ACPI_OBJECT *Object;
443 1.1 jruoho
444 1.1 jruoho
445 1.1.1.4 christos ACPI_INFO ((AE_INFO, "Executing _OSI reserved method"));
446 1.1 jruoho
447 1.1 jruoho /* Setup input argument */
448 1.1 jruoho
449 1.1 jruoho ArgList.Count = 1;
450 1.1 jruoho ArgList.Pointer = Arg;
451 1.1 jruoho
452 1.1 jruoho Arg[0].Type = ACPI_TYPE_STRING;
453 1.1 jruoho Arg[0].String.Pointer = "Windows 2001";
454 1.1 jruoho Arg[0].String.Length = strlen (Arg[0].String.Pointer);
455 1.1 jruoho
456 1.1 jruoho /* Ask ACPICA to allocate space for the return object */
457 1.1 jruoho
458 1.1 jruoho ReturnValue.Length = ACPI_ALLOCATE_BUFFER;
459 1.1 jruoho
460 1.1 jruoho Status = AcpiEvaluateObject (NULL, "\\_OSI", &ArgList, &ReturnValue);
461 1.1 jruoho if (ACPI_FAILURE (Status))
462 1.1 jruoho {
463 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "While executing _OSI"));
464 1.1 jruoho return;
465 1.1 jruoho }
466 1.1 jruoho
467 1.1 jruoho /* Ensure that the return object is large enough */
468 1.1 jruoho
469 1.1 jruoho if (ReturnValue.Length < sizeof (ACPI_OBJECT))
470 1.1 jruoho {
471 1.1 jruoho AcpiOsPrintf ("Return value from _OSI method too small, %.8X\n",
472 1.1 jruoho ReturnValue.Length);
473 1.1.1.4 christos goto ErrorExit;
474 1.1 jruoho }
475 1.1 jruoho
476 1.1 jruoho /* Expect an integer return value from execution of _OSI */
477 1.1 jruoho
478 1.1 jruoho Object = ReturnValue.Pointer;
479 1.1 jruoho if (Object->Type != ACPI_TYPE_INTEGER)
480 1.1 jruoho {
481 1.1 jruoho AcpiOsPrintf ("Invalid return type from _OSI, %.2X\n", Object->Type);
482 1.1 jruoho }
483 1.1 jruoho
484 1.1 jruoho ACPI_INFO ((AE_INFO, "_OSI returned 0x%8.8X", (UINT32) Object->Integer.Value));
485 1.1.1.4 christos
486 1.1.1.4 christos
487 1.1.1.4 christos ErrorExit:
488 1.1.1.4 christos
489 1.1.1.4 christos /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
490 1.1.1.4 christos
491 1.1.1.4 christos AcpiOsFree (ReturnValue.Pointer);
492 1.1 jruoho }
493 1.1 jruoho
494 1.1 jruoho
495 1.1 jruoho /******************************************************************************
496 1.1 jruoho *
497 1.1.1.4 christos * Execute an actual control method in the DSDT (MAIN)
498 1.1 jruoho *
499 1.1 jruoho *****************************************************************************/
500 1.1 jruoho
501 1.1.1.4 christos static void
502 1.1.1.4 christos ExecuteMAIN (void)
503 1.1 jruoho {
504 1.1.1.4 christos ACPI_STATUS Status;
505 1.1.1.4 christos ACPI_OBJECT_LIST ArgList;
506 1.1.1.4 christos ACPI_OBJECT Arg[1];
507 1.1.1.4 christos ACPI_BUFFER ReturnValue;
508 1.1.1.4 christos ACPI_OBJECT *Object;
509 1.1 jruoho
510 1.1 jruoho
511 1.1.1.4 christos ACPI_INFO ((AE_INFO, "Executing MAIN method"));
512 1.1.1.3 jruoho
513 1.1.1.4 christos /* Setup input argument */
514 1.1.1.4 christos
515 1.1.1.4 christos ArgList.Count = 1;
516 1.1.1.4 christos ArgList.Pointer = Arg;
517 1.1.1.4 christos
518 1.1.1.4 christos Arg[0].Type = ACPI_TYPE_STRING;
519 1.1.1.4 christos Arg[0].String.Pointer = "Method [MAIN] is executing";
520 1.1.1.4 christos Arg[0].String.Length = strlen (Arg[0].String.Pointer);
521 1.1.1.4 christos
522 1.1.1.4 christos /* Ask ACPICA to allocate space for the return object */
523 1.1.1.4 christos
524 1.1.1.4 christos ReturnValue.Length = ACPI_ALLOCATE_BUFFER;
525 1.1.1.4 christos
526 1.1.1.4 christos Status = AcpiEvaluateObject (NULL, "\\MAIN", &ArgList, &ReturnValue);
527 1.1.1.4 christos if (ACPI_FAILURE (Status))
528 1.1.1.4 christos {
529 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status, "While executing MAIN"));
530 1.1.1.4 christos return;
531 1.1.1.4 christos }
532 1.1.1.4 christos
533 1.1.1.4 christos if (ReturnValue.Pointer)
534 1.1.1.4 christos {
535 1.1.1.4 christos /* Obtain and validate the returned ACPI_OBJECT */
536 1.1.1.4 christos
537 1.1.1.4 christos Object = ReturnValue.Pointer;
538 1.1.1.4 christos if (Object->Type == ACPI_TYPE_STRING)
539 1.1.1.4 christos {
540 1.1.1.4 christos AcpiOsPrintf ("Method [MAIN] returned: \"%s\"\n", Object->String.Pointer);
541 1.1.1.4 christos }
542 1.1.1.4 christos
543 1.1.1.4 christos ACPI_FREE (ReturnValue.Pointer);
544 1.1.1.4 christos }
545 1.1.1.3 jruoho }
546