1 /******************************************************************************
3 * Module Name: evrgnini- ACPI Address_space (Op_region) init
6 *****************************************************************************/
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
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
48 * DESCRIPTION: Do any prep work for region handling, a nop for now
50 ****************************************************************************/
53 acpi_ev_system_memory_region_setup (
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
;
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
);
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
91 * DESCRIPTION: Do any prep work for region handling
93 ****************************************************************************/
96 acpi_ev_io_space_region_setup (
99 void *handler_context
,
100 void **region_context
)
102 if (function
== ACPI_REGION_DEACTIVATE
) {
103 *region_context
= NULL
;
106 *region_context
= handler_context
;
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
124 * DESCRIPTION: Do any prep work for region handling
126 * MUTEX: Assumes namespace is not locked
128 ****************************************************************************/
131 acpi_ev_pci_config_region_setup (
134 void *handler_context
,
135 void **region_context
)
137 ACPI_STATUS status
= AE_OK
;
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
;
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
) {
157 acpi_cm_free (pci_context
);
158 *region_context
= NULL
;
165 /* Create a new context */
167 pci_context
= acpi_cm_callocate (sizeof(PCI_HANDLER_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
)) {
197 pci_context
->dev_func
= (u32
) temp
;
201 * Get the _SEG and _BBN values from the device upon which the handler
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
);
232 node
= acpi_ns_get_parent_object(node
);
236 node
= handler_obj
->addr_handler
.node
;
239 status
= acpi_cm_evaluate_numeric_object (METHOD_NAME__SEG
, node
, &temp
);
240 if (ACPI_SUCCESS (status
)) {
244 pci_context
->seg
= (u32
) temp
;
247 status
= acpi_cm_evaluate_numeric_object (METHOD_NAME__BBN
, node
, &temp
);
248 if (ACPI_SUCCESS (status
)) {
252 pci_context
->bus
= (u32
) temp
;
255 *region_context
= pci_context
;
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
272 * DESCRIPTION: Do any prep work for region handling
274 ****************************************************************************/
277 acpi_ev_default_region_setup (
280 void *handler_context
,
281 void **region_context
)
283 if (function
== ACPI_REGION_DEACTIVATE
) {
284 *region_context
= NULL
;
287 *region_context
= handler_context
;
294 /******************************************************************************
296 * FUNCTION: Acpi_ev_initialize_region
298 * PARAMETERS: Region_obj - Region we are initializing
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
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 ******************************************************************************/
316 acpi_ev_initialize_region (
317 ACPI_OPERAND_OBJECT
*region_obj
,
320 ACPI_OPERAND_OBJECT
*handler_obj
;
321 ACPI_OPERAND_OBJECT
*obj_desc
;
322 ACPI_ADDRESS_SPACE_TYPE space_id
;
323 ACPI_NAMESPACE_NODE
*node
;
325 ACPI_NAMESPACE_NODE
*method_node
;
326 ACPI_NAME
*reg_name_ptr
= (ACPI_NAME
*) METHOD_NAME__REG
;
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
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
362 * Check to see if a handler exists
365 obj_desc
= acpi_ns_get_attached_object ((ACPI_HANDLE
) node
);
368 * can only be a handler if the object exists
372 case ACPI_TYPE_DEVICE
:
374 handler_obj
= obj_desc
->device
.addr_handler
;
377 case ACPI_TYPE_PROCESSOR
:
379 handler_obj
= obj_desc
->processor
.addr_handler
;
382 case ACPI_TYPE_THERMAL
:
384 handler_obj
= obj_desc
->thermal_zone
.addr_handler
;
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
);
401 handler_obj
= handler_obj
->addr_handler
.next
;
403 } /* while handlerobj */
407 * This one does not have the handler we need
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
);