xref: /haiku/src/add-ons/kernel/bus_managers/acpi/ACPICAHaiku.cpp (revision 5c1f231967bbf06af56728b86ad70f266c99f64d)
1775afec4SFredrik Holmqvist /******************************************************************************
2775afec4SFredrik Holmqvist  *
3775afec4SFredrik Holmqvist  * Module Name: oshaiku - Haiku OSL interfaces
4775afec4SFredrik Holmqvist  *
5775afec4SFredrik Holmqvist  *****************************************************************************/
6775afec4SFredrik Holmqvist 
7775afec4SFredrik Holmqvist /******************************************************************************
8775afec4SFredrik Holmqvist  *
9775afec4SFredrik Holmqvist  * 1. Copyright Notice
10775afec4SFredrik Holmqvist  *
11775afec4SFredrik Holmqvist  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12775afec4SFredrik Holmqvist  * All rights reserved.
13775afec4SFredrik Holmqvist  *
14775afec4SFredrik Holmqvist  * 2. License
15775afec4SFredrik Holmqvist  *
16775afec4SFredrik Holmqvist  * 2.1. This is your license from Intel Corp. under its intellectual property
17775afec4SFredrik Holmqvist  * rights.  You may have additional license terms from the party that provided
18775afec4SFredrik Holmqvist  * you this software, covering your right to use that party's intellectual
19775afec4SFredrik Holmqvist  * property rights.
20775afec4SFredrik Holmqvist  *
21775afec4SFredrik Holmqvist  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22775afec4SFredrik Holmqvist  * copy of the source code appearing in this file ("Covered Code") an
23775afec4SFredrik Holmqvist  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24775afec4SFredrik Holmqvist  * base code distributed originally by Intel ("Original Intel Code") to copy,
25775afec4SFredrik Holmqvist  * make derivatives, distribute, use and display any portion of the Covered
26775afec4SFredrik Holmqvist  * Code in any form, with the right to sublicense such rights; and
27775afec4SFredrik Holmqvist  *
28775afec4SFredrik Holmqvist  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29775afec4SFredrik Holmqvist  * license (with the right to sublicense), under only those claims of Intel
30775afec4SFredrik Holmqvist  * patents that are infringed by the Original Intel Code, to make, use, sell,
31775afec4SFredrik Holmqvist  * offer to sell, and import the Covered Code and derivative works thereof
32775afec4SFredrik Holmqvist  * solely to the minimum extent necessary to exercise the above copyright
33775afec4SFredrik Holmqvist  * license, and in no event shall the patent license extend to any additions
34775afec4SFredrik Holmqvist  * to or modifications of the Original Intel Code.  No other license or right
35775afec4SFredrik Holmqvist  * is granted directly or by implication, estoppel or otherwise;
36775afec4SFredrik Holmqvist  *
37775afec4SFredrik Holmqvist  * The above copyright and patent license is granted only if the following
38775afec4SFredrik Holmqvist  * conditions are met:
39775afec4SFredrik Holmqvist  *
40775afec4SFredrik Holmqvist  * 3. Conditions
41775afec4SFredrik Holmqvist  *
42775afec4SFredrik Holmqvist  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43775afec4SFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
44775afec4SFredrik Holmqvist  * Code or modification with rights to further distribute source must include
45775afec4SFredrik Holmqvist  * the above Copyright Notice, the above License, this list of Conditions,
46775afec4SFredrik Holmqvist  * and the following Disclaimer and Export Compliance provision.  In addition,
47775afec4SFredrik Holmqvist  * Licensee must cause all Covered Code to which Licensee contributes to
48775afec4SFredrik Holmqvist  * contain a file documenting the changes Licensee made to create that Covered
49775afec4SFredrik Holmqvist  * Code and the date of any change.  Licensee must include in that file the
50775afec4SFredrik Holmqvist  * documentation of any changes made by any predecessor Licensee.  Licensee
51775afec4SFredrik Holmqvist  * must include a prominent statement that the modification is derived,
52775afec4SFredrik Holmqvist  * directly or indirectly, from Original Intel Code.
53775afec4SFredrik Holmqvist  *
54775afec4SFredrik Holmqvist  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55775afec4SFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
56775afec4SFredrik Holmqvist  * Code or modification without rights to further distribute source must
57775afec4SFredrik Holmqvist  * include the following Disclaimer and Export Compliance provision in the
58775afec4SFredrik Holmqvist  * documentation and/or other materials provided with distribution.  In
59775afec4SFredrik Holmqvist  * addition, Licensee may not authorize further sublicense of source of any
60775afec4SFredrik Holmqvist  * portion of the Covered Code, and must include terms to the effect that the
61775afec4SFredrik Holmqvist  * license from Licensee to its licensee is limited to the intellectual
62775afec4SFredrik Holmqvist  * property embodied in the software Licensee provides to its licensee, and
63775afec4SFredrik Holmqvist  * not to intellectual property embodied in modifications its licensee may
64775afec4SFredrik Holmqvist  * make.
65775afec4SFredrik Holmqvist  *
66775afec4SFredrik Holmqvist  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67775afec4SFredrik Holmqvist  * substantial portion of the Covered Code or modification must reproduce the
68775afec4SFredrik Holmqvist  * above Copyright Notice, and the following Disclaimer and Export Compliance
69775afec4SFredrik Holmqvist  * provision in the documentation and/or other materials provided with the
70775afec4SFredrik Holmqvist  * distribution.
71775afec4SFredrik Holmqvist  *
72775afec4SFredrik Holmqvist  * 3.4. Intel retains all right, title, and interest in and to the Original
73775afec4SFredrik Holmqvist  * Intel Code.
74775afec4SFredrik Holmqvist  *
75775afec4SFredrik Holmqvist  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76775afec4SFredrik Holmqvist  * Intel shall be used in advertising or otherwise to promote the sale, use or
77775afec4SFredrik Holmqvist  * other dealings in products derived from or relating to the Covered Code
78775afec4SFredrik Holmqvist  * without prior written authorization from Intel.
79775afec4SFredrik Holmqvist  *
80775afec4SFredrik Holmqvist  * 4. Disclaimer and Export Compliance
81775afec4SFredrik Holmqvist  *
82775afec4SFredrik Holmqvist  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83775afec4SFredrik Holmqvist  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84775afec4SFredrik Holmqvist  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85775afec4SFredrik Holmqvist  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86775afec4SFredrik Holmqvist  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87775afec4SFredrik Holmqvist  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88775afec4SFredrik Holmqvist  * PARTICULAR PURPOSE.
89775afec4SFredrik Holmqvist  *
90775afec4SFredrik Holmqvist  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91775afec4SFredrik Holmqvist  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92775afec4SFredrik Holmqvist  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93775afec4SFredrik Holmqvist  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94775afec4SFredrik Holmqvist  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95775afec4SFredrik Holmqvist  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96775afec4SFredrik Holmqvist  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97775afec4SFredrik Holmqvist  * LIMITED REMEDY.
98775afec4SFredrik Holmqvist  *
99775afec4SFredrik Holmqvist  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100775afec4SFredrik Holmqvist  * software or system incorporating such software without first obtaining any
101775afec4SFredrik Holmqvist  * required license or other approval from the U. S. Department of Commerce or
102775afec4SFredrik Holmqvist  * any other agency or department of the United States Government.  In the
103775afec4SFredrik Holmqvist  * event Licensee exports any such software from the United States or
104775afec4SFredrik Holmqvist  * re-exports any such software from a foreign destination, Licensee shall
105775afec4SFredrik Holmqvist  * ensure that the distribution and export/re-export of the software is in
106775afec4SFredrik Holmqvist  * compliance with all laws, regulations, orders, or other restrictions of the
107775afec4SFredrik Holmqvist  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108775afec4SFredrik Holmqvist  * any of its subsidiaries will export/re-export any technical data, process,
109775afec4SFredrik Holmqvist  * software, or service, directly or indirectly, to any country for which the
110775afec4SFredrik Holmqvist  * United States government or any agency thereof requires an export license,
111775afec4SFredrik Holmqvist  * other governmental approval, or letter of assurance, without first obtaining
112775afec4SFredrik Holmqvist  * such license, approval or letter.
113775afec4SFredrik Holmqvist  *
114775afec4SFredrik Holmqvist  *****************************************************************************/
115775afec4SFredrik Holmqvist 
116775afec4SFredrik Holmqvist 
117775afec4SFredrik Holmqvist #include <stdio.h>
118775afec4SFredrik Holmqvist #include <sys/cdefs.h>
119775afec4SFredrik Holmqvist #include <time.h>
120775afec4SFredrik Holmqvist #include <unistd.h>
121775afec4SFredrik Holmqvist 
122775afec4SFredrik Holmqvist #include <OS.h>
123775afec4SFredrik Holmqvist 
124775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
125775afec4SFredrik Holmqvist #	include <KernelExport.h>
126775afec4SFredrik Holmqvist 
127775afec4SFredrik Holmqvist #	include <dpc.h>
128775afec4SFredrik Holmqvist #	include <PCI.h>
129775afec4SFredrik Holmqvist 
1306e6efaecSJessica Hamilton #	include <boot_item.h>
131775afec4SFredrik Holmqvist #	include <kernel.h>
132775afec4SFredrik Holmqvist #	include <vm/vm.h>
133775afec4SFredrik Holmqvist #endif
134775afec4SFredrik Holmqvist 
135775afec4SFredrik Holmqvist __BEGIN_DECLS
136775afec4SFredrik Holmqvist #include "acpi.h"
137775afec4SFredrik Holmqvist #include "accommon.h"
138775afec4SFredrik Holmqvist #include "amlcode.h"
139775afec4SFredrik Holmqvist #include "acparser.h"
140775afec4SFredrik Holmqvist #include "acdebug.h"
141775afec4SFredrik Holmqvist __END_DECLS
142775afec4SFredrik Holmqvist 
143748b4883Smilek7 #include "arch_init.h"
144748b4883Smilek7 
145775afec4SFredrik Holmqvist 
146775afec4SFredrik Holmqvist ACPI_MODULE_NAME("Haiku ACPI Module")
147775afec4SFredrik Holmqvist 
148775afec4SFredrik Holmqvist #define _COMPONENT ACPI_OS_SERVICES
149775afec4SFredrik Holmqvist 
150775afec4SFredrik Holmqvist // verbosity level 0 = off, 1 = normal, 2 = all
151775afec4SFredrik Holmqvist #define DEBUG_OSHAIKU 0
152775afec4SFredrik Holmqvist 
153775afec4SFredrik Holmqvist #if DEBUG_OSHAIKU <= 0
154775afec4SFredrik Holmqvist // No debugging, do nothing
155775afec4SFredrik Holmqvist #	define DEBUG_FUNCTION()
156775afec4SFredrik Holmqvist #	define DEBUG_FUNCTION_F(x, y...)
157775afec4SFredrik Holmqvist #	define DEBUG_FUNCTION_V()
158775afec4SFredrik Holmqvist #	define DEBUG_FUNCTION_VF(x, y...)
159775afec4SFredrik Holmqvist #else
160775afec4SFredrik Holmqvist #	define DEBUG_FUNCTION() \
161841c1c0cSPulkoMandy 		dprintf("acpi[%" B_PRId32 "]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__);
162775afec4SFredrik Holmqvist #	define DEBUG_FUNCTION_F(x, y...) \
163841c1c0cSPulkoMandy 		dprintf("acpi[%" B_PRId32 "]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y);
164775afec4SFredrik Holmqvist #	if DEBUG_OSHAIKU == 1
165775afec4SFredrik Holmqvist // No verbose debugging, do nothing
166775afec4SFredrik Holmqvist #		define DEBUG_FUNCTION_V()
167775afec4SFredrik Holmqvist #		define DEBUG_FUNCTION_VF(x, y...)
168775afec4SFredrik Holmqvist #	else
169775afec4SFredrik Holmqvist // Full debugging
170775afec4SFredrik Holmqvist #		define DEBUG_FUNCTION_V() \
171841c1c0cSPulkoMandy 			dprintf("acpi[%" B_PRId32 "]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__);
172775afec4SFredrik Holmqvist #		define DEBUG_FUNCTION_VF(x, y...) \
173841c1c0cSPulkoMandy 			dprintf("acpi[%" B_PRId32 "]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y);
174775afec4SFredrik Holmqvist #	endif
175775afec4SFredrik Holmqvist #endif
176775afec4SFredrik Holmqvist 
177775afec4SFredrik Holmqvist 
178775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
179775afec4SFredrik Holmqvist extern pci_module_info *gPCIManager;
180775afec4SFredrik Holmqvist extern dpc_module_info *gDPC;
181775afec4SFredrik Holmqvist extern void *gDPCHandle;
182775afec4SFredrik Holmqvist #endif
183775afec4SFredrik Holmqvist 
184775afec4SFredrik Holmqvist extern FILE *AcpiGbl_DebugFile;
185775afec4SFredrik Holmqvist FILE *AcpiGbl_OutputFile;
186775afec4SFredrik Holmqvist 
1876e6efaecSJessica Hamilton static ACPI_PHYSICAL_ADDRESS sACPIRoot = 0;
188775afec4SFredrik Holmqvist static void *sInterruptHandlerData[32];
189775afec4SFredrik Holmqvist 
190775afec4SFredrik Holmqvist 
191775afec4SFredrik Holmqvist /******************************************************************************
192775afec4SFredrik Holmqvist  *
193775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
194775afec4SFredrik Holmqvist  *
195775afec4SFredrik Holmqvist  * PARAMETERS:  None
196775afec4SFredrik Holmqvist  *
197775afec4SFredrik Holmqvist  * RETURN:      Status
198775afec4SFredrik Holmqvist  *
199775afec4SFredrik Holmqvist  * DESCRIPTION: Init and terminate.  Nothing to do.
200775afec4SFredrik Holmqvist  *
201775afec4SFredrik Holmqvist  *****************************************************************************/
202775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsInitialize()203775afec4SFredrik Holmqvist AcpiOsInitialize()
204775afec4SFredrik Holmqvist {
205775afec4SFredrik Holmqvist #ifndef _KERNEL_MODE
206775afec4SFredrik Holmqvist 	AcpiGbl_OutputFile = stdout;
207775afec4SFredrik Holmqvist #else
208775afec4SFredrik Holmqvist 	AcpiGbl_OutputFile = NULL;
209775afec4SFredrik Holmqvist #endif
210775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
211775afec4SFredrik Holmqvist 	return AE_OK;
212775afec4SFredrik Holmqvist }
213775afec4SFredrik Holmqvist 
214775afec4SFredrik Holmqvist 
215775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsTerminate()216775afec4SFredrik Holmqvist AcpiOsTerminate()
217775afec4SFredrik Holmqvist {
218775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
219775afec4SFredrik Holmqvist 	return AE_OK;
220775afec4SFredrik Holmqvist }
221775afec4SFredrik Holmqvist 
222775afec4SFredrik Holmqvist 
223775afec4SFredrik Holmqvist /******************************************************************************
224775afec4SFredrik Holmqvist  *
225775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsGetRootPointer
226775afec4SFredrik Holmqvist  *
227775afec4SFredrik Holmqvist  * PARAMETERS:  None
228775afec4SFredrik Holmqvist  *
229775afec4SFredrik Holmqvist  * RETURN:      RSDP physical address
230775afec4SFredrik Holmqvist  *
231775afec4SFredrik Holmqvist  * DESCRIPTION: Gets the root pointer (RSDP)
232775afec4SFredrik Holmqvist  *
233775afec4SFredrik Holmqvist  *****************************************************************************/
234775afec4SFredrik Holmqvist ACPI_PHYSICAL_ADDRESS
AcpiOsGetRootPointer()235775afec4SFredrik Holmqvist AcpiOsGetRootPointer()
236775afec4SFredrik Holmqvist {
237775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
238775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
239775afec4SFredrik Holmqvist 	if (sACPIRoot == 0) {
240a7b50febSDavid Karoly 		phys_addr_t* acpiRootPointer = (phys_addr_t*)get_boot_item("ACPI_ROOT_POINTER", NULL);
241a7b50febSDavid Karoly 		if (acpiRootPointer != NULL)
242a7b50febSDavid Karoly 			sACPIRoot = *acpiRootPointer;
243a7b50febSDavid Karoly 
244748b4883Smilek7 		if (sACPIRoot == 0)
245748b4883Smilek7 			sACPIRoot = arch_init_find_root_pointer();
2466e6efaecSJessica Hamilton 	}
247775afec4SFredrik Holmqvist 	return sACPIRoot;
248775afec4SFredrik Holmqvist #else
249775afec4SFredrik Holmqvist 	return AeLocalGetRootPointer();
250775afec4SFredrik Holmqvist #endif
251775afec4SFredrik Holmqvist }
252775afec4SFredrik Holmqvist 
253775afec4SFredrik Holmqvist 
254775afec4SFredrik Holmqvist /******************************************************************************
255775afec4SFredrik Holmqvist  *
256775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsPredefinedOverride
257775afec4SFredrik Holmqvist  *
258775afec4SFredrik Holmqvist  * PARAMETERS:  initVal     - Initial value of the predefined object
259775afec4SFredrik Holmqvist  *              newVal      - The new value for the object
260775afec4SFredrik Holmqvist  *
261775afec4SFredrik Holmqvist  * RETURN:      Status, pointer to value.  Null pointer returned if not
262775afec4SFredrik Holmqvist  *              overriding.
263775afec4SFredrik Holmqvist  *
264775afec4SFredrik Holmqvist  * DESCRIPTION: Allow the OS to override predefined names
265775afec4SFredrik Holmqvist  *
266775afec4SFredrik Holmqvist  *****************************************************************************/
267775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES * initVal,ACPI_STRING * newVal)268775afec4SFredrik Holmqvist AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *initVal,
269775afec4SFredrik Holmqvist 		ACPI_STRING *newVal)
270775afec4SFredrik Holmqvist {
271775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
272775afec4SFredrik Holmqvist 	if (!initVal || !newVal)
273775afec4SFredrik Holmqvist 		return AE_BAD_PARAMETER;
274775afec4SFredrik Holmqvist 
275775afec4SFredrik Holmqvist 	*newVal = NULL;
276775afec4SFredrik Holmqvist 	return AE_OK;
277775afec4SFredrik Holmqvist }
278775afec4SFredrik Holmqvist 
279775afec4SFredrik Holmqvist 
280775afec4SFredrik Holmqvist /******************************************************************************
281775afec4SFredrik Holmqvist  *
282775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsTableOverride
283775afec4SFredrik Holmqvist  *
284775afec4SFredrik Holmqvist  * PARAMETERS:  existingTable   - Header of current table (probably firmware)
285775afec4SFredrik Holmqvist  *              newTable        - Where an entire new table is returned.
286775afec4SFredrik Holmqvist  *
287775afec4SFredrik Holmqvist  * RETURN:      Status, pointer to new table.  Null pointer returned if no
288775afec4SFredrik Holmqvist  *              table is available to override
289775afec4SFredrik Holmqvist  *
290775afec4SFredrik Holmqvist  * DESCRIPTION: Return a different version of a table if one is available
291775afec4SFredrik Holmqvist  *
292775afec4SFredrik Holmqvist  *****************************************************************************/
293775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsTableOverride(ACPI_TABLE_HEADER * existingTable,ACPI_TABLE_HEADER ** newTable)294775afec4SFredrik Holmqvist AcpiOsTableOverride(ACPI_TABLE_HEADER *existingTable,
295775afec4SFredrik Holmqvist 		ACPI_TABLE_HEADER **newTable)
296775afec4SFredrik Holmqvist {
297775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
298775afec4SFredrik Holmqvist 	if (!existingTable || !newTable)
299775afec4SFredrik Holmqvist 		return AE_BAD_PARAMETER;
300775afec4SFredrik Holmqvist 
301775afec4SFredrik Holmqvist 	*newTable = NULL;
302775afec4SFredrik Holmqvist 
303775afec4SFredrik Holmqvist #ifdef ACPI_EXEC_APP
304775afec4SFredrik Holmqvist 	AeTableOverride(existingTable, newTable);
305775afec4SFredrik Holmqvist 	return AE_OK;
306775afec4SFredrik Holmqvist #else
307775afec4SFredrik Holmqvist 	return AE_NO_ACPI_TABLES;
308775afec4SFredrik Holmqvist #endif
309775afec4SFredrik Holmqvist }
310775afec4SFredrik Holmqvist 
311775afec4SFredrik Holmqvist 
312775afec4SFredrik Holmqvist /******************************************************************************
313775afec4SFredrik Holmqvist  *
314775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsPhysicalTableOverride
315775afec4SFredrik Holmqvist  *
316775afec4SFredrik Holmqvist  * PARAMETERS:  existingTable       - Header of current table (probably firmware)
317775afec4SFredrik Holmqvist  *              newAddress          - Where new table address is returned
318775afec4SFredrik Holmqvist  *                                    (Physical address)
319775afec4SFredrik Holmqvist  *              newTableLength      - Where new table length is returned
320775afec4SFredrik Holmqvist  *
321775afec4SFredrik Holmqvist  * RETURN:      Status, address/length of new table. Null pointer returned
322775afec4SFredrik Holmqvist  *              if no table is available to override.
323775afec4SFredrik Holmqvist  *
324775afec4SFredrik Holmqvist  * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
325775afec4SFredrik Holmqvist  *
326775afec4SFredrik Holmqvist  *****************************************************************************/
327775afec4SFredrik Holmqvist 
328775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsPhysicalTableOverride(ACPI_TABLE_HEADER * existingTable,ACPI_PHYSICAL_ADDRESS * newAddress,UINT32 * newTableLength)329775afec4SFredrik Holmqvist AcpiOsPhysicalTableOverride(ACPI_TABLE_HEADER *existingTable,
330775afec4SFredrik Holmqvist 	ACPI_PHYSICAL_ADDRESS *newAddress, UINT32 *newTableLength)
331775afec4SFredrik Holmqvist {
332775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
333775afec4SFredrik Holmqvist     return (AE_SUPPORT);
334775afec4SFredrik Holmqvist }
335775afec4SFredrik Holmqvist 
336775afec4SFredrik Holmqvist 
337775afec4SFredrik Holmqvist /******************************************************************************
338775afec4SFredrik Holmqvist  *
339775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsRedirectOutput
340775afec4SFredrik Holmqvist  *
341775afec4SFredrik Holmqvist  * PARAMETERS:  destination         - An open file handle/pointer
342775afec4SFredrik Holmqvist  *
343775afec4SFredrik Holmqvist  * RETURN:      None
344775afec4SFredrik Holmqvist  *
345775afec4SFredrik Holmqvist  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
346775afec4SFredrik Holmqvist  *
347775afec4SFredrik Holmqvist  *****************************************************************************/
348775afec4SFredrik Holmqvist void
AcpiOsRedirectOutput(void * destination)349775afec4SFredrik Holmqvist AcpiOsRedirectOutput(void *destination)
350775afec4SFredrik Holmqvist {
351775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
352775afec4SFredrik Holmqvist 	AcpiGbl_OutputFile = (FILE*)destination;
353775afec4SFredrik Holmqvist }
354775afec4SFredrik Holmqvist 
355775afec4SFredrik Holmqvist 
356775afec4SFredrik Holmqvist /******************************************************************************
357775afec4SFredrik Holmqvist  *
358775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsPrintf
359775afec4SFredrik Holmqvist  *
360775afec4SFredrik Holmqvist  * PARAMETERS:  fmt, ...            Standard printf format
361775afec4SFredrik Holmqvist  *
362775afec4SFredrik Holmqvist  * RETURN:      None
363775afec4SFredrik Holmqvist  *
364775afec4SFredrik Holmqvist  * DESCRIPTION: Formatted output
365775afec4SFredrik Holmqvist  *
366775afec4SFredrik Holmqvist  *****************************************************************************/
367775afec4SFredrik Holmqvist void ACPI_INTERNAL_VAR_XFACE
AcpiOsPrintf(const char * fmt,...)368775afec4SFredrik Holmqvist AcpiOsPrintf(const char *fmt, ...)
369775afec4SFredrik Holmqvist {
370775afec4SFredrik Holmqvist 	va_list args;
371775afec4SFredrik Holmqvist 
372775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
373775afec4SFredrik Holmqvist 	va_start(args, fmt);
374775afec4SFredrik Holmqvist 	AcpiOsVprintf(fmt, args);
375775afec4SFredrik Holmqvist 	va_end(args);
376775afec4SFredrik Holmqvist }
377775afec4SFredrik Holmqvist 
378775afec4SFredrik Holmqvist 
379775afec4SFredrik Holmqvist /******************************************************************************
380775afec4SFredrik Holmqvist  *
381775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsVprintf
382775afec4SFredrik Holmqvist  *
383775afec4SFredrik Holmqvist  * PARAMETERS:  fmt                 Standard printf format
384775afec4SFredrik Holmqvist  *              args                Argument list
385775afec4SFredrik Holmqvist  *
386775afec4SFredrik Holmqvist  * RETURN:      None
387775afec4SFredrik Holmqvist  *
388775afec4SFredrik Holmqvist  * DESCRIPTION: Formatted output with argument list pointer
389775afec4SFredrik Holmqvist  *
390775afec4SFredrik Holmqvist  *****************************************************************************/
391775afec4SFredrik Holmqvist void
AcpiOsVprintf(const char * fmt,va_list args)392775afec4SFredrik Holmqvist AcpiOsVprintf(const char *fmt, va_list args)
393775afec4SFredrik Holmqvist {
394775afec4SFredrik Holmqvist #ifndef _KERNEL_MODE
395775afec4SFredrik Holmqvist 	UINT8 flags;
396775afec4SFredrik Holmqvist 
397775afec4SFredrik Holmqvist 	flags = AcpiGbl_DbOutputFlags;
398775afec4SFredrik Holmqvist 	if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
399775afec4SFredrik Holmqvist 		// Output is directable to either a file (if open) or the console
400775afec4SFredrik Holmqvist 		if (AcpiGbl_DebugFile) {
401775afec4SFredrik Holmqvist 			// Output file is open, send the output there
402775afec4SFredrik Holmqvist 			vfprintf(AcpiGbl_DebugFile, fmt, args);
403775afec4SFredrik Holmqvist 		} else {
404775afec4SFredrik Holmqvist 			// No redirection, send output to console (once only!)
405775afec4SFredrik Holmqvist 			flags |= ACPI_DB_CONSOLE_OUTPUT;
406775afec4SFredrik Holmqvist 		}
407775afec4SFredrik Holmqvist 	}
408775afec4SFredrik Holmqvist 
409775afec4SFredrik Holmqvist 	if (flags & ACPI_DB_CONSOLE_OUTPUT) {
410775afec4SFredrik Holmqvist 		vfprintf(AcpiGbl_OutputFile, fmt, args);
411775afec4SFredrik Holmqvist     }
412775afec4SFredrik Holmqvist #else
413174a9dbfSPulkoMandy 	// Buffer the output until we have a complete line to send to syslog, this avoids added
414174a9dbfSPulkoMandy 	// "KERN:" entries in the middle of the line, and mixing up of the ACPI output with other
415174a9dbfSPulkoMandy 	// messages from other CPUs
416775afec4SFredrik Holmqvist 	static char outputBuffer[1024];
417174a9dbfSPulkoMandy 
418174a9dbfSPulkoMandy 	// Append the new text to the buffer
419174a9dbfSPulkoMandy 	size_t len = strlen(outputBuffer);
420174a9dbfSPulkoMandy 	size_t printed = vsnprintf(outputBuffer + len, 1024 - len, fmt, args);
421174a9dbfSPulkoMandy 	if (printed >= 1024 - len) {
422174a9dbfSPulkoMandy 		// There was no space to fit the printed string in the outputBuffer. Remove what we added
423174a9dbfSPulkoMandy 		// there, fush the buffer, and print the long string directly
424174a9dbfSPulkoMandy 		outputBuffer[len] = '\0';
425174a9dbfSPulkoMandy 		dprintf("%s\n", outputBuffer);
426174a9dbfSPulkoMandy 		outputBuffer[0] = '\0';
427174a9dbfSPulkoMandy 		dvprintf(fmt, args);
428174a9dbfSPulkoMandy 		return;
429174a9dbfSPulkoMandy 	}
430174a9dbfSPulkoMandy 
431174a9dbfSPulkoMandy 	// See if we have a complete line
432174a9dbfSPulkoMandy 	char* eol = strchr(outputBuffer + len, '\n');
433174a9dbfSPulkoMandy 	while (eol != nullptr) {
434174a9dbfSPulkoMandy 		// Print the completed line, then remove it from the buffer
435174a9dbfSPulkoMandy 		*eol = 0;
436174a9dbfSPulkoMandy 		dprintf("%s\n", outputBuffer);
437174a9dbfSPulkoMandy 		memmove(outputBuffer, eol + 1, strlen(eol + 1) + 1);
438174a9dbfSPulkoMandy 		// See if there is another line to print still in the buffer (in case ACPICA would call
439174a9dbfSPulkoMandy 		// this function with a single string containing multiple newlines)
440174a9dbfSPulkoMandy 		eol = strchr(outputBuffer, '\n');
441174a9dbfSPulkoMandy 	}
442775afec4SFredrik Holmqvist #endif
443775afec4SFredrik Holmqvist }
444775afec4SFredrik Holmqvist 
445775afec4SFredrik Holmqvist 
446775afec4SFredrik Holmqvist /******************************************************************************
447775afec4SFredrik Holmqvist  *
448775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsGetLine
449775afec4SFredrik Holmqvist  *
450775afec4SFredrik Holmqvist  * PARAMETERS:  fmt                 Standard printf format
451775afec4SFredrik Holmqvist  *              args                Argument list
452775afec4SFredrik Holmqvist  *
453775afec4SFredrik Holmqvist  * RETURN:      Actual bytes read
454775afec4SFredrik Holmqvist  *
455775afec4SFredrik Holmqvist  * DESCRIPTION: Formatted input with argument list pointer
456775afec4SFredrik Holmqvist  *
457775afec4SFredrik Holmqvist  *****************************************************************************/
458775afec4SFredrik Holmqvist UINT32
AcpiOsGetLine(char * buffer)459775afec4SFredrik Holmqvist AcpiOsGetLine(char *buffer)
460775afec4SFredrik Holmqvist {
461775afec4SFredrik Holmqvist 	uint32 i = 0;
462775afec4SFredrik Holmqvist 
463775afec4SFredrik Holmqvist #ifndef _KERNEL_MODE
464775afec4SFredrik Holmqvist 	uint8 temp;
465775afec4SFredrik Holmqvist 
466775afec4SFredrik Holmqvist 	for (i = 0; ; i++) {
467775afec4SFredrik Holmqvist 		scanf("%1c", &temp);
468775afec4SFredrik Holmqvist 		if (!temp || temp == '\n')
469775afec4SFredrik Holmqvist 			break;
470775afec4SFredrik Holmqvist 
471775afec4SFredrik Holmqvist 		buffer[i] = temp;
472775afec4SFredrik Holmqvist 	}
473775afec4SFredrik Holmqvist #endif
474775afec4SFredrik Holmqvist 
475775afec4SFredrik Holmqvist 	buffer[i] = 0;
476841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("buffer: \"%s\"; result: %" B_PRIu32, buffer, i);
477775afec4SFredrik Holmqvist 	return i;
478775afec4SFredrik Holmqvist }
479775afec4SFredrik Holmqvist 
480775afec4SFredrik Holmqvist 
481775afec4SFredrik Holmqvist /******************************************************************************
482775afec4SFredrik Holmqvist  *
483775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsMapMemory
484775afec4SFredrik Holmqvist  *
485775afec4SFredrik Holmqvist  * PARAMETERS:  where               Physical address of memory to be mapped
486775afec4SFredrik Holmqvist  *              length              How much memory to map
487775afec4SFredrik Holmqvist  *
488775afec4SFredrik Holmqvist  * RETURN:      Pointer to mapped memory.  Null on error.
489775afec4SFredrik Holmqvist  *
490775afec4SFredrik Holmqvist  * DESCRIPTION: Map physical memory into caller's address space
491775afec4SFredrik Holmqvist  *
492775afec4SFredrik Holmqvist  *****************************************************************************/
493775afec4SFredrik Holmqvist void *
AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS where,ACPI_SIZE length)494775afec4SFredrik Holmqvist AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS where, ACPI_SIZE length)
495775afec4SFredrik Holmqvist {
496775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
497d4d360a0SAugustin Cavalier 	// map_physical_memory() defaults to uncached memory if no type is specified.
498d4d360a0SAugustin Cavalier 	// But ACPICA handles flushing caches itself, so we don't need it uncached,
499d4d360a0SAugustin Cavalier 	// and on some architectures (e.g. ARM) uncached memory does not support
500d4d360a0SAugustin Cavalier 	// unaligned accesses. Hence we specify "writeback" to avoid the default.
501775afec4SFredrik Holmqvist 	void *there;
5028cb8c3d7SOwen Anderson 	area_id area = map_physical_memory("acpi_physical_mem_area", (phys_addr_t)where, length,
503*5c1f2319SAugustin Cavalier 		B_ANY_KERNEL_ADDRESS | B_WRITE_BACK_MEMORY, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA,
504*5c1f2319SAugustin Cavalier 		&there);
505775afec4SFredrik Holmqvist 
506841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("addr: 0x%08lx; length: %lu; mapped: %p; area: %" B_PRId32,
507775afec4SFredrik Holmqvist 		(addr_t)where, (size_t)length, there, area);
508775afec4SFredrik Holmqvist 	if (area < 0) {
509584a3968SFredrik Holmqvist 		dprintf("ACPI: cannot map memory at 0x%" B_PRIu64 ", length %"
510584a3968SFredrik Holmqvist 			B_PRIu64 "\n", (uint64)where, (uint64)length);
511775afec4SFredrik Holmqvist 		return NULL;
512775afec4SFredrik Holmqvist 	}
513775afec4SFredrik Holmqvist 	return there;
514775afec4SFredrik Holmqvist #else
515775afec4SFredrik Holmqvist 	return NULL;
516775afec4SFredrik Holmqvist #endif
517775afec4SFredrik Holmqvist 
518775afec4SFredrik Holmqvist 	// return ACPI_TO_POINTER((ACPI_SIZE) where);
519775afec4SFredrik Holmqvist }
520775afec4SFredrik Holmqvist 
521775afec4SFredrik Holmqvist 
522775afec4SFredrik Holmqvist /******************************************************************************
523775afec4SFredrik Holmqvist  *
524775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsUnmapMemory
525775afec4SFredrik Holmqvist  *
526775afec4SFredrik Holmqvist  * PARAMETERS:  where               Logical address of memory to be unmapped
527775afec4SFredrik Holmqvist  *              length              How much memory to unmap
528775afec4SFredrik Holmqvist  *
529775afec4SFredrik Holmqvist  * RETURN:      None.
530775afec4SFredrik Holmqvist  *
531775afec4SFredrik Holmqvist  * DESCRIPTION: Delete a previously created mapping.  Where and Length must
532775afec4SFredrik Holmqvist  *              correspond to a previous mapping exactly.
533775afec4SFredrik Holmqvist  *
534775afec4SFredrik Holmqvist  *****************************************************************************/
535775afec4SFredrik Holmqvist void
AcpiOsUnmapMemory(void * where,ACPI_SIZE length)536775afec4SFredrik Holmqvist AcpiOsUnmapMemory(void *where, ACPI_SIZE length)
537775afec4SFredrik Holmqvist {
538775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("mapped: %p; length: %lu", where, (size_t)length);
539775afec4SFredrik Holmqvist 	delete_area(area_for(where));
540775afec4SFredrik Holmqvist }
541775afec4SFredrik Holmqvist 
542775afec4SFredrik Holmqvist 
543775afec4SFredrik Holmqvist /******************************************************************************
544775afec4SFredrik Holmqvist  *
545775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsAllocate
546775afec4SFredrik Holmqvist  *
547775afec4SFredrik Holmqvist  * PARAMETERS:  size                Amount to allocate, in bytes
548775afec4SFredrik Holmqvist  *
549775afec4SFredrik Holmqvist  * RETURN:      Pointer to the new allocation.  Null on error.
550775afec4SFredrik Holmqvist  *
551775afec4SFredrik Holmqvist  * DESCRIPTION: Allocate memory.  Algorithm is dependent on the OS.
552775afec4SFredrik Holmqvist  *
553775afec4SFredrik Holmqvist  *****************************************************************************/
554775afec4SFredrik Holmqvist void *
AcpiOsAllocate(ACPI_SIZE size)555775afec4SFredrik Holmqvist AcpiOsAllocate(ACPI_SIZE size)
556775afec4SFredrik Holmqvist {
557775afec4SFredrik Holmqvist 	void *mem = (void *) malloc(size);
558775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_VF("result: %p", mem);
559775afec4SFredrik Holmqvist 	return mem;
560775afec4SFredrik Holmqvist }
561775afec4SFredrik Holmqvist 
562775afec4SFredrik Holmqvist 
563775afec4SFredrik Holmqvist /******************************************************************************
564775afec4SFredrik Holmqvist  *
565775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsFree
566775afec4SFredrik Holmqvist  *
567775afec4SFredrik Holmqvist  * PARAMETERS:  mem                 Pointer to previously allocated memory
568775afec4SFredrik Holmqvist  *
569775afec4SFredrik Holmqvist  * RETURN:      None.
570775afec4SFredrik Holmqvist  *
571775afec4SFredrik Holmqvist  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
572775afec4SFredrik Holmqvist  *
573775afec4SFredrik Holmqvist  *****************************************************************************/
574775afec4SFredrik Holmqvist void
AcpiOsFree(void * mem)575775afec4SFredrik Holmqvist AcpiOsFree(void *mem)
576775afec4SFredrik Holmqvist {
577775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_VF("mem: %p", mem);
578775afec4SFredrik Holmqvist 	free(mem);
579775afec4SFredrik Holmqvist }
580775afec4SFredrik Holmqvist 
581775afec4SFredrik Holmqvist 
582775afec4SFredrik Holmqvist /******************************************************************************
583775afec4SFredrik Holmqvist  *
584775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsCreateSemaphore
585775afec4SFredrik Holmqvist  *
586775afec4SFredrik Holmqvist  * PARAMETERS:  initialUnits        - Units to be assigned to the new semaphore
587775afec4SFredrik Holmqvist  *              outHandle           - Where a handle will be returned
588775afec4SFredrik Holmqvist  *
589775afec4SFredrik Holmqvist  * RETURN:      Status
590775afec4SFredrik Holmqvist  *
591775afec4SFredrik Holmqvist  * DESCRIPTION: Create an OS semaphore
592775afec4SFredrik Holmqvist  *
593775afec4SFredrik Holmqvist  *****************************************************************************/
594775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsCreateSemaphore(UINT32 maxUnits,UINT32 initialUnits,ACPI_SEMAPHORE * outHandle)595775afec4SFredrik Holmqvist AcpiOsCreateSemaphore(UINT32 maxUnits, UINT32 initialUnits,
596775afec4SFredrik Holmqvist 		ACPI_SEMAPHORE *outHandle)
597775afec4SFredrik Holmqvist {
598775afec4SFredrik Holmqvist 	if (!outHandle)
599775afec4SFredrik Holmqvist     	return AE_BAD_PARAMETER;
600775afec4SFredrik Holmqvist 
601775afec4SFredrik Holmqvist 	*outHandle = create_sem(initialUnits, "acpi_sem");
602841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("max: %" B_PRIu32 "; count: %" B_PRIu32 "; result: %" PRId32,
6034fced27dSFrançois Revol 		(uint32)maxUnits, (uint32)initialUnits, *outHandle);
604775afec4SFredrik Holmqvist 
605775afec4SFredrik Holmqvist 	if (*outHandle >= B_OK)
606775afec4SFredrik Holmqvist 		return AE_OK;
607775afec4SFredrik Holmqvist 
608775afec4SFredrik Holmqvist 	return *outHandle == B_BAD_VALUE ? AE_BAD_PARAMETER : AE_NO_MEMORY;
609775afec4SFredrik Holmqvist }
610775afec4SFredrik Holmqvist 
611775afec4SFredrik Holmqvist 
612775afec4SFredrik Holmqvist /******************************************************************************
613775afec4SFredrik Holmqvist  *
614775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsDeleteSemaphore
615775afec4SFredrik Holmqvist  *
616775afec4SFredrik Holmqvist  * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
617775afec4SFredrik Holmqvist  *
618775afec4SFredrik Holmqvist  * RETURN:      Status
619775afec4SFredrik Holmqvist  *
620775afec4SFredrik Holmqvist  * DESCRIPTION: Delete an OS semaphore
621775afec4SFredrik Holmqvist  *
622775afec4SFredrik Holmqvist  *****************************************************************************/
623775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsDeleteSemaphore(ACPI_SEMAPHORE handle)624775afec4SFredrik Holmqvist AcpiOsDeleteSemaphore(ACPI_SEMAPHORE handle)
625775afec4SFredrik Holmqvist {
626841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("sem: %" B_PRId32, handle);
627775afec4SFredrik Holmqvist 	return delete_sem(handle) == B_OK ? AE_OK : AE_BAD_PARAMETER;
628775afec4SFredrik Holmqvist }
629775afec4SFredrik Holmqvist 
630775afec4SFredrik Holmqvist 
631775afec4SFredrik Holmqvist /******************************************************************************
632775afec4SFredrik Holmqvist  *
633775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsWaitSemaphore
634775afec4SFredrik Holmqvist  *
635775afec4SFredrik Holmqvist  * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
636775afec4SFredrik Holmqvist  *              units               - How many units to wait for
637775afec4SFredrik Holmqvist  *              timeout             - How long to wait
638775afec4SFredrik Holmqvist  *
639775afec4SFredrik Holmqvist  * RETURN:      Status
640775afec4SFredrik Holmqvist  *
641775afec4SFredrik Holmqvist  * DESCRIPTION: Wait for units
642775afec4SFredrik Holmqvist  *
643775afec4SFredrik Holmqvist  *****************************************************************************/
644775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsWaitSemaphore(ACPI_SEMAPHORE handle,UINT32 units,UINT16 timeout)645775afec4SFredrik Holmqvist AcpiOsWaitSemaphore(ACPI_SEMAPHORE handle, UINT32 units, UINT16 timeout)
646775afec4SFredrik Holmqvist {
647775afec4SFredrik Holmqvist 	ACPI_STATUS result = AE_OK;
648775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_VF("sem: %ld; count: %lu; timeout: %u",
6494fced27dSFrançois Revol 		handle, (uint32)units, timeout);
650775afec4SFredrik Holmqvist 
651775afec4SFredrik Holmqvist 	if (timeout == ACPI_WAIT_FOREVER) {
652775afec4SFredrik Holmqvist 		result = acquire_sem_etc(handle, units, 0, 0)
653775afec4SFredrik Holmqvist 			== B_OK ? AE_OK : AE_BAD_PARAMETER;
654775afec4SFredrik Holmqvist 	} else {
655775afec4SFredrik Holmqvist 		switch (acquire_sem_etc(handle, units, B_RELATIVE_TIMEOUT,
656775afec4SFredrik Holmqvist 			(bigtime_t)timeout * 1000)) {
657775afec4SFredrik Holmqvist 			case B_OK:
658775afec4SFredrik Holmqvist 				result = AE_OK;
659775afec4SFredrik Holmqvist 				break;
660775afec4SFredrik Holmqvist 			case B_INTERRUPTED:
661775afec4SFredrik Holmqvist 			case B_TIMED_OUT:
662775afec4SFredrik Holmqvist 			case B_WOULD_BLOCK:
663775afec4SFredrik Holmqvist 				result = AE_TIME;
664775afec4SFredrik Holmqvist 				break;
665775afec4SFredrik Holmqvist 			case B_BAD_VALUE:
666775afec4SFredrik Holmqvist 			default:
667775afec4SFredrik Holmqvist 				result = AE_BAD_PARAMETER;
668775afec4SFredrik Holmqvist 				break;
669775afec4SFredrik Holmqvist 		}
670775afec4SFredrik Holmqvist 	}
671775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_VF("sem: %ld; count: %lu; timeout: %u result: %lu",
6724fced27dSFrançois Revol 		handle, (uint32)units, timeout, (uint32)result);
673775afec4SFredrik Holmqvist 	return result;
674775afec4SFredrik Holmqvist }
675775afec4SFredrik Holmqvist 
676775afec4SFredrik Holmqvist 
677775afec4SFredrik Holmqvist /******************************************************************************
678775afec4SFredrik Holmqvist  *
679775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsSignalSemaphore
680775afec4SFredrik Holmqvist  *
681775afec4SFredrik Holmqvist  * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
682775afec4SFredrik Holmqvist  *              units               - Number of units to send
683775afec4SFredrik Holmqvist  *
684775afec4SFredrik Holmqvist  * RETURN:      Status
685775afec4SFredrik Holmqvist  *
686775afec4SFredrik Holmqvist  * DESCRIPTION: Send units
687775afec4SFredrik Holmqvist  *
688775afec4SFredrik Holmqvist  *****************************************************************************/
689775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsSignalSemaphore(ACPI_SEMAPHORE handle,UINT32 units)690775afec4SFredrik Holmqvist AcpiOsSignalSemaphore(ACPI_SEMAPHORE handle, UINT32 units)
691775afec4SFredrik Holmqvist {
692775afec4SFredrik Holmqvist 	status_t result;
6934fced27dSFrançois Revol 	DEBUG_FUNCTION_VF("sem: %ld; count: %lu", handle, (uint32)units);
694775afec4SFredrik Holmqvist 	// We can be called from interrupt handler, so don't reschedule
695775afec4SFredrik Holmqvist 	result = release_sem_etc(handle, units, B_DO_NOT_RESCHEDULE);
696775afec4SFredrik Holmqvist 	return result == B_OK ? AE_OK : AE_BAD_PARAMETER;
697775afec4SFredrik Holmqvist }
698775afec4SFredrik Holmqvist 
699775afec4SFredrik Holmqvist 
700775afec4SFredrik Holmqvist /******************************************************************************
701775afec4SFredrik Holmqvist  *
702775afec4SFredrik Holmqvist  * FUNCTION:    Spinlock interfaces
703775afec4SFredrik Holmqvist  *
704775afec4SFredrik Holmqvist  * DESCRIPTION: Map these interfaces to semaphore interfaces
705775afec4SFredrik Holmqvist  *
706775afec4SFredrik Holmqvist  *****************************************************************************/
707775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsCreateLock(ACPI_SPINLOCK * outHandle)708775afec4SFredrik Holmqvist AcpiOsCreateLock(ACPI_SPINLOCK *outHandle)
709775afec4SFredrik Holmqvist {
710775afec4SFredrik Holmqvist 	*outHandle = (ACPI_SPINLOCK) malloc(sizeof(spinlock));
711775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("result: %p", *outHandle);
712775afec4SFredrik Holmqvist 	if (*outHandle == NULL)
713775afec4SFredrik Holmqvist 		return AE_NO_MEMORY;
714775afec4SFredrik Holmqvist 
7151ee1d0cbSPawel Dziepak 	B_INITIALIZE_SPINLOCK(*outHandle);
716775afec4SFredrik Holmqvist 	return AE_OK;
717775afec4SFredrik Holmqvist }
718775afec4SFredrik Holmqvist 
719775afec4SFredrik Holmqvist 
720775afec4SFredrik Holmqvist void
AcpiOsDeleteLock(ACPI_SPINLOCK handle)721775afec4SFredrik Holmqvist AcpiOsDeleteLock(ACPI_SPINLOCK handle)
722775afec4SFredrik Holmqvist {
723775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
724775afec4SFredrik Holmqvist 	free((void*)handle);
725775afec4SFredrik Holmqvist }
726775afec4SFredrik Holmqvist 
727775afec4SFredrik Holmqvist 
728775afec4SFredrik Holmqvist ACPI_CPU_FLAGS
AcpiOsAcquireLock(ACPI_SPINLOCK handle)729775afec4SFredrik Holmqvist AcpiOsAcquireLock(ACPI_SPINLOCK handle)
730775afec4SFredrik Holmqvist {
731775afec4SFredrik Holmqvist 	cpu_status cpu;
732775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("spinlock: %p", handle);
733775afec4SFredrik Holmqvist 	cpu = disable_interrupts();
734775afec4SFredrik Holmqvist 	acquire_spinlock(handle);
735775afec4SFredrik Holmqvist 	return cpu;
736775afec4SFredrik Holmqvist }
737775afec4SFredrik Holmqvist 
738775afec4SFredrik Holmqvist 
739775afec4SFredrik Holmqvist void
AcpiOsReleaseLock(ACPI_SPINLOCK handle,ACPI_CPU_FLAGS flags)740775afec4SFredrik Holmqvist AcpiOsReleaseLock(ACPI_SPINLOCK handle, ACPI_CPU_FLAGS flags)
741775afec4SFredrik Holmqvist {
742775afec4SFredrik Holmqvist 	release_spinlock(handle);
743775afec4SFredrik Holmqvist 	restore_interrupts(flags);
744775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("spinlock: %p", handle);
745775afec4SFredrik Holmqvist }
746775afec4SFredrik Holmqvist 
747775afec4SFredrik Holmqvist 
748775afec4SFredrik Holmqvist /******************************************************************************
749775afec4SFredrik Holmqvist  *
750775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsInstallInterruptHandler
751775afec4SFredrik Holmqvist  *
752775afec4SFredrik Holmqvist  * PARAMETERS:  interruptNumber     Level handler should respond to.
753775afec4SFredrik Holmqvist  *              Isr                 Address of the ACPI interrupt handler
754775afec4SFredrik Holmqvist  *              ExceptPtr           Where status is returned
755775afec4SFredrik Holmqvist  *
756775afec4SFredrik Holmqvist  * RETURN:      Handle to the newly installed handler.
757775afec4SFredrik Holmqvist  *
758775afec4SFredrik Holmqvist  * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
759775afec4SFredrik Holmqvist  *              OS-independent handler.
760775afec4SFredrik Holmqvist  *
761775afec4SFredrik Holmqvist  *****************************************************************************/
762775afec4SFredrik Holmqvist UINT32
AcpiOsInstallInterruptHandler(UINT32 interruptNumber,ACPI_OSD_HANDLER serviceRoutine,void * context)763775afec4SFredrik Holmqvist AcpiOsInstallInterruptHandler(UINT32 interruptNumber,
764775afec4SFredrik Holmqvist 		ACPI_OSD_HANDLER serviceRoutine, void *context)
765775afec4SFredrik Holmqvist {
766775afec4SFredrik Holmqvist 	status_t result;
767841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("vector: %" B_PRIu32 "; handler: %p context %p",
7684fced27dSFrançois Revol 		(uint32)interruptNumber, serviceRoutine, context);
769775afec4SFredrik Holmqvist 
770775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
771775afec4SFredrik Holmqvist 	// It so happens that the Haiku and ACPI-CA interrupt handler routines
772775afec4SFredrik Holmqvist 	// return the same values with the same meanings
773775afec4SFredrik Holmqvist 	sInterruptHandlerData[interruptNumber] = context;
774775afec4SFredrik Holmqvist 	result = install_io_interrupt_handler(interruptNumber,
775775afec4SFredrik Holmqvist 		(interrupt_handler)serviceRoutine, context, 0);
776775afec4SFredrik Holmqvist 
777841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("vector: %" B_PRIu32 "; handler: %p context %p returned %" B_PRId32,
7784fced27dSFrançois Revol 		(uint32)interruptNumber, serviceRoutine, context, (uint32)result);
779775afec4SFredrik Holmqvist 
780775afec4SFredrik Holmqvist 	return result == B_OK ? AE_OK : AE_BAD_PARAMETER;
781775afec4SFredrik Holmqvist #else
782775afec4SFredrik Holmqvist 	return AE_BAD_PARAMETER;
783775afec4SFredrik Holmqvist #endif
784775afec4SFredrik Holmqvist }
785775afec4SFredrik Holmqvist 
786775afec4SFredrik Holmqvist 
787775afec4SFredrik Holmqvist /******************************************************************************
788775afec4SFredrik Holmqvist  *
789775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsRemoveInterruptHandler
790775afec4SFredrik Holmqvist  *
791775afec4SFredrik Holmqvist  * PARAMETERS:  Handle              Returned when handler was installed
792775afec4SFredrik Holmqvist  *
793775afec4SFredrik Holmqvist  * RETURN:      Status
794775afec4SFredrik Holmqvist  *
795775afec4SFredrik Holmqvist  * DESCRIPTION: Uninstalls an interrupt handler.
796775afec4SFredrik Holmqvist  *
797775afec4SFredrik Holmqvist  *****************************************************************************/
798775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsRemoveInterruptHandler(UINT32 interruptNumber,ACPI_OSD_HANDLER serviceRoutine)799775afec4SFredrik Holmqvist AcpiOsRemoveInterruptHandler(UINT32 interruptNumber,
800775afec4SFredrik Holmqvist 		ACPI_OSD_HANDLER serviceRoutine)
801775afec4SFredrik Holmqvist {
802841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("vector: %" B_PRIu32 "; handler: %p", (uint32)interruptNumber,
803775afec4SFredrik Holmqvist 		serviceRoutine);
804775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
805a4a538dbSAugustin Cavalier 	return remove_io_interrupt_handler(interruptNumber,
806775afec4SFredrik Holmqvist 		(interrupt_handler)serviceRoutine,
807a4a538dbSAugustin Cavalier 		sInterruptHandlerData[interruptNumber]) == B_OK ? AE_OK : AE_ERROR;
808775afec4SFredrik Holmqvist #else
809775afec4SFredrik Holmqvist 	return AE_ERROR;
810775afec4SFredrik Holmqvist #endif
811775afec4SFredrik Holmqvist }
812775afec4SFredrik Holmqvist 
813775afec4SFredrik Holmqvist 
814775afec4SFredrik Holmqvist /******************************************************************************
815775afec4SFredrik Holmqvist  *
816775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsExecute
817775afec4SFredrik Holmqvist  *
818775afec4SFredrik Holmqvist  * PARAMETERS:  type            - Type of execution
819775afec4SFredrik Holmqvist  *              function        - Address of the function to execute
820775afec4SFredrik Holmqvist  *              context         - Passed as a parameter to the function
821775afec4SFredrik Holmqvist  *
822775afec4SFredrik Holmqvist  * RETURN:      Status.
823775afec4SFredrik Holmqvist  *
824775afec4SFredrik Holmqvist  * DESCRIPTION: Execute a new thread
825775afec4SFredrik Holmqvist  *
826775afec4SFredrik Holmqvist  *****************************************************************************/
827775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsExecute(ACPI_EXECUTE_TYPE type,ACPI_OSD_EXEC_CALLBACK function,void * context)828775afec4SFredrik Holmqvist AcpiOsExecute(ACPI_EXECUTE_TYPE type, ACPI_OSD_EXEC_CALLBACK  function,
829775afec4SFredrik Holmqvist 		void *context)
830775afec4SFredrik Holmqvist {
831775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
832775afec4SFredrik Holmqvist /* TODO: Prioritize urgent?
833775afec4SFredrik Holmqvist 	switch (type) {
834775afec4SFredrik Holmqvist 		case OSL_GLOBAL_LOCK_HANDLER:
835775afec4SFredrik Holmqvist 		case OSL_NOTIFY_HANDLER:
836775afec4SFredrik Holmqvist 		case OSL_GPE_HANDLER:
837775afec4SFredrik Holmqvist 		case OSL_DEBUGGER_THREAD:
838775afec4SFredrik Holmqvist 		case OSL_EC_POLL_HANDLER:
839775afec4SFredrik Holmqvist 		case OSL_EC_BURST_HANDLER:
840775afec4SFredrik Holmqvist 			break;
841775afec4SFredrik Holmqvist 	}
842775afec4SFredrik Holmqvist */
843775afec4SFredrik Holmqvist 
844775afec4SFredrik Holmqvist 	if (gDPC->queue_dpc(gDPCHandle, function, context) != B_OK) {
845775afec4SFredrik Holmqvist 		DEBUG_FUNCTION_F("Serious failure in AcpiOsExecute! function: %p",
846775afec4SFredrik Holmqvist 			function);
847775afec4SFredrik Holmqvist 		return AE_BAD_PARAMETER;
848775afec4SFredrik Holmqvist 	}
849775afec4SFredrik Holmqvist 	return AE_OK;
850775afec4SFredrik Holmqvist }
851775afec4SFredrik Holmqvist 
852775afec4SFredrik Holmqvist 
853775afec4SFredrik Holmqvist /******************************************************************************
854775afec4SFredrik Holmqvist  *
855775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsStall
856775afec4SFredrik Holmqvist  *
857775afec4SFredrik Holmqvist  * PARAMETERS:  microseconds        To sleep
858775afec4SFredrik Holmqvist  *
859775afec4SFredrik Holmqvist  * RETURN:      Blocks until sleep is completed.
860775afec4SFredrik Holmqvist  *
861775afec4SFredrik Holmqvist  * DESCRIPTION: Sleep at microsecond granularity
862775afec4SFredrik Holmqvist  *
863775afec4SFredrik Holmqvist  *****************************************************************************/
864775afec4SFredrik Holmqvist void
AcpiOsStall(UINT32 microseconds)865775afec4SFredrik Holmqvist AcpiOsStall(UINT32 microseconds)
866775afec4SFredrik Holmqvist {
867841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("microseconds: %" B_PRIu32, (uint32)microseconds);
868775afec4SFredrik Holmqvist 	if (microseconds)
869775afec4SFredrik Holmqvist 		spin(microseconds);
870775afec4SFredrik Holmqvist }
871775afec4SFredrik Holmqvist 
872775afec4SFredrik Holmqvist 
873775afec4SFredrik Holmqvist /******************************************************************************
874775afec4SFredrik Holmqvist  *
875775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsSleep
876775afec4SFredrik Holmqvist  *
877775afec4SFredrik Holmqvist  * PARAMETERS:  milliseconds        To sleep
878775afec4SFredrik Holmqvist  *
879775afec4SFredrik Holmqvist  * RETURN:      Blocks until sleep is completed.
880775afec4SFredrik Holmqvist  *
881775afec4SFredrik Holmqvist  * DESCRIPTION: Sleep at millisecond granularity
882775afec4SFredrik Holmqvist  *
883775afec4SFredrik Holmqvist  *****************************************************************************/
884775afec4SFredrik Holmqvist void
AcpiOsSleep(ACPI_INTEGER milliseconds)885775afec4SFredrik Holmqvist AcpiOsSleep(ACPI_INTEGER milliseconds)
886775afec4SFredrik Holmqvist {
887841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("milliseconds: %" B_PRIu32, (uint32)milliseconds);
888775afec4SFredrik Holmqvist 	if (gKernelStartup)
889775afec4SFredrik Holmqvist 		spin(milliseconds * 1000);
890775afec4SFredrik Holmqvist 	else
891775afec4SFredrik Holmqvist 		snooze(milliseconds * 1000);
892775afec4SFredrik Holmqvist }
893775afec4SFredrik Holmqvist 
894775afec4SFredrik Holmqvist 
895775afec4SFredrik Holmqvist /******************************************************************************
896775afec4SFredrik Holmqvist  *
897775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsGetTimer
898775afec4SFredrik Holmqvist  *
899775afec4SFredrik Holmqvist  * PARAMETERS:  None
900775afec4SFredrik Holmqvist  *
901775afec4SFredrik Holmqvist  * RETURN:      Current time in 100 nanosecond units
902775afec4SFredrik Holmqvist  *
903775afec4SFredrik Holmqvist  * DESCRIPTION: Get the current system time
904775afec4SFredrik Holmqvist  *
905775afec4SFredrik Holmqvist  *****************************************************************************/
906775afec4SFredrik Holmqvist UINT64
AcpiOsGetTimer()907775afec4SFredrik Holmqvist AcpiOsGetTimer()
908775afec4SFredrik Holmqvist {
909775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
910775afec4SFredrik Holmqvist 	return system_time() * 10;
911775afec4SFredrik Holmqvist }
912775afec4SFredrik Holmqvist 
913775afec4SFredrik Holmqvist 
914775afec4SFredrik Holmqvist /******************************************************************************
915775afec4SFredrik Holmqvist  *
916775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsReadPciConfiguration
917775afec4SFredrik Holmqvist  *
918775afec4SFredrik Holmqvist  * PARAMETERS:  pciId               Seg/Bus/Dev
919775afec4SFredrik Holmqvist  *              reg                 Device Register
920775afec4SFredrik Holmqvist  *              value               Buffer where value is placed
921775afec4SFredrik Holmqvist  *              width               Number of bits
922775afec4SFredrik Holmqvist  *
923775afec4SFredrik Holmqvist  * RETURN:      Status
924775afec4SFredrik Holmqvist  *
925775afec4SFredrik Holmqvist  * DESCRIPTION: Read data from PCI configuration space
926775afec4SFredrik Holmqvist  *
927775afec4SFredrik Holmqvist  *****************************************************************************/
928775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsReadPciConfiguration(ACPI_PCI_ID * pciId,UINT32 reg,UINT64 * value,UINT32 width)929775afec4SFredrik Holmqvist AcpiOsReadPciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg, UINT64 *value,
930775afec4SFredrik Holmqvist 		UINT32 width)
931775afec4SFredrik Holmqvist {
932775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
933775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
934775afec4SFredrik Holmqvist 
935775afec4SFredrik Holmqvist 	switch (width) {
936775afec4SFredrik Holmqvist 		case 8:
937775afec4SFredrik Holmqvist 		case 16:
938775afec4SFredrik Holmqvist 		case 32:
939775afec4SFredrik Holmqvist 			*value = gPCIManager->read_pci_config(
940775afec4SFredrik Holmqvist 				pciId->Bus, pciId->Device, pciId->Function, reg, width / 8);
941775afec4SFredrik Holmqvist 			break;
942775afec4SFredrik Holmqvist 		default:
943775afec4SFredrik Holmqvist 			return AE_ERROR;
944775afec4SFredrik Holmqvist 	}
945775afec4SFredrik Holmqvist 	return AE_OK;
946775afec4SFredrik Holmqvist #else
947775afec4SFredrik Holmqvist 	return AE_ERROR;
948775afec4SFredrik Holmqvist #endif
949775afec4SFredrik Holmqvist }
950775afec4SFredrik Holmqvist 
951775afec4SFredrik Holmqvist 
952775afec4SFredrik Holmqvist /******************************************************************************
953775afec4SFredrik Holmqvist  *
954775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsWritePciConfiguration
955775afec4SFredrik Holmqvist  *
956775afec4SFredrik Holmqvist  * PARAMETERS:  pciId               Seg/Bus/Dev
957775afec4SFredrik Holmqvist  *              reg                 Device Register
958775afec4SFredrik Holmqvist  *              value               Value to be written
959775afec4SFredrik Holmqvist  *              width               Number of bits
960775afec4SFredrik Holmqvist  *
961775afec4SFredrik Holmqvist  * RETURN:      Status.
962775afec4SFredrik Holmqvist  *
963775afec4SFredrik Holmqvist  * DESCRIPTION: Write data to PCI configuration space
964775afec4SFredrik Holmqvist  *
965775afec4SFredrik Holmqvist  *****************************************************************************/
966775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsWritePciConfiguration(ACPI_PCI_ID * pciId,UINT32 reg,ACPI_INTEGER value,UINT32 width)967775afec4SFredrik Holmqvist AcpiOsWritePciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg,
968775afec4SFredrik Holmqvist 		ACPI_INTEGER value, UINT32 width)
969775afec4SFredrik Holmqvist {
970775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
971775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
972775afec4SFredrik Holmqvist 	gPCIManager->write_pci_config(
973775afec4SFredrik Holmqvist 		pciId->Bus, pciId->Device, pciId->Function, reg, width / 8, value);
974775afec4SFredrik Holmqvist 	return AE_OK;
975775afec4SFredrik Holmqvist #else
976775afec4SFredrik Holmqvist 	return AE_ERROR;
977775afec4SFredrik Holmqvist #endif
978775afec4SFredrik Holmqvist }
979775afec4SFredrik Holmqvist 
980775afec4SFredrik Holmqvist 
981775afec4SFredrik Holmqvist /******************************************************************************
982775afec4SFredrik Holmqvist  *
983775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsReadPort
984775afec4SFredrik Holmqvist  *
985775afec4SFredrik Holmqvist  * PARAMETERS:  address             Address of I/O port/register to read
986775afec4SFredrik Holmqvist  *              Value               Where value is placed
987775afec4SFredrik Holmqvist  *              width               Number of bits
988775afec4SFredrik Holmqvist  *
989775afec4SFredrik Holmqvist  * RETURN:      Value read from port
990775afec4SFredrik Holmqvist  *
991775afec4SFredrik Holmqvist  * DESCRIPTION: Read data from an I/O port or register
992775afec4SFredrik Holmqvist  *
993775afec4SFredrik Holmqvist  *****************************************************************************/
994775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsReadPort(ACPI_IO_ADDRESS address,UINT32 * value,UINT32 width)995775afec4SFredrik Holmqvist AcpiOsReadPort(ACPI_IO_ADDRESS address, UINT32 *value, UINT32 width)
996775afec4SFredrik Holmqvist {
997775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
998841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("addr: 0x%08lx; width: %" B_PRIu32, (addr_t)address, (uint32)width);
999775afec4SFredrik Holmqvist 	switch (width) {
1000775afec4SFredrik Holmqvist 		case 8:
1001775afec4SFredrik Holmqvist 			*value = gPCIManager->read_io_8(address);
1002775afec4SFredrik Holmqvist 			break;
1003775afec4SFredrik Holmqvist 
1004775afec4SFredrik Holmqvist 		case 16:
1005775afec4SFredrik Holmqvist 			*value = gPCIManager->read_io_16(address);
1006775afec4SFredrik Holmqvist 			break;
1007775afec4SFredrik Holmqvist 
1008775afec4SFredrik Holmqvist 		case 32:
1009775afec4SFredrik Holmqvist 			*value = gPCIManager->read_io_32(address);
1010775afec4SFredrik Holmqvist 			break;
1011775afec4SFredrik Holmqvist 
1012775afec4SFredrik Holmqvist 		default:
1013775afec4SFredrik Holmqvist 			return AE_ERROR;
1014775afec4SFredrik Holmqvist 	}
1015775afec4SFredrik Holmqvist 
1016775afec4SFredrik Holmqvist 	return AE_OK;
1017775afec4SFredrik Holmqvist #else
1018775afec4SFredrik Holmqvist 	return AE_ERROR;
1019775afec4SFredrik Holmqvist #endif
1020775afec4SFredrik Holmqvist }
1021775afec4SFredrik Holmqvist 
1022775afec4SFredrik Holmqvist 
1023775afec4SFredrik Holmqvist /******************************************************************************
1024775afec4SFredrik Holmqvist  *
1025775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsWritePort
1026775afec4SFredrik Holmqvist  *
1027775afec4SFredrik Holmqvist  * PARAMETERS:  address             Address of I/O port/register to write
1028775afec4SFredrik Holmqvist  *              value               Value to write
1029775afec4SFredrik Holmqvist  *              width               Number of bits
1030775afec4SFredrik Holmqvist  *
1031775afec4SFredrik Holmqvist  * RETURN:      None
1032775afec4SFredrik Holmqvist  *
1033775afec4SFredrik Holmqvist  * DESCRIPTION: Write data to an I/O port or register
1034775afec4SFredrik Holmqvist  *
1035775afec4SFredrik Holmqvist  *****************************************************************************/
1036775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsWritePort(ACPI_IO_ADDRESS address,UINT32 value,UINT32 width)1037775afec4SFredrik Holmqvist AcpiOsWritePort(ACPI_IO_ADDRESS address, UINT32 value, UINT32 width)
1038775afec4SFredrik Holmqvist {
1039775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
1040841c1c0cSPulkoMandy 	DEBUG_FUNCTION_F("addr: 0x%08lx; value: %" B_PRIu32 "; width: %" B_PRIu32,
10414fced27dSFrançois Revol 		(addr_t)address, (uint32)value, (uint32)width);
1042775afec4SFredrik Holmqvist 	switch (width) {
1043775afec4SFredrik Holmqvist 		case 8:
1044775afec4SFredrik Holmqvist 			gPCIManager->write_io_8(address, value);
1045775afec4SFredrik Holmqvist 			break;
1046775afec4SFredrik Holmqvist 
1047775afec4SFredrik Holmqvist 		case 16:
1048775afec4SFredrik Holmqvist 			gPCIManager->write_io_16(address,value);
1049775afec4SFredrik Holmqvist 			break;
1050775afec4SFredrik Holmqvist 
1051775afec4SFredrik Holmqvist 		case 32:
1052775afec4SFredrik Holmqvist 			gPCIManager->write_io_32(address,value);
1053775afec4SFredrik Holmqvist 			break;
1054775afec4SFredrik Holmqvist 
1055775afec4SFredrik Holmqvist 		default:
1056775afec4SFredrik Holmqvist 			return AE_ERROR;
1057775afec4SFredrik Holmqvist 	}
1058775afec4SFredrik Holmqvist 
1059775afec4SFredrik Holmqvist 	return AE_OK;
1060775afec4SFredrik Holmqvist #else
1061775afec4SFredrik Holmqvist 	return AE_ERROR;
1062775afec4SFredrik Holmqvist #endif
1063775afec4SFredrik Holmqvist }
1064775afec4SFredrik Holmqvist 
1065775afec4SFredrik Holmqvist 
1066775afec4SFredrik Holmqvist /******************************************************************************
1067775afec4SFredrik Holmqvist  *
1068775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsReadMemory
1069775afec4SFredrik Holmqvist  *
1070775afec4SFredrik Holmqvist  * PARAMETERS:  address             Physical Memory Address to read
1071775afec4SFredrik Holmqvist  *              value               Where value is placed
1072775afec4SFredrik Holmqvist  *              width               Number of bits
1073775afec4SFredrik Holmqvist  *
1074775afec4SFredrik Holmqvist  * RETURN:      Value read from physical memory address
1075775afec4SFredrik Holmqvist  *
1076775afec4SFredrik Holmqvist  * DESCRIPTION: Read data from a physical memory address
1077775afec4SFredrik Holmqvist  *
1078775afec4SFredrik Holmqvist  *****************************************************************************/
1079775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS address,UINT64 * value,UINT32 width)1080775afec4SFredrik Holmqvist AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS address, UINT64 *value, UINT32 width)
1081775afec4SFredrik Holmqvist {
1082775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
1083e5c95a01SFredrik Holmqvist 	if (vm_memcpy_from_physical(value, (phys_addr_t)address, width / 8, false)
1084775afec4SFredrik Holmqvist 		!= B_OK) {
1085775afec4SFredrik Holmqvist 		return AE_ERROR;
1086775afec4SFredrik Holmqvist 	}
1087775afec4SFredrik Holmqvist 	return AE_OK;
1088775afec4SFredrik Holmqvist #else
1089775afec4SFredrik Holmqvist 	return AE_ERROR;
1090775afec4SFredrik Holmqvist #endif
1091775afec4SFredrik Holmqvist }
1092775afec4SFredrik Holmqvist 
1093775afec4SFredrik Holmqvist 
1094775afec4SFredrik Holmqvist /******************************************************************************
1095775afec4SFredrik Holmqvist  *
1096775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsWriteMemory
1097775afec4SFredrik Holmqvist  *
1098775afec4SFredrik Holmqvist  * PARAMETERS:  address             Physical Memory Address to write
1099775afec4SFredrik Holmqvist  *              value               Value to write
1100775afec4SFredrik Holmqvist  *              width               Number of bits
1101775afec4SFredrik Holmqvist  *
1102775afec4SFredrik Holmqvist  * RETURN:      None
1103775afec4SFredrik Holmqvist  *
1104775afec4SFredrik Holmqvist  * DESCRIPTION: Write data to a physical memory address
1105775afec4SFredrik Holmqvist  *
1106775afec4SFredrik Holmqvist  *****************************************************************************/
1107775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS address,UINT64 value,UINT32 width)1108775afec4SFredrik Holmqvist AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS address, UINT64 value, UINT32 width)
1109775afec4SFredrik Holmqvist {
1110775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
1111e5c95a01SFredrik Holmqvist 	if (vm_memcpy_to_physical((phys_addr_t)address, &value, width / 8, false)
1112775afec4SFredrik Holmqvist 			!= B_OK) {
1113775afec4SFredrik Holmqvist 		return AE_ERROR;
1114775afec4SFredrik Holmqvist 	}
1115775afec4SFredrik Holmqvist 	return AE_OK;
1116775afec4SFredrik Holmqvist #else
1117775afec4SFredrik Holmqvist 	return AE_ERROR;
1118775afec4SFredrik Holmqvist #endif
1119775afec4SFredrik Holmqvist }
1120775afec4SFredrik Holmqvist 
1121775afec4SFredrik Holmqvist 
1122775afec4SFredrik Holmqvist /******************************************************************************
1123775afec4SFredrik Holmqvist  *
1124775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsReadable
1125775afec4SFredrik Holmqvist  *
1126775afec4SFredrik Holmqvist  * PARAMETERS:  pointer             - Area to be verified
1127775afec4SFredrik Holmqvist  *              length              - Size of area
1128775afec4SFredrik Holmqvist  *
1129775afec4SFredrik Holmqvist  * RETURN:      TRUE if readable for entire length
1130775afec4SFredrik Holmqvist  *
1131775afec4SFredrik Holmqvist  * DESCRIPTION: Verify that a pointer is valid for reading
1132775afec4SFredrik Holmqvist  *
1133775afec4SFredrik Holmqvist  *****************************************************************************/
1134775afec4SFredrik Holmqvist BOOLEAN
AcpiOsReadable(void * pointer,ACPI_SIZE length)1135775afec4SFredrik Holmqvist AcpiOsReadable(void *pointer, ACPI_SIZE length)
1136775afec4SFredrik Holmqvist {
1137775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
1138775afec4SFredrik Holmqvist 	return true;
1139775afec4SFredrik Holmqvist #else
1140775afec4SFredrik Holmqvist 	area_id id;
1141775afec4SFredrik Holmqvist 	area_info info;
1142775afec4SFredrik Holmqvist 
1143775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length);
1144775afec4SFredrik Holmqvist 
1145775afec4SFredrik Holmqvist 	id = area_for(pointer);
1146775afec4SFredrik Holmqvist 	if (id == B_ERROR) return false;
1147775afec4SFredrik Holmqvist 	if (get_area_info(id, &info) != B_OK) return false;
1148775afec4SFredrik Holmqvist 	return (info.protection & B_READ_AREA) != 0 &&
114986901205SFredrik Holmqvist 			((char *)pointer) + length <= info.address + info.ram_size;
1150775afec4SFredrik Holmqvist #endif
1151775afec4SFredrik Holmqvist }
1152775afec4SFredrik Holmqvist 
1153775afec4SFredrik Holmqvist 
1154775afec4SFredrik Holmqvist /******************************************************************************
1155775afec4SFredrik Holmqvist  *
1156775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsWritable
1157775afec4SFredrik Holmqvist  *
1158775afec4SFredrik Holmqvist  * PARAMETERS:  pointer             - Area to be verified
1159775afec4SFredrik Holmqvist  *              length              - Size of area
1160775afec4SFredrik Holmqvist  *
1161775afec4SFredrik Holmqvist  * RETURN:      TRUE if writable for entire length
1162775afec4SFredrik Holmqvist  *
1163775afec4SFredrik Holmqvist  * DESCRIPTION: Verify that a pointer is valid for writing
1164775afec4SFredrik Holmqvist  *
1165775afec4SFredrik Holmqvist  *****************************************************************************/
1166775afec4SFredrik Holmqvist BOOLEAN
AcpiOsWritable(void * pointer,ACPI_SIZE length)1167775afec4SFredrik Holmqvist AcpiOsWritable(void *pointer, ACPI_SIZE length)
1168775afec4SFredrik Holmqvist {
1169775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
1170775afec4SFredrik Holmqvist 	return true;
1171775afec4SFredrik Holmqvist #else
1172775afec4SFredrik Holmqvist 	area_id id;
1173775afec4SFredrik Holmqvist 	area_info info;
1174775afec4SFredrik Holmqvist 
1175775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length);
1176775afec4SFredrik Holmqvist 
1177775afec4SFredrik Holmqvist 	id = area_for(pointer);
1178775afec4SFredrik Holmqvist 	if (id == B_ERROR) return false;
1179775afec4SFredrik Holmqvist 	if (get_area_info(id, &info) != B_OK) return false;
1180775afec4SFredrik Holmqvist 	return (info.protection & B_READ_AREA) != 0 &&
1181775afec4SFredrik Holmqvist 			(info.protection & B_WRITE_AREA) != 0 &&
118286901205SFredrik Holmqvist 			((char *)pointer) + length <= info.address + info.ram_size;
1183775afec4SFredrik Holmqvist #endif
1184775afec4SFredrik Holmqvist }
1185775afec4SFredrik Holmqvist 
1186775afec4SFredrik Holmqvist 
1187775afec4SFredrik Holmqvist /******************************************************************************
1188775afec4SFredrik Holmqvist  *
1189775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsGetThreadId
1190775afec4SFredrik Holmqvist  *
1191775afec4SFredrik Holmqvist  * PARAMETERS:  None
1192775afec4SFredrik Holmqvist  *
1193775afec4SFredrik Holmqvist  * RETURN:      Id of the running thread
1194775afec4SFredrik Holmqvist  *
1195775afec4SFredrik Holmqvist  * DESCRIPTION: Get the Id of the current (running) thread
1196775afec4SFredrik Holmqvist  *
1197775afec4SFredrik Holmqvist  * NOTE:        The environment header should contain this line:
1198775afec4SFredrik Holmqvist  *                  #define ACPI_THREAD_ID pthread_t
1199775afec4SFredrik Holmqvist  *
1200775afec4SFredrik Holmqvist  *****************************************************************************/
1201775afec4SFredrik Holmqvist ACPI_THREAD_ID
AcpiOsGetThreadId()1202775afec4SFredrik Holmqvist AcpiOsGetThreadId()
1203775afec4SFredrik Holmqvist {
1204775afec4SFredrik Holmqvist 	thread_id thread = find_thread(NULL);
1205775afec4SFredrik Holmqvist 	// TODO: We arn't allowed threads with id 0, handle this case.
1206775afec4SFredrik Holmqvist 	// ACPI treats a 0 return as an error,
1207775afec4SFredrik Holmqvist 	// but we are thread 0 in early boot
1208775afec4SFredrik Holmqvist 	return thread;
1209775afec4SFredrik Holmqvist }
1210775afec4SFredrik Holmqvist 
1211775afec4SFredrik Holmqvist 
1212775afec4SFredrik Holmqvist /******************************************************************************
1213775afec4SFredrik Holmqvist  *
1214775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsSignal
1215775afec4SFredrik Holmqvist  *
1216775afec4SFredrik Holmqvist  * PARAMETERS:  function            ACPI CA signal function code
1217775afec4SFredrik Holmqvist  *              info                Pointer to function-dependent structure
1218775afec4SFredrik Holmqvist  *
1219775afec4SFredrik Holmqvist  * RETURN:      Status
1220775afec4SFredrik Holmqvist  *
1221775afec4SFredrik Holmqvist  * DESCRIPTION: Miscellaneous functions. Example implementation only.
1222775afec4SFredrik Holmqvist  *
1223775afec4SFredrik Holmqvist  *****************************************************************************/
1224775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsSignal(UINT32 function,void * info)1225775afec4SFredrik Holmqvist AcpiOsSignal(UINT32 function, void *info)
1226775afec4SFredrik Holmqvist {
1227775afec4SFredrik Holmqvist 	DEBUG_FUNCTION();
1228775afec4SFredrik Holmqvist 
1229775afec4SFredrik Holmqvist 	switch (function) {
1230775afec4SFredrik Holmqvist 		case ACPI_SIGNAL_FATAL:
1231775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE
123259642dc3SColdfirex 			panic("%s", info == NULL ? "AcpiOsSignal: fatal" : (const char*)info);
1233775afec4SFredrik Holmqvist 			break;
1234775afec4SFredrik Holmqvist #endif
1235775afec4SFredrik Holmqvist 		case ACPI_SIGNAL_BREAKPOINT:
1236775afec4SFredrik Holmqvist 			if (info != NULL)
1237c1e4908dSFredrik Holmqvist 				AcpiOsPrintf("AcpiOsBreakpoint: %s ****\n", (const char*)info);
1238775afec4SFredrik Holmqvist 			else
1239775afec4SFredrik Holmqvist 				AcpiOsPrintf("At AcpiOsBreakpoint ****\n");
1240775afec4SFredrik Holmqvist 			break;
1241775afec4SFredrik Holmqvist 	}
1242775afec4SFredrik Holmqvist 
1243775afec4SFredrik Holmqvist 	return AE_OK;
1244775afec4SFredrik Holmqvist }
1245775afec4SFredrik Holmqvist 
1246775afec4SFredrik Holmqvist 
1247775afec4SFredrik Holmqvist /*
1248775afec4SFredrik Holmqvist  * Adapted from FreeBSD since the documentation of its intended impl
1249775afec4SFredrik Holmqvist  * is lacking.
1250775afec4SFredrik Holmqvist  *  Section 5.2.10.1: global lock acquire/release functions */
1251775afec4SFredrik Holmqvist 
1252775afec4SFredrik Holmqvist /*
1253775afec4SFredrik Holmqvist  * Adapted from FreeBSD since the documentation of its intended impl
1254775afec4SFredrik Holmqvist  * is lacking.
1255775afec4SFredrik Holmqvist  * Acquire the global lock.  If busy, set the pending bit.  The caller
1256775afec4SFredrik Holmqvist  * will wait for notification from the BIOS that the lock is available
1257775afec4SFredrik Holmqvist  * and then attempt to acquire it again.
1258775afec4SFredrik Holmqvist  */
1259775afec4SFredrik Holmqvist int
AcpiOsAcquireGlobalLock(volatile uint32_t * lock)1260f2acc47fSJérôme Duval AcpiOsAcquireGlobalLock(volatile uint32_t *lock)
1261775afec4SFredrik Holmqvist {
1262f2acc47fSJérôme Duval 	uint32_t newValue;
1263f2acc47fSJérôme Duval 	uint32_t oldValue;
1264775afec4SFredrik Holmqvist 
1265775afec4SFredrik Holmqvist 	do {
1266775afec4SFredrik Holmqvist 		oldValue = *lock;
1267f2acc47fSJérôme Duval 		newValue = ((oldValue & ~ACPI_GLOCK_PENDING) | ACPI_GLOCK_OWNED);
1268f2acc47fSJérôme Duval 		if ((oldValue & ACPI_GLOCK_OWNED) != 0)
1269f2acc47fSJérôme Duval 			newValue |= ACPI_GLOCK_PENDING;
1270f2acc47fSJérôme Duval 	} while (atomic_test_and_set((int32*)lock, newValue, oldValue) != (int32)oldValue);
127164408be7SAugustin Cavalier 
127264408be7SAugustin Cavalier 	return (newValue & ACPI_GLOCK_PENDING) == 0;
1273775afec4SFredrik Holmqvist }
1274775afec4SFredrik Holmqvist 
1275775afec4SFredrik Holmqvist 
1276775afec4SFredrik Holmqvist /*
1277775afec4SFredrik Holmqvist  * Adapted from FreeBSD since the documentation of its intended impl
1278775afec4SFredrik Holmqvist  * is lacking.
1279775afec4SFredrik Holmqvist  * Release the global lock, returning whether there is a waiter pending.
1280775afec4SFredrik Holmqvist  * If the BIOS set the pending bit, OSPM must notify the BIOS when it
1281775afec4SFredrik Holmqvist  * releases the lock.
1282775afec4SFredrik Holmqvist  */
1283775afec4SFredrik Holmqvist int
AcpiOsReleaseGlobalLock(volatile uint32_t * lock)1284f2acc47fSJérôme Duval AcpiOsReleaseGlobalLock(volatile uint32_t *lock)
1285775afec4SFredrik Holmqvist {
1286775afec4SFredrik Holmqvist 	uint32 newValue;
1287775afec4SFredrik Holmqvist 	uint32 oldValue;
1288775afec4SFredrik Holmqvist 
1289775afec4SFredrik Holmqvist 	do {
1290775afec4SFredrik Holmqvist 		oldValue = *lock;
1291f2acc47fSJérôme Duval 		newValue = oldValue & ~(ACPI_GLOCK_PENDING | ACPI_GLOCK_OWNED);
1292f2acc47fSJérôme Duval 	} while (atomic_test_and_set((int32*)lock, newValue, oldValue) != (int32)oldValue);
129364408be7SAugustin Cavalier 
1294f2acc47fSJérôme Duval 	return (oldValue & ACPI_GLOCK_PENDING) != 0;
1295775afec4SFredrik Holmqvist }
1296775afec4SFredrik Holmqvist 
1297775afec4SFredrik Holmqvist 
1298775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsCreateMutex(ACPI_MUTEX * outHandle)1299775afec4SFredrik Holmqvist AcpiOsCreateMutex(ACPI_MUTEX* outHandle)
1300775afec4SFredrik Holmqvist {
1301775afec4SFredrik Holmqvist 	*outHandle = (ACPI_MUTEX) malloc(sizeof(mutex));
1302775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("result: %p", *outHandle);
1303775afec4SFredrik Holmqvist 	if (*outHandle == NULL)
1304775afec4SFredrik Holmqvist 		return AE_NO_MEMORY;
1305775afec4SFredrik Holmqvist 
1306775afec4SFredrik Holmqvist 	mutex_init(*outHandle, "acpi mutex");
1307775afec4SFredrik Holmqvist 	return AE_OK;
1308775afec4SFredrik Holmqvist }
1309775afec4SFredrik Holmqvist 
1310775afec4SFredrik Holmqvist 
1311775afec4SFredrik Holmqvist void
AcpiOsDeleteMutex(ACPI_MUTEX handle)1312775afec4SFredrik Holmqvist AcpiOsDeleteMutex(ACPI_MUTEX handle)
1313775afec4SFredrik Holmqvist {
13144fced27dSFrançois Revol 	DEBUG_FUNCTION_F("mutex: %ld", (addr_t)handle);
1315775afec4SFredrik Holmqvist 	mutex_destroy(handle);
1316775afec4SFredrik Holmqvist 	free((void*)handle);
1317775afec4SFredrik Holmqvist }
1318775afec4SFredrik Holmqvist 
1319775afec4SFredrik Holmqvist 
1320775afec4SFredrik Holmqvist ACPI_STATUS
AcpiOsAcquireMutex(ACPI_MUTEX handle,UINT16 timeout)1321775afec4SFredrik Holmqvist AcpiOsAcquireMutex(ACPI_MUTEX handle, UINT16 timeout)
1322775afec4SFredrik Holmqvist {
1323775afec4SFredrik Holmqvist 	ACPI_STATUS result = AE_OK;
13244fced27dSFrançois Revol 	DEBUG_FUNCTION_VF("mutex: %p; timeout: %u", handle, timeout);
1325775afec4SFredrik Holmqvist 
1326a3a192c1SAugustin Cavalier 	if (timeout == ACPI_WAIT_FOREVER) {
1327a3a192c1SAugustin Cavalier 		result = (mutex_lock(handle) == B_OK) ? AE_OK : AE_BAD_PARAMETER;
1328a3a192c1SAugustin Cavalier 	} else if (timeout == ACPI_DO_NOT_WAIT) {
1329a3a192c1SAugustin Cavalier 		result = (mutex_trylock(handle) == B_OK) ? AE_OK : AE_TIME;
1330a3a192c1SAugustin Cavalier 	} else {
1331775afec4SFredrik Holmqvist 		switch (mutex_lock_with_timeout(handle, B_RELATIVE_TIMEOUT,
1332775afec4SFredrik Holmqvist 			(bigtime_t)timeout * 1000)) {
1333775afec4SFredrik Holmqvist 			case B_OK:
1334775afec4SFredrik Holmqvist 				result = AE_OK;
1335775afec4SFredrik Holmqvist 				break;
1336775afec4SFredrik Holmqvist 			case B_INTERRUPTED:
1337775afec4SFredrik Holmqvist 			case B_TIMED_OUT:
1338775afec4SFredrik Holmqvist 			case B_WOULD_BLOCK:
1339775afec4SFredrik Holmqvist 				result = AE_TIME;
1340775afec4SFredrik Holmqvist 				break;
1341775afec4SFredrik Holmqvist 			case B_BAD_VALUE:
1342775afec4SFredrik Holmqvist 			default:
1343775afec4SFredrik Holmqvist 				result = AE_BAD_PARAMETER;
1344775afec4SFredrik Holmqvist 				break;
1345775afec4SFredrik Holmqvist 		}
1346775afec4SFredrik Holmqvist 	}
13474fced27dSFrançois Revol 	DEBUG_FUNCTION_VF("mutex: %p; timeout: %u result: %lu",
1348775afec4SFredrik Holmqvist 		handle, timeout, (uint32)result);
1349775afec4SFredrik Holmqvist 	return result;
1350775afec4SFredrik Holmqvist }
1351775afec4SFredrik Holmqvist 
1352775afec4SFredrik Holmqvist 
1353775afec4SFredrik Holmqvist void
AcpiOsReleaseMutex(ACPI_MUTEX handle)1354775afec4SFredrik Holmqvist AcpiOsReleaseMutex(ACPI_MUTEX handle)
1355775afec4SFredrik Holmqvist {
1356775afec4SFredrik Holmqvist 	DEBUG_FUNCTION_F("mutex: %p", handle);
1357775afec4SFredrik Holmqvist 	mutex_unlock(handle);
1358775afec4SFredrik Holmqvist }
1359775afec4SFredrik Holmqvist 
1360775afec4SFredrik Holmqvist 
1361775afec4SFredrik Holmqvist /******************************************************************************
1362775afec4SFredrik Holmqvist  *
1363775afec4SFredrik Holmqvist  * FUNCTION:    AcpiOsWaitEventsComplete
1364775afec4SFredrik Holmqvist  *
1365775afec4SFredrik Holmqvist  * PARAMETERS:  None
1366775afec4SFredrik Holmqvist  *
1367775afec4SFredrik Holmqvist  * RETURN:      None
1368775afec4SFredrik Holmqvist  *
1369775afec4SFredrik Holmqvist  * DESCRIPTION: Wait for all asynchronous events to complete. This
1370775afec4SFredrik Holmqvist  *              implementation does nothing.
1371775afec4SFredrik Holmqvist  *
1372775afec4SFredrik Holmqvist  *****************************************************************************/
1373775afec4SFredrik Holmqvist void
AcpiOsWaitEventsComplete()1374775afec4SFredrik Holmqvist AcpiOsWaitEventsComplete()
1375775afec4SFredrik Holmqvist {
1376775afec4SFredrik Holmqvist     //TODO: FreeBSD See description.
1377775afec4SFredrik Holmqvist     return;
1378775afec4SFredrik Holmqvist }
1379ff2e2f81SFredrik Holmqvist 
1380ff2e2f81SFredrik Holmqvist 
1381ff2e2f81SFredrik Holmqvist /******************************************************************************
1382ff2e2f81SFredrik Holmqvist  *
1383ff2e2f81SFredrik Holmqvist  * FUNCTION:    AcpiOsEnterSleep
1384ff2e2f81SFredrik Holmqvist  *
1385ff2e2f81SFredrik Holmqvist  * PARAMETERS:  SleepState          - Which sleep state to enter
1386ff2e2f81SFredrik Holmqvist  *              RegaValue           - Register A value
1387ff2e2f81SFredrik Holmqvist  *              RegbValue           - Register B value
1388ff2e2f81SFredrik Holmqvist  *
1389ff2e2f81SFredrik Holmqvist  * RETURN:      Status
1390ff2e2f81SFredrik Holmqvist  *
1391ff2e2f81SFredrik Holmqvist  * DESCRIPTION: A hook before writing sleep registers to enter the sleep
1392ff2e2f81SFredrik Holmqvist  *              state. Return AE_CTRL_TERMINATE to skip further sleep register
1393ff2e2f81SFredrik Holmqvist  *              writes.
1394ff2e2f81SFredrik Holmqvist  *
1395ff2e2f81SFredrik Holmqvist  *****************************************************************************/
1396ff2e2f81SFredrik Holmqvist 
1397ff2e2f81SFredrik Holmqvist ACPI_STATUS
AcpiOsEnterSleep(UINT8 SleepState,UINT32 RegaValue,UINT32 RegbValue)1398ff2e2f81SFredrik Holmqvist AcpiOsEnterSleep (
1399ff2e2f81SFredrik Holmqvist 	UINT8                   SleepState,
1400ff2e2f81SFredrik Holmqvist 	UINT32                  RegaValue,
1401ff2e2f81SFredrik Holmqvist 	UINT32                  RegbValue)
1402ff2e2f81SFredrik Holmqvist {
1403ff2e2f81SFredrik Holmqvist 	return (AE_OK);
1404ff2e2f81SFredrik Holmqvist }
1405