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