blob: b4b50a3d17051ed64426eb26ae093eea4bbc2bce [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*******************************************************************************
3 *
4 * Module Name: hwregs - Read/write access functions for the various ACPI
5 * control and status registers.
6 *
7 ******************************************************************************/
8
9/*
Bob Moore4a90c7e2006-01-13 16:22:00 -050010 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * 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
Len Brown4be44fc2005-08-05 00:44:28 -040053ACPI_MODULE_NAME("hwregs")
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*******************************************************************************
56 *
57 * FUNCTION: acpi_hw_clear_acpi_status
58 *
59 * PARAMETERS: Flags - Lock the hardware or not
60 *
61 * RETURN: none
62 *
63 * DESCRIPTION: Clears all fixed and general purpose status bits
64 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
65 *
66 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040067acpi_status acpi_hw_clear_acpi_status(u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Len Brown4be44fc2005-08-05 00:44:28 -040069 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Len Brown4be44fc2005-08-05 00:44:28 -040071 ACPI_FUNCTION_TRACE("hw_clear_acpi_status");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Len Brown4be44fc2005-08-05 00:44:28 -040073 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
74 ACPI_BITMASK_ALL_FIXED_STATUS,
75 (u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -040078 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
79 if (ACPI_FAILURE(status)) {
80 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82 }
83
Len Brown4be44fc2005-08-05 00:44:28 -040084 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
85 ACPI_REGISTER_PM1_STATUS,
86 ACPI_BITMASK_ALL_FIXED_STATUS);
87 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 goto unlock_and_exit;
89 }
90
91 /* Clear the fixed events */
92
93 if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
Len Brown4be44fc2005-08-05 00:44:28 -040094 status =
95 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
96 &acpi_gbl_FADT->xpm1b_evt_blk);
97 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 goto unlock_and_exit;
99 }
100 }
101
102 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
103
Len Brown4be44fc2005-08-05 00:44:28 -0400104 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Len Brown4be44fc2005-08-05 00:44:28 -0400106 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400108 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
Len Brown4be44fc2005-08-05 00:44:28 -0400110 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*******************************************************************************
114 *
115 * FUNCTION: acpi_get_sleep_type_data
116 *
117 * PARAMETERS: sleep_state - Numeric sleep state
118 * *sleep_type_a - Where SLP_TYPa is returned
119 * *sleep_type_b - Where SLP_TYPb is returned
120 *
121 * RETURN: Status - ACPI status
122 *
123 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
124 * state.
125 *
126 ******************************************************************************/
127
128acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400129acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Len Brown4be44fc2005-08-05 00:44:28 -0400131 acpi_status status = AE_OK;
132 struct acpi_parameter_info info;
133 char *sleep_state_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Len Brown4be44fc2005-08-05 00:44:28 -0400135 ACPI_FUNCTION_TRACE("acpi_get_sleep_type_data");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Robert Moore44f6c012005-04-18 22:49:35 -0400137 /* Validate parameters */
138
Len Brown4be44fc2005-08-05 00:44:28 -0400139 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
140 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142
Robert Moore44f6c012005-04-18 22:49:35 -0400143 /* Evaluate the namespace object containing the values for this state */
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 info.parameters = NULL;
Robert Moore44f6c012005-04-18 22:49:35 -0400146 info.return_object = NULL;
Bob Mooredefba1d2005-12-16 17:05:00 -0500147 sleep_state_name =
148 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
Robert Moore44f6c012005-04-18 22:49:35 -0400149
Len Brown4be44fc2005-08-05 00:44:28 -0400150 status = acpi_ns_evaluate_by_name(sleep_state_name, &info);
151 if (ACPI_FAILURE(status)) {
152 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
153 "%s while evaluating sleep_state [%s]\n",
154 acpi_format_exception(status),
155 sleep_state_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Len Brown4be44fc2005-08-05 00:44:28 -0400157 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
160 /* Must have a return object */
161
162 if (!info.return_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400163 ACPI_REPORT_ERROR(("No Sleep State object returned from [%s]\n",
164 sleep_state_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 status = AE_NOT_EXIST;
166 }
167
168 /* It must be of type Package */
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170 else if (ACPI_GET_OBJECT_TYPE(info.return_object) != ACPI_TYPE_PACKAGE) {
171 ACPI_REPORT_ERROR(("Sleep State return object is not a Package\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 status = AE_AML_OPERAND_TYPE;
173 }
174
Robert Moore44f6c012005-04-18 22:49:35 -0400175 /*
176 * The package must have at least two elements. NOTE (March 2005): This
177 * goes against the current ACPI spec which defines this object as a
178 * package with one encoded DWORD element. However, existing practice
179 * by BIOS vendors seems to be to have 2 or more elements, at least
180 * one per sleep type (A/B).
181 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 else if (info.return_object->package.count < 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400183 ACPI_REPORT_ERROR(("Sleep State return package does not have at least two elements\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 status = AE_AML_NO_OPERAND;
185 }
186
187 /* The first two elements must both be of type Integer */
188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 else if ((ACPI_GET_OBJECT_TYPE(info.return_object->package.elements[0])
190 != ACPI_TYPE_INTEGER) ||
191 (ACPI_GET_OBJECT_TYPE(info.return_object->package.elements[1])
192 != ACPI_TYPE_INTEGER)) {
193 ACPI_REPORT_ERROR(("Sleep State return package elements are not both Integers (%s, %s)\n", acpi_ut_get_object_type_name(info.return_object->package.elements[0]), acpi_ut_get_object_type_name(info.return_object->package.elements[1])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 status = AE_AML_OPERAND_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400195 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400196 /* Valid _Sx_ package size, type, and value */
197
198 *sleep_type_a = (u8)
Len Brown4be44fc2005-08-05 00:44:28 -0400199 (info.return_object->package.elements[0])->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400200 *sleep_type_b = (u8)
Len Brown4be44fc2005-08-05 00:44:28 -0400201 (info.return_object->package.elements[1])->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204 if (ACPI_FAILURE(status)) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500205 ACPI_REPORT_ERROR(("%s While evaluating sleep_state [%s], bad Sleep object %p type %s\n", acpi_format_exception(status), sleep_state_name, info.return_object, acpi_ut_get_object_type_name(info.return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207
Len Brown4be44fc2005-08-05 00:44:28 -0400208 acpi_ut_remove_reference(info.return_object);
209 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Len Brown4be44fc2005-08-05 00:44:28 -0400212EXPORT_SYMBOL(acpi_get_sleep_type_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214/*******************************************************************************
215 *
216 * FUNCTION: acpi_hw_get_register_bit_mask
217 *
218 * PARAMETERS: register_id - Index of ACPI Register to access
219 *
Robert Moore44f6c012005-04-18 22:49:35 -0400220 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 *
Robert Moore44f6c012005-04-18 22:49:35 -0400222 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 *
224 ******************************************************************************/
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500228 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 if (register_id > ACPI_BITREG_MAX) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500231 ACPI_REPORT_ERROR(("Invalid bit_register ID: %X\n",
232 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return (NULL);
234 }
235
236 return (&acpi_gbl_bit_register_info[register_id]);
237}
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*******************************************************************************
240 *
241 * FUNCTION: acpi_get_register
242 *
243 * PARAMETERS: register_id - ID of ACPI bit_register to access
244 * return_value - Value that was read from the register
245 * Flags - Lock the hardware or not
246 *
247 * RETURN: Status and the value read from specified Register. Value
248 * returned is normalized to bit0 (is shifted all the way right)
249 *
250 * DESCRIPTION: ACPI bit_register read function.
251 *
252 ******************************************************************************/
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Len Brown4be44fc2005-08-05 00:44:28 -0400256 u32 register_value = 0;
257 struct acpi_bit_register_info *bit_reg_info;
258 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Len Brown4be44fc2005-08-05 00:44:28 -0400260 ACPI_FUNCTION_TRACE("acpi_get_register");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 /* Get the info structure corresponding to the requested ACPI Register */
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400266 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268
269 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400270 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
271 if (ACPI_FAILURE(status)) {
272 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274 }
275
276 /* Read from the register */
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
279 bit_reg_info->parent_register,
280 &register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400283 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 /* Normalize the value that was read */
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 register_value =
290 ((register_value & bit_reg_info->access_bit_mask)
291 >> bit_reg_info->bit_position);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 *return_value = register_value;
294
Len Brown4be44fc2005-08-05 00:44:28 -0400295 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
296 register_value,
297 bit_reg_info->parent_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Len Brown4be44fc2005-08-05 00:44:28 -0400303EXPORT_SYMBOL(acpi_get_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305/*******************************************************************************
306 *
307 * FUNCTION: acpi_set_register
308 *
309 * PARAMETERS: register_id - ID of ACPI bit_register to access
310 * Value - (only used on write) value to write to the
311 * Register, NOT pre-normalized to the bit pos
312 * Flags - Lock the hardware or not
313 *
314 * RETURN: Status
315 *
316 * DESCRIPTION: ACPI Bit Register write function.
317 *
318 ******************************************************************************/
319
Len Brown4be44fc2005-08-05 00:44:28 -0400320acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Len Brown4be44fc2005-08-05 00:44:28 -0400322 u32 register_value = 0;
323 struct acpi_bit_register_info *bit_reg_info;
324 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Len Brown4be44fc2005-08-05 00:44:28 -0400326 ACPI_FUNCTION_TRACE_U32("acpi_set_register", register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Get the info structure corresponding to the requested ACPI Register */
329
Len Brown4be44fc2005-08-05 00:44:28 -0400330 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400332 ACPI_REPORT_ERROR(("Bad ACPI HW register_id: %X\n",
333 register_id));
334 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
336
337 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400338 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
339 if (ACPI_FAILURE(status)) {
340 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342 }
343
344 /* Always do a register read first so we can insert the new bits */
345
Len Brown4be44fc2005-08-05 00:44:28 -0400346 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
347 bit_reg_info->parent_register,
348 &register_value);
349 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 goto unlock_and_exit;
351 }
352
353 /*
354 * Decode the Register ID
355 * Register ID = [Register block ID] | [bit ID]
356 *
357 * Check bit ID to fine locate Register offset.
358 * Check Mask to determine Register offset, and then read-write.
359 */
360 switch (bit_reg_info->parent_register) {
361 case ACPI_REGISTER_PM1_STATUS:
362
363 /*
364 * Status Registers are different from the rest. Clear by
365 * writing 1, and writing 0 has no effect. So, the only relevant
366 * information is the single bit we're interested in, all others should
367 * be written as 0 so they will be left unchanged.
368 */
Len Brown4be44fc2005-08-05 00:44:28 -0400369 value = ACPI_REGISTER_PREPARE_BITS(value,
370 bit_reg_info->bit_position,
371 bit_reg_info->
372 access_bit_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (value) {
Len Brown4be44fc2005-08-05 00:44:28 -0400374 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
375 ACPI_REGISTER_PM1_STATUS,
376 (u16) value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 register_value = 0;
378 }
379 break;
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 case ACPI_REGISTER_PM1_ENABLE:
382
Len Brown4be44fc2005-08-05 00:44:28 -0400383 ACPI_REGISTER_INSERT_VALUE(register_value,
384 bit_reg_info->bit_position,
385 bit_reg_info->access_bit_mask,
386 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
389 ACPI_REGISTER_PM1_ENABLE,
390 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 break;
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 case ACPI_REGISTER_PM1_CONTROL:
394
395 /*
396 * Write the PM1 Control register.
397 * Note that at this level, the fact that there are actually TWO
398 * registers (A and B - and B may not exist) is abstracted.
399 */
Len Brown4be44fc2005-08-05 00:44:28 -0400400 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
401 register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 ACPI_REGISTER_INSERT_VALUE(register_value,
404 bit_reg_info->bit_position,
405 bit_reg_info->access_bit_mask,
406 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
409 ACPI_REGISTER_PM1_CONTROL,
410 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 break;
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 case ACPI_REGISTER_PM2_CONTROL:
414
Len Brown4be44fc2005-08-05 00:44:28 -0400415 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
416 ACPI_REGISTER_PM2_CONTROL,
417 &register_value);
418 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 goto unlock_and_exit;
420 }
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 ACPI_DEBUG_PRINT((ACPI_DB_IO,
423 "PM2 control: Read %X from %8.8X%8.8X\n",
424 register_value,
425 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
426 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 ACPI_REGISTER_INSERT_VALUE(register_value,
429 bit_reg_info->bit_position,
430 bit_reg_info->access_bit_mask,
431 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 ACPI_DEBUG_PRINT((ACPI_DB_IO,
434 "About to write %4.4X to %8.8X%8.8X\n",
435 register_value,
436 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
437 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
440 ACPI_REGISTER_PM2_CONTROL,
441 (u8) (register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 break;
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 default:
445 break;
446 }
447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400451 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
453
454 /* Normalize the value that was read */
455
Len Brown4be44fc2005-08-05 00:44:28 -0400456 ACPI_DEBUG_EXEC(register_value =
457 ((register_value & bit_reg_info->access_bit_mask) >>
458 bit_reg_info->bit_position));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Len Brown4be44fc2005-08-05 00:44:28 -0400460 ACPI_DEBUG_PRINT((ACPI_DB_IO,
461 "Set bits: %8.8X actual %8.8X register %X\n", value,
462 register_value, bit_reg_info->parent_register));
463 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Len Brown4be44fc2005-08-05 00:44:28 -0400466EXPORT_SYMBOL(acpi_set_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468/******************************************************************************
469 *
470 * FUNCTION: acpi_hw_register_read
471 *
472 * PARAMETERS: use_lock - Mutex hw access
473 * register_id - register_iD + Offset
Robert Moore44f6c012005-04-18 22:49:35 -0400474 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 *
476 * RETURN: Status and the value read.
477 *
478 * DESCRIPTION: Acpi register read function. Registers are read at the
479 * given offset.
480 *
481 ******************************************************************************/
482
483acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400484acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Len Brown4be44fc2005-08-05 00:44:28 -0400486 u32 value1 = 0;
487 u32 value2 = 0;
488 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Len Brown4be44fc2005-08-05 00:44:28 -0400490 ACPI_FUNCTION_TRACE("hw_register_read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400493 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
494 if (ACPI_FAILURE(status)) {
495 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497 }
498
499 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400500 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Len Brown4be44fc2005-08-05 00:44:28 -0400502 status =
503 acpi_hw_low_level_read(16, &value1,
504 &acpi_gbl_FADT->xpm1a_evt_blk);
505 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 goto unlock_and_exit;
507 }
508
509 /* PM1B is optional */
510
Len Brown4be44fc2005-08-05 00:44:28 -0400511 status =
512 acpi_hw_low_level_read(16, &value2,
513 &acpi_gbl_FADT->xpm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 value1 |= value2;
515 break;
516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Len Brown4be44fc2005-08-05 00:44:28 -0400519 status =
520 acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable);
521 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 goto unlock_and_exit;
523 }
524
525 /* PM1B is optional */
526
Len Brown4be44fc2005-08-05 00:44:28 -0400527 status =
528 acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 value1 |= value2;
530 break;
531
Len Brown4be44fc2005-08-05 00:44:28 -0400532 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Len Brown4be44fc2005-08-05 00:44:28 -0400534 status =
535 acpi_hw_low_level_read(16, &value1,
536 &acpi_gbl_FADT->xpm1a_cnt_blk);
537 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 goto unlock_and_exit;
539 }
540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 status =
542 acpi_hw_low_level_read(16, &value2,
543 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 value1 |= value2;
545 break;
546
Len Brown4be44fc2005-08-05 00:44:28 -0400547 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Len Brown4be44fc2005-08-05 00:44:28 -0400549 status =
550 acpi_hw_low_level_read(8, &value1,
551 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 break;
553
Len Brown4be44fc2005-08-05 00:44:28 -0400554 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Len Brown4be44fc2005-08-05 00:44:28 -0400556 status =
557 acpi_hw_low_level_read(32, &value1,
558 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 break;
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Len Brown4be44fc2005-08-05 00:44:28 -0400563 status = acpi_os_read_port(acpi_gbl_FADT->smi_cmd, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 break;
565
566 default:
Bob Moore4a90c7e2006-01-13 16:22:00 -0500567 ACPI_REPORT_ERROR(("Unknown Register ID: %X\n", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 status = AE_BAD_PARAMETER;
569 break;
570 }
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400574 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 }
576
Len Brown4be44fc2005-08-05 00:44:28 -0400577 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 *return_value = value1;
579 }
580
Len Brown4be44fc2005-08-05 00:44:28 -0400581 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584/******************************************************************************
585 *
586 * FUNCTION: acpi_hw_register_write
587 *
588 * PARAMETERS: use_lock - Mutex hw access
589 * register_id - register_iD + Offset
590 * Value - The value to write
591 *
592 * RETURN: Status
593 *
594 * DESCRIPTION: Acpi register Write function. Registers are written at the
595 * given offset.
596 *
597 ******************************************************************************/
598
Len Brown4be44fc2005-08-05 00:44:28 -0400599acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Len Brown4be44fc2005-08-05 00:44:28 -0400601 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Len Brown4be44fc2005-08-05 00:44:28 -0400603 ACPI_FUNCTION_TRACE("hw_register_write");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400606 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
607 if (ACPI_FAILURE(status)) {
608 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
610 }
611
612 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400613 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Len Brown4be44fc2005-08-05 00:44:28 -0400615 status =
616 acpi_hw_low_level_write(16, value,
617 &acpi_gbl_FADT->xpm1a_evt_blk);
618 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 goto unlock_and_exit;
620 }
621
622 /* PM1B is optional */
623
Len Brown4be44fc2005-08-05 00:44:28 -0400624 status =
625 acpi_hw_low_level_write(16, value,
626 &acpi_gbl_FADT->xpm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 break;
628
Len Brown4be44fc2005-08-05 00:44:28 -0400629 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 status =
632 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable);
633 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 goto unlock_and_exit;
635 }
636
637 /* PM1B is optional */
638
Len Brown4be44fc2005-08-05 00:44:28 -0400639 status =
640 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 break;
642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 status =
646 acpi_hw_low_level_write(16, value,
647 &acpi_gbl_FADT->xpm1a_cnt_blk);
648 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 goto unlock_and_exit;
650 }
651
Len Brown4be44fc2005-08-05 00:44:28 -0400652 status =
653 acpi_hw_low_level_write(16, value,
654 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 break;
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Len Brown4be44fc2005-08-05 00:44:28 -0400659 status =
660 acpi_hw_low_level_write(16, value,
661 &acpi_gbl_FADT->xpm1a_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 break;
663
Len Brown4be44fc2005-08-05 00:44:28 -0400664 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 status =
667 acpi_hw_low_level_write(16, value,
668 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 break;
670
Len Brown4be44fc2005-08-05 00:44:28 -0400671 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Len Brown4be44fc2005-08-05 00:44:28 -0400673 status =
674 acpi_hw_low_level_write(8, value,
675 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 break;
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 status =
681 acpi_hw_low_level_write(32, value,
682 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 break;
684
Len Brown4be44fc2005-08-05 00:44:28 -0400685 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 /* SMI_CMD is currently always in IO space */
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 default:
693 status = AE_BAD_PARAMETER;
694 break;
695 }
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400699 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705/******************************************************************************
706 *
707 * FUNCTION: acpi_hw_low_level_read
708 *
709 * PARAMETERS: Width - 8, 16, or 32
710 * Value - Where the value is returned
711 * Reg - GAS register structure
712 *
713 * RETURN: Status
714 *
715 * DESCRIPTION: Read from either memory or IO space.
716 *
717 ******************************************************************************/
718
719acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400720acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
Len Brown4be44fc2005-08-05 00:44:28 -0400722 u64 address;
723 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Len Brown4be44fc2005-08-05 00:44:28 -0400725 ACPI_FUNCTION_NAME("hw_low_level_read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727 /*
728 * Must have a valid pointer to a GAS structure, and
729 * a non-zero address within. However, don't return an error
730 * because the PM1A/B code must not fail if B isn't present.
731 */
732 if (!reg) {
733 return (AE_OK);
734 }
735
736 /* Get a local copy of the address. Handles possible alignment issues */
737
Len Brown4be44fc2005-08-05 00:44:28 -0400738 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 if (!address) {
740 return (AE_OK);
741 }
742 *value = 0;
743
744 /*
745 * Two address spaces supported: Memory or IO.
746 * PCI_Config is not supported here because the GAS struct is insufficient
747 */
748 switch (reg->address_space_id) {
749 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
750
Len Brown4be44fc2005-08-05 00:44:28 -0400751 status = acpi_os_read_memory((acpi_physical_address) address,
752 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 break;
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 case ACPI_ADR_SPACE_SYSTEM_IO:
756
Len Brown4be44fc2005-08-05 00:44:28 -0400757 status = acpi_os_read_port((acpi_io_address) address,
758 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 break;
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 default:
Bob Moore4a90c7e2006-01-13 16:22:00 -0500762 ACPI_REPORT_ERROR(("Unsupported address space: %X\n",
763 reg->address_space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 return (AE_BAD_PARAMETER);
765 }
766
Len Brown4be44fc2005-08-05 00:44:28 -0400767 ACPI_DEBUG_PRINT((ACPI_DB_IO,
768 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
769 *value, width,
770 ACPI_FORMAT_UINT64(address),
771 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 return (status);
774}
775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776/******************************************************************************
777 *
778 * FUNCTION: acpi_hw_low_level_write
779 *
780 * PARAMETERS: Width - 8, 16, or 32
781 * Value - To be written
782 * Reg - GAS register structure
783 *
784 * RETURN: Status
785 *
786 * DESCRIPTION: Write to either memory or IO space.
787 *
788 ******************************************************************************/
789
790acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400791acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
Len Brown4be44fc2005-08-05 00:44:28 -0400793 u64 address;
794 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Len Brown4be44fc2005-08-05 00:44:28 -0400796 ACPI_FUNCTION_NAME("hw_low_level_write");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 /*
799 * Must have a valid pointer to a GAS structure, and
800 * a non-zero address within. However, don't return an error
801 * because the PM1A/B code must not fail if B isn't present.
802 */
803 if (!reg) {
804 return (AE_OK);
805 }
806
807 /* Get a local copy of the address. Handles possible alignment issues */
808
Len Brown4be44fc2005-08-05 00:44:28 -0400809 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 if (!address) {
811 return (AE_OK);
812 }
813
814 /*
815 * Two address spaces supported: Memory or IO.
816 * PCI_Config is not supported here because the GAS struct is insufficient
817 */
818 switch (reg->address_space_id) {
819 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
820
Len Brown4be44fc2005-08-05 00:44:28 -0400821 status = acpi_os_write_memory((acpi_physical_address) address,
822 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 break;
824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 case ACPI_ADR_SPACE_SYSTEM_IO:
826
Len Brown4be44fc2005-08-05 00:44:28 -0400827 status = acpi_os_write_port((acpi_io_address) address,
828 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 break;
830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 default:
Bob Moore4a90c7e2006-01-13 16:22:00 -0500832 ACPI_REPORT_ERROR(("Unsupported address space: %X\n",
833 reg->address_space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return (AE_BAD_PARAMETER);
835 }
836
Len Brown4be44fc2005-08-05 00:44:28 -0400837 ACPI_DEBUG_PRINT((ACPI_DB_IO,
838 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
839 value, width,
840 ACPI_FORMAT_UINT64(address),
841 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 return (status);
844}