blob: fa58c1edce1e52f00c6b1cecebbe3f63a7a4af6f [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 *
Bob Moore4c90ece2006-06-08 16:29:00 -040064 * NOTE: TBD: Flags parameter is obsolete, to be removed
65 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040067acpi_status acpi_hw_clear_acpi_status(u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Len Brown4be44fc2005-08-05 00:44:28 -040069 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -040070 acpi_cpu_flags lock_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Bob Mooreb229cf92006-04-21 17:15:00 -040072 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Len Brown4be44fc2005-08-05 00:44:28 -040074 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
75 ACPI_BITMASK_ALL_FIXED_STATUS,
76 (u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Bob Moore4c90ece2006-06-08 16:29:00 -040078 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Len Brown4be44fc2005-08-05 00:44:28 -040080 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
81 ACPI_REGISTER_PM1_STATUS,
82 ACPI_BITMASK_ALL_FIXED_STATUS);
83 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 goto unlock_and_exit;
85 }
86
87 /* Clear the fixed events */
88
89 if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
Len Brown4be44fc2005-08-05 00:44:28 -040090 status =
91 acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
92 &acpi_gbl_FADT->xpm1b_evt_blk);
93 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 goto unlock_and_exit;
95 }
96 }
97
98 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
99
Len Brown4be44fc2005-08-05 00:44:28 -0400100 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Len Brown4be44fc2005-08-05 00:44:28 -0400102 unlock_and_exit:
Bob Moore4c90ece2006-06-08 16:29:00 -0400103 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400104 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/*******************************************************************************
108 *
109 * FUNCTION: acpi_get_sleep_type_data
110 *
111 * PARAMETERS: sleep_state - Numeric sleep state
112 * *sleep_type_a - Where SLP_TYPa is returned
113 * *sleep_type_b - Where SLP_TYPb is returned
114 *
115 * RETURN: Status - ACPI status
116 *
117 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
118 * state.
119 *
120 ******************************************************************************/
121
122acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400123acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Len Brown4be44fc2005-08-05 00:44:28 -0400125 acpi_status status = AE_OK;
Bob Moore41195322006-05-26 16:36:00 -0400126 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Bob Mooreb229cf92006-04-21 17:15:00 -0400128 ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Robert Moore44f6c012005-04-18 22:49:35 -0400130 /* Validate parameters */
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
133 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
135
Bob Moore41195322006-05-26 16:36:00 -0400136 /* Allocate the evaluation information block */
Robert Moore44f6c012005-04-18 22:49:35 -0400137
Bob Moore41195322006-05-26 16:36:00 -0400138 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
139 if (!info) {
140 return_ACPI_STATUS(AE_NO_MEMORY);
141 }
142
143 info->pathname =
Bob Mooredefba1d2005-12-16 17:05:00 -0500144 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
Robert Moore44f6c012005-04-18 22:49:35 -0400145
Bob Moore41195322006-05-26 16:36:00 -0400146 /* Evaluate the namespace object containing the values for this state */
147
148 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400149 if (ACPI_FAILURE(status)) {
150 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400151 "%s while evaluating SleepState [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400152 acpi_format_exception(status),
Bob Moore41195322006-05-26 16:36:00 -0400153 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Bob Moore41195322006-05-26 16:36:00 -0400155 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
158 /* Must have a return object */
159
Bob Moore41195322006-05-26 16:36:00 -0400160 if (!info->return_object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500161 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
Bob Moore41195322006-05-26 16:36:00 -0400162 info->pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 status = AE_NOT_EXIST;
164 }
165
166 /* It must be of type Package */
167
Bob Moore41195322006-05-26 16:36:00 -0400168 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500169 ACPI_ERROR((AE_INFO,
170 "Sleep State return object is not a Package"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 status = AE_AML_OPERAND_TYPE;
172 }
173
Robert Moore44f6c012005-04-18 22:49:35 -0400174 /*
Bob Moore967440e32006-06-23 17:04:00 -0400175 * The package must have at least two elements. NOTE (March 2005): This
Robert Moore44f6c012005-04-18 22:49:35 -0400176 * goes against the current ACPI spec which defines this object as a
Bob Moore967440e32006-06-23 17:04:00 -0400177 * package with one encoded DWORD element. However, existing practice
Robert Moore44f6c012005-04-18 22:49:35 -0400178 * by BIOS vendors seems to be to have 2 or more elements, at least
179 * one per sleep type (A/B).
180 */
Bob Moore41195322006-05-26 16:36:00 -0400181 else if (info->return_object->package.count < 2) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500182 ACPI_ERROR((AE_INFO,
183 "Sleep State return package does not have at least two elements"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 status = AE_AML_NO_OPERAND;
185 }
186
187 /* The first two elements must both be of type Integer */
188
Bob Moore41195322006-05-26 16:36:00 -0400189 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0])
Len Brown4be44fc2005-08-05 00:44:28 -0400190 != ACPI_TYPE_INTEGER) ||
Bob Moore41195322006-05-26 16:36:00 -0400191 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1])
Len Brown4be44fc2005-08-05 00:44:28 -0400192 != ACPI_TYPE_INTEGER)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500193 ACPI_ERROR((AE_INFO,
194 "Sleep State return package elements are not both Integers (%s, %s)",
Bob Moore41195322006-05-26 16:36:00 -0400195 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500196 package.elements[0]),
Bob Moore41195322006-05-26 16:36:00 -0400197 acpi_ut_get_object_type_name(info->return_object->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500198 package.elements[1])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 status = AE_AML_OPERAND_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400200 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400201 /* Valid _Sx_ package size, type, and value */
202
203 *sleep_type_a = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400204 (info->return_object->package.elements[0])->integer.value;
Robert Moore44f6c012005-04-18 22:49:35 -0400205 *sleep_type_b = (u8)
Bob Moore41195322006-05-26 16:36:00 -0400206 (info->return_object->package.elements[1])->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500210 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400211 "While evaluating SleepState [%s], bad Sleep object %p type %s",
Bob Moore41195322006-05-26 16:36:00 -0400212 info->pathname, info->return_object,
213 acpi_ut_get_object_type_name(info->
Bob Mooreb8e4d892006-01-27 16:43:00 -0500214 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
Bob Moore41195322006-05-26 16:36:00 -0400217 acpi_ut_remove_reference(info->return_object);
218
219 cleanup:
220 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400221 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Bob Moore83135242006-10-03 00:00:00 -0400224ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226/*******************************************************************************
227 *
228 * FUNCTION: acpi_hw_get_register_bit_mask
229 *
230 * PARAMETERS: register_id - Index of ACPI Register to access
231 *
Robert Moore44f6c012005-04-18 22:49:35 -0400232 * RETURN: The bitmask to be used when accessing the register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 *
Robert Moore44f6c012005-04-18 22:49:35 -0400234 * DESCRIPTION: Map register_id into a register bitmask.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 *
236 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400237struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Bob Moore4a90c7e2006-01-13 16:22:00 -0500239 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 if (register_id > ACPI_BITREG_MAX) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400242 ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500243 register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return (NULL);
245 }
246
247 return (&acpi_gbl_bit_register_info[register_id]);
248}
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/*******************************************************************************
251 *
252 * FUNCTION: acpi_get_register
253 *
254 * PARAMETERS: register_id - ID of ACPI bit_register to access
255 * return_value - Value that was read from the register
256 * Flags - Lock the hardware or not
257 *
Bob Moore967440e32006-06-23 17:04:00 -0400258 * RETURN: Status and the value read from specified Register. Value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 * returned is normalized to bit0 (is shifted all the way right)
260 *
261 * DESCRIPTION: ACPI bit_register read function.
262 *
Bob Moore4c90ece2006-06-08 16:29:00 -0400263 * NOTE: TBD: Flags parameter is obsolete, to be removed
264 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 ******************************************************************************/
266
Len Brown4be44fc2005-08-05 00:44:28 -0400267acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Len Brown4be44fc2005-08-05 00:44:28 -0400269 u32 register_value = 0;
270 struct acpi_bit_register_info *bit_reg_info;
271 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Bob Mooreb229cf92006-04-21 17:15:00 -0400273 ACPI_FUNCTION_TRACE(acpi_get_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 /* Get the info structure corresponding to the requested ACPI Register */
276
Len Brown4be44fc2005-08-05 00:44:28 -0400277 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (!bit_reg_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400279 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* Read from the register */
283
Bob Moore4c90ece2006-06-08 16:29:00 -0400284 status = acpi_hw_register_read(ACPI_MTX_LOCK,
Len Brown4be44fc2005-08-05 00:44:28 -0400285 bit_reg_info->parent_register,
286 &register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Len Brown4be44fc2005-08-05 00:44:28 -0400288 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 /* Normalize the value that was read */
291
Len Brown4be44fc2005-08-05 00:44:28 -0400292 register_value =
293 ((register_value & bit_reg_info->access_bit_mask)
294 >> bit_reg_info->bit_position);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 *return_value = register_value;
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
299 register_value,
300 bit_reg_info->parent_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
302
Len Brown4be44fc2005-08-05 00:44:28 -0400303 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Bob Moore83135242006-10-03 00:00:00 -0400306ACPI_EXPORT_SYMBOL(acpi_get_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308/*******************************************************************************
309 *
310 * FUNCTION: acpi_set_register
311 *
312 * PARAMETERS: register_id - ID of ACPI bit_register to access
313 * Value - (only used on write) value to write to the
314 * Register, NOT pre-normalized to the bit pos
315 * Flags - Lock the hardware or not
316 *
317 * RETURN: Status
318 *
319 * DESCRIPTION: ACPI Bit Register write function.
320 *
Bob Moore4c90ece2006-06-08 16:29:00 -0400321 * NOTE: TBD: Flags parameter is obsolete, to be removed
322 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400324acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
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
Len Brown4be44fc2005-08-05 00:44:28 -0400346 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
347 bit_reg_info->parent_register,
348 &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 Moore967440e32006-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) {
Len Brown4be44fc2005-08-05 00:44:28 -0400374 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
375 ACPI_REGISTER_PM1_STATUS,
376 (u16) value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 register_value = 0;
378 }
379 break;
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 case ACPI_REGISTER_PM1_ENABLE:
382
Len Brown4be44fc2005-08-05 00:44:28 -0400383 ACPI_REGISTER_INSERT_VALUE(register_value,
384 bit_reg_info->bit_position,
385 bit_reg_info->access_bit_mask,
386 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
389 ACPI_REGISTER_PM1_ENABLE,
390 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 break;
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 case ACPI_REGISTER_PM1_CONTROL:
394
395 /*
396 * Write the PM1 Control register.
397 * Note that at this level, the fact that there are actually TWO
398 * registers (A and B - and B may not exist) is abstracted.
399 */
Len Brown4be44fc2005-08-05 00:44:28 -0400400 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
401 register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 ACPI_REGISTER_INSERT_VALUE(register_value,
404 bit_reg_info->bit_position,
405 bit_reg_info->access_bit_mask,
406 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
409 ACPI_REGISTER_PM1_CONTROL,
410 (u16) register_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 break;
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 case ACPI_REGISTER_PM2_CONTROL:
414
Len Brown4be44fc2005-08-05 00:44:28 -0400415 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
416 ACPI_REGISTER_PM2_CONTROL,
417 &register_value);
418 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 goto unlock_and_exit;
420 }
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 ACPI_DEBUG_PRINT((ACPI_DB_IO,
423 "PM2 control: Read %X from %8.8X%8.8X\n",
424 register_value,
425 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
426 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 ACPI_REGISTER_INSERT_VALUE(register_value,
429 bit_reg_info->bit_position,
430 bit_reg_info->access_bit_mask,
431 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 ACPI_DEBUG_PRINT((ACPI_DB_IO,
434 "About to write %4.4X to %8.8X%8.8X\n",
435 register_value,
436 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
437 xpm2_cnt_blk.address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
440 ACPI_REGISTER_PM2_CONTROL,
441 (u8) (register_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 break;
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 default:
445 break;
446 }
447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Bob Moore4c90ece2006-06-08 16:29:00 -0400450 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 /* Normalize the value that was read */
453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 ACPI_DEBUG_EXEC(register_value =
455 ((register_value & bit_reg_info->access_bit_mask) >>
456 bit_reg_info->bit_position));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Len Brown4be44fc2005-08-05 00:44:28 -0400458 ACPI_DEBUG_PRINT((ACPI_DB_IO,
459 "Set bits: %8.8X actual %8.8X register %X\n", value,
460 register_value, bit_reg_info->parent_register));
461 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Bob Moore83135242006-10-03 00:00:00 -0400464ACPI_EXPORT_SYMBOL(acpi_set_register)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466/******************************************************************************
467 *
468 * FUNCTION: acpi_hw_register_read
469 *
Bob Moore967440e32006-06-23 17:04:00 -0400470 * PARAMETERS: use_lock - Lock hardware? True/False
471 * register_id - ACPI Register ID
Robert Moore44f6c012005-04-18 22:49:35 -0400472 * return_value - Where the register value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 *
474 * RETURN: Status and the value read.
475 *
Bob Moore967440e32006-06-23 17:04:00 -0400476 * DESCRIPTION: Read from the specified ACPI register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 *
478 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400480acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Len Brown4be44fc2005-08-05 00:44:28 -0400482 u32 value1 = 0;
483 u32 value2 = 0;
484 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400485 acpi_cpu_flags lock_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Bob Mooreb229cf92006-04-21 17:15:00 -0400487 ACPI_FUNCTION_TRACE(hw_register_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400490 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
493 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400494 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 status =
497 acpi_hw_low_level_read(16, &value1,
498 &acpi_gbl_FADT->xpm1a_evt_blk);
499 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 goto unlock_and_exit;
501 }
502
503 /* PM1B is optional */
504
Len Brown4be44fc2005-08-05 00:44:28 -0400505 status =
506 acpi_hw_low_level_read(16, &value2,
507 &acpi_gbl_FADT->xpm1b_evt_blk);
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_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Len Brown4be44fc2005-08-05 00:44:28 -0400513 status =
514 acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable);
515 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 goto unlock_and_exit;
517 }
518
519 /* PM1B is optional */
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 status =
522 acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 value1 |= value2;
524 break;
525
Len Brown4be44fc2005-08-05 00:44:28 -0400526 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Len Brown4be44fc2005-08-05 00:44:28 -0400528 status =
529 acpi_hw_low_level_read(16, &value1,
530 &acpi_gbl_FADT->xpm1a_cnt_blk);
531 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 goto unlock_and_exit;
533 }
534
Len Brown4be44fc2005-08-05 00:44:28 -0400535 status =
536 acpi_hw_low_level_read(16, &value2,
537 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 value1 |= value2;
539 break;
540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Len Brown4be44fc2005-08-05 00:44:28 -0400543 status =
544 acpi_hw_low_level_read(8, &value1,
545 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 break;
547
Len Brown4be44fc2005-08-05 00:44:28 -0400548 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Len Brown4be44fc2005-08-05 00:44:28 -0400550 status =
551 acpi_hw_low_level_read(32, &value1,
552 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 break;
554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Len Brown4be44fc2005-08-05 00:44:28 -0400557 status = acpi_os_read_port(acpi_gbl_FADT->smi_cmd, &value1, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 break;
559
560 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500561 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 status = AE_BAD_PARAMETER;
563 break;
564 }
565
Len Brown4be44fc2005-08-05 00:44:28 -0400566 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400568 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
570
Len Brown4be44fc2005-08-05 00:44:28 -0400571 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 *return_value = value1;
573 }
574
Len Brown4be44fc2005-08-05 00:44:28 -0400575 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/******************************************************************************
579 *
580 * FUNCTION: acpi_hw_register_write
581 *
Bob Moore967440e32006-06-23 17:04:00 -0400582 * PARAMETERS: use_lock - Lock hardware? True/False
583 * register_id - ACPI Register ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 * Value - The value to write
585 *
586 * RETURN: Status
587 *
Bob Moore967440e32006-06-23 17:04:00 -0400588 * DESCRIPTION: Write to the specified ACPI register
589 *
590 * NOTE: In accordance with the ACPI specification, this function automatically
591 * preserves the value of the following bits, meaning that these bits cannot be
592 * changed via this interface:
593 *
594 * PM1_CONTROL[0] = SCI_EN
595 * PM1_CONTROL[9]
596 * PM1_STATUS[11]
597 *
598 * ACPI References:
599 * 1) Hardware Ignored Bits: When software writes to a register with ignored
600 * bit fields, it preserves the ignored bit fields
601 * 2) SCI_EN: OSPM always preserves this bit position
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 *
603 ******************************************************************************/
604
Len Brown4be44fc2005-08-05 00:44:28 -0400605acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Len Brown4be44fc2005-08-05 00:44:28 -0400607 acpi_status status;
Bob Moore4c90ece2006-06-08 16:29:00 -0400608 acpi_cpu_flags lock_flags = 0;
Bob Moore967440e32006-06-23 17:04:00 -0400609 u32 read_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Bob Mooreb229cf92006-04-21 17:15:00 -0400611 ACPI_FUNCTION_TRACE(hw_register_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400614 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616
617 switch (register_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400618 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Bob Moore967440e32006-06-23 17:04:00 -0400620 /* Perform a read first to preserve certain bits (per ACPI spec) */
621
622 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
623 ACPI_REGISTER_PM1_STATUS,
624 &read_value);
625 if (ACPI_FAILURE(status)) {
626 goto unlock_and_exit;
627 }
628
629 /* Insert the bits to be preserved */
630
631 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
632 read_value);
633
634 /* Now we can write the data */
635
Len Brown4be44fc2005-08-05 00:44:28 -0400636 status =
637 acpi_hw_low_level_write(16, value,
638 &acpi_gbl_FADT->xpm1a_evt_blk);
639 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 goto unlock_and_exit;
641 }
642
643 /* PM1B is optional */
644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 status =
646 acpi_hw_low_level_write(16, value,
647 &acpi_gbl_FADT->xpm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 break;
649
Len Brown4be44fc2005-08-05 00:44:28 -0400650 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Len Brown4be44fc2005-08-05 00:44:28 -0400652 status =
653 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable);
654 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 goto unlock_and_exit;
656 }
657
658 /* PM1B is optional */
659
Len Brown4be44fc2005-08-05 00:44:28 -0400660 status =
661 acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 break;
663
Len Brown4be44fc2005-08-05 00:44:28 -0400664 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Bob Moore967440e32006-06-23 17:04:00 -0400666 /*
667 * Perform a read first to preserve certain bits (per ACPI spec)
Bob Moore967440e32006-06-23 17:04:00 -0400668 */
669 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
670 ACPI_REGISTER_PM1_CONTROL,
671 &read_value);
672 if (ACPI_FAILURE(status)) {
673 goto unlock_and_exit;
674 }
675
676 /* Insert the bits to be preserved */
677
678 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
679 read_value);
680
681 /* Now we can write the data */
682
Len Brown4be44fc2005-08-05 00:44:28 -0400683 status =
684 acpi_hw_low_level_write(16, value,
685 &acpi_gbl_FADT->xpm1a_cnt_blk);
686 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 goto unlock_and_exit;
688 }
689
Len Brown4be44fc2005-08-05 00:44:28 -0400690 status =
691 acpi_hw_low_level_write(16, value,
692 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 break;
694
Len Brown4be44fc2005-08-05 00:44:28 -0400695 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 status =
698 acpi_hw_low_level_write(16, value,
699 &acpi_gbl_FADT->xpm1a_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 break;
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Len Brown4be44fc2005-08-05 00:44:28 -0400704 status =
705 acpi_hw_low_level_write(16, value,
706 &acpi_gbl_FADT->xpm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 break;
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 status =
712 acpi_hw_low_level_write(8, value,
713 &acpi_gbl_FADT->xpm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 break;
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Len Brown4be44fc2005-08-05 00:44:28 -0400718 status =
719 acpi_hw_low_level_write(32, value,
720 &acpi_gbl_FADT->xpm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 break;
722
Len Brown4be44fc2005-08-05 00:44:28 -0400723 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 /* SMI_CMD is currently always in IO space */
726
Len Brown4be44fc2005-08-05 00:44:28 -0400727 status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, value, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 break;
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 default:
731 status = AE_BAD_PARAMETER;
732 break;
733 }
734
Len Brown4be44fc2005-08-05 00:44:28 -0400735 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 if (ACPI_MTX_LOCK == use_lock) {
Bob Moore4c90ece2006-06-08 16:29:00 -0400737 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739
Len Brown4be44fc2005-08-05 00:44:28 -0400740 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741}
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743/******************************************************************************
744 *
745 * FUNCTION: acpi_hw_low_level_read
746 *
747 * PARAMETERS: Width - 8, 16, or 32
748 * Value - Where the value is returned
749 * Reg - GAS register structure
750 *
751 * RETURN: Status
752 *
753 * DESCRIPTION: Read from either memory or IO space.
754 *
755 ******************************************************************************/
756
757acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400758acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Len Brown4be44fc2005-08-05 00:44:28 -0400760 u64 address;
761 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Bob Mooreb229cf92006-04-21 17:15:00 -0400763 ACPI_FUNCTION_NAME(hw_low_level_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /*
766 * Must have a valid pointer to a GAS structure, and
767 * a non-zero address within. However, don't return an error
768 * because the PM1A/B code must not fail if B isn't present.
769 */
770 if (!reg) {
771 return (AE_OK);
772 }
773
Bob Moore967440e32006-06-23 17:04:00 -0400774 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Len Brown4be44fc2005-08-05 00:44:28 -0400776 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 if (!address) {
778 return (AE_OK);
779 }
780 *value = 0;
781
782 /*
783 * Two address spaces supported: Memory or IO.
784 * PCI_Config is not supported here because the GAS struct is insufficient
785 */
786 switch (reg->address_space_id) {
787 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
788
Len Brown4be44fc2005-08-05 00:44:28 -0400789 status = acpi_os_read_memory((acpi_physical_address) address,
790 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 break;
792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 case ACPI_ADR_SPACE_SYSTEM_IO:
794
Len Brown4be44fc2005-08-05 00:44:28 -0400795 status = acpi_os_read_port((acpi_io_address) address,
796 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 break;
798
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500800 ACPI_ERROR((AE_INFO,
801 "Unsupported address space: %X",
802 reg->address_space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return (AE_BAD_PARAMETER);
804 }
805
Len Brown4be44fc2005-08-05 00:44:28 -0400806 ACPI_DEBUG_PRINT((ACPI_DB_IO,
807 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
808 *value, width,
809 ACPI_FORMAT_UINT64(address),
810 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 return (status);
813}
814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815/******************************************************************************
816 *
817 * FUNCTION: acpi_hw_low_level_write
818 *
819 * PARAMETERS: Width - 8, 16, or 32
820 * Value - To be written
821 * Reg - GAS register structure
822 *
823 * RETURN: Status
824 *
825 * DESCRIPTION: Write to either memory or IO space.
826 *
827 ******************************************************************************/
828
829acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400830acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Len Brown4be44fc2005-08-05 00:44:28 -0400832 u64 address;
833 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Bob Mooreb229cf92006-04-21 17:15:00 -0400835 ACPI_FUNCTION_NAME(hw_low_level_write);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 /*
838 * Must have a valid pointer to a GAS structure, and
839 * a non-zero address within. However, don't return an error
840 * because the PM1A/B code must not fail if B isn't present.
841 */
842 if (!reg) {
843 return (AE_OK);
844 }
845
Bob Moore967440e32006-06-23 17:04:00 -0400846 /* Get a local copy of the address. Handles possible alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Len Brown4be44fc2005-08-05 00:44:28 -0400848 ACPI_MOVE_64_TO_64(&address, &reg->address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (!address) {
850 return (AE_OK);
851 }
852
853 /*
854 * Two address spaces supported: Memory or IO.
855 * PCI_Config is not supported here because the GAS struct is insufficient
856 */
857 switch (reg->address_space_id) {
858 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
859
Len Brown4be44fc2005-08-05 00:44:28 -0400860 status = acpi_os_write_memory((acpi_physical_address) address,
861 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 case ACPI_ADR_SPACE_SYSTEM_IO:
865
Len Brown4be44fc2005-08-05 00:44:28 -0400866 status = acpi_os_write_port((acpi_io_address) address,
867 value, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 break;
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 default:
Bob Mooreb8e4d892006-01-27 16:43:00 -0500871 ACPI_ERROR((AE_INFO,
872 "Unsupported address space: %X",
873 reg->address_space_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 return (AE_BAD_PARAMETER);
875 }
876
Len Brown4be44fc2005-08-05 00:44:28 -0400877 ACPI_DEBUG_PRINT((ACPI_DB_IO,
878 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
879 value, width,
880 ACPI_FORMAT_UINT64(address),
881 acpi_ut_get_region_name(reg->address_space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 return (status);
884}