Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evgpeblk - GPE block creation and initialization. |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
| 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acevents.h> |
| 46 | #include <acpi/acnamesp.h> |
| 47 | |
| 48 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | ACPI_MODULE_NAME("evgpeblk") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 51 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | static acpi_status |
| 53 | acpi_ev_save_method_info(acpi_handle obj_handle, |
| 54 | u32 level, void *obj_desc, void **return_value); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | |
| 56 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | acpi_ev_match_prw_and_gpe(acpi_handle obj_handle, |
| 58 | u32 level, void *info, void **return_value); |
| 59 | |
| 60 | static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32 |
| 61 | interrupt_number); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 | |
| 63 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 64 | acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 65 | |
| 66 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block, |
| 68 | u32 interrupt_number); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 69 | |
| 70 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /******************************************************************************* |
| 74 | * |
| 75 | * FUNCTION: acpi_ev_valid_gpe_event |
| 76 | * |
| 77 | * PARAMETERS: gpe_event_info - Info for this GPE |
| 78 | * |
| 79 | * RETURN: TRUE if the gpe_event is valid |
| 80 | * |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 81 | * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * Should be called only when the GPE lists are semaphore locked |
| 83 | * and not subject to change. |
| 84 | * |
| 85 | ******************************************************************************/ |
| 86 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | struct acpi_gpe_xrupt_info *gpe_xrupt_block; |
| 90 | struct acpi_gpe_block_info *gpe_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* No need for spin lock since we are not changing any list elements */ |
| 95 | |
| 96 | /* Walk the GPE interrupt levels */ |
| 97 | |
| 98 | gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head; |
| 99 | while (gpe_xrupt_block) { |
| 100 | gpe_block = gpe_xrupt_block->gpe_block_list_head; |
| 101 | |
| 102 | /* Walk the GPE blocks on this interrupt level */ |
| 103 | |
| 104 | while (gpe_block) { |
| 105 | if ((&gpe_block->event_info[0] <= gpe_event_info) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | (&gpe_block-> |
| 107 | event_info[((acpi_size) gpe_block-> |
| 108 | register_count) * 8] > |
| 109 | gpe_event_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | return (TRUE); |
| 111 | } |
| 112 | |
| 113 | gpe_block = gpe_block->next; |
| 114 | } |
| 115 | |
| 116 | gpe_xrupt_block = gpe_xrupt_block->next; |
| 117 | } |
| 118 | |
| 119 | return (FALSE); |
| 120 | } |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /******************************************************************************* |
| 123 | * |
| 124 | * FUNCTION: acpi_ev_walk_gpe_list |
| 125 | * |
| 126 | * PARAMETERS: gpe_walk_callback - Routine called for each GPE block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | * |
| 128 | * RETURN: Status |
| 129 | * |
| 130 | * DESCRIPTION: Walk the GPE lists. |
| 131 | * |
| 132 | ******************************************************************************/ |
| 133 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | acpi_status acpi_ev_walk_gpe_list(ACPI_GPE_CALLBACK gpe_walk_callback) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | struct acpi_gpe_block_info *gpe_block; |
| 137 | struct acpi_gpe_xrupt_info *gpe_xrupt_info; |
| 138 | acpi_status status = AE_OK; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 139 | acpi_native_uint flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | ACPI_FUNCTION_TRACE("ev_walk_gpe_list"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* Walk the interrupt level descriptor list */ |
| 146 | |
| 147 | gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; |
| 148 | while (gpe_xrupt_info) { |
| 149 | /* Walk all Gpe Blocks attached to this interrupt level */ |
| 150 | |
| 151 | gpe_block = gpe_xrupt_info->gpe_block_list_head; |
| 152 | while (gpe_block) { |
| 153 | /* One callback per GPE block */ |
| 154 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | status = gpe_walk_callback(gpe_xrupt_info, gpe_block); |
| 156 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | goto unlock_and_exit; |
| 158 | } |
| 159 | |
| 160 | gpe_block = gpe_block->next; |
| 161 | } |
| 162 | |
| 163 | gpe_xrupt_info = gpe_xrupt_info->next; |
| 164 | } |
| 165 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | unlock_and_exit: |
| 167 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 168 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 171 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | * |
| 173 | * FUNCTION: acpi_ev_delete_gpe_handlers |
| 174 | * |
| 175 | * PARAMETERS: gpe_xrupt_info - GPE Interrupt info |
| 176 | * gpe_block - Gpe Block info |
| 177 | * |
| 178 | * RETURN: Status |
| 179 | * |
| 180 | * DESCRIPTION: Delete all Handler objects found in the GPE data structs. |
| 181 | * Used only prior to termination. |
| 182 | * |
| 183 | ******************************************************************************/ |
| 184 | |
| 185 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
| 187 | struct acpi_gpe_block_info *gpe_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | struct acpi_gpe_event_info *gpe_event_info; |
| 190 | acpi_native_uint i; |
| 191 | acpi_native_uint j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | ACPI_FUNCTION_TRACE("ev_delete_gpe_handlers"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | /* Examine each GPE Register within the block */ |
| 196 | |
| 197 | for (i = 0; i < gpe_block->register_count; i++) { |
| 198 | /* Now look at the individual GPEs in this byte register */ |
| 199 | |
| 200 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | gpe_event_info = |
| 202 | &gpe_block-> |
| 203 | event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 205 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | ACPI_GPE_DISPATCH_HANDLER) { |
| 207 | ACPI_MEM_FREE(gpe_event_info->dispatch.handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | gpe_event_info->dispatch.handler = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | gpe_event_info->flags &= |
| 210 | ~ACPI_GPE_DISPATCH_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /******************************************************************************* |
| 219 | * |
| 220 | * FUNCTION: acpi_ev_save_method_info |
| 221 | * |
| 222 | * PARAMETERS: Callback from walk_namespace |
| 223 | * |
| 224 | * RETURN: Status |
| 225 | * |
| 226 | * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a |
| 227 | * control method under the _GPE portion of the namespace. |
| 228 | * Extract the name and GPE type from the object, saving this |
| 229 | * information for quick lookup during GPE dispatch |
| 230 | * |
| 231 | * The name of each GPE control method is of the form: |
| 232 | * "_Lxx" or "_Exx" |
| 233 | * Where: |
| 234 | * L - means that the GPE is level triggered |
| 235 | * E - means that the GPE is edge triggered |
| 236 | * xx - is the GPE number [in HEX] |
| 237 | * |
| 238 | ******************************************************************************/ |
| 239 | |
| 240 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | acpi_ev_save_method_info(acpi_handle obj_handle, |
| 242 | u32 level, void *obj_desc, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | struct acpi_gpe_block_info *gpe_block = (void *)obj_desc; |
| 245 | struct acpi_gpe_event_info *gpe_event_info; |
| 246 | u32 gpe_number; |
| 247 | char name[ACPI_NAME_SIZE + 1]; |
| 248 | u8 type; |
| 249 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | ACPI_FUNCTION_TRACE("ev_save_method_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | /* |
| 254 | * _Lxx and _Exx GPE method support |
| 255 | * |
| 256 | * 1) Extract the name from the object and convert to a string |
| 257 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | ACPI_MOVE_32_TO_32(name, |
| 259 | &((struct acpi_namespace_node *)obj_handle)->name. |
| 260 | integer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | name[ACPI_NAME_SIZE] = 0; |
| 262 | |
| 263 | /* |
| 264 | * 2) Edge/Level determination is based on the 2nd character |
| 265 | * of the method name |
| 266 | * |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 267 | * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | * if a _PRW object is found that points to this GPE. |
| 269 | */ |
| 270 | switch (name[1]) { |
| 271 | case 'L': |
| 272 | type = ACPI_GPE_LEVEL_TRIGGERED; |
| 273 | break; |
| 274 | |
| 275 | case 'E': |
| 276 | type = ACPI_GPE_EDGE_TRIGGERED; |
| 277 | break; |
| 278 | |
| 279 | default: |
| 280 | /* Unknown method type, just ignore it! */ |
| 281 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 282 | ACPI_REPORT_ERROR(("Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n", name)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /* Convert the last two characters of the name to the GPE Number */ |
| 287 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | gpe_number = ACPI_STRTOUL(&name[2], NULL, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (gpe_number == ACPI_UINT32_MAX) { |
| 290 | /* Conversion failed; invalid method, just ignore it */ |
| 291 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 292 | ACPI_REPORT_ERROR(("Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n", name)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /* Ensure that we have a valid GPE number for this GPE block */ |
| 297 | |
| 298 | if ((gpe_number < gpe_block->block_base_number) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | (gpe_number >= |
| 300 | (gpe_block->block_base_number + |
| 301 | (gpe_block->register_count * 8)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | /* |
| 303 | * Not valid for this GPE block, just ignore it |
| 304 | * However, it may be valid for a different GPE block, since GPE0 and GPE1 |
| 305 | * methods both appear under \_GPE. |
| 306 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Now we can add this information to the gpe_event_info block |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 312 | * for use during dispatch of this GPE. Default type is RUNTIME, although |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | * this may change when the _PRW methods are executed later. |
| 314 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | gpe_event_info = |
| 316 | &gpe_block->event_info[gpe_number - gpe_block->block_base_number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 318 | gpe_event_info->flags = (u8) |
| 319 | (type | ACPI_GPE_DISPATCH_METHOD | ACPI_GPE_TYPE_RUNTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | gpe_event_info->dispatch.method_node = |
| 322 | (struct acpi_namespace_node *)obj_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | /* Update enable mask, but don't enable the HW GPE as of yet */ |
| 325 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 326 | status = acpi_ev_enable_gpe(gpe_event_info, FALSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | ACPI_DEBUG_PRINT((ACPI_DB_LOAD, |
| 329 | "Registered GPE method %s as GPE number 0x%.2X\n", |
| 330 | name, gpe_number)); |
| 331 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /******************************************************************************* |
| 335 | * |
| 336 | * FUNCTION: acpi_ev_match_prw_and_gpe |
| 337 | * |
| 338 | * PARAMETERS: Callback from walk_namespace |
| 339 | * |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 340 | * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | * not aborted on a single _PRW failure. |
| 342 | * |
| 343 | * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 344 | * Device. Run the _PRW method. If present, extract the GPE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | * number and mark the GPE as a WAKE GPE. |
| 346 | * |
| 347 | ******************************************************************************/ |
| 348 | |
| 349 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | acpi_ev_match_prw_and_gpe(acpi_handle obj_handle, |
| 351 | u32 level, void *info, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | struct acpi_gpe_walk_info *gpe_info = (void *)info; |
| 354 | struct acpi_namespace_node *gpe_device; |
| 355 | struct acpi_gpe_block_info *gpe_block; |
| 356 | struct acpi_namespace_node *target_gpe_device; |
| 357 | struct acpi_gpe_event_info *gpe_event_info; |
| 358 | union acpi_operand_object *pkg_desc; |
| 359 | union acpi_operand_object *obj_desc; |
| 360 | u32 gpe_number; |
| 361 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 363 | ACPI_FUNCTION_TRACE("ev_match_prw_and_gpe"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | /* Check for a _PRW method under this device */ |
| 366 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 367 | status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW, |
| 368 | ACPI_BTYPE_PACKAGE, &pkg_desc); |
| 369 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | /* Ignore all errors from _PRW, we don't want to abort the subsystem */ |
| 371 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /* The returned _PRW package must have at least two elements */ |
| 376 | |
| 377 | if (pkg_desc->package.count < 2) { |
| 378 | goto cleanup; |
| 379 | } |
| 380 | |
| 381 | /* Extract pointers from the input context */ |
| 382 | |
| 383 | gpe_device = gpe_info->gpe_device; |
| 384 | gpe_block = gpe_info->gpe_block; |
| 385 | |
| 386 | /* |
| 387 | * The _PRW object must return a package, we are only interested |
| 388 | * in the first element |
| 389 | */ |
| 390 | obj_desc = pkg_desc->package.elements[0]; |
| 391 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /* Use FADT-defined GPE device (from definition of _PRW) */ |
| 394 | |
| 395 | target_gpe_device = acpi_gbl_fadt_gpe_device; |
| 396 | |
| 397 | /* Integer is the GPE number in the FADT described GPE blocks */ |
| 398 | |
| 399 | gpe_number = (u32) obj_desc->integer.value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | } else if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | /* Package contains a GPE reference and GPE number within a GPE block */ |
| 402 | |
| 403 | if ((obj_desc->package.count < 2) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[0]) != |
| 405 | ACPI_TYPE_LOCAL_REFERENCE) |
| 406 | || (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[1]) != |
| 407 | ACPI_TYPE_INTEGER)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | goto cleanup; |
| 409 | } |
| 410 | |
| 411 | /* Get GPE block reference and decode */ |
| 412 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 413 | target_gpe_device = |
| 414 | obj_desc->package.elements[0]->reference.node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | gpe_number = (u32) obj_desc->package.elements[1]->integer.value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | /* Unknown type, just ignore it */ |
| 418 | |
| 419 | goto cleanup; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Is this GPE within this block? |
| 424 | * |
| 425 | * TRUE iff these conditions are true: |
| 426 | * 1) The GPE devices match. |
| 427 | * 2) The GPE index(number) is within the range of the Gpe Block |
| 428 | * associated with the GPE device. |
| 429 | */ |
| 430 | if ((gpe_device == target_gpe_device) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 431 | (gpe_number >= gpe_block->block_base_number) && |
| 432 | (gpe_number < |
| 433 | gpe_block->block_base_number + (gpe_block->register_count * 8))) { |
| 434 | gpe_event_info = |
| 435 | &gpe_block->event_info[gpe_number - |
| 436 | gpe_block->block_base_number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */ |
| 439 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | gpe_event_info->flags &= |
| 441 | ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 442 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 443 | status = |
| 444 | acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE); |
| 445 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | goto cleanup; |
| 447 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | status = |
| 449 | acpi_ev_update_gpe_enable_masks(gpe_event_info, |
| 450 | ACPI_GPE_DISABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 453 | cleanup: |
| 454 | acpi_ut_remove_reference(pkg_desc); |
| 455 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | /******************************************************************************* |
| 459 | * |
| 460 | * FUNCTION: acpi_ev_get_gpe_xrupt_block |
| 461 | * |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 462 | * PARAMETERS: interrupt_number - Interrupt for a GPE block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | * |
| 464 | * RETURN: A GPE interrupt block |
| 465 | * |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 466 | * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | * block per unique interrupt level used for GPEs. |
| 468 | * Should be called only when the GPE lists are semaphore locked |
| 469 | * and not subject to change. |
| 470 | * |
| 471 | ******************************************************************************/ |
| 472 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 473 | static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32 |
| 474 | interrupt_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 476 | struct acpi_gpe_xrupt_info *next_gpe_xrupt; |
| 477 | struct acpi_gpe_xrupt_info *gpe_xrupt; |
| 478 | acpi_status status; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 479 | acpi_native_uint flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | ACPI_FUNCTION_TRACE("ev_get_gpe_xrupt_block"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 483 | /* No need for lock since we are not changing any list elements here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head; |
| 486 | while (next_gpe_xrupt) { |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 487 | if (next_gpe_xrupt->interrupt_number == interrupt_number) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 488 | return_PTR(next_gpe_xrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | next_gpe_xrupt = next_gpe_xrupt->next; |
| 492 | } |
| 493 | |
| 494 | /* Not found, must allocate a new xrupt descriptor */ |
| 495 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | gpe_xrupt = ACPI_MEM_CALLOCATE(sizeof(struct acpi_gpe_xrupt_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | if (!gpe_xrupt) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 501 | gpe_xrupt->interrupt_number = interrupt_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | /* Install new interrupt descriptor with spin lock */ |
| 504 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | if (acpi_gbl_gpe_xrupt_list_head) { |
| 507 | next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head; |
| 508 | while (next_gpe_xrupt->next) { |
| 509 | next_gpe_xrupt = next_gpe_xrupt->next; |
| 510 | } |
| 511 | |
| 512 | next_gpe_xrupt->next = gpe_xrupt; |
| 513 | gpe_xrupt->previous = next_gpe_xrupt; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | acpi_gbl_gpe_xrupt_list_head = gpe_xrupt; |
| 516 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | /* Install new interrupt handler if not SCI_INT */ |
| 520 | |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 521 | if (interrupt_number != acpi_gbl_FADT->sci_int) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 522 | status = acpi_os_install_interrupt_handler(interrupt_number, |
| 523 | acpi_ev_gpe_xrupt_handler, |
| 524 | gpe_xrupt); |
| 525 | if (ACPI_FAILURE(status)) { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 526 | ACPI_REPORT_ERROR(("Could not install GPE interrupt handler at level 0x%X\n", interrupt_number)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 531 | return_PTR(gpe_xrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | /******************************************************************************* |
| 535 | * |
| 536 | * FUNCTION: acpi_ev_delete_gpe_xrupt |
| 537 | * |
| 538 | * PARAMETERS: gpe_xrupt - A GPE interrupt info block |
| 539 | * |
| 540 | * RETURN: Status |
| 541 | * |
| 542 | * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated |
| 543 | * interrupt handler if not the SCI interrupt. |
| 544 | * |
| 545 | ******************************************************************************/ |
| 546 | |
| 547 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 550 | acpi_status status; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 551 | acpi_native_uint flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 553 | ACPI_FUNCTION_TRACE("ev_delete_gpe_xrupt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | /* We never want to remove the SCI interrupt handler */ |
| 556 | |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 557 | if (gpe_xrupt->interrupt_number == acpi_gbl_FADT->sci_int) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | gpe_xrupt->gpe_block_list_head = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 559 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /* Disable this interrupt */ |
| 563 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 564 | status = |
| 565 | acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number, |
| 566 | acpi_ev_gpe_xrupt_handler); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | if (ACPI_FAILURE(status)) { |
| 568 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /* Unlink the interrupt block with lock */ |
| 572 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | if (gpe_xrupt->previous) { |
| 575 | gpe_xrupt->previous->next = gpe_xrupt->next; |
| 576 | } |
| 577 | |
| 578 | if (gpe_xrupt->next) { |
| 579 | gpe_xrupt->next->previous = gpe_xrupt->previous; |
| 580 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | /* Free the block */ |
| 584 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 585 | ACPI_MEM_FREE(gpe_xrupt); |
| 586 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /******************************************************************************* |
| 590 | * |
| 591 | * FUNCTION: acpi_ev_install_gpe_block |
| 592 | * |
| 593 | * PARAMETERS: gpe_block - New GPE block |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 594 | * interrupt_number - Xrupt to be associated with this GPE block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | * |
| 596 | * RETURN: Status |
| 597 | * |
| 598 | * DESCRIPTION: Install new GPE block with mutex support |
| 599 | * |
| 600 | ******************************************************************************/ |
| 601 | |
| 602 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 603 | acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block, |
| 604 | u32 interrupt_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 606 | struct acpi_gpe_block_info *next_gpe_block; |
| 607 | struct acpi_gpe_xrupt_info *gpe_xrupt_block; |
| 608 | acpi_status status; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 609 | acpi_native_uint flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 611 | ACPI_FUNCTION_TRACE("ev_install_gpe_block"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 613 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 614 | if (ACPI_FAILURE(status)) { |
| 615 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 618 | gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | if (!gpe_xrupt_block) { |
| 620 | status = AE_NO_MEMORY; |
| 621 | goto unlock_and_exit; |
| 622 | } |
| 623 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 624 | /* Install the new block at the end of the list with lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 626 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | if (gpe_xrupt_block->gpe_block_list_head) { |
| 628 | next_gpe_block = gpe_xrupt_block->gpe_block_list_head; |
| 629 | while (next_gpe_block->next) { |
| 630 | next_gpe_block = next_gpe_block->next; |
| 631 | } |
| 632 | |
| 633 | next_gpe_block->next = gpe_block; |
| 634 | gpe_block->previous = next_gpe_block; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 635 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | gpe_xrupt_block->gpe_block_list_head = gpe_block; |
| 637 | } |
| 638 | |
| 639 | gpe_block->xrupt_block = gpe_xrupt_block; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 642 | unlock_and_exit: |
| 643 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 644 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | /******************************************************************************* |
| 648 | * |
| 649 | * FUNCTION: acpi_ev_delete_gpe_block |
| 650 | * |
| 651 | * PARAMETERS: gpe_block - Existing GPE block |
| 652 | * |
| 653 | * RETURN: Status |
| 654 | * |
| 655 | * DESCRIPTION: Remove a GPE block |
| 656 | * |
| 657 | ******************************************************************************/ |
| 658 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 659 | acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 661 | acpi_status status; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 662 | acpi_native_uint flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 664 | ACPI_FUNCTION_TRACE("ev_install_gpe_block"); |
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 = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 667 | if (ACPI_FAILURE(status)) { |
| 668 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /* Disable all GPEs in this block */ |
| 672 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 673 | status = acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | if (!gpe_block->previous && !gpe_block->next) { |
| 676 | /* This is the last gpe_block on this interrupt */ |
| 677 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block); |
| 679 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | goto unlock_and_exit; |
| 681 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 682 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | /* Remove the block on this interrupt with lock */ |
| 684 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 685 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | if (gpe_block->previous) { |
| 687 | gpe_block->previous->next = gpe_block->next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 688 | } else { |
| 689 | gpe_block->xrupt_block->gpe_block_list_head = |
| 690 | gpe_block->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | if (gpe_block->next) { |
| 694 | gpe_block->next->previous = gpe_block->previous; |
| 695 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 696 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /* Free the gpe_block */ |
| 700 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | ACPI_MEM_FREE(gpe_block->register_info); |
| 702 | ACPI_MEM_FREE(gpe_block->event_info); |
| 703 | ACPI_MEM_FREE(gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 705 | unlock_and_exit: |
| 706 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 707 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | /******************************************************************************* |
| 711 | * |
| 712 | * FUNCTION: acpi_ev_create_gpe_info_blocks |
| 713 | * |
| 714 | * PARAMETERS: gpe_block - New GPE block |
| 715 | * |
| 716 | * RETURN: Status |
| 717 | * |
| 718 | * DESCRIPTION: Create the register_info and event_info blocks for this GPE block |
| 719 | * |
| 720 | ******************************************************************************/ |
| 721 | |
| 722 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 723 | acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block) |
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 | struct acpi_gpe_register_info *gpe_register_info = NULL; |
| 726 | struct acpi_gpe_event_info *gpe_event_info = NULL; |
| 727 | struct acpi_gpe_event_info *this_event; |
| 728 | struct acpi_gpe_register_info *this_register; |
| 729 | acpi_native_uint i; |
| 730 | acpi_native_uint j; |
| 731 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 733 | ACPI_FUNCTION_TRACE("ev_create_gpe_info_blocks"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | /* Allocate the GPE register information block */ |
| 736 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 737 | gpe_register_info = ACPI_MEM_CALLOCATE((acpi_size) gpe_block-> |
| 738 | register_count * |
| 739 | sizeof(struct |
| 740 | acpi_gpe_register_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | if (!gpe_register_info) { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 742 | ACPI_REPORT_ERROR(("Could not allocate the gpe_register_info table\n")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 743 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* |
| 747 | * Allocate the GPE event_info block. There are eight distinct GPEs |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 748 | * per register. Initialization to zeros is sufficient. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 750 | gpe_event_info = ACPI_MEM_CALLOCATE(((acpi_size) gpe_block-> |
| 751 | register_count * |
| 752 | ACPI_GPE_REGISTER_WIDTH) * |
| 753 | sizeof(struct acpi_gpe_event_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | if (!gpe_event_info) { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 755 | ACPI_REPORT_ERROR(("Could not allocate the gpe_event_info table\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | status = AE_NO_MEMORY; |
| 757 | goto error_exit; |
| 758 | } |
| 759 | |
| 760 | /* Save the new Info arrays in the GPE block */ |
| 761 | |
| 762 | gpe_block->register_info = gpe_register_info; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 763 | gpe_block->event_info = gpe_event_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | /* |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 766 | * Initialize the GPE Register and Event structures. A goal of these |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | * tables is to hide the fact that there are two separate GPE register sets |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 768 | * in a given GPE hardware block, the status registers occupy the first half, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | * and the enable registers occupy the second half. |
| 770 | */ |
| 771 | this_register = gpe_register_info; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 772 | this_event = gpe_event_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | for (i = 0; i < gpe_block->register_count; i++) { |
| 775 | /* Init the register_info for this GPE register (8 GPEs) */ |
| 776 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 777 | this_register->base_gpe_number = |
| 778 | (u8) (gpe_block->block_base_number + |
| 779 | (i * ACPI_GPE_REGISTER_WIDTH)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 781 | ACPI_STORE_ADDRESS(this_register->status_address.address, |
| 782 | (gpe_block->block_address.address + i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 784 | ACPI_STORE_ADDRESS(this_register->enable_address.address, |
| 785 | (gpe_block->block_address.address |
| 786 | + i + gpe_block->register_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 788 | this_register->status_address.address_space_id = |
| 789 | gpe_block->block_address.address_space_id; |
| 790 | this_register->enable_address.address_space_id = |
| 791 | gpe_block->block_address.address_space_id; |
| 792 | this_register->status_address.register_bit_width = |
| 793 | ACPI_GPE_REGISTER_WIDTH; |
| 794 | this_register->enable_address.register_bit_width = |
| 795 | ACPI_GPE_REGISTER_WIDTH; |
| 796 | this_register->status_address.register_bit_offset = |
| 797 | ACPI_GPE_REGISTER_WIDTH; |
| 798 | this_register->enable_address.register_bit_offset = |
| 799 | ACPI_GPE_REGISTER_WIDTH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
| 801 | /* Init the event_info for each GPE within this register */ |
| 802 | |
| 803 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { |
| 804 | this_event->register_bit = acpi_gbl_decode_to8bit[j]; |
| 805 | this_event->register_info = this_register; |
| 806 | this_event++; |
| 807 | } |
| 808 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 809 | /* Disable all GPEs within this register */ |
| 810 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 811 | status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0x00, |
| 812 | &this_register-> |
| 813 | enable_address); |
| 814 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | goto error_exit; |
| 816 | } |
| 817 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 818 | /* Clear any pending GPE events within this register */ |
| 819 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 820 | status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0xFF, |
| 821 | &this_register-> |
| 822 | status_address); |
| 823 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | goto error_exit; |
| 825 | } |
| 826 | |
| 827 | this_register++; |
| 828 | } |
| 829 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 830 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 832 | error_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | if (gpe_register_info) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 834 | ACPI_MEM_FREE(gpe_register_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
| 836 | if (gpe_event_info) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 837 | ACPI_MEM_FREE(gpe_event_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 840 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | /******************************************************************************* |
| 844 | * |
| 845 | * FUNCTION: acpi_ev_create_gpe_block |
| 846 | * |
| 847 | * PARAMETERS: gpe_device - Handle to the parent GPE block |
| 848 | * gpe_block_address - Address and space_iD |
| 849 | * register_count - Number of GPE register pairs in the block |
| 850 | * gpe_block_base_number - Starting GPE number for the block |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 851 | * interrupt_number - H/W interrupt for the block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | * return_gpe_block - Where the new block descriptor is returned |
| 853 | * |
| 854 | * RETURN: Status |
| 855 | * |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 856 | * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within |
| 857 | * the block are disabled at exit. |
| 858 | * Note: Assumes namespace is locked. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | * |
| 860 | ******************************************************************************/ |
| 861 | |
| 862 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 863 | acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device, |
| 864 | struct acpi_generic_address *gpe_block_address, |
| 865 | u32 register_count, |
| 866 | u8 gpe_block_base_number, |
| 867 | u32 interrupt_number, |
| 868 | struct acpi_gpe_block_info **return_gpe_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 870 | acpi_status status; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 871 | struct acpi_gpe_block_info *gpe_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 873 | ACPI_FUNCTION_TRACE("ev_create_gpe_block"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | if (!register_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 876 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /* Allocate a new GPE block */ |
| 880 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | gpe_block = ACPI_MEM_CALLOCATE(sizeof(struct acpi_gpe_block_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | if (!gpe_block) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 883 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /* Initialize the new GPE block */ |
| 887 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 888 | gpe_block->node = gpe_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | gpe_block->register_count = register_count; |
| 890 | gpe_block->block_base_number = gpe_block_base_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 892 | ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address, |
| 893 | sizeof(struct acpi_generic_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 895 | /* |
| 896 | * Create the register_info and event_info sub-structures |
| 897 | * Note: disables and clears all GPEs in the block |
| 898 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 899 | status = acpi_ev_create_gpe_info_blocks(gpe_block); |
| 900 | if (ACPI_FAILURE(status)) { |
| 901 | ACPI_MEM_FREE(gpe_block); |
| 902 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 905 | /* Install the new block in the global lists */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 907 | status = acpi_ev_install_gpe_block(gpe_block, interrupt_number); |
| 908 | if (ACPI_FAILURE(status)) { |
| 909 | ACPI_MEM_FREE(gpe_block); |
| 910 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /* Find all GPE methods (_Lxx, _Exx) for this block */ |
| 914 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 915 | status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device, |
| 916 | ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, |
| 917 | acpi_ev_save_method_info, gpe_block, |
| 918 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 920 | /* Return the new block */ |
| 921 | |
| 922 | if (return_gpe_block) { |
| 923 | (*return_gpe_block) = gpe_block; |
| 924 | } |
| 925 | |
| 926 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 927 | "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n", |
| 928 | (u32) gpe_block->block_base_number, |
| 929 | (u32) (gpe_block->block_base_number + |
| 930 | ((gpe_block->register_count * |
| 931 | ACPI_GPE_REGISTER_WIDTH) - 1)), |
| 932 | gpe_device->name.ascii, gpe_block->register_count, |
| 933 | interrupt_number)); |
| 934 | |
| 935 | return_ACPI_STATUS(AE_OK); |
| 936 | } |
| 937 | |
| 938 | /******************************************************************************* |
| 939 | * |
| 940 | * FUNCTION: acpi_ev_initialize_gpe_block |
| 941 | * |
| 942 | * PARAMETERS: gpe_device - Handle to the parent GPE block |
| 943 | * gpe_block - Gpe Block info |
| 944 | * |
| 945 | * RETURN: Status |
| 946 | * |
| 947 | * DESCRIPTION: Initialize and enable a GPE block. First find and run any |
| 948 | * _PRT methods associated with the block, then enable the |
| 949 | * appropriate GPEs. |
| 950 | * Note: Assumes namespace is locked. |
| 951 | * |
| 952 | ******************************************************************************/ |
| 953 | |
| 954 | acpi_status |
| 955 | acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device, |
| 956 | struct acpi_gpe_block_info *gpe_block) |
| 957 | { |
| 958 | acpi_status status; |
| 959 | struct acpi_gpe_event_info *gpe_event_info; |
| 960 | struct acpi_gpe_walk_info gpe_info; |
| 961 | u32 wake_gpe_count; |
| 962 | u32 gpe_enabled_count; |
| 963 | acpi_native_uint i; |
| 964 | acpi_native_uint j; |
| 965 | |
| 966 | ACPI_FUNCTION_TRACE("ev_initialize_gpe_block"); |
| 967 | |
| 968 | /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */ |
| 969 | |
| 970 | if (!gpe_block) { |
| 971 | return_ACPI_STATUS(AE_OK); |
| 972 | } |
| 973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | /* |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 975 | * Runtime option: Should wake GPEs be enabled at runtime? The default |
| 976 | * is no, they should only be enabled just as the machine goes to sleep. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | */ |
| 978 | if (acpi_gbl_leave_wake_gpes_disabled) { |
| 979 | /* |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 980 | * Differentiate runtime vs wake GPEs, via the _PRW control methods. |
| 981 | * Each GPE that has one or more _PRWs that reference it is by |
| 982 | * definition a wake GPE and will not be enabled while the machine |
| 983 | * is running. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | */ |
| 985 | gpe_info.gpe_block = gpe_block; |
| 986 | gpe_info.gpe_device = gpe_device; |
| 987 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 988 | status = |
| 989 | acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
| 990 | ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, |
| 991 | acpi_ev_match_prw_and_gpe, &gpe_info, |
| 992 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /* |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 996 | * Enable all GPEs in this block that have these attributes: |
| 997 | * 1) are "runtime" or "run/wake" GPEs, and |
| 998 | * 2) have a corresponding _Lxx or _Exx method |
| 999 | * |
| 1000 | * Any other GPEs within this block must be enabled via the acpi_enable_gpe() |
| 1001 | * external interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | */ |
| 1003 | wake_gpe_count = 0; |
| 1004 | gpe_enabled_count = 0; |
| 1005 | |
| 1006 | for (i = 0; i < gpe_block->register_count; i++) { |
| 1007 | for (j = 0; j < 8; j++) { |
| 1008 | /* Get the info block for this particular GPE */ |
| 1009 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1010 | gpe_event_info = |
| 1011 | &gpe_block-> |
| 1012 | event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1014 | if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 1015 | ACPI_GPE_DISPATCH_METHOD) |
| 1016 | && (gpe_event_info-> |
| 1017 | flags & ACPI_GPE_TYPE_RUNTIME)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | gpe_enabled_count++; |
| 1019 | } |
| 1020 | |
| 1021 | if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) { |
| 1022 | wake_gpe_count++; |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1027 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 1028 | "Found %u Wake, Enabled %u Runtime GPEs in this block\n", |
| 1029 | wake_gpe_count, gpe_enabled_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 1031 | /* Enable all valid runtime GPEs found above */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 1033 | status = acpi_hw_enable_runtime_gpe_block(NULL, gpe_block); |
| 1034 | if (ACPI_FAILURE(status)) { |
| 1035 | ACPI_REPORT_ERROR(("Could not enable GPEs in gpe_block %p\n", |
| 1036 | gpe_block)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 1039 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | /******************************************************************************* |
| 1043 | * |
| 1044 | * FUNCTION: acpi_ev_gpe_initialize |
| 1045 | * |
| 1046 | * PARAMETERS: None |
| 1047 | * |
| 1048 | * RETURN: Status |
| 1049 | * |
| 1050 | * DESCRIPTION: Initialize the GPE data structures |
| 1051 | * |
| 1052 | ******************************************************************************/ |
| 1053 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1054 | acpi_status acpi_ev_gpe_initialize(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1056 | u32 register_count0 = 0; |
| 1057 | u32 register_count1 = 0; |
| 1058 | u32 gpe_number_max = 0; |
| 1059 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1061 | ACPI_FUNCTION_TRACE("ev_gpe_initialize"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1063 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 1064 | if (ACPI_FAILURE(status)) { |
| 1065 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | * Initialize the GPE Block(s) defined in the FADT |
| 1070 | * |
| 1071 | * Why the GPE register block lengths are divided by 2: From the ACPI Spec, |
| 1072 | * section "General-Purpose Event Registers", we have: |
| 1073 | * |
| 1074 | * "Each register block contains two registers of equal length |
| 1075 | * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the |
| 1076 | * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN |
| 1077 | * The length of the GPE1_STS and GPE1_EN registers is equal to |
| 1078 | * half the GPE1_LEN. If a generic register block is not supported |
| 1079 | * then its respective block pointer and block length values in the |
| 1080 | * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need |
| 1081 | * to be the same size." |
| 1082 | */ |
| 1083 | |
| 1084 | /* |
| 1085 | * Determine the maximum GPE number for this machine. |
| 1086 | * |
| 1087 | * Note: both GPE0 and GPE1 are optional, and either can exist without |
| 1088 | * the other. |
| 1089 | * |
| 1090 | * If EITHER the register length OR the block address are zero, then that |
| 1091 | * particular block is not supported. |
| 1092 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1093 | if (acpi_gbl_FADT->gpe0_blk_len && acpi_gbl_FADT->xgpe0_blk.address) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | /* GPE block 0 exists (has both length and address > 0) */ |
| 1095 | |
| 1096 | register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2); |
| 1097 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1098 | gpe_number_max = |
| 1099 | (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* Install GPE Block 0 */ |
| 1102 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1103 | status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device, |
| 1104 | &acpi_gbl_FADT->xgpe0_blk, |
| 1105 | register_count0, 0, |
| 1106 | acpi_gbl_FADT->sci_int, |
| 1107 | &acpi_gbl_gpe_fadt_blocks[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1109 | if (ACPI_FAILURE(status)) { |
| 1110 | ACPI_REPORT_ERROR(("Could not create GPE Block 0, %s\n", |
| 1111 | acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1115 | if (acpi_gbl_FADT->gpe1_blk_len && acpi_gbl_FADT->xgpe1_blk.address) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | /* GPE block 1 exists (has both length and address > 0) */ |
| 1117 | |
| 1118 | register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2); |
| 1119 | |
| 1120 | /* Check for GPE0/GPE1 overlap (if both banks exist) */ |
| 1121 | |
| 1122 | if ((register_count0) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1123 | (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) { |
| 1124 | ACPI_REPORT_ERROR(("GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n", gpe_number_max, acpi_gbl_FADT->gpe1_base, acpi_gbl_FADT->gpe1_base + ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* Ignore GPE1 block by setting the register count to zero */ |
| 1127 | |
| 1128 | register_count1 = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1129 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | /* Install GPE Block 1 */ |
| 1131 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1132 | status = |
| 1133 | acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device, |
| 1134 | &acpi_gbl_FADT->xgpe1_blk, |
| 1135 | register_count1, |
| 1136 | acpi_gbl_FADT->gpe1_base, |
| 1137 | acpi_gbl_FADT->sci_int, |
| 1138 | &acpi_gbl_gpe_fadt_blocks |
| 1139 | [1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1141 | if (ACPI_FAILURE(status)) { |
| 1142 | ACPI_REPORT_ERROR(("Could not create GPE Block 1, %s\n", acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /* |
| 1146 | * GPE0 and GPE1 do not have to be contiguous in the GPE number |
| 1147 | * space. However, GPE0 always starts at GPE number zero. |
| 1148 | */ |
| 1149 | gpe_number_max = acpi_gbl_FADT->gpe1_base + |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1150 | ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | /* Exit if there are no GPE registers */ |
| 1155 | |
| 1156 | if ((register_count0 + register_count1) == 0) { |
| 1157 | /* GPEs are not required by ACPI, this is OK */ |
| 1158 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1159 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 1160 | "There are no GPE blocks defined in the FADT\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | status = AE_OK; |
| 1162 | goto cleanup; |
| 1163 | } |
| 1164 | |
| 1165 | /* Check for Max GPE number out-of-range */ |
| 1166 | |
| 1167 | if (gpe_number_max > ACPI_GPE_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1168 | ACPI_REPORT_ERROR(("Maximum GPE number from FADT is too large: 0x%X\n", gpe_number_max)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | status = AE_BAD_VALUE; |
| 1170 | goto cleanup; |
| 1171 | } |
| 1172 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1173 | cleanup: |
| 1174 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 1175 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |