Changes in uspace/lib/drv/generic/driver.c [58563585:8820544] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/driver.c
r58563585 r8820544 49 49 #include <str_error.h> 50 50 #include <ctype.h> 51 #include <errno.h> 51 52 #include <inttypes.h> 52 53 #include <devman.h> 54 55 #include <ipc/driver.h> 53 56 54 57 #include "dev_iface.h" … … 120 123 devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall); 121 124 122 char *dev_name = NULL;123 int rc = async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);124 if (rc != EOK) {125 async_answer_0(iid, rc);126 return;127 }128 129 125 ddf_dev_t *dev = create_device(); 130 if (!dev) {131 free(dev_name);132 async_answer_0(iid, ENOMEM);133 return;134 }135 126 136 127 /* Add one reference that will be dropped by driver_dev_remove() */ 137 128 dev_add_ref(dev); 138 129 dev->handle = dev_handle; 130 131 char *dev_name = NULL; 132 async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0); 139 133 dev->name = dev_name; 140 134 … … 284 278 } 285 279 286 static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall, 287 void *arg) 280 static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall) 288 281 { 289 282 /* Accept connection */ … … 335 328 fibril_mutex_lock(&functions_mutex); 336 329 ddf_fun_t *fun = driver_get_function(handle); 337 if (fun != NULL)338 fun_add_ref(fun);339 330 fibril_mutex_unlock(&functions_mutex); 331 /* XXX Need a lock on fun */ 340 332 341 333 if (fun == NULL) { … … 349 341 /* Driver has a custom connection handler. */ 350 342 (*fun->conn_handler)(iid, icall, (void *)fun); 351 fun_del_ref(fun);352 343 return; 353 344 } … … 364 355 365 356 async_answer_0(iid, ret); 366 if (ret != EOK) { 367 fun_del_ref(fun); 357 if (ret != EOK) 368 358 return; 369 }370 359 371 360 while (true) { … … 380 369 (*fun->ops->close)(fun); 381 370 async_answer_0(callid, EOK); 382 fun_del_ref(fun);383 371 return; 384 372 } … … 448 436 } 449 437 450 static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall, 451 void *arg) 438 static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall) 452 439 { 453 440 driver_connection_gen(iid, icall, true); 454 441 } 455 442 456 static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall, 457 void *arg) 443 static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall) 458 444 { 459 445 driver_connection_gen(iid, icall, false); 446 } 447 448 /** Function for handling connections to device driver. */ 449 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 450 { 451 sysarg_t conn_type; 452 453 if (iid == 0) { 454 /* Callback connection from devman */ 455 /* XXX Use separate handler for this type of connection */ 456 conn_type = DRIVER_DEVMAN; 457 } else { 458 conn_type = IPC_GET_ARG1(*icall); 459 } 460 461 /* Select interface */ 462 switch (conn_type) { 463 case DRIVER_DEVMAN: 464 /* Handle request from device manager */ 465 driver_connection_devman(iid, icall); 466 break; 467 case DRIVER_DRIVER: 468 /* Handle request from drivers of child devices */ 469 driver_connection_driver(iid, icall); 470 break; 471 case DRIVER_CLIENT: 472 /* Handle request from client applications */ 473 driver_connection_client(iid, icall); 474 break; 475 default: 476 /* No such interface */ 477 async_answer_0(iid, ENOENT); 478 } 460 479 } 461 480 … … 503 522 if (dev->driver_data != NULL) 504 523 free(dev->driver_data); 505 if (dev->name)506 free(dev->name);507 524 free(dev); 508 525 } … … 603 620 * The session will be automatically closed when @a dev is destroyed. 604 621 * 605 * @param dev Device 606 * 607 * @return New session or NULL if session could not be created 608 * 609 */ 610 async_sess_t *ddf_dev_parent_sess_create(ddf_dev_t *dev) 622 * @param dev Device 623 * @param mgmt Exchange management style 624 * @return New session or NULL if session could not be created 625 */ 626 async_sess_t *ddf_dev_parent_sess_create(ddf_dev_t *dev, exch_mgmt_t mgmt) 611 627 { 612 628 assert(dev->parent_sess == NULL); 613 dev->parent_sess = devman_parent_device_connect( dev->handle,629 dev->parent_sess = devman_parent_device_connect(mgmt, dev->handle, 614 630 IPC_FLAG_BLOCKING); 615 631 … … 786 802 assert(fun->bound == false); 787 803 assert(fun->name != NULL); 788 assert(fun->dev != NULL);789 804 790 805 add_to_functions_list(fun); … … 891 906 892 907 /** Set function ops. */ 893 void ddf_fun_set_ops(ddf_fun_t *fun, constddf_dev_ops_t *dev_ops)908 void ddf_fun_set_ops(ddf_fun_t *fun, ddf_dev_ops_t *dev_ops) 894 909 { 895 910 assert(fun->conn_handler == NULL); … … 901 916 * This allows handling connections the non-devman way. 902 917 */ 903 void ddf_fun_set_conn_handler(ddf_fun_t *fun, async_ port_handler_t conn)918 void ddf_fun_set_conn_handler(ddf_fun_t *fun, async_client_conn_t conn) 904 919 { 905 920 assert(fun->ops == NULL); … … 940 955 * incoming connections. 941 956 */ 942 port_id_t port; 943 int rc = async_create_port(INTERFACE_DDF_DRIVER, driver_connection_driver, 944 NULL, &port); 945 if (rc != EOK) 946 return rc; 947 948 rc = async_create_port(INTERFACE_DDF_DEVMAN, driver_connection_devman, 949 NULL, &port); 950 if (rc != EOK) 951 return rc; 952 953 async_set_fallback_port_handler(driver_connection_client, NULL); 954 955 rc = devman_driver_register(driver->name); 957 async_set_client_connection(driver_connection); 958 int rc = devman_driver_register(driver->name); 956 959 if (rc != EOK) { 957 960 printf("Error: Failed to register driver with device manager " 958 "(%s).\n", (rc == EEXIST ) ? "driver already started" :961 "(%s).\n", (rc == EEXISTS) ? "driver already started" : 959 962 str_error(rc)); 960 963
Note:
See TracChangeset
for help on using the changeset viewer.