func: static void xhci_doorbell_write(void *ptr, hwaddr uint64_t val, unsigned size) XHCIState * xhci = ptr ; if ( ! xhci_running ( xhci ) )  static inline int xhci_running(XHCIState *xhci) return ! ( xhci -> usbsts & USBSTS_HCH ) && ! xhci -> intr [ 0 ] . er_full ; reg >>= 2; if ( reg == 0 )  if ( val == 0 )  xhci_process_commands ( xhci ); static void xhci_process_commands(XHCIState *xhci) XHCITRB trb ; TRBType type ; XHCIEvent event = { ER_COMMAND_COMPLETE , CC_SUCCESS } ; dma_addr_t addr ; unsigned int i , slotid = 0 ; if ( ! xhci_running ( xhci ) )  static inline int xhci_running(XHCIState *xhci) return ! ( xhci -> usbsts & USBSTS_HCH ) && ! xhci -> intr [ 0 ] . er_full ; xhci -> crcr_low |= CRCR_CRR; while ( type = xhci_ring_fetch ( xhci , & xhci -> cmd_ring , & trb , & addr ) )  static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB dma_addr_t *addr) while ( 1 )  TRBType type ; trb -> addr = ring -> dequeue; trb -> ccs = ring -> ccs; if ( ( trb -> control & TRB_C ) != ring -> ccs )  return 0 ; type = TRB_TYPE ( * trb ); if ( type != TR_LINK )  return type ; ring -> dequeue = xhci_mask64 ( trb -> parameter ); static inline dma_addr_t xhci_mask64(uint64_t addr) if ( sizeof ( dma_addr_t ) == 4 )  return addr & 0xffffffff ; return addr ; if ( trb -> control & TRB_LK_TC )  ring -> ccs = ! ring -> ccs; event . ptr = addr; switch ( type )  for (i = 0; i < xhci->numslots; i++) if ( ! xhci -> slots [ i ] . enabled )  if ( i >= xhci -> numslots )  event . ccode = CC_NO_SLOTS_ERROR; slotid = i + 1; event . ccode = xhci_enable_slot ( xhci , slotid ); static TRBCCode xhci_enable_slot(XHCIState *xhci, unsigned int slotid) return CC_SUCCESS ; slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  event . ccode = xhci_disable_slot ( xhci , slotid ); static TRBCCode xhci_disable_slot(XHCIState *xhci, unsigned int slotid) return CC_SUCCESS ; slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  event . ccode = xhci_address_slot ( xhci , slotid , trb . parameter , trb . control & TRB_CR_BSR ); slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  event . ccode = xhci_configure_slot ( xhci , slotid , trb . parameter , trb . control & TRB_CR_DC ); slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  event . ccode = xhci_evaluate_slot ( xhci , slotid , trb . parameter ); slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  unsigned int epid = ( trb . control >> TRB_CR_EPID_SHIFT ) & TRB_CR_EPID_MASK ; event . ccode = xhci_stop_ep ( xhci , slotid , epid ); slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  unsigned int epid = ( trb . control >> TRB_CR_EPID_SHIFT ) & TRB_CR_EPID_MASK ; event . ccode = xhci_reset_ep ( xhci , slotid , epid ); slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  unsigned int epid = ( trb . control >> TRB_CR_EPID_SHIFT ) & TRB_CR_EPID_MASK ; unsigned int streamid = ( trb . status >> 16 ) & 0xffff ; event . ccode = xhci_set_ep_dequeue ( xhci , slotid , epid , streamid , trb . parameter ); slotid = xhci_get_slot ( xhci , & event , & trb ); static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *trb) unsigned int slotid ; slotid = ( trb -> control >> TRB_CR_SLOTID_SHIFT ) & TRB_CR_SLOTID_MASK; if ( slotid < 1 || slotid > xhci -> numslots )  return 0 ; if ( ! xhci -> slots [ slotid - 1 ] . enabled )  return 0 ; return slotid ; if ( slotid )  event . ccode = xhci_reset_slot ( xhci , slotid ); event . ccode = xhci_get_port_bandwidth ( xhci , trb . parameter ); static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx) return CC_SUCCESS ; event . type = 48; event . length = 0x3025; uint32_t chi = trb . parameter >> 32 ; uint32_t clo = trb . parameter ; uint32_t val = xhci_nec_challenge ( chi , clo ) ; static uint32_t xhci_nec_challenge(uint32_t hi, uint32_t lo) return ~val ; event . length = val & 0xFFFF; event . epid = val >> 16; slotid = val >> 24; event . type = 48; event . ccode = CC_TRB_ERROR; event . slotid = slotid; static TRBCCode xhci_evaluate_slot(XHCIState *xhci, unsigned int uint64_t pictx) dma_addr_t ictx , octx ; uint32_t ictl_ctx [ 2 ] ; uint32_t islot_ctx [ 4 ] ; ictx = xhci_mask64 ( pictx ); static inline dma_addr_t xhci_mask64(uint64_t addr) if ( sizeof ( dma_addr_t ) == 4 )  return addr & 0xffffffff ; return addr ; if ( ictl_ctx [ 0 ] != 0x0 || ictl_ctx [ 1 ] & ~0x3 )  if ( ictl_ctx [ 1 ] & 0x1 )  xhci_dma_read_u32s ( xhci , ictx + 32 , islot_ctx , sizeof ( islot_ctx ) ); static inline void xhci_dma_read_u32s(XHCIState *xhci, dma_addr_t uint32_t *buf, size_t len) assert ( ( len % sizeof ( uint32_t ) ) == 0 ); 