Linux Audio

Check our new training course

Loading...
v3.1
 
  1/******************************************************************************
  2 *
  3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
  4 *
 
 
  5 *****************************************************************************/
  6
  7/*
  8 * Copyright (C) 2000 - 2011, Intel Corp.
  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>
 45#include "accommon.h"
 46#include "acevents.h"
 47#include "acnamesp.h"
 48
 49#define _COMPONENT          ACPI_EVENTS
 50ACPI_MODULE_NAME("evxfgpe")
 51
 52/******************************************************************************
 
 53 *
 54 * FUNCTION:    acpi_update_all_gpes
 55 *
 56 * PARAMETERS:  None
 57 *
 58 * RETURN:      Status
 59 *
 60 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
 61 *              associated _Lxx or _Exx methods and are not pointed to by any
 62 *              device _PRW methods (this indicates that these GPEs are
 63 *              generally intended for system or device wakeup. Such GPEs
 64 *              have to be enabled directly when the devices whose _PRW
 65 *              methods point to them are set up for wakeup signaling.)
 66 *
 67 * NOTE: Should be called after any GPEs are added to the system. Primarily,
 68 * after the system _PRW methods have been run, but also after a GPE Block
 69 * Device has been added or if any new GPE methods have been added via a
 70 * dynamic table load.
 71 *
 72 ******************************************************************************/
 73
 74acpi_status acpi_update_all_gpes(void)
 75{
 76	acpi_status status;
 
 77
 78	ACPI_FUNCTION_TRACE(acpi_update_all_gpes);
 79
 80	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
 81	if (ACPI_FAILURE(status)) {
 82		return_ACPI_STATUS(status);
 83	}
 84
 85	if (acpi_gbl_all_gpes_initialized) {
 86		goto unlock_and_exit;
 87	}
 88
 89	status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL);
 
 90	if (ACPI_SUCCESS(status)) {
 91		acpi_gbl_all_gpes_initialized = TRUE;
 92	}
 93
 94unlock_and_exit:
 95	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 96
 
 
 
 
 
 
 97	return_ACPI_STATUS(status);
 98}
 99
100ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)
101
102/*******************************************************************************
103 *
104 * FUNCTION:    acpi_enable_gpe
105 *
106 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
107 *              gpe_number      - GPE level within the GPE block
108 *
109 * RETURN:      Status
110 *
111 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
112 *              hardware-enabled.
113 *
114 ******************************************************************************/
115
116acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
117{
118	acpi_status status = AE_BAD_PARAMETER;
119	struct acpi_gpe_event_info *gpe_event_info;
120	acpi_cpu_flags flags;
121
122	ACPI_FUNCTION_TRACE(acpi_enable_gpe);
123
124	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
125
126	/* Ensure that we have a valid GPE number */
127
 
 
 
128	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
129	if (gpe_event_info) {
130		status = acpi_ev_add_gpe_reference(gpe_event_info);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131	}
132
133	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
134	return_ACPI_STATUS(status);
135}
136ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
137
138/*******************************************************************************
139 *
140 * FUNCTION:    acpi_disable_gpe
141 *
142 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
143 *              gpe_number      - GPE level within the GPE block
144 *
145 * RETURN:      Status
146 *
147 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
148 *              removed, only then is the GPE disabled (for runtime GPEs), or
149 *              the GPE mask bit disabled (for wake GPEs)
150 *
151 ******************************************************************************/
152
153acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
154{
155	acpi_status status = AE_BAD_PARAMETER;
156	struct acpi_gpe_event_info *gpe_event_info;
157	acpi_cpu_flags flags;
158
159	ACPI_FUNCTION_TRACE(acpi_disable_gpe);
160
161	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
162
163	/* Ensure that we have a valid GPE number */
164
165	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
166	if (gpe_event_info) {
167		status = acpi_ev_remove_gpe_reference(gpe_event_info) ;
168	}
169
170	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
171	return_ACPI_STATUS(status);
172}
 
173ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
176/*******************************************************************************
177 *
178 * FUNCTION:    acpi_setup_gpe_for_wake
179 *
180 * PARAMETERS:  wake_device         - Device associated with the GPE (via _PRW)
181 *              gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
182 *              gpe_number          - GPE level within the GPE block
183 *
184 * RETURN:      Status
185 *
186 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
187 *              interface is intended to be used as the host executes the
188 *              _PRW methods (Power Resources for Wake) in the system tables.
189 *              Each _PRW appears under a Device Object (The wake_device), and
190 *              contains the info for the wake GPE associated with the
191 *              wake_device.
192 *
193 ******************************************************************************/
194acpi_status
195acpi_setup_gpe_for_wake(acpi_handle wake_device,
196			acpi_handle gpe_device, u32 gpe_number)
197{
198	acpi_status status = AE_BAD_PARAMETER;
199	struct acpi_gpe_event_info *gpe_event_info;
200	struct acpi_namespace_node *device_node;
201	struct acpi_gpe_notify_object *notify_object;
 
202	acpi_cpu_flags flags;
203	u8 gpe_dispatch_mask;
204
205	ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
206
207	/* Parameter Validation */
208
209	if (!wake_device) {
210		/*
211		 * By forcing wake_device to be valid, we automatically enable the
212		 * implicit notify feature on all hosts.
213		 */
214		return_ACPI_STATUS(AE_BAD_PARAMETER);
215	}
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
218
219	/* Ensure that we have a valid GPE number */
220
221	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
222	if (!gpe_event_info) {
 
223		goto unlock_and_exit;
224	}
225
226	if (wake_device == ACPI_ROOT_OBJECT) {
227		goto out;
228	}
229
230	/*
231	 * If there is no method or handler for this GPE, then the
232	 * wake_device will be notified whenever this GPE fires (aka
233	 * "implicit notify") Note: The GPE is assumed to be
234	 * level-triggered (for windows compatibility).
235	 */
236	gpe_dispatch_mask = gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK;
237	if (gpe_dispatch_mask != ACPI_GPE_DISPATCH_NONE
238	    && gpe_dispatch_mask != ACPI_GPE_DISPATCH_NOTIFY) {
239		goto out;
 
 
 
 
 
 
 
 
 
 
 
 
240	}
241
242	/* Validate wake_device is of type Device */
243
244	device_node = ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
245	if (device_node->type != ACPI_TYPE_DEVICE) {
246		goto unlock_and_exit;
247	}
248
249	if (gpe_dispatch_mask == ACPI_GPE_DISPATCH_NONE) {
250		gpe_event_info->flags = (ACPI_GPE_DISPATCH_NOTIFY |
251					 ACPI_GPE_LEVEL_TRIGGERED);
252		gpe_event_info->dispatch.device.node = device_node;
253		gpe_event_info->dispatch.device.next = NULL;
254	} else {
255		/* There are multiple devices to notify implicitly. */
256
257		notify_object = ACPI_ALLOCATE_ZEROED(sizeof(*notify_object));
258		if (!notify_object) {
259			status = AE_NO_MEMORY;
260			goto unlock_and_exit;
 
 
 
261		}
262
263		notify_object->node = device_node;
264		notify_object->next = gpe_event_info->dispatch.device.next;
265		gpe_event_info->dispatch.device.next = notify_object;
 
 
 
266	}
267
268 out:
 
269	gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
270	status = AE_OK;
271
272 unlock_and_exit:
273	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 
 
 
 
 
 
274	return_ACPI_STATUS(status);
275}
276ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
277
278/*******************************************************************************
279 *
280 * FUNCTION:    acpi_set_gpe_wake_mask
281 *
282 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
283 *              gpe_number      - GPE level within the GPE block
284 *              Action          - Enable or Disable
285 *
286 * RETURN:      Status
287 *
288 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
289 *              already be marked as a WAKE GPE.
290 *
291 ******************************************************************************/
292
293acpi_status acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
 
