ACPICA: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
 
(18 intermediate revisions by 4 users not shown)
Line 1:
{{ACPI}}
 
The ACPI Component Architecture '''ACPICA''' provides an operating system (OS)-independent reference implementation of the [[ACPI|Advanced Configuration and Power Interface]]. It can be adapted to any host OS. The ACPICA code is meant to be directly integrated into the host OS, as a kernel-resident subsystem. Hosting the ACPICA requires no changes to the core ACPICA code. However, it does require a small OS-specific interface layer, which must be written specifically for each host OS.
 
Line 21 ⟶ 23:
ACPI_PHYSICAL_ADDRESS AcpiOsGetRootPointer()
{
ACPI_PHYSICAL_ADDRESS Ret = 0;
Ret = 0;
AcpiFindRootPointer(&Ret);
return Ret;
Line 48 ⟶ 49:
==== AcpiOsUnmapMemory ====
void AcpiOsUnmapMemory(void *where, ACPI_SIZE length)
Unmap pages mapped using AcpiOsMapMemory. whereWhere is the Virtual address returned in AcpiOsMapMemory and length is equal to the length of the same function. Just remove the virtual address form the page directory and set that virtual address as reusable.
'''Note:''' for the last two functions you might need a separated heap.
 
==== AcpiOsGetPhysicalAddress ====
ACPI_STATUS AcpiOsGetPhysicalAddress(void *LogicalAddress, ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
Line 71 ⟶ 73:
#define ACPI_USE_LOCAL_CACHE 1
=== Multithreading and Scheduling Services ===
To use all the features of ACPICA you need Scheduling support too. AcpicaACPICA specifies Threads but if you have only processes, that should work too. If you don't have and don't plan to have a scheduler, you can only use the Table features of ACPICA.
==== AcpiOsGetThreadId ====
ACPI_THREAD_ID AcpiOsGetThreadId()
Line 78 ⟶ 80:
==== AcpiOsExecute ====
ACPI_STATUS AcpiOsExecute(ACPI_EXECUTE_TYPE Type, ACPI_OSD_EXEC_CALLBACK Function, void *Context)
Create a new Threadthread (or process) with entry point at ''Function'' using parameter ''Context''. ''Type'' is not really useful. When the scheduler chooses this thread it has to putpass in ''Context'' onto the first argument (RDI for x86-64, stack for x86-32 (using System V ABI) to have something like:
Function(Context);
 
==== AcpiOsSleep ====
void AcpiOsSleep(UINT64 Milliseconds)
Line 86 ⟶ 89:
void AcpiOsStall(UINT32 Microseconds)
Stall the thread for ''n'' microseconds. Note: this should not put the thread in the sleep queue. The thread should keep on running. Just looping.
 
=== Mutual Exclusion and Synchronization ===
Yes, you need Spinlocks, Mutexes and Semaphores too. Nobody said it was easy. :)
==== AcpiOsCreateMutex ====
ACPI_STATUS AcpiOsCreateMutex(ACPI_MUTEX *OutHandle)
Create space for a new mutexMutex using malloc (or eventually new) and put the address of the mutexMutex in *OutHandle, return AE_NO_MEMORY if malloc or new return NULL. Else return AE_OK like in most other functions.
 
==== AcpiOsDeleteMutex ====
void AcpiOsDeleteMutex(ACPI_MUTEX Handle)
Line 97 ⟶ 102:
ACPI_STATUS AcpiOsAcquireMutex(ACPI_MUTEX Handle, UINT16 Timeout)
This would be silly too if not for the Timeout parameter. Timeout can be one of:
* 0: acquire the mutexMutex if it is free, but do not wait if it is not
* 1 - +inf: acquire the mutexMutex if it is free, but wait for ''Timeout'' milliseconds if it is not
* -1 (0xFFFF): acquire the mutexMutex if it is free, or wait until it becamesbecame free, then return
 
==== AcpiOsReleaseMutex ====
void AcpiOsReleaseMutex(ACPI_MUTEX Handle)
Line 105 ⟶ 111:
==== AcpiOsCreateSemaphore ====
ACPI_STATUS AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, ACPI_SEMAPHORE *OutHandle)
Create a new semaphoreSemaphore with the counter initialized to ''InitialUnits'' and put its address in *OutHandle. I don't know how tu use MaxUnits. The spec says: The maximum number of units this semaphoreSemaphore will be required to accept.<br> However you should be ok if you ignore this.
 
==== AcpiOsDeleteSemahore ====
==== AcpiOsDeleteSemaphore ====
ACPI_STATUS AcpiOsDeleteSemaphore(ACPI_SEMAPHORE Handle)
-_-'
 
==== AcpiOsWaitSemaphore ====
ACPI_STATUS AcpiOsWaitSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units, UINT16 Timeout)
Line 117 ⟶ 125:
==== AcpiOsCreateLock ====
ACPI_STATUS AcpiOsCreateLock(ACPI_SPINLOCK *OutHandle)
Create a new spinlock and put its address in *OutHandle. Spinlock should disable interrupts on the current cpuCPU to avoid scheduling and make sure that no other cpuCPU will access the reserved area.
 
==== AcpiOsDeleteLock ====
void AcpiOsDeleteLock(ACPI_HANDLE Handle)
Line 126 ⟶ 135:
void AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags)
Release the lock. ''Flags'' is the return value of AcquireLock. If you used this to store the interrupt state, now is the moment to use it.
 
=== Interrupt Handling ===
==== AcpiOsInstallInterruptHandler ====
Line 132 ⟶ 142:
If you're lucky, your IRQ manager uses handlers of this form:
uint32_t handler(void *);
In this case just assign the handler to the irqIRQ number with that context. I wasn't as lucky so I did:
#include <Irq.h>
ACPI_OSD_HANDLER ServiceRout;
Line 152 ⟶ 162:
==== AcpiOsRemoveInterruptHandler ====
ACPI_STATUS AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER Handler)
Just UnregisterIrq (InterruptNumber). Handler is provided in case you have an IrqIRQ manager which can have many handlers for one IrqIRQ. This would let you know which handler on that IrqIRQ you have to remove.
 
== Using ACPICA in your OS ==
 
Line 166 ⟶ 177:
 
=== Visual Studio experience ===
From Visual Studio, although there is little organization in the files, it is relatively easy to port. In the provided /generate directory, there is a VC 9.0 solution. The only project required for integration is "AcpiSubsystem". Copy this project along with all the files listed (you can keep the old directory structure). #define's can be used to configure certain aspects of it, and perhaps changing #ifdef WIN32 to #ifdef X86 might be a good idea (WIN64Win64 -> X64x64). Once this is done though the base of it is in place, and actypes.h is the only header file that needs any modification (that listed above). It might be an idea to change the option "Compile as C code" to default - it's all .c anyway. This allows you to add C++ to the project without problems. Once this is done, add OSL.c or OSLPP.cpp, write your OS layer and you are done.
 
== Code Examples ==
Line 179 ⟶ 190:
 
== External links ==
*[httphttps://www.acpica.org/ ACPICA Website]
*[httphttps://acpica.org/sites/acpica/files/acpica-reference_2reference_19.pdf ACPICA User Guide and Programmer Reference]. Explains how to integrate it in your OS. Any missing OS layer that isn't documented in this page, must be there.
 
[[Category:ACPI]]