1 /*****************************************************************************
3 * Module Name: bmxface.c
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 Andrew Grover
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
29 #define _COMPONENT ACPI_BUS_MANAGER
30 MODULE_NAME ("bmxface")
33 /****************************************************************************
35 ****************************************************************************/
37 /****************************************************************************
39 * FUNCTION: bm_get_device_status
47 ****************************************************************************/
49 bm_get_device_status (
50 BM_HANDLE device_handle
,
51 BM_DEVICE_STATUS
*device_status
)
53 ACPI_STATUS status
= AE_OK
;
56 FUNCTION_TRACE("bm_get_device_status");
59 return_ACPI_STATUS(AE_BAD_PARAMETER
);
62 *device_status
= BM_STATUS_UNKNOWN
;
65 * Resolve device handle to node.
67 status
= bm_get_node(device_handle
, 0, &node
);
68 if (ACPI_FAILURE(status
)) {
69 return_ACPI_STATUS(status
);
75 * If the parent isn't present we can't evalute _STA on the child.
76 * Return an unknown status.
78 if (!BM_NODE_PRESENT(node
->parent
)) {
79 return_ACPI_STATUS(AE_OK
);
85 * If _STA isn't present we just return the default status.
87 if (!(node
->device
.flags
& BM_FLAGS_DYNAMIC_STATUS
)) {
88 *device_status
= BM_STATUS_DEFAULT
;
89 return_ACPI_STATUS(AE_OK
);
96 status
= bm_evaluate_simple_integer(node
->device
.acpi_handle
, "_STA",
97 &(node
->device
.status
));
98 if (ACPI_SUCCESS(status
)) {
99 *device_status
= node
->device
.status
;
102 return_ACPI_STATUS(status
);
106 /****************************************************************************
108 * FUNCTION: bm_get_device_info
116 ****************************************************************************/
119 BM_HANDLE device_handle
,
122 ACPI_STATUS status
= AE_OK
;
123 BM_NODE
*node
= NULL
;
125 FUNCTION_TRACE("bm_get_device_info");
128 return_ACPI_STATUS(AE_BAD_PARAMETER
);
132 * Resolve device handle to internal device.
134 status
= bm_get_node(device_handle
, 0, &node
);
135 if (ACPI_FAILURE(status
)) {
136 return_ACPI_STATUS(status
);
139 *device
= &(node
->device
);
141 return_ACPI_STATUS(AE_OK
);
145 /****************************************************************************
147 * FUNCTION: bm_get_device_context
155 ****************************************************************************/
157 bm_get_device_context (
158 BM_HANDLE device_handle
,
159 BM_DRIVER_CONTEXT
*context
)
161 ACPI_STATUS status
= AE_OK
;
162 BM_NODE
*node
= NULL
;
164 FUNCTION_TRACE("bm_get_device_context");
167 return_ACPI_STATUS(AE_BAD_PARAMETER
);
173 * Resolve device handle to internal device.
175 status
= bm_get_node(device_handle
, 0, &node
);
176 if (ACPI_FAILURE(status
)) {
177 return_ACPI_STATUS(status
);
180 if (!node
->driver
.context
) {
181 return_ACPI_STATUS(AE_NULL_ENTRY
);
184 *context
= node
->driver
.context
;
186 return_ACPI_STATUS(AE_OK
);
190 /****************************************************************************
192 * FUNCTION: bm_register_driver
200 ****************************************************************************/
204 BM_DEVICE_ID
*criteria
,
207 ACPI_STATUS status
= AE_NOT_FOUND
;
208 BM_HANDLE_LIST device_list
;
209 BM_NODE
*node
= NULL
;
212 FUNCTION_TRACE("bm_register_driver");
214 if (!criteria
|| !driver
|| !driver
->notify
|| !driver
->request
) {
215 return_ACPI_STATUS(AE_BAD_PARAMETER
);
218 MEMSET(&device_list
, 0, sizeof(BM_HANDLE_LIST
));
223 * Search through the entire device hierarchy for matches against
224 * the given device criteria.
226 status
= bm_search(BM_HANDLE_ROOT
, criteria
, &device_list
);
227 if (ACPI_FAILURE(status
)) {
228 return_ACPI_STATUS(status
);
234 * For each match, record the driver information and execute the
235 * driver's Notify() funciton (if present) to notify the driver
236 * of the device's presence.
238 for (i
= 0; i
< device_list
.count
; i
++) {
240 /* Resolve the device handle. */
241 status
= bm_get_node(device_list
.handles
[i
], 0, &node
);
242 if (ACPI_FAILURE(status
)) {
246 DEBUG_PRINT(ACPI_INFO
, ("Registering driver for device [0x%02x].\n", node
->device
.handle
));
248 /* Notify driver of new device. */
249 status
= driver
->notify(BM_NOTIFY_DEVICE_ADDED
,
250 node
->device
.handle
, &(node
->driver
.context
));
251 if (ACPI_SUCCESS(status
)) {
252 node
->driver
.notify
= driver
->notify
;
253 node
->driver
.request
= driver
->request
;
254 node
->device
.flags
|= BM_FLAGS_DRIVER_CONTROL
;
258 return_ACPI_STATUS(AE_OK
);
262 /****************************************************************************
264 * FUNCTION: bm_unregister_driver
272 ****************************************************************************/
275 bm_unregister_driver (
276 BM_DEVICE_ID
*criteria
,
279 ACPI_STATUS status
= AE_NOT_FOUND
;
280 BM_HANDLE_LIST device_list
;
281 BM_NODE
*node
= NULL
;
284 FUNCTION_TRACE("bm_unregister_driver");
286 if (!criteria
|| !driver
|| !driver
->notify
|| !driver
->request
) {
287 return_ACPI_STATUS(AE_BAD_PARAMETER
);
290 MEMSET(&device_list
, 0, sizeof(BM_HANDLE_LIST
));
295 * Search through the entire device hierarchy for matches against
296 * the given device criteria.
298 status
= bm_search(BM_HANDLE_ROOT
, criteria
, &device_list
);
299 if (ACPI_FAILURE(status
)) {
300 return_ACPI_STATUS(status
);
306 * For each match, execute the driver's Notify() function to allow
307 * the driver to cleanup each device instance.
309 for (i
= 0; i
< device_list
.count
; i
++) {
311 * Resolve the device handle.
313 status
= bm_get_node(device_list
.handles
[i
], 0, &node
);
314 if (ACPI_FAILURE(status
)) {
318 DEBUG_PRINT(ACPI_INFO
, ("Unregistering driver for device [0x%02x].\n", node
->device
.handle
));
320 /* Notify driver of device removal. */
321 status
= node
->driver
.notify(BM_NOTIFY_DEVICE_REMOVED
,
322 node
->device
.handle
, &(node
->driver
.context
));
324 node
->device
.flags
&= ~BM_FLAGS_DRIVER_CONTROL
;
326 MEMSET(&(node
->driver
), 0, sizeof(BM_DRIVER
));
329 return_ACPI_STATUS(AE_OK
);