ACPICA: Implement simplified Table Manager
[pandora-kernel.git] / drivers / acpi / hardware / hwacpi.c
1
2 /******************************************************************************
3  *
4  * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
5  *
6  *****************************************************************************/
7
8 /*
9  * Copyright (C) 2000 - 2006, R. Byron Moore
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions, and the following disclaimer,
17  *    without modification.
18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19  *    substantially similar to the "NO WARRANTY" disclaimer below
20  *    ("Disclaimer") and any redistribution must be conditioned upon
21  *    including a substantially similar Disclaimer requirement for further
22  *    binary redistribution.
23  * 3. Neither the names of the above-listed copyright holders nor the names
24  *    of any contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * Alternatively, this software may be distributed under the terms of the
28  * GNU General Public License ("GPL") version 2 as published by the Free
29  * Software Foundation.
30  *
31  * NO WARRANTY
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGES.
43  */
44
45 #include <acpi/acpi.h>
46
47 #define _COMPONENT          ACPI_HARDWARE
48 ACPI_MODULE_NAME("hwacpi")
49
50 /******************************************************************************
51  *
52  * FUNCTION:    acpi_hw_initialize
53  *
54  * PARAMETERS:  None
55  *
56  * RETURN:      Status
57  *
58  * DESCRIPTION: Initialize and validate the various ACPI registers defined in
59  *              the FADT.
60  *
61  ******************************************************************************/
62 acpi_status acpi_hw_initialize(void)
63 {
64         acpi_status status;
65
66         ACPI_FUNCTION_TRACE(hw_initialize);
67
68         /* Sanity check the FADT for valid values */
69
70         status = acpi_ut_validate_fadt();
71         if (ACPI_FAILURE(status)) {
72                 return_ACPI_STATUS(status);
73         }
74
75         return_ACPI_STATUS(AE_OK);
76 }
77
78 /******************************************************************************
79  *
80  * FUNCTION:    acpi_hw_set_mode
81  *
82  * PARAMETERS:  Mode            - SYS_MODE_ACPI or SYS_MODE_LEGACY
83  *
84  * RETURN:      Status
85  *
86  * DESCRIPTION: Transitions the system into the requested mode.
87  *
88  ******************************************************************************/
89
90 acpi_status acpi_hw_set_mode(u32 mode)
91 {
92
93         acpi_status status;
94         u32 retry;
95
96         ACPI_FUNCTION_TRACE(hw_set_mode);
97
98         /*
99          * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
100          * system does not support mode transition.
101          */
102         if (!acpi_gbl_FADT.smi_command) {
103                 ACPI_ERROR((AE_INFO,
104                             "No SMI_CMD in FADT, mode transition failed"));
105                 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
106         }
107
108         /*
109          * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
110          * in FADT: If it is zero, enabling or disabling is not supported.
111          * As old systems may have used zero for mode transition,
112          * we make sure both the numbers are zero to determine these
113          * transitions are not supported.
114          */
115         if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
116                 ACPI_ERROR((AE_INFO,
117                             "No ACPI mode transition supported in this system (enable/disable both zero)"));
118                 return_ACPI_STATUS(AE_OK);
119         }
120
121         switch (mode) {
122         case ACPI_SYS_MODE_ACPI:
123
124                 /* BIOS should have disabled ALL fixed and GP events */
125
126                 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
127                                             (u32) acpi_gbl_FADT.acpi_enable, 8);
128                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
129                                   "Attempting to enable ACPI mode\n"));
130                 break;
131
132         case ACPI_SYS_MODE_LEGACY:
133
134                 /*
135                  * BIOS should clear all fixed status bits and restore fixed event
136                  * enable bits to default
137                  */
138                 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
139                                             (u32) acpi_gbl_FADT.acpi_disable,
140                                             8);
141                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
142                                   "Attempting to enable Legacy (non-ACPI) mode\n"));
143                 break;
144
145         default:
146                 return_ACPI_STATUS(AE_BAD_PARAMETER);
147         }
148
149         if (ACPI_FAILURE(status)) {
150                 ACPI_EXCEPTION((AE_INFO, status,
151                                 "Could not write ACPI mode change"));
152                 return_ACPI_STATUS(status);
153         }
154
155         /*
156          * Some hardware takes a LONG time to switch modes. Give them 3 sec to
157          * do so, but allow faster systems to proceed more quickly.
158          */
159         retry = 3000;
160         while (retry) {
161                 if (acpi_hw_get_mode() == mode) {
162                         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
163                                           "Mode %X successfully enabled\n",
164                                           mode));
165                         return_ACPI_STATUS(AE_OK);
166                 }
167                 acpi_os_stall(1000);
168                 retry--;
169         }
170
171         ACPI_ERROR((AE_INFO, "Hardware did not change modes"));
172         return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
173 }
174
175 /*******************************************************************************
176  *
177  * FUNCTION:    acpi_hw_get_mode
178  *
179  * PARAMETERS:  none
180  *
181  * RETURN:      SYS_MODE_ACPI or SYS_MODE_LEGACY
182  *
183  * DESCRIPTION: Return current operating state of system.  Determined by
184  *              querying the SCI_EN bit.
185  *
186  ******************************************************************************/
187
188 u32 acpi_hw_get_mode(void)
189 {
190         acpi_status status;
191         u32 value;
192
193         ACPI_FUNCTION_TRACE(hw_get_mode);
194
195         /*
196          * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
197          * system does not support mode transition.
198          */
199         if (!acpi_gbl_FADT.smi_command) {
200                 return_UINT32(ACPI_SYS_MODE_ACPI);
201         }
202
203         status =
204             acpi_get_register(ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
205         if (ACPI_FAILURE(status)) {
206                 return_UINT32(ACPI_SYS_MODE_LEGACY);
207         }
208
209         if (value) {
210                 return_UINT32(ACPI_SYS_MODE_ACPI);
211         } else {
212                 return_UINT32(ACPI_SYS_MODE_LEGACY);
213         }
214 }