evxfevnt.c 27.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2010, Intel Corp.
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
L
Len Brown 已提交
45 46 47 48
#include "accommon.h"
#include "acevents.h"
#include "acnamesp.h"
#include "actables.h"
L
Linus Torvalds 已提交
49 50

#define _COMPONENT          ACPI_EVENTS
L
Len Brown 已提交
51
ACPI_MODULE_NAME("evxfevnt")
L
Linus Torvalds 已提交
52

53
/* Local prototypes */
B
Bob Moore 已提交
54
static acpi_status
55 56 57
acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
		       struct acpi_gpe_block_info *gpe_block, void *context);

L
Linus Torvalds 已提交
58 59 60 61 62 63 64 65 66 67 68
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Transfers the system into ACPI mode.
 *
 ******************************************************************************/
69

L
Len Brown 已提交
70
acpi_status acpi_enable(void)
L
Linus Torvalds 已提交
71
{
L
Len Brown 已提交
72
	acpi_status status;
L
Linus Torvalds 已提交
73

B
Bob Moore 已提交
74
	ACPI_FUNCTION_TRACE(acpi_enable);
L
Linus Torvalds 已提交
75

76 77 78 79 80 81 82 83
	/* ACPI tables must be present */

	if (!acpi_tb_tables_loaded()) {
		return_ACPI_STATUS(AE_NO_ACPI_TABLES);
	}

	/* Check current mode */

L
Linus Torvalds 已提交
84
	if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
L
Len Brown 已提交
85 86
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in ACPI mode\n"));
L
Len Brown 已提交
87 88
		return_ACPI_STATUS(AE_OK);
	}
L
Linus Torvalds 已提交
89

L
Len Brown 已提交
90
	/* Transition to ACPI mode */
L
Linus Torvalds 已提交
91

L
Len Brown 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104
	status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
	if (ACPI_FAILURE(status)) {
		ACPI_ERROR((AE_INFO,
			    "Could not transition to ACPI mode"));
		return_ACPI_STATUS(status);
	}

	/* Sanity check that transition succeeded */

	if (acpi_hw_get_mode() != ACPI_SYS_MODE_ACPI) {
		ACPI_ERROR((AE_INFO,
			    "Hardware did not enter ACPI mode"));
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
105 106
	}

L
Len Brown 已提交
107 108 109 110
	ACPI_DEBUG_PRINT((ACPI_DB_INIT,
			  "Transition to ACPI mode successful\n"));

	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
111 112
}

B
Bob Moore 已提交
113 114
ACPI_EXPORT_SYMBOL(acpi_enable)

L
Linus Torvalds 已提交
115 116 117 118 119 120 121 122
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
123
 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
L
Linus Torvalds 已提交
124 125
 *
 ******************************************************************************/
L
Len Brown 已提交
126
acpi_status acpi_disable(void)
L
Linus Torvalds 已提交
127
{
L
Len Brown 已提交
128
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
129

B
Bob Moore 已提交
130
	ACPI_FUNCTION_TRACE(acpi_disable);
L
Linus Torvalds 已提交
131 132

	if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
L
Len Brown 已提交
133 134 135
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in legacy (non-ACPI) mode\n"));
	} else {
L
Linus Torvalds 已提交
136 137
		/* Transition to LEGACY mode */

L
Len Brown 已提交
138
		status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
L
Linus Torvalds 已提交
139

L
Len Brown 已提交
140
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
141 142
			ACPI_ERROR((AE_INFO,
				    "Could not exit ACPI mode to legacy mode"));
L
Len Brown 已提交
143
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
144 145
		}

L
Len Brown 已提交
146
		ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
L
Linus Torvalds 已提交
147 148
	}

L
Len Brown 已提交
149
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
150 151
}

B
Bob Moore 已提交
152 153
ACPI_EXPORT_SYMBOL(acpi_disable)

L
Linus Torvalds 已提交
154 155 156 157 158 159 160 161 162 163 164 165
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
166
acpi_status acpi_enable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
167
{
L
Len Brown 已提交
168 169
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
170

B
Bob Moore 已提交
171
	ACPI_FUNCTION_TRACE(acpi_enable_event);
L
Linus Torvalds 已提交
172 173 174 175

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
176
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
177 178 179
	}

	/*
180 181
	 * Enable the requested fixed event (by writing a one to the enable
	 * register bit)
L
Linus Torvalds 已提交
182
	 */
