blob: 5b19fc75cbd0ceeff535e0280c8c928f2ae8b2e8 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
47#include <acpi/acnamesp.h>
48#include <acpi/acevents.h>
49
50#define _COMPONENT ACPI_HARDWARE
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("hwregs")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_hw_clear_acpi_status
56 *
Bob Moored8c71b62007-02-02 19:48:21 +030057 * PARAMETERS: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 *
Bob Moored8c71b62007-02-02 19:48:21 +030059 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * DESCRIPTION: Clears all fixed and general purpose status bits
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
63 *
64 ******************************************************************************/
Bob Moored8c71b62007-02-02 19:48:21 +030065acpi_status acpi_hw_clear_acpi_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Len Brown4be44fc2005-08-05 00:44:28 -040067 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -040068 acpi_cpu_flags lock_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Bob Mooreb229cf92006-04-21 17:15:00 -040070 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Len Brown4be44fc2005-08-05 00:44:28 -040072 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
73 ACPI_BITMASK_ALL_FIXED_STATUS,
Bob Mooref3d2e782007-02-02 19:48:18 +030074 (u16) acpi_gbl_FADT.xpm1a_event_block.address));
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Moore4c90ece2006-06-08 16:29:00 -040076 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Len Brown4be44fc2005-08-05 00:44:28 -040078 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
79 ACPI_REGISTER_PM1_STATUS,
80 ACPI_BITMASK_ALL_FIXED_STATUS);
81 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 goto unlock_and_exit;
83 }
84
85 /* Clear the fixed events */
86
Bob Mooref3d2e782007-02-02 19:48:18 +030087 if (acpi_gbl_FADT.xpm1b_event_block.address) {
Len Brown4be44fc2005-08-05 00:44:28 -040088 status =
89 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
Bob Mooref3d2e782007-02-02 19:48:18 +030090 &acpi_gbl_FADT.xpm1b_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -040091 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 goto unlock_and_exit;
93 }
94 }
95
96 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
97
Len Brown4be44fc2005-08-05 00:44:28 -040098 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Len Brown4be44fc2005-08-05 00:44:28 -0400100 unlock_and_exit:
Bob Moore4c90ece2006-06-08 16:29:00 -0400101 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400102 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105/*******************************************************************************
106 *
107 * FUNCTION: acpi_get_sleep_type_data
108 *
109 * PARAMETERS: sleep_state - Numeric sleep state
110 * *sleep_type_a - Where SLP_TYPa is returned
111 * *sleep_type_b - Where SLP_TYPb is returned
112 *
113 * RETURN: Status - ACPI status
114 *
115 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
116 * state.
117 *
118 ******************************************************************************/
119
120acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400121acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Len Brown4be44fc2005-08-05 00:44:28 -0400123 acpi_status status = AE_OK;
Bob Moore41195322006-05-26 16:36:00 -0400124 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Bob Mooreb229cf92006-04-21 17:15:00 -0400126 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Robert Moore44f6c012005-04-18 22:49:35 -0400128 /* Validate parameters */
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
131 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
133
Bob Moore41195322006-05-26 16:36:00 -0400134 /* Allocate the evaluation information block */
Robert Moore44f6c012005-04-18 22:49:35 -0400135
Bob Moore41195322006-05-26 16:36:00 -0400136 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
137 if (!info) {
138 return_ACPI_STATUS(AE_NO_MEMORY);
139 }
140
141 info->pathname =
Bob Mooredefba1d2005-12-16 17:05:00 -0500142 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
Robert Moore44f6c012005-04-18 22:49:35 -0400143
Bob Moore41195322006-05-26 16:36:00 -0400144 /* Evaluate the namespace object containing the values for this state */
145
146 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400147 if (ACPI_FAILURE(status)) {
148 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400149 "%s while evaluating SleepState [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400150 acpi_format_exception(status),
Bob Moore41195322006-05-26 16:36:00 -0400151 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Bob Moore41195322006-05-26 16:36:00 -0400153 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155
156 /* Must have a return object */
157
Bob Moore41195322006-05-26 16:36:00 -0400158 if (!info->return_object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500159 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
Bob Moore41195322006-05-26 16:36:00 -0400160 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 status = AE_NOT_EXIST;
162 }
163
164 /* It must be of type Package */
165
Bob Moore41195322006-05-26 16:36:00 -0400166 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500167 ACPI_ERROR((AE_INFO,
168 "Sleep State return object is not a Package"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 status = AE_AML_OPERAND_TYPE;
170 }
171
Robert Moore44f6c012005-04-18 22:49:35 -0400172 /*
Bob Moore967440e2006-06-23 17:04:00 -0400173 * The package must have at least two elements. NOTE (March 2005): This
Robert Moore44f6c012005-04-18 22:49:35 -0400174 * goes against the current ACPI spec which defines this object as a
Bob Moore967440e2006-06-23 17:04:00 -0400175 * package with one encoded DWORD element. However, existing practice
Robert Moore44f6c012005-04-18 22:49:35 -0400176 * by BIOS vendors seems to be to have 2 or more elements, at least
177 * one per sleep type (A/B).
178 */
Bob Moore41195322006-05-26 16:36:00 -0400179 else if (info->return_object->package.count < 2) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500180 ACPI_ERROR((AE_INFO,
181 "Sleep State return package does not have at least two elements"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 status = AE_AML_NO_OPERAND;
183 }
184
185 /* The first two elements must both be of type Integer */
186
Bob Moore41195322006-05-26 16:36:00 -0400187 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
Len Brown4be44fc2005-08-05 00:44:28 -0400188 != ACPI_TYPE_INTEGER) ||
Bob Moore41195322006-05-26 16:36:00 -0400189 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
Len Brown4be44fc2005-08-05 00:44:28 -0400190 != ACPI_TYPE_INTEGER)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500191 ACPI_ERROR((AE_INFO,
192 "Sleep State return package elements are not both Integers (%s, %s)",
Bob Moore41195322006-05-26 16:36:00 -0400193 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500194 package.elements[0]),
Bob Moore41195322006-05-26 16:36:00 -0400195 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500196 package.elements[1])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 status = AE_AML_OPERAND_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400198 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400199 /* Valid _Sx_ package size, type, and value */
200
201 *sleep_type_a = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400202 (info->return_object->package.elements[0])->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400203 *sleep_type_b = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400204 (info->return_object->package.elements[1])->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500208 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400209 "While evaluating SleepState [%s], bad Sleep object %p type %s",
Bob Moore41195322006-05-26 16:36:00 -0400210 info->pathname, info->return_object,
211 acpi_ut_get_object_type_name(info->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500212 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214
Bob Moore41195322006-05-26 16:36:00 -0400215 acpi_ut_remove_reference(info->return_object);
216
217 cleanup:
218 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400219 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Bob Moore83135242006-10-03 00:00:00 -0400222ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224/*******************************************************************************
225 *
226 * FUNCTION: acpi_hw_get_register_bit_mask
227 *
228 * PARAMETERS: register_id - Index of ACPI Register to access
229 *
Robert Moore44f6c012005-04-18 22:49:35 -0400230 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 *
Robert Moore44f6c012005-04-18 22:49:35 -0400232 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 *
234 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400235struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500237 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 if (register_id > ACPI_BITREG_MAX) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400240 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500241 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 return (NULL);
243 }
244
245 return (&acpi_gbl_bit_register_info[register_id]);
246}
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/*******************************************************************************
249 *
250 * FUNCTION: acpi_get_register
251 *
252 * PARAMETERS: register_id - ID of ACPI bit_register to access
253 * return_value - Value that was read from the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 *
Bob Moore967440e2006-06-23 17:04:00 -0400255 * RETURN: Status and the value read from specified Register. Value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 * returned is normalized to bit0 (is shifted all the way right)
257 *
258 * DESCRIPTION: ACPI bit_register read function.
259 *
260 ******************************************************************************/
261
Bob Moored8c71b62007-02-02 19:48:21 +0300262acpi_status acpi_get_register(u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Len Brown4be44fc2005-08-05 00:44:28 -0400264 u32 register_value = 0;
265 struct acpi_bit_register_info *bit_reg_info;
266 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Bob Mooreb229cf92006-04-21 17:15:00 -0400268 ACPI_FUNCTION_TRACE(acpi_get_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Get the info structure corresponding to the requested ACPI Register */
271
Len Brown4be44fc2005-08-05 00:44:28 -0400272 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400274 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* Read from the register */
278
Bob Moore4c90ece2006-06-08 16:29:00 -0400279 status = acpi_hw_register_read(ACPI_MTX_LOCK,
Len Brown4be44fc2005-08-05 00:44:28 -0400280 bit_reg_info->parent_register,
281 &register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 /* Normalize the value that was read */
286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 register_value =
288 ((register_value & bit_reg_info->access_bit_mask)
289 >> bit_reg_info->bit_position);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 *return_value = register_value;
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
294 register_value,
295 bit_reg_info->parent_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Bob Moore83135242006-10-03 00:00:00 -0400301ACPI_EXPORT_SYMBOL(acpi_get_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303/*******************************************************************************
304 *
305 * FUNCTION: acpi_set_register
306 *
307 * PARAMETERS: register_id - ID of ACPI bit_register to access
308 * Value - (only used on write) value to write to the
309 * Register, NOT pre-normalized to the bit pos
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 *
311 * RETURN: Status
312 *
313 * DESCRIPTION: ACPI Bit Register write function.
314 *
315 ******************************************************************************/
Bob Moored8c71b62007-02-02 19:48:21 +0300316acpi_status acpi_set_register(u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Len Brown4be44fc2005-08-05 00:44:28 -0400318 u32 register_value = 0;
319 struct acpi_bit_register_info *bit_reg_info;
320 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400321 acpi_cpu_flags lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Bob Mooreb229cf92006-04-21 17:15:00 -0400323 ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 /* Get the info structure corresponding to the requested ACPI Register */
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (!bit_reg_info) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400329 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500330 register_id));
Len Brown4be44fc2005-08-05 00:44:28 -0400331 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
Bob Moore4c90ece2006-06-08 16:29:00 -0400334 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 /* Always do a register read first so we can insert the new bits */
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
339 bit_reg_info->parent_register,
340 &register_value);
341 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 goto unlock_and_exit;
343 }
344
345 /*
346 * Decode the Register ID
347 * Register ID = [Register block ID] | [bit ID]
348 *
349 * Check bit ID to fine locate Register offset.
350 * Check Mask to determine Register offset, and then read-write.
351 */
352 switch (bit_reg_info->parent_register) {
353 case ACPI_REGISTER_PM1_STATUS:
354
355 /*
Bob Moore967440e2006-06-23 17:04:00 -0400356 * Status Registers are different from the rest. Clear by
357 * writing 1, and writing 0 has no effect. So, the only relevant
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 * information is the single bit we're interested in, all others should
359 * be written as 0 so they will be left unchanged.
360 */
Len Brown4be44fc2005-08-05 00:44:28 -0400361 value = ACPI_REGISTER_PREPARE_BITS(value,
362 bit_reg_info->bit_position,
363 bit_reg_info->
364 access_bit_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (value) {
Len Brown4be44fc2005-08-05 00:44:28 -0400366 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
367 ACPI_REGISTER_PM1_STATUS,
368 (u16) value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 register_value = 0;
370 }
371 break;
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 case ACPI_REGISTER_PM1_ENABLE:
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 ACPI_REGISTER_INSERT_VALUE(register_value,
376 bit_reg_info->bit_position,
377 bit_reg_info->access_bit_mask,
378 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Len Brown4be44fc2005-08-05 00:44:28 -0400380 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
381 ACPI_REGISTER_PM1_ENABLE,
382 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 case ACPI_REGISTER_PM1_CONTROL:
386
387 /*
388 * Write the PM1 Control register.
389 * Note that at this level, the fact that there are actually TWO
390 * registers (A and B - and B may not exist) is abstracted.
391 */
Len Brown4be44fc2005-08-05 00:44:28 -0400392 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
393 register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Len Brown4be44fc2005-08-05 00:44:28 -0400395 ACPI_REGISTER_INSERT_VALUE(register_value,
396 bit_reg_info->bit_position,
397 bit_reg_info->access_bit_mask,
398 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
401 ACPI_REGISTER_PM1_CONTROL,
402 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 break;
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 case ACPI_REGISTER_PM2_CONTROL:
406
Len Brown4be44fc2005-08-05 00:44:28 -0400407 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
408 ACPI_REGISTER_PM2_CONTROL,
409 &register_value);
410 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 goto unlock_and_exit;
412 }
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 ACPI_DEBUG_PRINT((ACPI_DB_IO,
415 "PM2 control: Read %X from %8.8X%8.8X\n",
416 register_value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300417 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
418 xpm2_control_block.
419 address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 ACPI_REGISTER_INSERT_VALUE(register_value,
422 bit_reg_info->bit_position,
423 bit_reg_info->access_bit_mask,
424 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Len Brown4be44fc2005-08-05 00:44:28 -0400426 ACPI_DEBUG_PRINT((ACPI_DB_IO,
427 "About to write %4.4X to %8.8X%8.8X\n",
428 register_value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300429 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
430 xpm2_control_block.
431 address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
434 ACPI_REGISTER_PM2_CONTROL,
435 (u8) (register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 break;
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 default:
439 break;
440 }
441
Len Brown4be44fc2005-08-05 00:44:28 -0400442 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Bob Moore4c90ece2006-06-08 16:29:00 -0400444 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 /* Normalize the value that was read */
447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 ACPI_DEBUG_EXEC(register_value =
449 ((register_value & bit_reg_info->access_bit_mask) >>
450 bit_reg_info->bit_position));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Len Brown4be44fc2005-08-05 00:44:28 -0400452 ACPI_DEBUG_PRINT((ACPI_DB_IO,
453 "Set bits: %8.8X actual %8.8X register %X\n", value,
454 register_value, bit_reg_info->parent_register));
455 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Bob Moore83135242006-10-03 00:00:00 -0400458ACPI_EXPORT_SYMBOL(acpi_set_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460/******************************************************************************
461 *
462 * FUNCTION: acpi_hw_register_read
463 *
Bob Moore967440e2006-06-23 17:04:00 -0400464 * PARAMETERS: use_lock - Lock hardware? True/False
465 * register_id - ACPI Register ID
Robert Moore44f6c012005-04-18 22:49:35 -0400466 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 *
468 * RETURN: Status and the value read.
469 *
Bob Moore967440e2006-06-23 17:04:00 -0400470 * DESCRIPTION: Read from the specified ACPI register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 *
472 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400474acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Len Brown4be44fc2005-08-05 00:44:28 -0400476 u32 value1 = 0;
477 u32 value2 = 0;
478 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400479 acpi_cpu_flags lock_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Bob Mooreb229cf92006-04-21 17:15:00 -0400481 ACPI_FUNCTION_TRACE(hw_register_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400484 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486
487 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400488 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Len Brown4be44fc2005-08-05 00:44:28 -0400490 status =
491 acpi_hw_low_level_read(16, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300492 &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400493 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 goto unlock_and_exit;
495 }
496
497 /* PM1B is optional */
498
Len Brown4be44fc2005-08-05 00:44:28 -0400499 status =
500 acpi_hw_low_level_read(16, &value2,
Bob Mooref3d2e782007-02-02 19:48:18 +0300501 &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 value1 |= value2;
503 break;
504
Len Brown4be44fc2005-08-05 00:44:28 -0400505 case ACPI_REGISTER_PM1_ENABLE: /* 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, &acpi_gbl_xpm1a_enable);
509 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 goto unlock_and_exit;
511 }
512
513 /* PM1B is optional */
514
Len Brown4be44fc2005-08-05 00:44:28 -0400515 status =
516 acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 value1 |= value2;
518 break;
519
Len Brown4be44fc2005-08-05 00:44:28 -0400520 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 status =
523 acpi_hw_low_level_read(16, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300524 &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400525 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 goto unlock_and_exit;
527 }
528
Len Brown4be44fc2005-08-05 00:44:28 -0400529 status =
530 acpi_hw_low_level_read(16, &value2,
Bob Mooref3d2e782007-02-02 19:48:18 +0300531 &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 value1 |= value2;
533 break;
534
Len Brown4be44fc2005-08-05 00:44:28 -0400535 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Len Brown4be44fc2005-08-05 00:44:28 -0400537 status =
538 acpi_hw_low_level_read(8, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300539 &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 break;
541
Len Brown4be44fc2005-08-05 00:44:28 -0400542 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Len Brown4be44fc2005-08-05 00:44:28 -0400544 status =
545 acpi_hw_low_level_read(32, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300546 &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 break;
548
Len Brown4be44fc2005-08-05 00:44:28 -0400549 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Bob Mooref3d2e782007-02-02 19:48:18 +0300551 status =
552 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 break;
554
555 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500556 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 status = AE_BAD_PARAMETER;
558 break;
559 }
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400563 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565
Len Brown4be44fc2005-08-05 00:44:28 -0400566 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 *return_value = value1;
568 }
569
Len Brown4be44fc2005-08-05 00:44:28 -0400570 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573/******************************************************************************
574 *
575 * FUNCTION: acpi_hw_register_write
576 *
Bob Moore967440e2006-06-23 17:04:00 -0400577 * PARAMETERS: use_lock - Lock hardware? True/False
578 * register_id - ACPI Register ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 * Value - The value to write
580 *
581 * RETURN: Status
582 *
Bob Moore967440e2006-06-23 17:04:00 -0400583 * DESCRIPTION: Write to the specified ACPI register
584 *
585 * NOTE: In accordance with the ACPI specification, this function automatically
586 * preserves the value of the following bits, meaning that these bits cannot be
587 * changed via this interface:
588 *
589 * PM1_CONTROL[0] = SCI_EN
590 * PM1_CONTROL[9]
591 * PM1_STATUS[11]
592 *
593 * ACPI References:
594 * 1) Hardware Ignored Bits: When software writes to a register with ignored
595 * bit fields, it preserves the ignored bit fields
596 * 2) SCI_EN: OSPM always preserves this bit position
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 *
598 ******************************************************************************/
599
Len Brown4be44fc2005-08-05 00:44:28 -0400600acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Len Brown4be44fc2005-08-05 00:44:28 -0400602 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400603 acpi_cpu_flags lock_flags = 0;
Bob Moore967440e2006-06-23 17:04:00 -0400604 u32 read_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Bob Mooreb229cf92006-04-21 17:15:00 -0400606 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400609 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 }
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
Bob Moore967440e2006-06-23 17:04:00 -0400615 /* Perform a read first to preserve certain bits (per ACPI spec) */
616
617 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
618 ACPI_REGISTER_PM1_STATUS,
619 &read_value);
620 if (ACPI_FAILURE(status)) {
621 goto unlock_and_exit;
622 }
623
624 /* Insert the bits to be preserved */
625
626 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
627 read_value);
628
629 /* Now we can write the data */
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 status =
632 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300633 &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400634 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 goto unlock_and_exit;
636 }
637
638 /* PM1B is optional */
639
Len Brown4be44fc2005-08-05 00:44:28 -0400640 status =
641 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300642 &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 break;
644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Len Brown4be44fc2005-08-05 00:44:28 -0400647 status =
648 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable);
649 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 goto unlock_and_exit;
651 }
652
653 /* PM1B is optional */
654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 status =
656 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 break;
658
Len Brown4be44fc2005-08-05 00:44:28 -0400659 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Bob Moore967440e2006-06-23 17:04:00 -0400661 /*
662 * Perform a read first to preserve certain bits (per ACPI spec)
Bob Moore967440e2006-06-23 17:04:00 -0400663 */
664 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
665 ACPI_REGISTER_PM1_CONTROL,
666 &read_value);
667 if (ACPI_FAILURE(status)) {
668 goto unlock_and_exit;
669 }
670
671 /* Insert the bits to be preserved */
672
673 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
674 read_value);
675
676 /* Now we can write the data */
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 status =
679 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300680 &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400681 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 goto unlock_and_exit;
683 }
684
Len Brown4be44fc2005-08-05 00:44:28 -0400685 status =
686 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300687 &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 break;
689
Len Brown4be44fc2005-08-05 00:44:28 -0400690 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Len Brown4be44fc2005-08-05 00:44:28 -0400692 status =
693 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300694 &acpi_gbl_FADT.xpm1a_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 break;
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 status =
700 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300701 &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 break;
703
Len Brown4be44fc2005-08-05 00:44:28 -0400704 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Len Brown4be44fc2005-08-05 00:44:28 -0400706 status =
707 acpi_hw_low_level_write(8, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300708 &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 break;
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Len Brown4be44fc2005-08-05 00:44:28 -0400713 status =
714 acpi_hw_low_level_write(32, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300715 &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 break;
717
Len Brown4be44fc2005-08-05 00:44:28 -0400718 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 /* SMI_CMD is currently always in IO space */
721
Bob Mooref3d2e782007-02-02 19:48:18 +0300722 status =
723 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 break;
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 default:
727 status = AE_BAD_PARAMETER;
728 break;
729 }
730
Len Brown4be44fc2005-08-05 00:44:28 -0400731 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400733 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735
Len Brown4be44fc2005-08-05 00:44:28 -0400736 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}
738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739/******************************************************************************
740 *
741 * FUNCTION: acpi_hw_low_level_read
742 *
743 * PARAMETERS: Width - 8, 16, or 32
744 * Value - Where the value is returned
745 * Reg - GAS register structure
746 *
747 * RETURN: Status
748 *
749 * DESCRIPTION: Read from either memory or IO space.
750 *
751 ******************************************************************************/
752
753acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400754acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
Len Brown4be44fc2005-08-05 00:44:28 -0400756 u64 address;
757 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Bob Mooreb229cf92006-04-21 17:15:00 -0400759 ACPI_FUNCTION_NAME(hw_low_level_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /*
762 * Must have a valid pointer to a GAS structure, and
763 * a non-zero address within. However, don't return an error
764 * because the PM1A/B code must not fail if B isn't present.
765 */
766 if (!reg) {
767 return (AE_OK);
768 }
769
Bob Moore967440e2006-06-23 17:04:00 -0400770 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Len Brown4be44fc2005-08-05 00:44:28 -0400772 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if (!address) {
774 return (AE_OK);
775 }
776 *value = 0;
777
778 /*
779 * Two address spaces supported: Memory or IO.
780 * PCI_Config is not supported here because the GAS struct is insufficient
781 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300782 switch (reg->space_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
784
Len Brown4be44fc2005-08-05 00:44:28 -0400785 status = acpi_os_read_memory((acpi_physical_address) address,
786 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 break;
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 case ACPI_ADR_SPACE_SYSTEM_IO:
790
Bob Moore59fa8502007-02-02 19:48:23 +0300791 status =
792 acpi_os_read_port((acpi_io_address) address, value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 break;
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500796 ACPI_ERROR((AE_INFO,
Bob Mooref3d2e782007-02-02 19:48:18 +0300797 "Unsupported address space: %X", reg->space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return (AE_BAD_PARAMETER);
799 }
800
Len Brown4be44fc2005-08-05 00:44:28 -0400801 ACPI_DEBUG_PRINT((ACPI_DB_IO,
802 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
Bob Moore59fa8502007-02-02 19:48:23 +0300803 *value, width, ACPI_FORMAT_UINT64(address),
Bob Mooref3d2e782007-02-02 19:48:18 +0300804 acpi_ut_get_region_name(reg->space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 return (status);
807}
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809/******************************************************************************
810 *
811 * FUNCTION: acpi_hw_low_level_write
812 *
813 * PARAMETERS: Width - 8, 16, or 32
814 * Value - To be written
815 * Reg - GAS register structure
816 *
817 * RETURN: Status
818 *
819 * DESCRIPTION: Write to either memory or IO space.
820 *
821 ******************************************************************************/
822
823acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400824acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
Len Brown4be44fc2005-08-05 00:44:28 -0400826 u64 address;
827 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Bob Mooreb229cf92006-04-21 17:15:00 -0400829 ACPI_FUNCTION_NAME(hw_low_level_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 /*
832 * Must have a valid pointer to a GAS structure, and
833 * a non-zero address within. However, don't return an error
834 * because the PM1A/B code must not fail if B isn't present.
835 */
836 if (!reg) {
837 return (AE_OK);
838 }
839
Bob Moore967440e2006-06-23 17:04:00 -0400840 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Len Brown4be44fc2005-08-05 00:44:28 -0400842 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 if (!address) {
844 return (AE_OK);
845 }
846
847 /*
848 * Two address spaces supported: Memory or IO.
849 * PCI_Config is not supported here because the GAS struct is insufficient
850 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300851 switch (reg->space_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
853
Len Brown4be44fc2005-08-05 00:44:28 -0400854 status = acpi_os_write_memory((acpi_physical_address) address,
855 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 break;
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 case ACPI_ADR_SPACE_SYSTEM_IO:
859
Bob Moore59fa8502007-02-02 19:48:23 +0300860 status = acpi_os_write_port((acpi_io_address) address, value,
861 width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500865 ACPI_ERROR((AE_INFO,
Bob Mooref3d2e782007-02-02 19:48:18 +0300866 "Unsupported address space: %X", reg->space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 return (AE_BAD_PARAMETER);
868 }
869
Len Brown4be44fc2005-08-05 00:44:28 -0400870 ACPI_DEBUG_PRINT((ACPI_DB_IO,
871 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
Bob Moore59fa8502007-02-02 19:48:23 +0300872 value, width, ACPI_FORMAT_UINT64(address),
Bob Mooref3d2e782007-02-02 19:48:18 +0300873 acpi_ut_get_region_name(reg->space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 return (status);
876}