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

/*
B
Bob Moore 已提交
8
 * Copyright (C) 2000 - 2006, R. Byron Moore
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 45 46 47 48 49 50
 * 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 <linux/module.h>

#include <acpi/acpi.h>
#include <acpi/acevents.h>
#include <acpi/acnamesp.h>

#define _COMPONENT          ACPI_EVENTS
L
Len Brown 已提交
51
ACPI_MODULE_NAME("evxfevnt")
L
Linus Torvalds 已提交
52 53 54 55 56 57 58 59 60 61 62 63

/*******************************************************************************
 *
 * FUNCTION:    acpi_enable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Transfers the system into ACPI mode.
 *
 ******************************************************************************/
L
Len Brown 已提交
64
acpi_status acpi_enable(void)
L
Linus Torvalds 已提交
65
{
L
Len Brown 已提交
66
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
67

L
Len Brown 已提交
68
	ACPI_FUNCTION_TRACE("acpi_enable");
L
Linus Torvalds 已提交
69

L
Len Brown 已提交
70
	/* Make sure we have the FADT */
L
Linus Torvalds 已提交
71 72

	if (!acpi_gbl_FADT) {
B
Bob Moore 已提交
73
		ACPI_REPORT_WARNING(("No FADT information present!\n"));
L
Len Brown 已提交
74
		return_ACPI_STATUS(AE_NO_ACPI_TABLES);
L
Linus Torvalds 已提交
75 76 77
	}

	if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
L
Len Brown 已提交
78 79 80
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in ACPI mode\n"));
	} else {
L
Linus Torvalds 已提交
81 82
		/* Transition to ACPI mode */

L
Len Brown 已提交
83 84
		status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
85
			ACPI_REPORT_ERROR(("Could not transition to ACPI mode\n"));
L
Len Brown 已提交
86
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
87 88
		}

L
Len Brown 已提交
89 90
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "Transition to ACPI mode successful\n"));
L
Linus Torvalds 已提交
91 92
	}

L
Len Brown 已提交
93
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
94 95 96 97 98 99 100 101 102 103
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
104
 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
L
Linus Torvalds 已提交
105 106 107
 *
 ******************************************************************************/

L
Len Brown 已提交
108
acpi_status acpi_disable(void)
L
Linus Torvalds 已提交
109
{
L
Len Brown 已提交
110
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
111

L
Len Brown 已提交
112
	ACPI_FUNCTION_TRACE("acpi_disable");
L
Linus Torvalds 已提交
113 114

	if (!acpi_gbl_FADT) {
B
Bob Moore 已提交
115
		ACPI_REPORT_WARNING(("No FADT information present!\n"));
L
Len Brown 已提交
116
		return_ACPI_STATUS(AE_NO_ACPI_TABLES);
L
Linus Torvalds 已提交
117 118 119
	}

	if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
L
Len Brown 已提交
120 121 122
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in legacy (non-ACPI) mode\n"));
	} else {
L
Linus Torvalds 已提交
123 124
		/* Transition to LEGACY mode */

L
Len Brown 已提交
125
		status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
L
Linus Torvalds 已提交
126

L
Len Brown 已提交
127
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
128
			ACPI_REPORT_ERROR(("Could not exit ACPI mode to legacy mode"));
L
Len Brown 已提交
129
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
130 131
		}

L
Len Brown 已提交
132
		ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
L
Linus Torvalds 已提交
133 134
	}

L
Len Brown 已提交
135
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable an ACPI event (fixed)
 *
 ******************************************************************************/

L
Len Brown 已提交
151
acpi_status acpi_enable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
152
{
L
Len Brown 已提交
153 154
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
155

L
Len Brown 已提交
156
	ACPI_FUNCTION_TRACE("acpi_enable_event");
L
Linus Torvalds 已提交
157 158 159 160

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
161
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
162 163 164 165 166 167
	}

	/*
	 * Enable the requested fixed event (by writing a one to the
	 * enable register bit)
	 */
L
Len Brown 已提交
168 169 170 171 172
	status =
	    acpi_set_register(acpi_gbl_fixed_event_info[event].
			      enable_register_id, 1, ACPI_MTX_LOCK);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
173 174 175 176
	}

	/* Make sure that the hardware responded */

