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