diff options
Diffstat (limited to 'sys/contrib/dev/acpica')
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Hardware/hwcpu32.c | 837 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Hardware/hwxface.c | 737 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Include/acconfig.h | 3 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Include/acfreebsd.h | 66 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Include/acgcc.h | 4 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Include/acpixf.h | 3 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Parser/psparse.c | 19 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/acconfig.h | 14 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/acfreebsd.h | 29 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/acgcc.h | 7 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/acpixf.h | 49 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/exfldio.c | 1064 | ||||
-rw-r--r-- | sys/contrib/dev/acpica/psparse.c | 150 |
13 files changed, 653 insertions, 2329 deletions
diff --git a/sys/contrib/dev/acpica/Subsystem/Hardware/hwcpu32.c b/sys/contrib/dev/acpica/Subsystem/Hardware/hwcpu32.c deleted file mode 100644 index 8401061..0000000 --- a/sys/contrib/dev/acpica/Subsystem/Hardware/hwcpu32.c +++ /dev/null @@ -1,837 +0,0 @@ -/****************************************************************************** - * - * Name: hwcpu32.c - CPU support for IA32 (Throttling, CxStates) - * $Revision: 40 $ - * - *****************************************************************************/ - -/****************************************************************************** - * - * 1. Copyright Notice - * - * Some or all of this work - Copyright (c) 1999, 2000, Intel Corp. - * All rights reserved. - * - * 2. License - * - * 2.1. This is your license from Intel Corp. under its intellectual property - * rights. You may have additional license terms from the party that provided - * you this software, covering your right to use that party's intellectual - * property rights. - * - * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a - * copy of the source code appearing in this file ("Covered Code") an - * irrevocable, perpetual, worldwide license under Intel's copyrights in the - * base code distributed originally by Intel ("Original Intel Code") to copy, - * make derivatives, distribute, use and display any portion of the Covered - * Code in any form, with the right to sublicense such rights; and - * - * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent - * license (with the right to sublicense), under only those claims of Intel - * patents that are infringed by the Original Intel Code, to make, use, sell, - * offer to sell, and import the Covered Code and derivative works thereof - * solely to the minimum extent necessary to exercise the above copyright - * license, and in no event shall the patent license extend to any additions - * to or modifications of the Original Intel Code. No other license or right - * is granted directly or by implication, estoppel or otherwise; - * - * The above copyright and patent license is granted only if the following - * conditions are met: - * - * 3. Conditions - * - * 3.1. Redistribution of Source with Rights to Further Distribute Source. - * Redistribution of source code of any substantial portion of the Covered - * Code or modification with rights to further distribute source must include - * the above Copyright Notice, the above License, this list of Conditions, - * and the following Disclaimer and Export Compliance provision. In addition, - * Licensee must cause all Covered Code to which Licensee contributes to - * contain a file documenting the changes Licensee made to create that Covered - * Code and the date of any change. Licensee must include in that file the - * documentation of any changes made by any predecessor Licensee. Licensee - * must include a prominent statement that the modification is derived, - * directly or indirectly, from Original Intel Code. - * - * 3.2. Redistribution of Source with no Rights to Further Distribute Source. - * Redistribution of source code of any substantial portion of the Covered - * Code or modification without rights to further distribute source must - * include the following Disclaimer and Export Compliance provision in the - * documentation and/or other materials provided with distribution. In - * addition, Licensee may not authorize further sublicense of source of any - * portion of the Covered Code, and must include terms to the effect that the - * license from Licensee to its licensee is limited to the intellectual - * property embodied in the software Licensee provides to its licensee, and - * not to intellectual property embodied in modifications its licensee may - * make. - * - * 3.3. Redistribution of Executable. Redistribution in executable form of any - * substantial portion of the Covered Code or modification must reproduce the - * above Copyright Notice, and the following Disclaimer and Export Compliance - * provision in the documentation and/or other materials provided with the - * distribution. - * - * 3.4. Intel retains all right, title, and interest in and to the Original - * Intel Code. - * - * 3.5. Neither the name Intel nor any other trademark owned or controlled by - * Intel shall be used in advertising or otherwise to promote the sale, use or - * other dealings in products derived from or relating to the Covered Code - * without prior written authorization from Intel. - * - * 4. Disclaimer and Export Compliance - * - * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED - * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE - * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, - * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY - * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY - * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A - * PARTICULAR PURPOSE. - * - * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES - * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR - * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, - * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY - * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL - * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS - * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY - * LIMITED REMEDY. - * - * 4.3. Licensee shall not export, either directly or indirectly, any of this - * software or system incorporating such software without first obtaining any - * required license or other approval from the U. S. Department of Commerce or - * any other agency or department of the United States Government. In the - * event Licensee exports any such software from the United States or - * re-exports any such software from a foreign destination, Licensee shall - * ensure that the distribution and export/re-export of the software is in - * compliance with all laws, regulations, orders, or other restrictions of the - * U.S. Export Administration Regulations. Licensee agrees that neither it nor - * any of its subsidiaries will export/re-export any technical data, process, - * software, or service, directly or indirectly, to any country for which the - * United States government or any agency thereof requires an export license, - * other governmental approval, or letter of assurance, without first obtaining - * such license, approval or letter. - * - *****************************************************************************/ - -#include "acpi.h" -#include "acnamesp.h" -#include "achware.h" - -#define _COMPONENT HARDWARE - MODULE_NAME ("Hwcpu32") - - -#define BIT_4 0x10 /* TBD: [investigate] is this correct? */ - - -/**************************************************************************** - * - * FUNCTION: AcpiHwEnterC1 - * - * PARAMETERS: PblkAddress - Address of the processor control block - * PmTimerTicks - Number of PM timer ticks elapsed while asleep - * - * RETURN: Function status. - * - * DESCRIPTION: Set C1 state on IA32 processor (halt) - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwEnterC1( - ACPI_IO_ADDRESS PblkAddress, - UINT32 *PmTimerTicks) -{ - UINT32 Timer = 0; - - - if (!PmTimerTicks) - { - /* - * Enter C1: - * --------- - */ - enable(); - halt(); - *PmTimerTicks = ACPI_UINT32_MAX; - } - else - { - Timer = AcpiHwPmtTicks (); - - /* - * Enter C1: - * --------- - */ - enable (); - halt (); - - /* - * Compute Time in C1: - * ------------------- - */ - Timer = AcpiHwPmtTicks () - Timer; - - *PmTimerTicks = Timer; - } - - return (AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiHwEnterC2 - * - * PARAMETERS: PblkAddress - Address of the processor control block - * PmTimerTicks - Number of PM timer ticks elapsed while asleep - * - * RETURN: <none> - * - * DESCRIPTION: Set C2 state on IA32 processor - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwEnterC2( - ACPI_IO_ADDRESS PblkAddress, - UINT32 *PmTimerTicks) -{ - UINT32 Timer = 0; - - - if (!PblkAddress || !PmTimerTicks) - { - return (AE_BAD_PARAMETER); - } - - /* - * Disable interrupts before all C2/C3 transitions. - */ - disable (); - - Timer = AcpiHwPmtTicks (); - - /* - * Enter C2: - * --------- - * Read from the P_LVL2 (P_BLK+4) register to invoke a C2 transition. - */ - AcpiOsIn8 ((ACPI_IO_ADDRESS) (PblkAddress + 4)); - - /* - * Perform Dummy Op: - * ----------------- - * We have to do something useless after reading LVL2 because chipsets - * cannot guarantee that STPCLK# gets asserted in time to freeze execution. - */ - AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, PM2_CONTROL); - - /* - * Compute Time in C2: - * ------------------- - */ - Timer = AcpiHwPmtTicks () - Timer; - - *PmTimerTicks = Timer; - - /* - * Re-enable interrupts after coming out of C2/C3. - */ - enable (); - - return (AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiHwEnterC3 - * - * PARAMETERS: PblkAddress - Address of the processor control block - * PmTimerTicks - Number of PM timer ticks elapsed while asleep - * - * RETURN: Status of function - * - * DESCRIPTION: Set C3 state on IA32 processor (UP only, cache coherency via - * disabling bus mastering) - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwEnterC3( - ACPI_IO_ADDRESS PblkAddress, - UINT32 *PmTimerTicks) -{ - UINT32 Timer = 0; - UINT32 BusMasterStatus = 0; - - - if (!PblkAddress || !PmTimerTicks) - { - return (AE_BAD_PARAMETER); - } - - /* - * Check the BM_STS bit, if it is set, do not enter C3 - * but clear the bit (with a write) and exit, telling - * the calling module that we spent zero time in C3. - * If bus mastering continues, this action should - * eventually cause a demotion to C2 - */ - if (1 == (BusMasterStatus = - AcpiHwRegisterBitAccess (ACPI_READ, ACPI_MTX_LOCK, BM_STS))) - { - /* - * Clear the BM_STS bit by setting it. - */ - AcpiHwRegisterBitAccess (ACPI_WRITE, ACPI_MTX_LOCK, BM_STS, 1); - *PmTimerTicks = 0; - return (AE_OK); - } - - /* - * Disable interrupts before all C2/C3 transitions. - */ - disable(); - - /* - * Disable Bus Mastering: - * ---------------------- - * Set the PM2_CNT.ARB_DIS bit (bit #0), preserving all other bits. - */ - AcpiHwRegisterBitAccess(ACPI_WRITE, ACPI_MTX_LOCK, ARB_DIS, 1); - - /* - * Get the timer base before entering C state - */ - Timer = AcpiHwPmtTicks (); - - /* - * Enter C3: - * --------- - * Read from the P_LVL3 (P_BLK+5) register to invoke a C3 transition. - */ - AcpiOsIn8 ((ACPI_IO_ADDRESS)(PblkAddress + 5)); - - /* - * Perform Dummy Op: - * ----------------- - * We have to do something useless after reading LVL3 because chipsets - * cannot guarantee that STPCLK# gets asserted in time to freeze execution. - */ - AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, PM2_CONTROL); - /* - * Immediately compute the time in the C state - */ - Timer = AcpiHwPmtTicks() - Timer; - - /* - * Re-Enable Bus Mastering: - * ------------------------ - * Clear the PM2_CNT.ARB_DIS bit (bit #0), preserving all other bits. - */ - AcpiHwRegisterBitAccess(ACPI_WRITE, ACPI_MTX_LOCK, ARB_DIS, 0); - - /* TBD: [Unhandled]: Support 24-bit timers (this algorithm assumes 32-bit) */ - - *PmTimerTicks = Timer; - - /* - * Re-enable interrupts after coming out of C2/C3. - */ - enable(); - - return (AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiHwEnterCx - * - * PARAMETERS: ProcessorHandle - handle of the processor - * - * RETURN: Status of function - * - * DESCRIPTION: Invoke the currently active processor Cx handler to put this - * processor to sleep. - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwEnterCx ( - ACPI_IO_ADDRESS PblkAddress, - UINT32 *PmTimerTicks) -{ - - if (!AcpiHwCxHandlers[AcpiHwActiveCxState]) - { - return (AE_SUPPORT); - } - - return (AcpiHwCxHandlers[AcpiHwActiveCxState] (PblkAddress, PmTimerTicks)); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiHwSetCx - * - * PARAMETERS: State - value (1-3) of the Cx state to 'make active' - * - * RETURN: Function status. - * - * DESCRIPTION: Sets the state to use during calls to AcpiHwEnterCx(). - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwSetCx ( - UINT32 CxState) -{ - /* - * Supported State? - * ---------------- - */ - if ((CxState < 1) || (CxState > 3)) - { - return (AE_BAD_PARAMETER); - } - - if (!AcpiHwCxHandlers[CxState]) - { - return (AE_SUPPORT); - } - - /* - * New Cx State? - * ------------- - * We only care when moving from one state to another... - */ - if (AcpiHwActiveCxState == CxState) - { - return (AE_OK); - } - - /* - * Prepare to Use New State: - * ------------------------- - * If the new CxState is C3, the BM_RLD bit must be set to allow - * the generation of a bus master requets to cause the processor - * in the C3 state to transition to the C0 state. - */ - switch (CxState) - { - case 3: - AcpiHwRegisterBitAccess (ACPI_WRITE, ACPI_MTX_LOCK, BM_RLD, 1); - break; - } - - /* - * Clean up from Old State: - * ------------------------ - * If the old CxState was C3, the BM_RLD bit is reset. When the - * bit is reset, the generation of a bus master request does not - * effect any processor in the C3 state. - */ - switch (AcpiHwActiveCxState) - { - case 3: - AcpiHwRegisterBitAccess (ACPI_WRITE, ACPI_MTX_LOCK, BM_RLD, 0); - break; - } - - /* - * Enable: - * ------- - */ - AcpiHwActiveCxState = CxState; - - return (AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiHwGetCxInfo - * - * PARAMETERS: CxStates - Information (latencies) on all Cx states - * - * RETURN: Status of function - * - * DESCRIPTION: This function is called both to initialize Cx handling - * and retrieve the current Cx information (latency values). - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwGetCxInfo ( - UINT32 CxStates[]) -{ - BOOLEAN SMP_system = FALSE; - - - FUNCTION_TRACE("HwGetCxInfo"); - - - if (!CxStates) - { - return_ACPI_STATUS(AE_BAD_PARAMETER); - } - - /* - * TBD: [Unhandled] need to init SMP_system using info from the MAPIC - * table. - */ - - /* - * Set Defaults: - * ------------- - * C0 and C1 support is implied (but what about that PROC_C1 register - * in the FADT?!?!). Set C2/C3 to max. latency (not supported until - * proven otherwise). - */ - CxStates[0] = 0; - CxStates[1] = 0; - CxStates[2] = MAX_CX_STATE_LATENCY; - CxStates[3] = MAX_CX_STATE_LATENCY; - - /* - * C2 Supported? - * ------------- - * We're only supporting C2 when the latency is <= 100 microseconds, - * and on SMP systems when P_LVL2_UP (which indicates C2 only on UP) - * is not set. - */ - if (AcpiGbl_FADT->Plvl2Lat <= 100) - { - if (!SMP_system) - { - AcpiHwCxHandlers[2] = AcpiHwEnterC2; - CxStates[2] = AcpiGbl_FADT->Plvl2Lat; - } - - else if (!AcpiGbl_FADT->Plvl2Up) - { - AcpiHwCxHandlers[2] = AcpiHwEnterC2; - CxStates[2] = AcpiGbl_FADT->Plvl2Lat; - } - } - - /* - * C3 Supported? - * ------------- - * We're only supporting C3 on UP systems when the latency is - * <= 1000 microseconds and that include the ability to disable - * Bus Mastering while in C3 (ARB_DIS) but allows Bus Mastering - * requests to wake the system from C3 (BM_RLD). Note his method - * of maintaining cache coherency (disabling of bus mastering) - * cannot be used on SMP systems, and flushing caches (e.g. WBINVD) - * is simply too costly (at this time). - */ - if (AcpiGbl_FADT->Plvl3Lat <= 1000) - { - if (!SMP_system && (AcpiGbl_FADT->XPm2CntBlk.Address && - AcpiGbl_FADT->Pm2CntLen)) - { - AcpiHwCxHandlers[3] = AcpiHwEnterC3; - CxStates[3] = AcpiGbl_FADT->Plvl3Lat; - } - } - - return_ACPI_STATUS(AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiHwGetCxHandler - * - * PARAMETERS: State - the Cx state - * Handler - pointer to location for the returned handler - * - * RETURN: Status of function - * - * DESCRIPTION: This function is called to get an installed Cx state handler. - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwGetCxHandler ( - UINT32 CxState, - ACPI_C_STATE_HANDLER *Handler) -{ - FUNCTION_TRACE ("HwGetCxHandler"); - - - if ((CxState == 0) || (CxState >= MAX_CX_STATES) || !Handler) - { - return_ACPI_STATUS(AE_BAD_PARAMETER); - } - - *Handler = AcpiHwCxHandlers[CxState]; - - return_ACPI_STATUS(AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiHwSetCxHandler - * - * PARAMETERS: CxState - the Cx state - * Handler - new Cx state handler - * - * RETURN: Status of function - * - * DESCRIPTION: This function is called to install a new Cx state handler. - * - ****************************************************************************/ - -ACPI_STATUS -AcpiHwSetCxHandler ( - UINT32 CxState, - ACPI_C_STATE_HANDLER Handler) -{ - FUNCTION_TRACE ("HwSetCxHandler"); - - - if ((CxState == 0) || (CxState >= MAX_CX_STATES) || !Handler) - { - return_ACPI_STATUS(AE_BAD_PARAMETER); - } - - AcpiHwCxHandlers[CxState] = Handler; - - return_ACPI_STATUS(AE_OK); -} - - -/************************************************************************** - * - * FUNCTION: AcpiHwLocalPow - * - * PARAMETERS: x,y operands - * - * RETURN: result - * - * DESCRIPTION: Compute x ^ y - * - *************************************************************************/ - -NATIVE_UINT -AcpiHwLocalPow ( - NATIVE_UINT x, - NATIVE_UINT y) -{ - NATIVE_UINT i; - NATIVE_UINT Result = 1; - - - for (i = 0; i < y; i++) - { - Result = Result * x; - } - - return (Result); -} - - -/************************************************************************** - * - * FUNCTION: AcpiHwEnableThrottling - * - * PARAMETERS: PblkAddress - Address of Pcnt (Processor Control) - * register - * - * RETURN: none - * - * DESCRIPTION: Enable throttling by setting the THT_EN bit. - * - *************************************************************************/ - -void -AcpiHwEnableThrottling ( - ACPI_IO_ADDRESS PblkAddress) -{ - UINT32 PblkValue; - - - FUNCTION_TRACE ("EnableThrottling"); - - - PblkValue = AcpiOsIn32 (PblkAddress); - PblkValue = PblkValue | BIT_4; - AcpiOsOut32 (PblkAddress, PblkValue); - - return_VOID; -} - - -/************************************************************************** - * - * FUNCTION: AcpiHwDisableThrottling - * - * PARAMETERS: PblkAddress - Address of Pcnt (Processor Control) - * register - * - * RETURN: none - * - * DESCRIPTION:Disable throttling by clearing the THT_EN bit - * - *************************************************************************/ - -void -AcpiHwDisableThrottling ( - ACPI_IO_ADDRESS PblkAddress) -{ - UINT32 PblkValue; - - - FUNCTION_TRACE ("DisableThrottling"); - - - PblkValue = AcpiOsIn32 (PblkAddress); - PblkValue = PblkValue & (~(UINT32)BIT_4); - AcpiOsOut32 (PblkAddress, PblkValue); - - return_VOID; -} - - -/************************************************************************** - * - * FUNCTION: AcpiHwGetDutyCycle - * - * PARAMETERS: DutyOffset Pcnt register duty cycle field offset - * PblkAddress Pcnt register address in chipset - * NumThrottleStates # of CPU throttle states this system - * supports - * - * RETURN: none - * - * DESCRIPTION: Get the duty cycle from the chipset - * - *************************************************************************/ - -UINT32 -AcpiHwGetDutyCycle ( - UINT8 DutyOffset, - ACPI_IO_ADDRESS PblkAddress, - UINT32 NumThrottleStates) -{ - NATIVE_UINT Index; - UINT32 Duty32Value; - UINT32 PcntMaskOffDutyField; - - - FUNCTION_TRACE ("GetDutyCycle"); - - - /* - * Use NumThrottleStates - 1 as mask [ex. 8 - 1 = 7 (Fh)] - * and then shift it into the right position - */ - PcntMaskOffDutyField = NumThrottleStates - 1; - - /* - * Read in the current value from the port - */ - Duty32Value = AcpiOsIn32 ((ACPI_IO_ADDRESS) PblkAddress); - - /* - * Shift the the value to LSB - */ - for (Index = 0; Index < (NATIVE_UINT) DutyOffset; Index++) - { - Duty32Value = Duty32Value >> 1; - } - - /* - * Get the duty field only - */ - Duty32Value = Duty32Value & PcntMaskOffDutyField; - - return_VALUE ((UINT32) Duty32Value); -} - - -/************************************************************************** - * - * FUNCTION: AcpiHwProgramDutyCycle - * - * PARAMETERS: DutyOffset Pcnt register duty cycle field offset - * DutyCycle duty cycle to program into chipset - * PblkAddress Pcnt register address in chipset - * NumThrottleStates # of CPU throttle states this system - * supports - * - * RETURN: none - * - * DESCRIPTION: Program chipset with specified duty cycle by bit-shifting the - * duty cycle bits to the appropriate offset, reading the duty - * cycle register, OR-ing in the duty cycle, and writing it to - * the Pcnt register. - * - *************************************************************************/ - -void -AcpiHwProgramDutyCycle ( - UINT8 DutyOffset, - UINT32 DutyCycle, - ACPI_IO_ADDRESS PblkAddress, - UINT32 NumThrottleStates) -{ - NATIVE_UINT Index; - UINT32 Duty32Value; - UINT32 PcntMaskOffDutyField; - UINT32 PortValue; - - - FUNCTION_TRACE ("HwProgramDutyCycle"); - - - /* - * valid DutyCycle passed - */ - Duty32Value = DutyCycle; - - /* - * use NumThrottleStates - 1 as mask [ex. 8 - 1 = 7 (Fh)] - * and then shift it into the right position - */ - PcntMaskOffDutyField = NumThrottleStates - 1; - - /* - * Shift the mask - */ - for (Index = 0; Index < (NATIVE_UINT) DutyOffset; Index++) - { - PcntMaskOffDutyField = PcntMaskOffDutyField << 1; - Duty32Value = Duty32Value << 1; - } - - /* - * Read in the current value from the port - */ - PortValue = AcpiOsIn32 ((ACPI_IO_ADDRESS) PblkAddress); - - /* - * Mask off the duty field so we don't OR in junk! - */ - PortValue = PortValue & (~PcntMaskOffDutyField); - - /* - * OR in the bits we want to write out to the port - */ - PortValue = (PortValue | Duty32Value) & (~(UINT32)BIT_4); - - /* - * write it to the port - */ - AcpiOsOut32 ((ACPI_IO_ADDRESS) PblkAddress, PortValue); - - return_VOID; -} diff --git a/sys/contrib/dev/acpica/Subsystem/Hardware/hwxface.c b/sys/contrib/dev/acpica/Subsystem/Hardware/hwxface.c deleted file mode 100644 index 3bece9a..0000000 --- a/sys/contrib/dev/acpica/Subsystem/Hardware/hwxface.c +++ /dev/null @@ -1,737 +0,0 @@ - -/****************************************************************************** - * - * Name: hwxface.c - Hardware access external interfaces - * $Revision: 37 $ - * - *****************************************************************************/ - -/****************************************************************************** - * - * 1. Copyright Notice - * - * Some or all of this work - Copyright (c) 1999, 2000, Intel Corp. - * All rights reserved. - * - * 2. License - * - * 2.1. This is your license from Intel Corp. under its intellectual property - * rights. You may have additional license terms from the party that provided - * you this software, covering your right to use that party's intellectual - * property rights. - * - * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a - * copy of the source code appearing in this file ("Covered Code") an - * irrevocable, perpetual, worldwide license under Intel's copyrights in the - * base code distributed originally by Intel ("Original Intel Code") to copy, - * make derivatives, distribute, use and display any portion of the Covered - * Code in any form, with the right to sublicense such rights; and - * - * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent - * license (with the right to sublicense), under only those claims of Intel - * patents that are infringed by the Original Intel Code, to make, use, sell, - * offer to sell, and import the Covered Code and derivative works thereof - * solely to the minimum extent necessary to exercise the above copyright - * license, and in no event shall the patent license extend to any additions - * to or modifications of the Original Intel Code. No other license or right - * is granted directly or by implication, estoppel or otherwise; - * - * The above copyright and patent license is granted only if the following - * conditions are met: - * - * 3. Conditions - * - * 3.1. Redistribution of Source with Rights to Further Distribute Source. - * Redistribution of source code of any substantial portion of the Covered - * Code or modification with rights to further distribute source must include - * the above Copyright Notice, the above License, this list of Conditions, - * and the following Disclaimer and Export Compliance provision. In addition, - * Licensee must cause all Covered Code to which Licensee contributes to - * contain a file documenting the changes Licensee made to create that Covered - * Code and the date of any change. Licensee must include in that file the - * documentation of any changes made by any predecessor Licensee. Licensee - * must include a prominent statement that the modification is derived, - * directly or indirectly, from Original Intel Code. - * - * 3.2. Redistribution of Source with no Rights to Further Distribute Source. - * Redistribution of source code of any substantial portion of the Covered - * Code or modification without rights to further distribute source must - * include the following Disclaimer and Export Compliance provision in the - * documentation and/or other materials provided with distribution. In - * addition, Licensee may not authorize further sublicense of source of any - * portion of the Covered Code, and must include terms to the effect that the - * license from Licensee to its licensee is limited to the intellectual - * property embodied in the software Licensee provides to its licensee, and - * not to intellectual property embodied in modifications its licensee may - * make. - * - * 3.3. Redistribution of Executable. Redistribution in executable form of any - * substantial portion of the Covered Code or modification must reproduce the - * above Copyright Notice, and the following Disclaimer and Export Compliance - * provision in the documentation and/or other materials provided with the - * distribution. - * - * 3.4. Intel retains all right, title, and interest in and to the Original - * Intel Code. - * - * 3.5. Neither the name Intel nor any other trademark owned or controlled by - * Intel shall be used in advertising or otherwise to promote the sale, use or - * other dealings in products derived from or relating to the Covered Code - * without prior written authorization from Intel. - * - * 4. Disclaimer and Export Compliance - * - * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED - * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE - * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, - * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY - * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY - * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A - * PARTICULAR PURPOSE. - * - * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES - * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR - * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, - * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY - * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL - * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS - * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY - * LIMITED REMEDY. - * - * 4.3. Licensee shall not export, either directly or indirectly, any of this - * software or system incorporating such software without first obtaining any - * required license or other approval from the U. S. Department of Commerce or - * any other agency or department of the United States Government. In the - * event Licensee exports any such software from the United States or - * re-exports any such software from a foreign destination, Licensee shall - * ensure that the distribution and export/re-export of the software is in - * compliance with all laws, regulations, orders, or other restrictions of the - * U.S. Export Administration Regulations. Licensee agrees that neither it nor - * any of its subsidiaries will export/re-export any technical data, process, - * software, or service, directly or indirectly, to any country for which the - * United States government or any agency thereof requires an export license, - * other governmental approval, or letter of assurance, without first obtaining - * such license, approval or letter. - * - *****************************************************************************/ - -#include "acpi.h" -#include "acnamesp.h" -#include "achware.h" - -#define _COMPONENT HARDWARE - MODULE_NAME ("hwxface") - - -/****************************************************************************** - * - * Hardware globals - * - ******************************************************************************/ - - -ACPI_C_STATE_HANDLER AcpiHwCxHandlers[MAX_CX_STATES] = - {NULL, AcpiHwEnterC1, NULL, NULL}; - -UINT32 AcpiHwActiveCxState = 1; - - -/**************************************************************************** - * - * FUNCTION: AcpiGetProcessorThrottlingInfo - * - * PARAMETERS: ProcessorHandle - handle for the cpu to get info about - * UserBuffer - caller supplied buffer - * - * RETURN: Status of function - * - * DESCRIPTION: Get throttling capabilities for the processor, this routine - * builds the data directly into the callers buffer - * - ****************************************************************************/ - -ACPI_STATUS -AcpiGetProcessorThrottlingInfo ( - ACPI_HANDLE ProcessorHandle, - ACPI_BUFFER *UserBuffer) -{ - NATIVE_UINT PercentStep; - NATIVE_UINT NextPercent; - NATIVE_UINT NumThrottleStates; - NATIVE_UINT BufferSpaceNeeded; - NATIVE_UINT i; - UINT8 DutyWidth; - ACPI_NAMESPACE_NODE *CpuNode; - ACPI_OPERAND_OBJECT *CpuObj; - ACPI_CPU_THROTTLING_STATE *StatePtr; - - - FUNCTION_TRACE ("AcpiGetProcessorThrottlingInfo"); - - - /* - * Have to at least have a buffer to return info in - */ - if (!UserBuffer) - { - return_ACPI_STATUS(AE_BAD_PARAMETER); - } - - /* - * Convert and validate the device handle - */ - - CpuNode = AcpiNsConvertHandleToEntry (ProcessorHandle); - if (!CpuNode) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } - - /* - * Check for an existing internal object - */ - - CpuObj = AcpiNsGetAttachedObject ((ACPI_HANDLE) CpuNode); - if (!CpuObj) - { - return_ACPI_STATUS (AE_NOT_FOUND); - } - - /* - * (Duty Width on IA-64 is zero) - */ - DutyWidth = AcpiGbl_FADT->DutyWidth; - - /* - * P0 must always have a P_BLK all others may be null - * in either case, we can't throttle a processor that has no P_BLK - * - * Also if no Duty width, one state and it is 100% - * - */ - if (!CpuObj->Processor.Length || !DutyWidth || - (ACPI_UINT16_MAX < CpuObj->Processor.Address)) - { - /* - * AcpiEven though we can't throttle, we still have one state (100%) - */ - NumThrottleStates = 1; - } - - else - { - NumThrottleStates = (int) AcpiHwLocalPow (2,DutyWidth); - } - - BufferSpaceNeeded = NumThrottleStates * sizeof (ACPI_CPU_THROTTLING_STATE); - - if ((UserBuffer->Length < BufferSpaceNeeded) || !UserBuffer->Pointer) - { - UserBuffer->Length = BufferSpaceNeeded; - return_ACPI_STATUS (AE_BUFFER_OVERFLOW); - } - - UserBuffer->Length = BufferSpaceNeeded; - StatePtr = (ACPI_CPU_THROTTLING_STATE *) UserBuffer->Pointer; - PercentStep = 1000 / NumThrottleStates; - - /* - * Build each entry in the buffer. Note that we're using the value - * 1000 and dividing each state by 10 to better avoid round-off - * accumulation. Also note that the throttling STATES are ordered - * sequentially from 100% (state 0) on down (e.g. 87.5% = state 1), - * which is exactly opposite from duty cycle values (12.5% = state 1). - */ - for (i = 0, NextPercent = 1000; i < NumThrottleStates; i++) - { - StatePtr[i].StateNumber = i; - StatePtr[i].PercentOfClock = NextPercent / 10; - NextPercent -= PercentStep; - } - - return_ACPI_STATUS(AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiGetProcessorThrottlingState - * - * PARAMETERS: ProcessorHandle - handle for the cpu to throttle - * ThrottleState - throttling state to enter - * - * RETURN: Status of function - * - * DESCRIPTION: Get current hardware throttling state - * - ****************************************************************************/ - -ACPI_STATUS -AcpiGetProcessorThrottlingState ( - ACPI_HANDLE ProcessorHandle, - UINT32 *ThrottleState) -{ - ACPI_NAMESPACE_NODE *CpuNode; - ACPI_OPERAND_OBJECT *CpuObj; - UINT32 NumThrottleStates; - UINT32 DutyCycle; - UINT8 DutyOffset; - UINT8 DutyWidth; - - - FUNCTION_TRACE ("AcpiGetProcessorThrottlingState"); - - - /* Convert and validate the device handle */ - - CpuNode = AcpiNsConvertHandleToEntry (ProcessorHandle); - if (!CpuNode || !ThrottleState) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } - - /* Check for an existing internal object */ - - CpuObj = AcpiNsGetAttachedObject ((ACPI_HANDLE) CpuNode); - if (!CpuObj) - { - return_ACPI_STATUS (AE_NOT_FOUND); - } - - /* - * No Duty fields in IA64 tables - */ - DutyOffset = AcpiGbl_FADT->DutyOffset; - DutyWidth = AcpiGbl_FADT->DutyWidth; - - /* - * Must have a valid P_BLK P0 must have a P_BLK all others may be null - * in either case, we can't thottle a processor that has no P_BLK - * that means we are in the only supported state (0 - 100%) - * - * also, if DutyWidth is zero there are no additional states - */ - if (!CpuObj->Processor.Length || !DutyWidth || - (ACPI_UINT16_MAX < CpuObj->Processor.Address)) - { - *ThrottleState = 0; - return_ACPI_STATUS(AE_OK); - } - - NumThrottleStates = (UINT32) AcpiHwLocalPow (2,DutyWidth); - - /* - * Get the current duty cycle value. - */ - DutyCycle = AcpiHwGetDutyCycle (DutyOffset, - CpuObj->Processor.Address, - NumThrottleStates); - - /* - * Convert duty cycle to throttling state (invert). - */ - if (DutyCycle == 0) - { - *ThrottleState = 0; - } - - else - { - *ThrottleState = NumThrottleStates - DutyCycle; - } - - return_ACPI_STATUS(AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiSetProcessorThrottlingState - * - * PARAMETERS: ProcessorHandle - handle for the cpu to throttle - * ThrottleState - throttling state to enter - * - * RETURN: Status of function - * - * DESCRIPTION: Set hardware into requested throttling state, the handle - * passed in must have a valid P_BLK - * - ****************************************************************************/ - -ACPI_STATUS -AcpiSetProcessorThrottlingState ( - ACPI_HANDLE ProcessorHandle, - UINT32 ThrottleState) -{ - ACPI_NAMESPACE_NODE *CpuNode; - ACPI_OPERAND_OBJECT *CpuObj; - UINT32 NumThrottleStates = 0; - UINT8 DutyOffset; - UINT8 DutyWidth; - UINT32 DutyCycle = 0; - - - FUNCTION_TRACE ("AcpiSetProcessorThrottlingState"); - - - /* Convert and validate the device handle */ - - CpuNode = AcpiNsConvertHandleToEntry (ProcessorHandle); - if (!CpuNode) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } - - /* Check for an existing internal object */ - - CpuObj = AcpiNsGetAttachedObject ((ACPI_HANDLE) CpuNode); - if (!CpuObj) - { - return_ACPI_STATUS (AE_NOT_FOUND); - } - - /* - * No Duty fields in IA64 tables - */ - DutyOffset = AcpiGbl_FADT->DutyOffset; - DutyWidth = AcpiGbl_FADT->DutyWidth; - - /* - * Must have a valid P_BLK P0 must have a P_BLK all others may be null - * in either case, we can't thottle a processor that has no P_BLK - * that means we are in the only supported state (0 - 100%) - * - * also, if DutyWidth is zero there are no additional states - */ - if (!CpuObj->Processor.Length || !DutyWidth || - (ACPI_UINT16_MAX < CpuObj->Processor.Address)) - { - /* - * If caller wants to set the state to the only state we handle - * we're done. - */ - if (ThrottleState == 0) - { - return_ACPI_STATUS (AE_OK); - } - - /* - * Can't set this state - */ - return_ACPI_STATUS (AE_SUPPORT); - } - - NumThrottleStates = (UINT32) AcpiHwLocalPow (2,DutyWidth); - - /* - * Convert throttling state to duty cycle (invert). - */ - if (ThrottleState > 0) - { - DutyCycle = NumThrottleStates - ThrottleState; - } - - /* - * Turn off throttling (don't muck with the h/w while throttling). - */ - AcpiHwDisableThrottling (CpuObj->Processor.Address); - - /* - * Program the throttling state. - */ - AcpiHwProgramDutyCycle (DutyOffset, DutyCycle, - CpuObj->Processor.Address, NumThrottleStates); - - /* - * Only enable throttling for non-zero states (0 - 100%) - */ - if (ThrottleState) - { - AcpiHwEnableThrottling (CpuObj->Processor.Address); - } - - return_ACPI_STATUS(AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiGetProcessorCxInfo - * - * PARAMETERS: ProcessorHandle - handle for the cpu return info about - * UserBuffer - caller supplied buffer - * - * RETURN: Status of function - * - * DESCRIPTION: Get Cx state latencies, this routine - * builds the data directly into the callers buffer - * - * - ****************************************************************************/ - -ACPI_STATUS -AcpiGetProcessorCxInfo ( - ACPI_HANDLE ProcessorHandle, - ACPI_BUFFER *UserBuffer) -{ - ACPI_STATUS Status = AE_OK; - UINT32 CxStateLatencies[4] = {0, 0, 0, 0}; - NATIVE_UINT BufferSpaceNeeded = 0; - ACPI_CX_STATE *StatePtr = NULL; - NATIVE_UINT i = 0; - - - FUNCTION_TRACE ("AcpiGetProcessorCxInfo"); - - - /* - * Have to at least have a buffer to return info in - */ - if (!UserBuffer) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } - - Status = AcpiHwGetCxInfo (CxStateLatencies); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } - - BufferSpaceNeeded = 4 * sizeof (ACPI_CX_STATE); - - if ((UserBuffer->Length < BufferSpaceNeeded) || !UserBuffer->Pointer) - { - UserBuffer->Length = BufferSpaceNeeded; - return_ACPI_STATUS (AE_BUFFER_OVERFLOW); - } - - UserBuffer->Length = BufferSpaceNeeded; - - StatePtr = (ACPI_CX_STATE *) UserBuffer->Pointer; - - for (i = 0; i < 4; i++) - { - StatePtr[i].StateNumber = i; - StatePtr[i].Latency = CxStateLatencies[i]; - } - - return_ACPI_STATUS (AE_OK); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiSetProcessorSleepState - * - * PARAMETERS: ProcessorHandle - handle for the cpu return info about - * CxState - the Cx sleeping state (C1-C3) to make - * 'active' - * - * RETURN: Status of function - * - * DESCRIPTION: Sets which Cx state will be used during calls to - * AcpiProcessorSleep () - * - ****************************************************************************/ - -ACPI_STATUS -AcpiSetProcessorSleepState ( - ACPI_HANDLE ProcessorHandle, - UINT32 CxState) -{ - ACPI_STATUS Status; - - - FUNCTION_TRACE ("AcpiSetProcessorSleepState"); - - - Status = AcpiHwSetCx (CxState); - - return_ACPI_STATUS (Status); -} - - -/**************************************************************************** - * - * FUNCTION: AcpiProcessorSleep - * - * PARAMETERS: ProcessorHandle - handle for the cpu to put to sleep (Cx) - * TimeSleeping - time (in microseconds) elapsed while - * sleeping - * - * RETURN: Status of function - * - * DESCRIPTION: Puts the processor into the currently active sleep state (Cx) - * - ****************************************************************************/ - -ACPI_STATUS -AcpiProcessorSleep ( - ACPI_HANDLE ProcessorHandle, - UINT32 *PmTimerTicks) -{ - ACPI_NAMESPACE_NODE *CpuNode = NULL; - ACPI_OPERAND_OBJECT *CpuObj = NULL; - ACPI_IO_ADDRESS Address = 0; - - - /* - * Convert ProcessorHandle to PblkAddres... - */ - - /* Convert and validate the device handle */ - - CpuNode = AcpiNsConvertHandleToEntry (ProcessorHandle); - if (!CpuNode) - { - return (AE_BAD_PARAMETER); - } - - /* Check for an existing internal object */ - - CpuObj = AcpiNsGetAttachedObject ((ACPI_HANDLE) CpuNode); - if (!CpuObj) - { - return (AE_NOT_FOUND); - } - - /* Get the processor register block (P_BLK) address */ - - Address = CpuObj->Processor.Address; - if (!CpuObj->Processor.Length) - { - /* Ensure a NULL addresss (note that P_BLK isn't required for C1) */ - - Address = 0; - } - - /* - * Enter the currently active Cx sleep state. - */ - return (AcpiHwEnterCx (Address, PmTimerTicks)); -} - - -/****************************************************************************** - * - * FUNCTION: AcpiGetTimer - * - * PARAMETERS: none - * - * RETURN: Current value of the ACPI PMT (timer) - * - * DESCRIPTION: Obtains current value of ACPI PMT - * - ******************************************************************************/ - -ACPI_STATUS -AcpiGetTimer ( - UINT32 *OutTicks) -{ - FUNCTION_TRACE ("AcpiGetTimer"); - - - if (!OutTicks) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } - - *OutTicks = AcpiHwPmtTicks (); - - return_ACPI_STATUS (AE_OK); -} - - -/****************************************************************************** - * - * FUNCTION: AcpiSetFirmwareWakingVector - * - * PARAMETERS: PhysicalAddress - Physical address of ACPI real mode - * entry point. - * - * RETURN: AE_OK or AE_ERROR - * - * DESCRIPTION: Access function for dFirmwareWakingVector field in FACS - * - ******************************************************************************/ - -ACPI_STATUS -AcpiSetFirmwareWakingVector ( - ACPI_PHYSICAL_ADDRESS PhysicalAddress) -{ - - FUNCTION_TRACE ("AcpiSetFirmwareWakingVector"); - - - /* Make sure that we have an FACS */ - - if (!AcpiGbl_FACS) - { - return_ACPI_STATUS (AE_NO_ACPI_TABLES); - } - - /* Set the vector */ - - if (AcpiGbl_FACS->VectorWidth == 32) - { - * (UINT32 *) AcpiGbl_FACS->FirmwareWakingVector = (UINT32) PhysicalAddress; - } - else - { - *AcpiGbl_FACS->FirmwareWakingVector = PhysicalAddress; - } - - return_ACPI_STATUS (AE_OK); -} - - -/****************************************************************************** - * - * FUNCTION: AcpiGetFirmwareWakingVector - * - * PARAMETERS: *PhysicalAddress - Output buffer where contents of - * the FirmwareWakingVector field of - * the FACS will be stored. - * - * RETURN: Status - * - * DESCRIPTION: Access function for dFirmwareWakingVector field in FACS - * - ******************************************************************************/ - -ACPI_STATUS -AcpiGetFirmwareWakingVector ( - ACPI_PHYSICAL_ADDRESS *PhysicalAddress) -{ - - FUNCTION_TRACE ("AcpiGetFirmwareWakingVector"); - - - if (!PhysicalAddress) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } - - /* Make sure that we have an FACS */ - - if (!AcpiGbl_FACS) - { - return_ACPI_STATUS (AE_NO_ACPI_TABLES); - } - - /* Get the vector */ - - if (AcpiGbl_FACS->VectorWidth == 32) - { - *PhysicalAddress = * (UINT32 *) AcpiGbl_FACS->FirmwareWakingVector; - } - else - { - *PhysicalAddress = *AcpiGbl_FACS->FirmwareWakingVector; - } - - return_ACPI_STATUS (AE_OK); -} - - diff --git a/sys/contrib/dev/acpica/Subsystem/Include/acconfig.h b/sys/contrib/dev/acpica/Subsystem/Include/acconfig.h index b3c7ed6..0721500 100644 --- a/sys/contrib/dev/acpica/Subsystem/Include/acconfig.h +++ b/sys/contrib/dev/acpica/Subsystem/Include/acconfig.h @@ -189,13 +189,14 @@ #define DEBUGGER_SINGLE_THREADED 0 #define DEBUGGER_MULTI_THREADED 1 +#ifndef DEBUGGER_THREADING #ifdef ACPI_APPLICATION #define DEBUGGER_THREADING DEBUGGER_SINGLE_THREADED #else #define DEBUGGER_THREADING DEBUGGER_MULTI_THREADED #endif - +#endif /****************************************************************************** * diff --git a/sys/contrib/dev/acpica/Subsystem/Include/acfreebsd.h b/sys/contrib/dev/acpica/Subsystem/Include/acfreebsd.h index ca6c799..2d42e83 100644 --- a/sys/contrib/dev/acpica/Subsystem/Include/acfreebsd.h +++ b/sys/contrib/dev/acpica/Subsystem/Include/acfreebsd.h @@ -117,18 +117,82 @@ #ifndef __ACFREEBSD_H__ #define __ACFREEBSD_H__ +/* + * XXX this is technically correct, but will cause problems with some ASL + * which only works if the string names a Microsoft operating system. + */ #define ACPI_OS_NAME "FreeBSD" +/* FreeBSD uses GCC */ + +#include "acgcc.h" + #ifdef _KERNEL +#include "opt_acpi.h" /* collect build-time options here */ + #include <sys/ctype.h> #include <sys/param.h> #include <sys/systm.h> #include <sys/libkern.h> -#include <stdarg.h> +#include <machine/stdarg.h> #define asm __asm #define __cli() disable_intr() #define __sti() enable_intr() +#ifdef ACPI_DEBUG +#ifdef DEBUGGER_THREADING +#undef DEBUGGER_THREADING +#endif /* DEBUGGER_THREADING */ +#define DEBUGGER_THREADING 0 /* integrated with DDB */ +#include "opt_ddb.h" +#ifdef DDB +#define ENABLE_DEBUGGER +#endif /* DDB */ +#endif /* ACPI_DEBUG */ + +#else /* _KERNEL */ + +/* Not building kernel code, so use libc */ +#define ACPI_USE_STANDARD_HEADERS + +#endif /* _KERNEL */ + +/* Always use FreeBSD code over our local versions */ +#define ACPI_USE_SYSTEM_CLIBRARY + +/* FreeBSD doesn't have strupr, should be fixed. (move to libkern) */ +static __inline char * +strupr(char *str) +{ + char *c = str; + while(*c) { + *c = toupper(*c); + c++; + } + return(str); +} + +#ifdef _KERNEL +/* Or strstr (used in debugging mode, also move to libkern) */ +static __inline char * +strstr(char *s, char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while (sc != c); + } while (strncmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} +#endif /* _KERNEL */ #endif /* __ACFREEBSD_H__ */ diff --git a/sys/contrib/dev/acpica/Subsystem/Include/acgcc.h b/sys/contrib/dev/acpica/Subsystem/Include/acgcc.h index eb2f4ce..e486315 100644 --- a/sys/contrib/dev/acpica/Subsystem/Include/acgcc.h +++ b/sys/contrib/dev/acpica/Subsystem/Include/acgcc.h @@ -131,7 +131,9 @@ #define BREAKPOINT3 #define disable() __cli() #define enable() __sti() +#ifndef __FreeBSD__ /* XXX conflicts with inline in cpufunc.h */ #define wbinvd() +#endif /*! [Begin] no source code translation */ @@ -193,7 +195,9 @@ #define disable() __cli() #define enable() __sti() #define halt() __asm__ __volatile__ ("sti; hlt":::"memory") +#ifndef __FreeBSD__ /* XXX conflicts with inline in cpufunc.h */ #define wbinvd() +#endif /*! [Begin] no source code translation * diff --git a/sys/contrib/dev/acpica/Subsystem/Include/acpixf.h b/sys/contrib/dev/acpica/Subsystem/Include/acpixf.h index c33ca3f..5dd9c30 100644 --- a/sys/contrib/dev/acpica/Subsystem/Include/acpixf.h +++ b/sys/contrib/dev/acpica/Subsystem/Include/acpixf.h @@ -409,5 +409,8 @@ AcpiProcessorSleep ( ACPI_HANDLE ProcessorHandle, UINT32 *PmTimerTicks); +ACPI_STATUS +AcpiSetSystemSleepState ( + UINT8 SleepState); #endif /* __ACXFACE_H__ */ diff --git a/sys/contrib/dev/acpica/Subsystem/Parser/psparse.c b/sys/contrib/dev/acpica/Subsystem/Parser/psparse.c index 78443bc..1d44bd8 100644 --- a/sys/contrib/dev/acpica/Subsystem/Parser/psparse.c +++ b/sys/contrib/dev/acpica/Subsystem/Parser/psparse.c @@ -1235,6 +1235,7 @@ AcpiPsParseAml ( ACPI_NAMESPACE_NODE *Node = NULL; ACPI_WALK_LIST *PrevWalkList = AcpiGbl_CurrentWalkList; ACPI_OPERAND_OBJECT *ReturnDesc; + ACPI_OPERAND_OBJECT *EffectiveReturnDesc = NULL; ACPI_OPERAND_OBJECT *MthDesc = NULL; @@ -1376,6 +1377,14 @@ AcpiPsParseAml ( ReturnDesc = WalkState->ReturnDesc; + /* Save the last effective return value */ + + if (CallerReturnDesc && ReturnDesc) + { + EffectiveReturnDesc = ReturnDesc; + AcpiCmAddReference (EffectiveReturnDesc); + } + DEBUG_PRINT (TRACE_PARSE, ("PsParseAml: ReturnValue=%p, State=%p\n", WalkState->ReturnDesc, WalkState)); @@ -1424,6 +1433,16 @@ AcpiPsParseAml ( else if (CallerReturnDesc) { + /* + * Some AML code expects return value w/o ReturnOp. + * Return the saved effective return value instead. + */ + + if (ReturnDesc == NULL && EffectiveReturnDesc != NULL) + { + AcpiCmRemoveReference (ReturnDesc); + ReturnDesc = EffectiveReturnDesc; + } *CallerReturnDesc = ReturnDesc; /* NULL if no return value */ } diff --git a/sys/contrib/dev/acpica/acconfig.h b/sys/contrib/dev/acpica/acconfig.h index 8683e86e..0721500 100644 --- a/sys/contrib/dev/acpica/acconfig.h +++ b/sys/contrib/dev/acpica/acconfig.h @@ -1,7 +1,7 @@ /****************************************************************************** * * Name: acconfig.h - Global configuration constants - * $Revision: 64 $ + * $Revision: 55 $ * *****************************************************************************/ @@ -144,7 +144,7 @@ /* Version string */ -#define ACPI_CA_VERSION 0x20010518 +#define ACPI_CA_VERSION 0x20010208 /* Maximum objects in the various object caches */ @@ -180,7 +180,7 @@ /* * Debugger threading model * Use single threaded if the entire subsystem is contained in an application - * Use multiple threaded when the subsystem is running in the kernel. + * Use multiple threaded when the the subsystem is running in the kernel. * * By default the model is single threaded if ACPI_APPLICATION is set, * multi-threaded if ACPI_APPLICATION is not set. @@ -189,13 +189,14 @@ #define DEBUGGER_SINGLE_THREADED 0 #define DEBUGGER_MULTI_THREADED 1 +#ifndef DEBUGGER_THREADING #ifdef ACPI_APPLICATION #define DEBUGGER_THREADING DEBUGGER_SINGLE_THREADED #else #define DEBUGGER_THREADING DEBUGGER_MULTI_THREADED #endif - +#endif /****************************************************************************** * @@ -239,11 +240,6 @@ #define HI_RSDP_WINDOW_SIZE 0x20000 #define RSDP_SCAN_STEP 16 -/* Maximum SpaceIds for Operation Regions */ - -#define ACPI_MAX_ADDRESS_SPACE 255 -#define ACPI_NUM_ADDRESS_SPACES 256 - #endif /* _ACCONFIG_H */ diff --git a/sys/contrib/dev/acpica/acfreebsd.h b/sys/contrib/dev/acpica/acfreebsd.h index 894af50..2d42e83 100644 --- a/sys/contrib/dev/acpica/acfreebsd.h +++ b/sys/contrib/dev/acpica/acfreebsd.h @@ -1,7 +1,7 @@ /****************************************************************************** * * Name: acfreebsd.h - OS specific defines, etc. - * $Revision: 6 $ + * $Revision: 4 $ * *****************************************************************************/ @@ -128,6 +128,8 @@ #include "acgcc.h" #ifdef _KERNEL +#include "opt_acpi.h" /* collect build-time options here */ + #include <sys/ctype.h> #include <sys/param.h> #include <sys/systm.h> @@ -142,7 +144,7 @@ #ifdef DEBUGGER_THREADING #undef DEBUGGER_THREADING #endif /* DEBUGGER_THREADING */ -#define DEBUGGER_THREADING 0 /* integrated with DDB */ +#define DEBUGGER_THREADING 0 /* integrated with DDB */ #include "opt_ddb.h" #ifdef DDB #define ENABLE_DEBUGGER @@ -154,9 +156,6 @@ /* Not building kernel code, so use libc */ #define ACPI_USE_STANDARD_HEADERS -#define __cli() -#define __sti() - #endif /* _KERNEL */ /* Always use FreeBSD code over our local versions */ @@ -168,8 +167,8 @@ strupr(char *str) { char *c = str; while(*c) { - *c = toupper(*c); - c++; + *c = toupper(*c); + c++; } return(str); } @@ -183,14 +182,14 @@ strstr(char *s, char *find) size_t len; if ((c = *find++) != 0) { - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while (sc != c); - } while (strncmp(s, find, len) != 0); - s--; + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while (sc != c); + } while (strncmp(s, find, len) != 0); + s--; } return ((char *)s); } diff --git a/sys/contrib/dev/acpica/acgcc.h b/sys/contrib/dev/acpica/acgcc.h index c426663..e486315 100644 --- a/sys/contrib/dev/acpica/acgcc.h +++ b/sys/contrib/dev/acpica/acgcc.h @@ -1,7 +1,7 @@ /****************************************************************************** * * Name: acgcc.h - GCC specific defines, etc. - * $Revision: 6 $ + * $Revision: 5 $ * *****************************************************************************/ @@ -118,6 +118,7 @@ #define __ACGCC_H__ + #ifdef __ia64__ #define _IA64 @@ -130,7 +131,9 @@ #define BREAKPOINT3 #define disable() __cli() #define enable() __sti() +#ifndef __FreeBSD__ /* XXX conflicts with inline in cpufunc.h */ #define wbinvd() +#endif /*! [Begin] no source code translation */ @@ -192,7 +195,9 @@ #define disable() __cli() #define enable() __sti() #define halt() __asm__ __volatile__ ("sti; hlt":::"memory") +#ifndef __FreeBSD__ /* XXX conflicts with inline in cpufunc.h */ #define wbinvd() +#endif /*! [Begin] no source code translation * diff --git a/sys/contrib/dev/acpica/acpixf.h b/sys/contrib/dev/acpica/acpixf.h index 84ec9a2..5dd9c30 100644 --- a/sys/contrib/dev/acpica/acpixf.h +++ b/sys/contrib/dev/acpica/acpixf.h @@ -121,7 +121,6 @@ #include "actypes.h" #include "actbl.h" - /* * Global interfaces */ @@ -157,23 +156,6 @@ AcpiFormatException ( /* - * ACPI Memory manager - */ - -void * -AcpiAllocate ( - UINT32 Size); - -void * -AcpiCallocate ( - UINT32 Size); - -void -AcpiFree ( - void *Address); - - -/* * ACPI table manipulation interfaces */ @@ -215,14 +197,14 @@ AcpiWalkNamespace ( ACPI_OBJECT_TYPE Type, ACPI_HANDLE StartObject, UINT32 MaxDepth, - ACPI_WALK_CALLBACK UserFunction, + WALK_CALLBACK UserFunction, void *Context, void * *ReturnValue); ACPI_STATUS AcpiGetDevices ( NATIVE_CHAR *HID, - ACPI_WALK_CALLBACK UserFunction, + WALK_CALLBACK UserFunction, void *Context, void **ReturnValue); @@ -274,52 +256,52 @@ AcpiGetParent ( /* - * Event handler interfaces + * AcpiEvent handler interfaces */ ACPI_STATUS AcpiInstallFixedEventHandler ( UINT32 AcpiEvent, - ACPI_EVENT_HANDLER Handler, + FIXED_EVENT_HANDLER Handler, void *Context); ACPI_STATUS AcpiRemoveFixedEventHandler ( UINT32 AcpiEvent, - ACPI_EVENT_HANDLER Handler); + FIXED_EVENT_HANDLER Handler); ACPI_STATUS AcpiInstallNotifyHandler ( ACPI_HANDLE Device, UINT32 HandlerType, - ACPI_NOTIFY_HANDLER Handler, + NOTIFY_HANDLER Handler, void *Context); ACPI_STATUS AcpiRemoveNotifyHandler ( ACPI_HANDLE Device, UINT32 HandlerType, - ACPI_NOTIFY_HANDLER Handler); + NOTIFY_HANDLER Handler); ACPI_STATUS AcpiInstallAddressSpaceHandler ( ACPI_HANDLE Device, - ACPI_ADR_SPACE_TYPE SpaceId, - ACPI_ADR_SPACE_HANDLER Handler, - ACPI_ADR_SPACE_SETUP Setup, + ACPI_ADDRESS_SPACE_TYPE SpaceId, + ADDRESS_SPACE_HANDLER Handler, + ADDRESS_SPACE_SETUP Setup, void *Context); ACPI_STATUS AcpiRemoveAddressSpaceHandler ( ACPI_HANDLE Device, - ACPI_ADR_SPACE_TYPE SpaceId, - ACPI_ADR_SPACE_HANDLER Handler); + ACPI_ADDRESS_SPACE_TYPE SpaceId, + ADDRESS_SPACE_HANDLER Handler); ACPI_STATUS AcpiInstallGpeHandler ( UINT32 GpeNumber, UINT32 Type, - ACPI_GPE_HANDLER Handler, + GPE_HANDLER Handler, void *Context); ACPI_STATUS @@ -333,7 +315,7 @@ AcpiReleaseGlobalLock ( ACPI_STATUS AcpiRemoveGpeHandler ( UINT32 GpeNumber, - ACPI_GPE_HANDLER Handler); + GPE_HANDLER Handler); ACPI_STATUS AcpiEnableEvent ( @@ -427,5 +409,8 @@ AcpiProcessorSleep ( ACPI_HANDLE ProcessorHandle, UINT32 *PmTimerTicks); +ACPI_STATUS +AcpiSetSystemSleepState ( + UINT8 SleepState); #endif /* __ACXFACE_H__ */ diff --git a/sys/contrib/dev/acpica/exfldio.c b/sys/contrib/dev/acpica/exfldio.c index 96f3227..24c9a2a 100644 --- a/sys/contrib/dev/acpica/exfldio.c +++ b/sys/contrib/dev/acpica/exfldio.c @@ -1,7 +1,7 @@ /****************************************************************************** * - * Module Name: exfldio - Aml Field I/O - * $Revision: 57 $ + * Module Name: amfldio - Aml Field I/O + * $Revision: 39 $ * *****************************************************************************/ @@ -115,7 +115,7 @@ *****************************************************************************/ -#define __EXFLDIO_C__ +#define __AMFLDIO_C__ #include "acpi.h" #include "acinterp.h" @@ -123,324 +123,116 @@ #include "acnamesp.h" #include "achware.h" #include "acevents.h" -#include "acdispat.h" -#define _COMPONENT ACPI_EXECUTER - MODULE_NAME ("exfldio") +#define _COMPONENT INTERPRETER + MODULE_NAME ("amfldio") /******************************************************************************* * - * FUNCTION: AcpiExSetupField + * FUNCTION: AcpiAmlReadFieldData * - * PARAMETERS: *ObjDesc - Field to be read or written - * FieldDatumByteOffset - Current offset into the field + * PARAMETERS: *ObjDesc - Field to be read + * *Value - Where to store value + * FieldBitWidth - Field Width in bits (8, 16, or 32) * * RETURN: Status * - * DESCRIPTION: Common processing for AcpiExExtractFromField and - * AcpiExInsertIntoField + * DESCRIPTION: Retrieve the value of the given field * ******************************************************************************/ ACPI_STATUS -AcpiExSetupField ( +AcpiAmlReadFieldData ( ACPI_OPERAND_OBJECT *ObjDesc, - UINT32 FieldDatumByteOffset) + UINT32 FieldByteOffset, + UINT32 FieldBitWidth, + UINT32 *Value) { - ACPI_STATUS Status = AE_OK; - ACPI_OPERAND_OBJECT *RgnDesc; - - - FUNCTION_TRACE ("ExSetupField"); - + ACPI_STATUS Status; + ACPI_OPERAND_OBJECT *RgnDesc = NULL; + ACPI_PHYSICAL_ADDRESS Address; + UINT32 LocalValue = 0; + UINT32 FieldByteWidth; - /* Parameter validation */ - RgnDesc = ObjDesc->CommonField.RegionObj; - if (!ObjDesc || !RgnDesc) - { - DEBUG_PRINTP (ACPI_ERROR, ("Internal error - null handle\n")); - return_ACPI_STATUS (AE_AML_NO_OPERAND); - } + FUNCTION_TRACE ("AmlReadFieldData"); - if (ACPI_TYPE_REGION != RgnDesc->Common.Type) - { - DEBUG_PRINTP (ACPI_ERROR, ("Needed Region, found type %x %s\n", - RgnDesc->Common.Type, AcpiUtGetTypeName (RgnDesc->Common.Type))); - return_ACPI_STATUS (AE_AML_OPERAND_TYPE); - } + /* ObjDesc is validated by callers */ - /* - * If the Region Address and Length have not been previously evaluated, - * evaluate them now and save the results. - */ - if (!(RgnDesc->Region.Flags & AOPOBJ_DATA_VALID)) + if (ObjDesc) { - - Status = AcpiDsGetRegionArguments (RgnDesc); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } + RgnDesc = ObjDesc->Field.Container; } - /* - * Validate the request. The entire request from the byte offset for a - * length of one field datum (access width) must fit within the region. - * (Region length is specified in bytes) - */ - if (RgnDesc->Region.Length < (ObjDesc->CommonField.BaseByteOffset + - FieldDatumByteOffset + - ObjDesc->CommonField.AccessByteWidth)) + FieldByteWidth = DIV_8 (FieldBitWidth); + Status = AcpiAmlSetupField (ObjDesc, RgnDesc, FieldBitWidth); + if (ACPI_FAILURE (Status)) { - if (RgnDesc->Region.Length < ObjDesc->CommonField.AccessByteWidth) - { - /* - * This is the case where the AccessType (AccWord, etc.) is wider - * than the region itself. For example, a region of length one - * byte, and a field with Dword access specified. - */ - DEBUG_PRINTP (ACPI_ERROR, - ("Field access width (%d bytes) too large for region size (%X)\n", - ObjDesc->CommonField.AccessByteWidth, RgnDesc->Region.Length)); - } - - /* - * Offset rounded up to next multiple of field width - * exceeds region length, indicate an error - */ - DEBUG_PRINTP (ACPI_ERROR, - ("Field base+offset+width %X+%X+%X exceeds region size (%X bytes) field=%p region=%p\n", - ObjDesc->CommonField.BaseByteOffset, FieldDatumByteOffset, - ObjDesc->CommonField.AccessByteWidth, - RgnDesc->Region.Length, ObjDesc, RgnDesc)); - - return_ACPI_STATUS (AE_AML_REGION_LIMIT); + return_ACPI_STATUS (Status); } - return_ACPI_STATUS (AE_OK); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiExReadFieldDatum - * - * PARAMETERS: *ObjDesc - Field to be read - * *Value - Where to store value (must be 32 bits) - * - * RETURN: Status - * - * DESCRIPTION: Retrieve the value of the given field - * - ******************************************************************************/ - -ACPI_STATUS -AcpiExReadFieldDatum ( - ACPI_OPERAND_OBJECT *ObjDesc, - UINT32 FieldDatumByteOffset, - UINT32 *Value) -{ - ACPI_STATUS Status; - ACPI_OPERAND_OBJECT *RgnDesc; - ACPI_PHYSICAL_ADDRESS Address; - UINT32 LocalValue; - - - FUNCTION_TRACE_U32 ("ExReadFieldDatum", FieldDatumByteOffset); - + /* SetupField validated RgnDesc and FieldBitWidth */ if (!Value) { - LocalValue = 0; Value = &LocalValue; /* support reads without saving value */ } - /* Clear the entire return buffer first, [Very Important!] */ - - *Value = 0; - /* - * BufferFields - Read from a Buffer - * Other Fields - Read from a Operation Region. + * Set offset to next multiple of field width, + * add region base address and offset within the field */ - switch (ObjDesc->Common.Type) - { - case ACPI_TYPE_BUFFER_FIELD: - - /* - * For BufferFields, we only need to copy the data from the - * source buffer. Length is the field width in bytes. - */ - MEMCPY (Value, (ObjDesc->BufferField.BufferObj)->Buffer.Pointer - + ObjDesc->BufferField.BaseByteOffset + FieldDatumByteOffset, - ObjDesc->CommonField.AccessByteWidth); - Status = AE_OK; - break; - - - case INTERNAL_TYPE_REGION_FIELD: - case INTERNAL_TYPE_BANK_FIELD: + Address = RgnDesc->Region.Address + + (ObjDesc->Field.Offset * FieldByteWidth) + + FieldByteOffset; - /* - * For other fields, we need to go through an Operation Region - * (Only types that will get here are RegionFields and BankFields) - */ - Status = AcpiExSetupField (ObjDesc, FieldDatumByteOffset); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } + DEBUG_PRINT (TRACE_OPREGION, + ("AmlReadFieldData: Region %s(%X) at %08lx width %X\n", + AcpiCmGetRegionName (RgnDesc->Region.SpaceId), + RgnDesc->Region.SpaceId, Address, + FieldBitWidth)); - /* - * The physical address of this field datum is: - * - * 1) The base of the region, plus - * 2) The base offset of the field, plus - * 3) The current offset into the field - */ - RgnDesc = ObjDesc->CommonField.RegionObj; - Address = RgnDesc->Region.Address + ObjDesc->CommonField.BaseByteOffset + - FieldDatumByteOffset; - - DEBUG_PRINTP (TRACE_BFIELD, ("Region %s(%X) width %X base:off %X:%X at %08lX\n", - AcpiUtGetRegionName (RgnDesc->Region.SpaceId), - RgnDesc->Region.SpaceId, ObjDesc->CommonField.AccessBitWidth, - ObjDesc->CommonField.BaseByteOffset, FieldDatumByteOffset, - Address)); - + /* Invoke the appropriate AddressSpace/OpRegion handler */ - /* Invoke the appropriate AddressSpace/OpRegion handler */ + Status = AcpiEvAddressSpaceDispatch (RgnDesc, ADDRESS_SPACE_READ, + Address, FieldBitWidth, Value); - Status = AcpiEvAddressSpaceDispatch (RgnDesc, ACPI_READ_ADR_SPACE, - Address, ObjDesc->CommonField.AccessBitWidth, Value); - if (Status == AE_NOT_IMPLEMENTED) - { - DEBUG_PRINTP (ACPI_ERROR, ("Region %s(%X) not implemented\n", - AcpiUtGetRegionName (RgnDesc->Region.SpaceId), - RgnDesc->Region.SpaceId)); - } - - else if (Status == AE_NOT_EXIST) - { - DEBUG_PRINTP (ACPI_ERROR, ("Region %s(%X) has no handler\n", - AcpiUtGetRegionName (RgnDesc->Region.SpaceId), - RgnDesc->Region.SpaceId)); - } - break; - - - default: - - DEBUG_PRINTP (ACPI_ERROR, ("%p, wrong source type - %s\n", - ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type))); - Status = AE_AML_INTERNAL; - break; - } - - - DEBUG_PRINTP (TRACE_BFIELD, ("Returned value=%08lX \n", *Value)); - - return_ACPI_STATUS (Status); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiExGetBufferDatum - * - * PARAMETERS: MergedDatum - Value to store - * Buffer - Receiving buffer - * ByteGranularity - 1/2/4 Granularity of the field - * (aka Datum Size) - * Offset - Datum offset into the buffer - * - * RETURN: none - * - * DESCRIPTION: Store the merged datum to the buffer according to the - * byte granularity - * - ******************************************************************************/ - -static void -AcpiExGetBufferDatum( - UINT32 *Datum, - void *Buffer, - UINT32 ByteGranularity, - UINT32 Offset) -{ - - switch (ByteGranularity) + if (Status == AE_NOT_IMPLEMENTED) { - case ACPI_FIELD_BYTE_GRANULARITY: - *Datum = ((UINT8 *) Buffer) [Offset]; - break; - - case ACPI_FIELD_WORD_GRANULARITY: - MOVE_UNALIGNED16_TO_32 (Datum, &(((UINT16 *) Buffer) [Offset])); - break; - - case ACPI_FIELD_DWORD_GRANULARITY: - MOVE_UNALIGNED32_TO_32 (Datum, &(((UINT32 *) Buffer) [Offset])); - break; + DEBUG_PRINT (ACPI_ERROR, + ("AmlReadFieldData: **** Region %s(%X) not implemented\n", + AcpiCmGetRegionName (RgnDesc->Region.SpaceId), + RgnDesc->Region.SpaceId)); } -} - - -/******************************************************************************* - * - * FUNCTION: AcpiExSetBufferDatum - * - * PARAMETERS: MergedDatum - Value to store - * Buffer - Receiving buffer - * ByteGranularity - 1/2/4 Granularity of the field - * (aka Datum Size) - * Offset - Datum offset into the buffer - * - * RETURN: none - * - * DESCRIPTION: Store the merged datum to the buffer according to the - * byte granularity - * - ******************************************************************************/ -static void -AcpiExSetBufferDatum ( - UINT32 MergedDatum, - void *Buffer, - UINT32 ByteGranularity, - UINT32 Offset) -{ - - switch (ByteGranularity) + else if (Status == AE_NOT_EXIST) { - case ACPI_FIELD_BYTE_GRANULARITY: - ((UINT8 *) Buffer) [Offset] = (UINT8) MergedDatum; - break; + DEBUG_PRINT (ACPI_ERROR, + ("AmlReadFieldData: **** Region %s(%X) has no handler\n", + AcpiCmGetRegionName (RgnDesc->Region.SpaceId), + RgnDesc->Region.SpaceId)); + } - case ACPI_FIELD_WORD_GRANULARITY: - MOVE_UNALIGNED16_TO_16 (&(((UINT16 *) Buffer)[Offset]), &MergedDatum); - break; + DEBUG_PRINT (TRACE_OPREGION, + ("AmlReadField: Returned value=%08lx \n", *Value)); - case ACPI_FIELD_DWORD_GRANULARITY: - MOVE_UNALIGNED32_TO_32 (&(((UINT32 *) Buffer)[Offset]), &MergedDatum); - break; - } + return_ACPI_STATUS (Status); } /******************************************************************************* * - * FUNCTION: AcpiExExtractFromField + * FUNCTION: AcpiAmlReadField * * PARAMETERS: *ObjDesc - Field to be read * *Value - Where to store value + * FieldBitWidth - Field Width in bits (8, 16, or 32) * * RETURN: Status * @@ -449,186 +241,218 @@ AcpiExSetBufferDatum ( ******************************************************************************/ ACPI_STATUS -AcpiExExtractFromField ( +AcpiAmlReadField ( ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer, - UINT32 BufferLength) + UINT32 BufferLength, + UINT32 ByteLength, + UINT32 DatumLength, + UINT32 BitGranularity, + UINT32 ByteGranularity) { ACPI_STATUS Status; - UINT32 FieldDatumByteOffset; - UINT32 DatumOffset; + UINT32 ThisFieldByteOffset; + UINT32 ThisFieldDatumOffset; UINT32 PreviousRawDatum; UINT32 ThisRawDatum = 0; + UINT32 ValidFieldBits; + UINT32 Mask; UINT32 MergedDatum = 0; - UINT32 ByteFieldLength; - UINT32 DatumCount; - - FUNCTION_TRACE ("ExExtractFromField"); - - - /* - * The field must fit within the caller's buffer - */ - ByteFieldLength = ROUND_BITS_UP_TO_BYTES (ObjDesc->CommonField.BitLength); - if (ByteFieldLength > BufferLength) - { - DEBUG_PRINTP (ACPI_INFO, ("Field size %X (bytes) too large for buffer (%X)\n", - ByteFieldLength, BufferLength)); - - return_ACPI_STATUS (AE_BUFFER_OVERFLOW); - } - - /* Convert field byte count to datum count, round up if necessary */ - - DatumCount = ROUND_UP_TO (ByteFieldLength, ObjDesc->CommonField.AccessByteWidth); - - DEBUG_PRINT (ACPI_INFO, - ("ByteLen=%x, DatumLen=%x, BitGran=%x, ByteGran=%x\n", - ByteFieldLength, DatumCount, ObjDesc->CommonField.AccessBitWidth, - ObjDesc->CommonField.AccessByteWidth)); + FUNCTION_TRACE ("AmlReadField"); /* * Clear the caller's buffer (the whole buffer length as given) * This is very important, especially in the cases where a byte is read, * but the buffer is really a UINT32 (4 bytes). */ + MEMSET (Buffer, 0, BufferLength); /* Read the first raw datum to prime the loop */ - FieldDatumByteOffset = 0; - DatumOffset= 0; + ThisFieldByteOffset = 0; + ThisFieldDatumOffset= 0; - Status = AcpiExReadFieldDatum (ObjDesc, FieldDatumByteOffset, &PreviousRawDatum); + Status = AcpiAmlReadFieldData (ObjDesc, ThisFieldByteOffset, BitGranularity, + &PreviousRawDatum); if (ACPI_FAILURE (Status)) { - return_ACPI_STATUS (Status); + goto Cleanup; } - /* We might actually be done if the request fits in one datum */ - if ((DatumCount == 1) && - (ObjDesc->CommonField.AccessFlags & AFIELD_SINGLE_DATUM)) + if ((DatumLength == 1) && + ((ObjDesc->Field.BitOffset + ObjDesc->FieldUnit.Length) <= + (UINT16) BitGranularity)) { - /* 1) Shift the valid data bits down to start at bit 0 */ - - MergedDatum = (PreviousRawDatum >> ObjDesc->CommonField.StartFieldBitOffset); + MergedDatum = PreviousRawDatum; - /* 2) Mask off any upper unused bits (bits not part of the field) */ + MergedDatum = (MergedDatum >> ObjDesc->Field.BitOffset); - if (ObjDesc->CommonField.EndBufferValidBits) + ValidFieldBits = ObjDesc->FieldUnit.Length % BitGranularity; + if (ValidFieldBits) { - MergedDatum &= MASK_BITS_ABOVE (ObjDesc->CommonField.EndBufferValidBits); + Mask = (((UINT32) 1 << ValidFieldBits) - (UINT32) 1); + MergedDatum &= Mask; } - /* Store the datum to the caller buffer */ - AcpiExSetBufferDatum (MergedDatum, Buffer, ObjDesc->CommonField.AccessByteWidth, - DatumOffset); + /* + * Place the MergedDatum into the proper format and return buffer + * field + */ - return_ACPI_STATUS (AE_OK); - } + switch (ByteGranularity) + { + case 1: + ((UINT8 *) Buffer) [ThisFieldDatumOffset] = (UINT8) MergedDatum; + break; + + case 2: + MOVE_UNALIGNED16_TO_16 (&(((UINT16 *) Buffer)[ThisFieldDatumOffset]), &MergedDatum); + break; + case 4: + MOVE_UNALIGNED32_TO_32 (&(((UINT32 *) Buffer)[ThisFieldDatumOffset]), &MergedDatum); + break; + } - /* We need to get more raw data to complete one or more field data */ + ThisFieldByteOffset = 1; + ThisFieldDatumOffset = 1; + } - while (DatumOffset < DatumCount) + else { - FieldDatumByteOffset += ObjDesc->CommonField.AccessByteWidth; + /* We need to get more raw data to complete one or more field data */ - /* - * If the field is aligned on a byte boundary, we don't want - * to perform a final read, since this would potentially read - * past the end of the region. - * - * TBD: [Investigate] It may make more sense to just split the aligned - * and non-aligned cases since the aligned case is so very simple, - */ - if ((ObjDesc->CommonField.StartFieldBitOffset != 0) || - ((ObjDesc->CommonField.StartFieldBitOffset == 0) && - (DatumOffset < (DatumCount -1)))) + while (ThisFieldDatumOffset < DatumLength) { /* - * Get the next raw datum, it contains some or all bits - * of the current field datum + * If the field is aligned on a byte boundary, we don't want + * to perform a final read, since this would potentially read + * past the end of the region. + * + * TBD: [Investigate] It may make more sense to just split the aligned + * and non-aligned cases since the aligned case is so very simple, */ - Status = AcpiExReadFieldDatum (ObjDesc, FieldDatumByteOffset, &ThisRawDatum); - if (ACPI_FAILURE (Status)) + if ((ObjDesc->Field.BitOffset != 0) || + ((ObjDesc->Field.BitOffset == 0) && + (ThisFieldDatumOffset < (DatumLength -1)))) { - return_ACPI_STATUS (Status); + /* + * Get the next raw datum, it contains some or all bits + * of the current field datum + */ + + Status = AcpiAmlReadFieldData (ObjDesc, + ThisFieldByteOffset + ByteGranularity, + BitGranularity, &ThisRawDatum); + if (ACPI_FAILURE (Status)) + { + goto Cleanup; + } + + /* Before merging the data, make sure the unused bits are clear */ + + switch (ByteGranularity) + { + case 1: + ThisRawDatum &= 0x000000FF; + PreviousRawDatum &= 0x000000FF; + break; + + case 2: + ThisRawDatum &= 0x0000FFFF; + PreviousRawDatum &= 0x0000FFFF; + break; + } } - } - /* - * Create the (possibly) merged datum to be stored to the caller buffer - */ - if (ObjDesc->CommonField.StartFieldBitOffset == 0) - { - /* Field is not skewed and we can just copy the datum */ - MergedDatum = PreviousRawDatum; - } + /* + * Put together bits of the two raw data to make a complete + * field datum + */ + + + if (ObjDesc->Field.BitOffset != 0) + { + MergedDatum = + (PreviousRawDatum >> ObjDesc->Field.BitOffset) | + (ThisRawDatum << (BitGranularity - ObjDesc->Field.BitOffset)); + } + + else + { + MergedDatum = PreviousRawDatum; + } - else - { /* - * Put together the appropriate bits of the two raw data to make a - * single complete field datum - * - * 1) Normalize the first datum down to bit 0 + * Prepare the merged datum for storing into the caller's + * buffer. It is possible to have a 32-bit buffer + * (ByteGranularity == 4), but a ObjDesc->Field.Length + * of 8 or 16, meaning that the upper bytes of merged data + * are undesired. This section fixes that. */ - MergedDatum = (PreviousRawDatum >> ObjDesc->CommonField.StartFieldBitOffset); + switch (ObjDesc->Field.Length) + { + case 8: + MergedDatum &= 0x000000FF; + break; - /* 2) Insert the second datum "above" the first datum */ + case 16: + MergedDatum &= 0x0000FFFF; + break; + } - MergedDatum |= (ThisRawDatum << ObjDesc->CommonField.DatumValidBits); - - if ((DatumOffset >= (DatumCount -1))) + /* + * Now store the datum in the caller's buffer, according to + * the data type + */ + switch (ByteGranularity) { - /* - * This is the last iteration of the loop. We need to clear - * any unused bits (bits that are not part of this field) that - * came from the last raw datum before we store the final - * merged datum into the caller buffer. - */ - if (ObjDesc->CommonField.EndBufferValidBits) - { - MergedDatum &= - MASK_BITS_ABOVE (ObjDesc->CommonField.EndBufferValidBits); - } + case 1: + ((UINT8 *) Buffer) [ThisFieldDatumOffset] = (UINT8) MergedDatum; + break; + + case 2: + MOVE_UNALIGNED16_TO_16 (&(((UINT16 *) Buffer) [ThisFieldDatumOffset]), &MergedDatum); + break; + + case 4: + MOVE_UNALIGNED32_TO_32 (&(((UINT32 *) Buffer) [ThisFieldDatumOffset]), &MergedDatum); + break; } - } + /* + * Save the most recent datum since it contains bits of + * the *next* field datum + */ - /* - * Store the merged field datum in the caller's buffer, according to - * the granularity of the field (size of each datum). - */ - AcpiExSetBufferDatum (MergedDatum, Buffer, ObjDesc->CommonField.AccessByteWidth, - DatumOffset); + PreviousRawDatum = ThisRawDatum; - /* - * Save the raw datum that was just acquired since it may contain bits - * of the *next* field datum. Update offsets - */ - PreviousRawDatum = ThisRawDatum; - DatumOffset++; + ThisFieldByteOffset += ByteGranularity; + ThisFieldDatumOffset++; + + } /* while */ } +Cleanup: - return_ACPI_STATUS (AE_OK); + return_ACPI_STATUS (Status); } /******************************************************************************* * - * FUNCTION: AcpiExWriteFieldDatum + * FUNCTION: AcpiAmlWriteFieldData * * PARAMETERS: *ObjDesc - Field to be set * Value - Value to store + * FieldBitWidth - Field Width in bits (8, 16, or 32) * * RETURN: Status * @@ -637,418 +461,400 @@ AcpiExExtractFromField ( ******************************************************************************/ static ACPI_STATUS -AcpiExWriteFieldDatum ( +AcpiAmlWriteFieldData ( ACPI_OPERAND_OBJECT *ObjDesc, - UINT32 FieldDatumByteOffset, + UINT32 FieldByteOffset, + UINT32 FieldBitWidth, UINT32 Value) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *RgnDesc = NULL; ACPI_PHYSICAL_ADDRESS Address; + UINT32 FieldByteWidth; - FUNCTION_TRACE_U32 ("ExWriteFieldDatum", FieldDatumByteOffset); + FUNCTION_TRACE ("AmlWriteFieldData"); + /* ObjDesc is validated by callers */ - /* - * BufferFields - Read from a Buffer - * Other Fields - Read from a Operation Region. - */ - switch (ObjDesc->Common.Type) + if (ObjDesc) { - case ACPI_TYPE_BUFFER_FIELD: - - /* - * For BufferFields, we only need to copy the data to the - * target buffer. Length is the field width in bytes. - */ - MEMCPY ((ObjDesc->BufferField.BufferObj)->Buffer.Pointer - + ObjDesc->BufferField.BaseByteOffset + FieldDatumByteOffset, - &Value, ObjDesc->CommonField.AccessByteWidth); - Status = AE_OK; - break; - - - case INTERNAL_TYPE_REGION_FIELD: - case INTERNAL_TYPE_BANK_FIELD: - - /* - * For other fields, we need to go through an Operation Region - * (Only types that will get here are RegionFields and BankFields) - */ - Status = AcpiExSetupField (ObjDesc, FieldDatumByteOffset); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } - - /* - * The physical address of this field datum is: - * - * 1) The base of the region, plus - * 2) The base offset of the field, plus - * 3) The current offset into the field - */ - RgnDesc = ObjDesc->CommonField.RegionObj; - Address = RgnDesc->Region.Address + - ObjDesc->CommonField.BaseByteOffset + - FieldDatumByteOffset; - - DEBUG_PRINTP (TRACE_BFIELD, - ("Store %X in Region %s(%X) at %p width %X\n", - Value, AcpiUtGetRegionName (RgnDesc->Region.SpaceId), - RgnDesc->Region.SpaceId, Address, ObjDesc->CommonField.AccessBitWidth)); - - /* Invoke the appropriate AddressSpace/OpRegion handler */ + RgnDesc = ObjDesc->Field.Container; + } - Status = AcpiEvAddressSpaceDispatch (RgnDesc, ACPI_WRITE_ADR_SPACE, - Address, ObjDesc->CommonField.AccessBitWidth, &Value); + FieldByteWidth = DIV_8 (FieldBitWidth); + Status = AcpiAmlSetupField (ObjDesc, RgnDesc, FieldBitWidth); + if (ACPI_FAILURE (Status)) + { + return_ACPI_STATUS (Status); + } - if (Status == AE_NOT_IMPLEMENTED) - { - DEBUG_PRINTP (ACPI_ERROR, - ("**** Region type %s(%X) not implemented\n", - AcpiUtGetRegionName (RgnDesc->Region.SpaceId), - RgnDesc->Region.SpaceId)); - } - else if (Status == AE_NOT_EXIST) - { - DEBUG_PRINTP (ACPI_ERROR, - ("**** Region type %s(%X) does not have a handler\n", - AcpiUtGetRegionName (RgnDesc->Region.SpaceId), - RgnDesc->Region.SpaceId)); - } + /* + * Set offset to next multiple of field width, + * add region base address and offset within the field + */ + Address = RgnDesc->Region.Address + + (ObjDesc->Field.Offset * FieldByteWidth) + + FieldByteOffset; - break; + DEBUG_PRINT (TRACE_OPREGION, + ("AmlWriteField: Store %lx in Region %s(%X) at %p width %X\n", + Value, AcpiCmGetRegionName (RgnDesc->Region.SpaceId), + RgnDesc->Region.SpaceId, Address, + FieldBitWidth)); + /* Invoke the appropriate AddressSpace/OpRegion handler */ - default: + Status = AcpiEvAddressSpaceDispatch (RgnDesc, ADDRESS_SPACE_WRITE, + Address, FieldBitWidth, &Value); - DEBUG_PRINTP (ACPI_ERROR, ("%p, wrong source type - %s\n", - ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type))); - Status = AE_AML_INTERNAL; - break; + if (Status == AE_NOT_IMPLEMENTED) + { + DEBUG_PRINT (ACPI_ERROR, + ("AmlWriteField: **** Region type %s(%X) not implemented\n", + AcpiCmGetRegionName (RgnDesc->Region.SpaceId), + RgnDesc->Region.SpaceId)); } + else if (Status == AE_NOT_EXIST) + { + DEBUG_PRINT (ACPI_ERROR, + ("AmlWriteField: **** Region type %s(%X) does not have a handler\n", + AcpiCmGetRegionName (RgnDesc->Region.SpaceId), + RgnDesc->Region.SpaceId)); + } - DEBUG_PRINTP (TRACE_BFIELD, ("Value written=%08lX \n", Value)); return_ACPI_STATUS (Status); } -/******************************************************************************* +/***************************************************************************** * - * FUNCTION: AcpiExWriteFieldDatumWithUpdateRule + * FUNCTION: AcpiAmlWriteFieldDataWithUpdateRule * * PARAMETERS: *ObjDesc - Field to be set * Value - Value to store + * FieldBitWidth - Field Width in bits (8, 16, or 32) * * RETURN: Status * * DESCRIPTION: Apply the field update rule to a field write * - ******************************************************************************/ + ****************************************************************************/ static ACPI_STATUS -AcpiExWriteFieldDatumWithUpdateRule ( +AcpiAmlWriteFieldDataWithUpdateRule ( ACPI_OPERAND_OBJECT *ObjDesc, UINT32 Mask, UINT32 FieldValue, - UINT32 FieldDatumByteOffset) + UINT32 ThisFieldByteOffset, + UINT32 BitGranularity) { ACPI_STATUS Status = AE_OK; UINT32 MergedValue; UINT32 CurrentValue; - FUNCTION_TRACE ("ExWriteFieldDatumWithUpdateRule"); - - /* Start with the new bits */ MergedValue = FieldValue; - /* If the mask is all ones, we don't need to worry about the update rule */ - if (Mask != ACPI_UINT32_MAX) + /* Decode the update rule */ + + switch (ObjDesc->Field.UpdateRule) { - /* Decode the update rule */ - switch (ObjDesc->CommonField.UpdateRule) - { + case UPDATE_PRESERVE: - case UPDATE_PRESERVE: + /* Check if update rule needs to be applied (not if mask is all ones) */ - /* - * Check if update rule needs to be applied (not if mask is all - * ones) The left shift drops the bits we want to ignore. + /* The left shift drops the bits we want to ignore. */ + if ((~Mask << (sizeof(Mask)*8 - BitGranularity)) != 0) + { + /* + * Read the current contents of the byte/word/dword containing + * the field, and merge with the new field value. */ - if ((~Mask << (sizeof (Mask) * 8 - - ObjDesc->CommonField.AccessBitWidth)) != 0) - { - /* - * Read the current contents of the byte/word/dword containing - * the field, and merge with the new field value. - */ - Status = AcpiExReadFieldDatum (ObjDesc, FieldDatumByteOffset, - &CurrentValue); - MergedValue |= (CurrentValue & ~Mask); - } - break; + Status = AcpiAmlReadFieldData (ObjDesc, ThisFieldByteOffset, + BitGranularity, &CurrentValue); + MergedValue |= (CurrentValue & ~Mask); + } + break; - case UPDATE_WRITE_AS_ONES: + case UPDATE_WRITE_AS_ONES: - /* Set positions outside the field to all ones */ + /* Set positions outside the field to all ones */ - MergedValue |= ~Mask; - break; + MergedValue |= ~Mask; + break; - case UPDATE_WRITE_AS_ZEROS: + case UPDATE_WRITE_AS_ZEROS: - /* Set positions outside the field to all zeros */ + /* Set positions outside the field to all zeros */ - MergedValue &= Mask; - break; + MergedValue &= Mask; + break; - default: - DEBUG_PRINT (ACPI_ERROR, - ("WriteWithUpdateRule: Unknown UpdateRule setting: %x\n", - ObjDesc->CommonField.UpdateRule)); - return_ACPI_STATUS (AE_AML_OPERAND_VALUE); - break; - } + default: + DEBUG_PRINT (ACPI_ERROR, + ("WriteFieldDataWithUpdateRule: Unknown UpdateRule setting: %x\n", + ObjDesc->Field.UpdateRule)); + Status = AE_AML_OPERAND_VALUE; } /* Write the merged value */ - Status = AcpiExWriteFieldDatum (ObjDesc, FieldDatumByteOffset, - MergedValue); - - DEBUG_PRINTP (TRACE_BFIELD, ("Mask %X DatumOffset %X Value %X, MergedValue %X\n", - Mask, FieldDatumByteOffset, FieldValue, MergedValue)); + if (ACPI_SUCCESS (Status)) + { + Status = AcpiAmlWriteFieldData (ObjDesc, ThisFieldByteOffset, + BitGranularity, MergedValue); + } - return_ACPI_STATUS (Status); + return (Status); } -/******************************************************************************* +/***************************************************************************** * - * FUNCTION: AcpiExInsertIntoField + * FUNCTION: AcpiAmlWriteField * * PARAMETERS: *ObjDesc - Field to be set - * Buffer - Value to store + * Value - Value to store + * FieldBitWidth - Field Width in bits (8, 16, or 32) * * RETURN: Status * * DESCRIPTION: Store the value into the given field * - ******************************************************************************/ + ****************************************************************************/ ACPI_STATUS -AcpiExInsertIntoField ( +AcpiAmlWriteField ( ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer, - UINT32 BufferLength) + UINT32 BufferLength, + UINT32 ByteLength, + UINT32 DatumLength, + UINT32 BitGranularity, + UINT32 ByteGranularity) { ACPI_STATUS Status; - UINT32 FieldDatumByteOffset; - UINT32 DatumOffset; + UINT32 ThisFieldByteOffset; + UINT32 ThisFieldDatumOffset; UINT32 Mask; UINT32 MergedDatum; UINT32 PreviousRawDatum; UINT32 ThisRawDatum; - UINT32 ByteFieldLength; - UINT32 DatumCount; + UINT32 FieldValue; + UINT32 ValidFieldBits; - FUNCTION_TRACE ("ExInsertIntoField"); + FUNCTION_TRACE ("AmlWriteField"); /* - * Incoming buffer must be at least as long as the field, we do not - * allow "partial" field writes. We do not care if the buffer is - * larger than the field, this typically happens when an integer is - * written to a field that is actually smaller than an integer. + * Break the request into up to three parts: + * non-aligned part at start, aligned part in middle, non-aligned part + * at end --- Just like an I/O request --- */ - ByteFieldLength = ROUND_BITS_UP_TO_BYTES (ObjDesc->CommonField.BitLength); - if (BufferLength < ByteFieldLength) - { - DEBUG_PRINTP (ACPI_INFO, ("Buffer length %X too small for field %X\n", - BufferLength, ByteFieldLength)); - /* TBD: Need a better error code */ + ThisFieldByteOffset = 0; + ThisFieldDatumOffset= 0; - return_ACPI_STATUS (AE_BUFFER_OVERFLOW); - } - - /* Convert byte count to datum count, round up if necessary */ - - DatumCount = ROUND_UP_TO (ByteFieldLength, ObjDesc->CommonField.AccessByteWidth); + /* Get a datum */ - DEBUG_PRINT (ACPI_INFO, - ("ByteLen=%x, DatumLen=%x, BitGran=%x, ByteGran=%x\n", - ByteFieldLength, DatumCount, ObjDesc->CommonField.AccessBitWidth, - ObjDesc->CommonField.AccessByteWidth)); + switch (ByteGranularity) + { + case 1: + PreviousRawDatum = ((UINT8 *) Buffer) [ThisFieldDatumOffset]; + break; + case 2: + MOVE_UNALIGNED16_TO_32 (&PreviousRawDatum, &(((UINT16 *) Buffer) [ThisFieldDatumOffset])); + break; - /* - * Break the request into up to three parts (similar to an I/O request): - * 1) non-aligned part at start - * 2) aligned part in middle - * 3) non-aligned part at the end - */ - FieldDatumByteOffset = 0; - DatumOffset= 0; + case 4: + MOVE_UNALIGNED32_TO_32 (&PreviousRawDatum, &(((UINT32 *) Buffer) [ThisFieldDatumOffset])); + break; - /* Get a single datum from the caller's buffer */ + default: + DEBUG_PRINT (ACPI_ERROR, ("AmlWriteField: Invalid granularity: %x\n", + ByteGranularity)); + Status = AE_AML_OPERAND_VALUE; + goto Cleanup; + } - AcpiExGetBufferDatum (&PreviousRawDatum, Buffer, - ObjDesc->CommonField.AccessByteWidth, DatumOffset); /* - * Part1: * Write a partial field datum if field does not begin on a datum boundary - * Note: The code in this section also handles the aligned case * * Construct Mask with 1 bits where the field is, 0 bits elsewhere - * (Only the bottom 5 bits of BitLength are valid for a shift operation) * - * Mask off bits that are "below" the field (if any) + * 1) Bits above the field */ - Mask = MASK_BITS_BELOW (ObjDesc->CommonField.StartFieldBitOffset); - /* If the field fits in one datum, may need to mask upper bits */ + Mask = (((UINT32)(-1)) << (UINT32)ObjDesc->Field.BitOffset); + + /* 2) Only the bottom 5 bits are valid for a shift operation. */ - if ((ObjDesc->CommonField.AccessFlags & AFIELD_SINGLE_DATUM) && - ObjDesc->CommonField.EndFieldValidBits) + if ((ObjDesc->Field.BitOffset + ObjDesc->FieldUnit.Length) < 32) { - /* There are bits above the field, mask them off also */ + /* Bits above the field */ - Mask &= MASK_BITS_ABOVE (ObjDesc->CommonField.EndFieldValidBits); + Mask &= (~(((UINT32)(-1)) << ((UINT32)ObjDesc->Field.BitOffset + + (UINT32)ObjDesc->FieldUnit.Length))); } - /* Shift and mask the value into the field position */ - - MergedDatum = (PreviousRawDatum << ObjDesc->CommonField.StartFieldBitOffset); - MergedDatum &= Mask; + /* 3) Shift and mask the value into the field position */ - /* Apply the update rule (if necessary) and write the datum to the field */ + FieldValue = (PreviousRawDatum << ObjDesc->Field.BitOffset) & Mask; - Status = AcpiExWriteFieldDatumWithUpdateRule (ObjDesc, Mask, MergedDatum, - FieldDatumByteOffset); + Status = AcpiAmlWriteFieldDataWithUpdateRule (ObjDesc, Mask, FieldValue, + ThisFieldByteOffset, + BitGranularity); if (ACPI_FAILURE (Status)) { - return_ACPI_STATUS (Status); + goto Cleanup; } - /* If the entire field fits within one datum, we are done. */ - if ((DatumCount == 1) && - (ObjDesc->CommonField.AccessFlags & AFIELD_SINGLE_DATUM)) + /* If the field fits within one datum, we are done. */ + + if ((DatumLength == 1) && + ((ObjDesc->Field.BitOffset + ObjDesc->FieldUnit.Length) <= + (UINT16) BitGranularity)) { - return_ACPI_STATUS (AE_OK); + goto Cleanup; } /* - * Part2: - * Write the aligned data. - * * We don't need to worry about the update rule for these data, because - * all of the bits in each datum are part of the field. + * all of the bits are part of the field. * - * The last datum must be special cased because it might contain bits - * that are not part of the field -- therefore the "update rule" must be - * applied in Part3 below. + * Can't write the last datum, however, because it might contain bits that + * are not part of the field -- the update rule must be applied. */ - while (DatumOffset < DatumCount) + + while (ThisFieldDatumOffset < (DatumLength - 1)) { - DatumOffset++; - FieldDatumByteOffset += ObjDesc->CommonField.AccessByteWidth; + ThisFieldDatumOffset++; - /* - * Get the next raw buffer datum. It may contain bits of the previous - * field datum - */ - AcpiExGetBufferDatum (&ThisRawDatum, Buffer, - ObjDesc->CommonField.AccessByteWidth, DatumOffset); + /* Get the next raw datum, it contains bits of the current field datum... */ + + switch (ByteGranularity) + { + case 1: + ThisRawDatum = ((UINT8 *) Buffer) [ThisFieldDatumOffset]; + break; + + case 2: + MOVE_UNALIGNED16_TO_32 (&ThisRawDatum, &(((UINT16 *) Buffer) [ThisFieldDatumOffset])); + break; + + case 4: + MOVE_UNALIGNED32_TO_32 (&ThisRawDatum, &(((UINT32 *) Buffer) [ThisFieldDatumOffset])); + break; - /* Create the field datum based on the field alignment */ + default: + DEBUG_PRINT (ACPI_ERROR, ("AmlWriteField: Invalid Byte Granularity: %x\n", + ByteGranularity)); + Status = AE_AML_OPERAND_VALUE; + goto Cleanup; + } + + /* + * Put together bits of the two raw data to make a complete field + * datum + */ - if (ObjDesc->CommonField.StartFieldBitOffset != 0) + if (ObjDesc->Field.BitOffset != 0) { - /* - * Put together appropriate bits of the two raw buffer data to make - * a single complete field datum - */ - MergedDatum = - (PreviousRawDatum >> ObjDesc->CommonField.DatumValidBits) | - (ThisRawDatum << ObjDesc->CommonField.StartFieldBitOffset); + MergedDatum = + (PreviousRawDatum >> (BitGranularity - ObjDesc->Field.BitOffset)) | + (ThisRawDatum << ObjDesc->Field.BitOffset); } else { - /* Field began aligned on datum boundary */ - MergedDatum = ThisRawDatum; } + /* Now write the completed datum */ + + + Status = AcpiAmlWriteFieldData (ObjDesc, + ThisFieldByteOffset + ByteGranularity, + BitGranularity, MergedDatum); + if (ACPI_FAILURE (Status)) + { + goto Cleanup; + } + /* - * Special handling for the last datum if the field does NOT end on - * a datum boundary. Update Rule must be applied to the bits outside - * the field. + * Save the most recent datum since it contains bits of + * the *next* field datum */ - if ((DatumOffset == DatumCount) && - ObjDesc->CommonField.EndFieldValidBits) - { - /* - * Part3: - * This is the last datum and the field does not end on a datum boundary. - * Build the partial datum and write with the update rule. - */ - /* Mask off the unused bits above (after) the end-of-field */ + PreviousRawDatum = ThisRawDatum; - Mask = MASK_BITS_ABOVE (ObjDesc->CommonField.EndFieldValidBits); - MergedDatum &= Mask; + ThisFieldByteOffset += ByteGranularity; - /* Write the last datum with the update rule */ + } /* while */ - Status = AcpiExWriteFieldDatumWithUpdateRule (ObjDesc, Mask, - MergedDatum, FieldDatumByteOffset); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } - } - else + /* Write a partial field datum if field does not end on a datum boundary */ + + if ((ObjDesc->FieldUnit.Length + ObjDesc->FieldUnit.BitOffset) % + BitGranularity) + { + switch (ByteGranularity) { - /* Normal case -- write the completed datum */ + case 1: + ThisRawDatum = ((UINT8 *) Buffer) [ThisFieldDatumOffset]; + break; - Status = AcpiExWriteFieldDatum (ObjDesc, - FieldDatumByteOffset, MergedDatum); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } + case 2: + MOVE_UNALIGNED16_TO_32 (&ThisRawDatum, &(((UINT16 *) Buffer) [ThisFieldDatumOffset])); + break; + + case 4: + MOVE_UNALIGNED32_TO_32 (&ThisRawDatum, &(((UINT32 *) Buffer) [ThisFieldDatumOffset])); + break; } - /* - * Save the most recent datum since it may contain bits of the *next* - * field datum. Update current byte offset. - */ - PreviousRawDatum = ThisRawDatum; + /* Construct Mask with 1 bits where the field is, 0 bits elsewhere */ + + ValidFieldBits = ((ObjDesc->FieldUnit.Length % BitGranularity) + + ObjDesc->Field.BitOffset); + + Mask = (((UINT32) 1 << ValidFieldBits) - (UINT32) 1); + + /* Shift and mask the value into the field position */ + + FieldValue = (PreviousRawDatum >> + (BitGranularity - ObjDesc->Field.BitOffset)) & Mask; + + Status = AcpiAmlWriteFieldDataWithUpdateRule (ObjDesc, Mask, FieldValue, + ThisFieldByteOffset + ByteGranularity, + BitGranularity); + if (ACPI_FAILURE (Status)) + { + goto Cleanup; + } } +Cleanup: + return_ACPI_STATUS (Status); } diff --git a/sys/contrib/dev/acpica/psparse.c b/sys/contrib/dev/acpica/psparse.c index fc68ef4..1d44bd8 100644 --- a/sys/contrib/dev/acpica/psparse.c +++ b/sys/contrib/dev/acpica/psparse.c @@ -1,7 +1,7 @@ /****************************************************************************** * * Module Name: psparse - Parser top level AML parse routines - * $Revision: 85 $ + * $Revision: 74 $ * *****************************************************************************/ @@ -130,9 +130,8 @@ #include "amlcode.h" #include "acnamesp.h" #include "acdebug.h" -#include "acinterp.h" -#define _COMPONENT ACPI_PARSER +#define _COMPONENT PARSER MODULE_NAME ("psparse") @@ -204,9 +203,9 @@ AcpiPsPeekOpcode ( * * if (Opcode == AML_EXTOP * || (Opcode == AML_LNOT - * && (GET8 (Aml) == AML_LEQUAL - * || GET8 (Aml) == AML_LGREATER - * || GET8 (Aml) == AML_LLESS))) + * && (GET8 (AcpiAml) == AML_LEQUAL + * || GET8 (AcpiAml) == AML_LGREATER + * || GET8 (AcpiAml) == AML_LLESS))) * * extended Opcode, !=, <=, or >= */ @@ -229,8 +228,8 @@ AcpiPsPeekOpcode ( * * FUNCTION: AcpiPsCreateState * - * PARAMETERS: Aml - Aml code pointer - * AmlSize - Length of AML code + * PARAMETERS: AcpiAml - AcpiAml code pointer + * AcpiAmlSize - Length of AML code * * RETURN: A new parser state object * @@ -249,10 +248,10 @@ AcpiPsCreateState ( FUNCTION_TRACE ("PsCreateState"); - ParserState = AcpiUtCallocate (sizeof (ACPI_PARSE_STATE)); + ParserState = AcpiCmCallocate (sizeof (ACPI_PARSE_STATE)); if (!ParserState) { - return_PTR (NULL); + return_VALUE (NULL); } ParserState->Aml = Aml; @@ -363,7 +362,7 @@ AcpiPsCompleteThisOp ( (OpcodeClass != OPTYPE_LOCAL_VARIABLE) && (OpcodeClass != OPTYPE_METHOD_ARGUMENT) && (OpcodeClass != OPTYPE_DATA_TERM) && - (Op->Opcode != AML_INT_NAMEPATH_OP)) + (Op->Opcode != AML_NAMEPATH_OP)) { /* Make sure that we only delete this subtree */ @@ -388,15 +387,15 @@ AcpiPsCompleteThisOp ( * op must be replace by a placeholder return op */ - if ((Op->Parent->Opcode == AML_REGION_OP) || - (Op->Parent->Opcode == AML_CREATE_FIELD_OP) || - (Op->Parent->Opcode == AML_CREATE_BIT_FIELD_OP) || - (Op->Parent->Opcode == AML_CREATE_BYTE_FIELD_OP) || - (Op->Parent->Opcode == AML_CREATE_WORD_FIELD_OP) || - (Op->Parent->Opcode == AML_CREATE_DWORD_FIELD_OP) || - (Op->Parent->Opcode == AML_CREATE_QWORD_FIELD_OP)) + if ((Op->Parent->Opcode == AML_REGION_OP) || + (Op->Parent->Opcode == AML_CREATE_FIELD_OP) || + (Op->Parent->Opcode == AML_BIT_FIELD_OP) || + (Op->Parent->Opcode == AML_BYTE_FIELD_OP) || + (Op->Parent->Opcode == AML_WORD_FIELD_OP) || + (Op->Parent->Opcode == AML_DWORD_FIELD_OP) || + (Op->Parent->Opcode == AML_QWORD_FIELD_OP)) { - ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); + ReplacementOp = AcpiPsAllocOp (AML_RETURN_VALUE_OP); if (!ReplacementOp) { return_VALUE (FALSE); @@ -406,7 +405,7 @@ AcpiPsCompleteThisOp ( break; default: - ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); + ReplacementOp = AcpiPsAllocOp (AML_RETURN_VALUE_OP); if (!ReplacementOp) { return_VALUE (FALSE); @@ -622,7 +621,7 @@ AcpiPsParseLoop ( ACPI_PARSE2_OBJECT *DeferredOp; UINT32 ArgCount; /* push for fixed or var args */ UINT32 ArgTypes = 0; - UINT32 AmlOffset; + ACPI_PTRDIFF AmlOffset; UINT16 Opcode; ACPI_PARSE_OBJECT PreOp; ACPI_PARSE_STATE *ParserState; @@ -664,13 +663,14 @@ AcpiPsParseLoop ( { if (Status == AE_AML_NO_RETURN_VALUE) { - DEBUG_PRINTP (ACPI_ERROR, - ("Invoked method did not return a value, %s\n", - AcpiUtFormatException (Status))); + DEBUG_PRINT (ACPI_ERROR, + ("PsParseLoop: Invoked method did not return a value, %s\n", + AcpiCmFormatException (Status))); } - DEBUG_PRINTP (ACPI_ERROR, ("GetPredicate Failed, %s\n", - AcpiUtFormatException (Status))); + DEBUG_PRINT (ACPI_ERROR, + ("PsParseLoop: GetPredicate Failed, %s\n", + AcpiCmFormatException (Status))); return_ACPI_STATUS (Status); } @@ -678,7 +678,7 @@ AcpiPsParseLoop ( } AcpiPsPopScope (ParserState, &Op, &ArgTypes, &ArgCount); - DEBUG_PRINTP (TRACE_PARSE, ("Popped scope, Op=%p\n", Op)); + DEBUG_PRINT (TRACE_PARSE, ("ParseLoop: Popped scope, Op=%p\n", Op)); } else if (WalkState->PrevOp) @@ -729,7 +729,7 @@ AcpiPsParseLoop ( * string. Convert the bare name string to a namepath. */ - Opcode = AML_INT_NAMEPATH_OP; + Opcode = AML_NAMEPATH_OP; ArgTypes = ARGP_NAMESTRING; break; @@ -737,8 +737,8 @@ AcpiPsParseLoop ( /* The opcode is unrecognized. Just skip unknown opcodes */ - DEBUG_PRINTP (ACPI_ERROR, - ("Found unknown opcode %lX at AML offset %X, ignoring\n", + DEBUG_PRINT (ACPI_ERROR, + ("ParseLoop: Found unknown opcode %lX at AML offset %X, ignoring\n", Opcode, AmlOffset)); DUMP_BUFFER (ParserState->Aml, 128); @@ -835,12 +835,11 @@ AcpiPsParseLoop ( } - if ((Op->Opcode == AML_CREATE_FIELD_OP) || - (Op->Opcode == AML_CREATE_BIT_FIELD_OP) || - (Op->Opcode == AML_CREATE_BYTE_FIELD_OP) || - (Op->Opcode == AML_CREATE_WORD_FIELD_OP) || - (Op->Opcode == AML_CREATE_DWORD_FIELD_OP) || - (Op->Opcode == AML_CREATE_QWORD_FIELD_OP)) + if ((Op->Opcode == AML_CREATE_FIELD_OP) || + (Op->Opcode == AML_BIT_FIELD_OP) || + (Op->Opcode == AML_BYTE_FIELD_OP) || + (Op->Opcode == AML_WORD_FIELD_OP) || + (Op->Opcode == AML_DWORD_FIELD_OP)) { /* * Backup to beginning of CreateXXXfield declaration @@ -879,8 +878,8 @@ AcpiPsParseLoop ( if (OpInfo) { - DEBUG_PRINTP (TRACE_PARSE, - ("Op=%p Opcode=%4.4lX Aml %p Oft=%5.5lX\n", + DEBUG_PRINT (TRACE_PARSE, + ("ParseLoop: Op=%p Opcode=%4.4lX Aml %p Oft=%5.5lX\n", Op, Op->Opcode, ParserState->Aml, Op->AmlOffset)); } } @@ -908,7 +907,7 @@ AcpiPsParseLoop ( GET_CURRENT_ARG_TYPE (ArgTypes), Op); break; - case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ + case AML_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ AcpiPsGetNextNamepath (ParserState, Op, &ArgCount, 1); ArgTypes = 0; @@ -949,8 +948,8 @@ AcpiPsParseLoop ( */ DeferredOp->Data = ParserState->Aml; - DeferredOp->Length = (UINT32) (ParserState->PkgEnd - - ParserState->Aml); + DeferredOp->Length = ParserState->PkgEnd - + ParserState->Aml; /* * Skip body of method. For OpRegions, we must continue @@ -995,18 +994,18 @@ AcpiPsParseLoop ( * know the length. */ - DeferredOp->Length = (UINT32) (ParserState->Aml - - DeferredOp->Data); + DeferredOp->Length = ParserState->Aml - + DeferredOp->Data; } } } - if ((Op->Opcode == AML_CREATE_FIELD_OP) || - (Op->Opcode == AML_CREATE_BIT_FIELD_OP) || - (Op->Opcode == AML_CREATE_BYTE_FIELD_OP) || - (Op->Opcode == AML_CREATE_WORD_FIELD_OP) || - (Op->Opcode == AML_CREATE_DWORD_FIELD_OP) || - (Op->Opcode == AML_CREATE_QWORD_FIELD_OP)) + if ((Op->Opcode == AML_CREATE_FIELD_OP) || + (Op->Opcode == AML_BIT_FIELD_OP) || + (Op->Opcode == AML_BYTE_FIELD_OP) || + (Op->Opcode == AML_WORD_FIELD_OP) || + (Op->Opcode == AML_DWORD_FIELD_OP) || + (Op->Opcode == AML_QWORD_FIELD_OP)) { /* * Backup to beginning of CreateXXXfield declaration (1 for @@ -1015,8 +1014,7 @@ AcpiPsParseLoop ( * BodyLength is unknown until we parse the body */ DeferredOp = (ACPI_PARSE2_OBJECT *) Op; - DeferredOp->Length = (UINT32) (ParserState->Aml - - DeferredOp->Data); + DeferredOp->Length = ParserState->Aml - DeferredOp->Data; } /* This op complete, notify the dispatcher */ @@ -1120,7 +1118,7 @@ CloseThisOp: if (AcpiPsHasCompletedScope (ParserState)) { AcpiPsPopScope (ParserState, &Op, &ArgTypes, &ArgCount); - DEBUG_PRINTP (TRACE_PARSE, ("Popped scope, Op=%p\n", Op)); + DEBUG_PRINT (TRACE_PARSE, ("ParseLoop: Popped scope, Op=%p\n", Op)); } else @@ -1151,7 +1149,7 @@ CloseThisOp: * sequential closing braces). We want to terminate each one cleanly. */ - DEBUG_PRINTP (TRACE_PARSE, ("Package complete at Op %p\n", Op)); + DEBUG_PRINT (TRACE_PARSE, ("PsParseLoop: Package complete at Op %p\n", Op)); do { if (Op) @@ -1237,12 +1235,14 @@ AcpiPsParseAml ( ACPI_NAMESPACE_NODE *Node = NULL; ACPI_WALK_LIST *PrevWalkList = AcpiGbl_CurrentWalkList; ACPI_OPERAND_OBJECT *ReturnDesc; + ACPI_OPERAND_OBJECT *EffectiveReturnDesc = NULL; ACPI_OPERAND_OBJECT *MthDesc = NULL; FUNCTION_TRACE ("PsParseAml"); - DEBUG_PRINTP (TRACE_PARSE, ("Entered with Scope=%p Aml=%p size=%lX\n", + DEBUG_PRINT (TRACE_PARSE, + ("PsParseAml: Entered with Scope=%p Aml=%p size=%lX\n", StartScope, Aml, AmlSize)); @@ -1264,11 +1264,8 @@ AcpiPsParseAml ( /* Create and initialize a new walk list */ WalkList.WalkState = NULL; - WalkList.AcquiredMutexList.Prev = NULL; - WalkList.AcquiredMutexList.Next = NULL; - WalkState = AcpiDsCreateWalkState (TABLE_ID_DSDT, ParserState->StartOp, - MthDesc, &WalkList); + WalkState = AcpiDsCreateWalkState (TABLE_ID_DSDT, ParserState->StartOp, MthDesc, &WalkList); if (!WalkState) { Status = AE_NO_MEMORY; @@ -1334,7 +1331,8 @@ AcpiPsParseAml ( * handles nested control method invocations without recursion. */ - DEBUG_PRINTP (TRACE_PARSE, ("State=%p\n", WalkState)); + DEBUG_PRINT (TRACE_PARSE, ("PsParseAml: State=%p\n", + WalkState)); while (WalkState) { @@ -1343,8 +1341,9 @@ AcpiPsParseAml ( Status = AcpiPsParseLoop (WalkState); } - DEBUG_PRINTP (TRACE_PARSE, - ("Completed one call to walk loop, State=%p\n", WalkState)); + DEBUG_PRINT (TRACE_PARSE, + ("PsParseAml: Completed one call to walk loop, State=%p\n", + WalkState)); if (Status == AE_CTRL_TRANSFER) { @@ -1378,7 +1377,16 @@ AcpiPsParseAml ( ReturnDesc = WalkState->ReturnDesc; - DEBUG_PRINTP (TRACE_PARSE, ("ReturnValue=%p, State=%p\n", + /* Save the last effective return value */ + + if (CallerReturnDesc && ReturnDesc) + { + EffectiveReturnDesc = ReturnDesc; + AcpiCmAddReference (EffectiveReturnDesc); + } + + DEBUG_PRINT (TRACE_PARSE, + ("PsParseAml: ReturnValue=%p, State=%p\n", WalkState->ReturnDesc, WalkState)); /* Reset the current scope to the beginning of scope stack */ @@ -1398,7 +1406,7 @@ AcpiPsParseAml ( /* Delete this walk state and all linked control states */ AcpiPsCleanupScope (WalkState->ParserState); - AcpiUtFree (WalkState->ParserState); + AcpiCmFree (WalkState->ParserState); AcpiDsDeleteWalkState (WalkState); /* Check if we have restarted a preempted walk */ @@ -1425,6 +1433,16 @@ AcpiPsParseAml ( else if (CallerReturnDesc) { + /* + * Some AML code expects return value w/o ReturnOp. + * Return the saved effective return value instead. + */ + + if (ReturnDesc == NULL && EffectiveReturnDesc != NULL) + { + AcpiCmRemoveReference (ReturnDesc); + ReturnDesc = EffectiveReturnDesc; + } *CallerReturnDesc = ReturnDesc; /* NULL if no return value */ } @@ -1432,14 +1450,13 @@ AcpiPsParseAml ( { /* Caller doesn't want it, must delete it */ - AcpiUtRemoveReference (ReturnDesc); + AcpiCmRemoveReference (ReturnDesc); } } /* Normal exit */ - AcpiExReleaseAllMutexes ((ACPI_OPERAND_OBJECT *) &WalkList.AcquiredMutexList); AcpiGbl_CurrentWalkList = PrevWalkList; return_ACPI_STATUS (Status); @@ -1450,9 +1467,8 @@ Cleanup: AcpiDsDeleteWalkState (WalkState); AcpiPsCleanupScope (ParserState); - AcpiUtFree (ParserState); + AcpiCmFree (ParserState); - AcpiExReleaseAllMutexes ((ACPI_OPERAND_OBJECT *)&WalkList.AcquiredMutexList); AcpiGbl_CurrentWalkList = PrevWalkList; return_ACPI_STATUS (Status); |