evxfevnt.c 25.9 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
 * FUNCTION:    acpi_set_gpe
L
Linus Torvalds 已提交
214
 *
215
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
216
 *              gpe_number      - GPE level within the GPE block
217
 *              action          - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
L
Linus Torvalds 已提交
218 219 220
 *
 * RETURN:      Status
 *
221 222 223 224 225 226 227
 * 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 已提交
228 229
 *
 ******************************************************************************/
230
acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
L
Linus Torvalds 已提交
231
{
L
Len Brown 已提交
232
	struct acpi_gpe_event_info *gpe_event_info;
233 234
	acpi_status status;
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
235

236 237 238
	ACPI_FUNCTION_TRACE(acpi_set_gpe);

	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
239 240 241

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

L
Len Brown 已提交
242
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
243 244 245 246 247
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

248 249 250 251
	/* Perform the action */

	switch (action) {
	case ACPI_GPE_ENABLE:
252
		status = acpi_ev_enable_gpe(gpe_event_info);
253
		break;
L
Linus Torvalds 已提交
254

255
	case ACPI_GPE_DISABLE:
256
		status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
257
		break;
L
Linus Torvalds 已提交
258

259 260 261 262
	default:
		status = AE_BAD_PARAMETER;
		break;
	}
L
Linus Torvalds 已提交
263

L
Len Brown 已提交
264
      unlock_and_exit:
265
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
266
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
267 268
}

269
ACPI_EXPORT_SYMBOL(acpi_set_gpe)
L
Linus Torvalds 已提交
270

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
/*******************************************************************************
 *
 * FUNCTION:    acpi_gpe_wakeup
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
 *              gpe_number      - GPE level within the GPE block
 *              Action          - Enable or Disable
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
 *
 ******************************************************************************/
acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
{
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
	struct acpi_gpe_register_info *gpe_register_info;
	acpi_cpu_flags flags;
	u32 register_bit;

	ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);

	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);

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

	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	gpe_register_info = gpe_event_info->register_info;
	if (!gpe_register_info) {
		status = AE_NOT_EXIST;
		goto unlock_and_exit;
	}

	register_bit =
	    acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);

	/* Perform the action */

	switch (action) {
	case ACPI_GPE_ENABLE:
317 318
		ACPI_SET_BIT(gpe_register_info->enable_for_wake,
			     (u8)register_bit);
319 320 321 322
		break;

	case ACPI_GPE_DISABLE:
		ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
323
			       (u8)register_bit);
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
		break;

	default:
		ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
		status = AE_BAD_PARAMETER;
		break;
	}

unlock_and_exit:
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
	return_ACPI_STATUS(status);
}

ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)

L
Linus Torvalds 已提交
339 340 341 342
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_gpe
 *
343
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
344 345 346 347
 *              gpe_number      - GPE level within the GPE block
 *
 * RETURN:      Status
 *
348
 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
349
 *              hardware-enabled.
L
Linus Torvalds 已提交
350 351
 *
 ******************************************************************************/
352
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
L
Linus Torvalds 已提交
353
{
L
Len Brown 已提交
354 355
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
356
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
357

B
Bob Moore 已提交
358
	ACPI_FUNCTION_TRACE(acpi_enable_gpe);
L
Linus Torvalds 已提交
359

360
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
361 362 363

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

L
Len Brown 已提交
364
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
365 366 367 368 369
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

370 371 372
	if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
		status = AE_LIMIT;	/* Too many references */
		goto unlock_and_exit;
373
	}
L
Linus Torvalds 已提交
374

375 376 377 378
	gpe_event_info->runtime_count++;
	if (gpe_event_info->runtime_count == 1) {
		status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
		if (ACPI_SUCCESS(status)) {
379
			status = acpi_ev_enable_gpe(gpe_event_info);
380
		}
381 382
		if (ACPI_FAILURE(status)) {
			gpe_event_info->runtime_count--;
383
		}
384 385 386
	}

unlock_and_exit:
387
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
388
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
389
}
B
Bob Moore 已提交
390
ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
L
Linus Torvalds 已提交
391 392 393 394 395

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_gpe
 *
396
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
397 398 399 400
 *              gpe_number      - GPE level within the GPE block
 *
 * RETURN:      Status
 *
401 402 403
 * 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 已提交
404 405
 *
 ******************************************************************************/
