blob: 8b3c36ed3b543e9932ef6bcd2568be53a0366eeb [file] [log] [blame]
Kevin O'Connor114592f2009-09-28 21:32:08 -04001// Main code for handling USB controllers and devices.
2//
3// Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4//
5// This file may be distributed under the terms of the GNU LGPLv3 license.
6
7#include "util.h" // dprintf
8#include "pci.h" // foreachpci
9#include "config.h" // CONFIG_*
10#include "pci_regs.h" // PCI_CLASS_REVISION
11#include "pci_ids.h" // PCI_CLASS_SERIAL_USB_UHCI
12#include "usb-uhci.h" // uhci_init
Kevin O'Connor59f02832009-10-12 10:09:15 -040013#include "usb-ohci.h" // ohci_init
Kevin O'Connor190cc622010-03-09 19:43:52 -050014#include "usb-ehci.h" // ehci_init
Kevin O'Connor114592f2009-09-28 21:32:08 -040015#include "usb-hid.h" // usb_keyboard_setup
Kevin O'Connor54671c12010-02-15 18:58:12 -050016#include "usb-hub.h" // usb_hub_init
Kevin O'Connor7149fc82010-02-17 23:24:42 -050017#include "usb-msc.h" // usb_msc_init
Kevin O'Connor114592f2009-09-28 21:32:08 -040018#include "usb.h" // struct usb_s
Kevin O'Connor1c46a542009-10-17 23:53:32 -040019#include "biosvar.h" // GET_GLOBAL
Kevin O'Connor114592f2009-09-28 21:32:08 -040020
Kevin O'Connor3c160dd2010-02-17 23:06:52 -050021
22/****************************************************************
23 * Controller function wrappers
24 ****************************************************************/
25
Kevin O'Connor357bdfa2010-02-26 08:57:13 -050026// Free an allocated control or bulk pipe.
27void
28free_pipe(struct usb_pipe *pipe)
29{
30 ASSERT32FLAT();
31 if (!pipe)
32 return;
Kevin O'Connor4547eb92010-02-28 02:17:28 -050033 switch (pipe->type) {
Kevin O'Connor357bdfa2010-02-26 08:57:13 -050034 default:
35 case USB_TYPE_UHCI:
36 return uhci_free_pipe(pipe);
37 case USB_TYPE_OHCI:
38 return ohci_free_pipe(pipe);
Kevin O'Connor190cc622010-03-09 19:43:52 -050039 case USB_TYPE_EHCI:
40 return ehci_free_pipe(pipe);
Kevin O'Connor357bdfa2010-02-26 08:57:13 -050041 }
42}
43
Kevin O'Connor4547eb92010-02-28 02:17:28 -050044// Allocate a control pipe to a default endpoint (which can only be
45// used by 32bit code)
Kevin O'Connor357bdfa2010-02-26 08:57:13 -050046static struct usb_pipe *
Kevin O'Connor4547eb92010-02-28 02:17:28 -050047alloc_default_control_pipe(struct usb_pipe *dummy)
Kevin O'Connor114592f2009-09-28 21:32:08 -040048{
Kevin O'Connor4547eb92010-02-28 02:17:28 -050049 switch (dummy->type) {
Kevin O'Connor59f02832009-10-12 10:09:15 -040050 default:
51 case USB_TYPE_UHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -050052 return uhci_alloc_control_pipe(dummy);
Kevin O'Connor59f02832009-10-12 10:09:15 -040053 case USB_TYPE_OHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -050054 return ohci_alloc_control_pipe(dummy);
Kevin O'Connor190cc622010-03-09 19:43:52 -050055 case USB_TYPE_EHCI:
56 return ehci_alloc_control_pipe(dummy);
Kevin O'Connor357bdfa2010-02-26 08:57:13 -050057 }
58}
59
60// Send a message on a control pipe using the default control descriptor.
61static int
62send_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize
63 , void *data, int datasize)
64{
65 ASSERT32FLAT();
Kevin O'Connor4547eb92010-02-28 02:17:28 -050066 switch (pipe->type) {
Kevin O'Connor357bdfa2010-02-26 08:57:13 -050067 default:
68 case USB_TYPE_UHCI:
69 return uhci_control(pipe, dir, cmd, cmdsize, data, datasize);
70 case USB_TYPE_OHCI:
71 return ohci_control(pipe, dir, cmd, cmdsize, data, datasize);
Kevin O'Connor190cc622010-03-09 19:43:52 -050072 case USB_TYPE_EHCI:
73 return ehci_control(pipe, dir, cmd, cmdsize, data, datasize);
Kevin O'Connor59f02832009-10-12 10:09:15 -040074 }
Kevin O'Connor114592f2009-09-28 21:32:08 -040075}
76
Kevin O'Connor4547eb92010-02-28 02:17:28 -050077// Fill "pipe" endpoint info from an endpoint descriptor.
78static void
79desc2pipe(struct usb_pipe *newpipe, struct usb_pipe *origpipe
80 , struct usb_endpoint_descriptor *epdesc)
Kevin O'Connor7149fc82010-02-17 23:24:42 -050081{
Kevin O'Connor4547eb92010-02-28 02:17:28 -050082 memcpy(newpipe, origpipe, sizeof(*newpipe));
83 newpipe->ep = epdesc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
84 newpipe->maxpacket = epdesc->wMaxPacketSize;
85}
86
87struct usb_pipe *
88alloc_bulk_pipe(struct usb_pipe *pipe, struct usb_endpoint_descriptor *epdesc)
89{
90 struct usb_pipe dummy;
91 desc2pipe(&dummy, pipe, epdesc);
92 switch (pipe->type) {
Kevin O'Connor7149fc82010-02-17 23:24:42 -050093 default:
94 case USB_TYPE_UHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -050095 return uhci_alloc_bulk_pipe(&dummy);
Kevin O'Connor7149fc82010-02-17 23:24:42 -050096 case USB_TYPE_OHCI:
97 return NULL;
Kevin O'Connor190cc622010-03-09 19:43:52 -050098 case USB_TYPE_EHCI:
99 return ehci_alloc_bulk_pipe(&dummy);
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500100 }
101}
102
103int
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500104usb_send_bulk(struct usb_pipe *pipe_fl, int dir, void *data, int datasize)
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500105{
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500106 switch (GET_FLATPTR(pipe_fl->type)) {
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500107 default:
108 case USB_TYPE_UHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500109 return uhci_send_bulk(pipe_fl, dir, data, datasize);
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500110 case USB_TYPE_OHCI:
111 return -1;
Kevin O'Connor190cc622010-03-09 19:43:52 -0500112 case USB_TYPE_EHCI:
113 return ehci_send_bulk(pipe_fl, dir, data, datasize);
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500114 }
115}
116
117struct usb_pipe *
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500118alloc_intr_pipe(struct usb_pipe *pipe, struct usb_endpoint_descriptor *epdesc)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400119{
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500120 struct usb_pipe dummy;
121 desc2pipe(&dummy, pipe, epdesc);
Kevin O'Connor991eaff2010-02-13 21:51:47 -0500122 // Find the exponential period of the requested time.
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500123 int period = epdesc->bInterval;
Kevin O'Connor190cc622010-03-09 19:43:52 -0500124 int frameexp;
125 if (pipe->speed != USB_HIGHSPEED)
126 frameexp = (period <= 0) ? 0 : __fls(period);
127 else
128 frameexp = (period <= 4) ? 0 : period - 4;
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500129 switch (pipe->type) {
Kevin O'Connor59f02832009-10-12 10:09:15 -0400130 default:
131 case USB_TYPE_UHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500132 return uhci_alloc_intr_pipe(&dummy, frameexp);
Kevin O'Connor59f02832009-10-12 10:09:15 -0400133 case USB_TYPE_OHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500134 return ohci_alloc_intr_pipe(&dummy, frameexp);
Kevin O'Connor190cc622010-03-09 19:43:52 -0500135 case USB_TYPE_EHCI:
136 return ehci_alloc_intr_pipe(&dummy, frameexp);
Kevin O'Connor59f02832009-10-12 10:09:15 -0400137 }
Kevin O'Connor114592f2009-09-28 21:32:08 -0400138}
139
Kevin O'Connor84a4d4b2010-02-11 22:32:12 -0500140int noinline
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500141usb_poll_intr(struct usb_pipe *pipe_fl, void *data)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400142{
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500143 switch (GET_FLATPTR(pipe_fl->type)) {
Kevin O'Connor59f02832009-10-12 10:09:15 -0400144 default:
145 case USB_TYPE_UHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500146 return uhci_poll_intr(pipe_fl, data);
Kevin O'Connor59f02832009-10-12 10:09:15 -0400147 case USB_TYPE_OHCI:
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500148 return ohci_poll_intr(pipe_fl, data);
Kevin O'Connor190cc622010-03-09 19:43:52 -0500149 case USB_TYPE_EHCI:
150 return ehci_poll_intr(pipe_fl, data);
Kevin O'Connor59f02832009-10-12 10:09:15 -0400151 }
Kevin O'Connor114592f2009-09-28 21:32:08 -0400152}
153
Kevin O'Connor3c160dd2010-02-17 23:06:52 -0500154
155/****************************************************************
156 * Helper functions
157 ****************************************************************/
158
159// Find the first endpoing of a given type in an interface description.
160struct usb_endpoint_descriptor *
161findEndPointDesc(struct usb_interface_descriptor *iface, int imax
162 , int type, int dir)
163{
164 struct usb_endpoint_descriptor *epdesc = (void*)&iface[1];
165 for (;;) {
166 if ((void*)epdesc >= (void*)iface + imax
167 || epdesc->bDescriptorType == USB_DT_INTERFACE) {
168 return NULL;
169 }
170 if (epdesc->bDescriptorType == USB_DT_ENDPOINT
171 && (epdesc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir
172 && (epdesc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == type)
173 return epdesc;
174 epdesc = (void*)epdesc + epdesc->bLength;
175 }
176}
177
Kevin O'Connor3c160dd2010-02-17 23:06:52 -0500178// Send a message to the default control pipe of a device.
Kevin O'Connor114592f2009-09-28 21:32:08 -0400179int
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500180send_default_control(struct usb_pipe *pipe, const struct usb_ctrlrequest *req
181 , void *data)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400182{
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500183 return send_control(pipe, req->bRequestType & USB_DIR_IN
Kevin O'Connor114592f2009-09-28 21:32:08 -0400184 , req, sizeof(*req), data, req->wLength);
185}
186
187// Get the first 8 bytes of the device descriptor.
188static int
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500189get_device_info8(struct usb_pipe *pipe, struct usb_device_descriptor *dinfo)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400190{
191 struct usb_ctrlrequest req;
192 req.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
193 req.bRequest = USB_REQ_GET_DESCRIPTOR;
194 req.wValue = USB_DT_DEVICE<<8;
195 req.wIndex = 0;
196 req.wLength = 8;
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500197 return send_default_control(pipe, &req, dinfo);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400198}
199
200static struct usb_config_descriptor *
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500201get_device_config(struct usb_pipe *pipe)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400202{
203 struct usb_config_descriptor cfg;
204
205 struct usb_ctrlrequest req;
206 req.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
207 req.bRequest = USB_REQ_GET_DESCRIPTOR;
208 req.wValue = USB_DT_CONFIG<<8;
209 req.wIndex = 0;
210 req.wLength = sizeof(cfg);
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500211 int ret = send_default_control(pipe, &req, &cfg);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400212 if (ret)
213 return NULL;
214
215 void *config = malloc_tmphigh(cfg.wTotalLength);
216 if (!config)
217 return NULL;
218 req.wLength = cfg.wTotalLength;
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500219 ret = send_default_control(pipe, &req, config);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400220 if (ret)
221 return NULL;
222 //hexdump(config, cfg.wTotalLength);
223 return config;
224}
225
Kevin O'Connor114592f2009-09-28 21:32:08 -0400226static int
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500227set_configuration(struct usb_pipe *pipe, u16 val)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400228{
229 struct usb_ctrlrequest req;
230 req.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
231 req.bRequest = USB_REQ_SET_CONFIGURATION;
232 req.wValue = val;
233 req.wIndex = 0;
234 req.wLength = 0;
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500235 return send_default_control(pipe, &req, NULL);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400236}
237
Kevin O'Connor3c160dd2010-02-17 23:06:52 -0500238
239/****************************************************************
240 * Initialization and enumeration
241 ****************************************************************/
242
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500243// Assign an address to a device in the default state on the given
244// controller.
245struct usb_pipe *
Kevin O'Connor190cc622010-03-09 19:43:52 -0500246usb_set_address(struct usbhub_s *hub, int port, int speed)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400247{
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500248 ASSERT32FLAT();
Kevin O'Connor190cc622010-03-09 19:43:52 -0500249 struct usb_s *cntl = hub->cntl;
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500250 dprintf(3, "set_address %p\n", cntl);
251 if (cntl->maxaddr >= USB_MAXADDR)
252 return NULL;
Kevin O'Connor114592f2009-09-28 21:32:08 -0400253
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500254 struct usb_pipe *defpipe = cntl->defaultpipe;
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500255 if (!defpipe) {
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500256 // Create a pipe for the default address.
257 struct usb_pipe dummy;
258 memset(&dummy, 0, sizeof(dummy));
259 dummy.cntl = cntl;
260 dummy.type = cntl->type;
261 dummy.maxpacket = 8;
262 cntl->defaultpipe = defpipe = alloc_default_control_pipe(&dummy);
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500263 if (!defpipe)
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500264 return NULL;
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500265 }
Kevin O'Connor190cc622010-03-09 19:43:52 -0500266 defpipe->speed = speed;
267 if (hub->pipe) {
268 if (hub->pipe->speed == USB_HIGHSPEED) {
269 defpipe->tt_devaddr = hub->pipe->devaddr;
270 defpipe->tt_port = port;
271 } else {
272 defpipe->tt_devaddr = hub->pipe->tt_devaddr;
273 defpipe->tt_port = hub->pipe->tt_port;
274 }
275 } else {
276 defpipe->tt_devaddr = defpipe->tt_port = 0;
277 }
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500278
279 msleep(USB_TIME_RSTRCY);
280
281 struct usb_ctrlrequest req;
282 req.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
283 req.bRequest = USB_REQ_SET_ADDRESS;
284 req.wValue = cntl->maxaddr + 1;
285 req.wIndex = 0;
286 req.wLength = 0;
287 int ret = send_default_control(defpipe, &req, NULL);
288 if (ret)
289 return NULL;
290
291 msleep(USB_TIME_SETADDR_RECOVERY);
292
293 cntl->maxaddr++;
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500294 defpipe->devaddr = cntl->maxaddr;
295 struct usb_pipe *pipe = alloc_default_control_pipe(defpipe);
296 defpipe->devaddr = 0;
297 return pipe;
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500298}
299
300// Called for every found device - see if a driver is available for
301// this device and do setup if so.
302int
303configure_usb_device(struct usb_pipe *pipe)
304{
305 ASSERT32FLAT();
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500306 dprintf(3, "config_usb: %p\n", pipe);
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500307
308 // Set the max packet size for endpoint 0 of this device.
Kevin O'Connor114592f2009-09-28 21:32:08 -0400309 struct usb_device_descriptor dinfo;
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500310 int ret = get_device_info8(pipe, &dinfo);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400311 if (ret)
312 return 0;
313 dprintf(3, "device rev=%04x cls=%02x sub=%02x proto=%02x size=%02x\n"
314 , dinfo.bcdUSB, dinfo.bDeviceClass, dinfo.bDeviceSubClass
315 , dinfo.bDeviceProtocol, dinfo.bMaxPacketSize0);
316 if (dinfo.bMaxPacketSize0 < 8 || dinfo.bMaxPacketSize0 > 64)
317 return 0;
Kevin O'Connor4547eb92010-02-28 02:17:28 -0500318 pipe->maxpacket = dinfo.bMaxPacketSize0;
Kevin O'Connor114592f2009-09-28 21:32:08 -0400319
320 // Get configuration
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500321 struct usb_config_descriptor *config = get_device_config(pipe);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400322 if (!config)
323 return 0;
324
325 // Determine if a driver exists for this device - only look at the
326 // first interface of the first configuration.
327 struct usb_interface_descriptor *iface = (void*)(&config[1]);
Kevin O'Connor54671c12010-02-15 18:58:12 -0500328 if ((iface->bInterfaceClass != USB_CLASS_HID
329 || iface->bInterfaceSubClass != USB_INTERFACE_SUBCLASS_BOOT
330 || iface->bInterfaceProtocol != USB_INTERFACE_PROTOCOL_KEYBOARD)
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500331 && (iface->bInterfaceClass != USB_CLASS_MASS_STORAGE)
Kevin O'Connor54671c12010-02-15 18:58:12 -0500332 && (iface->bInterfaceClass != USB_CLASS_HUB))
333 // Not a supported device.
Kevin O'Connor114592f2009-09-28 21:32:08 -0400334 goto fail;
335
Kevin O'Connor8ebcac02010-03-09 19:58:23 -0500336 // Set the configuration.
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500337 ret = set_configuration(pipe, config->bConfigurationValue);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400338 if (ret)
339 goto fail;
340
341 // Configure driver.
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500342 int imax = (void*)config + config->wTotalLength - (void*)iface;
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500343 if (iface->bInterfaceClass == USB_CLASS_HUB)
344 ret = usb_hub_init(pipe);
345 else if (iface->bInterfaceClass == USB_CLASS_MASS_STORAGE)
346 ret = usb_msc_init(pipe, iface, imax);
Kevin O'Connor7149fc82010-02-17 23:24:42 -0500347 else
Kevin O'Connor357bdfa2010-02-26 08:57:13 -0500348 ret = usb_keyboard_init(pipe, iface, imax);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400349 if (ret)
350 goto fail;
351
Kevin O'Connor1c46a542009-10-17 23:53:32 -0400352 free(config);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400353 return 1;
354fail:
Kevin O'Connor1c46a542009-10-17 23:53:32 -0400355 free(config);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400356 return 0;
357}
358
359void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500360usb_setup(void)
Kevin O'Connor114592f2009-09-28 21:32:08 -0400361{
Kevin O'Connor59c75742010-02-13 18:49:24 -0500362 ASSERT32FLAT();
Kevin O'Connor114592f2009-09-28 21:32:08 -0400363 if (! CONFIG_USB)
364 return;
365
366 dprintf(3, "init usb\n");
367
368 usb_keyboard_setup();
369
370 // Look for USB controllers
Kevin O'Connor190cc622010-03-09 19:43:52 -0500371 int ehcibdf = -1;
Kevin O'Connor114592f2009-09-28 21:32:08 -0400372 int count = 0;
373 int bdf, max;
374 foreachpci(bdf, max) {
375 u32 code = pci_config_readl(bdf, PCI_CLASS_REVISION) >> 8;
376
377 if (code >> 8 != PCI_CLASS_SERIAL_USB)
378 continue;
379
Kevin O'Connor190cc622010-03-09 19:43:52 -0500380 if (bdf > ehcibdf) {
381 // Check to see if this device has an ehci controller
382 ehcibdf = bdf;
383 u32 ehcicode = code;
384 int found = 0;
385 for (;;) {
386 if (ehcicode == PCI_CLASS_SERIAL_USB_EHCI) {
387 // Found an ehci controller.
388 int ret = ehci_init(ehcibdf, count++, bdf);
389 if (ret)
390 // Error
391 break;
392 count += found;
393 bdf = ehcibdf;
394 code = 0;
395 break;
396 }
397 if (ehcicode >> 8 == PCI_CLASS_SERIAL_USB)
398 found++;
399 ehcibdf = pci_next(ehcibdf+1, &max);
400 if (ehcibdf < 0
401 || pci_bdf_to_busdev(ehcibdf) != pci_bdf_to_busdev(bdf))
402 // No ehci controller found.
403 break;
404 ehcicode = pci_config_readl(ehcibdf, PCI_CLASS_REVISION) >> 8;
405 }
406 }
Kevin O'Connor114592f2009-09-28 21:32:08 -0400407
Kevin O'Connor190cc622010-03-09 19:43:52 -0500408 if (code == PCI_CLASS_SERIAL_USB_UHCI)
409 uhci_init(bdf, count++);
410 else if (code == PCI_CLASS_SERIAL_USB_OHCI)
411 ohci_init(bdf, count++);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400412 }
413}