[SeaBIOS] [PATCH 09/19] usb: Build path via chain of usbdevice_s.
Kevin O'Connor
kevin at koconnor.net
Sun Mar 11 03:45:02 CET 2012
Instead of building a dummy u64 with the path, construct the path via
the 'struct usbdevice_s' links.
Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
src/boot.c | 25 ++++++++++++++++---------
src/boot.h | 3 ++-
src/usb-hub.c | 8 ++++----
src/usb-msc.c | 3 +--
src/usb.c | 14 +++++---------
src/usb.h | 3 +--
6 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/src/boot.c b/src/boot.c
index c737ba4..8cc94b0 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -14,6 +14,7 @@
#include "cmos.h" // inb_cmos
#include "paravirt.h" // romfile_loadfile
#include "pci.h" //pci_bdf_to_*
+#include "usb.h" // struct usbdevice_s
/****************************************************************
@@ -194,20 +195,26 @@ int bootprio_find_named_rom(const char *name, int instance)
return find_prio(desc);
}
-int bootprio_find_usb(struct pci_device *pci, u64 path)
+static char *
+build_usb_path(char *buf, int max, struct usbhub_s *hub)
+{
+ if (!hub->usbdev)
+ // Root hub - nothing to add.
+ return buf;
+ char *p = build_usb_path(buf, max, hub->usbdev->hub);
+ p += snprintf(p, buf+max-p, "/hub@%x", hub->usbdev->port+1);
+ return p;
+}
+
+int bootprio_find_usb(struct usbdevice_s *usbdev)
{
if (!CONFIG_BOOTORDER)
return -1;
// Find usb - for example: /pci at i0cf8/usb at 1,2/hub at 1/network at 0/ethernet at 0
- int i;
char desc[256], *p;
- p = build_pci_path(desc, sizeof(desc), "usb", pci);
- for (i=56; i>0; i-=8) {
- int port = (path >> i) & 0xff;
- if (port != 0xff)
- p += snprintf(p, desc+sizeof(desc)-p, "/hub@%x", port+1);
- }
- snprintf(p, desc+sizeof(desc)-p, "/*@%x", (u32)(path & 0xff)+1);
+ p = build_pci_path(desc, sizeof(desc), "usb", usbdev->hub->cntl->pci);
+ p = build_usb_path(p, desc+sizeof(desc)-p, usbdev->hub);
+ snprintf(p, desc+sizeof(desc)-p, "/*@%x", usbdev->port+1);
return find_prio(desc);
}
diff --git a/src/boot.h b/src/boot.h
index 686f04d..c7c34dc 100644
--- a/src/boot.h
+++ b/src/boot.h
@@ -19,6 +19,7 @@ int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave);
int bootprio_find_fdc_device(struct pci_device *pci, int port, int fdid);
int bootprio_find_pci_rom(struct pci_device *pci, int instance);
int bootprio_find_named_rom(const char *name, int instance);
-int bootprio_find_usb(struct pci_device *pci, u64 path);
+struct usbdevice_s;
+int bootprio_find_usb(struct usbdevice_s *usbdev);
#endif // __BOOT_H
diff --git a/src/usb-hub.c b/src/usb-hub.c
index caa6a3b..6f1aaa1 100644
--- a/src/usb-hub.c
+++ b/src/usb-hub.c
@@ -31,7 +31,7 @@ set_port_feature(struct usbhub_s *hub, int port, int feature)
req.wIndex = port + 1;
req.wLength = 0;
mutex_lock(&hub->lock);
- int ret = send_default_control(hub->pipe, &req, NULL);
+ int ret = send_default_control(hub->usbdev->defpipe, &req, NULL);
mutex_unlock(&hub->lock);
return ret;
}
@@ -46,7 +46,7 @@ clear_port_feature(struct usbhub_s *hub, int port, int feature)
req.wIndex = port + 1;
req.wLength = 0;
mutex_lock(&hub->lock);
- int ret = send_default_control(hub->pipe, &req, NULL);
+ int ret = send_default_control(hub->usbdev->defpipe, &req, NULL);
mutex_unlock(&hub->lock);
return ret;
}
@@ -61,7 +61,7 @@ get_port_status(struct usbhub_s *hub, int port, struct usb_port_status *sts)
req.wIndex = port + 1;
req.wLength = sizeof(*sts);
mutex_lock(&hub->lock);
- int ret = send_default_control(hub->pipe, &req, sts);
+ int ret = send_default_control(hub->usbdev->defpipe, &req, sts);
mutex_unlock(&hub->lock);
return ret;
}
@@ -171,7 +171,7 @@ usb_hub_init(struct usbdevice_s *usbdev)
struct usbhub_s hub;
memset(&hub, 0, sizeof(hub));
- hub.pipe = usbdev->defpipe;
+ hub.usbdev = usbdev;
hub.cntl = usbdev->defpipe->cntl;
hub.powerwait = desc.bPwrOn2PwrGood * 2;
hub.portcount = desc.bNbrPorts;
diff --git a/src/usb-msc.c b/src/usb-msc.c
index dad90d6..c21433f 100644
--- a/src/usb-msc.c
+++ b/src/usb-msc.c
@@ -161,8 +161,7 @@ usb_msc_init(struct usbdevice_s *usbdev)
if (!udrive_g->bulkin || !udrive_g->bulkout)
goto fail;
- int prio = bootprio_find_usb(usbdev->defpipe->cntl->pci
- , usbdev->defpipe->path);
+ int prio = bootprio_find_usb(usbdev);
int ret = scsi_init_drive(&udrive_g->drive, "USB MSC", prio);
if (ret)
goto fail;
diff --git a/src/usb.c b/src/usb.c
index 1657bf5..3eaa289 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -262,27 +262,23 @@ usb_set_address(struct usbdevice_s *usbdev)
dummy.cntl = cntl;
dummy.type = cntl->type;
dummy.maxpacket = 8;
- dummy.path = (u64)-1;
dummy.eptype = USB_ENDPOINT_XFER_CONTROL;
struct usb_pipe *defpipe = alloc_async_pipe(&dummy);
if (!defpipe)
return -1;
usbdev->defpipe = defpipe;
defpipe->speed = usbdev->speed;
- if (hub->pipe) {
- if (hub->pipe->speed == USB_HIGHSPEED) {
- defpipe->tt_devaddr = hub->pipe->devaddr;
+ if (hub->usbdev) {
+ if (hub->usbdev->defpipe->speed == USB_HIGHSPEED) {
+ defpipe->tt_devaddr = hub->usbdev->defpipe->devaddr;
defpipe->tt_port = usbdev->port;
} else {
- defpipe->tt_devaddr = hub->pipe->tt_devaddr;
- defpipe->tt_port = hub->pipe->tt_port;
+ defpipe->tt_devaddr = hub->usbdev->defpipe->tt_devaddr;
+ defpipe->tt_port = hub->usbdev->defpipe->tt_port;
}
} else {
defpipe->tt_devaddr = defpipe->tt_port = 0;
}
- if (hub->pipe)
- defpipe->path = hub->pipe->path;
- defpipe->path = (defpipe->path << 8) | usbdev->port;
msleep(USB_TIME_RSTRCY);
diff --git a/src/usb.h b/src/usb.h
index 83ccb58..90b727a 100644
--- a/src/usb.h
+++ b/src/usb.h
@@ -10,7 +10,6 @@ struct usb_pipe {
struct usb_s *cntl;
struct usb_pipe *freenext;
};
- u64 path;
u8 type;
u8 ep;
u8 devaddr;
@@ -45,7 +44,7 @@ struct usb_s {
// Information for enumerating USB hubs
struct usbhub_s {
struct usbhub_op_s *op;
- struct usb_pipe *pipe;
+ struct usbdevice_s *usbdev;
struct usb_s *cntl;
struct mutex_s lock;
u32 powerwait;
--
1.7.6.5
More information about the SeaBIOS
mailing list