1 /****************************************************************************** 2 * 3 * Module Name: osunixxf - UNIX OSL interfaces 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2012, 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 /* Apple-specific */ 88 89 #ifdef __APPLE__ 90 #define sem_destroy sem_close 91 #endif 92 93 94 /****************************************************************************** 95 * 96 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate 97 * 98 * PARAMETERS: None 99 * 100 * RETURN: Status 101 * 102 * DESCRIPTION: Init and terminate. Nothing to do. 103 * 104 *****************************************************************************/ 105 106 ACPI_STATUS 107 AcpiOsInitialize ( 108 void) 109 { 110 111 AcpiGbl_OutputFile = stdout; 112 return (AE_OK); 113 } 114 115 116 ACPI_STATUS 117 AcpiOsTerminate ( 118 void) 119 { 120 121 return (AE_OK); 122 } 123 124 125 /****************************************************************************** 126 * 127 * FUNCTION: AcpiOsGetRootPointer 128 * 129 * PARAMETERS: None 130 * 131 * RETURN: RSDP physical address 132 * 133 * DESCRIPTION: Gets the ACPI root pointer (RSDP) 134 * 135 *****************************************************************************/ 136 137 ACPI_PHYSICAL_ADDRESS 138 AcpiOsGetRootPointer ( 139 void) 140 { 141 142 return (AeLocalGetRootPointer ()); 143 } 144 145 146 /****************************************************************************** 147 * 148 * FUNCTION: AcpiOsPredefinedOverride 149 * 150 * PARAMETERS: InitVal - Initial value of the predefined object 151 * NewVal - The new value for the object 152 * 153 * RETURN: Status, pointer to value. Null pointer returned if not 154 * overriding. 155 * 156 * DESCRIPTION: Allow the OS to override predefined names 157 * 158 *****************************************************************************/ 159 160 ACPI_STATUS 161 AcpiOsPredefinedOverride ( 162 const ACPI_PREDEFINED_NAMES *InitVal, 163 ACPI_STRING *NewVal) 164 { 165 166 if (!InitVal || !NewVal) 167 { 168 return (AE_BAD_PARAMETER); 169 } 170 171 *NewVal = NULL; 172 return (AE_OK); 173 } 174 175 176 /****************************************************************************** 177 * 178 * FUNCTION: AcpiOsTableOverride 179 * 180 * PARAMETERS: ExistingTable - Header of current table (probably 181 * firmware) 182 * NewTable - Where an entire new table is returned. 183 * 184 * RETURN: Status, pointer to new table. Null pointer returned if no 185 * table is available to override 186 * 187 * DESCRIPTION: Return a different version of a table if one is available 188 * 189 *****************************************************************************/ 190 191 ACPI_STATUS 192 AcpiOsTableOverride ( 193 ACPI_TABLE_HEADER *ExistingTable, 194 ACPI_TABLE_HEADER **NewTable) 195 { 196 197 if (!ExistingTable || !NewTable) 198 { 199 return (AE_BAD_PARAMETER); 200 } 201 202 *NewTable = NULL; 203 204 #ifdef ACPI_EXEC_APP 205 206 AeTableOverride (ExistingTable, NewTable); 207 return (AE_OK); 208 #else 209 210 return (AE_NO_ACPI_TABLES); 211 #endif 212 } 213 214 215 /****************************************************************************** 216 * 217 * FUNCTION: AcpiOsPhysicalTableOverride 218 * 219 * PARAMETERS: ExistingTable - Header of current table (probably firmware) 220 * NewAddress - Where new table address is returned 221 * (Physical address) 222 * NewTableLength - Where new table length is returned 223 * 224 * RETURN: Status, address/length of new table. Null pointer returned 225 * if no table is available to override. 226 * 227 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. 228 * 229 *****************************************************************************/ 230 231 ACPI_STATUS 232 AcpiOsPhysicalTableOverride ( 233 ACPI_TABLE_HEADER *ExistingTable, 234 ACPI_PHYSICAL_ADDRESS *NewAddress, 235 UINT32 *NewTableLength) 236 { 237 238 return (AE_SUPPORT); 239 } 240 241 242 /****************************************************************************** 243 * 244 * FUNCTION: AcpiOsRedirectOutput 245 * 246 * PARAMETERS: Destination - An open file handle/pointer 247 * 248 * RETURN: None 249 * 250 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf 251 * 252 *****************************************************************************/ 253 254 void 255 AcpiOsRedirectOutput ( 256 void *Destination) 257 { 258 259 AcpiGbl_OutputFile = Destination; 260 } 261 262 263 /****************************************************************************** 264 * 265 * FUNCTION: AcpiOsPrintf 266 * 267 * PARAMETERS: fmt, ... - Standard printf format 268 * 269 * RETURN: None 270 * 271 * DESCRIPTION: Formatted output 272 * 273 *****************************************************************************/ 274 275 void ACPI_INTERNAL_VAR_XFACE 276 AcpiOsPrintf ( 277 const char *Fmt, 278 ...) 279 { 280 va_list Args; 281 282 283 va_start (Args, Fmt); 284 AcpiOsVprintf (Fmt, Args); 285 va_end (Args); 286 } 287 288 289 /****************************************************************************** 290 * 291 * FUNCTION: AcpiOsVprintf 292 * 293 * PARAMETERS: fmt - Standard printf format 294 * args - Argument list 295 * 296 * RETURN: None 297 * 298 * DESCRIPTION: Formatted output with argument list pointer 299 * 300 *****************************************************************************/ 301 302 void 303 AcpiOsVprintf ( 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 350 ACPI_STATUS 351 AcpiOsGetLine ( 352 char *Buffer, 353 UINT32 BufferLength, 354 UINT32 *BytesRead) 355 { 356 int 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 if ((Temp = getchar ()) == EOF) 368 { 369 return (AE_ERROR); 370 } 371 372 if (!Temp || Temp == '\n') 373 { 374 break; 375 } 376 377 Buffer [i] = (char) Temp; 378 } 379 380 /* Null terminate the buffer */ 381 382 Buffer [i] = 0; 383 384 /* Return the number of bytes in the string */ 385 386 if (BytesRead) 387 { 388 *BytesRead = i; 389 } 390 return (AE_OK); 391 } 392 393 394 /****************************************************************************** 395 * 396 * FUNCTION: AcpiOsMapMemory 397 * 398 * PARAMETERS: where - Physical address of memory to be mapped 399 * length - How much memory to map 400 * 401 * RETURN: Pointer to mapped memory. Null on error. 402 * 403 * DESCRIPTION: Map physical memory into caller's address space 404 * 405 *****************************************************************************/ 406 407 void * 408 AcpiOsMapMemory ( 409 ACPI_PHYSICAL_ADDRESS where, 410 ACPI_SIZE length) 411 { 412 413 return (ACPI_TO_POINTER ((ACPI_SIZE) where)); 414 } 415 416 417 /****************************************************************************** 418 * 419 * FUNCTION: AcpiOsUnmapMemory 420 * 421 * PARAMETERS: where - Logical address of memory to be unmapped 422 * length - How much memory to unmap 423 * 424 * RETURN: None. 425 * 426 * DESCRIPTION: Delete a previously created mapping. Where and Length must 427 * correspond to a previous mapping exactly. 428 * 429 *****************************************************************************/ 430 431 void 432 AcpiOsUnmapMemory ( 433 void *where, 434 ACPI_SIZE length) 435 { 436 437 return; 438 } 439 440 441 /****************************************************************************** 442 * 443 * FUNCTION: AcpiOsAllocate 444 * 445 * PARAMETERS: Size - Amount to allocate, in bytes 446 * 447 * RETURN: Pointer to the new allocation. Null on error. 448 * 449 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. 450 * 451 *****************************************************************************/ 452 453 void * 454 AcpiOsAllocate ( 455 ACPI_SIZE size) 456 { 457 void *Mem; 458 459 460 Mem = (void *) malloc ((size_t) size); 461 return (Mem); 462 } 463 464 465 /****************************************************************************** 466 * 467 * FUNCTION: AcpiOsFree 468 * 469 * PARAMETERS: mem - Pointer to previously allocated memory 470 * 471 * RETURN: None. 472 * 473 * DESCRIPTION: Free memory allocated via AcpiOsAllocate 474 * 475 *****************************************************************************/ 476 477 void 478 AcpiOsFree ( 479 void *mem) 480 { 481 482 free (mem); 483 } 484 485 486 #ifdef ACPI_SINGLE_THREADED 487 /****************************************************************************** 488 * 489 * FUNCTION: Semaphore stub functions 490 * 491 * DESCRIPTION: Stub functions used for single-thread applications that do 492 * not require semaphore synchronization. Full implementations 493 * of these functions appear after the stubs. 494 * 495 *****************************************************************************/ 496 497 ACPI_STATUS 498 AcpiOsCreateSemaphore ( 499 UINT32 MaxUnits, 500 UINT32 InitialUnits, 501 ACPI_HANDLE *OutHandle) 502 { 503 *OutHandle = (ACPI_HANDLE) 1; 504 return (AE_OK); 505 } 506 507 ACPI_STATUS 508 AcpiOsDeleteSemaphore ( 509 ACPI_HANDLE Handle) 510 { 511 return (AE_OK); 512 } 513 514 ACPI_STATUS 515 AcpiOsWaitSemaphore ( 516 ACPI_HANDLE Handle, 517 UINT32 Units, 518 UINT16 Timeout) 519 { 520 return (AE_OK); 521 } 522 523 ACPI_STATUS 524 AcpiOsSignalSemaphore ( 525 ACPI_HANDLE Handle, 526 UINT32 Units) 527 { 528 return (AE_OK); 529 } 530 531 #else 532 /****************************************************************************** 533 * 534 * FUNCTION: AcpiOsCreateSemaphore 535 * 536 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore 537 * OutHandle - Where a handle will be returned 538 * 539 * RETURN: Status 540 * 541 * DESCRIPTION: Create an OS semaphore 542 * 543 *****************************************************************************/ 544 545 ACPI_STATUS 546 AcpiOsCreateSemaphore ( 547 UINT32 MaxUnits, 548 UINT32 InitialUnits, 549 ACPI_HANDLE *OutHandle) 550 { 551 sem_t *Sem; 552 553 554 if (!OutHandle) 555 { 556 return (AE_BAD_PARAMETER); 557 } 558 559 #ifdef __APPLE__ 560 { 561 char *SemaphoreName = tmpnam (NULL); 562 563 Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits); 564 if (!Sem) 565 { 566 return (AE_NO_MEMORY); 567 } 568 sem_unlink (SemaphoreName); /* This just deletes the name */ 569 } 570 571 #else 572 Sem = AcpiOsAllocate (sizeof (sem_t)); 573 if (!Sem) 574 { 575 return (AE_NO_MEMORY); 576 } 577 578 if (sem_init (Sem, 0, InitialUnits) == -1) 579 { 580 AcpiOsFree (Sem); 581 return (AE_BAD_PARAMETER); 582 } 583 #endif 584 585 *OutHandle = (ACPI_HANDLE) Sem; 586 return (AE_OK); 587 } 588 589 590 /****************************************************************************** 591 * 592 * FUNCTION: AcpiOsDeleteSemaphore 593 * 594 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 595 * 596 * RETURN: Status 597 * 598 * DESCRIPTION: Delete an OS semaphore 599 * 600 *****************************************************************************/ 601 602 ACPI_STATUS 603 AcpiOsDeleteSemaphore ( 604 ACPI_HANDLE Handle) 605 { 606 sem_t *Sem = (sem_t *) Handle; 607 608 609 if (!Sem) 610 { 611 return (AE_BAD_PARAMETER); 612 } 613 614 if (sem_destroy (Sem) == -1) 615 { 616 return (AE_BAD_PARAMETER); 617 } 618 619 return (AE_OK); 620 } 621 622 623 /****************************************************************************** 624 * 625 * FUNCTION: AcpiOsWaitSemaphore 626 * 627 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 628 * Units - How many units to wait for 629 * Timeout - How long to wait 630 * 631 * RETURN: Status 632 * 633 * DESCRIPTION: Wait for units 634 * 635 *****************************************************************************/ 636 637 ACPI_STATUS 638 AcpiOsWaitSemaphore ( 639 ACPI_HANDLE Handle, 640 UINT32 Units, 641 UINT16 Timeout) 642 { 643 ACPI_STATUS Status = AE_OK; 644 sem_t *Sem = (sem_t *) Handle; 645 struct timespec T; 646 647 648 if (!Sem) 649 { 650 return (AE_BAD_PARAMETER); 651 } 652 653 switch (Timeout) 654 { 655 /* 656 * No Wait: 657 * -------- 658 * A zero timeout value indicates that we shouldn't wait - just 659 * acquire the semaphore if available otherwise return AE_TIME 660 * (a.k.a. 'would block'). 661 */ 662 case 0: 663 664 if (sem_trywait(Sem) == -1) 665 { 666 Status = (AE_TIME); 667 } 668 break; 669 670 /* Wait Indefinitely */ 671 672 case ACPI_WAIT_FOREVER: 673 674 if (sem_wait (Sem)) 675 { 676 Status = (AE_TIME); 677 } 678 break; 679 680 /* Wait with Timeout */ 681 682 default: 683 684 T.tv_sec = Timeout / 1000; 685 T.tv_nsec = (Timeout - (T.tv_sec * 1000)) * 1000000; 686 687 #ifdef ACPI_USE_ALTERNATE_TIMEOUT 688 /* 689 * Alternate timeout mechanism for environments where 690 * sem_timedwait is not available or does not work properly. 691 */ 692 while (Timeout) 693 { 694 if (sem_trywait (Sem) == 0) 695 { 696 /* Got the semaphore */ 697 return (AE_OK); 698 } 699 usleep (1000); /* one millisecond */ 700 Timeout--; 701 } 702 Status = (AE_TIME); 703 #else 704 705 if (sem_timedwait (Sem, &T)) 706 { 707 Status = (AE_TIME); 708 } 709 #endif 710 711 break; 712 } 713 714 return (Status); 715 } 716 717 718 /****************************************************************************** 719 * 720 * FUNCTION: AcpiOsSignalSemaphore 721 * 722 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 723 * Units - Number of units to send 724 * 725 * RETURN: Status 726 * 727 * DESCRIPTION: Send units 728 * 729 *****************************************************************************/ 730 731 ACPI_STATUS 732 AcpiOsSignalSemaphore ( 733 ACPI_HANDLE Handle, 734 UINT32 Units) 735 { 736 sem_t *Sem = (sem_t *)Handle; 737 738 739 if (!Sem) 740 { 741 return (AE_BAD_PARAMETER); 742 } 743 744 if (sem_post (Sem) == -1) 745 { 746 return (AE_LIMIT); 747 } 748 749 return (AE_OK); 750 } 751 752 #endif /* ACPI_SINGLE_THREADED */ 753 754 755 /****************************************************************************** 756 * 757 * FUNCTION: Spinlock interfaces 758 * 759 * DESCRIPTION: Map these interfaces to semaphore interfaces 760 * 761 *****************************************************************************/ 762 763 ACPI_STATUS 764 AcpiOsCreateLock ( 765 ACPI_SPINLOCK *OutHandle) 766 { 767 768 return (AcpiOsCreateSemaphore (1, 1, OutHandle)); 769 } 770 771 772 void 773 AcpiOsDeleteLock ( 774 ACPI_SPINLOCK Handle) 775 { 776 AcpiOsDeleteSemaphore (Handle); 777 } 778 779 780 ACPI_CPU_FLAGS 781 AcpiOsAcquireLock ( 782 ACPI_HANDLE Handle) 783 { 784 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF); 785 return (0); 786 } 787 788 789 void 790 AcpiOsReleaseLock ( 791 ACPI_SPINLOCK Handle, 792 ACPI_CPU_FLAGS Flags) 793 { 794 AcpiOsSignalSemaphore (Handle, 1); 795 } 796 797 798 /****************************************************************************** 799 * 800 * FUNCTION: AcpiOsInstallInterruptHandler 801 * 802 * PARAMETERS: InterruptNumber - Level handler should respond to. 803 * Isr - Address of the ACPI interrupt handler 804 * ExceptPtr - Where status is returned 805 * 806 * RETURN: Handle to the newly installed handler. 807 * 808 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI 809 * OS-independent handler. 810 * 811 *****************************************************************************/ 812 813 UINT32 814 AcpiOsInstallInterruptHandler ( 815 UINT32 InterruptNumber, 816 ACPI_OSD_HANDLER ServiceRoutine, 817 void *Context) 818 { 819 820 return (AE_OK); 821 } 822 823 824 /****************************************************************************** 825 * 826 * FUNCTION: AcpiOsRemoveInterruptHandler 827 * 828 * PARAMETERS: Handle - Returned when handler was installed 829 * 830 * RETURN: Status 831 * 832 * DESCRIPTION: Uninstalls an interrupt handler. 833 * 834 *****************************************************************************/ 835 836 ACPI_STATUS 837 AcpiOsRemoveInterruptHandler ( 838 UINT32 InterruptNumber, 839 ACPI_OSD_HANDLER ServiceRoutine) 840 { 841 842 return (AE_OK); 843 } 844 845 846 /****************************************************************************** 847 * 848 * FUNCTION: AcpiOsStall 849 * 850 * PARAMETERS: microseconds - Time to sleep 851 * 852 * RETURN: Blocks until sleep is completed. 853 * 854 * DESCRIPTION: Sleep at microsecond granularity 855 * 856 *****************************************************************************/ 857 858 void 859 AcpiOsStall ( 860 UINT32 microseconds) 861 { 862 863 if (microseconds) 864 { 865 usleep (microseconds); 866 } 867 } 868 869 870 /****************************************************************************** 871 * 872 * FUNCTION: AcpiOsSleep 873 * 874 * PARAMETERS: milliseconds - Time to sleep 875 * 876 * RETURN: Blocks until sleep is completed. 877 * 878 * DESCRIPTION: Sleep at millisecond granularity 879 * 880 *****************************************************************************/ 881 882 void 883 AcpiOsSleep ( 884 UINT64 milliseconds) 885 { 886 887 sleep (milliseconds / 1000); /* Sleep for whole seconds */ 888 889 /* 890 * Arg to usleep() must be less than 1,000,000 (1 second) 891 */ 892 usleep ((milliseconds % 1000) * 1000); /* Sleep for remaining usecs */ 893 } 894 895 896 /****************************************************************************** 897 * 898 * FUNCTION: AcpiOsGetTimer 899 * 900 * PARAMETERS: None 901 * 902 * RETURN: Current time in 100 nanosecond units 903 * 904 * DESCRIPTION: Get the current system time 905 * 906 *****************************************************************************/ 907 908 UINT64 909 AcpiOsGetTimer ( 910 void) 911 { 912 struct timeval time; 913 914 915 gettimeofday (&time, NULL); 916 917 /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */ 918 919 return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10)); 920 } 921 922 923 /****************************************************************************** 924 * 925 * FUNCTION: AcpiOsReadPciConfiguration 926 * 927 * PARAMETERS: PciId - Seg/Bus/Dev 928 * Register - Device Register 929 * Value - Buffer where value is placed 930 * Width - Number of bits 931 * 932 * RETURN: Status 933 * 934 * DESCRIPTION: Read data from PCI configuration space 935 * 936 *****************************************************************************/ 937 938 ACPI_STATUS 939 AcpiOsReadPciConfiguration ( 940 ACPI_PCI_ID *PciId, 941 UINT32 Register, 942 UINT64 *Value, 943 UINT32 Width) 944 { 945 946 return (AE_OK); 947 } 948 949 950 /****************************************************************************** 951 * 952 * FUNCTION: AcpiOsWritePciConfiguration 953 * 954 * PARAMETERS: PciId - Seg/Bus/Dev 955 * Register - Device Register 956 * Value - Value to be written 957 * Width - Number of bits 958 * 959 * RETURN: Status. 960 * 961 * DESCRIPTION: Write data to PCI configuration space 962 * 963 *****************************************************************************/ 964 965 ACPI_STATUS 966 AcpiOsWritePciConfiguration ( 967 ACPI_PCI_ID *PciId, 968 UINT32 Register, 969 UINT64 Value, 970 UINT32 Width) 971 { 972 973 return (AE_OK); 974 } 975 976 977 /****************************************************************************** 978 * 979 * FUNCTION: AcpiOsReadPort 980 * 981 * PARAMETERS: Address - Address of I/O port/register to read 982 * Value - Where value is placed 983 * Width - Number of bits 984 * 985 * RETURN: Value read from port 986 * 987 * DESCRIPTION: Read data from an I/O port or register 988 * 989 *****************************************************************************/ 990 991 ACPI_STATUS 992 AcpiOsReadPort ( 993 ACPI_IO_ADDRESS Address, 994 UINT32 *Value, 995 UINT32 Width) 996 { 997 998 switch (Width) 999 { 1000 case 8: 1001 *Value = 0xFF; 1002 break; 1003 1004 case 16: 1005 *Value = 0xFFFF; 1006 break; 1007 1008 case 32: 1009 *Value = 0xFFFFFFFF; 1010 break; 1011 1012 default: 1013 return (AE_BAD_PARAMETER); 1014 } 1015 1016 return (AE_OK); 1017 } 1018 1019 1020 /****************************************************************************** 1021 * 1022 * FUNCTION: AcpiOsWritePort 1023 * 1024 * PARAMETERS: Address - Address of I/O port/register to write 1025 * Value - Value to write 1026 * Width - Number of bits 1027 * 1028 * RETURN: None 1029 * 1030 * DESCRIPTION: Write data to an I/O port or register 1031 * 1032 *****************************************************************************/ 1033 1034 ACPI_STATUS 1035 AcpiOsWritePort ( 1036 ACPI_IO_ADDRESS Address, 1037 UINT32 Value, 1038 UINT32 Width) 1039 { 1040 1041 return (AE_OK); 1042 } 1043 1044 1045 /****************************************************************************** 1046 * 1047 * FUNCTION: AcpiOsReadMemory 1048 * 1049 * PARAMETERS: Address - Physical Memory Address to read 1050 * Value - Where value is placed 1051 * Width - Number of bits (8,16,32, or 64) 1052 * 1053 * RETURN: Value read from physical memory address. Always returned 1054 * as a 64-bit integer, regardless of the read width. 1055 * 1056 * DESCRIPTION: Read data from a physical memory address 1057 * 1058 *****************************************************************************/ 1059 1060 ACPI_STATUS 1061 AcpiOsReadMemory ( 1062 ACPI_PHYSICAL_ADDRESS Address, 1063 UINT64 *Value, 1064 UINT32 Width) 1065 { 1066 1067 switch (Width) 1068 { 1069 case 8: 1070 case 16: 1071 case 32: 1072 case 64: 1073 *Value = 0; 1074 break; 1075 1076 default: 1077 return (AE_BAD_PARAMETER); 1078 } 1079 return (AE_OK); 1080 } 1081 1082 1083 /****************************************************************************** 1084 * 1085 * FUNCTION: AcpiOsWriteMemory 1086 * 1087 * PARAMETERS: Address - Physical Memory Address to write 1088 * Value - Value to write 1089 * Width - Number of bits (8,16,32, or 64) 1090 * 1091 * RETURN: None 1092 * 1093 * DESCRIPTION: Write data to a physical memory address 1094 * 1095 *****************************************************************************/ 1096 1097 ACPI_STATUS 1098 AcpiOsWriteMemory ( 1099 ACPI_PHYSICAL_ADDRESS Address, 1100 UINT64 Value, 1101 UINT32 Width) 1102 { 1103 1104 return (AE_OK); 1105 } 1106 1107 1108 /****************************************************************************** 1109 * 1110 * FUNCTION: AcpiOsReadable 1111 * 1112 * PARAMETERS: Pointer - Area to be verified 1113 * Length - Size of area 1114 * 1115 * RETURN: TRUE if readable for entire length 1116 * 1117 * DESCRIPTION: Verify that a pointer is valid for reading 1118 * 1119 *****************************************************************************/ 1120 1121 BOOLEAN 1122 AcpiOsReadable ( 1123 void *Pointer, 1124 ACPI_SIZE Length) 1125 { 1126 1127 return (TRUE); 1128 } 1129 1130 1131 /****************************************************************************** 1132 * 1133 * FUNCTION: AcpiOsWritable 1134 * 1135 * PARAMETERS: Pointer - Area to be verified 1136 * Length - Size of area 1137 * 1138 * RETURN: TRUE if writable for entire length 1139 * 1140 * DESCRIPTION: Verify that a pointer is valid for writing 1141 * 1142 *****************************************************************************/ 1143 1144 BOOLEAN 1145 AcpiOsWritable ( 1146 void *Pointer, 1147 ACPI_SIZE Length) 1148 { 1149 1150 return (TRUE); 1151 } 1152 1153 1154 /****************************************************************************** 1155 * 1156 * FUNCTION: AcpiOsSignal 1157 * 1158 * PARAMETERS: Function - ACPI CA signal function code 1159 * Info - Pointer to function-dependent structure 1160 * 1161 * RETURN: Status 1162 * 1163 * DESCRIPTION: Miscellaneous functions. Example implementation only. 1164 * 1165 *****************************************************************************/ 1166 1167 ACPI_STATUS 1168 AcpiOsSignal ( 1169 UINT32 Function, 1170 void *Info) 1171 { 1172 1173 switch (Function) 1174 { 1175 case ACPI_SIGNAL_FATAL: 1176 break; 1177 1178 case ACPI_SIGNAL_BREAKPOINT: 1179 break; 1180 1181 default: 1182 break; 1183 } 1184 1185 return (AE_OK); 1186 } 1187 1188 /* Optional multi-thread support */ 1189 1190 #ifndef ACPI_SINGLE_THREADED 1191 /****************************************************************************** 1192 * 1193 * FUNCTION: AcpiOsGetThreadId 1194 * 1195 * PARAMETERS: None 1196 * 1197 * RETURN: Id of the running thread 1198 * 1199 * DESCRIPTION: Get the ID of the current (running) thread 1200 * 1201 *****************************************************************************/ 1202 1203 ACPI_THREAD_ID 1204 AcpiOsGetThreadId ( 1205 void) 1206 { 1207 pthread_t thread; 1208 1209 1210 thread = pthread_self(); 1211 return (ACPI_CAST_PTHREAD_T (thread)); 1212 } 1213 1214 1215 /****************************************************************************** 1216 * 1217 * FUNCTION: AcpiOsExecute 1218 * 1219 * PARAMETERS: Type - Type of execution 1220 * Function - Address of the function to execute 1221 * Context - Passed as a parameter to the function 1222 * 1223 * RETURN: Status. 1224 * 1225 * DESCRIPTION: Execute a new thread 1226 * 1227 *****************************************************************************/ 1228 1229 ACPI_STATUS 1230 AcpiOsExecute ( 1231 ACPI_EXECUTE_TYPE Type, 1232 ACPI_OSD_EXEC_CALLBACK Function, 1233 void *Context) 1234 { 1235 pthread_t thread; 1236 int ret; 1237 1238 1239 ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context); 1240 if (ret) 1241 { 1242 AcpiOsPrintf("Create thread failed"); 1243 } 1244 return (0); 1245 } 1246 1247 #endif /* ACPI_SINGLE_THREADED */ 1248 1249 1250 /****************************************************************************** 1251 * 1252 * FUNCTION: AcpiOsWaitEventsComplete 1253 * 1254 * PARAMETERS: None 1255 * 1256 * RETURN: None 1257 * 1258 * DESCRIPTION: Wait for all asynchronous events to complete. This 1259 * implementation does nothing. 1260 * 1261 *****************************************************************************/ 1262 1263 void 1264 AcpiOsWaitEventsComplete ( 1265 void) 1266 { 1267 return; 1268 } 1269