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 70extern FILE *AcpiGbl_DebugFile; 71FILE *AcpiGbl_OutputFile; 72 73 74/* Upcalls to AcpiExec */ 75 76ACPI_PHYSICAL_ADDRESS 77AeLocalGetRootPointer ( 78 void); 79 80void 81AeTableOverride ( 82 ACPI_TABLE_HEADER *ExistingTable, 83 ACPI_TABLE_HEADER **NewTable); 84 85typedef 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 106ACPI_STATUS 107AcpiOsInitialize ( 108 void) 109{ 110 111 AcpiGbl_OutputFile = stdout; 112 return (AE_OK); 113} 114 115 116ACPI_STATUS 117AcpiOsTerminate ( 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 137ACPI_PHYSICAL_ADDRESS 138AcpiOsGetRootPointer ( 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 160ACPI_STATUS 161AcpiOsPredefinedOverride ( 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 191ACPI_STATUS 192AcpiOsTableOverride ( 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 231ACPI_STATUS 232AcpiOsPhysicalTableOverride ( 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 254void 255AcpiOsRedirectOutput ( 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 275void ACPI_INTERNAL_VAR_XFACE 276AcpiOsPrintf ( 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 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 */
| 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 70extern FILE *AcpiGbl_DebugFile; 71FILE *AcpiGbl_OutputFile; 72 73 74/* Upcalls to AcpiExec */ 75 76ACPI_PHYSICAL_ADDRESS 77AeLocalGetRootPointer ( 78 void); 79 80void 81AeTableOverride ( 82 ACPI_TABLE_HEADER *ExistingTable, 83 ACPI_TABLE_HEADER **NewTable); 84 85typedef 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 106ACPI_STATUS 107AcpiOsInitialize ( 108 void) 109{ 110 111 AcpiGbl_OutputFile = stdout; 112 return (AE_OK); 113} 114 115 116ACPI_STATUS 117AcpiOsTerminate ( 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 137ACPI_PHYSICAL_ADDRESS 138AcpiOsGetRootPointer ( 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 160ACPI_STATUS 161AcpiOsPredefinedOverride ( 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 191ACPI_STATUS 192AcpiOsTableOverride ( 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 231ACPI_STATUS 232AcpiOsPhysicalTableOverride ( 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 254void 255AcpiOsRedirectOutput ( 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 275void ACPI_INTERNAL_VAR_XFACE 276AcpiOsPrintf ( 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 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 */
|