blob: 536a7aea80c93a802f206a0268d9c688d48478a3 [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/*
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
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;
Len Brown4be44fc2005-08-05 00:44:28 -0400147 sleep_state_name = (char *)acpi_gbl_sleep_state_names[sleep_state];
Robert Moore44f6c012005-04-18 22:49:35 -0400148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 status = acpi_ns_evaluate_by_name(sleep_state_name, &info);
150 if (ACPI_FAILURE(status)) {
151 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
152 "%s while evaluating sleep_state [%s]\n",
153 acpi_format_exception(status),
154 sleep_state_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158
159 /* Must have a return object */
160
161 if (!info.return_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400162 ACPI_REPORT_ERROR(("No Sleep State object returned from [%s]\n",
163 sleep_state_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 status = AE_NOT_EXIST;
165 }
166
167 /* It must be of type Package */
168
Len Brown4be44fc2005-08-05 00:44:28 -0400169 else if (ACPI_GET_OBJECT_TYPE(info.return_object) != ACPI_TYPE_PACKAGE) {
170 ACPI_REPORT_ERROR(("Sleep State return object is not a Package\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 status = AE_AML_OPERAND_TYPE;
172 }
173
Robert Moore44f6c012005-04-18 22:49:35 -0400174 /*
175 * The package must have at least two elements. NOTE (March 2005): This
176 * goes against the current ACPI spec which defines this object as a
177 * package with one encoded DWORD element. However, existing practice
178 * by BIOS vendors seems to be to have 2 or more elements, at least
179 * one per sleep type (A/B).
180 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 else if (info.return_object->package.count < 2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400182 ACPI_REPORT_ERROR(("Sleep State return package does not have at least two elements\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 status = AE_AML_NO_OPERAND;
184 }
185
186 /* The first two elements must both be of type Integer */
187
Len Brown4be44fc2005-08-05 00:44:28 -0400188 else if ((ACPI_GET_OBJECT_TYPE(info.return_object->package.elements[0])
189 != ACPI_TYPE_INTEGER) ||
190 (ACPI_GET_OBJECT_TYPE(info.return_object->package.elements[1])
191 != ACPI_TYPE_INTEGER)) {
192 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 -0700193 status = AE_AML_OPERAND_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400194 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400195 /* Valid _Sx_ package size, type, and value */
196
197 *sleep_type_a = (u8)
Len Brown4be44fc2005-08-05 00:44:28 -0400198 (info.return_object->package.elements[0])->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400199 *sleep_type_b = (u8)
Len Brown4be44fc2005-08-05 00:44:28 -0400200 (info.return_object->package.elements[1])->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 if (ACPI_FAILURE(status)) {
204 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
205 "%s While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
206 acpi_format_exception(status),
207 sleep_state_name, info.return_object,
208 acpi_ut_get_object_type_name(info.
209 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211
Len Brown4be44fc2005-08-05 00:44:28 -0400212 acpi_ut_remove_reference(info.return_object);
213 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Len Brown4be44fc2005-08-05 00:44:28 -0400216EXPORT_SYMBOL(acpi_get_sleep_type_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218/*******************************************************************************
219 *
220 * FUNCTION: acpi_hw_get_register_bit_mask
221 *
222 * PARAMETERS: register_id - Index of ACPI Register to access
223 *
Robert Moore44f6c012005-04-18 22:49:35 -0400224 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 *
Robert Moore44f6c012005-04-18 22:49:35 -0400226 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 *
228 ******************************************************************************/
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Len Brown4be44fc2005-08-05 00:44:28 -0400232 ACPI_FUNCTION_NAME("hw_get_bit_register_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 if (register_id > ACPI_BITREG_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400235 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
236 "Invalid bit_register ID: %X\n",
237 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return (NULL);
239 }
240
241 return (&acpi_gbl_bit_register_info[register_id]);
242}
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/*******************************************************************************
245 *
246 * FUNCTION: acpi_get_register
247 *
248 * PARAMETERS: register_id - ID of ACPI bit_register to access
249 * return_value - Value that was read from the register
250 * Flags - Lock the hardware or not
251 *
252 * RETURN: Status and the value read from specified Register. Value
253 * returned is normalized to bit0 (is shifted all the way right)
254 *
255 * DESCRIPTION: ACPI bit_register read function.
256 *
257 ******************************************************************************/
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Len Brown4be44fc2005-08-05 00:44:28 -0400261 u32 register_value = 0;
262 struct acpi_bit_register_info *bit_reg_info;
263 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Len Brown4be44fc2005-08-05 00:44:28 -0400265 ACPI_FUNCTION_TRACE("acpi_get_register");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 /* Get the info structure corresponding to the requested ACPI Register */
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400271 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 }
273
274 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400275 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
276 if (ACPI_FAILURE(status)) {
277 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
279 }
280
281 /* Read from the register */
282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
284 bit_reg_info->parent_register,
285 &register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400288 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 /* Normalize the value that was read */
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 register_value =
295 ((register_value & bit_reg_info->access_bit_mask)
296 >> bit_reg_info->bit_position);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 *return_value = register_value;
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
301 register_value,
302 bit_reg_info->parent_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Len Brown4be44fc2005-08-05 00:44:28 -0400308EXPORT_SYMBOL(acpi_get_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310/*******************************************************************************
311 *
312 * FUNCTION: acpi_set_register
313 *
314 * PARAMETERS: register_id - ID of ACPI bit_register to access
315 * Value - (only used on write) value to write to the
316 * Register, NOT pre-normalized to the bit pos
317 * Flags - Lock the hardware or not
318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: ACPI Bit Register write function.
322 *
323 ******************************************************************************/
324
Len Brown4be44fc2005-08-05 00:44:28 -0400325acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Len Brown4be44fc2005-08-05 00:44:28 -0400327 u32 register_value = 0;
328 struct acpi_bit_register_info *bit_reg_info;
329 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 ACPI_FUNCTION_TRACE_U32("acpi_set_register", register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* Get the info structure corresponding to the requested ACPI Register */
334
Len Brown4be44fc2005-08-05 00:44:28 -0400335 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400337 ACPI_REPORT_ERROR(("Bad ACPI HW register_id: %X\n",
338 register_id));
339 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
341
342 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400343 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
344 if (ACPI_FAILURE(status)) {
345 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347 }
348
349 /* Always do a register read first so we can insert the new bits */
350
Len Brown4be44fc2005-08-05 00:44:28 -0400351 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
352 bit_reg_info->parent_register,
353 &register_value);
354 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 goto unlock_and_exit;
356 }
357
358 /*
359 * Decode the Register ID
360 * Register ID = [Register block ID] | [bit ID]
361 *
362 * Check bit ID to fine locate Register offset.
363 * Check Mask to determine Register offset, and then read-write.
364 */
365 switch (bit_reg_info->parent_register) {
366 case ACPI_REGISTER_PM1_STATUS:
367
368 /*
369 * Status Registers are different from the rest. Clear by
370 * writing 1, and writing 0 has no effect. So, the only relevant
371 * information is the single bit we're interested in, all others should
372 * be written as 0 so they will be left unchanged.
373 */
Len Brown4be44fc2005-08-05 00:44:28 -0400374 value = ACPI_REGISTER_PREPARE_BITS(value,
375 bit_reg_info->bit_position,
376 bit_reg_info->
377 access_bit_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 if (value) {
Len Brown4be44fc2005-08-05 00:44:28 -0400379 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
380 ACPI_REGISTER_PM1_STATUS,
381 (u16) value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 register_value = 0;
383 }
384 break;
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 case ACPI_REGISTER_PM1_ENABLE:
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 ACPI_REGISTER_INSERT_VALUE(register_value,
389 bit_reg_info->bit_position,
390 bit_reg_info->access_bit_mask,
391 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Len Brown4be44fc2005-08-05 00:44:28 -0400393 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
394 ACPI_REGISTER_PM1_ENABLE,
395 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 case ACPI_REGISTER_PM1_CONTROL:
399
400 /*
401 * Write the PM1 Control register.
402 * Note that at this level, the fact that there are actually TWO
403 * registers (A and B - and B may not exist) is abstracted.
404 */
Len Brown4be44fc2005-08-05 00:44:28 -0400405 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
406 register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 ACPI_REGISTER_INSERT_VALUE(register_value,
409 bit_reg_info->bit_position,
410 bit_reg_info->access_bit_mask,
411 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Len Brown4be44fc2005-08-05 00:44:28 -0400413 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
414 ACPI_REGISTER_PM1_CONTROL,
415 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 break;
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 case ACPI_REGISTER_PM2_CONTROL:
419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
421 ACPI_REGISTER_PM2_CONTROL,
422 &register_value);
423 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 goto unlock_and_exit;
425 }
426
Len Brown4be44fc2005-08-05 00:44:28 -0400427 ACPI_DEBUG_PRINT((ACPI_DB_IO,
428 "PM2 control: Read %X from %8.8X%8.8X\n",
429 register_value,
430 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
431 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 ACPI_REGISTER_INSERT_VALUE(register_value,
434 bit_reg_info->bit_position,
435 bit_reg_info->access_bit_mask,
436 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Len Brown4be44fc2005-08-05 00:44:28 -0400438 ACPI_DEBUG_PRINT((ACPI_DB_IO,
439 "About to write %4.4X to %8.8X%8.8X\n",
440 register_value,
441 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
442 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Len Brown4be44fc2005-08-05 00:44:28 -0400444 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
445 ACPI_REGISTER_PM2_CONTROL,
446 (u8) (register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 break;
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 default:
450 break;
451 }
452
Len Brown4be44fc2005-08-05 00:44:28 -0400453 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400456 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458
459 /* Normalize the value that was read */
460
Len Brown4be44fc2005-08-05 00:44:28 -0400461 ACPI_DEBUG_EXEC(register_value =
462 ((register_value & bit_reg_info->access_bit_mask) >>
463 bit_reg_info->bit_position));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Len Brown4be44fc2005-08-05 00:44:28 -0400465 ACPI_DEBUG_PRINT((ACPI_DB_IO,
466 "Set bits: %8.8X actual %8.8X register %X\n", value,
467 register_value, bit_reg_info->parent_register));
468 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Len Brown4be44fc2005-08-05 00:44:28 -0400471EXPORT_SYMBOL(acpi_set_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473/******************************************************************************
474 *
475 * FUNCTION: acpi_hw_register_read
476 *
477 * PARAMETERS: use_lock - Mutex hw access
478 * register_id - register_iD + Offset
Robert Moore44f6c012005-04-18 22:49:35 -0400479 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 *
481 * RETURN: Status and the value read.
482 *
483 * DESCRIPTION: Acpi register read function. Registers are read at the
484 * given offset.
485 *
486 ******************************************************************************/
487
488acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400489acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Len Brown4be44fc2005-08-05 00:44:28 -0400491 u32 value1 = 0;
492 u32 value2 = 0;
493 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Len Brown4be44fc2005-08-05 00:44:28 -0400495 ACPI_FUNCTION_TRACE("hw_register_read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400498 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
499 if (ACPI_FAILURE(status)) {
500 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502 }
503
504 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400505 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Len Brown4be44fc2005-08-05 00:44:28 -0400507 status =
508 acpi_hw_low_level_read(16, &value1,
509 &acpi_gbl_FADT->xpm1a_evt_blk);
510 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 goto unlock_and_exit;
512 }
513
514 /* PM1B is optional */
515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 status =
517 acpi_hw_low_level_read(16, &value2,
518 &acpi_gbl_FADT->xpm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 value1 |= value2;
520 break;
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Len Brown4be44fc2005-08-05 00:44:28 -0400524 status =
525 acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable);
526 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 goto unlock_and_exit;
528 }
529
530 /* PM1B is optional */
531
Len Brown4be44fc2005-08-05 00:44:28 -0400532 status =
533 acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 value1 |= value2;
535 break;
536
Len Brown4be44fc2005-08-05 00:44:28 -0400537 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Len Brown4be44fc2005-08-05 00:44:28 -0400539 status =
540 acpi_hw_low_level_read(16, &value1,
541 &acpi_gbl_FADT->xpm1a_cnt_blk);
542 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 goto unlock_and_exit;
544 }
545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 status =
547 acpi_hw_low_level_read(16, &value2,
548 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 value1 |= value2;
550 break;
551
Len Brown4be44fc2005-08-05 00:44:28 -0400552 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Len Brown4be44fc2005-08-05 00:44:28 -0400554 status =
555 acpi_hw_low_level_read(8, &value1,
556 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 break;
558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 status =
562 acpi_hw_low_level_read(32, &value1,
563 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 break;
565
Len Brown4be44fc2005-08-05 00:44:28 -0400566 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Len Brown4be44fc2005-08-05 00:44:28 -0400568 status = acpi_os_read_port(acpi_gbl_FADT->smi_cmd, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 break;
570
571 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400572 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown Register ID: %X\n",
573 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 status = AE_BAD_PARAMETER;
575 break;
576 }
577
Len Brown4be44fc2005-08-05 00:44:28 -0400578 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400580 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582
Len Brown4be44fc2005-08-05 00:44:28 -0400583 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 *return_value = value1;
585 }
586
Len Brown4be44fc2005-08-05 00:44:28 -0400587 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590/******************************************************************************
591 *
592 * FUNCTION: acpi_hw_register_write
593 *
594 * PARAMETERS: use_lock - Mutex hw access
595 * register_id - register_iD + Offset
596 * Value - The value to write
597 *
598 * RETURN: Status
599 *
600 * DESCRIPTION: Acpi register Write function. Registers are written at the
601 * given offset.
602 *
603 ******************************************************************************/
604
Len Brown4be44fc2005-08-05 00:44:28 -0400605acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Len Brown4be44fc2005-08-05 00:44:28 -0400607 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Len Brown4be44fc2005-08-05 00:44:28 -0400609 ACPI_FUNCTION_TRACE("hw_register_write");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400612 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
613 if (ACPI_FAILURE(status)) {
614 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616 }
617
618 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400619 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Len Brown4be44fc2005-08-05 00:44:28 -0400621 status =
622 acpi_hw_low_level_write(16, value,
623 &acpi_gbl_FADT->xpm1a_evt_blk);
624 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 goto unlock_and_exit;
626 }
627
628 /* PM1B is optional */
629
Len Brown4be44fc2005-08-05 00:44:28 -0400630 status =
631 acpi_hw_low_level_write(16, value,
632 &acpi_gbl_FADT->xpm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 break;
634
Len Brown4be44fc2005-08-05 00:44:28 -0400635 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 status =
638 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable);
639 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 goto unlock_and_exit;
641 }
642
643 /* PM1B is optional */
644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 status =
646 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 break;
648
Len Brown4be44fc2005-08-05 00:44:28 -0400649 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Len Brown4be44fc2005-08-05 00:44:28 -0400651 status =
652 acpi_hw_low_level_write(16, value,
653 &acpi_gbl_FADT->xpm1a_cnt_blk);
654 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 goto unlock_and_exit;
656 }
657
Len Brown4be44fc2005-08-05 00:44:28 -0400658 status =
659 acpi_hw_low_level_write(16, value,
660 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 break;
662
Len Brown4be44fc2005-08-05 00:44:28 -0400663 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Len Brown4be44fc2005-08-05 00:44:28 -0400665 status =
666 acpi_hw_low_level_write(16, value,
667 &acpi_gbl_FADT->xpm1a_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 break;
669
Len Brown4be44fc2005-08-05 00:44:28 -0400670 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 status =
673 acpi_hw_low_level_write(16, value,
674 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 break;
676
Len Brown4be44fc2005-08-05 00:44:28 -0400677 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Len Brown4be44fc2005-08-05 00:44:28 -0400679 status =
680 acpi_hw_low_level_write(8, value,
681 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 break;
683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Len Brown4be44fc2005-08-05 00:44:28 -0400686 status =
687 acpi_hw_low_level_write(32, value,
688 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 break;
690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 /* SMI_CMD is currently always in IO space */
694
Len Brown4be44fc2005-08-05 00:44:28 -0400695 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 break;
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 default:
699 status = AE_BAD_PARAMETER;
700 break;
701 }
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400705 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 }
707
Len Brown4be44fc2005-08-05 00:44:28 -0400708 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709}
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711/******************************************************************************
712 *
713 * FUNCTION: acpi_hw_low_level_read
714 *
715 * PARAMETERS: Width - 8, 16, or 32
716 * Value - Where the value is returned
717 * Reg - GAS register structure
718 *
719 * RETURN: Status
720 *
721 * DESCRIPTION: Read from either memory or IO space.
722 *
723 ******************************************************************************/
724
725acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400726acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Len Brown4be44fc2005-08-05 00:44:28 -0400728 u64 address;
729 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Len Brown4be44fc2005-08-05 00:44:28 -0400731 ACPI_FUNCTION_NAME("hw_low_level_read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 /*
734 * Must have a valid pointer to a GAS structure, and
735 * a non-zero address within. However, don't return an error
736 * because the PM1A/B code must not fail if B isn't present.
737 */
738 if (!reg) {
739 return (AE_OK);
740 }
741
742 /* Get a local copy of the address. Handles possible alignment issues */
743
Len Brown4be44fc2005-08-05 00:44:28 -0400744 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 if (!address) {
746 return (AE_OK);
747 }
748 *value = 0;
749
750 /*
751 * Two address spaces supported: Memory or IO.
752 * PCI_Config is not supported here because the GAS struct is insufficient
753 */
754 switch (reg->address_space_id) {
755 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
756
Len Brown4be44fc2005-08-05 00:44:28 -0400757 status = acpi_os_read_memory((acpi_physical_address) address,
758 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 break;
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 case ACPI_ADR_SPACE_SYSTEM_IO:
762
Len Brown4be44fc2005-08-05 00:44:28 -0400763 status = acpi_os_read_port((acpi_io_address) address,
764 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 break;
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400768 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
769 "Unsupported address space: %X\n",
770 reg->address_space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 return (AE_BAD_PARAMETER);
772 }
773
Len Brown4be44fc2005-08-05 00:44:28 -0400774 ACPI_DEBUG_PRINT((ACPI_DB_IO,
775 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
776 *value, width,
777 ACPI_FORMAT_UINT64(address),
778 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 return (status);
781}
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783/******************************************************************************
784 *
785 * FUNCTION: acpi_hw_low_level_write
786 *
787 * PARAMETERS: Width - 8, 16, or 32
788 * Value - To be written
789 * Reg - GAS register structure
790 *
791 * RETURN: Status
792 *
793 * DESCRIPTION: Write to either memory or IO space.
794 *
795 ******************************************************************************/
796
797acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400798acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
Len Brown4be44fc2005-08-05 00:44:28 -0400800 u64 address;
801 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Len Brown4be44fc2005-08-05 00:44:28 -0400803 ACPI_FUNCTION_NAME("hw_low_level_write");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 /*
806 * Must have a valid pointer to a GAS structure, and
807 * a non-zero address within. However, don't return an error
808 * because the PM1A/B code must not fail if B isn't present.
809 */
810 if (!reg) {
811 return (AE_OK);
812 }
813
814 /* Get a local copy of the address. Handles possible alignment issues */
815
Len Brown4be44fc2005-08-05 00:44:28 -0400816 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 if (!address) {
818 return (AE_OK);
819 }
820
821 /*
822 * Two address spaces supported: Memory or IO.
823 * PCI_Config is not supported here because the GAS struct is insufficient
824 */
825 switch (reg->address_space_id) {
826 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
827
Len Brown4be44fc2005-08-05 00:44:28 -0400828 status = acpi_os_write_memory((acpi_physical_address) address,
829 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 break;
831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 case ACPI_ADR_SPACE_SYSTEM_IO:
833
Len Brown4be44fc2005-08-05 00:44:28 -0400834 status = acpi_os_write_port((acpi_io_address) address,
835 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 break;
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400839 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
840 "Unsupported address space: %X\n",
841 reg->address_space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 return (AE_BAD_PARAMETER);
843 }
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845 ACPI_DEBUG_PRINT((ACPI_DB_IO,
846 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
847 value, width,
848 ACPI_FORMAT_UINT64(address),
849 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 return (status);
852}