aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/hardware
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/acpi/hardware
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/acpi/hardware')
-rw-r--r--drivers/acpi/hardware/Makefile9
-rw-r--r--drivers/acpi/hardware/hwacpi.c230
-rw-r--r--drivers/acpi/hardware/hwgpe.c444
-rw-r--r--drivers/acpi/hardware/hwregs.c850
-rw-r--r--drivers/acpi/hardware/hwsleep.c582
-rw-r--r--drivers/acpi/hardware/hwtimer.c203
6 files changed, 2318 insertions, 0 deletions
diff --git a/drivers/acpi/hardware/Makefile b/drivers/acpi/hardware/Makefile
new file mode 100644
index 000000000000..438ad373b9ad
--- /dev/null
+++ b/drivers/acpi/hardware/Makefile
@@ -0,0 +1,9 @@
1#
2# Makefile for all Linux ACPI interpreter subdirectories
3#
4
5obj-y := hwacpi.o hwgpe.o hwregs.o hwsleep.o
6
7obj-$(ACPI_FUTURE_USAGE) += hwtimer.o
8
9EXTRA_CFLAGS += $(ACPI_CFLAGS)
diff --git a/drivers/acpi/hardware/hwacpi.c b/drivers/acpi/hardware/hwacpi.c
new file mode 100644
index 000000000000..529e922bdc85
--- /dev/null
+++ b/drivers/acpi/hardware/hwacpi.c
@@ -0,0 +1,230 @@
1
2/******************************************************************************
3 *
4 * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2005, 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
46#include <acpi/acpi.h>
47
48
49#define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwacpi")
51
52
53/******************************************************************************
54 *
55 * FUNCTION: acpi_hw_initialize
56 *
57 * PARAMETERS: None
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Initialize and validate various ACPI registers
62 *
63 ******************************************************************************/
64
65acpi_status
66acpi_hw_initialize (
67 void)
68{
69 acpi_status status;
70
71
72 ACPI_FUNCTION_TRACE ("hw_initialize");
73
74
75 /* We must have the ACPI tables by the time we get here */
76
77 if (!acpi_gbl_FADT) {
78 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "A FADT is not loaded\n"));
79
80 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
81 }
82
83 /* Sanity check the FADT for valid values */
84
85 status = acpi_ut_validate_fadt ();
86 if (ACPI_FAILURE (status)) {
87 return_ACPI_STATUS (status);
88 }
89
90 return_ACPI_STATUS (AE_OK);
91}
92
93
94/******************************************************************************
95 *
96 * FUNCTION: acpi_hw_set_mode
97 *
98 * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
99 *
100 * RETURN: Status
101 *
102 * DESCRIPTION: Transitions the system into the requested mode.
103 *
104 ******************************************************************************/
105
106acpi_status
107acpi_hw_set_mode (
108 u32 mode)
109{
110
111 acpi_status status;
112 u32 retry;
113
114
115 ACPI_FUNCTION_TRACE ("hw_set_mode");
116
117 /*
118 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
119 * system does not support mode transition.
120 */
121 if (!acpi_gbl_FADT->smi_cmd) {
122 ACPI_REPORT_ERROR (("No SMI_CMD in FADT, mode transition failed.\n"));
123 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
124 }
125
126 /*
127 * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
128 * in FADT: If it is zero, enabling or disabling is not supported.
129 * As old systems may have used zero for mode transition,
130 * we make sure both the numbers are zero to determine these
131 * transitions are not supported.
132 */
133 if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) {
134 ACPI_REPORT_ERROR (("No ACPI mode transition supported in this system (enable/disable both zero)\n"));
135 return_ACPI_STATUS (AE_OK);
136 }
137
138 switch (mode) {
139 case ACPI_SYS_MODE_ACPI:
140
141 /* BIOS should have disabled ALL fixed and GP events */
142
143 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
144 (u32) acpi_gbl_FADT->acpi_enable, 8);
145 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n"));
146 break;
147
148 case ACPI_SYS_MODE_LEGACY:
149
150 /*
151 * BIOS should clear all fixed status bits and restore fixed event
152 * enable bits to default
153 */
154 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
155 (u32) acpi_gbl_FADT->acpi_disable, 8);
156 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
157 "Attempting to enable Legacy (non-ACPI) mode\n"));
158 break;
159
160 default:
161 return_ACPI_STATUS (AE_BAD_PARAMETER);
162 }
163
164 if (ACPI_FAILURE (status)) {
165 ACPI_REPORT_ERROR (("Could not write mode change, %s\n", acpi_format_exception (status)));
166 return_ACPI_STATUS (status);
167 }
168
169 /*
170 * Some hardware takes a LONG time to switch modes. Give them 3 sec to
171 * do so, but allow faster systems to proceed more quickly.
172 */
173 retry = 3000;
174 while (retry) {
175 if (acpi_hw_get_mode() == mode) {
176 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", mode));
177 return_ACPI_STATUS (AE_OK);
178 }
179 acpi_os_stall(1000);
180 retry--;
181 }
182
183 ACPI_REPORT_ERROR (("Hardware never changed modes\n"));
184 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
185}
186
187
188/******************************************************************************
189 *
190 * FUNCTION: acpi_hw_get_mode
191 *
192 * PARAMETERS: none
193 *
194 * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
195 *
196 * DESCRIPTION: Return current operating state of system. Determined by
197 * querying the SCI_EN bit.
198 *
199 ******************************************************************************/
200
201u32
202acpi_hw_get_mode (void)
203{
204 acpi_status status;
205 u32 value;
206
207
208 ACPI_FUNCTION_TRACE ("hw_get_mode");
209
210
211 /*
212 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
213 * system does not support mode transition.
214 */
215 if (!acpi_gbl_FADT->smi_cmd) {
216 return_VALUE (ACPI_SYS_MODE_ACPI);
217 }
218
219 status = acpi_get_register (ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
220 if (ACPI_FAILURE (status)) {
221 return_VALUE (ACPI_SYS_MODE_LEGACY);
222 }
223
224 if (value) {
225 return_VALUE (ACPI_SYS_MODE_ACPI);
226 }
227 else {
228 return_VALUE (ACPI_SYS_MODE_LEGACY);
229 }
230}
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
new file mode 100644
index 000000000000..9ac1d639bf51
--- /dev/null
+++ b/drivers/acpi/hardware/hwgpe.c
@@ -0,0 +1,444 @@
1
2/******************************************************************************
3 *
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2005, 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#include <acpi/acevents.h>
47
48#define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwgpe")
50
51
52/******************************************************************************
53 *
54 * FUNCTION: acpi_hw_write_gpe_enable_reg
55 *
56 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
61 * already be cleared or set in the parent register
62 * enable_for_run mask.
63 *
64 ******************************************************************************/
65
66acpi_status
67acpi_hw_write_gpe_enable_reg (
68 struct acpi_gpe_event_info *gpe_event_info)
69{
70 struct acpi_gpe_register_info *gpe_register_info;
71 acpi_status status;
72
73
74 ACPI_FUNCTION_ENTRY ();
75
76
77 /* Get the info block for the entire GPE register */
78
79 gpe_register_info = gpe_event_info->register_info;
80 if (!gpe_register_info) {
81 return (AE_NOT_EXIST);
82 }
83
84 /* Write the entire GPE (runtime) enable register */
85
86 status = acpi_hw_low_level_write (8, gpe_register_info->enable_for_run,
87 &gpe_register_info->enable_address);
88
89 return (status);
90}
91
92
93/******************************************************************************
94 *
95 * FUNCTION: acpi_hw_clear_gpe
96 *
97 * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
98 *
99 * RETURN: Status
100 *
101 * DESCRIPTION: Clear the status bit for a single GPE.
102 *
103 ******************************************************************************/
104
105acpi_status
106acpi_hw_clear_gpe (
107 struct acpi_gpe_event_info *gpe_event_info)
108{
109 acpi_status status;
110
111
112 ACPI_FUNCTION_ENTRY ();
113
114
115 /*
116 * Write a one to the appropriate bit in the status register to
117 * clear this GPE.
118 */
119 status = acpi_hw_low_level_write (8, gpe_event_info->register_bit,
120 &gpe_event_info->register_info->status_address);
121
122 return (status);
123}
124
125
126/******************************************************************************
127 *
128 * FUNCTION: acpi_hw_get_gpe_status
129 *
130 * PARAMETERS: gpe_event_info - Info block for the GPE to queried
131 * event_status - Where the GPE status is returned
132 *
133 * RETURN: Status
134 *
135 * DESCRIPTION: Return the status of a single GPE.
136 *
137 ******************************************************************************/
138#ifdef ACPI_FUTURE_USAGE
139acpi_status
140acpi_hw_get_gpe_status (
141 struct acpi_gpe_event_info *gpe_event_info,
142 acpi_event_status *event_status)
143{
144 u32 in_byte;
145 u8 register_bit;
146 struct acpi_gpe_register_info *gpe_register_info;
147 acpi_status status;
148 acpi_event_status local_event_status = 0;
149
150
151 ACPI_FUNCTION_ENTRY ();
152
153
154 if (!event_status) {
155 return (AE_BAD_PARAMETER);
156 }
157
158 /* Get the info block for the entire GPE register */
159
160 gpe_register_info = gpe_event_info->register_info;
161
162 /* Get the register bitmask for this GPE */
163
164 register_bit = gpe_event_info->register_bit;
165
166 /* GPE currently enabled? (enabled for runtime?) */
167
168 if (register_bit & gpe_register_info->enable_for_run) {
169 local_event_status |= ACPI_EVENT_FLAG_ENABLED;
170 }
171
172 /* GPE enabled for wake? */
173
174 if (register_bit & gpe_register_info->enable_for_wake) {
175 local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
176 }
177
178 /* GPE currently active (status bit == 1)? */
179
180 status = acpi_hw_low_level_read (8, &in_byte, &gpe_register_info->status_address);
181 if (ACPI_FAILURE (status)) {
182 goto unlock_and_exit;
183 }
184
185 if (register_bit & in_byte) {
186 local_event_status |= ACPI_EVENT_FLAG_SET;
187 }
188
189 /* Set return value */
190
191 (*event_status) = local_event_status;
192
193
194unlock_and_exit:
195 return (status);
196}
197#endif /* ACPI_FUTURE_USAGE */
198
199
200/******************************************************************************
201 *
202 * FUNCTION: acpi_hw_disable_gpe_block
203 *
204 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
205 * gpe_block - Gpe Block info
206 *
207 * RETURN: Status
208 *
209 * DESCRIPTION: Disable all GPEs within a GPE block
210 *
211 ******************************************************************************/
212
213acpi_status
214acpi_hw_disable_gpe_block (
215 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
216 struct acpi_gpe_block_info *gpe_block)
217{
218 u32 i;
219 acpi_status status;
220
221
222 /* Examine each GPE Register within the block */
223
224 for (i = 0; i < gpe_block->register_count; i++) {
225 /* Disable all GPEs in this register */
226
227 status = acpi_hw_low_level_write (8, 0x00,
228 &gpe_block->register_info[i].enable_address);
229 if (ACPI_FAILURE (status)) {
230 return (status);
231 }
232 }
233
234 return (AE_OK);
235}
236
237
238/******************************************************************************
239 *
240 * FUNCTION: acpi_hw_clear_gpe_block
241 *
242 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
243 * gpe_block - Gpe Block info
244 *
245 * RETURN: Status
246 *
247 * DESCRIPTION: Clear status bits for all GPEs within a GPE block
248 *
249 ******************************************************************************/
250
251acpi_status
252acpi_hw_clear_gpe_block (
253 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
254 struct acpi_gpe_block_info *gpe_block)
255{
256 u32 i;
257 acpi_status status;
258
259
260 /* Examine each GPE Register within the block */
261
262 for (i = 0; i < gpe_block->register_count; i++) {
263 /* Clear status on all GPEs in this register */
264
265 status = acpi_hw_low_level_write (8, 0xFF,
266 &gpe_block->register_info[i].status_address);
267 if (ACPI_FAILURE (status)) {
268 return (status);
269 }
270 }
271
272 return (AE_OK);
273}
274
275
276/******************************************************************************
277 *
278 * FUNCTION: acpi_hw_enable_runtime_gpe_block
279 *
280 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
281 * gpe_block - Gpe Block info
282 *
283 * RETURN: Status
284 *
285 * DESCRIPTION: Enable all "runtime" GPEs within a GPE block. (Includes
286 * combination wake/run GPEs.)
287 *
288 ******************************************************************************/
289
290acpi_status
291acpi_hw_enable_runtime_gpe_block (
292 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
293 struct acpi_gpe_block_info *gpe_block)
294{
295 u32 i;
296 acpi_status status;
297
298
299 /* NOTE: assumes that all GPEs are currently disabled */
300
301 /* Examine each GPE Register within the block */
302
303 for (i = 0; i < gpe_block->register_count; i++) {
304 if (!gpe_block->register_info[i].enable_for_run) {
305 continue;
306 }
307
308 /* Enable all "runtime" GPEs in this register */
309
310 status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_run,
311 &gpe_block->register_info[i].enable_address);
312 if (ACPI_FAILURE (status)) {
313 return (status);
314 }
315 }
316
317 return (AE_OK);
318}
319
320
321/******************************************************************************
322 *
323 * FUNCTION: acpi_hw_enable_wakeup_gpe_block
324 *
325 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
326 * gpe_block - Gpe Block info
327 *
328 * RETURN: Status
329 *
330 * DESCRIPTION: Enable all "wake" GPEs within a GPE block. (Includes
331 * combination wake/run GPEs.)
332 *
333 ******************************************************************************/
334
335acpi_status
336acpi_hw_enable_wakeup_gpe_block (
337 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
338 struct acpi_gpe_block_info *gpe_block)
339{
340 u32 i;
341 acpi_status status;
342
343
344 /* Examine each GPE Register within the block */
345
346 for (i = 0; i < gpe_block->register_count; i++) {
347 if (!gpe_block->register_info[i].enable_for_wake) {
348 continue;
349 }
350
351 /* Enable all "wake" GPEs in this register */
352
353 status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_wake,
354 &gpe_block->register_info[i].enable_address);
355 if (ACPI_FAILURE (status)) {
356 return (status);
357 }
358 }
359
360 return (AE_OK);
361}
362
363
364/******************************************************************************
365 *
366 * FUNCTION: acpi_hw_disable_all_gpes
367 *
368 * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
369 *
370 * RETURN: Status
371 *
372 * DESCRIPTION: Disable and clear all GPEs
373 *
374 ******************************************************************************/
375
376acpi_status
377acpi_hw_disable_all_gpes (
378 u32 flags)
379{
380 acpi_status status;
381
382
383 ACPI_FUNCTION_TRACE ("hw_disable_all_gpes");
384
385
386 status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, flags);
387 status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, flags);
388 return_ACPI_STATUS (status);
389}
390
391
392/******************************************************************************
393 *
394 * FUNCTION: acpi_hw_enable_all_runtime_gpes
395 *
396 * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
397 *
398 * RETURN: Status
399 *
400 * DESCRIPTION: Enable all GPEs of the given type
401 *
402 ******************************************************************************/
403
404acpi_status
405acpi_hw_enable_all_runtime_gpes (
406 u32 flags)
407{
408 acpi_status status;
409
410
411 ACPI_FUNCTION_TRACE ("hw_enable_all_runtime_gpes");
412
413
414 status = acpi_ev_walk_gpe_list (acpi_hw_enable_runtime_gpe_block, flags);
415 return_ACPI_STATUS (status);
416}
417
418
419/******************************************************************************
420 *
421 * FUNCTION: acpi_hw_enable_all_wakeup_gpes
422 *
423 * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
424 *
425 * RETURN: Status
426 *
427 * DESCRIPTION: Enable all GPEs of the given type
428 *
429 ******************************************************************************/
430
431acpi_status
432acpi_hw_enable_all_wakeup_gpes (
433 u32 flags)
434{
435 acpi_status status;
436
437
438 ACPI_FUNCTION_TRACE ("hw_enable_all_wakeup_gpes");
439
440
441 status = acpi_ev_walk_gpe_list (acpi_hw_enable_wakeup_gpe_block, flags);
442 return_ACPI_STATUS (status);
443}
444
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
new file mode 100644
index 000000000000..91af0c2ddcf7
--- /dev/null
+++ b/drivers/acpi/hardware/hwregs.c
@@ -0,0 +1,850 @@
1
2/*******************************************************************************
3 *
4 * Module Name: hwregs - Read/write access functions for the various ACPI
5 * control and status registers.
6 *
7 ******************************************************************************/
8
9/*
10 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions, and the following disclaimer,
18 * without modification.
19 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
20 * substantially similar to the "NO WARRANTY" disclaimer below
21 * ("Disclaimer") and any redistribution must be conditioned upon
22 * including a substantially similar Disclaimer requirement for further
23 * binary redistribution.
24 * 3. Neither the names of the above-listed copyright holders nor the names
25 * of any contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * Alternatively, this software may be distributed under the terms of the
29 * GNU General Public License ("GPL") version 2 as published by the Free
30 * Software Foundation.
31 *
32 * NO WARRANTY
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGES.
44 */
45
46#include <linux/module.h>
47
48#include <acpi/acpi.h>
49#include <acpi/acnamesp.h>
50#include <acpi/acevents.h>
51
52#define _COMPONENT ACPI_HARDWARE
53 ACPI_MODULE_NAME ("hwregs")
54
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_hw_clear_acpi_status
59 *
60 * PARAMETERS: Flags - Lock the hardware or not
61 *
62 * RETURN: none
63 *
64 * DESCRIPTION: Clears all fixed and general purpose status bits
65 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
66 *
67 ******************************************************************************/
68
69acpi_status
70acpi_hw_clear_acpi_status (
71 u32 flags)
72{
73 acpi_status status;
74
75
76 ACPI_FUNCTION_TRACE ("hw_clear_acpi_status");
77
78
79 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %04X\n",
80 ACPI_BITMASK_ALL_FIXED_STATUS,
81 (u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
82
83 if (flags & ACPI_MTX_LOCK) {
84 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
85 if (ACPI_FAILURE (status)) {
86 return_ACPI_STATUS (status);
87 }
88 }
89
90 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
91 ACPI_BITMASK_ALL_FIXED_STATUS);
92 if (ACPI_FAILURE (status)) {
93 goto unlock_and_exit;
94 }
95
96 /* Clear the fixed events */
97
98 if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
99 status = acpi_hw_low_level_write (16, ACPI_BITMASK_ALL_FIXED_STATUS,
100 &acpi_gbl_FADT->xpm1b_evt_blk);
101 if (ACPI_FAILURE (status)) {
102 goto unlock_and_exit;
103 }
104 }
105
106 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
107
108 status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, ACPI_ISR);
109
110unlock_and_exit:
111 if (flags & ACPI_MTX_LOCK) {
112 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
113 }
114 return_ACPI_STATUS (status);
115}
116
117
118/*******************************************************************************
119 *
120 * FUNCTION: acpi_get_sleep_type_data
121 *
122 * PARAMETERS: sleep_state - Numeric sleep state
123 * *sleep_type_a - Where SLP_TYPa is returned
124 * *sleep_type_b - Where SLP_TYPb is returned
125 *
126 * RETURN: Status - ACPI status
127 *
128 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
129 * state.
130 *
131 ******************************************************************************/
132
133acpi_status
134acpi_get_sleep_type_data (
135 u8 sleep_state,
136 u8 *sleep_type_a,
137 u8 *sleep_type_b)
138{
139 acpi_status status = AE_OK;
140 struct acpi_parameter_info info;
141
142
143 ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data");
144
145
146 /*
147 * Validate parameters
148 */
149 if ((sleep_state > ACPI_S_STATES_MAX) ||
150 !sleep_type_a || !sleep_type_b) {
151 return_ACPI_STATUS (AE_BAD_PARAMETER);
152 }
153
154 /*
155 * Evaluate the namespace object containing the values for this state
156 */
157 info.parameters = NULL;
158 status = acpi_ns_evaluate_by_name ((char *) acpi_gbl_sleep_state_names[sleep_state],
159 &info);
160 if (ACPI_FAILURE (status)) {
161 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating sleep_state [%s]\n",
162 acpi_format_exception (status), acpi_gbl_sleep_state_names[sleep_state]));
163
164 return_ACPI_STATUS (status);
165 }
166
167 /* Must have a return object */
168
169 if (!info.return_object) {
170 ACPI_REPORT_ERROR (("Missing Sleep State object\n"));
171 status = AE_NOT_EXIST;
172 }
173
174 /* It must be of type Package */
175
176 else if (ACPI_GET_OBJECT_TYPE (info.return_object) != ACPI_TYPE_PACKAGE) {
177 ACPI_REPORT_ERROR (("Sleep State object not a Package\n"));
178 status = AE_AML_OPERAND_TYPE;
179 }
180
181 /* The package must have at least two elements */
182
183 else if (info.return_object->package.count < 2) {
184 ACPI_REPORT_ERROR (("Sleep State package does not have at least two elements\n"));
185 status = AE_AML_NO_OPERAND;
186 }
187
188 /* The first two elements must both be of type Integer */
189
190 else if ((ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[0]) != ACPI_TYPE_INTEGER) ||
191 (ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[1]) != ACPI_TYPE_INTEGER)) {
192 ACPI_REPORT_ERROR (("Sleep State package elements are not both Integers (%s, %s)\n",
193 acpi_ut_get_object_type_name (info.return_object->package.elements[0]),
194 acpi_ut_get_object_type_name (info.return_object->package.elements[1])));
195 status = AE_AML_OPERAND_TYPE;
196 }
197 else {
198 /*
199 * Valid _Sx_ package size, type, and value
200 */
201 *sleep_type_a = (u8) (info.return_object->package.elements[0])->integer.value;
202 *sleep_type_b = (u8) (info.return_object->package.elements[1])->integer.value;
203 }
204
205 if (ACPI_FAILURE (status)) {
206 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
207 "While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
208 acpi_gbl_sleep_state_names[sleep_state], info.return_object,
209 acpi_ut_get_object_type_name (info.return_object)));
210 }
211
212 acpi_ut_remove_reference (info.return_object);
213 return_ACPI_STATUS (status);
214}
215EXPORT_SYMBOL(acpi_get_sleep_type_data);
216
217
218/*******************************************************************************
219 *
220 * FUNCTION: acpi_hw_get_register_bit_mask
221 *
222 * PARAMETERS: register_id - Index of ACPI Register to access
223 *
224 * RETURN: The bit mask to be used when accessing the register
225 *
226 * DESCRIPTION: Map register_id into a register bit mask.
227 *
228 ******************************************************************************/
229
230struct acpi_bit_register_info *
231acpi_hw_get_bit_register_info (
232 u32 register_id)
233{
234 ACPI_FUNCTION_NAME ("hw_get_bit_register_info");
235
236
237 if (register_id > ACPI_BITREG_MAX) {
238 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid bit_register ID: %X\n", register_id));
239 return (NULL);
240 }
241
242 return (&acpi_gbl_bit_register_info[register_id]);
243}
244
245
246/*******************************************************************************
247 *
248 * FUNCTION: acpi_get_register
249 *
250 * PARAMETERS: register_id - ID of ACPI bit_register to access
251 * return_value - Value that was read from the register
252 * Flags - Lock the hardware or not
253 *
254 * RETURN: Status and the value read from specified Register. Value
255 * returned is normalized to bit0 (is shifted all the way right)
256 *
257 * DESCRIPTION: ACPI bit_register read function.
258 *
259 ******************************************************************************/
260
261acpi_status
262acpi_get_register (
263 u32 register_id,
264 u32 *return_value,
265 u32 flags)
266{
267 u32 register_value = 0;
268 struct acpi_bit_register_info *bit_reg_info;
269 acpi_status status;
270
271
272 ACPI_FUNCTION_TRACE ("acpi_get_register");
273
274
275 /* Get the info structure corresponding to the requested ACPI Register */
276
277 bit_reg_info = acpi_hw_get_bit_register_info (register_id);
278 if (!bit_reg_info) {
279 return_ACPI_STATUS (AE_BAD_PARAMETER);
280 }
281
282 if (flags & ACPI_MTX_LOCK) {
283 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
284 if (ACPI_FAILURE (status)) {
285 return_ACPI_STATUS (status);
286 }
287 }
288
289 /* Read from the register */
290
291 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
292 bit_reg_info->parent_register, &register_value);
293
294 if (flags & ACPI_MTX_LOCK) {
295 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
296 }
297
298 if (ACPI_SUCCESS (status)) {
299 /* Normalize the value that was read */
300
301 register_value = ((register_value & bit_reg_info->access_bit_mask)
302 >> bit_reg_info->bit_position);
303
304 *return_value = register_value;
305
306 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read value %8.8X register %X\n",
307 register_value, bit_reg_info->parent_register));
308 }
309
310 return_ACPI_STATUS (status);
311}
312EXPORT_SYMBOL(acpi_get_register);
313
314
315/*******************************************************************************
316 *
317 * FUNCTION: acpi_set_register
318 *
319 * PARAMETERS: register_id - ID of ACPI bit_register to access
320 * Value - (only used on write) value to write to the
321 * Register, NOT pre-normalized to the bit pos
322 * Flags - Lock the hardware or not
323 *
324 * RETURN: Status
325 *
326 * DESCRIPTION: ACPI Bit Register write function.
327 *
328 ******************************************************************************/
329
330acpi_status
331acpi_set_register (
332 u32 register_id,
333 u32 value,
334 u32 flags)
335{
336 u32 register_value = 0;
337 struct acpi_bit_register_info *bit_reg_info;
338 acpi_status status;
339
340
341 ACPI_FUNCTION_TRACE_U32 ("acpi_set_register", register_id);
342
343
344 /* Get the info structure corresponding to the requested ACPI Register */
345
346 bit_reg_info = acpi_hw_get_bit_register_info (register_id);
347 if (!bit_reg_info) {
348 ACPI_REPORT_ERROR (("Bad ACPI HW register_id: %X\n", register_id));
349 return_ACPI_STATUS (AE_BAD_PARAMETER);
350 }
351
352 if (flags & ACPI_MTX_LOCK) {
353 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
354 if (ACPI_FAILURE (status)) {
355 return_ACPI_STATUS (status);
356 }
357 }
358
359 /* Always do a register read first so we can insert the new bits */
360
361 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
362 bit_reg_info->parent_register, &register_value);
363 if (ACPI_FAILURE (status)) {
364 goto unlock_and_exit;
365 }
366
367 /*
368 * Decode the Register ID
369 * Register ID = [Register block ID] | [bit ID]
370 *
371 * Check bit ID to fine locate Register offset.
372 * Check Mask to determine Register offset, and then read-write.
373 */
374 switch (bit_reg_info->parent_register) {
375 case ACPI_REGISTER_PM1_STATUS:
376
377 /*
378 * Status Registers are different from the rest. Clear by
379 * writing 1, and writing 0 has no effect. So, the only relevant
380 * information is the single bit we're interested in, all others should
381 * be written as 0 so they will be left unchanged.
382 */
383 value = ACPI_REGISTER_PREPARE_BITS (value,
384 bit_reg_info->bit_position, bit_reg_info->access_bit_mask);
385 if (value) {
386 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
387 ACPI_REGISTER_PM1_STATUS, (u16) value);
388 register_value = 0;
389 }
390 break;
391
392
393 case ACPI_REGISTER_PM1_ENABLE:
394
395 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
396 bit_reg_info->access_bit_mask, value);
397
398 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
399 ACPI_REGISTER_PM1_ENABLE, (u16) register_value);
400 break;
401
402
403 case ACPI_REGISTER_PM1_CONTROL:
404
405 /*
406 * Write the PM1 Control register.
407 * Note that at this level, the fact that there are actually TWO
408 * registers (A and B - and B may not exist) is abstracted.
409 */
410 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM1 control: Read %X\n", register_value));
411
412 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
413 bit_reg_info->access_bit_mask, value);
414
415 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
416 ACPI_REGISTER_PM1_CONTROL, (u16) register_value);
417 break;
418
419
420 case ACPI_REGISTER_PM2_CONTROL:
421
422 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
423 ACPI_REGISTER_PM2_CONTROL, &register_value);
424 if (ACPI_FAILURE (status)) {
425 goto unlock_and_exit;
426 }
427
428 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
429 register_value,
430 ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address)));
431
432 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
433 bit_reg_info->access_bit_mask, value);
434
435 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
436 register_value,
437 ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address)));
438
439 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
440 ACPI_REGISTER_PM2_CONTROL, (u8) (register_value));
441 break;
442
443
444 default:
445 break;
446 }
447
448
449unlock_and_exit:
450
451 if (flags & ACPI_MTX_LOCK) {
452 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
453 }
454
455 /* Normalize the value that was read */
456
457 ACPI_DEBUG_EXEC (register_value = ((register_value & bit_reg_info->access_bit_mask) >> bit_reg_info->bit_position));
458
459 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n",
460 value, register_value, bit_reg_info->parent_register));
461 return_ACPI_STATUS (status);
462}
463EXPORT_SYMBOL(acpi_set_register);
464
465
466/******************************************************************************
467 *
468 * FUNCTION: acpi_hw_register_read
469 *
470 * PARAMETERS: use_lock - Mutex hw access
471 * register_id - register_iD + Offset
472 * return_value - Value that was read from the register
473 *
474 * RETURN: Status and the value read.
475 *
476 * DESCRIPTION: Acpi register read function. Registers are read at the
477 * given offset.
478 *
479 ******************************************************************************/
480
481acpi_status
482acpi_hw_register_read (
483 u8 use_lock,
484 u32 register_id,
485 u32 *return_value)
486{
487 u32 value1 = 0;
488 u32 value2 = 0;
489 acpi_status status;
490
491
492 ACPI_FUNCTION_TRACE ("hw_register_read");
493
494
495 if (ACPI_MTX_LOCK == use_lock) {
496 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
497 if (ACPI_FAILURE (status)) {
498 return_ACPI_STATUS (status);
499 }
500 }
501
502 switch (register_id) {
503 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
504
505 status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_evt_blk);
506 if (ACPI_FAILURE (status)) {
507 goto unlock_and_exit;
508 }
509
510 /* PM1B is optional */
511
512 status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_evt_blk);
513 value1 |= value2;
514 break;
515
516
517 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
518
519 status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_xpm1a_enable);
520 if (ACPI_FAILURE (status)) {
521 goto unlock_and_exit;
522 }
523
524 /* PM1B is optional */
525
526 status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_xpm1b_enable);
527 value1 |= value2;
528 break;
529
530
531 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
532
533 status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_cnt_blk);
534 if (ACPI_FAILURE (status)) {
535 goto unlock_and_exit;
536 }
537
538 status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_cnt_blk);
539 value1 |= value2;
540 break;
541
542
543 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
544
545 status = acpi_hw_low_level_read (8, &value1, &acpi_gbl_FADT->xpm2_cnt_blk);
546 break;
547
548
549 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
550
551 status = acpi_hw_low_level_read (32, &value1, &acpi_gbl_FADT->xpm_tmr_blk);
552 break;
553
554 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
555
556 status = acpi_os_read_port (acpi_gbl_FADT->smi_cmd, &value1, 8);
557 break;
558
559 default:
560 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n", register_id));
561 status = AE_BAD_PARAMETER;
562 break;
563 }
564
565unlock_and_exit:
566 if (ACPI_MTX_LOCK == use_lock) {
567 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
568 }
569
570 if (ACPI_SUCCESS (status)) {
571 *return_value = value1;
572 }
573
574 return_ACPI_STATUS (status);
575}
576
577
578/******************************************************************************
579 *
580 * FUNCTION: acpi_hw_register_write
581 *
582 * PARAMETERS: use_lock - Mutex hw access
583 * register_id - register_iD + Offset
584 * Value - The value to write
585 *
586 * RETURN: Status
587 *
588 * DESCRIPTION: Acpi register Write function. Registers are written at the
589 * given offset.
590 *
591 ******************************************************************************/
592
593acpi_status
594acpi_hw_register_write (
595 u8 use_lock,
596 u32 register_id,
597 u32 value)
598{
599 acpi_status status;
600
601
602 ACPI_FUNCTION_TRACE ("hw_register_write");
603
604
605 if (ACPI_MTX_LOCK == use_lock) {
606 status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
607 if (ACPI_FAILURE (status)) {
608 return_ACPI_STATUS (status);
609 }
610 }
611
612 switch (register_id) {
613 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
614
615 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_evt_blk);
616 if (ACPI_FAILURE (status)) {
617 goto unlock_and_exit;
618 }
619
620 /* PM1B is optional */
621
622 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_evt_blk);
623 break;
624
625
626 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access*/
627
628 status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1a_enable);
629 if (ACPI_FAILURE (status)) {
630 goto unlock_and_exit;
631 }
632
633 /* PM1B is optional */
634
635 status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1b_enable);
636 break;
637
638
639 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
640
641 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
642 if (ACPI_FAILURE (status)) {
643 goto unlock_and_exit;
644 }
645
646 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
647 break;
648
649
650 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
651
652 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
653 break;
654
655
656 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
657
658 status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
659 break;
660
661
662 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
663
664 status = acpi_hw_low_level_write (8, value, &acpi_gbl_FADT->xpm2_cnt_blk);
665 break;
666
667
668 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
669
670 status = acpi_hw_low_level_write (32, value, &acpi_gbl_FADT->xpm_tmr_blk);
671 break;
672
673
674 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
675
676 /* SMI_CMD is currently always in IO space */
677
678 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, value, 8);
679 break;
680
681
682 default:
683 status = AE_BAD_PARAMETER;
684 break;
685 }
686
687unlock_and_exit:
688 if (ACPI_MTX_LOCK == use_lock) {
689 (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
690 }
691
692 return_ACPI_STATUS (status);
693}
694
695
696/******************************************************************************
697 *
698 * FUNCTION: acpi_hw_low_level_read
699 *
700 * PARAMETERS: Width - 8, 16, or 32
701 * Value - Where the value is returned
702 * Reg - GAS register structure
703 *
704 * RETURN: Status
705 *
706 * DESCRIPTION: Read from either memory or IO space.
707 *
708 ******************************************************************************/
709
710acpi_status
711acpi_hw_low_level_read (
712 u32 width,
713 u32 *value,
714 struct acpi_generic_address *reg)
715{
716 u64 address;
717 acpi_status status;
718
719
720 ACPI_FUNCTION_NAME ("hw_low_level_read");
721
722
723 /*
724 * Must have a valid pointer to a GAS structure, and
725 * a non-zero address within. However, don't return an error
726 * because the PM1A/B code must not fail if B isn't present.
727 */
728 if (!reg) {
729 return (AE_OK);
730 }
731
732 /* Get a local copy of the address. Handles possible alignment issues */
733
734 ACPI_MOVE_64_TO_64 (&address, &reg->address);
735 if (!address) {
736 return (AE_OK);
737 }
738 *value = 0;
739
740 /*
741 * Two address spaces supported: Memory or IO.
742 * PCI_Config is not supported here because the GAS struct is insufficient
743 */
744 switch (reg->address_space_id) {
745 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
746
747 status = acpi_os_read_memory (
748 (acpi_physical_address) address,
749 value, width);
750 break;
751
752
753 case ACPI_ADR_SPACE_SYSTEM_IO:
754
755 status = acpi_os_read_port ((acpi_io_address) address,
756 value, width);
757 break;
758
759
760 default:
761 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
762 "Unsupported address space: %X\n", reg->address_space_id));
763 return (AE_BAD_PARAMETER);
764 }
765
766 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
767 *value, width,
768 ACPI_FORMAT_UINT64 (address),
769 acpi_ut_get_region_name (reg->address_space_id)));
770
771 return (status);
772}
773
774
775/******************************************************************************
776 *
777 * FUNCTION: acpi_hw_low_level_write
778 *
779 * PARAMETERS: Width - 8, 16, or 32
780 * Value - To be written
781 * Reg - GAS register structure
782 *
783 * RETURN: Status
784 *
785 * DESCRIPTION: Write to either memory or IO space.
786 *
787 ******************************************************************************/
788
789acpi_status
790acpi_hw_low_level_write (
791 u32 width,
792 u32 value,
793 struct acpi_generic_address *reg)
794{
795 u64 address;
796 acpi_status status;
797
798
799 ACPI_FUNCTION_NAME ("hw_low_level_write");
800
801
802 /*
803 * Must have a valid pointer to a GAS structure, and
804 * a non-zero address within. However, don't return an error
805 * because the PM1A/B code must not fail if B isn't present.
806 */
807 if (!reg) {
808 return (AE_OK);
809 }
810
811 /* Get a local copy of the address. Handles possible alignment issues */
812
813 ACPI_MOVE_64_TO_64 (&address, &reg->address);
814 if (!address) {
815 return (AE_OK);
816 }
817
818 /*
819 * Two address spaces supported: Memory or IO.
820 * PCI_Config is not supported here because the GAS struct is insufficient
821 */
822 switch (reg->address_space_id) {
823 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
824
825 status = acpi_os_write_memory (
826 (acpi_physical_address) address,
827 value, width);
828 break;
829
830
831 case ACPI_ADR_SPACE_SYSTEM_IO:
832
833 status = acpi_os_write_port ((acpi_io_address) address,
834 value, width);
835 break;
836
837
838 default:
839 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
840 "Unsupported address space: %X\n", reg->address_space_id));
841 return (AE_BAD_PARAMETER);
842 }
843
844 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
845 value, width,
846 ACPI_FORMAT_UINT64 (address),
847 acpi_ut_get_region_name (reg->address_space_id)));
848
849 return (status);
850}
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
new file mode 100644
index 000000000000..77b3e9a8550b
--- /dev/null
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -0,0 +1,582 @@
1
2/******************************************************************************
3 *
4 * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2005, 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 <linux/module.h>
46
47#include <acpi/acpi.h>
48
49#define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwsleep")
51
52
53#define METHOD_NAME__BFS "\\_BFS"
54#define METHOD_NAME__GTS "\\_GTS"
55#define METHOD_NAME__PTS "\\_PTS"
56#define METHOD_NAME__SST "\\_SI._SST"
57#define METHOD_NAME__WAK "\\_WAK"
58
59#define ACPI_SST_INDICATOR_OFF 0
60#define ACPI_SST_WORKING 1
61#define ACPI_SST_WAKING 2
62#define ACPI_SST_SLEEPING 3
63#define ACPI_SST_SLEEP_CONTEXT 4
64
65
66/******************************************************************************
67 *
68 * FUNCTION: acpi_set_firmware_waking_vector
69 *
70 * PARAMETERS: physical_address - Physical address of ACPI real mode
71 * entry point.
72 *
73 * RETURN: Status
74 *
75 * DESCRIPTION: access function for d_firmware_waking_vector field in FACS
76 *
77 ******************************************************************************/
78
79acpi_status
80acpi_set_firmware_waking_vector (
81 acpi_physical_address physical_address)
82{
83
84 ACPI_FUNCTION_TRACE ("acpi_set_firmware_waking_vector");
85
86
87 /* Set the vector */
88
89 if (acpi_gbl_common_fACS.vector_width == 32) {
90 *(ACPI_CAST_PTR (u32, acpi_gbl_common_fACS.firmware_waking_vector))
91 = (u32) physical_address;
92 }
93 else {
94 *acpi_gbl_common_fACS.firmware_waking_vector
95 = physical_address;
96 }
97
98 return_ACPI_STATUS (AE_OK);
99}
100
101
102/******************************************************************************
103 *
104 * FUNCTION: acpi_get_firmware_waking_vector
105 *
106 * PARAMETERS: *physical_address - Output buffer where contents of
107 * the firmware_waking_vector field of
108 * the FACS will be stored.
109 *
110 * RETURN: Status
111 *
112 * DESCRIPTION: Access function for firmware_waking_vector field in FACS
113 *
114 ******************************************************************************/
115#ifdef ACPI_FUTURE_USAGE
116acpi_status
117acpi_get_firmware_waking_vector (
118 acpi_physical_address *physical_address)
119{
120
121 ACPI_FUNCTION_TRACE ("acpi_get_firmware_waking_vector");
122
123
124 if (!physical_address) {
125 return_ACPI_STATUS (AE_BAD_PARAMETER);
126 }
127
128 /* Get the vector */
129
130 if (acpi_gbl_common_fACS.vector_width == 32) {
131 *physical_address = (acpi_physical_address)
132 *(ACPI_CAST_PTR (u32, acpi_gbl_common_fACS.firmware_waking_vector));
133 }
134 else {
135 *physical_address =
136 *acpi_gbl_common_fACS.firmware_waking_vector;
137 }
138
139 return_ACPI_STATUS (AE_OK);
140}
141#endif
142
143
144/******************************************************************************
145 *
146 * FUNCTION: acpi_enter_sleep_state_prep
147 *
148 * PARAMETERS: sleep_state - Which sleep state to enter
149 *
150 * RETURN: Status
151 *
152 * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231)
153 * This function must execute with interrupts enabled.
154 * We break sleeping into 2 stages so that OSPM can handle
155 * various OS-specific tasks between the two steps.
156 *
157 ******************************************************************************/
158
159acpi_status
160acpi_enter_sleep_state_prep (
161 u8 sleep_state)
162{
163 acpi_status status;
164 struct acpi_object_list arg_list;
165 union acpi_object arg;
166
167
168 ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state_prep");
169
170
171 /*
172 * _PSW methods could be run here to enable wake-on keyboard, LAN, etc.
173 */
174 status = acpi_get_sleep_type_data (sleep_state,
175 &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b);
176 if (ACPI_FAILURE (status)) {
177 return_ACPI_STATUS (status);
178 }
179
180 /* Setup parameter object */
181
182 arg_list.count = 1;
183 arg_list.pointer = &arg;
184
185 arg.type = ACPI_TYPE_INTEGER;
186 arg.integer.value = sleep_state;
187
188 /* Run the _PTS and _GTS methods */
189
190 status = acpi_evaluate_object (NULL, METHOD_NAME__PTS, &arg_list, NULL);
191 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
192 return_ACPI_STATUS (status);
193 }
194
195 status = acpi_evaluate_object (NULL, METHOD_NAME__GTS, &arg_list, NULL);
196 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
197 return_ACPI_STATUS (status);
198 }
199
200 /* Setup the argument to _SST */
201
202 switch (sleep_state) {
203 case ACPI_STATE_S0:
204 arg.integer.value = ACPI_SST_WORKING;
205 break;
206
207 case ACPI_STATE_S1:
208 case ACPI_STATE_S2:
209 case ACPI_STATE_S3:
210 arg.integer.value = ACPI_SST_SLEEPING;
211 break;
212
213 case ACPI_STATE_S4:
214 arg.integer.value = ACPI_SST_SLEEP_CONTEXT;
215 break;
216
217 default:
218 arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is indicator off */
219 break;
220 }
221
222 /* Set the system indicators to show the desired sleep state. */
223
224 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
225 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
226 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status)));
227 }
228
229 return_ACPI_STATUS (AE_OK);
230}
231
232
233/******************************************************************************
234 *
235 * FUNCTION: acpi_enter_sleep_state
236 *
237 * PARAMETERS: sleep_state - Which sleep state to enter
238 *
239 * RETURN: Status
240 *
241 * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
242 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
243 *
244 ******************************************************************************/
245
246acpi_status asmlinkage
247acpi_enter_sleep_state (
248 u8 sleep_state)
249{
250 u32 PM1Acontrol;
251 u32 PM1Bcontrol;
252 struct acpi_bit_register_info *sleep_type_reg_info;
253 struct acpi_bit_register_info *sleep_enable_reg_info;
254 u32 in_value;
255 acpi_status status;
256
257
258 ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state");
259
260
261 if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
262 (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) {
263 ACPI_REPORT_ERROR (("Sleep values out of range: A=%X B=%X\n",
264 acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
265 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
266 }
267
268 sleep_type_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_TYPE_A);
269 sleep_enable_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_ENABLE);
270
271 /* Clear wake status */
272
273 status = acpi_set_register (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
274 if (ACPI_FAILURE (status)) {
275 return_ACPI_STATUS (status);
276 }
277
278 /* Clear all fixed and general purpose status bits */
279
280 status = acpi_hw_clear_acpi_status (ACPI_MTX_DO_NOT_LOCK);
281 if (ACPI_FAILURE (status)) {
282 return_ACPI_STATUS (status);
283 }
284
285 /*
286 * 1) Disable/Clear all GPEs
287 * 2) Enable all wakeup GPEs
288 */
289 status = acpi_hw_disable_all_gpes (ACPI_ISR);
290 if (ACPI_FAILURE (status)) {
291 return_ACPI_STATUS (status);
292 }
293 acpi_gbl_system_awake_and_running = FALSE;
294
295 status = acpi_hw_enable_all_wakeup_gpes (ACPI_ISR);
296 if (ACPI_FAILURE (status)) {
297 return_ACPI_STATUS (status);
298 }
299
300 /* Get current value of PM1A control */
301
302 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
303 if (ACPI_FAILURE (status)) {
304 return_ACPI_STATUS (status);
305 }
306 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Entering sleep state [S%d]\n", sleep_state));
307
308 /* Clear SLP_EN and SLP_TYP fields */
309
310 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info->access_bit_mask);
311 PM1Bcontrol = PM1Acontrol;
312
313 /* Insert SLP_TYP bits */
314
315 PM1Acontrol |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position);
316 PM1Bcontrol |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position);
317
318 /*
319 * We split the writes of SLP_TYP and SLP_EN to workaround
320 * poorly implemented hardware.
321 */
322
323 /* Write #1: fill in SLP_TYP data */
324
325 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
326 if (ACPI_FAILURE (status)) {
327 return_ACPI_STATUS (status);
328 }
329
330 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
331 if (ACPI_FAILURE (status)) {
332 return_ACPI_STATUS (status);
333 }
334
335 /* Insert SLP_ENABLE bit */
336
337 PM1Acontrol |= sleep_enable_reg_info->access_bit_mask;
338 PM1Bcontrol |= sleep_enable_reg_info->access_bit_mask;
339
340 /* Write #2: SLP_TYP + SLP_EN */
341
342 ACPI_FLUSH_CPU_CACHE ();
343
344 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
345 if (ACPI_FAILURE (status)) {
346 return_ACPI_STATUS (status);
347 }
348
349 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
350 if (ACPI_FAILURE (status)) {
351 return_ACPI_STATUS (status);
352 }
353
354 if (sleep_state > ACPI_STATE_S3) {
355 /*
356 * We wanted to sleep > S3, but it didn't happen (by virtue of the fact that
357 * we are still executing!)
358 *
359 * Wait ten seconds, then try again. This is to get S4/S5 to work on all machines.
360 *
361 * We wait so long to allow chipsets that poll this reg very slowly to
362 * still read the right value. Ideally, this block would go
363 * away entirely.
364 */
365 acpi_os_stall (10000000);
366
367 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL,
368 sleep_enable_reg_info->access_bit_mask);
369 if (ACPI_FAILURE (status)) {
370 return_ACPI_STATUS (status);
371 }
372 }
373
374 /* Wait until we enter sleep state */
375
376 do {
377 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK);
378 if (ACPI_FAILURE (status)) {
379 return_ACPI_STATUS (status);
380 }
381
382 /* Spin until we wake */
383
384 } while (!in_value);
385
386 return_ACPI_STATUS (AE_OK);
387}
388EXPORT_SYMBOL(acpi_enter_sleep_state);
389
390
391/******************************************************************************
392 *
393 * FUNCTION: acpi_enter_sleep_state_s4bios
394 *
395 * PARAMETERS: None
396 *
397 * RETURN: Status
398 *
399 * DESCRIPTION: Perform a S4 bios request.
400 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
401 *
402 ******************************************************************************/
403
404acpi_status asmlinkage
405acpi_enter_sleep_state_s4bios (
406 void)
407{
408 u32 in_value;
409 acpi_status status;
410
411
412 ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state_s4bios");
413
414
415 status = acpi_set_register (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
416 if (ACPI_FAILURE (status)) {
417 return_ACPI_STATUS (status);
418 }
419
420 status = acpi_hw_clear_acpi_status (ACPI_MTX_DO_NOT_LOCK);
421 if (ACPI_FAILURE (status)) {
422 return_ACPI_STATUS (status);
423 }
424
425 /*
426 * 1) Disable/Clear all GPEs
427 * 2) Enable all wakeup GPEs
428 */
429 status = acpi_hw_disable_all_gpes (ACPI_ISR);
430 if (ACPI_FAILURE (status)) {
431 return_ACPI_STATUS (status);
432 }
433 acpi_gbl_system_awake_and_running = FALSE;
434
435 status = acpi_hw_enable_all_wakeup_gpes (ACPI_ISR);
436 if (ACPI_FAILURE (status)) {
437 return_ACPI_STATUS (status);
438 }
439
440 ACPI_FLUSH_CPU_CACHE ();
441
442 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, (u32) acpi_gbl_FADT->S4bios_req, 8);
443
444 do {
445 acpi_os_stall(1000);
446 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK);
447 if (ACPI_FAILURE (status)) {
448 return_ACPI_STATUS (status);
449 }
450 } while (!in_value);
451
452 return_ACPI_STATUS (AE_OK);
453}
454EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios);
455
456
457/******************************************************************************
458 *
459 * FUNCTION: acpi_leave_sleep_state
460 *
461 * PARAMETERS: sleep_state - Which sleep state we just exited
462 *
463 * RETURN: Status
464 *
465 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
466 * Called with interrupts ENABLED.
467 *
468 ******************************************************************************/
469
470acpi_status
471acpi_leave_sleep_state (
472 u8 sleep_state)
473{
474 struct acpi_object_list arg_list;
475 union acpi_object arg;
476 acpi_status status;
477 struct acpi_bit_register_info *sleep_type_reg_info;
478 struct acpi_bit_register_info *sleep_enable_reg_info;
479 u32 PM1Acontrol;
480 u32 PM1Bcontrol;
481
482
483 ACPI_FUNCTION_TRACE ("acpi_leave_sleep_state");
484
485
486 /*
487 * Set SLP_TYPE and SLP_EN to state S0.
488 * This is unclear from the ACPI Spec, but it is required
489 * by some machines.
490 */
491 status = acpi_get_sleep_type_data (ACPI_STATE_S0,
492 &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b);
493 if (ACPI_SUCCESS (status)) {
494 sleep_type_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_TYPE_A);
495 sleep_enable_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_ENABLE);
496
497 /* Get current value of PM1A control */
498
499 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
500 ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
501 if (ACPI_SUCCESS (status)) {
502 /* Clear SLP_EN and SLP_TYP fields */
503
504 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask |
505 sleep_enable_reg_info->access_bit_mask);
506 PM1Bcontrol = PM1Acontrol;
507
508 /* Insert SLP_TYP bits */
509
510 PM1Acontrol |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position);
511 PM1Bcontrol |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position);
512
513 /* Just ignore any errors */
514
515 (void) acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
516 ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
517 (void) acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
518 ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
519 }
520 }
521
522 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
523
524 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
525
526 /* Setup parameter object */
527
528 arg_list.count = 1;
529 arg_list.pointer = &arg;
530 arg.type = ACPI_TYPE_INTEGER;
531
532 /* Ignore any errors from these methods */
533
534 arg.integer.value = ACPI_SST_WAKING;
535 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
536 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
537 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status)));
538 }
539
540 arg.integer.value = sleep_state;
541 status = acpi_evaluate_object (NULL, METHOD_NAME__BFS, &arg_list, NULL);
542 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
543 ACPI_REPORT_ERROR (("Method _BFS failed, %s\n", acpi_format_exception (status)));
544 }
545
546 status = acpi_evaluate_object (NULL, METHOD_NAME__WAK, &arg_list, NULL);
547 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
548 ACPI_REPORT_ERROR (("Method _WAK failed, %s\n", acpi_format_exception (status)));
549 }
550 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */
551
552 /*
553 * Restore the GPEs:
554 * 1) Disable/Clear all GPEs
555 * 2) Enable all runtime GPEs
556 */
557 status = acpi_hw_disable_all_gpes (ACPI_NOT_ISR);
558 if (ACPI_FAILURE (status)) {
559 return_ACPI_STATUS (status);
560 }
561 acpi_gbl_system_awake_and_running = TRUE;
562
563 status = acpi_hw_enable_all_runtime_gpes (ACPI_NOT_ISR);
564 if (ACPI_FAILURE (status)) {
565 return_ACPI_STATUS (status);
566 }
567
568 /* Enable power button */
569
570 (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].enable_register_id,
571 1, ACPI_MTX_DO_NOT_LOCK);
572 (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].status_register_id,
573 1, ACPI_MTX_DO_NOT_LOCK);
574
575 arg.integer.value = ACPI_SST_WORKING;
576 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
577 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
578 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status)));
579 }
580
581 return_ACPI_STATUS (status);
582}
diff --git a/drivers/acpi/hardware/hwtimer.c b/drivers/acpi/hardware/hwtimer.c
new file mode 100644
index 000000000000..1906167d7294
--- /dev/null
+++ b/drivers/acpi/hardware/hwtimer.c
@@ -0,0 +1,203 @@
1
2/******************************************************************************
3 *
4 * Name: hwtimer.c - ACPI Power Management Timer Interface
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2005, 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 <linux/module.h>
46
47#include <acpi/acpi.h>
48
49#define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwtimer")
51
52
53/******************************************************************************
54 *
55 * FUNCTION: acpi_get_timer_resolution
56 *
57 * PARAMETERS: Resolution - Where the resolution is returned
58 *
59 * RETURN: Status and timer resolution
60 *
61 * DESCRIPTION: Obtains resolution of the ACPI PM Timer (24 or 32 bits).
62 *
63 ******************************************************************************/
64
65acpi_status
66acpi_get_timer_resolution (
67 u32 *resolution)
68{
69 ACPI_FUNCTION_TRACE ("acpi_get_timer_resolution");
70
71
72 if (!resolution) {
73 return_ACPI_STATUS (AE_BAD_PARAMETER);
74 }
75
76 if (0 == acpi_gbl_FADT->tmr_val_ext) {
77 *resolution = 24;
78 }
79 else {
80 *resolution = 32;
81 }
82
83 return_ACPI_STATUS (AE_OK);
84}
85
86
87/******************************************************************************
88 *
89 * FUNCTION: acpi_get_timer
90 *
91 * PARAMETERS: Ticks - Where the timer value is returned
92 *
93 * RETURN: Status and current ticks
94 *
95 * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks).
96 *
97 ******************************************************************************/
98
99acpi_status
100acpi_get_timer (
101 u32 *ticks)
102{
103 acpi_status status;
104
105
106 ACPI_FUNCTION_TRACE ("acpi_get_timer");
107
108
109 if (!ticks) {
110 return_ACPI_STATUS (AE_BAD_PARAMETER);
111 }
112
113 status = acpi_hw_low_level_read (32, ticks, &acpi_gbl_FADT->xpm_tmr_blk);
114
115 return_ACPI_STATUS (status);
116}
117EXPORT_SYMBOL(acpi_get_timer);
118
119
120/******************************************************************************
121 *
122 * FUNCTION: acpi_get_timer_duration
123 *
124 * PARAMETERS: start_ticks - Starting timestamp
125 * end_ticks - End timestamp
126 * time_elapsed - Where the elapsed time is returned
127 *
128 * RETURN: Status and time_elapsed
129 *
130 * DESCRIPTION: Computes the time elapsed (in microseconds) between two
131 * PM Timer time stamps, taking into account the possibility of
132 * rollovers, the timer resolution, and timer frequency.
133 *
134 * The PM Timer's clock ticks at roughly 3.6 times per
135 * _microsecond_, and its clock continues through Cx state
136 * transitions (unlike many CPU timestamp counters) -- making it
137 * a versatile and accurate timer.
138 *
139 * Note that this function accommodates only a single timer
140 * rollover. Thus for 24-bit timers, this function should only
141 * be used for calculating durations less than ~4.6 seconds
142 * (~20 minutes for 32-bit timers) -- calculations below:
143 *
144 * 2**24 Ticks / 3,600,000 Ticks/Sec = 4.66 sec
145 * 2**32 Ticks / 3,600,000 Ticks/Sec = 1193 sec or 19.88 minutes
146 *
147 ******************************************************************************/
148
149acpi_status
150acpi_get_timer_duration (
151 u32 start_ticks,
152 u32 end_ticks,
153 u32 *time_elapsed)
154{
155 acpi_status status;
156 u32 delta_ticks;
157 acpi_integer quotient;
158
159
160 ACPI_FUNCTION_TRACE ("acpi_get_timer_duration");
161
162
163 if (!time_elapsed) {
164 return_ACPI_STATUS (AE_BAD_PARAMETER);
165 }
166
167 /*
168 * Compute Tick Delta:
169 * Handle (max one) timer rollovers on 24-bit versus 32-bit timers.
170 */
171 if (start_ticks < end_ticks) {
172 delta_ticks = end_ticks - start_ticks;
173 }
174 else if (start_ticks > end_ticks) {
175 if (0 == acpi_gbl_FADT->tmr_val_ext) {
176 /* 24-bit Timer */
177
178 delta_ticks = (((0x00FFFFFF - start_ticks) + end_ticks) & 0x00FFFFFF);
179 }
180 else {
181 /* 32-bit Timer */
182
183 delta_ticks = (0xFFFFFFFF - start_ticks) + end_ticks;
184 }
185 }
186 else /* start_ticks == end_ticks */ {
187 *time_elapsed = 0;
188 return_ACPI_STATUS (AE_OK);
189 }
190
191 /*
192 * Compute Duration (Requires a 64-bit multiply and divide):
193 *
194 * time_elapsed = (delta_ticks * 1000000) / PM_TIMER_FREQUENCY;
195 */
196 status = acpi_ut_short_divide (((u64) delta_ticks) * 1000000,
197 PM_TIMER_FREQUENCY, &quotient, NULL);
198
199 *time_elapsed = (u32) quotient;
200 return_ACPI_STATUS (status);
201}
202EXPORT_SYMBOL(acpi_get_timer_duration);
203