L
Len Brown 已提交
177 178 179 180 181
	status =
	    acpi_get_register(acpi_gbl_fixed_event_info[event].
			      enable_register_id, &value, ACPI_MTX_LOCK);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
182 183 184
	}

	if (value != 1) {
B
Bob Moore 已提交
185 186
		ACPI_REPORT_ERROR(("Could not enable %s event\n",
				   acpi_ut_get_event_name(event)));
L
Len Brown 已提交
187
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
188 189
	}

L
Len Brown 已提交
190
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
191 192
}

L
Len Brown 已提交
193
EXPORT_SYMBOL(acpi_enable_event);
L
Linus Torvalds 已提交
194 195 196 197 198 199 200 201 202 203 204

/*******************************************************************************
 *
 * FUNCTION:    acpi_set_gpe_type
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Type            - New GPE type
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
205
 * DESCRIPTION: Set the type of an individual GPE
L
Linus Torvalds 已提交
206 207 208
 *
 ******************************************************************************/

L
Len Brown 已提交
209
acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
L
Linus Torvalds 已提交
210
{
L
Len Brown 已提交
211 212
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
213

L
Len Brown 已提交
214
	ACPI_FUNCTION_TRACE("acpi_set_gpe_type");
L
Linus Torvalds 已提交
215 216 217

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

L
Len Brown 已提交
218
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
219 220 221 222 223 224
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
L
Len Brown 已提交
225
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
226 227 228 229
	}

	/* Set the new type (will disable GPE if currently enabled) */

L
Len Brown 已提交
230
	status = acpi_ev_set_gpe_type(gpe_event_info, type);
L
Linus Torvalds 已提交
231

L
Len Brown 已提交
232 233
      unlock_and_exit:
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
234 235
}

L
Len Brown 已提交
236
EXPORT_SYMBOL(acpi_set_gpe_type);
L
Linus Torvalds 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252

/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_gpe
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Just enable, or also wake enable?
 *                                Called from ISR or not
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable an ACPI event (general purpose)
 *
 ******************************************************************************/

L
Len Brown 已提交
253
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
254
{
L
Len Brown 已提交
255 256
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
257

L
Len Brown 已提交
258
	ACPI_FUNCTION_TRACE("acpi_enable_gpe");
L
Linus Torvalds 已提交
259 260 261 262

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
263 264 265
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
266 267 268 269 270
		}
	}

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

L
Len Brown 已提交
271
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
272 273 274 275 276 277 278
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Perform the enable */

L
Len Brown 已提交
279
	status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
L
Linus Torvalds 已提交
280

L
Len Brown 已提交
281
      unlock_and_exit:
L
Linus Torvalds 已提交
282
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
283
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
284
	}
L
Len Brown 已提交
285
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
286 287
}

L
Len Brown 已提交
288
EXPORT_SYMBOL(acpi_enable_gpe);
L
Linus Torvalds 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_gpe
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Just disable, or also wake disable?
 *                                Called from ISR or not
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (general purpose)
 *
 ******************************************************************************/

L
Len Brown 已提交
305
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
306
{
L
Len Brown 已提交
307 308
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
309

L
Len Brown 已提交
310
	ACPI_FUNCTION_TRACE("acpi_disable_gpe");
L
Linus Torvalds 已提交
311 312 313 314

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
315 316 317
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
318 319 320 321 322
		}
	}

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

L
Len Brown 已提交
323
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
324 325 326 327 328
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
329
	status = acpi_ev_disable_gpe(gpe_event_info);
L
Linus Torvalds 已提交
330

L
Len Brown 已提交
331
      unlock_and_exit:
L
Linus Torvalds 已提交
332
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
333
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
334
	}
L
Len Brown 已提交
335
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/

L
Len Brown 已提交
351
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
352
{
L
Len Brown 已提交
353 354
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
355

L
Len Brown 已提交
356
	ACPI_FUNCTION_TRACE("acpi_disable_event");
L
Linus Torvalds 已提交
357 358 359 360

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
361
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
362 363 364 365 366 367
	}

	/*
	 * Disable the requested fixed event (by writing a zero to the
	 * enable register bit)
	 */
L
Len Brown 已提交
368 369 370 371 372
	status =
	    acpi_set_register(acpi_gbl_fixed_event_info[event].
			      enable_register_id, 0, ACPI_MTX_LOCK);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
