xref: /haiku/src/add-ons/kernel/bus_managers/acpi/ACPICAHaiku.cpp (revision 6a2d53e7237764eab0c7b6d121772f26d636fb60)
1 /******************************************************************************
2  *
3  * Module Name: oshaiku - Haiku OSL interfaces
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights.  You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code.  No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision.  In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change.  Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee.  Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution.  In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government.  In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115 
116 
117 #include <stdio.h>
118 #include <sys/cdefs.h>
119 #include <time.h>
120 #include <unistd.h>
121 
122 #include <OS.h>
123 
124 #ifdef _KERNEL_MODE
125 #	include <KernelExport.h>
126 
127 #	include <dpc.h>
128 #	include <PCI.h>
129 
130 #	include <boot_item.h>
131 #	include <kernel.h>
132 #	include <vm/vm.h>
133 #endif
134 
135 __BEGIN_DECLS
136 #include "acpi.h"
137 #include "accommon.h"
138 #include "amlcode.h"
139 #include "acparser.h"
140 #include "acdebug.h"
141 __END_DECLS
142 
143 #include "arch_init.h"
144 
145 
146 ACPI_MODULE_NAME("Haiku ACPI Module")
147 
148 #define _COMPONENT ACPI_OS_SERVICES
149 
150 // verbosity level 0 = off, 1 = normal, 2 = all
151 #define DEBUG_OSHAIKU 0
152 
153 #if DEBUG_OSHAIKU <= 0
154 // No debugging, do nothing
155 #	define DEBUG_FUNCTION()
156 #	define DEBUG_FUNCTION_F(x, y...)
157 #	define DEBUG_FUNCTION_V()
158 #	define DEBUG_FUNCTION_VF(x, y...)
159 #else
160 #	define DEBUG_FUNCTION() \
161 		dprintf("acpi[%" B_PRId32 "]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__);
162 #	define DEBUG_FUNCTION_F(x, y...) \
163 		dprintf("acpi[%" B_PRId32 "]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y);
164 #	if DEBUG_OSHAIKU == 1
165 // No verbose debugging, do nothing
166 #		define DEBUG_FUNCTION_V()
167 #		define DEBUG_FUNCTION_VF(x, y...)
168 #	else
169 // Full debugging
170 #		define DEBUG_FUNCTION_V() \
171 			dprintf("acpi[%" B_PRId32 "]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__);
172 #		define DEBUG_FUNCTION_VF(x, y...) \
173 			dprintf("acpi[%" B_PRId32 "]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y);
174 #	endif
175 #endif
176 
177 
178 #ifdef _KERNEL_MODE
179 extern pci_module_info *gPCIManager;
180 extern dpc_module_info *gDPC;
181 extern void *gDPCHandle;
182 #endif
183 
184 extern FILE *AcpiGbl_DebugFile;
185 FILE *AcpiGbl_OutputFile;
186 
187 static ACPI_PHYSICAL_ADDRESS sACPIRoot = 0;
188 static void *sInterruptHandlerData[32];
189 
190 
191 /******************************************************************************
192  *
193  * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
194  *
195  * PARAMETERS:  None
196  *
197  * RETURN:      Status
198  *
199  * DESCRIPTION: Init and terminate.  Nothing to do.
200  *
201  *****************************************************************************/
202 ACPI_STATUS
203 AcpiOsInitialize()
204 {
205 #ifndef _KERNEL_MODE
206 	AcpiGbl_OutputFile = stdout;
207 #else
208 	AcpiGbl_OutputFile = NULL;
209 #endif
210 	DEBUG_FUNCTION();
211 	return AE_OK;
212 }
213 
214 
215 ACPI_STATUS
216 AcpiOsTerminate()
217 {
218 	DEBUG_FUNCTION();
219 	return AE_OK;
220 }
221 
222 
223 /******************************************************************************
224  *
225  * FUNCTION:    AcpiOsGetRootPointer
226  *
227  * PARAMETERS:  None
228  *
229  * RETURN:      RSDP physical address
230  *
231  * DESCRIPTION: Gets the root pointer (RSDP)
232  *
233  *****************************************************************************/
234 ACPI_PHYSICAL_ADDRESS
235 AcpiOsGetRootPointer()
236 {
237 #ifdef _KERNEL_MODE
238 	DEBUG_FUNCTION();
239 	if (sACPIRoot == 0) {
240 		phys_addr_t* acpiRootPointer = (phys_addr_t*)get_boot_item("ACPI_ROOT_POINTER", NULL);
241 		if (acpiRootPointer != NULL)
242 			sACPIRoot = *acpiRootPointer;
243 
244 		if (sACPIRoot == 0)
245 			sACPIRoot = arch_init_find_root_pointer();
246 	}
247 	return sACPIRoot;
248 #else
249 	return AeLocalGetRootPointer();
250 #endif
251 }
252 
253 
254 /******************************************************************************
255  *
256  * FUNCTION:    AcpiOsPredefinedOverride
257  *
258  * PARAMETERS:  initVal     - Initial value of the predefined object
259  *              newVal      - The new value for the object
260  *
261  * RETURN:      Status, pointer to value.  Null pointer returned if not
262  *              overriding.
263  *
264  * DESCRIPTION: Allow the OS to override predefined names
265  *
266  *****************************************************************************/
267 ACPI_STATUS
268 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *initVal,
269 		ACPI_STRING *newVal)
270 {
271 	DEBUG_FUNCTION();
272 	if (!initVal || !newVal)
273 		return AE_BAD_PARAMETER;
274 
275 	*newVal = NULL;
276 	return AE_OK;
277 }
278 
279 
280 /******************************************************************************
281  *
282  * FUNCTION:    AcpiOsTableOverride
283  *
284  * PARAMETERS:  existingTable   - Header of current table (probably firmware)
285  *              newTable        - Where an entire new table is returned.
286  *
287  * RETURN:      Status, pointer to new table.  Null pointer returned if no
288  *              table is available to override
289  *
290  * DESCRIPTION: Return a different version of a table if one is available
291  *
292  *****************************************************************************/
293 ACPI_STATUS
294 AcpiOsTableOverride(ACPI_TABLE_HEADER *existingTable,
295 		ACPI_TABLE_HEADER **newTable)
296 {
297 	DEBUG_FUNCTION();
298 	if (!existingTable || !newTable)
299 		return AE_BAD_PARAMETER;
300 
301 	*newTable = NULL;
302 
303 #ifdef ACPI_EXEC_APP
304 	AeTableOverride(existingTable, newTable);
305 	return AE_OK;
306 #else
307 	return AE_NO_ACPI_TABLES;
308 #endif
309 }
310 
311 
312 /******************************************************************************
313  *
314  * FUNCTION:    AcpiOsPhysicalTableOverride
315  *
316  * PARAMETERS:  existingTable       - Header of current table (probably firmware)
317  *              newAddress          - Where new table address is returned
318  *                                    (Physical address)
319  *              newTableLength      - Where new table length is returned
320  *
321  * RETURN:      Status, address/length of new table. Null pointer returned
322  *              if no table is available to override.
323  *
324  * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
325  *
326  *****************************************************************************/
327 
328 ACPI_STATUS
329 AcpiOsPhysicalTableOverride(ACPI_TABLE_HEADER *existingTable,
330 	ACPI_PHYSICAL_ADDRESS *newAddress, UINT32 *newTableLength)
331 {
332 	DEBUG_FUNCTION();
333     return (AE_SUPPORT);
334 }
335 
336 
337 /******************************************************************************
338  *
339  * FUNCTION:    AcpiOsRedirectOutput
340  *
341  * PARAMETERS:  destination         - An open file handle/pointer
342  *
343  * RETURN:      None
344  *
345  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
346  *
347  *****************************************************************************/
348 void
349 AcpiOsRedirectOutput(void *destination)
350 {
351 	DEBUG_FUNCTION();
352 	AcpiGbl_OutputFile = (FILE*)destination;
353 }
354 
355 
356 /******************************************************************************
357  *
358  * FUNCTION:    AcpiOsPrintf
359  *
360  * PARAMETERS:  fmt, ...            Standard printf format
361  *
362  * RETURN:      None
363  *
364  * DESCRIPTION: Formatted output
365  *
366  *****************************************************************************/
367 void ACPI_INTERNAL_VAR_XFACE
368 AcpiOsPrintf(const char *fmt, ...)
369 {
370 	va_list args;
371 
372 	DEBUG_FUNCTION();
373 	va_start(args, fmt);
374 	AcpiOsVprintf(fmt, args);
375 	va_end(args);
376 }
377 
378 
379 /******************************************************************************
380  *
381  * FUNCTION:    AcpiOsVprintf
382  *
383  * PARAMETERS:  fmt                 Standard printf format
384  *              args                Argument list
385  *
386  * RETURN:      None
387  *
388  * DESCRIPTION: Formatted output with argument list pointer
389  *
390  *****************************************************************************/
391 void
392 AcpiOsVprintf(const char *fmt, va_list args)
393 {
394 #ifndef _KERNEL_MODE
395 	UINT8 flags;
396 
397 	flags = AcpiGbl_DbOutputFlags;
398 	if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
399 		// Output is directable to either a file (if open) or the console
400 		if (AcpiGbl_DebugFile) {
401 			// Output file is open, send the output there
402 			vfprintf(AcpiGbl_DebugFile, fmt, args);
403 		} else {
404 			// No redirection, send output to console (once only!)
405 			flags |= ACPI_DB_CONSOLE_OUTPUT;
406 		}
407 	}
408 
409 	if (flags & ACPI_DB_CONSOLE_OUTPUT) {
410 		vfprintf(AcpiGbl_OutputFile, fmt, args);
411     }
412 #else
413 	// Buffer the output until we have a complete line to send to syslog, this avoids added
414 	// "KERN:" entries in the middle of the line, and mixing up of the ACPI output with other
415 	// messages from other CPUs
416 	static char outputBuffer[1024];
417 
418 	// Append the new text to the buffer
419 	size_t len = strlen(outputBuffer);
420 	size_t printed = vsnprintf(outputBuffer + len, 1024 - len, fmt, args);
421 	if (printed >= 1024 - len) {
422 		// There was no space to fit the printed string in the outputBuffer. Remove what we added
423 		// there, fush the buffer, and print the long string directly
424 		outputBuffer[len] = '\0';
425 		dprintf("%s\n", outputBuffer);
426 		outputBuffer[0] = '\0';
427 		dvprintf(fmt, args);
428 		return;
429 	}
430 
431 	// See if we have a complete line
432 	char* eol = strchr(outputBuffer + len, '\n');
433 	while (eol != nullptr) {
434 		// Print the completed line, then remove it from the buffer
435 		*eol = 0;
436 		dprintf("%s\n", outputBuffer);
437 		memmove(outputBuffer, eol + 1, strlen(eol + 1) + 1);
438 		// See if there is another line to print still in the buffer (in case ACPICA would call
439 		// this function with a single string containing multiple newlines)
440 		eol = strchr(outputBuffer, '\n');
441 	}
442 #endif
443 }
444 
445 
446 /******************************************************************************
447  *
448  * FUNCTION:    AcpiOsGetLine
449  *
450  * PARAMETERS:  fmt                 Standard printf format
451  *              args                Argument list
452  *
453  * RETURN:      Actual bytes read
454  *
455  * DESCRIPTION: Formatted input with argument list pointer
456  *
457  *****************************************************************************/
458 UINT32
459 AcpiOsGetLine(char *buffer)
460 {
461 	uint32 i = 0;
462 
463 #ifndef _KERNEL_MODE
464 	uint8 temp;
465 
466 	for (i = 0; ; i++) {
467 		scanf("%1c", &temp);
468 		if (!temp || temp == '\n')
469 			break;
470 
471 		buffer[i] = temp;
472 	}
473 #endif
474 
475 	buffer[i] = 0;
476 	DEBUG_FUNCTION_F("buffer: \"%s\"; result: %" B_PRIu32, buffer, i);
477 	return i;
478 }
479 
480 
481 /******************************************************************************
482  *
483  * FUNCTION:    AcpiOsMapMemory
484  *
485  * PARAMETERS:  where               Physical address of memory to be mapped
486  *              length              How much memory to map
487  *
488  * RETURN:      Pointer to mapped memory.  Null on error.
489  *
490  * DESCRIPTION: Map physical memory into caller's address space
491  *
492  *****************************************************************************/
493 void *
494 AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS where, ACPI_SIZE length)
495 {
496 #ifdef _KERNEL_MODE
497 	// map_physical_memory() defaults to uncached memory if no type is specified.
498 	// But ACPICA handles flushing caches itself, so we don't need it uncached,
499 	// and on some architectures (e.g. ARM) uncached memory does not support
500 	// unaligned accesses. Hence we specify "writeback" to avoid the default.
501 	void *there;
502 	area_id area = map_physical_memory("acpi_physical_mem_area", (phys_addr_t)where, length,
503 		B_ANY_KERNEL_ADDRESS | B_MTR_WB, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, &there);
504 
505 	DEBUG_FUNCTION_F("addr: 0x%08lx; length: %lu; mapped: %p; area: %" B_PRId32,
506 		(addr_t)where, (size_t)length, there, area);
507 	if (area < 0) {
508 		dprintf("ACPI: cannot map memory at 0x%" B_PRIu64 ", length %"
509 			B_PRIu64 "\n", (uint64)where, (uint64)length);
510 		return NULL;
511 	}
512 	return there;
513 #else
514 	return NULL;
515 #endif
516 
517 	// return ACPI_TO_POINTER((ACPI_SIZE) where);
518 }
519 
520 
521 /******************************************************************************
522  *
523  * FUNCTION:    AcpiOsUnmapMemory
524  *
525  * PARAMETERS:  where               Logical address of memory to be unmapped
526  *              length              How much memory to unmap
527  *
528  * RETURN:      None.
529  *
530  * DESCRIPTION: Delete a previously created mapping.  Where and Length must
531  *              correspond to a previous mapping exactly.
532  *
533  *****************************************************************************/
534 void
535 AcpiOsUnmapMemory(void *where, ACPI_SIZE length)
536 {
537 	DEBUG_FUNCTION_F("mapped: %p; length: %lu", where, (size_t)length);
538 	delete_area(area_for(where));
539 }
540 
541 
542 /******************************************************************************
543  *
544  * FUNCTION:    AcpiOsAllocate
545  *
546  * PARAMETERS:  size                Amount to allocate, in bytes
547  *
548  * RETURN:      Pointer to the new allocation.  Null on error.
549  *
550  * DESCRIPTION: Allocate memory.  Algorithm is dependent on the OS.
551  *
552  *****************************************************************************/
553 void *
554 AcpiOsAllocate(ACPI_SIZE size)
555 {
556 	void *mem = (void *) malloc(size);
557 	DEBUG_FUNCTION_VF("result: %p", mem);
558 	return mem;
559 }
560 
561 
562 /******************************************************************************
563  *
564  * FUNCTION:    AcpiOsFree
565  *
566  * PARAMETERS:  mem                 Pointer to previously allocated memory
567  *
568  * RETURN:      None.
569  *
570  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
571  *
572  *****************************************************************************/
573 void
574 AcpiOsFree(void *mem)
575 {
576 	DEBUG_FUNCTION_VF("mem: %p", mem);
577 	free(mem);
578 }
579 
580 
581 /******************************************************************************
582  *
583  * FUNCTION:    AcpiOsCreateSemaphore
584  *
585  * PARAMETERS:  initialUnits        - Units to be assigned to the new semaphore
586  *              outHandle           - Where a handle will be returned
587  *
588  * RETURN:      Status
589  *
590  * DESCRIPTION: Create an OS semaphore
591  *
592  *****************************************************************************/
593 ACPI_STATUS
594 AcpiOsCreateSemaphore(UINT32 maxUnits, UINT32 initialUnits,
595 		ACPI_SEMAPHORE *outHandle)
596 {
597 	if (!outHandle)
598     	return AE_BAD_PARAMETER;
599 
600 	*outHandle = create_sem(initialUnits, "acpi_sem");
601 	DEBUG_FUNCTION_F("max: %" B_PRIu32 "; count: %" B_PRIu32 "; result: %" PRId32,
602 		(uint32)maxUnits, (uint32)initialUnits, *outHandle);
603 
604 	if (*outHandle >= B_OK)
605 		return AE_OK;
606 
607 	return *outHandle == B_BAD_VALUE ? AE_BAD_PARAMETER : AE_NO_MEMORY;
608 }
609 
610 
611 /******************************************************************************
612  *
613  * FUNCTION:    AcpiOsDeleteSemaphore
614  *
615  * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
616  *
617  * RETURN:      Status
618  *
619  * DESCRIPTION: Delete an OS semaphore
620  *
621  *****************************************************************************/
622 ACPI_STATUS
623 AcpiOsDeleteSemaphore(ACPI_SEMAPHORE handle)
624 {
625 	DEBUG_FUNCTION_F("sem: %" B_PRId32, handle);
626 	return delete_sem(handle) == B_OK ? AE_OK : AE_BAD_PARAMETER;
627 }
628 
629 
630 /******************************************************************************
631  *
632  * FUNCTION:    AcpiOsWaitSemaphore
633  *
634  * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
635  *              units               - How many units to wait for
636  *              timeout             - How long to wait
637  *
638  * RETURN:      Status
639  *
640  * DESCRIPTION: Wait for units
641  *
642  *****************************************************************************/
643 ACPI_STATUS
644 AcpiOsWaitSemaphore(ACPI_SEMAPHORE handle, UINT32 units, UINT16 timeout)
645 {
646 	ACPI_STATUS result = AE_OK;
647 	DEBUG_FUNCTION_VF("sem: %ld; count: %lu; timeout: %u",
648 		handle, (uint32)units, timeout);
649 
650 	if (timeout == ACPI_WAIT_FOREVER) {
651 		result = acquire_sem_etc(handle, units, 0, 0)
652 			== B_OK ? AE_OK : AE_BAD_PARAMETER;
653 	} else {
654 		switch (acquire_sem_etc(handle, units, B_RELATIVE_TIMEOUT,
655 			(bigtime_t)timeout * 1000)) {
656 			case B_OK:
657 				result = AE_OK;
658 				break;
659 			case B_INTERRUPTED:
660 			case B_TIMED_OUT:
661 			case B_WOULD_BLOCK:
662 				result = AE_TIME;
663 				break;
664 			case B_BAD_VALUE:
665 			default:
666 				result = AE_BAD_PARAMETER;
667 				break;
668 		}
669 	}
670 	DEBUG_FUNCTION_VF("sem: %ld; count: %lu; timeout: %u result: %lu",
671 		handle, (uint32)units, timeout, (uint32)result);
672 	return result;
673 }
674 
675 
676 /******************************************************************************
677  *
678  * FUNCTION:    AcpiOsSignalSemaphore
679  *
680  * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
681  *              units               - Number of units to send
682  *
683  * RETURN:      Status
684  *
685  * DESCRIPTION: Send units
686  *
687  *****************************************************************************/
688 ACPI_STATUS
689 AcpiOsSignalSemaphore(ACPI_SEMAPHORE handle, UINT32 units)
690 {
691 	status_t result;
692 	DEBUG_FUNCTION_VF("sem: %ld; count: %lu", handle, (uint32)units);
693 	// We can be called from interrupt handler, so don't reschedule
694 	result = release_sem_etc(handle, units, B_DO_NOT_RESCHEDULE);
695 	return result == B_OK ? AE_OK : AE_BAD_PARAMETER;
696 }
697 
698 
699 /******************************************************************************
700  *
701  * FUNCTION:    Spinlock interfaces
702  *
703  * DESCRIPTION: Map these interfaces to semaphore interfaces
704  *
705  *****************************************************************************/
706 ACPI_STATUS
707 AcpiOsCreateLock(ACPI_SPINLOCK *outHandle)
708 {
709 	*outHandle = (ACPI_SPINLOCK) malloc(sizeof(spinlock));
710 	DEBUG_FUNCTION_F("result: %p", *outHandle);
711 	if (*outHandle == NULL)
712 		return AE_NO_MEMORY;
713 
714 	B_INITIALIZE_SPINLOCK(*outHandle);
715 	return AE_OK;
716 }
717 
718 
719 void
720 AcpiOsDeleteLock(ACPI_SPINLOCK handle)
721 {
722 	DEBUG_FUNCTION();
723 	free((void*)handle);
724 }
725 
726 
727 ACPI_CPU_FLAGS
728 AcpiOsAcquireLock(ACPI_SPINLOCK handle)
729 {
730 	cpu_status cpu;
731 	DEBUG_FUNCTION_F("spinlock: %p", handle);
732 	cpu = disable_interrupts();
733 	acquire_spinlock(handle);
734 	return cpu;
735 }
736 
737 
738 void
739 AcpiOsReleaseLock(ACPI_SPINLOCK handle, ACPI_CPU_FLAGS flags)
740 {
741 	release_spinlock(handle);
742 	restore_interrupts(flags);
743 	DEBUG_FUNCTION_F("spinlock: %p", handle);
744 }
745 
746 
747 /******************************************************************************
748  *
749  * FUNCTION:    AcpiOsInstallInterruptHandler
750  *
751  * PARAMETERS:  interruptNumber     Level handler should respond to.
752  *              Isr                 Address of the ACPI interrupt handler
753  *              ExceptPtr           Where status is returned
754  *
755  * RETURN:      Handle to the newly installed handler.
756  *
757  * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
758  *              OS-independent handler.
759  *
760  *****************************************************************************/
761 UINT32
762 AcpiOsInstallInterruptHandler(UINT32 interruptNumber,
763 		ACPI_OSD_HANDLER serviceRoutine, void *context)
764 {
765 	status_t result;
766 	DEBUG_FUNCTION_F("vector: %" B_PRIu32 "; handler: %p context %p",
767 		(uint32)interruptNumber, serviceRoutine, context);
768 
769 #ifdef _KERNEL_MODE
770 	// It so happens that the Haiku and ACPI-CA interrupt handler routines
771 	// return the same values with the same meanings
772 	sInterruptHandlerData[interruptNumber] = context;
773 	result = install_io_interrupt_handler(interruptNumber,
774 		(interrupt_handler)serviceRoutine, context, 0);
775 
776 	DEBUG_FUNCTION_F("vector: %" B_PRIu32 "; handler: %p context %p returned %" B_PRId32,
777 		(uint32)interruptNumber, serviceRoutine, context, (uint32)result);
778 
779 	return result == B_OK ? AE_OK : AE_BAD_PARAMETER;
780 #else
781 	return AE_BAD_PARAMETER;
782 #endif
783 }
784 
785 
786 /******************************************************************************
787  *
788  * FUNCTION:    AcpiOsRemoveInterruptHandler
789  *
790  * PARAMETERS:  Handle              Returned when handler was installed
791  *
792  * RETURN:      Status
793  *
794  * DESCRIPTION: Uninstalls an interrupt handler.
795  *
796  *****************************************************************************/
797 ACPI_STATUS
798 AcpiOsRemoveInterruptHandler(UINT32 interruptNumber,
799 		ACPI_OSD_HANDLER serviceRoutine)
800 {
801 	DEBUG_FUNCTION_F("vector: %" B_PRIu32 "; handler: %p", (uint32)interruptNumber,
802 		serviceRoutine);
803 #ifdef _KERNEL_MODE
804 	return remove_io_interrupt_handler(interruptNumber,
805 		(interrupt_handler)serviceRoutine,
806 		sInterruptHandlerData[interruptNumber]) == B_OK ? AE_OK : AE_ERROR;
807 #else
808 	return AE_ERROR;
809 #endif
810 }
811 
812 
813 /******************************************************************************
814  *
815  * FUNCTION:    AcpiOsExecute
816  *
817  * PARAMETERS:  type            - Type of execution
818  *              function        - Address of the function to execute
819  *              context         - Passed as a parameter to the function
820  *
821  * RETURN:      Status.
822  *
823  * DESCRIPTION: Execute a new thread
824  *
825  *****************************************************************************/
826 ACPI_STATUS
827 AcpiOsExecute(ACPI_EXECUTE_TYPE type, ACPI_OSD_EXEC_CALLBACK  function,
828 		void *context)
829 {
830 	DEBUG_FUNCTION();
831 /* TODO: Prioritize urgent?
832 	switch (type) {
833 		case OSL_GLOBAL_LOCK_HANDLER:
834 		case OSL_NOTIFY_HANDLER:
835 		case OSL_GPE_HANDLER:
836 		case OSL_DEBUGGER_THREAD:
837 		case OSL_EC_POLL_HANDLER:
838 		case OSL_EC_BURST_HANDLER:
839 			break;
840 	}
841 */
842 
843 	if (gDPC->queue_dpc(gDPCHandle, function, context) != B_OK) {
844 		DEBUG_FUNCTION_F("Serious failure in AcpiOsExecute! function: %p",
845 			function);
846 		return AE_BAD_PARAMETER;
847 	}
848 	return AE_OK;
849 }
850 
851 
852 /******************************************************************************
853  *
854  * FUNCTION:    AcpiOsStall
855  *
856  * PARAMETERS:  microseconds        To sleep
857  *
858  * RETURN:      Blocks until sleep is completed.
859  *
860  * DESCRIPTION: Sleep at microsecond granularity
861  *
862  *****************************************************************************/
863 void
864 AcpiOsStall(UINT32 microseconds)
865 {
866 	DEBUG_FUNCTION_F("microseconds: %" B_PRIu32, (uint32)microseconds);
867 	if (microseconds)
868 		spin(microseconds);
869 }
870 
871 
872 /******************************************************************************
873  *
874  * FUNCTION:    AcpiOsSleep
875  *
876  * PARAMETERS:  milliseconds        To sleep
877  *
878  * RETURN:      Blocks until sleep is completed.
879  *
880  * DESCRIPTION: Sleep at millisecond granularity
881  *
882  *****************************************************************************/
883 void
884 AcpiOsSleep(ACPI_INTEGER milliseconds)
885 {
886 	DEBUG_FUNCTION_F("milliseconds: %" B_PRIu32, (uint32)milliseconds);
887 	if (gKernelStartup)
888 		spin(milliseconds * 1000);
889 	else
890 		snooze(milliseconds * 1000);
891 }
892 
893 
894 /******************************************************************************
895  *
896  * FUNCTION:    AcpiOsGetTimer
897  *
898  * PARAMETERS:  None
899  *
900  * RETURN:      Current time in 100 nanosecond units
901  *
902  * DESCRIPTION: Get the current system time
903  *
904  *****************************************************************************/
905 UINT64
906 AcpiOsGetTimer()
907 {
908 	DEBUG_FUNCTION();
909 	return system_time() * 10;
910 }
911 
912 
913 /******************************************************************************
914  *
915  * FUNCTION:    AcpiOsReadPciConfiguration
916  *
917  * PARAMETERS:  pciId               Seg/Bus/Dev
918  *              reg                 Device Register
919  *              value               Buffer where value is placed
920  *              width               Number of bits
921  *
922  * RETURN:      Status
923  *
924  * DESCRIPTION: Read data from PCI configuration space
925  *
926  *****************************************************************************/
927 ACPI_STATUS
928 AcpiOsReadPciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg, UINT64 *value,
929 		UINT32 width)
930 {
931 #ifdef _KERNEL_MODE
932 	DEBUG_FUNCTION();
933 
934 	switch (width) {
935 		case 8:
936 		case 16:
937 		case 32:
938 			*value = gPCIManager->read_pci_config(
939 				pciId->Bus, pciId->Device, pciId->Function, reg, width / 8);
940 			break;
941 		default:
942 			return AE_ERROR;
943 	}
944 	return AE_OK;
945 #else
946 	return AE_ERROR;
947 #endif
948 }
949 
950 
951 /******************************************************************************
952  *
953  * FUNCTION:    AcpiOsWritePciConfiguration
954  *
955  * PARAMETERS:  pciId               Seg/Bus/Dev
956  *              reg                 Device Register
957  *              value               Value to be written
958  *              width               Number of bits
959  *
960  * RETURN:      Status.
961  *
962  * DESCRIPTION: Write data to PCI configuration space
963  *
964  *****************************************************************************/
965 ACPI_STATUS
966 AcpiOsWritePciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg,
967 		ACPI_INTEGER value, UINT32 width)
968 {
969 #ifdef _KERNEL_MODE
970 	DEBUG_FUNCTION();
971 	gPCIManager->write_pci_config(
972 		pciId->Bus, pciId->Device, pciId->Function, reg, width / 8, value);
973 	return AE_OK;
974 #else
975 	return AE_ERROR;
976 #endif
977 }
978 
979 
980 /******************************************************************************
981  *
982  * FUNCTION:    AcpiOsReadPort
983  *
984  * PARAMETERS:  address             Address of I/O port/register to read
985  *              Value               Where value is placed
986  *              width               Number of bits
987  *
988  * RETURN:      Value read from port
989  *
990  * DESCRIPTION: Read data from an I/O port or register
991  *
992  *****************************************************************************/
993 ACPI_STATUS
994 AcpiOsReadPort(ACPI_IO_ADDRESS address, UINT32 *value, UINT32 width)
995 {
996 #ifdef _KERNEL_MODE
997 	DEBUG_FUNCTION_F("addr: 0x%08lx; width: %" B_PRIu32, (addr_t)address, (uint32)width);
998 	switch (width) {
999 		case 8:
1000 			*value = gPCIManager->read_io_8(address);
1001 			break;
1002 
1003 		case 16:
1004 			*value = gPCIManager->read_io_16(address);
1005 			break;
1006 
1007 		case 32:
1008 			*value = gPCIManager->read_io_32(address);
1009 			break;
1010 
1011 		default:
1012 			return AE_ERROR;
1013 	}
1014 
1015 	return AE_OK;
1016 #else
1017 	return AE_ERROR;
1018 #endif
1019 }
1020 
1021 
1022 /******************************************************************************
1023  *
1024  * FUNCTION:    AcpiOsWritePort
1025  *
1026  * PARAMETERS:  address             Address of I/O port/register to write
1027  *              value               Value to write
1028  *              width               Number of bits
1029  *
1030  * RETURN:      None
1031  *
1032  * DESCRIPTION: Write data to an I/O port or register
1033  *
1034  *****************************************************************************/
1035 ACPI_STATUS
1036 AcpiOsWritePort(ACPI_IO_ADDRESS address, UINT32 value, UINT32 width)
1037 {
1038 #ifdef _KERNEL_MODE
1039 	DEBUG_FUNCTION_F("addr: 0x%08lx; value: %" B_PRIu32 "; width: %" B_PRIu32,
1040 		(addr_t)address, (uint32)value, (uint32)width);
1041 	switch (width) {
1042 		case 8:
1043 			gPCIManager->write_io_8(address, value);
1044 			break;
1045 
1046 		case 16:
1047 			gPCIManager->write_io_16(address,value);
1048 			break;
1049 
1050 		case 32:
1051 			gPCIManager->write_io_32(address,value);
1052 			break;
1053 
1054 		default:
1055 			return AE_ERROR;
1056 	}
1057 
1058 	return AE_OK;
1059 #else
1060 	return AE_ERROR;
1061 #endif
1062 }
1063 
1064 
1065 /******************************************************************************
1066  *
1067  * FUNCTION:    AcpiOsReadMemory
1068  *
1069  * PARAMETERS:  address             Physical Memory Address to read
1070  *              value               Where value is placed
1071  *              width               Number of bits
1072  *
1073  * RETURN:      Value read from physical memory address
1074  *
1075  * DESCRIPTION: Read data from a physical memory address
1076  *
1077  *****************************************************************************/
1078 ACPI_STATUS
1079 AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS address, UINT64 *value, UINT32 width)
1080 {
1081 #ifdef _KERNEL_MODE
1082 	if (vm_memcpy_from_physical(value, (phys_addr_t)address, width / 8, false)
1083 		!= B_OK) {
1084 		return AE_ERROR;
1085 	}
1086 	return AE_OK;
1087 #else
1088 	return AE_ERROR;
1089 #endif
1090 }
1091 
1092 
1093 /******************************************************************************
1094  *
1095  * FUNCTION:    AcpiOsWriteMemory
1096  *
1097  * PARAMETERS:  address             Physical Memory Address to write
1098  *              value               Value to write
1099  *              width               Number of bits
1100  *
1101  * RETURN:      None
1102  *
1103  * DESCRIPTION: Write data to a physical memory address
1104  *
1105  *****************************************************************************/
1106 ACPI_STATUS
1107 AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS address, UINT64 value, UINT32 width)
1108 {
1109 #ifdef _KERNEL_MODE
1110 	if (vm_memcpy_to_physical((phys_addr_t)address, &value, width / 8, false)
1111 			!= B_OK) {
1112 		return AE_ERROR;
1113 	}
1114 	return AE_OK;
1115 #else
1116 	return AE_ERROR;
1117 #endif
1118 }
1119 
1120 
1121 /******************************************************************************
1122  *
1123  * FUNCTION:    AcpiOsReadable
1124  *
1125  * PARAMETERS:  pointer             - Area to be verified
1126  *              length              - Size of area
1127  *
1128  * RETURN:      TRUE if readable for entire length
1129  *
1130  * DESCRIPTION: Verify that a pointer is valid for reading
1131  *
1132  *****************************************************************************/
1133 BOOLEAN
1134 AcpiOsReadable(void *pointer, ACPI_SIZE length)
1135 {
1136 #ifdef _KERNEL_MODE
1137 	return true;
1138 #else
1139 	area_id id;
1140 	area_info info;
1141 
1142 	DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length);
1143 
1144 	id = area_for(pointer);
1145 	if (id == B_ERROR) return false;
1146 	if (get_area_info(id, &info) != B_OK) return false;
1147 	return (info.protection & B_READ_AREA) != 0 &&
1148 			((char *)pointer) + length <= info.address + info.ram_size;
1149 #endif
1150 }
1151 
1152 
1153 /******************************************************************************
1154  *
1155  * FUNCTION:    AcpiOsWritable
1156  *
1157  * PARAMETERS:  pointer             - Area to be verified
1158  *              length              - Size of area
1159  *
1160  * RETURN:      TRUE if writable for entire length
1161  *
1162  * DESCRIPTION: Verify that a pointer is valid for writing
1163  *
1164  *****************************************************************************/
1165 BOOLEAN
1166 AcpiOsWritable(void *pointer, ACPI_SIZE length)
1167 {
1168 #ifdef _KERNEL_MODE
1169 	return true;
1170 #else
1171 	area_id id;
1172 	area_info info;
1173 
1174 	DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length);
1175 
1176 	id = area_for(pointer);
1177 	if (id == B_ERROR) return false;
1178 	if (get_area_info(id, &info) != B_OK) return false;
1179 	return (info.protection & B_READ_AREA) != 0 &&
1180 			(info.protection & B_WRITE_AREA) != 0 &&
1181 			((char *)pointer) + length <= info.address + info.ram_size;
1182 #endif
1183 }
1184 
1185 
1186 /******************************************************************************
1187  *
1188  * FUNCTION:    AcpiOsGetThreadId
1189  *
1190  * PARAMETERS:  None
1191  *
1192  * RETURN:      Id of the running thread
1193  *
1194  * DESCRIPTION: Get the Id of the current (running) thread
1195  *
1196  * NOTE:        The environment header should contain this line:
1197  *                  #define ACPI_THREAD_ID pthread_t
1198  *
1199  *****************************************************************************/
1200 ACPI_THREAD_ID
1201 AcpiOsGetThreadId()
1202 {
1203 	thread_id thread = find_thread(NULL);
1204 	// TODO: We arn't allowed threads with id 0, handle this case.
1205 	// ACPI treats a 0 return as an error,
1206 	// but we are thread 0 in early boot
1207 	return thread;
1208 }
1209 
1210 
1211 /******************************************************************************
1212  *
1213  * FUNCTION:    AcpiOsSignal
1214  *
1215  * PARAMETERS:  function            ACPI CA signal function code
1216  *              info                Pointer to function-dependent structure
1217  *
1218  * RETURN:      Status
1219  *
1220  * DESCRIPTION: Miscellaneous functions. Example implementation only.
1221  *
1222  *****************************************************************************/
1223 ACPI_STATUS
1224 AcpiOsSignal(UINT32 function, void *info)
1225 {
1226 	DEBUG_FUNCTION();
1227 
1228 	switch (function) {
1229 		case ACPI_SIGNAL_FATAL:
1230 #ifdef _KERNEL_MODE
1231 			panic("%s", info == NULL ? "AcpiOsSignal: fatal" : (const char*)info);
1232 			break;
1233 #endif
1234 		case ACPI_SIGNAL_BREAKPOINT:
1235 			if (info != NULL)
1236 				AcpiOsPrintf("AcpiOsBreakpoint: %s ****\n", (const char*)info);
1237 			else
1238 				AcpiOsPrintf("At AcpiOsBreakpoint ****\n");
1239 			break;
1240 	}
1241 
1242 	return AE_OK;
1243 }
1244 
1245 
1246 /*
1247  * Adapted from FreeBSD since the documentation of its intended impl
1248  * is lacking.
1249  *  Section 5.2.10.1: global lock acquire/release functions */
1250 
1251 /*
1252  * Adapted from FreeBSD since the documentation of its intended impl
1253  * is lacking.
1254  * Acquire the global lock.  If busy, set the pending bit.  The caller
1255  * will wait for notification from the BIOS that the lock is available
1256  * and then attempt to acquire it again.
1257  */
1258 int
1259 AcpiOsAcquireGlobalLock(volatile uint32_t *lock)
1260 {
1261 	uint32_t newValue;
1262 	uint32_t oldValue;
1263 
1264 	do {
1265 		oldValue = *lock;
1266 		newValue = ((oldValue & ~ACPI_GLOCK_PENDING) | ACPI_GLOCK_OWNED);
1267 		if ((oldValue & ACPI_GLOCK_OWNED) != 0)
1268 			newValue |= ACPI_GLOCK_PENDING;
1269 	} while (atomic_test_and_set((int32*)lock, newValue, oldValue) != (int32)oldValue);
1270 
1271 	return (newValue & ACPI_GLOCK_PENDING) == 0;
1272 }
1273 
1274 
1275 /*
1276  * Adapted from FreeBSD since the documentation of its intended impl
1277  * is lacking.
1278  * Release the global lock, returning whether there is a waiter pending.
1279  * If the BIOS set the pending bit, OSPM must notify the BIOS when it
1280  * releases the lock.
1281  */
1282 int
1283 AcpiOsReleaseGlobalLock(volatile uint32_t *lock)
1284 {
1285 	uint32 newValue;
1286 	uint32 oldValue;
1287 
1288 	do {
1289 		oldValue = *lock;
1290 		newValue = oldValue & ~(ACPI_GLOCK_PENDING | ACPI_GLOCK_OWNED);
1291 	} while (atomic_test_and_set((int32*)lock, newValue, oldValue) != (int32)oldValue);
1292 
1293 	return (oldValue & ACPI_GLOCK_PENDING) != 0;
1294 }
1295 
1296 
1297 ACPI_STATUS
1298 AcpiOsCreateMutex(ACPI_MUTEX* outHandle)
1299 {
1300 	*outHandle = (ACPI_MUTEX) malloc(sizeof(mutex));
1301 	DEBUG_FUNCTION_F("result: %p", *outHandle);
1302 	if (*outHandle == NULL)
1303 		return AE_NO_MEMORY;
1304 
1305 	mutex_init(*outHandle, "acpi mutex");
1306 	return AE_OK;
1307 }
1308 
1309 
1310 void
1311 AcpiOsDeleteMutex(ACPI_MUTEX handle)
1312 {
1313 	DEBUG_FUNCTION_F("mutex: %ld", (addr_t)handle);
1314 	mutex_destroy(handle);
1315 	free((void*)handle);
1316 }
1317 
1318 
1319 ACPI_STATUS
1320 AcpiOsAcquireMutex(ACPI_MUTEX handle, UINT16 timeout)
1321 {
1322 	ACPI_STATUS result = AE_OK;
1323 	DEBUG_FUNCTION_VF("mutex: %p; timeout: %u", handle, timeout);
1324 
1325 	if (timeout == ACPI_WAIT_FOREVER) {
1326 		result = (mutex_lock(handle) == B_OK) ? AE_OK : AE_BAD_PARAMETER;
1327 	} else if (timeout == ACPI_DO_NOT_WAIT) {
1328 		result = (mutex_trylock(handle) == B_OK) ? AE_OK : AE_TIME;
1329 	} else {
1330 		switch (mutex_lock_with_timeout(handle, B_RELATIVE_TIMEOUT,
1331 			(bigtime_t)timeout * 1000)) {
1332 			case B_OK:
1333 				result = AE_OK;
1334 				break;
1335 			case B_INTERRUPTED:
1336 			case B_TIMED_OUT:
1337 			case B_WOULD_BLOCK:
1338 				result = AE_TIME;
1339 				break;
1340 			case B_BAD_VALUE:
1341 			default:
1342 				result = AE_BAD_PARAMETER;
1343 				break;
1344 		}
1345 	}
1346 	DEBUG_FUNCTION_VF("mutex: %p; timeout: %u result: %lu",
1347 		handle, timeout, (uint32)result);
1348 	return result;
1349 }
1350 
1351 
1352 void
1353 AcpiOsReleaseMutex(ACPI_MUTEX handle)
1354 {
1355 	DEBUG_FUNCTION_F("mutex: %p", handle);
1356 	mutex_unlock(handle);
1357 }
1358 
1359 
1360 /******************************************************************************
1361  *
1362  * FUNCTION:    AcpiOsWaitEventsComplete
1363  *
1364  * PARAMETERS:  None
1365  *
1366  * RETURN:      None
1367  *
1368  * DESCRIPTION: Wait for all asynchronous events to complete. This
1369  *              implementation does nothing.
1370  *
1371  *****************************************************************************/
1372 void
1373 AcpiOsWaitEventsComplete()
1374 {
1375     //TODO: FreeBSD See description.
1376     return;
1377 }
1378 
1379 
1380 /******************************************************************************
1381  *
1382  * FUNCTION:    AcpiOsEnterSleep
1383  *
1384  * PARAMETERS:  SleepState          - Which sleep state to enter
1385  *              RegaValue           - Register A value
1386  *              RegbValue           - Register B value
1387  *
1388  * RETURN:      Status
1389  *
1390  * DESCRIPTION: A hook before writing sleep registers to enter the sleep
1391  *              state. Return AE_CTRL_TERMINATE to skip further sleep register
1392  *              writes.
1393  *
1394  *****************************************************************************/
1395 
1396 ACPI_STATUS
1397 AcpiOsEnterSleep (
1398 	UINT8                   SleepState,
1399 	UINT32                  RegaValue,
1400 	UINT32                  RegbValue)
1401 {
1402 	return (AE_OK);
1403 }
1404