xref: /onnv-gate/usr/src/uts/intel/io/acpica/hardware/hwacpi.c (revision 7851:e828bbb1689c)
13446Smrj 
23446Smrj /******************************************************************************
33446Smrj  *
43446Smrj  * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
5*7851SDana.Myers@Sun.COM  *              $Revision: 1.79 $
63446Smrj  *
73446Smrj  *****************************************************************************/
83446Smrj 
93446Smrj /******************************************************************************
103446Smrj  *
113446Smrj  * 1. Copyright Notice
123446Smrj  *
13*7851SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
143446Smrj  * All rights reserved.
153446Smrj  *
163446Smrj  * 2. License
173446Smrj  *
183446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
193446Smrj  * rights.  You may have additional license terms from the party that provided
203446Smrj  * you this software, covering your right to use that party's intellectual
213446Smrj  * property rights.
223446Smrj  *
233446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
243446Smrj  * copy of the source code appearing in this file ("Covered Code") an
253446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
263446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
273446Smrj  * make derivatives, distribute, use and display any portion of the Covered
283446Smrj  * Code in any form, with the right to sublicense such rights; and
293446Smrj  *
303446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
313446Smrj  * license (with the right to sublicense), under only those claims of Intel
323446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
333446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
343446Smrj  * solely to the minimum extent necessary to exercise the above copyright
353446Smrj  * license, and in no event shall the patent license extend to any additions
363446Smrj  * to or modifications of the Original Intel Code.  No other license or right
373446Smrj  * is granted directly or by implication, estoppel or otherwise;
383446Smrj  *
393446Smrj  * The above copyright and patent license is granted only if the following
403446Smrj  * conditions are met:
413446Smrj  *
423446Smrj  * 3. Conditions
433446Smrj  *
443446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
453446Smrj  * Redistribution of source code of any substantial portion of the Covered
463446Smrj  * Code or modification with rights to further distribute source must include
473446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
483446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
493446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
503446Smrj  * contain a file documenting the changes Licensee made to create that Covered
513446Smrj  * Code and the date of any change.  Licensee must include in that file the
523446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
533446Smrj  * must include a prominent statement that the modification is derived,
543446Smrj  * directly or indirectly, from Original Intel Code.
553446Smrj  *
563446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
573446Smrj  * Redistribution of source code of any substantial portion of the Covered
583446Smrj  * Code or modification without rights to further distribute source must
593446Smrj  * include the following Disclaimer and Export Compliance provision in the
603446Smrj  * documentation and/or other materials provided with distribution.  In
613446Smrj  * addition, Licensee may not authorize further sublicense of source of any
623446Smrj  * portion of the Covered Code, and must include terms to the effect that the
633446Smrj  * license from Licensee to its licensee is limited to the intellectual
643446Smrj  * property embodied in the software Licensee provides to its licensee, and
653446Smrj  * not to intellectual property embodied in modifications its licensee may
663446Smrj  * make.
673446Smrj  *
683446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
693446Smrj  * substantial portion of the Covered Code or modification must reproduce the
703446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
713446Smrj  * provision in the documentation and/or other materials provided with the
723446Smrj  * distribution.
733446Smrj  *
743446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
753446Smrj  * Intel Code.
763446Smrj  *
773446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
783446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
793446Smrj  * other dealings in products derived from or relating to the Covered Code
803446Smrj  * without prior written authorization from Intel.
813446Smrj  *
823446Smrj  * 4. Disclaimer and Export Compliance
833446Smrj  *
843446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
853446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
863446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
873446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
883446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
893446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
903446Smrj  * PARTICULAR PURPOSE.
913446Smrj  *
923446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
933446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
943446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
953446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
963446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
973446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
983446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
993446Smrj  * LIMITED REMEDY.
1003446Smrj  *
1013446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1023446Smrj  * software or system incorporating such software without first obtaining any
1033446Smrj  * required license or other approval from the U. S. Department of Commerce or
1043446Smrj  * any other agency or department of the United States Government.  In the
1053446Smrj  * event Licensee exports any such software from the United States or
1063446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1073446Smrj  * ensure that the distribution and export/re-export of the software is in
1083446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1093446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1103446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1113446Smrj  * software, or service, directly or indirectly, to any country for which the
1123446Smrj  * United States government or any agency thereof requires an export license,
1133446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1143446Smrj  * such license, approval or letter.
1153446Smrj  *
1163446Smrj  *****************************************************************************/
1173446Smrj 
1183446Smrj #define __HWACPI_C__
1193446Smrj 
1203446Smrj #include "acpi.h"
1213446Smrj 
1223446Smrj 
1233446Smrj #define _COMPONENT          ACPI_HARDWARE
1243446Smrj         ACPI_MODULE_NAME    ("hwacpi")
1253446Smrj 
1263446Smrj 
1273446Smrj /******************************************************************************
1283446Smrj  *
1293446Smrj  * FUNCTION:    AcpiHwSetMode
1303446Smrj  *
1313446Smrj  * PARAMETERS:  Mode            - SYS_MODE_ACPI or SYS_MODE_LEGACY
1323446Smrj  *
1333446Smrj  * RETURN:      Status
1343446Smrj  *
1353446Smrj  * DESCRIPTION: Transitions the system into the requested mode.
1363446Smrj  *
1373446Smrj  ******************************************************************************/
1383446Smrj 
1393446Smrj ACPI_STATUS
1403446Smrj AcpiHwSetMode (
1413446Smrj     UINT32                  Mode)
1423446Smrj {
1433446Smrj 
1443446Smrj     ACPI_STATUS             Status;
1453446Smrj     UINT32                  Retry;
1463446Smrj 
1473446Smrj 
1483446Smrj     ACPI_FUNCTION_TRACE (HwSetMode);
1493446Smrj 
1503446Smrj     /*
1513446Smrj      * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
1523446Smrj      * system does not support mode transition.
1533446Smrj      */
154*7851SDana.Myers@Sun.COM     if (!AcpiGbl_FADT.SmiCommand)
1553446Smrj     {
1563446Smrj         ACPI_ERROR ((AE_INFO, "No SMI_CMD in FADT, mode transition failed"));
1573446Smrj         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
1583446Smrj     }
1593446Smrj 
1603446Smrj     /*
1613446Smrj      * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
1623446Smrj      * in FADT: If it is zero, enabling or disabling is not supported.
1633446Smrj      * As old systems may have used zero for mode transition,
1643446Smrj      * we make sure both the numbers are zero to determine these
1653446Smrj      * transitions are not supported.
1663446Smrj      */
167*7851SDana.Myers@Sun.COM     if (!AcpiGbl_FADT.AcpiEnable && !AcpiGbl_FADT.AcpiDisable)
1683446Smrj     {
1693446Smrj         ACPI_ERROR ((AE_INFO,
1703446Smrj             "No ACPI mode transition supported in this system (enable/disable both zero)"));
1713446Smrj         return_ACPI_STATUS (AE_OK);
1723446Smrj     }
1733446Smrj 
1743446Smrj     switch (Mode)
1753446Smrj     {
1763446Smrj     case ACPI_SYS_MODE_ACPI:
1773446Smrj 
1783446Smrj         /* BIOS should have disabled ALL fixed and GP events */
1793446Smrj 
180*7851SDana.Myers@Sun.COM         Status = AcpiOsWritePort (AcpiGbl_FADT.SmiCommand,
181*7851SDana.Myers@Sun.COM                         (UINT32) AcpiGbl_FADT.AcpiEnable, 8);
1823446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n"));
1833446Smrj         break;
1843446Smrj 
1853446Smrj     case ACPI_SYS_MODE_LEGACY:
1863446Smrj 
1873446Smrj         /*
1883446Smrj          * BIOS should clear all fixed status bits and restore fixed event
1893446Smrj          * enable bits to default
1903446Smrj          */
191*7851SDana.Myers@Sun.COM         Status = AcpiOsWritePort (AcpiGbl_FADT.SmiCommand,
192*7851SDana.Myers@Sun.COM                     (UINT32) AcpiGbl_FADT.AcpiDisable, 8);
1933446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
1943446Smrj                     "Attempting to enable Legacy (non-ACPI) mode\n"));
1953446Smrj         break;
1963446Smrj 
1973446Smrj     default:
1983446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
1993446Smrj     }
2003446Smrj 
2013446Smrj     if (ACPI_FAILURE (Status))
2023446Smrj     {
2033446Smrj         ACPI_EXCEPTION ((AE_INFO, Status,
2043446Smrj             "Could not write ACPI mode change"));
2053446Smrj         return_ACPI_STATUS (Status);
2063446Smrj     }
2073446Smrj 
2083446Smrj     /*
2093446Smrj      * Some hardware takes a LONG time to switch modes. Give them 3 sec to
2103446Smrj      * do so, but allow faster systems to proceed more quickly.
2113446Smrj      */
2123446Smrj     Retry = 3000;
2133446Smrj     while (Retry)
2143446Smrj     {
2153446Smrj         if (AcpiHwGetMode() == Mode)
2163446Smrj         {
2173446Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n",
2183446Smrj                 Mode));
2193446Smrj             return_ACPI_STATUS (AE_OK);
2203446Smrj         }
2213446Smrj         AcpiOsStall(1000);
2223446Smrj         Retry--;
2233446Smrj     }
2243446Smrj 
2253446Smrj     ACPI_ERROR ((AE_INFO, "Hardware did not change modes"));
2263446Smrj     return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
2273446Smrj }
2283446Smrj 
2293446Smrj 
2303446Smrj /*******************************************************************************
2313446Smrj  *
2323446Smrj  * FUNCTION:    AcpiHwGetMode
2333446Smrj  *
2343446Smrj  * PARAMETERS:  none
2353446Smrj  *
2363446Smrj  * RETURN:      SYS_MODE_ACPI or SYS_MODE_LEGACY
2373446Smrj  *
2383446Smrj  * DESCRIPTION: Return current operating state of system.  Determined by
2393446Smrj  *              querying the SCI_EN bit.
2403446Smrj  *
2413446Smrj  ******************************************************************************/
2423446Smrj 
2433446Smrj UINT32
2443446Smrj AcpiHwGetMode (
2453446Smrj     void)
2463446Smrj {
2473446Smrj     ACPI_STATUS             Status;
2483446Smrj     UINT32                  Value;
2493446Smrj 
2503446Smrj 
2513446Smrj     ACPI_FUNCTION_TRACE (HwGetMode);
2523446Smrj 
2533446Smrj 
2543446Smrj     /*
2553446Smrj      * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
2563446Smrj      * system does not support mode transition.
2573446Smrj      */
258*7851SDana.Myers@Sun.COM     if (!AcpiGbl_FADT.SmiCommand)
2593446Smrj     {
2603446Smrj         return_UINT32 (ACPI_SYS_MODE_ACPI);
2613446Smrj     }
2623446Smrj 
263*7851SDana.Myers@Sun.COM     Status = AcpiGetRegister (ACPI_BITREG_SCI_ENABLE, &Value);
2643446Smrj     if (ACPI_FAILURE (Status))
2653446Smrj     {
2663446Smrj         return_UINT32 (ACPI_SYS_MODE_LEGACY);
2673446Smrj     }
2683446Smrj 
2693446Smrj     if (Value)
2703446Smrj     {
2713446Smrj         return_UINT32 (ACPI_SYS_MODE_ACPI);
2723446Smrj     }
2733446Smrj     else
2743446Smrj     {
2753446Smrj         return_UINT32 (ACPI_SYS_MODE_LEGACY);
2763446Smrj     }
2773446Smrj }
278