294{
295	acpi_status status = AE_OK;
296	struct acpi_gpe_event_info *gpe_event_info;
297	struct acpi_gpe_register_info *gpe_register_info;
298	acpi_cpu_flags flags;
299	u32 register_bit;
300
301	ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
302
303	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
304
305	/*
306	 * Ensure that we have a valid GPE number and that this GPE is in
307	 * fact a wake GPE
308	 */
309	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
310	if (!gpe_event_info) {
311		status = AE_BAD_PARAMETER;
312		goto unlock_and_exit;
313	}
314
315	if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
316		status = AE_TYPE;
317		goto unlock_and_exit;
318	}
319
320	gpe_register_info = gpe_event_info->register_info;
321	if (!gpe_register_info) {
322		status = AE_NOT_EXIST;
323		goto unlock_and_exit;
324	}
325
326	register_bit =
327	    acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
328
329	/* Perform the action */
330
331	switch (action) {
332	case ACPI_GPE_ENABLE:
 
333		ACPI_SET_BIT(gpe_register_info->enable_for_wake,
334			     (u8)register_bit);
335		break;
336
337	case ACPI_GPE_DISABLE:
 
338		ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
339			       (u8)register_bit);
340		break;
341
342	default:
 
343		ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
344		status = AE_BAD_PARAMETER;
345		break;
346	}
347
348unlock_and_exit:
349	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
350	return_ACPI_STATUS(status);
351}
352
353ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
354
355/*******************************************************************************
356 *
357 * FUNCTION:    acpi_clear_gpe
358 *
359 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
360 *              gpe_number      - GPE level within the GPE block
361 *
362 * RETURN:      Status
363 *
364 * DESCRIPTION: Clear an ACPI event (general purpose)
365 *
366 ******************************************************************************/
367acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
368{
369	acpi_status status = AE_OK;
370	struct acpi_gpe_event_info *gpe_event_info;
371	acpi_cpu_flags flags;
372
373	ACPI_FUNCTION_TRACE(acpi_clear_gpe);
374
375	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
376
377	/* Ensure that we have a valid GPE number */
378
379	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
380	if (!gpe_event_info) {
381		status = AE_BAD_PARAMETER;
382		goto unlock_and_exit;
383	}
384
385	status = acpi_hw_clear_gpe(gpe_event_info);
386
387      unlock_and_exit:
388	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
389	return_ACPI_STATUS(status);
390}
391
392ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
393
394/*******************************************************************************
395 *
396 * FUNCTION:    acpi_get_gpe_status
397 *
398 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
399 *              gpe_number      - GPE level within the GPE block
400 *              event_status    - Where the current status of the event will
401 *                                be returned
402 *
403 * RETURN:      Status
404 *
405 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
406 *
407 ******************************************************************************/
408acpi_status
409acpi_get_gpe_status(acpi_handle gpe_device,
410		    u32 gpe_number, acpi_event_status *event_status)
411{
412	acpi_status status = AE_OK;
413	struct acpi_gpe_event_info *gpe_event_info;
414	acpi_cpu_flags flags;
415
416	ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
417
418	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
419
420	/* Ensure that we have a valid GPE number */
421
422	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
423	if (!gpe_event_info) {
424		status = AE_BAD_PARAMETER;
425		goto unlock_and_exit;
426	}
427
428	/* Obtain status on the requested GPE number */
429
430	status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
431
432	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
433		*event_status |= ACPI_EVENT_FLAG_HANDLE;
434
435      unlock_and_exit:
436	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
437	return_ACPI_STATUS(status);
438}
439
440ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
441
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442/******************************************************************************
443 *
444 * FUNCTION:    acpi_disable_all_gpes
445 *
446 * PARAMETERS:  None
447 *
448 * RETURN:      Status
449 *
450 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
451 *
452 ******************************************************************************/
453
454acpi_status acpi_disable_all_gpes(void)
455{
456	acpi_status status;
457
458	ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
459
460	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
461	if (ACPI_FAILURE(status)) {
462		return_ACPI_STATUS(status);
463	}
464
465	status = acpi_hw_disable_all_gpes();
466	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
467
468	return_ACPI_STATUS(status);
469}
470
471ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
472
473/******************************************************************************
474 *
475 * FUNCTION:    acpi_enable_all_runtime_gpes
476 *
477 * PARAMETERS:  None
478 *
479 * RETURN:      Status
480 *
481 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
482 *
483 ******************************************************************************/
484
485acpi_status acpi_enable_all_runtime_gpes(void)
486{
487	acpi_status status;
488
489	ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
490
491	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
492	if (ACPI_FAILURE(status)) {
493		return_ACPI_STATUS(status);
494	}
495
496	status = acpi_hw_enable_all_runtime_gpes();
497	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
498
499	return_ACPI_STATUS(status);
500}
501
502ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504/*******************************************************************************
505 *
506 * FUNCTION:    acpi_install_gpe_block
507 *
508 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
509 *              gpe_block_address   - Address and space_iD
510 *              register_count      - Number of GPE register pairs in the block
511 *              interrupt_number    - H/W interrupt for the block
512 *
513 * RETURN:      Status
514 *
515 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
516 *              enabled here.
517 *
518 ******************************************************************************/
519acpi_status
520acpi_install_gpe_block(acpi_handle gpe_device,
521		       struct acpi_generic_address *gpe_block_address,
522		       u32 register_count, u32 interrupt_number)
523{
524	acpi_status status;
525	union acpi_operand_object *obj_desc;
526	struct acpi_namespace_node *node;
527	struct acpi_gpe_block_info *gpe_block;
528
529	ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
530
531	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
532		return_ACPI_STATUS(AE_BAD_PARAMETER);
533	}
534
535	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
536	if (ACPI_FAILURE(status)) {
537		return (status);
538	}
539
540	node = acpi_ns_validate_handle(gpe_device);
541	if (!node) {
542		status = AE_BAD_PARAMETER;
543		goto unlock_and_exit;
544	}
545
 
 
 
 
 
 
 
 
 
 
 
 
546	/*
547	 * For user-installed GPE Block Devices, the gpe_block_base_number
548	 * is always zero
549	 */
550	status =
551	    acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
552				     interrupt_number, &gpe_block);
 
