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