L
Len Brown 已提交
183
	status =
184
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
185
				    enable_register_id, ACPI_ENABLE_EVENT);
L
Len Brown 已提交
186 187
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
188 189 190 191
	}

	/* Make sure that the hardware responded */

L
Len Brown 已提交
192
	status =
193 194
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
195 196
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
197 198 199
	}

	if (value != 1) {
B
Bob Moore 已提交
200 201 202
		ACPI_ERROR((AE_INFO,
			    "Could not enable %s event",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
203
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
204 205
	}

L
Len Brown 已提交
206
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
207 208
}

B
Bob Moore 已提交
209
ACPI_EXPORT_SYMBOL(acpi_enable_event)
L
Linus Torvalds 已提交
210

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_and_enable_gpe
 *
 * PARAMETERS:  gpe_event_info  - GPE to enable
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear the given GPE from stale events and enable it.
 *
 ******************************************************************************/
static acpi_status
acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
{
	acpi_status status;

	/*
	 * We will only allow a GPE to be enabled if it has either an
	 * associated method (_Lxx/_Exx) or a handler. Otherwise, the
	 * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
	 * first time it fires.
	 */
	if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
		return_ACPI_STATUS(AE_NO_HANDLER);
	}

	/* Clear the GPE (of stale events) */
	status = acpi_hw_clear_gpe(gpe_event_info);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	/* Enable the requested GPE */
	status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);

	return_ACPI_STATUS(status);
}

L
Linus Torvalds 已提交
249 250
/*******************************************************************************
 *
251
 * FUNCTION:    acpi_set_gpe
L
Linus Torvalds 已提交
252
 *
253
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
254
 *              gpe_number      - GPE level within the GPE block
255
 *              action          - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
L
Linus Torvalds 已提交
256 257 258
 *
 * RETURN:      Status
 *
259 260 261 262 263 264 265
 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
 *              the reference count mechanism used in the acpi_enable_gpe and
 *              acpi_disable_gpe interfaces -- and should be used with care.
 *
 * Note: Typically used to disable a runtime GPE for short period of time,
 * then re-enable it, without disturbing the existing reference counts. This
 * is useful, for example, in the Embedded Controller (EC) driver.
L
Linus Torvalds 已提交
266 267
 *
 ******************************************************************************/
268
acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
L
Linus Torvalds 已提交
269
{
L
Len Brown 已提交
270
	struct acpi_gpe_event_info *gpe_event_info;
271 272
	acpi_status status;
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
273

274 275 276
	ACPI_FUNCTION_TRACE(acpi_set_gpe);

	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
277 278 279

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
280
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
281 282 283 284 285
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

286 287 288 289
	/* Perform the action */

	switch (action) {
	case ACPI_GPE_ENABLE:
290
		status = acpi_clear_and_enable_gpe(gpe_event_info);
291
		break;
L
Linus Torvalds 已提交
292

293
	case ACPI_GPE_DISABLE:
294
		status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
295
		break;
L
Linus Torvalds 已提交
296

297 298 299 300
	default:
		status = AE_BAD_PARAMETER;
		break;
	}
L
Linus Torvalds 已提交
301

L
Len Brown 已提交
302
      unlock_and_exit:
303
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
304
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
305 306
}

307
ACPI_EXPORT_SYMBOL(acpi_set_gpe)
L
Linus Torvalds 已提交
308 309 310 311 312

/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_gpe
 *
313
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
314
 *              gpe_number      - GPE level within the GPE block
315 316
 *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
 *                                or both
L
Linus Torvalds 已提交
317 318 319
 *
 * RETURN:      Status
 *
320 321 322
 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
 *              hardware-enabled (for runtime GPEs), or the GPE register mask
 *              is updated (for wake GPEs).
L
Linus Torvalds 已提交
323 324
 *
 ******************************************************************************/
325
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
L
Linus Torvalds 已提交
326
{
L
Len Brown 已提交
327 328
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
329
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
330

B
Bob Moore 已提交
331
	ACPI_FUNCTION_TRACE(acpi_enable_gpe);
L
Linus Torvalds 已提交
332

333 334 335
	/* Parameter validation */

	if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
336
		return_ACPI_STATUS(AE_BAD_PARAMETER);
337
	}
338

339
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
340 341 342

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
343
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
344 345 346 347 348
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

349 350 351 352 353 354 355 356
	if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
		if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
			status = AE_LIMIT;	/* Too many references */
			goto unlock_and_exit;
		}

		gpe_event_info->runtime_count++;
		if (gpe_event_info->runtime_count == 1) {
357 358 359 360 361
			status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
			if (ACPI_SUCCESS(status)) {
				status = acpi_clear_and_enable_gpe(gpe_event_info);
			}

362
			if (ACPI_FAILURE(status)) {
363
				gpe_event_info->runtime_count--;
364 365
				goto unlock_and_exit;
			}
366
		}
367
	}
L
Linus Torvalds 已提交
368

369 370 371
	if (gpe_type & ACPI_GPE_TYPE_WAKE) {
		/* The GPE must have the ability to wake the system */

372
		if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
373 374 375 376 377 378
			status = AE_TYPE;
			goto unlock_and_exit;
		}

		if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
			status = AE_LIMIT;	/* Too many references */
379 380 381 382
			goto unlock_and_exit;
		}

		/*
383 384
		 * Update the enable mask on the first wakeup reference. Wake GPEs
		 * are only hardware-enabled just before sleeping.
385
		 */
386 387
		gpe_event_info->wakeup_count++;
		if (gpe_event_info->wakeup_count == 1) {
388
			status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
389
		}
390 391 392
	}

unlock_and_exit:
393
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
394
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
395
}
B
Bob Moore 已提交
396
ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
L
Linus Torvalds 已提交
397 398 399 400 401

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_gpe
 *
402
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
403
 *              gpe_number      - GPE level within the GPE block
404 405
 *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
 *                                or both
L
Linus Torvalds 已提交
406 407 408
 *
 * RETURN:      Status
 *
409 410 411
 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
 *              removed, only then is the GPE disabled (for runtime GPEs), or
 *              the GPE mask bit disabled (for wake GPEs)
L
Linus Torvalds 已提交
412 413
 *
 ******************************************************************************/
414
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
L
Linus Torvalds 已提交
415
{
L
Len Brown 已提交
416 417
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
418
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
419

B
Bob Moore 已提交
420
	ACPI_FUNCTION_TRACE(acpi_disable_gpe);
L
Linus Torvalds 已提交
421

422 423 424
	/* Parameter validation */

	if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
425
		return_ACPI_STATUS(AE_BAD_PARAMETER);
426
	}
427

428
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
429

L
Linus Torvalds 已提交
430 431
	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
432
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
433 434 435 436 437
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

438 439 440 441 442 443 444 445 446 447
	/* Hardware-disable a runtime GPE on removal of the last reference */

	if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
		if (!gpe_event_info->runtime_count) {
			status = AE_LIMIT;	/* There are no references to remove */
			goto unlock_and_exit;
		}

		gpe_event_info->runtime_count--;
		if (!gpe_event_info->runtime_count) {
448 449 450 451 452 453
			status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
			if (ACPI_SUCCESS(status)) {
				status = acpi_hw_low_set_gpe(gpe_event_info,
							     ACPI_GPE_DISABLE);
			}

454 455 456 457 458
			if (ACPI_FAILURE(status)) {
				gpe_event_info->runtime_count++;
				goto unlock_and_exit;
			}
		}
459 460
	}

461 462 463 464 465 466 467 468 469 470 471 472 473
	/*
	 * Update masks for wake GPE on removal of the last reference.
	 * No need to hardware-disable wake GPEs here, they are not currently
	 * enabled.
	 */
	if (gpe_type & ACPI_GPE_TYPE_WAKE) {
		if (!gpe_event_info->wakeup_count) {
			status = AE_LIMIT;	/* There are no references to remove */
			goto unlock_and_exit;
		}

		gpe_event_info->wakeup_count--;
		if (!gpe_event_info->wakeup_count) {
474
			status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
475
		}
476
	}
L
Linus Torvalds 已提交
477