553	if (ACPI_FAILURE(status)) {
554		goto unlock_and_exit;
555	}
556
557	/* Install block in the device_object attached to the node */
558
559	obj_desc = acpi_ns_get_attached_object(node);
560	if (!obj_desc) {
561
562		/*
563		 * No object, create a new one (Device nodes do not always have
564		 * an attached object)
565		 */
566		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
567		if (!obj_desc) {
568			status = AE_NO_MEMORY;
569			goto unlock_and_exit;
570		}
571
572		status =
573		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
574
575		/* Remove local reference to the object */
576
577		acpi_ut_remove_reference(obj_desc);
578
579		if (ACPI_FAILURE(status)) {
580			goto unlock_and_exit;
581		}
582	}
583
584	/* Now install the GPE block in the device_object */
585
586	obj_desc->device.gpe_block = gpe_block;
587
588      unlock_and_exit:
589	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
590	return_ACPI_STATUS(status);
591}
592
593ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
594
595/*******************************************************************************
596 *
597 * FUNCTION:    acpi_remove_gpe_block
598 *
599 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
600 *
601 * RETURN:      Status
602 *
603 * DESCRIPTION: Remove a previously installed block of GPE registers
604 *
605 ******************************************************************************/
606acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
607{
608	union acpi_operand_object *obj_desc;
609	acpi_status status;
610	struct acpi_namespace_node *node;
611
612	ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
613
614	if (!gpe_device) {
615		return_ACPI_STATUS(AE_BAD_PARAMETER);
616	}
617
618	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
619	if (ACPI_FAILURE(status)) {
620		return (status);
621	}
622
623	node = acpi_ns_validate_handle(gpe_device);
624	if (!node) {
625		status = AE_BAD_PARAMETER;
626		goto unlock_and_exit;
627	}
628
 
 
 
 
 
 
 
629	/* Get the device_object attached to the node */
630
631	obj_desc = acpi_ns_get_attached_object(node);
632	if (!obj_desc || !obj_desc->device.gpe_block) {
633		return_ACPI_STATUS(AE_NULL_OBJECT);
634	}
635
636	/* Delete the GPE block (but not the device_object) */
637
638	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
639	if (ACPI_SUCCESS(status)) {
640		obj_desc->device.gpe_block = NULL;
641	}
642
643      unlock_and_exit:
644	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
645	return_ACPI_STATUS(status);
646}
647
648ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
649
650/*******************************************************************************
651 *
652 * FUNCTION:    acpi_get_gpe_device
653 *
654 * PARAMETERS:  Index               - System GPE index (0-current_gpe_count)
655 *              gpe_device          - Where the parent GPE Device is returned
656 *
657 * RETURN:      Status
658 *
659 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
660 *              gpe device indicates that the gpe number is contained in one of
661 *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
662 *
663 ******************************************************************************/
664acpi_status
665acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
666{
667	struct acpi_gpe_device_info info;
668	acpi_status status;
669
670	ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
671
672	if (!gpe_device) {
673		return_ACPI_STATUS(AE_BAD_PARAMETER);
674	}
675
676	if (index >= acpi_current_gpe_count) {
677		return_ACPI_STATUS(AE_NOT_EXIST);
678	}
679
680	/* Setup and walk the GPE list */
681
682	info.index = index;
683	info.status = AE_NOT_EXIST;
684	info.gpe_device = NULL;
685	info.next_block_base_index = 0;
686
687	status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
688	if (ACPI_FAILURE(status)) {
689		return_ACPI_STATUS(status);
690	}
691
692	*gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
693	return_ACPI_STATUS(info.status);
694}
695
696ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
v6.2
   1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
   2/******************************************************************************
   3 *
   4 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
   5 *
   6 * Copyright (C) 2000 - 2022, Intel Corp.
   7 *
   8 *****************************************************************************/
   9
  10#define EXPORT_ACPI_INTERFACES
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  11
  12#include <acpi/acpi.h>
  13#include "accommon.h"
  14#include "acevents.h"
  15#include "acnamesp.h"
  16
  17#define _COMPONENT          ACPI_EVENTS
  18ACPI_MODULE_NAME("evxfgpe")
  19
  20#if (!ACPI_REDUCED_HARDWARE)	/* Entire module */
  21/*******************************************************************************
  22 *
  23 * FUNCTION:    acpi_update_all_gpes
  24 *
  25 * PARAMETERS:  None
  26 *
  27 * RETURN:      Status
  28 *
  29 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
  30 *              associated _Lxx or _Exx methods and are not pointed to by any
  31 *              device _PRW methods (this indicates that these GPEs are
  32 *              generally intended for system or device wakeup. Such GPEs
  33 *              have to be enabled directly when the devices whose _PRW
  34 *              methods point to them are set up for wakeup signaling.)
  35 *
  36 * NOTE: Should be called after any GPEs are added to the system. Primarily,
  37 * after the system _PRW methods have been run, but also after a GPE Block
  38 * Device has been added or if any new GPE methods have been added via a
  39 * dynamic table load.
  40 *
  41 ******************************************************************************/
  42
  43acpi_status acpi_update_all_gpes(void)
  44{
  45	acpi_status status;
  46	u8 is_polling_needed = FALSE;
  47
  48	ACPI_FUNCTION_TRACE(acpi_update_all_gpes);
  49
  50	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  51	if (ACPI_FAILURE(status)) {
  52		return_ACPI_STATUS(status);
  53	}
  54
  55	if (acpi_gbl_all_gpes_initialized) {
  56		goto unlock_and_exit;
  57	}
  58
  59	status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block,
  60				       &is_polling_needed);
  61	if (ACPI_SUCCESS(status)) {
  62		acpi_gbl_all_gpes_initialized = TRUE;
  63	}
  64
  65unlock_and_exit:
  66	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  67
  68	if (is_polling_needed && acpi_gbl_all_gpes_initialized) {
  69
  70		/* Poll GPEs to handle already triggered events */
  71
  72		acpi_ev_gpe_detect(acpi_gbl_gpe_xrupt_list_head);
  73	}
  74	return_ACPI_STATUS(status);
  75}
  76
  77ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)
  78
  79/*******************************************************************************
  80 *
  81 * FUNCTION:    acpi_enable_gpe
  82 *
  83 * PARAMETERS:  gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
  84 *              gpe_number          - GPE level within the GPE block
  85 *
  86 * RETURN:      Status
  87 *
  88 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  89 *              hardware-enabled.
  90 *
  91 ******************************************************************************/
 
  92acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
  93{
  94	acpi_status status = AE_BAD_PARAMETER;
  95	struct acpi_gpe_event_info *gpe_event_info;
  96	acpi_cpu_flags flags;
  97
  98	ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  99
 100	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 101
 102	/*
 103	 * Ensure that we have a valid GPE number and that there is some way
 104	 * of handling the GPE (handler or a GPE method). In other words, we
 105	 * won't allow a valid GPE to be enabled if there is no way to handle it.
 106	 */
 107	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 108	if (gpe_event_info) {
 109		if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
 110		    ACPI_GPE_DISPATCH_NONE) {
 111			status = acpi_ev_add_gpe_reference(gpe_event_info, TRUE);
 112			if (ACPI_SUCCESS(status) &&
 113			    ACPI_GPE_IS_POLLING_NEEDED(gpe_event_info)) {
 114
 115				/* Poll edge-triggered GPEs to handle existing events */
 116
 117				acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 118				(void)acpi_ev_detect_gpe(gpe_device,
 119							 gpe_event_info,
 120							 gpe_number);
 121				flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 122			}
 123		} else {
 124			status = AE_NO_HANDLER;
 125		}
 126	}
 127
 128	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 129	return_ACPI_STATUS(status);
 130}
 131ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
 132
 133/*******************************************************************************
 134 *
 135 * FUNCTION:    acpi_disable_gpe
 136 *
 137 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
 138 *              gpe_number      - GPE level within the GPE block
 139 *
 140 * RETURN:      Status
 141 *
 142 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
 143 *              removed, only then is the GPE disabled (for runtime GPEs), or
 144 *              the GPE mask bit disabled (for wake GPEs)
 145 *
 146 ******************************************************************************/
 147
 148acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
 149{
 150	acpi_status status = AE_BAD_PARAMETER;
 151	struct acpi_gpe_event_info *gpe_event_info;
 152	acpi_cpu_flags flags;
 153
 154	ACPI_FUNCTION_TRACE(acpi_disable_gpe);
 155
 156	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 157
 158	/* Ensure that we have a valid GPE number */
 159
 160	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 161	if (gpe_event_info) {
 162		status = acpi_ev_remove_gpe_reference(gpe_event_info) ;
 163	}
 164
 165	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 166	return_ACPI_STATUS(status);
 167}
 168
 169ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
 170
 171/*******************************************************************************
 172 *
 173 * FUNCTION:    acpi_set_gpe
 174 *
 175 * PARAMETERS:  gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
 176 *              gpe_number          - GPE level within the GPE block
 177 *              action              - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
 178 *
 179 * RETURN:      Status
 180 *
 181 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
 182 *              the reference count mechanism used in the acpi_enable_gpe(),
 183 *              acpi_disable_gpe() interfaces.
 184 *              This API is typically used by the GPE raw handler mode driver
 185 *              to switch between the polling mode and the interrupt mode after
 186 *              the driver has enabled the GPE.
 187 *              The APIs should be invoked in this order:
 188 *               acpi_enable_gpe()            <- Ensure the reference count > 0
 189 *               acpi_set_gpe(ACPI_GPE_DISABLE) <- Enter polling mode
 190 *               acpi_set_gpe(ACPI_GPE_ENABLE) <- Leave polling mode
 191 *               acpi_disable_gpe()           <- Decrease the reference count
 192 *
 193 * Note: If a GPE is shared by 2 silicon components, then both the drivers
 194 *       should support GPE polling mode or disabling the GPE for long period
 195 *       for one driver may break the other. So use it with care since all
 196 *       firmware _Lxx/_Exx handlers currently rely on the GPE interrupt mode.
 197 *
 198 ******************************************************************************/
 199acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
 200{
 201	struct acpi_gpe_event_info *gpe_event_info;
 202	acpi_status status;
 203	acpi_cpu_flags flags;
 204
 205	ACPI_FUNCTION_TRACE(acpi_set_gpe);
 206
 207	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 208
 209	/* Ensure that we have a valid GPE number */
 210
 211	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 212	if (!gpe_event_info) {
 213		status = AE_BAD_PARAMETER;
 214		goto unlock_and_exit;
 215	}
 216
 217	/* Perform the action */
 218
 219	switch (action) {
 220	case ACPI_GPE_ENABLE:
 221
 222		status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
 223		gpe_event_info->disable_for_dispatch = FALSE;
 224		break;
 225
 226	case ACPI_GPE_DISABLE:
 227
 228		status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
 229		gpe_event_info->disable_for_dispatch = TRUE;
 230		break;
 231
 232	default:
 233
 234		status = AE_BAD_PARAMETER;
 235		break;
 236	}
 237
 238unlock_and_exit:
 239	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 240	return_ACPI_STATUS(status);
 241}
 242
 243ACPI_EXPORT_SYMBOL(acpi_set_gpe)
 244
 245/*******************************************************************************
 246 *
 247 * FUNCTION:    acpi_mask_gpe
 248 *
 249 * PARAMETERS:  gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
 250 *              gpe_number          - GPE level within the GPE block
 251 *              is_masked           - Whether the GPE is masked or not
 252 *
 253 * RETURN:      Status
 254 *
 255 * DESCRIPTION: Unconditionally mask/unmask the an individual GPE, ex., to
 256 *              prevent a GPE flooding.
 257 *
 258 ******************************************************************************/
 259acpi_status acpi_mask_gpe(acpi_handle gpe_device, u32 gpe_number, u8 is_masked)
 260{
 261	struct acpi_gpe_event_info *gpe_event_info;
 262	acpi_status status;
 263	acpi_cpu_flags flags;
 264
 265	ACPI_FUNCTION_TRACE(acpi_mask_gpe);
 266
 267	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 268
 269	/* Ensure that we have a valid GPE number */
 270
 271	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 272	if (!gpe_event_info) {
 273		status = AE_BAD_PARAMETER;
 274		goto unlock_and_exit;
 275	}
 276
 277	status = acpi_ev_mask_gpe(gpe_event_info, is_masked);
 278
 279unlock_and_exit:
 280	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 281	return_ACPI_STATUS(status);
 282}
 283
 284ACPI_EXPORT_SYMBOL(acpi_mask_gpe)
 285
 286/*******************************************************************************
 287 *
 288 * FUNCTION:    acpi_mark_gpe_for_wake
 289 *
 290 * PARAMETERS:  gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
 291 *              gpe_number          - GPE level within the GPE block
 292 *
 293 * RETURN:      Status
 294 *
 295 * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
 296 *              sets the ACPI_GPE_CAN_WAKE flag.
 297 *
 298 * Some potential callers of acpi_setup_gpe_for_wake may know in advance that
 299 * there won't be any notify handlers installed for device wake notifications
 300 * from the given GPE (one example is a button GPE in Linux). For these cases,
 301 * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake.
 302 * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
 303 * setup implicit wake notification for it (since there's no handler method).
 304 *
 305 ******************************************************************************/
 306acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number)
 307{
 308	struct acpi_gpe_event_info *gpe_event_info;
 309	acpi_status status = AE_BAD_PARAMETER;
 310	acpi_cpu_flags flags;
 311
 312	ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake);
 313
 314	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 315
 316	/* Ensure that we have a valid GPE number */
 317
 318	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 319	if (gpe_event_info) {
 320
 321		/* Mark the GPE as a possible wake event */
 322
 323		gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
 324		status = AE_OK;
 325	}
 326
 327	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 328	return_ACPI_STATUS(status);
 329}
 330
 331ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake)
 332
 333/*******************************************************************************
 334 *
 335 * FUNCTION:    acpi_setup_gpe_for_wake
 336 *
 337 * PARAMETERS:  wake_device         - Device associated with the GPE (via _PRW)
 338 *              gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
 339 *              gpe_number          - GPE level within the GPE block
 340 *
 341 * RETURN:      Status
 342 *
 343 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
 344 *              interface is intended to be used as the host executes the
 345 *              _PRW methods (Power Resources for Wake) in the system tables.
 346 *              Each _PRW appears under a Device Object (The wake_device), and
 347 *              contains the info for the wake GPE associated with the
 348 *              wake_device.
 349 *
 350 ******************************************************************************/
 351acpi_status
 352acpi_setup_gpe_for_wake(acpi_handle wake_device,
 353			acpi_handle gpe_device, u32 gpe_number)
 354{
 355	acpi_status status;
 356	struct acpi_gpe_event_info *gpe_event_info;
 357	struct acpi_namespace_node *device_node;
 358	struct acpi_gpe_notify_info *notify;
 359	struct acpi_gpe_notify_info *new_notify;
 360	acpi_cpu_flags flags;
 
 361
 362	ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
 363
 364	/* Parameter Validation */
 365
 366	if (!wake_device) {
 367		/*
 368		 * By forcing wake_device to be valid, we automatically enable the
 369		 * implicit notify feature on all hosts.
 370		 */
 371		return_ACPI_STATUS(AE_BAD_PARAMETER);
 372	}
 373
 374	/* Handle root object case */
 375
 376	if (wake_device == ACPI_ROOT_OBJECT) {
 377		device_node = acpi_gbl_root_node;
 378	} else {
 379		device_node =
 380		    ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
 381	}
 382
 383	/* Validate wake_device is of type Device */
 384
 385	if (device_node->type != ACPI_TYPE_DEVICE) {
 386		return_ACPI_STATUS (AE_BAD_PARAMETER);
 387	}
 388
 389	/*
 390	 * Allocate a new notify object up front, in case it is needed.
 391	 * Memory allocation while holding a spinlock is a big no-no
 392	 * on some hosts.
 393	 */
 394	new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
 395	if (!new_notify) {
 396		return_ACPI_STATUS(AE_NO_MEMORY);
 397	}
 398
 399	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 400
 401	/* Ensure that we have a valid GPE number */
 402
 403	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 404	if (!gpe_event_info) {
 405		status = AE_BAD_PARAMETER;
 406		goto unlock_and_exit;
 407	}
 408
 
 
 
 
 409	/*
 410	 * If there is no method or handler for this GPE, then the
 411	 * wake_device will be notified whenever this GPE fires. This is
 412	 * known as an "implicit notify". Note: The GPE is assumed to be
 413	 * level-triggered (for windows compatibility).
 414	 */
 415	if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
 416	    ACPI_GPE_DISPATCH_NONE) {
 417		/*
 418		 * This is the first device for implicit notify on this GPE.
 419		 * Just set the flags here, and enter the NOTIFY block below.
 420		 */
 421		gpe_event_info->flags =
 422		    (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
 423	} else if (gpe_event_info->flags & ACPI_GPE_AUTO_ENABLED) {
 424		/*
 425		 * A reference to this GPE has been added during the GPE block
 426		 * initialization, so drop it now to prevent the GPE from being
 427		 * permanently enabled and clear its ACPI_GPE_AUTO_ENABLED flag.
 428		 */
 429		(void)acpi_ev_remove_gpe_reference(gpe_event_info);
 430		gpe_event_info->flags &= ~ACPI_GPE_AUTO_ENABLED;
 431	}
 432
 433	/*
 434	 * If we already have an implicit notify on this GPE, add
 435	 * this device to the notify list.
 436	 */
 437	if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
 438	    ACPI_GPE_DISPATCH_NOTIFY) {
 439
 440		/* Ensure that the device is not already in the list */
 
 
 
 
 
 
 441
 442		notify = gpe_event_info->dispatch.notify_list;
 443		while (notify) {
 444			if (notify->device_node == device_node) {
 445				status = AE_ALREADY_EXISTS;
 446				goto unlock_and_exit;
 447			}
 448			notify = notify->next;
 449		}
 450
 451		/* Add this device to the notify list for this GPE */
 452
 453		new_notify->device_node = device_node;
 454		new_notify->next = gpe_event_info->dispatch.notify_list;
 455		gpe_event_info->dispatch.notify_list = new_notify;
 456		new_notify = NULL;
 457	}
 458
 459	/* Mark the GPE as a possible wake event */
 460
 461	gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
 462	status = AE_OK;
 463
 464unlock_and_exit:
 465	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 466
 467	/* Delete the notify object if it was not used above */
 468
 469	if (new_notify) {
 470		ACPI_FREE(new_notify);
 471	}
 472	return_ACPI_STATUS(status);
 473}
 474ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
 475
 476/*******************************************************************************
 477 *
 478 * FUNCTION:    acpi_set_gpe_wake_mask
 479 *
 480 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
 481 *              gpe_number      - GPE level within the GPE block
 482 *              action              - Enable or Disable
 483 *
 484 * RETURN:      Status
 485 *
 486 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
 487 *              already be marked as a WAKE GPE.
 488 *
 489 ******************************************************************************/
 490
 491acpi_status
 492acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
 493{
 494	acpi_status status = AE_OK;
 495	struct acpi_gpe_event_info *gpe_event_info;
 496	struct acpi_gpe_register_info *gpe_register_info;
 497	acpi_cpu_flags flags;
 498	u32 register_bit;
 499
 500	ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
 501
 502	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 503
 504	/*
 505	 * Ensure that we have a valid GPE number and that this GPE is in
 506	 * fact a wake GPE
 507	 */
 508	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 509	if (!gpe_event_info) {
 510		status = AE_BAD_PARAMETER;
 511		goto unlock_and_exit;
 512	}
 513
 514	if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
 515		status = AE_TYPE;
 516		goto unlock_and_exit;
 517	}
 518
 519	gpe_register_info = gpe_event_info->register_info;
 520	if (!gpe_register_info) {
 521		status = AE_NOT_EXIST;
 522		goto unlock_and_exit;
 523	}
 524
 525	register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
 
 526
 527	/* Perform the action */
 528
 529	switch (action) {
 530	case ACPI_GPE_ENABLE:
 531
 532		ACPI_SET_BIT(gpe_register_info->enable_for_wake,
 533			     (u8)register_bit);
 534		break;
 535
 536	case ACPI_GPE_DISABLE:
 537
 538		ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
 539			       (u8)register_bit);
 540		break;
 541
 542	default:
 543
 544		ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
 545		status = AE_BAD_PARAMETER;
 546		break;
 547	}
 548
 549unlock_and_exit:
 550	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 551	return_ACPI_STATUS(status);
 552}
 553
 554ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
 555
 556/*******************************************************************************
 557 *
 558 * FUNCTION:    acpi_clear_gpe
 559 *
 560 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
 561 *              gpe_number      - GPE level within the GPE block
 562 *
 563 * RETURN:      Status
 564 *
 565 * DESCRIPTION: Clear an ACPI event (general purpose)
 566 *
 567 ******************************************************************************/
 568acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
 569{
 570	acpi_status status = AE_OK;
 571	struct acpi_gpe_event_info *gpe_event_info;
 572	acpi_cpu_flags flags;
 573
 574	ACPI_FUNCTION_TRACE(acpi_clear_gpe);
 575
 576	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 577
 578	/* Ensure that we have a valid GPE number */
 579
 580	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 581	if (!gpe_event_info) {
 582		status = AE_BAD_PARAMETER;
 583		goto unlock_and_exit;
 584	}
 585
 586	status = acpi_hw_clear_gpe(gpe_event_info);
 587
 588      unlock_and_exit:
 589	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 590	return_ACPI_STATUS(status);
 591}
 592
 593ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
 594
 595/*******************************************************************************
 596 *
 597 * FUNCTION:    acpi_get_gpe_status
 598 *
 599 * PARAMETERS:  gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
 600 *              gpe_number          - GPE level within the GPE block
 601 *              event_status        - Where the current status of the event
 602 *                                    will be returned
 603 *
 604 * RETURN:      Status
 605 *
 606 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
 607 *
 608 ******************************************************************************/
 609acpi_status
 610acpi_get_gpe_status(acpi_handle gpe_device,
 611		    u32 gpe_number, acpi_event_status *event_status)
 612{
 613	acpi_status status = AE_OK;
 614	struct acpi_gpe_event_info *gpe_event_info;
 615	acpi_cpu_flags flags;
 616
 617	ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
 618
 619	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 620
 621	/* Ensure that we have a valid GPE number */
 622
 623	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 624	if (!gpe_event_info) {
 625		status = AE_BAD_PARAMETER;
 626		goto unlock_and_exit;
 627	}
 628
 629	/* Obtain status on the requested GPE number */
 630
 631	status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
 632
 633unlock_and_exit:
 
 
 
 634	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 635	return_ACPI_STATUS(status);
 636}
 637
 638ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
 639
 640/*******************************************************************************
 641 *
 642 * FUNCTION:    acpi_gispatch_gpe
 643 *
 644 * PARAMETERS:  gpe_device          - Parent GPE Device. NULL for GPE0/GPE1
 645 *              gpe_number          - GPE level within the GPE block
 646 *
 647 * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
 648 *
 649 * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
 650 *              (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
 651 *
 652 ******************************************************************************/
 653u32 acpi_dispatch_gpe(acpi_handle gpe_device, u32 gpe_number)
 654{
 655	ACPI_FUNCTION_TRACE(acpi_dispatch_gpe);
 656
 657	return acpi_ev_detect_gpe(gpe_device, NULL, gpe_number);
 658}
 659
 660ACPI_EXPORT_SYMBOL(acpi_dispatch_gpe)
 661
 662/*******************************************************************************
 663 *
 664 * FUNCTION:    acpi_finish_gpe
 665 *
 666 * PARAMETERS:  gpe_device          - Namespace node for the GPE Block
 667 *                                    (NULL for FADT defined GPEs)
 668 *              gpe_number          - GPE level within the GPE block
 669 *
 670 * RETURN:      Status
 671 *
 672 * DESCRIPTION: Clear and conditionally re-enable a GPE. This completes the GPE
 673 *              processing. Intended for use by asynchronous host-installed
 674 *              GPE handlers. The GPE is only re-enabled if the enable_for_run bit
 675 *              is set in the GPE info.
 676 *
 677 ******************************************************************************/
 678acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
 679{
 680	struct acpi_gpe_event_info *gpe_event_info;
 681	acpi_status status;
 682	acpi_cpu_flags flags;
 683
 684	ACPI_FUNCTION_TRACE(acpi_finish_gpe);
 685
 686	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 687
 688	/* Ensure that we have a valid GPE number */
 689
 690	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
 691	if (!gpe_event_info) {
 692		status = AE_BAD_PARAMETER;
 693		goto unlock_and_exit;
 694	}
 695
 696	status = acpi_ev_finish_gpe(gpe_event_info);
 697
 698unlock_and_exit:
 699	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 700	return_ACPI_STATUS(status);
 701}
 702
 703ACPI_EXPORT_SYMBOL(acpi_finish_gpe)
 704
 705/******************************************************************************
 706 *
 707 * FUNCTION:    acpi_disable_all_gpes
 708 *
 709 * PARAMETERS:  None
 710 *
 711 * RETURN:      Status
 712 *
 713 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
 714 *
 715 ******************************************************************************/
 716
 717acpi_status acpi_disable_all_gpes(void)
 718{
 719	acpi_status status;
 720
 721	ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
 722
 723	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
 724	if (ACPI_FAILURE(status)) {
 725		return_ACPI_STATUS(status);
 726	}
 727
 728	status = acpi_hw_disable_all_gpes();
 729	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 730
 731	return_ACPI_STATUS(status);
 732}
 733
 734ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
 735
 736/******************************************************************************
 737 *
 738 * FUNCTION:    acpi_enable_all_runtime_gpes
 739 *
 740 * PARAMETERS:  None
 741 *
 742 * RETURN:      Status
 743 *
 744 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
 745 *
 746 ******************************************************************************/
 747
 748acpi_status acpi_enable_all_runtime_gpes(void)
 749{
 750	acpi_status status;
 751
 752	ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
 753
 754	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
 755	if (ACPI_FAILURE(status)) {
 756		return_ACPI_STATUS(status);
 757	}
 758
 759	status = acpi_hw_enable_all_runtime_gpes();
 760	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 761
 762	return_ACPI_STATUS(status);
 763}
 764
 765ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
 766
 767/******************************************************************************
 768 *
 769 * FUNCTION:    acpi_enable_all_wakeup_gpes
 770 *
 771 * PARAMETERS:  None
 772 *
 773 * RETURN:      Status
 774 *
 775 * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
 776 *              all GPE blocks.
 777 *
 778 ******************************************************************************/
 779acpi_status acpi_enable_all_wakeup_gpes(void)
 780{
 781	acpi_status status;
 782
 783	ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
 784
 785	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
 786	if (ACPI_FAILURE(status)) {
 787		return_ACPI_STATUS(status);
 788	}
 789
 790	status = acpi_hw_enable_all_wakeup_gpes();
 791	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 792
 793	return_ACPI_STATUS(status);
 794}
 795
 796ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
 797
 798/******************************************************************************
 799 *
 800 * FUNCTION:    acpi_any_gpe_status_set
 801 *
 802 * PARAMETERS:  gpe_skip_number      - Number of the GPE to skip
 803 *
 804 * RETURN:      Whether or not the status bit is set for any GPE
 805 *
 806 * DESCRIPTION: Check the status bits of all enabled GPEs, except for the one
 807 *              represented by the "skip" argument, and return TRUE if any of
 808 *              them is set or FALSE otherwise.
 809 *
 810 ******************************************************************************/
 811u32 acpi_any_gpe_status_set(u32 gpe_skip_number)
 812{
 813	acpi_status status;
 814	acpi_handle gpe_device;
 815	u8 ret;
 816
 817	ACPI_FUNCTION_TRACE(acpi_any_gpe_status_set);
 818
 819	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
 820	if (ACPI_FAILURE(status)) {
 821		return (FALSE);
 822	}
 823
 824	status = acpi_get_gpe_device(gpe_skip_number, &gpe_device);
 825	if (ACPI_FAILURE(status)) {
 826		gpe_device = NULL;
 827	}
 828
 829	ret = acpi_hw_check_all_gpes(gpe_device, gpe_skip_number);
 830	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 831
 832	return (ret);
 833}
 834
 835ACPI_EXPORT_SYMBOL(acpi_any_gpe_status_set)
 836
 837/*******************************************************************************
 838 *
 839 * FUNCTION:    acpi_install_gpe_block
 840 *
 841 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
 842 *              gpe_block_address   - Address and space_ID
 843 *              register_count      - Number of GPE register pairs in the block
 844 *              interrupt_number    - H/W interrupt for the block
 845 *
 846 * RETURN:      Status
 847 *
 848 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
 849 *              enabled here.
 850 *
 851 ******************************************************************************/
 852acpi_status
 853acpi_install_gpe_block(acpi_handle gpe_device,
 854		       struct acpi_generic_address *gpe_block_address,
 855		       u32 register_count, u32 interrupt_number)
 856{
 857	acpi_status status;
 858	union acpi_operand_object *obj_desc;
 859	struct acpi_namespace_node *node;
 860	struct acpi_gpe_block_info *gpe_block;
 861
 862	ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
 863
 864	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
 865		return_ACPI_STATUS(AE_BAD_PARAMETER);
 866	}
 867
 868	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
 869	if (ACPI_FAILURE(status)) {
 870		return_ACPI_STATUS(status);
 871	}
 872
 873	node = acpi_ns_validate_handle(gpe_device);
 874	if (!node) {
 875		status = AE_BAD_PARAMETER;
 876		goto unlock_and_exit;
 877	}
 878
 879	/* Validate the parent device */
 880
 881	if (node->type != ACPI_TYPE_DEVICE) {
 882		status = AE_TYPE;
 883		goto unlock_and_exit;
 884	}
 885
 886	if (node->object) {
 887		status = AE_ALREADY_EXISTS;
 888		goto unlock_and_exit;
 889	}
 890
 891	/*
 892	 * For user-installed GPE Block Devices, the gpe_block_base_number
 893	 * is always zero
 894	 */
 895	status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
 896					  gpe_block_address->space_id,
 897					  register_count, 0, interrupt_number,
 898					  &gpe_block);
 899	if (ACPI_FAILURE(status)) {
 900		goto unlock_and_exit;
 901	}
 902
 903	/* Install block in the device_object attached to the node */
 904
 905	obj_desc = acpi_ns_get_attached_object(node);
 906	if (!obj_desc) {
 907
 908		/*
 909		 * No object, create a new one (Device nodes do not always have
 910		 * an attached object)
 911		 */
 912		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
 913		if (!obj_desc) {
 914			status = AE_NO_MEMORY;
 915			goto unlock_and_exit;
 916		}
 917
 918		status =
 919		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
 920
 921		/* Remove local reference to the object */
 922
 923		acpi_ut_remove_reference(obj_desc);
 924
 925		if (ACPI_FAILURE(status)) {
 926			goto unlock_and_exit;
 927		}
 928	}
 929
 930	/* Now install the GPE block in the device_object */
 931
 932	obj_desc->device.gpe_block = gpe_block;
 933
 934unlock_and_exit:
 935	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
 936	return_ACPI_STATUS(status);
 937}
 938
 939ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
 940
 941/*******************************************************************************
 942 *
 943 * FUNCTION:    acpi_remove_gpe_block
 944 *
 945 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
 946 *
 947 * RETURN:      Status
 948 *
 949 * DESCRIPTION: Remove a previously installed block of GPE registers
 950 *
 951 ******************************************************************************/
 952acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
 953{
 954	union acpi_operand_object *obj_desc;
 955	acpi_status status;
 956	struct acpi_namespace_node *node;
 957
 958	ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
 959
 960	if (!gpe_device) {
 961		return_ACPI_STATUS(AE_BAD_PARAMETER);
 962	}
 963
 964	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
 965	if (ACPI_FAILURE(status)) {
 966		return_ACPI_STATUS(status);
 967	}
 968
 969	node = acpi_ns_validate_handle(gpe_device);
 970	if (!node) {
 971		status = AE_BAD_PARAMETER;
 972		goto unlock_and_exit;
 973	}
 974
 975	/* Validate the parent device */
 976
 977	if (node->type != ACPI_TYPE_DEVICE) {
 978		status = AE_TYPE;
 979		goto unlock_and_exit;
 980	}
 981
 982	/* Get the device_object attached to the node */
 983
 984	obj_desc = acpi_ns_get_attached_object(node);
 985	if (!obj_desc || !obj_desc->device.gpe_block) {
 986		return_ACPI_STATUS(AE_NULL_OBJECT);
 987	}
 988
 989	/* Delete the GPE block (but not the device_object) */
 990
 991	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
 992	if (ACPI_SUCCESS(status)) {
 993		obj_desc->device.gpe_block = NULL;
 994	}
 995
 996unlock_and_exit:
 997	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
 998	return_ACPI_STATUS(status);
 999}
1000
1001ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
1002
1003/*******************************************************************************
1004 *
1005 * FUNCTION:    acpi_get_gpe_device
1006 *
1007 * PARAMETERS:  index               - System GPE index (0-current_gpe_count)
1008 *              gpe_device          - Where the parent GPE Device is returned
1009 *
1010 * RETURN:      Status
1011 *
1012 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
1013 *              gpe device indicates that the gpe number is contained in one of
1014 *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
1015 *
1016 ******************************************************************************/
1017acpi_status acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
 
1018{
1019	struct acpi_gpe_device_info info;
1020	acpi_status status;
1021
1022	ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
1023
1024	if (!gpe_device) {
1025		return_ACPI_STATUS(AE_BAD_PARAMETER);
1026	}
1027
1028	if (index >= acpi_current_gpe_count) {
1029		return_ACPI_STATUS(AE_NOT_EXIST);
1030	}
1031
1032	/* Setup and walk the GPE list */
1033
1034	info.index = index;
1035	info.status = AE_NOT_EXIST;
1036	info.gpe_device = NULL;
1037	info.next_block_base_index = 0;
1038
1039	status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
1040	if (ACPI_FAILURE(status)) {
1041		return_ACPI_STATUS(status);
1042	}
1043
1044	*gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
1045	return_ACPI_STATUS(info.status);
1046}
1047
1048ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
1049#endif				/* !ACPI_REDUCED_HARDWARE */