Ticket #4152: acpi.patch
File acpi.patch, 50.3 KB (added by , 15 years ago) |
---|
-
build/jam/HaikuImage
467 467 468 468 # boot module links 469 469 AddBootModuleSymlinksToHaikuImage 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 471 471 $(IDE_ONLY)ide scsi usb 472 472 $(PPC_ONLY)openpic 473 473 $(ATA_ONLY)ata_adapter $(IDE_ONLY)ide_adapter locked_pool scsi_periph -
data/settings/kernel/drivers/kernel
55 55 56 56 #acpi true 57 57 # 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
117 117 #ifndef __ACHAIKU_H__ 118 118 #define __ACHAIKU_H__ 119 119 120 /* Haiku uses GCC */121 122 120 #include "acgcc.h" 123 121 124 122 #include <SupportDefs.h> 125 123 126 /*#ifdef _LP64127 #define ACPI_MACHINE_WIDTH 64128 #else*/129 #define ACPI_MACHINE_WIDTH 32 /* Haiku always 32 bit right now */130 /*#endif*/131 124 132 #define COMPILER_DEPENDENT_INT64 int64 133 #define COMPILER_DEPENDENT_UINT64 uint64 125 /* Host-dependent types and defines for user- and kernel-space ACPICA */ 134 126 135 # ifdef _KERNEL_MODE136 /* #include "opt_acpi.h" collect build-time options here */ 127 #define ACPI_USE_SYSTEM_CLIBRARY 128 #define ACPI_USE_STANDARD_HEADERS 137 129 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 */ 142 134 143 #define asm __asm 144 145 #define ACPI_USE_LOCAL_CACHE 135 //#define ACPI_MUTEX_DEBUG 146 136 #define ACPI_USE_NATIVE_DIVIDE 147 137 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 149 142 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 154 145 146 /* TODO: Add 64 bit when Haiku goes 64 bit */ 147 #define ACPI_MACHINE_WIDTH 32 155 148 156 #define ACPI_FLUSH_CPU_CACHE() __asm __volatile("wbinvd");157 149 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 */ 171 152 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> 175 154 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 176 163 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \ 177 164 do { \ 178 165 __asm __volatile( \ … … 206 193 : "edx"); \ 207 194 } while (0) 208 195 209 210 196 #else /* _KERNEL_MODE */ 197 /* Host-dependent types and defines for user-space ACPICA */ 211 198 212 # include <ctype.h>199 #error "We only support kernel mode ACPI atm." 213 200 214 /* Not building kernel code, so use libc */215 #define ACPI_USE_STANDARD_HEADERS216 #define ACPI_FLUSH_CPU_CACHE()217 218 #define __cli()219 #define __sti()220 221 /* XXX */222 #define __inline inline223 224 201 #endif /* _KERNEL_MODE */ 225 226 /* Always use Haiku code over our local versions */227 #define ACPI_USE_SYSTEM_CLIBRARY228 #define ACPI_USE_NATIVE_DIVIDE229 230 231 202 #endif /* __ACHAIKU_H__ */ -
src/add-ons/kernel/bus_managers/acpi/oshaiku.c
114 114 *****************************************************************************/ 115 115 116 116 117 /*118 * These interfaces are required in order to compile the ASL compiler under119 * BeOS/Haiku.120 */121 122 117 #include <stdio.h> 123 #include <stdlib.h>124 #include <stdarg.h>125 118 #include <unistd.h> 126 119 #include <sys/time.h> 127 120 #include <OS.h> 128 129 #ifdef _KERNEL_MODE130 #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 #endif138 121 122 139 123 #include "acpi.h" 140 124 #include "accommon.h" 141 125 #include "amlcode.h" 142 126 #include "acparser.h" 143 127 #include "acdebug.h" 144 128 145 #define _COMPONENT ACPI_OS_SERVICES146 ACPI_MODULE_NAME ("oshaiku")147 129 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> 150 135 151 static uint32 sACPIRoot = 0;152 static void *sInterruptHandlerData[32];153 136 154 #define DEBUG_OSHAIKU 0 /* verbosity level 0 = off, 1 = normal, 2 = all */ 137 extern pci_module_info *gPCIManager; 138 extern dpc_module_info *gDPC; 139 extern void *gDPCHandle; 140 #endif 155 141 156 #if DEBUG_OSHAIKU > 0 142 ACPI_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 157 156 # define DEBUG_FUNCTION() \ 158 157 dprintf("acpi[%ld]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__); 159 158 # define DEBUG_FUNCTION_F(x, y...) \ 160 159 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 163 166 # define DEBUG_FUNCTION_V() \ 164 167 dprintf("acpi[%ld]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__); 165 168 # define DEBUG_FUNCTION_VF(x, y...) \ 166 169 dprintf("acpi[%ld]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y); 167 # else168 # define DEBUG_FUNCTION_V() \169 /* nothing */170 # define DEBUG_FUNCTION_VF(x, y...) \171 /* nothing */172 170 # endif 173 #else174 # 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 */182 171 #endif 183 172 173 174 extern FILE *AcpiGbl_DebugFile; 175 FILE *AcpiGbl_OutputFile; 176 177 static uint32 sACPIRoot = 0; 178 static 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 184 191 /****************************************************************************** 185 192 * 186 * FUNCTION: 193 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate 187 194 * 188 * PARAMETERS: 195 * PARAMETERS: None 189 196 * 190 * RETURN: 197 * RETURN: Status 191 198 * 192 * DESCRIPTION: Init and terminate.Nothing to do.199 * DESCRIPTION: Init and terminate. Nothing to do. 193 200 * 194 201 *****************************************************************************/ 195 196 202 ACPI_STATUS 197 AcpiOsInitialize( void)203 AcpiOsInitialize() 198 204 { 199 205 #ifndef _KERNEL_MODE 200 206 AcpiGbl_OutputFile = stdout; … … 202 208 AcpiGbl_OutputFile = NULL; 203 209 #endif 204 210 DEBUG_FUNCTION(); 205 211 return AE_OK; 206 212 } 207 213 208 214 209 215 ACPI_STATUS 210 AcpiOsTerminate( void)216 AcpiOsTerminate() 211 217 { 212 218 DEBUG_FUNCTION(); 213 219 return AE_OK; 214 220 } 215 221 216 222 217 223 /****************************************************************************** 218 224 * 219 * FUNCTION: 225 * FUNCTION: AcpiOsGetRootPointer 220 226 * 221 * PARAMETERS: Flags - Logical or physical addressing mode 222 * Address - Where the address is returned 227 * PARAMETERS: None 223 228 * 224 * RETURN: Status229 * RETURN: RSDP physical address 225 230 * 226 * DESCRIPTION: 231 * DESCRIPTION: Gets the root pointer (RSDP) 227 232 * 228 233 *****************************************************************************/ 229 230 234 ACPI_PHYSICAL_ADDRESS 231 AcpiOsGetRootPointer( void)235 AcpiOsGetRootPointer() 232 236 { 233 237 #ifdef _KERNEL_MODE 234 238 ACPI_SIZE address; … … 242 246 dprintf("AcpiOsGetRootPointer returning %p\n", (void *)sACPIRoot); 243 247 return sACPIRoot; 244 248 #else 245 return (AeLocalGetRootPointer());249 return AeLocalGetRootPointer(); 246 250 #endif 247 251 } 248 252 249 253 250 254 /****************************************************************************** 251 255 * 252 * FUNCTION: 256 * FUNCTION: AcpiOsPredefinedOverride 253 257 * 254 * PARAMETERS: InitVal- Initial value of the predefined object255 * NewVal- The new value for the object258 * PARAMETERS: initVal - Initial value of the predefined object 259 * newVal - The new value for the object 256 260 * 257 * RETURN: Status, pointer to value.Null pointer returned if not258 * 261 * RETURN: Status, pointer to value. Null pointer returned if not 262 * overriding. 259 263 * 260 * DESCRIPTION: 264 * DESCRIPTION: Allow the OS to override predefined names 261 265 * 262 266 *****************************************************************************/ 263 264 267 ACPI_STATUS 265 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES * InitVal,266 ACPI_STRING *NewVal)268 AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *initVal, 269 ACPI_STRING *newVal) 267 270 { 268 271 DEBUG_FUNCTION(); 269 if (!InitVal || !NewVal)270 272 if (!initVal || !newVal) 273 return AE_BAD_PARAMETER; 271 274 272 *NewVal = NULL;273 275 *newVal = NULL; 276 return AE_OK; 274 277 } 275 278 276 279 277 280 /****************************************************************************** 278 281 * 279 * FUNCTION: 282 * FUNCTION: AcpiOsTableOverride 280 283 * 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. 283 286 * 284 * RETURN: Status, pointer to new table.Null pointer returned if no285 * 287 * RETURN: Status, pointer to new table. Null pointer returned if no 288 * table is available to override 286 289 * 287 * DESCRIPTION: 290 * DESCRIPTION: Return a different version of a table if one is available 288 291 * 289 292 *****************************************************************************/ 290 291 293 ACPI_STATUS 292 AcpiOsTableOverride(ACPI_TABLE_HEADER * ExistingTable,293 ACPI_TABLE_HEADER **NewTable)294 AcpiOsTableOverride(ACPI_TABLE_HEADER *existingTable, 295 ACPI_TABLE_HEADER **newTable) 294 296 { 295 297 DEBUG_FUNCTION(); 296 if (!ExistingTable || !NewTable)297 298 if (!existingTable || !newTable) 299 return AE_BAD_PARAMETER; 298 300 299 *NewTable = NULL;301 *newTable = NULL; 300 302 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; 309 306 #else 310 307 return AE_NO_ACPI_TABLES; 311 308 #endif 312 309 } 313 310 314 311 315 312 /****************************************************************************** 316 313 * 317 * FUNCTION: AcpiOsReadable314 * FUNCTION: AcpiOsRedirectOutput 318 315 * 319 * PARAMETERS: Pointer - Area to be verified 320 * Length - Size of area 316 * PARAMETERS: destination - An open file handle/pointer 321 317 * 322 * RETURN: TRUE if readable for entire length318 * RETURN: None 323 319 * 324 * DESCRIPTION: Verify that a pointer is valid for reading320 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf 325 321 * 326 322 *****************************************************************************/ 327 328 BOOLEAN329 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: AcpiOsWritable339 *340 * PARAMETERS: Pointer - Area to be verified341 * Length - Size of area342 *343 * RETURN: TRUE if writable for entire length344 *345 * DESCRIPTION: Verify that a pointer is valid for writing346 *347 *****************************************************************************/348 349 BOOLEAN350 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: AcpiOsRedirectOutput360 *361 * PARAMETERS: Destination - file handle/pointer362 *363 * RETURN: None364 *365 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf366 *367 *****************************************************************************/368 369 323 void 370 AcpiOsRedirectOutput(void * Destination)324 AcpiOsRedirectOutput(void *destination) 371 325 { 372 326 DEBUG_FUNCTION(); 373 AcpiGbl_OutputFile = Destination;327 AcpiGbl_OutputFile = destination; 374 328 } 375 329 376 330 377 331 /****************************************************************************** 378 332 * 379 * FUNCTION: 333 * FUNCTION: AcpiOsPrintf 380 334 * 381 * PARAMETERS: fmt, ...Standard printf format335 * PARAMETERS: fmt, ... Standard printf format 382 336 * 383 * RETURN: 337 * RETURN: None 384 338 * 385 * DESCRIPTION: 339 * DESCRIPTION: Formatted output 386 340 * 387 341 *****************************************************************************/ 388 389 342 void ACPI_INTERNAL_VAR_XFACE 390 AcpiOsPrintf(const char * Fmt, ...)343 AcpiOsPrintf(const char *fmt, ...) 391 344 { 392 va_list Args; 345 va_list args; 346 393 347 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); 397 351 } 398 352 399 353 400 354 /****************************************************************************** 401 355 * 402 * FUNCTION: 356 * FUNCTION: AcpiOsVprintf 403 357 * 404 * PARAMETERS: fmtStandard printf format405 * argsArgument list358 * PARAMETERS: fmt Standard printf format 359 * args Argument list 406 360 * 407 * RETURN: 361 * RETURN: None 408 362 * 409 * DESCRIPTION: 363 * DESCRIPTION: Formatted output with argument list pointer 410 364 * 411 365 *****************************************************************************/ 412 413 366 void 414 AcpiOsVprintf(const char * Fmt, va_list Args)367 AcpiOsVprintf(const char *fmt, va_list args) 415 368 { 416 369 #ifndef _KERNEL_MODE 417 INT32 Count = 0;418 UINT8 Flags;370 INT32 count = 0; 371 UINT8 flags; 419 372 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 424 /* Output file is open, send the output there */ 425 Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);426 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 } 431 384 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 } 435 388 #else 436 389 static char outputBuffer[1024]; 437 vsnprintf(outputBuffer, 1024, Fmt, Args);390 vsnprintf(outputBuffer, 1024, fmt, args); 438 391 dprintf("%s", outputBuffer); 439 392 #endif 440 393 } … … 442 395 443 396 /****************************************************************************** 444 397 * 445 * FUNCTION: 398 * FUNCTION: AcpiOsGetLine 446 399 * 447 * PARAMETERS: fmtStandard printf format448 * argsArgument list400 * PARAMETERS: fmt Standard printf format 401 * args Argument list 449 402 * 450 * RETURN: 403 * RETURN: Actual bytes read 451 404 * 452 * DESCRIPTION: 405 * DESCRIPTION: Formatted input with argument list pointer 453 406 * 454 407 *****************************************************************************/ 455 456 408 UINT32 457 AcpiOsGetLine(char * Buffer)409 AcpiOsGetLine(char *buffer) 458 410 { 459 UINT32 i = 0;411 uint32 i = 0; 460 412 461 413 #ifndef _KERNEL_MODE 462 UINT8 Temp;414 uint8 temp; 463 415 464 416 for (i = 0; ; i++) { 465 scanf("%1c", & Temp);466 if (! Temp || Temp == '\n')417 scanf("%1c", &temp); 418 if (!temp || temp == '\n') 467 419 break; 468 420 469 Buffer[i] = Temp;421 buffer[i] = temp; 470 422 } 471 423 #endif 472 424 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); 478 427 return i; 479 428 } 480 429 481 430 /****************************************************************************** 482 431 * 483 * FUNCTION: 432 * FUNCTION: AcpiOsMapMemory 484 433 * 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 488 436 * 489 * RETURN: Pointer to mapped memory.Null on error.437 * RETURN: Pointer to mapped memory. Null on error. 490 438 * 491 * DESCRIPTION: 439 * DESCRIPTION: Map physical memory into caller's address space 492 440 * 493 441 *****************************************************************************/ 494 495 442 void * 496 443 AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS where, ACPI_SIZE length) 497 444 { … … 510 457 #else 511 458 return NULL; 512 459 #endif 460 461 //return ACPI_TO_POINTER((ACPI_SIZE) where); 513 462 } 514 463 515 464 516 465 /****************************************************************************** 517 466 * 518 * FUNCTION: 467 * FUNCTION: AcpiOsUnmapMemory 519 468 * 520 * PARAMETERS: whereLogical address of memory to be unmapped521 * lengthHow much memory to unmap469 * PARAMETERS: where Logical address of memory to be unmapped 470 * length How much memory to unmap 522 471 * 523 * RETURN: 472 * RETURN: None. 524 473 * 525 * DESCRIPTION: Delete a previously created mapping.Where and Length must526 * 474 * DESCRIPTION: Delete a previously created mapping. Where and Length must 475 * correspond to a previous mapping exactly. 527 476 * 528 477 *****************************************************************************/ 529 530 478 void 531 479 AcpiOsUnmapMemory(void *where, ACPI_SIZE length) 532 480 { … … 537 485 538 486 /****************************************************************************** 539 487 * 540 * FUNCTION: 488 * FUNCTION: AcpiOsAllocate 541 489 * 542 * PARAMETERS: SizeAmount to allocate, in bytes490 * PARAMETERS: size Amount to allocate, in bytes 543 491 * 544 * RETURN: Pointer to the new allocation.Null on error.492 * RETURN: Pointer to the new allocation. Null on error. 545 493 * 546 * DESCRIPTION: Allocate memory.Algorithm is dependent on the OS.494 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. 547 495 * 548 496 *****************************************************************************/ 549 550 497 void * 551 498 AcpiOsAllocate(ACPI_SIZE size) 552 499 { 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; 556 503 } 557 504 558 505 559 506 /****************************************************************************** 560 507 * 561 * FUNCTION: 508 * FUNCTION: AcpiOsFree 562 509 * 563 * PARAMETERS: memPointer to previously allocated memory510 * PARAMETERS: mem Pointer to previously allocated memory 564 511 * 565 * RETURN: 512 * RETURN: None. 566 513 * 567 * DESCRIPTION: 514 * DESCRIPTION: Free memory allocated via AcpiOsAllocate 568 515 * 569 516 *****************************************************************************/ 570 571 517 void 572 518 AcpiOsFree(void *mem) 573 519 { 574 520 DEBUG_FUNCTION_VF("mem: %p", mem); 575 521 free(mem); 576 522 } 577 523 578 524 579 525 /****************************************************************************** 580 526 * 581 * FUNCTION: 527 * FUNCTION: AcpiOsCreateSemaphore 582 528 * 583 * PARAMETERS: InitialUnits- Units to be assigned to the new semaphore584 * OutHandle- Where a handle will be returned529 * PARAMETERS: initialUnits - Units to be assigned to the new semaphore 530 * outHandle - Where a handle will be returned 585 531 * 586 * RETURN: 532 * RETURN: Status 587 533 * 588 * DESCRIPTION: 534 * DESCRIPTION: Create an OS semaphore 589 535 * 590 536 *****************************************************************************/ 591 592 537 ACPI_STATUS 593 AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits,594 ACPI_HANDLE *OutHandle)538 AcpiOsCreateSemaphore(UINT32 maxUnits, UINT32 initialUnits, 539 ACPI_SEMAPHORE *outHandle) 595 540 { 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"); 597 545 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; 602 552 } 603 553 554 604 555 /****************************************************************************** 605 556 * 606 * FUNCTION: 557 * FUNCTION: AcpiOsDeleteSemaphore 607 558 * 608 * PARAMETERS: Handle- Handle returned by AcpiOsCreateSemaphore559 * PARAMETERS: handle - Handle returned by AcpiOsCreateSemaphore 609 560 * 610 * RETURN: 561 * RETURN: Status 611 562 * 612 * DESCRIPTION: 563 * DESCRIPTION: Delete an OS semaphore 613 564 * 614 565 *****************************************************************************/ 615 616 566 ACPI_STATUS 617 AcpiOsDeleteSemaphore(ACPI_ HANDLE Handle)567 AcpiOsDeleteSemaphore(ACPI_SEMAPHORE handle) 618 568 { 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; 622 571 } 623 572 624 573 625 574 /****************************************************************************** 626 575 * 627 * FUNCTION: 576 * FUNCTION: AcpiOsWaitSemaphore 628 577 * 629 * PARAMETERS: Handle- Handle returned by AcpiOsCreateSemaphore630 * Units- How many units to wait for631 * 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 632 581 * 633 * RETURN: 582 * RETURN: Status 634 583 * 635 * DESCRIPTION: 584 * DESCRIPTION: Wait for units 636 585 * 637 586 *****************************************************************************/ 638 639 587 ACPI_STATUS 640 AcpiOsWaitSemaphore(ACPI_ HANDLE Handle, UINT32 Units, UINT16 Timeout)588 AcpiOsWaitSemaphore(ACPI_SEMAPHORE handle, UINT32 units, UINT16 timeout) 641 589 { 642 ACPI_STATUS result;590 ACPI_STATUS result = AE_OK; 643 591 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: 648 604 case B_TIMED_OUT: 605 case B_WOULD_BLOCK: 649 606 result = AE_TIME; 650 607 break; 651 608 case B_BAD_VALUE: 609 default: 652 610 result = AE_BAD_PARAMETER; 653 611 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 } 664 613 } 665 666 614 DEBUG_FUNCTION_VF("result: %lu", (uint32)result); 667 615 return result; 668 616 } 669 617 670 618 671 619 /****************************************************************************** 672 620 * 673 * FUNCTION: 621 * FUNCTION: AcpiOsSignalSemaphore 674 622 * 675 * PARAMETERS: Handle- Handle returned by AcpiOsCreateSemaphore676 * Units- Number of units to send623 * PARAMETERS: handle - Handle returned by AcpiOsCreateSemaphore 624 * units - Number of units to send 677 625 * 678 * RETURN: 626 * RETURN: Status 679 627 * 680 * DESCRIPTION: 628 * DESCRIPTION: Send units 681 629 * 682 630 *****************************************************************************/ 683 684 631 ACPI_STATUS 685 AcpiOsSignalSemaphore(ACPI_ HANDLE Handle, UINT32 Units)632 AcpiOsSignalSemaphore(ACPI_SEMAPHORE handle, UINT32 units) 686 633 { 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; 691 639 } 692 640 693 641 642 /****************************************************************************** 643 * 644 * FUNCTION: Spinlock interfaces 645 * 646 * DESCRIPTION: Map these interfaces to semaphore interfaces 647 * 648 *****************************************************************************/ 694 649 ACPI_STATUS 695 AcpiOsCreateLock(ACPI_ HANDLE *OutHandle)650 AcpiOsCreateLock(ACPI_SPINLOCK *outHandle) 696 651 { 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) 700 655 return AE_NO_MEMORY; 701 702 * ((spinlock *)(*OutHandle))= 0;703 656 657 **outHandle = 0; 658 return AE_OK; 704 659 } 705 660 661 706 662 void 707 AcpiOsDeleteLock(ACPI_ HANDLE Handle)663 AcpiOsDeleteLock(ACPI_SPINLOCK handle) 708 664 { 709 665 DEBUG_FUNCTION(); 710 free(Handle);666 free(handle); 711 667 } 712 668 713 669 714 670 ACPI_CPU_FLAGS 715 AcpiOsAcquireLock(ACPI_ HANDLE Handle)671 AcpiOsAcquireLock(ACPI_SPINLOCK handle) 716 672 { 717 673 cpu_status cpu; 718 DEBUG_FUNCTION_F("spinlock: %p", (spinlock *)Handle);674 DEBUG_FUNCTION_F("spinlock: %p", handle); 719 675 cpu = disable_interrupts(); 720 acquire_spinlock( (spinlock *)Handle);721 return cpu; 676 acquire_spinlock(handle); 677 return cpu; 722 678 } 723 679 724 680 725 681 void 726 AcpiOsReleaseLock(ACPI_ HANDLE Handle, ACPI_CPU_FLAGS Flags)682 AcpiOsReleaseLock(ACPI_SPINLOCK handle, ACPI_CPU_FLAGS flags) 727 683 { 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); 731 687 } 732 688 733 689 734 690 /****************************************************************************** 735 691 * 736 * FUNCTION: 692 * FUNCTION: AcpiOsInstallInterruptHandler 737 693 * 738 * PARAMETERS: InterruptNumberLevel handler should respond to.739 * IsrAddress of the ACPI interrupt handler740 * ExceptPtrWhere status is returned694 * PARAMETERS: interruptNumber Level handler should respond to. 695 * Isr Address of the ACPI interrupt handler 696 * ExceptPtr Where status is returned 741 697 * 742 * RETURN: 698 * RETURN: Handle to the newly installed handler. 743 699 * 744 * DESCRIPTION: Install an interrupt handler.Used to install the ACPI745 * 700 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI 701 * OS-independent handler. 746 702 * 747 703 *****************************************************************************/ 748 749 704 UINT32 750 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber,751 ACPI_OSD_HANDLER ServiceRoutine, void *Context)705 AcpiOsInstallInterruptHandler(UINT32 interruptNumber, 706 ACPI_OSD_HANDLER serviceRoutine, void *context) 752 707 { 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 755 712 #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; 762 723 #else 763 return AE_ ERROR;724 return AE_BAD_PARAMETER; 764 725 #endif 765 726 } 766 727 767 728 768 729 /****************************************************************************** 769 730 * 770 * FUNCTION: 731 * FUNCTION: AcpiOsRemoveInterruptHandler 771 732 * 772 * PARAMETERS: HandleReturned when handler was installed733 * PARAMETERS: Handle Returned when handler was installed 773 734 * 774 * RETURN: 735 * RETURN: Status 775 736 * 776 * DESCRIPTION: 737 * DESCRIPTION: Uninstalls an interrupt handler. 777 738 * 778 739 *****************************************************************************/ 779 780 740 ACPI_STATUS 781 AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber,782 ACPI_OSD_HANDLER ServiceRoutine)741 AcpiOsRemoveInterruptHandler(UINT32 interruptNumber, 742 ACPI_OSD_HANDLER serviceRoutine) 783 743 { 784 DEBUG_FUNCTION_F("vector: %lu; handler: %p", (uint32)InterruptNumber,785 ServiceRoutine);744 DEBUG_FUNCTION_F("vector: %lu; handler: %p", interruptNumber, 745 serviceRoutine); 786 746 #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]); 790 750 return AE_OK; 791 751 #else 792 752 return AE_ERROR; … … 794 754 } 795 755 796 756 757 797 758 /****************************************************************************** 798 759 * 799 * FUNCTION: 760 * FUNCTION: AcpiOsExecute 800 761 * 801 * PARAMETERS: Type- Type of execution802 * Function- Address of the function to execute803 * Context- Passed as a parameter to the function762 * PARAMETERS: type - Type of execution 763 * function - Address of the function to execute 764 * context - Passed as a parameter to the function 804 765 * 805 * RETURN: 766 * RETURN: Status. 806 767 * 807 * DESCRIPTION: 768 * DESCRIPTION: Execute a new thread 808 769 * 809 770 *****************************************************************************/ 810 811 771 ACPI_STATUS 812 AcpiOsExecute(ACPI_EXECUTE_TYPE Type, ACPI_OSD_EXEC_CALLBACK Function,813 void *Context)772 AcpiOsExecute(ACPI_EXECUTE_TYPE type, ACPI_OSD_EXEC_CALLBACK function, 773 void *context) 814 774 { 815 775 DEBUG_FUNCTION(); 816 switch (Type) { 776 /* TODO: Prioritize urgent? 777 switch (type) { 817 778 case OSL_GLOBAL_LOCK_HANDLER: 818 779 case OSL_NOTIFY_HANDLER: 819 780 case OSL_GPE_HANDLER: … … 822 783 case OSL_EC_BURST_HANDLER: 823 784 break; 824 785 } 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 } 829 792 return AE_OK; 830 793 } 831 794 832 795 833 796 /****************************************************************************** 834 797 * 835 * FUNCTION: AcpiOsBreakpoint798 * FUNCTION: AcpiOsStall 836 799 * 837 * PARAMETERS: Msg Message to print800 * PARAMETERS: microseconds To sleep 838 801 * 839 * RETURN: Status802 * RETURN: Blocks until sleep is completed. 840 803 * 841 * DESCRIPTION: Print a message and break to the debugger.804 * DESCRIPTION: Sleep at microsecond granularity 842 805 * 843 806 *****************************************************************************/ 844 845 #if 0846 ACPI_STATUS847 AcpiOsBreakpoint(char *Msg)848 {849 if (Msg != NULL)850 kernel_debugger ("AcpiOsBreakpoint: %s ****\n", Msg);851 else852 kernel_debugger ("At AcpiOsBreakpoint ****\n");853 854 return AE_OK;855 }856 #endif857 858 /******************************************************************************859 *860 * FUNCTION: AcpiOsStall861 *862 * PARAMETERS: microseconds To sleep863 *864 * RETURN: Blocks until sleep is completed.865 *866 * DESCRIPTION: Sleep at microsecond granularity867 *868 *****************************************************************************/869 870 807 void 871 808 AcpiOsStall(UINT32 microseconds) 872 809 { 873 DEBUG_FUNCTION_F("microseconds: %lu", (uint32)microseconds); 874 spin(microseconds); 810 DEBUG_FUNCTION_F("microseconds: %lu", microseconds); 811 if (microseconds) 812 spin(microseconds); 875 813 } 876 814 877 815 878 816 /****************************************************************************** 879 817 * 880 * FUNCTION: 818 * FUNCTION: AcpiOsSleep 881 819 * 882 * PARAMETERS: millisecondsTo sleep820 * PARAMETERS: milliseconds To sleep 883 821 * 884 * RETURN: 822 * RETURN: Blocks until sleep is completed. 885 823 * 886 * DESCRIPTION: 824 * DESCRIPTION: Sleep at millisecond granularity 887 825 * 888 826 *****************************************************************************/ 889 890 827 void 891 828 AcpiOsSleep(ACPI_INTEGER milliseconds) 892 829 { 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); 895 832 } 896 833 834 897 835 /****************************************************************************** 898 836 * 899 * FUNCTION: 837 * FUNCTION: AcpiOsGetTimer 900 838 * 901 * PARAMETERS: 839 * PARAMETERS: None 902 840 * 903 * RETURN: 841 * RETURN: Current time in 100 nanosecond units 904 842 * 905 * DESCRIPTION: 843 * DESCRIPTION: Get the current system time 906 844 * 907 845 *****************************************************************************/ 908 909 846 UINT64 910 AcpiOsGetTimer (void)847 AcpiOsGetTimer() 911 848 { 912 849 DEBUG_FUNCTION(); 913 850 return system_time() * 10; … … 916 853 917 854 /****************************************************************************** 918 855 * 919 * FUNCTION: 856 * FUNCTION: AcpiOsValidateInterface 920 857 * 921 * PARAMETERS: Interface- Requested interface to be validated858 * PARAMETERS: interface - Requested interface to be validated 922 859 * 923 * RETURN: 860 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise 924 861 * 925 * DESCRIPTION: 926 * 862 * DESCRIPTION: Match an interface string to the interfaces supported by the 863 * host. Strings originate from an AML call to the _OSI method. 927 864 * 928 865 *****************************************************************************/ 929 930 866 ACPI_STATUS 931 AcpiOsValidateInterface(char * Interface)867 AcpiOsValidateInterface(char *interface) 932 868 { 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; 935 872 } 936 873 937 874 938 875 /****************************************************************************** 939 876 * 940 * FUNCTION: 877 * FUNCTION: AcpiOsReadPciConfiguration 941 878 * 942 * PARAMETERS: PciIdSeg/Bus/Dev943 * RegisterDevice Register944 * ValueBuffer where value is placed945 * WidthNumber of bits879 * PARAMETERS: pciId Seg/Bus/Dev 880 * reg Device Register 881 * value Buffer where value is placed 882 * width Number of bits 946 883 * 947 * RETURN: 884 * RETURN: Status 948 885 * 949 * DESCRIPTION: 886 * DESCRIPTION: Read data from PCI configuration space 950 887 * 951 888 *****************************************************************************/ 952 953 889 ACPI_STATUS 954 AcpiOsReadPciConfiguration(ACPI_PCI_ID *pciId, UINT32 offset, void *value,955 UINT32 width)890 AcpiOsReadPciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg, void *value, 891 UINT32 width) 956 892 { 957 893 #ifdef _KERNEL_MODE 958 894 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); 960 896 DEBUG_FUNCTION(); 961 897 switch (width) { 962 898 case 8: 963 *(UINT8 *) value = val;899 *(UINT8 *) value = val; 964 900 break; 965 901 case 16: 966 *(UINT16 *) value = val;902 *(UINT16 *) value = val; 967 903 break; 968 904 case 32: 969 *(UINT32 *) value = val;905 *(UINT32 *) value = val; 970 906 break; 971 907 default: 972 dprintf("AcpiOsReadPciConfiguration unhandled value width: %u\n", 973 width); 908 dprintf("AcpiOsReadPciConfiguration unhandled width: %u\n", width); 974 909 return AE_ERROR; 975 910 } 976 977 911 return AE_OK; 978 912 #else 979 913 return AE_ERROR; … … 983 917 984 918 /****************************************************************************** 985 919 * 986 * FUNCTION: 920 * FUNCTION: AcpiOsWritePciConfiguration 987 921 * 988 * PARAMETERS: PciIdSeg/Bus/Dev989 * RegisterDevice Register990 * ValueValue to be written991 * WidthNumber of bits922 * PARAMETERS: pciId Seg/Bus/Dev 923 * reg Device Register 924 * value Value to be written 925 * width Number of bits 992 926 * 993 * RETURN: 927 * RETURN: Status. 994 928 * 995 * DESCRIPTION: 929 * DESCRIPTION: Write data to PCI configuration space 996 930 * 997 931 *****************************************************************************/ 998 999 932 ACPI_STATUS 1000 AcpiOsWritePciConfiguration(ACPI_PCI_ID * PciId, UINT32 Register,1001 ACPI_INTEGER Value, UINT32 Width)933 AcpiOsWritePciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg, 934 ACPI_INTEGER value, UINT32 width) 1002 935 { 1003 936 #ifdef _KERNEL_MODE 1004 937 DEBUG_FUNCTION(); 1005 938 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); 1007 940 return AE_OK; 1008 941 #else 1009 942 return AE_ERROR; 1010 943 #endif 1011 944 } 1012 945 1013 /* TEMPORARY STUB FUNCTION */ 946 1014 947 void 1015 AcpiOsDerivePciId(ACPI_HANDLE rhandle, ACPI_HANDLE chandle, ACPI_PCI_ID ** PciId)948 AcpiOsDerivePciId(ACPI_HANDLE rhandle, ACPI_HANDLE chandle, ACPI_PCI_ID **pciId) 1016 949 { 950 // TODO: Implement this! 1017 951 } 1018 952 1019 953 1020 954 /****************************************************************************** 1021 955 * 1022 * FUNCTION: 956 * FUNCTION: AcpiOsReadPort 1023 957 * 1024 * PARAMETERS: AddressAddress of I/O port/register to read1025 * ValueWhere value is placed1026 * WidthNumber of bits958 * PARAMETERS: address Address of I/O port/register to read 959 * Value Where value is placed 960 * width Number of bits 1027 961 * 1028 * RETURN: 962 * RETURN: Value read from port 1029 963 * 1030 * DESCRIPTION: 964 * DESCRIPTION: Read data from an I/O port or register 1031 965 * 1032 966 *****************************************************************************/ 1033 1034 967 ACPI_STATUS 1035 AcpiOsReadPort(ACPI_IO_ADDRESS Address, UINT32 *Value, UINT32 Width)968 AcpiOsReadPort(ACPI_IO_ADDRESS address, UINT32 *value, UINT32 width) 1036 969 { 1037 970 #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) { 1041 973 case 8: 1042 * Value = gPCIManager->read_io_8(Address);974 *value = gPCIManager->read_io_8(address); 1043 975 break; 1044 976 1045 977 case 16: 1046 * Value = gPCIManager->read_io_16(Address);978 *value = gPCIManager->read_io_16(address); 1047 979 break; 1048 980 1049 981 case 32: 1050 * Value = gPCIManager->read_io_32(Address);982 *value = gPCIManager->read_io_32(address); 1051 983 break; 1052 984 1053 985 default: 1054 dprintf("AcpiOsReadPort: unhandeld width: %u\n", Width);986 dprintf("AcpiOsReadPort: unhandeld width: %u\n", width); 1055 987 return AE_ERROR; 1056 988 } 1057 989 … … 1064 996 1065 997 /****************************************************************************** 1066 998 * 1067 * FUNCTION: 999 * FUNCTION: AcpiOsWritePort 1068 1000 * 1069 * PARAMETERS: AddressAddress of I/O port/register to write1070 * ValueValue to write1071 * WidthNumber of bits1001 * PARAMETERS: address Address of I/O port/register to write 1002 * value Value to write 1003 * width Number of bits 1072 1004 * 1073 * RETURN: 1005 * RETURN: None 1074 1006 * 1075 * DESCRIPTION: 1007 * DESCRIPTION: Write data to an I/O port or register 1076 1008 * 1077 1009 *****************************************************************************/ 1078 1079 1010 ACPI_STATUS 1080 AcpiOsWritePort(ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width)1011 AcpiOsWritePort(ACPI_IO_ADDRESS address, UINT32 value, UINT32 width) 1081 1012 { 1082 1013 #ifdef _KERNEL_MODE 1083 1014 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) { 1086 1017 case 8: 1087 gPCIManager->write_io_8( Address, Value);1018 gPCIManager->write_io_8(address, value); 1088 1019 break; 1089 1020 1090 1021 case 16: 1091 gPCIManager->write_io_16( Address,Value);1022 gPCIManager->write_io_16(address,value); 1092 1023 break; 1093 1024 1094 1025 case 32: 1095 gPCIManager->write_io_32( Address,Value);1026 gPCIManager->write_io_32(address,value); 1096 1027 break; 1097 1028 1098 1029 default: 1099 dprintf("AcpiOsWritePort: unhandeld width: %u\n", Width);1030 dprintf("AcpiOsWritePort: unhandeld width: %u\n", width); 1100 1031 return AE_ERROR; 1101 1032 } 1102 1033 … … 1109 1040 1110 1041 /****************************************************************************** 1111 1042 * 1112 * FUNCTION: 1043 * FUNCTION: AcpiOsReadMemory 1113 1044 * 1114 * PARAMETERS: AddressPhysical Memory Address to read1115 * ValueWhere value is placed1116 * WidthNumber of bits1045 * PARAMETERS: address Physical Memory Address to read 1046 * value Where value is placed 1047 * width Number of bits 1117 1048 * 1118 * RETURN: 1049 * RETURN: Value read from physical memory address 1119 1050 * 1120 * DESCRIPTION: 1051 * DESCRIPTION: Read data from a physical memory address 1121 1052 * 1122 1053 *****************************************************************************/ 1123 1124 1054 ACPI_STATUS 1125 AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width)1055 AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS address, UINT32 *value, UINT32 width) 1126 1056 { 1127 1057 #ifdef _KERNEL_MODE 1128 if (vm_memcpy_from_physical( Value, (addr_t)Address, Width / 8, false)1129 1058 if (vm_memcpy_from_physical(value, (addr_t)address, width / 8, false) 1059 != B_OK) { 1130 1060 return AE_ERROR; 1131 1061 } 1132 1062 return AE_OK; … … 1138 1068 1139 1069 /****************************************************************************** 1140 1070 * 1141 * FUNCTION: 1071 * FUNCTION: AcpiOsWriteMemory 1142 1072 * 1143 * PARAMETERS: AddressPhysical Memory Address to write1144 * ValueValue to write1145 * WidthNumber of bits1073 * PARAMETERS: address Physical Memory Address to write 1074 * value Value to write 1075 * width Number of bits 1146 1076 * 1147 * RETURN: 1077 * RETURN: None 1148 1078 * 1149 * DESCRIPTION: 1079 * DESCRIPTION: Write data to a physical memory address 1150 1080 * 1151 1081 *****************************************************************************/ 1152 1153 1082 ACPI_STATUS 1154 AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 Value, UINT32 Width)1083 AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS address, UINT32 value, UINT32 width) 1155 1084 { 1156 1085 #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) 1158 1087 != B_OK) { 1159 1088 return AE_ERROR; 1160 1089 } … … 1165 1094 } 1166 1095 1167 1096 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 *****************************************************************************/ 1109 BOOLEAN 1110 AcpiOsReadable(void *pointer, ACPI_SIZE Length) 1170 1111 { 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 *****************************************************************************/ 1130 BOOLEAN 1131 AcpiOsWritable(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 *****************************************************************************/ 1153 ACPI_THREAD_ID 1154 AcpiOsGetThreadId() 1155 { 1156 thread_id thread = find_thread(NULL); 1157 return thread; 1158 1159 //TODO: Look if this is needed. 1171 1160 // ACPI treats a 0 return as an error, 1172 1161 // 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; 1175 1163 } 1176 1164 1177 1165 1178 1166 /****************************************************************************** 1179 1167 * 1180 * FUNCTION: 1168 * FUNCTION: AcpiOsSignal 1181 1169 * 1182 * PARAMETERS: FunctionACPI CA signal function code1183 * InfoPointer to function-dependent structure1170 * PARAMETERS: function ACPI CA signal function code 1171 * info Pointer to function-dependent structure 1184 1172 * 1185 * RETURN: 1173 * RETURN: Status 1186 1174 * 1187 * DESCRIPTION: Miscellaneous functions1175 * DESCRIPTION: Miscellaneous functions. Example implementation only. 1188 1176 * 1189 1177 *****************************************************************************/ 1190 1191 1178 ACPI_STATUS 1192 AcpiOsSignal(UINT32 Function, void *Info)1179 AcpiOsSignal(UINT32 function, void *info) 1193 1180 { 1194 1181 DEBUG_FUNCTION(); 1195 switch ( Function) {1182 switch (function) { 1196 1183 case ACPI_SIGNAL_FATAL: 1197 1184 #ifdef _KERNEL_MODE 1198 if (Info != NULL) 1199 panic(Info); 1200 else 1201 panic("AcpiOsSignal: fatal"); 1185 panic(info == NULL ? "AcpiOsSignal: fatal" : info); 1202 1186 break; 1203 1187 #endif 1204 1205 1188 case ACPI_SIGNAL_BREAKPOINT: 1206 if ( Info != NULL)1207 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);1189 if (info != NULL) 1190 AcpiOsPrintf("AcpiOsBreakpoint: %s ****\n", info); 1208 1191 else 1209 AcpiOsPrintf 1192 AcpiOsPrintf("At AcpiOsBreakpoint ****\n"); 1210 1193 break; 1211 1194 } 1212 1195 -
src/add-ons/kernel/bus_managers/acpi/acpi_busman.c
79 79 case B_MODULE_INIT: 80 80 { 81 81 ACPI_STATUS status; 82 uint32 flags; 83 void *settings; 82 84 bool acpiDisabled = false; 83 void *settings;85 bool acpiAvoidFullInit = false; 84 86 85 87 settings = load_driver_settings("kernel"); 86 88 if (settings != NULL) { 87 89 acpiDisabled = !get_driver_boolean_parameter(settings, "acpi", 88 90 false, false); 91 acpiAvoidFullInit = get_driver_boolean_parameter(settings, 92 "acpi_avoid_full_init", false, false); 89 93 unload_driver_settings(settings); 90 94 } 91 95 … … 103 107 ERROR("ACPI disabled\n"); 104 108 return ENOSYS; 105 109 } 110 AcpiGbl_EnableInterpreterSlack = true; 111 // AcpiGbl_CreateOSIMethod = true; 106 112 107 113 #ifdef ACPI_DEBUG_OUTPUT 108 114 AcpiDbgLevel = ACPI_DEBUG_ALL | ACPI_LV_VERBOSE; … … 130 136 goto err; 131 137 } 132 138 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. 133 146 status = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION); 134 147 if (status != AE_OK) { 135 148 ERROR("AcpiEnableSubsystem failed (%s)\n", … … 137 150 goto err; 138 151 } 139 152 153 status = AcpiInitializeObjects(flags); 154 if (status != AE_OK) { 155 ERROR("AcpiInitializeObjects failed (%s)\n", 156 AcpiFormatException(status)); 157 goto err; 158 } 159 140 160 /* Phew. Now in ACPI mode */ 141 161 TRACE("ACPI initialized\n"); 142 162 return B_OK; … … 545 565 if ((AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) == 0) 546 566 return B_UNSUPPORTED; 547 567 548 status = AcpiWrite(AcpiGbl_FADT.ResetValue, 549 &AcpiGbl_FADT.ResetRegister); 568 status = AcpiWrite(AcpiGbl_FADT.ResetValue, &AcpiGbl_FADT.ResetRegister); 550 569 551 570 if (status != AE_OK) { 552 571 ERROR("Reset failed, status = %d\n", status);