Deleted Added
full compact
utxface.c (231844) utxface.c (239340)
1/******************************************************************************
2 *
1/******************************************************************************
2 *
3 * Module Name: utxface - External interfaces for "global" ACPI functions
3 * Module Name: utxface - External interfaces, miscellaneous utility functions
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44
45#define __UTXFACE_C__
46
47#include <contrib/dev/acpica/include/acpi.h>
48#include <contrib/dev/acpica/include/accommon.h>
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44
45#define __UTXFACE_C__
46
47#include <contrib/dev/acpica/include/acpi.h>
48#include <contrib/dev/acpica/include/accommon.h>
49#include <contrib/dev/acpica/include/acevents.h>
50#include <contrib/dev/acpica/include/acnamesp.h>
51#include <contrib/dev/acpica/include/acdebug.h>
49#include <contrib/dev/acpica/include/acdebug.h>
52#include <contrib/dev/acpica/include/actables.h>
53
54#define _COMPONENT ACPI_UTILITIES
55 ACPI_MODULE_NAME ("utxface")
56
57
50
51#define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utxface")
53
54
58#ifndef ACPI_ASL_COMPILER
59/*******************************************************************************
60 *
55/*******************************************************************************
56 *
61 * FUNCTION: AcpiInitializeSubsystem
62 *
63 * PARAMETERS: None
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Initializes all global variables. This is the first function
68 * called, so any early initialization belongs here.
69 *
70 ******************************************************************************/
71
72ACPI_STATUS
73AcpiInitializeSubsystem (
74 void)
75{
76 ACPI_STATUS Status;
77
78
79 ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem);
80
81
82 AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE;
83 ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ());
84
85 /* Initialize the OS-Dependent layer */
86
87 Status = AcpiOsInitialize ();
88 if (ACPI_FAILURE (Status))
89 {
90 ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization"));
91 return_ACPI_STATUS (Status);
92 }
93
94 /* Initialize all globals used by the subsystem */
95
96 Status = AcpiUtInitGlobals ();
97 if (ACPI_FAILURE (Status))
98 {
99 ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals"));
100 return_ACPI_STATUS (Status);
101 }
102
103 /* Create the default mutex objects */
104
105 Status = AcpiUtMutexInitialize ();
106 if (ACPI_FAILURE (Status))
107 {
108 ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation"));
109 return_ACPI_STATUS (Status);
110 }
111
112 /*
113 * Initialize the namespace manager and
114 * the root of the namespace tree
115 */
116 Status = AcpiNsRootInitialize ();
117 if (ACPI_FAILURE (Status))
118 {
119 ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization"));
120 return_ACPI_STATUS (Status);
121 }
122
123 /* Initialize the global OSI interfaces list with the static names */
124
125 Status = AcpiUtInitializeInterfaces ();
126 if (ACPI_FAILURE (Status))
127 {
128 ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization"));
129 return_ACPI_STATUS (Status);
130 }
131
132 /* If configured, initialize the AML debugger */
133
134 ACPI_DEBUGGER_EXEC (Status = AcpiDbInitialize ());
135 return_ACPI_STATUS (Status);
136}
137
138ACPI_EXPORT_SYMBOL (AcpiInitializeSubsystem)
139
140
141/*******************************************************************************
142 *
143 * FUNCTION: AcpiEnableSubsystem
144 *
145 * PARAMETERS: Flags - Init/enable Options
146 *
147 * RETURN: Status
148 *
149 * DESCRIPTION: Completes the subsystem initialization including hardware.
150 * Puts system into ACPI mode if it isn't already.
151 *
152 ******************************************************************************/
153
154ACPI_STATUS
155AcpiEnableSubsystem (
156 UINT32 Flags)
157{
158 ACPI_STATUS Status = AE_OK;
159
160
161 ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
162
163
164#if (!ACPI_REDUCED_HARDWARE)
165
166 /* Enable ACPI mode */
167
168 if (!(Flags & ACPI_NO_ACPI_ENABLE))
169 {
170 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
171
172 AcpiGbl_OriginalMode = AcpiHwGetMode();
173
174 Status = AcpiEnable ();
175 if (ACPI_FAILURE (Status))
176 {
177 ACPI_WARNING ((AE_INFO, "AcpiEnable failed"));
178 return_ACPI_STATUS (Status);
179 }
180 }
181
182 /*
183 * Obtain a permanent mapping for the FACS. This is required for the
184 * Global Lock and the Firmware Waking Vector
185 */
186 Status = AcpiTbInitializeFacs ();
187 if (ACPI_FAILURE (Status))
188 {
189 ACPI_WARNING ((AE_INFO, "Could not map the FACS table"));
190 return_ACPI_STATUS (Status);
191 }
192
193#endif /* !ACPI_REDUCED_HARDWARE */
194
195 /*
196 * Install the default OpRegion handlers. These are installed unless
197 * other handlers have already been installed via the
198 * InstallAddressSpaceHandler interface.
199 */
200 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
201 {
202 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
203 "[Init] Installing default address space handlers\n"));
204
205 Status = AcpiEvInstallRegionHandlers ();
206 if (ACPI_FAILURE (Status))
207 {
208 return_ACPI_STATUS (Status);
209 }
210 }
211
212#if (!ACPI_REDUCED_HARDWARE)
213 /*
214 * Initialize ACPI Event handling (Fixed and General Purpose)
215 *
216 * Note1: We must have the hardware and events initialized before we can
217 * execute any control methods safely. Any control method can require
218 * ACPI hardware support, so the hardware must be fully initialized before
219 * any method execution!
220 *
221 * Note2: Fixed events are initialized and enabled here. GPEs are
222 * initialized, but cannot be enabled until after the hardware is
223 * completely initialized (SCI and GlobalLock activated) and the various
224 * initialization control methods are run (_REG, _STA, _INI) on the
225 * entire namespace.
226 */
227 if (!(Flags & ACPI_NO_EVENT_INIT))
228 {
229 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
230 "[Init] Initializing ACPI events\n"));
231
232 Status = AcpiEvInitializeEvents ();
233 if (ACPI_FAILURE (Status))
234 {
235 return_ACPI_STATUS (Status);
236 }
237 }
238
239 /*
240 * Install the SCI handler and Global Lock handler. This completes the
241 * hardware initialization.
242 */
243 if (!(Flags & ACPI_NO_HANDLER_INIT))
244 {
245 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
246 "[Init] Installing SCI/GL handlers\n"));
247
248 Status = AcpiEvInstallXruptHandlers ();
249 if (ACPI_FAILURE (Status))
250 {
251 return_ACPI_STATUS (Status);
252 }
253 }
254
255#endif /* !ACPI_REDUCED_HARDWARE */
256
257 return_ACPI_STATUS (Status);
258}
259
260ACPI_EXPORT_SYMBOL (AcpiEnableSubsystem)
261
262
263/*******************************************************************************
264 *
265 * FUNCTION: AcpiInitializeObjects
266 *
267 * PARAMETERS: Flags - Init/enable Options
268 *
269 * RETURN: Status
270 *
271 * DESCRIPTION: Completes namespace initialization by initializing device
272 * objects and executing AML code for Regions, buffers, etc.
273 *
274 ******************************************************************************/
275
276ACPI_STATUS
277AcpiInitializeObjects (
278 UINT32 Flags)
279{
280 ACPI_STATUS Status = AE_OK;
281
282
283 ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
284
285
286 /*
287 * Run all _REG methods
288 *
289 * Note: Any objects accessed by the _REG methods will be automatically
290 * initialized, even if they contain executable AML (see the call to
291 * AcpiNsInitializeObjects below).
292 */
293 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
294 {
295 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
296 "[Init] Executing _REG OpRegion methods\n"));
297
298 Status = AcpiEvInitializeOpRegions ();
299 if (ACPI_FAILURE (Status))
300 {
301 return_ACPI_STATUS (Status);
302 }
303 }
304
305 /*
306 * Execute any module-level code that was detected during the table load
307 * phase. Although illegal since ACPI 2.0, there are many machines that
308 * contain this type of code. Each block of detected executable AML code
309 * outside of any control method is wrapped with a temporary control
310 * method object and placed on a global list. The methods on this list
311 * are executed below.
312 */
313 AcpiNsExecModuleCodeList ();
314
315 /*
316 * Initialize the objects that remain uninitialized. This runs the
317 * executable AML that may be part of the declaration of these objects:
318 * OperationRegions, BufferFields, Buffers, and Packages.
319 */
320 if (!(Flags & ACPI_NO_OBJECT_INIT))
321 {
322 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
323 "[Init] Completing Initialization of ACPI Objects\n"));
324
325 Status = AcpiNsInitializeObjects ();
326 if (ACPI_FAILURE (Status))
327 {
328 return_ACPI_STATUS (Status);
329 }
330 }
331
332 /*
333 * Initialize all device objects in the namespace. This runs the device
334 * _STA and _INI methods.
335 */
336 if (!(Flags & ACPI_NO_DEVICE_INIT))
337 {
338 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
339 "[Init] Initializing ACPI Devices\n"));
340
341 Status = AcpiNsInitializeDevices ();
342 if (ACPI_FAILURE (Status))
343 {
344 return_ACPI_STATUS (Status);
345 }
346 }
347
348 /*
349 * Empty the caches (delete the cached objects) on the assumption that
350 * the table load filled them up more than they will be at runtime --
351 * thus wasting non-paged memory.
352 */
353 Status = AcpiPurgeCachedObjects ();
354
355 AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
356 return_ACPI_STATUS (Status);
357}
358
359ACPI_EXPORT_SYMBOL (AcpiInitializeObjects)
360
361
362#endif
363
364/*******************************************************************************
365 *
366 * FUNCTION: AcpiTerminate
367 *
368 * PARAMETERS: None
369 *
370 * RETURN: Status
371 *
372 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
373 *
374 ******************************************************************************/
375
376ACPI_STATUS
377AcpiTerminate (
378 void)
379{
380 ACPI_STATUS Status;
381
382
383 ACPI_FUNCTION_TRACE (AcpiTerminate);
384
385
386 /* Just exit if subsystem is already shutdown */
387
388 if (AcpiGbl_Shutdown)
389 {
390 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
391 return_ACPI_STATUS (AE_OK);
392 }
393
394 /* Subsystem appears active, go ahead and shut it down */
395
396 AcpiGbl_Shutdown = TRUE;
397 AcpiGbl_StartupFlags = 0;
398 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
399
400 /* Terminate the AML Debugger if present */
401
402 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
403
404 /* Shutdown and free all resources */
405
406 AcpiUtSubsystemShutdown ();
407
408 /* Free the mutex objects */
409
410 AcpiUtMutexTerminate ();
411
412
413#ifdef ACPI_DEBUGGER
414
415 /* Shut down the debugger */
416
417 AcpiDbTerminate ();
418#endif
419
420 /* Now we can shutdown the OS-dependent layer */
421
422 Status = AcpiOsTerminate ();
423 return_ACPI_STATUS (Status);
424}
425
426ACPI_EXPORT_SYMBOL (AcpiTerminate)
427
428
429#ifndef ACPI_ASL_COMPILER
430/*******************************************************************************
431 *
432 * FUNCTION: AcpiSubsystemStatus
433 *
434 * PARAMETERS: None
435 *
436 * RETURN: Status of the ACPI subsystem
437 *
438 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
439 * before making any other calls, to ensure the subsystem
440 * initialized successfully.
441 *
442 ******************************************************************************/
443
444ACPI_STATUS
445AcpiSubsystemStatus (
446 void)
447{
448
449 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
450 {
451 return (AE_OK);
452 }
453 else
454 {
455 return (AE_ERROR);
456 }
457}
458
459ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
460
461
462/*******************************************************************************
463 *
464 * FUNCTION: AcpiGetSystemInfo
465 *
466 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
467 * device
468 *
469 * RETURN: Status - the status of the call
470 *
471 * DESCRIPTION: This function is called to get information about the current
472 * state of the ACPI subsystem. It will return system information
473 * in the OutBuffer.
474 *
475 * If the function fails an appropriate status will be returned
476 * and the value of OutBuffer is undefined.
477 *
478 ******************************************************************************/
479
480ACPI_STATUS
481AcpiGetSystemInfo (
482 ACPI_BUFFER *OutBuffer)
483{
484 ACPI_SYSTEM_INFO *InfoPtr;
485 ACPI_STATUS Status;
486
487
488 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
489
490
491 /* Parameter validation */
492
493 Status = AcpiUtValidateBuffer (OutBuffer);
494 if (ACPI_FAILURE (Status))
495 {
496 return_ACPI_STATUS (Status);
497 }
498
499 /* Validate/Allocate/Clear caller buffer */
500
501 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
502 if (ACPI_FAILURE (Status))
503 {
504 return_ACPI_STATUS (Status);
505 }
506
507 /*
508 * Populate the return buffer
509 */
510 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
511
512 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
513
514 /* System flags (ACPI capabilities) */
515
516 InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
517
518 /* Timer resolution - 24 or 32 bits */
519
520 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
521 {
522 InfoPtr->TimerResolution = 24;
523 }
524 else
525 {
526 InfoPtr->TimerResolution = 32;
527 }
528
529 /* Clear the reserved fields */
530
531 InfoPtr->Reserved1 = 0;
532 InfoPtr->Reserved2 = 0;
533
534 /* Current debug levels */
535
536 InfoPtr->DebugLayer = AcpiDbgLayer;
537 InfoPtr->DebugLevel = AcpiDbgLevel;
538
539 return_ACPI_STATUS (AE_OK);
540}
541
542ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
543
544
545/*******************************************************************************
546 *
547 * FUNCTION: AcpiGetStatistics
548 *
549 * PARAMETERS: Stats - Where the statistics are returned
550 *
551 * RETURN: Status - the status of the call
552 *
553 * DESCRIPTION: Get the contents of the various system counters
554 *
555 ******************************************************************************/
556
557ACPI_STATUS
558AcpiGetStatistics (
559 ACPI_STATISTICS *Stats)
560{
561 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
562
563
564 /* Parameter validation */
565
566 if (!Stats)
567 {
568 return_ACPI_STATUS (AE_BAD_PARAMETER);
569 }
570
571 /* Various interrupt-based event counters */
572
573 Stats->SciCount = AcpiSciCount;
574 Stats->GpeCount = AcpiGpeCount;
575
576 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
577 sizeof (AcpiFixedEventCount));
578
579
580 /* Other counters */
581
582 Stats->MethodCount = AcpiMethodCount;
583
584 return_ACPI_STATUS (AE_OK);
585}
586
587ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
588
589
590/*****************************************************************************
591 *
592 * FUNCTION: AcpiInstallInitializationHandler
593 *
594 * PARAMETERS: Handler - Callback procedure
595 * Function - Not (currently) used, see below
596 *
597 * RETURN: Status
598 *
599 * DESCRIPTION: Install an initialization handler
600 *
601 * TBD: When a second function is added, must save the Function also.
602 *
603 ****************************************************************************/
604
605ACPI_STATUS
606AcpiInstallInitializationHandler (
607 ACPI_INIT_HANDLER Handler,
608 UINT32 Function)
609{
610
611 if (!Handler)
612 {
613 return (AE_BAD_PARAMETER);
614 }
615
616 if (AcpiGbl_InitHandler)
617 {
618 return (AE_ALREADY_EXISTS);
619 }
620
621 AcpiGbl_InitHandler = Handler;
622 return AE_OK;
623}
624
625ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
626
627
628/*****************************************************************************
629 *
630 * FUNCTION: AcpiPurgeCachedObjects
631 *
632 * PARAMETERS: None
633 *
634 * RETURN: Status
635 *
636 * DESCRIPTION: Empty all caches (delete the cached objects)
637 *
638 ****************************************************************************/
639
640ACPI_STATUS
641AcpiPurgeCachedObjects (
642 void)
643{
644 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
645
646 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
647 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
648 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
649 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
650 return_ACPI_STATUS (AE_OK);
651}
652
653ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
654
655
656/*****************************************************************************
657 *
658 * FUNCTION: AcpiInstallInterface
659 *
660 * PARAMETERS: InterfaceName - The interface to install
661 *
662 * RETURN: Status
663 *
664 * DESCRIPTION: Install an _OSI interface to the global list
665 *
666 ****************************************************************************/
667
668ACPI_STATUS
669AcpiInstallInterface (
670 ACPI_STRING InterfaceName)
671{
672 ACPI_STATUS Status;
673 ACPI_INTERFACE_INFO *InterfaceInfo;
674
675
676 /* Parameter validation */
677
678 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
679 {
680 return (AE_BAD_PARAMETER);
681 }
682
683 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
684
685 /* Check if the interface name is already in the global list */
686
687 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
688 if (InterfaceInfo)
689 {
690 /*
691 * The interface already exists in the list. This is OK if the
692 * interface has been marked invalid -- just clear the bit.
693 */
694 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
695 {
696 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
697 Status = AE_OK;
698 }
699 else
700 {
701 Status = AE_ALREADY_EXISTS;
702 }
703 }
704 else
705 {
706 /* New interface name, install into the global list */
707
708 Status = AcpiUtInstallInterface (InterfaceName);
709 }
710
711 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
712 return (Status);
713}
714
715ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
716
717
718/*****************************************************************************
719 *
720 * FUNCTION: AcpiRemoveInterface
721 *
722 * PARAMETERS: InterfaceName - The interface to remove
723 *
724 * RETURN: Status
725 *
726 * DESCRIPTION: Remove an _OSI interface from the global list
727 *
728 ****************************************************************************/
729
730ACPI_STATUS
731AcpiRemoveInterface (
732 ACPI_STRING InterfaceName)
733{
734 ACPI_STATUS Status;
735
736
737 /* Parameter validation */
738
739 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
740 {
741 return (AE_BAD_PARAMETER);
742 }
743
744 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
745
746 Status = AcpiUtRemoveInterface (InterfaceName);
747
748 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
749 return (Status);
750}
751
752ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
753
754
755/*****************************************************************************
756 *
757 * FUNCTION: AcpiInstallInterfaceHandler
758 *
759 * PARAMETERS: Handler - The _OSI interface handler to install
760 * NULL means "remove existing handler"
761 *
762 * RETURN: Status
763 *
764 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
765 * invoked during execution of the internal implementation of
766 * _OSI. A NULL handler simply removes any existing handler.
767 *
768 ****************************************************************************/
769
770ACPI_STATUS
771AcpiInstallInterfaceHandler (
772 ACPI_INTERFACE_HANDLER Handler)
773{
774 ACPI_STATUS Status = AE_OK;
775
776
777 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
778
779 if (Handler && AcpiGbl_InterfaceHandler)
780 {
781 Status = AE_ALREADY_EXISTS;
782 }
783 else
784 {
785 AcpiGbl_InterfaceHandler = Handler;
786 }
787
788 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
789 return (Status);
790}
791
792ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
793
794
795/*****************************************************************************
796 *
797 * FUNCTION: AcpiCheckAddressRange
798 *
799 * PARAMETERS: SpaceId - Address space ID
800 * Address - Start address
801 * Length - Length
802 * Warn - TRUE if warning on overlap desired
803 *
804 * RETURN: Count of the number of conflicts detected.
805 *
806 * DESCRIPTION: Check if the input address range overlaps any of the
807 * ASL operation region address ranges.
808 *
809 ****************************************************************************/
810
811UINT32
812AcpiCheckAddressRange (
813 ACPI_ADR_SPACE_TYPE SpaceId,
814 ACPI_PHYSICAL_ADDRESS Address,
815 ACPI_SIZE Length,
816 BOOLEAN Warn)
817{
818 UINT32 Overlaps;
819 ACPI_STATUS Status;
820
821
822 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
823 if (ACPI_FAILURE (Status))
824 {
825 return (0);
826 }
827
828 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
829 (UINT32) Length, Warn);
830
831 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
832 return (Overlaps);
833}
834
835ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
836
837#endif /* !ACPI_ASL_COMPILER */
57 * FUNCTION: AcpiTerminate
58 *
59 * PARAMETERS: None
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
64 *
65 ******************************************************************************/
66
67ACPI_STATUS
68AcpiTerminate (
69 void)
70{
71 ACPI_STATUS Status;
72
73
74 ACPI_FUNCTION_TRACE (AcpiTerminate);
75
76
77 /* Just exit if subsystem is already shutdown */
78
79 if (AcpiGbl_Shutdown)
80 {
81 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
82 return_ACPI_STATUS (AE_OK);
83 }
84
85 /* Subsystem appears active, go ahead and shut it down */
86
87 AcpiGbl_Shutdown = TRUE;
88 AcpiGbl_StartupFlags = 0;
89 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
90
91 /* Terminate the AML Debugger if present */
92
93 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE);
94
95 /* Shutdown and free all resources */
96
97 AcpiUtSubsystemShutdown ();
98
99 /* Free the mutex objects */
100
101 AcpiUtMutexTerminate ();
102
103
104#ifdef ACPI_DEBUGGER
105
106 /* Shut down the debugger */
107
108 AcpiDbTerminate ();
109#endif
110
111 /* Now we can shutdown the OS-dependent layer */
112
113 Status = AcpiOsTerminate ();
114 return_ACPI_STATUS (Status);
115}
116
117ACPI_EXPORT_SYMBOL (AcpiTerminate)
118
119
120#ifndef ACPI_ASL_COMPILER
121/*******************************************************************************
122 *
123 * FUNCTION: AcpiSubsystemStatus
124 *
125 * PARAMETERS: None
126 *
127 * RETURN: Status of the ACPI subsystem
128 *
129 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
130 * before making any other calls, to ensure the subsystem
131 * initialized successfully.
132 *
133 ******************************************************************************/
134
135ACPI_STATUS
136AcpiSubsystemStatus (
137 void)
138{
139
140 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
141 {
142 return (AE_OK);
143 }
144 else
145 {
146 return (AE_ERROR);
147 }
148}
149
150ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
151
152
153/*******************************************************************************
154 *
155 * FUNCTION: AcpiGetSystemInfo
156 *
157 * PARAMETERS: OutBuffer - A buffer to receive the resources for the
158 * device
159 *
160 * RETURN: Status - the status of the call
161 *
162 * DESCRIPTION: This function is called to get information about the current
163 * state of the ACPI subsystem. It will return system information
164 * in the OutBuffer.
165 *
166 * If the function fails an appropriate status will be returned
167 * and the value of OutBuffer is undefined.
168 *
169 ******************************************************************************/
170
171ACPI_STATUS
172AcpiGetSystemInfo (
173 ACPI_BUFFER *OutBuffer)
174{
175 ACPI_SYSTEM_INFO *InfoPtr;
176 ACPI_STATUS Status;
177
178
179 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
180
181
182 /* Parameter validation */
183
184 Status = AcpiUtValidateBuffer (OutBuffer);
185 if (ACPI_FAILURE (Status))
186 {
187 return_ACPI_STATUS (Status);
188 }
189
190 /* Validate/Allocate/Clear caller buffer */
191
192 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
193 if (ACPI_FAILURE (Status))
194 {
195 return_ACPI_STATUS (Status);
196 }
197
198 /*
199 * Populate the return buffer
200 */
201 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
202
203 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
204
205 /* System flags (ACPI capabilities) */
206
207 InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
208
209 /* Timer resolution - 24 or 32 bits */
210
211 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
212 {
213 InfoPtr->TimerResolution = 24;
214 }
215 else
216 {
217 InfoPtr->TimerResolution = 32;
218 }
219
220 /* Clear the reserved fields */
221
222 InfoPtr->Reserved1 = 0;
223 InfoPtr->Reserved2 = 0;
224
225 /* Current debug levels */
226
227 InfoPtr->DebugLayer = AcpiDbgLayer;
228 InfoPtr->DebugLevel = AcpiDbgLevel;
229
230 return_ACPI_STATUS (AE_OK);
231}
232
233ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
234
235
236/*******************************************************************************
237 *
238 * FUNCTION: AcpiGetStatistics
239 *
240 * PARAMETERS: Stats - Where the statistics are returned
241 *
242 * RETURN: Status - the status of the call
243 *
244 * DESCRIPTION: Get the contents of the various system counters
245 *
246 ******************************************************************************/
247
248ACPI_STATUS
249AcpiGetStatistics (
250 ACPI_STATISTICS *Stats)
251{
252 ACPI_FUNCTION_TRACE (AcpiGetStatistics);
253
254
255 /* Parameter validation */
256
257 if (!Stats)
258 {
259 return_ACPI_STATUS (AE_BAD_PARAMETER);
260 }
261
262 /* Various interrupt-based event counters */
263
264 Stats->SciCount = AcpiSciCount;
265 Stats->GpeCount = AcpiGpeCount;
266
267 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount,
268 sizeof (AcpiFixedEventCount));
269
270
271 /* Other counters */
272
273 Stats->MethodCount = AcpiMethodCount;
274
275 return_ACPI_STATUS (AE_OK);
276}
277
278ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
279
280
281/*****************************************************************************
282 *
283 * FUNCTION: AcpiInstallInitializationHandler
284 *
285 * PARAMETERS: Handler - Callback procedure
286 * Function - Not (currently) used, see below
287 *
288 * RETURN: Status
289 *
290 * DESCRIPTION: Install an initialization handler
291 *
292 * TBD: When a second function is added, must save the Function also.
293 *
294 ****************************************************************************/
295
296ACPI_STATUS
297AcpiInstallInitializationHandler (
298 ACPI_INIT_HANDLER Handler,
299 UINT32 Function)
300{
301
302 if (!Handler)
303 {
304 return (AE_BAD_PARAMETER);
305 }
306
307 if (AcpiGbl_InitHandler)
308 {
309 return (AE_ALREADY_EXISTS);
310 }
311
312 AcpiGbl_InitHandler = Handler;
313 return AE_OK;
314}
315
316ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
317
318
319/*****************************************************************************
320 *
321 * FUNCTION: AcpiPurgeCachedObjects
322 *
323 * PARAMETERS: None
324 *
325 * RETURN: Status
326 *
327 * DESCRIPTION: Empty all caches (delete the cached objects)
328 *
329 ****************************************************************************/
330
331ACPI_STATUS
332AcpiPurgeCachedObjects (
333 void)
334{
335 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
336
337 (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
338 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
339 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
340 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
341 return_ACPI_STATUS (AE_OK);
342}
343
344ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
345
346
347/*****************************************************************************
348 *
349 * FUNCTION: AcpiInstallInterface
350 *
351 * PARAMETERS: InterfaceName - The interface to install
352 *
353 * RETURN: Status
354 *
355 * DESCRIPTION: Install an _OSI interface to the global list
356 *
357 ****************************************************************************/
358
359ACPI_STATUS
360AcpiInstallInterface (
361 ACPI_STRING InterfaceName)
362{
363 ACPI_STATUS Status;
364 ACPI_INTERFACE_INFO *InterfaceInfo;
365
366
367 /* Parameter validation */
368
369 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
370 {
371 return (AE_BAD_PARAMETER);
372 }
373
374 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
375
376 /* Check if the interface name is already in the global list */
377
378 InterfaceInfo = AcpiUtGetInterface (InterfaceName);
379 if (InterfaceInfo)
380 {
381 /*
382 * The interface already exists in the list. This is OK if the
383 * interface has been marked invalid -- just clear the bit.
384 */
385 if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
386 {
387 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
388 Status = AE_OK;
389 }
390 else
391 {
392 Status = AE_ALREADY_EXISTS;
393 }
394 }
395 else
396 {
397 /* New interface name, install into the global list */
398
399 Status = AcpiUtInstallInterface (InterfaceName);
400 }
401
402 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
403 return (Status);
404}
405
406ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
407
408
409/*****************************************************************************
410 *
411 * FUNCTION: AcpiRemoveInterface
412 *
413 * PARAMETERS: InterfaceName - The interface to remove
414 *
415 * RETURN: Status
416 *
417 * DESCRIPTION: Remove an _OSI interface from the global list
418 *
419 ****************************************************************************/
420
421ACPI_STATUS
422AcpiRemoveInterface (
423 ACPI_STRING InterfaceName)
424{
425 ACPI_STATUS Status;
426
427
428 /* Parameter validation */
429
430 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0))
431 {
432 return (AE_BAD_PARAMETER);
433 }
434
435 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
436
437 Status = AcpiUtRemoveInterface (InterfaceName);
438
439 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
440 return (Status);
441}
442
443ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
444
445
446/*****************************************************************************
447 *
448 * FUNCTION: AcpiInstallInterfaceHandler
449 *
450 * PARAMETERS: Handler - The _OSI interface handler to install
451 * NULL means "remove existing handler"
452 *
453 * RETURN: Status
454 *
455 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
456 * invoked during execution of the internal implementation of
457 * _OSI. A NULL handler simply removes any existing handler.
458 *
459 ****************************************************************************/
460
461ACPI_STATUS
462AcpiInstallInterfaceHandler (
463 ACPI_INTERFACE_HANDLER Handler)
464{
465 ACPI_STATUS Status = AE_OK;
466
467
468 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
469
470 if (Handler && AcpiGbl_InterfaceHandler)
471 {
472 Status = AE_ALREADY_EXISTS;
473 }
474 else
475 {
476 AcpiGbl_InterfaceHandler = Handler;
477 }
478
479 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
480 return (Status);
481}
482
483ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
484
485
486/*****************************************************************************
487 *
488 * FUNCTION: AcpiCheckAddressRange
489 *
490 * PARAMETERS: SpaceId - Address space ID
491 * Address - Start address
492 * Length - Length
493 * Warn - TRUE if warning on overlap desired
494 *
495 * RETURN: Count of the number of conflicts detected.
496 *
497 * DESCRIPTION: Check if the input address range overlaps any of the
498 * ASL operation region address ranges.
499 *
500 ****************************************************************************/
501
502UINT32
503AcpiCheckAddressRange (
504 ACPI_ADR_SPACE_TYPE SpaceId,
505 ACPI_PHYSICAL_ADDRESS Address,
506 ACPI_SIZE Length,
507 BOOLEAN Warn)
508{
509 UINT32 Overlaps;
510 ACPI_STATUS Status;
511
512
513 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
514 if (ACPI_FAILURE (Status))
515 {
516 return (0);
517 }
518
519 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
520 (UINT32) Length, Warn);
521
522 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
523 return (Overlaps);
524}
525
526ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
527
528#endif /* !ACPI_ASL_COMPILER */
529
530
531/*******************************************************************************
532 *
533 * FUNCTION: AcpiDecodePldBuffer
534 *
535 * PARAMETERS: InBuffer - Buffer returned by _PLD method
536 * Length - Length of the InBuffer
537 * ReturnBuffer - Where the decode buffer is returned
538 *
539 * RETURN: Status and the decoded _PLD buffer. User must deallocate
540 * the buffer via ACPI_FREE.
541 *
542 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
543 * a local struct that is much more useful to an ACPI driver.
544 *
545 ******************************************************************************/
546
547ACPI_STATUS
548AcpiDecodePldBuffer (
549 UINT8 *InBuffer,
550 ACPI_SIZE Length,
551 ACPI_PLD_INFO **ReturnBuffer)
552{
553 ACPI_PLD_INFO *PldInfo;
554 UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
555 UINT32 Dword;
556
557
558 /* Parameter validation */
559
560 if (!InBuffer || !ReturnBuffer || (Length < 16))
561 {
562 return (AE_BAD_PARAMETER);
563 }
564
565 PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));
566 if (!PldInfo)
567 {
568 return (AE_NO_MEMORY);
569 }
570
571 /* First 32-bit DWord */
572
573 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]);
574 PldInfo->Revision = ACPI_PLD_GET_REVISION (&Dword);
575 PldInfo->IgnoreColor = ACPI_PLD_GET_IGNORE_COLOR (&Dword);
576 PldInfo->Color = ACPI_PLD_GET_COLOR (&Dword);
577
578 /* Second 32-bit DWord */
579
580 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[1]);
581 PldInfo->Width = ACPI_PLD_GET_WIDTH (&Dword);
582 PldInfo->Height = ACPI_PLD_GET_HEIGHT(&Dword);
583
584 /* Third 32-bit DWord */
585
586 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[2]);
587 PldInfo->UserVisible = ACPI_PLD_GET_USER_VISIBLE (&Dword);
588 PldInfo->Dock = ACPI_PLD_GET_DOCK (&Dword);
589 PldInfo->Lid = ACPI_PLD_GET_LID (&Dword);
590 PldInfo->Panel = ACPI_PLD_GET_PANEL (&Dword);
591 PldInfo->VerticalPosition = ACPI_PLD_GET_VERTICAL (&Dword);
592 PldInfo->HorizontalPosition = ACPI_PLD_GET_HORIZONTAL (&Dword);
593 PldInfo->Shape = ACPI_PLD_GET_SHAPE (&Dword);
594 PldInfo->GroupOrientation = ACPI_PLD_GET_ORIENTATION (&Dword);
595 PldInfo->GroupToken = ACPI_PLD_GET_TOKEN (&Dword);
596 PldInfo->GroupPosition = ACPI_PLD_GET_POSITION (&Dword);
597 PldInfo->Bay = ACPI_PLD_GET_BAY (&Dword);
598
599 /* Fourth 32-bit DWord */
600
601 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[3]);
602 PldInfo->Ejectable = ACPI_PLD_GET_EJECTABLE (&Dword);
603 PldInfo->OspmEjectRequired = ACPI_PLD_GET_OSPM_EJECT (&Dword);
604 PldInfo->CabinetNumber = ACPI_PLD_GET_CABINET (&Dword);
605 PldInfo->CardCageNumber = ACPI_PLD_GET_CARD_CAGE (&Dword);
606 PldInfo->Reference = ACPI_PLD_GET_REFERENCE (&Dword);
607 PldInfo->Rotation = ACPI_PLD_GET_ROTATION (&Dword);
608 PldInfo->Order = ACPI_PLD_GET_ORDER (&Dword);
609
610 if (Length >= ACPI_PLD_BUFFER_SIZE)
611 {
612 /* Fifth 32-bit DWord (Revision 2 of _PLD) */
613
614 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[4]);
615 PldInfo->VerticalOffset = ACPI_PLD_GET_VERT_OFFSET (&Dword);
616 PldInfo->HorizontalOffset = ACPI_PLD_GET_HORIZ_OFFSET (&Dword);
617 }
618
619 *ReturnBuffer = PldInfo;
620 return (AE_OK);
621}
622
623ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)