1775afec4SFredrik Holmqvist /****************************************************************************** 2775afec4SFredrik Holmqvist * 3775afec4SFredrik Holmqvist * Module Name: oshaiku - Haiku OSL interfaces 4775afec4SFredrik Holmqvist * 5775afec4SFredrik Holmqvist *****************************************************************************/ 6775afec4SFredrik Holmqvist 7775afec4SFredrik Holmqvist /****************************************************************************** 8775afec4SFredrik Holmqvist * 9775afec4SFredrik Holmqvist * 1. Copyright Notice 10775afec4SFredrik Holmqvist * 11775afec4SFredrik Holmqvist * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 12775afec4SFredrik Holmqvist * All rights reserved. 13775afec4SFredrik Holmqvist * 14775afec4SFredrik Holmqvist * 2. License 15775afec4SFredrik Holmqvist * 16775afec4SFredrik Holmqvist * 2.1. This is your license from Intel Corp. under its intellectual property 17775afec4SFredrik Holmqvist * rights. You may have additional license terms from the party that provided 18775afec4SFredrik Holmqvist * you this software, covering your right to use that party's intellectual 19775afec4SFredrik Holmqvist * property rights. 20775afec4SFredrik Holmqvist * 21775afec4SFredrik Holmqvist * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22775afec4SFredrik Holmqvist * copy of the source code appearing in this file ("Covered Code") an 23775afec4SFredrik Holmqvist * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24775afec4SFredrik Holmqvist * base code distributed originally by Intel ("Original Intel Code") to copy, 25775afec4SFredrik Holmqvist * make derivatives, distribute, use and display any portion of the Covered 26775afec4SFredrik Holmqvist * Code in any form, with the right to sublicense such rights; and 27775afec4SFredrik Holmqvist * 28775afec4SFredrik Holmqvist * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29775afec4SFredrik Holmqvist * license (with the right to sublicense), under only those claims of Intel 30775afec4SFredrik Holmqvist * patents that are infringed by the Original Intel Code, to make, use, sell, 31775afec4SFredrik Holmqvist * offer to sell, and import the Covered Code and derivative works thereof 32775afec4SFredrik Holmqvist * solely to the minimum extent necessary to exercise the above copyright 33775afec4SFredrik Holmqvist * license, and in no event shall the patent license extend to any additions 34775afec4SFredrik Holmqvist * to or modifications of the Original Intel Code. No other license or right 35775afec4SFredrik Holmqvist * is granted directly or by implication, estoppel or otherwise; 36775afec4SFredrik Holmqvist * 37775afec4SFredrik Holmqvist * The above copyright and patent license is granted only if the following 38775afec4SFredrik Holmqvist * conditions are met: 39775afec4SFredrik Holmqvist * 40775afec4SFredrik Holmqvist * 3. Conditions 41775afec4SFredrik Holmqvist * 42775afec4SFredrik Holmqvist * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43775afec4SFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered 44775afec4SFredrik Holmqvist * Code or modification with rights to further distribute source must include 45775afec4SFredrik Holmqvist * the above Copyright Notice, the above License, this list of Conditions, 46775afec4SFredrik Holmqvist * and the following Disclaimer and Export Compliance provision. In addition, 47775afec4SFredrik Holmqvist * Licensee must cause all Covered Code to which Licensee contributes to 48775afec4SFredrik Holmqvist * contain a file documenting the changes Licensee made to create that Covered 49775afec4SFredrik Holmqvist * Code and the date of any change. Licensee must include in that file the 50775afec4SFredrik Holmqvist * documentation of any changes made by any predecessor Licensee. Licensee 51775afec4SFredrik Holmqvist * must include a prominent statement that the modification is derived, 52775afec4SFredrik Holmqvist * directly or indirectly, from Original Intel Code. 53775afec4SFredrik Holmqvist * 54775afec4SFredrik Holmqvist * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55775afec4SFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered 56775afec4SFredrik Holmqvist * Code or modification without rights to further distribute source must 57775afec4SFredrik Holmqvist * include the following Disclaimer and Export Compliance provision in the 58775afec4SFredrik Holmqvist * documentation and/or other materials provided with distribution. In 59775afec4SFredrik Holmqvist * addition, Licensee may not authorize further sublicense of source of any 60775afec4SFredrik Holmqvist * portion of the Covered Code, and must include terms to the effect that the 61775afec4SFredrik Holmqvist * license from Licensee to its licensee is limited to the intellectual 62775afec4SFredrik Holmqvist * property embodied in the software Licensee provides to its licensee, and 63775afec4SFredrik Holmqvist * not to intellectual property embodied in modifications its licensee may 64775afec4SFredrik Holmqvist * make. 65775afec4SFredrik Holmqvist * 66775afec4SFredrik Holmqvist * 3.3. Redistribution of Executable. Redistribution in executable form of any 67775afec4SFredrik Holmqvist * substantial portion of the Covered Code or modification must reproduce the 68775afec4SFredrik Holmqvist * above Copyright Notice, and the following Disclaimer and Export Compliance 69775afec4SFredrik Holmqvist * provision in the documentation and/or other materials provided with the 70775afec4SFredrik Holmqvist * distribution. 71775afec4SFredrik Holmqvist * 72775afec4SFredrik Holmqvist * 3.4. Intel retains all right, title, and interest in and to the Original 73775afec4SFredrik Holmqvist * Intel Code. 74775afec4SFredrik Holmqvist * 75775afec4SFredrik Holmqvist * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76775afec4SFredrik Holmqvist * Intel shall be used in advertising or otherwise to promote the sale, use or 77775afec4SFredrik Holmqvist * other dealings in products derived from or relating to the Covered Code 78775afec4SFredrik Holmqvist * without prior written authorization from Intel. 79775afec4SFredrik Holmqvist * 80775afec4SFredrik Holmqvist * 4. Disclaimer and Export Compliance 81775afec4SFredrik Holmqvist * 82775afec4SFredrik Holmqvist * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83775afec4SFredrik Holmqvist * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84775afec4SFredrik Holmqvist * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85775afec4SFredrik Holmqvist * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86775afec4SFredrik Holmqvist * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87775afec4SFredrik Holmqvist * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88775afec4SFredrik Holmqvist * PARTICULAR PURPOSE. 89775afec4SFredrik Holmqvist * 90775afec4SFredrik Holmqvist * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91775afec4SFredrik Holmqvist * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92775afec4SFredrik Holmqvist * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93775afec4SFredrik Holmqvist * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94775afec4SFredrik Holmqvist * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95775afec4SFredrik Holmqvist * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96775afec4SFredrik Holmqvist * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97775afec4SFredrik Holmqvist * LIMITED REMEDY. 98775afec4SFredrik Holmqvist * 99775afec4SFredrik Holmqvist * 4.3. Licensee shall not export, either directly or indirectly, any of this 100775afec4SFredrik Holmqvist * software or system incorporating such software without first obtaining any 101775afec4SFredrik Holmqvist * required license or other approval from the U. S. Department of Commerce or 102775afec4SFredrik Holmqvist * any other agency or department of the United States Government. In the 103775afec4SFredrik Holmqvist * event Licensee exports any such software from the United States or 104775afec4SFredrik Holmqvist * re-exports any such software from a foreign destination, Licensee shall 105775afec4SFredrik Holmqvist * ensure that the distribution and export/re-export of the software is in 106775afec4SFredrik Holmqvist * compliance with all laws, regulations, orders, or other restrictions of the 107775afec4SFredrik Holmqvist * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108775afec4SFredrik Holmqvist * any of its subsidiaries will export/re-export any technical data, process, 109775afec4SFredrik Holmqvist * software, or service, directly or indirectly, to any country for which the 110775afec4SFredrik Holmqvist * United States government or any agency thereof requires an export license, 111775afec4SFredrik Holmqvist * other governmental approval, or letter of assurance, without first obtaining 112775afec4SFredrik Holmqvist * such license, approval or letter. 113775afec4SFredrik Holmqvist * 114775afec4SFredrik Holmqvist *****************************************************************************/ 115775afec4SFredrik Holmqvist 116775afec4SFredrik Holmqvist 117775afec4SFredrik Holmqvist #include <stdio.h> 118775afec4SFredrik Holmqvist #include <sys/cdefs.h> 119775afec4SFredrik Holmqvist #include <time.h> 120775afec4SFredrik Holmqvist #include <unistd.h> 121775afec4SFredrik Holmqvist 122775afec4SFredrik Holmqvist #include <OS.h> 123775afec4SFredrik Holmqvist 124775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 125775afec4SFredrik Holmqvist # include <KernelExport.h> 126775afec4SFredrik Holmqvist 127775afec4SFredrik Holmqvist # include <dpc.h> 128775afec4SFredrik Holmqvist # include <PCI.h> 129775afec4SFredrik Holmqvist 1306e6efaecSJessica Hamilton # include <boot_item.h> 131775afec4SFredrik Holmqvist # include <kernel.h> 132775afec4SFredrik Holmqvist # include <vm/vm.h> 133775afec4SFredrik Holmqvist #endif 134775afec4SFredrik Holmqvist 135775afec4SFredrik Holmqvist __BEGIN_DECLS 136775afec4SFredrik Holmqvist #include "acpi.h" 137775afec4SFredrik Holmqvist #include "accommon.h" 138775afec4SFredrik Holmqvist #include "amlcode.h" 139775afec4SFredrik Holmqvist #include "acparser.h" 140775afec4SFredrik Holmqvist #include "acdebug.h" 141775afec4SFredrik Holmqvist __END_DECLS 142775afec4SFredrik Holmqvist 143775afec4SFredrik Holmqvist 144775afec4SFredrik Holmqvist ACPI_MODULE_NAME("Haiku ACPI Module") 145775afec4SFredrik Holmqvist 146775afec4SFredrik Holmqvist #define _COMPONENT ACPI_OS_SERVICES 147775afec4SFredrik Holmqvist 148775afec4SFredrik Holmqvist // verbosity level 0 = off, 1 = normal, 2 = all 149775afec4SFredrik Holmqvist #define DEBUG_OSHAIKU 0 150775afec4SFredrik Holmqvist 151775afec4SFredrik Holmqvist #if DEBUG_OSHAIKU <= 0 152775afec4SFredrik Holmqvist // No debugging, do nothing 153775afec4SFredrik Holmqvist # define DEBUG_FUNCTION() 154775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_F(x, y...) 155775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_V() 156775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_VF(x, y...) 157775afec4SFredrik Holmqvist #else 158775afec4SFredrik Holmqvist # define DEBUG_FUNCTION() \ 159775afec4SFredrik Holmqvist dprintf("acpi[%ld]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__); 160775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_F(x, y...) \ 161775afec4SFredrik Holmqvist dprintf("acpi[%ld]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y); 162775afec4SFredrik Holmqvist # if DEBUG_OSHAIKU == 1 163775afec4SFredrik Holmqvist // No verbose debugging, do nothing 164775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_V() 165775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_VF(x, y...) 166775afec4SFredrik Holmqvist # else 167775afec4SFredrik Holmqvist // Full debugging 168775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_V() \ 169775afec4SFredrik Holmqvist dprintf("acpi[%ld]: %s\n", find_thread(NULL), __PRETTY_FUNCTION__); 170775afec4SFredrik Holmqvist # define DEBUG_FUNCTION_VF(x, y...) \ 171775afec4SFredrik Holmqvist dprintf("acpi[%ld]: %s(" x ")\n", find_thread(NULL), __PRETTY_FUNCTION__, y); 172775afec4SFredrik Holmqvist # endif 173775afec4SFredrik Holmqvist #endif 174775afec4SFredrik Holmqvist 175775afec4SFredrik Holmqvist 176775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 177775afec4SFredrik Holmqvist extern pci_module_info *gPCIManager; 178775afec4SFredrik Holmqvist extern dpc_module_info *gDPC; 179775afec4SFredrik Holmqvist extern void *gDPCHandle; 180775afec4SFredrik Holmqvist #endif 181775afec4SFredrik Holmqvist 182775afec4SFredrik Holmqvist extern FILE *AcpiGbl_DebugFile; 183775afec4SFredrik Holmqvist FILE *AcpiGbl_OutputFile; 184775afec4SFredrik Holmqvist 1856e6efaecSJessica Hamilton static ACPI_PHYSICAL_ADDRESS sACPIRoot = 0; 186775afec4SFredrik Holmqvist static void *sInterruptHandlerData[32]; 187775afec4SFredrik Holmqvist 188775afec4SFredrik Holmqvist 189775afec4SFredrik Holmqvist /****************************************************************************** 190775afec4SFredrik Holmqvist * 191775afec4SFredrik Holmqvist * FUNCTION: AcpiOsInitialize, AcpiOsTerminate 192775afec4SFredrik Holmqvist * 193775afec4SFredrik Holmqvist * PARAMETERS: None 194775afec4SFredrik Holmqvist * 195775afec4SFredrik Holmqvist * RETURN: Status 196775afec4SFredrik Holmqvist * 197775afec4SFredrik Holmqvist * DESCRIPTION: Init and terminate. Nothing to do. 198775afec4SFredrik Holmqvist * 199775afec4SFredrik Holmqvist *****************************************************************************/ 200775afec4SFredrik Holmqvist ACPI_STATUS 201775afec4SFredrik Holmqvist AcpiOsInitialize() 202775afec4SFredrik Holmqvist { 203775afec4SFredrik Holmqvist #ifndef _KERNEL_MODE 204775afec4SFredrik Holmqvist AcpiGbl_OutputFile = stdout; 205775afec4SFredrik Holmqvist #else 206775afec4SFredrik Holmqvist AcpiGbl_OutputFile = NULL; 207775afec4SFredrik Holmqvist #endif 208775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 209775afec4SFredrik Holmqvist return AE_OK; 210775afec4SFredrik Holmqvist } 211775afec4SFredrik Holmqvist 212775afec4SFredrik Holmqvist 213775afec4SFredrik Holmqvist ACPI_STATUS 214775afec4SFredrik Holmqvist AcpiOsTerminate() 215775afec4SFredrik Holmqvist { 216775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 217775afec4SFredrik Holmqvist return AE_OK; 218775afec4SFredrik Holmqvist } 219775afec4SFredrik Holmqvist 220775afec4SFredrik Holmqvist 221775afec4SFredrik Holmqvist /****************************************************************************** 222775afec4SFredrik Holmqvist * 223775afec4SFredrik Holmqvist * FUNCTION: AcpiOsGetRootPointer 224775afec4SFredrik Holmqvist * 225775afec4SFredrik Holmqvist * PARAMETERS: None 226775afec4SFredrik Holmqvist * 227775afec4SFredrik Holmqvist * RETURN: RSDP physical address 228775afec4SFredrik Holmqvist * 229775afec4SFredrik Holmqvist * DESCRIPTION: Gets the root pointer (RSDP) 230775afec4SFredrik Holmqvist * 231775afec4SFredrik Holmqvist *****************************************************************************/ 232775afec4SFredrik Holmqvist ACPI_PHYSICAL_ADDRESS 233775afec4SFredrik Holmqvist AcpiOsGetRootPointer() 234775afec4SFredrik Holmqvist { 235775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 23665ecbac0SFredrik Holmqvist ACPI_PHYSICAL_ADDRESS address; 2376e6efaecSJessica Hamilton ACPI_STATUS status = AE_OK; 238775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 239775afec4SFredrik Holmqvist if (sACPIRoot == 0) { 2406e6efaecSJessica Hamilton sACPIRoot = (ACPI_PHYSICAL_ADDRESS)get_boot_item("ACPI_ROOT_POINTER", NULL); 2416e6efaecSJessica Hamilton if (sACPIRoot == 0) { 242775afec4SFredrik Holmqvist status = AcpiFindRootPointer(&address); 243775afec4SFredrik Holmqvist if (status == AE_OK) 244775afec4SFredrik Holmqvist sACPIRoot = address; 245775afec4SFredrik Holmqvist } 2466e6efaecSJessica Hamilton } 247775afec4SFredrik Holmqvist return sACPIRoot; 248775afec4SFredrik Holmqvist #else 249775afec4SFredrik Holmqvist return AeLocalGetRootPointer(); 250775afec4SFredrik Holmqvist #endif 251775afec4SFredrik Holmqvist } 252775afec4SFredrik Holmqvist 253775afec4SFredrik Holmqvist 254775afec4SFredrik Holmqvist /****************************************************************************** 255775afec4SFredrik Holmqvist * 256775afec4SFredrik Holmqvist * FUNCTION: AcpiOsPredefinedOverride 257775afec4SFredrik Holmqvist * 258775afec4SFredrik Holmqvist * PARAMETERS: initVal - Initial value of the predefined object 259775afec4SFredrik Holmqvist * newVal - The new value for the object 260775afec4SFredrik Holmqvist * 261775afec4SFredrik Holmqvist * RETURN: Status, pointer to value. Null pointer returned if not 262775afec4SFredrik Holmqvist * overriding. 263775afec4SFredrik Holmqvist * 264775afec4SFredrik Holmqvist * DESCRIPTION: Allow the OS to override predefined names 265775afec4SFredrik Holmqvist * 266775afec4SFredrik Holmqvist *****************************************************************************/ 267775afec4SFredrik Holmqvist ACPI_STATUS 268775afec4SFredrik Holmqvist AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *initVal, 269775afec4SFredrik Holmqvist ACPI_STRING *newVal) 270775afec4SFredrik Holmqvist { 271775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 272775afec4SFredrik Holmqvist if (!initVal || !newVal) 273775afec4SFredrik Holmqvist return AE_BAD_PARAMETER; 274775afec4SFredrik Holmqvist 275775afec4SFredrik Holmqvist *newVal = NULL; 276775afec4SFredrik Holmqvist return AE_OK; 277775afec4SFredrik Holmqvist } 278775afec4SFredrik Holmqvist 279775afec4SFredrik Holmqvist 280775afec4SFredrik Holmqvist /****************************************************************************** 281775afec4SFredrik Holmqvist * 282775afec4SFredrik Holmqvist * FUNCTION: AcpiOsTableOverride 283775afec4SFredrik Holmqvist * 284775afec4SFredrik Holmqvist * PARAMETERS: existingTable - Header of current table (probably firmware) 285775afec4SFredrik Holmqvist * newTable - Where an entire new table is returned. 286775afec4SFredrik Holmqvist * 287775afec4SFredrik Holmqvist * RETURN: Status, pointer to new table. Null pointer returned if no 288775afec4SFredrik Holmqvist * table is available to override 289775afec4SFredrik Holmqvist * 290775afec4SFredrik Holmqvist * DESCRIPTION: Return a different version of a table if one is available 291775afec4SFredrik Holmqvist * 292775afec4SFredrik Holmqvist *****************************************************************************/ 293775afec4SFredrik Holmqvist ACPI_STATUS 294775afec4SFredrik Holmqvist AcpiOsTableOverride(ACPI_TABLE_HEADER *existingTable, 295775afec4SFredrik Holmqvist ACPI_TABLE_HEADER **newTable) 296775afec4SFredrik Holmqvist { 297775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 298775afec4SFredrik Holmqvist if (!existingTable || !newTable) 299775afec4SFredrik Holmqvist return AE_BAD_PARAMETER; 300775afec4SFredrik Holmqvist 301775afec4SFredrik Holmqvist *newTable = NULL; 302775afec4SFredrik Holmqvist 303775afec4SFredrik Holmqvist #ifdef ACPI_EXEC_APP 304775afec4SFredrik Holmqvist AeTableOverride(existingTable, newTable); 305775afec4SFredrik Holmqvist return AE_OK; 306775afec4SFredrik Holmqvist #else 307775afec4SFredrik Holmqvist return AE_NO_ACPI_TABLES; 308775afec4SFredrik Holmqvist #endif 309775afec4SFredrik Holmqvist } 310775afec4SFredrik Holmqvist 311775afec4SFredrik Holmqvist 312775afec4SFredrik Holmqvist /****************************************************************************** 313775afec4SFredrik Holmqvist * 314775afec4SFredrik Holmqvist * FUNCTION: AcpiOsPhysicalTableOverride 315775afec4SFredrik Holmqvist * 316775afec4SFredrik Holmqvist * PARAMETERS: existingTable - Header of current table (probably firmware) 317775afec4SFredrik Holmqvist * newAddress - Where new table address is returned 318775afec4SFredrik Holmqvist * (Physical address) 319775afec4SFredrik Holmqvist * newTableLength - Where new table length is returned 320775afec4SFredrik Holmqvist * 321775afec4SFredrik Holmqvist * RETURN: Status, address/length of new table. Null pointer returned 322775afec4SFredrik Holmqvist * if no table is available to override. 323775afec4SFredrik Holmqvist * 324775afec4SFredrik Holmqvist * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. 325775afec4SFredrik Holmqvist * 326775afec4SFredrik Holmqvist *****************************************************************************/ 327775afec4SFredrik Holmqvist 328775afec4SFredrik Holmqvist ACPI_STATUS 329775afec4SFredrik Holmqvist AcpiOsPhysicalTableOverride(ACPI_TABLE_HEADER *existingTable, 330775afec4SFredrik Holmqvist ACPI_PHYSICAL_ADDRESS *newAddress, UINT32 *newTableLength) 331775afec4SFredrik Holmqvist { 332775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 333775afec4SFredrik Holmqvist return (AE_SUPPORT); 334775afec4SFredrik Holmqvist } 335775afec4SFredrik Holmqvist 336775afec4SFredrik Holmqvist 337775afec4SFredrik Holmqvist /****************************************************************************** 338775afec4SFredrik Holmqvist * 339775afec4SFredrik Holmqvist * FUNCTION: AcpiOsRedirectOutput 340775afec4SFredrik Holmqvist * 341775afec4SFredrik Holmqvist * PARAMETERS: destination - An open file handle/pointer 342775afec4SFredrik Holmqvist * 343775afec4SFredrik Holmqvist * RETURN: None 344775afec4SFredrik Holmqvist * 345775afec4SFredrik Holmqvist * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf 346775afec4SFredrik Holmqvist * 347775afec4SFredrik Holmqvist *****************************************************************************/ 348775afec4SFredrik Holmqvist void 349775afec4SFredrik Holmqvist AcpiOsRedirectOutput(void *destination) 350775afec4SFredrik Holmqvist { 351775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 352775afec4SFredrik Holmqvist AcpiGbl_OutputFile = (FILE*)destination; 353775afec4SFredrik Holmqvist } 354775afec4SFredrik Holmqvist 355775afec4SFredrik Holmqvist 356775afec4SFredrik Holmqvist /****************************************************************************** 357775afec4SFredrik Holmqvist * 358775afec4SFredrik Holmqvist * FUNCTION: AcpiOsPrintf 359775afec4SFredrik Holmqvist * 360775afec4SFredrik Holmqvist * PARAMETERS: fmt, ... Standard printf format 361775afec4SFredrik Holmqvist * 362775afec4SFredrik Holmqvist * RETURN: None 363775afec4SFredrik Holmqvist * 364775afec4SFredrik Holmqvist * DESCRIPTION: Formatted output 365775afec4SFredrik Holmqvist * 366775afec4SFredrik Holmqvist *****************************************************************************/ 367775afec4SFredrik Holmqvist void ACPI_INTERNAL_VAR_XFACE 368775afec4SFredrik Holmqvist AcpiOsPrintf(const char *fmt, ...) 369775afec4SFredrik Holmqvist { 370775afec4SFredrik Holmqvist va_list args; 371775afec4SFredrik Holmqvist 372775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 373775afec4SFredrik Holmqvist va_start(args, fmt); 374775afec4SFredrik Holmqvist AcpiOsVprintf(fmt, args); 375775afec4SFredrik Holmqvist va_end(args); 376775afec4SFredrik Holmqvist } 377775afec4SFredrik Holmqvist 378775afec4SFredrik Holmqvist 379775afec4SFredrik Holmqvist /****************************************************************************** 380775afec4SFredrik Holmqvist * 381775afec4SFredrik Holmqvist * FUNCTION: AcpiOsVprintf 382775afec4SFredrik Holmqvist * 383775afec4SFredrik Holmqvist * PARAMETERS: fmt Standard printf format 384775afec4SFredrik Holmqvist * args Argument list 385775afec4SFredrik Holmqvist * 386775afec4SFredrik Holmqvist * RETURN: None 387775afec4SFredrik Holmqvist * 388775afec4SFredrik Holmqvist * DESCRIPTION: Formatted output with argument list pointer 389775afec4SFredrik Holmqvist * 390775afec4SFredrik Holmqvist *****************************************************************************/ 391775afec4SFredrik Holmqvist void 392775afec4SFredrik Holmqvist AcpiOsVprintf(const char *fmt, va_list args) 393775afec4SFredrik Holmqvist { 394775afec4SFredrik Holmqvist #ifndef _KERNEL_MODE 395775afec4SFredrik Holmqvist UINT8 flags; 396775afec4SFredrik Holmqvist 397775afec4SFredrik Holmqvist flags = AcpiGbl_DbOutputFlags; 398775afec4SFredrik Holmqvist if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) { 399775afec4SFredrik Holmqvist // Output is directable to either a file (if open) or the console 400775afec4SFredrik Holmqvist if (AcpiGbl_DebugFile) { 401775afec4SFredrik Holmqvist // Output file is open, send the output there 402775afec4SFredrik Holmqvist vfprintf(AcpiGbl_DebugFile, fmt, args); 403775afec4SFredrik Holmqvist } else { 404775afec4SFredrik Holmqvist // No redirection, send output to console (once only!) 405775afec4SFredrik Holmqvist flags |= ACPI_DB_CONSOLE_OUTPUT; 406775afec4SFredrik Holmqvist } 407775afec4SFredrik Holmqvist } 408775afec4SFredrik Holmqvist 409775afec4SFredrik Holmqvist if (flags & ACPI_DB_CONSOLE_OUTPUT) { 410775afec4SFredrik Holmqvist vfprintf(AcpiGbl_OutputFile, fmt, args); 411775afec4SFredrik Holmqvist } 412775afec4SFredrik Holmqvist #else 413775afec4SFredrik Holmqvist static char outputBuffer[1024]; 414775afec4SFredrik Holmqvist vsnprintf(outputBuffer, 1024, fmt, args); 415775afec4SFredrik Holmqvist dprintf("%s", outputBuffer); 416775afec4SFredrik Holmqvist #endif 417775afec4SFredrik Holmqvist } 418775afec4SFredrik Holmqvist 419775afec4SFredrik Holmqvist 420775afec4SFredrik Holmqvist /****************************************************************************** 421775afec4SFredrik Holmqvist * 422775afec4SFredrik Holmqvist * FUNCTION: AcpiOsGetLine 423775afec4SFredrik Holmqvist * 424775afec4SFredrik Holmqvist * PARAMETERS: fmt Standard printf format 425775afec4SFredrik Holmqvist * args Argument list 426775afec4SFredrik Holmqvist * 427775afec4SFredrik Holmqvist * RETURN: Actual bytes read 428775afec4SFredrik Holmqvist * 429775afec4SFredrik Holmqvist * DESCRIPTION: Formatted input with argument list pointer 430775afec4SFredrik Holmqvist * 431775afec4SFredrik Holmqvist *****************************************************************************/ 432775afec4SFredrik Holmqvist UINT32 433775afec4SFredrik Holmqvist AcpiOsGetLine(char *buffer) 434775afec4SFredrik Holmqvist { 435775afec4SFredrik Holmqvist uint32 i = 0; 436775afec4SFredrik Holmqvist 437775afec4SFredrik Holmqvist #ifndef _KERNEL_MODE 438775afec4SFredrik Holmqvist uint8 temp; 439775afec4SFredrik Holmqvist 440775afec4SFredrik Holmqvist for (i = 0; ; i++) { 441775afec4SFredrik Holmqvist scanf("%1c", &temp); 442775afec4SFredrik Holmqvist if (!temp || temp == '\n') 443775afec4SFredrik Holmqvist break; 444775afec4SFredrik Holmqvist 445775afec4SFredrik Holmqvist buffer[i] = temp; 446775afec4SFredrik Holmqvist } 447775afec4SFredrik Holmqvist #endif 448775afec4SFredrik Holmqvist 449775afec4SFredrik Holmqvist buffer[i] = 0; 450775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("buffer: \"%s\"; result: %lu", buffer, i); 451775afec4SFredrik Holmqvist return i; 452775afec4SFredrik Holmqvist } 453775afec4SFredrik Holmqvist 454775afec4SFredrik Holmqvist 455775afec4SFredrik Holmqvist /****************************************************************************** 456775afec4SFredrik Holmqvist * 457775afec4SFredrik Holmqvist * FUNCTION: AcpiOsMapMemory 458775afec4SFredrik Holmqvist * 459775afec4SFredrik Holmqvist * PARAMETERS: where Physical address of memory to be mapped 460775afec4SFredrik Holmqvist * length How much memory to map 461775afec4SFredrik Holmqvist * 462775afec4SFredrik Holmqvist * RETURN: Pointer to mapped memory. Null on error. 463775afec4SFredrik Holmqvist * 464775afec4SFredrik Holmqvist * DESCRIPTION: Map physical memory into caller's address space 465775afec4SFredrik Holmqvist * 466775afec4SFredrik Holmqvist *****************************************************************************/ 467775afec4SFredrik Holmqvist void * 468775afec4SFredrik Holmqvist AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS where, ACPI_SIZE length) 469775afec4SFredrik Holmqvist { 470775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 471775afec4SFredrik Holmqvist void *there; 472775afec4SFredrik Holmqvist area_id area = map_physical_memory("acpi_physical_mem_area", where, length, 473775afec4SFredrik Holmqvist B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, &there); 474775afec4SFredrik Holmqvist 475775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("addr: 0x%08lx; length: %lu; mapped: %p; area: %ld", 476775afec4SFredrik Holmqvist (addr_t)where, (size_t)length, there, area); 477775afec4SFredrik Holmqvist if (area < 0) { 478*584a3968SFredrik Holmqvist dprintf("ACPI: cannot map memory at 0x%" B_PRIu64 ", length %" 479*584a3968SFredrik Holmqvist B_PRIu64 "\n", (uint64)where, (uint64)length); 480775afec4SFredrik Holmqvist return NULL; 481775afec4SFredrik Holmqvist } 482775afec4SFredrik Holmqvist return there; 483775afec4SFredrik Holmqvist #else 484775afec4SFredrik Holmqvist return NULL; 485775afec4SFredrik Holmqvist #endif 486775afec4SFredrik Holmqvist 487775afec4SFredrik Holmqvist // return ACPI_TO_POINTER((ACPI_SIZE) where); 488775afec4SFredrik Holmqvist } 489775afec4SFredrik Holmqvist 490775afec4SFredrik Holmqvist 491775afec4SFredrik Holmqvist /****************************************************************************** 492775afec4SFredrik Holmqvist * 493775afec4SFredrik Holmqvist * FUNCTION: AcpiOsUnmapMemory 494775afec4SFredrik Holmqvist * 495775afec4SFredrik Holmqvist * PARAMETERS: where Logical address of memory to be unmapped 496775afec4SFredrik Holmqvist * length How much memory to unmap 497775afec4SFredrik Holmqvist * 498775afec4SFredrik Holmqvist * RETURN: None. 499775afec4SFredrik Holmqvist * 500775afec4SFredrik Holmqvist * DESCRIPTION: Delete a previously created mapping. Where and Length must 501775afec4SFredrik Holmqvist * correspond to a previous mapping exactly. 502775afec4SFredrik Holmqvist * 503775afec4SFredrik Holmqvist *****************************************************************************/ 504775afec4SFredrik Holmqvist void 505775afec4SFredrik Holmqvist AcpiOsUnmapMemory(void *where, ACPI_SIZE length) 506775afec4SFredrik Holmqvist { 507775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("mapped: %p; length: %lu", where, (size_t)length); 508775afec4SFredrik Holmqvist delete_area(area_for(where)); 509775afec4SFredrik Holmqvist } 510775afec4SFredrik Holmqvist 511775afec4SFredrik Holmqvist 512775afec4SFredrik Holmqvist /****************************************************************************** 513775afec4SFredrik Holmqvist * 514775afec4SFredrik Holmqvist * FUNCTION: AcpiOsAllocate 515775afec4SFredrik Holmqvist * 516775afec4SFredrik Holmqvist * PARAMETERS: size Amount to allocate, in bytes 517775afec4SFredrik Holmqvist * 518775afec4SFredrik Holmqvist * RETURN: Pointer to the new allocation. Null on error. 519775afec4SFredrik Holmqvist * 520775afec4SFredrik Holmqvist * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. 521775afec4SFredrik Holmqvist * 522775afec4SFredrik Holmqvist *****************************************************************************/ 523775afec4SFredrik Holmqvist void * 524775afec4SFredrik Holmqvist AcpiOsAllocate(ACPI_SIZE size) 525775afec4SFredrik Holmqvist { 526775afec4SFredrik Holmqvist void *mem = (void *) malloc(size); 527775afec4SFredrik Holmqvist DEBUG_FUNCTION_VF("result: %p", mem); 528775afec4SFredrik Holmqvist return mem; 529775afec4SFredrik Holmqvist } 530775afec4SFredrik Holmqvist 531775afec4SFredrik Holmqvist 532775afec4SFredrik Holmqvist /****************************************************************************** 533775afec4SFredrik Holmqvist * 534775afec4SFredrik Holmqvist * FUNCTION: AcpiOsFree 535775afec4SFredrik Holmqvist * 536775afec4SFredrik Holmqvist * PARAMETERS: mem Pointer to previously allocated memory 537775afec4SFredrik Holmqvist * 538775afec4SFredrik Holmqvist * RETURN: None. 539775afec4SFredrik Holmqvist * 540775afec4SFredrik Holmqvist * DESCRIPTION: Free memory allocated via AcpiOsAllocate 541775afec4SFredrik Holmqvist * 542775afec4SFredrik Holmqvist *****************************************************************************/ 543775afec4SFredrik Holmqvist void 544775afec4SFredrik Holmqvist AcpiOsFree(void *mem) 545775afec4SFredrik Holmqvist { 546775afec4SFredrik Holmqvist DEBUG_FUNCTION_VF("mem: %p", mem); 547775afec4SFredrik Holmqvist free(mem); 548775afec4SFredrik Holmqvist } 549775afec4SFredrik Holmqvist 550775afec4SFredrik Holmqvist 551775afec4SFredrik Holmqvist /****************************************************************************** 552775afec4SFredrik Holmqvist * 553775afec4SFredrik Holmqvist * FUNCTION: AcpiOsCreateSemaphore 554775afec4SFredrik Holmqvist * 555775afec4SFredrik Holmqvist * PARAMETERS: initialUnits - Units to be assigned to the new semaphore 556775afec4SFredrik Holmqvist * outHandle - Where a handle will be returned 557775afec4SFredrik Holmqvist * 558775afec4SFredrik Holmqvist * RETURN: Status 559775afec4SFredrik Holmqvist * 560775afec4SFredrik Holmqvist * DESCRIPTION: Create an OS semaphore 561775afec4SFredrik Holmqvist * 562775afec4SFredrik Holmqvist *****************************************************************************/ 563775afec4SFredrik Holmqvist ACPI_STATUS 564775afec4SFredrik Holmqvist AcpiOsCreateSemaphore(UINT32 maxUnits, UINT32 initialUnits, 565775afec4SFredrik Holmqvist ACPI_SEMAPHORE *outHandle) 566775afec4SFredrik Holmqvist { 567775afec4SFredrik Holmqvist if (!outHandle) 568775afec4SFredrik Holmqvist return AE_BAD_PARAMETER; 569775afec4SFredrik Holmqvist 570775afec4SFredrik Holmqvist *outHandle = create_sem(initialUnits, "acpi_sem"); 571775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("max: %lu; count: %lu; result: %ld", 572775afec4SFredrik Holmqvist maxUnits, initialUnits, *outHandle); 573775afec4SFredrik Holmqvist 574775afec4SFredrik Holmqvist if (*outHandle >= B_OK) 575775afec4SFredrik Holmqvist return AE_OK; 576775afec4SFredrik Holmqvist 577775afec4SFredrik Holmqvist return *outHandle == B_BAD_VALUE ? AE_BAD_PARAMETER : AE_NO_MEMORY; 578775afec4SFredrik Holmqvist } 579775afec4SFredrik Holmqvist 580775afec4SFredrik Holmqvist 581775afec4SFredrik Holmqvist /****************************************************************************** 582775afec4SFredrik Holmqvist * 583775afec4SFredrik Holmqvist * FUNCTION: AcpiOsDeleteSemaphore 584775afec4SFredrik Holmqvist * 585775afec4SFredrik Holmqvist * PARAMETERS: handle - Handle returned by AcpiOsCreateSemaphore 586775afec4SFredrik Holmqvist * 587775afec4SFredrik Holmqvist * RETURN: Status 588775afec4SFredrik Holmqvist * 589775afec4SFredrik Holmqvist * DESCRIPTION: Delete an OS semaphore 590775afec4SFredrik Holmqvist * 591775afec4SFredrik Holmqvist *****************************************************************************/ 592775afec4SFredrik Holmqvist ACPI_STATUS 593775afec4SFredrik Holmqvist AcpiOsDeleteSemaphore(ACPI_SEMAPHORE handle) 594775afec4SFredrik Holmqvist { 595775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("sem: %ld", handle); 596775afec4SFredrik Holmqvist return delete_sem(handle) == B_OK ? AE_OK : AE_BAD_PARAMETER; 597775afec4SFredrik Holmqvist } 598775afec4SFredrik Holmqvist 599775afec4SFredrik Holmqvist 600775afec4SFredrik Holmqvist /****************************************************************************** 601775afec4SFredrik Holmqvist * 602775afec4SFredrik Holmqvist * FUNCTION: AcpiOsWaitSemaphore 603775afec4SFredrik Holmqvist * 604775afec4SFredrik Holmqvist * PARAMETERS: handle - Handle returned by AcpiOsCreateSemaphore 605775afec4SFredrik Holmqvist * units - How many units to wait for 606775afec4SFredrik Holmqvist * timeout - How long to wait 607775afec4SFredrik Holmqvist * 608775afec4SFredrik Holmqvist * RETURN: Status 609775afec4SFredrik Holmqvist * 610775afec4SFredrik Holmqvist * DESCRIPTION: Wait for units 611775afec4SFredrik Holmqvist * 612775afec4SFredrik Holmqvist *****************************************************************************/ 613775afec4SFredrik Holmqvist ACPI_STATUS 614775afec4SFredrik Holmqvist AcpiOsWaitSemaphore(ACPI_SEMAPHORE handle, UINT32 units, UINT16 timeout) 615775afec4SFredrik Holmqvist { 616775afec4SFredrik Holmqvist ACPI_STATUS result = AE_OK; 617775afec4SFredrik Holmqvist DEBUG_FUNCTION_VF("sem: %ld; count: %lu; timeout: %u", 618775afec4SFredrik Holmqvist handle, units, timeout); 619775afec4SFredrik Holmqvist 620775afec4SFredrik Holmqvist if (timeout == ACPI_WAIT_FOREVER) { 621775afec4SFredrik Holmqvist result = acquire_sem_etc(handle, units, 0, 0) 622775afec4SFredrik Holmqvist == B_OK ? AE_OK : AE_BAD_PARAMETER; 623775afec4SFredrik Holmqvist } else { 624775afec4SFredrik Holmqvist switch (acquire_sem_etc(handle, units, B_RELATIVE_TIMEOUT, 625775afec4SFredrik Holmqvist (bigtime_t)timeout * 1000)) { 626775afec4SFredrik Holmqvist case B_OK: 627775afec4SFredrik Holmqvist result = AE_OK; 628775afec4SFredrik Holmqvist break; 629775afec4SFredrik Holmqvist case B_INTERRUPTED: 630775afec4SFredrik Holmqvist case B_TIMED_OUT: 631775afec4SFredrik Holmqvist case B_WOULD_BLOCK: 632775afec4SFredrik Holmqvist result = AE_TIME; 633775afec4SFredrik Holmqvist break; 634775afec4SFredrik Holmqvist case B_BAD_VALUE: 635775afec4SFredrik Holmqvist default: 636775afec4SFredrik Holmqvist result = AE_BAD_PARAMETER; 637775afec4SFredrik Holmqvist break; 638775afec4SFredrik Holmqvist } 639775afec4SFredrik Holmqvist } 640775afec4SFredrik Holmqvist DEBUG_FUNCTION_VF("sem: %ld; count: %lu; timeout: %u result: %lu", 641775afec4SFredrik Holmqvist handle, units, timeout, (uint32)result); 642775afec4SFredrik Holmqvist return result; 643775afec4SFredrik Holmqvist } 644775afec4SFredrik Holmqvist 645775afec4SFredrik Holmqvist 646775afec4SFredrik Holmqvist /****************************************************************************** 647775afec4SFredrik Holmqvist * 648775afec4SFredrik Holmqvist * FUNCTION: AcpiOsSignalSemaphore 649775afec4SFredrik Holmqvist * 650775afec4SFredrik Holmqvist * PARAMETERS: handle - Handle returned by AcpiOsCreateSemaphore 651775afec4SFredrik Holmqvist * units - Number of units to send 652775afec4SFredrik Holmqvist * 653775afec4SFredrik Holmqvist * RETURN: Status 654775afec4SFredrik Holmqvist * 655775afec4SFredrik Holmqvist * DESCRIPTION: Send units 656775afec4SFredrik Holmqvist * 657775afec4SFredrik Holmqvist *****************************************************************************/ 658775afec4SFredrik Holmqvist ACPI_STATUS 659775afec4SFredrik Holmqvist AcpiOsSignalSemaphore(ACPI_SEMAPHORE handle, UINT32 units) 660775afec4SFredrik Holmqvist { 661775afec4SFredrik Holmqvist status_t result; 662775afec4SFredrik Holmqvist DEBUG_FUNCTION_VF("sem: %ld; count: %lu", handle, units); 663775afec4SFredrik Holmqvist // We can be called from interrupt handler, so don't reschedule 664775afec4SFredrik Holmqvist result = release_sem_etc(handle, units, B_DO_NOT_RESCHEDULE); 665775afec4SFredrik Holmqvist return result == B_OK ? AE_OK : AE_BAD_PARAMETER; 666775afec4SFredrik Holmqvist } 667775afec4SFredrik Holmqvist 668775afec4SFredrik Holmqvist 669775afec4SFredrik Holmqvist /****************************************************************************** 670775afec4SFredrik Holmqvist * 671775afec4SFredrik Holmqvist * FUNCTION: Spinlock interfaces 672775afec4SFredrik Holmqvist * 673775afec4SFredrik Holmqvist * DESCRIPTION: Map these interfaces to semaphore interfaces 674775afec4SFredrik Holmqvist * 675775afec4SFredrik Holmqvist *****************************************************************************/ 676775afec4SFredrik Holmqvist ACPI_STATUS 677775afec4SFredrik Holmqvist AcpiOsCreateLock(ACPI_SPINLOCK *outHandle) 678775afec4SFredrik Holmqvist { 679775afec4SFredrik Holmqvist *outHandle = (ACPI_SPINLOCK) malloc(sizeof(spinlock)); 680775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("result: %p", *outHandle); 681775afec4SFredrik Holmqvist if (*outHandle == NULL) 682775afec4SFredrik Holmqvist return AE_NO_MEMORY; 683775afec4SFredrik Holmqvist 6841ee1d0cbSPawel Dziepak B_INITIALIZE_SPINLOCK(*outHandle); 685775afec4SFredrik Holmqvist return AE_OK; 686775afec4SFredrik Holmqvist } 687775afec4SFredrik Holmqvist 688775afec4SFredrik Holmqvist 689775afec4SFredrik Holmqvist void 690775afec4SFredrik Holmqvist AcpiOsDeleteLock(ACPI_SPINLOCK handle) 691775afec4SFredrik Holmqvist { 692775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 693775afec4SFredrik Holmqvist free((void*)handle); 694775afec4SFredrik Holmqvist } 695775afec4SFredrik Holmqvist 696775afec4SFredrik Holmqvist 697775afec4SFredrik Holmqvist ACPI_CPU_FLAGS 698775afec4SFredrik Holmqvist AcpiOsAcquireLock(ACPI_SPINLOCK handle) 699775afec4SFredrik Holmqvist { 700775afec4SFredrik Holmqvist cpu_status cpu; 701775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("spinlock: %p", handle); 702775afec4SFredrik Holmqvist cpu = disable_interrupts(); 703775afec4SFredrik Holmqvist acquire_spinlock(handle); 704775afec4SFredrik Holmqvist return cpu; 705775afec4SFredrik Holmqvist } 706775afec4SFredrik Holmqvist 707775afec4SFredrik Holmqvist 708775afec4SFredrik Holmqvist void 709775afec4SFredrik Holmqvist AcpiOsReleaseLock(ACPI_SPINLOCK handle, ACPI_CPU_FLAGS flags) 710775afec4SFredrik Holmqvist { 711775afec4SFredrik Holmqvist release_spinlock(handle); 712775afec4SFredrik Holmqvist restore_interrupts(flags); 713775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("spinlock: %p", handle); 714775afec4SFredrik Holmqvist } 715775afec4SFredrik Holmqvist 716775afec4SFredrik Holmqvist 717775afec4SFredrik Holmqvist /****************************************************************************** 718775afec4SFredrik Holmqvist * 719775afec4SFredrik Holmqvist * FUNCTION: AcpiOsInstallInterruptHandler 720775afec4SFredrik Holmqvist * 721775afec4SFredrik Holmqvist * PARAMETERS: interruptNumber Level handler should respond to. 722775afec4SFredrik Holmqvist * Isr Address of the ACPI interrupt handler 723775afec4SFredrik Holmqvist * ExceptPtr Where status is returned 724775afec4SFredrik Holmqvist * 725775afec4SFredrik Holmqvist * RETURN: Handle to the newly installed handler. 726775afec4SFredrik Holmqvist * 727775afec4SFredrik Holmqvist * DESCRIPTION: Install an interrupt handler. Used to install the ACPI 728775afec4SFredrik Holmqvist * OS-independent handler. 729775afec4SFredrik Holmqvist * 730775afec4SFredrik Holmqvist *****************************************************************************/ 731775afec4SFredrik Holmqvist UINT32 732775afec4SFredrik Holmqvist AcpiOsInstallInterruptHandler(UINT32 interruptNumber, 733775afec4SFredrik Holmqvist ACPI_OSD_HANDLER serviceRoutine, void *context) 734775afec4SFredrik Holmqvist { 735775afec4SFredrik Holmqvist status_t result; 736775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("vector: %lu; handler: %p context %p", 737775afec4SFredrik Holmqvist interruptNumber, serviceRoutine, context); 738775afec4SFredrik Holmqvist 739775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 740775afec4SFredrik Holmqvist // It so happens that the Haiku and ACPI-CA interrupt handler routines 741775afec4SFredrik Holmqvist // return the same values with the same meanings 742775afec4SFredrik Holmqvist sInterruptHandlerData[interruptNumber] = context; 743775afec4SFredrik Holmqvist result = install_io_interrupt_handler(interruptNumber, 744775afec4SFredrik Holmqvist (interrupt_handler)serviceRoutine, context, 0); 745775afec4SFredrik Holmqvist 746775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("vector: %lu; handler: %p context %p returned %d", 747775afec4SFredrik Holmqvist interruptNumber, serviceRoutine, context, result); 748775afec4SFredrik Holmqvist 749775afec4SFredrik Holmqvist return result == B_OK ? AE_OK : AE_BAD_PARAMETER; 750775afec4SFredrik Holmqvist #else 751775afec4SFredrik Holmqvist return AE_BAD_PARAMETER; 752775afec4SFredrik Holmqvist #endif 753775afec4SFredrik Holmqvist } 754775afec4SFredrik Holmqvist 755775afec4SFredrik Holmqvist 756775afec4SFredrik Holmqvist /****************************************************************************** 757775afec4SFredrik Holmqvist * 758775afec4SFredrik Holmqvist * FUNCTION: AcpiOsRemoveInterruptHandler 759775afec4SFredrik Holmqvist * 760775afec4SFredrik Holmqvist * PARAMETERS: Handle Returned when handler was installed 761775afec4SFredrik Holmqvist * 762775afec4SFredrik Holmqvist * RETURN: Status 763775afec4SFredrik Holmqvist * 764775afec4SFredrik Holmqvist * DESCRIPTION: Uninstalls an interrupt handler. 765775afec4SFredrik Holmqvist * 766775afec4SFredrik Holmqvist *****************************************************************************/ 767775afec4SFredrik Holmqvist ACPI_STATUS 768775afec4SFredrik Holmqvist AcpiOsRemoveInterruptHandler(UINT32 interruptNumber, 769775afec4SFredrik Holmqvist ACPI_OSD_HANDLER serviceRoutine) 770775afec4SFredrik Holmqvist { 771775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("vector: %lu; handler: %p", interruptNumber, 772775afec4SFredrik Holmqvist serviceRoutine); 773775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 774775afec4SFredrik Holmqvist remove_io_interrupt_handler(interruptNumber, 775775afec4SFredrik Holmqvist (interrupt_handler) serviceRoutine, 776775afec4SFredrik Holmqvist sInterruptHandlerData[interruptNumber]); 777775afec4SFredrik Holmqvist return AE_OK; 778775afec4SFredrik Holmqvist #else 779775afec4SFredrik Holmqvist return AE_ERROR; 780775afec4SFredrik Holmqvist #endif 781775afec4SFredrik Holmqvist } 782775afec4SFredrik Holmqvist 783775afec4SFredrik Holmqvist 784775afec4SFredrik Holmqvist /****************************************************************************** 785775afec4SFredrik Holmqvist * 786775afec4SFredrik Holmqvist * FUNCTION: AcpiOsExecute 787775afec4SFredrik Holmqvist * 788775afec4SFredrik Holmqvist * PARAMETERS: type - Type of execution 789775afec4SFredrik Holmqvist * function - Address of the function to execute 790775afec4SFredrik Holmqvist * context - Passed as a parameter to the function 791775afec4SFredrik Holmqvist * 792775afec4SFredrik Holmqvist * RETURN: Status. 793775afec4SFredrik Holmqvist * 794775afec4SFredrik Holmqvist * DESCRIPTION: Execute a new thread 795775afec4SFredrik Holmqvist * 796775afec4SFredrik Holmqvist *****************************************************************************/ 797775afec4SFredrik Holmqvist ACPI_STATUS 798775afec4SFredrik Holmqvist AcpiOsExecute(ACPI_EXECUTE_TYPE type, ACPI_OSD_EXEC_CALLBACK function, 799775afec4SFredrik Holmqvist void *context) 800775afec4SFredrik Holmqvist { 801775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 802775afec4SFredrik Holmqvist /* TODO: Prioritize urgent? 803775afec4SFredrik Holmqvist switch (type) { 804775afec4SFredrik Holmqvist case OSL_GLOBAL_LOCK_HANDLER: 805775afec4SFredrik Holmqvist case OSL_NOTIFY_HANDLER: 806775afec4SFredrik Holmqvist case OSL_GPE_HANDLER: 807775afec4SFredrik Holmqvist case OSL_DEBUGGER_THREAD: 808775afec4SFredrik Holmqvist case OSL_EC_POLL_HANDLER: 809775afec4SFredrik Holmqvist case OSL_EC_BURST_HANDLER: 810775afec4SFredrik Holmqvist break; 811775afec4SFredrik Holmqvist } 812775afec4SFredrik Holmqvist */ 813775afec4SFredrik Holmqvist 814775afec4SFredrik Holmqvist if (gDPC->queue_dpc(gDPCHandle, function, context) != B_OK) { 815775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("Serious failure in AcpiOsExecute! function: %p", 816775afec4SFredrik Holmqvist function); 817775afec4SFredrik Holmqvist return AE_BAD_PARAMETER; 818775afec4SFredrik Holmqvist } 819775afec4SFredrik Holmqvist return AE_OK; 820775afec4SFredrik Holmqvist } 821775afec4SFredrik Holmqvist 822775afec4SFredrik Holmqvist 823775afec4SFredrik Holmqvist /****************************************************************************** 824775afec4SFredrik Holmqvist * 825775afec4SFredrik Holmqvist * FUNCTION: AcpiOsStall 826775afec4SFredrik Holmqvist * 827775afec4SFredrik Holmqvist * PARAMETERS: microseconds To sleep 828775afec4SFredrik Holmqvist * 829775afec4SFredrik Holmqvist * RETURN: Blocks until sleep is completed. 830775afec4SFredrik Holmqvist * 831775afec4SFredrik Holmqvist * DESCRIPTION: Sleep at microsecond granularity 832775afec4SFredrik Holmqvist * 833775afec4SFredrik Holmqvist *****************************************************************************/ 834775afec4SFredrik Holmqvist void 835775afec4SFredrik Holmqvist AcpiOsStall(UINT32 microseconds) 836775afec4SFredrik Holmqvist { 837775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("microseconds: %lu", microseconds); 838775afec4SFredrik Holmqvist if (microseconds) 839775afec4SFredrik Holmqvist spin(microseconds); 840775afec4SFredrik Holmqvist } 841775afec4SFredrik Holmqvist 842775afec4SFredrik Holmqvist 843775afec4SFredrik Holmqvist /****************************************************************************** 844775afec4SFredrik Holmqvist * 845775afec4SFredrik Holmqvist * FUNCTION: AcpiOsSleep 846775afec4SFredrik Holmqvist * 847775afec4SFredrik Holmqvist * PARAMETERS: milliseconds To sleep 848775afec4SFredrik Holmqvist * 849775afec4SFredrik Holmqvist * RETURN: Blocks until sleep is completed. 850775afec4SFredrik Holmqvist * 851775afec4SFredrik Holmqvist * DESCRIPTION: Sleep at millisecond granularity 852775afec4SFredrik Holmqvist * 853775afec4SFredrik Holmqvist *****************************************************************************/ 854775afec4SFredrik Holmqvist void 855775afec4SFredrik Holmqvist AcpiOsSleep(ACPI_INTEGER milliseconds) 856775afec4SFredrik Holmqvist { 857775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("milliseconds: %lu", milliseconds); 858775afec4SFredrik Holmqvist if (gKernelStartup) 859775afec4SFredrik Holmqvist spin(milliseconds * 1000); 860775afec4SFredrik Holmqvist else 861775afec4SFredrik Holmqvist snooze(milliseconds * 1000); 862775afec4SFredrik Holmqvist } 863775afec4SFredrik Holmqvist 864775afec4SFredrik Holmqvist 865775afec4SFredrik Holmqvist /****************************************************************************** 866775afec4SFredrik Holmqvist * 867775afec4SFredrik Holmqvist * FUNCTION: AcpiOsGetTimer 868775afec4SFredrik Holmqvist * 869775afec4SFredrik Holmqvist * PARAMETERS: None 870775afec4SFredrik Holmqvist * 871775afec4SFredrik Holmqvist * RETURN: Current time in 100 nanosecond units 872775afec4SFredrik Holmqvist * 873775afec4SFredrik Holmqvist * DESCRIPTION: Get the current system time 874775afec4SFredrik Holmqvist * 875775afec4SFredrik Holmqvist *****************************************************************************/ 876775afec4SFredrik Holmqvist UINT64 877775afec4SFredrik Holmqvist AcpiOsGetTimer() 878775afec4SFredrik Holmqvist { 879775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 880775afec4SFredrik Holmqvist return system_time() * 10; 881775afec4SFredrik Holmqvist } 882775afec4SFredrik Holmqvist 883775afec4SFredrik Holmqvist 884775afec4SFredrik Holmqvist /****************************************************************************** 885775afec4SFredrik Holmqvist * 886775afec4SFredrik Holmqvist * FUNCTION: AcpiOsReadPciConfiguration 887775afec4SFredrik Holmqvist * 888775afec4SFredrik Holmqvist * PARAMETERS: pciId Seg/Bus/Dev 889775afec4SFredrik Holmqvist * reg Device Register 890775afec4SFredrik Holmqvist * value Buffer where value is placed 891775afec4SFredrik Holmqvist * width Number of bits 892775afec4SFredrik Holmqvist * 893775afec4SFredrik Holmqvist * RETURN: Status 894775afec4SFredrik Holmqvist * 895775afec4SFredrik Holmqvist * DESCRIPTION: Read data from PCI configuration space 896775afec4SFredrik Holmqvist * 897775afec4SFredrik Holmqvist *****************************************************************************/ 898775afec4SFredrik Holmqvist ACPI_STATUS 899775afec4SFredrik Holmqvist AcpiOsReadPciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg, UINT64 *value, 900775afec4SFredrik Holmqvist UINT32 width) 901775afec4SFredrik Holmqvist { 902775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 903775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 904775afec4SFredrik Holmqvist 905775afec4SFredrik Holmqvist switch (width) { 906775afec4SFredrik Holmqvist case 8: 907775afec4SFredrik Holmqvist case 16: 908775afec4SFredrik Holmqvist case 32: 909775afec4SFredrik Holmqvist *value = gPCIManager->read_pci_config( 910775afec4SFredrik Holmqvist pciId->Bus, pciId->Device, pciId->Function, reg, width / 8); 911775afec4SFredrik Holmqvist break; 912775afec4SFredrik Holmqvist default: 913775afec4SFredrik Holmqvist return AE_ERROR; 914775afec4SFredrik Holmqvist } 915775afec4SFredrik Holmqvist return AE_OK; 916775afec4SFredrik Holmqvist #else 917775afec4SFredrik Holmqvist return AE_ERROR; 918775afec4SFredrik Holmqvist #endif 919775afec4SFredrik Holmqvist } 920775afec4SFredrik Holmqvist 921775afec4SFredrik Holmqvist 922775afec4SFredrik Holmqvist /****************************************************************************** 923775afec4SFredrik Holmqvist * 924775afec4SFredrik Holmqvist * FUNCTION: AcpiOsWritePciConfiguration 925775afec4SFredrik Holmqvist * 926775afec4SFredrik Holmqvist * PARAMETERS: pciId Seg/Bus/Dev 927775afec4SFredrik Holmqvist * reg Device Register 928775afec4SFredrik Holmqvist * value Value to be written 929775afec4SFredrik Holmqvist * width Number of bits 930775afec4SFredrik Holmqvist * 931775afec4SFredrik Holmqvist * RETURN: Status. 932775afec4SFredrik Holmqvist * 933775afec4SFredrik Holmqvist * DESCRIPTION: Write data to PCI configuration space 934775afec4SFredrik Holmqvist * 935775afec4SFredrik Holmqvist *****************************************************************************/ 936775afec4SFredrik Holmqvist ACPI_STATUS 937775afec4SFredrik Holmqvist AcpiOsWritePciConfiguration(ACPI_PCI_ID *pciId, UINT32 reg, 938775afec4SFredrik Holmqvist ACPI_INTEGER value, UINT32 width) 939775afec4SFredrik Holmqvist { 940775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 941775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 942775afec4SFredrik Holmqvist gPCIManager->write_pci_config( 943775afec4SFredrik Holmqvist pciId->Bus, pciId->Device, pciId->Function, reg, width / 8, value); 944775afec4SFredrik Holmqvist return AE_OK; 945775afec4SFredrik Holmqvist #else 946775afec4SFredrik Holmqvist return AE_ERROR; 947775afec4SFredrik Holmqvist #endif 948775afec4SFredrik Holmqvist } 949775afec4SFredrik Holmqvist 950775afec4SFredrik Holmqvist 951775afec4SFredrik Holmqvist /****************************************************************************** 952775afec4SFredrik Holmqvist * 953775afec4SFredrik Holmqvist * FUNCTION: AcpiOsReadPort 954775afec4SFredrik Holmqvist * 955775afec4SFredrik Holmqvist * PARAMETERS: address Address of I/O port/register to read 956775afec4SFredrik Holmqvist * Value Where value is placed 957775afec4SFredrik Holmqvist * width Number of bits 958775afec4SFredrik Holmqvist * 959775afec4SFredrik Holmqvist * RETURN: Value read from port 960775afec4SFredrik Holmqvist * 961775afec4SFredrik Holmqvist * DESCRIPTION: Read data from an I/O port or register 962775afec4SFredrik Holmqvist * 963775afec4SFredrik Holmqvist *****************************************************************************/ 964775afec4SFredrik Holmqvist ACPI_STATUS 965775afec4SFredrik Holmqvist AcpiOsReadPort(ACPI_IO_ADDRESS address, UINT32 *value, UINT32 width) 966775afec4SFredrik Holmqvist { 967775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 968775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("addr: 0x%08lx; width: %lu", (addr_t)address, width); 969775afec4SFredrik Holmqvist switch (width) { 970775afec4SFredrik Holmqvist case 8: 971775afec4SFredrik Holmqvist *value = gPCIManager->read_io_8(address); 972775afec4SFredrik Holmqvist break; 973775afec4SFredrik Holmqvist 974775afec4SFredrik Holmqvist case 16: 975775afec4SFredrik Holmqvist *value = gPCIManager->read_io_16(address); 976775afec4SFredrik Holmqvist break; 977775afec4SFredrik Holmqvist 978775afec4SFredrik Holmqvist case 32: 979775afec4SFredrik Holmqvist *value = gPCIManager->read_io_32(address); 980775afec4SFredrik Holmqvist break; 981775afec4SFredrik Holmqvist 982775afec4SFredrik Holmqvist default: 983775afec4SFredrik Holmqvist return AE_ERROR; 984775afec4SFredrik Holmqvist } 985775afec4SFredrik Holmqvist 986775afec4SFredrik Holmqvist return AE_OK; 987775afec4SFredrik Holmqvist #else 988775afec4SFredrik Holmqvist return AE_ERROR; 989775afec4SFredrik Holmqvist #endif 990775afec4SFredrik Holmqvist } 991775afec4SFredrik Holmqvist 992775afec4SFredrik Holmqvist 993775afec4SFredrik Holmqvist /****************************************************************************** 994775afec4SFredrik Holmqvist * 995775afec4SFredrik Holmqvist * FUNCTION: AcpiOsWritePort 996775afec4SFredrik Holmqvist * 997775afec4SFredrik Holmqvist * PARAMETERS: address Address of I/O port/register to write 998775afec4SFredrik Holmqvist * value Value to write 999775afec4SFredrik Holmqvist * width Number of bits 1000775afec4SFredrik Holmqvist * 1001775afec4SFredrik Holmqvist * RETURN: None 1002775afec4SFredrik Holmqvist * 1003775afec4SFredrik Holmqvist * DESCRIPTION: Write data to an I/O port or register 1004775afec4SFredrik Holmqvist * 1005775afec4SFredrik Holmqvist *****************************************************************************/ 1006775afec4SFredrik Holmqvist ACPI_STATUS 1007775afec4SFredrik Holmqvist AcpiOsWritePort(ACPI_IO_ADDRESS address, UINT32 value, UINT32 width) 1008775afec4SFredrik Holmqvist { 1009775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 1010775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("addr: 0x%08lx; value: %lu; width: %lu", 1011775afec4SFredrik Holmqvist (addr_t)address, value, width); 1012775afec4SFredrik Holmqvist switch (width) { 1013775afec4SFredrik Holmqvist case 8: 1014775afec4SFredrik Holmqvist gPCIManager->write_io_8(address, value); 1015775afec4SFredrik Holmqvist break; 1016775afec4SFredrik Holmqvist 1017775afec4SFredrik Holmqvist case 16: 1018775afec4SFredrik Holmqvist gPCIManager->write_io_16(address,value); 1019775afec4SFredrik Holmqvist break; 1020775afec4SFredrik Holmqvist 1021775afec4SFredrik Holmqvist case 32: 1022775afec4SFredrik Holmqvist gPCIManager->write_io_32(address,value); 1023775afec4SFredrik Holmqvist break; 1024775afec4SFredrik Holmqvist 1025775afec4SFredrik Holmqvist default: 1026775afec4SFredrik Holmqvist return AE_ERROR; 1027775afec4SFredrik Holmqvist } 1028775afec4SFredrik Holmqvist 1029775afec4SFredrik Holmqvist return AE_OK; 1030775afec4SFredrik Holmqvist #else 1031775afec4SFredrik Holmqvist return AE_ERROR; 1032775afec4SFredrik Holmqvist #endif 1033775afec4SFredrik Holmqvist } 1034775afec4SFredrik Holmqvist 1035775afec4SFredrik Holmqvist 1036775afec4SFredrik Holmqvist /****************************************************************************** 1037775afec4SFredrik Holmqvist * 1038775afec4SFredrik Holmqvist * FUNCTION: AcpiOsReadMemory 1039775afec4SFredrik Holmqvist * 1040775afec4SFredrik Holmqvist * PARAMETERS: address Physical Memory Address to read 1041775afec4SFredrik Holmqvist * value Where value is placed 1042775afec4SFredrik Holmqvist * width Number of bits 1043775afec4SFredrik Holmqvist * 1044775afec4SFredrik Holmqvist * RETURN: Value read from physical memory address 1045775afec4SFredrik Holmqvist * 1046775afec4SFredrik Holmqvist * DESCRIPTION: Read data from a physical memory address 1047775afec4SFredrik Holmqvist * 1048775afec4SFredrik Holmqvist *****************************************************************************/ 1049775afec4SFredrik Holmqvist ACPI_STATUS 1050775afec4SFredrik Holmqvist AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS address, UINT64 *value, UINT32 width) 1051775afec4SFredrik Holmqvist { 1052775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 1053775afec4SFredrik Holmqvist if (vm_memcpy_from_physical(value, (addr_t)address, width / 8, false) 1054775afec4SFredrik Holmqvist != B_OK) { 1055775afec4SFredrik Holmqvist return AE_ERROR; 1056775afec4SFredrik Holmqvist } 1057775afec4SFredrik Holmqvist return AE_OK; 1058775afec4SFredrik Holmqvist #else 1059775afec4SFredrik Holmqvist return AE_ERROR; 1060775afec4SFredrik Holmqvist #endif 1061775afec4SFredrik Holmqvist } 1062775afec4SFredrik Holmqvist 1063775afec4SFredrik Holmqvist 1064775afec4SFredrik Holmqvist /****************************************************************************** 1065775afec4SFredrik Holmqvist * 1066775afec4SFredrik Holmqvist * FUNCTION: AcpiOsWriteMemory 1067775afec4SFredrik Holmqvist * 1068775afec4SFredrik Holmqvist * PARAMETERS: address Physical Memory Address to write 1069775afec4SFredrik Holmqvist * value Value to write 1070775afec4SFredrik Holmqvist * width Number of bits 1071775afec4SFredrik Holmqvist * 1072775afec4SFredrik Holmqvist * RETURN: None 1073775afec4SFredrik Holmqvist * 1074775afec4SFredrik Holmqvist * DESCRIPTION: Write data to a physical memory address 1075775afec4SFredrik Holmqvist * 1076775afec4SFredrik Holmqvist *****************************************************************************/ 1077775afec4SFredrik Holmqvist ACPI_STATUS 1078775afec4SFredrik Holmqvist AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS address, UINT64 value, UINT32 width) 1079775afec4SFredrik Holmqvist { 1080775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 1081775afec4SFredrik Holmqvist if (vm_memcpy_to_physical((addr_t)address, &value, width / 8, false) 1082775afec4SFredrik Holmqvist != B_OK) { 1083775afec4SFredrik Holmqvist return AE_ERROR; 1084775afec4SFredrik Holmqvist } 1085775afec4SFredrik Holmqvist return AE_OK; 1086775afec4SFredrik Holmqvist #else 1087775afec4SFredrik Holmqvist return AE_ERROR; 1088775afec4SFredrik Holmqvist #endif 1089775afec4SFredrik Holmqvist } 1090775afec4SFredrik Holmqvist 1091775afec4SFredrik Holmqvist 1092775afec4SFredrik Holmqvist /****************************************************************************** 1093775afec4SFredrik Holmqvist * 1094775afec4SFredrik Holmqvist * FUNCTION: AcpiOsReadable 1095775afec4SFredrik Holmqvist * 1096775afec4SFredrik Holmqvist * PARAMETERS: pointer - Area to be verified 1097775afec4SFredrik Holmqvist * length - Size of area 1098775afec4SFredrik Holmqvist * 1099775afec4SFredrik Holmqvist * RETURN: TRUE if readable for entire length 1100775afec4SFredrik Holmqvist * 1101775afec4SFredrik Holmqvist * DESCRIPTION: Verify that a pointer is valid for reading 1102775afec4SFredrik Holmqvist * 1103775afec4SFredrik Holmqvist *****************************************************************************/ 1104775afec4SFredrik Holmqvist BOOLEAN 1105775afec4SFredrik Holmqvist AcpiOsReadable(void *pointer, ACPI_SIZE length) 1106775afec4SFredrik Holmqvist { 1107775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 1108775afec4SFredrik Holmqvist return true; 1109775afec4SFredrik Holmqvist #else 1110775afec4SFredrik Holmqvist area_id id; 1111775afec4SFredrik Holmqvist area_info info; 1112775afec4SFredrik Holmqvist 1113775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length); 1114775afec4SFredrik Holmqvist 1115775afec4SFredrik Holmqvist id = area_for(pointer); 1116775afec4SFredrik Holmqvist if (id == B_ERROR) return false; 1117775afec4SFredrik Holmqvist if (get_area_info(id, &info) != B_OK) return false; 1118775afec4SFredrik Holmqvist return (info.protection & B_READ_AREA) != 0 && 1119775afec4SFredrik Holmqvist pointer + length <= info.address + info.ram_size; 1120775afec4SFredrik Holmqvist #endif 1121775afec4SFredrik Holmqvist } 1122775afec4SFredrik Holmqvist 1123775afec4SFredrik Holmqvist 1124775afec4SFredrik Holmqvist /****************************************************************************** 1125775afec4SFredrik Holmqvist * 1126775afec4SFredrik Holmqvist * FUNCTION: AcpiOsWritable 1127775afec4SFredrik Holmqvist * 1128775afec4SFredrik Holmqvist * PARAMETERS: pointer - Area to be verified 1129775afec4SFredrik Holmqvist * length - Size of area 1130775afec4SFredrik Holmqvist * 1131775afec4SFredrik Holmqvist * RETURN: TRUE if writable for entire length 1132775afec4SFredrik Holmqvist * 1133775afec4SFredrik Holmqvist * DESCRIPTION: Verify that a pointer is valid for writing 1134775afec4SFredrik Holmqvist * 1135775afec4SFredrik Holmqvist *****************************************************************************/ 1136775afec4SFredrik Holmqvist BOOLEAN 1137775afec4SFredrik Holmqvist AcpiOsWritable(void *pointer, ACPI_SIZE length) 1138775afec4SFredrik Holmqvist { 1139775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 1140775afec4SFredrik Holmqvist return true; 1141775afec4SFredrik Holmqvist #else 1142775afec4SFredrik Holmqvist area_id id; 1143775afec4SFredrik Holmqvist area_info info; 1144775afec4SFredrik Holmqvist 1145775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("addr: %p; length: %lu", pointer, (size_t)length); 1146775afec4SFredrik Holmqvist 1147775afec4SFredrik Holmqvist id = area_for(pointer); 1148775afec4SFredrik Holmqvist if (id == B_ERROR) return false; 1149775afec4SFredrik Holmqvist if (get_area_info(id, &info) != B_OK) return false; 1150775afec4SFredrik Holmqvist return (info.protection & B_READ_AREA) != 0 && 1151775afec4SFredrik Holmqvist (info.protection & B_WRITE_AREA) != 0 && 1152775afec4SFredrik Holmqvist pointer + length <= info.address + info.ram_size; 1153775afec4SFredrik Holmqvist #endif 1154775afec4SFredrik Holmqvist } 1155775afec4SFredrik Holmqvist 1156775afec4SFredrik Holmqvist 1157775afec4SFredrik Holmqvist /****************************************************************************** 1158775afec4SFredrik Holmqvist * 1159775afec4SFredrik Holmqvist * FUNCTION: AcpiOsGetThreadId 1160775afec4SFredrik Holmqvist * 1161775afec4SFredrik Holmqvist * PARAMETERS: None 1162775afec4SFredrik Holmqvist * 1163775afec4SFredrik Holmqvist * RETURN: Id of the running thread 1164775afec4SFredrik Holmqvist * 1165775afec4SFredrik Holmqvist * DESCRIPTION: Get the Id of the current (running) thread 1166775afec4SFredrik Holmqvist * 1167775afec4SFredrik Holmqvist * NOTE: The environment header should contain this line: 1168775afec4SFredrik Holmqvist * #define ACPI_THREAD_ID pthread_t 1169775afec4SFredrik Holmqvist * 1170775afec4SFredrik Holmqvist *****************************************************************************/ 1171775afec4SFredrik Holmqvist ACPI_THREAD_ID 1172775afec4SFredrik Holmqvist AcpiOsGetThreadId() 1173775afec4SFredrik Holmqvist { 1174775afec4SFredrik Holmqvist thread_id thread = find_thread(NULL); 1175775afec4SFredrik Holmqvist // TODO: We arn't allowed threads with id 0, handle this case. 1176775afec4SFredrik Holmqvist // ACPI treats a 0 return as an error, 1177775afec4SFredrik Holmqvist // but we are thread 0 in early boot 1178775afec4SFredrik Holmqvist return thread; 1179775afec4SFredrik Holmqvist } 1180775afec4SFredrik Holmqvist 1181775afec4SFredrik Holmqvist 1182775afec4SFredrik Holmqvist /****************************************************************************** 1183775afec4SFredrik Holmqvist * 1184775afec4SFredrik Holmqvist * FUNCTION: AcpiOsSignal 1185775afec4SFredrik Holmqvist * 1186775afec4SFredrik Holmqvist * PARAMETERS: function ACPI CA signal function code 1187775afec4SFredrik Holmqvist * info Pointer to function-dependent structure 1188775afec4SFredrik Holmqvist * 1189775afec4SFredrik Holmqvist * RETURN: Status 1190775afec4SFredrik Holmqvist * 1191775afec4SFredrik Holmqvist * DESCRIPTION: Miscellaneous functions. Example implementation only. 1192775afec4SFredrik Holmqvist * 1193775afec4SFredrik Holmqvist *****************************************************************************/ 1194775afec4SFredrik Holmqvist ACPI_STATUS 1195775afec4SFredrik Holmqvist AcpiOsSignal(UINT32 function, void *info) 1196775afec4SFredrik Holmqvist { 1197775afec4SFredrik Holmqvist DEBUG_FUNCTION(); 1198775afec4SFredrik Holmqvist 1199775afec4SFredrik Holmqvist switch (function) { 1200775afec4SFredrik Holmqvist case ACPI_SIGNAL_FATAL: 1201775afec4SFredrik Holmqvist #ifdef _KERNEL_MODE 1202775afec4SFredrik Holmqvist panic(info == NULL ? "AcpiOsSignal: fatal" : (const char*)info); 1203775afec4SFredrik Holmqvist break; 1204775afec4SFredrik Holmqvist #endif 1205775afec4SFredrik Holmqvist case ACPI_SIGNAL_BREAKPOINT: 1206775afec4SFredrik Holmqvist if (info != NULL) 1207775afec4SFredrik Holmqvist AcpiOsPrintf("AcpiOsBreakpoint: %s ****\n", info); 1208775afec4SFredrik Holmqvist else 1209775afec4SFredrik Holmqvist AcpiOsPrintf("At AcpiOsBreakpoint ****\n"); 1210775afec4SFredrik Holmqvist break; 1211775afec4SFredrik Holmqvist } 1212775afec4SFredrik Holmqvist 1213775afec4SFredrik Holmqvist return AE_OK; 1214775afec4SFredrik Holmqvist } 1215775afec4SFredrik Holmqvist 1216775afec4SFredrik Holmqvist 1217775afec4SFredrik Holmqvist /* 1218775afec4SFredrik Holmqvist * Adapted from FreeBSD since the documentation of its intended impl 1219775afec4SFredrik Holmqvist * is lacking. 1220775afec4SFredrik Holmqvist * Section 5.2.10.1: global lock acquire/release functions */ 1221775afec4SFredrik Holmqvist #define GL_ACQUIRED (-1) 1222775afec4SFredrik Holmqvist #define GL_BUSY 0 1223775afec4SFredrik Holmqvist #define GL_BIT_PENDING 0x01 1224775afec4SFredrik Holmqvist #define GL_BIT_OWNED 0x02 1225775afec4SFredrik Holmqvist #define GL_BIT_MASK (GL_BIT_PENDING | GL_BIT_OWNED) 1226775afec4SFredrik Holmqvist 1227775afec4SFredrik Holmqvist 1228775afec4SFredrik Holmqvist /* 1229775afec4SFredrik Holmqvist * Adapted from FreeBSD since the documentation of its intended impl 1230775afec4SFredrik Holmqvist * is lacking. 1231775afec4SFredrik Holmqvist * Acquire the global lock. If busy, set the pending bit. The caller 1232775afec4SFredrik Holmqvist * will wait for notification from the BIOS that the lock is available 1233775afec4SFredrik Holmqvist * and then attempt to acquire it again. 1234775afec4SFredrik Holmqvist */ 1235775afec4SFredrik Holmqvist int 1236775afec4SFredrik Holmqvist AcpiOsAcquireGlobalLock(uint32 *lock) 1237775afec4SFredrik Holmqvist { 1238775afec4SFredrik Holmqvist uint32 newValue; 1239775afec4SFredrik Holmqvist uint32 oldValue; 1240775afec4SFredrik Holmqvist 1241775afec4SFredrik Holmqvist do { 1242775afec4SFredrik Holmqvist oldValue = *lock; 1243775afec4SFredrik Holmqvist newValue = ((oldValue & ~GL_BIT_MASK) | GL_BIT_OWNED) | 1244775afec4SFredrik Holmqvist ((oldValue >> 1) & GL_BIT_PENDING); 1245775afec4SFredrik Holmqvist atomic_test_and_set((int32*)lock, newValue, oldValue); 1246775afec4SFredrik Holmqvist } while (*lock == oldValue); 1247775afec4SFredrik Holmqvist return ((newValue < GL_BIT_MASK) ? GL_ACQUIRED : GL_BUSY); 1248775afec4SFredrik Holmqvist } 1249775afec4SFredrik Holmqvist 1250775afec4SFredrik Holmqvist 1251775afec4SFredrik Holmqvist /* 1252775afec4SFredrik Holmqvist * Adapted from FreeBSD since the documentation of its intended impl 1253775afec4SFredrik Holmqvist * is lacking. 1254775afec4SFredrik Holmqvist * Release the global lock, returning whether there is a waiter pending. 1255775afec4SFredrik Holmqvist * If the BIOS set the pending bit, OSPM must notify the BIOS when it 1256775afec4SFredrik Holmqvist * releases the lock. 1257775afec4SFredrik Holmqvist */ 1258775afec4SFredrik Holmqvist int 1259775afec4SFredrik Holmqvist AcpiOsReleaseGlobalLock(uint32 *lock) 1260775afec4SFredrik Holmqvist { 1261775afec4SFredrik Holmqvist uint32 newValue; 1262775afec4SFredrik Holmqvist uint32 oldValue; 1263775afec4SFredrik Holmqvist 1264775afec4SFredrik Holmqvist do { 1265775afec4SFredrik Holmqvist oldValue = *lock; 1266775afec4SFredrik Holmqvist newValue = oldValue & ~GL_BIT_MASK; 1267775afec4SFredrik Holmqvist atomic_test_and_set((int32*)lock, newValue, oldValue); 1268775afec4SFredrik Holmqvist } while (*lock == oldValue); 1269775afec4SFredrik Holmqvist return (oldValue & GL_BIT_PENDING); 1270775afec4SFredrik Holmqvist } 1271775afec4SFredrik Holmqvist 1272775afec4SFredrik Holmqvist 1273775afec4SFredrik Holmqvist ACPI_STATUS 1274775afec4SFredrik Holmqvist AcpiOsCreateMutex(ACPI_MUTEX* outHandle) 1275775afec4SFredrik Holmqvist { 1276775afec4SFredrik Holmqvist *outHandle = (ACPI_MUTEX) malloc(sizeof(mutex)); 1277775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("result: %p", *outHandle); 1278775afec4SFredrik Holmqvist if (*outHandle == NULL) 1279775afec4SFredrik Holmqvist return AE_NO_MEMORY; 1280775afec4SFredrik Holmqvist 1281775afec4SFredrik Holmqvist mutex_init(*outHandle, "acpi mutex"); 1282775afec4SFredrik Holmqvist return AE_OK; 1283775afec4SFredrik Holmqvist } 1284775afec4SFredrik Holmqvist 1285775afec4SFredrik Holmqvist 1286775afec4SFredrik Holmqvist void 1287775afec4SFredrik Holmqvist AcpiOsDeleteMutex(ACPI_MUTEX handle) 1288775afec4SFredrik Holmqvist { 1289775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("mutex: %ld", handle); 1290775afec4SFredrik Holmqvist mutex_destroy(handle); 1291775afec4SFredrik Holmqvist free((void*)handle); 1292775afec4SFredrik Holmqvist } 1293775afec4SFredrik Holmqvist 1294775afec4SFredrik Holmqvist 1295775afec4SFredrik Holmqvist ACPI_STATUS 1296775afec4SFredrik Holmqvist AcpiOsAcquireMutex(ACPI_MUTEX handle, UINT16 timeout) 1297775afec4SFredrik Holmqvist { 1298775afec4SFredrik Holmqvist ACPI_STATUS result = AE_OK; 1299775afec4SFredrik Holmqvist DEBUG_FUNCTION_VF("mutex: %ld; timeout: %u", handle, timeout); 1300775afec4SFredrik Holmqvist 1301775afec4SFredrik Holmqvist if (timeout == ACPI_WAIT_FOREVER) 1302775afec4SFredrik Holmqvist result = mutex_lock(handle) == B_OK ? AE_OK : AE_BAD_PARAMETER; 1303775afec4SFredrik Holmqvist else { 1304775afec4SFredrik Holmqvist switch (mutex_lock_with_timeout(handle, B_RELATIVE_TIMEOUT, 1305775afec4SFredrik Holmqvist (bigtime_t)timeout * 1000)) { 1306775afec4SFredrik Holmqvist case B_OK: 1307775afec4SFredrik Holmqvist result = AE_OK; 1308775afec4SFredrik Holmqvist break; 1309775afec4SFredrik Holmqvist case B_INTERRUPTED: 1310775afec4SFredrik Holmqvist case B_TIMED_OUT: 1311775afec4SFredrik Holmqvist case B_WOULD_BLOCK: 1312775afec4SFredrik Holmqvist result = AE_TIME; 1313775afec4SFredrik Holmqvist break; 1314775afec4SFredrik Holmqvist case B_BAD_VALUE: 1315775afec4SFredrik Holmqvist default: 1316775afec4SFredrik Holmqvist result = AE_BAD_PARAMETER; 1317775afec4SFredrik Holmqvist break; 1318775afec4SFredrik Holmqvist } 1319775afec4SFredrik Holmqvist } 1320775afec4SFredrik Holmqvist DEBUG_FUNCTION_VF("mutex: %ld; timeout: %u result: %lu", 1321775afec4SFredrik Holmqvist handle, timeout, (uint32)result); 1322775afec4SFredrik Holmqvist return result; 1323775afec4SFredrik Holmqvist } 1324775afec4SFredrik Holmqvist 1325775afec4SFredrik Holmqvist 1326775afec4SFredrik Holmqvist void 1327775afec4SFredrik Holmqvist AcpiOsReleaseMutex(ACPI_MUTEX handle) 1328775afec4SFredrik Holmqvist { 1329775afec4SFredrik Holmqvist DEBUG_FUNCTION_F("mutex: %p", handle); 1330775afec4SFredrik Holmqvist mutex_unlock(handle); 1331775afec4SFredrik Holmqvist } 1332775afec4SFredrik Holmqvist 1333775afec4SFredrik Holmqvist 1334775afec4SFredrik Holmqvist /****************************************************************************** 1335775afec4SFredrik Holmqvist * 1336775afec4SFredrik Holmqvist * FUNCTION: AcpiOsWaitEventsComplete 1337775afec4SFredrik Holmqvist * 1338775afec4SFredrik Holmqvist * PARAMETERS: None 1339775afec4SFredrik Holmqvist * 1340775afec4SFredrik Holmqvist * RETURN: None 1341775afec4SFredrik Holmqvist * 1342775afec4SFredrik Holmqvist * DESCRIPTION: Wait for all asynchronous events to complete. This 1343775afec4SFredrik Holmqvist * implementation does nothing. 1344775afec4SFredrik Holmqvist * 1345775afec4SFredrik Holmqvist *****************************************************************************/ 1346775afec4SFredrik Holmqvist void 1347775afec4SFredrik Holmqvist AcpiOsWaitEventsComplete() 1348775afec4SFredrik Holmqvist { 1349775afec4SFredrik Holmqvist //TODO: FreeBSD See description. 1350775afec4SFredrik Holmqvist return; 1351775afec4SFredrik Holmqvist } 1352