Changeset 36f2b3e in mainline for uspace/lib/drv/generic/driver.c
- Timestamp:
- 2011-01-09T20:14:03Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 97adec8
- Parents:
- d35ac1d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/driver.c
rd35ac1d r36f2b3e 54 54 #include "driver.h" 55 55 56 /* driver structure */ 57 56 /** Driver structure */ 58 57 static driver_t *driver; 59 58 60 /* devices */ 61 59 /** Devices */ 62 60 LIST_INITIALIZE(devices); 63 61 FIBRIL_MUTEX_INITIALIZE(devices_mutex); 64 62 65 /* interrupts */ 66 63 /** Interrupts */ 67 64 static interrupt_context_list_t interrupt_contexts; 68 65 … … 85 82 86 83 ctx = find_interrupt_context_by_id(&interrupt_contexts, id); 87 if ( NULL != ctx && NULL != ctx->handler)84 if (ctx != NULL && ctx->handler != NULL) 88 85 (*ctx->handler)(ctx->dev, iid, icall); 89 86 } … … 101 98 add_interrupt_context(&interrupt_contexts, ctx); 102 99 103 if ( NULL == pseudocode)100 if (pseudocode == NULL) 104 101 pseudocode = &default_pseudocode; 105 102 106 103 int res = ipc_register_irq(irq, dev->handle, ctx->id, pseudocode); 107 if ( 0 != res) {104 if (res != EOK) { 108 105 remove_interrupt_context(&interrupt_contexts, ctx); 109 106 delete_interrupt_context(ctx); … … 118 115 dev, irq); 119 116 int res = ipc_unregister_irq(irq, dev->handle); 120 121 if ( NULL != ctx) {117 118 if (ctx != NULL) { 122 119 remove_interrupt_context(&interrupt_contexts, ctx); 123 120 delete_interrupt_context(ctx); 124 121 } 122 125 123 return res; 126 124 } … … 146 144 fibril_mutex_lock(&devices_mutex); 147 145 link_t *link = devices->next; 146 148 147 while (link != devices) { 149 148 dev = list_get_instance(link, device_t, link); 150 if ( handle == dev->handle) {149 if (dev->handle == handle) { 151 150 fibril_mutex_unlock(&devices_mutex); 152 151 return dev; … … 154 153 link = link->next; 155 154 } 155 156 156 fibril_mutex_unlock(&devices_mutex); 157 157 158 158 return NULL; 159 159 } … … 162 162 { 163 163 char *dev_name = NULL; 164 int res = EOK;164 int res; 165 165 166 166 devman_handle_t dev_handle = IPC_GET_ARG1(*icall); … … 177 177 178 178 res = driver->driver_ops->add_device(dev); 179 if (res == 0) {179 if (res == EOK) { 180 180 printf("%s: new device with handle=%" PRIun " was added.\n", 181 181 driver->name, dev_handle); … … 194 194 /* Accept connection */ 195 195 ipc_answer_0(iid, EOK); 196 196 197 197 bool cont = true; 198 198 while (cont) { 199 199 ipc_call_t call; 200 200 ipc_callid_t callid = async_get_call(&call); 201 201 202 202 switch (IPC_GET_IMETHOD(call)) { 203 203 case IPC_M_PHONE_HUNGUP: … … 240 240 * use the device. 241 241 */ 242 242 243 243 int ret = EOK; 244 244 /* open the device */ 245 if ( NULL != dev->ops && NULL != dev->ops->open)245 if (dev->ops != NULL && dev->ops->open != NULL) 246 246 ret = (*dev->ops->open)(dev); 247 247 248 248 ipc_answer_0(iid, ret); 249 if ( EOK != ret)249 if (ret != EOK) 250 250 return; 251 251 252 252 while (1) { 253 253 ipc_callid_t callid; … … 260 260 case IPC_M_PHONE_HUNGUP: 261 261 /* close the device */ 262 if ( NULL != dev->ops && NULL != dev->ops->close)262 if (dev->ops != NULL && dev->ops->close != NULL) 263 263 (*dev->ops->close)(dev); 264 264 ipc_answer_0(callid, EOK); … … 272 272 remote_handler_t *default_handler = 273 273 device_get_default_handler(dev); 274 if ( NULL != default_handler) {274 if (default_handler != NULL) { 275 275 (*default_handler)(dev, callid, &call); 276 276 break; … … 286 286 break; 287 287 } 288 288 289 289 /* calling one of the device's interfaces */ 290 290 … … 299 299 break; 300 300 } 301 301 302 302 /* 303 303 * Get the corresponding interface for remote request … … 305 305 */ 306 306 remote_iface_t *rem_iface = get_remote_iface(iface_idx); 307 assert( NULL != rem_iface);308 307 assert(rem_iface != NULL); 308 309 309 /* get the method of the remote interface */ 310 310 sysarg_t iface_method_idx = IPC_GET_ARG1(call); 311 311 remote_iface_func_ptr_t iface_method_ptr = 312 312 get_remote_method(rem_iface, iface_method_idx); 313 if ( NULL == iface_method_ptr) {313 if (iface_method_ptr == NULL) { 314 314 // the interface has not such method 315 315 printf("%s: driver_connection_gen error - " … … 348 348 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) { 349 349 case DRIVER_DEVMAN: 350 /* handle PnP eventsfrom device manager */350 /* Handle request from device manager */ 351 351 driver_connection_devman(iid, icall); 352 352 break; 353 353 case DRIVER_DRIVER: 354 /* handle request from drivers of child devices */354 /* Handle request from drivers of child devices */ 355 355 driver_connection_driver(iid, icall); 356 356 break; 357 357 case DRIVER_CLIENT: 358 /* handle requestsfrom client applications */358 /* Handle request from client applications */ 359 359 driver_connection_client(iid, icall); 360 360 break; 361 362 361 default: 363 362 /* No such interface */ … … 368 367 int child_device_register(device_t *child, device_t *parent) 369 368 { 370 assert( NULL != child->name);371 369 assert(child->name != NULL); 370 372 371 int res; 373 372 … … 375 374 res = devman_child_device_register(child->name, &child->match_ids, 376 375 parent->handle, &child->handle); 377 if (EOK == res) 376 if (res != EOK) { 377 remove_from_devices_list(child); 378 378 return res; 379 remove_from_devices_list(child); 379 } 380 380 381 return res; 381 382 } … … 395 396 match_id_t *match_id = NULL; 396 397 int rc; 397 398 398 399 child = create_device(); 399 400 if (child == NULL) { … … 401 402 goto failure; 402 403 } 403 404 404 405 child->name = child_name; 405 406 406 407 match_id = create_match_id(); 407 408 if (match_id == NULL) { … … 409 410 goto failure; 410 411 } 411 412 412 413 match_id->id = child_match_id; 413 414 match_id->score = child_match_score; 414 415 add_match_id(&child->match_ids, match_id); 415 416 416 417 rc = child_device_register(child, parent); 417 if ( EOK != rc)418 if (rc != EOK) 418 419 goto failure; 419 420 420 421 return EOK; 421 422 422 423 failure: 423 424 if (match_id != NULL) { … … 425 426 delete_match_id(match_id); 426 427 } 427 428 428 429 if (child != NULL) { 429 430 child->name = NULL; 430 431 delete_device(child); 431 432 } 432 433 433 434 return rc; 434 435 } … … 441 442 */ 442 443 driver = drv; 443 444 444 445 /* Initialize the list of interrupt contexts. */ 445 446 init_interrupt_context_list(&interrupt_contexts); … … 453 454 */ 454 455 devman_driver_register(driver->name, driver_connection); 455 456 456 457 async_manager(); 457 458 458 459 /* Never reached. */ 459 460 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.