blob: ddf792adcf9619fe581c9067c06761d8b2780955 [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/*
Len Brown75a44ce2008-04-23 23:00:13 -040010 * Copyright (C) 2000 - 2008, Intel Corp.
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
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +040078 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
Len Brown4be44fc2005-08-05 00:44:28 -040079 ACPI_BITMASK_ALL_FIXED_STATUS);
80 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 goto unlock_and_exit;
82 }
83
84 /* Clear the fixed events */
85
Bob Mooref3d2e782007-02-02 19:48:18 +030086 if (acpi_gbl_FADT.xpm1b_event_block.address) {
Len Brown4be44fc2005-08-05 00:44:28 -040087 status =
88 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
Bob Mooref3d2e782007-02-02 19:48:18 +030089 &acpi_gbl_FADT.xpm1b_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -040090 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 goto unlock_and_exit;
92 }
93 }
94
95 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
96
Len Brown4be44fc2005-08-05 00:44:28 -040097 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Len Brown4be44fc2005-08-05 00:44:28 -040099 unlock_and_exit:
Bob Moore4c90ece2006-06-08 16:29:00 -0400100 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400101 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104/*******************************************************************************
105 *
106 * FUNCTION: acpi_get_sleep_type_data
107 *
108 * PARAMETERS: sleep_state - Numeric sleep state
109 * *sleep_type_a - Where SLP_TYPa is returned
110 * *sleep_type_b - Where SLP_TYPb is returned
111 *
112 * RETURN: Status - ACPI status
113 *
114 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
115 * state.
116 *
117 ******************************************************************************/
118
119acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400120acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Len Brown4be44fc2005-08-05 00:44:28 -0400122 acpi_status status = AE_OK;
Bob Moore41195322006-05-26 16:36:00 -0400123 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Bob Mooreb229cf92006-04-21 17:15:00 -0400125 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Robert Moore44f6c012005-04-18 22:49:35 -0400127 /* Validate parameters */
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
130 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
Bob Moore41195322006-05-26 16:36:00 -0400133 /* Allocate the evaluation information block */
Robert Moore44f6c012005-04-18 22:49:35 -0400134
Bob Moore41195322006-05-26 16:36:00 -0400135 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
136 if (!info) {
137 return_ACPI_STATUS(AE_NO_MEMORY);
138 }
139
140 info->pathname =
Bob Mooredefba1d2005-12-16 17:05:00 -0500141 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
Robert Moore44f6c012005-04-18 22:49:35 -0400142
Bob Moore41195322006-05-26 16:36:00 -0400143 /* Evaluate the namespace object containing the values for this state */
144
145 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400146 if (ACPI_FAILURE(status)) {
147 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400148 "%s while evaluating SleepState [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400149 acpi_format_exception(status),
Bob Moore41195322006-05-26 16:36:00 -0400150 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Bob Moore41195322006-05-26 16:36:00 -0400152 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154
155 /* Must have a return object */
156
Bob Moore41195322006-05-26 16:36:00 -0400157 if (!info->return_object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500158 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
Bob Moore41195322006-05-26 16:36:00 -0400159 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 status = AE_NOT_EXIST;
161 }
162
163 /* It must be of type Package */
164
Bob Moore41195322006-05-26 16:36:00 -0400165 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500166 ACPI_ERROR((AE_INFO,
167 "Sleep State return object is not a Package"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 status = AE_AML_OPERAND_TYPE;
169 }
170
Robert Moore44f6c012005-04-18 22:49:35 -0400171 /*
Bob Moore967440e2006-06-23 17:04:00 -0400172 * The package must have at least two elements. NOTE (March 2005): This
Robert Moore44f6c012005-04-18 22:49:35 -0400173 * goes against the current ACPI spec which defines this object as a
Bob Moore967440e2006-06-23 17:04:00 -0400174 * package with one encoded DWORD element. However, existing practice
Robert Moore44f6c012005-04-18 22:49:35 -0400175 * by BIOS vendors seems to be to have 2 or more elements, at least
176 * one per sleep type (A/B).
177 */
Bob Moore41195322006-05-26 16:36:00 -0400178 else if (info->return_object->package.count < 2) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500179 ACPI_ERROR((AE_INFO,
180 "Sleep State return package does not have at least two elements"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 status = AE_AML_NO_OPERAND;
182 }
183
184 /* The first two elements must both be of type Integer */
185
Bob Moore41195322006-05-26 16:36:00 -0400186 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
Len Brown4be44fc2005-08-05 00:44:28 -0400187 != ACPI_TYPE_INTEGER) ||
Bob Moore41195322006-05-26 16:36:00 -0400188 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
Len Brown4be44fc2005-08-05 00:44:28 -0400189 != ACPI_TYPE_INTEGER)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500190 ACPI_ERROR((AE_INFO,
191 "Sleep State return package elements are not both Integers (%s, %s)",
Bob Moore41195322006-05-26 16:36:00 -0400192 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500193 package.elements[0]),
Bob Moore41195322006-05-26 16:36:00 -0400194 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500195 package.elements[1])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 status = AE_AML_OPERAND_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400197 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400198 /* Valid _Sx_ package size, type, and value */
199
200 *sleep_type_a = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400201 (info->return_object->package.elements[0])->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400202 *sleep_type_b = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400203 (info->return_object->package.elements[1])->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
205
Len Brown4be44fc2005-08-05 00:44:28 -0400206 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500207 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400208 "While evaluating SleepState [%s], bad Sleep object %p type %s",
Bob Moore41195322006-05-26 16:36:00 -0400209 info->pathname, info->return_object,
210 acpi_ut_get_object_type_name(info->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500211 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
213
Bob Moore41195322006-05-26 16:36:00 -0400214 acpi_ut_remove_reference(info->return_object);
215
216 cleanup:
217 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400218 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Bob Moore83135242006-10-03 00:00:00 -0400221ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223/*******************************************************************************
224 *
225 * FUNCTION: acpi_hw_get_register_bit_mask
226 *
227 * PARAMETERS: register_id - Index of ACPI Register to access
228 *
Robert Moore44f6c012005-04-18 22:49:35 -0400229 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 *
Robert Moore44f6c012005-04-18 22:49:35 -0400231 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 *
233 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400234struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500236 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 if (register_id > ACPI_BITREG_MAX) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400239 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500240 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return (NULL);
242 }
243
244 return (&acpi_gbl_bit_register_info[register_id]);
245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/*******************************************************************************
248 *
249 * FUNCTION: acpi_get_register
250 *
251 * PARAMETERS: register_id - ID of ACPI bit_register to access
252 * return_value - Value that was read from the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 *
Bob Moore967440e2006-06-23 17:04:00 -0400254 * RETURN: Status and the value read from specified Register. Value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 * returned is normalized to bit0 (is shifted all the way right)
256 *
257 * DESCRIPTION: ACPI bit_register read function.
258 *
259 ******************************************************************************/
260
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400261acpi_status acpi_get_register_unlocked(u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Len Brown4be44fc2005-08-05 00:44:28 -0400263 u32 register_value = 0;
264 struct acpi_bit_register_info *bit_reg_info;
265 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Bob Mooreb229cf92006-04-21 17:15:00 -0400267 ACPI_FUNCTION_TRACE(acpi_get_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 /* Get the info structure corresponding to the requested ACPI Register */
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400273 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* Read from the register */
277
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400278 status = acpi_hw_register_read(bit_reg_info->parent_register,
Len Brown4be44fc2005-08-05 00:44:28 -0400279 &register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Len Brown4be44fc2005-08-05 00:44:28 -0400281 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 /* Normalize the value that was read */
284
Len Brown4be44fc2005-08-05 00:44:28 -0400285 register_value =
286 ((register_value & bit_reg_info->access_bit_mask)
287 >> bit_reg_info->bit_position);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 *return_value = register_value;
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
292 register_value,
293 bit_reg_info->parent_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400299acpi_status acpi_get_register(u32 register_id, u32 * return_value)
300{
301 acpi_status status;
302 acpi_cpu_flags flags;
303 flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
304 status = acpi_get_register_unlocked(register_id, return_value);
305 acpi_os_release_lock(acpi_gbl_hardware_lock, flags);
306 return status;
307}
308
Bob Moore83135242006-10-03 00:00:00 -0400309ACPI_EXPORT_SYMBOL(acpi_get_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311/*******************************************************************************
312 *
313 * FUNCTION: acpi_set_register
314 *
315 * PARAMETERS: register_id - ID of ACPI bit_register to access
316 * Value - (only used on write) value to write to the
317 * Register, NOT pre-normalized to the bit pos
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: ACPI Bit Register write function.
322 *
323 ******************************************************************************/
Bob Moored8c71b62007-02-02 19:48:21 +0300324acpi_status acpi_set_register(u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Len Brown4be44fc2005-08-05 00:44:28 -0400326 u32 register_value = 0;
327 struct acpi_bit_register_info *bit_reg_info;
328 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400329 acpi_cpu_flags lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Bob Mooreb229cf92006-04-21 17:15:00 -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) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400337 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500338 register_id));
Len Brown4be44fc2005-08-05 00:44:28 -0400339 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
341
Bob Moore4c90ece2006-06-08 16:29:00 -0400342 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 /* Always do a register read first so we can insert the new bits */
345
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400346 status = acpi_hw_register_read(bit_reg_info->parent_register,
Len Brown4be44fc2005-08-05 00:44:28 -0400347 &register_value);
348 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 goto unlock_and_exit;
350 }
351
352 /*
353 * Decode the Register ID
354 * Register ID = [Register block ID] | [bit ID]
355 *
356 * Check bit ID to fine locate Register offset.
357 * Check Mask to determine Register offset, and then read-write.
358 */
359 switch (bit_reg_info->parent_register) {
360 case ACPI_REGISTER_PM1_STATUS:
361
362 /*
Bob Moore967440e2006-06-23 17:04:00 -0400363 * Status Registers are different from the rest. Clear by
364 * writing 1, and writing 0 has no effect. So, the only relevant
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 * information is the single bit we're interested in, all others should
366 * be written as 0 so they will be left unchanged.
367 */
Len Brown4be44fc2005-08-05 00:44:28 -0400368 value = ACPI_REGISTER_PREPARE_BITS(value,
369 bit_reg_info->bit_position,
370 bit_reg_info->
371 access_bit_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (value) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400373 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
Len Brown4be44fc2005-08-05 00:44:28 -0400374 (u16) value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 register_value = 0;
376 }
377 break;
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 case ACPI_REGISTER_PM1_ENABLE:
380
Len Brown4be44fc2005-08-05 00:44:28 -0400381 ACPI_REGISTER_INSERT_VALUE(register_value,
382 bit_reg_info->bit_position,
383 bit_reg_info->access_bit_mask,
384 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400386 status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE,
Len Brown4be44fc2005-08-05 00:44:28 -0400387 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 case ACPI_REGISTER_PM1_CONTROL:
391
392 /*
393 * Write the PM1 Control register.
394 * Note that at this level, the fact that there are actually TWO
395 * registers (A and B - and B may not exist) is abstracted.
396 */
Len Brown4be44fc2005-08-05 00:44:28 -0400397 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
398 register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 ACPI_REGISTER_INSERT_VALUE(register_value,
401 bit_reg_info->bit_position,
402 bit_reg_info->access_bit_mask,
403 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400405 status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL,
Len Brown4be44fc2005-08-05 00:44:28 -0400406 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 break;
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 case ACPI_REGISTER_PM2_CONTROL:
410
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400411 status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL,
Len Brown4be44fc2005-08-05 00:44:28 -0400412 &register_value);
413 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 goto unlock_and_exit;
415 }
416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 ACPI_DEBUG_PRINT((ACPI_DB_IO,
418 "PM2 control: Read %X from %8.8X%8.8X\n",
419 register_value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300420 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
421 xpm2_control_block.
422 address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Len Brown4be44fc2005-08-05 00:44:28 -0400424 ACPI_REGISTER_INSERT_VALUE(register_value,
425 bit_reg_info->bit_position,
426 bit_reg_info->access_bit_mask,
427 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 ACPI_DEBUG_PRINT((ACPI_DB_IO,
430 "About to write %4.4X to %8.8X%8.8X\n",
431 register_value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300432 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
433 xpm2_control_block.
434 address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400436 status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL,
Len Brown4be44fc2005-08-05 00:44:28 -0400437 (u8) (register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 break;
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 default:
441 break;
442 }
443
Len Brown4be44fc2005-08-05 00:44:28 -0400444 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Bob Moore4c90ece2006-06-08 16:29:00 -0400446 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 /* Normalize the value that was read */
449
Len Brown4be44fc2005-08-05 00:44:28 -0400450 ACPI_DEBUG_EXEC(register_value =
451 ((register_value & bit_reg_info->access_bit_mask) >>
452 bit_reg_info->bit_position));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 ACPI_DEBUG_PRINT((ACPI_DB_IO,
455 "Set bits: %8.8X actual %8.8X register %X\n", value,
456 register_value, bit_reg_info->parent_register));
457 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Bob Moore83135242006-10-03 00:00:00 -0400460ACPI_EXPORT_SYMBOL(acpi_set_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462/******************************************************************************
463 *
464 * FUNCTION: acpi_hw_register_read
465 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400466 * PARAMETERS: register_id - ACPI Register ID
Robert Moore44f6c012005-04-18 22:49:35 -0400467 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 *
469 * RETURN: Status and the value read.
470 *
Bob Moore967440e2006-06-23 17:04:00 -0400471 * DESCRIPTION: Read from the specified ACPI register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 *
473 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474acpi_status
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400475acpi_hw_register_read(u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
Len Brown4be44fc2005-08-05 00:44:28 -0400477 u32 value1 = 0;
478 u32 value2 = 0;
479 acpi_status status;
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400484 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Len Brown4be44fc2005-08-05 00:44:28 -0400486 status =
487 acpi_hw_low_level_read(16, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300488 &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400489 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400490 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
493 /* PM1B is optional */
494
Len Brown4be44fc2005-08-05 00:44:28 -0400495 status =
496 acpi_hw_low_level_read(16, &value2,
Bob Mooref3d2e782007-02-02 19:48:18 +0300497 &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 value1 |= value2;
499 break;
500
Len Brown4be44fc2005-08-05 00:44:28 -0400501 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Len Brown4be44fc2005-08-05 00:44:28 -0400503 status =
504 acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable);
505 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400506 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
508
509 /* PM1B is optional */
510
Len Brown4be44fc2005-08-05 00:44:28 -0400511 status =
512 acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 value1 |= value2;
514 break;
515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Len Brown4be44fc2005-08-05 00:44:28 -0400518 status =
519 acpi_hw_low_level_read(16, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300520 &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400521 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400522 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
Len Brown4be44fc2005-08-05 00:44:28 -0400525 status =
526 acpi_hw_low_level_read(16, &value2,
Bob Mooref3d2e782007-02-02 19:48:18 +0300527 &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 value1 |= value2;
529 break;
530
Len Brown4be44fc2005-08-05 00:44:28 -0400531 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Len Brown4be44fc2005-08-05 00:44:28 -0400533 status =
534 acpi_hw_low_level_read(8, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300535 &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 break;
537
Len Brown4be44fc2005-08-05 00:44:28 -0400538 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Len Brown4be44fc2005-08-05 00:44:28 -0400540 status =
541 acpi_hw_low_level_read(32, &value1,
Bob Mooref3d2e782007-02-02 19:48:18 +0300542 &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 break;
544
Len Brown4be44fc2005-08-05 00:44:28 -0400545 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Bob Mooref3d2e782007-02-02 19:48:18 +0300547 status =
548 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 break;
550
551 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500552 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 status = AE_BAD_PARAMETER;
554 break;
555 }
556
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400557 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 *return_value = value1;
561 }
562
Len Brown4be44fc2005-08-05 00:44:28 -0400563 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/******************************************************************************
567 *
568 * FUNCTION: acpi_hw_register_write
569 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400570 * PARAMETERS: register_id - ACPI Register ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * Value - The value to write
572 *
573 * RETURN: Status
574 *
Bob Moore967440e2006-06-23 17:04:00 -0400575 * DESCRIPTION: Write to the specified ACPI register
576 *
577 * NOTE: In accordance with the ACPI specification, this function automatically
578 * preserves the value of the following bits, meaning that these bits cannot be
579 * changed via this interface:
580 *
581 * PM1_CONTROL[0] = SCI_EN
582 * PM1_CONTROL[9]
583 * PM1_STATUS[11]
584 *
585 * ACPI References:
586 * 1) Hardware Ignored Bits: When software writes to a register with ignored
587 * bit fields, it preserves the ignored bit fields
588 * 2) SCI_EN: OSPM always preserves this bit position
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 *
590 ******************************************************************************/
591
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400592acpi_status acpi_hw_register_write(u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Len Brown4be44fc2005-08-05 00:44:28 -0400594 acpi_status status;
Bob Moore967440e2006-06-23 17:04:00 -0400595 u32 read_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Bob Mooreb229cf92006-04-21 17:15:00 -0400597 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400600 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Bob Moore967440e2006-06-23 17:04:00 -0400602 /* Perform a read first to preserve certain bits (per ACPI spec) */
603
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400604 status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS,
Bob Moore967440e2006-06-23 17:04:00 -0400605 &read_value);
606 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400607 goto exit;
Bob Moore967440e2006-06-23 17:04:00 -0400608 }
609
610 /* Insert the bits to be preserved */
611
612 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
613 read_value);
614
615 /* Now we can write the data */
616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 status =
618 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300619 &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400620 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400621 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623
624 /* PM1B is optional */
625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 status =
627 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300628 &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 break;
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Len Brown4be44fc2005-08-05 00:44:28 -0400633 status =
634 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable);
635 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400636 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638
639 /* PM1B is optional */
640
Len Brown4be44fc2005-08-05 00:44:28 -0400641 status =
642 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 break;
644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Bob Moore967440e2006-06-23 17:04:00 -0400647 /*
648 * Perform a read first to preserve certain bits (per ACPI spec)
Bob Moore967440e2006-06-23 17:04:00 -0400649 */
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400650 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
Bob Moore967440e2006-06-23 17:04:00 -0400651 &read_value);
652 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400653 goto exit;
Bob Moore967440e2006-06-23 17:04:00 -0400654 }
655
656 /* Insert the bits to be preserved */
657
658 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
659 read_value);
660
661 /* Now we can write the data */
662
Len Brown4be44fc2005-08-05 00:44:28 -0400663 status =
664 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300665 &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400666 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400667 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 }
669
Len Brown4be44fc2005-08-05 00:44:28 -0400670 status =
671 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300672 &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 break;
674
Len Brown4be44fc2005-08-05 00:44:28 -0400675 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Len Brown4be44fc2005-08-05 00:44:28 -0400677 status =
678 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300679 &acpi_gbl_FADT.xpm1a_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 break;
681
Len Brown4be44fc2005-08-05 00:44:28 -0400682 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 status =
685 acpi_hw_low_level_write(16, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300686 &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 break;
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 status =
692 acpi_hw_low_level_write(8, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300693 &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 break;
695
Len Brown4be44fc2005-08-05 00:44:28 -0400696 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Len Brown4be44fc2005-08-05 00:44:28 -0400698 status =
699 acpi_hw_low_level_write(32, value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300700 &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 break;
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 /* SMI_CMD is currently always in IO space */
706
Bob Mooref3d2e782007-02-02 19:48:18 +0300707 status =
708 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 break;
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 default:
712 status = AE_BAD_PARAMETER;
713 break;
714 }
715
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400716 exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400717 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720/******************************************************************************
721 *
722 * FUNCTION: acpi_hw_low_level_read
723 *
724 * PARAMETERS: Width - 8, 16, or 32
725 * Value - Where the value is returned
726 * Reg - GAS register structure
727 *
728 * RETURN: Status
729 *
730 * DESCRIPTION: Read from either memory or IO space.
731 *
732 ******************************************************************************/
733
734acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400735acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Len Brown4be44fc2005-08-05 00:44:28 -0400737 u64 address;
738 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Bob Mooreb229cf92006-04-21 17:15:00 -0400740 ACPI_FUNCTION_NAME(hw_low_level_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 /*
743 * Must have a valid pointer to a GAS structure, and
744 * a non-zero address within. However, don't return an error
745 * because the PM1A/B code must not fail if B isn't present.
746 */
747 if (!reg) {
748 return (AE_OK);
749 }
750
Bob Moore967440e2006-06-23 17:04:00 -0400751 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Len Brown4be44fc2005-08-05 00:44:28 -0400753 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 if (!address) {
755 return (AE_OK);
756 }
757 *value = 0;
758
759 /*
760 * Two address spaces supported: Memory or IO.
761 * PCI_Config is not supported here because the GAS struct is insufficient
762 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300763 switch (reg->space_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
765
Len Brown4be44fc2005-08-05 00:44:28 -0400766 status = acpi_os_read_memory((acpi_physical_address) address,
767 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 break;
769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 case ACPI_ADR_SPACE_SYSTEM_IO:
771
Bob Moore59fa8502007-02-02 19:48:23 +0300772 status =
773 acpi_os_read_port((acpi_io_address) address, value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 break;
775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500777 ACPI_ERROR((AE_INFO,
Bob Mooref3d2e782007-02-02 19:48:18 +0300778 "Unsupported address space: %X", reg->space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return (AE_BAD_PARAMETER);
780 }
781
Len Brown4be44fc2005-08-05 00:44:28 -0400782 ACPI_DEBUG_PRINT((ACPI_DB_IO,
783 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
Bob Moore59fa8502007-02-02 19:48:23 +0300784 *value, width, ACPI_FORMAT_UINT64(address),
Bob Mooref3d2e782007-02-02 19:48:18 +0300785 acpi_ut_get_region_name(reg->space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 return (status);
788}
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790/******************************************************************************
791 *
792 * FUNCTION: acpi_hw_low_level_write
793 *
794 * PARAMETERS: Width - 8, 16, or 32
795 * Value - To be written
796 * Reg - GAS register structure
797 *
798 * RETURN: Status
799 *
800 * DESCRIPTION: Write to either memory or IO space.
801 *
802 ******************************************************************************/
803
804acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400805acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
Len Brown4be44fc2005-08-05 00:44:28 -0400807 u64 address;
808 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Bob Mooreb229cf92006-04-21 17:15:00 -0400810 ACPI_FUNCTION_NAME(hw_low_level_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 /*
813 * Must have a valid pointer to a GAS structure, and
814 * a non-zero address within. However, don't return an error
815 * because the PM1A/B code must not fail if B isn't present.
816 */
817 if (!reg) {
818 return (AE_OK);
819 }
820
Bob Moore967440e2006-06-23 17:04:00 -0400821 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Len Brown4be44fc2005-08-05 00:44:28 -0400823 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 if (!address) {
825 return (AE_OK);
826 }
827
828 /*
829 * Two address spaces supported: Memory or IO.
830 * PCI_Config is not supported here because the GAS struct is insufficient
831 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300832 switch (reg->space_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
834
Len Brown4be44fc2005-08-05 00:44:28 -0400835 status = acpi_os_write_memory((acpi_physical_address) address,
836 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 break;
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 case ACPI_ADR_SPACE_SYSTEM_IO:
840
Bob Moore59fa8502007-02-02 19:48:23 +0300841 status = acpi_os_write_port((acpi_io_address) address, value,
842 width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 break;
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500846 ACPI_ERROR((AE_INFO,
Bob Mooref3d2e782007-02-02 19:48:18 +0300847 "Unsupported address space: %X", reg->space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 return (AE_BAD_PARAMETER);
849 }
850
Len Brown4be44fc2005-08-05 00:44:28 -0400851 ACPI_DEBUG_PRINT((ACPI_DB_IO,
852 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
Bob Moore59fa8502007-02-02 19:48:23 +0300853 value, width, ACPI_FORMAT_UINT64(address),
Bob Mooref3d2e782007-02-02 19:48:18 +0300854 acpi_ut_get_region_name(reg->space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856 return (status);
857}