478 479
unlock_and_exit:
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
480
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
481
}
B
Bob Moore 已提交
482 483
ACPI_EXPORT_SYMBOL(acpi_disable_gpe)

L
Linus Torvalds 已提交
484 485 486 487 488 489 490 491 492 493 494 495
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
496
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
497
{
L
Len Brown 已提交
498 499
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
500

B
Bob Moore 已提交
501
	ACPI_FUNCTION_TRACE(acpi_disable_event);
L
Linus Torvalds 已提交
502 503 504 505

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
506
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
507 508 509
	}

	/*
510 511
	 * Disable the requested fixed event (by writing a zero to the enable
	 * register bit)
L
Linus Torvalds 已提交
512
	 */
L
Len Brown 已提交
513
	status =
514
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
515
				    enable_register_id, ACPI_DISABLE_EVENT);
L
Len Brown 已提交
516 517
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
518 519
	}

L
Len Brown 已提交
520
	status =
521 522
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
523 524
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
525 526 527
	}

	if (value != 0) {
B
Bob Moore 已提交
528 529 530
		ACPI_ERROR((AE_INFO,
			    "Could not disable %s events",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
531
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
532 533
	}

L
Len Brown 已提交
534
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
535 536
}

B
Bob Moore 已提交
537
ACPI_EXPORT_SYMBOL(acpi_disable_event)
L
Linus Torvalds 已提交
538 539 540 541 542 543 544 545 546 547 548 549

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_event
 *
 * PARAMETERS:  Event           - The fixed event to be cleared
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
550
acpi_status acpi_clear_event(u32 event)
L
Linus Torvalds 已提交
551
{
L
Len Brown 已提交
552
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
553

B
Bob Moore 已提交
554
	ACPI_FUNCTION_TRACE(acpi_clear_event);
L
Linus Torvalds 已提交
555 556 557 558

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
559
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
560 561 562
	}

	/*
563 564
	 * Clear the requested fixed event (By writing a one to the status
	 * register bit)
L
Linus Torvalds 已提交
565
	 */
L
Len Brown 已提交
566
	status =
567
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
568
				    status_register_id, ACPI_CLEAR_STATUS);
L
Linus Torvalds 已提交
569

L
Len Brown 已提交
570
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
571 572
}

B
Bob Moore 已提交
573
ACPI_EXPORT_SYMBOL(acpi_clear_event)
L
Linus Torvalds 已提交
574 575 576 577 578

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_gpe
 *
579
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
580 581 582 583 584 585 586
 *              gpe_number      - GPE level within the GPE block
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (general purpose)
 *
 ******************************************************************************/
587
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
L
Linus Torvalds 已提交
588
{
L
Len Brown 已提交
589 590
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
591
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
592

B
Bob Moore 已提交
593
	ACPI_FUNCTION_TRACE(acpi_clear_gpe);
L
Linus Torvalds 已提交
594

595
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
596 597 598

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
599
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
600 601 602 603 604
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
605
	status = acpi_hw_clear_gpe(gpe_event_info);
L
Linus Torvalds 已提交
606

L
Len Brown 已提交
607
      unlock_and_exit:
608
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
609
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
610 611
}

B
Bob Moore 已提交
612
ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
L
Linus Torvalds 已提交
613 614 615 616 617
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_event_status
 *
 * PARAMETERS:  Event           - The fixed event
R
Robert Moore 已提交
618
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
619 620 621 622 623 624 625
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtains and returns the current status of the event
 *
 ******************************************************************************/
L
Len Brown 已提交
626
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
627
{
L
Len Brown 已提交
628
	acpi_status status = AE_OK;
629
	u32 value;
L
Linus Torvalds 已提交
630

B
Bob Moore 已提交
631
	ACPI_FUNCTION_TRACE(acpi_get_event_status);
L
Linus Torvalds 已提交
632 633

	if (!event_status) {
L
Len Brown 已提交
634
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
635 636 637 638 639
	}

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
640
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
641 642 643 644
	}

	/* Get the status of the requested fixed event */

L
Len Brown 已提交
645
	status =
646
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
647 648 649 650 651 652 653
			      enable_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

	*event_status = value;

	status =