373 374
	}

L
Len Brown 已提交
375 376 377 378 379
	status =
	    acpi_get_register(acpi_gbl_fixed_event_info[event].
			      enable_register_id, &value, ACPI_MTX_LOCK);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
380 381 382
	}

	if (value != 0) {
B
Bob Moore 已提交
383 384
		ACPI_REPORT_ERROR(("Could not disable %s events\n",
				   acpi_ut_get_event_name(event)));
L
Len Brown 已提交
385
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
386 387
	}

L
Len Brown 已提交
388
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
389 390
}

L
Len Brown 已提交
391
EXPORT_SYMBOL(acpi_disable_event);
L
Linus Torvalds 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_event
 *
 * PARAMETERS:  Event           - The fixed event to be cleared
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (fixed)
 *
 ******************************************************************************/

L
Len Brown 已提交
405
acpi_status acpi_clear_event(u32 event)
L
Linus Torvalds 已提交
406
{
L
Len Brown 已提交
407
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
408

L
Len Brown 已提交
409
	ACPI_FUNCTION_TRACE("acpi_clear_event");
L
Linus Torvalds 已提交
410 411 412 413

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
414
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
415 416 417 418 419 420
	}

	/*
	 * Clear the requested fixed event (By writing a one to the
	 * status register bit)
	 */
L
Len Brown 已提交
421 422 423
	status =
	    acpi_set_register(acpi_gbl_fixed_event_info[event].
			      status_register_id, 1, ACPI_MTX_LOCK);
L
Linus Torvalds 已提交
424

L
Len Brown 已提交
425
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
426 427
}

L
Len Brown 已提交
428
EXPORT_SYMBOL(acpi_clear_event);
L
Linus Torvalds 已提交
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_gpe
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Called from an ISR or not
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (general purpose)
 *
 ******************************************************************************/

L
Len Brown 已提交
444
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
445
{
L
Len Brown 已提交
446 447
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
448

L
Len Brown 已提交
449
	ACPI_FUNCTION_TRACE("acpi_clear_gpe");
L
Linus Torvalds 已提交
450 451 452 453

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
454 455 456
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
457 458 459 460 461
		}
	}

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

L
Len Brown 已提交
462
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
463 464 465 466 467
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
468
	status = acpi_hw_clear_gpe(gpe_event_info);
L
Linus Torvalds 已提交
469

L
Len Brown 已提交
470
      unlock_and_exit:
L
Linus Torvalds 已提交
471
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
472
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
473
	}
L
Len Brown 已提交
474
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
475 476 477 478 479 480 481 482
}

#ifdef ACPI_FUTURE_USAGE
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_event_status
 *
 * PARAMETERS:  Event           - The fixed event
R
Robert Moore 已提交
483
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
484 485 486 487 488 489 490 491
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtains and returns the current status of the event
 *
 ******************************************************************************/

L
Len Brown 已提交
492
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
493
{
L
Len Brown 已提交
494
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
495

L
Len Brown 已提交
496
	ACPI_FUNCTION_TRACE("acpi_get_event_status");
L
Linus Torvalds 已提交
497 498

	if (!event_status) {
L
Len Brown 已提交
499
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
500 501 502 503 504
	}

	/* Decode the Fixed Event */

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

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

L
Len Brown 已提交
510 511 512
	status =
	    acpi_get_register(acpi_gbl_fixed_event_info[event].
			      status_register_id, event_status, ACPI_MTX_LOCK);
L
Linus Torvalds 已提交
513

L
Len Brown 已提交
514
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
515 516 517 518 519 520 521 522 523
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_get_gpe_status
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Called from an ISR or not
R
Robert Moore 已提交
524
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
525 526 527 528 529 530 531 532 533
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get status of an event (general purpose)
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
534 535
acpi_get_gpe_status(acpi_handle gpe_device,
		    u32 gpe_number, u32 flags, acpi_event_status * event_status)
L
Linus Torvalds 已提交
536
{
L
Len Brown 已提交
537 538
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
539

L
Len Brown 已提交
540
	ACPI_FUNCTION_TRACE("acpi_get_gpe_status");
L
Linus Torvalds 已提交
541 542 543 544

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
545 546 547
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
548 549 550 551 552
		}
	}

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

