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 Address.QuadPart = (ULONG)phys;
152 *virt = MmMapIoSpace(Address, size, FALSE);
160 acpi_os_unmap_memory(void *virt, u32 size)
162 DPRINT("acpi_os_unmap_memory()\n");
164 if (virt == IVTVirtualAddress) {
165 /* Real mode Interrupt Vector Table */
166 ExFreePool(IVTVirtualAddress);
167 IVTVirtualAddress = NULL;
170 MmUnmapIoSpace(virt, size);
174 acpi_os_get_physical_address(void *virt, ACPI_PHYSICAL_ADDRESS *phys)
176 PHYSICAL_ADDRESS Address;
178 DPRINT("acpi_os_get_physical_address()\n");
181 return AE_BAD_PARAMETER;
183 Address = MmGetPhysicalAddress(virt);
185 *phys = (ULONG)Address.QuadPart;
192 PKINTERRUPT Interrupt,
193 PVOID ServiceContext)
197 Status = (*AcpiIrqHandler)(AcpiIrqContext);
199 if (Status == INTERRUPT_HANDLED)
206 acpi_os_install_interrupt_handler(u32 irq, OSD_HANDLER handler, void *context)
213 DPRINT("acpi_os_install_interrupt_handler()\n");
215 Vector = HalGetInterruptVector(
223 Status = IoConnectInterrupt(
231 LevelSensitive, /* FIXME: LevelSensitive or Latched? */
235 if (!NT_SUCCESS(Status)) {
236 DPRINT("Could not connect to interrupt %d\n", Vector);
241 AcpiIrqHandler = handler;
242 AcpiIrqContext = context;
243 AcpiInterruptHandlerRegistered = TRUE;
249 acpi_os_remove_interrupt_handler(u32 irq, OSD_HANDLER handler)
251 DPRINT("acpi_os_remove_interrupt_handler()\n");
253 if (AcpiInterruptHandlerRegistered) {
254 IoDisconnectInterrupt(AcpiInterrupt);
255 AcpiInterrupt = NULL;
256 AcpiInterruptHandlerRegistered = FALSE;
263 acpi_os_sleep(u32 sec, u32 ms)
269 acpi_os_sleep_usec(u32 us)
271 KeStallExecutionProcessor(us);
275 acpi_os_in8(ACPI_IO_ADDRESS port)
277 return READ_PORT_UCHAR((PUCHAR)port);
281 acpi_os_in16(ACPI_IO_ADDRESS port)
283 return READ_PORT_USHORT((PUSHORT)port);
287 acpi_os_in32(ACPI_IO_ADDRESS port)
289 return READ_PORT_ULONG((PULONG)port);
293 acpi_os_out8(ACPI_IO_ADDRESS port, u8 val)
295 WRITE_PORT_UCHAR((PUCHAR)port, val);
299 acpi_os_out16(ACPI_IO_ADDRESS port, u16 val)
301 WRITE_PORT_USHORT((PUSHORT)port, val);
305 acpi_os_out32(ACPI_IO_ADDRESS port, u32 val)
307 WRITE_PORT_ULONG((PULONG)port, val);
311 acpi_os_mem_in8 (ACPI_PHYSICAL_ADDRESS phys_addr)
313 return (*(PUCHAR)(ULONG)phys_addr);
317 acpi_os_mem_in16 (ACPI_PHYSICAL_ADDRESS phys_addr)
319 return (*(PUSHORT)(ULONG)phys_addr);
323 acpi_os_mem_in32 (ACPI_PHYSICAL_ADDRESS phys_addr)
325 return (*(PULONG)(ULONG)phys_addr);
329 acpi_os_mem_out8 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT8 value)
331 *(PUCHAR)(ULONG)phys_addr = value;
335 acpi_os_mem_out16 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT16 value)
337 *(PUSHORT)(ULONG)phys_addr = value;
341 acpi_os_mem_out32 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT32 value)
343 *(PULONG)(ULONG)phys_addr = value;
347 acpi_os_read_pci_cfg_byte(
353 /* FIXME: What do we do here? */
355 DPRINT("acpi_os_read_pci_cfg_byte is not implemented");
361 acpi_os_read_pci_cfg_word(
367 /* FIXME: What do we do here? */
369 DPRINT("acpi_os_read_pci_cfg_word is not implemented");
375 acpi_os_read_pci_cfg_dword(
381 /* FIXME: What do we do here? */
383 DPRINT("acpi_os_read_pci_cfg_dword is not implemented");
389 acpi_os_write_pci_cfg_byte(
395 /* FIXME: What do we do here? */
397 DPRINT("acpi_os_write_pci_cfg_byte is not implemented");
403 acpi_os_write_pci_cfg_word(
409 /* FIXME: What do we do here? */
411 DPRINT("acpi_os_write_pci_cfg_word is not implemented");
417 acpi_os_write_pci_cfg_dword(
423 /* FIXME: What do we do here? */
425 DPRINT("acpi_os_write_pci_cfg_dword is not implemented");
431 acpi_os_load_module (
434 DPRINT("acpi_os_load_module()\n");
437 return AE_BAD_PARAMETER;
443 acpi_os_unload_module (
446 DPRINT("acpi_os_unload_module()\n");
449 return AE_BAD_PARAMETER;
455 acpi_os_queue_for_execution(
457 OSD_EXECUTION_CALLBACK function,
460 ACPI_STATUS Status = AE_OK;
462 DPRINT("acpi_os_queue_for_execution()\n");
465 return AE_BAD_PARAMETER;
467 DPRINT("Scheduling task [%p](%p) for execution.\n", function, context);
471 case OSD_PRIORITY_MED:
472 KeSetImportanceDpc(&AcpiDpc, MediumImportance);
473 case OSD_PRIORITY_LO:
474 KeSetImportanceDpc(&AcpiDpc, LowImportance);
475 case OSD_PRIORITY_HIGH:
477 KeSetImportanceDpc(&AcpiDpc, HighImportance);
481 KeInsertQueueDpc(&AcpiDpc, (PVOID)function, (PVOID)context);
487 acpi_os_create_semaphore(
494 Mutex = ExAllocatePool(NonPagedPool, sizeof(FAST_MUTEX));
498 DPRINT("acpi_os_create_semaphore() at 0x%X\n", Mutex);
500 ExInitializeFastMutex(Mutex);
507 acpi_os_delete_semaphore(
510 PFAST_MUTEX Mutex = (PFAST_MUTEX)handle;
512 DPRINT("acpi_os_delete_semaphore(handle 0x%X)\n", handle);
515 return AE_BAD_PARAMETER;
523 acpi_os_wait_semaphore(
528 ACPI_STATUS Status = AE_OK;
529 PFAST_MUTEX Mutex = (PFAST_MUTEX)handle;
531 if (!Mutex || (units < 1)) {
532 DPRINT("acpi_os_wait_semaphore(handle 0x%X, units %d) Bad parameters\n",
534 return AE_BAD_PARAMETER;
537 DPRINT("Waiting for semaphore[%p|%d|%d]\n", handle, units, timeout);
539 //ExAcquireFastMutex(Mutex);
545 acpi_os_signal_semaphore(
549 PFAST_MUTEX Mutex = (PFAST_MUTEX)handle;
551 if (!Mutex || (units < 1)) {
552 DPRINT("acpi_os_signal_semaphore(handle 0x%X) Bad parameter\n", handle);
553 return AE_BAD_PARAMETER;
556 DPRINT("Signaling semaphore[%p|%d]\n", handle, units);
558 //ExReleaseFastMutex(Mutex);
564 acpi_os_breakpoint(NATIVE_CHAR *msg)
566 DPRINT1("BREAKPOINT: %s", msg);
571 acpi_os_dbg_trap(char *msg)
574 DPRINT1("TRAP: %s", msg);
578 acpi_os_dbg_assert(void *failure, void *file, u32 line, NATIVE_CHAR *msg)
580 DPRINT1("ASSERT: %s\n", msg);
584 acpi_os_get_line(NATIVE_CHAR *buffer)
590 acpi_os_readable(void *ptr, u32 len)
592 /* Always readable */
597 acpi_os_writable(void *ptr, u32 len)
599 /* Always writable */
604 acpi_os_get_thread_id (void)
606 return (ULONG)PsGetCurrentThreadId();