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