654
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
655 656 657 658 659 660
			      status_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

	if (value)
		*event_status |= ACPI_EVENT_FLAG_SET;
L
Linus Torvalds 已提交
661

662 663 664
	if (acpi_gbl_fixed_event_handlers[event].handler)
		*event_status |= ACPI_EVENT_FLAG_HANDLE;

L
Len Brown 已提交
665
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
666 667
}

B
Bob Moore 已提交
668 669
ACPI_EXPORT_SYMBOL(acpi_get_event_status)

L
Linus Torvalds 已提交
670 671 672 673
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_gpe_status
 *
674
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
675
 *              gpe_number      - GPE level within the GPE block
R
Robert Moore 已提交
676
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
677 678 679 680 681 682 683 684
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get status of an event (general purpose)
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
685
acpi_get_gpe_status(acpi_handle gpe_device,
686
		    u32 gpe_number, acpi_event_status *event_status)
L
Linus Torvalds 已提交
687
{
L
Len Brown 已提交
688 689
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
690
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
691

B
Bob Moore 已提交
692
	ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
L
Linus Torvalds 已提交
693

694
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
695 696 697

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
698
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
699 700 701 702 703 704 705
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Obtain status on the requested GPE number */

L
Len Brown 已提交
706
	status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
L
Linus Torvalds 已提交
707

708 709 710
	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
		*event_status |= ACPI_EVENT_FLAG_HANDLE;

L
Len Brown 已提交
711
      unlock_and_exit:
712
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
713
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
714
}
B
Bob Moore 已提交
715 716

ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
L
Linus Torvalds 已提交
717 718 719 720 721 722 723
/*******************************************************************************
 *
 * FUNCTION:    acpi_install_gpe_block
 *
 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
 *              gpe_block_address   - Address and space_iD
 *              register_count      - Number of GPE register pairs in the block
724
 *              interrupt_number    - H/W interrupt for the block
L
Linus Torvalds 已提交
725 726 727 728 729 730 731
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create and Install a block of GPE registers
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
732 733 734
acpi_install_gpe_block(acpi_handle gpe_device,
		       struct acpi_generic_address *gpe_block_address,
		       u32 register_count, u32 interrupt_number)
L
Linus Torvalds 已提交
735
{
L
Len Brown 已提交
736 737 738 739
	acpi_status status;
	union acpi_operand_object *obj_desc;
	struct acpi_namespace_node *node;
	struct acpi_gpe_block_info *gpe_block;
L
Linus Torvalds 已提交
740

B
Bob Moore 已提交
741
	ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
L
Linus Torvalds 已提交
742

L
Len Brown 已提交
743 744
	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
745 746
	}

L
Len Brown 已提交
747 748
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
749 750 751
		return (status);
	}

752
	node = acpi_ns_validate_handle(gpe_device);
L
Linus Torvalds 已提交
753 754 755 756 757 758 759 760 761
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/*
	 * For user-installed GPE Block Devices, the gpe_block_base_number
	 * is always zero
	 */
L
Len Brown 已提交
762 763 764 765
	status =
	    acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
				     interrupt_number, &gpe_block);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
766 767 768
		goto unlock_and_exit;
	}

769
	/* Install block in the device_object attached to the node */
L
Linus Torvalds 已提交
770

L
Len Brown 已提交
771
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
772
	if (!obj_desc) {
B
Bob Moore 已提交
773

774 775 776 777
		/*
		 * No object, create a new one (Device nodes do not always have
		 * an attached object)
		 */
L
Len Brown 已提交
778
		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
779 780 781 782 783
		if (!obj_desc) {
			status = AE_NO_MEMORY;
			goto unlock_and_exit;
		}

L
Len Brown 已提交
784 785
		status =
		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
786 787 788

		/* Remove local reference to the object */

L
Len Brown 已提交
789
		acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
790

L
Len Brown 已提交
791
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
792 793 794 795
			goto unlock_and_exit;
		}
	}

796
	/* Now install the GPE block in the device_object */
L
Linus Torvalds 已提交
797 798 799

	obj_desc->device.gpe_block = gpe_block;

800 801 802 803
	/* Run the _PRW methods and enable the runtime GPEs in the new block */

	status = acpi_ev_initialize_gpe_block(node, gpe_block);

