Ticket #4152: acpi.patch

File acpi.patch, 50.3 KB (added by tqh, 15 years ago)
  • build/jam/HaikuImage

     
    467467
    468468# boot module links
    469469AddBootModuleSymlinksToHaikuImage
    470     $(X86_ONLY)acpi $(ATA_ONLY)ata pci $(X86_ONLY)isa config_manager
     470    $(X86_ONLY)acpi $(ATA_ONLY)ata pci $(X86_ONLY)isa config_manager dpc
    471471    $(IDE_ONLY)ide scsi usb
    472472    $(PPC_ONLY)openpic
    473473    $(ATA_ONLY)ata_adapter $(IDE_ONLY)ide_adapter locked_pool scsi_periph
  • data/settings/kernel/drivers/kernel

     
    5555
    5656#acpi true
    5757    # ACPI support, off by default
     58
     59#acpi_avoid_full_init true
     60    # Avoids running _INI and _STA methods and final object initialization,
     61    # which may be used to for debugging ACPI issues.
  • src/add-ons/kernel/bus_managers/acpi/include/platform/achaiku.h

     
    117117#ifndef __ACHAIKU_H__
    118118#define __ACHAIKU_H__
    119119
    120 /* Haiku uses GCC */
    121 
    122120#include "acgcc.h"
    123121
    124122#include <SupportDefs.h>
    125123
    126 /*#ifdef _LP64
    127 #define ACPI_MACHINE_WIDTH      64
    128 #else*/
    129 #define ACPI_MACHINE_WIDTH      32 /* Haiku always 32 bit right now */
    130 /*#endif*/
    131124
    132 #define COMPILER_DEPENDENT_INT64  int64
    133 #define COMPILER_DEPENDENT_UINT64 uint64
     125/* Host-dependent types and defines for user- and kernel-space ACPICA */
    134126
    135 #ifdef _KERNEL_MODE
    136 /* #include "opt_acpi.h"           collect build-time options here */
     127#define ACPI_USE_SYSTEM_CLIBRARY
     128#define ACPI_USE_STANDARD_HEADERS
    137129
    138 #include <string.h>
    139 #include <ctype.h>
    140 #include <stdarg.h>
    141 #include <stdlib.h>
     130/* TODO: add mutex or benaphore code
     131#define ACPI_MUTEX_TYPE             ACPI_OSL_MUTEX
     132#define ACPI_MUTEX                  sem_id             
     133*/
    142134
    143 #define asm         __asm
    144 
    145 #define ACPI_USE_LOCAL_CACHE
     135//#define ACPI_MUTEX_DEBUG             
    146136#define ACPI_USE_NATIVE_DIVIDE
    147137
    148 #define ACPI_ASM_MACROS         /* tell acenv.h */
     138#define ACPI_THREAD_ID              thread_id
     139#define ACPI_SEMAPHORE              sem_id
     140#define ACPI_SPINLOCK               spinlock *
     141#define ACPI_CPU_FLAGS              cpu_status
    149142
    150 #define ACPI_SYSTEM_XFACE
    151 #define ACPI_EXTERNAL_XFACE
    152 #define ACPI_INTERNAL_XFACE
    153 #define ACPI_INTERNAL_VAR_XFACE
     143#define COMPILER_DEPENDENT_INT64    int64
     144#define COMPILER_DEPENDENT_UINT64   uint64
    154145
     146/* TODO: Add 64 bit when Haiku goes 64 bit */
     147#define ACPI_MACHINE_WIDTH              32
    155148
    156 #define ACPI_FLUSH_CPU_CACHE() __asm __volatile("wbinvd");
    157149
    158 #ifdef ACPI_DEBUG
    159 #define ACPI_DEBUG_OUTPUT
    160 #define ACPI_DBG_TRACK_ALLOCATIONS
    161 #ifdef DEBUGGER_THREADING
    162 #undef DEBUGGER_THREADING
    163 #endif /* DEBUGGER_THREADING */
    164 #define DEBUGGER_THREADING 0    /* integrated with DDB */
    165 //#include "opt_ddb.h"
    166 //#ifdef DDB
    167 #define ACPI_DISASSEMBLER
    168 #define ACPI_DEBUGGER
    169 //#endif /* DDB */
    170 #endif /* ACPI_DEBUG */
     150#ifdef _KERNEL_MODE
     151/* Host-dependent types and defines for in-kernel ACPICA */
    171152
    172 /* The following Global Lock code stolen from NetBSD
    173    src/sys/arch/i386/include/acpi_func.h which in turn
    174    was stolen from Intel's spec document */
     153#include <KernelExport.h>
    175154
     155#define ACPI_USE_LOCAL_CACHE
     156
     157
     158/* TODO: Use Haiku's slab code */
     159//#define ACPI_CACHE_T                struct kmem_cache
     160
     161#define ACPI_FLUSH_CPU_CACHE() __asm __volatile("wbinvd");
     162
    176163#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
    177164do { \
    178165    __asm __volatile( \
     
    206193    : "edx"); \
    207194} while (0)
    208195
    209 
    210196#else /* _KERNEL_MODE */
     197/* Host-dependent types and defines for user-space ACPICA */
    211198
    212 #include <ctype.h>
     199#error "We only support kernel mode ACPI atm."
    213200
    214 /* Not building kernel code, so use libc */
    215 #define ACPI_USE_STANDARD_HEADERS
    216 #define ACPI_FLUSH_CPU_CACHE()
    217 
    218 #define __cli()
    219 #define __sti()
    220 
    221 /* XXX */
    222 #define __inline inline
    223 
    224201#endif /* _KERNEL_MODE */
    225 
    226 /* Always use Haiku code over our local versions */
    227 #define ACPI_USE_SYSTEM_CLIBRARY
    228 #define ACPI_USE_NATIVE_DIVIDE
    229 
    230 
    231202#endif /* __ACHAIKU_H__ */
  • src/add-ons/kernel/bus_managers/acpi/oshaiku.c

     
    114114 *****************************************************************************/
    115115
    116116
    117 /*
    118  * These interfaces are required in order to compile the ASL compiler under
    119  * BeOS/Haiku.
    120  */
    121 
    122117#include <stdio.h>
    123 #include <stdlib.h>
    124 #include <stdarg.h>
    125118#include <unistd.h>
    126119#include <sys/time.h>
    127120#include <OS.h>
    128    
    129 #ifdef _KERNEL_MODE
    130 #include <KernelExport.h>
    131 #include <vm.h>
    132 #include <PCI.h>
    133 extern pci_module_info *gPCIManager;
    134 #include <dpc.h>
    135 extern dpc_module_info *gDPC;
    136 extern void *gDPCHandle;
    137 #endif
    138121
     122
    139123#include "acpi.h"
    140124#include "accommon.h"
    141125#include "amlcode.h"
    142126#include "acparser.h"
    143127#include "acdebug.h"
    144128
    145 #define _COMPONENT      ACPI_OS_SERVICES
    146 ACPI_MODULE_NAME        ("oshaiku")
    147129
    148 extern FILE *           AcpiGbl_DebugFile;
    149 FILE *                  AcpiGbl_OutputFile;
     130#ifdef _KERNEL_MODE
     131#include <KernelExport.h>
     132#include <dpc.h>
     133#include <PCI.h>
     134#include <vm.h>
    150135
    151 static uint32 sACPIRoot = 0;
    152 static void *sInterruptHandlerData[32];
    153136
    154 #define DEBUG_OSHAIKU   0 /* verbosity level 0 = off, 1 = normal, 2 = all */
     137extern pci_module_info *gPCIManager;
     138extern dpc_module_info *gDPC;
     139extern void *gDPCHandle;
     140#endif
    155141
    156 #if DEBUG_OSHAIKU > 0
     142ACPI_MODULE_NAME("Haiku ACPI Module")
     143
     144#define _COMPONENT ACPI_OS_SERVICES
     145
     146// verbosity level 0 = off, 1 = normal, 2 = all
     147#define DEBUG_OSHAIKU 0
     148
     149#if DEBUG_OSHAIKU <= 0
     150// No debugging, do nothing
     151#   define DEBUG_FUNCTION()
     152#   define DEBUG_FUNCTION_F(x, y...)
     153#   define DEBUG_FUNCTION_V()
     154#   define DEBUG_FUNCTION_VF(x, y...)
     155#else
    157156#   define DEBUG_FUNCTION() \
    158157        dprintf("acpi[%ld]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__);
    159158#   define DEBUG_FUNCTION_F(x, y...) \
    160159        dprintf("acpi[%ld]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y);
    161 
    162 #   if DEBUG_OSHAIKU > 1
     160#   if DEBUG_OSHAIKU = 1
     161// No verbose debugging, do nothing
     162#       define DEBUG_FUNCTION_V()
     163#       define DEBUG_FUNCTION_VF(x, y...)
     164#   else
     165// Full debugging
    163166#       define DEBUG_FUNCTION_V() \
    164167            dprintf("acpi[%ld]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__);
    165168#       define DEBUG_FUNCTION_VF(x, y...) \
    166169            dprintf("acpi[%ld]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y);
    167 #   else
    168 #       define DEBUG_FUNCTION_V() \
    169         /* nothing */
    170 #       define DEBUG_FUNCTION_VF(x, y...) \
    171         /* nothing */
    172170#   endif
    173 #else
    174 #   define DEBUG_FUNCTION() \
    175         /* nothing */
    176 #   define DEBUG_FUNCTION_F(x, y...) \
    177         /* nothing */
    178 #   define DEBUG_FUNCTION_V() \
    179         /* nothing */
    180 #   define DEBUG_FUNCTION_VF(x, y...) \
    181         /* nothing */
    182171#endif
    183172
     173
     174extern FILE *AcpiGbl_DebugFile;
     175FILE *AcpiGbl_OutputFile;
     176
     177static uint32 sACPIRoot = 0;
     178static void *sInterruptHandlerData[32];
     179
     180// Upcalls to AcpiExec
     181
     182//ACPI_PHYSICAL_ADDRESS
     183//AeLocalGetRootPointer();
     184
     185//void
     186//AeTableOverride(ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable);
     187
     188//typedef void* (*PTHREAD_CALLBACK)(void *);
     189
     190
    184191/******************************************************************************
    185192 *
    186  * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
     193 * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
    187194 *
    188  * PARAMETERS:  None
     195 * PARAMETERS:  None
    189196 *
    190  * RETURN:      Status
     197 * RETURN:      Status
    191198 *
    192  * DESCRIPTION: Init and terminate. Nothing to do.
     199 * DESCRIPTION: Init and terminate. Nothing to do.
    193200 *
    194201 *****************************************************************************/
    195 
    196202ACPI_STATUS
    197 AcpiOsInitialize(void)
     203AcpiOsInitialize()
    198204{
    199205#ifndef _KERNEL_MODE
    200206    AcpiGbl_OutputFile = stdout;
     
    202208    AcpiGbl_OutputFile = NULL;
    203209#endif
    204210    DEBUG_FUNCTION();
    205     return AE_OK;
     211    return AE_OK;
    206212}
    207213
    208214
    209215ACPI_STATUS
    210 AcpiOsTerminate(void)
     216AcpiOsTerminate()
    211217{
    212218    DEBUG_FUNCTION();
    213     return AE_OK;
     219    return AE_OK;
    214220}
    215221
    216222
    217223/******************************************************************************
    218224 *
    219  * FUNCTION:    AcpiOsGetRootPointer
     225 * FUNCTION:    AcpiOsGetRootPointer
    220226 *
    221  * PARAMETERS:  Flags   - Logical or physical addressing mode
    222  *              Address - Where the address is returned
     227 * PARAMETERS:  None
    223228 *
    224  * RETURN:      Status
     229 * RETURN:      RSDP physical address
    225230 *
    226  * DESCRIPTION: Gets the root pointer (RSDP)
     231 * DESCRIPTION: Gets the root pointer (RSDP)
    227232 *
    228233 *****************************************************************************/
    229 
    230234ACPI_PHYSICAL_ADDRESS
    231 AcpiOsGetRootPointer(void)
     235AcpiOsGetRootPointer()
    232236{
    233237#ifdef _KERNEL_MODE
    234238    ACPI_SIZE address;
     
    242246    dprintf("AcpiOsGetRootPointer returning %p\n", (void *)sACPIRoot);
    243247    return sACPIRoot;
    244248#else
    245     return (AeLocalGetRootPointer());
     249    return AeLocalGetRootPointer();
    246250#endif
    247251}
    248252
    249253
    250254/******************************************************************************
    251255 *
    252  * FUNCTION:    AcpiOsPredefinedOverride
     256 * FUNCTION:    AcpiOsPredefinedOverride
    253257 *
    254  * PARAMETERS:  InitVal     - Initial value of the predefined object
    255  *              NewVal      - The new value for the object
     258 * PARAMETERS:  initVal     - Initial value of the predefined object
     259 *              newVal      - The new value for the object
    256260 *
    257  * RETURN:      Status, pointer to value. Null pointer returned if not
    258  *              overriding.
     261 * RETURN:      Status, pointer to value. Null pointer returned if not
     262 *              overriding.
    259263 *
    260  * DESCRIPTION: Allow the OS to override predefined names
     264 * DESCRIPTION: Allow the OS to override predefined names
    261265 *
    262266 *****************************************************************************/
    263 
    264267ACPI_STATUS
    265 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal,
    266     ACPI_STRING *NewVal)
     268AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *initVal,
     269        ACPI_STRING *newVal)
    267270{
    268271    DEBUG_FUNCTION();
    269     if (!InitVal || !NewVal)
    270         return AE_BAD_PARAMETER;
     272    if (!initVal || !newVal)
     273        return AE_BAD_PARAMETER;
    271274
    272     *NewVal = NULL;
    273     return AE_OK;
     275    *newVal = NULL;
     276    return AE_OK;
    274277}
    275278
    276279
    277280/******************************************************************************
    278281 *
    279  * FUNCTION:    AcpiOsTableOverride
     282 * FUNCTION:    AcpiOsTableOverride
    280283 *
    281  * PARAMETERS:  ExistingTable   - Header of current table (probably firmware)
    282  *              NewTable        - Where an entire new table is returned.
     284 * PARAMETERS:  existingTable   - Header of current table (probably firmware)
     285 *              newTable        - Where an entire new table is returned.
    283286 *
    284  * RETURN:      Status, pointer to new table. Null pointer returned if no
    285  *              table is available to override
     287 * RETURN:      Status, pointer to new table. Null pointer returned if no
     288 *              table is available to override
    286289 *
    287  * DESCRIPTION: Return a different version of a table if one is available
     290 * DESCRIPTION: Return a different version of a table if one is available
    288291 *
    289292 *****************************************************************************/
    290 
    291293ACPI_STATUS
    292 AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable,
    293     ACPI_TABLE_HEADER **NewTable)
     294AcpiOsTableOverride(ACPI_TABLE_HEADER *existingTable,
     295        ACPI_TABLE_HEADER **newTable)
    294296{
    295297    DEBUG_FUNCTION();
    296     if (!ExistingTable || !NewTable)
    297         return AE_BAD_PARAMETER;
     298    if (!existingTable || !newTable)
     299        return AE_BAD_PARAMETER;
    298300
    299     *NewTable = NULL;
     301    *newTable = NULL;
    300302
    301 #ifdef _ACPI_EXEC_APP
    302     /* This code exercises the table override mechanism in the core */
    303     if (!ACPI_STRNCMP(ExistingTable->Signature, DSDT_SIG, ACPI_NAME_SIZE)) {
    304         /* override DSDT with itself */
    305         *NewTable = AcpiGbl_DbTablePtr;
    306     }
    307 
    308     return AE_OK;
     303#ifdef ACPI_EXEC_APP
     304    AeTableOverride(existingTable, newTable);
     305    return AE_OK;
    309306#else
    310     return AE_NO_ACPI_TABLES;
     307    return AE_NO_ACPI_TABLES;
    311308#endif
    312309}
    313310
    314311
    315312/******************************************************************************
    316313 *
    317  * FUNCTION:    AcpiOsReadable
     314 * FUNCTION:    AcpiOsRedirectOutput
    318315 *
    319  * PARAMETERS:  Pointer             - Area to be verified
    320  *              Length              - Size of area
     316 * PARAMETERS:  destination         - An open file handle/pointer
    321317 *
    322  * RETURN:      TRUE if readable for entire length
     318 * RETURN:      None
    323319 *
    324  * DESCRIPTION: Verify that a pointer is valid for reading
     320 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
    325321 *
    326322 *****************************************************************************/
    327 
    328 BOOLEAN
    329 AcpiOsReadable(void *Pointer, ACPI_SIZE Length)
    330 {
    331     DEBUG_FUNCTION_F("addr: %p; length: %lu", Pointer, (size_t)Length);
    332     return TRUE;
    333 }
    334 
    335 
    336 /******************************************************************************
    337  *
    338  * FUNCTION:    AcpiOsWritable
    339  *
    340  * PARAMETERS:  Pointer             - Area to be verified
    341  *              Length              - Size of area
    342  *
    343  * RETURN:      TRUE if writable for entire length
    344  *
    345  * DESCRIPTION: Verify that a pointer is valid for writing
    346  *
    347  *****************************************************************************/
    348 
    349 BOOLEAN
    350 AcpiOsWritable(void *Pointer, ACPI_SIZE Length)
    351 {
    352     DEBUG_FUNCTION_F("addr: %p; length: %lu", Pointer, (size_t)Length);
    353     return TRUE;
    354 }
    355 
    356 
    357 /******************************************************************************
    358  *
    359  * FUNCTION:    AcpiOsRedirectOutput
    360  *
    361  * PARAMETERS:  Destination         - file handle/pointer
    362  *
    363  * RETURN:      None
    364  *
    365  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
    366  *
    367  *****************************************************************************/
    368 
    369323void
    370 AcpiOsRedirectOutput(void *Destination)
     324AcpiOsRedirectOutput(void *destination)
    371325{
    372326    DEBUG_FUNCTION();
    373     AcpiGbl_OutputFile = Destination;
     327    AcpiGbl_OutputFile = destination;
    374328}
    375329
    376330
    377331/******************************************************************************
    378332 *
    379  * FUNCTION:    AcpiOsPrintf
     333 * FUNCTION:    AcpiOsPrintf
    380334 *
    381  * PARAMETERS:  fmt, ...            Standard printf format
     335 * PARAMETERS:  fmt, ...            Standard printf format
    382336 *
    383  * RETURN:      None
     337 * RETURN:      None
    384338 *
    385  * DESCRIPTION: Formatted output
     339 * DESCRIPTION: Formatted output
    386340 *
    387341 *****************************************************************************/
    388 
    389342void ACPI_INTERNAL_VAR_XFACE
    390 AcpiOsPrintf(const char *Fmt, ...)
     343AcpiOsPrintf(const char *fmt, ...)
    391344{
    392     va_list Args;
     345    va_list args;
     346
    393347    DEBUG_FUNCTION();
    394     va_start(Args, Fmt);
    395     AcpiOsVprintf(Fmt, Args);
    396     va_end(Args);
     348    va_start(args, fmt);
     349    AcpiOsVprintf(fmt, args);
     350    va_end(args);
    397351}
    398352
    399353
    400354/******************************************************************************
    401355 *
    402  * FUNCTION:    AcpiOsVprintf
     356 * FUNCTION:    AcpiOsVprintf
    403357 *
    404  * PARAMETERS:  fmt                 Standard printf format
    405  *              args                Argument list
     358 * PARAMETERS:  fmt                 Standard printf format
     359 *              args                Argument list
    406360 *
    407  * RETURN:      None
     361 * RETURN:      None
    408362 *
    409  * DESCRIPTION: Formatted output with argument list pointer
     363 * DESCRIPTION: Formatted output with argument list pointer
    410364 *
    411365 *****************************************************************************/
    412 
    413366void
    414 AcpiOsVprintf(const char *Fmt, va_list Args)
     367AcpiOsVprintf(const char *fmt, va_list args)
    415368{
    416369#ifndef _KERNEL_MODE
    417     INT32 Count = 0;
    418     UINT8 Flags;
     370    INT32 count = 0;
     371    UINT8 flags;
    419372
    420     Flags = AcpiGbl_DbOutputFlags;
    421     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
    422         /* Output is directable to either a file (if open) or the console */
    423         if (AcpiGbl_DebugFile) {
    424             /* Output file is open, send the output there */
    425             Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
    426         } else {
    427             /* No redirection, send output to console (once only!) */
    428             Flags |= ACPI_DB_CONSOLE_OUTPUT;
    429         }
    430     }
     373    flags = AcpiGbl_DbOutputFlags;
     374    if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
     375        // Output is directable to either a file (if open) or the console
     376        if (AcpiGbl_DebugFile) {
     377            // Output file is open, send the output there
     378            count = vfprintf(AcpiGbl_DebugFile, fmt, args);
     379        } else {
     380            // No redirection, send output to console (once only!)
     381            flags |= ACPI_DB_CONSOLE_OUTPUT;
     382        }
     383    }
    431384
    432     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
    433         Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
    434 
     385    if (flags & ACPI_DB_CONSOLE_OUTPUT) {
     386        count = vfprintf(AcpiGbl_OutputFile, fmt, args);
     387    }
    435388#else
    436389    static char outputBuffer[1024];
    437     vsnprintf(outputBuffer, 1024, Fmt, Args);
     390    vsnprintf(outputBuffer, 1024, fmt, args);
    438391    dprintf("%s", outputBuffer);
    439392#endif
    440393}
     
    442395
    443396/******************************************************************************
    444397 *
    445  * FUNCTION:    AcpiOsGetLine
     398 * FUNCTION:    AcpiOsGetLine
    446399 *
    447  * PARAMETERS:  fmt                 Standard printf format
    448  *              args                Argument list
     400 * PARAMETERS:  fmt                 Standard printf format
     401 *              args                Argument list
    449402 *
    450  * RETURN:      Actual bytes read
     403 * RETURN:      Actual bytes read
    451404 *
    452  * DESCRIPTION: Formatted input with argument list pointer
     405 * DESCRIPTION: Formatted input with argument list pointer
    453406 *
    454407 *****************************************************************************/
    455 
    456408UINT32
    457 AcpiOsGetLine(char *Buffer)
     409AcpiOsGetLine(char *buffer)
    458410{
    459     UINT32 i = 0;
     411    uint32 i = 0;
    460412
    461413#ifndef _KERNEL_MODE
    462     UINT8 Temp;
     414    uint8 temp;
    463415
    464416    for (i = 0; ; i++) {
    465         scanf("%1c", &Temp);
    466         if (!Temp || Temp == '\n')
     417        scanf("%1c", &temp);
     418        if (!temp || temp == '\n')
    467419            break;
    468420
    469         Buffer[i] = Temp;
     421        buffer[i] = temp;
    470422    }
    471423#endif
    472424
    473     /* Null terminate the buffer */
    474     Buffer[i] = 0;
    475 
    476     /* Return the number of bytes in the string */
    477     DEBUG_FUNCTION_F("buffer: \"%s\"; result: %lu", Buffer, (uint32)i);
     425    buffer[i] = 0;
     426    DEBUG_FUNCTION_F("buffer: \"%s\"; result: %lu", buffer, i);
    478427    return i;
    479428}
    480429
    481430/******************************************************************************
    482431 *
    483  * FUNCTION:    AcpiOsMapMemory
     432 * FUNCTION:    AcpiOsMapMemory
    484433 *
    485  * PARAMETERS:  where               Physical address of memory to be mapped
    486  *              length              How much memory to map
    487  *              there               Logical address of mapped memory
     434 * PARAMETERS:  where               Physical address of memory to be mapped
     435 *              length              How much memory to map
    488436 *
    489  * RETURN:      Pointer to mapped memory. Null on error.
     437 * RETURN:      Pointer to mapped memory. Null on error.
    490438 *
    491  * DESCRIPTION: Map physical memory into caller's address space
     439 * DESCRIPTION: Map physical memory into caller's address space
    492440 *
    493441 *****************************************************************************/
    494 
    495442void *
    496443AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS where, ACPI_SIZE length)
    497444{
     
    510457#else
    511458    return NULL;
    512459#endif
     460
     461    //return ACPI_TO_POINTER((ACPI_SIZE) where);
    513462}
    514463
    515464
    516465/******************************************************************************
    517466 *
    518  * FUNCTION:    AcpiOsUnmapMemory
     467 * FUNCTION:    AcpiOsUnmapMemory
    519468 *
    520  * PARAMETERS:  where               Logical address of memory to be unmapped
    521  *              length              How much memory to unmap
     469 * PARAMETERS:  where               Logical address of memory to be unmapped
     470 *              length              How much memory to unmap
    522471 *
    523  * RETURN:      None.
     472 * RETURN:      None.
    524473 *
    525  * DESCRIPTION: Delete a previously created mapping. Where and Length must
    526  *              correspond to a previous mapping exactly.
     474 * DESCRIPTION: Delete a previously created mapping. Where and Length must
     475 *              correspond to a previous mapping exactly.
    527476 *
    528477 *****************************************************************************/
    529 
    530478void
    531479AcpiOsUnmapMemory(void *where, ACPI_SIZE length)
    532480{
     
    537485
    538486/******************************************************************************
    539487 *
    540  * FUNCTION:    AcpiOsAllocate
     488 * FUNCTION:    AcpiOsAllocate
    541489 *
    542  * PARAMETERS:  Size                Amount to allocate, in bytes
     490 * PARAMETERS:  size                Amount to allocate, in bytes
    543491 *
    544  * RETURN:      Pointer to the new allocation. Null on error.
     492 * RETURN:      Pointer to the new allocation. Null on error.
    545493 *
    546  * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
     494 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
    547495 *
    548496 *****************************************************************************/
    549 
    550497void *
    551498AcpiOsAllocate(ACPI_SIZE size)
    552499{
    553     void *result = malloc((size_t)size);
    554     DEBUG_FUNCTION_VF("result: %p", result);
    555     return result;
     500    void *mem = (void *) malloc(size);
     501    DEBUG_FUNCTION_VF("result: %p", mem);
     502    return mem;
    556503}
    557504
    558505
    559506/******************************************************************************
    560507 *
    561  * FUNCTION:    AcpiOsFree
     508 * FUNCTION:    AcpiOsFree
    562509 *
    563  * PARAMETERS:  mem                 Pointer to previously allocated memory
     510 * PARAMETERS:  mem                 Pointer to previously allocated memory
    564511 *
    565  * RETURN:      None.
     512 * RETURN:      None.
    566513 *
    567  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
     514 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
    568515 *
    569516 *****************************************************************************/
    570 
    571517void
    572518AcpiOsFree(void *mem)
    573519{
    574520    DEBUG_FUNCTION_VF("mem: %p", mem);
    575     free(mem);
     521    free(mem);
    576522}
    577523
    578524
    579525/******************************************************************************
    580526 *
    581  * FUNCTION:    AcpiOsCreateSemaphore
     527 * FUNCTION:    AcpiOsCreateSemaphore
    582528 *
    583  * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
    584  *              OutHandle           - Where a handle will be returned
     529 * PARAMETERS:  initialUnits        - Units to be assigned to the new semaphore
     530 *              outHandle           - Where a handle will be returned
    585531 *
    586  * RETURN:      Status
     532 * RETURN:      Status
    587533 *
    588  * DESCRIPTION: Create an OS semaphore
     534 * DESCRIPTION: Create an OS semaphore
    589535 *
    590536 *****************************************************************************/
    591 
    592537ACPI_STATUS
    593 AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits,
    594     ACPI_HANDLE *OutHandle)
     538AcpiOsCreateSemaphore(UINT32 maxUnits, UINT32 initialUnits,
     539        ACPI_SEMAPHORE *outHandle)
    595540{
    596     *OutHandle = (ACPI_HANDLE)create_sem(InitialUnits, "acpi_sem");
     541    if (!outHandle)
     542        return AE_BAD_PARAMETER;
     543   
     544    *outHandle = create_sem(initialUnits, "acpi_sem");
    597545    DEBUG_FUNCTION_F("max: %lu; count: %lu; result: %ld",
    598         (uint32)MaxUnits, (uint32)InitialUnits, (sem_id)*OutHandle);
    599     if (*OutHandle < B_OK)
    600         return AE_ERROR;
    601     return AE_OK;
     546        maxUnits, initialUnits, *outHandle);
     547
     548    if (*outHandle >= B_OK)
     549        return AE_OK;
     550   
     551    return *outHandle == B_BAD_VALUE ? AE_BAD_PARAMETER : AE_NO_MEMORY;
    602552}
    603553
     554
    604555/******************************************************************************
    605556 *
    606  * FUNCTION:    AcpiOsDeleteSemaphore
     557 * FUNCTION:    AcpiOsDeleteSemaphore
    607558 *
    608  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
     559 * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
    609560 *
    610  * RETURN:      Status
     561 * RETURN:      Status
    611562 *
    612  * DESCRIPTION: Delete an OS semaphore
     563 * DESCRIPTION: Delete an OS semaphore
    613564 *
    614565 *****************************************************************************/
    615 
    616566ACPI_STATUS
    617 AcpiOsDeleteSemaphore(ACPI_HANDLE Handle)
     567AcpiOsDeleteSemaphore(ACPI_SEMAPHORE handle)
    618568{
    619     DEBUG_FUNCTION_F("sem: %ld", (sem_id)Handle);
    620     delete_sem((sem_id)Handle);
    621     return AE_OK;
     569    DEBUG_FUNCTION_F("sem: %ld", handle);   
     570    return delete_sem(handle) == B_OK ? AE_OK : AE_BAD_PARAMETER;
    622571}
    623572
    624573
    625574/******************************************************************************
    626575 *
    627  * FUNCTION:    AcpiOsWaitSemaphore
     576 * FUNCTION:    AcpiOsWaitSemaphore
    628577 *
    629  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
    630  *              Units               - How many units to wait for
    631  *              Timeout             - How long to wait (in milliseconds)
     578 * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
     579 *              units               - How many units to wait for
     580 *              timeout             - How long to wait
    632581 *
    633  * RETURN:      Status
     582 * RETURN:      Status
    634583 *
    635  * DESCRIPTION: Wait for units
     584 * DESCRIPTION: Wait for units
    636585 *
    637586 *****************************************************************************/
    638 
    639587ACPI_STATUS
    640 AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout)
     588AcpiOsWaitSemaphore(ACPI_SEMAPHORE handle, UINT32 units, UINT16 timeout)
    641589{
    642     ACPI_STATUS result;
     590    ACPI_STATUS result = AE_OK;
    643591    DEBUG_FUNCTION_VF("sem: %ld; count: %lu; timeout: %u",
    644         (sem_id)Handle, (uint32)Units, (uint16)Timeout);
    645     if (Timeout != ACPI_WAIT_FOREVER) {
    646         switch (acquire_sem_etc((sem_id)Handle, Units, B_RELATIVE_TIMEOUT,
    647             (bigtime_t)Timeout * 1000)) {
     592        handle, units, timeout);
     593
     594    if (timeout == ACPI_WAIT_FOREVER) {
     595        result = acquire_sem_etc(handle, units, 0, 0)
     596            == B_OK ? AE_OK : AE_BAD_PARAMETER;
     597    } else {
     598        switch (acquire_sem_etc(handle, units, B_RELATIVE_TIMEOUT,
     599            (bigtime_t)timeout * 1000)) {
     600            case B_OK:
     601                result = AE_OK;
     602                break;
     603            case B_INTERRUPTED:
    648604            case B_TIMED_OUT:
     605            case B_WOULD_BLOCK:
    649606                result = AE_TIME;
    650607                break;
    651608            case B_BAD_VALUE:
     609            default:
    652610                result = AE_BAD_PARAMETER;
    653611                break;
    654             case B_OK:
    655                 result = AE_OK;
    656                 break;
    657             default:
    658                 result = AE_ERROR;
    659                 break;
    660         }
    661     } else {
    662         result = acquire_sem_etc((sem_id)Handle, Units, 0, 0)
    663             == B_OK ? AE_OK : AE_BAD_PARAMETER;
     612        }       
    664613    }
    665 
    666614    DEBUG_FUNCTION_VF("result: %lu", (uint32)result);
    667     return result;
     615    return result;
    668616}
    669617
    670618
    671619/******************************************************************************
    672620 *
    673  * FUNCTION:    AcpiOsSignalSemaphore
     621 * FUNCTION:    AcpiOsSignalSemaphore
    674622 *
    675  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
    676  *              Units               - Number of units to send
     623 * PARAMETERS:  handle              - Handle returned by AcpiOsCreateSemaphore
     624 *              units               - Number of units to send
    677625 *
    678  * RETURN:      Status
     626 * RETURN:      Status
    679627 *
    680  * DESCRIPTION: Send units
     628 * DESCRIPTION: Send units
    681629 *
    682630 *****************************************************************************/
    683 
    684631ACPI_STATUS
    685 AcpiOsSignalSemaphore(ACPI_HANDLE Handle, UINT32 Units)
     632AcpiOsSignalSemaphore(ACPI_SEMAPHORE handle, UINT32 units)
    686633{
    687     DEBUG_FUNCTION_VF("sem: %ld; count: %lu", (sem_id)Handle,
    688         (uint32)Units);
    689     release_sem_etc((sem_id)Handle, Units, 0);
    690     return AE_OK;
     634    status_t result;
     635    DEBUG_FUNCTION_VF("sem: %ld; count: %lu", handle, units);
     636    // We can be called from interrupt handler, so don't reschedule
     637    result = release_sem_etc(handle, units, B_DO_NOT_RESCHEDULE);
     638    return result == B_OK ? AE_OK : AE_BAD_PARAMETER;
    691639}
    692640
    693641
     642/******************************************************************************
     643 *
     644 * FUNCTION:    Spinlock interfaces
     645 *
     646 * DESCRIPTION: Map these interfaces to semaphore interfaces
     647 *
     648 *****************************************************************************/
    694649ACPI_STATUS
    695 AcpiOsCreateLock(ACPI_HANDLE *OutHandle)
     650AcpiOsCreateLock(ACPI_SPINLOCK *outHandle)
    696651{
    697     *OutHandle = (ACPI_HANDLE)malloc(sizeof(spinlock));
    698     DEBUG_FUNCTION_F("result: %p", (spinlock *)*OutHandle);
    699     if (OutHandle == NULL)
     652    *outHandle = (ACPI_SPINLOCK) malloc(sizeof(spinlock));
     653    DEBUG_FUNCTION_F("result: %p", *outHandle);
     654    if (*outHandle == NULL)
    700655        return AE_NO_MEMORY;
    701 
    702     *((spinlock *)(*OutHandle)) = 0;
    703     return AE_OK;
     656   
     657    **outHandle = 0;
     658    return AE_OK;
    704659}
    705660
     661
    706662void
    707 AcpiOsDeleteLock(ACPI_HANDLE Handle)
     663AcpiOsDeleteLock(ACPI_SPINLOCK handle)
    708664{
    709665    DEBUG_FUNCTION();
    710     free(Handle);
     666    free(handle);
    711667}
    712668
    713669
    714670ACPI_CPU_FLAGS
    715 AcpiOsAcquireLock(ACPI_HANDLE Handle)
     671AcpiOsAcquireLock(ACPI_SPINLOCK handle)
    716672{
    717673    cpu_status cpu;
    718     DEBUG_FUNCTION_F("spinlock: %p", (spinlock *)Handle);
     674    DEBUG_FUNCTION_F("spinlock: %p", handle);
    719675    cpu = disable_interrupts();
    720     acquire_spinlock((spinlock *)Handle);
    721     return cpu;
     676    acquire_spinlock(handle);
     677    return cpu; 
    722678}
    723679
    724680
    725681void
    726 AcpiOsReleaseLock(ACPI_HANDLE Handle, ACPI_CPU_FLAGS Flags)
     682AcpiOsReleaseLock(ACPI_SPINLOCK handle, ACPI_CPU_FLAGS flags)
    727683{
    728     release_spinlock((spinlock *)Handle);
    729     restore_interrupts((cpu_status)Flags);
    730     DEBUG_FUNCTION_F("spinlock: %p", (spinlock *)Handle);
     684    release_spinlock(handle);
     685    restore_interrupts(flags);
     686    DEBUG_FUNCTION_F("spinlock: %p", handle);
    731687}
    732688
    733689
    734690/******************************************************************************
    735691 *
    736  * FUNCTION:    AcpiOsInstallInterruptHandler
     692 * FUNCTION:    AcpiOsInstallInterruptHandler
    737693 *
    738  * PARAMETERS:  InterruptNumber     Level handler should respond to.
    739  *              Isr                 Address of the ACPI interrupt handler
    740  *              ExceptPtr           Where status is returned
     694 * PARAMETERS:  interruptNumber     Level handler should respond to.
     695 *              Isr                 Address of the ACPI interrupt handler
     696 *              ExceptPtr           Where status is returned
    741697 *
    742  * RETURN:      Handle to the newly installed handler.
     698 * RETURN:      Handle to the newly installed handler.
    743699 *
    744  * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
    745  *              OS-independent handler.
     700 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
     701 *              OS-independent handler.
    746702 *
    747703 *****************************************************************************/
    748 
    749704UINT32
    750 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber,
    751     ACPI_OSD_HANDLER ServiceRoutine, void *Context)
     705AcpiOsInstallInterruptHandler(UINT32 interruptNumber,
     706        ACPI_OSD_HANDLER serviceRoutine, void *context)
    752707{
    753     DEBUG_FUNCTION_F("vector: %lu; handler: %p; data: %p",
    754         (uint32)InterruptNumber, ServiceRoutine, Context);
     708    status_t result;
     709    DEBUG_FUNCTION_F("vector: %lu; handler: %p context %p",
     710        interruptNumber, serviceRoutine, context);
     711
    755712#ifdef _KERNEL_MODE
    756     /*  It so happens that the Haiku and ACPI-CA interrupt handler routines
    757         return the same values with the same meanings */
    758     sInterruptHandlerData[InterruptNumber] = Context;
    759     return install_io_interrupt_handler(InterruptNumber,
    760         (interrupt_handler)ServiceRoutine, Context, 0) == B_OK ? AE_OK
    761         : AE_ERROR;
     713    // It so happens that the Haiku and ACPI-CA interrupt handler routines
     714    // return the same values with the same meanings
     715    sInterruptHandlerData[interruptNumber] = context;
     716    result = install_io_interrupt_handler(interruptNumber,
     717        (interrupt_handler)serviceRoutine, context, 0);
     718
     719    DEBUG_FUNCTION_F("vector: %lu; handler: %p context %p returned %d",
     720        interruptNumber, serviceRoutine, context, result);
     721   
     722    return result == B_OK ? AE_OK : AE_BAD_PARAMETER;
    762723#else
    763     return AE_ERROR;
     724    return AE_BAD_PARAMETER;
    764725#endif
    765726}
    766727
    767728
    768729/******************************************************************************
    769730 *
    770  * FUNCTION:    AcpiOsRemoveInterruptHandler
     731 * FUNCTION:    AcpiOsRemoveInterruptHandler
    771732 *
    772  * PARAMETERS:  Handle              Returned when handler was installed
     733 * PARAMETERS:  Handle              Returned when handler was installed
    773734 *
    774  * RETURN:      Status
     735 * RETURN:      Status
    775736 *
    776  * DESCRIPTION: Uninstalls an interrupt handler.
     737 * DESCRIPTION: Uninstalls an interrupt handler.
    777738 *
    778739 *****************************************************************************/
    779 
    780740ACPI_STATUS
    781 AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber,
    782     ACPI_OSD_HANDLER ServiceRoutine)
     741AcpiOsRemoveInterruptHandler(UINT32 interruptNumber,
     742        ACPI_OSD_HANDLER serviceRoutine)
    783743{
    784     DEBUG_FUNCTION_F("vector: %lu; handler: %p", (uint32)InterruptNumber,
    785         ServiceRoutine);
     744    DEBUG_FUNCTION_F("vector: %lu; handler: %p", interruptNumber,
     745        serviceRoutine);
    786746#ifdef _KERNEL_MODE
    787     remove_io_interrupt_handler(InterruptNumber,
    788         (interrupt_handler)ServiceRoutine,
    789         sInterruptHandlerData[InterruptNumber]);
     747    remove_io_interrupt_handler(interruptNumber,
     748        (interrupt_handler) serviceRoutine,
     749        sInterruptHandlerData[interruptNumber]);
    790750    return AE_OK;
    791751#else
    792752    return AE_ERROR;
     
    794754}
    795755
    796756
     757
    797758/******************************************************************************
    798759 *
    799  * FUNCTION:    AcpiOsExecute
     760 * FUNCTION:    AcpiOsExecute
    800761 *
    801  * PARAMETERS:  Type            - Type of execution
    802  *              Function        - Address of the function to execute
    803  *              Context         - Passed as a parameter to the function
     762 * PARAMETERS:  type            - Type of execution
     763 *              function        - Address of the function to execute
     764 *              context         - Passed as a parameter to the function
    804765 *
    805  * RETURN:      Status.
     766 * RETURN:      Status.
    806767 *
    807  * DESCRIPTION: Execute a new thread
     768 * DESCRIPTION: Execute a new thread
    808769 *
    809770 *****************************************************************************/
    810 
    811771ACPI_STATUS
    812 AcpiOsExecute(ACPI_EXECUTE_TYPE Type, ACPI_OSD_EXEC_CALLBACK Function,
    813     void *Context)
     772AcpiOsExecute(ACPI_EXECUTE_TYPE type, ACPI_OSD_EXEC_CALLBACK  function,
     773        void *context)
    814774{
    815775    DEBUG_FUNCTION();
    816     switch (Type) {
     776/* TODO: Prioritize urgent?
     777    switch (type) {
    817778        case OSL_GLOBAL_LOCK_HANDLER:
    818779        case OSL_NOTIFY_HANDLER:
    819780        case OSL_GPE_HANDLER:
     
    822783        case OSL_EC_BURST_HANDLER:
    823784            break;
    824785    }
    825 
    826     if (gDPC->queue_dpc(gDPCHandle, Function, Context) != B_OK)
    827         return AE_ERROR;
    828 
     786*/
     787    if (gDPC->queue_dpc(gDPCHandle, function, context) != B_OK) {
     788        DEBUG_FUNCTION_F("Serious failure in AcpiOsExecute! function: %p",
     789            function);
     790        return AE_BAD_PARAMETER;
     791    }
    829792    return AE_OK;
    830793}
    831794
    832795
    833796/******************************************************************************
    834797 *
    835  * FUNCTION:    AcpiOsBreakpoint
     798 * FUNCTION:    AcpiOsStall
    836799 *
    837  * PARAMETERS:  Msg                 Message to print
     800 * PARAMETERS:  microseconds        To sleep
    838801 *
    839  * RETURN:      Status
     802 * RETURN:      Blocks until sleep is completed.
    840803 *
    841  * DESCRIPTION: Print a message and break to the debugger.
     804 * DESCRIPTION: Sleep at microsecond granularity
    842805 *
    843806 *****************************************************************************/
    844 
    845 #if 0
    846 ACPI_STATUS
    847 AcpiOsBreakpoint(char *Msg)
    848 {
    849     if (Msg != NULL)
    850         kernel_debugger ("AcpiOsBreakpoint: %s ****\n", Msg);
    851     else
    852         kernel_debugger ("At AcpiOsBreakpoint ****\n");
    853 
    854     return AE_OK;
    855 }
    856 #endif
    857 
    858 /******************************************************************************
    859  *
    860  * FUNCTION:    AcpiOsStall
    861  *
    862  * PARAMETERS:  microseconds        To sleep
    863  *
    864  * RETURN:      Blocks until sleep is completed.
    865  *
    866  * DESCRIPTION: Sleep at microsecond granularity
    867  *
    868  *****************************************************************************/
    869 
    870807void
    871808AcpiOsStall(UINT32 microseconds)
    872809{
    873     DEBUG_FUNCTION_F("microseconds: %lu", (uint32)microseconds);
    874     spin(microseconds);
     810    DEBUG_FUNCTION_F("microseconds: %lu", microseconds);
     811    if (microseconds)
     812        spin(microseconds);
    875813}
    876814
    877815
    878816/******************************************************************************
    879817 *
    880  * FUNCTION:    AcpiOsSleep
     818 * FUNCTION:    AcpiOsSleep
    881819 *
    882  * PARAMETERS:  milliseconds        To sleep
     820 * PARAMETERS:  milliseconds        To sleep
    883821 *
    884  * RETURN:      Blocks until sleep is completed.
     822 * RETURN:      Blocks until sleep is completed.
    885823 *
    886  * DESCRIPTION: Sleep at millisecond granularity
     824 * DESCRIPTION: Sleep at millisecond granularity
    887825 *
    888826 *****************************************************************************/
    889 
    890827void
    891828AcpiOsSleep(ACPI_INTEGER milliseconds)
    892829{
    893     DEBUG_FUNCTION_F("milliseconds: %lu", (uint32)milliseconds);
    894     snooze(milliseconds * 1000); /* Sleep for micro seconds */
     830    DEBUG_FUNCTION_F("milliseconds: %lu", milliseconds);
     831    snooze(milliseconds * 1000);
    895832}
    896833
     834
    897835/******************************************************************************
    898836 *
    899  * FUNCTION:    AcpiOsGetTimer
     837 * FUNCTION:    AcpiOsGetTimer
    900838 *
    901  * PARAMETERS:  None
     839 * PARAMETERS:  None
    902840 *
    903  * RETURN:      Current time in 100 nanosecond units
     841 * RETURN:      Current time in 100 nanosecond units
    904842 *
    905  * DESCRIPTION: Get the current system time
     843 * DESCRIPTION: Get the current system time
    906844 *
    907845 *****************************************************************************/
    908 
    909846UINT64
    910 AcpiOsGetTimer (void)
     847AcpiOsGetTimer()
    911848{
    912849    DEBUG_FUNCTION();
    913850    return system_time() * 10;
     
    916853
    917854/******************************************************************************
    918855 *
    919  * FUNCTION:    AcpiOsValidateInterface
     856 * FUNCTION:    AcpiOsValidateInterface
    920857 *
    921  * PARAMETERS:  Interface           - Requested interface to be validated
     858 * PARAMETERS:  interface           - Requested interface to be validated
    922859 *
    923  * RETURN:      AE_OK if interface is supported, AE_SUPPORT otherwise
     860 * RETURN:      AE_OK if interface is supported, AE_SUPPORT otherwise
    924861 *
    925  * DESCRIPTION: Match an interface string to the interfaces supported by the
    926  *              host. Strings originate from an AML call to the _OSI method.
     862 * DESCRIPTION: Match an interface string to the interfaces supported by the
     863 *              host. Strings originate from an AML call to the _OSI method.
    927864 *
    928865 *****************************************************************************/
    929 
    930866ACPI_STATUS
    931 AcpiOsValidateInterface(char *Interface)
     867AcpiOsValidateInterface(char *interface)
    932868{
    933     DEBUG_FUNCTION_F("interface: \"%s\"", Interface);
    934     return AE_SUPPORT;
     869    DEBUG_FUNCTION_F("interface: \"%s\"", interface);
     870    //TODO: This looks unimplemented.
     871    return AE_SUPPORT;
    935872}
    936873
    937874
    938875/******************************************************************************
    939876 *
    940  * FUNCTION:    AcpiOsReadPciConfiguration
     877 * FUNCTION:    AcpiOsReadPciConfiguration
    941878 *
    942  * PARAMETERS:  PciId               Seg/Bus/Dev
    943  *              Register            Device Register
    944  *              Value               Buffer where value is placed
    945  *              Width               Number of bits
     879 * PARAMETERS:  pciId               Seg/Bus/Dev
     880 *              reg                 Device Register
     881 *              value               Buffer where value is placed
     882 *              width               Number of bits
    946883 *
    947  * RETURN:      Status
     884 * RETURN:      Status
    948885 *
    949  * DESCRIPTION: Read data from PCI configuration space
     886 * DESCRIPTION: Read data from PCI configuration space
    950887 *
    951888 *****************************************************************************/
    952 
    953889ACPI_STATUS
    954 AcpiOsReadPciConfiguration(ACPI_PCI_ID *pciId, UINT32 offset, void *value,
    955     UINT32 width)
     890AcpiOsReadPciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg, void *value,
     891        UINT32 width)
    956892{
    957893#ifdef _KERNEL_MODE
    958894    UINT32 val = gPCIManager->read_pci_config(
    959         pciId->Bus, pciId->Device, pciId->Function, offset, width / 8);
     895        pciId->Bus, pciId->Device, pciId->Function, reg, width / 8);
    960896    DEBUG_FUNCTION();
    961897    switch (width) {
    962898        case 8:
    963             *(UINT8 *)value = val;
     899            *(UINT8 *) value = val;
    964900            break;
    965901        case 16:
    966             *(UINT16 *)value = val;
     902            *(UINT16 *) value = val;
    967903            break;
    968904        case 32:
    969             *(UINT32 *)value = val;
     905            *(UINT32 *) value = val;
    970906            break;
    971907        default:
    972             dprintf("AcpiOsReadPciConfiguration unhandled value width: %u\n",
    973                 width);
     908            dprintf("AcpiOsReadPciConfiguration unhandled width: %u\n", width);
    974909            return AE_ERROR;
    975910    }
    976 
    977911    return AE_OK;
    978912#else
    979913    return AE_ERROR;
     
    983917
    984918/******************************************************************************
    985919 *
    986  * FUNCTION:    AcpiOsWritePciConfiguration
     920 * FUNCTION:    AcpiOsWritePciConfiguration
    987921 *
    988  * PARAMETERS:  PciId               Seg/Bus/Dev
    989  *              Register            Device Register
    990  *              Value               Value to be written
    991  *              Width               Number of bits
     922 * PARAMETERS:  pciId               Seg/Bus/Dev
     923 *              reg                 Device Register
     924 *              value               Value to be written
     925 *              width               Number of bits
    992926 *
    993  * RETURN:      Status.
     927 * RETURN:      Status.
    994928 *
    995  * DESCRIPTION: Write data to PCI configuration space
     929 * DESCRIPTION: Write data to PCI configuration space
    996930 *
    997931 *****************************************************************************/
    998 
    999932ACPI_STATUS
    1000 AcpiOsWritePciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register,
    1001     ACPI_INTEGER Value, UINT32 Width)
     933AcpiOsWritePciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg,
     934        ACPI_INTEGER value, UINT32 width)
    1002935{
    1003936#ifdef _KERNEL_MODE
    1004937    DEBUG_FUNCTION();
    1005938    gPCIManager->write_pci_config(
    1006         PciId->Bus, PciId->Device, PciId->Function, Register, Width / 8, Value);
     939        pciId->Bus, pciId->Device, pciId->Function, reg, width / 8, value);
    1007940    return AE_OK;
    1008941#else
    1009942    return AE_ERROR;
    1010943#endif
    1011944}
    1012945
    1013 /* TEMPORARY STUB FUNCTION */
     946
    1014947void
    1015 AcpiOsDerivePciId(ACPI_HANDLE rhandle, ACPI_HANDLE chandle, ACPI_PCI_ID **PciId)
     948AcpiOsDerivePciId(ACPI_HANDLE rhandle, ACPI_HANDLE chandle, ACPI_PCI_ID **pciId)
    1016949{
     950// TODO: Implement this!   
    1017951}
    1018952
    1019953
    1020954/******************************************************************************
    1021955 *
    1022  * FUNCTION:    AcpiOsReadPort
     956 * FUNCTION:    AcpiOsReadPort
    1023957 *
    1024  * PARAMETERS:  Address             Address of I/O port/register to read
    1025  *              Value               Where value is placed
    1026  *              Width               Number of bits
     958 * PARAMETERS:  address             Address of I/O port/register to read
     959 *              Value               Where value is placed
     960 *              width               Number of bits
    1027961 *
    1028  * RETURN:      Value read from port
     962 * RETURN:      Value read from port
    1029963 *
    1030  * DESCRIPTION: Read data from an I/O port or register
     964 * DESCRIPTION: Read data from an I/O port or register
    1031965 *
    1032966 *****************************************************************************/
    1033 
    1034967ACPI_STATUS
    1035 AcpiOsReadPort(ACPI_IO_ADDRESS Address, UINT32 *Value, UINT32 Width)
     968AcpiOsReadPort(ACPI_IO_ADDRESS address, UINT32 *value, UINT32 width)
    1036969{
    1037970#ifdef _KERNEL_MODE
    1038     DEBUG_FUNCTION_F("addr: 0x%08lx; width: %lu", (addr_t)Address,
    1039         (uint32)Width);
    1040     switch (Width) {
     971    DEBUG_FUNCTION_F("addr: 0x%08lx; width: %lu", (addr_t)address, width);
     972    switch (width) {
    1041973        case 8:
    1042             *Value = gPCIManager->read_io_8(Address);
     974            *value = gPCIManager->read_io_8(address);
    1043975            break;
    1044976
    1045977        case 16:
    1046             *Value = gPCIManager->read_io_16(Address);
     978            *value = gPCIManager->read_io_16(address);
    1047979            break;
    1048980
    1049981        case 32:
    1050             *Value = gPCIManager->read_io_32(Address);
     982            *value = gPCIManager->read_io_32(address);
    1051983            break;
    1052984
    1053985        default:
    1054             dprintf("AcpiOsReadPort: unhandeld width: %u\n", Width);
     986            dprintf("AcpiOsReadPort: unhandeld width: %u\n", width);
    1055987            return AE_ERROR;
    1056988    }
    1057989
     
    1064996
    1065997/******************************************************************************
    1066998 *
    1067  * FUNCTION:    AcpiOsWritePort
     999 * FUNCTION:    AcpiOsWritePort
    10681000 *
    1069  * PARAMETERS:  Address             Address of I/O port/register to write
    1070  *              Value               Value to write
    1071  *              Width               Number of bits
     1001 * PARAMETERS:  address             Address of I/O port/register to write
     1002 *              value               Value to write
     1003 *              width               Number of bits
    10721004 *
    1073  * RETURN:      None
     1005 * RETURN:      None
    10741006 *
    1075  * DESCRIPTION: Write data to an I/O port or register
     1007 * DESCRIPTION: Write data to an I/O port or register
    10761008 *
    10771009 *****************************************************************************/
    1078 
    10791010ACPI_STATUS
    1080 AcpiOsWritePort(ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width)
     1011AcpiOsWritePort(ACPI_IO_ADDRESS address, UINT32 value, UINT32 width)
    10811012{
    10821013#ifdef _KERNEL_MODE
    10831014    DEBUG_FUNCTION_F("addr: 0x%08lx; value: %lu; width: %lu",
    1084         (addr_t)Address, (uint32)Value, (uint32)Width);
    1085     switch (Width) {
     1015        (addr_t)address, value, width);
     1016    switch (width) {
    10861017        case 8:
    1087             gPCIManager->write_io_8(Address, Value);
     1018            gPCIManager->write_io_8(address, value);
    10881019            break;
    10891020
    10901021        case 16:
    1091             gPCIManager->write_io_16(Address,Value);
     1022            gPCIManager->write_io_16(address,value);
    10921023            break;
    10931024
    10941025        case 32:
    1095             gPCIManager->write_io_32(Address,Value);
     1026            gPCIManager->write_io_32(address,value);
    10961027            break;
    10971028
    10981029        default:
    1099             dprintf("AcpiOsWritePort: unhandeld width: %u\n", Width);
     1030            dprintf("AcpiOsWritePort: unhandeld width: %u\n", width);
    11001031            return AE_ERROR;
    11011032    }
    11021033
     
    11091040
    11101041/******************************************************************************
    11111042 *
    1112  * FUNCTION:    AcpiOsReadMemory
     1043 * FUNCTION:    AcpiOsReadMemory
    11131044 *
    1114  * PARAMETERS:  Address             Physical Memory Address to read
    1115  *              Value               Where value is placed
    1116  *              Width               Number of bits
     1045 * PARAMETERS:  address             Physical Memory Address to read
     1046 *              value               Where value is placed
     1047 *              width               Number of bits
    11171048 *
    1118  * RETURN:      Value read from physical memory address
     1049 * RETURN:      Value read from physical memory address
    11191050 *
    1120  * DESCRIPTION: Read data from a physical memory address
     1051 * DESCRIPTION: Read data from a physical memory address
    11211052 *
    11221053 *****************************************************************************/
    1123 
    11241054ACPI_STATUS
    1125 AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width)
     1055AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS address, UINT32 *value, UINT32 width)
    11261056{
    11271057#ifdef _KERNEL_MODE
    1128     if (vm_memcpy_from_physical(Value, (addr_t)Address, Width / 8, false)
    1129             != B_OK) {
     1058    if (vm_memcpy_from_physical(value, (addr_t)address, width / 8, false)
     1059        != B_OK) {
    11301060        return AE_ERROR;
    11311061    }
    11321062    return AE_OK;
     
    11381068
    11391069/******************************************************************************
    11401070 *
    1141  * FUNCTION:    AcpiOsWriteMemory
     1071 * FUNCTION:    AcpiOsWriteMemory
    11421072 *
    1143  * PARAMETERS:  Address             Physical Memory Address to write
    1144  *              Value               Value to write
    1145  *              Width               Number of bits
     1073 * PARAMETERS:  address             Physical Memory Address to write
     1074 *              value               Value to write
     1075 *              width               Number of bits
    11461076 *
    1147  * RETURN:      None
     1077 * RETURN:      None
    11481078 *
    1149  * DESCRIPTION: Write data to a physical memory address
     1079 * DESCRIPTION: Write data to a physical memory address
    11501080 *
    11511081 *****************************************************************************/
    1152 
    11531082ACPI_STATUS
    1154 AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 Value, UINT32 Width)
     1083AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS address, UINT32 value, UINT32 width)
    11551084{
    11561085#ifdef _KERNEL_MODE
    1157     if (vm_memcpy_to_physical((addr_t)Address, &Value, Width / 8, false)
     1086    if (vm_memcpy_to_physical((addr_t)address, &value, width / 8, false)
    11581087            != B_OK) {
    11591088        return AE_ERROR;
    11601089    }
     
    11651094}
    11661095
    11671096
    1168 UINT32
    1169 AcpiOsGetThreadId(void)
     1097/******************************************************************************
     1098 *
     1099 * FUNCTION:    AcpiOsReadable
     1100 *
     1101 * PARAMETERS:  pointer             - Area to be verified
     1102 *              length              - Size of area
     1103 *
     1104 * RETURN:      TRUE if readable for entire length
     1105 *
     1106 * DESCRIPTION: Verify that a pointer is valid for reading
     1107 *
     1108 *****************************************************************************/
     1109BOOLEAN
     1110AcpiOsReadable(void *pointer, ACPI_SIZE Length)
    11701111{
     1112    //TODO: Look if this is really ok.
     1113    DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length);
     1114    return TRUE;
     1115}
     1116
     1117
     1118/******************************************************************************
     1119 *
     1120 * FUNCTION:    AcpiOsWritable
     1121 *
     1122 * PARAMETERS:  pointer             - Area to be verified
     1123 *              length              - Size of area
     1124 *
     1125 * RETURN:      TRUE if writable for entire length
     1126 *
     1127 * DESCRIPTION: Verify that a pointer is valid for writing
     1128 *
     1129 *****************************************************************************/
     1130BOOLEAN
     1131AcpiOsWritable(void *pointer, ACPI_SIZE length)
     1132{
     1133    //TODO: Look if this is really ok.
     1134    DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length);
     1135    return TRUE;
     1136}
     1137
     1138
     1139/******************************************************************************
     1140 *
     1141 * FUNCTION:    AcpiOsGetThreadId
     1142 *
     1143 * PARAMETERS:  None
     1144 *
     1145 * RETURN:      Id of the running thread
     1146 *
     1147 * DESCRIPTION: Get the Id of the current (running) thread
     1148 *
     1149 * NOTE:        The environment header should contain this line:
     1150 *                  #define ACPI_THREAD_ID pthread_t
     1151 *
     1152 *****************************************************************************/
     1153ACPI_THREAD_ID
     1154AcpiOsGetThreadId()
     1155{
     1156    thread_id thread = find_thread(NULL);
     1157    return thread;
     1158
     1159    //TODO: Look if this is needed.
    11711160    // ACPI treats a 0 return as an error,
    11721161    // but we are thread 0 in early boot
    1173     thread_id thread = find_thread(NULL);
    1174     return thread == 0 ? 1 : thread;
     1162    //return thread == 0 ? 1 : thread;
    11751163}
    11761164
    11771165
    11781166/******************************************************************************
    11791167 *
    1180  * FUNCTION:    AcpiOsSignal
     1168 * FUNCTION:    AcpiOsSignal
    11811169 *
    1182  * PARAMETERS:  Function            ACPI CA signal function code
    1183  *              Info                Pointer to function-dependent structure
     1170 * PARAMETERS:  function            ACPI CA signal function code
     1171 *              info                Pointer to function-dependent structure
    11841172 *
    1185  * RETURN:      Status
     1173 * RETURN:      Status
    11861174 *
    1187  * DESCRIPTION: Miscellaneous functions
     1175 * DESCRIPTION: Miscellaneous functions. Example implementation only.
    11881176 *
    11891177 *****************************************************************************/
    1190 
    11911178ACPI_STATUS
    1192 AcpiOsSignal(UINT32 Function, void *Info)
     1179AcpiOsSignal(UINT32 function, void *info)
    11931180{
    11941181    DEBUG_FUNCTION();
    1195     switch (Function) {
     1182    switch (function) {
    11961183        case ACPI_SIGNAL_FATAL:
    11971184#ifdef _KERNEL_MODE
    1198             if (Info != NULL)
    1199                 panic(Info);
    1200             else
    1201                 panic("AcpiOsSignal: fatal");
     1185            panic(info == NULL ? "AcpiOsSignal: fatal" : info);
    12021186            break;
    12031187#endif
    1204 
    12051188        case ACPI_SIGNAL_BREAKPOINT:
    1206             if (Info != NULL)
    1207                 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);
     1189            if (info != NULL)
     1190                AcpiOsPrintf("AcpiOsBreakpoint: %s ****\n", info);
    12081191            else
    1209                 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
     1192                AcpiOsPrintf("At AcpiOsBreakpoint ****\n");
    12101193            break;
    12111194    }
    12121195
  • src/add-ons/kernel/bus_managers/acpi/acpi_busman.c

     
    7979        case B_MODULE_INIT:
    8080        {
    8181            ACPI_STATUS status;
     82            uint32 flags;
     83            void *settings;
    8284            bool acpiDisabled = false;
    83             void *settings;
     85            bool acpiAvoidFullInit = false;
    8486
    8587            settings = load_driver_settings("kernel");
    8688            if (settings != NULL) {
    8789                acpiDisabled = !get_driver_boolean_parameter(settings, "acpi",
    8890                    false, false);
     91                acpiAvoidFullInit = get_driver_boolean_parameter(settings,
     92                    "acpi_avoid_full_init", false, false);
    8993                unload_driver_settings(settings);
    9094            }
    9195
     
    103107                ERROR("ACPI disabled\n");
    104108                return ENOSYS;
    105109            }
     110            AcpiGbl_EnableInterpreterSlack = true;
     111//          AcpiGbl_CreateOSIMethod = true;
    106112
    107113#ifdef ACPI_DEBUG_OUTPUT
    108114            AcpiDbgLevel = ACPI_DEBUG_ALL | ACPI_LV_VERBOSE;
     
    130136                goto err;
    131137            }
    132138
     139            flags = acpiAvoidFullInit ?
     140                    ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT :
     141                    ACPI_FULL_INITIALIZATION;
     142           
     143            // FreeBSD seems to pass in the above flags here as
     144            // well but specs don't define ACPI_NO_DEVICE_INIT
     145            // and ACPI_NO_OBJECT_INIT here.
    133146            status = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION);
    134147            if (status != AE_OK) {
    135148                ERROR("AcpiEnableSubsystem failed (%s)\n",
     
    137150                goto err;
    138151            }
    139152   
     153            status = AcpiInitializeObjects(flags);
     154            if (status != AE_OK) {
     155                ERROR("AcpiInitializeObjects failed (%s)\n",
     156                    AcpiFormatException(status));
     157                goto err;
     158            }
     159
    140160            /* Phew. Now in ACPI mode */
    141161            TRACE("ACPI initialized\n");
    142162            return B_OK;
     
    545565    if ((AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) == 0)
    546566        return B_UNSUPPORTED;
    547567
    548     status = AcpiWrite(AcpiGbl_FADT.ResetValue,
    549         &AcpiGbl_FADT.ResetRegister);
     568    status = AcpiWrite(AcpiGbl_FADT.ResetValue, &AcpiGbl_FADT.ResetRegister);
    550569   
    551570    if (status != AE_OK) {
    552571        ERROR("Reset failed, status = %d\n", status);