#include "usb-uhci.h" // init_uhci
#include "usb-ohci.h" // init_ohci
-struct companion_s {
- u16 bdf;
- u16 type;
-};
-
struct usb_ehci_s {
struct usb_s usb;
struct ehci_caps *caps;
struct ehci_regs *regs;
struct ehci_qh *async_qh;
- struct companion_s companion[8];
+ struct pci_device *companion[8];
int checkports;
int legacycount;
};
// Start companion controllers.
int i;
for (i=0; i<ARRAY_SIZE(cntl->companion); i++) {
- u16 type = cntl->companion[i].type;
- if (type == USB_TYPE_UHCI)
- uhci_init(cntl->companion[i].bdf, cntl->usb.busid + i);
- else if (type == USB_TYPE_OHCI)
- ohci_init(cntl->companion[i].bdf, cntl->usb.busid + i);
- else
- return;
+ struct pci_device *pci = cntl->companion[i];
+ if (!pci)
+ break;
+ if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_UHCI)
+ uhci_init(pci, cntl->usb.busid + i);
+ else if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_OHCI)
+ ohci_init(pci, cntl->usb.busid + i);
}
}
}
int
-ehci_init(u16 bdf, int busid, int compbdf)
+ehci_init(struct pci_device *pci, int busid, struct pci_device *comppci)
{
if (! CONFIG_USB_EHCI)
return -1;
+ u16 bdf = pci->bdf;
u32 baseaddr = pci_config_readl(bdf, PCI_BASE_ADDRESS_0);
struct ehci_caps *caps = (void*)(baseaddr & PCI_BASE_ADDRESS_MEM_MASK);
u32 hcc_params = readl(&caps->hccparams);
struct usb_ehci_s *cntl = malloc_tmphigh(sizeof(*cntl));
memset(cntl, 0, sizeof(*cntl));
cntl->usb.busid = busid;
- cntl->usb.bdf = bdf;
+ cntl->usb.pci = pci;
cntl->usb.type = USB_TYPE_EHCI;
cntl->caps = caps;
cntl->regs = (void*)caps + readb(&caps->caplength);
// Find companion controllers.
int count = 0;
for (;;) {
- if (compbdf < 0 || compbdf >= bdf)
+ if (!comppci || comppci == pci)
break;
- u32 code = pci_config_readl(compbdf, PCI_CLASS_REVISION) >> 8;
- if (code == PCI_CLASS_SERIAL_USB_UHCI) {
- cntl->companion[count].bdf = compbdf;
- cntl->companion[count].type = USB_TYPE_UHCI;
- count++;
- } else if (code == PCI_CLASS_SERIAL_USB_OHCI) {
- cntl->companion[count].bdf = compbdf;
- cntl->companion[count].type = USB_TYPE_OHCI;
- count++;
- }
- compbdf = pci_next(compbdf+1, pci_bdf_to_bus(compbdf));
+ if (pci_classprog(comppci) == PCI_CLASS_SERIAL_USB_UHCI)
+ cntl->companion[count++] = comppci;
+ else if (pci_classprog(comppci) == PCI_CLASS_SERIAL_USB_OHCI)
+ cntl->companion[count++] = comppci;
+ comppci = comppci->next;
}
run_thread(configure_ehci, cntl);
#define __USB_EHCI_H
// usb-ehci.c
-int ehci_init(u16 bdf, int busid, int compbdf);
+int ehci_init(struct pci_device *pci, int busid, struct pci_device *comppci);
struct usb_pipe;
void ehci_free_pipe(struct usb_pipe *p);
struct usb_pipe *ehci_alloc_control_pipe(struct usb_pipe *dummy);
#include "blockcmd.h" // cdb_read
#include "disk.h" // DTYPE_USB
#include "boot.h" // boot_add_hd
+#include "pci.h" // struct pci_device
struct usbdrive_s {
struct drive_s drive;
op->drive_g->sectors = (u64)-1;
struct usb_pipe *pipe = container_of(
op->drive_g, struct usbdrive_s, drive)->bulkout;
- int prio = bootprio_find_usb(pipe->cntl->bdf, pipe->path);
+ int prio = bootprio_find_usb(pipe->cntl->pci->bdf, pipe->path);
boot_add_cd(op->drive_g, desc, prio);
return 0;
}
// Register with bcv system.
struct usb_pipe *pipe = container_of(
op->drive_g, struct usbdrive_s, drive)->bulkout;
- int prio = bootprio_find_usb(pipe->cntl->bdf, pipe->path);
+ int prio = bootprio_find_usb(pipe->cntl->pci->bdf, pipe->path);
boot_add_hd(op->drive_g, desc, prio);
return 0;
}
void
-ohci_init(u16 bdf, int busid)
+ohci_init(struct pci_device *pci, int busid)
{
if (! CONFIG_USB_OHCI)
return;
struct usb_ohci_s *cntl = malloc_tmphigh(sizeof(*cntl));
memset(cntl, 0, sizeof(*cntl));
cntl->usb.busid = busid;
- cntl->usb.bdf = bdf;
+ cntl->usb.pci = pci;
cntl->usb.type = USB_TYPE_OHCI;
+ u16 bdf = pci->bdf;
u32 baseaddr = pci_config_readl(bdf, PCI_BASE_ADDRESS_0);
cntl->regs = (void*)(baseaddr & PCI_BASE_ADDRESS_MEM_MASK);
#define __USB_OHCI_H
// usb-ohci.c
-void ohci_init(u16 bdf, int busid);
+void ohci_init(struct pci_device *pci, int busid);
struct usb_pipe;
void ohci_free_pipe(struct usb_pipe *p);
struct usb_pipe *ohci_alloc_control_pipe(struct usb_pipe *dummy);
}
void
-uhci_init(u16 bdf, int busid)
+uhci_init(struct pci_device *pci, int busid)
{
if (! CONFIG_USB_UHCI)
return;
+ u16 bdf = pci->bdf;
struct usb_uhci_s *cntl = malloc_tmphigh(sizeof(*cntl));
memset(cntl, 0, sizeof(*cntl));
cntl->usb.busid = busid;
- cntl->usb.bdf = bdf;
+ cntl->usb.pci = pci;
cntl->usb.type = USB_TYPE_UHCI;
cntl->iobase = (pci_config_readl(bdf, PCI_BASE_ADDRESS_4)
& PCI_BASE_ADDRESS_IO_MASK);
#define __USB_UHCI_H
// usb-uhci.c
-void uhci_init(u16 bdf, int busid);
+void uhci_init(struct pci_device *pci, int busid);
struct usb_pipe;
void uhci_free_pipe(struct usb_pipe *p);
struct usb_pipe *uhci_alloc_control_pipe(struct usb_pipe *dummy);
for (;;) {
if (pci_classprog(ehcipci) == PCI_CLASS_SERIAL_USB_EHCI) {
// Found an ehci controller.
- int ret = ehci_init(ehcipci->bdf, count++, pci->bdf);
+ int ret = ehci_init(ehcipci, count++, pci);
if (ret)
// Error
break;
}
if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_UHCI)
- uhci_init(pci->bdf, count++);
+ uhci_init(pci, count++);
else if (pci_classprog(pci) == PCI_CLASS_SERIAL_USB_OHCI)
- ohci_init(pci->bdf, count++);
+ ohci_init(pci, count++);
}
}
struct usb_s {
struct usb_pipe *defaultpipe;
struct mutex_s resetlock;
+ struct pci_device *pci;
int busid;
- u16 bdf;
u8 type;
u8 maxaddr;
};