blob: d6d2ec6969f4ba3109c0a8d5e4445f0db263203e [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) {
Bob Mooreecfbbc72008-12-31 02:55:32 +080087 status = acpi_write(ACPI_BITMASK_ALL_FIXED_STATUS,
88 &acpi_gbl_FADT.xpm1b_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -040089 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 goto unlock_and_exit;
91 }
92 }
93
94 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
95
Bob Mooree97d6bf2008-12-30 09:45:17 +080096 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Len Brown4be44fc2005-08-05 00:44:28 -040098 unlock_and_exit:
Bob Moore4c90ece2006-06-08 16:29:00 -040099 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400100 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*******************************************************************************
104 *
105 * FUNCTION: acpi_get_sleep_type_data
106 *
107 * PARAMETERS: sleep_state - Numeric sleep state
108 * *sleep_type_a - Where SLP_TYPa is returned
109 * *sleep_type_b - Where SLP_TYPb is returned
110 *
111 * RETURN: Status - ACPI status
112 *
113 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
114 * state.
115 *
116 ******************************************************************************/
117
118acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400119acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Len Brown4be44fc2005-08-05 00:44:28 -0400121 acpi_status status = AE_OK;
Bob Moore41195322006-05-26 16:36:00 -0400122 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Bob Mooreb229cf92006-04-21 17:15:00 -0400124 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Robert Moore44f6c012005-04-18 22:49:35 -0400126 /* Validate parameters */
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
129 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Bob Moore41195322006-05-26 16:36:00 -0400132 /* Allocate the evaluation information block */
Robert Moore44f6c012005-04-18 22:49:35 -0400133
Bob Moore41195322006-05-26 16:36:00 -0400134 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
135 if (!info) {
136 return_ACPI_STATUS(AE_NO_MEMORY);
137 }
138
139 info->pathname =
Bob Mooredefba1d2005-12-16 17:05:00 -0500140 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
Robert Moore44f6c012005-04-18 22:49:35 -0400141
Bob Moore41195322006-05-26 16:36:00 -0400142 /* Evaluate the namespace object containing the values for this state */
143
144 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400145 if (ACPI_FAILURE(status)) {
146 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400147 "%s while evaluating SleepState [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400148 acpi_format_exception(status),
Bob Moore41195322006-05-26 16:36:00 -0400149 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Bob Moore41195322006-05-26 16:36:00 -0400151 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153
154 /* Must have a return object */
155
Bob Moore41195322006-05-26 16:36:00 -0400156 if (!info->return_object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500157 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
Bob Moore41195322006-05-26 16:36:00 -0400158 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 status = AE_NOT_EXIST;
160 }
161
162 /* It must be of type Package */
163
Bob Moore41195322006-05-26 16:36:00 -0400164 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500165 ACPI_ERROR((AE_INFO,
166 "Sleep State return object is not a Package"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 status = AE_AML_OPERAND_TYPE;
168 }
169
Robert Moore44f6c012005-04-18 22:49:35 -0400170 /*
Bob Moore967440e2006-06-23 17:04:00 -0400171 * The package must have at least two elements. NOTE (March 2005): This
Robert Moore44f6c012005-04-18 22:49:35 -0400172 * goes against the current ACPI spec which defines this object as a
Bob Moore967440e2006-06-23 17:04:00 -0400173 * package with one encoded DWORD element. However, existing practice
Robert Moore44f6c012005-04-18 22:49:35 -0400174 * by BIOS vendors seems to be to have 2 or more elements, at least
175 * one per sleep type (A/B).
176 */
Bob Moore41195322006-05-26 16:36:00 -0400177 else if (info->return_object->package.count < 2) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500178 ACPI_ERROR((AE_INFO,
179 "Sleep State return package does not have at least two elements"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 status = AE_AML_NO_OPERAND;
181 }
182
183 /* The first two elements must both be of type Integer */
184
Bob Moore41195322006-05-26 16:36:00 -0400185 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
Len Brown4be44fc2005-08-05 00:44:28 -0400186 != ACPI_TYPE_INTEGER) ||
Bob Moore41195322006-05-26 16:36:00 -0400187 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
Len Brown4be44fc2005-08-05 00:44:28 -0400188 != ACPI_TYPE_INTEGER)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500189 ACPI_ERROR((AE_INFO,
190 "Sleep State return package elements are not both Integers (%s, %s)",
Bob Moore41195322006-05-26 16:36:00 -0400191 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500192 package.elements[0]),
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[1])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 status = AE_AML_OPERAND_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400196 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400197 /* Valid _Sx_ package size, type, and value */
198
199 *sleep_type_a = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400200 (info->return_object->package.elements[0])->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400201 *sleep_type_b = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400202 (info->return_object->package.elements[1])->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 }
204
Len Brown4be44fc2005-08-05 00:44:28 -0400205 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500206 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400207 "While evaluating SleepState [%s], bad Sleep object %p type %s",
Bob Moore41195322006-05-26 16:36:00 -0400208 info->pathname, info->return_object,
209 acpi_ut_get_object_type_name(info->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500210 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
Bob Moore41195322006-05-26 16:36:00 -0400213 acpi_ut_remove_reference(info->return_object);
214
215 cleanup:
216 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400217 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Bob Moore83135242006-10-03 00:00:00 -0400220ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222/*******************************************************************************
223 *
224 * FUNCTION: acpi_hw_get_register_bit_mask
225 *
226 * PARAMETERS: register_id - Index of ACPI Register to access
227 *
Robert Moore44f6c012005-04-18 22:49:35 -0400228 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 *
Robert Moore44f6c012005-04-18 22:49:35 -0400230 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 *
232 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400233struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500235 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 if (register_id > ACPI_BITREG_MAX) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400238 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500239 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return (NULL);
241 }
242
243 return (&acpi_gbl_bit_register_info[register_id]);
244}
245
Bob Mooreecfbbc72008-12-31 02:55:32 +0800246ACPI_EXPORT_SYMBOL(acpi_get_register_unlocked)
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
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400262acpi_status acpi_get_register_unlocked(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
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400279 status = acpi_hw_register_read(bit_reg_info->parent_register,
Len Brown4be44fc2005-08-05 00:44:28 -0400280 &register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Len Brown4be44fc2005-08-05 00:44:28 -0400282 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 /* Normalize the value that was read */
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286 register_value =
287 ((register_value & bit_reg_info->access_bit_mask)
288 >> bit_reg_info->bit_position);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 *return_value = register_value;
291
Len Brown4be44fc2005-08-05 00:44:28 -0400292 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
293 register_value,
294 bit_reg_info->parent_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400300acpi_status acpi_get_register(u32 register_id, u32 * return_value)
301{
302 acpi_status status;
303 acpi_cpu_flags flags;
304 flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
305 status = acpi_get_register_unlocked(register_id, return_value);
306 acpi_os_release_lock(acpi_gbl_hardware_lock, flags);
307 return status;
308}
309
Bob Moore83135242006-10-03 00:00:00 -0400310ACPI_EXPORT_SYMBOL(acpi_get_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312/*******************************************************************************
313 *
314 * FUNCTION: acpi_set_register
315 *
316 * PARAMETERS: register_id - ID of ACPI bit_register to access
317 * Value - (only used on write) value to write to the
318 * Register, NOT pre-normalized to the bit pos
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 *
320 * RETURN: Status
321 *
322 * DESCRIPTION: ACPI Bit Register write function.
323 *
324 ******************************************************************************/
Bob Moored8c71b62007-02-02 19:48:21 +0300325acpi_status acpi_set_register(u32 register_id, u32 value)
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;
Bob Moore4c90ece2006-06-08 16:29:00 -0400330 acpi_cpu_flags lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Bob Mooreb229cf92006-04-21 17:15:00 -0400332 ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 /* Get the info structure corresponding to the requested ACPI Register */
335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 if (!bit_reg_info) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400338 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500339 register_id));
Len Brown4be44fc2005-08-05 00:44:28 -0400340 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
Bob Moore4c90ece2006-06-08 16:29:00 -0400343 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 /* Always do a register read first so we can insert the new bits */
346
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400347 status = acpi_hw_register_read(bit_reg_info->parent_register,
Len Brown4be44fc2005-08-05 00:44:28 -0400348 &register_value);
349 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 goto unlock_and_exit;
351 }
352
353 /*
354 * Decode the Register ID
355 * Register ID = [Register block ID] | [bit ID]
356 *
357 * Check bit ID to fine locate Register offset.
358 * Check Mask to determine Register offset, and then read-write.
359 */
360 switch (bit_reg_info->parent_register) {
361 case ACPI_REGISTER_PM1_STATUS:
362
363 /*
Bob Moore967440e2006-06-23 17:04:00 -0400364 * Status Registers are different from the rest. Clear by
365 * writing 1, and writing 0 has no effect. So, the only relevant
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 * information is the single bit we're interested in, all others should
367 * be written as 0 so they will be left unchanged.
368 */
Len Brown4be44fc2005-08-05 00:44:28 -0400369 value = ACPI_REGISTER_PREPARE_BITS(value,
370 bit_reg_info->bit_position,
371 bit_reg_info->
372 access_bit_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (value) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400374 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
Len Brown4be44fc2005-08-05 00:44:28 -0400375 (u16) value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 register_value = 0;
377 }
378 break;
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 case ACPI_REGISTER_PM1_ENABLE:
381
Len Brown4be44fc2005-08-05 00:44:28 -0400382 ACPI_REGISTER_INSERT_VALUE(register_value,
383 bit_reg_info->bit_position,
384 bit_reg_info->access_bit_mask,
385 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400387 status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE,
Len Brown4be44fc2005-08-05 00:44:28 -0400388 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 break;
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 case ACPI_REGISTER_PM1_CONTROL:
392
393 /*
394 * Write the PM1 Control register.
395 * Note that at this level, the fact that there are actually TWO
396 * registers (A and B - and B may not exist) is abstracted.
397 */
Len Brown4be44fc2005-08-05 00:44:28 -0400398 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
399 register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Len Brown4be44fc2005-08-05 00:44:28 -0400401 ACPI_REGISTER_INSERT_VALUE(register_value,
402 bit_reg_info->bit_position,
403 bit_reg_info->access_bit_mask,
404 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400406 status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL,
Len Brown4be44fc2005-08-05 00:44:28 -0400407 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 break;
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 case ACPI_REGISTER_PM2_CONTROL:
411
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400412 status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL,
Len Brown4be44fc2005-08-05 00:44:28 -0400413 &register_value);
414 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 goto unlock_and_exit;
416 }
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 ACPI_DEBUG_PRINT((ACPI_DB_IO,
419 "PM2 control: Read %X from %8.8X%8.8X\n",
420 register_value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300421 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
422 xpm2_control_block.
423 address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 ACPI_REGISTER_INSERT_VALUE(register_value,
426 bit_reg_info->bit_position,
427 bit_reg_info->access_bit_mask,
428 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 ACPI_DEBUG_PRINT((ACPI_DB_IO,
431 "About to write %4.4X to %8.8X%8.8X\n",
432 register_value,
Bob Mooref3d2e782007-02-02 19:48:18 +0300433 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
434 xpm2_control_block.
435 address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400437 status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL,
Len Brown4be44fc2005-08-05 00:44:28 -0400438 (u8) (register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 break;
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 default:
442 break;
443 }
444
Len Brown4be44fc2005-08-05 00:44:28 -0400445 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Bob Moore4c90ece2006-06-08 16:29:00 -0400447 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 /* Normalize the value that was read */
450
Len Brown4be44fc2005-08-05 00:44:28 -0400451 ACPI_DEBUG_EXEC(register_value =
452 ((register_value & bit_reg_info->access_bit_mask) >>
453 bit_reg_info->bit_position));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Len Brown4be44fc2005-08-05 00:44:28 -0400455 ACPI_DEBUG_PRINT((ACPI_DB_IO,
456 "Set bits: %8.8X actual %8.8X register %X\n", value,
457 register_value, bit_reg_info->parent_register));
458 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Bob Moore83135242006-10-03 00:00:00 -0400461ACPI_EXPORT_SYMBOL(acpi_set_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463/******************************************************************************
464 *
465 * FUNCTION: acpi_hw_register_read
466 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400467 * PARAMETERS: register_id - ACPI Register ID
Robert Moore44f6c012005-04-18 22:49:35 -0400468 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 *
470 * RETURN: Status and the value read.
471 *
Bob Moore967440e2006-06-23 17:04:00 -0400472 * DESCRIPTION: Read from the specified ACPI register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 *
474 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475acpi_status
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400476acpi_hw_register_read(u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Len Brown4be44fc2005-08-05 00:44:28 -0400478 u32 value1 = 0;
479 u32 value2 = 0;
480 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Bob Mooreb229cf92006-04-21 17:15:00 -0400482 ACPI_FUNCTION_TRACE(hw_register_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400485 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Bob Mooreecfbbc72008-12-31 02:55:32 +0800487 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400488 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400489 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 }
491
492 /* PM1B is optional */
493
Bob Mooreecfbbc72008-12-31 02:55:32 +0800494 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 value1 |= value2;
496 break;
497
Len Brown4be44fc2005-08-05 00:44:28 -0400498 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Bob Mooreecfbbc72008-12-31 02:55:32 +0800500 status = acpi_read(&value1, &acpi_gbl_xpm1a_enable);
Len Brown4be44fc2005-08-05 00:44:28 -0400501 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400502 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504
505 /* PM1B is optional */
506
Bob Mooreecfbbc72008-12-31 02:55:32 +0800507 status = acpi_read(&value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 value1 |= value2;
509 break;
510
Len Brown4be44fc2005-08-05 00:44:28 -0400511 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Bob Mooreecfbbc72008-12-31 02:55:32 +0800513 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400514 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400515 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517
Bob Mooreecfbbc72008-12-31 02:55:32 +0800518 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 value1 |= value2;
520 break;
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Bob Mooreecfbbc72008-12-31 02:55:32 +0800524 status = acpi_read(&value1, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 break;
526
Len Brown4be44fc2005-08-05 00:44:28 -0400527 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Bob Mooreecfbbc72008-12-31 02:55:32 +0800529 status = acpi_read(&value1, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531
Len Brown4be44fc2005-08-05 00:44:28 -0400532 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Bob Mooref3d2e782007-02-02 19:48:18 +0300534 status =
535 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 break;
537
538 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500539 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 status = AE_BAD_PARAMETER;
541 break;
542 }
543
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400544 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 *return_value = value1;
548 }
549
Len Brown4be44fc2005-08-05 00:44:28 -0400550 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553/******************************************************************************
554 *
555 * FUNCTION: acpi_hw_register_write
556 *
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400557 * PARAMETERS: register_id - ACPI Register ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 * Value - The value to write
559 *
560 * RETURN: Status
561 *
Bob Moore967440e2006-06-23 17:04:00 -0400562 * DESCRIPTION: Write to the specified ACPI register
563 *
564 * NOTE: In accordance with the ACPI specification, this function automatically
565 * preserves the value of the following bits, meaning that these bits cannot be
566 * changed via this interface:
567 *
568 * PM1_CONTROL[0] = SCI_EN
569 * PM1_CONTROL[9]
570 * PM1_STATUS[11]
571 *
572 * ACPI References:
573 * 1) Hardware Ignored Bits: When software writes to a register with ignored
574 * bit fields, it preserves the ignored bit fields
575 * 2) SCI_EN: OSPM always preserves this bit position
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 *
577 ******************************************************************************/
578
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400579acpi_status acpi_hw_register_write(u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Len Brown4be44fc2005-08-05 00:44:28 -0400581 acpi_status status;
Bob Moore967440e2006-06-23 17:04:00 -0400582 u32 read_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Bob Mooreb229cf92006-04-21 17:15:00 -0400584 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400587 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Bob Moore967440e2006-06-23 17:04:00 -0400589 /* Perform a read first to preserve certain bits (per ACPI spec) */
590
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400591 status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS,
Bob Moore967440e2006-06-23 17:04:00 -0400592 &read_value);
593 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400594 goto exit;
Bob Moore967440e2006-06-23 17:04:00 -0400595 }
596
597 /* Insert the bits to be preserved */
598
599 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
600 read_value);
601
602 /* Now we can write the data */
603
Bob Mooreecfbbc72008-12-31 02:55:32 +0800604 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_event_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400605 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400606 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608
609 /* PM1B is optional */
610
Bob Mooreecfbbc72008-12-31 02:55:32 +0800611 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_event_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 break;
613
Len Brown4be44fc2005-08-05 00:44:28 -0400614 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Bob Mooreecfbbc72008-12-31 02:55:32 +0800616 status = acpi_write(value, &acpi_gbl_xpm1a_enable);
Len Brown4be44fc2005-08-05 00:44:28 -0400617 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400618 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620
621 /* PM1B is optional */
622
Bob Mooreecfbbc72008-12-31 02:55:32 +0800623 status = acpi_write(value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 break;
625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Bob Moore967440e2006-06-23 17:04:00 -0400628 /*
629 * Perform a read first to preserve certain bits (per ACPI spec)
Bob Moore967440e2006-06-23 17:04:00 -0400630 */
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400631 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
Bob Moore967440e2006-06-23 17:04:00 -0400632 &read_value);
633 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400634 goto exit;
Bob Moore967440e2006-06-23 17:04:00 -0400635 }
636
637 /* Insert the bits to be preserved */
638
639 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
640 read_value);
641
642 /* Now we can write the data */
643
Bob Mooreecfbbc72008-12-31 02:55:32 +0800644 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400645 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400646 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
Bob Mooreecfbbc72008-12-31 02:55:32 +0800649 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 break;
651
Len Brown4be44fc2005-08-05 00:44:28 -0400652 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Bob Mooreecfbbc72008-12-31 02:55:32 +0800654 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 break;
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Bob Mooreecfbbc72008-12-31 02:55:32 +0800659 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 break;
661
Len Brown4be44fc2005-08-05 00:44:28 -0400662 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Bob Mooreecfbbc72008-12-31 02:55:32 +0800664 status = acpi_write(value, &acpi_gbl_FADT.xpm2_control_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 break;
666
Len Brown4be44fc2005-08-05 00:44:28 -0400667 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Bob Mooreecfbbc72008-12-31 02:55:32 +0800669 status = acpi_write(value, &acpi_gbl_FADT.xpm_timer_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 break;
671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 /* SMI_CMD is currently always in IO space */
675
Bob Mooref3d2e782007-02-02 19:48:18 +0300676 status =
677 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 break;
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 default:
681 status = AE_BAD_PARAMETER;
682 break;
683 }
684
Alexey Starikovskiyd30dc9ab2007-09-30 22:39:36 +0400685 exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400686 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689/******************************************************************************
690 *
Bob Mooreecfbbc72008-12-31 02:55:32 +0800691 * FUNCTION: acpi_read
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 *
Bob Mooreecfbbc72008-12-31 02:55:32 +0800693 * PARAMETERS: Value - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 * Reg - GAS register structure
695 *
696 * RETURN: Status
697 *
698 * DESCRIPTION: Read from either memory or IO space.
699 *
700 ******************************************************************************/
701
Bob Mooreecfbbc72008-12-31 02:55:32 +0800702acpi_status acpi_read(u32 *value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
Bob Mooreecfbbc72008-12-31 02:55:32 +0800704 u32 width;
Len Brown4be44fc2005-08-05 00:44:28 -0400705 u64 address;
706 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Bob Mooreecfbbc72008-12-31 02:55:32 +0800708 ACPI_FUNCTION_NAME(acpi_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 /*
711 * Must have a valid pointer to a GAS structure, and
712 * a non-zero address within. However, don't return an error
713 * because the PM1A/B code must not fail if B isn't present.
714 */
715 if (!reg) {
716 return (AE_OK);
717 }
718
Bob Moore967440e2006-06-23 17:04:00 -0400719 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Len Brown4be44fc2005-08-05 00:44:28 -0400721 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (!address) {
723 return (AE_OK);
724 }
Bob Mooreecfbbc72008-12-31 02:55:32 +0800725
726 /* Supported widths are 8/16/32 */
727
728 width = reg->bit_width;
729 if ((width != 8) && (width != 16) && (width != 32)) {
730 return (AE_SUPPORT);
731 }
732
733 /* Initialize entire 32-bit return value to zero */
734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 *value = 0;
736
737 /*
738 * Two address spaces supported: Memory or IO.
739 * PCI_Config is not supported here because the GAS struct is insufficient
740 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300741 switch (reg->space_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
743
Len Brown4be44fc2005-08-05 00:44:28 -0400744 status = acpi_os_read_memory((acpi_physical_address) address,
745 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 break;
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 case ACPI_ADR_SPACE_SYSTEM_IO:
749
Bob Moore59fa8502007-02-02 19:48:23 +0300750 status =
751 acpi_os_read_port((acpi_io_address) address, value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 break;
753
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500755 ACPI_ERROR((AE_INFO,
Bob Mooref3d2e782007-02-02 19:48:18 +0300756 "Unsupported address space: %X", reg->space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 return (AE_BAD_PARAMETER);
758 }
759
Len Brown4be44fc2005-08-05 00:44:28 -0400760 ACPI_DEBUG_PRINT((ACPI_DB_IO,
761 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
Bob Moore59fa8502007-02-02 19:48:23 +0300762 *value, width, ACPI_FORMAT_UINT64(address),
Bob Mooref3d2e782007-02-02 19:48:18 +0300763 acpi_ut_get_region_name(reg->space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 return (status);
766}
767
Bob Mooreecfbbc72008-12-31 02:55:32 +0800768ACPI_EXPORT_SYMBOL(acpi_read)
769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770/******************************************************************************
771 *
Bob Mooreecfbbc72008-12-31 02:55:32 +0800772 * FUNCTION: acpi_write
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 *
Bob Mooreecfbbc72008-12-31 02:55:32 +0800774 * PARAMETERS: Value - To be written
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 * Reg - GAS register structure
776 *
777 * RETURN: Status
778 *
779 * DESCRIPTION: Write to either memory or IO space.
780 *
781 ******************************************************************************/
782
783acpi_status
Bob Mooreecfbbc72008-12-31 02:55:32 +0800784acpi_write(u32 value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
Bob Mooreecfbbc72008-12-31 02:55:32 +0800786 u32 width;
Len Brown4be44fc2005-08-05 00:44:28 -0400787 u64 address;
788 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Bob Mooreecfbbc72008-12-31 02:55:32 +0800790 ACPI_FUNCTION_NAME(acpi_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 /*
793 * Must have a valid pointer to a GAS structure, and
794 * a non-zero address within. However, don't return an error
795 * because the PM1A/B code must not fail if B isn't present.
796 */
797 if (!reg) {
798 return (AE_OK);
799 }
800
Bob Moore967440e2006-06-23 17:04:00 -0400801 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Len Brown4be44fc2005-08-05 00:44:28 -0400803 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 if (!address) {
805 return (AE_OK);
806 }
807
Bob Mooreecfbbc72008-12-31 02:55:32 +0800808 /* Supported widths are 8/16/32 */
809
810 width = reg->bit_width;
811 if ((width != 8) && (width != 16) && (width != 32)) {
812 return (AE_SUPPORT);
813 }
814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 /*
816 * Two address spaces supported: Memory or IO.
817 * PCI_Config is not supported here because the GAS struct is insufficient
818 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300819 switch (reg->space_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
821
Len Brown4be44fc2005-08-05 00:44:28 -0400822 status = acpi_os_write_memory((acpi_physical_address) address,
823 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 break;
825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 case ACPI_ADR_SPACE_SYSTEM_IO:
827
Bob Moore59fa8502007-02-02 19:48:23 +0300828 status = acpi_os_write_port((acpi_io_address) address, value,
829 width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 break;
831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500833 ACPI_ERROR((AE_INFO,
Bob Mooref3d2e782007-02-02 19:48:18 +0300834 "Unsupported address space: %X", reg->space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 return (AE_BAD_PARAMETER);
836 }
837
Len Brown4be44fc2005-08-05 00:44:28 -0400838 ACPI_DEBUG_PRINT((ACPI_DB_IO,
839 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
Bob Moore59fa8502007-02-02 19:48:23 +0300840 value, width, ACPI_FORMAT_UINT64(address),
Bob Mooref3d2e782007-02-02 19:48:18 +0300841 acpi_ut_get_region_name(reg->space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 return (status);
844}
Bob Mooreecfbbc72008-12-31 02:55:32 +0800845
846ACPI_EXPORT_SYMBOL(acpi_write)