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_WARNING((AE_INFO, "No FADT information present!"));
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 86
			ACPI_ERROR((AE_INFO,
				    "Could not transition to ACPI mode"));
L
Len Brown 已提交
87
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
88 89
		}

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

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

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

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

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

	if (!acpi_gbl_FADT) {
B
Bob Moore 已提交
116
		ACPI_WARNING((AE_INFO, "No FADT information present!"));
L
Len Brown 已提交
117
		return_ACPI_STATUS(AE_NO_ACPI_TABLES);
L
Linus Torvalds 已提交
118 119 120
	}

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

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

	/*
	 * Enable the requested fixed event (by writing a one to the
	 * enable register bit)
	 */
L
Len Brown 已提交
170 171 172 173 174
	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 已提交
175 176 177 178
	}

	/* Make sure that the hardware responded */

L
Len Brown 已提交
179 180 181 182 183
	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 已提交
184 185 186
	}

	if (value != 1) {
B
Bob Moore 已提交
187 188 189
		ACPI_ERROR((AE_INFO,
			    "Could not enable %s event",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
190
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
191 192
	}

L
Len Brown 已提交
193
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
194 195
}

L
Len Brown 已提交
196
EXPORT_SYMBOL(acpi_enable_event);
L
Linus Torvalds 已提交
197 198 199 200 201 202 203 204 205 206 207

/*******************************************************************************
 *
 * 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 已提交
208
 * DESCRIPTION: Set the type of an individual GPE
L
Linus Torvalds 已提交
209 210 211
 *
 ******************************************************************************/

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

L
Len Brown 已提交
217
	ACPI_FUNCTION_TRACE("acpi_set_gpe_type");
L
Linus Torvalds 已提交
218 219 220

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

L
Len Brown 已提交
221
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
222 223 224 225 226 227
	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 已提交
228
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
229 230 231 232
	}

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

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

L
Len Brown 已提交
235 236
      unlock_and_exit:
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
237 238
}

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

/*******************************************************************************
 *
 * 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 已提交
256
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
257
{
L
Len Brown 已提交
258 259
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
260

L
Len Brown 已提交
261
	ACPI_FUNCTION_TRACE("acpi_enable_gpe");
L
Linus Torvalds 已提交
262 263 264 265

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

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

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

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

	/* Perform the enable */

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

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

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

/*******************************************************************************
 *
 * 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 已提交
308
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
309
{
L
Len Brown 已提交
310 311
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
312

L
Len Brown 已提交
313
	ACPI_FUNCTION_TRACE("acpi_disable_gpe");
L
Linus Torvalds 已提交
314 315 316 317

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

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

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

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

L
Len Brown 已提交
332
	status = acpi_ev_disable_gpe(gpe_event_info);
L
Linus Torvalds 已提交
333

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

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

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

L
Len Brown 已提交
359
	ACPI_FUNCTION_TRACE("acpi_disable_event");
L
Linus Torvalds 已提交
360 361 362 363

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
364
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
365 366 367 368 369 370
	}

	/*
	 * Disable the requested fixed event (by writing a zero to the
	 * enable register bit)
	 */
L
Len Brown 已提交
371 372 373 374 375
	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 已提交
376 377
	}

L
Len Brown 已提交
378 379 380 381 382
	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 已提交
383 384 385
	}

	if (value != 0) {
B
Bob Moore 已提交
386 387 388
		ACPI_ERROR((AE_INFO,
			    "Could not disable %s events",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
389
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
390 391
	}

L
Len Brown 已提交
392
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
393 394
}

L
Len Brown 已提交
395
EXPORT_SYMBOL(acpi_disable_event);
L
Linus Torvalds 已提交
396 397 398 399 400 401 402 403 404 405 406 407 408

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

L
Len Brown 已提交
409
acpi_status acpi_clear_event(u32 event)
L
Linus Torvalds 已提交
410
{
L
Len Brown 已提交
411
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
412

L
Len Brown 已提交
413
	ACPI_FUNCTION_TRACE("acpi_clear_event");
L
Linus Torvalds 已提交
414 415 416 417

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
418
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
419 420 421 422 423 424
	}

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

L
Len Brown 已提交
429
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
430 431
}

L
Len Brown 已提交
432
EXPORT_SYMBOL(acpi_clear_event);
L
Linus Torvalds 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447

