| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include <libpayload-config.h> |
| 31 |
#include <usb/usb.h> |
| 32 |
#include "uhci.h" |
| 33 |
#include "ohci.h" |
| 34 |
#include "ehci.h" |
| 35 |
#include "xhci.h" |
| 36 |
#include "dwc2.h" |
| 37 |
#include <usb/usbdisk.h> |
| 38 |
|
| 39 |
#if CONFIG(LP_USB_PCI) |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
static int usb_controller_initialize(int bus, int dev, int func) |
| 48 |
{ |
| 49 |
u32 class; |
| 50 |
u32 devclass; |
| 51 |
u32 prog_if; |
| 52 |
pcidev_t pci_device; |
| 53 |
u32 pciid; |
| 54 |
|
| 55 |
pci_device = PCI_DEV(bus, dev, func); |
| 56 |
class = pci_read_config32(pci_device, 8); |
| 57 |
pciid = pci_read_config32(pci_device, 0); |
| 58 |
|
| 59 |
devclass = class >> 16; |
| 60 |
prog_if = (class >> 8) & 0xff; |
| 61 |
|
| 62 |
|
| 63 |
if (devclass == 0xc03) { |
| 64 |
u16 pci_command; |
| 65 |
|
| 66 |
pci_command = pci_read_config16(pci_device, PCI_COMMAND); |
| 67 |
pci_command |= PCI_COMMAND_MASTER; |
| 68 |
pci_write_config16(pci_device, PCI_COMMAND, pci_command); |
| 69 |
|
| 70 |
usb_debug("%02x:%02x.%x %04x:%04x.%d ", bus, dev, func, |
| 71 |
pciid >> 16, pciid & 0xFFFF, func); |
| 72 |
switch (prog_if) { |
| 73 |
case 0x00: |
| 74 |
#if CONFIG(LP_USB_UHCI) |
| 75 |
usb_debug("UHCI controller\n"); |
| 76 |
uhci_pci_init(pci_device); |
| 77 |
#else |
| 78 |
usb_debug("UHCI controller (not supported)\n"); |
| 79 |
#endif |
| 80 |
break; |
| 81 |
|
| 82 |
case 0x10: |
| 83 |
#if CONFIG(LP_USB_OHCI) |
| 84 |
usb_debug("OHCI controller\n"); |
| 85 |
ohci_pci_init(pci_device); |
| 86 |
#else |
| 87 |
usb_debug("OHCI controller (not supported)\n"); |
| 88 |
#endif |
| 89 |
break; |
| 90 |
|
| 91 |
case 0x20: |
| 92 |
#if CONFIG(LP_USB_EHCI) |
| 93 |
usb_debug("EHCI controller\n"); |
| 94 |
ehci_pci_init(pci_device); |
| 95 |
#else |
| 96 |
usb_debug("EHCI controller (not supported)\n"); |
| 97 |
#endif |
| 98 |
break; |
| 99 |
|
| 100 |
case 0x30: |
| 101 |
#if CONFIG(LP_USB_XHCI) |
| 102 |
usb_debug("xHCI controller\n"); |
| 103 |
xhci_pci_init(pci_device); |
| 104 |
#else |
| 105 |
usb_debug("xHCI controller (not supported)\n"); |
| 106 |
#endif |
| 107 |
break; |
| 108 |
|
| 109 |
default: |
| 110 |
usb_debug("unknown controller %x not supported\n", |
| 111 |
prog_if); |
| 112 |
break; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
return 0; |
| 117 |
} |
| 118 |
|
| 119 |
static void usb_scan_pci_bus(int bus) |
| 120 |
{ |
| 121 |
int dev, func; |
| 122 |
for (dev = 0; dev < 32; dev++) { |
| 123 |
u8 header_type; |
| 124 |
pcidev_t pci_device = PCI_DEV(bus, dev, 0); |
| 125 |
|
| 126 |
|
| 127 |
if (pci_read_config32(pci_device, REG_VENDOR_ID) == 0xffffffff) |
| 128 |
continue; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
header_type = pci_read_config8(pci_device, REG_HEADER_TYPE); |
| 139 |
if (header_type & HEADER_TYPE_MULTIFUNCTION) |
| 140 |
func = 7; |
| 141 |
else |
| 142 |
func = 0; |
| 143 |
|
| 144 |
for (; func >= 0; func--) { |
| 145 |
pci_device = PCI_DEV(bus, dev, func); |
| 146 |
header_type = pci_read_config8(pci_device, REG_HEADER_TYPE); |
| 147 |
|
| 148 |
if ((header_type & ~HEADER_TYPE_MULTIFUNCTION) == |
| 149 |
HEADER_TYPE_BRIDGE) { |
| 150 |
|
| 151 |
if ((pci_read_config16(pci_device, REG_COMMAND) |
| 152 |
& 3) != 0) |
| 153 |
usb_scan_pci_bus(pci_read_config8( |
| 154 |
pci_device, REG_SECONDARY_BUS)); |
| 155 |
} |
| 156 |
else |
| 157 |
usb_controller_initialize(bus, dev, func); |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
#endif |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
int usb_initialize(void) |
| 167 |
{ |
| 168 |
#if CONFIG(LP_USB_PCI) |
| 169 |
usb_scan_pci_bus(0); |
| 170 |
#endif |
| 171 |
return 0; |
| 172 |
} |
| 173 |
|
| 174 |
hci_t *usb_add_mmio_hc(hc_type type, void *bar) |
| 175 |
{ |
| 176 |
switch (type) { |
| 177 |
#if CONFIG(LP_USB_OHCI) |
| 178 |
case OHCI: |
| 179 |
return ohci_init((unsigned long)bar); |
| 180 |
#endif |
| 181 |
#if CONFIG(LP_USB_EHCI) |
| 182 |
case EHCI: |
| 183 |
return ehci_init((unsigned long)bar); |
| 184 |
#endif |
| 185 |
#if CONFIG(LP_USB_DWC2) |
| 186 |
case DWC2: |
| 187 |
return dwc2_init(bar); |
| 188 |
#endif |
| 189 |
#if CONFIG(LP_USB_XHCI) |
| 190 |
case XHCI: |
| 191 |
return xhci_init((unsigned long)bar); |
| 192 |
#endif |
| 193 |
default: |
| 194 |
usb_debug("HC type %d (at %p) is not supported!\n", type, bar); |
| 195 |
return NULL; |
| 196 |
} |
| 197 |
} |