diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/acpi/events |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/acpi/events')
-rw-r--r-- | drivers/acpi/events/Makefile | 9 | ||||
-rw-r--r-- | drivers/acpi/events/evevent.c | 297 | ||||
-rw-r--r-- | drivers/acpi/events/evgpe.c | 756 | ||||
-rw-r--r-- | drivers/acpi/events/evgpeblk.c | 1141 | ||||
-rw-r--r-- | drivers/acpi/events/evmisc.c | 588 | ||||
-rw-r--r-- | drivers/acpi/events/evregion.c | 1067 | ||||
-rw-r--r-- | drivers/acpi/events/evrgnini.c | 580 | ||||
-rw-r--r-- | drivers/acpi/events/evsci.c | 199 | ||||
-rw-r--r-- | drivers/acpi/events/evxface.c | 834 | ||||
-rw-r--r-- | drivers/acpi/events/evxfevnt.c | 778 | ||||
-rw-r--r-- | drivers/acpi/events/evxfregn.c | 247 |
11 files changed, 6496 insertions, 0 deletions
diff --git a/drivers/acpi/events/Makefile b/drivers/acpi/events/Makefile new file mode 100644 index 000000000000..d29f2ee449cc --- /dev/null +++ b/drivers/acpi/events/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # | ||
2 | # Makefile for all Linux ACPI interpreter subdirectories | ||
3 | # | ||
4 | |||
5 | obj-y := evevent.o evregion.o evsci.o evxfevnt.o \ | ||
6 | evmisc.o evrgnini.o evxface.o evxfregn.o \ | ||
7 | evgpe.o evgpeblk.o | ||
8 | |||
9 | EXTRA_CFLAGS += $(ACPI_CFLAGS) | ||
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c new file mode 100644 index 000000000000..2a213604ae51 --- /dev/null +++ b/drivers/acpi/events/evevent.c | |||
@@ -0,0 +1,297 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evevent - Fixed Event handling and dispatch | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | #include <acpi/acpi.h> | ||
45 | #include <acpi/acevents.h> | ||
46 | |||
47 | #define _COMPONENT ACPI_EVENTS | ||
48 | ACPI_MODULE_NAME ("evevent") | ||
49 | |||
50 | |||
51 | /******************************************************************************* | ||
52 | * | ||
53 | * FUNCTION: acpi_ev_initialize_events | ||
54 | * | ||
55 | * PARAMETERS: None | ||
56 | * | ||
57 | * RETURN: Status | ||
58 | * | ||
59 | * DESCRIPTION: Initialize global data structures for events. | ||
60 | * | ||
61 | ******************************************************************************/ | ||
62 | |||
63 | acpi_status | ||
64 | acpi_ev_initialize_events ( | ||
65 | void) | ||
66 | { | ||
67 | acpi_status status; | ||
68 | |||
69 | |||
70 | ACPI_FUNCTION_TRACE ("ev_initialize_events"); | ||
71 | |||
72 | |||
73 | /* Make sure we have ACPI tables */ | ||
74 | |||
75 | if (!acpi_gbl_DSDT) { | ||
76 | ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No ACPI tables present!\n")); | ||
77 | return_ACPI_STATUS (AE_NO_ACPI_TABLES); | ||
78 | } | ||
79 | |||
80 | /* | ||
81 | * Initialize the Fixed and General Purpose Events. This is | ||
82 | * done prior to enabling SCIs to prevent interrupts from | ||
83 | * occurring before handers are installed. | ||
84 | */ | ||
85 | status = acpi_ev_fixed_event_initialize (); | ||
86 | if (ACPI_FAILURE (status)) { | ||
87 | ACPI_REPORT_ERROR (( | ||
88 | "Unable to initialize fixed events, %s\n", | ||
89 | acpi_format_exception (status))); | ||
90 | return_ACPI_STATUS (status); | ||
91 | } | ||
92 | |||
93 | status = acpi_ev_gpe_initialize (); | ||
94 | if (ACPI_FAILURE (status)) { | ||
95 | ACPI_REPORT_ERROR (( | ||
96 | "Unable to initialize general purpose events, %s\n", | ||
97 | acpi_format_exception (status))); | ||
98 | return_ACPI_STATUS (status); | ||
99 | } | ||
100 | |||
101 | return_ACPI_STATUS (status); | ||
102 | } | ||
103 | |||
104 | |||
105 | /******************************************************************************* | ||
106 | * | ||
107 | * FUNCTION: acpi_ev_install_xrupt_handlers | ||
108 | * | ||
109 | * PARAMETERS: None | ||
110 | * | ||
111 | * RETURN: Status | ||
112 | * | ||
113 | * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock | ||
114 | * | ||
115 | ******************************************************************************/ | ||
116 | |||
117 | acpi_status | ||
118 | acpi_ev_install_xrupt_handlers ( | ||
119 | void) | ||
120 | { | ||
121 | acpi_status status; | ||
122 | |||
123 | |||
124 | ACPI_FUNCTION_TRACE ("ev_install_xrupt_handlers"); | ||
125 | |||
126 | |||
127 | /* Install the SCI handler */ | ||
128 | |||
129 | status = acpi_ev_install_sci_handler (); | ||
130 | if (ACPI_FAILURE (status)) { | ||
131 | ACPI_REPORT_ERROR (( | ||
132 | "Unable to install System Control Interrupt Handler, %s\n", | ||
133 | acpi_format_exception (status))); | ||
134 | return_ACPI_STATUS (status); | ||
135 | } | ||
136 | |||
137 | /* Install the handler for the Global Lock */ | ||
138 | |||
139 | status = acpi_ev_init_global_lock_handler (); | ||
140 | if (ACPI_FAILURE (status)) { | ||
141 | ACPI_REPORT_ERROR (( | ||
142 | "Unable to initialize Global Lock handler, %s\n", | ||
143 | acpi_format_exception (status))); | ||
144 | return_ACPI_STATUS (status); | ||
145 | } | ||
146 | |||
147 | acpi_gbl_events_initialized = TRUE; | ||
148 | return_ACPI_STATUS (status); | ||
149 | } | ||
150 | |||
151 | |||
152 | /******************************************************************************* | ||
153 | * | ||
154 | * FUNCTION: acpi_ev_fixed_event_initialize | ||
155 | * | ||
156 | * PARAMETERS: None | ||
157 | * | ||
158 | * RETURN: Status | ||
159 | * | ||
160 | * DESCRIPTION: Install the fixed event handlers and enable the fixed events. | ||
161 | * | ||
162 | ******************************************************************************/ | ||
163 | |||
164 | acpi_status | ||
165 | acpi_ev_fixed_event_initialize ( | ||
166 | void) | ||
167 | { | ||
168 | acpi_native_uint i; | ||
169 | acpi_status status; | ||
170 | |||
171 | |||
172 | /* | ||
173 | * Initialize the structure that keeps track of fixed event handlers | ||
174 | * and enable the fixed events. | ||
175 | */ | ||
176 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { | ||
177 | acpi_gbl_fixed_event_handlers[i].handler = NULL; | ||
178 | acpi_gbl_fixed_event_handlers[i].context = NULL; | ||
179 | |||
180 | /* Enable the fixed event */ | ||
181 | |||
182 | if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) { | ||
183 | status = acpi_set_register (acpi_gbl_fixed_event_info[i].enable_register_id, | ||
184 | 0, ACPI_MTX_LOCK); | ||
185 | if (ACPI_FAILURE (status)) { | ||
186 | return (status); | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | |||
191 | return (AE_OK); | ||
192 | } | ||
193 | |||
194 | |||
195 | /******************************************************************************* | ||
196 | * | ||
197 | * FUNCTION: acpi_ev_fixed_event_detect | ||
198 | * | ||
199 | * PARAMETERS: None | ||
200 | * | ||
201 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED | ||
202 | * | ||
203 | * DESCRIPTION: Checks the PM status register for fixed events | ||
204 | * | ||
205 | ******************************************************************************/ | ||
206 | |||
207 | u32 | ||
208 | acpi_ev_fixed_event_detect ( | ||
209 | void) | ||
210 | { | ||
211 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; | ||
212 | u32 fixed_status; | ||
213 | u32 fixed_enable; | ||
214 | acpi_native_uint i; | ||
215 | |||
216 | |||
217 | ACPI_FUNCTION_NAME ("ev_fixed_event_detect"); | ||
218 | |||
219 | |||
220 | /* | ||
221 | * Read the fixed feature status and enable registers, as all the cases | ||
222 | * depend on their values. Ignore errors here. | ||
223 | */ | ||
224 | (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, &fixed_status); | ||
225 | (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE, &fixed_enable); | ||
226 | |||
227 | ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, | ||
228 | "Fixed Event Block: Enable %08X Status %08X\n", | ||
229 | fixed_enable, fixed_status)); | ||
230 | |||
231 | /* | ||
232 | * Check for all possible Fixed Events and dispatch those that are active | ||
233 | */ | ||
234 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { | ||
235 | /* Both the status and enable bits must be on for this event */ | ||
236 | |||
237 | if ((fixed_status & acpi_gbl_fixed_event_info[i].status_bit_mask) && | ||
238 | (fixed_enable & acpi_gbl_fixed_event_info[i].enable_bit_mask)) { | ||
239 | /* Found an active (signalled) event */ | ||
240 | |||
241 | int_status |= acpi_ev_fixed_event_dispatch ((u32) i); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | return (int_status); | ||
246 | } | ||
247 | |||
248 | |||
249 | /******************************************************************************* | ||
250 | * | ||
251 | * FUNCTION: acpi_ev_fixed_event_dispatch | ||
252 | * | ||
253 | * PARAMETERS: Event - Event type | ||
254 | * | ||
255 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED | ||
256 | * | ||
257 | * DESCRIPTION: Clears the status bit for the requested event, calls the | ||
258 | * handler that previously registered for the event. | ||
259 | * | ||
260 | ******************************************************************************/ | ||
261 | |||
262 | u32 | ||
263 | acpi_ev_fixed_event_dispatch ( | ||
264 | u32 event) | ||
265 | { | ||
266 | |||
267 | |||
268 | ACPI_FUNCTION_ENTRY (); | ||
269 | |||
270 | |||
271 | /* Clear the status bit */ | ||
272 | |||
273 | (void) acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id, | ||
274 | 1, ACPI_MTX_DO_NOT_LOCK); | ||
275 | |||
276 | /* | ||
277 | * Make sure we've got a handler. If not, report an error. | ||
278 | * The event is disabled to prevent further interrupts. | ||
279 | */ | ||
280 | if (NULL == acpi_gbl_fixed_event_handlers[event].handler) { | ||
281 | (void) acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id, | ||
282 | 0, ACPI_MTX_DO_NOT_LOCK); | ||
283 | |||
284 | ACPI_REPORT_ERROR ( | ||
285 | ("No installed handler for fixed event [%08X]\n", | ||
286 | event)); | ||
287 | |||
288 | return (ACPI_INTERRUPT_NOT_HANDLED); | ||
289 | } | ||
290 | |||
291 | /* Invoke the Fixed Event handler */ | ||
292 | |||
293 | return ((acpi_gbl_fixed_event_handlers[event].handler)( | ||
294 | acpi_gbl_fixed_event_handlers[event].context)); | ||
295 | } | ||
296 | |||
297 | |||
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c new file mode 100644 index 000000000000..118d72ac7c76 --- /dev/null +++ b/drivers/acpi/events/evgpe.c | |||
@@ -0,0 +1,756 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evgpe - General Purpose Event handling and dispatch | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | #include <acpi/acpi.h> | ||
45 | #include <acpi/acevents.h> | ||
46 | #include <acpi/acnamesp.h> | ||
47 | |||
48 | #define _COMPONENT ACPI_EVENTS | ||
49 | ACPI_MODULE_NAME ("evgpe") | ||
50 | |||
51 | |||
52 | /******************************************************************************* | ||
53 | * | ||
54 | * FUNCTION: acpi_ev_set_gpe_type | ||
55 | * | ||
56 | * PARAMETERS: gpe_event_info - GPE to set | ||
57 | * Type - New type | ||
58 | * | ||
59 | * RETURN: Status | ||
60 | * | ||
61 | * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run) | ||
62 | * | ||
63 | ******************************************************************************/ | ||
64 | |||
65 | acpi_status | ||
66 | acpi_ev_set_gpe_type ( | ||
67 | struct acpi_gpe_event_info *gpe_event_info, | ||
68 | u8 type) | ||
69 | { | ||
70 | acpi_status status; | ||
71 | |||
72 | |||
73 | ACPI_FUNCTION_TRACE ("ev_set_gpe_type"); | ||
74 | |||
75 | |||
76 | /* Validate type and update register enable masks */ | ||
77 | |||
78 | switch (type) { | ||
79 | case ACPI_GPE_TYPE_WAKE: | ||
80 | case ACPI_GPE_TYPE_RUNTIME: | ||
81 | case ACPI_GPE_TYPE_WAKE_RUN: | ||
82 | break; | ||
83 | |||
84 | default: | ||
85 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
86 | } | ||
87 | |||
88 | /* Disable the GPE if currently enabled */ | ||
89 | |||
90 | status = acpi_ev_disable_gpe (gpe_event_info); | ||
91 | |||
92 | /* Type was validated above */ | ||
93 | |||
94 | gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK; /* Clear type bits */ | ||
95 | gpe_event_info->flags |= type; /* Insert type */ | ||
96 | return_ACPI_STATUS (status); | ||
97 | } | ||
98 | |||
99 | |||
100 | /******************************************************************************* | ||
101 | * | ||
102 | * FUNCTION: acpi_ev_update_gpe_enable_masks | ||
103 | * | ||
104 | * PARAMETERS: gpe_event_info - GPE to update | ||
105 | * Type - What to do: ACPI_GPE_DISABLE or | ||
106 | * ACPI_GPE_ENABLE | ||
107 | * | ||
108 | * RETURN: Status | ||
109 | * | ||
110 | * DESCRIPTION: Updates GPE register enable masks based on the GPE type | ||
111 | * | ||
112 | ******************************************************************************/ | ||
113 | |||
114 | acpi_status | ||
115 | acpi_ev_update_gpe_enable_masks ( | ||
116 | struct acpi_gpe_event_info *gpe_event_info, | ||
117 | u8 type) | ||
118 | { | ||
119 | struct acpi_gpe_register_info *gpe_register_info; | ||
120 | u8 register_bit; | ||
121 | |||
122 | |||
123 | ACPI_FUNCTION_TRACE ("ev_update_gpe_enable_masks"); | ||
124 | |||
125 | |||
126 | gpe_register_info = gpe_event_info->register_info; | ||
127 | if (!gpe_register_info) { | ||
128 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
129 | } | ||
130 | register_bit = gpe_event_info->register_bit; | ||
131 | |||
132 | /* 1) Disable case. Simply clear all enable bits */ | ||
133 | |||
134 | if (type == ACPI_GPE_DISABLE) { | ||
135 | ACPI_CLEAR_BIT (gpe_register_info->enable_for_wake, register_bit); | ||
136 | ACPI_CLEAR_BIT (gpe_register_info->enable_for_run, register_bit); | ||
137 | return_ACPI_STATUS (AE_OK); | ||
138 | } | ||
139 | |||
140 | /* 2) Enable case. Set/Clear the appropriate enable bits */ | ||
141 | |||
142 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { | ||
143 | case ACPI_GPE_TYPE_WAKE: | ||
144 | ACPI_SET_BIT (gpe_register_info->enable_for_wake, register_bit); | ||
145 | ACPI_CLEAR_BIT (gpe_register_info->enable_for_run, register_bit); | ||
146 | break; | ||
147 | |||
148 | case ACPI_GPE_TYPE_RUNTIME: | ||
149 | ACPI_CLEAR_BIT (gpe_register_info->enable_for_wake, register_bit); | ||
150 | ACPI_SET_BIT (gpe_register_info->enable_for_run, register_bit); | ||
151 | break; | ||
152 | |||
153 | case ACPI_GPE_TYPE_WAKE_RUN: | ||
154 | ACPI_SET_BIT (gpe_register_info->enable_for_wake, register_bit); | ||
155 | ACPI_SET_BIT (gpe_register_info->enable_for_run, register_bit); | ||
156 | break; | ||
157 | |||
158 | default: | ||
159 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
160 | } | ||
161 | |||
162 | return_ACPI_STATUS (AE_OK); | ||
163 | } | ||
164 | |||
165 | |||
166 | /******************************************************************************* | ||
167 | * | ||
168 | * FUNCTION: acpi_ev_enable_gpe | ||
169 | * | ||
170 | * PARAMETERS: gpe_event_info - GPE to enable | ||
171 | * write_to_hardware - Enable now, or just mark data structs | ||
172 | * (WAKE GPEs should be deferred) | ||
173 | * | ||
174 | * RETURN: Status | ||
175 | * | ||
176 | * DESCRIPTION: Enable a GPE based on the GPE type | ||
177 | * | ||
178 | ******************************************************************************/ | ||
179 | |||
180 | acpi_status | ||
181 | acpi_ev_enable_gpe ( | ||
182 | struct acpi_gpe_event_info *gpe_event_info, | ||
183 | u8 write_to_hardware) | ||
184 | { | ||
185 | acpi_status status; | ||
186 | |||
187 | |||
188 | ACPI_FUNCTION_TRACE ("ev_enable_gpe"); | ||
189 | |||
190 | |||
191 | /* Make sure HW enable masks are updated */ | ||
192 | |||
193 | status = acpi_ev_update_gpe_enable_masks (gpe_event_info, ACPI_GPE_ENABLE); | ||
194 | if (ACPI_FAILURE (status)) { | ||
195 | return_ACPI_STATUS (status); | ||
196 | } | ||
197 | |||
198 | /* Mark wake-enabled or HW enable, or both */ | ||
199 | |||
200 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { | ||
201 | case ACPI_GPE_TYPE_WAKE: | ||
202 | |||
203 | ACPI_SET_BIT (gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); | ||
204 | break; | ||
205 | |||
206 | case ACPI_GPE_TYPE_WAKE_RUN: | ||
207 | |||
208 | ACPI_SET_BIT (gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); | ||
209 | |||
210 | /*lint -fallthrough */ | ||
211 | |||
212 | case ACPI_GPE_TYPE_RUNTIME: | ||
213 | |||
214 | ACPI_SET_BIT (gpe_event_info->flags, ACPI_GPE_RUN_ENABLED); | ||
215 | |||
216 | if (write_to_hardware) { | ||
217 | /* Clear the GPE (of stale events), then enable it */ | ||
218 | |||
219 | status = acpi_hw_clear_gpe (gpe_event_info); | ||
220 | if (ACPI_FAILURE (status)) { | ||
221 | return_ACPI_STATUS (status); | ||
222 | } | ||
223 | |||
224 | /* Enable the requested runtime GPE */ | ||
225 | |||
226 | status = acpi_hw_write_gpe_enable_reg (gpe_event_info); | ||
227 | } | ||
228 | break; | ||
229 | |||
230 | default: | ||
231 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
232 | } | ||
233 | |||
234 | return_ACPI_STATUS (AE_OK); | ||
235 | } | ||
236 | |||
237 | |||
238 | /******************************************************************************* | ||
239 | * | ||
240 | * FUNCTION: acpi_ev_disable_gpe | ||
241 | * | ||
242 | * PARAMETERS: gpe_event_info - GPE to disable | ||
243 | * | ||
244 | * RETURN: Status | ||
245 | * | ||
246 | * DESCRIPTION: Disable a GPE based on the GPE type | ||
247 | * | ||
248 | ******************************************************************************/ | ||
249 | |||
250 | acpi_status | ||
251 | acpi_ev_disable_gpe ( | ||
252 | struct acpi_gpe_event_info *gpe_event_info) | ||
253 | { | ||
254 | acpi_status status; | ||
255 | |||
256 | |||
257 | ACPI_FUNCTION_TRACE ("ev_disable_gpe"); | ||
258 | |||
259 | |||
260 | if (!(gpe_event_info->flags & ACPI_GPE_ENABLE_MASK)) { | ||
261 | return_ACPI_STATUS (AE_OK); | ||
262 | } | ||
263 | |||
264 | /* Make sure HW enable masks are updated */ | ||
265 | |||
266 | status = acpi_ev_update_gpe_enable_masks (gpe_event_info, ACPI_GPE_DISABLE); | ||
267 | if (ACPI_FAILURE (status)) { | ||
268 | return_ACPI_STATUS (status); | ||
269 | } | ||
270 | |||
271 | /* Mark wake-disabled or HW disable, or both */ | ||
272 | |||
273 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { | ||
274 | case ACPI_GPE_TYPE_WAKE: | ||
275 | ACPI_CLEAR_BIT (gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); | ||
276 | break; | ||
277 | |||
278 | case ACPI_GPE_TYPE_WAKE_RUN: | ||
279 | ACPI_CLEAR_BIT (gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); | ||
280 | |||
281 | /*lint -fallthrough */ | ||
282 | |||
283 | case ACPI_GPE_TYPE_RUNTIME: | ||
284 | |||
285 | /* Disable the requested runtime GPE */ | ||
286 | |||
287 | ACPI_CLEAR_BIT (gpe_event_info->flags, ACPI_GPE_RUN_ENABLED); | ||
288 | status = acpi_hw_write_gpe_enable_reg (gpe_event_info); | ||
289 | break; | ||
290 | |||
291 | default: | ||
292 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
293 | } | ||
294 | |||
295 | return_ACPI_STATUS (AE_OK); | ||
296 | } | ||
297 | |||
298 | |||
299 | /******************************************************************************* | ||
300 | * | ||
301 | * FUNCTION: acpi_ev_get_gpe_event_info | ||
302 | * | ||
303 | * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 | ||
304 | * gpe_number - Raw GPE number | ||
305 | * | ||
306 | * RETURN: A GPE event_info struct. NULL if not a valid GPE | ||
307 | * | ||
308 | * DESCRIPTION: Returns the event_info struct associated with this GPE. | ||
309 | * Validates the gpe_block and the gpe_number | ||
310 | * | ||
311 | * Should be called only when the GPE lists are semaphore locked | ||
312 | * and not subject to change. | ||
313 | * | ||
314 | ******************************************************************************/ | ||
315 | |||
316 | struct acpi_gpe_event_info * | ||
317 | acpi_ev_get_gpe_event_info ( | ||
318 | acpi_handle gpe_device, | ||
319 | u32 gpe_number) | ||
320 | { | ||
321 | union acpi_operand_object *obj_desc; | ||
322 | struct acpi_gpe_block_info *gpe_block; | ||
323 | acpi_native_uint i; | ||
324 | |||
325 | |||
326 | ACPI_FUNCTION_ENTRY (); | ||
327 | |||
328 | |||
329 | /* A NULL gpe_block means use the FADT-defined GPE block(s) */ | ||
330 | |||
331 | if (!gpe_device) { | ||
332 | /* Examine GPE Block 0 and 1 (These blocks are permanent) */ | ||
333 | |||
334 | for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) { | ||
335 | gpe_block = acpi_gbl_gpe_fadt_blocks[i]; | ||
336 | if (gpe_block) { | ||
337 | if ((gpe_number >= gpe_block->block_base_number) && | ||
338 | (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) { | ||
339 | return (&gpe_block->event_info[gpe_number - gpe_block->block_base_number]); | ||
340 | } | ||
341 | } | ||
342 | } | ||
343 | |||
344 | /* The gpe_number was not in the range of either FADT GPE block */ | ||
345 | |||
346 | return (NULL); | ||
347 | } | ||
348 | |||
349 | /* A Non-NULL gpe_device means this is a GPE Block Device */ | ||
350 | |||
351 | obj_desc = acpi_ns_get_attached_object ((struct acpi_namespace_node *) gpe_device); | ||
352 | if (!obj_desc || | ||
353 | !obj_desc->device.gpe_block) { | ||
354 | return (NULL); | ||
355 | } | ||
356 | |||
357 | gpe_block = obj_desc->device.gpe_block; | ||
358 | |||
359 | if ((gpe_number >= gpe_block->block_base_number) && | ||
360 | (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) { | ||
361 | return (&gpe_block->event_info[gpe_number - gpe_block->block_base_number]); | ||
362 | } | ||
363 | |||
364 | return (NULL); | ||
365 | } | ||
366 | |||
367 | |||
368 | /******************************************************************************* | ||
369 | * | ||
370 | * FUNCTION: acpi_ev_gpe_detect | ||
371 | * | ||
372 | * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt. | ||
373 | * Can have multiple GPE blocks attached. | ||
374 | * | ||
375 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED | ||
376 | * | ||
377 | * DESCRIPTION: Detect if any GP events have occurred. This function is | ||
378 | * executed at interrupt level. | ||
379 | * | ||
380 | ******************************************************************************/ | ||
381 | |||
382 | u32 | ||
383 | acpi_ev_gpe_detect ( | ||
384 | struct acpi_gpe_xrupt_info *gpe_xrupt_list) | ||
385 | { | ||
386 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; | ||
387 | u8 enabled_status_byte; | ||
388 | struct acpi_gpe_register_info *gpe_register_info; | ||
389 | u32 status_reg; | ||
390 | u32 enable_reg; | ||
391 | acpi_status status; | ||
392 | struct acpi_gpe_block_info *gpe_block; | ||
393 | acpi_native_uint i; | ||
394 | acpi_native_uint j; | ||
395 | |||
396 | |||
397 | ACPI_FUNCTION_NAME ("ev_gpe_detect"); | ||
398 | |||
399 | /* Check for the case where there are no GPEs */ | ||
400 | |||
401 | if (!gpe_xrupt_list) { | ||
402 | return (int_status); | ||
403 | } | ||
404 | |||
405 | /* Examine all GPE blocks attached to this interrupt level */ | ||
406 | |||
407 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_ISR); | ||
408 | gpe_block = gpe_xrupt_list->gpe_block_list_head; | ||
409 | while (gpe_block) { | ||
410 | /* | ||
411 | * Read all of the 8-bit GPE status and enable registers | ||
412 | * in this GPE block, saving all of them. | ||
413 | * Find all currently active GP events. | ||
414 | */ | ||
415 | for (i = 0; i < gpe_block->register_count; i++) { | ||
416 | /* Get the next status/enable pair */ | ||
417 | |||
418 | gpe_register_info = &gpe_block->register_info[i]; | ||
419 | |||
420 | /* Read the Status Register */ | ||
421 | |||
422 | status = acpi_hw_low_level_read (ACPI_GPE_REGISTER_WIDTH, &status_reg, | ||
423 | &gpe_register_info->status_address); | ||
424 | if (ACPI_FAILURE (status)) { | ||
425 | goto unlock_and_exit; | ||
426 | } | ||
427 | |||
428 | /* Read the Enable Register */ | ||
429 | |||
430 | status = acpi_hw_low_level_read (ACPI_GPE_REGISTER_WIDTH, &enable_reg, | ||
431 | &gpe_register_info->enable_address); | ||
432 | if (ACPI_FAILURE (status)) { | ||
433 | goto unlock_and_exit; | ||
434 | } | ||
435 | |||
436 | ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, | ||
437 | "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n", | ||
438 | gpe_register_info->base_gpe_number, status_reg, enable_reg)); | ||
439 | |||
440 | /* First check if there is anything active at all in this register */ | ||
441 | |||
442 | enabled_status_byte = (u8) (status_reg & enable_reg); | ||
443 | if (!enabled_status_byte) { | ||
444 | /* No active GPEs in this register, move on */ | ||
445 | |||
446 | continue; | ||
447 | } | ||
448 | |||
449 | /* Now look at the individual GPEs in this byte register */ | ||
450 | |||
451 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { | ||
452 | /* Examine one GPE bit */ | ||
453 | |||
454 | if (enabled_status_byte & acpi_gbl_decode_to8bit[j]) { | ||
455 | /* | ||
456 | * Found an active GPE. Dispatch the event to a handler | ||
457 | * or method. | ||
458 | */ | ||
459 | int_status |= acpi_ev_gpe_dispatch ( | ||
460 | &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j], | ||
461 | (u32) j + gpe_register_info->base_gpe_number); | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | |||
466 | gpe_block = gpe_block->next; | ||
467 | } | ||
468 | |||
469 | unlock_and_exit: | ||
470 | |||
471 | acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_ISR); | ||
472 | return (int_status); | ||
473 | } | ||
474 | |||
475 | |||
476 | /******************************************************************************* | ||
477 | * | ||
478 | * FUNCTION: acpi_ev_asynch_execute_gpe_method | ||
479 | * | ||
480 | * PARAMETERS: Context (gpe_event_info) - Info for this GPE | ||
481 | * | ||
482 | * RETURN: None | ||
483 | * | ||
484 | * DESCRIPTION: Perform the actual execution of a GPE control method. This | ||
485 | * function is called from an invocation of acpi_os_queue_for_execution | ||
486 | * (and therefore does NOT execute at interrupt level) so that | ||
487 | * the control method itself is not executed in the context of | ||
488 | * an interrupt handler. | ||
489 | * | ||
490 | ******************************************************************************/ | ||
491 | |||
492 | static void ACPI_SYSTEM_XFACE | ||
493 | acpi_ev_asynch_execute_gpe_method ( | ||
494 | void *context) | ||
495 | { | ||
496 | struct acpi_gpe_event_info *gpe_event_info = (void *) context; | ||
497 | u32 gpe_number = 0; | ||
498 | acpi_status status; | ||
499 | struct acpi_gpe_event_info local_gpe_event_info; | ||
500 | struct acpi_parameter_info info; | ||
501 | |||
502 | |||
503 | ACPI_FUNCTION_TRACE ("ev_asynch_execute_gpe_method"); | ||
504 | |||
505 | |||
506 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
507 | if (ACPI_FAILURE (status)) { | ||
508 | return_VOID; | ||
509 | } | ||
510 | |||
511 | /* Must revalidate the gpe_number/gpe_block */ | ||
512 | |||
513 | if (!acpi_ev_valid_gpe_event (gpe_event_info)) { | ||
514 | status = acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
515 | return_VOID; | ||
516 | } | ||
517 | |||
518 | /* Set the GPE flags for return to enabled state */ | ||
519 | |||
520 | (void) acpi_ev_enable_gpe (gpe_event_info, FALSE); | ||
521 | |||
522 | /* | ||
523 | * Take a snapshot of the GPE info for this level - we copy the | ||
524 | * info to prevent a race condition with remove_handler/remove_block. | ||
525 | */ | ||
526 | ACPI_MEMCPY (&local_gpe_event_info, gpe_event_info, sizeof (struct acpi_gpe_event_info)); | ||
527 | |||
528 | status = acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
529 | if (ACPI_FAILURE (status)) { | ||
530 | return_VOID; | ||
531 | } | ||
532 | |||
533 | /* | ||
534 | * Must check for control method type dispatch one more | ||
535 | * time to avoid race with ev_gpe_install_handler | ||
536 | */ | ||
537 | if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD) { | ||
538 | /* | ||
539 | * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx | ||
540 | * control method that corresponds to this GPE | ||
541 | */ | ||
542 | info.node = local_gpe_event_info.dispatch.method_node; | ||
543 | info.parameters = ACPI_CAST_PTR (union acpi_operand_object *, gpe_event_info); | ||
544 | info.parameter_type = ACPI_PARAM_GPE; | ||
545 | |||
546 | status = acpi_ns_evaluate_by_handle (&info); | ||
547 | if (ACPI_FAILURE (status)) { | ||
548 | ACPI_REPORT_ERROR (( | ||
549 | "%s while evaluating method [%4.4s] for GPE[%2X]\n", | ||
550 | acpi_format_exception (status), | ||
551 | acpi_ut_get_node_name (local_gpe_event_info.dispatch.method_node), | ||
552 | gpe_number)); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | if ((local_gpe_event_info.flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED) { | ||
557 | /* | ||
558 | * GPE is level-triggered, we clear the GPE status bit after | ||
559 | * handling the event. | ||
560 | */ | ||
561 | status = acpi_hw_clear_gpe (&local_gpe_event_info); | ||
562 | if (ACPI_FAILURE (status)) { | ||
563 | return_VOID; | ||
564 | } | ||
565 | } | ||
566 | |||
567 | /* Enable this GPE */ | ||
568 | |||
569 | (void) acpi_hw_write_gpe_enable_reg (&local_gpe_event_info); | ||
570 | return_VOID; | ||
571 | } | ||
572 | |||
573 | |||
574 | /******************************************************************************* | ||
575 | * | ||
576 | * FUNCTION: acpi_ev_gpe_dispatch | ||
577 | * | ||
578 | * PARAMETERS: gpe_event_info - info for this GPE | ||
579 | * gpe_number - Number relative to the parent GPE block | ||
580 | * | ||
581 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED | ||
582 | * | ||
583 | * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC) | ||
584 | * or method (e.g. _Lxx/_Exx) handler. | ||
585 | * | ||
586 | * This function executes at interrupt level. | ||
587 | * | ||
588 | ******************************************************************************/ | ||
589 | |||
590 | u32 | ||
591 | acpi_ev_gpe_dispatch ( | ||
592 | struct acpi_gpe_event_info *gpe_event_info, | ||
593 | u32 gpe_number) | ||
594 | { | ||
595 | acpi_status status; | ||
596 | |||
597 | |||
598 | ACPI_FUNCTION_TRACE ("ev_gpe_dispatch"); | ||
599 | |||
600 | |||
601 | /* | ||
602 | * If edge-triggered, clear the GPE status bit now. Note that | ||
603 | * level-triggered events are cleared after the GPE is serviced. | ||
604 | */ | ||
605 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_EDGE_TRIGGERED) { | ||
606 | status = acpi_hw_clear_gpe (gpe_event_info); | ||
607 | if (ACPI_FAILURE (status)) { | ||
608 | ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: %s, Unable to clear GPE[%2X]\n", | ||
609 | acpi_format_exception (status), gpe_number)); | ||
610 | return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | ||
611 | } | ||
612 | } | ||
613 | |||
614 | /* Save current system state */ | ||
615 | |||
616 | if (acpi_gbl_system_awake_and_running) { | ||
617 | ACPI_SET_BIT (gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING); | ||
618 | } | ||
619 | else { | ||
620 | ACPI_CLEAR_BIT (gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING); | ||
621 | } | ||
622 | |||
623 | /* | ||
624 | * Dispatch the GPE to either an installed handler, or the control | ||
625 | * method associated with this GPE (_Lxx or _Exx). | ||
626 | * If a handler exists, we invoke it and do not attempt to run the method. | ||
627 | * If there is neither a handler nor a method, we disable the level to | ||
628 | * prevent further events from coming in here. | ||
629 | */ | ||
630 | switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) { | ||
631 | case ACPI_GPE_DISPATCH_HANDLER: | ||
632 | |||
633 | /* | ||
634 | * Invoke the installed handler (at interrupt level) | ||
635 | * Ignore return status for now. TBD: leave GPE disabled on error? | ||
636 | */ | ||
637 | (void) gpe_event_info->dispatch.handler->address ( | ||
638 | gpe_event_info->dispatch.handler->context); | ||
639 | |||
640 | /* It is now safe to clear level-triggered events. */ | ||
641 | |||
642 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED) { | ||
643 | status = acpi_hw_clear_gpe (gpe_event_info); | ||
644 | if (ACPI_FAILURE (status)) { | ||
645 | ACPI_REPORT_ERROR (( | ||
646 | "acpi_ev_gpe_dispatch: %s, Unable to clear GPE[%2X]\n", | ||
647 | acpi_format_exception (status), gpe_number)); | ||
648 | return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | ||
649 | } | ||
650 | } | ||
651 | break; | ||
652 | |||
653 | case ACPI_GPE_DISPATCH_METHOD: | ||
654 | |||
655 | /* | ||
656 | * Disable GPE, so it doesn't keep firing before the method has a | ||
657 | * chance to run. | ||
658 | */ | ||
659 | status = acpi_ev_disable_gpe (gpe_event_info); | ||
660 | if (ACPI_FAILURE (status)) { | ||
661 | ACPI_REPORT_ERROR (( | ||
662 | "acpi_ev_gpe_dispatch: %s, Unable to disable GPE[%2X]\n", | ||
663 | acpi_format_exception (status), gpe_number)); | ||
664 | return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | ||
665 | } | ||
666 | |||
667 | /* | ||
668 | * Execute the method associated with the GPE | ||
669 | * NOTE: Level-triggered GPEs are cleared after the method completes. | ||
670 | */ | ||
671 | status = acpi_os_queue_for_execution (OSD_PRIORITY_GPE, | ||
672 | acpi_ev_asynch_execute_gpe_method, gpe_event_info); | ||
673 | if (ACPI_FAILURE (status)) { | ||
674 | ACPI_REPORT_ERROR (( | ||
675 | "acpi_ev_gpe_dispatch: %s, Unable to queue handler for GPE[%2X] - event disabled\n", | ||
676 | acpi_format_exception (status), gpe_number)); | ||
677 | } | ||
678 | break; | ||
679 | |||
680 | default: | ||
681 | |||
682 | /* No handler or method to run! */ | ||
683 | |||
684 | ACPI_REPORT_ERROR (( | ||
685 | "acpi_ev_gpe_dispatch: No handler or method for GPE[%2X], disabling event\n", | ||
686 | gpe_number)); | ||
687 | |||
688 | /* | ||
689 | * Disable the GPE. The GPE will remain disabled until the ACPI | ||
690 | * Core Subsystem is restarted, or a handler is installed. | ||
691 | */ | ||
692 | status = acpi_ev_disable_gpe (gpe_event_info); | ||
693 | if (ACPI_FAILURE (status)) { | ||
694 | ACPI_REPORT_ERROR (( | ||
695 | "acpi_ev_gpe_dispatch: %s, Unable to disable GPE[%2X]\n", | ||
696 | acpi_format_exception (status), gpe_number)); | ||
697 | return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | ||
698 | } | ||
699 | break; | ||
700 | } | ||
701 | |||
702 | return_VALUE (ACPI_INTERRUPT_HANDLED); | ||
703 | } | ||
704 | |||
705 | |||
706 | #ifdef ACPI_GPE_NOTIFY_CHECK | ||
707 | |||
708 | /******************************************************************************* | ||
709 | * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED | ||
710 | * | ||
711 | * FUNCTION: acpi_ev_check_for_wake_only_gpe | ||
712 | * | ||
713 | * PARAMETERS: gpe_event_info - info for this GPE | ||
714 | * | ||
715 | * RETURN: Status | ||
716 | * | ||
717 | * DESCRIPTION: Determine if a a GPE is "wake-only". | ||
718 | * | ||
719 | * Called from Notify() code in interpreter when a "device_wake" | ||
720 | * Notify comes in. | ||
721 | * | ||
722 | ******************************************************************************/ | ||
723 | |||
724 | acpi_status | ||
725 | acpi_ev_check_for_wake_only_gpe ( | ||
726 | struct acpi_gpe_event_info *gpe_event_info) | ||
727 | { | ||
728 | acpi_status status; | ||
729 | |||
730 | |||
731 | ACPI_FUNCTION_TRACE ("ev_check_for_wake_only_gpe"); | ||
732 | |||
733 | |||
734 | if ((gpe_event_info) && /* Only >0 for _Lxx/_Exx */ | ||
735 | ((gpe_event_info->flags & ACPI_GPE_SYSTEM_MASK) == ACPI_GPE_SYSTEM_RUNNING)) /* System state at GPE time */ { | ||
736 | /* This must be a wake-only GPE, disable it */ | ||
737 | |||
738 | status = acpi_ev_disable_gpe (gpe_event_info); | ||
739 | |||
740 | /* Set GPE to wake-only. Do not change wake disabled/enabled status */ | ||
741 | |||
742 | acpi_ev_set_gpe_type (gpe_event_info, ACPI_GPE_TYPE_WAKE); | ||
743 | |||
744 | ACPI_REPORT_INFO (("GPE %p was updated from wake/run to wake-only\n", | ||
745 | gpe_event_info)); | ||
746 | |||
747 | /* This was a wake-only GPE */ | ||
748 | |||
749 | return_ACPI_STATUS (AE_WAKE_ONLY_GPE); | ||
750 | } | ||
751 | |||
752 | return_ACPI_STATUS (AE_OK); | ||
753 | } | ||
754 | #endif | ||
755 | |||
756 | |||
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c new file mode 100644 index 000000000000..00d981f53c6a --- /dev/null +++ b/drivers/acpi/events/evgpeblk.c | |||
@@ -0,0 +1,1141 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evgpeblk - GPE block creation and initialization. | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | #include <acpi/acpi.h> | ||
45 | #include <acpi/acevents.h> | ||
46 | #include <acpi/acnamesp.h> | ||
47 | |||
48 | #define _COMPONENT ACPI_EVENTS | ||
49 | ACPI_MODULE_NAME ("evgpeblk") | ||
50 | |||
51 | |||
52 | /******************************************************************************* | ||
53 | * | ||
54 | * FUNCTION: acpi_ev_valid_gpe_event | ||
55 | * | ||
56 | * PARAMETERS: gpe_event_info - Info for this GPE | ||
57 | * | ||
58 | * RETURN: TRUE if the gpe_event is valid | ||
59 | * | ||
60 | * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL. | ||
61 | * Should be called only when the GPE lists are semaphore locked | ||
62 | * and not subject to change. | ||
63 | * | ||
64 | ******************************************************************************/ | ||
65 | |||
66 | u8 | ||
67 | acpi_ev_valid_gpe_event ( | ||
68 | struct acpi_gpe_event_info *gpe_event_info) | ||
69 | { | ||
70 | struct acpi_gpe_xrupt_info *gpe_xrupt_block; | ||
71 | struct acpi_gpe_block_info *gpe_block; | ||
72 | |||
73 | |||
74 | ACPI_FUNCTION_ENTRY (); | ||
75 | |||
76 | |||
77 | /* No need for spin lock since we are not changing any list elements */ | ||
78 | |||
79 | /* Walk the GPE interrupt levels */ | ||
80 | |||
81 | gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head; | ||
82 | while (gpe_xrupt_block) { | ||
83 | gpe_block = gpe_xrupt_block->gpe_block_list_head; | ||
84 | |||
85 | /* Walk the GPE blocks on this interrupt level */ | ||
86 | |||
87 | while (gpe_block) { | ||
88 | if ((&gpe_block->event_info[0] <= gpe_event_info) && | ||
89 | (&gpe_block->event_info[((acpi_size) gpe_block->register_count) * 8] > gpe_event_info)) { | ||
90 | return (TRUE); | ||
91 | } | ||
92 | |||
93 | gpe_block = gpe_block->next; | ||
94 | } | ||
95 | |||
96 | gpe_xrupt_block = gpe_xrupt_block->next; | ||
97 | } | ||
98 | |||
99 | return (FALSE); | ||
100 | } | ||
101 | |||
102 | |||
103 | /******************************************************************************* | ||
104 | * | ||
105 | * FUNCTION: acpi_ev_walk_gpe_list | ||
106 | * | ||
107 | * PARAMETERS: gpe_walk_callback - Routine called for each GPE block | ||
108 | * Flags - ACPI_NOT_ISR or ACPI_ISR | ||
109 | * | ||
110 | * RETURN: Status | ||
111 | * | ||
112 | * DESCRIPTION: Walk the GPE lists. | ||
113 | * | ||
114 | ******************************************************************************/ | ||
115 | |||
116 | acpi_status | ||
117 | acpi_ev_walk_gpe_list ( | ||
118 | ACPI_GPE_CALLBACK gpe_walk_callback, | ||
119 | u32 flags) | ||
120 | { | ||
121 | struct acpi_gpe_block_info *gpe_block; | ||
122 | struct acpi_gpe_xrupt_info *gpe_xrupt_info; | ||
123 | acpi_status status = AE_OK; | ||
124 | |||
125 | |||
126 | ACPI_FUNCTION_TRACE ("ev_walk_gpe_list"); | ||
127 | |||
128 | |||
129 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, flags); | ||
130 | |||
131 | /* Walk the interrupt level descriptor list */ | ||
132 | |||
133 | gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; | ||
134 | while (gpe_xrupt_info) { | ||
135 | /* Walk all Gpe Blocks attached to this interrupt level */ | ||
136 | |||
137 | gpe_block = gpe_xrupt_info->gpe_block_list_head; | ||
138 | while (gpe_block) { | ||
139 | /* One callback per GPE block */ | ||
140 | |||
141 | status = gpe_walk_callback (gpe_xrupt_info, gpe_block); | ||
142 | if (ACPI_FAILURE (status)) { | ||
143 | goto unlock_and_exit; | ||
144 | } | ||
145 | |||
146 | gpe_block = gpe_block->next; | ||
147 | } | ||
148 | |||
149 | gpe_xrupt_info = gpe_xrupt_info->next; | ||
150 | } | ||
151 | |||
152 | unlock_and_exit: | ||
153 | acpi_os_release_lock (acpi_gbl_gpe_lock, flags); | ||
154 | return_ACPI_STATUS (status); | ||
155 | } | ||
156 | |||
157 | |||
158 | /****************************************************************************** | ||
159 | * | ||
160 | * FUNCTION: acpi_ev_delete_gpe_handlers | ||
161 | * | ||
162 | * PARAMETERS: gpe_xrupt_info - GPE Interrupt info | ||
163 | * gpe_block - Gpe Block info | ||
164 | * | ||
165 | * RETURN: Status | ||
166 | * | ||
167 | * DESCRIPTION: Delete all Handler objects found in the GPE data structs. | ||
168 | * Used only prior to termination. | ||
169 | * | ||
170 | ******************************************************************************/ | ||
171 | |||
172 | acpi_status | ||
173 | acpi_ev_delete_gpe_handlers ( | ||
174 | struct acpi_gpe_xrupt_info *gpe_xrupt_info, | ||
175 | struct acpi_gpe_block_info *gpe_block) | ||
176 | { | ||
177 | struct acpi_gpe_event_info *gpe_event_info; | ||
178 | acpi_native_uint i; | ||
179 | acpi_native_uint j; | ||
180 | |||
181 | |||
182 | ACPI_FUNCTION_TRACE ("ev_delete_gpe_handlers"); | ||
183 | |||
184 | |||
185 | /* Examine each GPE Register within the block */ | ||
186 | |||
187 | for (i = 0; i < gpe_block->register_count; i++) { | ||
188 | /* Now look at the individual GPEs in this byte register */ | ||
189 | |||
190 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { | ||
191 | gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; | ||
192 | |||
193 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) { | ||
194 | ACPI_MEM_FREE (gpe_event_info->dispatch.handler); | ||
195 | gpe_event_info->dispatch.handler = NULL; | ||
196 | gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | |||
201 | return_ACPI_STATUS (AE_OK); | ||
202 | } | ||
203 | |||
204 | |||
205 | /******************************************************************************* | ||
206 | * | ||
207 | * FUNCTION: acpi_ev_save_method_info | ||
208 | * | ||
209 | * PARAMETERS: Callback from walk_namespace | ||
210 | * | ||
211 | * RETURN: Status | ||
212 | * | ||
213 | * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a | ||
214 | * control method under the _GPE portion of the namespace. | ||
215 | * Extract the name and GPE type from the object, saving this | ||
216 | * information for quick lookup during GPE dispatch | ||
217 | * | ||
218 | * The name of each GPE control method is of the form: | ||
219 | * "_Lxx" or "_Exx" | ||
220 | * Where: | ||
221 | * L - means that the GPE is level triggered | ||
222 | * E - means that the GPE is edge triggered | ||
223 | * xx - is the GPE number [in HEX] | ||
224 | * | ||
225 | ******************************************************************************/ | ||
226 | |||
227 | static acpi_status | ||
228 | acpi_ev_save_method_info ( | ||
229 | acpi_handle obj_handle, | ||
230 | u32 level, | ||
231 | void *obj_desc, | ||
232 | void **return_value) | ||
233 | { | ||
234 | struct acpi_gpe_block_info *gpe_block = (void *) obj_desc; | ||
235 | struct acpi_gpe_event_info *gpe_event_info; | ||
236 | u32 gpe_number; | ||
237 | char name[ACPI_NAME_SIZE + 1]; | ||
238 | u8 type; | ||
239 | acpi_status status; | ||
240 | |||
241 | |||
242 | ACPI_FUNCTION_TRACE ("ev_save_method_info"); | ||
243 | |||
244 | |||
245 | /* | ||
246 | * _Lxx and _Exx GPE method support | ||
247 | * | ||
248 | * 1) Extract the name from the object and convert to a string | ||
249 | */ | ||
250 | ACPI_MOVE_32_TO_32 (name, | ||
251 | &((struct acpi_namespace_node *) obj_handle)->name.integer); | ||
252 | name[ACPI_NAME_SIZE] = 0; | ||
253 | |||
254 | /* | ||
255 | * 2) Edge/Level determination is based on the 2nd character | ||
256 | * of the method name | ||
257 | * | ||
258 | * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE | ||
259 | * if a _PRW object is found that points to this GPE. | ||
260 | */ | ||
261 | switch (name[1]) { | ||
262 | case 'L': | ||
263 | type = ACPI_GPE_LEVEL_TRIGGERED; | ||
264 | break; | ||
265 | |||
266 | case 'E': | ||
267 | type = ACPI_GPE_EDGE_TRIGGERED; | ||
268 | break; | ||
269 | |||
270 | default: | ||
271 | /* Unknown method type, just ignore it! */ | ||
272 | |||
273 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
274 | "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n", | ||
275 | name)); | ||
276 | return_ACPI_STATUS (AE_OK); | ||
277 | } | ||
278 | |||
279 | /* Convert the last two characters of the name to the GPE Number */ | ||
280 | |||
281 | gpe_number = ACPI_STRTOUL (&name[2], NULL, 16); | ||
282 | if (gpe_number == ACPI_UINT32_MAX) { | ||
283 | /* Conversion failed; invalid method, just ignore it */ | ||
284 | |||
285 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
286 | "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n", | ||
287 | name)); | ||
288 | return_ACPI_STATUS (AE_OK); | ||
289 | } | ||
290 | |||
291 | /* Ensure that we have a valid GPE number for this GPE block */ | ||
292 | |||
293 | if ((gpe_number < gpe_block->block_base_number) || | ||
294 | (gpe_number >= (gpe_block->block_base_number + (gpe_block->register_count * 8)))) { | ||
295 | /* | ||
296 | * Not valid for this GPE block, just ignore it | ||
297 | * However, it may be valid for a different GPE block, since GPE0 and GPE1 | ||
298 | * methods both appear under \_GPE. | ||
299 | */ | ||
300 | return_ACPI_STATUS (AE_OK); | ||
301 | } | ||
302 | |||
303 | /* | ||
304 | * Now we can add this information to the gpe_event_info block | ||
305 | * for use during dispatch of this GPE. Default type is RUNTIME, although | ||
306 | * this may change when the _PRW methods are executed later. | ||
307 | */ | ||
308 | gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number]; | ||
309 | |||
310 | gpe_event_info->flags = (u8) (type | ACPI_GPE_DISPATCH_METHOD | | ||
311 | ACPI_GPE_TYPE_RUNTIME); | ||
312 | |||
313 | gpe_event_info->dispatch.method_node = (struct acpi_namespace_node *) obj_handle; | ||
314 | |||
315 | /* Update enable mask, but don't enable the HW GPE as of yet */ | ||
316 | |||
317 | status = acpi_ev_enable_gpe (gpe_event_info, FALSE); | ||
318 | |||
319 | ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, | ||
320 | "Registered GPE method %s as GPE number 0x%.2X\n", | ||
321 | name, gpe_number)); | ||
322 | return_ACPI_STATUS (status); | ||
323 | } | ||
324 | |||
325 | |||
326 | /******************************************************************************* | ||
327 | * | ||
328 | * FUNCTION: acpi_ev_match_prw_and_gpe | ||
329 | * | ||
330 | * PARAMETERS: Callback from walk_namespace | ||
331 | * | ||
332 | * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is | ||
333 | * not aborted on a single _PRW failure. | ||
334 | * | ||
335 | * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a | ||
336 | * Device. Run the _PRW method. If present, extract the GPE | ||
337 | * number and mark the GPE as a WAKE GPE. | ||
338 | * | ||
339 | ******************************************************************************/ | ||
340 | |||
341 | static acpi_status | ||
342 | acpi_ev_match_prw_and_gpe ( | ||
343 | acpi_handle obj_handle, | ||
344 | u32 level, | ||
345 | void *info, | ||
346 | void **return_value) | ||
347 | { | ||
348 | struct acpi_gpe_walk_info *gpe_info = (void *) info; | ||
349 | struct acpi_namespace_node *gpe_device; | ||
350 | struct acpi_gpe_block_info *gpe_block; | ||
351 | struct acpi_namespace_node *target_gpe_device; | ||
352 | struct acpi_gpe_event_info *gpe_event_info; | ||
353 | union acpi_operand_object *pkg_desc; | ||
354 | union acpi_operand_object *obj_desc; | ||
355 | u32 gpe_number; | ||
356 | acpi_status status; | ||
357 | |||
358 | |||
359 | ACPI_FUNCTION_TRACE ("ev_match_prw_and_gpe"); | ||
360 | |||
361 | |||
362 | /* Check for a _PRW method under this device */ | ||
363 | |||
364 | status = acpi_ut_evaluate_object (obj_handle, METHOD_NAME__PRW, | ||
365 | ACPI_BTYPE_PACKAGE, &pkg_desc); | ||
366 | if (ACPI_FAILURE (status)) { | ||
367 | /* Ignore all errors from _PRW, we don't want to abort the subsystem */ | ||
368 | |||
369 | return_ACPI_STATUS (AE_OK); | ||
370 | } | ||
371 | |||
372 | /* The returned _PRW package must have at least two elements */ | ||
373 | |||
374 | if (pkg_desc->package.count < 2) { | ||
375 | goto cleanup; | ||
376 | } | ||
377 | |||
378 | /* Extract pointers from the input context */ | ||
379 | |||
380 | gpe_device = gpe_info->gpe_device; | ||
381 | gpe_block = gpe_info->gpe_block; | ||
382 | |||
383 | /* | ||
384 | * The _PRW object must return a package, we are only interested | ||
385 | * in the first element | ||
386 | */ | ||
387 | obj_desc = pkg_desc->package.elements[0]; | ||
388 | |||
389 | if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { | ||
390 | /* Use FADT-defined GPE device (from definition of _PRW) */ | ||
391 | |||
392 | target_gpe_device = acpi_gbl_fadt_gpe_device; | ||
393 | |||
394 | /* Integer is the GPE number in the FADT described GPE blocks */ | ||
395 | |||
396 | gpe_number = (u32) obj_desc->integer.value; | ||
397 | } | ||
398 | else if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) { | ||
399 | /* Package contains a GPE reference and GPE number within a GPE block */ | ||
400 | |||
401 | if ((obj_desc->package.count < 2) || | ||
402 | (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[0]) != ACPI_TYPE_LOCAL_REFERENCE) || | ||
403 | (ACPI_GET_OBJECT_TYPE (obj_desc->package.elements[1]) != ACPI_TYPE_INTEGER)) { | ||
404 | goto cleanup; | ||
405 | } | ||
406 | |||
407 | /* Get GPE block reference and decode */ | ||
408 | |||
409 | target_gpe_device = obj_desc->package.elements[0]->reference.node; | ||
410 | gpe_number = (u32) obj_desc->package.elements[1]->integer.value; | ||
411 | } | ||
412 | else { | ||
413 | /* Unknown type, just ignore it */ | ||
414 | |||
415 | goto cleanup; | ||
416 | } | ||
417 | |||
418 | /* | ||
419 | * Is this GPE within this block? | ||
420 | * | ||
421 | * TRUE iff these conditions are true: | ||
422 | * 1) The GPE devices match. | ||
423 | * 2) The GPE index(number) is within the range of the Gpe Block | ||
424 | * associated with the GPE device. | ||
425 | */ | ||
426 | if ((gpe_device == target_gpe_device) && | ||
427 | (gpe_number >= gpe_block->block_base_number) && | ||
428 | (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) { | ||
429 | gpe_event_info = &gpe_block->event_info[gpe_number - gpe_block->block_base_number]; | ||
430 | |||
431 | /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */ | ||
432 | |||
433 | gpe_event_info->flags &= ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED); | ||
434 | status = acpi_ev_set_gpe_type (gpe_event_info, ACPI_GPE_TYPE_WAKE); | ||
435 | if (ACPI_FAILURE (status)) { | ||
436 | goto cleanup; | ||
437 | } | ||
438 | status = acpi_ev_update_gpe_enable_masks (gpe_event_info, ACPI_GPE_DISABLE); | ||
439 | } | ||
440 | |||
441 | cleanup: | ||
442 | acpi_ut_remove_reference (pkg_desc); | ||
443 | return_ACPI_STATUS (AE_OK); | ||
444 | } | ||
445 | |||
446 | |||
447 | /******************************************************************************* | ||
448 | * | ||
449 | * FUNCTION: acpi_ev_get_gpe_xrupt_block | ||
450 | * | ||
451 | * PARAMETERS: interrupt_level - Interrupt for a GPE block | ||
452 | * | ||
453 | * RETURN: A GPE interrupt block | ||
454 | * | ||
455 | * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt | ||
456 | * block per unique interrupt level used for GPEs. | ||
457 | * Should be called only when the GPE lists are semaphore locked | ||
458 | * and not subject to change. | ||
459 | * | ||
460 | ******************************************************************************/ | ||
461 | |||
462 | static struct acpi_gpe_xrupt_info * | ||
463 | acpi_ev_get_gpe_xrupt_block ( | ||
464 | u32 interrupt_level) | ||
465 | { | ||
466 | struct acpi_gpe_xrupt_info *next_gpe_xrupt; | ||
467 | struct acpi_gpe_xrupt_info *gpe_xrupt; | ||
468 | acpi_status status; | ||
469 | |||
470 | |||
471 | ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block"); | ||
472 | |||
473 | |||
474 | /* No need for spin lock since we are not changing any list elements here */ | ||
475 | |||
476 | next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head; | ||
477 | while (next_gpe_xrupt) { | ||
478 | if (next_gpe_xrupt->interrupt_level == interrupt_level) { | ||
479 | return_PTR (next_gpe_xrupt); | ||
480 | } | ||
481 | |||
482 | next_gpe_xrupt = next_gpe_xrupt->next; | ||
483 | } | ||
484 | |||
485 | /* Not found, must allocate a new xrupt descriptor */ | ||
486 | |||
487 | gpe_xrupt = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_xrupt_info)); | ||
488 | if (!gpe_xrupt) { | ||
489 | return_PTR (NULL); | ||
490 | } | ||
491 | |||
492 | gpe_xrupt->interrupt_level = interrupt_level; | ||
493 | |||
494 | /* Install new interrupt descriptor with spin lock */ | ||
495 | |||
496 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
497 | if (acpi_gbl_gpe_xrupt_list_head) { | ||
498 | next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head; | ||
499 | while (next_gpe_xrupt->next) { | ||
500 | next_gpe_xrupt = next_gpe_xrupt->next; | ||
501 | } | ||
502 | |||
503 | next_gpe_xrupt->next = gpe_xrupt; | ||
504 | gpe_xrupt->previous = next_gpe_xrupt; | ||
505 | } | ||
506 | else { | ||
507 | acpi_gbl_gpe_xrupt_list_head = gpe_xrupt; | ||
508 | } | ||
509 | acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
510 | |||
511 | /* Install new interrupt handler if not SCI_INT */ | ||
512 | |||
513 | if (interrupt_level != acpi_gbl_FADT->sci_int) { | ||
514 | status = acpi_os_install_interrupt_handler (interrupt_level, | ||
515 | acpi_ev_gpe_xrupt_handler, gpe_xrupt); | ||
516 | if (ACPI_FAILURE (status)) { | ||
517 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
518 | "Could not install GPE interrupt handler at level 0x%X\n", | ||
519 | interrupt_level)); | ||
520 | return_PTR (NULL); | ||
521 | } | ||
522 | } | ||
523 | |||
524 | return_PTR (gpe_xrupt); | ||
525 | } | ||
526 | |||
527 | |||
528 | /******************************************************************************* | ||
529 | * | ||
530 | * FUNCTION: acpi_ev_delete_gpe_xrupt | ||
531 | * | ||
532 | * PARAMETERS: gpe_xrupt - A GPE interrupt info block | ||
533 | * | ||
534 | * RETURN: Status | ||
535 | * | ||
536 | * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated | ||
537 | * interrupt handler if not the SCI interrupt. | ||
538 | * | ||
539 | ******************************************************************************/ | ||
540 | |||
541 | static acpi_status | ||
542 | acpi_ev_delete_gpe_xrupt ( | ||
543 | struct acpi_gpe_xrupt_info *gpe_xrupt) | ||
544 | { | ||
545 | acpi_status status; | ||
546 | |||
547 | |||
548 | ACPI_FUNCTION_TRACE ("ev_delete_gpe_xrupt"); | ||
549 | |||
550 | |||
551 | /* We never want to remove the SCI interrupt handler */ | ||
552 | |||
553 | if (gpe_xrupt->interrupt_level == acpi_gbl_FADT->sci_int) { | ||
554 | gpe_xrupt->gpe_block_list_head = NULL; | ||
555 | return_ACPI_STATUS (AE_OK); | ||
556 | } | ||
557 | |||
558 | /* Disable this interrupt */ | ||
559 | |||
560 | status = acpi_os_remove_interrupt_handler (gpe_xrupt->interrupt_level, | ||
561 | acpi_ev_gpe_xrupt_handler); | ||
562 | if (ACPI_FAILURE (status)) { | ||
563 | return_ACPI_STATUS (status); | ||
564 | } | ||
565 | |||
566 | /* Unlink the interrupt block with lock */ | ||
567 | |||
568 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
569 | if (gpe_xrupt->previous) { | ||
570 | gpe_xrupt->previous->next = gpe_xrupt->next; | ||
571 | } | ||
572 | |||
573 | if (gpe_xrupt->next) { | ||
574 | gpe_xrupt->next->previous = gpe_xrupt->previous; | ||
575 | } | ||
576 | acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
577 | |||
578 | /* Free the block */ | ||
579 | |||
580 | ACPI_MEM_FREE (gpe_xrupt); | ||
581 | return_ACPI_STATUS (AE_OK); | ||
582 | } | ||
583 | |||
584 | |||
585 | /******************************************************************************* | ||
586 | * | ||
587 | * FUNCTION: acpi_ev_install_gpe_block | ||
588 | * | ||
589 | * PARAMETERS: gpe_block - New GPE block | ||
590 | * interrupt_level - Level to be associated with this GPE block | ||
591 | * | ||
592 | * RETURN: Status | ||
593 | * | ||
594 | * DESCRIPTION: Install new GPE block with mutex support | ||
595 | * | ||
596 | ******************************************************************************/ | ||
597 | |||
598 | static acpi_status | ||
599 | acpi_ev_install_gpe_block ( | ||
600 | struct acpi_gpe_block_info *gpe_block, | ||
601 | u32 interrupt_level) | ||
602 | { | ||
603 | struct acpi_gpe_block_info *next_gpe_block; | ||
604 | struct acpi_gpe_xrupt_info *gpe_xrupt_block; | ||
605 | acpi_status status; | ||
606 | |||
607 | |||
608 | ACPI_FUNCTION_TRACE ("ev_install_gpe_block"); | ||
609 | |||
610 | |||
611 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
612 | if (ACPI_FAILURE (status)) { | ||
613 | return_ACPI_STATUS (status); | ||
614 | } | ||
615 | |||
616 | gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block (interrupt_level); | ||
617 | if (!gpe_xrupt_block) { | ||
618 | status = AE_NO_MEMORY; | ||
619 | goto unlock_and_exit; | ||
620 | } | ||
621 | |||
622 | /* Install the new block at the end of the list for this interrupt with lock */ | ||
623 | |||
624 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
625 | if (gpe_xrupt_block->gpe_block_list_head) { | ||
626 | next_gpe_block = gpe_xrupt_block->gpe_block_list_head; | ||
627 | while (next_gpe_block->next) { | ||
628 | next_gpe_block = next_gpe_block->next; | ||
629 | } | ||
630 | |||
631 | next_gpe_block->next = gpe_block; | ||
632 | gpe_block->previous = next_gpe_block; | ||
633 | } | ||
634 | else { | ||
635 | gpe_xrupt_block->gpe_block_list_head = gpe_block; | ||
636 | } | ||
637 | |||
638 | gpe_block->xrupt_block = gpe_xrupt_block; | ||
639 | acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
640 | |||
641 | unlock_and_exit: | ||
642 | status = acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
643 | return_ACPI_STATUS (status); | ||
644 | } | ||
645 | |||
646 | |||
647 | /******************************************************************************* | ||
648 | * | ||
649 | * FUNCTION: acpi_ev_delete_gpe_block | ||
650 | * | ||
651 | * PARAMETERS: gpe_block - Existing GPE block | ||
652 | * | ||
653 | * RETURN: Status | ||
654 | * | ||
655 | * DESCRIPTION: Remove a GPE block | ||
656 | * | ||
657 | ******************************************************************************/ | ||
658 | |||
659 | acpi_status | ||
660 | acpi_ev_delete_gpe_block ( | ||
661 | struct acpi_gpe_block_info *gpe_block) | ||
662 | { | ||
663 | acpi_status status; | ||
664 | |||
665 | |||
666 | ACPI_FUNCTION_TRACE ("ev_install_gpe_block"); | ||
667 | |||
668 | |||
669 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
670 | if (ACPI_FAILURE (status)) { | ||
671 | return_ACPI_STATUS (status); | ||
672 | } | ||
673 | |||
674 | /* Disable all GPEs in this block */ | ||
675 | |||
676 | status = acpi_hw_disable_gpe_block (gpe_block->xrupt_block, gpe_block); | ||
677 | |||
678 | if (!gpe_block->previous && !gpe_block->next) { | ||
679 | /* This is the last gpe_block on this interrupt */ | ||
680 | |||
681 | status = acpi_ev_delete_gpe_xrupt (gpe_block->xrupt_block); | ||
682 | if (ACPI_FAILURE (status)) { | ||
683 | goto unlock_and_exit; | ||
684 | } | ||
685 | } | ||
686 | else { | ||
687 | /* Remove the block on this interrupt with lock */ | ||
688 | |||
689 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
690 | if (gpe_block->previous) { | ||
691 | gpe_block->previous->next = gpe_block->next; | ||
692 | } | ||
693 | else { | ||
694 | gpe_block->xrupt_block->gpe_block_list_head = gpe_block->next; | ||
695 | } | ||
696 | |||
697 | if (gpe_block->next) { | ||
698 | gpe_block->next->previous = gpe_block->previous; | ||
699 | } | ||
700 | acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
701 | } | ||
702 | |||
703 | /* Free the gpe_block */ | ||
704 | |||
705 | ACPI_MEM_FREE (gpe_block->register_info); | ||
706 | ACPI_MEM_FREE (gpe_block->event_info); | ||
707 | ACPI_MEM_FREE (gpe_block); | ||
708 | |||
709 | unlock_and_exit: | ||
710 | status = acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
711 | return_ACPI_STATUS (status); | ||
712 | } | ||
713 | |||
714 | |||
715 | /******************************************************************************* | ||
716 | * | ||
717 | * FUNCTION: acpi_ev_create_gpe_info_blocks | ||
718 | * | ||
719 | * PARAMETERS: gpe_block - New GPE block | ||
720 | * | ||
721 | * RETURN: Status | ||
722 | * | ||
723 | * DESCRIPTION: Create the register_info and event_info blocks for this GPE block | ||
724 | * | ||
725 | ******************************************************************************/ | ||
726 | |||
727 | static acpi_status | ||
728 | acpi_ev_create_gpe_info_blocks ( | ||
729 | struct acpi_gpe_block_info *gpe_block) | ||
730 | { | ||
731 | struct acpi_gpe_register_info *gpe_register_info = NULL; | ||
732 | struct acpi_gpe_event_info *gpe_event_info = NULL; | ||
733 | struct acpi_gpe_event_info *this_event; | ||
734 | struct acpi_gpe_register_info *this_register; | ||
735 | acpi_native_uint i; | ||
736 | acpi_native_uint j; | ||
737 | acpi_status status; | ||
738 | |||
739 | |||
740 | ACPI_FUNCTION_TRACE ("ev_create_gpe_info_blocks"); | ||
741 | |||
742 | |||
743 | /* Allocate the GPE register information block */ | ||
744 | |||
745 | gpe_register_info = ACPI_MEM_CALLOCATE ( | ||
746 | (acpi_size) gpe_block->register_count * | ||
747 | sizeof (struct acpi_gpe_register_info)); | ||
748 | if (!gpe_register_info) { | ||
749 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
750 | "Could not allocate the gpe_register_info table\n")); | ||
751 | return_ACPI_STATUS (AE_NO_MEMORY); | ||
752 | } | ||
753 | |||
754 | /* | ||
755 | * Allocate the GPE event_info block. There are eight distinct GPEs | ||
756 | * per register. Initialization to zeros is sufficient. | ||
757 | */ | ||
758 | gpe_event_info = ACPI_MEM_CALLOCATE ( | ||
759 | ((acpi_size) gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) * | ||
760 | sizeof (struct acpi_gpe_event_info)); | ||
761 | if (!gpe_event_info) { | ||
762 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the gpe_event_info table\n")); | ||
763 | status = AE_NO_MEMORY; | ||
764 | goto error_exit; | ||
765 | } | ||
766 | |||
767 | /* Save the new Info arrays in the GPE block */ | ||
768 | |||
769 | gpe_block->register_info = gpe_register_info; | ||
770 | gpe_block->event_info = gpe_event_info; | ||
771 | |||
772 | /* | ||
773 | * Initialize the GPE Register and Event structures. A goal of these | ||
774 | * tables is to hide the fact that there are two separate GPE register sets | ||
775 | * in a given gpe hardware block, the status registers occupy the first half, | ||
776 | * and the enable registers occupy the second half. | ||
777 | */ | ||
778 | this_register = gpe_register_info; | ||
779 | this_event = gpe_event_info; | ||
780 | |||
781 | for (i = 0; i < gpe_block->register_count; i++) { | ||
782 | /* Init the register_info for this GPE register (8 GPEs) */ | ||
783 | |||
784 | this_register->base_gpe_number = (u8) (gpe_block->block_base_number + | ||
785 | (i * ACPI_GPE_REGISTER_WIDTH)); | ||
786 | |||
787 | ACPI_STORE_ADDRESS (this_register->status_address.address, | ||
788 | (gpe_block->block_address.address | ||
789 | + i)); | ||
790 | |||
791 | ACPI_STORE_ADDRESS (this_register->enable_address.address, | ||
792 | (gpe_block->block_address.address | ||
793 | + i | ||
794 | + gpe_block->register_count)); | ||
795 | |||
796 | this_register->status_address.address_space_id = gpe_block->block_address.address_space_id; | ||
797 | this_register->enable_address.address_space_id = gpe_block->block_address.address_space_id; | ||
798 | this_register->status_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH; | ||
799 | this_register->enable_address.register_bit_width = ACPI_GPE_REGISTER_WIDTH; | ||
800 | this_register->status_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH; | ||
801 | this_register->enable_address.register_bit_offset = ACPI_GPE_REGISTER_WIDTH; | ||
802 | |||
803 | /* Init the event_info for each GPE within this register */ | ||
804 | |||
805 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { | ||
806 | this_event->register_bit = acpi_gbl_decode_to8bit[j]; | ||
807 | this_event->register_info = this_register; | ||
808 | this_event++; | ||
809 | } | ||
810 | |||
811 | /* | ||
812 | * Clear the status/enable registers. Note that status registers | ||
813 | * are cleared by writing a '1', while enable registers are cleared | ||
814 | * by writing a '0'. | ||
815 | */ | ||
816 | status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0x00, | ||
817 | &this_register->enable_address); | ||
818 | if (ACPI_FAILURE (status)) { | ||
819 | goto error_exit; | ||
820 | } | ||
821 | |||
822 | status = acpi_hw_low_level_write (ACPI_GPE_REGISTER_WIDTH, 0xFF, | ||
823 | &this_register->status_address); | ||
824 | if (ACPI_FAILURE (status)) { | ||
825 | goto error_exit; | ||
826 | } | ||
827 | |||
828 | this_register++; | ||
829 | } | ||
830 | |||
831 | return_ACPI_STATUS (AE_OK); | ||
832 | |||
833 | |||
834 | error_exit: | ||
835 | if (gpe_register_info) { | ||
836 | ACPI_MEM_FREE (gpe_register_info); | ||
837 | } | ||
838 | if (gpe_event_info) { | ||
839 | ACPI_MEM_FREE (gpe_event_info); | ||
840 | } | ||
841 | |||
842 | return_ACPI_STATUS (status); | ||
843 | } | ||
844 | |||
845 | |||
846 | /******************************************************************************* | ||
847 | * | ||
848 | * FUNCTION: acpi_ev_create_gpe_block | ||
849 | * | ||
850 | * PARAMETERS: gpe_device - Handle to the parent GPE block | ||
851 | * gpe_block_address - Address and space_iD | ||
852 | * register_count - Number of GPE register pairs in the block | ||
853 | * gpe_block_base_number - Starting GPE number for the block | ||
854 | * interrupt_level - H/W interrupt for the block | ||
855 | * return_gpe_block - Where the new block descriptor is returned | ||
856 | * | ||
857 | * RETURN: Status | ||
858 | * | ||
859 | * DESCRIPTION: Create and Install a block of GPE registers | ||
860 | * | ||
861 | ******************************************************************************/ | ||
862 | |||
863 | acpi_status | ||
864 | acpi_ev_create_gpe_block ( | ||
865 | struct acpi_namespace_node *gpe_device, | ||
866 | struct acpi_generic_address *gpe_block_address, | ||
867 | u32 register_count, | ||
868 | u8 gpe_block_base_number, | ||
869 | u32 interrupt_level, | ||
870 | struct acpi_gpe_block_info **return_gpe_block) | ||
871 | { | ||
872 | struct acpi_gpe_block_info *gpe_block; | ||
873 | struct acpi_gpe_event_info *gpe_event_info; | ||
874 | acpi_native_uint i; | ||
875 | acpi_native_uint j; | ||
876 | u32 wake_gpe_count; | ||
877 | u32 gpe_enabled_count; | ||
878 | acpi_status status; | ||
879 | struct acpi_gpe_walk_info gpe_info; | ||
880 | |||
881 | |||
882 | ACPI_FUNCTION_TRACE ("ev_create_gpe_block"); | ||
883 | |||
884 | |||
885 | if (!register_count) { | ||
886 | return_ACPI_STATUS (AE_OK); | ||
887 | } | ||
888 | |||
889 | /* Allocate a new GPE block */ | ||
890 | |||
891 | gpe_block = ACPI_MEM_CALLOCATE (sizeof (struct acpi_gpe_block_info)); | ||
892 | if (!gpe_block) { | ||
893 | return_ACPI_STATUS (AE_NO_MEMORY); | ||
894 | } | ||
895 | |||
896 | /* Initialize the new GPE block */ | ||
897 | |||
898 | gpe_block->register_count = register_count; | ||
899 | gpe_block->block_base_number = gpe_block_base_number; | ||
900 | gpe_block->node = gpe_device; | ||
901 | |||
902 | ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address, sizeof (struct acpi_generic_address)); | ||
903 | |||
904 | /* Create the register_info and event_info sub-structures */ | ||
905 | |||
906 | status = acpi_ev_create_gpe_info_blocks (gpe_block); | ||
907 | if (ACPI_FAILURE (status)) { | ||
908 | ACPI_MEM_FREE (gpe_block); | ||
909 | return_ACPI_STATUS (status); | ||
910 | } | ||
911 | |||
912 | /* Install the new block in the global list(s) */ | ||
913 | |||
914 | status = acpi_ev_install_gpe_block (gpe_block, interrupt_level); | ||
915 | if (ACPI_FAILURE (status)) { | ||
916 | ACPI_MEM_FREE (gpe_block); | ||
917 | return_ACPI_STATUS (status); | ||
918 | } | ||
919 | |||
920 | /* Find all GPE methods (_Lxx, _Exx) for this block */ | ||
921 | |||
922 | status = acpi_ns_walk_namespace (ACPI_TYPE_METHOD, gpe_device, | ||
923 | ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, acpi_ev_save_method_info, | ||
924 | gpe_block, NULL); | ||
925 | |||
926 | /* | ||
927 | * Runtime option: Should Wake GPEs be enabled at runtime? The default | ||
928 | * is No, they should only be enabled just as the machine goes to sleep. | ||
929 | */ | ||
930 | if (acpi_gbl_leave_wake_gpes_disabled) { | ||
931 | /* | ||
932 | * Differentiate RUNTIME vs WAKE GPEs, via the _PRW control methods. | ||
933 | * (Each GPE that has one or more _PRWs that reference it is by | ||
934 | * definition a WAKE GPE and will not be enabled while the machine | ||
935 | * is running.) | ||
936 | */ | ||
937 | gpe_info.gpe_block = gpe_block; | ||
938 | gpe_info.gpe_device = gpe_device; | ||
939 | |||
940 | status = acpi_ns_walk_namespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | ||
941 | ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, acpi_ev_match_prw_and_gpe, | ||
942 | &gpe_info, NULL); | ||
943 | } | ||
944 | |||
945 | /* | ||
946 | * Enable all GPEs in this block that are 1) "runtime" or "run/wake" GPEs, | ||
947 | * and 2) have a corresponding _Lxx or _Exx method. All other GPEs must | ||
948 | * be enabled via the acpi_enable_gpe() external interface. | ||
949 | */ | ||
950 | wake_gpe_count = 0; | ||
951 | gpe_enabled_count = 0; | ||
952 | |||
953 | for (i = 0; i < gpe_block->register_count; i++) { | ||
954 | for (j = 0; j < 8; j++) { | ||
955 | /* Get the info block for this particular GPE */ | ||
956 | |||
957 | gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; | ||
958 | |||
959 | if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD) && | ||
960 | (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) { | ||
961 | gpe_enabled_count++; | ||
962 | } | ||
963 | |||
964 | if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) { | ||
965 | wake_gpe_count++; | ||
966 | } | ||
967 | } | ||
968 | } | ||
969 | |||
970 | /* Dump info about this GPE block */ | ||
971 | |||
972 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, | ||
973 | "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n", | ||
974 | (u32) gpe_block->block_base_number, | ||
975 | (u32) (gpe_block->block_base_number + | ||
976 | ((gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) -1)), | ||
977 | gpe_device->name.ascii, | ||
978 | gpe_block->register_count, | ||
979 | interrupt_level)); | ||
980 | |||
981 | /* Enable all valid GPEs found above */ | ||
982 | |||
983 | status = acpi_hw_enable_runtime_gpe_block (NULL, gpe_block); | ||
984 | |||
985 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, | ||
986 | "Found %u Wake, Enabled %u Runtime GPEs in this block\n", | ||
987 | wake_gpe_count, gpe_enabled_count)); | ||
988 | |||
989 | /* Return the new block */ | ||
990 | |||
991 | if (return_gpe_block) { | ||
992 | (*return_gpe_block) = gpe_block; | ||
993 | } | ||
994 | |||
995 | return_ACPI_STATUS (AE_OK); | ||
996 | } | ||
997 | |||
998 | |||
999 | /******************************************************************************* | ||
1000 | * | ||
1001 | * FUNCTION: acpi_ev_gpe_initialize | ||
1002 | * | ||
1003 | * PARAMETERS: None | ||
1004 | * | ||
1005 | * RETURN: Status | ||
1006 | * | ||
1007 | * DESCRIPTION: Initialize the GPE data structures | ||
1008 | * | ||
1009 | ******************************************************************************/ | ||
1010 | |||
1011 | acpi_status | ||
1012 | acpi_ev_gpe_initialize ( | ||
1013 | void) | ||
1014 | { | ||
1015 | u32 register_count0 = 0; | ||
1016 | u32 register_count1 = 0; | ||
1017 | u32 gpe_number_max = 0; | ||
1018 | acpi_status status; | ||
1019 | |||
1020 | |||
1021 | ACPI_FUNCTION_TRACE ("ev_gpe_initialize"); | ||
1022 | |||
1023 | |||
1024 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
1025 | if (ACPI_FAILURE (status)) { | ||
1026 | return_ACPI_STATUS (status); | ||
1027 | } | ||
1028 | |||
1029 | /* | ||
1030 | * Initialize the GPE Block(s) defined in the FADT | ||
1031 | * | ||
1032 | * Why the GPE register block lengths are divided by 2: From the ACPI Spec, | ||
1033 | * section "General-Purpose Event Registers", we have: | ||
1034 | * | ||
1035 | * "Each register block contains two registers of equal length | ||
1036 | * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the | ||
1037 | * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN | ||
1038 | * The length of the GPE1_STS and GPE1_EN registers is equal to | ||
1039 | * half the GPE1_LEN. If a generic register block is not supported | ||
1040 | * then its respective block pointer and block length values in the | ||
1041 | * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need | ||
1042 | * to be the same size." | ||
1043 | */ | ||
1044 | |||
1045 | /* | ||
1046 | * Determine the maximum GPE number for this machine. | ||
1047 | * | ||
1048 | * Note: both GPE0 and GPE1 are optional, and either can exist without | ||
1049 | * the other. | ||
1050 | * | ||
1051 | * If EITHER the register length OR the block address are zero, then that | ||
1052 | * particular block is not supported. | ||
1053 | */ | ||
1054 | if (acpi_gbl_FADT->gpe0_blk_len && | ||
1055 | acpi_gbl_FADT->xgpe0_blk.address) { | ||
1056 | /* GPE block 0 exists (has both length and address > 0) */ | ||
1057 | |||
1058 | register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2); | ||
1059 | |||
1060 | gpe_number_max = (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1; | ||
1061 | |||
1062 | /* Install GPE Block 0 */ | ||
1063 | |||
1064 | status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe0_blk, | ||
1065 | register_count0, 0, acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]); | ||
1066 | |||
1067 | if (ACPI_FAILURE (status)) { | ||
1068 | ACPI_REPORT_ERROR (( | ||
1069 | "Could not create GPE Block 0, %s\n", | ||
1070 | acpi_format_exception (status))); | ||
1071 | } | ||
1072 | } | ||
1073 | |||
1074 | if (acpi_gbl_FADT->gpe1_blk_len && | ||
1075 | acpi_gbl_FADT->xgpe1_blk.address) { | ||
1076 | /* GPE block 1 exists (has both length and address > 0) */ | ||
1077 | |||
1078 | register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2); | ||
1079 | |||
1080 | /* Check for GPE0/GPE1 overlap (if both banks exist) */ | ||
1081 | |||
1082 | if ((register_count0) && | ||
1083 | (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) { | ||
1084 | ACPI_REPORT_ERROR (( | ||
1085 | "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n", | ||
1086 | gpe_number_max, acpi_gbl_FADT->gpe1_base, | ||
1087 | acpi_gbl_FADT->gpe1_base + | ||
1088 | ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1))); | ||
1089 | |||
1090 | /* Ignore GPE1 block by setting the register count to zero */ | ||
1091 | |||
1092 | register_count1 = 0; | ||
1093 | } | ||
1094 | else { | ||
1095 | /* Install GPE Block 1 */ | ||
1096 | |||
1097 | status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe1_blk, | ||
1098 | register_count1, acpi_gbl_FADT->gpe1_base, | ||
1099 | acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]); | ||
1100 | |||
1101 | if (ACPI_FAILURE (status)) { | ||
1102 | ACPI_REPORT_ERROR (( | ||
1103 | "Could not create GPE Block 1, %s\n", | ||
1104 | acpi_format_exception (status))); | ||
1105 | } | ||
1106 | |||
1107 | /* | ||
1108 | * GPE0 and GPE1 do not have to be contiguous in the GPE number | ||
1109 | * space. However, GPE0 always starts at GPE number zero. | ||
1110 | */ | ||
1111 | gpe_number_max = acpi_gbl_FADT->gpe1_base + | ||
1112 | ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1); | ||
1113 | } | ||
1114 | } | ||
1115 | |||
1116 | /* Exit if there are no GPE registers */ | ||
1117 | |||
1118 | if ((register_count0 + register_count1) == 0) { | ||
1119 | /* GPEs are not required by ACPI, this is OK */ | ||
1120 | |||
1121 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, | ||
1122 | "There are no GPE blocks defined in the FADT\n")); | ||
1123 | status = AE_OK; | ||
1124 | goto cleanup; | ||
1125 | } | ||
1126 | |||
1127 | /* Check for Max GPE number out-of-range */ | ||
1128 | |||
1129 | if (gpe_number_max > ACPI_GPE_MAX) { | ||
1130 | ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n", | ||
1131 | gpe_number_max)); | ||
1132 | status = AE_BAD_VALUE; | ||
1133 | goto cleanup; | ||
1134 | } | ||
1135 | |||
1136 | cleanup: | ||
1137 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
1138 | return_ACPI_STATUS (AE_OK); | ||
1139 | } | ||
1140 | |||
1141 | |||
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c new file mode 100644 index 000000000000..2548efa7a45f --- /dev/null +++ b/drivers/acpi/events/evmisc.c | |||
@@ -0,0 +1,588 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evmisc - Miscellaneous event manager support functions | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | #include <acpi/acpi.h> | ||
45 | #include <acpi/acevents.h> | ||
46 | #include <acpi/acnamesp.h> | ||
47 | #include <acpi/acinterp.h> | ||
48 | |||
49 | #define _COMPONENT ACPI_EVENTS | ||
50 | ACPI_MODULE_NAME ("evmisc") | ||
51 | |||
52 | |||
53 | /******************************************************************************* | ||
54 | * | ||
55 | * FUNCTION: acpi_ev_is_notify_object | ||
56 | * | ||
57 | * PARAMETERS: Node - Node to check | ||
58 | * | ||
59 | * RETURN: TRUE if notifies allowed on this object | ||
60 | * | ||
61 | * DESCRIPTION: Check type of node for a object that supports notifies. | ||
62 | * | ||
63 | * TBD: This could be replaced by a flag bit in the node. | ||
64 | * | ||
65 | ******************************************************************************/ | ||
66 | |||
67 | u8 | ||
68 | acpi_ev_is_notify_object ( | ||
69 | struct acpi_namespace_node *node) | ||
70 | { | ||
71 | switch (node->type) { | ||
72 | case ACPI_TYPE_DEVICE: | ||
73 | case ACPI_TYPE_PROCESSOR: | ||
74 | case ACPI_TYPE_POWER: | ||
75 | case ACPI_TYPE_THERMAL: | ||
76 | /* | ||
77 | * These are the ONLY objects that can receive ACPI notifications | ||
78 | */ | ||
79 | return (TRUE); | ||
80 | |||
81 | default: | ||
82 | return (FALSE); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | |||
87 | /******************************************************************************* | ||
88 | * | ||
89 | * FUNCTION: acpi_ev_queue_notify_request | ||
90 | * | ||
91 | * PARAMETERS: Node - NS node for the notified object | ||
92 | * notify_value - Value from the Notify() request | ||
93 | * | ||
94 | * RETURN: Status | ||
95 | * | ||
96 | * DESCRIPTION: Dispatch a device notification event to a previously | ||
97 | * installed handler. | ||
98 | * | ||
99 | ******************************************************************************/ | ||
100 | |||
101 | #ifdef ACPI_DEBUG_OUTPUT | ||
102 | static const char *acpi_notify_value_names[] = | ||
103 | { | ||
104 | "Bus Check", | ||
105 | "Device Check", | ||
106 | "Device Wake", | ||
107 | "Eject request", | ||
108 | "Device Check Light", | ||
109 | "Frequency Mismatch", | ||
110 | "Bus Mode Mismatch", | ||
111 | "Power Fault" | ||
112 | }; | ||
113 | #endif | ||
114 | |||
115 | acpi_status | ||
116 | acpi_ev_queue_notify_request ( | ||
117 | struct acpi_namespace_node *node, | ||
118 | u32 notify_value) | ||
119 | { | ||
120 | union acpi_operand_object *obj_desc; | ||
121 | union acpi_operand_object *handler_obj = NULL; | ||
122 | union acpi_generic_state *notify_info; | ||
123 | acpi_status status = AE_OK; | ||
124 | |||
125 | |||
126 | ACPI_FUNCTION_NAME ("ev_queue_notify_request"); | ||
127 | |||
128 | |||
129 | /* | ||
130 | * For value 3 (Ejection Request), some device method may need to be run. | ||
131 | * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need to be run. | ||
132 | * For value 0x80 (Status Change) on the power button or sleep button, | ||
133 | * initiate soft-off or sleep operation? | ||
134 | */ | ||
135 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | ||
136 | "Dispatching Notify(%X) on node %p\n", notify_value, node)); | ||
137 | |||
138 | if (notify_value <= 7) { | ||
139 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: %s\n", | ||
140 | acpi_notify_value_names[notify_value])); | ||
141 | } | ||
142 | else { | ||
143 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: 0x%2.2X **Device Specific**\n", | ||
144 | notify_value)); | ||
145 | } | ||
146 | |||
147 | /* Get the notify object attached to the NS Node */ | ||
148 | |||
149 | obj_desc = acpi_ns_get_attached_object (node); | ||
150 | if (obj_desc) { | ||
151 | /* We have the notify object, Get the right handler */ | ||
152 | |||
153 | switch (node->type) { | ||
154 | case ACPI_TYPE_DEVICE: | ||
155 | case ACPI_TYPE_THERMAL: | ||
156 | case ACPI_TYPE_PROCESSOR: | ||
157 | case ACPI_TYPE_POWER: | ||
158 | |||
159 | if (notify_value <= ACPI_MAX_SYS_NOTIFY) { | ||
160 | handler_obj = obj_desc->common_notify.system_notify; | ||
161 | } | ||
162 | else { | ||
163 | handler_obj = obj_desc->common_notify.device_notify; | ||
164 | } | ||
165 | break; | ||
166 | |||
167 | default: | ||
168 | /* All other types are not supported */ | ||
169 | return (AE_TYPE); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | /* If there is any handler to run, schedule the dispatcher */ | ||
174 | |||
175 | if ((acpi_gbl_system_notify.handler && (notify_value <= ACPI_MAX_SYS_NOTIFY)) || | ||
176 | (acpi_gbl_device_notify.handler && (notify_value > ACPI_MAX_SYS_NOTIFY)) || | ||
177 | handler_obj) { | ||
178 | notify_info = acpi_ut_create_generic_state (); | ||
179 | if (!notify_info) { | ||
180 | return (AE_NO_MEMORY); | ||
181 | } | ||
182 | |||
183 | notify_info->common.data_type = ACPI_DESC_TYPE_STATE_NOTIFY; | ||
184 | notify_info->notify.node = node; | ||
185 | notify_info->notify.value = (u16) notify_value; | ||
186 | notify_info->notify.handler_obj = handler_obj; | ||
187 | |||
188 | status = acpi_os_queue_for_execution (OSD_PRIORITY_HIGH, | ||
189 | acpi_ev_notify_dispatch, notify_info); | ||
190 | if (ACPI_FAILURE (status)) { | ||
191 | acpi_ut_delete_generic_state (notify_info); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | if (!handler_obj) { | ||
196 | /* | ||
197 | * There is no per-device notify handler for this device. | ||
198 | * This may or may not be a problem. | ||
199 | */ | ||
200 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | ||
201 | "No notify handler for Notify(%4.4s, %X) node %p\n", | ||
202 | acpi_ut_get_node_name (node), notify_value, node)); | ||
203 | } | ||
204 | |||
205 | return (status); | ||
206 | } | ||
207 | |||
208 | |||
209 | /******************************************************************************* | ||
210 | * | ||
211 | * FUNCTION: acpi_ev_notify_dispatch | ||
212 | * | ||
213 | * PARAMETERS: Context - To be passsed to the notify handler | ||
214 | * | ||
215 | * RETURN: None. | ||
216 | * | ||
217 | * DESCRIPTION: Dispatch a device notification event to a previously | ||
218 | * installed handler. | ||
219 | * | ||
220 | ******************************************************************************/ | ||
221 | |||
222 | void ACPI_SYSTEM_XFACE | ||
223 | acpi_ev_notify_dispatch ( | ||
224 | void *context) | ||
225 | { | ||
226 | union acpi_generic_state *notify_info = (union acpi_generic_state *) context; | ||
227 | acpi_notify_handler global_handler = NULL; | ||
228 | void *global_context = NULL; | ||
229 | union acpi_operand_object *handler_obj; | ||
230 | |||
231 | |||
232 | ACPI_FUNCTION_ENTRY (); | ||
233 | |||
234 | |||
235 | /* | ||
236 | * We will invoke a global notify handler if installed. | ||
237 | * This is done _before_ we invoke the per-device handler attached to the device. | ||
238 | */ | ||
239 | if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) { | ||
240 | /* Global system notification handler */ | ||
241 | |||
242 | if (acpi_gbl_system_notify.handler) { | ||
243 | global_handler = acpi_gbl_system_notify.handler; | ||
244 | global_context = acpi_gbl_system_notify.context; | ||
245 | } | ||
246 | } | ||
247 | else { | ||
248 | /* Global driver notification handler */ | ||
249 | |||
250 | if (acpi_gbl_device_notify.handler) { | ||
251 | global_handler = acpi_gbl_device_notify.handler; | ||
252 | global_context = acpi_gbl_device_notify.context; | ||
253 | } | ||
254 | } | ||
255 | |||
256 | /* Invoke the system handler first, if present */ | ||
257 | |||
258 | if (global_handler) { | ||
259 | global_handler (notify_info->notify.node, notify_info->notify.value, global_context); | ||
260 | } | ||
261 | |||
262 | /* Now invoke the per-device handler, if present */ | ||
263 | |||
264 | handler_obj = notify_info->notify.handler_obj; | ||
265 | if (handler_obj) { | ||
266 | handler_obj->notify.handler (notify_info->notify.node, notify_info->notify.value, | ||
267 | handler_obj->notify.context); | ||
268 | } | ||
269 | |||
270 | /* All done with the info object */ | ||
271 | |||
272 | acpi_ut_delete_generic_state (notify_info); | ||
273 | } | ||
274 | |||
275 | |||
276 | /******************************************************************************* | ||
277 | * | ||
278 | * FUNCTION: acpi_ev_global_lock_thread | ||
279 | * | ||
280 | * PARAMETERS: Context - From thread interface, not used | ||
281 | * | ||
282 | * RETURN: None | ||
283 | * | ||
284 | * DESCRIPTION: Invoked by SCI interrupt handler upon acquisition of the | ||
285 | * Global Lock. Simply signal all threads that are waiting | ||
286 | * for the lock. | ||
287 | * | ||
288 | ******************************************************************************/ | ||
289 | |||
290 | static void ACPI_SYSTEM_XFACE | ||
291 | acpi_ev_global_lock_thread ( | ||
292 | void *context) | ||
293 | { | ||
294 | acpi_status status; | ||
295 | |||
296 | |||
297 | /* Signal threads that are waiting for the lock */ | ||
298 | |||
299 | if (acpi_gbl_global_lock_thread_count) { | ||
300 | /* Send sufficient units to the semaphore */ | ||
301 | |||
302 | status = acpi_os_signal_semaphore (acpi_gbl_global_lock_semaphore, | ||
303 | acpi_gbl_global_lock_thread_count); | ||
304 | if (ACPI_FAILURE (status)) { | ||
305 | ACPI_REPORT_ERROR (("Could not signal Global Lock semaphore\n")); | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | |||
310 | |||
311 | /******************************************************************************* | ||
312 | * | ||
313 | * FUNCTION: acpi_ev_global_lock_handler | ||
314 | * | ||
315 | * PARAMETERS: Context - From thread interface, not used | ||
316 | * | ||
317 | * RETURN: ACPI_INTERRUPT_HANDLED or ACPI_INTERRUPT_NOT_HANDLED | ||
318 | * | ||
319 | * DESCRIPTION: Invoked directly from the SCI handler when a global lock | ||
320 | * release interrupt occurs. Grab the global lock and queue | ||
321 | * the global lock thread for execution | ||
322 | * | ||
323 | ******************************************************************************/ | ||
324 | |||
325 | static u32 | ||
326 | acpi_ev_global_lock_handler ( | ||
327 | void *context) | ||
328 | { | ||
329 | u8 acquired = FALSE; | ||
330 | acpi_status status; | ||
331 | |||
332 | |||
333 | /* | ||
334 | * Attempt to get the lock | ||
335 | * If we don't get it now, it will be marked pending and we will | ||
336 | * take another interrupt when it becomes free. | ||
337 | */ | ||
338 | ACPI_ACQUIRE_GLOBAL_LOCK (acpi_gbl_common_fACS.global_lock, acquired); | ||
339 | if (acquired) { | ||
340 | /* Got the lock, now wake all threads waiting for it */ | ||
341 | |||
342 | acpi_gbl_global_lock_acquired = TRUE; | ||
343 | |||
344 | /* Run the Global Lock thread which will signal all waiting threads */ | ||
345 | |||
346 | status = acpi_os_queue_for_execution (OSD_PRIORITY_HIGH, | ||
347 | acpi_ev_global_lock_thread, context); | ||
348 | if (ACPI_FAILURE (status)) { | ||
349 | ACPI_REPORT_ERROR (("Could not queue Global Lock thread, %s\n", | ||
350 | acpi_format_exception (status))); | ||
351 | |||
352 | return (ACPI_INTERRUPT_NOT_HANDLED); | ||
353 | } | ||
354 | } | ||
355 | |||
356 | return (ACPI_INTERRUPT_HANDLED); | ||
357 | } | ||
358 | |||
359 | |||
360 | /******************************************************************************* | ||
361 | * | ||
362 | * FUNCTION: acpi_ev_init_global_lock_handler | ||
363 | * | ||
364 | * PARAMETERS: None | ||
365 | * | ||
366 | * RETURN: Status | ||
367 | * | ||
368 | * DESCRIPTION: Install a handler for the global lock release event | ||
369 | * | ||
370 | ******************************************************************************/ | ||
371 | |||
372 | acpi_status | ||
373 | acpi_ev_init_global_lock_handler (void) | ||
374 | { | ||
375 | acpi_status status; | ||
376 | |||
377 | |||
378 | ACPI_FUNCTION_TRACE ("ev_init_global_lock_handler"); | ||
379 | |||
380 | |||
381 | acpi_gbl_global_lock_present = TRUE; | ||
382 | status = acpi_install_fixed_event_handler (ACPI_EVENT_GLOBAL, | ||
383 | acpi_ev_global_lock_handler, NULL); | ||
384 | |||
385 | /* | ||
386 | * If the global lock does not exist on this platform, the attempt | ||
387 | * to enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick) | ||
388 | * Map to AE_OK, but mark global lock as not present. | ||
389 | * Any attempt to actually use the global lock will be flagged | ||
390 | * with an error. | ||
391 | */ | ||
392 | if (status == AE_NO_HARDWARE_RESPONSE) { | ||
393 | acpi_gbl_global_lock_present = FALSE; | ||
394 | status = AE_OK; | ||
395 | } | ||
396 | |||
397 | return_ACPI_STATUS (status); | ||
398 | } | ||
399 | |||
400 | |||
401 | /****************************************************************************** | ||
402 | * | ||
403 | * FUNCTION: acpi_ev_acquire_global_lock | ||
404 | * | ||
405 | * PARAMETERS: Timeout - Max time to wait for the lock, in millisec. | ||
406 | * | ||
407 | * RETURN: Status | ||
408 | * | ||
409 | * DESCRIPTION: Attempt to gain ownership of the Global Lock. | ||
410 | * | ||
411 | *****************************************************************************/ | ||
412 | |||
413 | acpi_status | ||
414 | acpi_ev_acquire_global_lock ( | ||
415 | u16 timeout) | ||
416 | { | ||
417 | acpi_status status = AE_OK; | ||
418 | u8 acquired = FALSE; | ||
419 | |||
420 | |||
421 | ACPI_FUNCTION_TRACE ("ev_acquire_global_lock"); | ||
422 | |||
423 | |||
424 | #ifndef ACPI_APPLICATION | ||
425 | /* Make sure that we actually have a global lock */ | ||
426 | |||
427 | if (!acpi_gbl_global_lock_present) { | ||
428 | return_ACPI_STATUS (AE_NO_GLOBAL_LOCK); | ||
429 | } | ||
430 | #endif | ||
431 | |||
432 | /* One more thread wants the global lock */ | ||
433 | |||
434 | acpi_gbl_global_lock_thread_count++; | ||
435 | |||
436 | /* If we (OS side vs. BIOS side) have the hardware lock already, we are done */ | ||
437 | |||
438 | if (acpi_gbl_global_lock_acquired) { | ||
439 | return_ACPI_STATUS (AE_OK); | ||
440 | } | ||
441 | |||
442 | /* We must acquire the actual hardware lock */ | ||
443 | |||
444 | ACPI_ACQUIRE_GLOBAL_LOCK (acpi_gbl_common_fACS.global_lock, acquired); | ||
445 | if (acquired) { | ||
446 | /* We got the lock */ | ||
447 | |||
448 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired the HW Global Lock\n")); | ||
449 | |||
450 | acpi_gbl_global_lock_acquired = TRUE; | ||
451 | return_ACPI_STATUS (AE_OK); | ||
452 | } | ||
453 | |||
454 | /* | ||
455 | * Did not get the lock. The pending bit was set above, and we must now | ||
456 | * wait until we get the global lock released interrupt. | ||
457 | */ | ||
458 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for the HW Global Lock\n")); | ||
459 | |||
460 | /* | ||
461 | * Acquire the global lock semaphore first. | ||
462 | * Since this wait will block, we must release the interpreter | ||
463 | */ | ||
464 | status = acpi_ex_system_wait_semaphore (acpi_gbl_global_lock_semaphore, | ||
465 | timeout); | ||
466 | return_ACPI_STATUS (status); | ||
467 | } | ||
468 | |||
469 | |||
470 | /******************************************************************************* | ||
471 | * | ||
472 | * FUNCTION: acpi_ev_release_global_lock | ||
473 | * | ||
474 | * PARAMETERS: None | ||
475 | * | ||
476 | * RETURN: Status | ||
477 | * | ||
478 | * DESCRIPTION: Releases ownership of the Global Lock. | ||
479 | * | ||
480 | ******************************************************************************/ | ||
481 | |||
482 | acpi_status | ||
483 | acpi_ev_release_global_lock (void) | ||
484 | { | ||
485 | u8 pending = FALSE; | ||
486 | acpi_status status = AE_OK; | ||
487 | |||
488 | |||
489 | ACPI_FUNCTION_TRACE ("ev_release_global_lock"); | ||
490 | |||
491 | |||
492 | if (!acpi_gbl_global_lock_thread_count) { | ||
493 | ACPI_REPORT_WARNING(("Cannot release HW Global Lock, it has not been acquired\n")); | ||
494 | return_ACPI_STATUS (AE_NOT_ACQUIRED); | ||
495 | } | ||
496 | |||
497 | /* One fewer thread has the global lock */ | ||
498 | |||
499 | acpi_gbl_global_lock_thread_count--; | ||
500 | if (acpi_gbl_global_lock_thread_count) { | ||
501 | /* There are still some threads holding the lock, cannot release */ | ||
502 | |||
503 | return_ACPI_STATUS (AE_OK); | ||
504 | } | ||
505 | |||
506 | /* | ||
507 | * No more threads holding lock, we can do the actual hardware | ||
508 | * release | ||
509 | */ | ||
510 | ACPI_RELEASE_GLOBAL_LOCK (acpi_gbl_common_fACS.global_lock, pending); | ||
511 | acpi_gbl_global_lock_acquired = FALSE; | ||
512 | |||
513 | /* | ||
514 | * If the pending bit was set, we must write GBL_RLS to the control | ||
515 | * register | ||
516 | */ | ||
517 | if (pending) { | ||
518 | status = acpi_set_register (ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1, ACPI_MTX_LOCK); | ||
519 | } | ||
520 | |||
521 | return_ACPI_STATUS (status); | ||
522 | } | ||
523 | |||
524 | |||
525 | /****************************************************************************** | ||
526 | * | ||
527 | * FUNCTION: acpi_ev_terminate | ||
528 | * | ||
529 | * PARAMETERS: none | ||
530 | * | ||
531 | * RETURN: none | ||
532 | * | ||
533 | * DESCRIPTION: Disable events and free memory allocated for table storage. | ||
534 | * | ||
535 | ******************************************************************************/ | ||
536 | |||
537 | void | ||
538 | acpi_ev_terminate (void) | ||
539 | { | ||
540 | acpi_native_uint i; | ||
541 | acpi_status status; | ||
542 | |||
543 | |||
544 | ACPI_FUNCTION_TRACE ("ev_terminate"); | ||
545 | |||
546 | |||
547 | if (acpi_gbl_events_initialized) { | ||
548 | /* | ||
549 | * Disable all event-related functionality. | ||
550 | * In all cases, on error, print a message but obviously we don't abort. | ||
551 | */ | ||
552 | |||
553 | /* Disable all fixed events */ | ||
554 | |||
555 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { | ||
556 | status = acpi_disable_event ((u32) i, 0); | ||
557 | if (ACPI_FAILURE (status)) { | ||
558 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", (u32) i)); | ||
559 | } | ||
560 | } | ||
561 | |||
562 | /* Disable all GPEs in all GPE blocks */ | ||
563 | |||
564 | status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, ACPI_NOT_ISR); | ||
565 | |||
566 | /* Remove SCI handler */ | ||
567 | |||
568 | status = acpi_ev_remove_sci_handler (); | ||
569 | if (ACPI_FAILURE(status)) { | ||
570 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not remove SCI handler\n")); | ||
571 | } | ||
572 | } | ||
573 | |||
574 | /* Deallocate all handler objects installed within GPE info structs */ | ||
575 | |||
576 | status = acpi_ev_walk_gpe_list (acpi_ev_delete_gpe_handlers, ACPI_NOT_ISR); | ||
577 | |||
578 | /* Return to original mode if necessary */ | ||
579 | |||
580 | if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) { | ||
581 | status = acpi_disable (); | ||
582 | if (ACPI_FAILURE (status)) { | ||
583 | ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "acpi_disable failed\n")); | ||
584 | } | ||
585 | } | ||
586 | return_VOID; | ||
587 | } | ||
588 | |||
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c new file mode 100644 index 000000000000..772342708a7a --- /dev/null +++ b/drivers/acpi/events/evregion.c | |||
@@ -0,0 +1,1067 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evregion - ACPI address_space (op_region) handler dispatch | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | |||
45 | #include <acpi/acpi.h> | ||
46 | #include <acpi/acevents.h> | ||
47 | #include <acpi/acnamesp.h> | ||
48 | #include <acpi/acinterp.h> | ||
49 | |||
50 | #define _COMPONENT ACPI_EVENTS | ||
51 | ACPI_MODULE_NAME ("evregion") | ||
52 | |||
53 | #define ACPI_NUM_DEFAULT_SPACES 4 | ||
54 | |||
55 | static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = { | ||
56 | ACPI_ADR_SPACE_SYSTEM_MEMORY, | ||
57 | ACPI_ADR_SPACE_SYSTEM_IO, | ||
58 | ACPI_ADR_SPACE_PCI_CONFIG, | ||
59 | ACPI_ADR_SPACE_DATA_TABLE}; | ||
60 | |||
61 | |||
62 | /******************************************************************************* | ||
63 | * | ||
64 | * FUNCTION: acpi_ev_install_region_handlers | ||
65 | * | ||
66 | * PARAMETERS: None | ||
67 | * | ||
68 | * RETURN: Status | ||
69 | * | ||
70 | * DESCRIPTION: Installs the core subsystem default address space handlers. | ||
71 | * | ||
72 | ******************************************************************************/ | ||
73 | |||
74 | acpi_status | ||
75 | acpi_ev_install_region_handlers ( | ||
76 | void) { | ||
77 | acpi_status status; | ||
78 | acpi_native_uint i; | ||
79 | |||
80 | |||
81 | ACPI_FUNCTION_TRACE ("ev_install_region_handlers"); | ||
82 | |||
83 | |||
84 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
85 | if (ACPI_FAILURE (status)) { | ||
86 | return_ACPI_STATUS (status); | ||
87 | } | ||
88 | |||
89 | /* | ||
90 | * All address spaces (PCI Config, EC, SMBus) are scope dependent | ||
91 | * and registration must occur for a specific device. | ||
92 | * | ||
93 | * In the case of the system memory and IO address spaces there is currently | ||
94 | * no device associated with the address space. For these we use the root. | ||
95 | * | ||
96 | * We install the default PCI config space handler at the root so | ||
97 | * that this space is immediately available even though the we have | ||
98 | * not enumerated all the PCI Root Buses yet. This is to conform | ||
99 | * to the ACPI specification which states that the PCI config | ||
100 | * space must be always available -- even though we are nowhere | ||
101 | * near ready to find the PCI root buses at this point. | ||
102 | * | ||
103 | * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler | ||
104 | * has already been installed (via acpi_install_address_space_handler). | ||
105 | * Similar for AE_SAME_HANDLER. | ||
106 | */ | ||
107 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { | ||
108 | status = acpi_ev_install_space_handler (acpi_gbl_root_node, | ||
109 | acpi_gbl_default_address_spaces[i], | ||
110 | ACPI_DEFAULT_HANDLER, NULL, NULL); | ||
111 | switch (status) { | ||
112 | case AE_OK: | ||
113 | case AE_SAME_HANDLER: | ||
114 | case AE_ALREADY_EXISTS: | ||
115 | |||
116 | /* These exceptions are all OK */ | ||
117 | |||
118 | status = AE_OK; | ||
119 | break; | ||
120 | |||
121 | default: | ||
122 | |||
123 | goto unlock_and_exit; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | unlock_and_exit: | ||
128 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
129 | return_ACPI_STATUS (status); | ||
130 | } | ||
131 | |||
132 | |||
133 | /******************************************************************************* | ||
134 | * | ||
135 | * FUNCTION: acpi_ev_initialize_op_regions | ||
136 | * | ||
137 | * PARAMETERS: None | ||
138 | * | ||
139 | * RETURN: Status | ||
140 | * | ||
141 | * DESCRIPTION: Execute _REG methods for all Operation Regions that have | ||
142 | * an installed default region handler. | ||
143 | * | ||
144 | ******************************************************************************/ | ||
145 | |||
146 | acpi_status | ||
147 | acpi_ev_initialize_op_regions ( | ||
148 | void) | ||
149 | { | ||
150 | acpi_status status; | ||
151 | acpi_native_uint i; | ||
152 | |||
153 | |||
154 | ACPI_FUNCTION_TRACE ("ev_initialize_op_regions"); | ||
155 | |||
156 | |||
157 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
158 | if (ACPI_FAILURE (status)) { | ||
159 | return_ACPI_STATUS (status); | ||
160 | } | ||
161 | |||
162 | /* | ||
163 | * Run the _REG methods for op_regions in each default address space | ||
164 | */ | ||
165 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { | ||
166 | /* TBD: Make sure handler is the DEFAULT handler, otherwise | ||
167 | * _REG will have already been run. | ||
168 | */ | ||
169 | status = acpi_ev_execute_reg_methods (acpi_gbl_root_node, | ||
170 | acpi_gbl_default_address_spaces[i]); | ||
171 | } | ||
172 | |||
173 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
174 | return_ACPI_STATUS (status); | ||
175 | } | ||
176 | |||
177 | |||
178 | /******************************************************************************* | ||
179 | * | ||
180 | * FUNCTION: acpi_ev_execute_reg_method | ||
181 | * | ||
182 | * PARAMETERS: region_obj - Object structure | ||
183 | * Function - Passed to _REG: On (1) or Off (0) | ||
184 | * | ||
185 | * RETURN: Status | ||
186 | * | ||
187 | * DESCRIPTION: Execute _REG method for a region | ||
188 | * | ||
189 | ******************************************************************************/ | ||
190 | |||
191 | acpi_status | ||
192 | acpi_ev_execute_reg_method ( | ||
193 | union acpi_operand_object *region_obj, | ||
194 | u32 function) | ||
195 | { | ||
196 | struct acpi_parameter_info info; | ||
197 | union acpi_operand_object *params[3]; | ||
198 | union acpi_operand_object *region_obj2; | ||
199 | acpi_status status; | ||
200 | |||
201 | |||
202 | ACPI_FUNCTION_TRACE ("ev_execute_reg_method"); | ||
203 | |||
204 | |||
205 | region_obj2 = acpi_ns_get_secondary_object (region_obj); | ||
206 | if (!region_obj2) { | ||
207 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
208 | } | ||
209 | |||
210 | if (region_obj2->extra.method_REG == NULL) { | ||
211 | return_ACPI_STATUS (AE_OK); | ||
212 | } | ||
213 | |||
214 | /* | ||
215 | * The _REG method has two arguments: | ||
216 | * | ||
217 | * Arg0, Integer: Operation region space ID | ||
218 | * Same value as region_obj->Region.space_id | ||
219 | * Arg1, Integer: connection status | ||
220 | * 1 for connecting the handler, | ||
221 | * 0 for disconnecting the handler | ||
222 | * Passed as a parameter | ||
223 | */ | ||
224 | params[0] = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); | ||
225 | if (!params[0]) { | ||
226 | return_ACPI_STATUS (AE_NO_MEMORY); | ||
227 | } | ||
228 | |||
229 | params[1] = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); | ||
230 | if (!params[1]) { | ||
231 | status = AE_NO_MEMORY; | ||
232 | goto cleanup; | ||
233 | } | ||
234 | |||
235 | /* Setup the parameter objects */ | ||
236 | |||
237 | params[0]->integer.value = region_obj->region.space_id; | ||
238 | params[1]->integer.value = function; | ||
239 | params[2] = NULL; | ||
240 | |||
241 | info.node = region_obj2->extra.method_REG; | ||
242 | info.parameters = params; | ||
243 | info.parameter_type = ACPI_PARAM_ARGS; | ||
244 | |||
245 | /* Execute the method, no return value */ | ||
246 | |||
247 | ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname ( | ||
248 | ACPI_TYPE_METHOD, info.node, NULL)); | ||
249 | status = acpi_ns_evaluate_by_handle (&info); | ||
250 | |||
251 | acpi_ut_remove_reference (params[1]); | ||
252 | |||
253 | cleanup: | ||
254 | acpi_ut_remove_reference (params[0]); | ||
255 | |||
256 | return_ACPI_STATUS (status); | ||
257 | } | ||
258 | |||
259 | |||
260 | /******************************************************************************* | ||
261 | * | ||
262 | * FUNCTION: acpi_ev_address_space_dispatch | ||
263 | * | ||
264 | * PARAMETERS: region_obj - Internal region object | ||
265 | * Function - Read or Write operation | ||
266 | * Address - Where in the space to read or write | ||
267 | * bit_width - Field width in bits (8, 16, 32, or 64) | ||
268 | * Value - Pointer to in or out value | ||
269 | * | ||
270 | * RETURN: Status | ||
271 | * | ||
272 | * DESCRIPTION: Dispatch an address space or operation region access to | ||
273 | * a previously installed handler. | ||
274 | * | ||
275 | ******************************************************************************/ | ||
276 | |||
277 | acpi_status | ||
278 | acpi_ev_address_space_dispatch ( | ||
279 | union acpi_operand_object *region_obj, | ||
280 | u32 function, | ||
281 | acpi_physical_address address, | ||
282 | u32 bit_width, | ||
283 | void *value) | ||
284 | { | ||
285 | acpi_status status; | ||
286 | acpi_status status2; | ||
287 | acpi_adr_space_handler handler; | ||
288 | acpi_adr_space_setup region_setup; | ||
289 | union acpi_operand_object *handler_desc; | ||
290 | union acpi_operand_object *region_obj2; | ||
291 | void *region_context = NULL; | ||
292 | |||
293 | |||
294 | ACPI_FUNCTION_TRACE ("ev_address_space_dispatch"); | ||
295 | |||
296 | |||
297 | region_obj2 = acpi_ns_get_secondary_object (region_obj); | ||
298 | if (!region_obj2) { | ||
299 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
300 | } | ||
301 | |||
302 | /* Ensure that there is a handler associated with this region */ | ||
303 | |||
304 | handler_desc = region_obj->region.handler; | ||
305 | if (!handler_desc) { | ||
306 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
307 | "No handler for Region [%4.4s] (%p) [%s]\n", | ||
308 | acpi_ut_get_node_name (region_obj->region.node), | ||
309 | region_obj, acpi_ut_get_region_name (region_obj->region.space_id))); | ||
310 | |||
311 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
312 | } | ||
313 | |||
314 | /* | ||
315 | * It may be the case that the region has never been initialized | ||
316 | * Some types of regions require special init code | ||
317 | */ | ||
318 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { | ||
319 | /* | ||
320 | * This region has not been initialized yet, do it | ||
321 | */ | ||
322 | region_setup = handler_desc->address_space.setup; | ||
323 | if (!region_setup) { | ||
324 | /* No initialization routine, exit with error */ | ||
325 | |||
326 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No init routine for region(%p) [%s]\n", | ||
327 | region_obj, acpi_ut_get_region_name (region_obj->region.space_id))); | ||
328 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
329 | } | ||
330 | |||
331 | /* | ||
332 | * We must exit the interpreter because the region setup will potentially | ||
333 | * execute control methods (e.g., _REG method for this region) | ||
334 | */ | ||
335 | acpi_ex_exit_interpreter (); | ||
336 | |||
337 | status = region_setup (region_obj, ACPI_REGION_ACTIVATE, | ||
338 | handler_desc->address_space.context, ®ion_context); | ||
339 | |||
340 | /* Re-enter the interpreter */ | ||
341 | |||
342 | status2 = acpi_ex_enter_interpreter (); | ||
343 | if (ACPI_FAILURE (status2)) { | ||
344 | return_ACPI_STATUS (status2); | ||
345 | } | ||
346 | |||
347 | /* Check for failure of the Region Setup */ | ||
348 | |||
349 | if (ACPI_FAILURE (status)) { | ||
350 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Region Init: %s [%s]\n", | ||
351 | acpi_format_exception (status), | ||
352 | acpi_ut_get_region_name (region_obj->region.space_id))); | ||
353 | return_ACPI_STATUS (status); | ||
354 | } | ||
355 | |||
356 | /* | ||
357 | * Region initialization may have been completed by region_setup | ||
358 | */ | ||
359 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { | ||
360 | region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; | ||
361 | |||
362 | if (region_obj2->extra.region_context) { | ||
363 | /* The handler for this region was already installed */ | ||
364 | |||
365 | ACPI_MEM_FREE (region_context); | ||
366 | } | ||
367 | else { | ||
368 | /* | ||
369 | * Save the returned context for use in all accesses to | ||
370 | * this particular region | ||
371 | */ | ||
372 | region_obj2->extra.region_context = region_context; | ||
373 | } | ||
374 | } | ||
375 | } | ||
376 | |||
377 | /* We have everything we need, we can invoke the address space handler */ | ||
378 | |||
379 | handler = handler_desc->address_space.handler; | ||
380 | |||
381 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
382 | "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", | ||
383 | ®ion_obj->region.handler->address_space, handler, | ||
384 | ACPI_FORMAT_UINT64 (address), | ||
385 | acpi_ut_get_region_name (region_obj->region.space_id))); | ||
386 | |||
387 | if (!(handler_desc->address_space.hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | ||
388 | /* | ||
389 | * For handlers other than the default (supplied) handlers, we must | ||
390 | * exit the interpreter because the handler *might* block -- we don't | ||
391 | * know what it will do, so we can't hold the lock on the intepreter. | ||
392 | */ | ||
393 | acpi_ex_exit_interpreter(); | ||
394 | } | ||
395 | |||
396 | /* Call the handler */ | ||
397 | |||
398 | status = handler (function, address, bit_width, value, | ||
399 | handler_desc->address_space.context, | ||
400 | region_obj2->extra.region_context); | ||
401 | |||
402 | if (ACPI_FAILURE (status)) { | ||
403 | ACPI_REPORT_ERROR (("Handler for [%s] returned %s\n", | ||
404 | acpi_ut_get_region_name (region_obj->region.space_id), | ||
405 | acpi_format_exception (status))); | ||
406 | } | ||
407 | |||
408 | if (!(handler_desc->address_space.hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | ||
409 | /* | ||
410 | * We just returned from a non-default handler, we must re-enter the | ||
411 | * interpreter | ||
412 | */ | ||
413 | status2 = acpi_ex_enter_interpreter (); | ||
414 | if (ACPI_FAILURE (status2)) { | ||
415 | return_ACPI_STATUS (status2); | ||
416 | } | ||
417 | } | ||
418 | |||
419 | return_ACPI_STATUS (status); | ||
420 | } | ||
421 | |||
422 | |||
423 | /******************************************************************************* | ||
424 | * | ||
425 | * FUNCTION: acpi_ev_detach_region | ||
426 | * | ||
427 | * PARAMETERS: region_obj - Region Object | ||
428 | * acpi_ns_is_locked - Namespace Region Already Locked? | ||
429 | * | ||
430 | * RETURN: None | ||
431 | * | ||
432 | * DESCRIPTION: Break the association between the handler and the region | ||
433 | * this is a two way association. | ||
434 | * | ||
435 | ******************************************************************************/ | ||
436 | |||
437 | void | ||
438 | acpi_ev_detach_region( | ||
439 | union acpi_operand_object *region_obj, | ||
440 | u8 acpi_ns_is_locked) | ||
441 | { | ||
442 | union acpi_operand_object *handler_obj; | ||
443 | union acpi_operand_object *obj_desc; | ||
444 | union acpi_operand_object **last_obj_ptr; | ||
445 | acpi_adr_space_setup region_setup; | ||
446 | void **region_context; | ||
447 | union acpi_operand_object *region_obj2; | ||
448 | acpi_status status; | ||
449 | |||
450 | |||
451 | ACPI_FUNCTION_TRACE ("ev_detach_region"); | ||
452 | |||
453 | |||
454 | region_obj2 = acpi_ns_get_secondary_object (region_obj); | ||
455 | if (!region_obj2) { | ||
456 | return_VOID; | ||
457 | } | ||
458 | region_context = ®ion_obj2->extra.region_context; | ||
459 | |||
460 | /* Get the address handler from the region object */ | ||
461 | |||
462 | handler_obj = region_obj->region.handler; | ||
463 | if (!handler_obj) { | ||
464 | /* This region has no handler, all done */ | ||
465 | |||
466 | return_VOID; | ||
467 | } | ||
468 | |||
469 | /* Find this region in the handler's list */ | ||
470 | |||
471 | obj_desc = handler_obj->address_space.region_list; | ||
472 | last_obj_ptr = &handler_obj->address_space.region_list; | ||
473 | |||
474 | while (obj_desc) { | ||
475 | /* Is this the correct Region? */ | ||
476 | |||
477 | if (obj_desc == region_obj) { | ||
478 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
479 | "Removing Region %p from address handler %p\n", | ||
480 | region_obj, handler_obj)); | ||
481 | |||
482 | /* This is it, remove it from the handler's list */ | ||
483 | |||
484 | *last_obj_ptr = obj_desc->region.next; | ||
485 | obj_desc->region.next = NULL; /* Must clear field */ | ||
486 | |||
487 | if (acpi_ns_is_locked) { | ||
488 | status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
489 | if (ACPI_FAILURE (status)) { | ||
490 | return_VOID; | ||
491 | } | ||
492 | } | ||
493 | |||
494 | /* Now stop region accesses by executing the _REG method */ | ||
495 | |||
496 | status = acpi_ev_execute_reg_method (region_obj, 0); | ||
497 | if (ACPI_FAILURE (status)) { | ||
498 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s from region _REG, [%s]\n", | ||
499 | acpi_format_exception (status), | ||
500 | acpi_ut_get_region_name (region_obj->region.space_id))); | ||
501 | } | ||
502 | |||
503 | if (acpi_ns_is_locked) { | ||
504 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
505 | if (ACPI_FAILURE (status)) { | ||
506 | return_VOID; | ||
507 | } | ||
508 | } | ||
509 | |||
510 | /* Call the setup handler with the deactivate notification */ | ||
511 | |||
512 | region_setup = handler_obj->address_space.setup; | ||
513 | status = region_setup (region_obj, ACPI_REGION_DEACTIVATE, | ||
514 | handler_obj->address_space.context, region_context); | ||
515 | |||
516 | /* Init routine may fail, Just ignore errors */ | ||
517 | |||
518 | if (ACPI_FAILURE (status)) { | ||
519 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s from region init, [%s]\n", | ||
520 | acpi_format_exception (status), | ||
521 | acpi_ut_get_region_name (region_obj->region.space_id))); | ||
522 | } | ||
523 | |||
524 | region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE); | ||
525 | |||
526 | /* | ||
527 | * Remove handler reference in the region | ||
528 | * | ||
529 | * NOTE: this doesn't mean that the region goes away | ||
530 | * The region is just inaccessible as indicated to | ||
531 | * the _REG method | ||
532 | * | ||
533 | * If the region is on the handler's list | ||
534 | * this better be the region's handler | ||
535 | */ | ||
536 | region_obj->region.handler = NULL; | ||
537 | acpi_ut_remove_reference (handler_obj); | ||
538 | |||
539 | return_VOID; | ||
540 | } | ||
541 | |||
542 | /* Walk the linked list of handlers */ | ||
543 | |||
544 | last_obj_ptr = &obj_desc->region.next; | ||
545 | obj_desc = obj_desc->region.next; | ||
546 | } | ||
547 | |||
548 | /* If we get here, the region was not in the handler's region list */ | ||
549 | |||
550 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
551 | "Cannot remove region %p from address handler %p\n", | ||
552 | region_obj, handler_obj)); | ||
553 | |||
554 | return_VOID; | ||
555 | } | ||
556 | |||
557 | |||
558 | /******************************************************************************* | ||
559 | * | ||
560 | * FUNCTION: acpi_ev_attach_region | ||
561 | * | ||
562 | * PARAMETERS: handler_obj - Handler Object | ||
563 | * region_obj - Region Object | ||
564 | * acpi_ns_is_locked - Namespace Region Already Locked? | ||
565 | * | ||
566 | * RETURN: None | ||
567 | * | ||
568 | * DESCRIPTION: Create the association between the handler and the region | ||
569 | * this is a two way association. | ||
570 | * | ||
571 | ******************************************************************************/ | ||
572 | |||
573 | acpi_status | ||
574 | acpi_ev_attach_region ( | ||
575 | union acpi_operand_object *handler_obj, | ||
576 | union acpi_operand_object *region_obj, | ||
577 | u8 acpi_ns_is_locked) | ||
578 | { | ||
579 | |||
580 | ACPI_FUNCTION_TRACE ("ev_attach_region"); | ||
581 | |||
582 | |||
583 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
584 | "Adding Region [%4.4s] %p to address handler %p [%s]\n", | ||
585 | acpi_ut_get_node_name (region_obj->region.node), | ||
586 | region_obj, handler_obj, | ||
587 | acpi_ut_get_region_name (region_obj->region.space_id))); | ||
588 | |||
589 | /* Link this region to the front of the handler's list */ | ||
590 | |||
591 | region_obj->region.next = handler_obj->address_space.region_list; | ||
592 | handler_obj->address_space.region_list = region_obj; | ||
593 | |||
594 | /* Install the region's handler */ | ||
595 | |||
596 | if (region_obj->region.handler) { | ||
597 | return_ACPI_STATUS (AE_ALREADY_EXISTS); | ||
598 | } | ||
599 | |||
600 | region_obj->region.handler = handler_obj; | ||
601 | acpi_ut_add_reference (handler_obj); | ||
602 | |||
603 | return_ACPI_STATUS (AE_OK); | ||
604 | } | ||
605 | |||
606 | |||
607 | /******************************************************************************* | ||
608 | * | ||
609 | * FUNCTION: acpi_ev_install_handler | ||
610 | * | ||
611 | * PARAMETERS: walk_namespace callback | ||
612 | * | ||
613 | * DESCRIPTION: This routine installs an address handler into objects that are | ||
614 | * of type Region or Device. | ||
615 | * | ||
616 | * If the Object is a Device, and the device has a handler of | ||
617 | * the same type then the search is terminated in that branch. | ||
618 | * | ||
619 | * This is because the existing handler is closer in proximity | ||
620 | * to any more regions than the one we are trying to install. | ||
621 | * | ||
622 | ******************************************************************************/ | ||
623 | |||
624 | acpi_status | ||
625 | acpi_ev_install_handler ( | ||
626 | acpi_handle obj_handle, | ||
627 | u32 level, | ||
628 | void *context, | ||
629 | void **return_value) | ||
630 | { | ||
631 | union acpi_operand_object *handler_obj; | ||
632 | union acpi_operand_object *next_handler_obj; | ||
633 | union acpi_operand_object *obj_desc; | ||
634 | struct acpi_namespace_node *node; | ||
635 | acpi_status status; | ||
636 | |||
637 | |||
638 | ACPI_FUNCTION_NAME ("ev_install_handler"); | ||
639 | |||
640 | |||
641 | handler_obj = (union acpi_operand_object *) context; | ||
642 | |||
643 | /* Parameter validation */ | ||
644 | |||
645 | if (!handler_obj) { | ||
646 | return (AE_OK); | ||
647 | } | ||
648 | |||
649 | /* Convert and validate the device handle */ | ||
650 | |||
651 | node = acpi_ns_map_handle_to_node (obj_handle); | ||
652 | if (!node) { | ||
653 | return (AE_BAD_PARAMETER); | ||
654 | } | ||
655 | |||
656 | /* | ||
657 | * We only care about regions.and objects | ||
658 | * that are allowed to have address space handlers | ||
659 | */ | ||
660 | if ((node->type != ACPI_TYPE_DEVICE) && | ||
661 | (node->type != ACPI_TYPE_REGION) && | ||
662 | (node != acpi_gbl_root_node)) { | ||
663 | return (AE_OK); | ||
664 | } | ||
665 | |||
666 | /* Check for an existing internal object */ | ||
667 | |||
668 | obj_desc = acpi_ns_get_attached_object (node); | ||
669 | if (!obj_desc) { | ||
670 | /* No object, just exit */ | ||
671 | |||
672 | return (AE_OK); | ||
673 | } | ||
674 | |||
675 | /* Devices are handled different than regions */ | ||
676 | |||
677 | if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_DEVICE) { | ||
678 | /* Check if this Device already has a handler for this address space */ | ||
679 | |||
680 | next_handler_obj = obj_desc->device.handler; | ||
681 | while (next_handler_obj) { | ||
682 | /* Found a handler, is it for the same address space? */ | ||
683 | |||
684 | if (next_handler_obj->address_space.space_id == handler_obj->address_space.space_id) { | ||
685 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
686 | "Found handler for region [%s] in device %p(%p) handler %p\n", | ||
687 | acpi_ut_get_region_name (handler_obj->address_space.space_id), | ||
688 | obj_desc, next_handler_obj, handler_obj)); | ||
689 | |||
690 | /* | ||
691 | * Since the object we found it on was a device, then it | ||
692 | * means that someone has already installed a handler for | ||
693 | * the branch of the namespace from this device on. Just | ||
694 | * bail out telling the walk routine to not traverse this | ||
695 | * branch. This preserves the scoping rule for handlers. | ||
696 | */ | ||
697 | return (AE_CTRL_DEPTH); | ||
698 | } | ||
699 | |||
700 | /* Walk the linked list of handlers attached to this device */ | ||
701 | |||
702 | next_handler_obj = next_handler_obj->address_space.next; | ||
703 | } | ||
704 | |||
705 | /* | ||
706 | * As long as the device didn't have a handler for this | ||
707 | * space we don't care about it. We just ignore it and | ||
708 | * proceed. | ||
709 | */ | ||
710 | return (AE_OK); | ||
711 | } | ||
712 | |||
713 | /* Object is a Region */ | ||
714 | |||
715 | if (obj_desc->region.space_id != handler_obj->address_space.space_id) { | ||
716 | /* | ||
717 | * This region is for a different address space | ||
718 | * -- just ignore it | ||
719 | */ | ||
720 | return (AE_OK); | ||
721 | } | ||
722 | |||
723 | /* | ||
724 | * Now we have a region and it is for the handler's address | ||
725 | * space type. | ||
726 | * | ||
727 | * First disconnect region for any previous handler (if any) | ||
728 | */ | ||
729 | acpi_ev_detach_region (obj_desc, FALSE); | ||
730 | |||
731 | /* Connect the region to the new handler */ | ||
732 | |||
733 | status = acpi_ev_attach_region (handler_obj, obj_desc, FALSE); | ||
734 | return (status); | ||
735 | } | ||
736 | |||
737 | |||
738 | /******************************************************************************* | ||
739 | * | ||
740 | * FUNCTION: acpi_ev_install_space_handler | ||
741 | * | ||
742 | * PARAMETERS: Node - Namespace node for the device | ||
743 | * space_id - The address space ID | ||
744 | * Handler - Address of the handler | ||
745 | * Setup - Address of the setup function | ||
746 | * Context - Value passed to the handler on each access | ||
747 | * | ||
748 | * RETURN: Status | ||
749 | * | ||
750 | * DESCRIPTION: Install a handler for all op_regions of a given space_id. | ||
751 | * Assumes namespace is locked | ||
752 | * | ||
753 | ******************************************************************************/ | ||
754 | |||
755 | acpi_status | ||
756 | acpi_ev_install_space_handler ( | ||
757 | struct acpi_namespace_node *node, | ||
758 | acpi_adr_space_type space_id, | ||
759 | acpi_adr_space_handler handler, | ||
760 | acpi_adr_space_setup setup, | ||
761 | void *context) | ||
762 | { | ||
763 | union acpi_operand_object *obj_desc; | ||
764 | union acpi_operand_object *handler_obj; | ||
765 | acpi_status status; | ||
766 | acpi_object_type type; | ||
767 | u16 flags = 0; | ||
768 | |||
769 | |||
770 | ACPI_FUNCTION_TRACE ("ev_install_space_handler"); | ||
771 | |||
772 | |||
773 | /* | ||
774 | * This registration is valid for only the types below | ||
775 | * and the root. This is where the default handlers | ||
776 | * get placed. | ||
777 | */ | ||
778 | if ((node->type != ACPI_TYPE_DEVICE) && | ||
779 | (node->type != ACPI_TYPE_PROCESSOR) && | ||
780 | (node->type != ACPI_TYPE_THERMAL) && | ||
781 | (node != acpi_gbl_root_node)) { | ||
782 | status = AE_BAD_PARAMETER; | ||
783 | goto unlock_and_exit; | ||
784 | } | ||
785 | |||
786 | if (handler == ACPI_DEFAULT_HANDLER) { | ||
787 | flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED; | ||
788 | |||
789 | switch (space_id) { | ||
790 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | ||
791 | handler = acpi_ex_system_memory_space_handler; | ||
792 | setup = acpi_ev_system_memory_region_setup; | ||
793 | break; | ||
794 | |||
795 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
796 | handler = acpi_ex_system_io_space_handler; | ||
797 | setup = acpi_ev_io_space_region_setup; | ||
798 | break; | ||
799 | |||
800 | case ACPI_ADR_SPACE_PCI_CONFIG: | ||
801 | handler = acpi_ex_pci_config_space_handler; | ||
802 | setup = acpi_ev_pci_config_region_setup; | ||
803 | break; | ||
804 | |||
805 | case ACPI_ADR_SPACE_CMOS: | ||
806 | handler = acpi_ex_cmos_space_handler; | ||
807 | setup = acpi_ev_cmos_region_setup; | ||
808 | break; | ||
809 | |||
810 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: | ||
811 | handler = acpi_ex_pci_bar_space_handler; | ||
812 | setup = acpi_ev_pci_bar_region_setup; | ||
813 | break; | ||
814 | |||
815 | case ACPI_ADR_SPACE_DATA_TABLE: | ||
816 | handler = acpi_ex_data_table_space_handler; | ||
817 | setup = NULL; | ||
818 | break; | ||
819 | |||
820 | default: | ||
821 | status = AE_BAD_PARAMETER; | ||
822 | goto unlock_and_exit; | ||
823 | } | ||
824 | } | ||
825 | |||
826 | /* If the caller hasn't specified a setup routine, use the default */ | ||
827 | |||
828 | if (!setup) { | ||
829 | setup = acpi_ev_default_region_setup; | ||
830 | } | ||
831 | |||
832 | /* Check for an existing internal object */ | ||
833 | |||
834 | obj_desc = acpi_ns_get_attached_object (node); | ||
835 | if (obj_desc) { | ||
836 | /* | ||
837 | * The attached device object already exists. | ||
838 | * Make sure the handler is not already installed. | ||
839 | */ | ||
840 | handler_obj = obj_desc->device.handler; | ||
841 | |||
842 | /* Walk the handler list for this device */ | ||
843 | |||
844 | while (handler_obj) { | ||
845 | /* Same space_id indicates a handler already installed */ | ||
846 | |||
847 | if (handler_obj->address_space.space_id == space_id) { | ||
848 | if (handler_obj->address_space.handler == handler) { | ||
849 | /* | ||
850 | * It is (relatively) OK to attempt to install the SAME | ||
851 | * handler twice. This can easily happen with PCI_Config space. | ||
852 | */ | ||
853 | status = AE_SAME_HANDLER; | ||
854 | goto unlock_and_exit; | ||
855 | } | ||
856 | else { | ||
857 | /* A handler is already installed */ | ||
858 | |||
859 | status = AE_ALREADY_EXISTS; | ||
860 | } | ||
861 | goto unlock_and_exit; | ||
862 | } | ||
863 | |||
864 | /* Walk the linked list of handlers */ | ||
865 | |||
866 | handler_obj = handler_obj->address_space.next; | ||
867 | } | ||
868 | } | ||
869 | else { | ||
870 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
871 | "Creating object on Device %p while installing handler\n", node)); | ||
872 | |||
873 | /* obj_desc does not exist, create one */ | ||
874 | |||
875 | if (node->type == ACPI_TYPE_ANY) { | ||
876 | type = ACPI_TYPE_DEVICE; | ||
877 | } | ||
878 | else { | ||
879 | type = node->type; | ||
880 | } | ||
881 | |||
882 | obj_desc = acpi_ut_create_internal_object (type); | ||
883 | if (!obj_desc) { | ||
884 | status = AE_NO_MEMORY; | ||
885 | goto unlock_and_exit; | ||
886 | } | ||
887 | |||
888 | /* Init new descriptor */ | ||
889 | |||
890 | obj_desc->common.type = (u8) type; | ||
891 | |||
892 | /* Attach the new object to the Node */ | ||
893 | |||
894 | status = acpi_ns_attach_object (node, obj_desc, type); | ||
895 | |||
896 | /* Remove local reference to the object */ | ||
897 | |||
898 | acpi_ut_remove_reference (obj_desc); | ||
899 | |||
900 | if (ACPI_FAILURE (status)) { | ||
901 | goto unlock_and_exit; | ||
902 | } | ||
903 | } | ||
904 | |||
905 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
906 | "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n", | ||
907 | acpi_ut_get_region_name (space_id), space_id, | ||
908 | acpi_ut_get_node_name (node), node, obj_desc)); | ||
909 | |||
910 | /* | ||
911 | * Install the handler | ||
912 | * | ||
913 | * At this point there is no existing handler. | ||
914 | * Just allocate the object for the handler and link it | ||
915 | * into the list. | ||
916 | */ | ||
917 | handler_obj = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_ADDRESS_HANDLER); | ||
918 | if (!handler_obj) { | ||
919 | status = AE_NO_MEMORY; | ||
920 | goto unlock_and_exit; | ||
921 | } | ||
922 | |||
923 | /* Init handler obj */ | ||
924 | |||
925 | handler_obj->address_space.space_id = (u8) space_id; | ||
926 | handler_obj->address_space.hflags = flags; | ||
927 | handler_obj->address_space.region_list = NULL; | ||
928 | handler_obj->address_space.node = node; | ||
929 | handler_obj->address_space.handler = handler; | ||
930 | handler_obj->address_space.context = context; | ||
931 | handler_obj->address_space.setup = setup; | ||
932 | |||
933 | /* Install at head of Device.address_space list */ | ||
934 | |||
935 | handler_obj->address_space.next = obj_desc->device.handler; | ||
936 | |||
937 | /* | ||
938 | * The Device object is the first reference on the handler_obj. | ||
939 | * Each region that uses the handler adds a reference. | ||
940 | */ | ||
941 | obj_desc->device.handler = handler_obj; | ||
942 | |||
943 | /* | ||
944 | * Walk the namespace finding all of the regions this | ||
945 | * handler will manage. | ||
946 | * | ||
947 | * Start at the device and search the branch toward | ||
948 | * the leaf nodes until either the leaf is encountered or | ||
949 | * a device is detected that has an address handler of the | ||
950 | * same type. | ||
951 | * | ||
952 | * In either case, back up and search down the remainder | ||
953 | * of the branch | ||
954 | */ | ||
955 | status = acpi_ns_walk_namespace (ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, | ||
956 | ACPI_NS_WALK_UNLOCK, acpi_ev_install_handler, | ||
957 | handler_obj, NULL); | ||
958 | |||
959 | unlock_and_exit: | ||
960 | return_ACPI_STATUS (status); | ||
961 | } | ||
962 | |||
963 | |||
964 | /******************************************************************************* | ||
965 | * | ||
966 | * FUNCTION: acpi_ev_execute_reg_methods | ||
967 | * | ||
968 | * PARAMETERS: Node - Namespace node for the device | ||
969 | * space_id - The address space ID | ||
970 | * | ||
971 | * RETURN: Status | ||
972 | * | ||
973 | * DESCRIPTION: Run all _REG methods for the input Space ID; | ||
974 | * Note: assumes namespace is locked, or system init time. | ||
975 | * | ||
976 | ******************************************************************************/ | ||
977 | |||
978 | acpi_status | ||
979 | acpi_ev_execute_reg_methods ( | ||
980 | struct acpi_namespace_node *node, | ||
981 | acpi_adr_space_type space_id) | ||
982 | { | ||
983 | acpi_status status; | ||
984 | |||
985 | |||
986 | ACPI_FUNCTION_TRACE ("ev_execute_reg_methods"); | ||
987 | |||
988 | |||
989 | /* | ||
990 | * Run all _REG methods for all Operation Regions for this | ||
991 | * space ID. This is a separate walk in order to handle any | ||
992 | * interdependencies between regions and _REG methods. (i.e. handlers | ||
993 | * must be installed for all regions of this Space ID before we | ||
994 | * can run any _REG methods) | ||
995 | */ | ||
996 | status = acpi_ns_walk_namespace (ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, | ||
997 | ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, | ||
998 | &space_id, NULL); | ||
999 | |||
1000 | return_ACPI_STATUS (status); | ||
1001 | } | ||
1002 | |||
1003 | |||
1004 | /******************************************************************************* | ||
1005 | * | ||
1006 | * FUNCTION: acpi_ev_reg_run | ||
1007 | * | ||
1008 | * PARAMETERS: walk_namespace callback | ||
1009 | * | ||
1010 | * DESCRIPTION: Run _REg method for region objects of the requested space_iD | ||
1011 | * | ||
1012 | ******************************************************************************/ | ||
1013 | |||
1014 | acpi_status | ||
1015 | acpi_ev_reg_run ( | ||
1016 | acpi_handle obj_handle, | ||
1017 | u32 level, | ||
1018 | void *context, | ||
1019 | void **return_value) | ||
1020 | { | ||
1021 | union acpi_operand_object *obj_desc; | ||
1022 | struct acpi_namespace_node *node; | ||
1023 | acpi_adr_space_type space_id; | ||
1024 | acpi_status status; | ||
1025 | |||
1026 | |||
1027 | space_id = *ACPI_CAST_PTR (acpi_adr_space_type, context); | ||
1028 | |||
1029 | /* Convert and validate the device handle */ | ||
1030 | |||
1031 | node = acpi_ns_map_handle_to_node (obj_handle); | ||
1032 | if (!node) { | ||
1033 | return (AE_BAD_PARAMETER); | ||
1034 | } | ||
1035 | |||
1036 | /* | ||
1037 | * We only care about regions.and objects | ||
1038 | * that are allowed to have address space handlers | ||
1039 | */ | ||
1040 | if ((node->type != ACPI_TYPE_REGION) && | ||
1041 | (node != acpi_gbl_root_node)) { | ||
1042 | return (AE_OK); | ||
1043 | } | ||
1044 | |||
1045 | /* Check for an existing internal object */ | ||
1046 | |||
1047 | obj_desc = acpi_ns_get_attached_object (node); | ||
1048 | if (!obj_desc) { | ||
1049 | /* No object, just exit */ | ||
1050 | |||
1051 | return (AE_OK); | ||
1052 | } | ||
1053 | |||
1054 | /* Object is a Region */ | ||
1055 | |||
1056 | if (obj_desc->region.space_id != space_id) { | ||
1057 | /* | ||
1058 | * This region is for a different address space | ||
1059 | * -- just ignore it | ||
1060 | */ | ||
1061 | return (AE_OK); | ||
1062 | } | ||
1063 | |||
1064 | status = acpi_ev_execute_reg_method (obj_desc, 1); | ||
1065 | return (status); | ||
1066 | } | ||
1067 | |||
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c new file mode 100644 index 000000000000..4983a3378be5 --- /dev/null +++ b/drivers/acpi/events/evrgnini.c | |||
@@ -0,0 +1,580 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evrgnini- ACPI address_space (op_region) init | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | |||
45 | #include <acpi/acpi.h> | ||
46 | #include <acpi/acevents.h> | ||
47 | #include <acpi/acnamesp.h> | ||
48 | |||
49 | #define _COMPONENT ACPI_EVENTS | ||
50 | ACPI_MODULE_NAME ("evrgnini") | ||
51 | |||
52 | |||
53 | /******************************************************************************* | ||
54 | * | ||
55 | * FUNCTION: acpi_ev_system_memory_region_setup | ||
56 | * | ||
57 | * PARAMETERS: Handle - Region we are interested in | ||
58 | * Function - Start or stop | ||
59 | * handler_context - Address space handler context | ||
60 | * region_context - Region specific context | ||
61 | * | ||
62 | * RETURN: Status | ||
63 | * | ||
64 | * DESCRIPTION: Do any prep work for region handling, a nop for now | ||
65 | * | ||
66 | ******************************************************************************/ | ||
67 | |||
68 | acpi_status | ||
69 | acpi_ev_system_memory_region_setup ( | ||
70 | acpi_handle handle, | ||
71 | u32 function, | ||
72 | void *handler_context, | ||
73 | void **region_context) | ||
74 | { | ||
75 | union acpi_operand_object *region_desc = (union acpi_operand_object *) handle; | ||
76 | struct acpi_mem_space_context *local_region_context; | ||
77 | |||
78 | |||
79 | ACPI_FUNCTION_TRACE ("ev_system_memory_region_setup"); | ||
80 | |||
81 | |||
82 | if (function == ACPI_REGION_DEACTIVATE) { | ||
83 | if (*region_context) { | ||
84 | ACPI_MEM_FREE (*region_context); | ||
85 | *region_context = NULL; | ||
86 | } | ||
87 | return_ACPI_STATUS (AE_OK); | ||
88 | } | ||
89 | |||
90 | /* Create a new context */ | ||
91 | |||
92 | local_region_context = ACPI_MEM_CALLOCATE (sizeof (struct acpi_mem_space_context)); | ||
93 | if (!(local_region_context)) { | ||
94 | return_ACPI_STATUS (AE_NO_MEMORY); | ||
95 | } | ||
96 | |||
97 | /* Save the region length and address for use in the handler */ | ||
98 | |||
99 | local_region_context->length = region_desc->region.length; | ||
100 | local_region_context->address = region_desc->region.address; | ||
101 | |||
102 | *region_context = local_region_context; | ||
103 | return_ACPI_STATUS (AE_OK); | ||
104 | } | ||
105 | |||
106 | |||
107 | /******************************************************************************* | ||
108 | * | ||
109 | * FUNCTION: acpi_ev_io_space_region_setup | ||
110 | * | ||
111 | * PARAMETERS: Handle - Region we are interested in | ||
112 | * Function - Start or stop | ||
113 | * handler_context - Address space handler context | ||
114 | * region_context - Region specific context | ||
115 | * | ||
116 | * RETURN: Status | ||
117 | * | ||
118 | * DESCRIPTION: Do any prep work for region handling | ||
119 | * | ||
120 | ******************************************************************************/ | ||
121 | |||
122 | acpi_status | ||
123 | acpi_ev_io_space_region_setup ( | ||
124 | acpi_handle handle, | ||
125 | u32 function, | ||
126 | void *handler_context, | ||
127 | void **region_context) | ||
128 | { | ||
129 | ACPI_FUNCTION_TRACE ("ev_io_space_region_setup"); | ||
130 | |||
131 | |||
132 | if (function == ACPI_REGION_DEACTIVATE) { | ||
133 | *region_context = NULL; | ||
134 | } | ||
135 | else { | ||
136 | *region_context = handler_context; | ||
137 | } | ||
138 | |||
139 | return_ACPI_STATUS (AE_OK); | ||
140 | } | ||
141 | |||
142 | |||
143 | /******************************************************************************* | ||
144 | * | ||
145 | * FUNCTION: acpi_ev_pci_config_region_setup | ||
146 | * | ||
147 | * PARAMETERS: Handle - Region we are interested in | ||
148 | * Function - Start or stop | ||
149 | * handler_context - Address space handler context | ||
150 | * region_context - Region specific context | ||
151 | * | ||
152 | * RETURN: Status | ||
153 | * | ||
154 | * DESCRIPTION: Do any prep work for region handling | ||
155 | * | ||
156 | * MUTEX: Assumes namespace is not locked | ||
157 | * | ||
158 | ******************************************************************************/ | ||
159 | |||
160 | acpi_status | ||
161 | acpi_ev_pci_config_region_setup ( | ||
162 | acpi_handle handle, | ||
163 | u32 function, | ||
164 | void *handler_context, | ||
165 | void **region_context) | ||
166 | { | ||
167 | acpi_status status = AE_OK; | ||
168 | acpi_integer pci_value; | ||
169 | struct acpi_pci_id *pci_id = *region_context; | ||
170 | union acpi_operand_object *handler_obj; | ||
171 | struct acpi_namespace_node *parent_node; | ||
172 | struct acpi_namespace_node *pci_root_node; | ||
173 | union acpi_operand_object *region_obj = (union acpi_operand_object *) handle; | ||
174 | struct acpi_device_id object_hID; | ||
175 | |||
176 | |||
177 | ACPI_FUNCTION_TRACE ("ev_pci_config_region_setup"); | ||
178 | |||
179 | |||
180 | handler_obj = region_obj->region.handler; | ||
181 | if (!handler_obj) { | ||
182 | /* | ||
183 | * No installed handler. This shouldn't happen because the dispatch | ||
184 | * routine checks before we get here, but we check again just in case. | ||
185 | */ | ||
186 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
187 | "Attempting to init a region %p, with no handler\n", region_obj)); | ||
188 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
189 | } | ||
190 | |||
191 | *region_context = NULL; | ||
192 | if (function == ACPI_REGION_DEACTIVATE) { | ||
193 | if (pci_id) { | ||
194 | ACPI_MEM_FREE (pci_id); | ||
195 | } | ||
196 | return_ACPI_STATUS (status); | ||
197 | } | ||
198 | |||
199 | parent_node = acpi_ns_get_parent_node (region_obj->region.node); | ||
200 | |||
201 | /* | ||
202 | * Get the _SEG and _BBN values from the device upon which the handler | ||
203 | * is installed. | ||
204 | * | ||
205 | * We need to get the _SEG and _BBN objects relative to the PCI BUS device. | ||
206 | * This is the device the handler has been registered to handle. | ||
207 | */ | ||
208 | |||
209 | /* | ||
210 | * If the address_space.Node is still pointing to the root, we need | ||
211 | * to scan upward for a PCI Root bridge and re-associate the op_region | ||
212 | * handlers with that device. | ||
213 | */ | ||
214 | if (handler_obj->address_space.node == acpi_gbl_root_node) { | ||
215 | /* Start search from the parent object */ | ||
216 | |||
217 | pci_root_node = parent_node; | ||
218 | while (pci_root_node != acpi_gbl_root_node) { | ||
219 | status = acpi_ut_execute_HID (pci_root_node, &object_hID); | ||
220 | if (ACPI_SUCCESS (status)) { | ||
221 | /* Got a valid _HID, check if this is a PCI root */ | ||
222 | |||
223 | if (!(ACPI_STRNCMP (object_hID.value, PCI_ROOT_HID_STRING, | ||
224 | sizeof (PCI_ROOT_HID_STRING)))) { | ||
225 | /* Install a handler for this PCI root bridge */ | ||
226 | |||
227 | status = acpi_install_address_space_handler ((acpi_handle) pci_root_node, | ||
228 | ACPI_ADR_SPACE_PCI_CONFIG, | ||
229 | ACPI_DEFAULT_HANDLER, NULL, NULL); | ||
230 | if (ACPI_FAILURE (status)) { | ||
231 | if (status == AE_SAME_HANDLER) { | ||
232 | /* | ||
233 | * It is OK if the handler is already installed on the root | ||
234 | * bridge. Still need to return a context object for the | ||
235 | * new PCI_Config operation region, however. | ||
236 | */ | ||
237 | status = AE_OK; | ||
238 | } | ||
239 | else { | ||
240 | ACPI_REPORT_ERROR (( | ||
241 | "Could not install pci_config handler for Root Bridge %4.4s, %s\n", | ||
242 | acpi_ut_get_node_name (pci_root_node), acpi_format_exception (status))); | ||
243 | } | ||
244 | } | ||
245 | break; | ||
246 | } | ||
247 | } | ||
248 | |||
249 | pci_root_node = acpi_ns_get_parent_node (pci_root_node); | ||
250 | } | ||
251 | |||
252 | /* PCI root bridge not found, use namespace root node */ | ||
253 | } | ||
254 | else { | ||
255 | pci_root_node = handler_obj->address_space.node; | ||
256 | } | ||
257 | |||
258 | /* | ||
259 | * If this region is now initialized, we are done. | ||
260 | * (install_address_space_handler could have initialized it) | ||
261 | */ | ||
262 | if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { | ||
263 | return_ACPI_STATUS (AE_OK); | ||
264 | } | ||
265 | |||
266 | /* Region is still not initialized. Create a new context */ | ||
267 | |||
268 | pci_id = ACPI_MEM_CALLOCATE (sizeof (struct acpi_pci_id)); | ||
269 | if (!pci_id) { | ||
270 | return_ACPI_STATUS (AE_NO_MEMORY); | ||
271 | } | ||
272 | |||
273 | /* | ||
274 | * For PCI_Config space access, we need the segment, bus, | ||
275 | * device and function numbers. Acquire them here. | ||
276 | */ | ||
277 | |||
278 | /* | ||
279 | * Get the PCI device and function numbers from the _ADR object | ||
280 | * contained in the parent's scope. | ||
281 | */ | ||
282 | status = acpi_ut_evaluate_numeric_object (METHOD_NAME__ADR, parent_node, &pci_value); | ||
283 | |||
284 | /* | ||
285 | * The default is zero, and since the allocation above zeroed | ||
286 | * the data, just do nothing on failure. | ||
287 | */ | ||
288 | if (ACPI_SUCCESS (status)) { | ||
289 | pci_id->device = ACPI_HIWORD (ACPI_LODWORD (pci_value)); | ||
290 | pci_id->function = ACPI_LOWORD (ACPI_LODWORD (pci_value)); | ||
291 | } | ||
292 | |||
293 | /* The PCI segment number comes from the _SEG method */ | ||
294 | |||
295 | status = acpi_ut_evaluate_numeric_object (METHOD_NAME__SEG, pci_root_node, &pci_value); | ||
296 | if (ACPI_SUCCESS (status)) { | ||
297 | pci_id->segment = ACPI_LOWORD (pci_value); | ||
298 | } | ||
299 | |||
300 | /* The PCI bus number comes from the _BBN method */ | ||
301 | |||
302 | status = acpi_ut_evaluate_numeric_object (METHOD_NAME__BBN, pci_root_node, &pci_value); | ||
303 | if (ACPI_SUCCESS (status)) { | ||
304 | pci_id->bus = ACPI_LOWORD (pci_value); | ||
305 | } | ||
306 | |||
307 | /* Complete this device's pci_id */ | ||
308 | |||
309 | acpi_os_derive_pci_id (pci_root_node, region_obj->region.node, &pci_id); | ||
310 | |||
311 | *region_context = pci_id; | ||
312 | return_ACPI_STATUS (AE_OK); | ||
313 | } | ||
314 | |||
315 | |||
316 | /******************************************************************************* | ||
317 | * | ||
318 | * FUNCTION: acpi_ev_pci_bar_region_setup | ||
319 | * | ||
320 | * PARAMETERS: Handle - Region we are interested in | ||
321 | * Function - Start or stop | ||
322 | * handler_context - Address space handler context | ||
323 | * region_context - Region specific context | ||
324 | * | ||
325 | * RETURN: Status | ||
326 | * | ||
327 | * DESCRIPTION: Do any prep work for region handling | ||
328 | * | ||
329 | * MUTEX: Assumes namespace is not locked | ||
330 | * | ||
331 | ******************************************************************************/ | ||
332 | |||
333 | acpi_status | ||
334 | acpi_ev_pci_bar_region_setup ( | ||
335 | acpi_handle handle, | ||
336 | u32 function, | ||
337 | void *handler_context, | ||
338 | void **region_context) | ||
339 | { | ||
340 | ACPI_FUNCTION_TRACE ("ev_pci_bar_region_setup"); | ||
341 | |||
342 | |||
343 | return_ACPI_STATUS (AE_OK); | ||
344 | } | ||
345 | |||
346 | |||
347 | /******************************************************************************* | ||
348 | * | ||
349 | * FUNCTION: acpi_ev_cmos_region_setup | ||
350 | * | ||
351 | * PARAMETERS: Handle - Region we are interested in | ||
352 | * Function - Start or stop | ||
353 | * handler_context - Address space handler context | ||
354 | * region_context - Region specific context | ||
355 | * | ||
356 | * RETURN: Status | ||
357 | * | ||
358 | * DESCRIPTION: Do any prep work for region handling | ||
359 | * | ||
360 | * MUTEX: Assumes namespace is not locked | ||
361 | * | ||
362 | ******************************************************************************/ | ||
363 | |||
364 | acpi_status | ||
365 | acpi_ev_cmos_region_setup ( | ||
366 | acpi_handle handle, | ||
367 | u32 function, | ||
368 | void *handler_context, | ||
369 | void **region_context) | ||
370 | { | ||
371 | ACPI_FUNCTION_TRACE ("ev_cmos_region_setup"); | ||
372 | |||
373 | |||
374 | return_ACPI_STATUS (AE_OK); | ||
375 | } | ||
376 | |||
377 | |||
378 | /******************************************************************************* | ||
379 | * | ||
380 | * FUNCTION: acpi_ev_default_region_setup | ||
381 | * | ||
382 | * PARAMETERS: Handle - Region we are interested in | ||
383 | * Function - Start or stop | ||
384 | * handler_context - Address space handler context | ||
385 | * region_context - Region specific context | ||
386 | * | ||
387 | * RETURN: Status | ||
388 | * | ||
389 | * DESCRIPTION: Do any prep work for region handling | ||
390 | * | ||
391 | ******************************************************************************/ | ||
392 | |||
393 | acpi_status | ||
394 | acpi_ev_default_region_setup ( | ||
395 | acpi_handle handle, | ||
396 | u32 function, | ||
397 | void *handler_context, | ||
398 | void **region_context) | ||
399 | { | ||
400 | ACPI_FUNCTION_TRACE ("ev_default_region_setup"); | ||
401 | |||
402 | |||
403 | if (function == ACPI_REGION_DEACTIVATE) { | ||
404 | *region_context = NULL; | ||
405 | } | ||
406 | else { | ||
407 | *region_context = handler_context; | ||
408 | } | ||
409 | |||
410 | return_ACPI_STATUS (AE_OK); | ||
411 | } | ||
412 | |||
413 | |||
414 | /******************************************************************************* | ||
415 | * | ||
416 | * FUNCTION: acpi_ev_initialize_region | ||
417 | * | ||
418 | * PARAMETERS: region_obj - Region we are initializing | ||
419 | * acpi_ns_locked - Is namespace locked? | ||
420 | * | ||
421 | * RETURN: Status | ||
422 | * | ||
423 | * DESCRIPTION: Initializes the region, finds any _REG methods and saves them | ||
424 | * for execution at a later time | ||
425 | * | ||
426 | * Get the appropriate address space handler for a newly | ||
427 | * created region. | ||
428 | * | ||
429 | * This also performs address space specific initialization. For | ||
430 | * example, PCI regions must have an _ADR object that contains | ||
431 | * a PCI address in the scope of the definition. This address is | ||
432 | * required to perform an access to PCI config space. | ||
433 | * | ||
434 | ******************************************************************************/ | ||
435 | |||
436 | acpi_status | ||
437 | acpi_ev_initialize_region ( | ||
438 | union acpi_operand_object *region_obj, | ||
439 | u8 acpi_ns_locked) | ||
440 | { | ||
441 | union acpi_operand_object *handler_obj; | ||
442 | union acpi_operand_object *obj_desc; | ||
443 | acpi_adr_space_type space_id; | ||
444 | struct acpi_namespace_node *node; | ||
445 | acpi_status status; | ||
446 | struct acpi_namespace_node *method_node; | ||
447 | acpi_name *reg_name_ptr = (acpi_name *) METHOD_NAME__REG; | ||
448 | union acpi_operand_object *region_obj2; | ||
449 | |||
450 | |||
451 | ACPI_FUNCTION_TRACE_U32 ("ev_initialize_region", acpi_ns_locked); | ||
452 | |||
453 | |||
454 | if (!region_obj) { | ||
455 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
456 | } | ||
457 | |||
458 | if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) { | ||
459 | return_ACPI_STATUS (AE_OK); | ||
460 | } | ||
461 | |||
462 | region_obj2 = acpi_ns_get_secondary_object (region_obj); | ||
463 | if (!region_obj2) { | ||
464 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
465 | } | ||
466 | |||
467 | node = acpi_ns_get_parent_node (region_obj->region.node); | ||
468 | space_id = region_obj->region.space_id; | ||
469 | |||
470 | /* Setup defaults */ | ||
471 | |||
472 | region_obj->region.handler = NULL; | ||
473 | region_obj2->extra.method_REG = NULL; | ||
474 | region_obj->common.flags &= ~(AOPOBJ_SETUP_COMPLETE); | ||
475 | region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED; | ||
476 | |||
477 | /* Find any "_REG" method associated with this region definition */ | ||
478 | |||
479 | status = acpi_ns_search_node (*reg_name_ptr, node, | ||
480 | ACPI_TYPE_METHOD, &method_node); | ||
481 | if (ACPI_SUCCESS (status)) { | ||
482 | /* | ||
483 | * The _REG method is optional and there can be only one per region | ||
484 | * definition. This will be executed when the handler is attached | ||
485 | * or removed | ||
486 | */ | ||
487 | region_obj2->extra.method_REG = method_node; | ||
488 | } | ||
489 | |||
490 | /* | ||
491 | * The following loop depends upon the root Node having no parent | ||
492 | * ie: acpi_gbl_root_node->parent_entry being set to NULL | ||
493 | */ | ||
494 | while (node) { | ||
495 | /* Check to see if a handler exists */ | ||
496 | |||
497 | handler_obj = NULL; | ||
498 | obj_desc = acpi_ns_get_attached_object (node); | ||
499 | if (obj_desc) { | ||
500 | /* Can only be a handler if the object exists */ | ||
501 | |||
502 | switch (node->type) { | ||
503 | case ACPI_TYPE_DEVICE: | ||
504 | |||
505 | handler_obj = obj_desc->device.handler; | ||
506 | break; | ||
507 | |||
508 | case ACPI_TYPE_PROCESSOR: | ||
509 | |||
510 | handler_obj = obj_desc->processor.handler; | ||
511 | break; | ||
512 | |||
513 | case ACPI_TYPE_THERMAL: | ||
514 | |||
515 | handler_obj = obj_desc->thermal_zone.handler; | ||
516 | break; | ||
517 | |||
518 | default: | ||
519 | /* Ignore other objects */ | ||
520 | break; | ||
521 | } | ||
522 | |||
523 | while (handler_obj) { | ||
524 | /* Is this handler of the correct type? */ | ||
525 | |||
526 | if (handler_obj->address_space.space_id == space_id) { | ||
527 | /* Found correct handler */ | ||
528 | |||
529 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
530 | "Found handler %p for region %p in obj %p\n", | ||
531 | handler_obj, region_obj, obj_desc)); | ||
532 | |||
533 | status = acpi_ev_attach_region (handler_obj, region_obj, | ||
534 | acpi_ns_locked); | ||
535 | |||
536 | /* | ||
537 | * Tell all users that this region is usable by running the _REG | ||
538 | * method | ||
539 | */ | ||
540 | if (acpi_ns_locked) { | ||
541 | status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
542 | if (ACPI_FAILURE (status)) { | ||
543 | return_ACPI_STATUS (status); | ||
544 | } | ||
545 | } | ||
546 | |||
547 | status = acpi_ev_execute_reg_method (region_obj, 1); | ||
548 | |||
549 | if (acpi_ns_locked) { | ||
550 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
551 | if (ACPI_FAILURE (status)) { | ||
552 | return_ACPI_STATUS (status); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | return_ACPI_STATUS (AE_OK); | ||
557 | } | ||
558 | |||
559 | /* Try next handler in the list */ | ||
560 | |||
561 | handler_obj = handler_obj->address_space.next; | ||
562 | } | ||
563 | } | ||
564 | |||
565 | /* | ||
566 | * This node does not have the handler we need; | ||
567 | * Pop up one level | ||
568 | */ | ||
569 | node = acpi_ns_get_parent_node (node); | ||
570 | } | ||
571 | |||
572 | /* If we get here, there is no handler for this region */ | ||
573 | |||
574 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
575 | "No handler for region_type %s(%X) (region_obj %p)\n", | ||
576 | acpi_ut_get_region_name (space_id), space_id, region_obj)); | ||
577 | |||
578 | return_ACPI_STATUS (AE_NOT_EXIST); | ||
579 | } | ||
580 | |||
diff --git a/drivers/acpi/events/evsci.c b/drivers/acpi/events/evsci.c new file mode 100644 index 000000000000..46b31995c827 --- /dev/null +++ b/drivers/acpi/events/evsci.c | |||
@@ -0,0 +1,199 @@ | |||
1 | /******************************************************************************* | ||
2 | * | ||
3 | * Module Name: evsci - System Control Interrupt configuration and | ||
4 | * legacy to ACPI mode state transition functions | ||
5 | * | ||
6 | ******************************************************************************/ | ||
7 | |||
8 | /* | ||
9 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
10 | * All rights reserved. | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions, and the following disclaimer, | ||
17 | * without modification. | ||
18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
19 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
20 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
21 | * including a substantially similar Disclaimer requirement for further | ||
22 | * binary redistribution. | ||
23 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
24 | * of any contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * Alternatively, this software may be distributed under the terms of the | ||
28 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
29 | * Software Foundation. | ||
30 | * | ||
31 | * NO WARRANTY | ||
32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
42 | * POSSIBILITY OF SUCH DAMAGES. | ||
43 | */ | ||
44 | |||
45 | #include <acpi/acpi.h> | ||
46 | #include <acpi/acevents.h> | ||
47 | |||
48 | |||
49 | #define _COMPONENT ACPI_EVENTS | ||
50 | ACPI_MODULE_NAME ("evsci") | ||
51 | |||
52 | |||
53 | /******************************************************************************* | ||
54 | * | ||
55 | * FUNCTION: acpi_ev_sci_xrupt_handler | ||
56 | * | ||
57 | * PARAMETERS: Context - Calling Context | ||
58 | * | ||
59 | * RETURN: Status code indicates whether interrupt was handled. | ||
60 | * | ||
61 | * DESCRIPTION: Interrupt handler that will figure out what function or | ||
62 | * control method to call to deal with a SCI. | ||
63 | * | ||
64 | ******************************************************************************/ | ||
65 | |||
66 | static u32 ACPI_SYSTEM_XFACE | ||
67 | acpi_ev_sci_xrupt_handler ( | ||
68 | void *context) | ||
69 | { | ||
70 | struct acpi_gpe_xrupt_info *gpe_xrupt_list = context; | ||
71 | u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED; | ||
72 | |||
73 | |||
74 | ACPI_FUNCTION_TRACE("ev_sci_xrupt_handler"); | ||
75 | |||
76 | |||
77 | /* | ||
78 | * We are guaranteed by the ACPI CA initialization/shutdown code that | ||
79 | * if this interrupt handler is installed, ACPI is enabled. | ||
80 | */ | ||
81 | |||
82 | /* | ||
83 | * Fixed Events: | ||
84 | * Check for and dispatch any Fixed Events that have occurred | ||
85 | */ | ||
86 | interrupt_handled |= acpi_ev_fixed_event_detect (); | ||
87 | |||
88 | /* | ||
89 | * General Purpose Events: | ||
90 | * Check for and dispatch any GPEs that have occurred | ||
91 | */ | ||
92 | interrupt_handled |= acpi_ev_gpe_detect (gpe_xrupt_list); | ||
93 | |||
94 | return_VALUE (interrupt_handled); | ||
95 | } | ||
96 | |||
97 | |||
98 | /******************************************************************************* | ||
99 | * | ||
100 | * FUNCTION: acpi_ev_gpe_xrupt_handler | ||
101 | * | ||
102 | * PARAMETERS: Context - Calling Context | ||
103 | * | ||
104 | * RETURN: Status code indicates whether interrupt was handled. | ||
105 | * | ||
106 | * DESCRIPTION: Handler for GPE Block Device interrupts | ||
107 | * | ||
108 | ******************************************************************************/ | ||
109 | |||
110 | u32 ACPI_SYSTEM_XFACE | ||
111 | acpi_ev_gpe_xrupt_handler ( | ||
112 | void *context) | ||
113 | { | ||
114 | struct acpi_gpe_xrupt_info *gpe_xrupt_list = context; | ||
115 | u32 interrupt_handled = ACPI_INTERRUPT_NOT_HANDLED; | ||
116 | |||
117 | |||
118 | ACPI_FUNCTION_TRACE("ev_gpe_xrupt_handler"); | ||
119 | |||
120 | |||
121 | /* | ||
122 | * We are guaranteed by the ACPI CA initialization/shutdown code that | ||
123 | * if this interrupt handler is installed, ACPI is enabled. | ||
124 | */ | ||
125 | |||
126 | /* | ||
127 | * GPEs: | ||
128 | * Check for and dispatch any GPEs that have occurred | ||
129 | */ | ||
130 | interrupt_handled |= acpi_ev_gpe_detect (gpe_xrupt_list); | ||
131 | |||
132 | return_VALUE (interrupt_handled); | ||
133 | } | ||
134 | |||
135 | |||
136 | /****************************************************************************** | ||
137 | * | ||
138 | * FUNCTION: acpi_ev_install_sci_handler | ||
139 | * | ||
140 | * PARAMETERS: none | ||
141 | * | ||
142 | * RETURN: Status | ||
143 | * | ||
144 | * DESCRIPTION: Installs SCI handler. | ||
145 | * | ||
146 | ******************************************************************************/ | ||
147 | |||
148 | u32 | ||
149 | acpi_ev_install_sci_handler (void) | ||
150 | { | ||
151 | u32 status = AE_OK; | ||
152 | |||
153 | |||
154 | ACPI_FUNCTION_TRACE ("ev_install_sci_handler"); | ||
155 | |||
156 | |||
157 | status = acpi_os_install_interrupt_handler ((u32) acpi_gbl_FADT->sci_int, | ||
158 | acpi_ev_sci_xrupt_handler, acpi_gbl_gpe_xrupt_list_head); | ||
159 | return_ACPI_STATUS (status); | ||
160 | } | ||
161 | |||
162 | |||
163 | /****************************************************************************** | ||
164 | * | ||
165 | * FUNCTION: acpi_ev_remove_sci_handler | ||
166 | * | ||
167 | * PARAMETERS: none | ||
168 | * | ||
169 | * RETURN: E_OK if handler uninstalled OK, E_ERROR if handler was not | ||
170 | * installed to begin with | ||
171 | * | ||
172 | * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be | ||
173 | * taken. | ||
174 | * | ||
175 | * Note: It doesn't seem important to disable all events or set the event | ||
176 | * enable registers to their original values. The OS should disable | ||
177 | * the SCI interrupt level when the handler is removed, so no more | ||
178 | * events will come in. | ||
179 | * | ||
180 | ******************************************************************************/ | ||
181 | |||
182 | acpi_status | ||
183 | acpi_ev_remove_sci_handler (void) | ||
184 | { | ||
185 | acpi_status status; | ||
186 | |||
187 | |||
188 | ACPI_FUNCTION_TRACE ("ev_remove_sci_handler"); | ||
189 | |||
190 | |||
191 | /* Just let the OS remove the handler and disable the level */ | ||
192 | |||
193 | status = acpi_os_remove_interrupt_handler ((u32) acpi_gbl_FADT->sci_int, | ||
194 | acpi_ev_sci_xrupt_handler); | ||
195 | |||
196 | return_ACPI_STATUS (status); | ||
197 | } | ||
198 | |||
199 | |||
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c new file mode 100644 index 000000000000..0bfec10a5f1e --- /dev/null +++ b/drivers/acpi/events/evxface.c | |||
@@ -0,0 +1,834 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evxface - External interfaces for ACPI events | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | #include <linux/module.h> | ||
45 | |||
46 | #include <acpi/acpi.h> | ||
47 | #include <acpi/acnamesp.h> | ||
48 | #include <acpi/acevents.h> | ||
49 | #include <acpi/acinterp.h> | ||
50 | |||
51 | #define _COMPONENT ACPI_EVENTS | ||
52 | ACPI_MODULE_NAME ("evxface") | ||
53 | |||
54 | |||
55 | /******************************************************************************* | ||
56 | * | ||
57 | * FUNCTION: acpi_install_exception_handler | ||
58 | * | ||
59 | * PARAMETERS: Handler - Pointer to the handler function for the | ||
60 | * event | ||
61 | * | ||
62 | * RETURN: Status | ||
63 | * | ||
64 | * DESCRIPTION: Saves the pointer to the handler function | ||
65 | * | ||
66 | ******************************************************************************/ | ||
67 | #ifdef ACPI_FUTURE_USAGE | ||
68 | acpi_status | ||
69 | acpi_install_exception_handler ( | ||
70 | acpi_exception_handler handler) | ||
71 | { | ||
72 | acpi_status status; | ||
73 | |||
74 | |||
75 | ACPI_FUNCTION_TRACE ("acpi_install_exception_handler"); | ||
76 | |||
77 | |||
78 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
79 | if (ACPI_FAILURE (status)) { | ||
80 | return_ACPI_STATUS (status); | ||
81 | } | ||
82 | |||
83 | /* Don't allow two handlers. */ | ||
84 | |||
85 | if (acpi_gbl_exception_handler) { | ||
86 | status = AE_ALREADY_EXISTS; | ||
87 | goto cleanup; | ||
88 | } | ||
89 | |||
90 | /* Install the handler */ | ||
91 | |||
92 | acpi_gbl_exception_handler = handler; | ||
93 | |||
94 | cleanup: | ||
95 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
96 | return_ACPI_STATUS (status); | ||
97 | } | ||
98 | #endif /* ACPI_FUTURE_USAGE */ | ||
99 | |||
100 | |||
101 | /******************************************************************************* | ||
102 | * | ||
103 | * FUNCTION: acpi_install_fixed_event_handler | ||
104 | * | ||
105 | * PARAMETERS: Event - Event type to enable. | ||
106 | * Handler - Pointer to the handler function for the | ||
107 | * event | ||
108 | * Context - Value passed to the handler on each GPE | ||
109 | * | ||
110 | * RETURN: Status | ||
111 | * | ||
112 | * DESCRIPTION: Saves the pointer to the handler function and then enables the | ||
113 | * event. | ||
114 | * | ||
115 | ******************************************************************************/ | ||
116 | |||
117 | acpi_status | ||
118 | acpi_install_fixed_event_handler ( | ||
119 | u32 event, | ||
120 | acpi_event_handler handler, | ||
121 | void *context) | ||
122 | { | ||
123 | acpi_status status; | ||
124 | |||
125 | |||
126 | ACPI_FUNCTION_TRACE ("acpi_install_fixed_event_handler"); | ||
127 | |||
128 | |||
129 | /* Parameter validation */ | ||
130 | |||
131 | if (event > ACPI_EVENT_MAX) { | ||
132 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
133 | } | ||
134 | |||
135 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
136 | if (ACPI_FAILURE (status)) { | ||
137 | return_ACPI_STATUS (status); | ||
138 | } | ||
139 | |||
140 | /* Don't allow two handlers. */ | ||
141 | |||
142 | if (NULL != acpi_gbl_fixed_event_handlers[event].handler) { | ||
143 | status = AE_ALREADY_EXISTS; | ||
144 | goto cleanup; | ||
145 | } | ||
146 | |||
147 | /* Install the handler before enabling the event */ | ||
148 | |||
149 | acpi_gbl_fixed_event_handlers[event].handler = handler; | ||
150 | acpi_gbl_fixed_event_handlers[event].context = context; | ||
151 | |||
152 | status = acpi_clear_event (event); | ||
153 | if (ACPI_SUCCESS(status)) | ||
154 | status = acpi_enable_event (event, 0); | ||
155 | if (ACPI_FAILURE (status)) { | ||
156 | ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Could not enable fixed event.\n")); | ||
157 | |||
158 | /* Remove the handler */ | ||
159 | |||
160 | acpi_gbl_fixed_event_handlers[event].handler = NULL; | ||
161 | acpi_gbl_fixed_event_handlers[event].context = NULL; | ||
162 | } | ||
163 | else { | ||
164 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | ||
165 | "Enabled fixed event %X, Handler=%p\n", event, handler)); | ||
166 | } | ||
167 | |||
168 | |||
169 | cleanup: | ||
170 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
171 | return_ACPI_STATUS (status); | ||
172 | } | ||
173 | EXPORT_SYMBOL(acpi_install_fixed_event_handler); | ||
174 | |||
175 | |||
176 | /******************************************************************************* | ||
177 | * | ||
178 | * FUNCTION: acpi_remove_fixed_event_handler | ||
179 | * | ||
180 | * PARAMETERS: Event - Event type to disable. | ||
181 | * Handler - Address of the handler | ||
182 | * | ||
183 | * RETURN: Status | ||
184 | * | ||
185 | * DESCRIPTION: Disables the event and unregisters the event handler. | ||
186 | * | ||
187 | ******************************************************************************/ | ||
188 | |||
189 | acpi_status | ||
190 | acpi_remove_fixed_event_handler ( | ||
191 | u32 event, | ||
192 | acpi_event_handler handler) | ||
193 | { | ||
194 | acpi_status status = AE_OK; | ||
195 | |||
196 | |||
197 | ACPI_FUNCTION_TRACE ("acpi_remove_fixed_event_handler"); | ||
198 | |||
199 | |||
200 | /* Parameter validation */ | ||
201 | |||
202 | if (event > ACPI_EVENT_MAX) { | ||
203 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
204 | } | ||
205 | |||
206 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
207 | if (ACPI_FAILURE (status)) { | ||
208 | return_ACPI_STATUS (status); | ||
209 | } | ||
210 | |||
211 | /* Disable the event before removing the handler */ | ||
212 | |||
213 | status = acpi_disable_event (event, 0); | ||
214 | |||
215 | /* Always Remove the handler */ | ||
216 | |||
217 | acpi_gbl_fixed_event_handlers[event].handler = NULL; | ||
218 | acpi_gbl_fixed_event_handlers[event].context = NULL; | ||
219 | |||
220 | if (ACPI_FAILURE (status)) { | ||
221 | ACPI_DEBUG_PRINT ((ACPI_DB_WARN, | ||
222 | "Could not write to fixed event enable register.\n")); | ||
223 | } | ||
224 | else { | ||
225 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Disabled fixed event %X.\n", event)); | ||
226 | } | ||
227 | |||
228 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
229 | return_ACPI_STATUS (status); | ||
230 | } | ||
231 | EXPORT_SYMBOL(acpi_remove_fixed_event_handler); | ||
232 | |||
233 | |||
234 | /******************************************************************************* | ||
235 | * | ||
236 | * FUNCTION: acpi_install_notify_handler | ||
237 | * | ||
238 | * PARAMETERS: Device - The device for which notifies will be handled | ||
239 | * handler_type - The type of handler: | ||
240 | * ACPI_SYSTEM_NOTIFY: system_handler (00-7f) | ||
241 | * ACPI_DEVICE_NOTIFY: driver_handler (80-ff) | ||
242 | * ACPI_ALL_NOTIFY: both system and device | ||
243 | * Handler - Address of the handler | ||
244 | * Context - Value passed to the handler on each GPE | ||
245 | * | ||
246 | * RETURN: Status | ||
247 | * | ||
248 | * DESCRIPTION: Install a handler for notifies on an ACPI device | ||
249 | * | ||
250 | ******************************************************************************/ | ||
251 | |||
252 | acpi_status | ||
253 | acpi_install_notify_handler ( | ||
254 | acpi_handle device, | ||
255 | u32 handler_type, | ||
256 | acpi_notify_handler handler, | ||
257 | void *context) | ||
258 | { | ||
259 | union acpi_operand_object *obj_desc; | ||
260 | union acpi_operand_object *notify_obj; | ||
261 | struct acpi_namespace_node *node; | ||
262 | acpi_status status; | ||
263 | |||
264 | |||
265 | ACPI_FUNCTION_TRACE ("acpi_install_notify_handler"); | ||
266 | |||
267 | |||
268 | /* Parameter validation */ | ||
269 | |||
270 | if ((!device) || | ||
271 | (!handler) || | ||
272 | (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | ||
273 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
274 | } | ||
275 | |||
276 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
277 | if (ACPI_FAILURE (status)) { | ||
278 | return_ACPI_STATUS (status); | ||
279 | } | ||
280 | |||
281 | /* Convert and validate the device handle */ | ||
282 | |||
283 | node = acpi_ns_map_handle_to_node (device); | ||
284 | if (!node) { | ||
285 | status = AE_BAD_PARAMETER; | ||
286 | goto unlock_and_exit; | ||
287 | } | ||
288 | |||
289 | /* | ||
290 | * Root Object: | ||
291 | * Registering a notify handler on the root object indicates that the | ||
292 | * caller wishes to receive notifications for all objects. Note that | ||
293 | * only one <external> global handler can be regsitered (per notify type). | ||
294 | */ | ||
295 | if (device == ACPI_ROOT_OBJECT) { | ||
296 | /* Make sure the handler is not already installed */ | ||
297 | |||
298 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | ||
299 | acpi_gbl_system_notify.handler) || | ||
300 | ((handler_type & ACPI_DEVICE_NOTIFY) && | ||
301 | acpi_gbl_device_notify.handler)) { | ||
302 | status = AE_ALREADY_EXISTS; | ||
303 | goto unlock_and_exit; | ||
304 | } | ||
305 | |||
306 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | ||
307 | acpi_gbl_system_notify.node = node; | ||
308 | acpi_gbl_system_notify.handler = handler; | ||
309 | acpi_gbl_system_notify.context = context; | ||
310 | } | ||
311 | |||
312 | if (handler_type & ACPI_DEVICE_NOTIFY) { | ||
313 | acpi_gbl_device_notify.node = node; | ||
314 | acpi_gbl_device_notify.handler = handler; | ||
315 | acpi_gbl_device_notify.context = context; | ||
316 | } | ||
317 | |||
318 | /* Global notify handler installed */ | ||
319 | } | ||
320 | |||
321 | /* | ||
322 | * All Other Objects: | ||
323 | * Caller will only receive notifications specific to the target object. | ||
324 | * Note that only certain object types can receive notifications. | ||
325 | */ | ||
326 | else { | ||
327 | /* Notifies allowed on this object? */ | ||
328 | |||
329 | if (!acpi_ev_is_notify_object (node)) { | ||
330 | status = AE_TYPE; | ||
331 | goto unlock_and_exit; | ||
332 | } | ||
333 | |||
334 | /* Check for an existing internal object */ | ||
335 | |||
336 | obj_desc = acpi_ns_get_attached_object (node); | ||
337 | if (obj_desc) { | ||
338 | /* Object exists - make sure there's no handler */ | ||
339 | |||
340 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | ||
341 | obj_desc->common_notify.system_notify) || | ||
342 | ((handler_type & ACPI_DEVICE_NOTIFY) && | ||
343 | obj_desc->common_notify.device_notify)) { | ||
344 | status = AE_ALREADY_EXISTS; | ||
345 | goto unlock_and_exit; | ||
346 | } | ||
347 | } | ||
348 | else { | ||
349 | /* Create a new object */ | ||
350 | |||
351 | obj_desc = acpi_ut_create_internal_object (node->type); | ||
352 | if (!obj_desc) { | ||
353 | status = AE_NO_MEMORY; | ||
354 | goto unlock_and_exit; | ||
355 | } | ||
356 | |||
357 | /* Attach new object to the Node */ | ||
358 | |||
359 | status = acpi_ns_attach_object (device, obj_desc, node->type); | ||
360 | |||
361 | /* Remove local reference to the object */ | ||
362 | |||
363 | acpi_ut_remove_reference (obj_desc); | ||
364 | if (ACPI_FAILURE (status)) { | ||
365 | goto unlock_and_exit; | ||
366 | } | ||
367 | } | ||
368 | |||
369 | /* Install the handler */ | ||
370 | |||
371 | notify_obj = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_NOTIFY); | ||
372 | if (!notify_obj) { | ||
373 | status = AE_NO_MEMORY; | ||
374 | goto unlock_and_exit; | ||
375 | } | ||
376 | |||
377 | notify_obj->notify.node = node; | ||
378 | notify_obj->notify.handler = handler; | ||
379 | notify_obj->notify.context = context; | ||
380 | |||
381 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | ||
382 | obj_desc->common_notify.system_notify = notify_obj; | ||
383 | } | ||
384 | |||
385 | if (handler_type & ACPI_DEVICE_NOTIFY) { | ||
386 | obj_desc->common_notify.device_notify = notify_obj; | ||
387 | } | ||
388 | |||
389 | if (handler_type == ACPI_ALL_NOTIFY) { | ||
390 | /* Extra ref if installed in both */ | ||
391 | |||
392 | acpi_ut_add_reference (notify_obj); | ||
393 | } | ||
394 | } | ||
395 | |||
396 | |||
397 | unlock_and_exit: | ||
398 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
399 | return_ACPI_STATUS (status); | ||
400 | } | ||
401 | EXPORT_SYMBOL(acpi_install_notify_handler); | ||
402 | |||
403 | |||
404 | /******************************************************************************* | ||
405 | * | ||
406 | * FUNCTION: acpi_remove_notify_handler | ||
407 | * | ||
408 | * PARAMETERS: Device - The device for which notifies will be handled | ||
409 | * handler_type - The type of handler: | ||
410 | * ACPI_SYSTEM_NOTIFY: system_handler (00-7f) | ||
411 | * ACPI_DEVICE_NOTIFY: driver_handler (80-ff) | ||
412 | * ACPI_ALL_NOTIFY: both system and device | ||
413 | * Handler - Address of the handler | ||
414 | * | ||
415 | * RETURN: Status | ||
416 | * | ||
417 | * DESCRIPTION: Remove a handler for notifies on an ACPI device | ||
418 | * | ||
419 | ******************************************************************************/ | ||
420 | |||
421 | acpi_status | ||
422 | acpi_remove_notify_handler ( | ||
423 | acpi_handle device, | ||
424 | u32 handler_type, | ||
425 | acpi_notify_handler handler) | ||
426 | { | ||
427 | union acpi_operand_object *notify_obj; | ||
428 | union acpi_operand_object *obj_desc; | ||
429 | struct acpi_namespace_node *node; | ||
430 | acpi_status status; | ||
431 | |||
432 | |||
433 | ACPI_FUNCTION_TRACE ("acpi_remove_notify_handler"); | ||
434 | |||
435 | |||
436 | /* Parameter validation */ | ||
437 | |||
438 | if ((!device) || | ||
439 | (!handler) || | ||
440 | (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | ||
441 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
442 | } | ||
443 | |||
444 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
445 | if (ACPI_FAILURE (status)) { | ||
446 | return_ACPI_STATUS (status); | ||
447 | } | ||
448 | |||
449 | /* Convert and validate the device handle */ | ||
450 | |||
451 | node = acpi_ns_map_handle_to_node (device); | ||
452 | if (!node) { | ||
453 | status = AE_BAD_PARAMETER; | ||
454 | goto unlock_and_exit; | ||
455 | } | ||
456 | |||
457 | /* Root Object */ | ||
458 | |||
459 | if (device == ACPI_ROOT_OBJECT) { | ||
460 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing notify handler for ROOT object.\n")); | ||
461 | |||
462 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | ||
463 | !acpi_gbl_system_notify.handler) || | ||
464 | ((handler_type & ACPI_DEVICE_NOTIFY) && | ||
465 | !acpi_gbl_device_notify.handler)) { | ||
466 | status = AE_NOT_EXIST; | ||
467 | goto unlock_and_exit; | ||
468 | } | ||
469 | |||
470 | /* Make sure all deferred tasks are completed */ | ||
471 | |||
472 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
473 | acpi_os_wait_events_complete(NULL); | ||
474 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
475 | if (ACPI_FAILURE (status)) { | ||
476 | return_ACPI_STATUS (status); | ||
477 | } | ||
478 | |||
479 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | ||
480 | acpi_gbl_system_notify.node = NULL; | ||
481 | acpi_gbl_system_notify.handler = NULL; | ||
482 | acpi_gbl_system_notify.context = NULL; | ||
483 | } | ||
484 | |||
485 | if (handler_type & ACPI_DEVICE_NOTIFY) { | ||
486 | acpi_gbl_device_notify.node = NULL; | ||
487 | acpi_gbl_device_notify.handler = NULL; | ||
488 | acpi_gbl_device_notify.context = NULL; | ||
489 | } | ||
490 | } | ||
491 | |||
492 | /* All Other Objects */ | ||
493 | |||
494 | else { | ||
495 | /* Notifies allowed on this object? */ | ||
496 | |||
497 | if (!acpi_ev_is_notify_object (node)) { | ||
498 | status = AE_TYPE; | ||
499 | goto unlock_and_exit; | ||
500 | } | ||
501 | |||
502 | /* Check for an existing internal object */ | ||
503 | |||
504 | obj_desc = acpi_ns_get_attached_object (node); | ||
505 | if (!obj_desc) { | ||
506 | status = AE_NOT_EXIST; | ||
507 | goto unlock_and_exit; | ||
508 | } | ||
509 | |||
510 | /* Object exists - make sure there's an existing handler */ | ||
511 | |||
512 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | ||
513 | notify_obj = obj_desc->common_notify.system_notify; | ||
514 | if ((!notify_obj) || | ||
515 | (notify_obj->notify.handler != handler)) { | ||
516 | status = AE_BAD_PARAMETER; | ||
517 | goto unlock_and_exit; | ||
518 | } | ||
519 | /* Make sure all deferred tasks are completed */ | ||
520 | |||
521 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
522 | acpi_os_wait_events_complete(NULL); | ||
523 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
524 | if (ACPI_FAILURE (status)) { | ||
525 | return_ACPI_STATUS (status); | ||
526 | } | ||
527 | |||
528 | /* Remove the handler */ | ||
529 | obj_desc->common_notify.system_notify = NULL; | ||
530 | acpi_ut_remove_reference (notify_obj); | ||
531 | } | ||
532 | |||
533 | if (handler_type & ACPI_DEVICE_NOTIFY) { | ||
534 | notify_obj = obj_desc->common_notify.device_notify; | ||
535 | if ((!notify_obj) || | ||
536 | (notify_obj->notify.handler != handler)) { | ||
537 | status = AE_BAD_PARAMETER; | ||
538 | goto unlock_and_exit; | ||
539 | } | ||
540 | /* Make sure all deferred tasks are completed */ | ||
541 | |||
542 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
543 | acpi_os_wait_events_complete(NULL); | ||
544 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
545 | if (ACPI_FAILURE (status)) { | ||
546 | return_ACPI_STATUS (status); | ||
547 | } | ||
548 | |||
549 | /* Remove the handler */ | ||
550 | obj_desc->common_notify.device_notify = NULL; | ||
551 | acpi_ut_remove_reference (notify_obj); | ||
552 | } | ||
553 | } | ||
554 | |||
555 | |||
556 | unlock_and_exit: | ||
557 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
558 | return_ACPI_STATUS (status); | ||
559 | } | ||
560 | EXPORT_SYMBOL(acpi_remove_notify_handler); | ||
561 | |||
562 | |||
563 | /******************************************************************************* | ||
564 | * | ||
565 | * FUNCTION: acpi_install_gpe_handler | ||
566 | * | ||
567 | * PARAMETERS: gpe_number - The GPE number within the GPE block | ||
568 | * gpe_block - GPE block (NULL == FADT GPEs) | ||
569 | * Type - Whether this GPE should be treated as an | ||
570 | * edge- or level-triggered interrupt. | ||
571 | * Address - Address of the handler | ||
572 | * Context - Value passed to the handler on each GPE | ||
573 | * | ||
574 | * RETURN: Status | ||
575 | * | ||
576 | * DESCRIPTION: Install a handler for a General Purpose Event. | ||
577 | * | ||
578 | ******************************************************************************/ | ||
579 | |||
580 | acpi_status | ||
581 | acpi_install_gpe_handler ( | ||
582 | acpi_handle gpe_device, | ||
583 | u32 gpe_number, | ||
584 | u32 type, | ||
585 | acpi_event_handler address, | ||
586 | void *context) | ||
587 | { | ||
588 | struct acpi_gpe_event_info *gpe_event_info; | ||
589 | struct acpi_handler_info *handler; | ||
590 | acpi_status status; | ||
591 | |||
592 | |||
593 | ACPI_FUNCTION_TRACE ("acpi_install_gpe_handler"); | ||
594 | |||
595 | |||
596 | /* Parameter validation */ | ||
597 | |||
598 | if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) { | ||
599 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
600 | } | ||
601 | |||
602 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
603 | if (ACPI_FAILURE (status)) { | ||
604 | return_ACPI_STATUS (status); | ||
605 | } | ||
606 | |||
607 | /* Ensure that we have a valid GPE number */ | ||
608 | |||
609 | gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number); | ||
610 | if (!gpe_event_info) { | ||
611 | status = AE_BAD_PARAMETER; | ||
612 | goto unlock_and_exit; | ||
613 | } | ||
614 | |||
615 | /* Make sure that there isn't a handler there already */ | ||
616 | |||
617 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) { | ||
618 | status = AE_ALREADY_EXISTS; | ||
619 | goto unlock_and_exit; | ||
620 | } | ||
621 | |||
622 | /* Allocate and init handler object */ | ||
623 | |||
624 | handler = ACPI_MEM_CALLOCATE (sizeof (struct acpi_handler_info)); | ||
625 | if (!handler) { | ||
626 | status = AE_NO_MEMORY; | ||
627 | goto unlock_and_exit; | ||
628 | } | ||
629 | |||
630 | handler->address = address; | ||
631 | handler->context = context; | ||
632 | handler->method_node = gpe_event_info->dispatch.method_node; | ||
633 | |||
634 | /* Disable the GPE before installing the handler */ | ||
635 | |||
636 | status = acpi_ev_disable_gpe (gpe_event_info); | ||
637 | if (ACPI_FAILURE (status)) { | ||
638 | goto unlock_and_exit; | ||
639 | } | ||
640 | |||
641 | /* Install the handler */ | ||
642 | |||
643 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
644 | gpe_event_info->dispatch.handler = handler; | ||
645 | |||
646 | /* Setup up dispatch flags to indicate handler (vs. method) */ | ||
647 | |||
648 | gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */ | ||
649 | gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER); | ||
650 | |||
651 | acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
652 | |||
653 | |||
654 | unlock_and_exit: | ||
655 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
656 | return_ACPI_STATUS (status); | ||
657 | } | ||
658 | EXPORT_SYMBOL(acpi_install_gpe_handler); | ||
659 | |||
660 | |||
661 | /******************************************************************************* | ||
662 | * | ||
663 | * FUNCTION: acpi_remove_gpe_handler | ||
664 | * | ||
665 | * PARAMETERS: gpe_number - The event to remove a handler | ||
666 | * gpe_block - GPE block (NULL == FADT GPEs) | ||
667 | * Address - Address of the handler | ||
668 | * | ||
669 | * RETURN: Status | ||
670 | * | ||
671 | * DESCRIPTION: Remove a handler for a General Purpose acpi_event. | ||
672 | * | ||
673 | ******************************************************************************/ | ||
674 | |||
675 | acpi_status | ||
676 | acpi_remove_gpe_handler ( | ||
677 | acpi_handle gpe_device, | ||
678 | u32 gpe_number, | ||
679 | acpi_event_handler address) | ||
680 | { | ||
681 | struct acpi_gpe_event_info *gpe_event_info; | ||
682 | struct acpi_handler_info *handler; | ||
683 | acpi_status status; | ||
684 | |||
685 | |||
686 | ACPI_FUNCTION_TRACE ("acpi_remove_gpe_handler"); | ||
687 | |||
688 | |||
689 | /* Parameter validation */ | ||
690 | |||
691 | if (!address) { | ||
692 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
693 | } | ||
694 | |||
695 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
696 | if (ACPI_FAILURE (status)) { | ||
697 | return_ACPI_STATUS (status); | ||
698 | } | ||
699 | |||
700 | /* Ensure that we have a valid GPE number */ | ||
701 | |||
702 | gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number); | ||
703 | if (!gpe_event_info) { | ||
704 | status = AE_BAD_PARAMETER; | ||
705 | goto unlock_and_exit; | ||
706 | } | ||
707 | |||
708 | /* Make sure that a handler is indeed installed */ | ||
709 | |||
710 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) != ACPI_GPE_DISPATCH_HANDLER) { | ||
711 | status = AE_NOT_EXIST; | ||
712 | goto unlock_and_exit; | ||
713 | } | ||
714 | |||
715 | /* Make sure that the installed handler is the same */ | ||
716 | |||
717 | if (gpe_event_info->dispatch.handler->address != address) { | ||
718 | status = AE_BAD_PARAMETER; | ||
719 | goto unlock_and_exit; | ||
720 | } | ||
721 | |||
722 | /* Disable the GPE before removing the handler */ | ||
723 | |||
724 | status = acpi_ev_disable_gpe (gpe_event_info); | ||
725 | if (ACPI_FAILURE (status)) { | ||
726 | goto unlock_and_exit; | ||
727 | } | ||
728 | |||
729 | /* Make sure all deferred tasks are completed */ | ||
730 | |||
731 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
732 | acpi_os_wait_events_complete(NULL); | ||
733 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
734 | if (ACPI_FAILURE (status)) { | ||
735 | return_ACPI_STATUS (status); | ||
736 | } | ||
737 | |||
738 | /* Remove the handler */ | ||
739 | |||
740 | acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
741 | handler = gpe_event_info->dispatch.handler; | ||
742 | |||
743 | /* Restore Method node (if any), set dispatch flags */ | ||
744 | |||
745 | gpe_event_info->dispatch.method_node = handler->method_node; | ||
746 | gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */ | ||
747 | if (handler->method_node) { | ||
748 | gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD; | ||
749 | } | ||
750 | acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); | ||
751 | |||
752 | /* Now we can free the handler object */ | ||
753 | |||
754 | ACPI_MEM_FREE (handler); | ||
755 | |||
756 | |||
757 | unlock_and_exit: | ||
758 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
759 | return_ACPI_STATUS (status); | ||
760 | } | ||
761 | EXPORT_SYMBOL(acpi_remove_gpe_handler); | ||
762 | |||
763 | |||
764 | /******************************************************************************* | ||
765 | * | ||
766 | * FUNCTION: acpi_acquire_global_lock | ||
767 | * | ||
768 | * PARAMETERS: Timeout - How long the caller is willing to wait | ||
769 | * out_handle - A handle to the lock if acquired | ||
770 | * | ||
771 | * RETURN: Status | ||
772 | * | ||
773 | * DESCRIPTION: Acquire the ACPI Global Lock | ||
774 | * | ||
775 | ******************************************************************************/ | ||
776 | |||
777 | acpi_status | ||
778 | acpi_acquire_global_lock ( | ||
779 | u16 timeout, | ||
780 | u32 *handle) | ||
781 | { | ||
782 | acpi_status status; | ||
783 | |||
784 | |||
785 | if (!handle) { | ||
786 | return (AE_BAD_PARAMETER); | ||
787 | } | ||
788 | |||
789 | status = acpi_ex_enter_interpreter (); | ||
790 | if (ACPI_FAILURE (status)) { | ||
791 | return (status); | ||
792 | } | ||
793 | |||
794 | status = acpi_ev_acquire_global_lock (timeout); | ||
795 | acpi_ex_exit_interpreter (); | ||
796 | |||
797 | if (ACPI_SUCCESS (status)) { | ||
798 | acpi_gbl_global_lock_handle++; | ||
799 | *handle = acpi_gbl_global_lock_handle; | ||
800 | } | ||
801 | |||
802 | return (status); | ||
803 | } | ||
804 | EXPORT_SYMBOL(acpi_acquire_global_lock); | ||
805 | |||
806 | |||
807 | /******************************************************************************* | ||
808 | * | ||
809 | * FUNCTION: acpi_release_global_lock | ||
810 | * | ||
811 | * PARAMETERS: Handle - Returned from acpi_acquire_global_lock | ||
812 | * | ||
813 | * RETURN: Status | ||
814 | * | ||
815 | * DESCRIPTION: Release the ACPI Global Lock | ||
816 | * | ||
817 | ******************************************************************************/ | ||
818 | |||
819 | acpi_status | ||
820 | acpi_release_global_lock ( | ||
821 | u32 handle) | ||
822 | { | ||
823 | acpi_status status; | ||
824 | |||
825 | |||
826 | if (handle != acpi_gbl_global_lock_handle) { | ||
827 | return (AE_NOT_ACQUIRED); | ||
828 | } | ||
829 | |||
830 | status = acpi_ev_release_global_lock (); | ||
831 | return (status); | ||
832 | } | ||
833 | EXPORT_SYMBOL(acpi_release_global_lock); | ||
834 | |||
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c new file mode 100644 index 000000000000..fa8d5f25be62 --- /dev/null +++ b/drivers/acpi/events/evxfevnt.c | |||
@@ -0,0 +1,778 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | #include <linux/module.h> | ||
45 | |||
46 | #include <acpi/acpi.h> | ||
47 | #include <acpi/acevents.h> | ||
48 | #include <acpi/acnamesp.h> | ||
49 | |||
50 | #define _COMPONENT ACPI_EVENTS | ||
51 | ACPI_MODULE_NAME ("evxfevnt") | ||
52 | |||
53 | |||
54 | /******************************************************************************* | ||
55 | * | ||
56 | * FUNCTION: acpi_enable | ||
57 | * | ||
58 | * PARAMETERS: None | ||
59 | * | ||
60 | * RETURN: Status | ||
61 | * | ||
62 | * DESCRIPTION: Transfers the system into ACPI mode. | ||
63 | * | ||
64 | ******************************************************************************/ | ||
65 | |||
66 | acpi_status | ||
67 | acpi_enable (void) | ||
68 | { | ||
69 | acpi_status status = AE_OK; | ||
70 | |||
71 | |||
72 | ACPI_FUNCTION_TRACE ("acpi_enable"); | ||
73 | |||
74 | |||
75 | /* Make sure we have the FADT*/ | ||
76 | |||
77 | if (!acpi_gbl_FADT) { | ||
78 | ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n")); | ||
79 | return_ACPI_STATUS (AE_NO_ACPI_TABLES); | ||
80 | } | ||
81 | |||
82 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) { | ||
83 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n")); | ||
84 | } | ||
85 | else { | ||
86 | /* Transition to ACPI mode */ | ||
87 | |||
88 | status = acpi_hw_set_mode (ACPI_SYS_MODE_ACPI); | ||
89 | if (ACPI_FAILURE (status)) { | ||
90 | ACPI_REPORT_ERROR (("Could not transition to ACPI mode.\n")); | ||
91 | return_ACPI_STATUS (status); | ||
92 | } | ||
93 | |||
94 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Transition to ACPI mode successful\n")); | ||
95 | } | ||
96 | |||
97 | return_ACPI_STATUS (status); | ||
98 | } | ||
99 | |||
100 | |||
101 | /******************************************************************************* | ||
102 | * | ||
103 | * FUNCTION: acpi_disable | ||
104 | * | ||
105 | * PARAMETERS: None | ||
106 | * | ||
107 | * RETURN: Status | ||
108 | * | ||
109 | * DESCRIPTION: Transfers the system into LEGACY mode. | ||
110 | * | ||
111 | ******************************************************************************/ | ||
112 | |||
113 | acpi_status | ||
114 | acpi_disable (void) | ||
115 | { | ||
116 | acpi_status status = AE_OK; | ||
117 | |||
118 | |||
119 | ACPI_FUNCTION_TRACE ("acpi_disable"); | ||
120 | |||
121 | |||
122 | if (!acpi_gbl_FADT) { | ||
123 | ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n")); | ||
124 | return_ACPI_STATUS (AE_NO_ACPI_TABLES); | ||
125 | } | ||
126 | |||
127 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { | ||
128 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in legacy (non-ACPI) mode\n")); | ||
129 | } | ||
130 | else { | ||
131 | /* Transition to LEGACY mode */ | ||
132 | |||
133 | status = acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY); | ||
134 | |||
135 | if (ACPI_FAILURE (status)) { | ||
136 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not exit ACPI mode to legacy mode")); | ||
137 | return_ACPI_STATUS (status); | ||
138 | } | ||
139 | |||
140 | ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n")); | ||
141 | } | ||
142 | |||
143 | return_ACPI_STATUS (status); | ||
144 | } | ||
145 | |||
146 | |||
147 | /******************************************************************************* | ||
148 | * | ||
149 | * FUNCTION: acpi_enable_event | ||
150 | * | ||
151 | * PARAMETERS: Event - The fixed eventto be enabled | ||
152 | * Flags - Reserved | ||
153 | * | ||
154 | * RETURN: Status | ||
155 | * | ||
156 | * DESCRIPTION: Enable an ACPI event (fixed) | ||
157 | * | ||
158 | ******************************************************************************/ | ||
159 | |||
160 | acpi_status | ||
161 | acpi_enable_event ( | ||
162 | u32 event, | ||
163 | u32 flags) | ||
164 | { | ||
165 | acpi_status status = AE_OK; | ||
166 | u32 value; | ||
167 | |||
168 | |||
169 | ACPI_FUNCTION_TRACE ("acpi_enable_event"); | ||
170 | |||
171 | |||
172 | /* Decode the Fixed Event */ | ||
173 | |||
174 | if (event > ACPI_EVENT_MAX) { | ||
175 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * Enable the requested fixed event (by writing a one to the | ||
180 | * enable register bit) | ||
181 | */ | ||
182 | status = acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id, | ||
183 | 1, ACPI_MTX_LOCK); | ||
184 | if (ACPI_FAILURE (status)) { | ||
185 | return_ACPI_STATUS (status); | ||
186 | } | ||
187 | |||
188 | /* Make sure that the hardware responded */ | ||
189 | |||
190 | status = acpi_get_register (acpi_gbl_fixed_event_info[event].enable_register_id, | ||
191 | &value, ACPI_MTX_LOCK); | ||
192 | if (ACPI_FAILURE (status)) { | ||
193 | return_ACPI_STATUS (status); | ||
194 | } | ||
195 | |||
196 | if (value != 1) { | ||
197 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
198 | "Could not enable %s event\n", acpi_ut_get_event_name (event))); | ||
199 | return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); | ||
200 | } | ||
201 | |||
202 | return_ACPI_STATUS (status); | ||
203 | } | ||
204 | EXPORT_SYMBOL(acpi_enable_event); | ||
205 | |||
206 | |||
207 | /******************************************************************************* | ||
208 | * | ||
209 | * FUNCTION: acpi_set_gpe_type | ||
210 | * | ||
211 | * PARAMETERS: gpe_device - Parent GPE Device | ||
212 | * gpe_number - GPE level within the GPE block | ||
213 | * Type - New GPE type | ||
214 | * | ||
215 | * RETURN: Status | ||
216 | * | ||
217 | * DESCRIPTION: Enable an ACPI event (general purpose) | ||
218 | * | ||
219 | ******************************************************************************/ | ||
220 | |||
221 | acpi_status | ||
222 | acpi_set_gpe_type ( | ||
223 | acpi_handle gpe_device, | ||
224 | u32 gpe_number, | ||
225 | u8 type) | ||
226 | { | ||
227 | acpi_status status = AE_OK; | ||
228 | struct acpi_gpe_event_info *gpe_event_info; | ||
229 | |||
230 | |||
231 | ACPI_FUNCTION_TRACE ("acpi_set_gpe_type"); | ||
232 | |||
233 | |||
234 | /* Ensure that we have a valid GPE number */ | ||
235 | |||
236 | gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number); | ||
237 | if (!gpe_event_info) { | ||
238 | status = AE_BAD_PARAMETER; | ||
239 | goto unlock_and_exit; | ||
240 | } | ||
241 | |||
242 | if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) { | ||
243 | return_ACPI_STATUS (AE_OK); | ||
244 | } | ||
245 | |||
246 | /* Set the new type (will disable GPE if currently enabled) */ | ||
247 | |||
248 | status = acpi_ev_set_gpe_type (gpe_event_info, type); | ||
249 | |||
250 | unlock_and_exit: | ||
251 | return_ACPI_STATUS (status); | ||
252 | } | ||
253 | EXPORT_SYMBOL(acpi_set_gpe_type); | ||
254 | |||
255 | |||
256 | /******************************************************************************* | ||
257 | * | ||
258 | * FUNCTION: acpi_enable_gpe | ||
259 | * | ||
260 | * PARAMETERS: gpe_device - Parent GPE Device | ||
261 | * gpe_number - GPE level within the GPE block | ||
262 | * Flags - Just enable, or also wake enable? | ||
263 | * Called from ISR or not | ||
264 | * | ||
265 | * RETURN: Status | ||
266 | * | ||
267 | * DESCRIPTION: Enable an ACPI event (general purpose) | ||
268 | * | ||
269 | ******************************************************************************/ | ||
270 | |||
271 | acpi_status | ||
272 | acpi_enable_gpe ( | ||
273 | acpi_handle gpe_device, | ||
274 | u32 gpe_number, | ||
275 | u32 flags) | ||
276 | { | ||
277 | acpi_status status = AE_OK; | ||
278 | struct acpi_gpe_event_info *gpe_event_info; | ||
279 | |||
280 | |||
281 | ACPI_FUNCTION_TRACE ("acpi_enable_gpe"); | ||
282 | |||
283 | |||
284 | /* Use semaphore lock if not executing at interrupt level */ | ||
285 | |||
286 | if (flags & ACPI_NOT_ISR) { | ||
287 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
288 | if (ACPI_FAILURE (status)) { | ||
289 | return_ACPI_STATUS (status); | ||
290 | } | ||
291 | } | ||
292 | |||
293 | /* Ensure that we have a valid GPE number */ | ||
294 | |||
295 | gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number); | ||
296 | if (!gpe_event_info) { | ||
297 | status = AE_BAD_PARAMETER; | ||
298 | goto unlock_and_exit; | ||
299 | } | ||
300 | |||
301 | /* Perform the enable */ | ||
302 | |||
303 | status = acpi_ev_enable_gpe (gpe_event_info, TRUE); | ||
304 | |||
305 | unlock_and_exit: | ||
306 | if (flags & ACPI_NOT_ISR) { | ||
307 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
308 | } | ||
309 | return_ACPI_STATUS (status); | ||
310 | } | ||
311 | EXPORT_SYMBOL(acpi_enable_gpe); | ||
312 | |||
313 | |||
314 | /******************************************************************************* | ||
315 | * | ||
316 | * FUNCTION: acpi_disable_gpe | ||
317 | * | ||
318 | * PARAMETERS: gpe_device - Parent GPE Device | ||
319 | * gpe_number - GPE level within the GPE block | ||
320 | * Flags - Just disable, or also wake disable? | ||
321 | * Called from ISR or not | ||
322 | * | ||
323 | * RETURN: Status | ||
324 | * | ||
325 | * DESCRIPTION: Disable an ACPI event (general purpose) | ||
326 | * | ||
327 | ******************************************************************************/ | ||
328 | |||
329 | acpi_status | ||
330 | acpi_disable_gpe ( | ||
331 | acpi_handle gpe_device, | ||
332 | u32 gpe_number, | ||
333 | u32 flags) | ||
334 | { | ||
335 | acpi_status status = AE_OK; | ||
336 | struct acpi_gpe_event_info *gpe_event_info; | ||
337 | |||
338 | |||
339 | ACPI_FUNCTION_TRACE ("acpi_disable_gpe"); | ||
340 | |||
341 | |||
342 | /* Use semaphore lock if not executing at interrupt level */ | ||
343 | |||
344 | if (flags & ACPI_NOT_ISR) { | ||
345 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
346 | if (ACPI_FAILURE (status)) { | ||
347 | return_ACPI_STATUS (status); | ||
348 | } | ||
349 | } | ||
350 | |||
351 | /* Ensure that we have a valid GPE number */ | ||
352 | |||
353 | gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number); | ||
354 | if (!gpe_event_info) { | ||
355 | status = AE_BAD_PARAMETER; | ||
356 | goto unlock_and_exit; | ||
357 | } | ||
358 | |||
359 | status = acpi_ev_disable_gpe (gpe_event_info); | ||
360 | |||
361 | unlock_and_exit: | ||
362 | if (flags & ACPI_NOT_ISR) { | ||
363 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
364 | } | ||
365 | return_ACPI_STATUS (status); | ||
366 | } | ||
367 | |||
368 | |||
369 | /******************************************************************************* | ||
370 | * | ||
371 | * FUNCTION: acpi_disable_event | ||
372 | * | ||
373 | * PARAMETERS: Event - The fixed eventto be enabled | ||
374 | * Flags - Reserved | ||
375 | * | ||
376 | * RETURN: Status | ||
377 | * | ||
378 | * DESCRIPTION: Disable an ACPI event (fixed) | ||
379 | * | ||
380 | ******************************************************************************/ | ||
381 | |||
382 | acpi_status | ||
383 | acpi_disable_event ( | ||
384 | u32 event, | ||
385 | u32 flags) | ||
386 | { | ||
387 | acpi_status status = AE_OK; | ||
388 | u32 value; | ||
389 | |||
390 | |||
391 | ACPI_FUNCTION_TRACE ("acpi_disable_event"); | ||
392 | |||
393 | |||
394 | /* Decode the Fixed Event */ | ||
395 | |||
396 | if (event > ACPI_EVENT_MAX) { | ||
397 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
398 | } | ||
399 | |||
400 | /* | ||
401 | * Disable the requested fixed event (by writing a zero to the | ||
402 | * enable register bit) | ||
403 | */ | ||
404 | status = acpi_set_register (acpi_gbl_fixed_event_info[event].enable_register_id, | ||
405 | 0, ACPI_MTX_LOCK); | ||
406 | if (ACPI_FAILURE (status)) { | ||
407 | return_ACPI_STATUS (status); | ||
408 | } | ||
409 | |||
410 | status = acpi_get_register (acpi_gbl_fixed_event_info[event].enable_register_id, | ||
411 | &value, ACPI_MTX_LOCK); | ||
412 | if (ACPI_FAILURE (status)) { | ||
413 | return_ACPI_STATUS (status); | ||
414 | } | ||
415 | |||
416 | if (value != 0) { | ||
417 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, | ||
418 | "Could not disable %s events\n", acpi_ut_get_event_name (event))); | ||
419 | return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); | ||
420 | } | ||
421 | |||
422 | return_ACPI_STATUS (status); | ||
423 | } | ||
424 | EXPORT_SYMBOL(acpi_disable_event); | ||
425 | |||
426 | |||
427 | /******************************************************************************* | ||
428 | * | ||
429 | * FUNCTION: acpi_clear_event | ||
430 | * | ||
431 | * PARAMETERS: Event - The fixed event to be cleared | ||
432 | * | ||
433 | * RETURN: Status | ||
434 | * | ||
435 | * DESCRIPTION: Clear an ACPI event (fixed) | ||
436 | * | ||
437 | ******************************************************************************/ | ||
438 | |||
439 | acpi_status | ||
440 | acpi_clear_event ( | ||
441 | u32 event) | ||
442 | { | ||
443 | acpi_status status = AE_OK; | ||
444 | |||
445 | |||
446 | ACPI_FUNCTION_TRACE ("acpi_clear_event"); | ||
447 | |||
448 | |||
449 | /* Decode the Fixed Event */ | ||
450 | |||
451 | if (event > ACPI_EVENT_MAX) { | ||
452 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
453 | } | ||
454 | |||
455 | /* | ||
456 | * Clear the requested fixed event (By writing a one to the | ||
457 | * status register bit) | ||
458 | */ | ||
459 | status = acpi_set_register (acpi_gbl_fixed_event_info[event].status_register_id, | ||
460 | 1, ACPI_MTX_LOCK); | ||
461 | |||
462 | return_ACPI_STATUS (status); | ||
463 | } | ||
464 | EXPORT_SYMBOL(acpi_clear_event); | ||
465 | |||
466 | |||
467 | /******************************************************************************* | ||
468 | * | ||
469 | * FUNCTION: acpi_clear_gpe | ||
470 | * | ||
471 | * PARAMETERS: gpe_device - Parent GPE Device | ||
472 | * gpe_number - GPE level within the GPE block | ||
473 | * Flags - Called from an ISR or not | ||
474 | * | ||
475 | * RETURN: Status | ||
476 | * | ||
477 | * DESCRIPTION: Clear an ACPI event (general purpose) | ||
478 | * | ||
479 | ******************************************************************************/ | ||
480 | |||
481 | acpi_status | ||
482 | acpi_clear_gpe ( | ||
483 | acpi_handle gpe_device, | ||
484 | u32 gpe_number, | ||
485 | u32 flags) | ||
486 | { | ||
487 | acpi_status status = AE_OK; | ||
488 | struct acpi_gpe_event_info *gpe_event_info; | ||
489 | |||
490 | |||
491 | ACPI_FUNCTION_TRACE ("acpi_clear_gpe"); | ||
492 | |||
493 | |||
494 | /* Use semaphore lock if not executing at interrupt level */ | ||
495 | |||
496 | if (flags & ACPI_NOT_ISR) { | ||
497 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
498 | if (ACPI_FAILURE (status)) { | ||
499 | return_ACPI_STATUS (status); | ||
500 | } | ||
501 | } | ||
502 | |||
503 | /* Ensure that we have a valid GPE number */ | ||
504 | |||
505 | gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number); | ||
506 | if (!gpe_event_info) { | ||
507 | status = AE_BAD_PARAMETER; | ||
508 | goto unlock_and_exit; | ||
509 | } | ||
510 | |||
511 | status = acpi_hw_clear_gpe (gpe_event_info); | ||
512 | |||
513 | unlock_and_exit: | ||
514 | if (flags & ACPI_NOT_ISR) { | ||
515 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
516 | } | ||
517 | return_ACPI_STATUS (status); | ||
518 | } | ||
519 | |||
520 | |||
521 | #ifdef ACPI_FUTURE_USAGE | ||
522 | |||
523 | /******************************************************************************* | ||
524 | * | ||
525 | * FUNCTION: acpi_get_event_status | ||
526 | * | ||
527 | * PARAMETERS: Event - The fixed event | ||
528 | * Event Status - Where the current status of the event will | ||
529 | * be returned | ||
530 | * | ||
531 | * RETURN: Status | ||
532 | * | ||
533 | * DESCRIPTION: Obtains and returns the current status of the event | ||
534 | * | ||
535 | ******************************************************************************/ | ||
536 | |||
537 | acpi_status | ||
538 | acpi_get_event_status ( | ||
539 | u32 event, | ||
540 | acpi_event_status *event_status) | ||
541 | { | ||
542 | acpi_status status = AE_OK; | ||
543 | |||
544 | |||
545 | ACPI_FUNCTION_TRACE ("acpi_get_event_status"); | ||
546 | |||
547 | |||
548 | if (!event_status) { | ||
549 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
550 | } | ||
551 | |||
552 | /* Decode the Fixed Event */ | ||
553 | |||
554 | if (event > ACPI_EVENT_MAX) { | ||
555 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
556 | } | ||
557 | |||
558 | /* Get the status of the requested fixed event */ | ||
559 | |||
560 | status = acpi_get_register (acpi_gbl_fixed_event_info[event].status_register_id, | ||
561 | event_status, ACPI_MTX_LOCK); | ||
562 | |||
563 | return_ACPI_STATUS (status); | ||
564 | } | ||
565 | |||
566 | |||
567 | /******************************************************************************* | ||
568 | * | ||
569 | * FUNCTION: acpi_get_gpe_status | ||
570 | * | ||
571 | * PARAMETERS: gpe_device - Parent GPE Device | ||
572 | * gpe_number - GPE level within the GPE block | ||
573 | * Flags - Called from an ISR or not | ||
574 | * Event Status - Where the current status of the event will | ||
575 | * be returned | ||
576 | * | ||
577 | * RETURN: Status | ||
578 | * | ||
579 | * DESCRIPTION: Get status of an event (general purpose) | ||
580 | * | ||
581 | ******************************************************************************/ | ||
582 | |||
583 | acpi_status | ||
584 | acpi_get_gpe_status ( | ||
585 | acpi_handle gpe_device, | ||
586 | u32 gpe_number, | ||
587 | u32 flags, | ||
588 | acpi_event_status *event_status) | ||
589 | { | ||
590 | acpi_status status = AE_OK; | ||
591 | struct acpi_gpe_event_info *gpe_event_info; | ||
592 | |||
593 | |||
594 | ACPI_FUNCTION_TRACE ("acpi_get_gpe_status"); | ||
595 | |||
596 | |||
597 | /* Use semaphore lock if not executing at interrupt level */ | ||
598 | |||
599 | if (flags & ACPI_NOT_ISR) { | ||
600 | status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS); | ||
601 | if (ACPI_FAILURE (status)) { | ||
602 | return_ACPI_STATUS (status); | ||
603 | } | ||
604 | } | ||
605 | |||
606 | /* Ensure that we have a valid GPE number */ | ||
607 | |||
608 | gpe_event_info = acpi_ev_get_gpe_event_info (gpe_device, gpe_number); | ||
609 | if (!gpe_event_info) { | ||
610 | status = AE_BAD_PARAMETER; | ||
611 | goto unlock_and_exit; | ||
612 | } | ||
613 | |||
614 | /* Obtain status on the requested GPE number */ | ||
615 | |||
616 | status = acpi_hw_get_gpe_status (gpe_event_info, event_status); | ||
617 | |||
618 | unlock_and_exit: | ||
619 | if (flags & ACPI_NOT_ISR) { | ||
620 | (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS); | ||
621 | } | ||
622 | return_ACPI_STATUS (status); | ||
623 | } | ||
624 | #endif /* ACPI_FUTURE_USAGE */ | ||
625 | |||
626 | |||
627 | /******************************************************************************* | ||
628 | * | ||
629 | * FUNCTION: acpi_install_gpe_block | ||
630 | * | ||
631 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device | ||
632 | * gpe_block_address - Address and space_iD | ||
633 | * register_count - Number of GPE register pairs in the block | ||
634 | * interrupt_level - H/W interrupt for the block | ||
635 | * | ||
636 | * RETURN: Status | ||
637 | * | ||
638 | * DESCRIPTION: Create and Install a block of GPE registers | ||
639 | * | ||
640 | ******************************************************************************/ | ||
641 | |||
642 | acpi_status | ||
643 | acpi_install_gpe_block ( | ||
644 | acpi_handle gpe_device, | ||
645 | struct acpi_generic_address *gpe_block_address, | ||
646 | u32 register_count, | ||
647 | u32 interrupt_level) | ||
648 | { | ||
649 | acpi_status status; | ||
650 | union acpi_operand_object *obj_desc; | ||
651 | struct acpi_namespace_node *node; | ||
652 | struct acpi_gpe_block_info *gpe_block; | ||
653 | |||
654 | |||
655 | ACPI_FUNCTION_TRACE ("acpi_install_gpe_block"); | ||
656 | |||
657 | |||
658 | if ((!gpe_device) || | ||
659 | (!gpe_block_address) || | ||
660 | (!register_count)) { | ||
661 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
662 | } | ||
663 | |||
664 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
665 | if (ACPI_FAILURE (status)) { | ||
666 | return (status); | ||
667 | } | ||
668 | |||
669 | node = acpi_ns_map_handle_to_node (gpe_device); | ||
670 | if (!node) { | ||
671 | status = AE_BAD_PARAMETER; | ||
672 | goto unlock_and_exit; | ||
673 | } | ||
674 | |||
675 | /* | ||
676 | * For user-installed GPE Block Devices, the gpe_block_base_number | ||
677 | * is always zero | ||
678 | */ | ||
679 | status = acpi_ev_create_gpe_block (node, gpe_block_address, register_count, | ||
680 | 0, interrupt_level, &gpe_block); | ||
681 | if (ACPI_FAILURE (status)) { | ||
682 | goto unlock_and_exit; | ||
683 | } | ||
684 | |||
685 | /* Get the device_object attached to the node */ | ||
686 | |||
687 | obj_desc = acpi_ns_get_attached_object (node); | ||
688 | if (!obj_desc) { | ||
689 | /* No object, create a new one */ | ||
690 | |||
691 | obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_DEVICE); | ||
692 | if (!obj_desc) { | ||
693 | status = AE_NO_MEMORY; | ||
694 | goto unlock_and_exit; | ||
695 | } | ||
696 | |||
697 | status = acpi_ns_attach_object (node, obj_desc, ACPI_TYPE_DEVICE); | ||
698 | |||
699 | /* Remove local reference to the object */ | ||
700 | |||
701 | acpi_ut_remove_reference (obj_desc); | ||
702 | |||
703 | if (ACPI_FAILURE (status)) { | ||
704 | goto unlock_and_exit; | ||
705 | } | ||
706 | } | ||
707 | |||
708 | /* Install the GPE block in the device_object */ | ||
709 | |||
710 | obj_desc->device.gpe_block = gpe_block; | ||
711 | |||
712 | |||
713 | unlock_and_exit: | ||
714 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
715 | return_ACPI_STATUS (status); | ||
716 | } | ||
717 | EXPORT_SYMBOL(acpi_install_gpe_block); | ||
718 | |||
719 | |||
720 | /******************************************************************************* | ||
721 | * | ||
722 | * FUNCTION: acpi_remove_gpe_block | ||
723 | * | ||
724 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device | ||
725 | * | ||
726 | * RETURN: Status | ||
727 | * | ||
728 | * DESCRIPTION: Remove a previously installed block of GPE registers | ||
729 | * | ||
730 | ******************************************************************************/ | ||
731 | |||
732 | acpi_status | ||
733 | acpi_remove_gpe_block ( | ||
734 | acpi_handle gpe_device) | ||
735 | { | ||
736 | union acpi_operand_object *obj_desc; | ||
737 | acpi_status status; | ||
738 | struct acpi_namespace_node *node; | ||
739 | |||
740 | |||
741 | ACPI_FUNCTION_TRACE ("acpi_remove_gpe_block"); | ||
742 | |||
743 | |||
744 | if (!gpe_device) { | ||
745 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
746 | } | ||
747 | |||
748 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
749 | if (ACPI_FAILURE (status)) { | ||
750 | return (status); | ||
751 | } | ||
752 | |||
753 | node = acpi_ns_map_handle_to_node (gpe_device); | ||
754 | if (!node) { | ||
755 | status = AE_BAD_PARAMETER; | ||
756 | goto unlock_and_exit; | ||
757 | } | ||
758 | |||
759 | /* Get the device_object attached to the node */ | ||
760 | |||
761 | obj_desc = acpi_ns_get_attached_object (node); | ||
762 | if (!obj_desc || | ||
763 | !obj_desc->device.gpe_block) { | ||
764 | return_ACPI_STATUS (AE_NULL_OBJECT); | ||
765 | } | ||
766 | |||
767 | /* Delete the GPE block (but not the device_object) */ | ||
768 | |||
769 | status = acpi_ev_delete_gpe_block (obj_desc->device.gpe_block); | ||
770 | if (ACPI_SUCCESS (status)) { | ||
771 | obj_desc->device.gpe_block = NULL; | ||
772 | } | ||
773 | |||
774 | unlock_and_exit: | ||
775 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
776 | return_ACPI_STATUS (status); | ||
777 | } | ||
778 | EXPORT_SYMBOL(acpi_remove_gpe_block); | ||
diff --git a/drivers/acpi/events/evxfregn.c b/drivers/acpi/events/evxfregn.c new file mode 100644 index 000000000000..d058587b3427 --- /dev/null +++ b/drivers/acpi/events/evxfregn.c | |||
@@ -0,0 +1,247 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and | ||
4 | * Address Spaces. | ||
5 | * | ||
6 | *****************************************************************************/ | ||
7 | |||
8 | /* | ||
9 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
10 | * All rights reserved. | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions, and the following disclaimer, | ||
17 | * without modification. | ||
18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
19 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
20 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
21 | * including a substantially similar Disclaimer requirement for further | ||
22 | * binary redistribution. | ||
23 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
24 | * of any contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * Alternatively, this software may be distributed under the terms of the | ||
28 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
29 | * Software Foundation. | ||
30 | * | ||
31 | * NO WARRANTY | ||
32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
42 | * POSSIBILITY OF SUCH DAMAGES. | ||
43 | */ | ||
44 | |||
45 | #include <linux/module.h> | ||
46 | |||
47 | #include <acpi/acpi.h> | ||
48 | #include <acpi/acnamesp.h> | ||
49 | #include <acpi/acevents.h> | ||
50 | |||
51 | #define _COMPONENT ACPI_EVENTS | ||
52 | ACPI_MODULE_NAME ("evxfregn") | ||
53 | |||
54 | |||
55 | /******************************************************************************* | ||
56 | * | ||
57 | * FUNCTION: acpi_install_address_space_handler | ||
58 | * | ||
59 | * PARAMETERS: Device - Handle for the device | ||
60 | * space_id - The address space ID | ||
61 | * Handler - Address of the handler | ||
62 | * Setup - Address of the setup function | ||
63 | * Context - Value passed to the handler on each access | ||
64 | * | ||
65 | * RETURN: Status | ||
66 | * | ||
67 | * DESCRIPTION: Install a handler for all op_regions of a given space_id. | ||
68 | * | ||
69 | ******************************************************************************/ | ||
70 | |||
71 | acpi_status | ||
72 | acpi_install_address_space_handler ( | ||
73 | acpi_handle device, | ||
74 | acpi_adr_space_type space_id, | ||
75 | acpi_adr_space_handler handler, | ||
76 | acpi_adr_space_setup setup, | ||
77 | void *context) | ||
78 | { | ||
79 | struct acpi_namespace_node *node; | ||
80 | acpi_status status; | ||
81 | |||
82 | |||
83 | ACPI_FUNCTION_TRACE ("acpi_install_address_space_handler"); | ||
84 | |||
85 | |||
86 | /* Parameter validation */ | ||
87 | |||
88 | if (!device) { | ||
89 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
90 | } | ||
91 | |||
92 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
93 | if (ACPI_FAILURE (status)) { | ||
94 | return_ACPI_STATUS (status); | ||
95 | } | ||
96 | |||
97 | /* Convert and validate the device handle */ | ||
98 | |||
99 | node = acpi_ns_map_handle_to_node (device); | ||
100 | if (!node) { | ||
101 | status = AE_BAD_PARAMETER; | ||
102 | goto unlock_and_exit; | ||
103 | } | ||
104 | |||
105 | /* Install the handler for all Regions for this Space ID */ | ||
106 | |||
107 | status = acpi_ev_install_space_handler (node, space_id, handler, setup, context); | ||
108 | if (ACPI_FAILURE (status)) { | ||
109 | goto unlock_and_exit; | ||
110 | } | ||
111 | |||
112 | /* Run all _REG methods for this address space */ | ||
113 | |||
114 | status = acpi_ev_execute_reg_methods (node, space_id); | ||
115 | |||
116 | unlock_and_exit: | ||
117 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
118 | return_ACPI_STATUS (status); | ||
119 | } | ||
120 | EXPORT_SYMBOL(acpi_install_address_space_handler); | ||
121 | |||
122 | |||
123 | /******************************************************************************* | ||
124 | * | ||
125 | * FUNCTION: acpi_remove_address_space_handler | ||
126 | * | ||
127 | * PARAMETERS: Device - Handle for the device | ||
128 | * space_id - The address space ID | ||
129 | * Handler - Address of the handler | ||
130 | * | ||
131 | * RETURN: Status | ||
132 | * | ||
133 | * DESCRIPTION: Remove a previously installed handler. | ||
134 | * | ||
135 | ******************************************************************************/ | ||
136 | |||
137 | acpi_status | ||
138 | acpi_remove_address_space_handler ( | ||
139 | acpi_handle device, | ||
140 | acpi_adr_space_type space_id, | ||
141 | acpi_adr_space_handler handler) | ||
142 | { | ||
143 | union acpi_operand_object *obj_desc; | ||
144 | union acpi_operand_object *handler_obj; | ||
145 | union acpi_operand_object *region_obj; | ||
146 | union acpi_operand_object **last_obj_ptr; | ||
147 | struct acpi_namespace_node *node; | ||
148 | acpi_status status; | ||
149 | |||
150 | |||
151 | ACPI_FUNCTION_TRACE ("acpi_remove_address_space_handler"); | ||
152 | |||
153 | |||
154 | /* Parameter validation */ | ||
155 | |||
156 | if (!device) { | ||
157 | return_ACPI_STATUS (AE_BAD_PARAMETER); | ||
158 | } | ||
159 | |||
160 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | ||
161 | if (ACPI_FAILURE (status)) { | ||
162 | return_ACPI_STATUS (status); | ||
163 | } | ||
164 | |||
165 | /* Convert and validate the device handle */ | ||
166 | |||
167 | node = acpi_ns_map_handle_to_node (device); | ||
168 | if (!node) { | ||
169 | status = AE_BAD_PARAMETER; | ||
170 | goto unlock_and_exit; | ||
171 | } | ||
172 | |||
173 | /* Make sure the internal object exists */ | ||
174 | |||
175 | obj_desc = acpi_ns_get_attached_object (node); | ||
176 | if (!obj_desc) { | ||
177 | status = AE_NOT_EXIST; | ||
178 | goto unlock_and_exit; | ||
179 | } | ||
180 | |||
181 | /* Find the address handler the user requested */ | ||
182 | |||
183 | handler_obj = obj_desc->device.handler; | ||
184 | last_obj_ptr = &obj_desc->device.handler; | ||
185 | while (handler_obj) { | ||
186 | /* We have a handler, see if user requested this one */ | ||
187 | |||
188 | if (handler_obj->address_space.space_id == space_id) { | ||
189 | /* Matched space_id, first dereference this in the Regions */ | ||
190 | |||
191 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
192 | "Removing address handler %p(%p) for region %s on Device %p(%p)\n", | ||
193 | handler_obj, handler, acpi_ut_get_region_name (space_id), | ||
194 | node, obj_desc)); | ||
195 | |||
196 | region_obj = handler_obj->address_space.region_list; | ||
197 | |||
198 | /* Walk the handler's region list */ | ||
199 | |||
200 | while (region_obj) { | ||
201 | /* | ||
202 | * First disassociate the handler from the region. | ||
203 | * | ||
204 | * NOTE: this doesn't mean that the region goes away | ||
205 | * The region is just inaccessible as indicated to | ||
206 | * the _REG method | ||
207 | */ | ||
208 | acpi_ev_detach_region (region_obj, TRUE); | ||
209 | |||
210 | /* | ||
211 | * Walk the list: Just grab the head because the | ||
212 | * detach_region removed the previous head. | ||
213 | */ | ||
214 | region_obj = handler_obj->address_space.region_list; | ||
215 | |||
216 | } | ||
217 | |||
218 | /* Remove this Handler object from the list */ | ||
219 | |||
220 | *last_obj_ptr = handler_obj->address_space.next; | ||
221 | |||
222 | /* Now we can delete the handler object */ | ||
223 | |||
224 | acpi_ut_remove_reference (handler_obj); | ||
225 | goto unlock_and_exit; | ||
226 | } | ||
227 | |||
228 | /* Walk the linked list of handlers */ | ||
229 | |||
230 | last_obj_ptr = &handler_obj->address_space.next; | ||
231 | handler_obj = handler_obj->address_space.next; | ||
232 | } | ||
233 | |||
234 | /* The handler does not exist */ | ||
235 | |||
236 | ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, | ||
237 | "Unable to remove address handler %p for %s(%X), dev_node %p, obj %p\n", | ||
238 | handler, acpi_ut_get_region_name (space_id), space_id, node, obj_desc)); | ||
239 | |||
240 | status = AE_NOT_EXIST; | ||
241 | |||
242 | unlock_and_exit: | ||
243 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | ||
244 | return_ACPI_STATUS (status); | ||
245 | } | ||
246 | EXPORT_SYMBOL(acpi_remove_address_space_handler); | ||
247 | |||