Changes in uspace/srv/devmap/devmap.c [b72efe8:4ae90f9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
rb72efe8 r4ae90f9 37 37 38 38 #include <ipc/services.h> 39 #include < ns.h>39 #include <ipc/ns.h> 40 40 #include <async.h> 41 41 #include <stdio.h> … … 57 57 */ 58 58 typedef struct { 59 /** Link to drivers_list */59 /** Pointers to previous and next drivers in linked list */ 60 60 link_t drivers; 61 62 /** List of devices controlled by this driver */ 63 list_t devices; 64 65 /** Session asociated with this driver */ 66 async_sess_t *sess; 67 61 /** Pointer to the linked list of devices controlled by this driver */ 62 link_t devices; 63 /** Phone asociated with this driver */ 64 sysarg_t phone; 68 65 /** Device driver name */ 69 66 char *name; 70 71 67 /** Fibril mutex for list of devices owned by this driver */ 72 68 fibril_mutex_t devices_mutex; … … 77 73 */ 78 74 typedef struct { 79 /** Link to namespaces_list*/75 /** Pointer to the previous and next device in the list of all namespaces */ 80 76 link_t namespaces; 81 82 77 /** Unique namespace identifier */ 83 78 devmap_handle_t handle; 84 85 79 /** Namespace name */ 86 80 char *name; 87 88 81 /** Reference count */ 89 82 size_t refcnt; … … 94 87 */ 95 88 typedef struct { 96 /** Link to global list of devices (devices_list)*/89 /** Pointer to the previous and next device in the list of all devices */ 97 90 link_t devices; 98 /** Link to driver list of devices (devmap_driver_t.devices) */ 91 /** Pointer to the previous and next device in the list of devices 92 owned by one driver */ 99 93 link_t driver_devices; 100 94 /** Unique device identifier */ … … 224 218 static devmap_namespace_t *devmap_namespace_find_name(const char *name) 225 219 { 220 link_t *item; 221 226 222 assert(fibril_mutex_is_locked(&devices_list_mutex)); 227 223 228 list_foreach(namespaces_list, item) {224 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 229 225 devmap_namespace_t *namespace = 230 226 list_get_instance(item, devmap_namespace_t, namespaces); … … 243 239 static devmap_namespace_t *devmap_namespace_find_handle(devmap_handle_t handle) 244 240 { 241 link_t *item; 242 245 243 assert(fibril_mutex_is_locked(&devices_list_mutex)); 246 244 247 list_foreach(namespaces_list, item) {245 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 248 246 devmap_namespace_t *namespace = 249 247 list_get_instance(item, devmap_namespace_t, namespaces); … … 259 257 const char *name) 260 258 { 259 link_t *item; 260 261 261 assert(fibril_mutex_is_locked(&devices_list_mutex)); 262 262 263 list_foreach(devices_list, item) {263 for (item = devices_list.next; item != &devices_list; item = item->next) { 264 264 devmap_device_t *device = 265 265 list_get_instance(item, devmap_device_t, devices); … … 279 279 static devmap_device_t *devmap_device_find_handle(devmap_handle_t handle) 280 280 { 281 link_t *item; 282 281 283 assert(fibril_mutex_is_locked(&devices_list_mutex)); 282 284 283 list_foreach(devices_list, item) {285 for (item = devices_list.next; item != &devices_list; item = item->next) { 284 286 devmap_device_t *device = 285 287 list_get_instance(item, devmap_device_t, devices); … … 403 405 * Create connection to the driver 404 406 */ 405 driver->sess = async_callback_receive(EXCHANGE_SERIALIZE); 406 if (!driver->sess) { 407 ipc_call_t call; 408 ipc_callid_t callid = async_get_call(&call); 409 410 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 407 411 free(driver->name); 408 412 free(driver); 413 async_answer_0(callid, ENOTSUP); 409 414 async_answer_0(iid, ENOTSUP); 410 415 return NULL; 411 416 } 417 418 driver->phone = IPC_GET_ARG5(call); 419 async_answer_0(callid, EOK); 412 420 413 421 /* … … 454 462 fibril_mutex_lock(&drivers_list_mutex); 455 463 456 if (driver-> sess)457 async_hangup(driver-> sess);464 if (driver->phone != 0) 465 async_hangup(driver->phone); 458 466 459 467 /* Remove it from list of drivers */ … … 464 472 fibril_mutex_lock(&driver->devices_mutex); 465 473 466 while (!list_empty(&driver->devices)) { 467 devmap_device_t *device = list_get_instance( 468 list_first(&driver->devices), devmap_device_t, 469 driver_devices); 474 while (!list_empty(&(driver->devices))) { 475 devmap_device_t *device = list_get_instance(driver->devices.next, 476 devmap_device_t, driver_devices); 470 477 devmap_device_unregister_core(device); 471 478 } … … 600 607 devmap_device_t *dev = devmap_device_find_handle(handle); 601 608 602 if ((dev == NULL) || (dev->driver == NULL) || ( !dev->driver->sess)) {609 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 603 610 fibril_mutex_unlock(&devices_list_mutex); 604 611 async_answer_0(callid, ENOENT); … … 606 613 } 607 614 608 async_exch_t *exch = async_exchange_begin(dev->driver->sess);609 610 if (dev->forward_interface == 0)611 async_forward_fast(callid, exch, dev->handle, 0, 0,IPC_FF_NONE);612 else613 async_forward_fast(callid, exch, dev->forward_interface,614 dev-> handle, 0, IPC_FF_NONE);615 616 async_exchange_end(exch);615 if (dev->forward_interface == 0) { 616 async_forward_fast(callid, dev->driver->phone, 617 dev->handle, 0, 0, 618 IPC_FF_NONE); 619 } else { 620 async_forward_fast(callid, dev->driver->phone, 621 dev->forward_interface, dev->handle, 0, 622 IPC_FF_NONE); 623 } 617 624 618 625 fibril_mutex_unlock(&devices_list_mutex); … … 807 814 } 808 815 816 link_t *item; 809 817 size_t pos = 0; 810 list_foreach(namespaces_list, item) { 818 for (item = namespaces_list.next; item != &namespaces_list; 819 item = item->next) { 811 820 devmap_namespace_t *namespace = 812 821 list_get_instance(item, devmap_namespace_t, namespaces); … … 871 880 } 872 881 882 link_t *item; 873 883 size_t pos = 0; 874 list_foreach(devices_list, item) {884 for (item = devices_list.next; item != &devices_list; item = item->next) { 875 885 devmap_device_t *device = 876 886 list_get_instance(item, devmap_device_t, devices); … … 1019 1029 return; 1020 1030 1021 while (true) { 1031 bool cont = true; 1032 while (cont) { 1022 1033 ipc_call_t call; 1023 1034 ipc_callid_t callid = async_get_call(&call); 1024 1035 1025 if (!IPC_GET_IMETHOD(call))1026 break;1027 1028 1036 switch (IPC_GET_IMETHOD(call)) { 1037 case IPC_M_PHONE_HUNGUP: 1038 cont = false; 1039 continue; 1029 1040 case DEVMAP_DRIVER_UNREGISTER: 1030 1041 if (NULL == driver) … … 1069 1080 async_answer_0(iid, EOK); 1070 1081 1071 while (true) { 1082 bool cont = true; 1083 while (cont) { 1072 1084 ipc_call_t call; 1073 1085 ipc_callid_t callid = async_get_call(&call); 1074 1086 1075 if (!IPC_GET_IMETHOD(call))1076 break;1077 1078 1087 switch (IPC_GET_IMETHOD(call)) { 1088 case IPC_M_PHONE_HUNGUP: 1089 cont = false; 1090 continue; 1079 1091 case DEVMAP_DEVICE_GET_HANDLE: 1080 1092 devmap_device_get_handle(callid, &call); … … 1113 1125 * 1114 1126 */ 1115 static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall , void *arg)1127 static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall) 1116 1128 { 1117 1129 /* Select interface */
Note:
See TracChangeset
for help on using the changeset viewer.