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