[c16cf62] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * @defgroup libdrv generic device driver support.
|
---|
| 31 | * @brief HelenOS generic device driver support.
|
---|
| 32 | * @{
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | /** @file
|
---|
| 36 | */
|
---|
[52b7b1bb] | 37 |
|
---|
[c16cf62] | 38 | #include <assert.h>
|
---|
| 39 | #include <ipc/services.h>
|
---|
| 40 | #include <ipc/ns.h>
|
---|
| 41 | #include <async.h>
|
---|
| 42 | #include <stdio.h>
|
---|
| 43 | #include <errno.h>
|
---|
| 44 | #include <bool.h>
|
---|
| 45 | #include <fibril_synch.h>
|
---|
| 46 | #include <stdlib.h>
|
---|
[c47e1a8] | 47 | #include <str.h>
|
---|
[c16cf62] | 48 | #include <ctype.h>
|
---|
[66babbd] | 49 | #include <errno.h>
|
---|
[c16cf62] | 50 |
|
---|
[084ff99] | 51 | #include <ipc/driver.h>
|
---|
[c16cf62] | 52 |
|
---|
| 53 | #include "driver.h"
|
---|
| 54 |
|
---|
[7a252ec8] | 55 | /* driver structure */
|
---|
[7f8b581] | 56 |
|
---|
[c16cf62] | 57 | static driver_t *driver;
|
---|
[7f8b581] | 58 |
|
---|
[7a252ec8] | 59 | /* devices */
|
---|
[7f8b581] | 60 |
|
---|
[084ff99] | 61 | LIST_INITIALIZE(devices);
|
---|
[9a66bc2e] | 62 | FIBRIL_MUTEX_INITIALIZE(devices_mutex);
|
---|
[084ff99] | 63 |
|
---|
[7a252ec8] | 64 | /* interrupts */
|
---|
[7f8b581] | 65 |
|
---|
| 66 | static interrupt_context_list_t interrupt_contexts;
|
---|
| 67 |
|
---|
| 68 | static irq_cmd_t default_cmds[] = {
|
---|
| 69 | {
|
---|
| 70 | .cmd = CMD_ACCEPT
|
---|
| 71 | }
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | static irq_code_t default_pseudocode = {
|
---|
| 75 | sizeof(default_cmds) / sizeof(irq_cmd_t),
|
---|
| 76 | default_cmds
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[7a252ec8] | 81 | {
|
---|
[7f8b581] | 82 | int id = (int)IPC_GET_METHOD(*icall);
|
---|
[7a252ec8] | 83 | interrupt_context_t *ctx;
|
---|
| 84 |
|
---|
| 85 | ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
|
---|
| 86 | if (NULL != ctx && NULL != ctx->handler)
|
---|
| 87 | (*ctx->handler)(ctx->dev, iid, icall);
|
---|
[7f8b581] | 88 | }
|
---|
| 89 |
|
---|
[7a252ec8] | 90 | int
|
---|
| 91 | register_interrupt_handler(device_t *dev, int irq, interrupt_handler_t *handler,
|
---|
| 92 | irq_code_t *pseudocode)
|
---|
[7f8b581] | 93 | {
|
---|
| 94 | interrupt_context_t *ctx = create_interrupt_context();
|
---|
| 95 |
|
---|
| 96 | ctx->dev = dev;
|
---|
| 97 | ctx->irq = irq;
|
---|
| 98 | ctx->handler = handler;
|
---|
| 99 |
|
---|
| 100 | add_interrupt_context(&interrupt_contexts, ctx);
|
---|
| 101 |
|
---|
[7a252ec8] | 102 | if (NULL == pseudocode)
|
---|
[7f8b581] | 103 | pseudocode = &default_pseudocode;
|
---|
| 104 |
|
---|
| 105 | int res = ipc_register_irq(irq, dev->handle, ctx->id, pseudocode);
|
---|
| 106 | if (0 != res) {
|
---|
| 107 | remove_interrupt_context(&interrupt_contexts, ctx);
|
---|
| 108 | delete_interrupt_context(ctx);
|
---|
| 109 | }
|
---|
[7a252ec8] | 110 |
|
---|
| 111 | return res;
|
---|
[7f8b581] | 112 | }
|
---|
| 113 |
|
---|
| 114 | int unregister_interrupt_handler(device_t *dev, int irq)
|
---|
| 115 | {
|
---|
[7a252ec8] | 116 | interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
|
---|
| 117 | dev, irq);
|
---|
[7f8b581] | 118 | int res = ipc_unregister_irq(irq, dev->handle);
|
---|
[7a252ec8] | 119 |
|
---|
[7f8b581] | 120 | if (NULL != ctx) {
|
---|
| 121 | remove_interrupt_context(&interrupt_contexts, ctx);
|
---|
[7a252ec8] | 122 | delete_interrupt_context(ctx);
|
---|
[7f8b581] | 123 | }
|
---|
| 124 | return res;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[9a66bc2e] | 127 | static void add_to_devices_list(device_t *dev)
|
---|
| 128 | {
|
---|
| 129 | fibril_mutex_lock(&devices_mutex);
|
---|
| 130 | list_append(&dev->link, &devices);
|
---|
| 131 | fibril_mutex_unlock(&devices_mutex);
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | static void remove_from_devices_list(device_t *dev)
|
---|
| 135 | {
|
---|
| 136 | fibril_mutex_lock(&devices_mutex);
|
---|
[5af21c5] | 137 | list_remove(&dev->link);
|
---|
[9a66bc2e] | 138 | fibril_mutex_unlock(&devices_mutex);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[0b5a4131] | 141 | static device_t * driver_get_device(link_t *devices, devman_handle_t handle)
|
---|
[52b7b1bb] | 142 | {
|
---|
[a1769ee] | 143 | device_t *dev = NULL;
|
---|
[9a66bc2e] | 144 |
|
---|
[7a252ec8] | 145 | fibril_mutex_lock(&devices_mutex);
|
---|
[a1769ee] | 146 | link_t *link = devices->next;
|
---|
| 147 | while (link != devices) {
|
---|
| 148 | dev = list_get_instance(link, device_t, link);
|
---|
| 149 | if (handle == dev->handle) {
|
---|
[9a66bc2e] | 150 | fibril_mutex_unlock(&devices_mutex);
|
---|
[a1769ee] | 151 | return dev;
|
---|
| 152 | }
|
---|
[9a66bc2e] | 153 | link = link->next;
|
---|
[a1769ee] | 154 | }
|
---|
[9a66bc2e] | 155 | fibril_mutex_unlock(&devices_mutex);
|
---|
[52b7b1bb] | 156 |
|
---|
[a1769ee] | 157 | return NULL;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[52b7b1bb] | 160 | static void driver_add_device(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[084ff99] | 161 | {
|
---|
[df747b9c] | 162 | char *dev_name = NULL;
|
---|
| 163 | int res = EOK;
|
---|
[9a66bc2e] | 164 |
|
---|
[0b5a4131] | 165 | devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
|
---|
[0d6915f] | 166 | devman_handle_t parent_dev_handle = IPC_GET_ARG2(*icall);
|
---|
| 167 |
|
---|
[5af21c5] | 168 | device_t *dev = create_device();
|
---|
[084ff99] | 169 | dev->handle = dev_handle;
|
---|
[df747b9c] | 170 |
|
---|
[7a252ec8] | 171 | async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
|
---|
[df747b9c] | 172 | dev->name = dev_name;
|
---|
| 173 |
|
---|
[7a252ec8] | 174 | add_to_devices_list(dev);
|
---|
[0d6915f] | 175 | dev->parent = driver_get_device(&devices, parent_dev_handle);
|
---|
| 176 |
|
---|
[df747b9c] | 177 | res = driver->driver_ops->add_device(dev);
|
---|
| 178 | if (0 == res) {
|
---|
[7a252ec8] | 179 | printf("%s: new device with handle = %x was added.\n",
|
---|
| 180 | driver->name, dev_handle);
|
---|
[9a66bc2e] | 181 | } else {
|
---|
[7a252ec8] | 182 | printf("%s: failed to add a new device with handle = %d.\n",
|
---|
| 183 | driver->name, dev_handle);
|
---|
[9a66bc2e] | 184 | remove_from_devices_list(dev);
|
---|
[7a252ec8] | 185 | delete_device(dev);
|
---|
[084ff99] | 186 | }
|
---|
[df747b9c] | 187 |
|
---|
| 188 | ipc_answer_0(iid, res);
|
---|
[084ff99] | 189 | }
|
---|
[c16cf62] | 190 |
|
---|
| 191 | static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 192 | {
|
---|
| 193 | /* Accept connection */
|
---|
| 194 | ipc_answer_0(iid, EOK);
|
---|
[52b7b1bb] | 195 |
|
---|
[c16cf62] | 196 | bool cont = true;
|
---|
| 197 | while (cont) {
|
---|
| 198 | ipc_call_t call;
|
---|
| 199 | ipc_callid_t callid = async_get_call(&call);
|
---|
[52b7b1bb] | 200 |
|
---|
[c16cf62] | 201 | switch (IPC_GET_METHOD(call)) {
|
---|
| 202 | case IPC_M_PHONE_HUNGUP:
|
---|
| 203 | cont = false;
|
---|
| 204 | continue;
|
---|
| 205 | case DRIVER_ADD_DEVICE:
|
---|
[084ff99] | 206 | driver_add_device(callid, &call);
|
---|
[c16cf62] | 207 | break;
|
---|
| 208 | default:
|
---|
| 209 | if (!(callid & IPC_CALLID_NOTIFICATION))
|
---|
| 210 | ipc_answer_0(callid, ENOENT);
|
---|
| 211 | }
|
---|
[52b7b1bb] | 212 | }
|
---|
[c16cf62] | 213 | }
|
---|
| 214 |
|
---|
[52b7b1bb] | 215 | /**
|
---|
[a1769ee] | 216 | * Generic client connection handler both for applications and drivers.
|
---|
[52b7b1bb] | 217 | *
|
---|
[7a252ec8] | 218 | * @param drv True for driver client, false for other clients
|
---|
| 219 | * (applications, services etc.).
|
---|
[a1769ee] | 220 | */
|
---|
[9a66bc2e] | 221 | static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
|
---|
[52b7b1bb] | 222 | {
|
---|
[7a252ec8] | 223 | /*
|
---|
| 224 | * Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of
|
---|
| 225 | * the device to which the client connected.
|
---|
| 226 | */
|
---|
[0b5a4131] | 227 | devman_handle_t handle = IPC_GET_ARG2(*icall);
|
---|
[a1769ee] | 228 | device_t *dev = driver_get_device(&devices, handle);
|
---|
[52b7b1bb] | 229 |
|
---|
[a1769ee] | 230 | if (dev == NULL) {
|
---|
[7a252ec8] | 231 | printf("%s: driver_connection_gen error - no device with handle"
|
---|
| 232 | " %x was found.\n", driver->name, handle);
|
---|
[a1769ee] | 233 | ipc_answer_0(iid, ENOENT);
|
---|
| 234 | return;
|
---|
| 235 | }
|
---|
[5cd136ab] | 236 |
|
---|
| 237 |
|
---|
[7a252ec8] | 238 | /*
|
---|
| 239 | * TODO - if the client is not a driver, check whether it is allowed to
|
---|
| 240 | * use the device.
|
---|
| 241 | */
|
---|
[a1769ee] | 242 |
|
---|
[25a7e11d] | 243 | int ret = EOK;
|
---|
[7a252ec8] | 244 | /* open the device */
|
---|
| 245 | if (NULL != dev->ops && NULL != dev->ops->open)
|
---|
[5159ae9] | 246 | ret = (*dev->ops->open)(dev);
|
---|
[a1769ee] | 247 |
|
---|
[25a7e11d] | 248 | ipc_answer_0(iid, ret);
|
---|
[7a252ec8] | 249 | if (EOK != ret)
|
---|
[a6e54c5d] | 250 | return;
|
---|
[52b7b1bb] | 251 |
|
---|
[a1769ee] | 252 | while (1) {
|
---|
| 253 | ipc_callid_t callid;
|
---|
| 254 | ipc_call_t call;
|
---|
| 255 | callid = async_get_call(&call);
|
---|
| 256 | ipcarg_t method = IPC_GET_METHOD(call);
|
---|
[3843ecb] | 257 | int iface_idx;
|
---|
| 258 |
|
---|
[a1769ee] | 259 | switch (method) {
|
---|
[25a7e11d] | 260 | case IPC_M_PHONE_HUNGUP:
|
---|
[7a252ec8] | 261 | /* close the device */
|
---|
| 262 | if (NULL != dev->ops && NULL != dev->ops->close)
|
---|
[5159ae9] | 263 | (*dev->ops->close)(dev);
|
---|
[a1769ee] | 264 | ipc_answer_0(callid, EOK);
|
---|
| 265 | return;
|
---|
[3843ecb] | 266 | default:
|
---|
[7a252ec8] | 267 | /* convert ipc interface id to interface index */
|
---|
[3843ecb] | 268 |
|
---|
| 269 | iface_idx = DEV_IFACE_IDX(method);
|
---|
| 270 |
|
---|
| 271 | if (!is_valid_iface_idx(iface_idx)) {
|
---|
[7a252ec8] | 272 | remote_handler_t *default_handler =
|
---|
| 273 | device_get_default_handler(dev);
|
---|
| 274 | if (NULL != default_handler) {
|
---|
[08d9525a] | 275 | (*default_handler)(dev, callid, &call);
|
---|
| 276 | break;
|
---|
| 277 | }
|
---|
[7a252ec8] | 278 | /*
|
---|
| 279 | * This is not device's interface and the
|
---|
| 280 | * default handler is not provided.
|
---|
| 281 | */
|
---|
| 282 | printf("%s: driver_connection_gen error - "
|
---|
| 283 | "invalid interface id %d.",
|
---|
| 284 | driver->name, iface_idx);
|
---|
[52b7b1bb] | 285 | ipc_answer_0(callid, ENOTSUP);
|
---|
| 286 | break;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
[7a252ec8] | 289 | /* calling one of the device's interfaces */
|
---|
[52b7b1bb] | 290 |
|
---|
[7a252ec8] | 291 | /* get the device interface structure */
|
---|
[3843ecb] | 292 | void *iface = device_get_iface(dev, iface_idx);
|
---|
[52b7b1bb] | 293 | if (NULL == iface) {
|
---|
[7a252ec8] | 294 | printf("%s: driver_connection_gen error - ",
|
---|
| 295 | driver->name);
|
---|
| 296 | printf("device with handle %d has no interface "
|
---|
| 297 | "with id %d.\n", handle, iface_idx);
|
---|
[a1769ee] | 298 | ipc_answer_0(callid, ENOTSUP);
|
---|
[52b7b1bb] | 299 | break;
|
---|
[a1769ee] | 300 | }
|
---|
[52b7b1bb] | 301 |
|
---|
[7a252ec8] | 302 | /*
|
---|
| 303 | * Get the corresponding interface for remote request
|
---|
| 304 | * handling ("remote interface").
|
---|
| 305 | */
|
---|
[3843ecb] | 306 | remote_iface_t* rem_iface = get_remote_iface(iface_idx);
|
---|
[52b7b1bb] | 307 | assert(NULL != rem_iface);
|
---|
| 308 |
|
---|
[7a252ec8] | 309 | /* get the method of the remote interface */
|
---|
[52b7b1bb] | 310 | ipcarg_t iface_method_idx = IPC_GET_ARG1(call);
|
---|
[7a252ec8] | 311 | remote_iface_func_ptr_t iface_method_ptr =
|
---|
| 312 | get_remote_method(rem_iface, iface_method_idx);
|
---|
[52b7b1bb] | 313 | if (NULL == iface_method_ptr) {
|
---|
| 314 | // the interface has not such method
|
---|
[7a252ec8] | 315 | printf("%s: driver_connection_gen error - "
|
---|
| 316 | "invalid interface method.", driver->name);
|
---|
[52b7b1bb] | 317 | ipc_answer_0(callid, ENOTSUP);
|
---|
| 318 | break;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[7a252ec8] | 321 | /*
|
---|
| 322 | * Call the remote interface's method, which will
|
---|
| 323 | * receive parameters from the remote client and it will
|
---|
| 324 | * pass it to the corresponding local interface method
|
---|
| 325 | * associated with the device by its driver.
|
---|
| 326 | */
|
---|
[52b7b1bb] | 327 | (*iface_method_ptr)(dev, iface, callid, &call);
|
---|
[a1769ee] | 328 | break;
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[c16cf62] | 333 | static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 334 | {
|
---|
[52b7b1bb] | 335 | driver_connection_gen(iid, icall, true);
|
---|
[c16cf62] | 336 | }
|
---|
| 337 |
|
---|
| 338 | static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 339 | {
|
---|
[52b7b1bb] | 340 | driver_connection_gen(iid, icall, false);
|
---|
[c16cf62] | 341 | }
|
---|
| 342 |
|
---|
| 343 |
|
---|
[7a252ec8] | 344 | /** Function for handling connections to device driver. */
|
---|
[c16cf62] | 345 | static void driver_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 346 | {
|
---|
| 347 | /* Select interface */
|
---|
| 348 | switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
|
---|
| 349 | case DRIVER_DEVMAN:
|
---|
[7a252ec8] | 350 | /* handle PnP events from device manager */
|
---|
[c16cf62] | 351 | driver_connection_devman(iid, icall);
|
---|
| 352 | break;
|
---|
| 353 | case DRIVER_DRIVER:
|
---|
[7a252ec8] | 354 | /* handle request from drivers of child devices */
|
---|
[c16cf62] | 355 | driver_connection_driver(iid, icall);
|
---|
| 356 | break;
|
---|
| 357 | case DRIVER_CLIENT:
|
---|
[7a252ec8] | 358 | /* handle requests from client applications */
|
---|
[c16cf62] | 359 | driver_connection_client(iid, icall);
|
---|
| 360 | break;
|
---|
| 361 |
|
---|
| 362 | default:
|
---|
[52b7b1bb] | 363 | /* No such interface */
|
---|
[c16cf62] | 364 | ipc_answer_0(iid, ENOENT);
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 |
|
---|
[df747b9c] | 368 | int child_device_register(device_t *child, device_t *parent)
|
---|
[7707954] | 369 | {
|
---|
[bda60d9] | 370 | assert(NULL != child->name);
|
---|
[52b7b1bb] | 371 |
|
---|
[df747b9c] | 372 | int res;
|
---|
| 373 |
|
---|
[9a66bc2e] | 374 | add_to_devices_list(child);
|
---|
[7a252ec8] | 375 | res = devman_child_device_register(child->name, &child->match_ids,
|
---|
| 376 | parent->handle, &child->handle);
|
---|
| 377 | if (EOK == res)
|
---|
[df747b9c] | 378 | return res;
|
---|
[9a66bc2e] | 379 | remove_from_devices_list(child);
|
---|
[df747b9c] | 380 | return res;
|
---|
[7707954] | 381 | }
|
---|
| 382 |
|
---|
[0ca16307] | 383 | /** Wrapper for child_device_register for devices with single match id.
|
---|
| 384 | *
|
---|
| 385 | * @param parent Parent device.
|
---|
| 386 | * @param child_name Child device name.
|
---|
| 387 | * @param child_match_id Child device match id.
|
---|
| 388 | * @param child_match_score Child device match score.
|
---|
| 389 | * @return Error code.
|
---|
| 390 | */
|
---|
| 391 | int child_device_register_wrapper(device_t *parent, const char *child_name,
|
---|
| 392 | const char *child_match_id, int child_match_score)
|
---|
| 393 | {
|
---|
| 394 | device_t *child = NULL;
|
---|
| 395 | match_id_t *match_id = NULL;
|
---|
| 396 | int rc;
|
---|
| 397 |
|
---|
| 398 | child = create_device();
|
---|
| 399 | if (child == NULL) {
|
---|
| 400 | rc = ENOMEM;
|
---|
| 401 | goto failure;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | child->name = child_name;
|
---|
| 405 |
|
---|
| 406 | match_id = create_match_id();
|
---|
| 407 | if (match_id == NULL) {
|
---|
| 408 | rc = ENOMEM;
|
---|
| 409 | goto failure;
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | match_id->id = child_match_id;
|
---|
| 413 | match_id->score = child_match_score;
|
---|
| 414 | add_match_id(&child->match_ids, match_id);
|
---|
| 415 |
|
---|
| 416 | rc = child_device_register(child, parent);
|
---|
| 417 | if (EOK != rc)
|
---|
| 418 | goto failure;
|
---|
| 419 |
|
---|
| 420 | goto leave;
|
---|
| 421 |
|
---|
| 422 | failure:
|
---|
| 423 | if (match_id != NULL) {
|
---|
| 424 | match_id->id = NULL;
|
---|
| 425 | delete_match_id(match_id);
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | if (child != NULL) {
|
---|
| 429 | child->name = NULL;
|
---|
| 430 | delete_device(child);
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | leave:
|
---|
| 434 | return rc;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
[52b7b1bb] | 437 | int driver_main(driver_t *drv)
|
---|
[c16cf62] | 438 | {
|
---|
[7a252ec8] | 439 | /*
|
---|
| 440 | * Remember the driver structure - driver_ops will be called by generic
|
---|
| 441 | * handler for incoming connections.
|
---|
| 442 | */
|
---|
[c16cf62] | 443 | driver = drv;
|
---|
[52b7b1bb] | 444 |
|
---|
[7a252ec8] | 445 | /* Initialize the list of interrupt contexts. */
|
---|
[7f8b581] | 446 | init_interrupt_context_list(&interrupt_contexts);
|
---|
| 447 |
|
---|
[7a252ec8] | 448 | /* Set generic interrupt handler. */
|
---|
[7f8b581] | 449 | async_set_interrupt_received(driver_irq_handler);
|
---|
| 450 |
|
---|
[7a252ec8] | 451 | /*
|
---|
| 452 | * Register driver by device manager with generic handler for incoming
|
---|
| 453 | * connections.
|
---|
| 454 | */
|
---|
[52b7b1bb] | 455 | devman_driver_register(driver->name, driver_connection);
|
---|
[c16cf62] | 456 |
|
---|
| 457 | async_manager();
|
---|
| 458 |
|
---|
[7a252ec8] | 459 | /* Never reached. */
|
---|
[52b7b1bb] | 460 | return 0;
|
---|
[c16cf62] | 461 | }
|
---|
| 462 |
|
---|
| 463 | /**
|
---|
| 464 | * @}
|
---|
[52b7b1bb] | 465 | */
|
---|