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 | fbb7a2d | 2014-02-08 09:42:25 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2014, 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") |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 51 | #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ |
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 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block, |
| 55 | u32 interrupt_number); |
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_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /******************************************************************************* |
| 61 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * FUNCTION: acpi_ev_install_gpe_block |
| 63 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 64 | * PARAMETERS: gpe_block - New GPE block |
| 65 | * interrupt_number - Xrupt to be associated with this |
| 66 | * GPE block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | * |
| 68 | * RETURN: Status |
| 69 | * |
| 70 | * DESCRIPTION: Install new GPE block with mutex support |
| 71 | * |
| 72 | ******************************************************************************/ |
| 73 | |
| 74 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block, |
| 76 | u32 interrupt_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | struct acpi_gpe_block_info *next_gpe_block; |
| 79 | struct acpi_gpe_xrupt_info *gpe_xrupt_block; |
| 80 | acpi_status status; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 81 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 83 | ACPI_FUNCTION_TRACE(ev_install_gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 86 | if (ACPI_FAILURE(status)) { |
| 87 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Bob Moore | 4bec3d8 | 2014-01-08 13:44:10 +0800 | [diff] [blame] | 90 | status = |
| 91 | acpi_ev_get_gpe_xrupt_block(interrupt_number, &gpe_xrupt_block); |
| 92 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | goto unlock_and_exit; |
| 94 | } |
| 95 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 96 | /* Install the new block at the end of the list with lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (gpe_xrupt_block->gpe_block_list_head) { |
| 100 | next_gpe_block = gpe_xrupt_block->gpe_block_list_head; |
| 101 | while (next_gpe_block->next) { |
| 102 | next_gpe_block = next_gpe_block->next; |
| 103 | } |
| 104 | |
| 105 | next_gpe_block->next = gpe_block; |
| 106 | gpe_block->previous = next_gpe_block; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | gpe_xrupt_block->gpe_block_list_head = gpe_block; |
| 109 | } |
| 110 | |
| 111 | gpe_block->xrupt_block = gpe_xrupt_block; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 114 | unlock_and_exit: |
Bob Moore | 4bec3d8 | 2014-01-08 13:44:10 +0800 | [diff] [blame] | 115 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /******************************************************************************* |
| 120 | * |
| 121 | * FUNCTION: acpi_ev_delete_gpe_block |
| 122 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 123 | * PARAMETERS: gpe_block - Existing GPE block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * |
| 125 | * RETURN: Status |
| 126 | * |
| 127 | * DESCRIPTION: Remove a GPE block |
| 128 | * |
| 129 | ******************************************************************************/ |
| 130 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | 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] | 132 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | acpi_status status; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 134 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 136 | ACPI_FUNCTION_TRACE(ev_install_gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 139 | if (ACPI_FAILURE(status)) { |
| 140 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* Disable all GPEs in this block */ |
| 144 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 145 | status = |
| 146 | acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | if (!gpe_block->previous && !gpe_block->next) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* This is the last gpe_block on this interrupt */ |
| 151 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block); |
| 153 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | goto unlock_and_exit; |
| 155 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* Remove the block on this interrupt with lock */ |
| 158 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (gpe_block->previous) { |
| 161 | gpe_block->previous->next = gpe_block->next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | } else { |
| 163 | gpe_block->xrupt_block->gpe_block_list_head = |
| 164 | gpe_block->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | if (gpe_block->next) { |
| 168 | gpe_block->next->previous = gpe_block->previous; |
| 169 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 173 | acpi_current_gpe_count -= gpe_block->gpe_count; |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /* Free the gpe_block */ |
| 176 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 177 | ACPI_FREE(gpe_block->register_info); |
| 178 | ACPI_FREE(gpe_block->event_info); |
| 179 | ACPI_FREE(gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 181 | unlock_and_exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 183 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /******************************************************************************* |
| 187 | * |
| 188 | * FUNCTION: acpi_ev_create_gpe_info_blocks |
| 189 | * |
| 190 | * PARAMETERS: gpe_block - New GPE block |
| 191 | * |
| 192 | * RETURN: Status |
| 193 | * |
| 194 | * DESCRIPTION: Create the register_info and event_info blocks for this GPE block |
| 195 | * |
| 196 | ******************************************************************************/ |
| 197 | |
| 198 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | 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] | 200 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | struct acpi_gpe_register_info *gpe_register_info = NULL; |
| 202 | struct acpi_gpe_event_info *gpe_event_info = NULL; |
| 203 | struct acpi_gpe_event_info *this_event; |
| 204 | struct acpi_gpe_register_info *this_register; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 205 | u32 i; |
| 206 | u32 j; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 209 | ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* Allocate the GPE register information block */ |
| 212 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 213 | gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block-> |
| 214 | register_count * |
| 215 | sizeof(struct |
| 216 | acpi_gpe_register_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | if (!gpe_register_info) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 218 | ACPI_ERROR((AE_INFO, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 219 | "Could not allocate the GpeRegisterInfo table")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Allocate the GPE event_info block. There are eight distinct GPEs |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 225 | * per register. Initialization to zeros is sufficient. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | */ |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 227 | gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count * |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 228 | sizeof(struct |
| 229 | acpi_gpe_event_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if (!gpe_event_info) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 231 | ACPI_ERROR((AE_INFO, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 232 | "Could not allocate the GpeEventInfo table")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | status = AE_NO_MEMORY; |
| 234 | goto error_exit; |
| 235 | } |
| 236 | |
| 237 | /* Save the new Info arrays in the GPE block */ |
| 238 | |
| 239 | gpe_block->register_info = gpe_register_info; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | gpe_block->event_info = gpe_event_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 243 | * Initialize the GPE Register and Event structures. A goal of these |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 244 | * tables is to hide the fact that there are two separate GPE register |
| 245 | * sets in a given GPE hardware block, the status registers occupy the |
| 246 | * first half, and the enable registers occupy the second half. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | */ |
| 248 | this_register = gpe_register_info; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | this_event = gpe_event_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | for (i = 0; i < gpe_block->register_count; i++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | /* Init the register_info for this GPE register (8 GPEs) */ |
| 254 | |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 255 | this_register->base_gpe_number = (u16) |
| 256 | (gpe_block->block_base_number + |
| 257 | (i * ACPI_GPE_REGISTER_WIDTH)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 259 | this_register->status_address.address = gpe_block->address + i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Bob Moore | 59fa850 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 261 | this_register->enable_address.address = |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 262 | gpe_block->address + i + gpe_block->register_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 264 | this_register->status_address.space_id = gpe_block->space_id; |
| 265 | this_register->enable_address.space_id = gpe_block->space_id; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 266 | this_register->status_address.bit_width = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | ACPI_GPE_REGISTER_WIDTH; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 268 | this_register->enable_address.bit_width = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | ACPI_GPE_REGISTER_WIDTH; |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 270 | this_register->status_address.bit_offset = 0; |
| 271 | this_register->enable_address.bit_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
| 273 | /* Init the event_info for each GPE within this register */ |
| 274 | |
| 275 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { |
Alexey Starikovskiy | 6987416 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 276 | this_event->gpe_number = |
| 277 | (u8) (this_register->base_gpe_number + j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | this_event->register_info = this_register; |
| 279 | this_event++; |
| 280 | } |
| 281 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 282 | /* Disable all GPEs within this register */ |
| 283 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 284 | status = acpi_hw_write(0x00, &this_register->enable_address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | goto error_exit; |
| 287 | } |
| 288 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 289 | /* Clear any pending GPE events within this register */ |
| 290 | |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 291 | status = acpi_hw_write(0xFF, &this_register->status_address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 292 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | goto error_exit; |
| 294 | } |
| 295 | |
| 296 | this_register++; |
| 297 | } |
| 298 | |
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 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 301 | error_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (gpe_register_info) { |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 303 | ACPI_FREE(gpe_register_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | if (gpe_event_info) { |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 306 | ACPI_FREE(gpe_event_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | /******************************************************************************* |
| 313 | * |
| 314 | * FUNCTION: acpi_ev_create_gpe_block |
| 315 | * |
| 316 | * PARAMETERS: gpe_device - Handle to the parent GPE block |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 317 | * gpe_block_address - Address and space_ID |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | * register_count - Number of GPE register pairs in the block |
| 319 | * gpe_block_base_number - Starting GPE number for the block |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 320 | * interrupt_number - H/W interrupt for the block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | * return_gpe_block - Where the new block descriptor is returned |
| 322 | * |
| 323 | * RETURN: Status |
| 324 | * |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 325 | * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within |
| 326 | * the block are disabled at exit. |
| 327 | * Note: Assumes namespace is locked. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * |
| 329 | ******************************************************************************/ |
| 330 | |
| 331 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device, |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 333 | u64 address, |
| 334 | u8 space_id, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | u32 register_count, |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 336 | u16 gpe_block_base_number, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | u32 interrupt_number, |
| 338 | struct acpi_gpe_block_info **return_gpe_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | acpi_status status; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 341 | struct acpi_gpe_block_info *gpe_block; |
Bob Moore | 186c307 | 2010-04-27 11:32:28 +0800 | [diff] [blame] | 342 | struct acpi_gpe_walk_info walk_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 344 | ACPI_FUNCTION_TRACE(ev_create_gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | if (!register_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* Allocate a new GPE block */ |
| 351 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 352 | gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (!gpe_block) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /* Initialize the new GPE block */ |
| 358 | |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 359 | gpe_block->address = address; |
| 360 | gpe_block->space_id = space_id; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 361 | gpe_block->node = gpe_device; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 362 | gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH); |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 363 | gpe_block->initialized = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | gpe_block->register_count = register_count; |
| 365 | gpe_block->block_base_number = gpe_block_base_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 367 | /* |
| 368 | * Create the register_info and event_info sub-structures |
| 369 | * Note: disables and clears all GPEs in the block |
| 370 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | status = acpi_ev_create_gpe_info_blocks(gpe_block); |
| 372 | if (ACPI_FAILURE(status)) { |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 373 | ACPI_FREE(gpe_block); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 377 | /* Install the new block in the global lists */ |
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 | status = acpi_ev_install_gpe_block(gpe_block, interrupt_number); |
| 380 | if (ACPI_FAILURE(status)) { |
Tomasz Nowicki | b739f10 | 2013-06-08 01:00:07 +0000 | [diff] [blame] | 381 | ACPI_FREE(gpe_block->register_info); |
| 382 | ACPI_FREE(gpe_block->event_info); |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 383 | ACPI_FREE(gpe_block); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 387 | acpi_gbl_all_gpes_initialized = FALSE; |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 388 | |
Bob Moore | 186c307 | 2010-04-27 11:32:28 +0800 | [diff] [blame] | 389 | /* Find all GPE methods (_Lxx or_Exx) for this block */ |
| 390 | |
| 391 | walk_info.gpe_block = gpe_block; |
| 392 | walk_info.gpe_device = gpe_device; |
Bob Moore | 186c307 | 2010-04-27 11:32:28 +0800 | [diff] [blame] | 393 | walk_info.execute_by_owner_id = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device, |
| 396 | ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 397 | acpi_ev_match_gpe_method, NULL, |
Bob Moore | 186c307 | 2010-04-27 11:32:28 +0800 | [diff] [blame] | 398 | &walk_info, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 400 | /* Return the new block */ |
| 401 | |
| 402 | if (return_gpe_block) { |
| 403 | (*return_gpe_block) = gpe_block; |
| 404 | } |
| 405 | |
Bob Moore | 3e5621a | 2012-12-31 00:07:13 +0000 | [diff] [blame] | 406 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 407 | " Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n", |
Bob Moore | 3e5621a | 2012-12-31 00:07:13 +0000 | [diff] [blame] | 408 | (u32)gpe_block->block_base_number, |
| 409 | (u32)(gpe_block->block_base_number + |
| 410 | (gpe_block->gpe_count - 1)), |
| 411 | gpe_device->name.ascii, gpe_block->register_count, |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame^] | 412 | interrupt_number, |
| 413 | interrupt_number == |
| 414 | acpi_gbl_FADT.sci_interrupt ? " (SCI)" : "")); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 415 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 416 | /* Update global count of currently available GPEs */ |
| 417 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 418 | acpi_current_gpe_count += gpe_block->gpe_count; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 419 | return_ACPI_STATUS(AE_OK); |
| 420 | } |
| 421 | |
| 422 | /******************************************************************************* |
| 423 | * |
| 424 | * FUNCTION: acpi_ev_initialize_gpe_block |
| 425 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 426 | * PARAMETERS: acpi_gpe_callback |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 427 | * |
| 428 | * RETURN: Status |
| 429 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 430 | * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have |
| 431 | * associated methods. |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 432 | * Note: Assumes namespace is locked. |
| 433 | * |
| 434 | ******************************************************************************/ |
| 435 | |
| 436 | acpi_status |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 437 | acpi_ev_initialize_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
| 438 | struct acpi_gpe_block_info *gpe_block, |
| 439 | void *ignored) |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 440 | { |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 441 | acpi_status status; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 442 | struct acpi_gpe_event_info *gpe_event_info; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 443 | u32 gpe_enabled_count; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 444 | u32 gpe_index; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 445 | u32 i; |
| 446 | u32 j; |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 447 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 448 | ACPI_FUNCTION_TRACE(ev_initialize_gpe_block); |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 449 | |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 450 | /* |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 451 | * Ignore a null GPE block (e.g., if no GPE block 1 exists), and |
| 452 | * any GPE blocks that have been initialized already. |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 453 | */ |
| 454 | if (!gpe_block || gpe_block->initialized) { |
Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 455 | return_ACPI_STATUS(AE_OK); |
| 456 | } |
| 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | /* |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 459 | * Enable all GPEs that have a corresponding method and have the |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 460 | * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block |
| 461 | * must be enabled via the acpi_enable_gpe() interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | gpe_enabled_count = 0; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | for (i = 0; i < gpe_block->register_count; i++) { |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 466 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | /* Get the info block for this particular GPE */ |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 469 | |
| 470 | gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j; |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 471 | gpe_event_info = &gpe_block->event_info[gpe_index]; |
Rafael J. Wysocki | ce43ace | 2010-06-08 10:50:20 +0200 | [diff] [blame] | 472 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 473 | /* |
| 474 | * Ignore GPEs that have no corresponding _Lxx/_Exx method |
| 475 | * and GPEs that are used to wake the system |
| 476 | */ |
| 477 | if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 478 | ACPI_GPE_DISPATCH_NONE) |
| 479 | || ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) |
| 480 | == ACPI_GPE_DISPATCH_HANDLER) |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 481 | || (gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) { |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 482 | continue; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 483 | } |
| 484 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 485 | status = acpi_ev_add_gpe_reference(gpe_event_info); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 486 | if (ACPI_FAILURE(status)) { |
| 487 | ACPI_EXCEPTION((AE_INFO, status, |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 488 | "Could not enable GPE 0x%02X", |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 489 | gpe_index + |
| 490 | gpe_block->block_base_number)); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 491 | continue; |
| 492 | } |
| 493 | |
| 494 | gpe_enabled_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
Rafael J. Wysocki | 9874647 | 2010-07-08 00:43:36 +0200 | [diff] [blame] | 498 | if (gpe_enabled_count) { |
Bob Moore | 3e5621a | 2012-12-31 00:07:13 +0000 | [diff] [blame] | 499 | ACPI_INFO((AE_INFO, |
| 500 | "Enabled %u GPEs in block %02X to %02X", |
| 501 | gpe_enabled_count, (u32)gpe_block->block_base_number, |
| 502 | (u32)(gpe_block->block_base_number + |
| 503 | (gpe_block->gpe_count - 1)))); |
Bob Moore | 186c307 | 2010-04-27 11:32:28 +0800 | [diff] [blame] | 504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 506 | gpe_block->initialized = TRUE; |
| 507 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 508 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 510 | |
| 511 | #endif /* !ACPI_REDUCED_HARDWARE */ |