L
Len Brown 已提交
553
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
554 555 556 557 558 559 560
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Obtain status on the requested GPE number */

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

L
Len Brown 已提交
563
      unlock_and_exit:
L
Linus Torvalds 已提交
564
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
565
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
566
	}
L
Len Brown 已提交
567
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
568
}
L
Len Brown 已提交
569
#endif				/*  ACPI_FUTURE_USAGE  */
L
Linus Torvalds 已提交
570 571 572 573 574 575 576 577

/*******************************************************************************
 *
 * 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
578
 *              interrupt_number    - H/W interrupt for the block
L
Linus Torvalds 已提交
579 580 581 582 583 584 585 586
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create and Install a block of GPE registers
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
587 588 589
acpi_install_gpe_block(acpi_handle gpe_device,
		       struct acpi_generic_address *gpe_block_address,
		       u32 register_count, u32 interrupt_number)
L
Linus Torvalds 已提交
590
{
L
Len Brown 已提交
591 592 593 594
	acpi_status status;
	union acpi_operand_object *obj_desc;
	struct acpi_namespace_node *node;
	struct acpi_gpe_block_info *gpe_block;
L
Linus Torvalds 已提交
595

L
Len Brown 已提交
596
	ACPI_FUNCTION_TRACE("acpi_install_gpe_block");
L
Linus Torvalds 已提交
597

L
Len Brown 已提交
598 599
	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
600 601
	}

L
Len Brown 已提交
602 603
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
604 605 606
		return (status);
	}

L
Len Brown 已提交
607
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
608 609 610 611 612 613 614 615 616
	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 已提交
617 618 619 620
	status =
	    acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
				     interrupt_number, &gpe_block);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
621 622 623
		goto unlock_and_exit;
	}

B
Bob Moore 已提交
624 625 626 627 628 629 630
	/* Run the _PRW methods and enable the GPEs */

	status = acpi_ev_initialize_gpe_block(node, gpe_block);
	if (ACPI_FAILURE(status)) {
		goto unlock_and_exit;
	}

L
Linus Torvalds 已提交
631 632
	/* Get the device_object attached to the node */

L
Len Brown 已提交
633
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
634 635 636
	if (!obj_desc) {
		/* No object, create a new one */

L
Len Brown 已提交
637
		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
638 639 640 641 642
		if (!obj_desc) {
			status = AE_NO_MEMORY;
			goto unlock_and_exit;
		}

L
Len Brown 已提交
643 644
		status =
		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
645 646 647

		/* Remove local reference to the object */

L
Len Brown 已提交
648
		acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
649

L
Len Brown 已提交
650
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
651 652 653 654 655 656 657 658
			goto unlock_and_exit;
		}
	}

	/* Install the GPE block in the device_object */

	obj_desc->device.gpe_block = gpe_block;

L
Len Brown 已提交
659 660 661
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
662 663
}

L
Len Brown 已提交
664
EXPORT_SYMBOL(acpi_install_gpe_block);
L
Linus Torvalds 已提交
665 666 667 668 669 670 671 672 673 674 675 676 677

/*******************************************************************************
 *
 * 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 已提交
678
acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
L
Linus Torvalds 已提交
679
{
L
Len Brown 已提交
680 681 682
	union acpi_operand_object *obj_desc;
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
683

L
Len Brown 已提交
684
	ACPI_FUNCTION_TRACE("acpi_remove_gpe_block");
L
Linus Torvalds 已提交
685 686

	if (!gpe_device) {
L
Len Brown 已提交
687
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
688 689
	}

L
Len Brown 已提交
690 691
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
692 693 694
		return (status);
	}

L
Len Brown 已提交
695
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
696 697 698 699 700 701 702
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Get the device_object attached to the node */

L
Len Brown 已提交
703 704 705
	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 已提交
706 707 708 709
	}

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

L
Len Brown 已提交
710 711
	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
	if (ACPI_SUCCESS(status)) {
L
Linus Torvalds 已提交
712 713 714
		obj_desc->device.gpe_block = NULL;
	}

L
Len Brown 已提交
715 716 717
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
718
}
R
Robert Moore 已提交
719

L
Linus Torvalds 已提交
720
EXPORT_SYMBOL(acpi_remove_gpe_block);