/*******************************************************************************
 *
 * 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 已提交
448
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
449
{
L
Len Brown 已提交
450 451
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
452

L
Len Brown 已提交
453
	ACPI_FUNCTION_TRACE("acpi_clear_gpe");
L
Linus Torvalds 已提交
454 455 456 457

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

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
458 459 460
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
461 462 463 464 465
		}
	}

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

L
Len Brown 已提交
466
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
467 468 469 470 471
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
472
	status = acpi_hw_clear_gpe(gpe_event_info);
L
Linus Torvalds 已提交
473

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

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

L
Len Brown 已提交
496
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
497
{
L
Len Brown 已提交
498
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
499

L
Len Brown 已提交
500
	ACPI_FUNCTION_TRACE("acpi_get_event_status");
L
Linus Torvalds 已提交
501 502

	if (!event_status) {
L
Len Brown 已提交
503
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
504 505 506 507 508
	}

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
509
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
510 511 512 513
	}

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

L
Len Brown 已提交
514 515 516
	status =
	    acpi_get_register(acpi_gbl_fixed_event_info[event].
			      status_register_id, event_status, ACPI_MTX_LOCK);
L
Linus Torvalds 已提交
517

L
Len Brown 已提交
518
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
519 520 521 522 523 524 525 526 527
}

/*******************************************************************************
 *
 * 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 已提交
528
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
529 530 531 532 533 534 535 536 537
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get status of an event (general purpose)
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
538 539
acpi_get_gpe_status(acpi_handle gpe_device,
		    u32 gpe_number, u32 flags, acpi_event_status * event_status)
L
Linus Torvalds 已提交
540
{
L
Len Brown 已提交
541 542
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
543

L
Len Brown 已提交
544
	ACPI_FUNCTION_TRACE("acpi_get_gpe_status");
L
Linus Torvalds 已提交
545 546 547 548

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

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
549 550 551
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
552 553 554 555 556
		}
	}

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

L
Len Brown 已提交
557
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
558 559 560 561 562 563 564
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Obtain status on the requested GPE number */

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

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

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

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

L
Len Brown 已提交
600
	ACPI_FUNCTION_TRACE("acpi_install_gpe_block");
L
Linus Torvalds 已提交
601

L
Len Brown 已提交
602 603
	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
604 605
	}

L
Len Brown 已提交
606 607
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
608 609 610
		return (status);
	}

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

B
Bob Moore 已提交
628 629 630 631 632 633 634
	/* 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 已提交
635 636
	/* Get the device_object attached to the node */

L
Len Brown 已提交
637
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
638 639 640
	if (!obj_desc) {
		/* No object, create a new one */

L
Len Brown 已提交
641
		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
642 643 644 645 646
		if (!obj_desc) {
			status = AE_NO_MEMORY;
			goto unlock_and_exit;
		}

L
Len Brown 已提交
647 648
		status =
		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
649 650 651

		/* Remove local reference to the object */

L
Len Brown 已提交
652
		acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
653

L
Len Brown 已提交
654
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
655 656 657 658 659 660 661 662
			goto unlock_and_exit;
		}
	}

	/* Install the GPE block in the device_object */

	obj_desc->device.gpe_block = gpe_block;

L
Len Brown 已提交
663 664 665
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
666 667
}

L
Len Brown 已提交
668
EXPORT_SYMBOL(acpi_install_gpe_block);
L
Linus Torvalds 已提交
669 670 671 672 673 674 675 676 677 678 679 680 681

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

L
Len Brown 已提交
688
	ACPI_FUNCTION_TRACE("acpi_remove_gpe_block");
L
Linus Torvalds 已提交
689 690

	if (!gpe_device) {
L
Len Brown 已提交
691
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
692 693
	}

L
Len Brown 已提交
694 695
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
696 697 698
		return (status);
	}

L
Len Brown 已提交
699
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
700 701 702 703 704 705 706
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Get the device_object attached to the node */

L
Len Brown 已提交
707 708 709
	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 已提交
710 711 712 713
	}

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

L
Len Brown 已提交
714 715
	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
	if (ACPI_SUCCESS(status)) {
L
Linus Torvalds 已提交
716 717 718
		obj_desc->device.gpe_block = NULL;
	}

L
Len Brown 已提交
719 720 721
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
722
}
R
Robert Moore 已提交
723

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