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