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
30 #define _COMPONENT ACPI_BUS_MANAGER
31 MODULE_NAME ("bmxface")
34 /****************************************************************************
36 ****************************************************************************/
38 /****************************************************************************
40 * FUNCTION: bm_get_device_status
48 ****************************************************************************/
50 bm_get_device_status (
51 BM_HANDLE device_handle,
52 BM_DEVICE_STATUS *device_status)
54 ACPI_STATUS status = AE_OK;
57 FUNCTION_TRACE("bm_get_device_status");
60 return_ACPI_STATUS(AE_BAD_PARAMETER);
63 *device_status = BM_STATUS_UNKNOWN;
66 * Resolve device handle to node.
68 status = bm_get_node(device_handle, 0, &node);
69 if (ACPI_FAILURE(status)) {
70 return_ACPI_STATUS(status);
76 * If the parent isn't present we can't evalute _STA on the child.
77 * Return an unknown status.
79 if (!BM_NODE_PRESENT(node->parent)) {
80 return_ACPI_STATUS(AE_OK);
86 * If _STA isn't present we just return the default status.
88 if (!(node->device.flags & BM_FLAGS_DYNAMIC_STATUS)) {
89 *device_status = BM_STATUS_DEFAULT;
90 return_ACPI_STATUS(AE_OK);
97 status = bm_evaluate_simple_integer(node->device.acpi_handle, "_STA",
98 &(node->device.status));
99 if (ACPI_SUCCESS(status)) {
100 *device_status = node->device.status;
103 return_ACPI_STATUS(status);
107 /****************************************************************************
109 * FUNCTION: bm_get_device_info
117 ****************************************************************************/
120 BM_HANDLE device_handle,
123 ACPI_STATUS status = AE_OK;
124 BM_NODE *node = NULL;
126 FUNCTION_TRACE("bm_get_device_info");
129 return_ACPI_STATUS(AE_BAD_PARAMETER);
133 * Resolve device handle to internal device.
135 status = bm_get_node(device_handle, 0, &node);
136 if (ACPI_FAILURE(status)) {
137 return_ACPI_STATUS(status);
140 *device = &(node->device);
142 return_ACPI_STATUS(AE_OK);
146 /****************************************************************************
148 * FUNCTION: bm_get_device_context
156 ****************************************************************************/
158 bm_get_device_context (
159 BM_HANDLE device_handle,
160 BM_DRIVER_CONTEXT *context)
162 ACPI_STATUS status = AE_OK;
163 BM_NODE *node = NULL;
165 FUNCTION_TRACE("bm_get_device_context");
168 return_ACPI_STATUS(AE_BAD_PARAMETER);
174 * Resolve device handle to internal device.
176 status = bm_get_node(device_handle, 0, &node);
177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status);
181 if (!node->driver.context) {
182 return_ACPI_STATUS(AE_NULL_ENTRY);
185 *context = node->driver.context;
187 return_ACPI_STATUS(AE_OK);
191 /****************************************************************************
193 * FUNCTION: bm_register_driver
201 ****************************************************************************/
205 BM_DEVICE_ID *criteria,
208 ACPI_STATUS status = AE_NOT_FOUND;
209 BM_HANDLE_LIST device_list;
210 BM_NODE *node = NULL;
213 FUNCTION_TRACE("bm_register_driver");
215 if (!criteria || !driver || !driver->notify || !driver->request) {
216 return_ACPI_STATUS(AE_BAD_PARAMETER);
219 MEMSET(&device_list, 0, sizeof(BM_HANDLE_LIST));
224 * Search through the entire device hierarchy for matches against
225 * the given device criteria.
227 status = bm_search(BM_HANDLE_ROOT, criteria, &device_list);
228 if (ACPI_FAILURE(status)) {
229 return_ACPI_STATUS(status);
235 * For each match, record the driver information and execute the
236 * driver's Notify() funciton (if present) to notify the driver
237 * of the device's presence.
239 for (i = 0; i < device_list.count; i++) {
241 /* Resolve the device handle. */
242 status = bm_get_node(device_list.handles[i], 0, &node);
243 if (ACPI_FAILURE(status)) {
247 DEBUG_PRINT(ACPI_INFO, ("Registering driver for device [0x%02x].\n", node->device.handle));
249 /* Notify driver of new device. */
250 status = driver->notify(BM_NOTIFY_DEVICE_ADDED,
251 node->device.handle, &(node->driver.context));
252 if (ACPI_SUCCESS(status)) {
253 node->driver.notify = driver->notify;
254 node->driver.request = driver->request;
255 node->device.flags |= BM_FLAGS_DRIVER_CONTROL;
259 return_ACPI_STATUS(AE_OK);
263 /****************************************************************************
265 * FUNCTION: bm_unregister_driver
273 ****************************************************************************/
276 bm_unregister_driver (
277 BM_DEVICE_ID *criteria,
280 ACPI_STATUS status = AE_NOT_FOUND;
281 BM_HANDLE_LIST device_list;
282 BM_NODE *node = NULL;
285 FUNCTION_TRACE("bm_unregister_driver");
287 if (!criteria || !driver || !driver->notify || !driver->request) {
288 return_ACPI_STATUS(AE_BAD_PARAMETER);
291 MEMSET(&device_list, 0, sizeof(BM_HANDLE_LIST));
296 * Search through the entire device hierarchy for matches against
297 * the given device criteria.
299 status = bm_search(BM_HANDLE_ROOT, criteria, &device_list);
300 if (ACPI_FAILURE(status)) {
301 return_ACPI_STATUS(status);
307 * For each match, execute the driver's Notify() function to allow
308 * the driver to cleanup each device instance.
310 for (i = 0; i < device_list.count; i++) {
312 * Resolve the device handle.
314 status = bm_get_node(device_list.handles[i], 0, &node);
315 if (ACPI_FAILURE(status)) {
319 DEBUG_PRINT(ACPI_INFO, ("Unregistering driver for device [0x%02x].\n", node->device.handle));
321 /* Notify driver of device removal. */
322 status = node->driver.notify(BM_NOTIFY_DEVICE_REMOVED,
323 node->device.handle, &(node->driver.context));
325 node->device.flags &= ~BM_FLAGS_DRIVER_CONTROL;
327 MEMSET(&(node->driver), 0, sizeof(BM_DRIVER));
330 return_ACPI_STATUS(AE_OK);