evevent.c 8.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: evevent - Fixed Event handling and dispatch
 *
 *****************************************************************************/

/*
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
#include "accommon.h"
#include "acevents.h"
L
Linus Torvalds 已提交
47 48

#define _COMPONENT          ACPI_EVENTS
L
Len Brown 已提交
49
ACPI_MODULE_NAME("evevent")
L
Linus Torvalds 已提交
50

R
Robert Moore 已提交
51
/* Local prototypes */
L
Len Brown 已提交
52
static acpi_status acpi_ev_fixed_event_initialize(void);
R
Robert Moore 已提交
53

L
Len Brown 已提交
54
static u32 acpi_ev_fixed_event_dispatch(u32 event);
L
Linus Torvalds 已提交
55 56 57 58 59 60 61 62 63

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_initialize_events
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
64
 * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
L
Linus Torvalds 已提交
65 66 67
 *
 ******************************************************************************/

L
Len Brown 已提交
68
acpi_status acpi_ev_initialize_events(void)
L
Linus Torvalds 已提交
69
{
L
Len Brown 已提交
70
	acpi_status status;
L
Linus Torvalds 已提交
71

B
Bob Moore 已提交
72
	ACPI_FUNCTION_TRACE(ev_initialize_events);
L
Linus Torvalds 已提交
73 74

	/*
R
Robert Moore 已提交
75
	 * Initialize the Fixed and General Purpose Events. This is done prior to
76 77
	 * enabling SCIs to prevent interrupts from occurring before the handlers
	 * are installed.
L
Linus Torvalds 已提交
78
	 */
L
Len Brown 已提交
79 80
	status = acpi_ev_fixed_event_initialize();
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
81 82
		ACPI_EXCEPTION((AE_INFO, status,
				"Unable to initialize fixed events"));
L
Len Brown 已提交
83
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
84 85
	}

L
Len Brown 已提交
86 87
	status = acpi_ev_gpe_initialize();
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
88 89
		ACPI_EXCEPTION((AE_INFO, status,
				"Unable to initialize general purpose events"));
L
Len Brown 已提交
90
		return_ACPI_STATUS(status);
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 104 105 106 107
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_install_xrupt_handlers
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
 *
 ******************************************************************************/

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

B
Bob Moore 已提交
112
	ACPI_FUNCTION_TRACE(ev_install_xrupt_handlers);
L
Linus Torvalds 已提交
113 114 115

	/* Install the SCI handler */

L
Len Brown 已提交
116 117
	status = acpi_ev_install_sci_handler();
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
118 119
		ACPI_EXCEPTION((AE_INFO, status,
				"Unable to install System Control Interrupt handler"));
L
Len Brown 已提交
120
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
121 122 123 124
	}

	/* Install the handler for the Global Lock */

L
Len Brown 已提交
125 126
	status = acpi_ev_init_global_lock_handler();
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
127 128
		ACPI_EXCEPTION((AE_INFO, status,
				"Unable to initialize Global Lock handler"));
L
Len Brown 已提交
129
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
130 131 132
	}

	acpi_gbl_events_initialized = TRUE;
L
Len Brown 已提交
133
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
134 135 136 137 138 139 140 141 142 143
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_fixed_event_initialize
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
144
 * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
L
Linus Torvalds 已提交
145 146 147
 *
 ******************************************************************************/

L
Len Brown 已提交
148
static acpi_status acpi_ev_fixed_event_initialize(void)
L
Linus Torvalds 已提交
149
{
150
	u32 i;
L
Len Brown 已提交
151
	acpi_status status;
L
Linus Torvalds 已提交
152 153

	/*
154 155
	 * Initialize the structure that keeps track of fixed event handlers and
	 * enable the fixed events.
L
Linus Torvalds 已提交
156 157 158 159 160
	 */
	for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
		acpi_gbl_fixed_event_handlers[i].handler = NULL;
		acpi_gbl_fixed_event_handlers[i].context = NULL;

161
		/* Disable the fixed event */
L
Linus Torvalds 已提交
162 163

		if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
L
Len Brown 已提交
164
			status =
165
			    acpi_write_bit_register(acpi_gbl_fixed_event_info
166 167
						    [i].enable_register_id,
						    ACPI_DISABLE_EVENT);
L
Len Brown 已提交
168
			if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
				return (status);
			}
		}
	}

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_fixed_event_detect
 *
 * PARAMETERS:  None
 *
 * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
 *
