1 /****************************************************************************** 2 * 3 * Module Name: osunixxf - UNIX OSL interfaces 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2013, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 45 /* 46 * These interfaces are required in order to compile the ASL compiler and the 47 * various ACPICA tools under Linux or other Unix-like system. 48 * 49 * Note: Use #define __APPLE__ for OS X generation. 50 */ 51 #include <contrib/dev/acpica/include/acpi.h> 52 #include <contrib/dev/acpica/include/accommon.h> 53 #include <contrib/dev/acpica/include/amlcode.h> 54 #include <contrib/dev/acpica/include/acparser.h> 55 #include <contrib/dev/acpica/include/acdebug.h> 56 57 #include <stdio.h> 58 #include <stdlib.h> 59 #include <stdarg.h> 60 #include <unistd.h> 61 #include <sys/time.h> 62 #include <semaphore.h> 63 #include <pthread.h> 64 #include <errno.h> 65 66 #define _COMPONENT ACPI_OS_SERVICES 67 ACPI_MODULE_NAME ("osunixxf") 68 69 70 extern FILE *AcpiGbl_DebugFile; 71 FILE *AcpiGbl_OutputFile; 72 73 74 /* Upcalls to AcpiExec */ 75 76 ACPI_PHYSICAL_ADDRESS 77 AeLocalGetRootPointer ( 78 void); 79 80 void 81 AeTableOverride ( 82 ACPI_TABLE_HEADER *ExistingTable, 83 ACPI_TABLE_HEADER **NewTable); 84 85 typedef void* (*PTHREAD_CALLBACK) (void *); 86 87 /* Buffer used by AcpiOsVprintf */ 88 89 #define ACPI_VPRINTF_BUFFER_SIZE 512 90 91 /* Apple-specific */ 92 93 #ifdef __APPLE__ 94 #define sem_destroy sem_close 95 #endif 96 97 98 /****************************************************************************** 99 * 100 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate 101 * 102 * PARAMETERS: None 103 * 104 * RETURN: Status 105 * 106 * DESCRIPTION: Init and terminate. Nothing to do. 107 * 108 *****************************************************************************/ 109 110 ACPI_STATUS 111 AcpiOsInitialize ( 112 void) 113 { 114 115 AcpiGbl_OutputFile = stdout; 116 return (AE_OK); 117 } 118 119 120 ACPI_STATUS 121 AcpiOsTerminate ( 122 void) 123 { 124 125 return (AE_OK); 126 } 127 128 129 /****************************************************************************** 130 * 131 * FUNCTION: AcpiOsGetRootPointer 132 * 133 * PARAMETERS: None 134 * 135 * RETURN: RSDP physical address 136 * 137 * DESCRIPTION: Gets the ACPI root pointer (RSDP) 138 * 139 *****************************************************************************/ 140 141 ACPI_PHYSICAL_ADDRESS 142 AcpiOsGetRootPointer ( 143 void) 144 { 145 146 return (AeLocalGetRootPointer ()); 147 } 148 149 150 /****************************************************************************** 151 * 152 * FUNCTION: AcpiOsPredefinedOverride 153 * 154 * PARAMETERS: InitVal - Initial value of the predefined object 155 * NewVal - The new value for the object 156 * 157 * RETURN: Status, pointer to value. Null pointer returned if not 158 * overriding. 159 * 160 * DESCRIPTION: Allow the OS to override predefined names 161 * 162 *****************************************************************************/ 163 164 ACPI_STATUS 165 AcpiOsPredefinedOverride ( 166 const ACPI_PREDEFINED_NAMES *InitVal, 167 ACPI_STRING *NewVal) 168 { 169 170 if (!InitVal || !NewVal) 171 { 172 return (AE_BAD_PARAMETER); 173 } 174 175 *NewVal = NULL; 176 return (AE_OK); 177 } 178 179 180 /****************************************************************************** 181 * 182 * FUNCTION: AcpiOsTableOverride 183 * 184 * PARAMETERS: ExistingTable - Header of current table (probably 185 * firmware) 186 * NewTable - Where an entire new table is returned. 187 * 188 * RETURN: Status, pointer to new table. Null pointer returned if no 189 * table is available to override 190 * 191 * DESCRIPTION: Return a different version of a table if one is available 192 * 193 *****************************************************************************/ 194 195 ACPI_STATUS 196 AcpiOsTableOverride ( 197 ACPI_TABLE_HEADER *ExistingTable, 198 ACPI_TABLE_HEADER **NewTable) 199 { 200 201 if (!ExistingTable || !NewTable) 202 { 203 return (AE_BAD_PARAMETER); 204 } 205 206 *NewTable = NULL; 207 208 #ifdef ACPI_EXEC_APP 209 210 AeTableOverride (ExistingTable, NewTable); 211 return (AE_OK); 212 #else 213 214 return (AE_NO_ACPI_TABLES); 215 #endif 216 } 217 218 219 /****************************************************************************** 220 * 221 * FUNCTION: AcpiOsPhysicalTableOverride 222 * 223 * PARAMETERS: ExistingTable - Header of current table (probably firmware) 224 * NewAddress - Where new table address is returned 225 * (Physical address) 226 * NewTableLength - Where new table length is returned 227 * 228 * RETURN: Status, address/length of new table. Null pointer returned 229 * if no table is available to override. 230 * 231 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. 232 * 233 *****************************************************************************/ 234 235 ACPI_STATUS 236 AcpiOsPhysicalTableOverride ( 237 ACPI_TABLE_HEADER *ExistingTable, 238 ACPI_PHYSICAL_ADDRESS *NewAddress, 239 UINT32 *NewTableLength) 240 { 241 242 return (AE_SUPPORT); 243 } 244 245 246 /****************************************************************************** 247 * 248 * FUNCTION: AcpiOsRedirectOutput 249 * 250 * PARAMETERS: Destination - An open file handle/pointer 251 * 252 * RETURN: None 253 * 254 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf 255 * 256 *****************************************************************************/ 257 258 void 259 AcpiOsRedirectOutput ( 260 void *Destination) 261 { 262 263 AcpiGbl_OutputFile = Destination; 264 } 265 266 267 /****************************************************************************** 268 * 269 * FUNCTION: AcpiOsPrintf 270 * 271 * PARAMETERS: fmt, ... - Standard printf format 272 * 273 * RETURN: None 274 * 275 * DESCRIPTION: Formatted output. Note: very similar to AcpiOsVprintf 276 * (performance), changes should be tracked in both functions. 277 * 278 *****************************************************************************/ 279 280 void ACPI_INTERNAL_VAR_XFACE 281 AcpiOsPrintf ( 282 const char *Fmt, 283 ...) 284 { 285 va_list Args; 286 UINT8 Flags; 287 288 289 Flags = AcpiGbl_DbOutputFlags; 290 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT) 291 { 292 /* Output is directable to either a file (if open) or the console */ 293 294 if (AcpiGbl_DebugFile) 295 { 296 /* Output file is open, send the output there */ 297 298 va_start (Args, Fmt); 299 vfprintf (AcpiGbl_DebugFile, Fmt, Args); 300 va_end (Args); 301 } 302 else 303 { 304 /* No redirection, send output to console (once only!) */ 305 306 Flags |= ACPI_DB_CONSOLE_OUTPUT; 307 } 308 } 309 310 if (Flags & ACPI_DB_CONSOLE_OUTPUT) 311 { 312 va_start (Args, Fmt); 313 vfprintf (AcpiGbl_OutputFile, Fmt, Args); 314 va_end (Args); 315 } 316 } 317 318 319 /****************************************************************************** 320 * 321 * FUNCTION: AcpiOsVprintf 322 * 323 * PARAMETERS: fmt - Standard printf format 324 * args - Argument list 325 * 326 * RETURN: None 327 * 328 * DESCRIPTION: Formatted output with argument list pointer. Note: very 329 * similar to AcpiOsPrintf, changes should be tracked in both 330 * functions. 331 * 332 *****************************************************************************/ 333 334 void 335 AcpiOsVprintf ( 336 const char *Fmt, 337 va_list Args) 338 { 339 UINT8 Flags; 340 char Buffer[ACPI_VPRINTF_BUFFER_SIZE]; 341 342 343 /* 344 * We build the output string in a local buffer because we may be 345 * outputting the buffer twice. Using vfprintf is problematic because 346 * some implementations modify the args pointer/structure during 347 * execution. Thus, we use the local buffer for portability. 348 * 349 * Note: Since this module is intended for use by the various ACPICA 350 * utilities/applications, we can safely declare the buffer on the stack. 351 * Also, This function is used for relatively small error messages only. 352 */ 353 vsnprintf (Buffer, ACPI_VPRINTF_BUFFER_SIZE, Fmt, Args); 354 355 Flags = AcpiGbl_DbOutputFlags; 356 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT) 357 { 358 /* Output is directable to either a file (if open) or the console */ 359 360 if (AcpiGbl_DebugFile) 361 { 362 /* Output file is open, send the output there */ 363 364 fputs (Buffer, AcpiGbl_DebugFile); 365 } 366 else 367 { 368 /* No redirection, send output to console (once only!) */ 369 370 Flags |= ACPI_DB_CONSOLE_OUTPUT; 371 } 372 } 373 374 if (Flags & ACPI_DB_CONSOLE_OUTPUT) 375 { 376 fputs (Buffer, AcpiGbl_OutputFile); 377 } 378 } 379 380 381 /****************************************************************************** 382 * 383 * FUNCTION: AcpiOsGetLine 384 * 385 * PARAMETERS: Buffer - Where to return the command line 386 * BufferLength - Maximum length of Buffer 387 * BytesRead - Where the actual byte count is returned 388 * 389 * RETURN: Status and actual bytes read 390 * 391 * DESCRIPTION: Formatted input with argument list pointer 392 * 393 *****************************************************************************/ 394 395 ACPI_STATUS 396 AcpiOsGetLine ( 397 char *Buffer, 398 UINT32 BufferLength, 399 UINT32 *BytesRead) 400 { 401 int Temp; 402 UINT32 i; 403 404 405 for (i = 0; ; i++) 406 { 407 if (i >= BufferLength) 408 { 409 return (AE_BUFFER_OVERFLOW); 410 } 411 412 if ((Temp = getchar ()) == EOF) 413 { 414 return (AE_ERROR); 415 } 416 417 if (!Temp || Temp == '\n') 418 { 419 break; 420 } 421 422 Buffer [i] = (char) Temp; 423 } 424 425 /* Null terminate the buffer */ 426 427 Buffer [i] = 0; 428 429 /* Return the number of bytes in the string */ 430 431 if (BytesRead) 432 { 433 *BytesRead = i; 434 } 435 return (AE_OK); 436 } 437 438 439 /****************************************************************************** 440 * 441 * FUNCTION: AcpiOsMapMemory 442 * 443 * PARAMETERS: where - Physical address of memory to be mapped 444 * length - How much memory to map 445 * 446 * RETURN: Pointer to mapped memory. Null on error. 447 * 448 * DESCRIPTION: Map physical memory into caller's address space 449 * 450 *****************************************************************************/ 451 452 void * 453 AcpiOsMapMemory ( 454 ACPI_PHYSICAL_ADDRESS where, 455 ACPI_SIZE length) 456 { 457 458 return (ACPI_TO_POINTER ((ACPI_SIZE) where)); 459 } 460 461 462 /****************************************************************************** 463 * 464 * FUNCTION: AcpiOsUnmapMemory 465 * 466 * PARAMETERS: where - Logical address of memory to be unmapped 467 * length - How much memory to unmap 468 * 469 * RETURN: None. 470 * 471 * DESCRIPTION: Delete a previously created mapping. Where and Length must 472 * correspond to a previous mapping exactly. 473 * 474 *****************************************************************************/ 475 476 void 477 AcpiOsUnmapMemory ( 478 void *where, 479 ACPI_SIZE length) 480 { 481 482 return; 483 } 484 485 486 /****************************************************************************** 487 * 488 * FUNCTION: AcpiOsAllocate 489 * 490 * PARAMETERS: Size - Amount to allocate, in bytes 491 * 492 * RETURN: Pointer to the new allocation. Null on error. 493 * 494 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. 495 * 496 *****************************************************************************/ 497 498 void * 499 AcpiOsAllocate ( 500 ACPI_SIZE size) 501 { 502 void *Mem; 503 504 505 Mem = (void *) malloc ((size_t) size); 506 return (Mem); 507 } 508 509 510 /****************************************************************************** 511 * 512 * FUNCTION: AcpiOsFree 513 * 514 * PARAMETERS: mem - Pointer to previously allocated memory 515 * 516 * RETURN: None. 517 * 518 * DESCRIPTION: Free memory allocated via AcpiOsAllocate 519 * 520 *****************************************************************************/ 521 522 void 523 AcpiOsFree ( 524 void *mem) 525 { 526 527 free (mem); 528 } 529 530 531 #ifdef ACPI_SINGLE_THREADED 532 /****************************************************************************** 533 * 534 * FUNCTION: Semaphore stub functions 535 * 536 * DESCRIPTION: Stub functions used for single-thread applications that do 537 * not require semaphore synchronization. Full implementations 538 * of these functions appear after the stubs. 539 * 540 *****************************************************************************/ 541 542 ACPI_STATUS 543 AcpiOsCreateSemaphore ( 544 UINT32 MaxUnits, 545 UINT32 InitialUnits, 546 ACPI_HANDLE *OutHandle) 547 { 548 *OutHandle = (ACPI_HANDLE) 1; 549 return (AE_OK); 550 } 551 552 ACPI_STATUS 553 AcpiOsDeleteSemaphore ( 554 ACPI_HANDLE Handle) 555 { 556 return (AE_OK); 557 } 558 559 ACPI_STATUS 560 AcpiOsWaitSemaphore ( 561 ACPI_HANDLE Handle, 562 UINT32 Units, 563 UINT16 Timeout) 564 { 565 return (AE_OK); 566 } 567 568 ACPI_STATUS 569 AcpiOsSignalSemaphore ( 570 ACPI_HANDLE Handle, 571 UINT32 Units) 572 { 573 return (AE_OK); 574 } 575 576 #else 577 /****************************************************************************** 578 * 579 * FUNCTION: AcpiOsCreateSemaphore 580 * 581 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore 582 * OutHandle - Where a handle will be returned 583 * 584 * RETURN: Status 585 * 586 * DESCRIPTION: Create an OS semaphore 587 * 588 *****************************************************************************/ 589 590 ACPI_STATUS 591 AcpiOsCreateSemaphore ( 592 UINT32 MaxUnits, 593 UINT32 InitialUnits, 594 ACPI_HANDLE *OutHandle) 595 { 596 sem_t *Sem; 597 598 599 if (!OutHandle) 600 { 601 return (AE_BAD_PARAMETER); 602 } 603 604 #ifdef __APPLE__ 605 { 606 char *SemaphoreName = tmpnam (NULL); 607 608 Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits); 609 if (!Sem) 610 { 611 return (AE_NO_MEMORY); 612 } 613 sem_unlink (SemaphoreName); /* This just deletes the name */ 614 } 615 616 #else 617 Sem = AcpiOsAllocate (sizeof (sem_t)); 618 if (!Sem) 619 { 620 return (AE_NO_MEMORY); 621 } 622 623 if (sem_init (Sem, 0, InitialUnits) == -1) 624 { 625 AcpiOsFree (Sem); 626 return (AE_BAD_PARAMETER); 627 } 628 #endif 629 630 *OutHandle = (ACPI_HANDLE) Sem; 631 return (AE_OK); 632 } 633 634 635 /****************************************************************************** 636 * 637 * FUNCTION: AcpiOsDeleteSemaphore 638 * 639 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 640 * 641 * RETURN: Status 642 * 643 * DESCRIPTION: Delete an OS semaphore 644 * 645 *****************************************************************************/ 646 647 ACPI_STATUS 648 AcpiOsDeleteSemaphore ( 649 ACPI_HANDLE Handle) 650 { 651 sem_t *Sem = (sem_t *) Handle; 652 653 654 if (!Sem) 655 { 656 return (AE_BAD_PARAMETER); 657 } 658 659 if (sem_destroy (Sem) == -1) 660 { 661 return (AE_BAD_PARAMETER); 662 } 663 664 return (AE_OK); 665 } 666 667 668 /****************************************************************************** 669 * 670 * FUNCTION: AcpiOsWaitSemaphore 671 * 672 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 673 * Units - How many units to wait for 674 * MsecTimeout - How long to wait (milliseconds) 675 * 676 * RETURN: Status 677 * 678 * DESCRIPTION: Wait for units 679 * 680 *****************************************************************************/ 681 682 ACPI_STATUS 683 AcpiOsWaitSemaphore ( 684 ACPI_HANDLE Handle, 685 UINT32 Units, 686 UINT16 MsecTimeout) 687 { 688 ACPI_STATUS Status = AE_OK; 689 sem_t *Sem = (sem_t *) Handle; 690 #ifndef ACPI_USE_ALTERNATE_TIMEOUT 691 struct timespec Time; 692 int RetVal; 693 #endif 694 695 696 if (!Sem) 697 { 698 return (AE_BAD_PARAMETER); 699 } 700 701 switch (MsecTimeout) 702 { 703 /* 704 * No Wait: 705 * -------- 706 * A zero timeout value indicates that we shouldn't wait - just 707 * acquire the semaphore if available otherwise return AE_TIME 708 * (a.k.a. 'would block'). 709 */ 710 case 0: 711 712 if (sem_trywait(Sem) == -1) 713 { 714 Status = (AE_TIME); 715 } 716 break; 717 718 /* Wait Indefinitely */ 719 720 case ACPI_WAIT_FOREVER: 721 722 if (sem_wait (Sem)) 723 { 724 Status = (AE_TIME); 725 } 726 break; 727 728 /* Wait with MsecTimeout */ 729 730 default: 731 732 #ifdef ACPI_USE_ALTERNATE_TIMEOUT 733 /* 734 * Alternate timeout mechanism for environments where 735 * sem_timedwait is not available or does not work properly. 736 */ 737 while (MsecTimeout) 738 { 739 if (sem_trywait (Sem) == 0) 740 { 741 /* Got the semaphore */ 742 return (AE_OK); 743 } 744 745 if (MsecTimeout >= 10) 746 { 747 MsecTimeout -= 10; 748 usleep (10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */ 749 } 750 else 751 { 752 MsecTimeout--; 753 usleep (ACPI_USEC_PER_MSEC); /* one millisecond */ 754 } 755 } 756 Status = (AE_TIME); 757 #else 758 /* 759 * The interface to sem_timedwait is an absolute time, so we need to 760 * get the current time, then add in the millisecond Timeout value. 761 */ 762 if (clock_gettime (CLOCK_REALTIME, &Time) == -1) 763 { 764 perror ("clock_gettime"); 765 return (AE_TIME); 766 } 767 768 Time.tv_sec += (MsecTimeout / ACPI_MSEC_PER_SEC); 769 Time.tv_nsec += ((MsecTimeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC); 770 771 /* Handle nanosecond overflow (field must be less than one second) */ 772 773 if (Time.tv_nsec >= ACPI_NSEC_PER_SEC) 774 { 775 Time.tv_sec += (Time.tv_nsec / ACPI_NSEC_PER_SEC); 776 Time.tv_nsec = (Time.tv_nsec % ACPI_NSEC_PER_SEC); 777 } 778 779 while (((RetVal = sem_timedwait (Sem, &Time)) == -1) && (errno == EINTR)) 780 { 781 continue; 782 } 783 784 if (RetVal != 0) 785 { 786 if (errno != ETIMEDOUT) 787 { 788 perror ("sem_timedwait"); 789 } 790 Status = (AE_TIME); 791 } 792 #endif 793 break; 794 } 795 796 return (Status); 797 } 798 799 800 /****************************************************************************** 801 * 802 * FUNCTION: AcpiOsSignalSemaphore 803 * 804 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 805 * Units - Number of units to send 806 * 807 * RETURN: Status 808 * 809 * DESCRIPTION: Send units 810 * 811 *****************************************************************************/ 812 813 ACPI_STATUS 814 AcpiOsSignalSemaphore ( 815 ACPI_HANDLE Handle, 816 UINT32 Units) 817 { 818 sem_t *Sem = (sem_t *)Handle; 819 820 821 if (!Sem) 822 { 823 return (AE_BAD_PARAMETER); 824 } 825 826 if (sem_post (Sem) == -1) 827 { 828 return (AE_LIMIT); 829 } 830 831 return (AE_OK); 832 } 833 834 #endif /* ACPI_SINGLE_THREADED */ 835 836 837 /****************************************************************************** 838 * 839 * FUNCTION: Spinlock interfaces 840 * 841 * DESCRIPTION: Map these interfaces to semaphore interfaces 842 * 843 *****************************************************************************/ 844 845 ACPI_STATUS 846 AcpiOsCreateLock ( 847 ACPI_SPINLOCK *OutHandle) 848 { 849 850 return (AcpiOsCreateSemaphore (1, 1, OutHandle)); 851 } 852 853 854 void 855 AcpiOsDeleteLock ( 856 ACPI_SPINLOCK Handle) 857 { 858 AcpiOsDeleteSemaphore (Handle); 859 } 860 861 862 ACPI_CPU_FLAGS 863 AcpiOsAcquireLock ( 864 ACPI_HANDLE Handle) 865 { 866 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF); 867 return (0); 868 } 869 870 871 void 872 AcpiOsReleaseLock ( 873 ACPI_SPINLOCK Handle, 874 ACPI_CPU_FLAGS Flags) 875 { 876 AcpiOsSignalSemaphore (Handle, 1); 877 } 878 879 880 /****************************************************************************** 881 * 882 * FUNCTION: AcpiOsInstallInterruptHandler 883 * 884 * PARAMETERS: InterruptNumber - Level handler should respond to. 885 * Isr - Address of the ACPI interrupt handler 886 * ExceptPtr - Where status is returned 887 * 888 * RETURN: Handle to the newly installed handler. 889 * 890 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI 891 * OS-independent handler. 892 * 893 *****************************************************************************/ 894 895 UINT32 896 AcpiOsInstallInterruptHandler ( 897 UINT32 InterruptNumber, 898 ACPI_OSD_HANDLER ServiceRoutine, 899 void *Context) 900 { 901 902 return (AE_OK); 903 } 904 905 906 /****************************************************************************** 907 * 908 * FUNCTION: AcpiOsRemoveInterruptHandler 909 * 910 * PARAMETERS: Handle - Returned when handler was installed 911 * 912 * RETURN: Status 913 * 914 * DESCRIPTION: Uninstalls an interrupt handler. 915 * 916 *****************************************************************************/ 917 918 ACPI_STATUS 919 AcpiOsRemoveInterruptHandler ( 920 UINT32 InterruptNumber, 921 ACPI_OSD_HANDLER ServiceRoutine) 922 { 923 924 return (AE_OK); 925 } 926 927 928 /****************************************************************************** 929 * 930 * FUNCTION: AcpiOsStall 931 * 932 * PARAMETERS: microseconds - Time to sleep 933 * 934 * RETURN: Blocks until sleep is completed. 935 * 936 * DESCRIPTION: Sleep at microsecond granularity 937 * 938 *****************************************************************************/ 939 940 void 941 AcpiOsStall ( 942 UINT32 microseconds) 943 { 944 945 if (microseconds) 946 { 947 usleep (microseconds); 948 } 949 } 950 951 952 /****************************************************************************** 953 * 954 * FUNCTION: AcpiOsSleep 955 * 956 * PARAMETERS: milliseconds - Time to sleep 957 * 958 * RETURN: Blocks until sleep is completed. 959 * 960 * DESCRIPTION: Sleep at millisecond granularity 961 * 962 *****************************************************************************/ 963 964 void 965 AcpiOsSleep ( 966 UINT64 milliseconds) 967 { 968 969 /* Sleep for whole seconds */ 970 971 sleep (milliseconds / ACPI_MSEC_PER_SEC); 972 973 /* 974 * Sleep for remaining microseconds. 975 * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second). 976 */ 977 usleep ((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC); 978 } 979 980 981 /****************************************************************************** 982 * 983 * FUNCTION: AcpiOsGetTimer 984 * 985 * PARAMETERS: None 986 * 987 * RETURN: Current time in 100 nanosecond units 988 * 989 * DESCRIPTION: Get the current system time 990 * 991 *****************************************************************************/ 992 993 UINT64 994 AcpiOsGetTimer ( 995 void) 996 { 997 struct timeval time; 998 999 1000 /* This timer has sufficient resolution for user-space application code */ 1001 1002 gettimeofday (&time, NULL); 1003 1004 /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */ 1005 1006 return (((UINT64) time.tv_sec * ACPI_100NSEC_PER_SEC) + 1007 ((UINT64) time.tv_usec * ACPI_100NSEC_PER_USEC)); 1008 } 1009 1010 1011 /****************************************************************************** 1012 * 1013 * FUNCTION: AcpiOsReadPciConfiguration 1014 * 1015 * PARAMETERS: PciId - Seg/Bus/Dev 1016 * Register - Device Register 1017 * Value - Buffer where value is placed 1018 * Width - Number of bits 1019 * 1020 * RETURN: Status 1021 * 1022 * DESCRIPTION: Read data from PCI configuration space 1023 * 1024 *****************************************************************************/ 1025 1026 ACPI_STATUS 1027 AcpiOsReadPciConfiguration ( 1028 ACPI_PCI_ID *PciId, 1029 UINT32 Register, 1030 UINT64 *Value, 1031 UINT32 Width) 1032 { 1033 1034 return (AE_OK); 1035 } 1036 1037 1038 /****************************************************************************** 1039 * 1040 * FUNCTION: AcpiOsWritePciConfiguration 1041 * 1042 * PARAMETERS: PciId - Seg/Bus/Dev 1043 * Register - Device Register 1044 * Value - Value to be written 1045 * Width - Number of bits 1046 * 1047 * RETURN: Status. 1048 * 1049 * DESCRIPTION: Write data to PCI configuration space 1050 * 1051 *****************************************************************************/ 1052 1053 ACPI_STATUS 1054 AcpiOsWritePciConfiguration ( 1055 ACPI_PCI_ID *PciId, 1056 UINT32 Register, 1057 UINT64 Value, 1058 UINT32 Width) 1059 { 1060 1061 return (AE_OK); 1062 } 1063 1064 1065 /****************************************************************************** 1066 * 1067 * FUNCTION: AcpiOsReadPort 1068 * 1069 * PARAMETERS: Address - Address of I/O port/register to read 1070 * Value - Where value is placed 1071 * Width - Number of bits 1072 * 1073 * RETURN: Value read from port 1074 * 1075 * DESCRIPTION: Read data from an I/O port or register 1076 * 1077 *****************************************************************************/ 1078 1079 ACPI_STATUS 1080 AcpiOsReadPort ( 1081 ACPI_IO_ADDRESS Address, 1082 UINT32 *Value, 1083 UINT32 Width) 1084 { 1085 1086 switch (Width) 1087 { 1088 case 8: 1089 *Value = 0xFF; 1090 break; 1091 1092 case 16: 1093 *Value = 0xFFFF; 1094 break; 1095 1096 case 32: 1097 *Value = 0xFFFFFFFF; 1098 break; 1099 1100 default: 1101 return (AE_BAD_PARAMETER); 1102 } 1103 1104 return (AE_OK); 1105 } 1106 1107 1108 /****************************************************************************** 1109 * 1110 * FUNCTION: AcpiOsWritePort 1111 * 1112 * PARAMETERS: Address - Address of I/O port/register to write 1113 * Value - Value to write 1114 * Width - Number of bits 1115 * 1116 * RETURN: None 1117 * 1118 * DESCRIPTION: Write data to an I/O port or register 1119 * 1120 *****************************************************************************/ 1121 1122 ACPI_STATUS 1123 AcpiOsWritePort ( 1124 ACPI_IO_ADDRESS Address, 1125 UINT32 Value, 1126 UINT32 Width) 1127 { 1128 1129 return (AE_OK); 1130 } 1131 1132 1133 /****************************************************************************** 1134 * 1135 * FUNCTION: AcpiOsReadMemory 1136 * 1137 * PARAMETERS: Address - Physical Memory Address to read 1138 * Value - Where value is placed 1139 * Width - Number of bits (8,16,32, or 64) 1140 * 1141 * RETURN: Value read from physical memory address. Always returned 1142 * as a 64-bit integer, regardless of the read width. 1143 * 1144 * DESCRIPTION: Read data from a physical memory address 1145 * 1146 *****************************************************************************/ 1147 1148 ACPI_STATUS 1149 AcpiOsReadMemory ( 1150 ACPI_PHYSICAL_ADDRESS Address, 1151 UINT64 *Value, 1152 UINT32 Width) 1153 { 1154 1155 switch (Width) 1156 { 1157 case 8: 1158 case 16: 1159 case 32: 1160 case 64: 1161 *Value = 0; 1162 break; 1163 1164 default: 1165 return (AE_BAD_PARAMETER); 1166 } 1167 return (AE_OK); 1168 } 1169 1170 1171 /****************************************************************************** 1172 * 1173 * FUNCTION: AcpiOsWriteMemory 1174 * 1175 * PARAMETERS: Address - Physical Memory Address to write 1176 * Value - Value to write 1177 * Width - Number of bits (8,16,32, or 64) 1178 * 1179 * RETURN: None 1180 * 1181 * DESCRIPTION: Write data to a physical memory address 1182 * 1183 *****************************************************************************/ 1184 1185 ACPI_STATUS 1186 AcpiOsWriteMemory ( 1187 ACPI_PHYSICAL_ADDRESS Address, 1188 UINT64 Value, 1189 UINT32 Width) 1190 { 1191 1192 return (AE_OK); 1193 } 1194 1195 1196 /****************************************************************************** 1197 * 1198 * FUNCTION: AcpiOsReadable 1199 * 1200 * PARAMETERS: Pointer - Area to be verified 1201 * Length - Size of area 1202 * 1203 * RETURN: TRUE if readable for entire length 1204 * 1205 * DESCRIPTION: Verify that a pointer is valid for reading 1206 * 1207 *****************************************************************************/ 1208 1209 BOOLEAN 1210 AcpiOsReadable ( 1211 void *Pointer, 1212 ACPI_SIZE Length) 1213 { 1214 1215 return (TRUE); 1216 } 1217 1218 1219 /****************************************************************************** 1220 * 1221 * FUNCTION: AcpiOsWritable 1222 * 1223 * PARAMETERS: Pointer - Area to be verified 1224 * Length - Size of area 1225 * 1226 * RETURN: TRUE if writable for entire length 1227 * 1228 * DESCRIPTION: Verify that a pointer is valid for writing 1229 * 1230 *****************************************************************************/ 1231 1232 BOOLEAN 1233 AcpiOsWritable ( 1234 void *Pointer, 1235 ACPI_SIZE Length) 1236 { 1237 1238 return (TRUE); 1239 } 1240 1241 1242 /****************************************************************************** 1243 * 1244 * FUNCTION: AcpiOsSignal 1245 * 1246 * PARAMETERS: Function - ACPI CA signal function code 1247 * Info - Pointer to function-dependent structure 1248 * 1249 * RETURN: Status 1250 * 1251 * DESCRIPTION: Miscellaneous functions. Example implementation only. 1252 * 1253 *****************************************************************************/ 1254 1255 ACPI_STATUS 1256 AcpiOsSignal ( 1257 UINT32 Function, 1258 void *Info) 1259 { 1260 1261 switch (Function) 1262 { 1263 case ACPI_SIGNAL_FATAL: 1264 break; 1265 1266 case ACPI_SIGNAL_BREAKPOINT: 1267 break; 1268 1269 default: 1270 break; 1271 } 1272 1273 return (AE_OK); 1274 } 1275 1276 /* Optional multi-thread support */ 1277 1278 #ifndef ACPI_SINGLE_THREADED 1279 /****************************************************************************** 1280 * 1281 * FUNCTION: AcpiOsGetThreadId 1282 * 1283 * PARAMETERS: None 1284 * 1285 * RETURN: Id of the running thread 1286 * 1287 * DESCRIPTION: Get the ID of the current (running) thread 1288 * 1289 *****************************************************************************/ 1290 1291 ACPI_THREAD_ID 1292 AcpiOsGetThreadId ( 1293 void) 1294 { 1295 pthread_t thread; 1296 1297 1298 thread = pthread_self(); 1299 return (ACPI_CAST_PTHREAD_T (thread)); 1300 } 1301 1302 1303 /****************************************************************************** 1304 * 1305 * FUNCTION: AcpiOsExecute 1306 * 1307 * PARAMETERS: Type - Type of execution 1308 * Function - Address of the function to execute 1309 * Context - Passed as a parameter to the function 1310 * 1311 * RETURN: Status. 1312 * 1313 * DESCRIPTION: Execute a new thread 1314 * 1315 *****************************************************************************/ 1316 1317 ACPI_STATUS 1318 AcpiOsExecute ( 1319 ACPI_EXECUTE_TYPE Type, 1320 ACPI_OSD_EXEC_CALLBACK Function, 1321 void *Context) 1322 { 1323 pthread_t thread; 1324 int ret; 1325 1326 1327 ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context); 1328 if (ret) 1329 { 1330 AcpiOsPrintf("Create thread failed"); 1331 } 1332 return (0); 1333 } 1334 1335 #endif /* ACPI_SINGLE_THREADED */ 1336 1337 1338 /****************************************************************************** 1339 * 1340 * FUNCTION: AcpiOsWaitEventsComplete 1341 * 1342 * PARAMETERS: None 1343 * 1344 * RETURN: None 1345 * 1346 * DESCRIPTION: Wait for all asynchronous events to complete. This 1347 * implementation does nothing. 1348 * 1349 *****************************************************************************/ 1350 1351 void 1352 AcpiOsWaitEventsComplete ( 1353 void) 1354 { 1355 return; 1356 } 1357