Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Module Name: hwregs - Read/write access functions for the various ACPI |
| 5 | * control and status registers. |
| 6 | * |
| 7 | ******************************************************************************/ |
| 8 | |
| 9 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 10 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * 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 | |
| 46 | #include <linux/module.h> |
| 47 | |
| 48 | #include <acpi/acpi.h> |
| 49 | #include <acpi/acnamesp.h> |
| 50 | #include <acpi/acevents.h> |
| 51 | |
| 52 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | ACPI_MODULE_NAME("hwregs") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /******************************************************************************* |
| 56 | * |
| 57 | * FUNCTION: acpi_hw_clear_acpi_status |
| 58 | * |
| 59 | * PARAMETERS: Flags - Lock the hardware or not |
| 60 | * |
| 61 | * RETURN: none |
| 62 | * |
| 63 | * DESCRIPTION: Clears all fixed and general purpose status bits |
| 64 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 65 | * |
| 66 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | acpi_status acpi_hw_clear_acpi_status(u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | ACPI_FUNCTION_TRACE("hw_clear_acpi_status"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n", |
| 74 | ACPI_BITMASK_ALL_FIXED_STATUS, |
| 75 | (u16) acpi_gbl_FADT->xpm1a_evt_blk.address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | if (flags & ACPI_MTX_LOCK) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE); |
| 79 | if (ACPI_FAILURE(status)) { |
| 80 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, |
| 85 | ACPI_REGISTER_PM1_STATUS, |
| 86 | ACPI_BITMASK_ALL_FIXED_STATUS); |
| 87 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | goto unlock_and_exit; |
| 89 | } |
| 90 | |
| 91 | /* Clear the fixed events */ |
| 92 | |
| 93 | if (acpi_gbl_FADT->xpm1b_evt_blk.address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | status = |
| 95 | acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS, |
| 96 | &acpi_gbl_FADT->xpm1b_evt_blk); |
| 97 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | goto unlock_and_exit; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /* Clear the GPE Bits in all GPE registers in all GPE blocks */ |
| 103 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | if (flags & ACPI_MTX_LOCK) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /******************************************************************************* |
| 114 | * |
| 115 | * FUNCTION: acpi_get_sleep_type_data |
| 116 | * |
| 117 | * PARAMETERS: sleep_state - Numeric sleep state |
| 118 | * *sleep_type_a - Where SLP_TYPa is returned |
| 119 | * *sleep_type_b - Where SLP_TYPb is returned |
| 120 | * |
| 121 | * RETURN: Status - ACPI status |
| 122 | * |
| 123 | * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep |
| 124 | * state. |
| 125 | * |
| 126 | ******************************************************************************/ |
| 127 | |
| 128 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | acpi_status status = AE_OK; |
| 132 | struct acpi_parameter_info info; |
| 133 | char *sleep_state_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | ACPI_FUNCTION_TRACE("acpi_get_sleep_type_data"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 137 | /* Validate parameters */ |
| 138 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) { |
| 140 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 143 | /* Evaluate the namespace object containing the values for this state */ |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | info.parameters = NULL; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 146 | info.return_object = NULL; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 147 | sleep_state_name = |
| 148 | ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 149 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | status = acpi_ns_evaluate_by_name(sleep_state_name, &info); |
| 151 | if (ACPI_FAILURE(status)) { |
| 152 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 153 | "%s while evaluating sleep_state [%s]\n", |
| 154 | acpi_format_exception(status), |
| 155 | sleep_state_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* Must have a return object */ |
| 161 | |
| 162 | if (!info.return_object) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 163 | ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]", |
| 164 | sleep_state_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | status = AE_NOT_EXIST; |
| 166 | } |
| 167 | |
| 168 | /* It must be of type Package */ |
| 169 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | else if (ACPI_GET_OBJECT_TYPE(info.return_object) != ACPI_TYPE_PACKAGE) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 171 | ACPI_ERROR((AE_INFO, |
| 172 | "Sleep State return object is not a Package")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | status = AE_AML_OPERAND_TYPE; |
| 174 | } |
| 175 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 176 | /* |
| 177 | * The package must have at least two elements. NOTE (March 2005): This |
| 178 | * goes against the current ACPI spec which defines this object as a |
| 179 | * package with one encoded DWORD element. However, existing practice |
| 180 | * by BIOS vendors seems to be to have 2 or more elements, at least |
| 181 | * one per sleep type (A/B). |
| 182 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | else if (info.return_object->package.count < 2) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 184 | ACPI_ERROR((AE_INFO, |
| 185 | "Sleep State return package does not have at least two elements")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | status = AE_AML_NO_OPERAND; |
| 187 | } |
| 188 | |
| 189 | /* The first two elements must both be of type Integer */ |
| 190 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | else if ((ACPI_GET_OBJECT_TYPE(info.return_object->package.elements[0]) |
| 192 | != ACPI_TYPE_INTEGER) || |
| 193 | (ACPI_GET_OBJECT_TYPE(info.return_object->package.elements[1]) |
| 194 | != ACPI_TYPE_INTEGER)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 195 | ACPI_ERROR((AE_INFO, |
| 196 | "Sleep State return package elements are not both Integers (%s, %s)", |
| 197 | acpi_ut_get_object_type_name(info.return_object-> |
| 198 | package.elements[0]), |
| 199 | acpi_ut_get_object_type_name(info.return_object-> |
| 200 | package.elements[1]))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | status = AE_AML_OPERAND_TYPE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | } else { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 203 | /* Valid _Sx_ package size, type, and value */ |
| 204 | |
| 205 | *sleep_type_a = (u8) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | (info.return_object->package.elements[0])->integer.value; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 207 | *sleep_type_b = (u8) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | (info.return_object->package.elements[1])->integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 212 | ACPI_EXCEPTION((AE_INFO, status, |
| 213 | "While evaluating sleep_state [%s], bad Sleep object %p type %s", |
| 214 | sleep_state_name, info.return_object, |
| 215 | acpi_ut_get_object_type_name(info. |
| 216 | return_object))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | acpi_ut_remove_reference(info.return_object); |
| 220 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | EXPORT_SYMBOL(acpi_get_sleep_type_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | /******************************************************************************* |
| 226 | * |
| 227 | * FUNCTION: acpi_hw_get_register_bit_mask |
| 228 | * |
| 229 | * PARAMETERS: register_id - Index of ACPI Register to access |
| 230 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 231 | * RETURN: The bitmask to be used when accessing the register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 233 | * DESCRIPTION: Map register_id into a register bitmask. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | * |
| 235 | ******************************************************************************/ |
| 236 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 239 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | if (register_id > ACPI_BITREG_MAX) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 242 | ACPI_ERROR((AE_INFO, "Invalid bit_register ID: %X", |
| 243 | register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return (NULL); |
| 245 | } |
| 246 | |
| 247 | return (&acpi_gbl_bit_register_info[register_id]); |
| 248 | } |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | /******************************************************************************* |
| 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 | * |
| 258 | * RETURN: Status and the value read from specified Register. Value |
| 259 | * returned is normalized to bit0 (is shifted all the way right) |
| 260 | * |
| 261 | * DESCRIPTION: ACPI bit_register read function. |
| 262 | * |
| 263 | ******************************************************************************/ |
| 264 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | u32 register_value = 0; |
| 268 | struct acpi_bit_register_info *bit_reg_info; |
| 269 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | ACPI_FUNCTION_TRACE("acpi_get_register"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
| 273 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 274 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | if (!bit_reg_info) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 277 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | if (flags & ACPI_MTX_LOCK) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 281 | status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE); |
| 282 | if (ACPI_FAILURE(status)) { |
| 283 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | /* Read from the register */ |
| 288 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, |
| 290 | bit_reg_info->parent_register, |
| 291 | ®ister_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | if (flags & ACPI_MTX_LOCK) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* Normalize the value that was read */ |
| 300 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | register_value = |
| 302 | ((register_value & bit_reg_info->access_bit_mask) |
| 303 | >> bit_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | *return_value = register_value; |
| 306 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n", |
| 308 | register_value, |
| 309 | bit_reg_info->parent_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | EXPORT_SYMBOL(acpi_get_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | /******************************************************************************* |
| 318 | * |
| 319 | * FUNCTION: acpi_set_register |
| 320 | * |
| 321 | * PARAMETERS: register_id - ID of ACPI bit_register to access |
| 322 | * Value - (only used on write) value to write to the |
| 323 | * Register, NOT pre-normalized to the bit pos |
| 324 | * Flags - Lock the hardware or not |
| 325 | * |
| 326 | * RETURN: Status |
| 327 | * |
| 328 | * DESCRIPTION: ACPI Bit Register write function. |
| 329 | * |
| 330 | ******************************************************************************/ |
| 331 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 334 | u32 register_value = 0; |
| 335 | struct acpi_bit_register_info *bit_reg_info; |
| 336 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | ACPI_FUNCTION_TRACE_U32("acpi_set_register", register_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 341 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | if (!bit_reg_info) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 344 | ACPI_ERROR((AE_INFO, "Bad ACPI HW register_id: %X", |
| 345 | register_id)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 346 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | if (flags & ACPI_MTX_LOCK) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE); |
| 351 | if (ACPI_FAILURE(status)) { |
| 352 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | /* Always do a register read first so we can insert the new bits */ |
| 357 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, |
| 359 | bit_reg_info->parent_register, |
| 360 | ®ister_value); |
| 361 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | goto unlock_and_exit; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Decode the Register ID |
| 367 | * Register ID = [Register block ID] | [bit ID] |
| 368 | * |
| 369 | * Check bit ID to fine locate Register offset. |
| 370 | * Check Mask to determine Register offset, and then read-write. |
| 371 | */ |
| 372 | switch (bit_reg_info->parent_register) { |
| 373 | case ACPI_REGISTER_PM1_STATUS: |
| 374 | |
| 375 | /* |
| 376 | * Status Registers are different from the rest. Clear by |
| 377 | * writing 1, and writing 0 has no effect. So, the only relevant |
| 378 | * information is the single bit we're interested in, all others should |
| 379 | * be written as 0 so they will be left unchanged. |
| 380 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 381 | value = ACPI_REGISTER_PREPARE_BITS(value, |
| 382 | bit_reg_info->bit_position, |
| 383 | bit_reg_info-> |
| 384 | access_bit_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | if (value) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, |
| 387 | ACPI_REGISTER_PM1_STATUS, |
| 388 | (u16) value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | register_value = 0; |
| 390 | } |
| 391 | break; |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | case ACPI_REGISTER_PM1_ENABLE: |
| 394 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 396 | bit_reg_info->bit_position, |
| 397 | bit_reg_info->access_bit_mask, |
| 398 | value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, |
| 401 | ACPI_REGISTER_PM1_ENABLE, |
| 402 | (u16) register_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | break; |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | case ACPI_REGISTER_PM1_CONTROL: |
| 406 | |
| 407 | /* |
| 408 | * Write the PM1 Control register. |
| 409 | * Note that at this level, the fact that there are actually TWO |
| 410 | * registers (A and B - and B may not exist) is abstracted. |
| 411 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n", |
| 413 | register_value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 416 | bit_reg_info->bit_position, |
| 417 | bit_reg_info->access_bit_mask, |
| 418 | value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, |
| 421 | ACPI_REGISTER_PM1_CONTROL, |
| 422 | (u16) register_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | break; |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | case ACPI_REGISTER_PM2_CONTROL: |
| 426 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 427 | status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, |
| 428 | ACPI_REGISTER_PM2_CONTROL, |
| 429 | ®ister_value); |
| 430 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | goto unlock_and_exit; |
| 432 | } |
| 433 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 434 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 435 | "PM2 control: Read %X from %8.8X%8.8X\n", |
| 436 | register_value, |
| 437 | ACPI_FORMAT_UINT64(acpi_gbl_FADT-> |
| 438 | xpm2_cnt_blk.address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 441 | bit_reg_info->bit_position, |
| 442 | bit_reg_info->access_bit_mask, |
| 443 | value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 445 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 446 | "About to write %4.4X to %8.8X%8.8X\n", |
| 447 | register_value, |
| 448 | ACPI_FORMAT_UINT64(acpi_gbl_FADT-> |
| 449 | xpm2_cnt_blk.address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 451 | status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, |
| 452 | ACPI_REGISTER_PM2_CONTROL, |
| 453 | (u8) (register_value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | break; |
| 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | default: |
| 457 | break; |
| 458 | } |
| 459 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 460 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
| 462 | if (flags & ACPI_MTX_LOCK) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /* Normalize the value that was read */ |
| 467 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | ACPI_DEBUG_EXEC(register_value = |
| 469 | ((register_value & bit_reg_info->access_bit_mask) >> |
| 470 | bit_reg_info->bit_position)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 472 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 473 | "Set bits: %8.8X actual %8.8X register %X\n", value, |
| 474 | register_value, bit_reg_info->parent_register)); |
| 475 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | EXPORT_SYMBOL(acpi_set_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
| 480 | /****************************************************************************** |
| 481 | * |
| 482 | * FUNCTION: acpi_hw_register_read |
| 483 | * |
| 484 | * PARAMETERS: use_lock - Mutex hw access |
| 485 | * register_id - register_iD + Offset |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 486 | * return_value - Where the register value is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | * |
| 488 | * RETURN: Status and the value read. |
| 489 | * |
| 490 | * DESCRIPTION: Acpi register read function. Registers are read at the |
| 491 | * given offset. |
| 492 | * |
| 493 | ******************************************************************************/ |
| 494 | |
| 495 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | u32 value1 = 0; |
| 499 | u32 value2 = 0; |
| 500 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | ACPI_FUNCTION_TRACE("hw_register_read"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | if (ACPI_MTX_LOCK == use_lock) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE); |
| 506 | if (ACPI_FAILURE(status)) { |
| 507 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
| 511 | switch (register_id) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | status = |
| 515 | acpi_hw_low_level_read(16, &value1, |
| 516 | &acpi_gbl_FADT->xpm1a_evt_blk); |
| 517 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | goto unlock_and_exit; |
| 519 | } |
| 520 | |
| 521 | /* PM1B is optional */ |
| 522 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | status = |
| 524 | acpi_hw_low_level_read(16, &value2, |
| 525 | &acpi_gbl_FADT->xpm1b_evt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | value1 |= value2; |
| 527 | break; |
| 528 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 531 | status = |
| 532 | acpi_hw_low_level_read(16, &value1, &acpi_gbl_xpm1a_enable); |
| 533 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | goto unlock_and_exit; |
| 535 | } |
| 536 | |
| 537 | /* PM1B is optional */ |
| 538 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 539 | status = |
| 540 | acpi_hw_low_level_read(16, &value2, &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | value1 |= value2; |
| 542 | break; |
| 543 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 544 | case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | status = |
| 547 | acpi_hw_low_level_read(16, &value1, |
| 548 | &acpi_gbl_FADT->xpm1a_cnt_blk); |
| 549 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | goto unlock_and_exit; |
| 551 | } |
| 552 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 553 | status = |
| 554 | acpi_hw_low_level_read(16, &value2, |
| 555 | &acpi_gbl_FADT->xpm1b_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | value1 |= value2; |
| 557 | break; |
| 558 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 559 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 561 | status = |
| 562 | acpi_hw_low_level_read(8, &value1, |
| 563 | &acpi_gbl_FADT->xpm2_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | break; |
| 565 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 566 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 568 | status = |
| 569 | acpi_hw_low_level_read(32, &value1, |
| 570 | &acpi_gbl_FADT->xpm_tmr_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | break; |
| 572 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 575 | status = acpi_os_read_port(acpi_gbl_FADT->smi_cmd, &value1, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | break; |
| 577 | |
| 578 | default: |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 579 | ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | status = AE_BAD_PARAMETER; |
| 581 | break; |
| 582 | } |
| 583 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 584 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (ACPI_MTX_LOCK == use_lock) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 586 | (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 589 | if (ACPI_SUCCESS(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | *return_value = value1; |
| 591 | } |
| 592 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 593 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | /****************************************************************************** |
| 597 | * |
| 598 | * FUNCTION: acpi_hw_register_write |
| 599 | * |
| 600 | * PARAMETERS: use_lock - Mutex hw access |
| 601 | * register_id - register_iD + Offset |
| 602 | * Value - The value to write |
| 603 | * |
| 604 | * RETURN: Status |
| 605 | * |
| 606 | * DESCRIPTION: Acpi register Write function. Registers are written at the |
| 607 | * given offset. |
| 608 | * |
| 609 | ******************************************************************************/ |
| 610 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 611 | acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 613 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 615 | ACPI_FUNCTION_TRACE("hw_register_write"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | if (ACPI_MTX_LOCK == use_lock) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 618 | status = acpi_ut_acquire_mutex(ACPI_MTX_HARDWARE); |
| 619 | if (ACPI_FAILURE(status)) { |
| 620 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | switch (register_id) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 625 | case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 627 | status = |
| 628 | acpi_hw_low_level_write(16, value, |
| 629 | &acpi_gbl_FADT->xpm1a_evt_blk); |
| 630 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | goto unlock_and_exit; |
| 632 | } |
| 633 | |
| 634 | /* PM1B is optional */ |
| 635 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 636 | status = |
| 637 | acpi_hw_low_level_write(16, value, |
| 638 | &acpi_gbl_FADT->xpm1b_evt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | break; |
| 640 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 641 | case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 643 | status = |
| 644 | acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1a_enable); |
| 645 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | goto unlock_and_exit; |
| 647 | } |
| 648 | |
| 649 | /* PM1B is optional */ |
| 650 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 651 | status = |
| 652 | acpi_hw_low_level_write(16, value, &acpi_gbl_xpm1b_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | break; |
| 654 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 655 | case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 657 | status = |
| 658 | acpi_hw_low_level_write(16, value, |
| 659 | &acpi_gbl_FADT->xpm1a_cnt_blk); |
| 660 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | goto unlock_and_exit; |
| 662 | } |
| 663 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 664 | status = |
| 665 | acpi_hw_low_level_write(16, value, |
| 666 | &acpi_gbl_FADT->xpm1b_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | break; |
| 668 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 669 | case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 671 | status = |
| 672 | acpi_hw_low_level_write(16, value, |
| 673 | &acpi_gbl_FADT->xpm1a_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | break; |
| 675 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 676 | case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | status = |
| 679 | acpi_hw_low_level_write(16, value, |
| 680 | &acpi_gbl_FADT->xpm1b_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | break; |
| 682 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 683 | case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 685 | status = |
| 686 | acpi_hw_low_level_write(8, value, |
| 687 | &acpi_gbl_FADT->xpm2_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | break; |
| 689 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 690 | case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 692 | status = |
| 693 | acpi_hw_low_level_write(32, value, |
| 694 | &acpi_gbl_FADT->xpm_tmr_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | break; |
| 696 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 697 | case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
| 699 | /* SMI_CMD is currently always in IO space */ |
| 700 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, value, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | break; |
| 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | default: |
| 705 | status = AE_BAD_PARAMETER; |
| 706 | break; |
| 707 | } |
| 708 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 709 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | if (ACPI_MTX_LOCK == use_lock) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | (void)acpi_ut_release_mutex(ACPI_MTX_HARDWARE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 714 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | /****************************************************************************** |
| 718 | * |
| 719 | * FUNCTION: acpi_hw_low_level_read |
| 720 | * |
| 721 | * PARAMETERS: Width - 8, 16, or 32 |
| 722 | * Value - Where the value is returned |
| 723 | * Reg - GAS register structure |
| 724 | * |
| 725 | * RETURN: Status |
| 726 | * |
| 727 | * DESCRIPTION: Read from either memory or IO space. |
| 728 | * |
| 729 | ******************************************************************************/ |
| 730 | |
| 731 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 734 | u64 address; |
| 735 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 737 | ACPI_FUNCTION_NAME("hw_low_level_read"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | /* |
| 740 | * Must have a valid pointer to a GAS structure, and |
| 741 | * a non-zero address within. However, don't return an error |
| 742 | * because the PM1A/B code must not fail if B isn't present. |
| 743 | */ |
| 744 | if (!reg) { |
| 745 | return (AE_OK); |
| 746 | } |
| 747 | |
| 748 | /* Get a local copy of the address. Handles possible alignment issues */ |
| 749 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 750 | ACPI_MOVE_64_TO_64(&address, ®->address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | if (!address) { |
| 752 | return (AE_OK); |
| 753 | } |
| 754 | *value = 0; |
| 755 | |
| 756 | /* |
| 757 | * Two address spaces supported: Memory or IO. |
| 758 | * PCI_Config is not supported here because the GAS struct is insufficient |
| 759 | */ |
| 760 | switch (reg->address_space_id) { |
| 761 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
| 762 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 763 | status = acpi_os_read_memory((acpi_physical_address) address, |
| 764 | value, width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | break; |
| 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 768 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 769 | status = acpi_os_read_port((acpi_io_address) address, |
| 770 | value, width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | break; |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | default: |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 774 | ACPI_ERROR((AE_INFO, |
| 775 | "Unsupported address space: %X", |
| 776 | reg->address_space_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | return (AE_BAD_PARAMETER); |
| 778 | } |
| 779 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 780 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 781 | "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", |
| 782 | *value, width, |
| 783 | ACPI_FORMAT_UINT64(address), |
| 784 | acpi_ut_get_region_name(reg->address_space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | return (status); |
| 787 | } |
| 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /****************************************************************************** |
| 790 | * |
| 791 | * FUNCTION: acpi_hw_low_level_write |
| 792 | * |
| 793 | * PARAMETERS: Width - 8, 16, or 32 |
| 794 | * Value - To be written |
| 795 | * Reg - GAS register structure |
| 796 | * |
| 797 | * RETURN: Status |
| 798 | * |
| 799 | * DESCRIPTION: Write to either memory or IO space. |
| 800 | * |
| 801 | ******************************************************************************/ |
| 802 | |
| 803 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 804 | acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 806 | u64 address; |
| 807 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 809 | ACPI_FUNCTION_NAME("hw_low_level_write"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | /* |
| 812 | * Must have a valid pointer to a GAS structure, and |
| 813 | * a non-zero address within. However, don't return an error |
| 814 | * because the PM1A/B code must not fail if B isn't present. |
| 815 | */ |
| 816 | if (!reg) { |
| 817 | return (AE_OK); |
| 818 | } |
| 819 | |
| 820 | /* Get a local copy of the address. Handles possible alignment issues */ |
| 821 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 822 | ACPI_MOVE_64_TO_64(&address, ®->address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | if (!address) { |
| 824 | return (AE_OK); |
| 825 | } |
| 826 | |
| 827 | /* |
| 828 | * Two address spaces supported: Memory or IO. |
| 829 | * PCI_Config is not supported here because the GAS struct is insufficient |
| 830 | */ |
| 831 | switch (reg->address_space_id) { |
| 832 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
| 833 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 834 | status = acpi_os_write_memory((acpi_physical_address) address, |
| 835 | value, width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | break; |
| 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 839 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 840 | status = acpi_os_write_port((acpi_io_address) address, |
| 841 | value, width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | break; |
| 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | default: |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 845 | ACPI_ERROR((AE_INFO, |
| 846 | "Unsupported address space: %X", |
| 847 | reg->address_space_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | return (AE_BAD_PARAMETER); |
| 849 | } |
| 850 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 851 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 852 | "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", |
| 853 | value, width, |
| 854 | ACPI_FORMAT_UINT64(address), |
| 855 | acpi_ut_get_region_name(reg->address_space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | return (status); |
| 858 | } |