1 /*******************************************************************************
3 * ACPI Component Architecture Operating System Layer (OSL) for ReactOS *
5 *******************************************************************************/
8 * Copyright (C) 2000 Andrew Henroid
9 * Copyright (C) 2001 Andrew Grover
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 static PKINTERRUPT AcpiInterrupt
;
31 static BOOLEAN AcpiInterruptHandlerRegistered
= FALSE
;
32 static OSD_HANDLER AcpiIrqHandler
= NULL
;
33 static PVOID AcpiIrqContext
= NULL
;
34 static ULONG AcpiIrqNumber
= 0;
36 static PVOID IVTVirtualAddress
= NULL
;
37 static PVOID BDAVirtualAddress
= NULL
;
43 IN PVOID DeferredContext
,
44 IN PVOID SystemArgument1
,
45 IN PVOID SystemArgument2
)
47 OSD_EXECUTION_CALLBACK Routine
= (OSD_EXECUTION_CALLBACK
)SystemArgument1
;
49 DPRINT("OslDpcStub()\n");
51 DPRINT("Calling [%p]([%p])\n", Routine
, SystemArgument2
);
53 (*Routine
)(SystemArgument2
);
58 acpi_os_remove_interrupt_handler(
64 acpi_os_initialize(void)
66 DPRINT("acpi_os_initialize()\n");
68 KeInitializeDpc(&AcpiDpc
, OslDpcStub
, NULL
);
74 acpi_os_terminate(void)
76 DPRINT("acpi_os_terminate()\n");
78 if (AcpiInterruptHandlerRegistered
) {
79 acpi_os_remove_interrupt_handler(AcpiIrqNumber
, AcpiIrqHandler
);
86 acpi_os_printf(const NATIVE_CHAR
*fmt
,...)
91 Size
= acpi_os_vprintf(fmt
, args
);
97 acpi_os_vprintf(const NATIVE_CHAR
*fmt
, va_list args
)
99 static char Buffer
[512];
100 LONG Size
= vsprintf(Buffer
, fmt
, args
);
102 DbgPrint("%s", Buffer
);
107 acpi_os_allocate(u32 size
)
109 return ExAllocatePool(NonPagedPool
, size
);
113 acpi_os_callocate(u32 size
)
115 PVOID ptr
= ExAllocatePool(NonPagedPool
, size
);
117 memset(ptr
, 0, size
);
122 acpi_os_free(void *ptr
)
125 /* FIXME: There is at least one bug somewhere that
126 results in an attempt to release a null pointer */
132 acpi_os_map_memory(ACPI_PHYSICAL_ADDRESS phys
, u32 size
, void **virt
)
134 PHYSICAL_ADDRESS Address
;
137 DPRINT("acpi_os_map_memory(phys 0x%X size 0x%X)\n", (ULONG
)phys
, size
);
140 /* Real mode Interrupt Vector Table */
141 Virtual
= ExAllocatePool(NonPagedPool
, size
);
142 if (NT_SUCCESS(NtVdmControl(0, Virtual
))) {
143 IVTVirtualAddress
= Virtual
;
151 if ((ULONG
)phys
>= 0x100000) {
152 Address
.QuadPart
= (ULONG
)phys
;
153 *virt
= MmMapIoSpace(Address
, size
, FALSE
);
157 *virt
= (PVOID
)((ULONG
)phys
);
164 acpi_os_unmap_memory(void *virt
, u32 size
)
166 DPRINT("acpi_os_unmap_memory()\n");
168 if (virt
== IVTVirtualAddress
) {
169 /* Real mode Interrupt Vector Table */
170 ExFreePool(IVTVirtualAddress
);
171 IVTVirtualAddress
= NULL
;
174 /* FIXME: Causes "Memory area is NULL" bugcheck in marea.c */
175 //if ((ULONG)virt >= 0x100000)
176 //MmUnmapIoSpace(virt, size);
180 acpi_os_get_physical_address(void *virt
, ACPI_PHYSICAL_ADDRESS
*phys
)
182 PHYSICAL_ADDRESS Address
;
184 DPRINT("acpi_os_get_physical_address()\n");
187 return AE_BAD_PARAMETER
;
189 Address
= MmGetPhysicalAddress(virt
);
191 *phys
= (ULONG
)Address
.QuadPart
;
198 PKINTERRUPT Interrupt
,
199 PVOID ServiceContext
)
203 Status
= (*AcpiIrqHandler
)(AcpiIrqContext
);
205 if (Status
== INTERRUPT_HANDLED
)
212 acpi_os_install_interrupt_handler(u32 irq
, OSD_HANDLER handler
, void *context
)
219 DPRINT("acpi_os_install_interrupt_handler()\n");
221 Vector
= HalGetInterruptVector(
229 Status
= IoConnectInterrupt(
237 LevelSensitive
, /* FIXME: LevelSensitive or Latched? */
241 if (!NT_SUCCESS(Status
)) {
242 DPRINT("Could not connect to interrupt %d\n", Vector
);
247 AcpiIrqHandler
= handler
;
248 AcpiIrqContext
= context
;
249 AcpiInterruptHandlerRegistered
= TRUE
;
255 acpi_os_remove_interrupt_handler(u32 irq
, OSD_HANDLER handler
)
257 DPRINT("acpi_os_remove_interrupt_handler()\n");
259 if (AcpiInterruptHandlerRegistered
) {
260 IoDisconnectInterrupt(AcpiInterrupt
);
261 AcpiInterrupt
= NULL
;
262 AcpiInterruptHandlerRegistered
= FALSE
;
269 acpi_os_sleep(u32 sec
, u32 ms
)
275 acpi_os_sleep_usec(u32 us
)
277 KeStallExecutionProcessor(us
);
281 acpi_os_in8(ACPI_IO_ADDRESS port
)
283 return READ_PORT_UCHAR((PUCHAR
)port
);
287 acpi_os_in16(ACPI_IO_ADDRESS port
)
289 return READ_PORT_USHORT((PUSHORT
)port
);
293 acpi_os_in32(ACPI_IO_ADDRESS port
)
295 return READ_PORT_ULONG((PULONG
)port
);
299 acpi_os_out8(ACPI_IO_ADDRESS port
, u8 val
)
301 WRITE_PORT_UCHAR((PUCHAR
)port
, val
);
305 acpi_os_out16(ACPI_IO_ADDRESS port
, u16 val
)
307 WRITE_PORT_USHORT((PUSHORT
)port
, val
);
311 acpi_os_out32(ACPI_IO_ADDRESS port
, u32 val
)
313 WRITE_PORT_ULONG((PULONG
)port
, val
);
317 acpi_os_mem_in8 (ACPI_PHYSICAL_ADDRESS phys_addr
)
319 return (*(PUCHAR
)(ULONG
)phys_addr
);
323 acpi_os_mem_in16 (ACPI_PHYSICAL_ADDRESS phys_addr
)
325 return (*(PUSHORT
)(ULONG
)phys_addr
);
329 acpi_os_mem_in32 (ACPI_PHYSICAL_ADDRESS phys_addr
)
331 return (*(PULONG
)(ULONG
)phys_addr
);
335 acpi_os_mem_out8 (ACPI_PHYSICAL_ADDRESS phys_addr
, UINT8 value
)
337 *(PUCHAR
)(ULONG
)phys_addr
= value
;
341 acpi_os_mem_out16 (ACPI_PHYSICAL_ADDRESS phys_addr
, UINT16 value
)
343 *(PUSHORT
)(ULONG
)phys_addr
= value
;
347 acpi_os_mem_out32 (ACPI_PHYSICAL_ADDRESS phys_addr
, UINT32 value
)
349 *(PULONG
)(ULONG
)phys_addr
= value
;
353 acpi_os_read_pci_cfg_byte(
359 /* FIXME: What do we do here? */
361 DPRINT("acpi_os_read_pci_cfg_byte is not implemented");
367 acpi_os_read_pci_cfg_word(
373 /* FIXME: What do we do here? */
375 DPRINT("acpi_os_read_pci_cfg_word is not implemented");
381 acpi_os_read_pci_cfg_dword(
387 /* FIXME: What do we do here? */
389 DPRINT("acpi_os_read_pci_cfg_dword is not implemented");
395 acpi_os_write_pci_cfg_byte(
401 /* FIXME: What do we do here? */
403 DPRINT("acpi_os_write_pci_cfg_byte is not implemented");
409 acpi_os_write_pci_cfg_word(
415 /* FIXME: What do we do here? */
417 DPRINT("acpi_os_write_pci_cfg_word is not implemented");
423 acpi_os_write_pci_cfg_dword(
429 /* FIXME: What do we do here? */
431 DPRINT("acpi_os_write_pci_cfg_dword is not implemented");
437 acpi_os_load_module (
440 DPRINT("acpi_os_load_module()\n");
443 return AE_BAD_PARAMETER
;
449 acpi_os_unload_module (
452 DPRINT("acpi_os_unload_module()\n");
455 return AE_BAD_PARAMETER
;
461 acpi_os_queue_for_execution(
463 OSD_EXECUTION_CALLBACK function
,
466 ACPI_STATUS Status
= AE_OK
;
468 DPRINT("acpi_os_queue_for_execution()\n");
471 return AE_BAD_PARAMETER
;
473 DPRINT("Scheduling task [%p](%p) for execution.\n", function
, context
);
477 case OSD_PRIORITY_MED
:
478 KeSetImportanceDpc(&AcpiDpc
, MediumImportance
);
479 case OSD_PRIORITY_LO
:
480 KeSetImportanceDpc(&AcpiDpc
, LowImportance
);
481 case OSD_PRIORITY_HIGH
:
483 KeSetImportanceDpc(&AcpiDpc
, HighImportance
);
487 KeInsertQueueDpc(&AcpiDpc
, (PVOID
)function
, (PVOID
)context
);
493 acpi_os_create_semaphore(
500 Mutex
= ExAllocatePool(NonPagedPool
, sizeof(FAST_MUTEX
));
504 DPRINT("acpi_os_create_semaphore() at 0x%X\n", Mutex
);
506 ExInitializeFastMutex(Mutex
);
513 acpi_os_delete_semaphore(
516 PFAST_MUTEX Mutex
= (PFAST_MUTEX
)handle
;
518 DPRINT("acpi_os_delete_semaphore(handle 0x%X)\n", handle
);
521 return AE_BAD_PARAMETER
;
529 acpi_os_wait_semaphore(
534 ACPI_STATUS Status
= AE_OK
;
535 PFAST_MUTEX Mutex
= (PFAST_MUTEX
)handle
;
537 if (!Mutex
|| (units
< 1)) {
538 DPRINT("acpi_os_wait_semaphore(handle 0x%X, units %d) Bad parameters\n",
540 return AE_BAD_PARAMETER
;
543 DPRINT("Waiting for semaphore[%p|%d|%d]\n", handle
, units
, timeout
);
545 //ExAcquireFastMutex(Mutex);
551 acpi_os_signal_semaphore(
555 PFAST_MUTEX Mutex
= (PFAST_MUTEX
)handle
;
557 if (!Mutex
|| (units
< 1)) {
558 DPRINT("acpi_os_signal_semaphore(handle 0x%X) Bad parameter\n", handle
);
559 return AE_BAD_PARAMETER
;
562 DPRINT("Signaling semaphore[%p|%d]\n", handle
, units
);
564 //ExReleaseFastMutex(Mutex);
570 acpi_os_breakpoint(NATIVE_CHAR
*msg
)
572 DPRINT1("BREAKPOINT: %s", msg
);
577 acpi_os_dbg_trap(char *msg
)
580 DPRINT1("TRAP: %s", msg
);
584 acpi_os_dbg_assert(void *failure
, void *file
, u32 line
, NATIVE_CHAR
*msg
)
586 DPRINT1("ASSERT: %s\n", msg
);
590 acpi_os_get_line(NATIVE_CHAR
*buffer
)
596 acpi_os_readable(void *ptr
, u32 len
)
598 /* Always readable */
603 acpi_os_writable(void *ptr
, u32 len
)
605 /* Always writable */
610 acpi_os_get_thread_id (void)
612 return (ULONG
)PsGetCurrentThreadId();