Changeset 91173333 in mainline for uspace/drv/bus
- Timestamp:
- 2018-01-13T21:36:13Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- edc51615
- Parents:
- 8a0c52a
- Location:
- uspace/drv/bus/usb
- Files:
-
- 6 edited
-
usbdiag/main.c (modified) (3 diffs)
-
usbflbk/main.c (modified) (2 diffs)
-
usbhub/main.c (modified) (1 diff)
-
usbhub/usbhub.c (modified) (7 diffs)
-
usbhub/usbhub.h (modified) (4 diffs)
-
usbmid/main.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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,
Note:
See TracChangeset
for help on using the changeset viewer.
