Skip to content

Commit 27eeea4

Browse files
xiaoguangwulijinxia
authored andcommitted
DM USB: xHCI: refine port assignment logic
The variable native_assign_ports in struct pci_xhci_vdev is used to record wether certain root hub port in SOS is assigned to UOS. The logic uses zero to express 'not assigned' and nonzero to express 'assigned'. In this patch, use macro to replace number to express better. 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 5cc389a commit 27eeea4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

devicemodel/hw/pci/xhci.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ struct pci_xhci_vdev {
384384
#define XHCI_HALTED(xdev) ((xdev)->opregs.usbsts & XHCI_STS_HCH)
385385
#define XHCI_GADDR(xdev, a) paddr_guest2host((xdev)->dev->vmctx, (a), \
386386
XHCI_PADDR_SZ - ((a) & (XHCI_PADDR_SZ-1)))
387+
388+
#define VPORT_FREE (0)
389+
#define VPORT_ASSIGNED (-1)
390+
387391
struct pci_xhci_option_elem {
388392
char *parse_opt;
389393
int (*parse_fn)(struct pci_xhci_vdev *, char *);
@@ -500,7 +504,7 @@ pci_xhci_native_usb_dev_conn_cb(void *hci_data, void *dev_data)
500504
UPRINTF(LDBG, "%04x:%04x %d-%d connecting.\r\n",
501505
di->vid, di->pid, di->bus, di->port);
502506

503-
if (!xdev->native_assign_ports[di->bus][di->port]) {
507+
if (xdev->native_assign_ports[di->bus][di->port] == VPORT_FREE) {
504508
UPRINTF(LDBG, "%04x:%04x %d-%d doesn't belong to this vm, bye."
505509
"\r\n", di->vid, di->pid, di->bus, di->port);
506510
goto errout;
@@ -3360,7 +3364,7 @@ pci_xhci_parse_bus_port(struct pci_xhci_vdev *xdev, char *opts)
33603364
goto errout;
33613365
}
33623366

3363-
xdev->native_assign_ports[bus][port] = 1;
3367+
xdev->native_assign_ports[bus][port] = VPORT_ASSIGNED;
33643368
errout:
33653369
if (rc)
33663370
UPRINTF(LWRN, "%s fails, rc=%d\r\n", __func__, rc);

0 commit comments

Comments
 (0)