Changeset 91173333 in mainline
- Timestamp:
- 2018-01-13T21:36:13Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- edc51615
- Parents:
- 8a0c52a
- Location:
- uspace
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/usbmast/main.c
r8a0c52a r91173333 140 140 } 141 141 142 static int usbmast_device_removed(usb_device_t *dev)143 {144 // TODO: Implement me!145 return EOK;146 }147 148 142 /** Callback when new device is attached and recognized as a mass storage. 149 143 * … … 397 391 .device_add = usbmast_device_add, 398 392 .device_remove = usbmast_device_remove, 399 .device_removed = usbmast_device_removed,400 393 .device_gone = usbmast_device_gone, 401 394 }; -
uspace/drv/bus/usb/usbdiag/main.c
r8a0c52a r91173333 77 77 } 78 78 79 static int device_cleanup(usbdiag_dev_t *diag_dev) 80 { 81 /* TODO: Join some fibrils? */ 82 83 /* Free memory. */ 84 usbdiag_dev_destroy(diag_dev); 85 return EOK; 86 } 87 79 88 static int device_remove(usb_device_t *dev) 80 89 { … … 91 100 } 92 101 93 return EOK; 102 usb_log_info("Device '%s' removed.", usb_device_get_name(dev)); 103 return device_cleanup(diag_dev); 94 104 95 105 err: 96 106 return rc; 97 }98 99 static int device_cleanup(usbdiag_dev_t *diag_dev)100 {101 /* TODO: Join some fibrils? */102 103 /* Free memory. */104 usbdiag_dev_destroy(diag_dev);105 return EOK;106 }107 108 static int device_removed(usb_device_t *dev)109 {110 usb_log_info("Device '%s' removed.", usb_device_get_name(dev));111 112 usbdiag_dev_t *diag_dev = usb_device_to_usbdiag_dev(dev);113 return device_cleanup(diag_dev);114 107 } 115 108 … … 207 200 .device_add = device_add, 208 201 .device_remove = device_remove, 209 .device_removed = device_removed,210 202 .device_gone = device_gone, 211 203 .function_online = function_online, -
uspace/drv/bus/usb/usbflbk/main.c
r8a0c52a r91173333 69 69 { 70 70 assert(dev); 71 usb_log_info("Device '%s' will be removed.", usb_device_get_name(dev));72 return EOK;73 }74 75 static int usbfallback_device_removed(usb_device_t *dev)76 {77 assert(dev);78 71 usb_log_info("Device '%s' removed.", usb_device_get_name(dev)); 79 72 return EOK; … … 84 77 .device_add = usbfallback_device_add, 85 78 .device_remove = usbfallback_device_remove, 86 .device_removed = usbfallback_device_removed,87 79 .device_gone = usbfallback_device_gone, 88 80 }; -
uspace/drv/bus/usb/usbhub/main.c
r8a0c52a r91173333 49 49 .device_add = usb_hub_device_add, 50 50 .device_remove = usb_hub_device_remove, 51 .device_removed = usb_hub_device_removed,52 51 .device_gone = usb_hub_device_gone, 53 52 }; -
uspace/drv/bus/usb/usbhub/usbhub.c
r8a0c52a r91173333 99 99 100 100 /* Continue polling until the device is about to be removed. */ 101 return hub->running && !hub->poll_stop;101 return hub->running; 102 102 } 103 103 … … 123 123 hub_dev->pending_ops_count = 0; 124 124 hub_dev->running = false; 125 hub_dev->poll_stop = false;126 125 fibril_mutex_initialize(&hub_dev->pending_ops_mutex); 127 fibril_mutex_initialize(&hub_dev->poll_guard);128 126 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 129 fibril_condvar_initialize(&hub_dev->poll_cv);130 127 131 128 /* Set hub's first configuration. (There should be only one) */ … … 197 194 } 198 195 199 /**200 * Turn off power to all ports.201 *202 * @param usb_dev generic usb device information203 * @return error code204 */205 int usb_hub_device_remove(usb_device_t *usb_dev)206 {207 assert(usb_dev);208 usb_hub_dev_t *hub = usb_device_data_get(usb_dev);209 assert(hub);210 211 usb_log_info("(%p) USB hub will be removed.", hub);212 213 /* Instruct the hub to stop once endpoints are unregistered. */214 hub->poll_stop = true;215 return EOK;216 }217 218 196 static int usb_hub_cleanup(usb_hub_dev_t *hub) 219 197 { … … 241 219 } 242 220 243 int usb_hub_device_removed(usb_device_t *usb_dev) 221 /** 222 * Turn off power to all ports. 223 * 224 * @param usb_dev generic usb device information 225 * @return error code 226 */ 227 int usb_hub_device_remove(usb_device_t *usb_dev) 244 228 { 245 229 assert(usb_dev); … … 247 231 assert(hub); 248 232 249 usb_log_info("(%p) USB hub wasremoved, joining polling fibril.", hub);233 usb_log_info("(%p) USB hub removed, joining polling fibril.", hub); 250 234 251 235 /* Join polling fibril. */ 252 fibril_mutex_lock(&hub->poll_guard); 253 while (hub->running) 254 fibril_condvar_wait(&hub->poll_cv, &hub->poll_guard); 255 fibril_mutex_unlock(&hub->poll_guard); 256 236 usb_device_poll_join(hub->polling); 257 237 usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub); 258 238 … … 272 252 assert(hub); 273 253 274 hub->poll_stop = true;275 254 usb_log_info("(%p) USB hub gone, joining polling fibril.", hub); 276 255 277 256 /* Join polling fibril. */ 278 fibril_mutex_lock(&hub->poll_guard); 279 while (hub->running) 280 fibril_condvar_wait(&hub->poll_cv, &hub->poll_guard); 281 fibril_mutex_unlock(&hub->poll_guard); 257 usb_device_poll_join(hub->polling); 258 usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub); 282 259 283 260 /* Destroy hub. */ … … 592 569 fibril_mutex_unlock(&hub->pending_ops_mutex); 593 570 hub->running = false; 594 595 /* Signal polling end to joining thread. */ 596 fibril_mutex_lock(&hub->poll_guard); 597 fibril_condvar_signal(&hub->poll_cv); 598 fibril_mutex_unlock(&hub->poll_guard); 599 } 571 } 572 600 573 /** 601 574 * @} -
uspace/drv/bus/usb/usbhub/usbhub.h
r8a0c52a r91173333 39 39 40 40 #include <ddf/driver.h> 41 #include <fibril_synch.h> 41 42 42 43 #include <usb/classes/hub.h> … … 45 46 #include <usb/dev/driver.h> 46 47 #include <usb/dev/poll.h> 47 48 #include <fibril_synch.h>49 48 50 49 #define NAME "usbhub" … … 81 80 /** Each port is switched individually. */ 82 81 bool per_port_power; 83 /** True if the device should stop running as soon as possible. */84 volatile bool poll_stop;85 fibril_mutex_t poll_guard;86 fibril_condvar_t poll_cv;87 82 }; 88 83 … … 91 86 extern int usb_hub_device_add(usb_device_t *); 92 87 extern int usb_hub_device_remove(usb_device_t *); 93 extern int usb_hub_device_removed(usb_device_t *);94 88 extern int usb_hub_device_gone(usb_device_t *); 95 89 -
uspace/drv/bus/usb/usbmid/main.c
r8a0c52a r91173333 56 56 } 57 57 58 static int destroy_interfaces(usb_mid_t *usb_mid) 59 { 60 int ret = EOK; 61 62 while (!list_empty(&usb_mid->interface_list)) { 63 link_t *item = list_first(&usb_mid->interface_list); 64 list_remove(item); 65 66 usbmid_interface_t *iface = usbmid_interface_from_link(item); 67 68 const int pret = usbmid_interface_destroy(iface); 69 if (pret != EOK) { 70 usb_log_error("Failed to remove child `%s': %s\n", 71 ddf_fun_get_name(iface->fun), str_error(pret)); 72 ret = pret; 73 } 74 } 75 76 return ret; 77 } 78 58 79 /** Callback when a MID device is about to be removed from the host. 59 80 * … … 90 111 } 91 112 92 return ret;93 }94 95 static int destroy_interfaces(usb_mid_t *usb_mid)96 {97 int ret = EOK;98 99 while (!list_empty(&usb_mid->interface_list)) {100 link_t *item = list_first(&usb_mid->interface_list);101 list_remove(item);102 103 usbmid_interface_t *iface = usbmid_interface_from_link(item);104 105 const int pret = usbmid_interface_destroy(iface);106 if (pret != EOK) {107 usb_log_error("Failed to remove child `%s': %s\n",108 ddf_fun_get_name(iface->fun), str_error(pret));109 ret = pret;110 }111 }112 113 return ret;114 }115 116 static int usbmid_device_removed(usb_device_t *dev)117 {118 assert(dev);119 usb_mid_t *usb_mid = usb_device_data_get(dev);120 assert(usb_mid);121 122 /* Children are offline. Destroy them now. */123 113 return destroy_interfaces(usb_mid); 124 114 } … … 166 156 .device_add = usbmid_device_add, 167 157 .device_remove = usbmid_device_remove, 168 .device_removed = usbmid_device_removed,169 158 .device_gone = usbmid_device_gone, 170 159 .function_online = usbmid_function_online, -
uspace/drv/hid/usbhid/generic/hiddev.c
r8a0c52a r91173333 220 220 { 221 221 /* Continue polling until the device is about to be removed. */ 222 return !hid_dev->poll_stop;222 return true; 223 223 } 224 224 -
uspace/drv/hid/usbhid/kbd/kbddev.c
r8a0c52a r91173333 710 710 711 711 /* Continue polling until the device is about to be removed. */ 712 return !hid_dev->poll_stop;712 return true; 713 713 } 714 714 -
uspace/drv/hid/usbhid/main.c
r8a0c52a r91173333 40 40 #include <errno.h> 41 41 #include <str_error.h> 42 #include <fibril_synch.h>43 42 44 43 #include <usb/dev/driver.h> … … 117 116 } 118 117 118 static int join_and_clean(usb_device_t *dev) 119 { 120 assert(dev); 121 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 122 assert(hid_dev); 123 124 /* Join polling fibril. */ 125 usb_device_poll_join(hid_dev->polling); 126 127 /* Clean up. */ 128 usb_hid_deinit(hid_dev); 129 usb_log_info("%s destruction complete.\n", usb_device_get_name(dev)); 130 131 return EOK; 132 } 133 119 134 /** 120 135 * Callback for a device about to be removed from the driver. … … 129 144 assert(hid_dev); 130 145 131 usb_log_info("%s will be removed, setting remove flag.\n", usb_device_get_name(dev)); 132 usb_hid_prepare_deinit(hid_dev); 133 134 return EOK; 135 } 136 137 static int join_and_clean(usb_device_t *dev) 138 { 139 assert(dev); 140 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 141 assert(hid_dev); 142 143 /* Join polling fibril. */ 144 fibril_mutex_lock(&hid_dev->poll_guard); 145 while (hid_dev->running) 146 fibril_condvar_wait(&hid_dev->poll_cv, &hid_dev->poll_guard); 147 fibril_mutex_unlock(&hid_dev->poll_guard); 148 149 /* Clean up. */ 150 usb_hid_deinit(hid_dev); 151 usb_log_info("%s destruction complete.\n", usb_device_get_name(dev)); 152 153 return EOK; 154 } 155 156 /** 157 * Callback for when a device has just been from the driver. 158 * 159 * @param dev Structure representing the device. 160 * @return Error code. 161 */ 162 static int usb_hid_device_removed(usb_device_t *dev) 163 { 164 assert(dev); 165 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 166 assert(hid_dev); 167 168 usb_log_info("%s endpoints unregistered, joining polling fibril.\n", usb_device_get_name(dev)); 146 usb_log_info("Device %s removed.\n", usb_device_get_name(dev)); 169 147 return join_and_clean(dev); 170 148 } … … 182 160 assert(hid_dev); 183 161 184 usb_log_info("Device %s gone, joining the polling fibril.\n", usb_device_get_name(dev)); 185 usb_hid_prepare_deinit(hid_dev); 162 usb_log_info("Device %s gone.\n", usb_device_get_name(dev)); 186 163 return join_and_clean(dev); 187 164 } … … 191 168 .device_add = usb_hid_device_add, 192 169 .device_remove = usb_hid_device_remove, 193 .device_removed = usb_hid_device_removed,194 170 .device_gone = usb_hid_device_gone, 195 171 }; -
uspace/drv/hid/usbhid/mouse/mousedev.c
r8a0c52a r91173333 415 415 416 416 /* Continue polling until the device is about to be removed. */ 417 return !hid_dev->poll_stop;417 return true; 418 418 } 419 419 -
uspace/drv/hid/usbhid/multimedia/multimedia.c
r8a0c52a r91173333 246 246 usb_hid_report_path_t *path = usb_hid_report_path(); 247 247 if (path == NULL) 248 return !hid_dev->poll_stop; /* This might be a temporary failure. */248 return true; /* This might be a temporary failure. */ 249 249 250 250 int ret = … … 252 252 if (ret != EOK) { 253 253 usb_hid_report_path_free(path); 254 return !hid_dev->poll_stop; /* This might be a temporary failure. */254 return true; /* This might be a temporary failure. */ 255 255 } 256 256 … … 284 284 usb_hid_report_path_free(path); 285 285 286 return !hid_dev->poll_stop;286 return true; 287 287 } 288 288 /** -
uspace/drv/hid/usbhid/usbhid.c
r8a0c52a r91173333 355 355 hid_dev->poll_pipe_mapping = NULL; 356 356 357 hid_dev->poll_stop = false;358 fibril_mutex_initialize(&hid_dev->poll_guard);359 fibril_condvar_initialize(&hid_dev->poll_cv);360 361 357 int rc = usb_hid_check_pipes(hid_dev, dev); 362 358 if (rc != EOK) { … … 506 502 507 503 /* Continue polling until the device is about to be removed. */ 508 return hid_dev->running && !hid_dev->poll_stop;504 return hid_dev->running; 509 505 } 510 506 … … 524 520 525 521 hid_dev->running = false; 526 527 /* Signal polling end to joining thread. */528 fibril_mutex_lock(&hid_dev->poll_guard);529 fibril_condvar_signal(&hid_dev->poll_cv);530 fibril_mutex_unlock(&hid_dev->poll_guard);531 522 } 532 523 … … 539 530 { 540 531 return hid_dev->report_nr; 541 }542 543 void usb_hid_prepare_deinit(usb_hid_dev_t *hid_dev)544 {545 assert(hid_dev);546 hid_dev->poll_stop = true;547 532 } 548 533 -
uspace/drv/hid/usbhid/usbhid.h
r8a0c52a r91173333 46 46 #include <usb/hid/hid.h> 47 47 #include <stdbool.h> 48 #include <fibril_synch.h>49 48 50 49 typedef struct usb_hid_dev usb_hid_dev_t; … … 135 134 int report_nr; 136 135 volatile bool running; 137 138 /** True if polling should stop as soon as possible */139 volatile bool poll_stop;140 141 /** Synchronization primitives for joining polling end. */142 fibril_mutex_t poll_guard;143 fibril_condvar_t poll_cv;144 136 }; 145 137 … … 147 139 148 140 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); 149 150 void usb_hid_prepare_deinit(usb_hid_dev_t *hid_dev);151 141 152 142 void usb_hid_deinit(usb_hid_dev_t *hid_dev); -
uspace/lib/usbdev/include/usb/dev/driver.h
r8a0c52a r91173333 46 46 /** Callback when a device is about to be removed from the system. */ 47 47 int (*device_remove)(usb_device_t *); 48 /** Callback when a device has just been removed from the system (optional). */49 int (*device_removed)(usb_device_t *);50 48 /** Callback when a device was removed from the system. */ 51 49 int (*device_gone)(usb_device_t *); -
uspace/lib/usbdev/src/driver.c
r8a0c52a r91173333 94 94 return ret; 95 95 96 /* Notify the driver after endpoints were unregistered. */97 usb_device_destroy_pipes(usb_dev);98 if (driver->ops->device_removed != NULL) {99 ret = driver->ops->device_removed(usb_dev);100 if (ret != EOK)101 return ret;102 }103 104 96 usb_device_destroy_ddf(gen_dev); 105 97 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.