R
Robert Moore 已提交
185
 * DESCRIPTION: Checks the PM status register for active fixed events
L
Linus Torvalds 已提交
186 187 188
 *
 ******************************************************************************/

L
Len Brown 已提交
189
u32 acpi_ev_fixed_event_detect(void)
L
Linus Torvalds 已提交
190
{
L
Len Brown 已提交
191 192 193
	u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
	u32 fixed_status;
	u32 fixed_enable;
194
	u32 i;
L
Linus Torvalds 已提交
195

B
Bob Moore 已提交
196
	ACPI_FUNCTION_NAME(ev_fixed_event_detect);
L
Linus Torvalds 已提交
197 198 199

	/*
	 * Read the fixed feature status and enable registers, as all the cases
200
	 * depend on their values. Ignore errors here.
L
Linus Torvalds 已提交
201
	 */
202 203
	(void)acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, &fixed_status);
	(void)acpi_hw_register_read(ACPI_REGISTER_PM1_ENABLE, &fixed_enable);
L
Linus Torvalds 已提交
204

L
Len Brown 已提交
205 206 207
	ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
			  "Fixed Event Block: Enable %08X Status %08X\n",
			  fixed_enable, fixed_status));
L
Linus Torvalds 已提交
208 209 210 211 212

	/*
	 * Check for all possible Fixed Events and dispatch those that are active
	 */
	for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
B
Bob Moore 已提交
213

L
Linus Torvalds 已提交
214 215
		/* Both the status and enable bits must be on for this event */

L
Len Brown 已提交
216 217 218 219
		if ((fixed_status & acpi_gbl_fixed_event_info[i].
		     status_bit_mask)
		    && (fixed_enable & acpi_gbl_fixed_event_info[i].
			enable_bit_mask)) {
B
Bob Moore 已提交
220

L
Linus Torvalds 已提交
221
			/* Found an active (signalled) event */
222
			acpi_os_fixed_event_count(i);
223
			int_status |= acpi_ev_fixed_event_dispatch(i);
L
Linus Torvalds 已提交
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
		}
	}

	return (int_status);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_fixed_event_dispatch
 *
 * PARAMETERS:  Event               - Event type
 *
 * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
 *
 * DESCRIPTION: Clears the status bit for the requested event, calls the
 *              handler that previously registered for the event.
 *
 ******************************************************************************/

L
Len Brown 已提交
243
static u32 acpi_ev_fixed_event_dispatch(u32 event)
L
Linus Torvalds 已提交
244 245
{

L
Len Brown 已提交
246
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
247 248 249

	/* Clear the status bit */

250
	(void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
251
				      status_register_id, ACPI_CLEAR_STATUS);
L
Linus Torvalds 已提交
252 253

	/*
254 255
	 * Make sure we've got a handler. If not, report an error. The event is
	 * disabled to prevent further interrupts.
L
Linus Torvalds 已提交
256 257
	 */
	if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
258
		(void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
259 260
					      enable_register_id,
					      ACPI_DISABLE_EVENT);
L
Linus Torvalds 已提交
261

B
Bob Moore 已提交
262
		ACPI_ERROR((AE_INFO,
263
			    "No installed handler for fixed event [0x%08X]",
B
Bob Moore 已提交
264
			    event));
L
Linus Torvalds 已提交
265 266 267 268 269 270

		return (ACPI_INTERRUPT_NOT_HANDLED);
	}

	/* Invoke the Fixed Event handler */

L
Len Brown 已提交
271 272
	return ((acpi_gbl_fixed_event_handlers[event].
		 handler) (acpi_gbl_fixed_event_handlers[event].context));
L
Linus Torvalds 已提交
273
}