1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj *
3ae115bc7Smrj * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
4ae115bc7Smrj *
5ae115bc7Smrj *****************************************************************************/
6ae115bc7Smrj
726f3cdf0SGordon Ross /*
8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj * All rights reserved.
10ae115bc7Smrj *
1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross * are met:
1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross * without modification.
1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross * binary redistribution.
2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross * from this software without specific prior written permission.
25ae115bc7Smrj *
2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross * Software Foundation.
29ae115bc7Smrj *
3026f3cdf0SGordon Ross * NO WARRANTY
3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross */
43ae115bc7Smrj
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj
47ae115bc7Smrj
48ae115bc7Smrj #define _COMPONENT ACPI_HARDWARE
49ae115bc7Smrj ACPI_MODULE_NAME ("hwacpi")
50ae115bc7Smrj
51ae115bc7Smrj
52*385cc6b4SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53ae115bc7Smrj /******************************************************************************
54ae115bc7Smrj *
55ae115bc7Smrj * FUNCTION: AcpiHwSetMode
56ae115bc7Smrj *
57ae115bc7Smrj * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
58ae115bc7Smrj *
59ae115bc7Smrj * RETURN: Status
60ae115bc7Smrj *
61ae115bc7Smrj * DESCRIPTION: Transitions the system into the requested mode.
62ae115bc7Smrj *
63ae115bc7Smrj ******************************************************************************/
64ae115bc7Smrj
65ae115bc7Smrj ACPI_STATUS
AcpiHwSetMode(UINT32 Mode)66ae115bc7Smrj AcpiHwSetMode (
67ae115bc7Smrj UINT32 Mode)
68ae115bc7Smrj {
69ae115bc7Smrj
70ae115bc7Smrj ACPI_STATUS Status;
71ae115bc7Smrj UINT32 Retry;
72ae115bc7Smrj
73ae115bc7Smrj
74ae115bc7Smrj ACPI_FUNCTION_TRACE (HwSetMode);
75ae115bc7Smrj
76*385cc6b4SJerry Jelinek
77*385cc6b4SJerry Jelinek /* If the Hardware Reduced flag is set, machine is always in acpi mode */
78*385cc6b4SJerry Jelinek
79*385cc6b4SJerry Jelinek if (AcpiGbl_ReducedHardware)
80*385cc6b4SJerry Jelinek {
81*385cc6b4SJerry Jelinek return_ACPI_STATUS (AE_OK);
82*385cc6b4SJerry Jelinek }
83*385cc6b4SJerry Jelinek
84ae115bc7Smrj /*
85ae115bc7Smrj * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
86ae115bc7Smrj * system does not support mode transition.
87ae115bc7Smrj */
88db2bae30SDana Myers if (!AcpiGbl_FADT.SmiCommand)
89ae115bc7Smrj {
90ae115bc7Smrj ACPI_ERROR ((AE_INFO, "No SMI_CMD in FADT, mode transition failed"));
91ae115bc7Smrj return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
92ae115bc7Smrj }
93ae115bc7Smrj
94ae115bc7Smrj /*
95ae115bc7Smrj * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
96ae115bc7Smrj * in FADT: If it is zero, enabling or disabling is not supported.
97ae115bc7Smrj * As old systems may have used zero for mode transition,
98ae115bc7Smrj * we make sure both the numbers are zero to determine these
99ae115bc7Smrj * transitions are not supported.
100ae115bc7Smrj */
101db2bae30SDana Myers if (!AcpiGbl_FADT.AcpiEnable && !AcpiGbl_FADT.AcpiDisable)
102ae115bc7Smrj {
103ae115bc7Smrj ACPI_ERROR ((AE_INFO,
104aa2aa9a6SDana Myers "No ACPI mode transition supported in this system "
105aa2aa9a6SDana Myers "(enable/disable both zero)"));
106ae115bc7Smrj return_ACPI_STATUS (AE_OK);
107ae115bc7Smrj }
108ae115bc7Smrj
109ae115bc7Smrj switch (Mode)
110ae115bc7Smrj {
111ae115bc7Smrj case ACPI_SYS_MODE_ACPI:
112ae115bc7Smrj
113ae115bc7Smrj /* BIOS should have disabled ALL fixed and GP events */
114ae115bc7Smrj
115aa2aa9a6SDana Myers Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand,
116db2bae30SDana Myers (UINT32) AcpiGbl_FADT.AcpiEnable, 8);
117ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n"));
118ae115bc7Smrj break;
119ae115bc7Smrj
120ae115bc7Smrj case ACPI_SYS_MODE_LEGACY:
121ae115bc7Smrj /*
122ae115bc7Smrj * BIOS should clear all fixed status bits and restore fixed event
123ae115bc7Smrj * enable bits to default
124ae115bc7Smrj */
125aa2aa9a6SDana Myers Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand,
126db2bae30SDana Myers (UINT32) AcpiGbl_FADT.AcpiDisable, 8);
127ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
128ae115bc7Smrj "Attempting to enable Legacy (non-ACPI) mode\n"));
129ae115bc7Smrj break;
130ae115bc7Smrj
131ae115bc7Smrj default:
132*385cc6b4SJerry Jelinek
133ae115bc7Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
134ae115bc7Smrj }
135ae115bc7Smrj
136ae115bc7Smrj if (ACPI_FAILURE (Status))
137ae115bc7Smrj {
138ae115bc7Smrj ACPI_EXCEPTION ((AE_INFO, Status,
139ae115bc7Smrj "Could not write ACPI mode change"));
140ae115bc7Smrj return_ACPI_STATUS (Status);
141ae115bc7Smrj }
142ae115bc7Smrj
143ae115bc7Smrj /*
144ae115bc7Smrj * Some hardware takes a LONG time to switch modes. Give them 3 sec to
145ae115bc7Smrj * do so, but allow faster systems to proceed more quickly.
146ae115bc7Smrj */
147ae115bc7Smrj Retry = 3000;
148ae115bc7Smrj while (Retry)
149ae115bc7Smrj {
150ae115bc7Smrj if (AcpiHwGetMode () == Mode)
151ae115bc7Smrj {
152*385cc6b4SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
153*385cc6b4SJerry Jelinek "Mode %X successfully enabled\n", Mode));
154ae115bc7Smrj return_ACPI_STATUS (AE_OK);
155ae115bc7Smrj }
156*385cc6b4SJerry Jelinek AcpiOsStall (ACPI_USEC_PER_MSEC);
157ae115bc7Smrj Retry--;
158ae115bc7Smrj }
159ae115bc7Smrj
160ae115bc7Smrj ACPI_ERROR ((AE_INFO, "Hardware did not change modes"));
161ae115bc7Smrj return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
162ae115bc7Smrj }
163ae115bc7Smrj
164ae115bc7Smrj
165ae115bc7Smrj /*******************************************************************************
166ae115bc7Smrj *
167ae115bc7Smrj * FUNCTION: AcpiHwGetMode
168ae115bc7Smrj *
169ae115bc7Smrj * PARAMETERS: none
170ae115bc7Smrj *
171ae115bc7Smrj * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
172ae115bc7Smrj *
173ae115bc7Smrj * DESCRIPTION: Return current operating state of system. Determined by
174ae115bc7Smrj * querying the SCI_EN bit.
175ae115bc7Smrj *
176ae115bc7Smrj ******************************************************************************/
177ae115bc7Smrj
178ae115bc7Smrj UINT32
AcpiHwGetMode(void)179ae115bc7Smrj AcpiHwGetMode (
180ae115bc7Smrj void)
181ae115bc7Smrj {
182ae115bc7Smrj ACPI_STATUS Status;
183ae115bc7Smrj UINT32 Value;
184ae115bc7Smrj
185ae115bc7Smrj
186ae115bc7Smrj ACPI_FUNCTION_TRACE (HwGetMode);
187ae115bc7Smrj
188ae115bc7Smrj
189*385cc6b4SJerry Jelinek /* If the Hardware Reduced flag is set, machine is always in acpi mode */
190*385cc6b4SJerry Jelinek
191*385cc6b4SJerry Jelinek if (AcpiGbl_ReducedHardware)
192*385cc6b4SJerry Jelinek {
193*385cc6b4SJerry Jelinek return_UINT32 (ACPI_SYS_MODE_ACPI);
194*385cc6b4SJerry Jelinek }
195*385cc6b4SJerry Jelinek
196ae115bc7Smrj /*
197ae115bc7Smrj * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
198ae115bc7Smrj * system does not support mode transition.
199ae115bc7Smrj */
200db2bae30SDana Myers if (!AcpiGbl_FADT.SmiCommand)
201ae115bc7Smrj {
202ae115bc7Smrj return_UINT32 (ACPI_SYS_MODE_ACPI);
203ae115bc7Smrj }
204ae115bc7Smrj
205aa2aa9a6SDana Myers Status = AcpiReadBitRegister (ACPI_BITREG_SCI_ENABLE, &Value);
206ae115bc7Smrj if (ACPI_FAILURE (Status))
207ae115bc7Smrj {
208ae115bc7Smrj return_UINT32 (ACPI_SYS_MODE_LEGACY);
209ae115bc7Smrj }
210ae115bc7Smrj
211ae115bc7Smrj if (Value)
212ae115bc7Smrj {
213ae115bc7Smrj return_UINT32 (ACPI_SYS_MODE_ACPI);
214ae115bc7Smrj }
215ae115bc7Smrj else
216ae115bc7Smrj {
217ae115bc7Smrj return_UINT32 (ACPI_SYS_MODE_LEGACY);
218ae115bc7Smrj }
219ae115bc7Smrj }
220*385cc6b4SJerry Jelinek
221*385cc6b4SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */
222