406
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
L
Linus Torvalds 已提交
407
{
L
Len Brown 已提交
408 409
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
410
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
411

B
Bob Moore 已提交
412
	ACPI_FUNCTION_TRACE(acpi_disable_gpe);
L
Linus Torvalds 已提交
413

414
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
415

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

L
Len Brown 已提交
418
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
419 420 421 422 423
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

424 425
	/* Hardware-disable a runtime GPE on removal of the last reference */

426 427 428
	if (!gpe_event_info->runtime_count) {
		status = AE_LIMIT;	/* There are no references to remove */
		goto unlock_and_exit;
429 430
	}

431 432 433 434 435 436 437
	gpe_event_info->runtime_count--;
	if (!gpe_event_info->runtime_count) {
		status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
		if (ACPI_SUCCESS(status)) {
			status =
			    acpi_hw_low_set_gpe(gpe_event_info,
						ACPI_GPE_DISABLE);
438
		}
439 440
		if (ACPI_FAILURE(status)) {
			gpe_event_info->runtime_count++;
441
		}
442
	}
L
Linus Torvalds 已提交
443

444 445
unlock_and_exit:
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
446
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
447
}
B
Bob Moore 已提交
448 449
ACPI_EXPORT_SYMBOL(acpi_disable_gpe)

L
Linus Torvalds 已提交
450 451 452 453 454 455 456 457 458 459 460 461
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
462
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
463
{
L
Len Brown 已提交
464 465
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
466

B
Bob Moore 已提交
467
	ACPI_FUNCTION_TRACE(acpi_disable_event);
L
Linus Torvalds 已提交
468 469 470 471

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
472
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
473 474 475
	}

	/*
476 477
	 * Disable the requested fixed event (by writing a zero to the enable
	 * register bit)
L
Linus Torvalds 已提交
478
	 */
L
Len Brown 已提交
479
	status =
480
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
481
				    enable_register_id, ACPI_DISABLE_EVENT);
L
Len Brown 已提交
482 483
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
484 485
	}

L
Len Brown 已提交
486
	status =
487 488
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
489 490
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
491 492 493
	}

	if (value != 0) {
B
Bob Moore 已提交
494 495 496
		ACPI_ERROR((AE_INFO,
			    "Could not disable %s events",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
497
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
498 499
	}

L
Len Brown 已提交
500
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
501 502
}

B
Bob Moore 已提交
503
ACPI_EXPORT_SYMBOL(acpi_disable_event)
L
Linus Torvalds 已提交
504 505 506 507 508 509 510 511 512 513 514 515

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

B
Bob Moore 已提交
520
	ACPI_FUNCTION_TRACE(acpi_clear_event);
L
Linus Torvalds 已提交
521 522 523 524

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
525
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
526 527 528
	}

	/*
529 530
	 * Clear the requested fixed event (By writing a one to the status
	 * register bit)
L
Linus Torvalds 已提交
531
	 */
L
Len Brown 已提交
532
	status =
533
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
534
				    status_register_id, ACPI_CLEAR_STATUS);
L
Linus Torvalds 已提交
535

L
Len Brown 已提交
536
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
537 538
}

B
Bob Moore 已提交
539
ACPI_EXPORT_SYMBOL(acpi_clear_event)
L
Linus Torvalds 已提交
540 541 542 543 544

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_gpe
 *
545
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
546 547 548 549 550 551 552
 *              gpe_number      - GPE level within the GPE block
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (general purpose)
 *
 ******************************************************************************/
553
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
L
Linus Torvalds 已提交
554
{
L
Len Brown 已提交
555 556
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
557
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
558

B
Bob Moore 已提交
559
	ACPI_FUNCTION_TRACE(acpi_clear_gpe);
L
Linus Torvalds 已提交
560

561
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
562 563 564

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

L
Len Brown 已提交
565
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
566 567 568 569 570
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
571
	status = acpi_hw_clear_gpe(gpe_event_info);
L
Linus Torvalds 已提交
572

L
Len Brown 已提交
573
      unlock_and_exit:
574
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
575
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
576 577
}

B
Bob Moore 已提交
578
ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
L
Linus Torvalds 已提交
579 580 581 582 583
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_event_status
 *
 * PARAMETERS:  Event           - The fixed event
R
Robert Moore 已提交
584
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
585 586 587 588 589 590 591
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtains and returns the current status of the event
 *
 ******************************************************************************/
L
Len Brown 已提交
592
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
593
{
L
Len Brown 已提交
594
	acpi_status status = AE_OK;
595
	u32 value;
L
Linus Torvalds 已提交
596

B
Bob Moore 已提交
597
	ACPI_FUNCTION_TRACE(acpi_get_event_status);
L
Linus Torvalds 已提交
598 599

	if (!event_status) {
L
Len Brown 已提交
600
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
601 602 603 604 605
	}

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
606
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
607 608 609 610
	}

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

L
Len Brown 已提交
611
	status =
612
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
613 614 615 616 617 618 619
			      enable_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

	*event_status = value;

	status =
620
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
621 622 623 624 625 626
			      status_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

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

628 629 630
	if (acpi_gbl_fixed_event_handlers[event].handler)
		*event_status |= ACPI_EVENT_FLAG_HANDLE;

L
Len Brown 已提交
631
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
632 633
}

B
Bob Moore 已提交
634 635
ACPI_EXPORT_SYMBOL(acpi_get_event_status)

