1 /******************************************************************************
3 * Module Name: evgpeutil - GPE utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME("evgpeutil")
51 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
52 /*******************************************************************************
54 * FUNCTION: acpi_ev_walk_gpe_list
56 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
57 * Context - Value passed to callback
61 * DESCRIPTION: Walk the GPE lists.
63 ******************************************************************************/
65 acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback
, void *context
)
67 struct acpi_gpe_block_info
*gpe_block
;
68 struct acpi_gpe_xrupt_info
*gpe_xrupt_info
;
69 acpi_status status
= AE_OK
;
72 ACPI_FUNCTION_TRACE(ev_walk_gpe_list
);
74 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
76 /* Walk the interrupt level descriptor list */
78 gpe_xrupt_info
= acpi_gbl_gpe_xrupt_list_head
;
79 while (gpe_xrupt_info
) {
81 /* Walk all Gpe Blocks attached to this interrupt level */
83 gpe_block
= gpe_xrupt_info
->gpe_block_list_head
;
86 /* One callback per GPE block */
89 gpe_walk_callback(gpe_xrupt_info
, gpe_block
,
91 if (ACPI_FAILURE(status
)) {
92 if (status
== AE_CTRL_END
) { /* Callback abort */
98 gpe_block
= gpe_block
->next
;
101 gpe_xrupt_info
= gpe_xrupt_info
->next
;
105 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
106 return_ACPI_STATUS(status
);
109 /*******************************************************************************
111 * FUNCTION: acpi_ev_valid_gpe_event
113 * PARAMETERS: gpe_event_info - Info for this GPE
115 * RETURN: TRUE if the gpe_event is valid
117 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
118 * Should be called only when the GPE lists are semaphore locked
119 * and not subject to change.
121 ******************************************************************************/
123 u8
acpi_ev_valid_gpe_event(struct acpi_gpe_event_info
*gpe_event_info
)
125 struct acpi_gpe_xrupt_info
*gpe_xrupt_block
;
126 struct acpi_gpe_block_info
*gpe_block
;
128 ACPI_FUNCTION_ENTRY();
130 /* No need for spin lock since we are not changing any list elements */
132 /* Walk the GPE interrupt levels */
134 gpe_xrupt_block
= acpi_gbl_gpe_xrupt_list_head
;
135 while (gpe_xrupt_block
) {
136 gpe_block
= gpe_xrupt_block
->gpe_block_list_head
;
138 /* Walk the GPE blocks on this interrupt level */
141 if ((&gpe_block
->event_info
[0] <= gpe_event_info
) &&
142 (&gpe_block
->event_info
[gpe_block
->gpe_count
] >
147 gpe_block
= gpe_block
->next
;
150 gpe_xrupt_block
= gpe_xrupt_block
->next
;
156 /*******************************************************************************
158 * FUNCTION: acpi_ev_get_gpe_device
160 * PARAMETERS: GPE_WALK_CALLBACK
164 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
165 * block device. NULL if the GPE is one of the FADT-defined GPEs.
167 ******************************************************************************/
170 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
171 struct acpi_gpe_block_info
*gpe_block
, void *context
)
173 struct acpi_gpe_device_info
*info
= context
;
175 /* Increment Index by the number of GPEs in this block */
177 info
->next_block_base_index
+= gpe_block
->gpe_count
;
179 if (info
->index
< info
->next_block_base_index
) {
181 * The GPE index is within this block, get the node. Leave the node
182 * NULL for the FADT-defined GPEs
184 if ((gpe_block
->node
)->type
== ACPI_TYPE_DEVICE
) {
185 info
->gpe_device
= gpe_block
->node
;
188 info
->status
= AE_OK
;
189 return (AE_CTRL_END
);
195 /*******************************************************************************
197 * FUNCTION: acpi_ev_get_gpe_xrupt_block
199 * PARAMETERS: interrupt_number - Interrupt for a GPE block
201 * RETURN: A GPE interrupt block
203 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
204 * block per unique interrupt level used for GPEs. Should be
205 * called only when the GPE lists are semaphore locked and not
208 ******************************************************************************/
210 struct acpi_gpe_xrupt_info
*acpi_ev_get_gpe_xrupt_block(u32 interrupt_number
)
212 struct acpi_gpe_xrupt_info
*next_gpe_xrupt
;
213 struct acpi_gpe_xrupt_info
*gpe_xrupt
;
215 acpi_cpu_flags flags
;
217 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block
);
219 /* No need for lock since we are not changing any list elements here */
221 next_gpe_xrupt
= acpi_gbl_gpe_xrupt_list_head
;
222 while (next_gpe_xrupt
) {
223 if (next_gpe_xrupt
->interrupt_number
== interrupt_number
) {
224 return_PTR(next_gpe_xrupt
);
227 next_gpe_xrupt
= next_gpe_xrupt
->next
;
230 /* Not found, must allocate a new xrupt descriptor */
232 gpe_xrupt
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info
));
237 gpe_xrupt
->interrupt_number
= interrupt_number
;
239 /* Install new interrupt descriptor with spin lock */
241 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
242 if (acpi_gbl_gpe_xrupt_list_head
) {
243 next_gpe_xrupt
= acpi_gbl_gpe_xrupt_list_head
;
244 while (next_gpe_xrupt
->next
) {
245 next_gpe_xrupt
= next_gpe_xrupt
->next
;
248 next_gpe_xrupt
->next
= gpe_xrupt
;
249 gpe_xrupt
->previous
= next_gpe_xrupt
;
251 acpi_gbl_gpe_xrupt_list_head
= gpe_xrupt
;
253 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
255 /* Install new interrupt handler if not SCI_INT */
257 if (interrupt_number
!= acpi_gbl_FADT
.sci_interrupt
) {
258 status
= acpi_os_install_interrupt_handler(interrupt_number
,
259 acpi_ev_gpe_xrupt_handler
,
261 if (ACPI_FAILURE(status
)) {
263 "Could not install GPE interrupt handler at level 0x%X",
269 return_PTR(gpe_xrupt
);
272 /*******************************************************************************
274 * FUNCTION: acpi_ev_delete_gpe_xrupt
276 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
280 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
281 * interrupt handler if not the SCI interrupt.
283 ******************************************************************************/
285 acpi_status
acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info
*gpe_xrupt
)
288 acpi_cpu_flags flags
;
290 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt
);
292 /* We never want to remove the SCI interrupt handler */
294 if (gpe_xrupt
->interrupt_number
== acpi_gbl_FADT
.sci_interrupt
) {
295 gpe_xrupt
->gpe_block_list_head
= NULL
;
296 return_ACPI_STATUS(AE_OK
);
299 /* Disable this interrupt */
302 acpi_os_remove_interrupt_handler(gpe_xrupt
->interrupt_number
,
303 acpi_ev_gpe_xrupt_handler
);
304 if (ACPI_FAILURE(status
)) {
305 return_ACPI_STATUS(status
);
308 /* Unlink the interrupt block with lock */
310 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
311 if (gpe_xrupt
->previous
) {
312 gpe_xrupt
->previous
->next
= gpe_xrupt
->next
;
314 /* No previous, update list head */
316 acpi_gbl_gpe_xrupt_list_head
= gpe_xrupt
->next
;
319 if (gpe_xrupt
->next
) {
320 gpe_xrupt
->next
->previous
= gpe_xrupt
->previous
;
322 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
326 ACPI_FREE(gpe_xrupt
);
327 return_ACPI_STATUS(AE_OK
);
330 /*******************************************************************************
332 * FUNCTION: acpi_ev_delete_gpe_handlers
334 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
335 * gpe_block - Gpe Block info
339 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
340 * Used only prior to termination.
342 ******************************************************************************/
345 acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
346 struct acpi_gpe_block_info
*gpe_block
,
349 struct acpi_gpe_event_info
*gpe_event_info
;
353 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers
);
355 /* Examine each GPE Register within the block */
357 for (i
= 0; i
< gpe_block
->register_count
; i
++) {
359 /* Now look at the individual GPEs in this byte register */
361 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++) {
362 gpe_event_info
= &gpe_block
->event_info
[((acpi_size
) i
*
363 ACPI_GPE_REGISTER_WIDTH
)
366 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
367 ACPI_GPE_DISPATCH_HANDLER
) {
368 ACPI_FREE(gpe_event_info
->dispatch
.handler
);
369 gpe_event_info
->dispatch
.handler
= NULL
;
370 gpe_event_info
->flags
&=
371 ~ACPI_GPE_DISPATCH_MASK
;
376 return_ACPI_STATUS(AE_OK
);
379 #endif /* !ACPI_REDUCED_HARDWARE */