blob: 5a3aa8dd8cb7b60cf383569b7bdb17a72d8c1f3f [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 *
57 * PARAMETERS: Flags - Lock the hardware or not
58 *
59 * RETURN: none
60 *
61 * DESCRIPTION: Clears all fixed and general purpose status bits
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
63 *
64 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040065acpi_status acpi_hw_clear_acpi_status(u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Len Brown4be44fc2005-08-05 00:44:28 -040067 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Bob Mooreb229cf92006-04-21 17:15:00 -040069 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Len Brown4be44fc2005-08-05 00:44:28 -040071 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
72 ACPI_BITMASK_ALL_FIXED_STATUS,
73 (u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -040076 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
77 if (ACPI_FAILURE(status)) {
78 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
80 }
81
Len Brown4be44fc2005-08-05 00:44:28 -040082 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
83 ACPI_REGISTER_PM1_STATUS,
84 ACPI_BITMASK_ALL_FIXED_STATUS);
85 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 goto unlock_and_exit;
87 }
88
89 /* Clear the fixed events */
90
91 if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
Len Brown4be44fc2005-08-05 00:44:28 -040092 status =
93 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
94 &acpi_gbl_FADT->xpm1b_evt_blk);
95 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 goto unlock_and_exit;
97 }
98 }
99
100 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
101
Len Brown4be44fc2005-08-05 00:44:28 -0400102 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Len Brown4be44fc2005-08-05 00:44:28 -0400104 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400106 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
Len Brown4be44fc2005-08-05 00:44:28 -0400108 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/*******************************************************************************
112 *
113 * FUNCTION: acpi_get_sleep_type_data
114 *
115 * PARAMETERS: sleep_state - Numeric sleep state
116 * *sleep_type_a - Where SLP_TYPa is returned
117 * *sleep_type_b - Where SLP_TYPb is returned
118 *
119 * RETURN: Status - ACPI status
120 *
121 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
122 * state.
123 *
124 ******************************************************************************/
125
126acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400127acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Len Brown4be44fc2005-08-05 00:44:28 -0400129 acpi_status status = AE_OK;
Bob Moore41195322006-05-26 16:36:00 -0400130 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Bob Mooreb229cf92006-04-21 17:15:00 -0400132 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Robert Moore44f6c012005-04-18 22:49:35 -0400134 /* Validate parameters */
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
137 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139
Bob Moore41195322006-05-26 16:36:00 -0400140 /* Allocate the evaluation information block */
Robert Moore44f6c012005-04-18 22:49:35 -0400141
Bob Moore41195322006-05-26 16:36:00 -0400142 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
143 if (!info) {
144 return_ACPI_STATUS(AE_NO_MEMORY);
145 }
146
147 info->pathname =
Bob Mooredefba1d2005-12-16 17:05:00 -0500148 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
Robert Moore44f6c012005-04-18 22:49:35 -0400149
Bob Moore41195322006-05-26 16:36:00 -0400150 /* Evaluate the namespace object containing the values for this state */
151
152 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400153 if (ACPI_FAILURE(status)) {
154 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400155 "%s while evaluating SleepState [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400156 acpi_format_exception(status),
Bob Moore41195322006-05-26 16:36:00 -0400157 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Bob Moore41195322006-05-26 16:36:00 -0400159 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
161
162 /* Must have a return object */
163
Bob Moore41195322006-05-26 16:36:00 -0400164 if (!info->return_object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500165 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
Bob Moore41195322006-05-26 16:36:00 -0400166 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 status = AE_NOT_EXIST;
168 }
169
170 /* It must be of type Package */
171
Bob Moore41195322006-05-26 16:36:00 -0400172 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500173 ACPI_ERROR((AE_INFO,
174 "Sleep State return object is not a Package"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 status = AE_AML_OPERAND_TYPE;
176 }
177
Robert Moore44f6c012005-04-18 22:49:35 -0400178 /*
179 * The package must have at least two elements. NOTE (March 2005): This
180 * goes against the current ACPI spec which defines this object as a
181 * package with one encoded DWORD element. However, existing practice
182 * by BIOS vendors seems to be to have 2 or more elements, at least
183 * one per sleep type (A/B).
184 */
Bob Moore41195322006-05-26 16:36:00 -0400185 else if (info->return_object->package.count < 2) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500186 ACPI_ERROR((AE_INFO,
187 "Sleep State return package does not have at least two elements"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 status = AE_AML_NO_OPERAND;
189 }
190
191 /* The first two elements must both be of type Integer */
192
Bob Moore41195322006-05-26 16:36:00 -0400193 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
Len Brown4be44fc2005-08-05 00:44:28 -0400194 != ACPI_TYPE_INTEGER) ||
Bob Moore41195322006-05-26 16:36:00 -0400195 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
Len Brown4be44fc2005-08-05 00:44:28 -0400196 != ACPI_TYPE_INTEGER)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500197 ACPI_ERROR((AE_INFO,
198 "Sleep State return package elements are not both Integers (%s, %s)",
Bob Moore41195322006-05-26 16:36:00 -0400199 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500200 package.elements[0]),
Bob Moore41195322006-05-26 16:36:00 -0400201 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500202 package.elements[1])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 status = AE_AML_OPERAND_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400204 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400205 /* Valid _Sx_ package size, type, and value */
206
207 *sleep_type_a = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400208 (info->return_object->package.elements[0])->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400209 *sleep_type_b = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400210 (info->return_object->package.elements[1])->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500214 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400215 "While evaluating SleepState [%s], bad Sleep object %p type %s",
Bob Moore41195322006-05-26 16:36:00 -0400216 info->pathname, info->return_object,
217 acpi_ut_get_object_type_name(info->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500218 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
220
Bob Moore41195322006-05-26 16:36:00 -0400221 acpi_ut_remove_reference(info->return_object);
222
223 cleanup:
224 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400225 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Bob Moore83135242006-10-03 00:00:00 -0400228ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230/*******************************************************************************
231 *
232 * FUNCTION: acpi_hw_get_register_bit_mask
233 *
234 * PARAMETERS: register_id - Index of ACPI Register to access
235 *
Robert Moore44f6c012005-04-18 22:49:35 -0400236 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 *
Robert Moore44f6c012005-04-18 22:49:35 -0400238 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 *
240 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400241struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500243 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 if (register_id > ACPI_BITREG_MAX) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400246 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500247 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return (NULL);
249 }
250
251 return (&acpi_gbl_bit_register_info[register_id]);
252}
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254/*******************************************************************************
255 *
256 * FUNCTION: acpi_get_register
257 *
258 * PARAMETERS: register_id - ID of ACPI bit_register to access
259 * return_value - Value that was read from the register
260 * Flags - Lock the hardware or not
261 *
262 * RETURN: Status and the value read from specified Register. Value
263 * returned is normalized to bit0 (is shifted all the way right)
264 *
265 * DESCRIPTION: ACPI bit_register read function.
266 *
267 ******************************************************************************/
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Len Brown4be44fc2005-08-05 00:44:28 -0400271 u32 register_value = 0;
272 struct acpi_bit_register_info *bit_reg_info;
273 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Bob Mooreb229cf92006-04-21 17:15:00 -0400275 ACPI_FUNCTION_TRACE(acpi_get_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 /* Get the info structure corresponding to the requested ACPI Register */
278
Len Brown4be44fc2005-08-05 00:44:28 -0400279 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400281 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 }
283
284 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400285 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
286 if (ACPI_FAILURE(status)) {
287 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289 }
290
291 /* Read from the register */
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
294 bit_reg_info->parent_register,
295 &register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400298 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 }
300
Len Brown4be44fc2005-08-05 00:44:28 -0400301 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 /* Normalize the value that was read */
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 register_value =
306 ((register_value & bit_reg_info->access_bit_mask)
307 >> bit_reg_info->bit_position);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 *return_value = register_value;
310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
312 register_value,
313 bit_reg_info->parent_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315
Len Brown4be44fc2005-08-05 00:44:28 -0400316 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Bob Moore83135242006-10-03 00:00:00 -0400319ACPI_EXPORT_SYMBOL(acpi_get_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321/*******************************************************************************
322 *
323 * FUNCTION: acpi_set_register
324 *
325 * PARAMETERS: register_id - ID of ACPI bit_register to access
326 * Value - (only used on write) value to write to the
327 * Register, NOT pre-normalized to the bit pos
328 * Flags - Lock the hardware or not
329 *
330 * RETURN: Status
331 *
332 * DESCRIPTION: ACPI Bit Register write function.
333 *
334 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400335acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
Len Brown4be44fc2005-08-05 00:44:28 -0400337 u32 register_value = 0;
338 struct acpi_bit_register_info *bit_reg_info;
339 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Bob Mooreb229cf92006-04-21 17:15:00 -0400341 ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /* Get the info structure corresponding to the requested ACPI Register */
344
Len Brown4be44fc2005-08-05 00:44:28 -0400345 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 if (!bit_reg_info) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400347 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500348 register_id));
Len Brown4be44fc2005-08-05 00:44:28 -0400349 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
352 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400353 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
354 if (ACPI_FAILURE(status)) {
355 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357 }
358
359 /* Always do a register read first so we can insert the new bits */
360
Len Brown4be44fc2005-08-05 00:44:28 -0400361 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
362 bit_reg_info->parent_register,
363 &register_value);
364 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 goto unlock_and_exit;
366 }
367
368 /*
369 * Decode the Register ID
370 * Register ID = [Register block ID] | [bit ID]
371 *
372 * Check bit ID to fine locate Register offset.
373 * Check Mask to determine Register offset, and then read-write.
374 */
375 switch (bit_reg_info->parent_register) {
376 case ACPI_REGISTER_PM1_STATUS:
377
378 /*
379 * Status Registers are different from the rest. Clear by
380 * writing 1, and writing 0 has no effect. So, the only relevant
381 * information is the single bit we're interested in, all others should
382 * be written as 0 so they will be left unchanged.
383 */
Len Brown4be44fc2005-08-05 00:44:28 -0400384 value = ACPI_REGISTER_PREPARE_BITS(value,
385 bit_reg_info->bit_position,
386 bit_reg_info->
387 access_bit_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 if (value) {
Len Brown4be44fc2005-08-05 00:44:28 -0400389 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
390 ACPI_REGISTER_PM1_STATUS,
391 (u16) value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 register_value = 0;
393 }
394 break;
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 case ACPI_REGISTER_PM1_ENABLE:
397
Len Brown4be44fc2005-08-05 00:44:28 -0400398 ACPI_REGISTER_INSERT_VALUE(register_value,
399 bit_reg_info->bit_position,
400 bit_reg_info->access_bit_mask,
401 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
404 ACPI_REGISTER_PM1_ENABLE,
405 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 break;
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 case ACPI_REGISTER_PM1_CONTROL:
409
410 /*
411 * Write the PM1 Control register.
412 * Note that at this level, the fact that there are actually TWO
413 * registers (A and B - and B may not exist) is abstracted.
414 */
Len Brown4be44fc2005-08-05 00:44:28 -0400415 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
416 register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 ACPI_REGISTER_INSERT_VALUE(register_value,
419 bit_reg_info->bit_position,
420 bit_reg_info->access_bit_mask,
421 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Len Brown4be44fc2005-08-05 00:44:28 -0400423 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
424 ACPI_REGISTER_PM1_CONTROL,
425 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 break;
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 case ACPI_REGISTER_PM2_CONTROL:
429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
431 ACPI_REGISTER_PM2_CONTROL,
432 &register_value);
433 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 goto unlock_and_exit;
435 }
436
Len Brown4be44fc2005-08-05 00:44:28 -0400437 ACPI_DEBUG_PRINT((ACPI_DB_IO,
438 "PM2 control: Read %X from %8.8X%8.8X\n",
439 register_value,
440 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
441 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Len Brown4be44fc2005-08-05 00:44:28 -0400443 ACPI_REGISTER_INSERT_VALUE(register_value,
444 bit_reg_info->bit_position,
445 bit_reg_info->access_bit_mask,
446 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 ACPI_DEBUG_PRINT((ACPI_DB_IO,
449 "About to write %4.4X to %8.8X%8.8X\n",
450 register_value,
451 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
452 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
455 ACPI_REGISTER_PM2_CONTROL,
456 (u8) (register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 break;
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 default:
460 break;
461 }
462
Len Brown4be44fc2005-08-05 00:44:28 -0400463 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 if (flags & ACPI_MTX_LOCK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400466 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
469 /* Normalize the value that was read */
470
Len Brown4be44fc2005-08-05 00:44:28 -0400471 ACPI_DEBUG_EXEC(register_value =
472 ((register_value & bit_reg_info->access_bit_mask) >>
473 bit_reg_info->bit_position));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 ACPI_DEBUG_PRINT((ACPI_DB_IO,
476 "Set bits: %8.8X actual %8.8X register %X\n", value,
477 register_value, bit_reg_info->parent_register));
478 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Bob Moore83135242006-10-03 00:00:00 -0400481ACPI_EXPORT_SYMBOL(acpi_set_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483/******************************************************************************
484 *
485 * FUNCTION: acpi_hw_register_read
486 *
487 * PARAMETERS: use_lock - Mutex hw access
488 * register_id - register_iD + Offset
Robert Moore44f6c012005-04-18 22:49:35 -0400489 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 *
491 * RETURN: Status and the value read.
492 *
493 * DESCRIPTION: Acpi register read function. Registers are read at the
494 * given offset.
495 *
496 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400498acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Len Brown4be44fc2005-08-05 00:44:28 -0400500 u32 value1 = 0;
501 u32 value2 = 0;
502 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Bob Mooreb229cf92006-04-21 17:15:00 -0400504 ACPI_FUNCTION_TRACE(hw_register_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400507 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
508 if (ACPI_FAILURE(status)) {
509 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511 }
512
513 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400514 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 status =
517 acpi_hw_low_level_read(16, &value1,
518 &acpi_gbl_FADT->xpm1a_evt_blk);
519 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 goto unlock_and_exit;
521 }
522
523 /* PM1B is optional */
524
Len Brown4be44fc2005-08-05 00:44:28 -0400525 status =
526 acpi_hw_low_level_read(16, &value2,
527 &acpi_gbl_FADT->xpm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 value1 |= value2;
529 break;
530
Len Brown4be44fc2005-08-05 00:44:28 -0400531 case ACPI_REGISTER_PM1_ENABLE: /* 16-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(16, &value1, &acpi_gbl_xpm1a_enable);
535 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 goto unlock_and_exit;
537 }
538
539 /* PM1B is optional */
540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 status =
542 acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 value1 |= value2;
544 break;
545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Len Brown4be44fc2005-08-05 00:44:28 -0400548 status =
549 acpi_hw_low_level_read(16, &value1,
550 &acpi_gbl_FADT->xpm1a_cnt_blk);
551 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 goto unlock_and_exit;
553 }
554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 status =
556 acpi_hw_low_level_read(16, &value2,
557 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 value1 |= value2;
559 break;
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Len Brown4be44fc2005-08-05 00:44:28 -0400563 status =
564 acpi_hw_low_level_read(8, &value1,
565 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 break;
567
Len Brown4be44fc2005-08-05 00:44:28 -0400568 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Len Brown4be44fc2005-08-05 00:44:28 -0400570 status =
571 acpi_hw_low_level_read(32, &value1,
572 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 break;
574
Len Brown4be44fc2005-08-05 00:44:28 -0400575 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Len Brown4be44fc2005-08-05 00:44:28 -0400577 status = acpi_os_read_port(acpi_gbl_FADT->smi_cmd, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 break;
579
580 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500581 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 status = AE_BAD_PARAMETER;
583 break;
584 }
585
Len Brown4be44fc2005-08-05 00:44:28 -0400586 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400588 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
590
Len Brown4be44fc2005-08-05 00:44:28 -0400591 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 *return_value = value1;
593 }
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598/******************************************************************************
599 *
600 * FUNCTION: acpi_hw_register_write
601 *
602 * PARAMETERS: use_lock - Mutex hw access
603 * register_id - register_iD + Offset
604 * Value - The value to write
605 *
606 * RETURN: Status
607 *
608 * DESCRIPTION: Acpi register Write function. Registers are written at the
609 * given offset.
610 *
611 ******************************************************************************/
612
Len Brown4be44fc2005-08-05 00:44:28 -0400613acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Len Brown4be44fc2005-08-05 00:44:28 -0400615 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Bob Mooreb229cf92006-04-21 17:15:00 -0400617 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400620 status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE);
621 if (ACPI_FAILURE(status)) {
622 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
624 }
625
626 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400627 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Len Brown4be44fc2005-08-05 00:44:28 -0400629 status =
630 acpi_hw_low_level_write(16, value,
631 &acpi_gbl_FADT->xpm1a_evt_blk);
632 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 goto unlock_and_exit;
634 }
635
636 /* PM1B is optional */
637
Len Brown4be44fc2005-08-05 00:44:28 -0400638 status =
639 acpi_hw_low_level_write(16, value,
640 &acpi_gbl_FADT->xpm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 break;
642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 status =
646 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable);
647 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 goto unlock_and_exit;
649 }
650
651 /* PM1B is optional */
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 status =
654 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 break;
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Len Brown4be44fc2005-08-05 00:44:28 -0400659 status =
660 acpi_hw_low_level_write(16, value,
661 &acpi_gbl_FADT->xpm1a_cnt_blk);
662 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 goto unlock_and_exit;
664 }
665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 status =
667 acpi_hw_low_level_write(16, value,
668 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 break;
670
Len Brown4be44fc2005-08-05 00:44:28 -0400671 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Len Brown4be44fc2005-08-05 00:44:28 -0400673 status =
674 acpi_hw_low_level_write(16, value,
675 &acpi_gbl_FADT->xpm1a_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 break;
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 status =
681 acpi_hw_low_level_write(16, value,
682 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 break;
684
Len Brown4be44fc2005-08-05 00:44:28 -0400685 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Len Brown4be44fc2005-08-05 00:44:28 -0400687 status =
688 acpi_hw_low_level_write(8, value,
689 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
691
Len Brown4be44fc2005-08-05 00:44:28 -0400692 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Len Brown4be44fc2005-08-05 00:44:28 -0400694 status =
695 acpi_hw_low_level_write(32, value,
696 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 break;
698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 /* SMI_CMD is currently always in IO space */
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 break;
705
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 default:
707 status = AE_BAD_PARAMETER;
708 break;
709 }
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 if (ACPI_MTX_LOCK == use_lock) {
Len Brown4be44fc2005-08-05 00:44:28 -0400713 (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719/******************************************************************************
720 *
721 * FUNCTION: acpi_hw_low_level_read
722 *
723 * PARAMETERS: Width - 8, 16, or 32
724 * Value - Where the value is returned
725 * Reg - GAS register structure
726 *
727 * RETURN: Status
728 *
729 * DESCRIPTION: Read from either memory or IO space.
730 *
731 ******************************************************************************/
732
733acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400734acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Len Brown4be44fc2005-08-05 00:44:28 -0400736 u64 address;
737 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Bob Mooreb229cf92006-04-21 17:15:00 -0400739 ACPI_FUNCTION_NAME(hw_low_level_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 /*
742 * Must have a valid pointer to a GAS structure, and
743 * a non-zero address within. However, don't return an error
744 * because the PM1A/B code must not fail if B isn't present.
745 */
746 if (!reg) {
747 return (AE_OK);
748 }
749
750 /* Get a local copy of the address. Handles possible alignment issues */
751
Len Brown4be44fc2005-08-05 00:44:28 -0400752 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 if (!address) {
754 return (AE_OK);
755 }
756 *value = 0;
757
758 /*
759 * Two address spaces supported: Memory or IO.
760 * PCI_Config is not supported here because the GAS struct is insufficient
761 */
762 switch (reg->address_space_id) {
763 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
764
Len Brown4be44fc2005-08-05 00:44:28 -0400765 status = acpi_os_read_memory((acpi_physical_address) address,
766 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 break;
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 case ACPI_ADR_SPACE_SYSTEM_IO:
770
Len Brown4be44fc2005-08-05 00:44:28 -0400771 status = acpi_os_read_port((acpi_io_address) address,
772 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 break;
774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500776 ACPI_ERROR((AE_INFO,
777 "Unsupported address space: %X",
778 reg->address_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",
784 *value, width,
785 ACPI_FORMAT_UINT64(address),
786 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 return (status);
789}
790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791/******************************************************************************
792 *
793 * FUNCTION: acpi_hw_low_level_write
794 *
795 * PARAMETERS: Width - 8, 16, or 32
796 * Value - To be written
797 * Reg - GAS register structure
798 *
799 * RETURN: Status
800 *
801 * DESCRIPTION: Write to either memory or IO space.
802 *
803 ******************************************************************************/
804
805acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400806acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
Len Brown4be44fc2005-08-05 00:44:28 -0400808 u64 address;
809 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Bob Mooreb229cf92006-04-21 17:15:00 -0400811 ACPI_FUNCTION_NAME(hw_low_level_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 /*
814 * Must have a valid pointer to a GAS structure, and
815 * a non-zero address within. However, don't return an error
816 * because the PM1A/B code must not fail if B isn't present.
817 */
818 if (!reg) {
819 return (AE_OK);
820 }
821
822 /* Get a local copy of the address. Handles possible alignment issues */
823
Len Brown4be44fc2005-08-05 00:44:28 -0400824 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 if (!address) {
826 return (AE_OK);
827 }
828
829 /*
830 * Two address spaces supported: Memory or IO.
831 * PCI_Config is not supported here because the GAS struct is insufficient
832 */
833 switch (reg->address_space_id) {
834 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
835
Len Brown4be44fc2005-08-05 00:44:28 -0400836 status = acpi_os_write_memory((acpi_physical_address) address,
837 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 break;
839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 case ACPI_ADR_SPACE_SYSTEM_IO:
841
Len Brown4be44fc2005-08-05 00:44:28 -0400842 status = acpi_os_write_port((acpi_io_address) address,
843 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 break;
845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500847 ACPI_ERROR((AE_INFO,
848 "Unsupported address space: %X",
849 reg->address_space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 return (AE_BAD_PARAMETER);
851 }
852
Len Brown4be44fc2005-08-05 00:44:28 -0400853 ACPI_DEBUG_PRINT((ACPI_DB_IO,
854 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
855 value, width,
856 ACPI_FORMAT_UINT64(address),
857 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 return (status);
860}