blob: 447fa1cac64fdb3c3bdde2f3199e0ae326a8d953 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evgpeblk - GPE block creation and initialization.
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evgpeblk")
Bob Moore33620c52012-02-14 18:14:27 +080051#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040053static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040054acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
55 u32 interrupt_number);
Robert Moore44f6c012005-04-18 22:49:35 -040056
57static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040058acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*******************************************************************************
61 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * FUNCTION: acpi_ev_install_gpe_block
63 *
Bob Moore9f15fc62008-11-12 16:01:56 +080064 * PARAMETERS: gpe_block - New GPE block
65 * interrupt_number - Xrupt to be associated with this
66 * GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Install new GPE block with mutex support
71 *
72 ******************************************************************************/
73
74static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040075acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
76 u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Len Brown4be44fc2005-08-05 00:44:28 -040078 struct acpi_gpe_block_info *next_gpe_block;
79 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
80 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -050081 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Bob Mooreb229cf92006-04-21 17:15:00 -040083 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Len Brown4be44fc2005-08-05 00:44:28 -040085 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
86 if (ACPI_FAILURE(status)) {
87 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
Bob Moore4bec3d82014-01-08 13:44:10 +080090 status =
91 acpi_ev_get_gpe_xrupt_block(interrupt_number, &gpe_xrupt_block);
92 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 goto unlock_and_exit;
94 }
95
Robert Moore44f6c012005-04-18 22:49:35 -040096 /* Install the new block at the end of the list with lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Len Brown4be44fc2005-08-05 00:44:28 -040098 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 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 Brown4be44fc2005-08-05 00:44:28 -0400107 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 gpe_xrupt_block->gpe_block_list_head = gpe_block;
109 }
110
111 gpe_block->xrupt_block = gpe_xrupt_block;
Len Brown4be44fc2005-08-05 00:44:28 -0400112 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Lv Zheng10622bf2013-10-29 09:30:02 +0800114unlock_and_exit:
Bob Moore4bec3d82014-01-08 13:44:10 +0800115 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Len Brown4be44fc2005-08-05 00:44:28 -0400116 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/*******************************************************************************
120 *
121 * FUNCTION: acpi_ev_delete_gpe_block
122 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800123 * PARAMETERS: gpe_block - Existing GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *
125 * RETURN: Status
126 *
127 * DESCRIPTION: Remove a GPE block
128 *
129 ******************************************************************************/
130
Len Brown4be44fc2005-08-05 00:44:28 -0400131acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Len Brown4be44fc2005-08-05 00:44:28 -0400133 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500134 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Bob Mooreb229cf92006-04-21 17:15:00 -0400136 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Len Brown4be44fc2005-08-05 00:44:28 -0400138 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
139 if (ACPI_FAILURE(status)) {
140 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142
143 /* Disable all GPEs in this block */
144
Bob Mooree97d6bf2008-12-30 09:45:17 +0800145 status =
146 acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 if (!gpe_block->previous && !gpe_block->next) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /* This is the last gpe_block on this interrupt */
151
Len Brown4be44fc2005-08-05 00:44:28 -0400152 status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
153 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 goto unlock_and_exit;
155 }
Len Brown4be44fc2005-08-05 00:44:28 -0400156 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /* Remove the block on this interrupt with lock */
158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (gpe_block->previous) {
161 gpe_block->previous->next = gpe_block->next;
Len Brown4be44fc2005-08-05 00:44:28 -0400162 } else {
163 gpe_block->xrupt_block->gpe_block_list_head =
164 gpe_block->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
167 if (gpe_block->next) {
168 gpe_block->next->previous = gpe_block->previous;
169 }
Bob Moore1fad8732015-12-29 13:54:36 +0800170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
Lin Ming0f849d22010-04-06 14:52:37 +0800174 acpi_current_gpe_count -= gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +0800175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 /* Free the gpe_block */
177
Bob Moore83135242006-10-03 00:00:00 -0400178 ACPI_FREE(gpe_block->register_info);
179 ACPI_FREE(gpe_block->event_info);
180 ACPI_FREE(gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Lv Zheng10622bf2013-10-29 09:30:02 +0800182unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
184 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/*******************************************************************************
188 *
189 * FUNCTION: acpi_ev_create_gpe_info_blocks
190 *
191 * PARAMETERS: gpe_block - New GPE block
192 *
193 * RETURN: Status
194 *
195 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
196 *
197 ******************************************************************************/
198
199static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400200acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Len Brown4be44fc2005-08-05 00:44:28 -0400202 struct acpi_gpe_register_info *gpe_register_info = NULL;
203 struct acpi_gpe_event_info *gpe_event_info = NULL;
204 struct acpi_gpe_event_info *this_event;
205 struct acpi_gpe_register_info *this_register;
Bob Moore67a119f2008-06-10 13:42:13 +0800206 u32 i;
207 u32 j;
Len Brown4be44fc2005-08-05 00:44:28 -0400208 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Mooreb229cf92006-04-21 17:15:00 -0400210 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 /* Allocate the GPE register information block */
213
Bob Moore83135242006-10-03 00:00:00 -0400214 gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
215 register_count *
216 sizeof(struct
217 acpi_gpe_register_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 if (!gpe_register_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500219 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400220 "Could not allocate the GpeRegisterInfo table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400221 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223
224 /*
225 * Allocate the GPE event_info block. There are eight distinct GPEs
Bob Moore96db2552005-11-02 00:00:00 -0500226 * per register. Initialization to zeros is sufficient.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 */
Lin Ming0f849d22010-04-06 14:52:37 +0800228 gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
Bob Moore83135242006-10-03 00:00:00 -0400229 sizeof(struct
230 acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 if (!gpe_event_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500232 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400233 "Could not allocate the GpeEventInfo table"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 status = AE_NO_MEMORY;
235 goto error_exit;
236 }
237
238 /* Save the new Info arrays in the GPE block */
239
240 gpe_block->register_info = gpe_register_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400241 gpe_block->event_info = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 /*
Bob Moore96db2552005-11-02 00:00:00 -0500244 * Initialize the GPE Register and Event structures. A goal of these
Bob Moore9f15fc62008-11-12 16:01:56 +0800245 * tables is to hide the fact that there are two separate GPE register
246 * sets in a given GPE hardware block, the status registers occupy the
247 * first half, and the enable registers occupy the second half.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 */
249 this_register = gpe_register_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400250 this_event = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 /* Init the register_info for this GPE register (8 GPEs) */
255
Bob Moore7505da42014-04-30 10:06:15 +0800256 this_register->base_gpe_number = (u16)
257 (gpe_block->block_base_number +
258 (i * ACPI_GPE_REGISTER_WIDTH));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Bob Moore7505da42014-04-30 10:06:15 +0800260 this_register->status_address.address = gpe_block->address + i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Bob Moore59fa8502007-02-02 19:48:23 +0300262 this_register->enable_address.address =
Bob Moore7505da42014-04-30 10:06:15 +0800263 gpe_block->address + i + gpe_block->register_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Bob Moore7505da42014-04-30 10:06:15 +0800265 this_register->status_address.space_id = gpe_block->space_id;
266 this_register->enable_address.space_id = gpe_block->space_id;
Bob Mooref3d2e782007-02-02 19:48:18 +0300267 this_register->status_address.bit_width =
Len Brown4be44fc2005-08-05 00:44:28 -0400268 ACPI_GPE_REGISTER_WIDTH;
Bob Mooref3d2e782007-02-02 19:48:18 +0300269 this_register->enable_address.bit_width =
Len Brown4be44fc2005-08-05 00:44:28 -0400270 ACPI_GPE_REGISTER_WIDTH;
Bob Mooreecfbbc72008-12-31 02:55:32 +0800271 this_register->status_address.bit_offset = 0;
272 this_register->enable_address.bit_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 /* Init the event_info for each GPE within this register */
275
276 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300277 this_event->gpe_number =
278 (u8) (this_register->base_gpe_number + j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 this_event->register_info = this_register;
280 this_event++;
281 }
282
Bob Moore96db2552005-11-02 00:00:00 -0500283 /* Disable all GPEs within this register */
284
Bob Moorec6b57742009-06-24 09:44:06 +0800285 status = acpi_hw_write(0x00, &this_register->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400286 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 goto error_exit;
288 }
289
Bob Moore96db2552005-11-02 00:00:00 -0500290 /* Clear any pending GPE events within this register */
291
Bob Moorec6b57742009-06-24 09:44:06 +0800292 status = acpi_hw_write(0xFF, &this_register->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400293 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 goto error_exit;
295 }
296
297 this_register++;
298 }
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Lv Zheng10622bf2013-10-29 09:30:02 +0800302error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 if (gpe_register_info) {
Bob Moore83135242006-10-03 00:00:00 -0400304 ACPI_FREE(gpe_register_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306 if (gpe_event_info) {
Bob Moore83135242006-10-03 00:00:00 -0400307 ACPI_FREE(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
309
Len Brown4be44fc2005-08-05 00:44:28 -0400310 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313/*******************************************************************************
314 *
315 * FUNCTION: acpi_ev_create_gpe_block
316 *
317 * PARAMETERS: gpe_device - Handle to the parent GPE block
Bob Mooreba494be2012-07-12 09:40:10 +0800318 * gpe_block_address - Address and space_ID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 * register_count - Number of GPE register pairs in the block
320 * gpe_block_base_number - Starting GPE number for the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400321 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * return_gpe_block - Where the new block descriptor is returned
323 *
324 * RETURN: Status
325 *
Bob Moore96db2552005-11-02 00:00:00 -0500326 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
327 * the block are disabled at exit.
328 * Note: Assumes namespace is locked.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 *
330 ******************************************************************************/
331
332acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400333acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
Bob Moore7505da42014-04-30 10:06:15 +0800334 u64 address,
335 u8 space_id,
Len Brown4be44fc2005-08-05 00:44:28 -0400336 u32 register_count,
Bob Moore7505da42014-04-30 10:06:15 +0800337 u16 gpe_block_base_number,
Len Brown4be44fc2005-08-05 00:44:28 -0400338 u32 interrupt_number,
339 struct acpi_gpe_block_info **return_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Len Brown4be44fc2005-08-05 00:44:28 -0400341 acpi_status status;
Bob Moore96db2552005-11-02 00:00:00 -0500342 struct acpi_gpe_block_info *gpe_block;
Bob Moore186c3072010-04-27 11:32:28 +0800343 struct acpi_gpe_walk_info walk_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Bob Mooreb229cf92006-04-21 17:15:00 -0400345 ACPI_FUNCTION_TRACE(ev_create_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if (!register_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400348 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
351 /* Allocate a new GPE block */
352
Bob Moore83135242006-10-03 00:00:00 -0400353 gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (!gpe_block) {
Len Brown4be44fc2005-08-05 00:44:28 -0400355 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 /* Initialize the new GPE block */
359
Bob Moore7505da42014-04-30 10:06:15 +0800360 gpe_block->address = address;
361 gpe_block->space_id = space_id;
Bob Moore96db2552005-11-02 00:00:00 -0500362 gpe_block->node = gpe_device;
Lin Ming0f849d22010-04-06 14:52:37 +0800363 gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
Lin Mingda503372010-12-13 13:39:37 +0800364 gpe_block->initialized = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 gpe_block->register_count = register_count;
366 gpe_block->block_base_number = gpe_block_base_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Bob Moore96db2552005-11-02 00:00:00 -0500368 /*
369 * Create the register_info and event_info sub-structures
370 * Note: disables and clears all GPEs in the block
371 */
Len Brown4be44fc2005-08-05 00:44:28 -0400372 status = acpi_ev_create_gpe_info_blocks(gpe_block);
373 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400374 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400375 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
Bob Moore96db2552005-11-02 00:00:00 -0500378 /* Install the new block in the global lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Len Brown4be44fc2005-08-05 00:44:28 -0400380 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
381 if (ACPI_FAILURE(status)) {
Tomasz Nowickib739f102013-06-08 01:00:07 +0000382 ACPI_FREE(gpe_block->register_info);
383 ACPI_FREE(gpe_block->event_info);
Bob Moore83135242006-10-03 00:00:00 -0400384 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400385 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
387
Lin Ming3a378982010-12-13 13:36:15 +0800388 acpi_gbl_all_gpes_initialized = FALSE;
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200389
Bob Moore186c3072010-04-27 11:32:28 +0800390 /* Find all GPE methods (_Lxx or_Exx) for this block */
391
392 walk_info.gpe_block = gpe_block;
393 walk_info.gpe_device = gpe_device;
Bob Moore186c3072010-04-27 11:32:28 +0800394 walk_info.execute_by_owner_id = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
397 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
Lin Ming0f849d22010-04-06 14:52:37 +0800398 acpi_ev_match_gpe_method, NULL,
Bob Moore186c3072010-04-27 11:32:28 +0800399 &walk_info, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Bob Moore96db2552005-11-02 00:00:00 -0500401 /* Return the new block */
402
403 if (return_gpe_block) {
404 (*return_gpe_block) = gpe_block;
405 }
406
Bob Moore3e5621a2012-12-31 00:07:13 +0000407 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
Bob Moore7505da42014-04-30 10:06:15 +0800408 " Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n",
Bob Moore3e5621a2012-12-31 00:07:13 +0000409 (u32)gpe_block->block_base_number,
410 (u32)(gpe_block->block_base_number +
411 (gpe_block->gpe_count - 1)),
412 gpe_device->name.ascii, gpe_block->register_count,
Bob Moore7505da42014-04-30 10:06:15 +0800413 interrupt_number,
414 interrupt_number ==
415 acpi_gbl_FADT.sci_interrupt ? " (SCI)" : ""));
Bob Moore96db2552005-11-02 00:00:00 -0500416
Bob Mooree97d6bf2008-12-30 09:45:17 +0800417 /* Update global count of currently available GPEs */
418
Lin Ming0f849d22010-04-06 14:52:37 +0800419 acpi_current_gpe_count += gpe_block->gpe_count;
Bob Moore96db2552005-11-02 00:00:00 -0500420 return_ACPI_STATUS(AE_OK);
421}
422
423/*******************************************************************************
424 *
425 * FUNCTION: acpi_ev_initialize_gpe_block
426 *
Lin Mingda503372010-12-13 13:39:37 +0800427 * PARAMETERS: acpi_gpe_callback
Bob Moore96db2552005-11-02 00:00:00 -0500428 *
429 * RETURN: Status
430 *
Lin Mingda503372010-12-13 13:39:37 +0800431 * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
432 * associated methods.
Bob Moore96db2552005-11-02 00:00:00 -0500433 * Note: Assumes namespace is locked.
434 *
435 ******************************************************************************/
436
437acpi_status
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200438acpi_ev_initialize_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
439 struct acpi_gpe_block_info *gpe_block,
440 void *ignored)
Bob Moore96db2552005-11-02 00:00:00 -0500441{
Lin Ming0f849d22010-04-06 14:52:37 +0800442 acpi_status status;
Bob Moore96db2552005-11-02 00:00:00 -0500443 struct acpi_gpe_event_info *gpe_event_info;
Bob Moore96db2552005-11-02 00:00:00 -0500444 u32 gpe_enabled_count;
Lin Ming0f849d22010-04-06 14:52:37 +0800445 u32 gpe_index;
Bob Moore67a119f2008-06-10 13:42:13 +0800446 u32 i;
447 u32 j;
Bob Moore96db2552005-11-02 00:00:00 -0500448
Bob Mooreb229cf92006-04-21 17:15:00 -0400449 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
Bob Moore96db2552005-11-02 00:00:00 -0500450
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200451 /*
Lin Mingda503372010-12-13 13:39:37 +0800452 * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
453 * any GPE blocks that have been initialized already.
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200454 */
455 if (!gpe_block || gpe_block->initialized) {
Bob Moore96db2552005-11-02 00:00:00 -0500456 return_ACPI_STATUS(AE_OK);
457 }
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 /*
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200460 * Enable all GPEs that have a corresponding method and have the
Lin Mingda503372010-12-13 13:39:37 +0800461 * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
462 * must be enabled via the acpi_enable_gpe() interface.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 gpe_enabled_count = 0;
Lin Ming0f849d22010-04-06 14:52:37 +0800465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 for (i = 0; i < gpe_block->register_count; i++) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100467 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 /* Get the info block for this particular GPE */
Lin Ming0f849d22010-04-06 14:52:37 +0800470
471 gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100472 gpe_event_info = &gpe_block->event_info[gpe_index];
Rafael J. Wysockice43ace2010-06-08 10:50:20 +0200473
Lin Mingbba63a22010-12-13 13:39:17 +0800474 /*
475 * Ignore GPEs that have no corresponding _Lxx/_Exx method
476 * and GPEs that are used to wake the system
477 */
Lv Zheng7c433122015-02-05 15:20:29 +0800478 if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
Lin Mingbba63a22010-12-13 13:39:17 +0800479 ACPI_GPE_DISPATCH_NONE)
Lv Zheng7c433122015-02-05 15:20:29 +0800480 || (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
481 ACPI_GPE_DISPATCH_HANDLER)
Lv Zheng0d0988a2015-02-05 16:27:03 +0800482 || (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
483 ACPI_GPE_DISPATCH_RAW_HANDLER)
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200484 || (gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100485 continue;
Lin Ming0f849d22010-04-06 14:52:37 +0800486 }
487
Lin Ming3a378982010-12-13 13:36:15 +0800488 status = acpi_ev_add_gpe_reference(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800489 if (ACPI_FAILURE(status)) {
490 ACPI_EXCEPTION((AE_INFO, status,
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200491 "Could not enable GPE 0x%02X",
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000492 gpe_index +
493 gpe_block->block_base_number));
Lin Ming0f849d22010-04-06 14:52:37 +0800494 continue;
495 }
496
497 gpe_enabled_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499 }
500
Rafael J. Wysocki98746472010-07-08 00:43:36 +0200501 if (gpe_enabled_count) {
Bob Moore05fb04b2016-02-19 14:16:42 +0800502 ACPI_INFO(("Enabled %u GPEs in block %02X to %02X",
Bob Moore3e5621a2012-12-31 00:07:13 +0000503 gpe_enabled_count, (u32)gpe_block->block_base_number,
504 (u32)(gpe_block->block_base_number +
505 (gpe_block->gpe_count - 1))));
Bob Moore186c3072010-04-27 11:32:28 +0800506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200508 gpe_block->initialized = TRUE;
509
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100510 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
Bob Moore33620c52012-02-14 18:14:27 +0800512
513#endif /* !ACPI_REDUCED_HARDWARE */