- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / events / evrgnini.c
blob92e5f198fac93d609470d8639f7e133046fbe400
1 /******************************************************************************
3 * Module Name: evrgnini- ACPI Address_space (Op_region) init
4 * $Revision: 31 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "acpi.h"
28 #include "acevents.h"
29 #include "acnamesp.h"
30 #include "acinterp.h"
31 #include "amlcode.h"
33 #define _COMPONENT EVENT_HANDLING
34 MODULE_NAME ("evrgnini")
37 /*****************************************************************************
39 * FUNCTION: Acpi_ev_system_memory_region_setup
41 * PARAMETERS: Region_obj - region we are interested in
42 * Function - start or stop
43 * Handler_context - Address space handler context
44 * Region_context - Region specific context
46 * RETURN: Status
48 * DESCRIPTION: Do any prep work for region handling, a nop for now
50 ****************************************************************************/
52 ACPI_STATUS
53 acpi_ev_system_memory_region_setup (
54 ACPI_HANDLE handle,
55 u32 function,
56 void *handler_context,
57 void **region_context)
60 if (function == ACPI_REGION_DEACTIVATE) {
61 if (*region_context) {
62 acpi_cm_free (*region_context);
63 *region_context = NULL;
65 return (AE_OK);
69 /* Activate. Create a new context */
71 *region_context = acpi_cm_callocate (sizeof (MEM_HANDLER_CONTEXT));
72 if (!(*region_context)) {
73 return (AE_NO_MEMORY);
76 return (AE_OK);
80 /*****************************************************************************
82 * FUNCTION: Acpi_ev_io_space_region_setup
84 * PARAMETERS: Region_obj - region we are interested in
85 * Function - start or stop
86 * Handler_context - Address space handler context
87 * Region_context - Region specific context
89 * RETURN: Status
91 * DESCRIPTION: Do any prep work for region handling
93 ****************************************************************************/
95 ACPI_STATUS
96 acpi_ev_io_space_region_setup (
97 ACPI_HANDLE handle,
98 u32 function,
99 void *handler_context,
100 void **region_context)
102 if (function == ACPI_REGION_DEACTIVATE) {
103 *region_context = NULL;
105 else {
106 *region_context = handler_context;
109 return (AE_OK);
113 /*****************************************************************************
115 * FUNCTION: Acpi_ev_pci_config_region_setup
117 * PARAMETERS: Region_obj - region we are interested in
118 * Function - start or stop
119 * Handler_context - Address space handler context
120 * Region_context - Region specific context
122 * RETURN: Status
124 * DESCRIPTION: Do any prep work for region handling
126 * MUTEX: Assumes namespace is not locked
128 ****************************************************************************/
130 ACPI_STATUS
131 acpi_ev_pci_config_region_setup (
132 ACPI_HANDLE handle,
133 u32 function,
134 void *handler_context,
135 void **region_context)
137 ACPI_STATUS status = AE_OK;
138 ACPI_INTEGER temp;
139 PCI_HANDLER_CONTEXT *pci_context = *region_context;
140 ACPI_OPERAND_OBJECT *handler_obj;
141 ACPI_NAMESPACE_NODE *node;
142 ACPI_OPERAND_OBJECT *region_obj = (ACPI_OPERAND_OBJECT *) handle;
143 DEVICE_ID object_hID;
145 handler_obj = region_obj->region.addr_handler;
147 if (!handler_obj) {
149 * No installed handler. This shouldn't happen because the dispatch
150 * routine checks before we get here, but we check again just in case.
152 return(AE_NOT_EXIST);
155 if (function == ACPI_REGION_DEACTIVATE) {
156 if (pci_context) {
157 acpi_cm_free (pci_context);
158 *region_context = NULL;
161 return (status);
165 /* Create a new context */
167 pci_context = acpi_cm_callocate (sizeof(PCI_HANDLER_CONTEXT));
168 if (!pci_context) {
169 return (AE_NO_MEMORY);
173 * For PCI Config space access, we have to pass the segment, bus,
174 * device and function numbers. This routine must acquire those.
178 * First get device and function numbers from the _ADR object
179 * in the parent's scope.
181 ACPI_ASSERT(region_obj->region.node);
183 node = acpi_ns_get_parent_object (region_obj->region.node);
186 /* Acpi_evaluate the _ADR object */
188 status = acpi_cm_evaluate_numeric_object (METHOD_NAME__ADR, node, &temp);
190 * The default is zero, since the allocation above zeroed the data, just
191 * do nothing on failures.
193 if (ACPI_SUCCESS (status)) {
195 * Got it..
197 pci_context->dev_func = (u32) temp;
201 * Get the _SEG and _BBN values from the device upon which the handler
202 * is installed.
204 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
205 * This is the device the handler has been registered to handle.
209 * If the Addr_handler.Node is still pointing to the root, we need
210 * to scan upward for a PCI Root bridge and re-associate the Op_region
211 * handlers with that device.
213 if (handler_obj->addr_handler.node == acpi_gbl_root_node) {
215 * Node is currently the parent object
217 while (node != acpi_gbl_root_node) {
218 status = acpi_cm_execute_HID(node, &object_hID);
220 if (ACPI_SUCCESS (status)) {
221 if (!(STRNCMP(object_hID.buffer, PCI_ROOT_HID_STRING,
222 sizeof (PCI_ROOT_HID_STRING))))
224 acpi_install_address_space_handler(node,
225 ADDRESS_SPACE_PCI_CONFIG,
226 ACPI_DEFAULT_HANDLER, NULL, NULL);
228 break;
232 node = acpi_ns_get_parent_object(node);
235 else {
236 node = handler_obj->addr_handler.node;
239 status = acpi_cm_evaluate_numeric_object (METHOD_NAME__SEG, node, &temp);
240 if (ACPI_SUCCESS (status)) {
242 * Got it..
244 pci_context->seg = (u32) temp;
247 status = acpi_cm_evaluate_numeric_object (METHOD_NAME__BBN, node, &temp);
248 if (ACPI_SUCCESS (status)) {
250 * Got it..
252 pci_context->bus = (u32) temp;
255 *region_context = pci_context;
257 return (AE_OK);
261 /*****************************************************************************
263 * FUNCTION: Acpi_ev_default_region_setup
265 * PARAMETERS: Region_obj - region we are interested in
266 * Function - start or stop
267 * Handler_context - Address space handler context
268 * Region_context - Region specific context
270 * RETURN: Status
272 * DESCRIPTION: Do any prep work for region handling
274 ****************************************************************************/
276 ACPI_STATUS
277 acpi_ev_default_region_setup (
278 ACPI_HANDLE handle,
279 u32 function,
280 void *handler_context,
281 void **region_context)
283 if (function == ACPI_REGION_DEACTIVATE) {
284 *region_context = NULL;
286 else {
287 *region_context = handler_context;
290 return (AE_OK);
294 /******************************************************************************
296 * FUNCTION: Acpi_ev_initialize_region
298 * PARAMETERS: Region_obj - Region we are initializing
300 * RETURN: Status
302 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
303 * for execution at a later time
305 * Get the appropriate address space handler for a newly
306 * created region.
308 * This also performs address space specific intialization. For
309 * example, PCI regions must have an _ADR object that contains
310 * a PCI address in the scope of the defintion. This address is
311 * required to perform an access to PCI config space.
313 ******************************************************************************/
315 ACPI_STATUS
316 acpi_ev_initialize_region (
317 ACPI_OPERAND_OBJECT *region_obj,
318 u8 acpi_ns_locked)
320 ACPI_OPERAND_OBJECT *handler_obj;
321 ACPI_OPERAND_OBJECT *obj_desc;
322 ACPI_ADDRESS_SPACE_TYPE space_id;
323 ACPI_NAMESPACE_NODE *node;
324 ACPI_STATUS status;
325 ACPI_NAMESPACE_NODE *method_node;
326 ACPI_NAME *reg_name_ptr = (ACPI_NAME *) METHOD_NAME__REG;
329 if (!region_obj) {
330 return (AE_BAD_PARAMETER);
333 ACPI_ASSERT(region_obj->region.node);
335 node = acpi_ns_get_parent_object (region_obj->region.node);
336 space_id = region_obj->region.space_id;
338 region_obj->region.addr_handler = NULL;
339 region_obj->region.extra->extra.method_REG = NULL;
340 region_obj->region.flags &= ~(AOPOBJ_INITIALIZED);
343 * Find any "_REG" associated with this region definition
345 status = acpi_ns_search_node (*reg_name_ptr, node,
346 ACPI_TYPE_METHOD, &method_node);
347 if (ACPI_SUCCESS (status)) {
349 * The _REG method is optional and there can be only one per region
350 * definition. This will be executed when the handler is attached
351 * or removed
353 region_obj->region.extra->extra.method_REG = method_node;
357 * The following loop depends upon the root Node having no parent
358 * ie: Acpi_gbl_Root_node->Parent_entry being set to NULL
360 while (node) {
362 * Check to see if a handler exists
364 handler_obj = NULL;
365 obj_desc = acpi_ns_get_attached_object ((ACPI_HANDLE) node);
366 if (obj_desc) {
368 * can only be a handler if the object exists
370 switch (node->type)
372 case ACPI_TYPE_DEVICE:
374 handler_obj = obj_desc->device.addr_handler;
375 break;
377 case ACPI_TYPE_PROCESSOR:
379 handler_obj = obj_desc->processor.addr_handler;
380 break;
382 case ACPI_TYPE_THERMAL:
384 handler_obj = obj_desc->thermal_zone.addr_handler;
385 break;
388 while (handler_obj) {
390 * This guy has at least one address handler
391 * see if it has the type we want
393 if (handler_obj->addr_handler.space_id == space_id) {
395 * Found it! Now update the region and the handler
397 acpi_ev_associate_region_and_handler (handler_obj, region_obj, acpi_ns_locked);
398 return (AE_OK);
401 handler_obj = handler_obj->addr_handler.next;
403 } /* while handlerobj */
407 * This one does not have the handler we need
408 * Pop up one level
410 node = acpi_ns_get_parent_object (node);
412 } /* while Node != ROOT */
415 * If we get here, there is no handler for this region
417 return (AE_NOT_EXIST);