Changeset 047fbc8 in mainline
- Timestamp:
- 2018-01-25T20:27:21Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a94cbfa
- Parents:
- 629255a
- git-author:
- Ondřej Hlavatý <aearsis@…> (2018-01-25 20:27:16)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2018-01-25 20:27:21)
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/hc.c
r629255a r047fbc8 549 549 } 550 550 551 static int handle_port_status_change_event(xhci_hc_t *hc, xhci_trb_t *trb)552 {553 uint8_t port_id = XHCI_QWORD_EXTRACT(trb->parameter, 31, 24);554 usb_log_debug("Port status change event detected for port %u.", port_id);555 xhci_rh_handle_port_change(&hc->rh, port_id);556 return EOK;557 }558 559 551 typedef int (*event_handler) (xhci_hc_t *, xhci_trb_t *trb); 560 552 … … 563 555 */ 564 556 static event_handler event_handlers [] = { 565 [XHCI_TRB_TYPE_PORT_STATUS_CHANGE_EVENT] = &handle_port_status_change_event,566 557 [XHCI_TRB_TYPE_TRANSFER_EVENT] = &xhci_handle_transfer_event, 567 558 }; … … 586 577 return xhci_sw_ring_enqueue(&hc->sw_ring, trb); 587 578 579 if (type == XHCI_TRB_TYPE_PORT_STATUS_CHANGE_EVENT) 580 return xhci_sw_ring_enqueue(&hc->rh.event_ring, trb); 581 588 582 return ENOTSUP; 589 583 } … … 606 600 fibril_mutex_lock(&hc->event_fibril_completion.guard); 607 601 hc->event_fibril_completion.active = false; 608 fibril_condvar_wait(&hc->event_fibril_completion.cv, 609 &hc->event_fibril_completion.guard); 602 fibril_condvar_broadcast(&hc->event_fibril_completion.cv); 610 603 fibril_mutex_unlock(&hc->event_fibril_completion.guard); 611 604 -
uspace/drv/bus/usb/xhci/rh.c
r629255a r047fbc8 74 74 } rh_port_t; 75 75 76 static int rh_worker(void *); 77 76 78 /** 77 79 * Initialize the roothub subsystem. … … 94 96 } 95 97 98 fid_t fid = fibril_create(&rh_worker, rh); 99 if (!fid) { 100 free(rh->ports); 101 return err; 102 } 103 96 104 for (unsigned i = 0; i < rh->max_ports; i++) { 97 105 usb_port_init(&rh->ports[i].base); … … 103 111 rh->device.route_str = 0; 104 112 113 xhci_sw_ring_init(&rh->event_ring, rh->max_ports); 114 115 hc->event_fibril_completion.active = true; 116 fibril_mutex_initialize(&hc->event_fibril_completion.guard); 117 fibril_condvar_initialize(&hc->event_fibril_completion.cv); 118 119 fibril_add_ready(fid); 120 105 121 return EOK; 106 122 } … … 114 130 for (unsigned i = 0; i < rh->max_ports; i++) 115 131 usb_port_fini(&rh->ports[i].base); 132 133 xhci_sw_ring_stop(&rh->event_ring); 134 135 // TODO: completion_wait 136 fibril_mutex_lock(&rh->event_fibril_completion.guard); 137 while (rh->event_fibril_completion.active) 138 fibril_condvar_wait(&rh->event_fibril_completion.cv, 139 &rh->event_fibril_completion.guard); 140 fibril_mutex_unlock(&rh->event_fibril_completion.guard); 141 xhci_sw_ring_fini(&rh->event_ring); 116 142 return EOK; 117 143 } … … 219 245 * Handle all changes on specified port. 220 246 */ 221 void xhci_rh_handle_port_change(xhci_rh_t *rh, uint8_t port_id)247 static void handle_port_change(xhci_rh_t *rh, uint8_t port_id) 222 248 { 223 249 rh_port_t * const port = &rh->ports[port_id - 1]; … … 280 306 */ 281 307 for (uint8_t i = 0; i < rh->max_ports; ++i) { 282 xhci_rh_handle_port_change(rh, i + 1);308 handle_port_change(rh, i + 1); 283 309 284 310 rh_port_t * const port = &rh->ports[i]; … … 295 321 } 296 322 323 static int rh_worker(void *arg) 324 { 325 xhci_rh_t * const rh = arg; 326 327 xhci_trb_t trb; 328 while (xhci_sw_ring_dequeue(&rh->event_ring, &trb) == EOK) { 329 uint8_t port_id = XHCI_QWORD_EXTRACT(trb.parameter, 31, 24); 330 usb_log_debug("Port status change event detected for port %u.", port_id); 331 handle_port_change(rh, port_id); 332 } 333 334 // TODO: completion_complete 335 fibril_mutex_lock(&rh->event_fibril_completion.guard); 336 rh->event_fibril_completion.active = false; 337 fibril_condvar_broadcast(&rh->event_fibril_completion.cv); 338 fibril_mutex_unlock(&rh->event_fibril_completion.guard); 339 340 return EOK; 341 } 342 297 343 /** 298 344 * @} -
uspace/drv/bus/usb/xhci/rh.h
r629255a r047fbc8 73 73 /* Array of port structures. (size is `max_ports`) */ 74 74 rh_port_t *ports; 75 76 /* Event ring for roothub */ 77 xhci_sw_ring_t event_ring; 78 79 struct { 80 fibril_mutex_t guard; 81 fibril_condvar_t cv; 82 bool active; 83 } event_fibril_completion; 75 84 } xhci_rh_t; 76 85 … … 78 87 extern int xhci_rh_fini(xhci_rh_t *); 79 88 80 extern void xhci_rh_handle_port_change(xhci_rh_t *, uint8_t);81 89 extern void xhci_rh_set_ports_protocol(xhci_rh_t *, unsigned, unsigned, unsigned); 82 90 extern void xhci_rh_startup(xhci_rh_t *);
Note:
See TracChangeset
for help on using the changeset viewer.