Changeset 047fbc8 in mainline


Ignore:
Timestamp:
2018-01-25T20:27:21Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
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)
Message:

xhci rh: have standalone buffer for events

Location:
uspace/drv/bus/usb/xhci
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/hc.c

    r629255a r047fbc8  
    549549}
    550550
    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 
    559551typedef int (*event_handler) (xhci_hc_t *, xhci_trb_t *trb);
    560552
     
    563555 */
    564556static event_handler event_handlers [] = {
    565         [XHCI_TRB_TYPE_PORT_STATUS_CHANGE_EVENT] = &handle_port_status_change_event,
    566557        [XHCI_TRB_TYPE_TRANSFER_EVENT] = &xhci_handle_transfer_event,
    567558};
     
    586577                return xhci_sw_ring_enqueue(&hc->sw_ring, trb);
    587578
     579        if (type == XHCI_TRB_TYPE_PORT_STATUS_CHANGE_EVENT)
     580                return xhci_sw_ring_enqueue(&hc->rh.event_ring, trb);
     581
    588582        return ENOTSUP;
    589583}
     
    606600        fibril_mutex_lock(&hc->event_fibril_completion.guard);
    607601        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);
    610603        fibril_mutex_unlock(&hc->event_fibril_completion.guard);
    611604
  • uspace/drv/bus/usb/xhci/rh.c

    r629255a r047fbc8  
    7474} rh_port_t;
    7575
     76static int rh_worker(void *);
     77
    7678/**
    7779 * Initialize the roothub subsystem.
     
    9496        }
    9597
     98        fid_t fid = fibril_create(&rh_worker, rh);
     99        if (!fid) {
     100                free(rh->ports);
     101                return err;
     102        }
     103
    96104        for (unsigned i = 0; i < rh->max_ports; i++) {
    97105                usb_port_init(&rh->ports[i].base);
     
    103111        rh->device.route_str = 0;
    104112
     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
    105121        return EOK;
    106122}
     
    114130        for (unsigned i = 0; i < rh->max_ports; i++)
    115131                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);
    116142        return EOK;
    117143}
     
    219245 * Handle all changes on specified port.
    220246 */
    221 void xhci_rh_handle_port_change(xhci_rh_t *rh, uint8_t port_id)
     247static void handle_port_change(xhci_rh_t *rh, uint8_t port_id)
    222248{
    223249        rh_port_t * const port = &rh->ports[port_id - 1];
     
    280306         */
    281307        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);
    283309
    284310                rh_port_t * const port = &rh->ports[i];
     
    295321}
    296322
     323static 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
    297343/**
    298344 * @}
  • uspace/drv/bus/usb/xhci/rh.h

    r629255a r047fbc8  
    7373        /* Array of port structures. (size is `max_ports`) */
    7474        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;
    7584} xhci_rh_t;
    7685
     
    7887extern int xhci_rh_fini(xhci_rh_t *);
    7988
    80 extern void xhci_rh_handle_port_change(xhci_rh_t *, uint8_t);
    8189extern void xhci_rh_set_ports_protocol(xhci_rh_t *, unsigned, unsigned, unsigned);
    8290extern void xhci_rh_startup(xhci_rh_t *);
Note: See TracChangeset for help on using the changeset viewer.