Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 230ef1c in mainline


Ignore:
Timestamp:
2018-01-13T01:34:06Z (2 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
master
Children:
837581fd
Parents:
94e9c29
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-13 01:20:57)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-13 01:34:06)
Message:

xhci rh: fixed broken event system

The previous one broke when two events were to be run simultaneously.

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

Legend:

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

    r94e9c29 r230ef1c  
    9898}
    9999
     100typedef struct rh_event {
     101        uint8_t port_id;
     102        uint32_t events;
     103        unsigned readers_to_go;
     104} rh_event_t;
     105
    100106static int rh_event_wait_timeout(xhci_rh_t *rh, uint8_t port_id, uint32_t mask, suseconds_t timeout)
    101107{
     
    109115                if (r != EOK)
    110116                        break;
    111         } while (rh->event.port_id != port_id || (rh->event.events & mask) != mask);
     117
     118                assert(rh->event);
     119                if (--rh->event->readers_to_go == 0)
     120                        fibril_condvar_broadcast(&rh->event_handled);
     121        } while (rh->event->port_id != port_id || (rh->event->events & mask) != mask);
    112122
    113123        if (r == EOK)
    114                 rh->event.events &= ~mask;
     124                rh->event->events &= ~mask;
    115125
    116126        --rh->event_readers_waiting;
    117         if (--rh->event_readers_to_go == 0)
    118                 fibril_condvar_broadcast(&rh->event_handled);
    119127
    120128        return r;
    121129}
    122130
    123 static void rh_event_run_handlers(xhci_rh_t *rh)
     131static void rh_event_run_handlers(xhci_rh_t *rh, uint8_t port_id, uint32_t *events)
    124132{
    125133        assert(fibril_mutex_is_locked(&rh->event_guard));
    126         assert(rh->event_readers_to_go == 0);
    127 
    128         rh->event_readers_to_go = rh->event_readers_waiting;
     134
     135        /* There can be different event running already */
     136        while (rh->event)
     137                fibril_condvar_wait(&rh->event_handled, &rh->event_guard);
     138
     139        rh_event_t event = {
     140                .port_id = port_id,
     141                .events = *events,
     142                .readers_to_go = rh->event_readers_waiting,
     143        };
     144
     145        rh->event = &event;
    129146        fibril_condvar_broadcast(&rh->event_ready);
    130         while (rh->event_readers_to_go)
     147        while (event.readers_to_go)
    131148                fibril_condvar_wait(&rh->event_handled, &rh->event_guard);
     149        *events = event.events;
     150        rh->event = NULL;
    132151}
    133152
     
    194213        const int r = rh_event_wait_timeout(rh, port_id, XHCI_REG_MASK(XHCI_PORT_PRC), 0);
    195214        fibril_mutex_unlock(&rh->event_guard);
    196 
    197215        return r;
    198216}
     
    324342                }
    325343
    326                 if (events != 0) {
    327                         rh->event.port_id = port_id;
    328                         rh->event.events = events;
    329                         rh_event_run_handlers(rh);
    330                 }
    331 
    332                 if (rh->event.events != 0)
    333                         usb_log_debug("RH port %u change not handled: 0x%x", port_id, rh->event.events);
     344                if (events != 0)
     345                        rh_event_run_handlers(rh, port_id, &events);
     346
     347                if (events != 0)
     348                        usb_log_debug("RH port %u change not handled: 0x%x", port_id, events);
    334349               
    335350                /* Make sure that PSCEG is 0 before exiting the loop. */
  • uspace/drv/bus/usb/xhci/rh.h

    r94e9c29 r230ef1c  
    5858typedef struct hcd_roothub hcd_roothub_t;
    5959typedef struct xhci_bus xhci_bus_t;
     60typedef struct rh_event rh_event_t;
    6061
    6162/* XHCI root hub instance */
     
    7980        fibril_mutex_t event_guard;
    8081        fibril_condvar_t event_ready, event_handled;
    81         unsigned event_readers_waiting, event_readers_to_go;
    82         struct {
    83                 uint8_t port_id;
    84                 uint32_t events;
    85         } event;
     82        unsigned event_readers_waiting;
     83        rh_event_t *event;
    8684} xhci_rh_t;
    8785
Note: See TracChangeset for help on using the changeset viewer.