L
Linus Torvalds 已提交
636 637 638 639
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_gpe_status
 *
640
 * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
L
Linus Torvalds 已提交
641
 *              gpe_number      - GPE level within the GPE block
R
Robert Moore 已提交
642
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
643 644 645 646 647 648 649 650
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get status of an event (general purpose)
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
651
acpi_get_gpe_status(acpi_handle gpe_device,
652
		    u32 gpe_number, acpi_event_status *event_status)
L
Linus Torvalds 已提交
653
{
L
Len Brown 已提交
654 655
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
656
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
657

B
Bob Moore 已提交
658
	ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
L
Linus Torvalds 已提交
659

660
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
661 662 663

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

L
Len Brown 已提交
664
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
665 666 667 668 669 670 671
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Obtain status on the requested GPE number */

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

674 675 676
	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
		*event_status |= ACPI_EVENT_FLAG_HANDLE;

L
Len Brown 已提交
677
      unlock_and_exit:
678
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
679
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
680
}
B
Bob Moore 已提交
681 682

ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
L
Linus Torvalds 已提交
683 684 685 686 687 688 689
/*******************************************************************************
 *
 * 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
690
 *              interrupt_number    - H/W interrupt for the block
L
Linus Torvalds 已提交
691 692 693 694 695 696 697
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create and Install a block of GPE registers
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
698 699 700
acpi_install_gpe_block(acpi_handle gpe_device,
		       struct acpi_generic_address *gpe_block_address,
		       u32 register_count, u32 interrupt_number)
L
Linus Torvalds 已提交
701
{
L
Len Brown 已提交
702 703 704 705
	acpi_status status;
	union acpi_operand_object *obj_desc;
	struct acpi_namespace_node *node;
	struct acpi_gpe_block_info *gpe_block;
L
Linus Torvalds 已提交
706

B
Bob Moore 已提交
707
	ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
L
Linus Torvalds 已提交
708

L
Len Brown 已提交
709 710
	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
711 712
	}

L
Len Brown 已提交
713 714
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
715 716 717
		return (status);
	}

718
	node = acpi_ns_validate_handle(gpe_device);
L
Linus Torvalds 已提交
719 720 721 722 723 724 725 726 727
	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 已提交
728 729 730 731
	status =
	    acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
				     interrupt_number, &gpe_block);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
732 733 734
		goto unlock_and_exit;
	}

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

L
Len Brown 已提交
737
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
738
	if (!obj_desc) {
B
Bob Moore 已提交
739

740 741 742 743
		/*
		 * No object, create a new one (Device nodes do not always have
		 * an attached object)
		 */
L
Len Brown 已提交
744
		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
745 746 747 748 749
		if (!obj_desc) {
			status = AE_NO_MEMORY;
			goto unlock_and_exit;
		}

L
Len Brown 已提交
750 751
		status =
		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
752 753 754

		/* Remove local reference to the object */

L
Len Brown 已提交
755
		acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
756

L
Len Brown 已提交
757
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
758 759 760 761
			goto unlock_and_exit;
		}
	}

762
	/* Now install the GPE block in the device_object */
L
Linus Torvalds 已提交
763 764 765

	obj_desc->device.gpe_block = gpe_block;

766 767 768 769
	/* 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 已提交
770 771 772
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
773 774
}

B
Bob Moore 已提交
775
ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
L
Linus Torvalds 已提交
776 777 778 779 780 781 782 783 784 785 786 787

/*******************************************************************************
 *
 * 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 已提交
788
acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
L
Linus Torvalds 已提交
789
{
L
Len Brown 已提交
790 791 792
	union acpi_operand_object *obj_desc;
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
793

B
Bob Moore 已提交
794
	ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
L
Linus Torvalds 已提交
795 796

	if (!gpe_device) {
L
Len Brown 已提交
797
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
798 799
	}

L
Len Brown 已提交
800 801
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
802 803 804
		return (status);
	}

805
	node = acpi_ns_validate_handle(gpe_device);
L
Linus Torvalds 已提交
806 807 808 809 810 811 812
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Get the device_object attached to the node */

L
Len Brown 已提交
813 814 815
	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 已提交
816 817 818 819
	}

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

L
Len Brown 已提交
820 821
	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
	if (ACPI_SUCCESS(status)) {
L
Linus Torvalds 已提交
822 823 824
		obj_desc->device.gpe_block = NULL;
	}

L
Len Brown 已提交
825 826 827
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
828
}
R
Robert Moore 已提交
829

B
Bob Moore 已提交
830
ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 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

/*******************************************************************************
 *
 * 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 已提交
892
static acpi_status
893 894 895 896 897 898 899
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 */

900
	info->next_block_base_index += gpe_block->gpe_count;
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916

	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);
}
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974

/******************************************************************************
 *
 * 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);
}