L
Len Brown 已提交
804 805 806
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
807 808
}

B
Bob Moore 已提交
809
ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
L
Linus Torvalds 已提交
810 811 812 813 814 815 816 817 818 819 820 821

/*******************************************************************************
 *
 * FUNCTION:    acpi_remove_gpe_block
 *
 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Remove a previously installed block of GPE registers
 *
 ******************************************************************************/
L
Len Brown 已提交
822
acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
L
Linus Torvalds 已提交
823
{
L
Len Brown 已提交
824 825 826
	union acpi_operand_object *obj_desc;
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
827

B
Bob Moore 已提交
828
	ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
L
Linus Torvalds 已提交
829 830

	if (!gpe_device) {
L
Len Brown 已提交
831
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
832 833
	}

L
Len Brown 已提交
834 835
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
836 837 838
		return (status);
	}

839
	node = acpi_ns_validate_handle(gpe_device);
L
Linus Torvalds 已提交
840 841 842 843 844 845 846
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Get the device_object attached to the node */

L
Len Brown 已提交
847 848 849
	obj_desc = acpi_ns_get_attached_object(node);
	if (!obj_desc || !obj_desc->device.gpe_block) {
		return_ACPI_STATUS(AE_NULL_OBJECT);
L
Linus Torvalds 已提交
850 851 852 853
	}

	/* Delete the GPE block (but not the device_object) */

L
Len Brown 已提交
854 855
	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
	if (ACPI_SUCCESS(status)) {
L
Linus Torvalds 已提交
856 857 858
		obj_desc->device.gpe_block = NULL;
	}

L
Len Brown 已提交
859 860 861
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
862
}
R
Robert Moore 已提交
863

B
Bob Moore 已提交
864
ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925

/*******************************************************************************
 *
 * FUNCTION:    acpi_get_gpe_device
 *
 * PARAMETERS:  Index               - System GPE index (0-current_gpe_count)
 *              gpe_device          - Where the parent GPE Device is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
 *              gpe device indicates that the gpe number is contained in one of
 *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
 *
 ******************************************************************************/
acpi_status
acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
{
	struct acpi_gpe_device_info info;
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_get_gpe_device);

	if (!gpe_device) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
	}

	if (index >= acpi_current_gpe_count) {
		return_ACPI_STATUS(AE_NOT_EXIST);
	}

	/* Setup and walk the GPE list */

	info.index = index;
	info.status = AE_NOT_EXIST;
	info.gpe_device = NULL;
	info.next_block_base_index = 0;

	status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	*gpe_device = info.gpe_device;
	return_ACPI_STATUS(info.status);
}

ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_get_gpe_device
 *
 * PARAMETERS:  GPE_WALK_CALLBACK
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
 *              block device. NULL if the GPE is one of the FADT-defined GPEs.
 *
 ******************************************************************************/
B
Bob Moore 已提交
926
static acpi_status
927 928 929 930 931 932 933
acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
		       struct acpi_gpe_block_info *gpe_block, void *context)
{
	struct acpi_gpe_device_info *info = context;

	/* Increment Index by the number of GPEs in this block */

934
	info->next_block_base_index += gpe_block->gpe_count;
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950

	if (info->index < info->next_block_base_index) {
		/*
		 * The GPE index is within this block, get the node. Leave the node
		 * NULL for the FADT-defined GPEs
		 */
		if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
			info->gpe_device = gpe_block->node;
		}

		info->status = AE_OK;
		return (AE_CTRL_END);
	}

	return (AE_OK);
}
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008

/******************************************************************************
 *
 * FUNCTION:    acpi_disable_all_gpes
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
 *
 ******************************************************************************/

acpi_status acpi_disable_all_gpes(void)
{
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);

	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	status = acpi_hw_disable_all_gpes();
	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);

	return_ACPI_STATUS(status);
}

/******************************************************************************
 *
 * FUNCTION:    acpi_enable_all_runtime_gpes
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
 *
 ******************************************************************************/

acpi_status acpi_enable_all_runtime_gpes(void)
{
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);

	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	status = acpi_hw_enable_all_runtime_gpes();
	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);

	return_ACPI_STATUS(status);
}