Skip to content

Commit b9597d4

Browse files
xiaoguangwulijinxia
authored andcommitted
DM USB: xHCI: add microframe index(MFINDEX) register emulation support
Add microframe index register support, which is an important timing component for isochronous transport. Change-Id: I615664275b539cfb713d7795edd3f213b0302b92 Tracked-On: Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Reviewed-by: Liang Yang <liang3.yang@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent a49d483 commit b9597d4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

devicemodel/hw/pci/xhci.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ struct pci_xhci_vdev {
374374
int usb2_port_start;
375375
int usb3_port_start;
376376
uint8_t *native_assign_ports[USB_NATIVE_NUM_BUS];
377+
struct timespec mf_prev_time; /* previous time of accessing MFINDEX */
377378
};
378379

379380
/* portregs and devices arrays are set up to start from idx=1 */
@@ -3055,13 +3056,22 @@ pci_xhci_dbregs_read(struct pci_xhci_vdev *xdev, uint64_t offset)
30553056
static uint64_t
30563057
pci_xhci_rtsregs_read(struct pci_xhci_vdev *xdev, uint64_t offset)
30573058
{
3058-
uint32_t value;
3059+
uint32_t value;
3060+
struct timespec t;
3061+
uint64_t time_diff;
30593062

30603063
offset -= xdev->rtsoff;
30613064
value = 0;
30623065

30633066
if (offset == XHCI_MFINDEX) {
3064-
value = xdev->rtsregs.mfindex;
3067+
clock_gettime(CLOCK_MONOTONIC, &t);
3068+
time_diff = (t.tv_sec - xdev->mf_prev_time.tv_sec) * 1000000
3069+
+ (t.tv_nsec - xdev->mf_prev_time.tv_nsec) / 1000;
3070+
xdev->mf_prev_time = t;
3071+
value = time_diff / 125;
3072+
3073+
if (value >= 1)
3074+
xdev->rtsregs.mfindex += value;
30653075
} else if (offset >= 0x20) {
30663076
int item;
30673077
uint32_t *p;
@@ -3622,6 +3632,9 @@ pci_xhci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
36223632
xdev->vid = XHCI_PCI_DEVICE_ID_DFLT;
36233633
xdev->pid = XHCI_PCI_VENDOR_ID_DFLT;
36243634

3635+
xdev->rtsregs.mfindex = 0;
3636+
clock_gettime(CLOCK_MONOTONIC, &xdev->mf_prev_time);
3637+
36253638
/* discover devices */
36263639
error = pci_xhci_parse_opts(xdev, opts);
36273640
if (error < 0)

0 commit comments

Comments
 (0)