osunixxf.c revision 235945
1187767Sluigi/****************************************************************************** 2187767Sluigi * 3187767Sluigi * Module Name: osunixxf - UNIX OSL interfaces 4187767Sluigi * 5187767Sluigi *****************************************************************************/ 6187767Sluigi 7187767Sluigi/* 8187767Sluigi * Copyright (C) 2000 - 2012, Intel Corp. 9187767Sluigi * All rights reserved. 10187767Sluigi * 11187767Sluigi * Redistribution and use in source and binary forms, with or without 12187767Sluigi * modification, are permitted provided that the following conditions 13187767Sluigi * are met: 14187767Sluigi * 1. Redistributions of source code must retain the above copyright 15187767Sluigi * notice, this list of conditions, and the following disclaimer, 16187767Sluigi * without modification. 17187767Sluigi * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18187767Sluigi * substantially similar to the "NO WARRANTY" disclaimer below 19187767Sluigi * ("Disclaimer") and any redistribution must be conditioned upon 20187767Sluigi * including a substantially similar Disclaimer requirement for further 21187767Sluigi * binary redistribution. 22187767Sluigi * 3. Neither the names of the above-listed copyright holders nor the names 23187767Sluigi * of any contributors may be used to endorse or promote products derived 24187767Sluigi * from this software without specific prior written permission. 25187767Sluigi * 26187767Sluigi * Alternatively, this software may be distributed under the terms of the 27187767Sluigi * GNU General Public License ("GPL") version 2 as published by the Free 28187767Sluigi * Software Foundation. 29187767Sluigi * 30187767Sluigi * NO WARRANTY 31187767Sluigi * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32187767Sluigi * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33187767Sluigi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34187767Sluigi * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35187767Sluigi * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36187767Sluigi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37187767Sluigi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38204591Sluigi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39187767Sluigi * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40187767Sluigi * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41187767Sluigi * POSSIBILITY OF SUCH DAMAGES. 42187767Sluigi */ 43187767Sluigi 44187767Sluigi 45187767Sluigi/* 46187767Sluigi * These interfaces are required in order to compile the ASL compiler and the 47187767Sluigi * various ACPICA tools under Linux or other Unix-like system. 48187767Sluigi * 49187767Sluigi * Note: Use #define __APPLE__ for OS X generation. 50187767Sluigi */ 51187767Sluigi#include <contrib/dev/acpica/include/acpi.h> 52187767Sluigi#include <contrib/dev/acpica/include/accommon.h> 53187767Sluigi#include <contrib/dev/acpica/include/amlcode.h> 54187767Sluigi#include <contrib/dev/acpica/include/acparser.h> 55187767Sluigi#include <contrib/dev/acpica/include/acdebug.h> 56187767Sluigi 57187767Sluigi#include <stdio.h> 58187767Sluigi#include <stdlib.h> 59187767Sluigi#include <stdarg.h> 60187767Sluigi#include <unistd.h> 61187767Sluigi#include <sys/time.h> 62187767Sluigi#include <semaphore.h> 63187767Sluigi#include <pthread.h> 64187767Sluigi#include <errno.h> 65187767Sluigi 66187767Sluigi#define _COMPONENT ACPI_OS_SERVICES 67187767Sluigi ACPI_MODULE_NAME ("osunixxf") 68187767Sluigi 69187767Sluigi 70187767Sluigiextern FILE *AcpiGbl_DebugFile; 71187767SluigiFILE *AcpiGbl_OutputFile; 72187767Sluigi 73187767Sluigi 74187769Sluigi/* Upcalls to AcpiExec */ 75187769Sluigi 76187769SluigiACPI_PHYSICAL_ADDRESS 77187769SluigiAeLocalGetRootPointer ( 78187769Sluigi void); 79187769Sluigi 80187769Sluigivoid 81187769SluigiAeTableOverride ( 82187769Sluigi ACPI_TABLE_HEADER *ExistingTable, 83187769Sluigi ACPI_TABLE_HEADER **NewTable); 84187769Sluigi 85204591Sluigitypedef void* (*PTHREAD_CALLBACK) (void *); 86187769Sluigi 87204591Sluigi/* Apple-specific */ 88204591Sluigi 89187769Sluigi#ifdef __APPLE__ 90187769Sluigi#define sem_destroy sem_close 91187769Sluigi#endif 92187769Sluigi 93187769Sluigi 94187769Sluigi/****************************************************************************** 95187769Sluigi * 96187769Sluigi * FUNCTION: AcpiOsInitialize, AcpiOsTerminate 97187769Sluigi * 98187769Sluigi * PARAMETERS: None 99187769Sluigi * 100187769Sluigi * RETURN: Status 101190633Spiso * 102223666Sae * DESCRIPTION: Init and terminate. Nothing to do. 103223666Sae * 104187769Sluigi *****************************************************************************/ 105187769Sluigi 106187769SluigiACPI_STATUS 107187769SluigiAcpiOsInitialize ( 108187769Sluigi void) 109187769Sluigi{ 110187769Sluigi 111187769Sluigi AcpiGbl_OutputFile = stdout; 112187769Sluigi return (AE_OK); 113187769Sluigi} 114187769Sluigi 115187769Sluigi 116187769SluigiACPI_STATUS 117187769SluigiAcpiOsTerminate ( 118187769Sluigi void) 119187769Sluigi{ 120187769Sluigi 121187769Sluigi return (AE_OK); 122187769Sluigi} 123187769Sluigi 124187769Sluigi 125187769Sluigi/****************************************************************************** 126187769Sluigi * 127187769Sluigi * FUNCTION: AcpiOsGetRootPointer 128187769Sluigi * 129187769Sluigi * PARAMETERS: None 130205169Sluigi * 131187769Sluigi * RETURN: RSDP physical address 132187769Sluigi * 133187769Sluigi * DESCRIPTION: Gets the ACPI root pointer (RSDP) 134187769Sluigi * 135187769Sluigi *****************************************************************************/ 136187769Sluigi 137187769SluigiACPI_PHYSICAL_ADDRESS 138187769SluigiAcpiOsGetRootPointer ( 139187769Sluigi void) 140187769Sluigi{ 141187769Sluigi 142187769Sluigi return (AeLocalGetRootPointer ()); 143187769Sluigi} 144187769Sluigi 145187769Sluigi 146187769Sluigi/****************************************************************************** 147187769Sluigi * 148187769Sluigi * FUNCTION: AcpiOsPredefinedOverride 149187769Sluigi * 150187769Sluigi * PARAMETERS: InitVal - Initial value of the predefined object 151187769Sluigi * NewVal - The new value for the object 152187769Sluigi * 153187769Sluigi * RETURN: Status, pointer to value. Null pointer returned if not 154187769Sluigi * overriding. 155187769Sluigi * 156187769Sluigi * DESCRIPTION: Allow the OS to override predefined names 157187769Sluigi * 158187769Sluigi *****************************************************************************/ 159187769Sluigi 160204591SluigiACPI_STATUS 161204591SluigiAcpiOsPredefinedOverride ( 162187769Sluigi const ACPI_PREDEFINED_NAMES *InitVal, 163187769Sluigi ACPI_STRING *NewVal) 164204591Sluigi{ 165194930Soleg 166187769Sluigi if (!InitVal || !NewVal) 167187769Sluigi { 168187769Sluigi return (AE_BAD_PARAMETER); 169187769Sluigi } 170204591Sluigi 171187769Sluigi *NewVal = NULL; 172204591Sluigi return (AE_OK); 173204591Sluigi} 174204591Sluigi 175204591Sluigi 176204591Sluigi/****************************************************************************** 177187769Sluigi * 178187769Sluigi * FUNCTION: AcpiOsTableOverride 179187769Sluigi * 180187769Sluigi * PARAMETERS: ExistingTable - Header of current table (probably 181187769Sluigi * firmware) 182187769Sluigi * NewTable - Where an entire new table is returned. 183223080Sae * 184187769Sluigi * RETURN: Status, pointer to new table. Null pointer returned if no 185187769Sluigi * table is available to override 186187769Sluigi * 187187769Sluigi * DESCRIPTION: Return a different version of a table if one is available 188187769Sluigi * 189220804Sglebius *****************************************************************************/ 190187769Sluigi 191187769SluigiACPI_STATUS 192187769SluigiAcpiOsTableOverride ( 193187769Sluigi ACPI_TABLE_HEADER *ExistingTable, 194187769Sluigi ACPI_TABLE_HEADER **NewTable) 195187769Sluigi{ 196187769Sluigi 197187769Sluigi if (!ExistingTable || !NewTable) 198187769Sluigi { 199187769Sluigi return (AE_BAD_PARAMETER); 200187769Sluigi } 201187769Sluigi 202187769Sluigi *NewTable = NULL; 203187769Sluigi 204200567Sluigi#ifdef ACPI_EXEC_APP 205215179Sluigi 206250762Smelifaro AeTableOverride (ExistingTable, NewTable); 207187769Sluigi return (AE_OK); 208187767Sluigi#else 209187767Sluigi 210187767Sluigi return (AE_NO_ACPI_TABLES); 211187767Sluigi#endif 212204591Sluigi} 213204591Sluigi 214187767Sluigi 215206843Sluigi/****************************************************************************** 216187787Sluigi * 217187767Sluigi * FUNCTION: AcpiOsPhysicalTableOverride 218187767Sluigi * 219187767Sluigi * PARAMETERS: ExistingTable - Header of current table (probably firmware) 220187767Sluigi * NewAddress - Where new table address is returned 221187770Sluigi * (Physical address) 222187767Sluigi * NewTableLength - Where new table length is returned 223187769Sluigi * 224187767Sluigi * RETURN: Status, address/length of new table. Null pointer returned 225187770Sluigi * if no table is available to override. 226187769Sluigi * 227187770Sluigi * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. 228187770Sluigi * 229187769Sluigi *****************************************************************************/ 230187769Sluigi 231265699SmelifaroACPI_STATUS 232265699SmelifaroAcpiOsPhysicalTableOverride ( 233187769Sluigi ACPI_TABLE_HEADER *ExistingTable, 234187769Sluigi ACPI_PHYSICAL_ADDRESS *NewAddress, 235187770Sluigi UINT32 *NewTableLength) 236187769Sluigi{ 237187819Sluigi 238187819Sluigi return (AE_SUPPORT); 239187819Sluigi} 240187819Sluigi 241187819Sluigi 242187819Sluigi/****************************************************************************** 243187819Sluigi * 244187819Sluigi * FUNCTION: AcpiOsRedirectOutput 245187819Sluigi * 246187983Sluigi * PARAMETERS: Destination - An open file handle/pointer 247187819Sluigi * 248187819Sluigi * RETURN: None 249187819Sluigi * 250187769Sluigi * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf 251187767Sluigi * 252187767Sluigi *****************************************************************************/ 253187767Sluigi 254187767Sluigivoid 255187767SluigiAcpiOsRedirectOutput ( 256187767Sluigi void *Destination) 257187767Sluigi{ 258187770Sluigi 259204591Sluigi AcpiGbl_OutputFile = Destination; 260187767Sluigi} 261187767Sluigi 262187767Sluigi 263204591Sluigi/****************************************************************************** 264187767Sluigi * 265204591Sluigi * FUNCTION: AcpiOsPrintf 266204591Sluigi * 267187767Sluigi * PARAMETERS: fmt, ... - Standard printf format 268187767Sluigi * 269187767Sluigi * RETURN: None 270187767Sluigi * 271187983Sluigi * DESCRIPTION: Formatted output 272187983Sluigi * 273187983Sluigi *****************************************************************************/ 274187983Sluigi 275187983Sluigivoid ACPI_INTERNAL_VAR_XFACE 276187983SluigiAcpiOsPrintf ( 277187770Sluigi const char *Fmt, 278204591Sluigi ...) 279204591Sluigi{ 280187769Sluigi va_list Args; 281187769Sluigi 282187770Sluigi 283187770Sluigi va_start (Args, Fmt); 284187819Sluigi AcpiOsVprintf (Fmt, Args); 285187819Sluigi va_end (Args); 286187819Sluigi} 287187819Sluigi 288187770Sluigi 289248505Smelifaro/****************************************************************************** 290248505Smelifaro * 291187770Sluigi * FUNCTION: AcpiOsVprintf 292248505Smelifaro * 293187770Sluigi * PARAMETERS: fmt - Standard printf format 294248505Smelifaro * args - Argument list 295187819Sluigi * 296 * RETURN: None 297 * 298 * DESCRIPTION: Formatted output with argument list pointer 299 * 300 *****************************************************************************/ 301 302void 303AcpiOsVprintf ( 304 const char *Fmt, 305 va_list Args) 306{ 307 UINT8 Flags; 308 309 310 Flags = AcpiGbl_DbOutputFlags; 311 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT) 312 { 313 /* Output is directable to either a file (if open) or the console */ 314 315 if (AcpiGbl_DebugFile) 316 { 317 /* Output file is open, send the output there */ 318 319 vfprintf (AcpiGbl_DebugFile, Fmt, Args); 320 } 321 else 322 { 323 /* No redirection, send output to console (once only!) */ 324 325 Flags |= ACPI_DB_CONSOLE_OUTPUT; 326 } 327 } 328 329 if (Flags & ACPI_DB_CONSOLE_OUTPUT) 330 { 331 vfprintf (AcpiGbl_OutputFile, Fmt, Args); 332 } 333} 334 335 336/****************************************************************************** 337 * 338 * FUNCTION: AcpiOsGetLine 339 * 340 * PARAMETERS: Buffer - Where to return the command line 341 * BufferLength - Maximum length of Buffer 342 * BytesRead - Where the actual byte count is returned 343 * 344 * RETURN: Status and actual bytes read 345 * 346 * DESCRIPTION: Formatted input with argument list pointer 347 * 348 *****************************************************************************/ 349 350ACPI_STATUS 351AcpiOsGetLine ( 352 char *Buffer, 353 UINT32 BufferLength, 354 UINT32 *BytesRead) 355{ 356 UINT8 Temp; 357 UINT32 i; 358 359 360 for (i = 0; ; i++) 361 { 362 if (i >= BufferLength) 363 { 364 return (AE_BUFFER_OVERFLOW); 365 } 366 367 scanf ("%1c", &Temp); 368 if (!Temp || Temp == '\n') 369 { 370 break; 371 } 372 373 Buffer [i] = Temp; 374 } 375 376 /* Null terminate the buffer */ 377 378 Buffer [i] = 0; 379 380 /* Return the number of bytes in the string */ 381 382 if (BytesRead) 383 { 384 *BytesRead = i; 385 } 386 return (AE_OK); 387} 388 389 390/****************************************************************************** 391 * 392 * FUNCTION: AcpiOsMapMemory 393 * 394 * PARAMETERS: where - Physical address of memory to be mapped 395 * length - How much memory to map 396 * 397 * RETURN: Pointer to mapped memory. Null on error. 398 * 399 * DESCRIPTION: Map physical memory into caller's address space 400 * 401 *****************************************************************************/ 402 403void * 404AcpiOsMapMemory ( 405 ACPI_PHYSICAL_ADDRESS where, 406 ACPI_SIZE length) 407{ 408 409 return (ACPI_TO_POINTER ((ACPI_SIZE) where)); 410} 411 412 413/****************************************************************************** 414 * 415 * FUNCTION: AcpiOsUnmapMemory 416 * 417 * PARAMETERS: where - Logical address of memory to be unmapped 418 * length - How much memory to unmap 419 * 420 * RETURN: None. 421 * 422 * DESCRIPTION: Delete a previously created mapping. Where and Length must 423 * correspond to a previous mapping exactly. 424 * 425 *****************************************************************************/ 426 427void 428AcpiOsUnmapMemory ( 429 void *where, 430 ACPI_SIZE length) 431{ 432 433 return; 434} 435 436 437/****************************************************************************** 438 * 439 * FUNCTION: AcpiOsAllocate 440 * 441 * PARAMETERS: Size - Amount to allocate, in bytes 442 * 443 * RETURN: Pointer to the new allocation. Null on error. 444 * 445 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. 446 * 447 *****************************************************************************/ 448 449void * 450AcpiOsAllocate ( 451 ACPI_SIZE size) 452{ 453 void *Mem; 454 455 456 Mem = (void *) malloc ((size_t) size); 457 return (Mem); 458} 459 460 461/****************************************************************************** 462 * 463 * FUNCTION: AcpiOsFree 464 * 465 * PARAMETERS: mem - Pointer to previously allocated memory 466 * 467 * RETURN: None. 468 * 469 * DESCRIPTION: Free memory allocated via AcpiOsAllocate 470 * 471 *****************************************************************************/ 472 473void 474AcpiOsFree ( 475 void *mem) 476{ 477 478 free (mem); 479} 480 481 482#ifdef ACPI_SINGLE_THREADED 483/****************************************************************************** 484 * 485 * FUNCTION: Semaphore stub functions 486 * 487 * DESCRIPTION: Stub functions used for single-thread applications that do 488 * not require semaphore synchronization. Full implementations 489 * of these functions appear after the stubs. 490 * 491 *****************************************************************************/ 492 493ACPI_STATUS 494AcpiOsCreateSemaphore ( 495 UINT32 MaxUnits, 496 UINT32 InitialUnits, 497 ACPI_HANDLE *OutHandle) 498{ 499 *OutHandle = (ACPI_HANDLE) 1; 500 return (AE_OK); 501} 502 503ACPI_STATUS 504AcpiOsDeleteSemaphore ( 505 ACPI_HANDLE Handle) 506{ 507 return (AE_OK); 508} 509 510ACPI_STATUS 511AcpiOsWaitSemaphore ( 512 ACPI_HANDLE Handle, 513 UINT32 Units, 514 UINT16 Timeout) 515{ 516 return (AE_OK); 517} 518 519ACPI_STATUS 520AcpiOsSignalSemaphore ( 521 ACPI_HANDLE Handle, 522 UINT32 Units) 523{ 524 return (AE_OK); 525} 526 527#else 528/****************************************************************************** 529 * 530 * FUNCTION: AcpiOsCreateSemaphore 531 * 532 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore 533 * OutHandle - Where a handle will be returned 534 * 535 * RETURN: Status 536 * 537 * DESCRIPTION: Create an OS semaphore 538 * 539 *****************************************************************************/ 540 541ACPI_STATUS 542AcpiOsCreateSemaphore ( 543 UINT32 MaxUnits, 544 UINT32 InitialUnits, 545 ACPI_HANDLE *OutHandle) 546{ 547 sem_t *Sem; 548 549 550 if (!OutHandle) 551 { 552 return (AE_BAD_PARAMETER); 553 } 554 555#ifdef __APPLE__ 556 { 557 char *SemaphoreName = tmpnam (NULL); 558 559 Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits); 560 if (!Sem) 561 { 562 return (AE_NO_MEMORY); 563 } 564 sem_unlink (SemaphoreName); /* This just deletes the name */ 565 } 566 567#else 568 Sem = AcpiOsAllocate (sizeof (sem_t)); 569 if (!Sem) 570 { 571 return (AE_NO_MEMORY); 572 } 573 574 if (sem_init (Sem, 0, InitialUnits) == -1) 575 { 576 AcpiOsFree (Sem); 577 return (AE_BAD_PARAMETER); 578 } 579#endif 580 581 *OutHandle = (ACPI_HANDLE) Sem; 582 return (AE_OK); 583} 584 585 586/****************************************************************************** 587 * 588 * FUNCTION: AcpiOsDeleteSemaphore 589 * 590 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 591 * 592 * RETURN: Status 593 * 594 * DESCRIPTION: Delete an OS semaphore 595 * 596 *****************************************************************************/ 597 598ACPI_STATUS 599AcpiOsDeleteSemaphore ( 600 ACPI_HANDLE Handle) 601{ 602 sem_t *Sem = (sem_t *) Handle; 603 604 605 if (!Sem) 606 { 607 return (AE_BAD_PARAMETER); 608 } 609 610 if (sem_destroy (Sem) == -1) 611 { 612 return (AE_BAD_PARAMETER); 613 } 614 615 return (AE_OK); 616} 617 618 619/****************************************************************************** 620 * 621 * FUNCTION: AcpiOsWaitSemaphore 622 * 623 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 624 * Units - How many units to wait for 625 * Timeout - How long to wait 626 * 627 * RETURN: Status 628 * 629 * DESCRIPTION: Wait for units 630 * 631 *****************************************************************************/ 632 633ACPI_STATUS 634AcpiOsWaitSemaphore ( 635 ACPI_HANDLE Handle, 636 UINT32 Units, 637 UINT16 Timeout) 638{ 639 ACPI_STATUS Status = AE_OK; 640 sem_t *Sem = (sem_t *) Handle; 641 struct timespec T; 642 643 644 if (!Sem) 645 { 646 return (AE_BAD_PARAMETER); 647 } 648 649 switch (Timeout) 650 { 651 /* 652 * No Wait: 653 * -------- 654 * A zero timeout value indicates that we shouldn't wait - just 655 * acquire the semaphore if available otherwise return AE_TIME 656 * (a.k.a. 'would block'). 657 */ 658 case 0: 659 660 if (sem_trywait(Sem) == -1) 661 { 662 Status = (AE_TIME); 663 } 664 break; 665 666 /* Wait Indefinitely */ 667 668 case ACPI_WAIT_FOREVER: 669 670 if (sem_wait (Sem)) 671 { 672 Status = (AE_TIME); 673 } 674 break; 675 676 /* Wait with Timeout */ 677 678 default: 679 680 T.tv_sec = Timeout / 1000; 681 T.tv_nsec = (Timeout - (T.tv_sec * 1000)) * 1000000; 682 683#ifdef ACPI_USE_ALTERNATE_TIMEOUT 684 /* 685 * Alternate timeout mechanism for environments where 686 * sem_timedwait is not available or does not work properly. 687 */ 688 while (Timeout) 689 { 690 if (sem_trywait (Sem) == 0) 691 { 692 /* Got the semaphore */ 693 return (AE_OK); 694 } 695 usleep (1000); /* one millisecond */ 696 Timeout--; 697 } 698 Status = (AE_TIME); 699#else 700 701 if (sem_timedwait (Sem, &T)) 702 { 703 Status = (AE_TIME); 704 } 705#endif 706 707 break; 708 } 709 710 return (Status); 711} 712 713 714/****************************************************************************** 715 * 716 * FUNCTION: AcpiOsSignalSemaphore 717 * 718 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 719 * Units - Number of units to send 720 * 721 * RETURN: Status 722 * 723 * DESCRIPTION: Send units 724 * 725 *****************************************************************************/ 726 727ACPI_STATUS 728AcpiOsSignalSemaphore ( 729 ACPI_HANDLE Handle, 730 UINT32 Units) 731{ 732 sem_t *Sem = (sem_t *)Handle; 733 734 735 if (!Sem) 736 { 737 return (AE_BAD_PARAMETER); 738 } 739 740 if (sem_post (Sem) == -1) 741 { 742 return (AE_LIMIT); 743 } 744 745 return (AE_OK); 746} 747 748#endif /* ACPI_SINGLE_THREADED */ 749 750 751/****************************************************************************** 752 * 753 * FUNCTION: Spinlock interfaces 754 * 755 * DESCRIPTION: Map these interfaces to semaphore interfaces 756 * 757 *****************************************************************************/ 758 759ACPI_STATUS 760AcpiOsCreateLock ( 761 ACPI_SPINLOCK *OutHandle) 762{ 763 764 return (AcpiOsCreateSemaphore (1, 1, OutHandle)); 765} 766 767 768void 769AcpiOsDeleteLock ( 770 ACPI_SPINLOCK Handle) 771{ 772 AcpiOsDeleteSemaphore (Handle); 773} 774 775 776ACPI_CPU_FLAGS 777AcpiOsAcquireLock ( 778 ACPI_HANDLE Handle) 779{ 780 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF); 781 return (0); 782} 783 784 785void 786AcpiOsReleaseLock ( 787 ACPI_SPINLOCK Handle, 788 ACPI_CPU_FLAGS Flags) 789{ 790 AcpiOsSignalSemaphore (Handle, 1); 791} 792 793 794/****************************************************************************** 795 * 796 * FUNCTION: AcpiOsInstallInterruptHandler 797 * 798 * PARAMETERS: InterruptNumber - Level handler should respond to. 799 * Isr - Address of the ACPI interrupt handler 800 * ExceptPtr - Where status is returned 801 * 802 * RETURN: Handle to the newly installed handler. 803 * 804 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI 805 * OS-independent handler. 806 * 807 *****************************************************************************/ 808 809UINT32 810AcpiOsInstallInterruptHandler ( 811 UINT32 InterruptNumber, 812 ACPI_OSD_HANDLER ServiceRoutine, 813 void *Context) 814{ 815 816 return (AE_OK); 817} 818 819 820/****************************************************************************** 821 * 822 * FUNCTION: AcpiOsRemoveInterruptHandler 823 * 824 * PARAMETERS: Handle - Returned when handler was installed 825 * 826 * RETURN: Status 827 * 828 * DESCRIPTION: Uninstalls an interrupt handler. 829 * 830 *****************************************************************************/ 831 832ACPI_STATUS 833AcpiOsRemoveInterruptHandler ( 834 UINT32 InterruptNumber, 835 ACPI_OSD_HANDLER ServiceRoutine) 836{ 837 838 return (AE_OK); 839} 840 841 842/****************************************************************************** 843 * 844 * FUNCTION: AcpiOsStall 845 * 846 * PARAMETERS: microseconds - Time to sleep 847 * 848 * RETURN: Blocks until sleep is completed. 849 * 850 * DESCRIPTION: Sleep at microsecond granularity 851 * 852 *****************************************************************************/ 853 854void 855AcpiOsStall ( 856 UINT32 microseconds) 857{ 858 859 if (microseconds) 860 { 861 usleep (microseconds); 862 } 863} 864 865 866/****************************************************************************** 867 * 868 * FUNCTION: AcpiOsSleep 869 * 870 * PARAMETERS: milliseconds - Time to sleep 871 * 872 * RETURN: Blocks until sleep is completed. 873 * 874 * DESCRIPTION: Sleep at millisecond granularity 875 * 876 *****************************************************************************/ 877 878void 879AcpiOsSleep ( 880 UINT64 milliseconds) 881{ 882 883 sleep (milliseconds / 1000); /* Sleep for whole seconds */ 884 885 /* 886 * Arg to usleep() must be less than 1,000,000 (1 second) 887 */ 888 usleep ((milliseconds % 1000) * 1000); /* Sleep for remaining usecs */ 889} 890 891 892/****************************************************************************** 893 * 894 * FUNCTION: AcpiOsGetTimer 895 * 896 * PARAMETERS: None 897 * 898 * RETURN: Current time in 100 nanosecond units 899 * 900 * DESCRIPTION: Get the current system time 901 * 902 *****************************************************************************/ 903 904UINT64 905AcpiOsGetTimer ( 906 void) 907{ 908 struct timeval time; 909 910 911 gettimeofday (&time, NULL); 912 913 /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */ 914 915 return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10)); 916} 917 918 919/****************************************************************************** 920 * 921 * FUNCTION: AcpiOsReadPciConfiguration 922 * 923 * PARAMETERS: PciId - Seg/Bus/Dev 924 * Register - Device Register 925 * Value - Buffer where value is placed 926 * Width - Number of bits 927 * 928 * RETURN: Status 929 * 930 * DESCRIPTION: Read data from PCI configuration space 931 * 932 *****************************************************************************/ 933 934ACPI_STATUS 935AcpiOsReadPciConfiguration ( 936 ACPI_PCI_ID *PciId, 937 UINT32 Register, 938 UINT64 *Value, 939 UINT32 Width) 940{ 941 942 return (AE_OK); 943} 944 945 946/****************************************************************************** 947 * 948 * FUNCTION: AcpiOsWritePciConfiguration 949 * 950 * PARAMETERS: PciId - Seg/Bus/Dev 951 * Register - Device Register 952 * Value - Value to be written 953 * Width - Number of bits 954 * 955 * RETURN: Status. 956 * 957 * DESCRIPTION: Write data to PCI configuration space 958 * 959 *****************************************************************************/ 960 961ACPI_STATUS 962AcpiOsWritePciConfiguration ( 963 ACPI_PCI_ID *PciId, 964 UINT32 Register, 965 UINT64 Value, 966 UINT32 Width) 967{ 968 969 return (AE_OK); 970} 971 972 973/****************************************************************************** 974 * 975 * FUNCTION: AcpiOsReadPort 976 * 977 * PARAMETERS: Address - Address of I/O port/register to read 978 * Value - Where value is placed 979 * Width - Number of bits 980 * 981 * RETURN: Value read from port 982 * 983 * DESCRIPTION: Read data from an I/O port or register 984 * 985 *****************************************************************************/ 986 987ACPI_STATUS 988AcpiOsReadPort ( 989 ACPI_IO_ADDRESS Address, 990 UINT32 *Value, 991 UINT32 Width) 992{ 993 994 switch (Width) 995 { 996 case 8: 997 *Value = 0xFF; 998 break; 999 1000 case 16: 1001 *Value = 0xFFFF; 1002 break; 1003 1004 case 32: 1005 *Value = 0xFFFFFFFF; 1006 break; 1007 1008 default: 1009 return (AE_BAD_PARAMETER); 1010 } 1011 1012 return (AE_OK); 1013} 1014 1015 1016/****************************************************************************** 1017 * 1018 * FUNCTION: AcpiOsWritePort 1019 * 1020 * PARAMETERS: Address - Address of I/O port/register to write 1021 * Value - Value to write 1022 * Width - Number of bits 1023 * 1024 * RETURN: None 1025 * 1026 * DESCRIPTION: Write data to an I/O port or register 1027 * 1028 *****************************************************************************/ 1029 1030ACPI_STATUS 1031AcpiOsWritePort ( 1032 ACPI_IO_ADDRESS Address, 1033 UINT32 Value, 1034 UINT32 Width) 1035{ 1036 1037 return (AE_OK); 1038} 1039 1040 1041/****************************************************************************** 1042 * 1043 * FUNCTION: AcpiOsReadMemory 1044 * 1045 * PARAMETERS: Address - Physical Memory Address to read 1046 * Value - Where value is placed 1047 * Width - Number of bits (8,16,32, or 64) 1048 * 1049 * RETURN: Value read from physical memory address. Always returned 1050 * as a 64-bit integer, regardless of the read width. 1051 * 1052 * DESCRIPTION: Read data from a physical memory address 1053 * 1054 *****************************************************************************/ 1055 1056ACPI_STATUS 1057AcpiOsReadMemory ( 1058 ACPI_PHYSICAL_ADDRESS Address, 1059 UINT64 *Value, 1060 UINT32 Width) 1061{ 1062 1063 switch (Width) 1064 { 1065 case 8: 1066 case 16: 1067 case 32: 1068 case 64: 1069 *Value = 0; 1070 break; 1071 1072 default: 1073 return (AE_BAD_PARAMETER); 1074 } 1075 return (AE_OK); 1076} 1077 1078 1079/****************************************************************************** 1080 * 1081 * FUNCTION: AcpiOsWriteMemory 1082 * 1083 * PARAMETERS: Address - Physical Memory Address to write 1084 * Value - Value to write 1085 * Width - Number of bits (8,16,32, or 64) 1086 * 1087 * RETURN: None 1088 * 1089 * DESCRIPTION: Write data to a physical memory address 1090 * 1091 *****************************************************************************/ 1092 1093ACPI_STATUS 1094AcpiOsWriteMemory ( 1095 ACPI_PHYSICAL_ADDRESS Address, 1096 UINT64 Value, 1097 UINT32 Width) 1098{ 1099 1100 return (AE_OK); 1101} 1102 1103 1104/****************************************************************************** 1105 * 1106 * FUNCTION: AcpiOsReadable 1107 * 1108 * PARAMETERS: Pointer - Area to be verified 1109 * Length - Size of area 1110 * 1111 * RETURN: TRUE if readable for entire length 1112 * 1113 * DESCRIPTION: Verify that a pointer is valid for reading 1114 * 1115 *****************************************************************************/ 1116 1117BOOLEAN 1118AcpiOsReadable ( 1119 void *Pointer, 1120 ACPI_SIZE Length) 1121{ 1122 1123 return (TRUE); 1124} 1125 1126 1127/****************************************************************************** 1128 * 1129 * FUNCTION: AcpiOsWritable 1130 * 1131 * PARAMETERS: Pointer - Area to be verified 1132 * Length - Size of area 1133 * 1134 * RETURN: TRUE if writable for entire length 1135 * 1136 * DESCRIPTION: Verify that a pointer is valid for writing 1137 * 1138 *****************************************************************************/ 1139 1140BOOLEAN 1141AcpiOsWritable ( 1142 void *Pointer, 1143 ACPI_SIZE Length) 1144{ 1145 1146 return (TRUE); 1147} 1148 1149 1150/****************************************************************************** 1151 * 1152 * FUNCTION: AcpiOsSignal 1153 * 1154 * PARAMETERS: Function - ACPI CA signal function code 1155 * Info - Pointer to function-dependent structure 1156 * 1157 * RETURN: Status 1158 * 1159 * DESCRIPTION: Miscellaneous functions. Example implementation only. 1160 * 1161 *****************************************************************************/ 1162 1163ACPI_STATUS 1164AcpiOsSignal ( 1165 UINT32 Function, 1166 void *Info) 1167{ 1168 1169 switch (Function) 1170 { 1171 case ACPI_SIGNAL_FATAL: 1172 break; 1173 1174 case ACPI_SIGNAL_BREAKPOINT: 1175 break; 1176 1177 default: 1178 break; 1179 } 1180 1181 return (AE_OK); 1182} 1183 1184/* Optional multi-thread support */ 1185 1186#ifndef ACPI_SINGLE_THREADED 1187/****************************************************************************** 1188 * 1189 * FUNCTION: AcpiOsGetThreadId 1190 * 1191 * PARAMETERS: None 1192 * 1193 * RETURN: Id of the running thread 1194 * 1195 * DESCRIPTION: Get the ID of the current (running) thread 1196 * 1197 *****************************************************************************/ 1198 1199ACPI_THREAD_ID 1200AcpiOsGetThreadId ( 1201 void) 1202{ 1203 pthread_t thread; 1204 1205 1206 thread = pthread_self(); 1207 return (ACPI_CAST_PTHREAD_T (thread)); 1208} 1209 1210 1211/****************************************************************************** 1212 * 1213 * FUNCTION: AcpiOsExecute 1214 * 1215 * PARAMETERS: Type - Type of execution 1216 * Function - Address of the function to execute 1217 * Context - Passed as a parameter to the function 1218 * 1219 * RETURN: Status. 1220 * 1221 * DESCRIPTION: Execute a new thread 1222 * 1223 *****************************************************************************/ 1224 1225ACPI_STATUS 1226AcpiOsExecute ( 1227 ACPI_EXECUTE_TYPE Type, 1228 ACPI_OSD_EXEC_CALLBACK Function, 1229 void *Context) 1230{ 1231 pthread_t thread; 1232 int ret; 1233 1234 1235 ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context); 1236 if (ret) 1237 { 1238 AcpiOsPrintf("Create thread failed"); 1239 } 1240 return (0); 1241} 1242 1243#endif /* ACPI_SINGLE_THREADED */ 1244 1245 1246/****************************************************************************** 1247 * 1248 * FUNCTION: AcpiOsWaitEventsComplete 1249 * 1250 * PARAMETERS: None 1251 * 1252 * RETURN: None 1253 * 1254 * DESCRIPTION: Wait for all asynchronous events to complete. This 1255 * implementation does nothing. 1256 * 1257 *****************************************************************************/ 1258 1259void 1260AcpiOsWaitEventsComplete ( 1261 void) 1262{ 1263 return; 1264} 1265