1193267Sjkim/****************************************************************************** 2193267Sjkim * 3193267Sjkim * Module Name: osunixxf - UNIX OSL interfaces 4193267Sjkim * 5193267Sjkim *****************************************************************************/ 6193267Sjkim 7217355Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp. 9193267Sjkim * All rights reserved. 10193267Sjkim * 11217355Sjkim * Redistribution and use in source and binary forms, with or without 12217355Sjkim * modification, are permitted provided that the following conditions 13217355Sjkim * are met: 14217355Sjkim * 1. Redistributions of source code must retain the above copyright 15217355Sjkim * notice, this list of conditions, and the following disclaimer, 16217355Sjkim * without modification. 17217355Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217355Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217355Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217355Sjkim * including a substantially similar Disclaimer requirement for further 21217355Sjkim * binary redistribution. 22217355Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217355Sjkim * of any contributors may be used to endorse or promote products derived 24217355Sjkim * from this software without specific prior written permission. 25193267Sjkim * 26217355Sjkim * Alternatively, this software may be distributed under the terms of the 27217355Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217355Sjkim * Software Foundation. 29193267Sjkim * 30217355Sjkim * NO WARRANTY 31217355Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217355Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217355Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217355Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217355Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217355Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217355Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217355Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217355Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217355Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217355Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217355Sjkim */ 43193267Sjkim 44193267Sjkim/* 45213800Sjkim * These interfaces are required in order to compile the ASL compiler and the 46213800Sjkim * various ACPICA tools under Linux or other Unix-like system. 47193267Sjkim */ 48228110Sjkim#include <contrib/dev/acpica/include/acpi.h> 49228110Sjkim#include <contrib/dev/acpica/include/accommon.h> 50228110Sjkim#include <contrib/dev/acpica/include/amlcode.h> 51228110Sjkim#include <contrib/dev/acpica/include/acparser.h> 52228110Sjkim#include <contrib/dev/acpica/include/acdebug.h> 53223480Sjkim 54193267Sjkim#include <stdio.h> 55193267Sjkim#include <stdlib.h> 56193267Sjkim#include <stdarg.h> 57193267Sjkim#include <unistd.h> 58193267Sjkim#include <sys/time.h> 59193267Sjkim#include <semaphore.h> 60193267Sjkim#include <pthread.h> 61209734Sjkim#include <errno.h> 62193267Sjkim 63193267Sjkim#define _COMPONENT ACPI_OS_SERVICES 64193267Sjkim ACPI_MODULE_NAME ("osunixxf") 65193267Sjkim 66193267Sjkim 67281075SdimBOOLEAN AcpiGbl_DebugTimeout = FALSE; 68193267Sjkim 69193267Sjkim 70193267Sjkim/* Upcalls to AcpiExec */ 71193267Sjkim 72193267Sjkimvoid 73193267SjkimAeTableOverride ( 74193267Sjkim ACPI_TABLE_HEADER *ExistingTable, 75193267Sjkim ACPI_TABLE_HEADER **NewTable); 76193267Sjkim 77193267Sjkimtypedef void* (*PTHREAD_CALLBACK) (void *); 78193267Sjkim 79245582Sjkim/* Buffer used by AcpiOsVprintf */ 80245582Sjkim 81281075Sdim#define ACPI_VPRINTF_BUFFER_SIZE 512 82281075Sdim#define _ASCII_NEWLINE '\n' 83245582Sjkim 84281075Sdim/* Terminal support for AcpiExec only */ 85193267Sjkim 86281075Sdim#ifdef ACPI_EXEC_APP 87281075Sdim#include <termios.h> 88281075Sdim 89281075Sdimstruct termios OriginalTermAttributes; 90281075Sdimint TermAttributesWereSet = 0; 91281075Sdim 92281075SdimACPI_STATUS 93281075SdimAcpiUtReadLine ( 94281075Sdim char *Buffer, 95281075Sdim UINT32 BufferLength, 96281075Sdim UINT32 *BytesRead); 97281075Sdim 98281075Sdimstatic void 99281075SdimOsEnterLineEditMode ( 100281075Sdim void); 101281075Sdim 102281075Sdimstatic void 103281075SdimOsExitLineEditMode ( 104281075Sdim void); 105281075Sdim 106281075Sdim 107193267Sjkim/****************************************************************************** 108193267Sjkim * 109281075Sdim * FUNCTION: OsEnterLineEditMode, OsExitLineEditMode 110281075Sdim * 111281075Sdim * PARAMETERS: None 112281075Sdim * 113281075Sdim * RETURN: None 114281075Sdim * 115281075Sdim * DESCRIPTION: Enter/Exit the raw character input mode for the terminal. 116281075Sdim * 117281075Sdim * Interactive line-editing support for the AML debugger. Used with the 118281075Sdim * common/acgetline module. 119281075Sdim * 120281075Sdim * readline() is not used because of non-portability. It is not available 121281075Sdim * on all systems, and if it is, often the package must be manually installed. 122281075Sdim * 123281075Sdim * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line 124281075Sdim * editing that we need in AcpiOsGetLine. 125281075Sdim * 126281075Sdim * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these 127281075Sdim * calls will also work: 128281075Sdim * For OsEnterLineEditMode: system ("stty cbreak -echo") 129281075Sdim * For OsExitLineEditMode: system ("stty cooked echo") 130281075Sdim * 131281075Sdim *****************************************************************************/ 132281075Sdim 133281075Sdimstatic void 134281075SdimOsEnterLineEditMode ( 135281075Sdim void) 136281075Sdim{ 137281075Sdim struct termios LocalTermAttributes; 138281075Sdim 139281075Sdim 140281075Sdim TermAttributesWereSet = 0; 141281075Sdim 142281075Sdim /* STDIN must be a terminal */ 143281075Sdim 144281075Sdim if (!isatty (STDIN_FILENO)) 145281075Sdim { 146281075Sdim return; 147281075Sdim } 148281075Sdim 149281075Sdim /* Get and keep the original attributes */ 150281075Sdim 151281075Sdim if (tcgetattr (STDIN_FILENO, &OriginalTermAttributes)) 152281075Sdim { 153281075Sdim fprintf (stderr, "Could not get terminal attributes!\n"); 154281075Sdim return; 155281075Sdim } 156281075Sdim 157281075Sdim /* Set the new attributes to enable raw character input */ 158281075Sdim 159281075Sdim memcpy (&LocalTermAttributes, &OriginalTermAttributes, 160281075Sdim sizeof (struct termios)); 161281075Sdim 162281075Sdim LocalTermAttributes.c_lflag &= ~(ICANON | ECHO); 163281075Sdim LocalTermAttributes.c_cc[VMIN] = 1; 164281075Sdim LocalTermAttributes.c_cc[VTIME] = 0; 165281075Sdim 166281075Sdim if (tcsetattr (STDIN_FILENO, TCSANOW, &LocalTermAttributes)) 167281075Sdim { 168281075Sdim fprintf (stderr, "Could not set terminal attributes!\n"); 169281075Sdim return; 170281075Sdim } 171281075Sdim 172281075Sdim TermAttributesWereSet = 1; 173281075Sdim} 174281075Sdim 175281075Sdim 176281075Sdimstatic void 177281075SdimOsExitLineEditMode ( 178281075Sdim void) 179281075Sdim{ 180281075Sdim 181281075Sdim if (!TermAttributesWereSet) 182281075Sdim { 183281075Sdim return; 184281075Sdim } 185281075Sdim 186281075Sdim /* Set terminal attributes back to the original values */ 187281075Sdim 188281075Sdim if (tcsetattr (STDIN_FILENO, TCSANOW, &OriginalTermAttributes)) 189281075Sdim { 190281075Sdim fprintf (stderr, "Could not restore terminal attributes!\n"); 191281075Sdim } 192281075Sdim} 193281075Sdim 194281075Sdim 195281075Sdim#else 196281075Sdim 197281075Sdim/* These functions are not needed for other ACPICA utilities */ 198281075Sdim 199281075Sdim#define OsEnterLineEditMode() 200281075Sdim#define OsExitLineEditMode() 201281075Sdim#endif 202281075Sdim 203281075Sdim 204281075Sdim/****************************************************************************** 205281075Sdim * 206193267Sjkim * FUNCTION: AcpiOsInitialize, AcpiOsTerminate 207193267Sjkim * 208193267Sjkim * PARAMETERS: None 209193267Sjkim * 210193267Sjkim * RETURN: Status 211193267Sjkim * 212281075Sdim * DESCRIPTION: Initialize and terminate this module. 213193267Sjkim * 214193267Sjkim *****************************************************************************/ 215193267Sjkim 216193267SjkimACPI_STATUS 217213800SjkimAcpiOsInitialize ( 218213800Sjkim void) 219193267Sjkim{ 220281075Sdim ACPI_STATUS Status; 221193267Sjkim 222281075Sdim 223193267Sjkim AcpiGbl_OutputFile = stdout; 224281075Sdim 225281075Sdim OsEnterLineEditMode (); 226281075Sdim 227281075Sdim Status = AcpiOsCreateLock (&AcpiGbl_PrintLock); 228281075Sdim if (ACPI_FAILURE (Status)) 229281075Sdim { 230281075Sdim return (Status); 231281075Sdim } 232281075Sdim 233193267Sjkim return (AE_OK); 234193267Sjkim} 235193267Sjkim 236193267SjkimACPI_STATUS 237213800SjkimAcpiOsTerminate ( 238213800Sjkim void) 239193267Sjkim{ 240193267Sjkim 241281075Sdim OsExitLineEditMode (); 242193267Sjkim return (AE_OK); 243193267Sjkim} 244193267Sjkim 245193267Sjkim 246281075Sdim#ifndef ACPI_USE_NATIVE_RSDP_POINTER 247193267Sjkim/****************************************************************************** 248193267Sjkim * 249193267Sjkim * FUNCTION: AcpiOsGetRootPointer 250193267Sjkim * 251193267Sjkim * PARAMETERS: None 252193267Sjkim * 253193267Sjkim * RETURN: RSDP physical address 254193267Sjkim * 255213800Sjkim * DESCRIPTION: Gets the ACPI root pointer (RSDP) 256193267Sjkim * 257193267Sjkim *****************************************************************************/ 258193267Sjkim 259193267SjkimACPI_PHYSICAL_ADDRESS 260193267SjkimAcpiOsGetRootPointer ( 261193267Sjkim void) 262193267Sjkim{ 263193267Sjkim 264281075Sdim return (0); 265193267Sjkim} 266281075Sdim#endif 267193267Sjkim 268193267Sjkim 269193267Sjkim/****************************************************************************** 270193267Sjkim * 271193267Sjkim * FUNCTION: AcpiOsPredefinedOverride 272193267Sjkim * 273213800Sjkim * PARAMETERS: InitVal - Initial value of the predefined object 274213800Sjkim * NewVal - The new value for the object 275193267Sjkim * 276213800Sjkim * RETURN: Status, pointer to value. Null pointer returned if not 277193267Sjkim * overriding. 278193267Sjkim * 279193267Sjkim * DESCRIPTION: Allow the OS to override predefined names 280193267Sjkim * 281193267Sjkim *****************************************************************************/ 282193267Sjkim 283193267SjkimACPI_STATUS 284193267SjkimAcpiOsPredefinedOverride ( 285193267Sjkim const ACPI_PREDEFINED_NAMES *InitVal, 286193267Sjkim ACPI_STRING *NewVal) 287193267Sjkim{ 288193267Sjkim 289193267Sjkim if (!InitVal || !NewVal) 290193267Sjkim { 291193267Sjkim return (AE_BAD_PARAMETER); 292193267Sjkim } 293193267Sjkim 294193267Sjkim *NewVal = NULL; 295193267Sjkim return (AE_OK); 296193267Sjkim} 297193267Sjkim 298193267Sjkim 299193267Sjkim/****************************************************************************** 300193267Sjkim * 301193267Sjkim * FUNCTION: AcpiOsTableOverride 302193267Sjkim * 303213800Sjkim * PARAMETERS: ExistingTable - Header of current table (probably 304213800Sjkim * firmware) 305213800Sjkim * NewTable - Where an entire new table is returned. 306193267Sjkim * 307213800Sjkim * RETURN: Status, pointer to new table. Null pointer returned if no 308193267Sjkim * table is available to override 309193267Sjkim * 310193267Sjkim * DESCRIPTION: Return a different version of a table if one is available 311193267Sjkim * 312193267Sjkim *****************************************************************************/ 313193267Sjkim 314193267SjkimACPI_STATUS 315193267SjkimAcpiOsTableOverride ( 316193267Sjkim ACPI_TABLE_HEADER *ExistingTable, 317193267Sjkim ACPI_TABLE_HEADER **NewTable) 318193267Sjkim{ 319193267Sjkim 320193267Sjkim if (!ExistingTable || !NewTable) 321193267Sjkim { 322193267Sjkim return (AE_BAD_PARAMETER); 323193267Sjkim } 324193267Sjkim 325193267Sjkim *NewTable = NULL; 326193267Sjkim 327193267Sjkim#ifdef ACPI_EXEC_APP 328193267Sjkim 329193267Sjkim AeTableOverride (ExistingTable, NewTable); 330193267Sjkim return (AE_OK); 331193267Sjkim#else 332193267Sjkim 333193267Sjkim return (AE_NO_ACPI_TABLES); 334193267Sjkim#endif 335193267Sjkim} 336193267Sjkim 337193267Sjkim 338193267Sjkim/****************************************************************************** 339193267Sjkim * 340231844Sjkim * FUNCTION: AcpiOsPhysicalTableOverride 341231844Sjkim * 342231844Sjkim * PARAMETERS: ExistingTable - Header of current table (probably firmware) 343231844Sjkim * NewAddress - Where new table address is returned 344231844Sjkim * (Physical address) 345231844Sjkim * NewTableLength - Where new table length is returned 346231844Sjkim * 347231844Sjkim * RETURN: Status, address/length of new table. Null pointer returned 348231844Sjkim * if no table is available to override. 349231844Sjkim * 350231844Sjkim * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. 351231844Sjkim * 352231844Sjkim *****************************************************************************/ 353231844Sjkim 354231844SjkimACPI_STATUS 355231844SjkimAcpiOsPhysicalTableOverride ( 356231844Sjkim ACPI_TABLE_HEADER *ExistingTable, 357231844Sjkim ACPI_PHYSICAL_ADDRESS *NewAddress, 358231844Sjkim UINT32 *NewTableLength) 359231844Sjkim{ 360231844Sjkim 361231844Sjkim return (AE_SUPPORT); 362231844Sjkim} 363231844Sjkim 364231844Sjkim 365231844Sjkim/****************************************************************************** 366231844Sjkim * 367193267Sjkim * FUNCTION: AcpiOsRedirectOutput 368193267Sjkim * 369193267Sjkim * PARAMETERS: Destination - An open file handle/pointer 370193267Sjkim * 371193267Sjkim * RETURN: None 372193267Sjkim * 373193267Sjkim * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf 374193267Sjkim * 375193267Sjkim *****************************************************************************/ 376193267Sjkim 377193267Sjkimvoid 378193267SjkimAcpiOsRedirectOutput ( 379193267Sjkim void *Destination) 380193267Sjkim{ 381193267Sjkim 382193267Sjkim AcpiGbl_OutputFile = Destination; 383193267Sjkim} 384193267Sjkim 385193267Sjkim 386193267Sjkim/****************************************************************************** 387193267Sjkim * 388193267Sjkim * FUNCTION: AcpiOsPrintf 389193267Sjkim * 390213800Sjkim * PARAMETERS: fmt, ... - Standard printf format 391193267Sjkim * 392193267Sjkim * RETURN: None 393193267Sjkim * 394245582Sjkim * DESCRIPTION: Formatted output. Note: very similar to AcpiOsVprintf 395245582Sjkim * (performance), changes should be tracked in both functions. 396193267Sjkim * 397193267Sjkim *****************************************************************************/ 398193267Sjkim 399193267Sjkimvoid ACPI_INTERNAL_VAR_XFACE 400193267SjkimAcpiOsPrintf ( 401193267Sjkim const char *Fmt, 402193267Sjkim ...) 403193267Sjkim{ 404193267Sjkim va_list Args; 405245582Sjkim UINT8 Flags; 406193267Sjkim 407193267Sjkim 408245582Sjkim Flags = AcpiGbl_DbOutputFlags; 409245582Sjkim if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT) 410245582Sjkim { 411245582Sjkim /* Output is directable to either a file (if open) or the console */ 412245582Sjkim 413245582Sjkim if (AcpiGbl_DebugFile) 414245582Sjkim { 415245582Sjkim /* Output file is open, send the output there */ 416245582Sjkim 417245582Sjkim va_start (Args, Fmt); 418245582Sjkim vfprintf (AcpiGbl_DebugFile, Fmt, Args); 419245582Sjkim va_end (Args); 420245582Sjkim } 421245582Sjkim else 422245582Sjkim { 423245582Sjkim /* No redirection, send output to console (once only!) */ 424245582Sjkim 425245582Sjkim Flags |= ACPI_DB_CONSOLE_OUTPUT; 426245582Sjkim } 427245582Sjkim } 428245582Sjkim 429245582Sjkim if (Flags & ACPI_DB_CONSOLE_OUTPUT) 430245582Sjkim { 431245582Sjkim va_start (Args, Fmt); 432245582Sjkim vfprintf (AcpiGbl_OutputFile, Fmt, Args); 433245582Sjkim va_end (Args); 434245582Sjkim } 435193267Sjkim} 436193267Sjkim 437193267Sjkim 438193267Sjkim/****************************************************************************** 439193267Sjkim * 440193267Sjkim * FUNCTION: AcpiOsVprintf 441193267Sjkim * 442213800Sjkim * PARAMETERS: fmt - Standard printf format 443213800Sjkim * args - Argument list 444193267Sjkim * 445193267Sjkim * RETURN: None 446193267Sjkim * 447245582Sjkim * DESCRIPTION: Formatted output with argument list pointer. Note: very 448245582Sjkim * similar to AcpiOsPrintf, changes should be tracked in both 449245582Sjkim * functions. 450193267Sjkim * 451193267Sjkim *****************************************************************************/ 452193267Sjkim 453193267Sjkimvoid 454193267SjkimAcpiOsVprintf ( 455193267Sjkim const char *Fmt, 456193267Sjkim va_list Args) 457193267Sjkim{ 458193267Sjkim UINT8 Flags; 459245582Sjkim char Buffer[ACPI_VPRINTF_BUFFER_SIZE]; 460193267Sjkim 461193267Sjkim 462245582Sjkim /* 463245582Sjkim * We build the output string in a local buffer because we may be 464245582Sjkim * outputting the buffer twice. Using vfprintf is problematic because 465245582Sjkim * some implementations modify the args pointer/structure during 466245582Sjkim * execution. Thus, we use the local buffer for portability. 467245582Sjkim * 468245582Sjkim * Note: Since this module is intended for use by the various ACPICA 469245582Sjkim * utilities/applications, we can safely declare the buffer on the stack. 470245582Sjkim * Also, This function is used for relatively small error messages only. 471245582Sjkim */ 472245582Sjkim vsnprintf (Buffer, ACPI_VPRINTF_BUFFER_SIZE, Fmt, Args); 473245582Sjkim 474193267Sjkim Flags = AcpiGbl_DbOutputFlags; 475193267Sjkim if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT) 476193267Sjkim { 477193267Sjkim /* Output is directable to either a file (if open) or the console */ 478193267Sjkim 479193267Sjkim if (AcpiGbl_DebugFile) 480193267Sjkim { 481193267Sjkim /* Output file is open, send the output there */ 482193267Sjkim 483245582Sjkim fputs (Buffer, AcpiGbl_DebugFile); 484193267Sjkim } 485193267Sjkim else 486193267Sjkim { 487193267Sjkim /* No redirection, send output to console (once only!) */ 488193267Sjkim 489193267Sjkim Flags |= ACPI_DB_CONSOLE_OUTPUT; 490193267Sjkim } 491193267Sjkim } 492193267Sjkim 493193267Sjkim if (Flags & ACPI_DB_CONSOLE_OUTPUT) 494193267Sjkim { 495245582Sjkim fputs (Buffer, AcpiGbl_OutputFile); 496193267Sjkim } 497193267Sjkim} 498193267Sjkim 499193267Sjkim 500281075Sdim#ifndef ACPI_EXEC_APP 501193267Sjkim/****************************************************************************** 502193267Sjkim * 503193267Sjkim * FUNCTION: AcpiOsGetLine 504193267Sjkim * 505222538Sjkim * PARAMETERS: Buffer - Where to return the command line 506222538Sjkim * BufferLength - Maximum length of Buffer 507222538Sjkim * BytesRead - Where the actual byte count is returned 508193267Sjkim * 509222538Sjkim * RETURN: Status and actual bytes read 510193267Sjkim * 511281075Sdim * DESCRIPTION: Get the next input line from the terminal. NOTE: For the 512281075Sdim * AcpiExec utility, we use the acgetline module instead to 513281075Sdim * provide line-editing and history support. 514193267Sjkim * 515193267Sjkim *****************************************************************************/ 516193267Sjkim 517222538SjkimACPI_STATUS 518193267SjkimAcpiOsGetLine ( 519222538Sjkim char *Buffer, 520222538Sjkim UINT32 BufferLength, 521222538Sjkim UINT32 *BytesRead) 522193267Sjkim{ 523281075Sdim int InputChar; 524281075Sdim UINT32 EndOfLine; 525193267Sjkim 526193267Sjkim 527281075Sdim /* Standard AcpiOsGetLine for all utilities except AcpiExec */ 528281075Sdim 529281075Sdim for (EndOfLine = 0; ; EndOfLine++) 530193267Sjkim { 531281075Sdim if (EndOfLine >= BufferLength) 532222538Sjkim { 533222538Sjkim return (AE_BUFFER_OVERFLOW); 534222538Sjkim } 535222538Sjkim 536281075Sdim if ((InputChar = getchar ()) == EOF) 537239340Sjkim { 538239340Sjkim return (AE_ERROR); 539239340Sjkim } 540239340Sjkim 541281075Sdim if (!InputChar || InputChar == _ASCII_NEWLINE) 542193267Sjkim { 543193267Sjkim break; 544193267Sjkim } 545193267Sjkim 546281075Sdim Buffer[EndOfLine] = (char) InputChar; 547193267Sjkim } 548193267Sjkim 549193267Sjkim /* Null terminate the buffer */ 550193267Sjkim 551281075Sdim Buffer[EndOfLine] = 0; 552193267Sjkim 553193267Sjkim /* Return the number of bytes in the string */ 554193267Sjkim 555222538Sjkim if (BytesRead) 556222538Sjkim { 557281075Sdim *BytesRead = EndOfLine; 558222538Sjkim } 559281075Sdim 560222538Sjkim return (AE_OK); 561193267Sjkim} 562281075Sdim#endif 563193267Sjkim 564213800Sjkim 565281075Sdim#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING 566193267Sjkim/****************************************************************************** 567193267Sjkim * 568193267Sjkim * FUNCTION: AcpiOsMapMemory 569193267Sjkim * 570213800Sjkim * PARAMETERS: where - Physical address of memory to be mapped 571213800Sjkim * length - How much memory to map 572193267Sjkim * 573213800Sjkim * RETURN: Pointer to mapped memory. Null on error. 574193267Sjkim * 575193267Sjkim * DESCRIPTION: Map physical memory into caller's address space 576193267Sjkim * 577193267Sjkim *****************************************************************************/ 578193267Sjkim 579193267Sjkimvoid * 580193267SjkimAcpiOsMapMemory ( 581193267Sjkim ACPI_PHYSICAL_ADDRESS where, 582193267Sjkim ACPI_SIZE length) 583193267Sjkim{ 584193267Sjkim 585193267Sjkim return (ACPI_TO_POINTER ((ACPI_SIZE) where)); 586193267Sjkim} 587193267Sjkim 588193267Sjkim 589193267Sjkim/****************************************************************************** 590193267Sjkim * 591193267Sjkim * FUNCTION: AcpiOsUnmapMemory 592193267Sjkim * 593213800Sjkim * PARAMETERS: where - Logical address of memory to be unmapped 594213800Sjkim * length - How much memory to unmap 595193267Sjkim * 596193267Sjkim * RETURN: None. 597193267Sjkim * 598213800Sjkim * DESCRIPTION: Delete a previously created mapping. Where and Length must 599193267Sjkim * correspond to a previous mapping exactly. 600193267Sjkim * 601193267Sjkim *****************************************************************************/ 602193267Sjkim 603193267Sjkimvoid 604193267SjkimAcpiOsUnmapMemory ( 605193267Sjkim void *where, 606193267Sjkim ACPI_SIZE length) 607193267Sjkim{ 608193267Sjkim 609193267Sjkim return; 610193267Sjkim} 611281075Sdim#endif 612193267Sjkim 613193267Sjkim 614193267Sjkim/****************************************************************************** 615193267Sjkim * 616193267Sjkim * FUNCTION: AcpiOsAllocate 617193267Sjkim * 618213800Sjkim * PARAMETERS: Size - Amount to allocate, in bytes 619193267Sjkim * 620213800Sjkim * RETURN: Pointer to the new allocation. Null on error. 621193267Sjkim * 622213800Sjkim * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. 623193267Sjkim * 624193267Sjkim *****************************************************************************/ 625193267Sjkim 626193267Sjkimvoid * 627193267SjkimAcpiOsAllocate ( 628193267Sjkim ACPI_SIZE size) 629193267Sjkim{ 630193267Sjkim void *Mem; 631193267Sjkim 632193267Sjkim 633193267Sjkim Mem = (void *) malloc ((size_t) size); 634193267Sjkim return (Mem); 635193267Sjkim} 636193267Sjkim 637193267Sjkim 638281075Sdim#ifdef USE_NATIVE_ALLOCATE_ZEROED 639193267Sjkim/****************************************************************************** 640193267Sjkim * 641281075Sdim * FUNCTION: AcpiOsAllocateZeroed 642281075Sdim * 643281075Sdim * PARAMETERS: Size - Amount to allocate, in bytes 644281075Sdim * 645281075Sdim * RETURN: Pointer to the new allocation. Null on error. 646281075Sdim * 647281075Sdim * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS. 648281075Sdim * 649281075Sdim *****************************************************************************/ 650281075Sdim 651281075Sdimvoid * 652281075SdimAcpiOsAllocateZeroed ( 653281075Sdim ACPI_SIZE size) 654281075Sdim{ 655281075Sdim void *Mem; 656281075Sdim 657281075Sdim 658281075Sdim Mem = (void *) calloc (1, (size_t) size); 659281075Sdim return (Mem); 660281075Sdim} 661281075Sdim#endif 662281075Sdim 663281075Sdim 664281075Sdim/****************************************************************************** 665281075Sdim * 666193267Sjkim * FUNCTION: AcpiOsFree 667193267Sjkim * 668213800Sjkim * PARAMETERS: mem - Pointer to previously allocated memory 669193267Sjkim * 670193267Sjkim * RETURN: None. 671193267Sjkim * 672193267Sjkim * DESCRIPTION: Free memory allocated via AcpiOsAllocate 673193267Sjkim * 674193267Sjkim *****************************************************************************/ 675193267Sjkim 676193267Sjkimvoid 677193267SjkimAcpiOsFree ( 678193267Sjkim void *mem) 679193267Sjkim{ 680193267Sjkim 681193267Sjkim free (mem); 682193267Sjkim} 683193267Sjkim 684193267Sjkim 685213800Sjkim#ifdef ACPI_SINGLE_THREADED 686193267Sjkim/****************************************************************************** 687193267Sjkim * 688213800Sjkim * FUNCTION: Semaphore stub functions 689213800Sjkim * 690213800Sjkim * DESCRIPTION: Stub functions used for single-thread applications that do 691213800Sjkim * not require semaphore synchronization. Full implementations 692213800Sjkim * of these functions appear after the stubs. 693213800Sjkim * 694213800Sjkim *****************************************************************************/ 695213800Sjkim 696213800SjkimACPI_STATUS 697213800SjkimAcpiOsCreateSemaphore ( 698213800Sjkim UINT32 MaxUnits, 699213800Sjkim UINT32 InitialUnits, 700213800Sjkim ACPI_HANDLE *OutHandle) 701213800Sjkim{ 702213800Sjkim *OutHandle = (ACPI_HANDLE) 1; 703213800Sjkim return (AE_OK); 704213800Sjkim} 705213800Sjkim 706213800SjkimACPI_STATUS 707213800SjkimAcpiOsDeleteSemaphore ( 708213800Sjkim ACPI_HANDLE Handle) 709213800Sjkim{ 710213800Sjkim return (AE_OK); 711213800Sjkim} 712213800Sjkim 713213800SjkimACPI_STATUS 714213800SjkimAcpiOsWaitSemaphore ( 715213800Sjkim ACPI_HANDLE Handle, 716213800Sjkim UINT32 Units, 717213800Sjkim UINT16 Timeout) 718213800Sjkim{ 719213800Sjkim return (AE_OK); 720213800Sjkim} 721213800Sjkim 722213800SjkimACPI_STATUS 723213800SjkimAcpiOsSignalSemaphore ( 724213800Sjkim ACPI_HANDLE Handle, 725213800Sjkim UINT32 Units) 726213800Sjkim{ 727213800Sjkim return (AE_OK); 728213800Sjkim} 729213800Sjkim 730213800Sjkim#else 731213800Sjkim/****************************************************************************** 732213800Sjkim * 733193267Sjkim * FUNCTION: AcpiOsCreateSemaphore 734193267Sjkim * 735193267Sjkim * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore 736193267Sjkim * OutHandle - Where a handle will be returned 737193267Sjkim * 738193267Sjkim * RETURN: Status 739193267Sjkim * 740193267Sjkim * DESCRIPTION: Create an OS semaphore 741193267Sjkim * 742193267Sjkim *****************************************************************************/ 743193267Sjkim 744193267SjkimACPI_STATUS 745193267SjkimAcpiOsCreateSemaphore ( 746193267Sjkim UINT32 MaxUnits, 747193267Sjkim UINT32 InitialUnits, 748193267Sjkim ACPI_HANDLE *OutHandle) 749193267Sjkim{ 750193267Sjkim sem_t *Sem; 751193267Sjkim 752193267Sjkim 753193267Sjkim if (!OutHandle) 754193267Sjkim { 755193267Sjkim return (AE_BAD_PARAMETER); 756193267Sjkim } 757193267Sjkim 758209734Sjkim#ifdef __APPLE__ 759209734Sjkim { 760213800Sjkim char *SemaphoreName = tmpnam (NULL); 761213800Sjkim 762213800Sjkim Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits); 763213800Sjkim if (!Sem) 764213800Sjkim { 765213800Sjkim return (AE_NO_MEMORY); 766213800Sjkim } 767213800Sjkim sem_unlink (SemaphoreName); /* This just deletes the name */ 768209734Sjkim } 769209734Sjkim 770209734Sjkim#else 771193267Sjkim Sem = AcpiOsAllocate (sizeof (sem_t)); 772193267Sjkim if (!Sem) 773193267Sjkim { 774193267Sjkim return (AE_NO_MEMORY); 775193267Sjkim } 776193267Sjkim 777193267Sjkim if (sem_init (Sem, 0, InitialUnits) == -1) 778193267Sjkim { 779193267Sjkim AcpiOsFree (Sem); 780193267Sjkim return (AE_BAD_PARAMETER); 781193267Sjkim } 782209734Sjkim#endif 783193267Sjkim 784193267Sjkim *OutHandle = (ACPI_HANDLE) Sem; 785193267Sjkim return (AE_OK); 786193267Sjkim} 787193267Sjkim 788193267Sjkim 789193267Sjkim/****************************************************************************** 790193267Sjkim * 791193267Sjkim * FUNCTION: AcpiOsDeleteSemaphore 792193267Sjkim * 793193267Sjkim * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 794193267Sjkim * 795193267Sjkim * RETURN: Status 796193267Sjkim * 797193267Sjkim * DESCRIPTION: Delete an OS semaphore 798193267Sjkim * 799193267Sjkim *****************************************************************************/ 800193267Sjkim 801193267SjkimACPI_STATUS 802193267SjkimAcpiOsDeleteSemaphore ( 803193267Sjkim ACPI_HANDLE Handle) 804193267Sjkim{ 805193267Sjkim sem_t *Sem = (sem_t *) Handle; 806193267Sjkim 807193267Sjkim 808193267Sjkim if (!Sem) 809193267Sjkim { 810193267Sjkim return (AE_BAD_PARAMETER); 811193267Sjkim } 812193267Sjkim 813193267Sjkim if (sem_destroy (Sem) == -1) 814193267Sjkim { 815193267Sjkim return (AE_BAD_PARAMETER); 816193267Sjkim } 817193267Sjkim 818193267Sjkim return (AE_OK); 819193267Sjkim} 820193267Sjkim 821193267Sjkim 822193267Sjkim/****************************************************************************** 823193267Sjkim * 824193267Sjkim * FUNCTION: AcpiOsWaitSemaphore 825193267Sjkim * 826193267Sjkim * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 827193267Sjkim * Units - How many units to wait for 828245582Sjkim * MsecTimeout - How long to wait (milliseconds) 829193267Sjkim * 830193267Sjkim * RETURN: Status 831193267Sjkim * 832193267Sjkim * DESCRIPTION: Wait for units 833193267Sjkim * 834193267Sjkim *****************************************************************************/ 835193267Sjkim 836193267SjkimACPI_STATUS 837193267SjkimAcpiOsWaitSemaphore ( 838193267Sjkim ACPI_HANDLE Handle, 839193267Sjkim UINT32 Units, 840245582Sjkim UINT16 MsecTimeout) 841193267Sjkim{ 842193267Sjkim ACPI_STATUS Status = AE_OK; 843193267Sjkim sem_t *Sem = (sem_t *) Handle; 844245582Sjkim#ifndef ACPI_USE_ALTERNATE_TIMEOUT 845245582Sjkim struct timespec Time; 846245582Sjkim int RetVal; 847245582Sjkim#endif 848193267Sjkim 849193267Sjkim 850193267Sjkim if (!Sem) 851193267Sjkim { 852193267Sjkim return (AE_BAD_PARAMETER); 853193267Sjkim } 854193267Sjkim 855245582Sjkim switch (MsecTimeout) 856193267Sjkim { 857193267Sjkim /* 858193267Sjkim * No Wait: 859193267Sjkim * -------- 860193267Sjkim * A zero timeout value indicates that we shouldn't wait - just 861193267Sjkim * acquire the semaphore if available otherwise return AE_TIME 862193267Sjkim * (a.k.a. 'would block'). 863193267Sjkim */ 864193267Sjkim case 0: 865193267Sjkim 866193267Sjkim if (sem_trywait(Sem) == -1) 867193267Sjkim { 868193267Sjkim Status = (AE_TIME); 869193267Sjkim } 870193267Sjkim break; 871193267Sjkim 872193267Sjkim /* Wait Indefinitely */ 873193267Sjkim 874193267Sjkim case ACPI_WAIT_FOREVER: 875193267Sjkim 876193267Sjkim if (sem_wait (Sem)) 877193267Sjkim { 878193267Sjkim Status = (AE_TIME); 879193267Sjkim } 880193267Sjkim break; 881193267Sjkim 882245582Sjkim /* Wait with MsecTimeout */ 883193267Sjkim 884193267Sjkim default: 885193267Sjkim 886193267Sjkim#ifdef ACPI_USE_ALTERNATE_TIMEOUT 887193267Sjkim /* 888193267Sjkim * Alternate timeout mechanism for environments where 889193267Sjkim * sem_timedwait is not available or does not work properly. 890193267Sjkim */ 891245582Sjkim while (MsecTimeout) 892193267Sjkim { 893193267Sjkim if (sem_trywait (Sem) == 0) 894193267Sjkim { 895193267Sjkim /* Got the semaphore */ 896193267Sjkim return (AE_OK); 897193267Sjkim } 898245582Sjkim 899245582Sjkim if (MsecTimeout >= 10) 900245582Sjkim { 901245582Sjkim MsecTimeout -= 10; 902245582Sjkim usleep (10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */ 903245582Sjkim } 904245582Sjkim else 905245582Sjkim { 906245582Sjkim MsecTimeout--; 907245582Sjkim usleep (ACPI_USEC_PER_MSEC); /* one millisecond */ 908245582Sjkim } 909193267Sjkim } 910193267Sjkim Status = (AE_TIME); 911193267Sjkim#else 912245582Sjkim /* 913245582Sjkim * The interface to sem_timedwait is an absolute time, so we need to 914245582Sjkim * get the current time, then add in the millisecond Timeout value. 915245582Sjkim */ 916245582Sjkim if (clock_gettime (CLOCK_REALTIME, &Time) == -1) 917245582Sjkim { 918245582Sjkim perror ("clock_gettime"); 919245582Sjkim return (AE_TIME); 920245582Sjkim } 921193267Sjkim 922245582Sjkim Time.tv_sec += (MsecTimeout / ACPI_MSEC_PER_SEC); 923245582Sjkim Time.tv_nsec += ((MsecTimeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC); 924245582Sjkim 925245582Sjkim /* Handle nanosecond overflow (field must be less than one second) */ 926245582Sjkim 927245582Sjkim if (Time.tv_nsec >= ACPI_NSEC_PER_SEC) 928193267Sjkim { 929245582Sjkim Time.tv_sec += (Time.tv_nsec / ACPI_NSEC_PER_SEC); 930245582Sjkim Time.tv_nsec = (Time.tv_nsec % ACPI_NSEC_PER_SEC); 931245582Sjkim } 932245582Sjkim 933245582Sjkim while (((RetVal = sem_timedwait (Sem, &Time)) == -1) && (errno == EINTR)) 934245582Sjkim { 935245582Sjkim continue; 936245582Sjkim } 937245582Sjkim 938245582Sjkim if (RetVal != 0) 939245582Sjkim { 940245582Sjkim if (errno != ETIMEDOUT) 941245582Sjkim { 942245582Sjkim perror ("sem_timedwait"); 943245582Sjkim } 944193267Sjkim Status = (AE_TIME); 945193267Sjkim } 946193267Sjkim#endif 947193267Sjkim break; 948193267Sjkim } 949193267Sjkim 950193267Sjkim return (Status); 951193267Sjkim} 952193267Sjkim 953193267Sjkim 954193267Sjkim/****************************************************************************** 955193267Sjkim * 956193267Sjkim * FUNCTION: AcpiOsSignalSemaphore 957193267Sjkim * 958193267Sjkim * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore 959193267Sjkim * Units - Number of units to send 960193267Sjkim * 961193267Sjkim * RETURN: Status 962193267Sjkim * 963193267Sjkim * DESCRIPTION: Send units 964193267Sjkim * 965193267Sjkim *****************************************************************************/ 966193267Sjkim 967193267SjkimACPI_STATUS 968193267SjkimAcpiOsSignalSemaphore ( 969193267Sjkim ACPI_HANDLE Handle, 970193267Sjkim UINT32 Units) 971193267Sjkim{ 972193267Sjkim sem_t *Sem = (sem_t *)Handle; 973193267Sjkim 974193267Sjkim 975193267Sjkim if (!Sem) 976193267Sjkim { 977193267Sjkim return (AE_BAD_PARAMETER); 978193267Sjkim } 979193267Sjkim 980193267Sjkim if (sem_post (Sem) == -1) 981193267Sjkim { 982193267Sjkim return (AE_LIMIT); 983193267Sjkim } 984193267Sjkim 985193267Sjkim return (AE_OK); 986193267Sjkim} 987193267Sjkim 988213800Sjkim#endif /* ACPI_SINGLE_THREADED */ 989193267Sjkim 990213800Sjkim 991193267Sjkim/****************************************************************************** 992193267Sjkim * 993193267Sjkim * FUNCTION: Spinlock interfaces 994193267Sjkim * 995193267Sjkim * DESCRIPTION: Map these interfaces to semaphore interfaces 996193267Sjkim * 997193267Sjkim *****************************************************************************/ 998193267Sjkim 999193267SjkimACPI_STATUS 1000193267SjkimAcpiOsCreateLock ( 1001193267Sjkim ACPI_SPINLOCK *OutHandle) 1002193267Sjkim{ 1003193267Sjkim 1004193267Sjkim return (AcpiOsCreateSemaphore (1, 1, OutHandle)); 1005193267Sjkim} 1006193267Sjkim 1007193267Sjkim 1008193267Sjkimvoid 1009193267SjkimAcpiOsDeleteLock ( 1010193267Sjkim ACPI_SPINLOCK Handle) 1011193267Sjkim{ 1012193267Sjkim AcpiOsDeleteSemaphore (Handle); 1013193267Sjkim} 1014193267Sjkim 1015193267Sjkim 1016193267SjkimACPI_CPU_FLAGS 1017193267SjkimAcpiOsAcquireLock ( 1018193267Sjkim ACPI_HANDLE Handle) 1019193267Sjkim{ 1020193267Sjkim AcpiOsWaitSemaphore (Handle, 1, 0xFFFF); 1021193267Sjkim return (0); 1022193267Sjkim} 1023193267Sjkim 1024193267Sjkim 1025193267Sjkimvoid 1026193267SjkimAcpiOsReleaseLock ( 1027193267Sjkim ACPI_SPINLOCK Handle, 1028193267Sjkim ACPI_CPU_FLAGS Flags) 1029193267Sjkim{ 1030193267Sjkim AcpiOsSignalSemaphore (Handle, 1); 1031193267Sjkim} 1032193267Sjkim 1033193267Sjkim 1034193267Sjkim/****************************************************************************** 1035193267Sjkim * 1036193267Sjkim * FUNCTION: AcpiOsInstallInterruptHandler 1037193267Sjkim * 1038213800Sjkim * PARAMETERS: InterruptNumber - Level handler should respond to. 1039213800Sjkim * Isr - Address of the ACPI interrupt handler 1040213800Sjkim * ExceptPtr - Where status is returned 1041193267Sjkim * 1042193267Sjkim * RETURN: Handle to the newly installed handler. 1043193267Sjkim * 1044213800Sjkim * DESCRIPTION: Install an interrupt handler. Used to install the ACPI 1045193267Sjkim * OS-independent handler. 1046193267Sjkim * 1047193267Sjkim *****************************************************************************/ 1048193267Sjkim 1049193267SjkimUINT32 1050193267SjkimAcpiOsInstallInterruptHandler ( 1051193267Sjkim UINT32 InterruptNumber, 1052193267Sjkim ACPI_OSD_HANDLER ServiceRoutine, 1053193267Sjkim void *Context) 1054193267Sjkim{ 1055193267Sjkim 1056193267Sjkim return (AE_OK); 1057193267Sjkim} 1058193267Sjkim 1059193267Sjkim 1060193267Sjkim/****************************************************************************** 1061193267Sjkim * 1062193267Sjkim * FUNCTION: AcpiOsRemoveInterruptHandler 1063193267Sjkim * 1064213800Sjkim * PARAMETERS: Handle - Returned when handler was installed 1065193267Sjkim * 1066193267Sjkim * RETURN: Status 1067193267Sjkim * 1068193267Sjkim * DESCRIPTION: Uninstalls an interrupt handler. 1069193267Sjkim * 1070193267Sjkim *****************************************************************************/ 1071193267Sjkim 1072193267SjkimACPI_STATUS 1073193267SjkimAcpiOsRemoveInterruptHandler ( 1074193267Sjkim UINT32 InterruptNumber, 1075193267Sjkim ACPI_OSD_HANDLER ServiceRoutine) 1076193267Sjkim{ 1077193267Sjkim 1078193267Sjkim return (AE_OK); 1079193267Sjkim} 1080193267Sjkim 1081193267Sjkim 1082193267Sjkim/****************************************************************************** 1083193267Sjkim * 1084193267Sjkim * FUNCTION: AcpiOsStall 1085193267Sjkim * 1086213800Sjkim * PARAMETERS: microseconds - Time to sleep 1087193267Sjkim * 1088193267Sjkim * RETURN: Blocks until sleep is completed. 1089193267Sjkim * 1090193267Sjkim * DESCRIPTION: Sleep at microsecond granularity 1091193267Sjkim * 1092193267Sjkim *****************************************************************************/ 1093193267Sjkim 1094193267Sjkimvoid 1095193267SjkimAcpiOsStall ( 1096193267Sjkim UINT32 microseconds) 1097193267Sjkim{ 1098193267Sjkim 1099193267Sjkim if (microseconds) 1100193267Sjkim { 1101193267Sjkim usleep (microseconds); 1102193267Sjkim } 1103193267Sjkim} 1104193267Sjkim 1105193267Sjkim 1106193267Sjkim/****************************************************************************** 1107193267Sjkim * 1108193267Sjkim * FUNCTION: AcpiOsSleep 1109193267Sjkim * 1110213800Sjkim * PARAMETERS: milliseconds - Time to sleep 1111193267Sjkim * 1112193267Sjkim * RETURN: Blocks until sleep is completed. 1113193267Sjkim * 1114193267Sjkim * DESCRIPTION: Sleep at millisecond granularity 1115193267Sjkim * 1116193267Sjkim *****************************************************************************/ 1117193267Sjkim 1118193267Sjkimvoid 1119193267SjkimAcpiOsSleep ( 1120202766Sjkim UINT64 milliseconds) 1121193267Sjkim{ 1122193267Sjkim 1123245582Sjkim /* Sleep for whole seconds */ 1124193267Sjkim 1125245582Sjkim sleep (milliseconds / ACPI_MSEC_PER_SEC); 1126245582Sjkim 1127193267Sjkim /* 1128245582Sjkim * Sleep for remaining microseconds. 1129245582Sjkim * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second). 1130193267Sjkim */ 1131245582Sjkim usleep ((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC); 1132193267Sjkim} 1133193267Sjkim 1134213800Sjkim 1135193267Sjkim/****************************************************************************** 1136193267Sjkim * 1137193267Sjkim * FUNCTION: AcpiOsGetTimer 1138193267Sjkim * 1139193267Sjkim * PARAMETERS: None 1140193267Sjkim * 1141193267Sjkim * RETURN: Current time in 100 nanosecond units 1142193267Sjkim * 1143193267Sjkim * DESCRIPTION: Get the current system time 1144193267Sjkim * 1145193267Sjkim *****************************************************************************/ 1146193267Sjkim 1147193267SjkimUINT64 1148213800SjkimAcpiOsGetTimer ( 1149213800Sjkim void) 1150193267Sjkim{ 1151193267Sjkim struct timeval time; 1152193267Sjkim 1153193267Sjkim 1154245582Sjkim /* This timer has sufficient resolution for user-space application code */ 1155245582Sjkim 1156193267Sjkim gettimeofday (&time, NULL); 1157193267Sjkim 1158245582Sjkim /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */ 1159193267Sjkim 1160245582Sjkim return (((UINT64) time.tv_sec * ACPI_100NSEC_PER_SEC) + 1161245582Sjkim ((UINT64) time.tv_usec * ACPI_100NSEC_PER_USEC)); 1162193267Sjkim} 1163193267Sjkim 1164193267Sjkim 1165193267Sjkim/****************************************************************************** 1166193267Sjkim * 1167193267Sjkim * FUNCTION: AcpiOsReadPciConfiguration 1168193267Sjkim * 1169213800Sjkim * PARAMETERS: PciId - Seg/Bus/Dev 1170281075Sdim * PciRegister - Device Register 1171213800Sjkim * Value - Buffer where value is placed 1172213800Sjkim * Width - Number of bits 1173193267Sjkim * 1174193267Sjkim * RETURN: Status 1175193267Sjkim * 1176193267Sjkim * DESCRIPTION: Read data from PCI configuration space 1177193267Sjkim * 1178193267Sjkim *****************************************************************************/ 1179193267Sjkim 1180193267SjkimACPI_STATUS 1181193267SjkimAcpiOsReadPciConfiguration ( 1182193267Sjkim ACPI_PCI_ID *PciId, 1183281075Sdim UINT32 PciRegister, 1184210944Sjkim UINT64 *Value, 1185193267Sjkim UINT32 Width) 1186193267Sjkim{ 1187193267Sjkim 1188254745Sjkim *Value = 0; 1189193267Sjkim return (AE_OK); 1190193267Sjkim} 1191193267Sjkim 1192193267Sjkim 1193193267Sjkim/****************************************************************************** 1194193267Sjkim * 1195193267Sjkim * FUNCTION: AcpiOsWritePciConfiguration 1196193267Sjkim * 1197213800Sjkim * PARAMETERS: PciId - Seg/Bus/Dev 1198281075Sdim * PciRegister - Device Register 1199213800Sjkim * Value - Value to be written 1200213800Sjkim * Width - Number of bits 1201193267Sjkim * 1202193267Sjkim * RETURN: Status. 1203193267Sjkim * 1204193267Sjkim * DESCRIPTION: Write data to PCI configuration space 1205193267Sjkim * 1206193267Sjkim *****************************************************************************/ 1207193267Sjkim 1208193267SjkimACPI_STATUS 1209193267SjkimAcpiOsWritePciConfiguration ( 1210193267Sjkim ACPI_PCI_ID *PciId, 1211281075Sdim UINT32 PciRegister, 1212202766Sjkim UINT64 Value, 1213193267Sjkim UINT32 Width) 1214193267Sjkim{ 1215193267Sjkim 1216193267Sjkim return (AE_OK); 1217193267Sjkim} 1218193267Sjkim 1219193267Sjkim 1220193267Sjkim/****************************************************************************** 1221193267Sjkim * 1222193267Sjkim * FUNCTION: AcpiOsReadPort 1223193267Sjkim * 1224213800Sjkim * PARAMETERS: Address - Address of I/O port/register to read 1225213800Sjkim * Value - Where value is placed 1226213800Sjkim * Width - Number of bits 1227193267Sjkim * 1228193267Sjkim * RETURN: Value read from port 1229193267Sjkim * 1230193267Sjkim * DESCRIPTION: Read data from an I/O port or register 1231193267Sjkim * 1232193267Sjkim *****************************************************************************/ 1233193267Sjkim 1234193267SjkimACPI_STATUS 1235193267SjkimAcpiOsReadPort ( 1236193267Sjkim ACPI_IO_ADDRESS Address, 1237193267Sjkim UINT32 *Value, 1238193267Sjkim UINT32 Width) 1239193267Sjkim{ 1240193267Sjkim 1241193267Sjkim switch (Width) 1242193267Sjkim { 1243193267Sjkim case 8: 1244250838Sjkim 1245193267Sjkim *Value = 0xFF; 1246193267Sjkim break; 1247193267Sjkim 1248193267Sjkim case 16: 1249250838Sjkim 1250193267Sjkim *Value = 0xFFFF; 1251193267Sjkim break; 1252193267Sjkim 1253193267Sjkim case 32: 1254250838Sjkim 1255193267Sjkim *Value = 0xFFFFFFFF; 1256193267Sjkim break; 1257193267Sjkim 1258193267Sjkim default: 1259250838Sjkim 1260193267Sjkim return (AE_BAD_PARAMETER); 1261193267Sjkim } 1262193267Sjkim 1263193267Sjkim return (AE_OK); 1264193267Sjkim} 1265193267Sjkim 1266193267Sjkim 1267193267Sjkim/****************************************************************************** 1268193267Sjkim * 1269193267Sjkim * FUNCTION: AcpiOsWritePort 1270193267Sjkim * 1271213800Sjkim * PARAMETERS: Address - Address of I/O port/register to write 1272213800Sjkim * Value - Value to write 1273213800Sjkim * Width - Number of bits 1274193267Sjkim * 1275193267Sjkim * RETURN: None 1276193267Sjkim * 1277193267Sjkim * DESCRIPTION: Write data to an I/O port or register 1278193267Sjkim * 1279193267Sjkim *****************************************************************************/ 1280193267Sjkim 1281193267SjkimACPI_STATUS 1282193267SjkimAcpiOsWritePort ( 1283193267Sjkim ACPI_IO_ADDRESS Address, 1284193267Sjkim UINT32 Value, 1285193267Sjkim UINT32 Width) 1286193267Sjkim{ 1287193267Sjkim 1288193267Sjkim return (AE_OK); 1289193267Sjkim} 1290193267Sjkim 1291193267Sjkim 1292193267Sjkim/****************************************************************************** 1293193267Sjkim * 1294193267Sjkim * FUNCTION: AcpiOsReadMemory 1295193267Sjkim * 1296213800Sjkim * PARAMETERS: Address - Physical Memory Address to read 1297213800Sjkim * Value - Where value is placed 1298231844Sjkim * Width - Number of bits (8,16,32, or 64) 1299193267Sjkim * 1300231844Sjkim * RETURN: Value read from physical memory address. Always returned 1301231844Sjkim * as a 64-bit integer, regardless of the read width. 1302193267Sjkim * 1303193267Sjkim * DESCRIPTION: Read data from a physical memory address 1304193267Sjkim * 1305193267Sjkim *****************************************************************************/ 1306193267Sjkim 1307193267SjkimACPI_STATUS 1308193267SjkimAcpiOsReadMemory ( 1309193267Sjkim ACPI_PHYSICAL_ADDRESS Address, 1310231844Sjkim UINT64 *Value, 1311193267Sjkim UINT32 Width) 1312193267Sjkim{ 1313193267Sjkim 1314193267Sjkim switch (Width) 1315193267Sjkim { 1316193267Sjkim case 8: 1317193267Sjkim case 16: 1318193267Sjkim case 32: 1319231844Sjkim case 64: 1320250838Sjkim 1321193267Sjkim *Value = 0; 1322193267Sjkim break; 1323193267Sjkim 1324193267Sjkim default: 1325250838Sjkim 1326193267Sjkim return (AE_BAD_PARAMETER); 1327193267Sjkim } 1328193267Sjkim return (AE_OK); 1329193267Sjkim} 1330193267Sjkim 1331193267Sjkim 1332193267Sjkim/****************************************************************************** 1333193267Sjkim * 1334193267Sjkim * FUNCTION: AcpiOsWriteMemory 1335193267Sjkim * 1336213800Sjkim * PARAMETERS: Address - Physical Memory Address to write 1337213800Sjkim * Value - Value to write 1338231844Sjkim * Width - Number of bits (8,16,32, or 64) 1339193267Sjkim * 1340193267Sjkim * RETURN: None 1341193267Sjkim * 1342193267Sjkim * DESCRIPTION: Write data to a physical memory address 1343193267Sjkim * 1344193267Sjkim *****************************************************************************/ 1345193267Sjkim 1346193267SjkimACPI_STATUS 1347193267SjkimAcpiOsWriteMemory ( 1348193267Sjkim ACPI_PHYSICAL_ADDRESS Address, 1349231844Sjkim UINT64 Value, 1350193267Sjkim UINT32 Width) 1351193267Sjkim{ 1352193267Sjkim 1353193267Sjkim return (AE_OK); 1354193267Sjkim} 1355193267Sjkim 1356193267Sjkim 1357193267Sjkim/****************************************************************************** 1358193267Sjkim * 1359193267Sjkim * FUNCTION: AcpiOsReadable 1360193267Sjkim * 1361193267Sjkim * PARAMETERS: Pointer - Area to be verified 1362193267Sjkim * Length - Size of area 1363193267Sjkim * 1364193267Sjkim * RETURN: TRUE if readable for entire length 1365193267Sjkim * 1366193267Sjkim * DESCRIPTION: Verify that a pointer is valid for reading 1367193267Sjkim * 1368193267Sjkim *****************************************************************************/ 1369193267Sjkim 1370193267SjkimBOOLEAN 1371193267SjkimAcpiOsReadable ( 1372193267Sjkim void *Pointer, 1373193267Sjkim ACPI_SIZE Length) 1374193267Sjkim{ 1375193267Sjkim 1376193267Sjkim return (TRUE); 1377193267Sjkim} 1378193267Sjkim 1379193267Sjkim 1380193267Sjkim/****************************************************************************** 1381193267Sjkim * 1382193267Sjkim * FUNCTION: AcpiOsWritable 1383193267Sjkim * 1384193267Sjkim * PARAMETERS: Pointer - Area to be verified 1385193267Sjkim * Length - Size of area 1386193267Sjkim * 1387193267Sjkim * RETURN: TRUE if writable for entire length 1388193267Sjkim * 1389193267Sjkim * DESCRIPTION: Verify that a pointer is valid for writing 1390193267Sjkim * 1391193267Sjkim *****************************************************************************/ 1392193267Sjkim 1393193267SjkimBOOLEAN 1394193267SjkimAcpiOsWritable ( 1395193267Sjkim void *Pointer, 1396193267Sjkim ACPI_SIZE Length) 1397193267Sjkim{ 1398193267Sjkim 1399193267Sjkim return (TRUE); 1400193267Sjkim} 1401193267Sjkim 1402193267Sjkim 1403193267Sjkim/****************************************************************************** 1404193267Sjkim * 1405223480Sjkim * FUNCTION: AcpiOsSignal 1406223480Sjkim * 1407281075Sdim * PARAMETERS: Function - ACPI A signal function code 1408223480Sjkim * Info - Pointer to function-dependent structure 1409223480Sjkim * 1410223480Sjkim * RETURN: Status 1411223480Sjkim * 1412223480Sjkim * DESCRIPTION: Miscellaneous functions. Example implementation only. 1413223480Sjkim * 1414223480Sjkim *****************************************************************************/ 1415223480Sjkim 1416223480SjkimACPI_STATUS 1417223480SjkimAcpiOsSignal ( 1418223480Sjkim UINT32 Function, 1419223480Sjkim void *Info) 1420223480Sjkim{ 1421223480Sjkim 1422223480Sjkim switch (Function) 1423223480Sjkim { 1424223480Sjkim case ACPI_SIGNAL_FATAL: 1425250838Sjkim 1426223480Sjkim break; 1427223480Sjkim 1428223480Sjkim case ACPI_SIGNAL_BREAKPOINT: 1429250838Sjkim 1430223480Sjkim break; 1431223480Sjkim 1432223480Sjkim default: 1433250838Sjkim 1434223480Sjkim break; 1435223480Sjkim } 1436223480Sjkim 1437223480Sjkim return (AE_OK); 1438223480Sjkim} 1439223480Sjkim 1440223480Sjkim/* Optional multi-thread support */ 1441223480Sjkim 1442223480Sjkim#ifndef ACPI_SINGLE_THREADED 1443223480Sjkim/****************************************************************************** 1444223480Sjkim * 1445193267Sjkim * FUNCTION: AcpiOsGetThreadId 1446193267Sjkim * 1447193267Sjkim * PARAMETERS: None 1448193267Sjkim * 1449193267Sjkim * RETURN: Id of the running thread 1450193267Sjkim * 1451213800Sjkim * DESCRIPTION: Get the ID of the current (running) thread 1452193267Sjkim * 1453193267Sjkim *****************************************************************************/ 1454193267Sjkim 1455193267SjkimACPI_THREAD_ID 1456212700SjkimAcpiOsGetThreadId ( 1457212700Sjkim void) 1458193267Sjkim{ 1459227896Sjkim pthread_t thread; 1460193267Sjkim 1461227896Sjkim 1462227896Sjkim thread = pthread_self(); 1463227896Sjkim return (ACPI_CAST_PTHREAD_T (thread)); 1464193267Sjkim} 1465193267Sjkim 1466193267Sjkim 1467193267Sjkim/****************************************************************************** 1468193267Sjkim * 1469223480Sjkim * FUNCTION: AcpiOsExecute 1470193267Sjkim * 1471223480Sjkim * PARAMETERS: Type - Type of execution 1472223480Sjkim * Function - Address of the function to execute 1473223480Sjkim * Context - Passed as a parameter to the function 1474193267Sjkim * 1475223480Sjkim * RETURN: Status. 1476193267Sjkim * 1477223480Sjkim * DESCRIPTION: Execute a new thread 1478193267Sjkim * 1479193267Sjkim *****************************************************************************/ 1480193267Sjkim 1481193267SjkimACPI_STATUS 1482223480SjkimAcpiOsExecute ( 1483223480Sjkim ACPI_EXECUTE_TYPE Type, 1484223480Sjkim ACPI_OSD_EXEC_CALLBACK Function, 1485223480Sjkim void *Context) 1486193267Sjkim{ 1487223480Sjkim pthread_t thread; 1488223480Sjkim int ret; 1489193267Sjkim 1490223480Sjkim 1491223480Sjkim ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context); 1492223480Sjkim if (ret) 1493193267Sjkim { 1494223480Sjkim AcpiOsPrintf("Create thread failed"); 1495193267Sjkim } 1496223480Sjkim return (0); 1497223480Sjkim} 1498193267Sjkim 1499281075Sdim#else /* ACPI_SINGLE_THREADED */ 1500281075SdimACPI_THREAD_ID 1501281075SdimAcpiOsGetThreadId ( 1502281075Sdim void) 1503281075Sdim{ 1504281075Sdim return (1); 1505281075Sdim} 1506281075Sdim 1507281075SdimACPI_STATUS 1508281075SdimAcpiOsExecute ( 1509281075Sdim ACPI_EXECUTE_TYPE Type, 1510281075Sdim ACPI_OSD_EXEC_CALLBACK Function, 1511281075Sdim void *Context) 1512281075Sdim{ 1513281075Sdim 1514281075Sdim Function (Context); 1515281075Sdim 1516281075Sdim return (AE_OK); 1517281075Sdim} 1518281075Sdim 1519223480Sjkim#endif /* ACPI_SINGLE_THREADED */ 1520235945Sjkim 1521235945Sjkim 1522235945Sjkim/****************************************************************************** 1523235945Sjkim * 1524235945Sjkim * FUNCTION: AcpiOsWaitEventsComplete 1525235945Sjkim * 1526235945Sjkim * PARAMETERS: None 1527235945Sjkim * 1528235945Sjkim * RETURN: None 1529235945Sjkim * 1530235945Sjkim * DESCRIPTION: Wait for all asynchronous events to complete. This 1531235945Sjkim * implementation does nothing. 1532235945Sjkim * 1533235945Sjkim *****************************************************************************/ 1534235945Sjkim 1535235945Sjkimvoid 1536235945SjkimAcpiOsWaitEventsComplete ( 1537235945Sjkim void) 1538235945Sjkim{ 1539235945Sjkim return; 1540235945Sjkim} 1541