1c2c66affSColin Finck /******************************************************************************
2c2c66affSColin Finck  *
3c2c66affSColin Finck  * Module Name: utxface - External interfaces, miscellaneous utility functions
4c2c66affSColin Finck  *
5c2c66affSColin Finck  *****************************************************************************/
6c2c66affSColin Finck 
7c2c66affSColin Finck /*
8*03b24380SThomas Faber  * Copyright (C) 2000 - 2022, Intel Corp.
9c2c66affSColin Finck  * All rights reserved.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * Redistribution and use in source and binary forms, with or without
12c2c66affSColin Finck  * modification, are permitted provided that the following conditions
13c2c66affSColin Finck  * are met:
14c2c66affSColin Finck  * 1. Redistributions of source code must retain the above copyright
15c2c66affSColin Finck  *    notice, this list of conditions, and the following disclaimer,
16c2c66affSColin Finck  *    without modification.
17c2c66affSColin Finck  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18c2c66affSColin Finck  *    substantially similar to the "NO WARRANTY" disclaimer below
19c2c66affSColin Finck  *    ("Disclaimer") and any redistribution must be conditioned upon
20c2c66affSColin Finck  *    including a substantially similar Disclaimer requirement for further
21c2c66affSColin Finck  *    binary redistribution.
22c2c66affSColin Finck  * 3. Neither the names of the above-listed copyright holders nor the names
23c2c66affSColin Finck  *    of any contributors may be used to endorse or promote products derived
24c2c66affSColin Finck  *    from this software without specific prior written permission.
25c2c66affSColin Finck  *
26c2c66affSColin Finck  * Alternatively, this software may be distributed under the terms of the
27c2c66affSColin Finck  * GNU General Public License ("GPL") version 2 as published by the Free
28c2c66affSColin Finck  * Software Foundation.
29c2c66affSColin Finck  *
30c2c66affSColin Finck  * NO WARRANTY
31c2c66affSColin Finck  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32c2c66affSColin Finck  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
336eb8cc49SThomas Faber  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34c2c66affSColin Finck  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35c2c66affSColin Finck  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36c2c66affSColin Finck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37c2c66affSColin Finck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38c2c66affSColin Finck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39c2c66affSColin Finck  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40c2c66affSColin Finck  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41c2c66affSColin Finck  * POSSIBILITY OF SUCH DAMAGES.
42c2c66affSColin Finck  */
43c2c66affSColin Finck 
44c2c66affSColin Finck #define EXPORT_ACPI_INTERFACES
45c2c66affSColin Finck 
46c2c66affSColin Finck #include "acpi.h"
47c2c66affSColin Finck #include "accommon.h"
48c2c66affSColin Finck #include "acdebug.h"
49c2c66affSColin Finck 
50c2c66affSColin Finck #define _COMPONENT          ACPI_UTILITIES
51c2c66affSColin Finck         ACPI_MODULE_NAME    ("utxface")
52c2c66affSColin Finck 
53c2c66affSColin Finck 
54c2c66affSColin Finck /*******************************************************************************
55c2c66affSColin Finck  *
56c2c66affSColin Finck  * FUNCTION:    AcpiTerminate
57c2c66affSColin Finck  *
58c2c66affSColin Finck  * PARAMETERS:  None
59c2c66affSColin Finck  *
60c2c66affSColin Finck  * RETURN:      Status
61c2c66affSColin Finck  *
62c2c66affSColin Finck  * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
63c2c66affSColin Finck  *
64c2c66affSColin Finck  ******************************************************************************/
65c2c66affSColin Finck 
66c2c66affSColin Finck ACPI_STATUS ACPI_INIT_FUNCTION
AcpiTerminate(void)67c2c66affSColin Finck AcpiTerminate (
68c2c66affSColin Finck     void)
69c2c66affSColin Finck {
70c2c66affSColin Finck     ACPI_STATUS         Status;
71c2c66affSColin Finck 
72c2c66affSColin Finck 
73c2c66affSColin Finck     ACPI_FUNCTION_TRACE (AcpiTerminate);
74c2c66affSColin Finck 
75c2c66affSColin Finck 
76c2c66affSColin Finck     /* Shutdown and free all resources */
77c2c66affSColin Finck 
78c2c66affSColin Finck     AcpiUtSubsystemShutdown ();
79c2c66affSColin Finck 
80c2c66affSColin Finck     /* Free the mutex objects */
81c2c66affSColin Finck 
82c2c66affSColin Finck     AcpiUtMutexTerminate ();
83c2c66affSColin Finck 
84c2c66affSColin Finck     /* Now we can shutdown the OS-dependent layer */
85c2c66affSColin Finck 
86c2c66affSColin Finck     Status = AcpiOsTerminate ();
87c2c66affSColin Finck     return_ACPI_STATUS (Status);
88c2c66affSColin Finck }
89c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL_INIT(AcpiTerminate)90c2c66affSColin Finck ACPI_EXPORT_SYMBOL_INIT (AcpiTerminate)
91c2c66affSColin Finck 
92c2c66affSColin Finck 
93c2c66affSColin Finck #ifndef ACPI_ASL_COMPILER
94c2c66affSColin Finck /*******************************************************************************
95c2c66affSColin Finck  *
96c2c66affSColin Finck  * FUNCTION:    AcpiSubsystemStatus
97c2c66affSColin Finck  *
98c2c66affSColin Finck  * PARAMETERS:  None
99c2c66affSColin Finck  *
100c2c66affSColin Finck  * RETURN:      Status of the ACPI subsystem
101c2c66affSColin Finck  *
102c2c66affSColin Finck  * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
103c2c66affSColin Finck  *              before making any other calls, to ensure the subsystem
104c2c66affSColin Finck  *              initialized successfully.
105c2c66affSColin Finck  *
106c2c66affSColin Finck  ******************************************************************************/
107c2c66affSColin Finck 
108c2c66affSColin Finck ACPI_STATUS
109c2c66affSColin Finck AcpiSubsystemStatus (
110c2c66affSColin Finck     void)
111c2c66affSColin Finck {
112c2c66affSColin Finck 
113c2c66affSColin Finck     if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK)
114c2c66affSColin Finck     {
115c2c66affSColin Finck         return (AE_OK);
116c2c66affSColin Finck     }
117c2c66affSColin Finck     else
118c2c66affSColin Finck     {
119c2c66affSColin Finck         return (AE_ERROR);
120c2c66affSColin Finck     }
121c2c66affSColin Finck }
122c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiSubsystemStatus)123c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus)
124c2c66affSColin Finck 
125c2c66affSColin Finck 
126c2c66affSColin Finck /*******************************************************************************
127c2c66affSColin Finck  *
128c2c66affSColin Finck  * FUNCTION:    AcpiGetSystemInfo
129c2c66affSColin Finck  *
130c2c66affSColin Finck  * PARAMETERS:  OutBuffer       - A buffer to receive the resources for the
131c2c66affSColin Finck  *                                device
132c2c66affSColin Finck  *
133c2c66affSColin Finck  * RETURN:      Status          - the status of the call
134c2c66affSColin Finck  *
135c2c66affSColin Finck  * DESCRIPTION: This function is called to get information about the current
136c2c66affSColin Finck  *              state of the ACPI subsystem. It will return system information
137c2c66affSColin Finck  *              in the OutBuffer.
138c2c66affSColin Finck  *
139c2c66affSColin Finck  *              If the function fails an appropriate status will be returned
140c2c66affSColin Finck  *              and the value of OutBuffer is undefined.
141c2c66affSColin Finck  *
142c2c66affSColin Finck  ******************************************************************************/
143c2c66affSColin Finck 
144c2c66affSColin Finck ACPI_STATUS
145c2c66affSColin Finck AcpiGetSystemInfo (
146c2c66affSColin Finck     ACPI_BUFFER             *OutBuffer)
147c2c66affSColin Finck {
148c2c66affSColin Finck     ACPI_SYSTEM_INFO        *InfoPtr;
149c2c66affSColin Finck     ACPI_STATUS             Status;
150c2c66affSColin Finck 
151c2c66affSColin Finck 
152c2c66affSColin Finck     ACPI_FUNCTION_TRACE (AcpiGetSystemInfo);
153c2c66affSColin Finck 
154c2c66affSColin Finck 
155c2c66affSColin Finck     /* Parameter validation */
156c2c66affSColin Finck 
157c2c66affSColin Finck     Status = AcpiUtValidateBuffer (OutBuffer);
158c2c66affSColin Finck     if (ACPI_FAILURE (Status))
159c2c66affSColin Finck     {
160c2c66affSColin Finck         return_ACPI_STATUS (Status);
161c2c66affSColin Finck     }
162c2c66affSColin Finck 
163c2c66affSColin Finck     /* Validate/Allocate/Clear caller buffer */
164c2c66affSColin Finck 
165c2c66affSColin Finck     Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO));
166c2c66affSColin Finck     if (ACPI_FAILURE (Status))
167c2c66affSColin Finck     {
168c2c66affSColin Finck         return_ACPI_STATUS (Status);
169c2c66affSColin Finck     }
170c2c66affSColin Finck 
171c2c66affSColin Finck     /*
172c2c66affSColin Finck      * Populate the return buffer
173c2c66affSColin Finck      */
174c2c66affSColin Finck     InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer;
175c2c66affSColin Finck     InfoPtr->AcpiCaVersion = ACPI_CA_VERSION;
176c2c66affSColin Finck 
177c2c66affSColin Finck     /* System flags (ACPI capabilities) */
178c2c66affSColin Finck 
179c2c66affSColin Finck     InfoPtr->Flags = ACPI_SYS_MODE_ACPI;
180c2c66affSColin Finck 
181c2c66affSColin Finck     /* Timer resolution - 24 or 32 bits  */
182c2c66affSColin Finck 
183c2c66affSColin Finck     if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER)
184c2c66affSColin Finck     {
185c2c66affSColin Finck         InfoPtr->TimerResolution = 24;
186c2c66affSColin Finck     }
187c2c66affSColin Finck     else
188c2c66affSColin Finck     {
189c2c66affSColin Finck         InfoPtr->TimerResolution = 32;
190c2c66affSColin Finck     }
191c2c66affSColin Finck 
192c2c66affSColin Finck     /* Clear the reserved fields */
193c2c66affSColin Finck 
194c2c66affSColin Finck     InfoPtr->Reserved1 = 0;
195c2c66affSColin Finck     InfoPtr->Reserved2 = 0;
196c2c66affSColin Finck 
197c2c66affSColin Finck     /* Current debug levels */
198c2c66affSColin Finck 
199c2c66affSColin Finck     InfoPtr->DebugLayer = AcpiDbgLayer;
200c2c66affSColin Finck     InfoPtr->DebugLevel = AcpiDbgLevel;
201c2c66affSColin Finck 
202c2c66affSColin Finck     return_ACPI_STATUS (AE_OK);
203c2c66affSColin Finck }
204c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiGetSystemInfo)205c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo)
206c2c66affSColin Finck 
207c2c66affSColin Finck 
208c2c66affSColin Finck /*******************************************************************************
209c2c66affSColin Finck  *
210c2c66affSColin Finck  * FUNCTION:    AcpiGetStatistics
211c2c66affSColin Finck  *
212c2c66affSColin Finck  * PARAMETERS:  Stats           - Where the statistics are returned
213c2c66affSColin Finck  *
214c2c66affSColin Finck  * RETURN:      Status          - the status of the call
215c2c66affSColin Finck  *
216c2c66affSColin Finck  * DESCRIPTION: Get the contents of the various system counters
217c2c66affSColin Finck  *
218c2c66affSColin Finck  ******************************************************************************/
219c2c66affSColin Finck 
220c2c66affSColin Finck ACPI_STATUS
221c2c66affSColin Finck AcpiGetStatistics (
222c2c66affSColin Finck     ACPI_STATISTICS         *Stats)
223c2c66affSColin Finck {
224c2c66affSColin Finck     ACPI_FUNCTION_TRACE (AcpiGetStatistics);
225c2c66affSColin Finck 
226c2c66affSColin Finck 
227c2c66affSColin Finck     /* Parameter validation */
228c2c66affSColin Finck 
229c2c66affSColin Finck     if (!Stats)
230c2c66affSColin Finck     {
231c2c66affSColin Finck         return_ACPI_STATUS (AE_BAD_PARAMETER);
232c2c66affSColin Finck     }
233c2c66affSColin Finck 
234c2c66affSColin Finck     /* Various interrupt-based event counters */
235c2c66affSColin Finck 
236c2c66affSColin Finck     Stats->SciCount = AcpiSciCount;
237c2c66affSColin Finck     Stats->GpeCount = AcpiGpeCount;
238c2c66affSColin Finck 
239c2c66affSColin Finck     memcpy (Stats->FixedEventCount, AcpiFixedEventCount,
240c2c66affSColin Finck         sizeof (AcpiFixedEventCount));
241c2c66affSColin Finck 
242c2c66affSColin Finck     /* Other counters */
243c2c66affSColin Finck 
244c2c66affSColin Finck     Stats->MethodCount = AcpiMethodCount;
245c2c66affSColin Finck     return_ACPI_STATUS (AE_OK);
246c2c66affSColin Finck }
247c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiGetStatistics)248c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiGetStatistics)
249c2c66affSColin Finck 
250c2c66affSColin Finck 
251c2c66affSColin Finck /*****************************************************************************
252c2c66affSColin Finck  *
253c2c66affSColin Finck  * FUNCTION:    AcpiInstallInitializationHandler
254c2c66affSColin Finck  *
255c2c66affSColin Finck  * PARAMETERS:  Handler             - Callback procedure
256c2c66affSColin Finck  *              Function            - Not (currently) used, see below
257c2c66affSColin Finck  *
258c2c66affSColin Finck  * RETURN:      Status
259c2c66affSColin Finck  *
260c2c66affSColin Finck  * DESCRIPTION: Install an initialization handler
261c2c66affSColin Finck  *
262c2c66affSColin Finck  * TBD: When a second function is added, must save the Function also.
263c2c66affSColin Finck  *
264c2c66affSColin Finck  ****************************************************************************/
265c2c66affSColin Finck 
266c2c66affSColin Finck ACPI_STATUS
267c2c66affSColin Finck AcpiInstallInitializationHandler (
268c2c66affSColin Finck     ACPI_INIT_HANDLER       Handler,
269c2c66affSColin Finck     UINT32                  Function)
270c2c66affSColin Finck {
271c2c66affSColin Finck 
272c2c66affSColin Finck     if (!Handler)
273c2c66affSColin Finck     {
274c2c66affSColin Finck         return (AE_BAD_PARAMETER);
275c2c66affSColin Finck     }
276c2c66affSColin Finck 
277c2c66affSColin Finck     if (AcpiGbl_InitHandler)
278c2c66affSColin Finck     {
279c2c66affSColin Finck         return (AE_ALREADY_EXISTS);
280c2c66affSColin Finck     }
281c2c66affSColin Finck 
282c2c66affSColin Finck     AcpiGbl_InitHandler = Handler;
283c2c66affSColin Finck     return (AE_OK);
284c2c66affSColin Finck }
285c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiInstallInitializationHandler)286c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
287c2c66affSColin Finck 
288c2c66affSColin Finck 
289c2c66affSColin Finck /*****************************************************************************
290c2c66affSColin Finck  *
291c2c66affSColin Finck  * FUNCTION:    AcpiPurgeCachedObjects
292c2c66affSColin Finck  *
293c2c66affSColin Finck  * PARAMETERS:  None
294c2c66affSColin Finck  *
295c2c66affSColin Finck  * RETURN:      Status
296c2c66affSColin Finck  *
297c2c66affSColin Finck  * DESCRIPTION: Empty all caches (delete the cached objects)
298c2c66affSColin Finck  *
299c2c66affSColin Finck  ****************************************************************************/
300c2c66affSColin Finck 
301c2c66affSColin Finck ACPI_STATUS
302c2c66affSColin Finck AcpiPurgeCachedObjects (
303c2c66affSColin Finck     void)
304c2c66affSColin Finck {
305c2c66affSColin Finck     ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
306c2c66affSColin Finck 
307c2c66affSColin Finck 
308c2c66affSColin Finck     (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
309c2c66affSColin Finck     (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
310c2c66affSColin Finck     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
311c2c66affSColin Finck     (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
312c2c66affSColin Finck 
313c2c66affSColin Finck     return_ACPI_STATUS (AE_OK);
314c2c66affSColin Finck }
315c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiPurgeCachedObjects)316c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
317c2c66affSColin Finck 
318c2c66affSColin Finck 
319c2c66affSColin Finck /*****************************************************************************
320c2c66affSColin Finck  *
321c2c66affSColin Finck  * FUNCTION:    AcpiInstallInterface
322c2c66affSColin Finck  *
323c2c66affSColin Finck  * PARAMETERS:  InterfaceName       - The interface to install
324c2c66affSColin Finck  *
325c2c66affSColin Finck  * RETURN:      Status
326c2c66affSColin Finck  *
327c2c66affSColin Finck  * DESCRIPTION: Install an _OSI interface to the global list
328c2c66affSColin Finck  *
329c2c66affSColin Finck  ****************************************************************************/
330c2c66affSColin Finck 
331c2c66affSColin Finck ACPI_STATUS
332c2c66affSColin Finck AcpiInstallInterface (
333c2c66affSColin Finck     ACPI_STRING             InterfaceName)
334c2c66affSColin Finck {
335c2c66affSColin Finck     ACPI_STATUS             Status;
336c2c66affSColin Finck     ACPI_INTERFACE_INFO     *InterfaceInfo;
337c2c66affSColin Finck 
338c2c66affSColin Finck 
339c2c66affSColin Finck     /* Parameter validation */
340c2c66affSColin Finck 
341c2c66affSColin Finck     if (!InterfaceName || (strlen (InterfaceName) == 0))
342c2c66affSColin Finck     {
343c2c66affSColin Finck         return (AE_BAD_PARAMETER);
344c2c66affSColin Finck     }
345c2c66affSColin Finck 
346c2c66affSColin Finck     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
347c2c66affSColin Finck     if (ACPI_FAILURE (Status))
348c2c66affSColin Finck     {
349c2c66affSColin Finck         return (Status);
350c2c66affSColin Finck     }
351c2c66affSColin Finck 
352c2c66affSColin Finck     /* Check if the interface name is already in the global list */
353c2c66affSColin Finck 
354c2c66affSColin Finck     InterfaceInfo = AcpiUtGetInterface (InterfaceName);
355c2c66affSColin Finck     if (InterfaceInfo)
356c2c66affSColin Finck     {
357c2c66affSColin Finck         /*
358c2c66affSColin Finck          * The interface already exists in the list. This is OK if the
359c2c66affSColin Finck          * interface has been marked invalid -- just clear the bit.
360c2c66affSColin Finck          */
361c2c66affSColin Finck         if (InterfaceInfo->Flags & ACPI_OSI_INVALID)
362c2c66affSColin Finck         {
363c2c66affSColin Finck             InterfaceInfo->Flags &= ~ACPI_OSI_INVALID;
364c2c66affSColin Finck             Status = AE_OK;
365c2c66affSColin Finck         }
366c2c66affSColin Finck         else
367c2c66affSColin Finck         {
368c2c66affSColin Finck             Status = AE_ALREADY_EXISTS;
369c2c66affSColin Finck         }
370c2c66affSColin Finck     }
371c2c66affSColin Finck     else
372c2c66affSColin Finck     {
373c2c66affSColin Finck         /* New interface name, install into the global list */
374c2c66affSColin Finck 
375c2c66affSColin Finck         Status = AcpiUtInstallInterface (InterfaceName);
376c2c66affSColin Finck     }
377c2c66affSColin Finck 
378c2c66affSColin Finck     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
379c2c66affSColin Finck     return (Status);
380c2c66affSColin Finck }
381c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiInstallInterface)382c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiInstallInterface)
383c2c66affSColin Finck 
384c2c66affSColin Finck 
385c2c66affSColin Finck /*****************************************************************************
386c2c66affSColin Finck  *
387c2c66affSColin Finck  * FUNCTION:    AcpiRemoveInterface
388c2c66affSColin Finck  *
389c2c66affSColin Finck  * PARAMETERS:  InterfaceName       - The interface to remove
390c2c66affSColin Finck  *
391c2c66affSColin Finck  * RETURN:      Status
392c2c66affSColin Finck  *
393c2c66affSColin Finck  * DESCRIPTION: Remove an _OSI interface from the global list
394c2c66affSColin Finck  *
395c2c66affSColin Finck  ****************************************************************************/
396c2c66affSColin Finck 
397c2c66affSColin Finck ACPI_STATUS
398c2c66affSColin Finck AcpiRemoveInterface (
399c2c66affSColin Finck     ACPI_STRING             InterfaceName)
400c2c66affSColin Finck {
401c2c66affSColin Finck     ACPI_STATUS             Status;
402c2c66affSColin Finck 
403c2c66affSColin Finck 
404c2c66affSColin Finck     /* Parameter validation */
405c2c66affSColin Finck 
406c2c66affSColin Finck     if (!InterfaceName || (strlen (InterfaceName) == 0))
407c2c66affSColin Finck     {
408c2c66affSColin Finck         return (AE_BAD_PARAMETER);
409c2c66affSColin Finck     }
410c2c66affSColin Finck 
411c2c66affSColin Finck     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
412c2c66affSColin Finck     if (ACPI_FAILURE (Status))
413c2c66affSColin Finck     {
414c2c66affSColin Finck         return (Status);
415c2c66affSColin Finck     }
416c2c66affSColin Finck 
417c2c66affSColin Finck     Status = AcpiUtRemoveInterface (InterfaceName);
418c2c66affSColin Finck 
419c2c66affSColin Finck     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
420c2c66affSColin Finck     return (Status);
421c2c66affSColin Finck }
422c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiRemoveInterface)423c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiRemoveInterface)
424c2c66affSColin Finck 
425c2c66affSColin Finck 
426c2c66affSColin Finck /*****************************************************************************
427c2c66affSColin Finck  *
428c2c66affSColin Finck  * FUNCTION:    AcpiInstallInterfaceHandler
429c2c66affSColin Finck  *
430c2c66affSColin Finck  * PARAMETERS:  Handler             - The _OSI interface handler to install
431c2c66affSColin Finck  *                                    NULL means "remove existing handler"
432c2c66affSColin Finck  *
433c2c66affSColin Finck  * RETURN:      Status
434c2c66affSColin Finck  *
435c2c66affSColin Finck  * DESCRIPTION: Install a handler for the predefined _OSI ACPI method.
436c2c66affSColin Finck  *              invoked during execution of the internal implementation of
437c2c66affSColin Finck  *              _OSI. A NULL handler simply removes any existing handler.
438c2c66affSColin Finck  *
439c2c66affSColin Finck  ****************************************************************************/
440c2c66affSColin Finck 
441c2c66affSColin Finck ACPI_STATUS
442c2c66affSColin Finck AcpiInstallInterfaceHandler (
443c2c66affSColin Finck     ACPI_INTERFACE_HANDLER  Handler)
444c2c66affSColin Finck {
445c2c66affSColin Finck     ACPI_STATUS             Status;
446c2c66affSColin Finck 
447c2c66affSColin Finck 
448c2c66affSColin Finck     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
449c2c66affSColin Finck     if (ACPI_FAILURE (Status))
450c2c66affSColin Finck     {
451c2c66affSColin Finck         return (Status);
452c2c66affSColin Finck     }
453c2c66affSColin Finck 
454c2c66affSColin Finck     if (Handler && AcpiGbl_InterfaceHandler)
455c2c66affSColin Finck     {
456c2c66affSColin Finck         Status = AE_ALREADY_EXISTS;
457c2c66affSColin Finck     }
458c2c66affSColin Finck     else
459c2c66affSColin Finck     {
460c2c66affSColin Finck         AcpiGbl_InterfaceHandler = Handler;
461c2c66affSColin Finck     }
462c2c66affSColin Finck 
463c2c66affSColin Finck     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
464c2c66affSColin Finck     return (Status);
465c2c66affSColin Finck }
466c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiInstallInterfaceHandler)467c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler)
468c2c66affSColin Finck 
469c2c66affSColin Finck 
470c2c66affSColin Finck /*****************************************************************************
471c2c66affSColin Finck  *
472c2c66affSColin Finck  * FUNCTION:    AcpiUpdateInterfaces
473c2c66affSColin Finck  *
474c2c66affSColin Finck  * PARAMETERS:  Action              - Actions to be performed during the
475c2c66affSColin Finck  *                                    update
476c2c66affSColin Finck  *
477c2c66affSColin Finck  * RETURN:      Status
478c2c66affSColin Finck  *
479c2c66affSColin Finck  * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
480c2c66affSColin Finck  *              string or/and feature group strings.
481c2c66affSColin Finck  *
482c2c66affSColin Finck  ****************************************************************************/
483c2c66affSColin Finck 
484c2c66affSColin Finck ACPI_STATUS
485c2c66affSColin Finck AcpiUpdateInterfaces (
486c2c66affSColin Finck     UINT8                   Action)
487c2c66affSColin Finck {
488c2c66affSColin Finck     ACPI_STATUS             Status;
489c2c66affSColin Finck 
490c2c66affSColin Finck 
491c2c66affSColin Finck     Status = AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
492c2c66affSColin Finck     if (ACPI_FAILURE (Status))
493c2c66affSColin Finck     {
494c2c66affSColin Finck         return (Status);
495c2c66affSColin Finck     }
496c2c66affSColin Finck 
497c2c66affSColin Finck     Status = AcpiUtUpdateInterfaces (Action);
498c2c66affSColin Finck 
499c2c66affSColin Finck     AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
500c2c66affSColin Finck     return (Status);
501c2c66affSColin Finck }
502c2c66affSColin Finck 
503c2c66affSColin Finck 
504c2c66affSColin Finck /*****************************************************************************
505c2c66affSColin Finck  *
506c2c66affSColin Finck  * FUNCTION:    AcpiCheckAddressRange
507c2c66affSColin Finck  *
508c2c66affSColin Finck  * PARAMETERS:  SpaceId             - Address space ID
509c2c66affSColin Finck  *              Address             - Start address
510c2c66affSColin Finck  *              Length              - Length
511c2c66affSColin Finck  *              Warn                - TRUE if warning on overlap desired
512c2c66affSColin Finck  *
513c2c66affSColin Finck  * RETURN:      Count of the number of conflicts detected.
514c2c66affSColin Finck  *
515c2c66affSColin Finck  * DESCRIPTION: Check if the input address range overlaps any of the
516c2c66affSColin Finck  *              ASL operation region address ranges.
517c2c66affSColin Finck  *
518c2c66affSColin Finck  ****************************************************************************/
519c2c66affSColin Finck 
520c2c66affSColin Finck UINT32
AcpiCheckAddressRange(ACPI_ADR_SPACE_TYPE SpaceId,ACPI_PHYSICAL_ADDRESS Address,ACPI_SIZE Length,BOOLEAN Warn)521c2c66affSColin Finck AcpiCheckAddressRange (
522c2c66affSColin Finck     ACPI_ADR_SPACE_TYPE     SpaceId,
523c2c66affSColin Finck     ACPI_PHYSICAL_ADDRESS   Address,
524c2c66affSColin Finck     ACPI_SIZE               Length,
525c2c66affSColin Finck     BOOLEAN                 Warn)
526c2c66affSColin Finck {
527c2c66affSColin Finck     UINT32                  Overlaps;
528c2c66affSColin Finck     ACPI_STATUS             Status;
529c2c66affSColin Finck 
530c2c66affSColin Finck 
531c2c66affSColin Finck     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
532c2c66affSColin Finck     if (ACPI_FAILURE (Status))
533c2c66affSColin Finck     {
534c2c66affSColin Finck         return (0);
535c2c66affSColin Finck     }
536c2c66affSColin Finck 
537c2c66affSColin Finck     Overlaps = AcpiUtCheckAddressRange (SpaceId, Address,
538c2c66affSColin Finck         (UINT32) Length, Warn);
539c2c66affSColin Finck 
540c2c66affSColin Finck     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
541c2c66affSColin Finck     return (Overlaps);
542c2c66affSColin Finck }
543c2c66affSColin Finck 
ACPI_EXPORT_SYMBOL(AcpiCheckAddressRange)544c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange)
545c2c66affSColin Finck 
546c2c66affSColin Finck #endif /* !ACPI_ASL_COMPILER */
547c2c66affSColin Finck 
548c2c66affSColin Finck 
549c2c66affSColin Finck /*******************************************************************************
550c2c66affSColin Finck  *
551c2c66affSColin Finck  * FUNCTION:    AcpiDecodePldBuffer
552c2c66affSColin Finck  *
553c2c66affSColin Finck  * PARAMETERS:  InBuffer            - Buffer returned by _PLD method
554c2c66affSColin Finck  *              Length              - Length of the InBuffer
555c2c66affSColin Finck  *              ReturnBuffer        - Where the decode buffer is returned
556c2c66affSColin Finck  *
557c2c66affSColin Finck  * RETURN:      Status and the decoded _PLD buffer. User must deallocate
558c2c66affSColin Finck  *              the buffer via ACPI_FREE.
559c2c66affSColin Finck  *
560c2c66affSColin Finck  * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into
561c2c66affSColin Finck  *              a local struct that is much more useful to an ACPI driver.
562c2c66affSColin Finck  *
563c2c66affSColin Finck  ******************************************************************************/
564c2c66affSColin Finck 
565c2c66affSColin Finck ACPI_STATUS
566c2c66affSColin Finck AcpiDecodePldBuffer (
567c2c66affSColin Finck     UINT8                   *InBuffer,
568c2c66affSColin Finck     ACPI_SIZE               Length,
569c2c66affSColin Finck     ACPI_PLD_INFO           **ReturnBuffer)
570c2c66affSColin Finck {
571c2c66affSColin Finck     ACPI_PLD_INFO           *PldInfo;
572c2c66affSColin Finck     UINT32                  *Buffer = ACPI_CAST_PTR (UINT32, InBuffer);
573c2c66affSColin Finck     UINT32                  Dword;
574c2c66affSColin Finck 
575c2c66affSColin Finck 
576c2c66affSColin Finck     /* Parameter validation */
577c2c66affSColin Finck 
578c2c66affSColin Finck     if (!InBuffer || !ReturnBuffer || (Length < ACPI_PLD_REV1_BUFFER_SIZE))
579c2c66affSColin Finck     {
580c2c66affSColin Finck         return (AE_BAD_PARAMETER);
581c2c66affSColin Finck     }
582c2c66affSColin Finck 
583c2c66affSColin Finck     PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO));
584c2c66affSColin Finck     if (!PldInfo)
585c2c66affSColin Finck     {
586c2c66affSColin Finck         return (AE_NO_MEMORY);
587c2c66affSColin Finck     }
588c2c66affSColin Finck 
589c2c66affSColin Finck     /* First 32-bit DWord */
590c2c66affSColin Finck 
591c2c66affSColin Finck     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]);
592c2c66affSColin Finck     PldInfo->Revision =             ACPI_PLD_GET_REVISION (&Dword);
593c2c66affSColin Finck     PldInfo->IgnoreColor =          ACPI_PLD_GET_IGNORE_COLOR (&Dword);
594c2c66affSColin Finck     PldInfo->Red =                  ACPI_PLD_GET_RED (&Dword);
595c2c66affSColin Finck     PldInfo->Green =                ACPI_PLD_GET_GREEN (&Dword);
596c2c66affSColin Finck     PldInfo->Blue =                 ACPI_PLD_GET_BLUE (&Dword);
597c2c66affSColin Finck 
598c2c66affSColin Finck     /* Second 32-bit DWord */
599c2c66affSColin Finck 
600c2c66affSColin Finck     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[1]);
601c2c66affSColin Finck     PldInfo->Width =                ACPI_PLD_GET_WIDTH (&Dword);
602c2c66affSColin Finck     PldInfo->Height =               ACPI_PLD_GET_HEIGHT(&Dword);
603c2c66affSColin Finck 
604c2c66affSColin Finck     /* Third 32-bit DWord */
605c2c66affSColin Finck 
606c2c66affSColin Finck     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[2]);
607c2c66affSColin Finck     PldInfo->UserVisible =          ACPI_PLD_GET_USER_VISIBLE (&Dword);
608c2c66affSColin Finck     PldInfo->Dock =                 ACPI_PLD_GET_DOCK (&Dword);
609c2c66affSColin Finck     PldInfo->Lid =                  ACPI_PLD_GET_LID (&Dword);
610c2c66affSColin Finck     PldInfo->Panel =                ACPI_PLD_GET_PANEL (&Dword);
611c2c66affSColin Finck     PldInfo->VerticalPosition =     ACPI_PLD_GET_VERTICAL (&Dword);
612c2c66affSColin Finck     PldInfo->HorizontalPosition =   ACPI_PLD_GET_HORIZONTAL (&Dword);
613c2c66affSColin Finck     PldInfo->Shape =                ACPI_PLD_GET_SHAPE (&Dword);
614c2c66affSColin Finck     PldInfo->GroupOrientation =     ACPI_PLD_GET_ORIENTATION (&Dword);
615c2c66affSColin Finck     PldInfo->GroupToken =           ACPI_PLD_GET_TOKEN (&Dword);
616c2c66affSColin Finck     PldInfo->GroupPosition =        ACPI_PLD_GET_POSITION (&Dword);
617c2c66affSColin Finck     PldInfo->Bay =                  ACPI_PLD_GET_BAY (&Dword);
618c2c66affSColin Finck 
619c2c66affSColin Finck     /* Fourth 32-bit DWord */
620c2c66affSColin Finck 
621c2c66affSColin Finck     ACPI_MOVE_32_TO_32 (&Dword, &Buffer[3]);
622c2c66affSColin Finck     PldInfo->Ejectable =            ACPI_PLD_GET_EJECTABLE (&Dword);
623c2c66affSColin Finck     PldInfo->OspmEjectRequired =    ACPI_PLD_GET_OSPM_EJECT (&Dword);
624c2c66affSColin Finck     PldInfo->CabinetNumber =        ACPI_PLD_GET_CABINET (&Dword);
625c2c66affSColin Finck     PldInfo->CardCageNumber =       ACPI_PLD_GET_CARD_CAGE (&Dword);
626c2c66affSColin Finck     PldInfo->Reference =            ACPI_PLD_GET_REFERENCE (&Dword);
627c2c66affSColin Finck     PldInfo->Rotation =             ACPI_PLD_GET_ROTATION (&Dword);
628c2c66affSColin Finck     PldInfo->Order =                ACPI_PLD_GET_ORDER (&Dword);
629c2c66affSColin Finck 
630c2c66affSColin Finck     if (Length >= ACPI_PLD_REV2_BUFFER_SIZE)
631c2c66affSColin Finck     {
632c2c66affSColin Finck         /* Fifth 32-bit DWord (Revision 2 of _PLD) */
633c2c66affSColin Finck 
634c2c66affSColin Finck         ACPI_MOVE_32_TO_32 (&Dword, &Buffer[4]);
635c2c66affSColin Finck         PldInfo->VerticalOffset =       ACPI_PLD_GET_VERT_OFFSET (&Dword);
636c2c66affSColin Finck         PldInfo->HorizontalOffset =     ACPI_PLD_GET_HORIZ_OFFSET (&Dword);
637c2c66affSColin Finck     }
638c2c66affSColin Finck 
639c2c66affSColin Finck     *ReturnBuffer = PldInfo;
640c2c66affSColin Finck     return (AE_OK);
641c2c66affSColin Finck }
642c2c66affSColin Finck 
643c2c66affSColin Finck ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer)
644