diff options
author | Yidi Lin <yidilin@chromium.org> | 2022-08-10 14:59:18 +0800 |
---|---|---|
committer | Martin Roth <martin.roth@amd.corp-partner.google.com> | 2022-08-12 17:17:53 +0000 |
commit | 5ef258b3f6a6481d20f1fca0f60db894b80649ab (patch) | |
tree | 8fc99f95a5c066384e15bd464f04a327b3d10bb7 | |
parent | ad6b27e9efa84d121b1d55db44fd35a8a52635cc (diff) |
libpayload: usb: Fix spacing issues
Found by:
find payloads/libpayload/drivers/usb -type f -name "*.[ch]" | xargs \
util/lint/checkpatch.pl --types SPACING -q --fix-inplace -f
Change-Id: Id23e2e573e475c6d795812a4b2df9aeffbcaaaf4
Signed-off-by: Yidi Lin <yidilin@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66596
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
24 files changed, 623 insertions, 623 deletions
diff --git a/payloads/libpayload/drivers/usb/dwc2.h b/payloads/libpayload/drivers/usb/dwc2.h index 8a0098f57f..9a71d6986a 100644 --- a/payloads/libpayload/drivers/usb/dwc2.h +++ b/payloads/libpayload/drivers/usb/dwc2.h @@ -17,6 +17,6 @@ #include <usb/usb.h> hci_t *dwc2_init(void *bar); -void dwc2_rh_init (usbdev_t *dev); +void dwc2_rh_init(usbdev_t *dev); #endif diff --git a/payloads/libpayload/drivers/usb/ehci.c b/payloads/libpayload/drivers/usb/ehci.c index 58fc64eead..822fdb19a9 100644 --- a/payloads/libpayload/drivers/usb/ehci.c +++ b/payloads/libpayload/drivers/usb/ehci.c @@ -119,17 +119,17 @@ static void dump_qh(ehci_qh_t *cur) } #endif -static void ehci_start (hci_t *controller) +static void ehci_start(hci_t *controller) { EHCI_INST(controller)->operation->usbcmd |= HC_OP_RS; } -static void ehci_stop (hci_t *controller) +static void ehci_stop(hci_t *controller) { EHCI_INST(controller)->operation->usbcmd &= ~HC_OP_RS; } -static void ehci_reset (hci_t *controller) +static void ehci_reset(hci_t *controller) { short count = 0; ehci_stop(controller); @@ -148,7 +148,7 @@ static void ehci_reset (hci_t *controller) usb_debug("ehci_reset(): reset failed!\n"); } -static void ehci_reinit (hci_t *controller) +static void ehci_reinit(hci_t *controller) { } @@ -174,7 +174,7 @@ static int ehci_set_periodic_schedule(ehci_t *ehcic, int enable) return 0; } -static void ehci_shutdown (hci_t *controller) +static void ehci_shutdown(hci_t *controller) { detach_controller(controller); @@ -192,7 +192,7 @@ static void ehci_shutdown (hci_t *controller) free(controller); } -enum { EHCI_OUT=0, EHCI_IN=1, EHCI_SETUP=2 }; +enum { EHCI_OUT = 0, EHCI_IN = 1, EHCI_SETUP = 2 }; /* returns handled bytes. assumes that the fields it writes are empty on entry */ static int fill_td(qtd_t *td, void* data, int datalen) @@ -341,7 +341,7 @@ static int ehci_process_async_schedule( return result; } -static int ehci_bulk (endpoint_t *ep, int size, u8 *src, int finalize) +static int ehci_bulk(endpoint_t *ep, int size, u8 *src, int finalize) { int result = 0; u8 *end = src + size; @@ -430,7 +430,7 @@ oom: } /* FIXME: Handle control transfers as 3 QHs, so the 2nd stage can be >0x4000 bytes */ -static int ehci_control (usbdev_t *dev, direction_t dir, int drlen, void *setup, +static int ehci_control(usbdev_t *dev, direction_t dir, int drlen, void *setup, int dalen, u8 *src) { u8 *data = src; @@ -771,11 +771,11 @@ static u8 *ehci_poll_intr_queue(void *const queue) } hci_t * -ehci_init (unsigned long physical_bar) +ehci_init(unsigned long physical_bar) { int i; - hci_t *controller = new_controller (); - controller->instance = xzalloc(sizeof (ehci_t)); + hci_t *controller = new_controller(); + controller->instance = xzalloc(sizeof(ehci_t)); controller->reg_base = (uintptr_t)physical_bar; controller->type = EHCI; controller->start = ehci_start; @@ -791,7 +791,7 @@ ehci_init (unsigned long physical_bar) controller->create_intr_queue = ehci_create_intr_queue; controller->destroy_intr_queue = ehci_destroy_intr_queue; controller->poll_intr_queue = ehci_poll_intr_queue; - init_device_entry (controller, 0); + init_device_entry(controller, 0); EHCI_INST(controller)->capabilities = phys_to_virt(physical_bar); EHCI_INST(controller)->operation = (hc_op_t *)(phys_to_virt(physical_bar) + EHCI_INST(controller)->capabilities->caplength); @@ -848,23 +848,23 @@ ehci_init (unsigned long physical_bar) controller->devices[0]->controller = controller; controller->devices[0]->init = ehci_rh_init; - controller->devices[0]->init (controller->devices[0]); + controller->devices[0]->init(controller->devices[0]); return controller; } #if CONFIG(LP_USB_PCI) hci_t * -ehci_pci_init (pcidev_t addr) +ehci_pci_init(pcidev_t addr) { hci_t *controller; u32 reg_base; u16 pci_command = pci_read_config16(addr, PCI_COMMAND); - pci_command = (pci_command | PCI_COMMAND_MEMORY) & ~PCI_COMMAND_IO ; + pci_command = (pci_command | PCI_COMMAND_MEMORY) & ~PCI_COMMAND_IO; pci_write_config16(addr, PCI_COMMAND, pci_command); - reg_base = pci_read_config32 (addr, USBBASE); + reg_base = pci_read_config32(addr, USBBASE); /* default value for frame length adjust */ pci_write_config8(addr, FLADJ, FLADJ_framelength(60000)); diff --git a/payloads/libpayload/drivers/usb/ehci.h b/payloads/libpayload/drivers/usb/ehci.h index d3937c6711..94b5d6f175 100644 --- a/payloads/libpayload/drivers/usb/ehci.h +++ b/payloads/libpayload/drivers/usb/ehci.h @@ -32,9 +32,9 @@ #include <pci.h> #include <usb/usb.h> -hci_t *ehci_pci_init (pcidev_t addr); -hci_t *ehci_init (unsigned long physical_bar); +hci_t *ehci_pci_init(pcidev_t addr); +hci_t *ehci_init(unsigned long physical_bar); -void ehci_rh_init (usbdev_t *dev); +void ehci_rh_init(usbdev_t *dev); #endif diff --git a/payloads/libpayload/drivers/usb/ehci_rh.c b/payloads/libpayload/drivers/usb/ehci_rh.c index edb1b4ad4d..c5bcd5df95 100644 --- a/payloads/libpayload/drivers/usb/ehci_rh.c +++ b/payloads/libpayload/drivers/usb/ehci_rh.c @@ -46,7 +46,7 @@ typedef struct { #define RH_INST(dev) ((rh_inst_t*)(dev)->data) static void -ehci_rh_destroy (usbdev_t *dev) +ehci_rh_destroy(usbdev_t *dev) { int port; @@ -59,12 +59,12 @@ ehci_rh_destroy (usbdev_t *dev) } } - free (RH_INST(dev)->devices); - free (RH_INST(dev)); + free(RH_INST(dev)->devices); + free(RH_INST(dev)); } static void -ehci_rh_hand_over_port (usbdev_t *dev, int port) +ehci_rh_hand_over_port(usbdev_t *dev, int port) { usb_debug("giving up port %x, it's USB1\n", port+1); @@ -89,14 +89,14 @@ ehci_rh_hand_over_port (usbdev_t *dev, int port) } static void -ehci_rh_scanport (usbdev_t *dev, int port) +ehci_rh_scanport(usbdev_t *dev, int port) { usb_speed port_speed; - if (RH_INST(dev)->devices[port]!=-1) { + if (RH_INST(dev)->devices[port] != -1) { usb_debug("Unregister device at port %x\n", port+1); usb_detach_device(dev->controller, RH_INST(dev)->devices[port]); - RH_INST(dev)->devices[port]=-1; + RH_INST(dev)->devices[port] = -1; } /* device connected, handle */ if (RH_INST(dev)->ports[port] & P_CURR_CONN_STATUS) { @@ -153,10 +153,10 @@ ehci_rh_scanport (usbdev_t *dev, int port) } static int -ehci_rh_report_port_changes (usbdev_t *dev) +ehci_rh_report_port_changes(usbdev_t *dev) { int i; - for (i=0; i<RH_INST(dev)->n_ports; i++) { + for (i = 0; i < RH_INST(dev)->n_ports; i++) { if (RH_INST(dev)->ports[i] & P_CONN_STATUS_CHANGE) return i; } @@ -164,15 +164,15 @@ ehci_rh_report_port_changes (usbdev_t *dev) } static void -ehci_rh_poll (usbdev_t *dev) +ehci_rh_poll(usbdev_t *dev) { int port; - while ((port = ehci_rh_report_port_changes (dev)) != -1) - ehci_rh_scanport (dev, port); + while ((port = ehci_rh_report_port_changes(dev)) != -1) + ehci_rh_scanport(dev, port); } void -ehci_rh_init (usbdev_t *dev) +ehci_rh_init(usbdev_t *dev) { int i; dev->destroy = ehci_rh_destroy; @@ -192,7 +192,7 @@ ehci_rh_init (usbdev_t *dev) & HCS_PORT_POWER_CONTROL) { usb_debug("host controller has port power control, " "giving power to all ports.\n"); - for (i=0; i < RH_INST(dev)->n_ports; i++) + for (i = 0; i < RH_INST(dev)->n_ports; i++) RH_INST(dev)->ports[i] |= P_PP; } mdelay(20); // ehci spec 2.3.9 @@ -201,7 +201,7 @@ ehci_rh_init (usbdev_t *dev) dev->address = 0; dev->hub = -1; dev->port = -1; - for (i=0; i < RH_INST(dev)->n_ports; i++) { + for (i = 0; i < RH_INST(dev)->n_ports; i++) { RH_INST(dev)->devices[i] = -1; ehci_rh_scanport(dev, i); } diff --git a/payloads/libpayload/drivers/usb/generic_hub.h b/payloads/libpayload/drivers/usb/generic_hub.h index 1e7d1be069..d63d186be3 100644 --- a/payloads/libpayload/drivers/usb/generic_hub.h +++ b/payloads/libpayload/drivers/usb/generic_hub.h @@ -45,7 +45,7 @@ typedef struct generic_hub_ops { /* returns 1 if the port is enabled */ int (*port_enabled)(usbdev_t *, int port); /* returns speed if port is enabled, negative value if not */ - usb_speed (*port_speed)(usbdev_t *, int port); + usb_speed(*port_speed)(usbdev_t *, int port); /* enables (powers up) a port (optional) */ int (*enable_port)(usbdev_t *, int port); diff --git a/payloads/libpayload/drivers/usb/ohci.c b/payloads/libpayload/drivers/usb/ohci.c index f35d1ff0e8..79add33fe7 100644 --- a/payloads/libpayload/drivers/usb/ohci.c +++ b/payloads/libpayload/drivers/usb/ohci.c @@ -34,21 +34,21 @@ #include "ohci_private.h" #include "ohci.h" -static void ohci_start (hci_t *controller); -static void ohci_stop (hci_t *controller); -static void ohci_reset (hci_t *controller); -static void ohci_shutdown (hci_t *controller); -static int ohci_bulk (endpoint_t *ep, int size, u8 *data, int finalize); -static int ohci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, +static void ohci_start(hci_t *controller); +static void ohci_stop(hci_t *controller); +static void ohci_reset(hci_t *controller); +static void ohci_shutdown(hci_t *controller); +static int ohci_bulk(endpoint_t *ep, int size, u8 *data, int finalize); +static int ohci_control(usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen, u8 *data); -static void* ohci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming); -static void ohci_destroy_intr_queue (endpoint_t *ep, void *queue); -static u8* ohci_poll_intr_queue (void *queue); +static void* ohci_create_intr_queue(endpoint_t *ep, int reqsize, int reqcount, int reqtiming); +static void ohci_destroy_intr_queue(endpoint_t *ep, void *queue); +static u8* ohci_poll_intr_queue(void *queue); static int ohci_process_done_queue(ohci_t *ohci, int spew_debug); #ifdef USB_DEBUG static void -dump_td (td_t *cur) +dump_td(td_t *cur) { usb_debug("+---------------------------------------------------+\n"); if (((cur->config & (3UL << 19)) >> 19) == 0) @@ -81,7 +81,7 @@ dump_td (td_t *cur) } static void -dump_ed (ed_t *cur) +dump_ed(ed_t *cur) { td_t *tmp_td = NULL; usb_debug("+===================================================+\n"); @@ -120,7 +120,7 @@ dump_ed (ed_t *cur) #endif static void -ohci_reset (hci_t *controller) +ohci_reset(hci_t *controller) { if (controller == NULL) return; @@ -132,7 +132,7 @@ ohci_reset (hci_t *controller) } static void -ohci_reinit (hci_t *controller) +ohci_reinit(hci_t *controller) { } @@ -167,12 +167,12 @@ static const char *direction[] = { #endif hci_t * -ohci_init (unsigned long physical_bar) +ohci_init(unsigned long physical_bar) { int i; - hci_t *controller = new_controller (); - controller->instance = xzalloc(sizeof (ohci_t)); + hci_t *controller = new_controller(); + controller->instance = xzalloc(sizeof(ohci_t)); controller->reg_base = (uintptr_t)physical_bar; controller->type = OHCI; controller->start = ohci_start; @@ -188,33 +188,33 @@ ohci_init (unsigned long physical_bar) controller->create_intr_queue = ohci_create_intr_queue; controller->destroy_intr_queue = ohci_destroy_intr_queue; controller->poll_intr_queue = ohci_poll_intr_queue; - init_device_entry (controller, 0); - OHCI_INST (controller)->roothub = controller->devices[0]; + init_device_entry(controller, 0); + OHCI_INST(controller)->roothub = controller->devices[0]; - OHCI_INST (controller)->opreg = (opreg_t*)phys_to_virt(physical_bar); - usb_debug("OHCI Version %x.%x\n", (OHCI_INST (controller)->opreg->HcRevision >> 4) & 0xf, OHCI_INST (controller)->opreg->HcRevision & 0xf); + OHCI_INST(controller)->opreg = (opreg_t*)phys_to_virt(physical_bar); + usb_debug("OHCI Version %x.%x\n", (OHCI_INST(controller)->opreg->HcRevision >> 4) & 0xf, OHCI_INST(controller)->opreg->HcRevision & 0xf); - if ((OHCI_INST (controller)->opreg->HcControl & HostControllerFunctionalStateMask) == USBReset) { + if ((OHCI_INST(controller)->opreg->HcControl & HostControllerFunctionalStateMask) == USBReset) { /* cold boot */ - OHCI_INST (controller)->opreg->HcControl &= ~RemoteWakeupConnected; - OHCI_INST (controller)->opreg->HcFmInterval = (11999 * FrameInterval) | ((((11999 - 210)*6)/7) * FSLargestDataPacket); + OHCI_INST(controller)->opreg->HcControl &= ~RemoteWakeupConnected; + OHCI_INST(controller)->opreg->HcFmInterval = (11999 * FrameInterval) | ((((11999 - 210)*6)/7) * FSLargestDataPacket); /* TODO: right value for PowerOnToPowerGoodTime ? */ - OHCI_INST (controller)->opreg->HcRhDescriptorA = NoPowerSwitching | NoOverCurrentProtection | (10 * PowerOnToPowerGoodTime); - OHCI_INST (controller)->opreg->HcRhDescriptorB = (0 * DeviceRemovable); + OHCI_INST(controller)->opreg->HcRhDescriptorA = NoPowerSwitching | NoOverCurrentProtection | (10 * PowerOnToPowerGoodTime); + OHCI_INST(controller)->opreg->HcRhDescriptorB = (0 * DeviceRemovable); udelay(100); /* TODO: reset asserting according to USB spec */ - } else if ((OHCI_INST (controller)->opreg->HcControl & HostControllerFunctionalStateMask) != USBOperational) { - OHCI_INST (controller)->opreg->HcControl = (OHCI_INST (controller)->opreg->HcControl & ~HostControllerFunctionalStateMask) | USBResume; + } else if ((OHCI_INST(controller)->opreg->HcControl & HostControllerFunctionalStateMask) != USBOperational) { + OHCI_INST(controller)->opreg->HcControl = (OHCI_INST(controller)->opreg->HcControl & ~HostControllerFunctionalStateMask) | USBResume; udelay(100); /* TODO: resume time according to USB spec */ } - int interval = OHCI_INST (controller)->opreg->HcFmInterval; + int interval = OHCI_INST(controller)->opreg->HcFmInterval; - OHCI_INST (controller)->opreg->HcCommandStatus = HostControllerReset; - udelay (10); /* at most 10us for reset to complete. State must be set to Operational within 2ms (5.1.1.4) */ - OHCI_INST (controller)->opreg->HcFmInterval = interval; - OHCI_INST (controller)->hcca = dma_memalign(256, 256); + OHCI_INST(controller)->opreg->HcCommandStatus = HostControllerReset; + udelay(10); /* at most 10us for reset to complete. State must be set to Operational within 2ms (5.1.1.4) */ + OHCI_INST(controller)->opreg->HcFmInterval = interval; + OHCI_INST(controller)->hcca = dma_memalign(256, 256); if (!OHCI_INST(controller)->hcca) fatal("Not enough DMA memory for OHCI HCCA.\n"); - memset((void*)OHCI_INST (controller)->hcca, 0, 256); + memset((void*)OHCI_INST(controller)->hcca, 0, 256); if (dma_initialized()) { OHCI_INST(controller)->dma_buffer = dma_memalign(4096, DMA_SIZE); @@ -230,66 +230,66 @@ ohci_init (unsigned long physical_bar) memset((void *)periodic_ed, 0, sizeof(*periodic_ed)); for (i = 0; i < 32; ++i) intr_table[i] = virt_to_phys(periodic_ed); - OHCI_INST (controller)->periodic_ed = periodic_ed; + OHCI_INST(controller)->periodic_ed = periodic_ed; - OHCI_INST (controller)->opreg->HcHCCA = virt_to_phys(OHCI_INST (controller)->hcca); + OHCI_INST(controller)->opreg->HcHCCA = virt_to_phys(OHCI_INST(controller)->hcca); /* Make sure periodic schedule is enabled. */ - OHCI_INST (controller)->opreg->HcControl |= PeriodicListEnable; - OHCI_INST (controller)->opreg->HcControl &= ~IsochronousEnable; // unused by this driver + OHCI_INST(controller)->opreg->HcControl |= PeriodicListEnable; + OHCI_INST(controller)->opreg->HcControl &= ~IsochronousEnable; // unused by this driver // disable everything, contrary to what OHCI spec says in 5.1.1.4, as we don't need IRQs - OHCI_INST (controller)->opreg->HcInterruptEnable = 1 << 31; - OHCI_INST (controller)->opreg->HcInterruptDisable = ~(1 << 31); - OHCI_INST (controller)->opreg->HcInterruptStatus = ~0; - OHCI_INST (controller)->opreg->HcPeriodicStart = (((OHCI_INST (controller)->opreg->HcFmInterval & FrameIntervalMask) / 10) * 9); - OHCI_INST (controller)->opreg->HcControl = (OHCI_INST (controller)->opreg->HcControl & ~HostControllerFunctionalStateMask) | USBOperational; + OHCI_INST(controller)->opreg->HcInterruptEnable = 1 << 31; + OHCI_INST(controller)->opreg->HcInterruptDisable = ~(1 << 31); + OHCI_INST(controller)->opreg->HcInterruptStatus = ~0; + OHCI_INST(controller)->opreg->HcPeriodicStart = (((OHCI_INST(controller)->opreg->HcFmInterval & FrameIntervalMask) / 10) * 9); + OHCI_INST(controller)->opreg->HcControl = (OHCI_INST(controller)->opreg->HcControl & ~HostControllerFunctionalStateMask) | USBOperational; mdelay(100); controller->devices[0]->controller = controller; controller->devices[0]->init = ohci_rh_init; - controller->devices[0]->init (controller->devices[0]); + controller->devices[0]->init(controller->devices[0]); return controller; } #if CONFIG(LP_USB_PCI) hci_t * -ohci_pci_init (pcidev_t addr) +ohci_pci_init(pcidev_t addr) { u32 reg_base; /* regarding OHCI spec, Appendix A, BAR_OHCI register description, Table A-4 * BASE ADDRESS only [31-12] bits. All other usually 0, but not all. * OHCI mandates MMIO, so bit 0 is clear */ - reg_base = pci_read_config32 (addr, 0x10) & 0xfffff000; + reg_base = pci_read_config32(addr, 0x10) & 0xfffff000; return ohci_init((unsigned long)reg_base); } #endif static void -ohci_shutdown (hci_t *controller) +ohci_shutdown(hci_t *controller) { if (controller == 0) return; - detach_controller (controller); + detach_controller(controller); ohci_stop(controller); ohci_reset(controller); - free (OHCI_INST (controller)->hcca); - free ((void *)OHCI_INST (controller)->periodic_ed); - free (OHCI_INST (controller)); - free (controller); + free(OHCI_INST(controller)->hcca); + free((void *)OHCI_INST(controller)->periodic_ed); + free(OHCI_INST(controller)); + free(controller); } static void -ohci_start (hci_t *controller) +ohci_start(hci_t *controller) { - OHCI_INST (controller)->opreg->HcControl |= PeriodicListEnable; + OHCI_INST(controller)->opreg->HcControl |= PeriodicListEnable; } static void -ohci_stop (hci_t *controller) +ohci_stop(hci_t *controller) { - OHCI_INST (controller)->opreg->HcControl &= ~PeriodicListEnable; + OHCI_INST(controller)->opreg->HcControl &= ~PeriodicListEnable; } #define OHCI_SLEEP_TIME_US 1000 @@ -330,7 +330,7 @@ wait_for_ed(usbdev_t *dev, ed_t *head, int pages) } static void -ohci_free_ed (ed_t *const head) +ohci_free_ed(ed_t *const head) { /* In case the transfer canceled, we have to free unprocessed TDs. */ while ((head->head_pointer & ~0x3) != head->tail_pointer) { @@ -351,7 +351,7 @@ ohci_free_ed (ed_t *const head) } static int -ohci_control (usbdev_t *dev, direction_t dir, int drlen, void *setup, int dalen, +ohci_control(usbdev_t *dev, direction_t dir, int drlen, void *setup, int dalen, unsigned char *src) { u8 *data = src; @@ -501,7 +501,7 @@ ohci_control (usbdev_t *dev, direction_t dir, int drlen, void *setup, int dalen, /* finalize == 1: if data is of packet aligned size, add a zero length packet */ static int -ohci_bulk (endpoint_t *ep, int dalen, u8 *src, int finalize) +ohci_bulk(endpoint_t *ep, int dalen, u8 *src, int finalize) { int i; td_t *cur, *next; @@ -763,7 +763,7 @@ ohci_destroy_intr_queue(endpoint_t *const ep, void *const q_) /* Remove interrupt queue from periodic table. */ ohci_t *const ohci = OHCI_INST(ep->dev->controller); u32 *const intr_table = ohci->hcca->HccaInterruptTable; - for (i=0; i < 32; ++i) { + for (i = 0; i < 32; ++i) { if (intr_table[i] == virt_to_phys(intrq)) intr_table[i] = virt_to_phys(ohci->periodic_ed); } diff --git a/payloads/libpayload/drivers/usb/ohci.h b/payloads/libpayload/drivers/usb/ohci.h index 83ec058838..a92e621fc9 100644 --- a/payloads/libpayload/drivers/usb/ohci.h +++ b/payloads/libpayload/drivers/usb/ohci.h @@ -32,9 +32,9 @@ #include <pci.h> #include <usb/usb.h> -hci_t *ohci_pci_init (pcidev_t addr); -hci_t *ohci_init (unsigned long physical_bar); +hci_t *ohci_pci_init(pcidev_t addr); +hci_t *ohci_init(unsigned long physical_bar); -void ohci_rh_init (usbdev_t *dev); +void ohci_rh_init(usbdev_t *dev); #endif diff --git a/payloads/libpayload/drivers/usb/ohci_private.h b/payloads/libpayload/drivers/usb/ohci_private.h index e29e5901bf..fd5ef65eb5 100644 --- a/payloads/libpayload/drivers/usb/ohci_private.h +++ b/payloads/libpayload/drivers/usb/ohci_private.h @@ -262,6 +262,6 @@ void *dma_buffer; } ohci_t; - typedef enum { OHCI_SETUP=0, OHCI_OUT=1, OHCI_IN=2, OHCI_FROM_TD=3 } ohci_pid_t; + typedef enum { OHCI_SETUP = 0, OHCI_OUT = 1, OHCI_IN = 2, OHCI_FROM_TD = 3 } ohci_pid_t; #endif diff --git a/payloads/libpayload/drivers/usb/ohci_rh.c b/payloads/libpayload/drivers/usb/ohci_rh.c index c84694743f..d217b96b67 100644 --- a/payloads/libpayload/drivers/usb/ohci_rh.c +++ b/payloads/libpayload/drivers/usb/ohci_rh.c @@ -40,7 +40,7 @@ typedef struct { #define RH_INST(dev) ((rh_inst_t*)(dev)->data) static void -ohci_rh_enable_port (usbdev_t *dev, int port) +ohci_rh_enable_port(usbdev_t *dev, int port) { /* Reset RH port should hold 50ms with pulses of at least 10ms and * gaps of at most 3ms (usb20 spec 7.1.7.5). @@ -54,15 +54,15 @@ ohci_rh_enable_port (usbdev_t *dev, int port) return; /* start reset */ - OHCI_INST (dev->controller)->opreg->HcRhPortStatus[port] = + OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] = SetPortReset; int timeout = 200; /* timeout after 200 * 500us == 100ms */ - while ((OHCI_INST (dev->controller)->opreg->HcRhPortStatus[port] + while ((OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] & PortResetStatus) && timeout--) { udelay(500); total_delay--; } - if (OHCI_INST (dev->controller)->opreg->HcRhPortStatus[port] + if (OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] & PortResetStatus) { usb_debug("Warning: root-hub port reset timed out.\n"); break; @@ -72,24 +72,24 @@ ohci_rh_enable_port (usbdev_t *dev, int port) "should be at least 10ms.\n", (200-timeout)/2); /* clear reset status change */ - OHCI_INST (dev->controller)->opreg->HcRhPortStatus[port] = + OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] = PortResetStatusChange; - usb_debug ("rh port reset finished after %dms.\n", (200-timeout)/2); + usb_debug("rh port reset finished after %dms.\n", (200-timeout)/2); } } /* disable root hub */ static void -ohci_rh_disable_port (usbdev_t *dev, int port) +ohci_rh_disable_port(usbdev_t *dev, int port) { - if (RH_INST (dev)->port[port] != -1) { - usb_detach_device(dev->controller, RH_INST (dev)->port[port]); - RH_INST (dev)->port[port] = -1; + if (RH_INST(dev)->port[port] != -1) { + usb_detach_device(dev->controller, RH_INST(dev)->port[port]); + RH_INST(dev)->port[port] = -1; } - OHCI_INST (dev->controller)->opreg->HcRhPortStatus[port] = ClearPortEnable; // disable port + OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] = ClearPortEnable; // disable port int timeout = 50; /* timeout after 50 * 100us == 5ms */ - while ((OHCI_INST (dev->controller)->opreg->HcRhPortStatus[port] + while ((OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] & PortEnableStatus) && timeout--) { udelay(100); @@ -97,7 +97,7 @@ ohci_rh_disable_port (usbdev_t *dev, int port) } static void -ohci_rh_scanport (usbdev_t *dev, int port) +ohci_rh_scanport(usbdev_t *dev, int port) { if (port >= RH_INST(dev)->numports) { usb_debug("Invalid port %d\n", port); @@ -105,9 +105,9 @@ ohci_rh_scanport (usbdev_t *dev, int port) } /* device registered, and device change logged, so something must have happened */ - if (RH_INST (dev)->port[port] != -1) { - usb_detach_device(dev->controller, RH_INST (dev)->port[port]); - RH_INST (dev)->port[port] = -1; + if (RH_INST(dev)->port[port] != -1) { + usb_detach_device(dev->controller, RH_INST(dev)->port[port]); + RH_INST(dev)->port[port] = -1; } /* no device attached @@ -115,24 +115,24 @@ ohci_rh_scanport (usbdev_t *dev, int port) if (!(OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] & CurrentConnectStatus)) return; - OHCI_INST (dev->controller)->opreg->HcRhPortStatus[port] = ConnectStatusChange; // clear port state change - ohci_rh_enable_port (dev, port); + OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] = ConnectStatusChange; // clear port state change + ohci_rh_enable_port(dev, port); mdelay(100); // wait for signal to stabilize if (!(OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] & PortEnableStatus)) { - usb_debug ("port enable failed\n"); + usb_debug("port enable failed\n"); return; } usb_speed speed = (OHCI_INST(dev->controller)->opreg->HcRhPortStatus[port] & LowSpeedDeviceAttached) != 0; - RH_INST (dev)->port[port] = usb_attach_device(dev->controller, dev->address, port, speed); + RH_INST(dev)->port[port] = usb_attach_device(dev->controller, dev->address, port, speed); } static int -ohci_rh_report_port_changes (usbdev_t *dev) +ohci_rh_report_port_changes(usbdev_t *dev) { - ohci_t *const ohcic = OHCI_INST (dev->controller); + ohci_t *const ohcic = OHCI_INST(dev->controller); int i; @@ -150,18 +150,18 @@ ohci_rh_report_port_changes (usbdev_t *dev) } static void -ohci_rh_destroy (usbdev_t *dev) +ohci_rh_destroy(usbdev_t *dev) { int i; - for (i = 0; i < RH_INST (dev)->numports; i++) - ohci_rh_disable_port (dev, i); - free (RH_INST (dev)); + for (i = 0; i < RH_INST(dev)->numports; i++) + ohci_rh_disable_port(dev, i); + free(RH_INST(dev)); } static void -ohci_rh_poll (usbdev_t *dev) +ohci_rh_poll(usbdev_t *dev) { - ohci_t *const ohcic = OHCI_INST (dev->controller); + ohci_t *const ohcic = OHCI_INST(dev->controller); int port; @@ -172,26 +172,26 @@ ohci_rh_poll (usbdev_t *dev) usb_debug("root hub status change\n"); /* Scan ports with changed connection status. */ - while ((port = ohci_rh_report_port_changes (dev)) != -1) - ohci_rh_scanport (dev, port); + while ((port = ohci_rh_report_port_changes(dev)) != -1) + ohci_rh_scanport(dev, port); } void -ohci_rh_init (usbdev_t *dev) +ohci_rh_init(usbdev_t *dev) { int i; dev->destroy = ohci_rh_destroy; dev->poll = ohci_rh_poll; - dev->data = xmalloc (sizeof (rh_inst_t)); - RH_INST (dev)->numports = OHCI_INST (dev->controller)->opreg->HcRhDescriptorA & NumberDownstreamPortsMask; - RH_INST (dev)->port = xmalloc(sizeof(int) * RH_INST (dev)->numports); - usb_debug("%d ports registered\n", RH_INST (dev)->numports); + dev->data = xmalloc(sizeof(rh_inst_t)); + RH_INST(dev)->numports = OHCI_INST(dev->controller)->opreg->HcRhDescriptorA & NumberDownstreamPortsMask; + RH_INST(dev)->port = xmalloc(sizeof(int) * RH_INST(dev)->numports); + usb_debug("%d ports registered\n", RH_INST(dev)->numports); - for (i = 0; i < RH_INST (dev)->numports; i++) { - ohci_rh_enable_port (dev, i); - RH_INST (dev)->port[i] = -1; + for (i = 0; i < RH_INST(dev)->numports; i++) { + ohci_rh_enable_port(dev, i); + RH_INST(dev)->port[i] = -1; } /* we can set them here because a root hub _really_ shouldn't diff --git a/payloads/libpayload/drivers/usb/uhci.c b/payloads/libpayload/drivers/usb/uhci.c index b87ec26965..538107eca3 100644 --- a/payloads/libpayload/drivers/usb/uhci.c +++ b/payloads/libpayload/drivers/usb/uhci.c @@ -34,30 +34,30 @@ #include "uhci.h" #include "uhci_private.h" -static void uhci_start (hci_t *controller); -static void uhci_stop (hci_t *controller); -static void uhci_reset (hci_t *controller); -static void uhci_shutdown (hci_t *controller); -static int uhci_bulk (endpoint_t *ep, int size, u8 *data, int finalize); -static int uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, +static void uhci_start(hci_t *controller); +static void uhci_stop(hci_t *controller); +static void uhci_reset(hci_t *controller); +static void uhci_shutdown(hci_t *controller); +static int uhci_bulk(endpoint_t *ep, int size, u8 *data, int finalize); +static int uhci_control(usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen, u8 *data); -static void* uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming); -static void uhci_destroy_intr_queue (endpoint_t *ep, void *queue); -static u8* uhci_poll_intr_queue (void *queue); +static void* uhci_create_intr_queue(endpoint_t *ep, int reqsize, int reqcount, int reqtiming); +static void uhci_destroy_intr_queue(endpoint_t *ep, void *queue); +static u8* uhci_poll_intr_queue(void *queue); #if 0 /* dump uhci */ static void -uhci_dump (hci_t *controller) +uhci_dump(hci_t *controller) { - usb_debug ("dump:\nUSBCMD: %x\n", uhci_reg_read16 (controller, USBCMD)); - usb_debug ("USBSTS: %x\n", uhci_reg_read16 (controller, USBSTS)); - usb_debug ("USBINTR: %x\n", uhci_reg_read16 (controller, USBINTR)); - usb_debug ("FRNUM: %x\n", uhci_reg_read16 (controller, FRNUM)); - usb_debug ("FLBASEADD: %x\n", uhci_reg_read32 (controller, FLBASEADD)); - usb_debug ("SOFMOD: %x\n", uhci_reg_read8 (controller, SOFMOD)); - usb_debug ("PORTSC1: %x\n", uhci_reg_read16 (controller, PORTSC1)); - usb_debug ("PORTSC2: %x\n", uhci_reg_read16 (controller, PORTSC2)); + usb_debug("dump:\nUSBCMD: %x\n", uhci_reg_read16(controller, USBCMD)); + usb_debug("USBSTS: %x\n", uhci_reg_read16(controller, USBSTS)); + usb_debug("USBINTR: %x\n", uhci_reg_read16(controller, USBINTR)); + usb_debug("FRNUM: %x\n", uhci_reg_read16(controller, FRNUM)); + usb_debug("FLBASEADD: %x\n", uhci_reg_read32(controller, FLBASEADD)); + usb_debug("SOFMOD: %x\n", uhci_reg_read8(controller, SOFMOD)); + usb_debug("PORTSC1: %x\n", uhci_reg_read16(controller, PORTSC1)); + usb_debug("PORTSC2: %x\n", uhci_reg_read16(controller, PORTSC2)); } #endif @@ -109,52 +109,52 @@ static void td_dump(td_t *td) } static void -uhci_reset (hci_t *controller) +uhci_reset(hci_t *controller) { /* reset */ - uhci_reg_write16 (controller, USBCMD, 4); /* Global Reset */ - mdelay (50); /* uhci spec 2.1.1: at least 10ms */ - uhci_reg_write16 (controller, USBCMD, 0); - mdelay (10); - uhci_reg_write16 (controller, USBCMD, 2); /* Host Controller Reset */ + uhci_reg_write16(controller, USBCMD, 4); /* Global Reset */ + mdelay(50); /* uhci spec 2.1.1: at least 10ms */ + uhci_reg_write16(controller, USBCMD, 0); + mdelay(10); + uhci_reg_write16(controller, USBCMD, 2); /* Host Controller Reset */ /* wait for controller to finish reset */ /* TOTEST: how long to wait? 100ms for now */ int timeout = 200; /* time out after 200 * 500us == 100ms */ - while (((uhci_reg_read16 (controller, USBCMD) & 2) != 0) && timeout--) - udelay (500); + while (((uhci_reg_read16(controller, USBCMD) & 2) != 0) && timeout--) + udelay(500); if (timeout < 0) - usb_debug ("Warning: uhci: host controller reset timed out.\n"); + usb_debug("Warning: uhci: host controller reset timed out.\n"); } static void -uhci_reinit (hci_t *controller) +uhci_reinit(hci_t *controller) { - uhci_reg_write32 (controller, FLBASEADD, - (u32) virt_to_phys (UHCI_INST (controller)-> + uhci_reg_write32(controller, FLBASEADD, + (u32) virt_to_phys(UHCI_INST(controller)-> framelistptr)); //usb_debug ("framelist at %p\n",UHCI_INST(controller)->framelistptr); /* disable irqs */ - uhci_reg_write16 (controller, USBINTR, 0); + uhci_reg_write16(controller, USBINTR, 0); /* reset framelist index */ - uhci_reg_write16 (controller, FRNUM, 0); + uhci_reg_write16(controller, FRNUM, 0); uhci_reg_write16(controller, USBCMD, uhci_reg_read16(controller, USBCMD) | 0xc0); // max packets, configure flag - uhci_start (controller); + uhci_start(controller); } hci_t * -uhci_pci_init (pcidev_t addr) +uhci_pci_init(pcidev_t addr) { int i; u16 reg16; - hci_t *controller = new_controller (); + hci_t *controller = new_controller(); controller->pcidev = addr; - controller->instance = xzalloc(sizeof (uhci_t)); + controller->instance = xzalloc(sizeof(uhci_t)); controller->type = UHCI; controller->start = uhci_start; controller->stop = uhci_stop; @@ -169,27 +169,27 @@ uhci_pci_init (pcidev_t addr) controller->create_intr_queue = uhci_create_intr_queue; controller->destroy_intr_queue = uhci_destroy_intr_queue; controller->poll_intr_queue = uhci_poll_intr_queue; - init_device_entry (controller, 0); - UHCI_INST (controller)->roothub = controller->devices[0]; + init_device_entry(controller, 0); + UHCI_INST(controller)->roothub = controller->devices[0]; /* ~1 clears the register type indicator that is set to 1 * for IO space */ - controller->reg_base = pci_read_config32 (addr, 0x20) & ~1; + controller->reg_base = pci_read_config32(addr, 0x20) & ~1; /* kill legacy support handler */ - uhci_stop (controller); - mdelay (1); - uhci_reg_write16 (controller, USBSTS, 0x3f); + uhci_stop(controller); + mdelay(1); + uhci_reg_write16(controller, USBSTS, 0x3f); reg16 = pci_read_config16(addr, 0xc0); reg16 &= 0xdf80; - pci_write_config16 (addr, 0xc0, reg16); + pci_write_config16(addr, 0xc0, reg16); - UHCI_INST (controller)->framelistptr = memalign (0x1000, 1024 * sizeof (flistp_t)); /* 4kb aligned to 4kb */ - if (! UHCI_INST (controller)->framelistptr) + UHCI_INST(controller)->framelistptr = memalign(0x1000, 1024 * sizeof(flistp_t)); /* 4kb aligned to 4kb */ + if (!UHCI_INST (controller)->framelistptr) fatal("Not enough memory for USB frame list pointer.\n"); - memset (UHCI_INST (controller)->framelistptr, 0, - 1024 * sizeof (flistp_t)); + memset(UHCI_INST(controller)->framelistptr, 0, + 1024 * sizeof(flistp_t)); /* According to the *BSD UHCI code, this one is needed on some PIIX chips, because otherwise they misbehave. It must be @@ -203,70 +203,70 @@ uhci_pci_init (pcidev_t addr) fatal("Not enough memory for chipset workaround.\n"); memset(antiberserk, 0, sizeof(td_t)); - UHCI_INST (controller)->qh_prei = memalign (16, sizeof (qh_t)); - UHCI_INST (controller)->qh_intr = memalign (16, sizeof (qh_t)); - UHCI_INST (controller)->qh_data = memalign (16, sizeof (qh_t)); - UHCI_INST (controller)->qh_last = memalign (16, sizeof (qh_t)); + UHCI_INST(controller)->qh_prei = memalign(16, sizeof(qh_t)); + UHCI_INST(controller)->qh_intr = memalign(16, sizeof(qh_t)); + UHCI_INST(controller)->qh_data = memalign(16, sizeof(qh_t)); + UHCI_INST(controller)->qh_last = memalign(16, sizeof(qh_t)); - if (! UHCI_INST (controller)->qh_prei || - ! UHCI_INST (controller)->qh_intr || - ! UHCI_INST (controller)->qh_data || - ! UHCI_INST (controller)->qh_last) + if (!UHCI_INST (controller)->qh_prei || + !UHCI_INST (controller)->qh_intr || + !UHCI_INST (controller)->qh_data || + !UHCI_INST (controller)->qh_last) fatal("Not enough memory for USB controller queues.\n"); - UHCI_INST (controller)->qh_prei->headlinkptr = - virt_to_phys (UHCI_INST (controller)->qh_intr) | FLISTP_QH; - UHCI_INST (controller)->qh_prei->elementlinkptr = 0 | FLISTP_TERMINATE; + UHCI_INST(controller)->qh_prei->headlinkptr = + virt_to_phys(UHCI_INST(controller)->qh_intr) | FLISTP_QH; + UHCI_INST(controller)->qh_prei->elementlinkptr = 0 | FLISTP_TERMINATE; - UHCI_INST (controller)->qh_intr->headlinkptr = - virt_to_phys (UHCI_INST (controller)->qh_data) | FLISTP_QH; - UHCI_INST (controller)->qh_intr->elementlinkptr = 0 | FLISTP_TERMINATE; + UHCI_INST(controller)->qh_intr->headlinkptr = + virt_to_phys(UHCI_INST(controller)->qh_data) | FLISTP_QH; + UHCI_INST(controller)->qh_intr->elementlinkptr = 0 | FLISTP_TERMINATE; - UHCI_INST (controller)->qh_data->headlinkptr = - virt_to_phys (UHCI_INST (controller)->qh_last) | FLISTP_QH; - UHCI_INST (controller)->qh_data->elementlinkptr = 0 | FLISTP_TERMINATE; + UHCI_INST(controller)->qh_data->headlinkptr = + virt_to_phys(UHCI_INST(controller)->qh_last) | FLISTP_QH; + UHCI_INST(controller)->qh_data->elementlinkptr = 0 | FLISTP_TERMINATE; - UHCI_INST (controller)->qh_last->headlinkptr = virt_to_phys (UHCI_INST (controller)->qh_data) | FLISTP_TERMINATE; - UHCI_INST (controller)->qh_last->elementlinkptr = virt_to_phys (antiberserk) | FLISTP_TERMINATE; + UHCI_INST(controller)->qh_last->headlinkptr = virt_to_phys(UHCI_INST(controller)->qh_data) | FLISTP_TERMINATE; + UHCI_INST(controller)->qh_last->elementlinkptr = virt_to_phys(antiberserk) | FLISTP_TERMINATE; for (i = 0; i < 1024; i++) { - UHCI_INST (controller)->framelistptr[i] = - virt_to_phys (UHCI_INST (controller)->qh_prei) | FLISTP_QH; + UHCI_INST(controller)->framelistptr[i] = + virt_to_phys(UHCI_INST(controller)->qh_prei) | FLISTP_QH; } controller->devices[0]->controller = controller; controller->devices[0]->init = uhci_rh_init; - controller->devices[0]->init (controller->devices[0]); - uhci_reset (controller); - uhci_reinit (controller); + controller->devices[0]->init(controller->devices[0]); + uhci_reset(controller); + uhci_reinit(controller); return controller; } static void -uhci_shutdown (hci_t *controller) +uhci_shutdown(hci_t *controller) { if (controller == 0) return; - detach_controller (controller); + detach_controller(controller); uhci_reg_write16(controller, USBCMD, uhci_reg_read16(controller, USBCMD) & 0); // stop work - free (UHCI_INST (controller)->framelistptr); - free (UHCI_INST (controller)->qh_prei); - free (UHCI_INST (controller)->qh_intr); - free (UHCI_INST (controller)->qh_data); - free (UHCI_INST (controller)->qh_last); - free (UHCI_INST (controller)); - free (controller); + free(UHCI_INST(controller)->framelistptr); + free(UHCI_INST(controller)->qh_prei); + free(UHCI_INST(controller)->qh_intr); + free(UHCI_INST(controller)->qh_data); + free(UHCI_INST(controller)->qh_last); + free(UHCI_INST(controller)); + free(controller); } static void -uhci_start (hci_t *controller) +uhci_start(hci_t *controller) { uhci_reg_write16(controller, USBCMD, uhci_reg_read16(controller, USBCMD) | 1); // start work on schedule } static void -uhci_stop (hci_t *controller) +uhci_stop(hci_t *controller) { uhci_reg_write16(controller, USBCMD, uhci_reg_read16(controller, USBCMD) & ~1); // stop work on schedule @@ -277,31 +277,31 @@ uhci_stop (hci_t *controller) #define GET_TD(x) ((void*)(((unsigned int)(x))&~0xf)) static td_t * -wait_for_completed_qh (hci_t *controller, qh_t *qh) +wait_for_completed_qh(hci_t *controller, qh_t *qh) { int timeout = UHCI_TIMEOUT; - void *current = GET_TD (qh->elementlinkptr); + void *current = GET_TD(qh->elementlinkptr); while (((qh->elementlinkptr & FLISTP_TERMINATE) == 0) && (timeout-- > 0)) { - if (current != GET_TD (qh->elementlinkptr)) { - current = GET_TD (qh->elementlinkptr); + if (current != GET_TD(qh->elementlinkptr)) { + current = GET_TD(qh->elementlinkptr); timeout = UHCI_TIMEOUT; } uhci_reg_write16(controller, USBSTS, uhci_reg_read16(controller, USBSTS) | 0); // clear resettable registers udelay(UHCI_SLEEP_TIME_US); } - return (GET_TD (qh->elementlinkptr) == - 0) ? 0 : GET_TD (phys_to_virt (qh->elementlinkptr)); + return (GET_TD(qh->elementlinkptr) == + 0) ? 0 : GET_TD(phys_to_virt(qh->elementlinkptr)); } static int -maxlen (int size) +maxlen(int size) { return (size - 1) & 0x7ff; } static int -min (int a, int b) +min(int a, int b) { if (a < b) return a; @@ -310,7 +310,7 @@ min (int a, int b) } static int -uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen, +uhci_control(usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen, unsigned char *data) { int endp = 0; /* this is control: always 0 */ @@ -318,13 +318,13 @@ uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen int count = (2 + (dalen + mlen - 1) / mlen); unsigned short req = ((unsigned short *) devreq)[0]; int i; - td_t *tds = memalign (16, sizeof (td_t) * count); + td_t *tds = memalign(16, sizeof(td_t) * count); if (!tds) fatal("Not enough memory for uhci control.\n"); - memset (tds, 0, sizeof (td_t) * count); + memset(tds, 0, sizeof(td_t) * count); count--; /* to compensate for 0-indexed array */ for (i = 0; i < count; i++) { - tds[i].ptr = virt_to_phys (&tds[i + 1]) | TD_DEPTH_FIRST; + tds[i].ptr = virt_to_phys(&tds[i + 1]) | TD_DEPTH_FIRST; } tds[count].ptr = 0 | TD_DEPTH_FIRST | TD_TERMINATE; @@ -333,7 +333,7 @@ uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen endp << TD_EP_SHIFT | TD_TOGGLE_DATA0 | maxlen(drlen) << TD_MAXLEN_SHIFT; - tds[0].bufptr = virt_to_phys (devreq); + tds[0].bufptr = virt_to_phys(devreq); tds[0].ctrlsts = (3 << TD_COUNTER_SHIFT) | (dev->speed?TD_LOWSPEED:0) | TD_STATUS_ACTIVE; @@ -347,9 +347,9 @@ uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen } tds[i].token |= dev->address << TD_DEVADDR_SHIFT | endp << TD_EP_SHIFT | - maxlen (min (mlen, dalen)) << TD_MAXLEN_SHIFT | + maxlen(min(mlen, dalen)) << TD_MAXLEN_SHIFT | toggle << TD_TOGGLE_SHIFT; - tds[i].bufptr = virt_to_phys (data); + tds[i].bufptr = virt_to_phys(data); tds[i].ctrlsts = (3 << TD_COUNTER_SHIFT) | (dev->speed?TD_LOWSPEED:0) | TD_STATUS_ACTIVE; @@ -367,42 +367,42 @@ uhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen tds[count].ctrlsts = (0 << TD_COUNTER_SHIFT) | /* as Linux 2.4.10 does */ (dev->speed?TD_LOWSPEED:0) | TD_STATUS_ACTIVE; - UHCI_INST (dev->controller)->qh_data->elementlinkptr = - virt_to_phys (tds) & ~(FLISTP_QH | FLISTP_TERMINATE); - td_t *td = wait_for_completed_qh (dev->controller, - UHCI_INST (dev->controller)-> + UHCI_INST(dev->controller)->qh_data->elementlinkptr = + virt_to_phys(tds) & ~(FLISTP_QH | FLISTP_TERMINATE); + td_t *td = wait_for_completed_qh(dev->controller, + UHCI_INST(dev->controller)-> qh_data); int result; if (td == 0) { result = 0; } else { - usb_debug ("control packet, req %x\n", req); - td_dump (td); + usb_debug("control packet, req %x\n", req); + td_dump(td); result = -1; } - free (tds); + free(tds); return result; } static td_t * -create_schedule (int numpackets) +create_schedule(int numpackets) { if (numpackets == 0) return 0; - td_t *tds = memalign (16, sizeof (td_t) * numpackets); + td_t *tds = memalign(16, sizeof(td_t) * numpackets); if (!tds) fatal("Not enough memory for packets scheduling.\n"); - memset (tds, 0, sizeof (td_t) * numpackets); + memset(tds, 0, sizeof(td_t) * numpackets); int i; for (i = 0; i < numpackets; i++) { - tds[i].ptr = virt_to_phys (&tds[i + 1]) | TD_DEPTH_FIRST; + tds[i].ptr = virt_to_phys(&tds[i + 1]) | TD_DEPTH_FIRST; } tds[numpackets - 1].ptr = 0 | TD_TERMINATE; return tds; } static void -fill_schedule (td_t *td, endpoint_t *ep, int length, unsigned char *data, +fill_schedule(td_t *td, endpoint_t *ep, int length, unsigned char *data, int *toggle) { switch (ep->direction) { @@ -412,9 +412,9 @@ fill_schedule (td_t *td, endpoint_t *ep, int length, unsigned char *data, } td->token |= ep->dev->address << TD_DEVADDR_SHIFT | (ep->endpoint & 0xf) << TD_EP_SHIFT | - maxlen (length) << TD_MAXLEN_SHIFT | + maxlen(length) << TD_MAXLEN_SHIFT | (*toggle & 1) << TD_TOGGLE_SHIFT; - td->bufptr = virt_to_phys (data); + td->bufptr = virt_to_phys(data); td->ctrlsts = ((ep->direction == SETUP?3:0) << TD_COUNTER_SHIFT) | (ep->dev->speed?TD_LOWSPEED:0) | TD_STATUS_ACTIVE; @@ -422,23 +422,23 @@ fill_schedule (td_t *td, endpoint_t *ep, int length, unsigned char *data, } static int -run_schedule (usbdev_t *dev, td_t *td) +run_schedule(usbdev_t *dev, td_t *td) { - UHCI_INST (dev->controller)->qh_data->elementlinkptr = - virt_to_phys (td) & ~(FLISTP_QH | FLISTP_TERMINATE); - td = wait_for_completed_qh (dev->controller, - UHCI_INST (dev->controller)->qh_data); + UHCI_INST(dev->controller)->qh_data->elementlinkptr = + virt_to_phys(td) & ~(FLISTP_QH | FLISTP_TERMINATE); + td = wait_for_completed_qh(dev->controller, + UHCI_INST(dev->controller)->qh_data); if (td == 0) { return 0; } else { - td_dump (td); + td_dump(td); return 1; } } /* finalize == 1: if data is of packet aligned size, add a zero length packet */ static int -uhci_bulk (endpoint_t *ep, int size, u8 *data, int finalize) +uhci_bulk(endpoint_t *ep, int size, u8 *data, int finalize) { int maxpsize = ep->maxpacketsize; if (maxpsize == 0) @@ -449,21 +449,21 @@ uhci_bulk (endpoint_t *ep, int size, u8 *data, int finalize) } if (numpackets == 0) return 0; - td_t *tds = create_schedule (numpackets); + td_t *tds = create_schedule(numpackets); int i = 0, toggle = ep->toggle; while ((size > 0) || ((size == 0) && (finalize != 0))) { - fill_schedule (&tds[i], ep, min (size, maxpsize), data, + fill_schedule(&tds[i], ep, min(size, maxpsize), data, &toggle); i++; data += maxpsize; size -= maxpsize; } - if (run_schedule (ep->dev, tds) == 1) { - free (tds); + if (run_schedule(ep->dev, tds) == 1) { + free(tds); return -1; } ep->toggle = toggle; - free (tds); + free(tds); return 0; } @@ -479,7 +479,7 @@ typedef struct { /* create and hook-up an intr queue into device schedule */ static void* -uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming) +uhci_create_intr_queue(endpoint_t *ep, int reqsize, int reqcount, int reqtiming) { u8 *data = malloc(reqsize*reqcount); td_t *tds = memalign(16, sizeof(td_t) * reqcount); @@ -501,10 +501,10 @@ uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming q->reqsize = reqsize; q->last_td = &tds[reqcount - 1]; - memset (tds, 0, sizeof (td_t) * reqcount); + memset(tds, 0, sizeof(td_t) * reqcount); int i; for (i = 0; i < reqcount; i++) { - tds[i].ptr = virt_to_phys (&tds[i + 1]); + tds[i].ptr = virt_to_phys(&tds[i + 1]); switch (ep->direction) { case IN: tds[i].token = UHCI_IN; break; @@ -513,9 +513,9 @@ uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming } tds[i].token |= ep->dev->address << TD_DEVADDR_SHIFT | (ep->endpoint & 0xf) << TD_EP_SHIFT | - maxlen (reqsize) << TD_MAXLEN_SHIFT | + maxlen(reqsize) << TD_MAXLEN_SHIFT | (ep->toggle & 1) << TD_TOGGLE_SHIFT; - tds[i].bufptr = virt_to_phys (data); + tds[i].bufptr = virt_to_phys(data); tds[i].ctrlsts = (0 << TD_COUNTER_SHIFT) | (ep->dev->speed?TD_LOWSPEED:0) | TD_STATUS_ACTIVE; @@ -549,7 +549,7 @@ uhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming /* remove queue from device schedule, dropping all data that came in */ static void -uhci_destroy_intr_queue (endpoint_t *ep, void *q_) +uhci_destroy_intr_queue(endpoint_t *ep, void *q_) { intr_q *const q = (intr_q*)q_; @@ -574,7 +574,7 @@ uhci_destroy_intr_queue (endpoint_t *ep, void *q_) Recommended use: while (data=poll_intr_queue(q)) process(data); */ static u8* -uhci_poll_intr_queue (void *q_) +uhci_poll_intr_queue(void *q_) { intr_q *q = (intr_q*)q_; if ((q->tds[q->lastread].ctrlsts & TD_STATUS_ACTIVE) == 0) { @@ -605,37 +605,37 @@ uhci_poll_intr_queue (void *q_) } void -uhci_reg_write32 (hci_t *ctrl, usbreg reg, u32 value) +uhci_reg_write32(hci_t *ctrl, usbreg reg, u32 value) { - outl (value, ctrl->reg_base + reg); + outl(value, ctrl->reg_base + reg); } u32 -uhci_reg_read32 (hci_t *ctrl, usbreg reg) +uhci_reg_read32(hci_t *ctrl, usbreg reg) { - return inl (ctrl->reg_base + reg); + return inl(ctrl->reg_base + reg); } void -uhci_reg_write16 (hci_t *ctrl, usbreg reg, u16 value) +uhci_reg_write16(hci_t *ctrl, usbreg reg, u16 value) { - outw (value, ctrl->reg_base + reg); + outw(value, ctrl->reg_base + reg); } u16 -uhci_reg_read16 (hci_t *ctrl, usbreg reg) +uhci_reg_read16(hci_t *ctrl, usbreg reg) { - return inw (ctrl->reg_base + reg); + return inw(ctrl->reg_base + reg); } void -uhci_reg_write8 (hci_t *ctrl, usbreg reg, u8 value) +uhci_reg_write8(hci_t *ctrl, usbreg reg, u8 value) { - outb (value, ctrl->reg_base + reg); + outb(value, ctrl->reg_base + reg); } u8 -uhci_reg_read8 (hci_t *ctrl, usbreg reg) +uhci_reg_read8(hci_t *ctrl, usbreg reg) { - return inb (ctrl->reg_base + reg); + return inb(ctrl->reg_base + reg); } diff --git a/payloads/libpayload/drivers/usb/uhci.h b/payloads/libpayload/drivers/usb/uhci.h index 6bfe768c3c..1430b23fa4 100644 --- a/payloads/libpayload/drivers/usb/uhci.h +++ b/payloads/libpayload/drivers/usb/uhci.h @@ -32,8 +32,8 @@ #include <pci.h> #include <usb/usb.h> -hci_t *uhci_pci_init (pcidev_t addr); +hci_t *uhci_pci_init(pcidev_t addr); -void uhci_rh_init (usbdev_t *dev); +void uhci_rh_init(usbdev_t *dev); #endif diff --git a/payloads/libpayload/drivers/usb/uhci_private.h b/payloads/libpayload/drivers/usb/uhci_private.h index 9df8f3d117..3da8712fe7 100644 --- a/payloads/libpayload/drivers/usb/uhci_private.h +++ b/payloads/libpayload/drivers/usb/uhci_private.h @@ -80,12 +80,12 @@ typedef struct { 0x12 } usbreg; - void uhci_reg_write32 (hci_t *ctrl, usbreg reg, u32 value); - u32 uhci_reg_read32 (hci_t *ctrl, usbreg reg); - void uhci_reg_write16 (hci_t *ctrl, usbreg reg, u16 value); - u16 uhci_reg_read16 (hci_t *ctrl, usbreg reg); - void uhci_reg_write8 (hci_t *ctrl, usbreg reg, u8 value); - u8 uhci_reg_read8 (hci_t *ctrl, usbreg reg); + void uhci_reg_write32(hci_t *ctrl, usbreg reg, u32 value); + u32 uhci_reg_read32(hci_t *ctrl, usbreg reg); + void uhci_reg_write16(hci_t *ctrl, usbreg reg, u16 value); + u16 uhci_reg_read16(hci_t *ctrl, usbreg reg); + void uhci_reg_write8(hci_t *ctrl, usbreg reg, u8 value); + u8 uhci_reg_read8(hci_t *ctrl, usbreg reg); typedef struct uhci { flistp_t *framelistptr; diff --git a/payloads/libpayload/drivers/usb/uhci_rh.c b/payloads/libpayload/drivers/usb/uhci_rh.c index d3337597c1..e7f0da7666 100644 --- a/payloads/libpayload/drivers/usb/uhci_rh.c +++ b/payloads/libpayload/drivers/usb/uhci_rh.c @@ -39,7 +39,7 @@ typedef struct { #define RH_INST(dev) ((rh_inst_t*)(dev)->data) static void -uhci_rh_enable_port (usbdev_t *dev, int port) +uhci_rh_enable_port(usbdev_t *dev, int port) { u16 value; hci_t *controller = dev->controller; @@ -57,10 +57,10 @@ uhci_rh_enable_port (usbdev_t *dev, int port) uhci_reg_write16(controller, port, uhci_reg_read16(controller, port) | 1 << 9); /* reset */ - mdelay (30); // >10ms + mdelay(30); // >10ms uhci_reg_write16(controller, port, uhci_reg_read16(controller, port) & ~(1 << 9)); - mdelay (1); // >5.3us per spec, <3ms because some devices make trouble + mdelay(1); // >5.3us per spec, <3ms because some devices make trouble uhci_reg_write16(controller, port, uhci_reg_read16(controller, port) | 1 << 2); /* enable */ @@ -68,7 +68,7 @@ uhci_rh_enable_port (usbdev_t *dev, int port) /* TOTEST: how long to wait? 100ms for now */ int timeout = 200; /* time out after 200 * 500us == 100ms */ do { - value = uhci_reg_read16 (controller, port); + value = uhci_reg_read16(controller, port); udelay(500); timeout--; } while (((value & (1 << 2)) == 0) && (value & 0x01) && timeout); if (!timeout) @@ -77,7 +77,7 @@ uhci_rh_enable_port (usbdev_t *dev, int port) /* disable root hub */ static void -uhci_rh_disable_port (usbdev_t *dev, int port) +uhci_rh_disable_port(usbdev_t *dev, int port) { hci_t *controller = dev->controller; if (port == 1) @@ -95,7 +95,7 @@ uhci_rh_disable_port (usbdev_t *dev, int port) /* TOTEST: how long to wait? 100ms for now */ int timeout = 200; /* time out after 200 * 500us == 100ms */ do { - value = uhci_reg_read16 (controller, port); + value = uhci_reg_read16(controller, port); udelay(500); timeout--; } while (((value & (1 << 2)) != 0) && timeout); if (!timeout) @@ -103,7 +103,7 @@ uhci_rh_disable_port (usbdev_t *dev, int port) } static void -uhci_rh_scanport (usbdev_t *dev, int port) +uhci_rh_scanport(usbdev_t *dev, int port) { int portsc, offset; if (port == 1) { @@ -116,42 +116,42 @@ uhci_rh_scanport (usbdev_t *dev, int port) usb_debug("Invalid port %d\n", port); return; } - int devno = RH_INST (dev)->port[offset]; + int devno = RH_INST(dev)->port[offset]; if ((devno != -1) && (dev->controller->devices[devno] != 0)) { usb_detach_device(dev->controller, devno); - RH_INST (dev)->port[offset] = -1; + RH_INST(dev)->port[offset] = -1; } uhci_reg_write16(dev->controller, portsc, uhci_reg_read16(dev->controller, portsc) | (1 << 3) | (1 << 2)); // clear port state change, enable port mdelay(100); // wait for signal to stabilize - if ((uhci_reg_read16 (dev->controller, portsc) & 1) != 0) { + if ((uhci_reg_read16(dev->controller, portsc) & 1) != 0) { // device attached - uhci_rh_disable_port (dev, port); - uhci_rh_enable_port (dev, port); + uhci_rh_disable_port(dev, port); + uhci_rh_enable_port(dev, port); - usb_speed speed = ((uhci_reg_read16 (dev->controller, portsc) >> 8) & 1); + usb_speed speed = ((uhci_reg_read16(dev->controller, portsc) >> 8) & 1); - RH_INST (dev)->port[offset] = usb_attach_device(dev->controller, dev->address, portsc, speed); + RH_INST(dev)->port[offset] = usb_attach_device(dev->controller, dev->address, portsc, speed); } } static int -uhci_rh_report_port_changes (usbdev_t *dev) +uhci_rh_report_port_changes(usbdev_t *dev) { u16 stored, real; - stored = (RH_INST (dev)->port[0] == -1); - real = ((uhci_reg_read16 (dev->controller, PORTSC1) & 1) == 0); + stored = (RH_INST(dev)->port[0] == -1); + real = ((uhci_reg_read16(dev->controller, PORTSC1) & 1) == 0); if (stored != real) { usb_debug("change on port 1\n"); return 1; } - stored = (RH_INST (dev)->port[1] == -1); - real = ((uhci_reg_read16 (dev->controller, PORTSC2) & 1) == 0); + stored = (RH_INST(dev)->port[1] == -1); + real = ((uhci_reg_read16(dev->controller, PORTSC2) & 1) == 0); if (stored != real) { usb_debug("change on port 2\n"); return 2; @@ -159,11 +159,11 @@ uhci_rh_report_port_changes (usbdev_t *dev) // maybe detach+attach happened between two scans? - if ((uhci_reg_read16 (dev->controller, PORTSC1) & 2) > 0) { + if ((uhci_reg_read16(dev->controller, PORTSC1) & 2) > 0) { usb_debug("possibly re-attached on port 1\n"); return 1; } - if ((uhci_reg_read16 (dev->controller, PORTSC2) & 2) > 0) { + if ((uhci_reg_read16(dev->controller, PORTSC2) & 2) > 0) { usb_debug("possibly re-attached on port 2\n"); return 2; } @@ -173,35 +173,35 @@ uhci_rh_report_port_changes (usbdev_t *dev) } static void -uhci_rh_destroy (usbdev_t *dev) +uhci_rh_destroy(usbdev_t *dev) { - usb_detach_device (dev->controller, 1); - usb_detach_device (dev->controller, 2); - uhci_rh_disable_port (dev, 1); - uhci_rh_disable_port (dev, 2); - free (RH_INST (dev)); + usb_detach_device(dev->controller, 1); + usb_detach_device(dev->controller, 2); + uhci_rh_disable_port(dev, 1); + uhci_rh_disable_port(dev, 2); + free(RH_INST(dev)); } static void -uhci_rh_poll (usbdev_t *dev) +uhci_rh_poll(usbdev_t *dev) { int port; - while ((port = uhci_rh_report_port_changes (dev)) != -1) - uhci_rh_scanport (dev, port); + while ((port = uhci_rh_report_port_changes(dev)) != -1) + uhci_rh_scanport(dev, port); } void -uhci_rh_init (usbdev_t *dev) +uhci_rh_init(usbdev_t *dev) { dev->destroy = uhci_rh_destroy; dev->poll = uhci_rh_poll; - uhci_rh_enable_port (dev, 1); - uhci_rh_enable_port (dev, 2); - dev->data = xmalloc (sizeof (rh_inst_t)); + uhci_rh_enable_port(dev, 1); + uhci_rh_enable_port(dev, 2); + dev->data = xmalloc(sizeof(rh_inst_t)); - RH_INST (dev)->port[0] = -1; - RH_INST (dev)->port[1] = -1; + RH_INST(dev)->port[0] = -1; + RH_INST(dev)->port[1] = -1; /* we can set them here because a root hub _really_ shouldn't appear elsewhere */ diff --git a/payloads/libpayload/drivers/usb/usb.c b/payloads/libpayload/drivers/usb/usb.c index ed33147c51..e260cf6e66 100644 --- a/payloads/libpayload/drivers/usb/usb.c +++ b/payloads/libpayload/drivers/usb/usb.c @@ -37,16 +37,16 @@ hci_t *usb_hcs = 0; hci_t * -new_controller (void) +new_controller(void) { - hci_t *controller = xzalloc(sizeof (hci_t)); + hci_t *controller = xzalloc(sizeof(hci_t)); controller->next = usb_hcs; usb_hcs = controller; return controller; } void -detach_controller (hci_t *controller) +detach_controller(hci_t *controller) { if (controller == NULL) return; @@ -71,7 +71,7 @@ detach_controller (hci_t *controller) * Shut down all controllers */ int -usb_exit (void) +usb_exit(void) { while (usb_hcs != NULL) { usb_hcs->shutdown(usb_hcs); @@ -83,7 +83,7 @@ usb_exit (void) * Polls all hubs on all USB controllers, to find out about device changes */ void -usb_poll (void) +usb_poll(void) { if (usb_hcs == 0) return; @@ -96,7 +96,7 @@ usb_poll (void) int i; for (i = 0; i < 128; i++) { if (controller->devices[i] != 0) { - controller->devices[i]->poll (controller->devices[i]); + controller->devices[i]->poll(controller->devices[i]); } } controller = controller->next; @@ -104,7 +104,7 @@ usb_poll (void) } usbdev_t * -init_device_entry (hci_t *controller, int i) +init_device_entry(hci_t *controller, int i) { usbdev_t *dev = calloc(1, sizeof(usbdev_t)); if (!dev) { @@ -119,12 +119,12 @@ init_device_entry (hci_t *controller, int i) dev->hub = -1; dev->port = -1; dev->init = usb_nop_init; - dev->init (controller->devices[i]); + dev->init(controller->devices[i]); return dev; } int -set_feature (usbdev_t *dev, int endp, int feature, int rtype) +set_feature(usbdev_t *dev, int endp, int feature, int rtype) { dev_req_t dr; @@ -135,11 +135,11 @@ set_feature (usbdev_t *dev, int endp, int feature, int rtype) dr.wIndex = endp; dr.wLength = 0; - return dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0); + return dev->controller->control(dev, OUT, sizeof(dr), &dr, 0, 0); } int -get_status (usbdev_t *dev, int intf, int rtype, int len, void *data) +get_status(usbdev_t *dev, int intf, int rtype, int len, void *data) { dev_req_t dr; @@ -150,7 +150,7 @@ get_status (usbdev_t *dev, int intf, int rtype, int len, void *data) dr.wIndex = intf; dr.wLength = len; - return dev->controller->control (dev, IN, sizeof (dr), &dr, len, data); + return dev->controller->control(dev, IN, sizeof(dr), &dr, len, data); } /* @@ -186,7 +186,7 @@ get_descriptor(usbdev_t *dev, int rtype, int desc_type, int desc_idx, } int -set_configuration (usbdev_t *dev) +set_configuration(usbdev_t *dev) { dev_req_t dr; @@ -196,11 +196,11 @@ set_configuration (usbdev_t *dev) dr.wIndex = 0; dr.wLength = 0; - return dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0); + return dev->controller->control(dev, OUT, sizeof(dr), &dr, 0, 0); } int -clear_feature (usbdev_t *dev, int endp, int feature, int rtype) +clear_feature(usbdev_t *dev, int endp, int feature, int rtype) { dev_req_t dr; @@ -211,21 +211,21 @@ clear_feature (usbdev_t *dev, int endp, int feature, int rtype) dr.wIndex = endp; dr.wLength = 0; - return dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0) < 0; + return dev->controller->control(dev, OUT, sizeof(dr), &dr, 0, 0) < 0; } int -clear_stall (endpoint_t *ep) +clear_stall(endpoint_t *ep) { - int ret = clear_feature (ep->dev, ep->endpoint, ENDPOINT_HALT, - gen_bmRequestType (host_to_device, standard_type, endp_recp)); + int ret = clear_feature(ep->dev, ep->endpoint, ENDPOINT_HALT, + gen_bmRequestType(host_to_device, standard_type, endp_recp)); ep->toggle = 0; return ret; } /* returns free address or -1 */ static int -get_free_address (hci_t *controller) +get_free_address(hci_t *controller) { int i = controller->latest_address + 1; for (; i != controller->latest_address; i++) { @@ -240,7 +240,7 @@ get_free_address (hci_t *controller) return i; } } - usb_debug ("no free address found\n"); + usb_debug("no free address found\n"); return -1; // no free address } @@ -342,15 +342,15 @@ usb_decode_interval(usb_speed speed, const endpoint_type type, const unsigned ch } usbdev_t * -generic_set_address (hci_t *controller, usb_speed speed, +generic_set_address(hci_t *controller, usb_speed speed, int hubport, int hubaddr) { - int adr = get_free_address (controller); // address to set + int adr = get_free_address(controller); // address to set if (adr < 0) return NULL; dev_req_t dr; - memset (&dr, 0, sizeof (dr)); + memset(&dr, 0, sizeof(dr)); dr.data_dir = host_to_device; dr.req_type = standard_type; dr.req_recp = dev_recp; @@ -374,19 +374,19 @@ generic_set_address (hci_t *controller, usb_speed speed, dev->endpoints[0].toggle = 0; dev->endpoints[0].direction = SETUP; dev->endpoints[0].type = CONTROL; - if (dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0) < 0) { - usb_debug ("set_address failed\n"); - usb_detach_device (controller, adr); + if (dev->controller->control(dev, OUT, sizeof(dr), &dr, 0, 0) < 0) { + usb_debug("set_address failed\n"); + usb_detach_device(controller, adr); return NULL; } - mdelay (SET_ADDRESS_MDELAY); + mdelay(SET_ADDRESS_MDELAY); u8 buf[8]; dev->address = adr; - if (get_descriptor (dev, DR_DESC, DT_DEV, 0, buf, sizeof(buf)) + if (get_descriptor(dev, DR_DESC, DT_DEV, 0, buf, sizeof(buf)) != sizeof(buf)) { usb_debug("first get_descriptor(DT_DEV) failed\n"); - usb_detach_device (controller, adr); + usb_detach_device(controller, adr); return NULL; } dev->endpoints[0].maxpacketsize = usb_decode_mps0(speed, buf[7]); @@ -395,45 +395,45 @@ generic_set_address (hci_t *controller, usb_speed speed, } static int -set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) +set_address(hci_t *controller, usb_speed speed, int hubport, int hubaddr) { usbdev_t *dev = controller->set_address(controller, speed, hubport, hubaddr); if (!dev) { - usb_debug ("set_address failed\n"); + usb_debug("set_address failed\n"); return -1; } dev->descriptor = malloc(sizeof(*dev->descriptor)); - if (!dev->descriptor || get_descriptor (dev, DR_DESC, DT_DEV, 0, + if (!dev->descriptor || get_descriptor(dev, DR_DESC, DT_DEV, 0, dev->descriptor, sizeof(*dev->descriptor)) != sizeof(*dev->descriptor)) { - usb_debug ("get_descriptor(DT_DEV) failed\n"); - usb_detach_device (controller, dev->address); + usb_debug("get_descriptor(DT_DEV) failed\n"); + usb_detach_device(controller, dev->address); return -1; } - usb_debug ("* found device (0x%04x:0x%04x, USB %x.%x, MPS0: %d)\n", + usb_debug("* found device (0x%04x:0x%04x, USB %x.%x, MPS0: %d)\n", dev->descriptor->idVendor, dev->descriptor->idProduct, dev->descriptor->bcdUSB >> 8, dev->descriptor->bcdUSB & 0xff, dev->endpoints[0].maxpacketsize); dev->quirks = usb_quirk_check(dev->descriptor->idVendor, dev->descriptor->idProduct); - usb_debug ("device has %d configurations\n", + usb_debug("device has %d configurations\n", dev->descriptor->bNumConfigurations); if (dev->descriptor->bNumConfigurations == 0) { /* device isn't usable */ - usb_debug ("... no usable configuration!\n"); - usb_detach_device (controller, dev->address); + usb_debug("... no usable configuration!\n"); + usb_detach_device(controller, dev->address); return -1; } u16 buf[2]; - if (get_descriptor (dev, DR_DESC, DT_CFG, 0, buf, sizeof(buf)) + if (get_descriptor(dev, DR_DESC, DT_CFG, 0, buf, sizeof(buf)) != sizeof(buf)) { - usb_debug ("first get_descriptor(DT_CFG) failed\n"); - usb_detach_device (controller, dev->address); + usb_debug("first get_descriptor(DT_CFG) failed\n"); + usb_detach_device(controller, dev->address); return -1; } /* workaround for some USB devices: wait until they're ready, or @@ -441,20 +441,20 @@ set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) mdelay(1); dev->configuration = malloc(buf[1]); if (!dev->configuration) { - usb_debug ("could not allocate %d bytes for DT_CFG\n", buf[1]); - usb_detach_device (controller, dev->address); + usb_debug("could not allocate %d bytes for DT_CFG\n", buf[1]); + usb_detach_device(controller, dev->address); return -1; } - if (get_descriptor (dev, DR_DESC, DT_CFG, 0, dev->configuration, + if (get_descriptor(dev, DR_DESC, DT_CFG, 0, dev->configuration, buf[1]) != buf[1]) { - usb_debug ("get_descriptor(DT_CFG) failed\n"); - usb_detach_device (controller, dev->address); + usb_debug("get_descriptor(DT_CFG) failed\n"); + usb_detach_device(controller, dev->address); return -1; } configuration_descriptor_t *cd = dev->configuration; if (cd->wTotalLength != buf[1]) { - usb_debug ("configuration descriptor size changed, aborting\n"); - usb_detach_device (controller, dev->address); + usb_debug("configuration descriptor size changed, aborting\n"); + usb_detach_device(controller, dev->address); return -1; } @@ -464,11 +464,11 @@ set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) * else for the time being. If you need it, see the SetInterface and * GetInterface functions in the USB specification and set it yourself. */ - usb_debug ("device has %x interfaces\n", cd->bNumInterfaces); + usb_debug("device has %x interfaces\n", cd->bNumInterfaces); int ifnum = usb_interface_check(dev->descriptor->idVendor, dev->descriptor->idProduct); if (cd->bNumInterfaces > 1 && ifnum < 0) - usb_debug ("NOTICE: Your device has multiple interfaces and\n" + usb_debug("NOTICE: Your device has multiple interfaces and\n" "this driver will only use the first one. That may\n" "be the wrong choice and cause the device to not\n" "work correctly. Please report this case\n" @@ -483,20 +483,20 @@ set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) /* Find our interface (or the first good one if we don't know) */ for (ptr = (void *)dev->configuration + sizeof(*cd); ; ptr += ptr[0]) { if (ptr + 2 > end || !ptr[0] || ptr + ptr[0] > end) { - usb_debug ("Couldn't find usable DT_INTF\n"); - usb_detach_device (controller, dev->address); + usb_debug("Couldn't find usable DT_INTF\n"); + usb_detach_device(controller, dev->address); return -1; } if (ptr[1] != DT_INTF) continue; intf = (void *)ptr; if (intf->bLength != sizeof(*intf)) { - usb_debug ("Skipping broken DT_INTF\n"); + usb_debug("Skipping broken DT_INTF\n"); continue; } if (ifnum >= 0 && intf->bInterfaceNumber != ifnum) continue; - usb_debug ("Interface %d: class 0x%x, sub 0x%x. proto 0x%x\n", + usb_debug("Interface %d: class 0x%x, sub 0x%x. proto 0x%x\n", intf->bInterfaceNumber, intf->bInterfaceClass, intf->bInterfaceSubClass, intf->bInterfaceProtocol); ptr += sizeof(*intf); @@ -516,7 +516,7 @@ set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) static const char *transfertypes[4] = { "control", "isochronous", "bulk", "interrupt" }; - usb_debug (" #Endpoint %d (%s), max packet size %x, type %s\n", + usb_debug(" #Endpoint %d (%s), max packet size %x, type %s\n", desc->bEndpointAddress & 0x7f, (desc->bEndpointAddress & 0x80) ? "in" : "out", desc->wMaxPacketSize, @@ -529,15 +529,15 @@ set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) ep->maxpacketsize = desc->wMaxPacketSize; ep->direction = (desc->bEndpointAddress & 0x80) ? IN : OUT; ep->type = desc->bmAttributes & 0x3; - ep->interval = usb_decode_interval (dev->speed, ep->type, + ep->interval = usb_decode_interval(dev->speed, ep->type, desc->bInterval); } if ((controller->finish_device_config && controller->finish_device_config(dev)) || set_configuration(dev) < 0) { - usb_debug ("Could not finalize device configuration\n"); - usb_detach_device (controller, dev->address); + usb_debug("Could not finalize device configuration\n"); + usb_detach_device(controller, dev->address); return -1; } @@ -572,12 +572,12 @@ set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) usb_debug("communication\n"); break; case hid_device: - usb_debug ("HID\n"); + usb_debug("HID\n"); #if CONFIG(LP_USB_HID) dev->init = usb_hid_init; return dev->address; #else - usb_debug ("NOTICE: USB HID support not compiled in\n"); + usb_debug("NOTICE: USB HID support not compiled in\n"); #endif break; case physical_device: @@ -590,21 +590,21 @@ set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) usb_debug("printer\n"); break; case msc_device: - usb_debug ("MSC\n"); + usb_debug("MSC\n"); #if CONFIG(LP_USB_MSC) dev->init = usb_msc_init; return dev->address; #else - usb_debug ("NOTICE: USB MSC support not compiled in\n"); + usb_debug("NOTICE: USB MSC support not compiled in\n"); #endif break; case hub_device: - usb_debug ("hub\n"); + usb_debug("hub\n"); #if CONFIG(LP_USB_HUB) dev->init = usb_hub_init; return dev->address; #else - usb_debug ("NOTICE: USB hub support not compiled in\n"); + usb_debug("NOTICE: USB hub support not compiled in\n"); #endif break; case cdc_device: @@ -647,7 +647,7 @@ usb_detach_device(hci_t *controller, int devno) /* check if device exists, as we may have been called yet by the USB class driver */ if (controller->devices[devno]) { - controller->devices[devno]->destroy (controller->devices[devno]); + controller->devices[devno]->destroy(controller->devices[devno]); if (controller->destroy_device) controller->destroy_device(controller, devno); @@ -668,27 +668,27 @@ int usb_attach_device(hci_t *controller, int hubaddress, int port, usb_speed speed) { static const char *speeds[] = { "full", "low", "high", "super", "ultra" }; - usb_debug ("%sspeed device\n", (speed < sizeof(speeds) / sizeof(char*)) + usb_debug("%sspeed device\n", (speed < sizeof(speeds) / sizeof(char*)) ? speeds[speed] : "invalid value - no"); - int newdev = set_address (controller, speed, port, hubaddress); + int newdev = set_address(controller, speed, port, hubaddress); if (newdev == -1) return -1; usbdev_t *newdev_t = controller->devices[newdev]; // determine responsible driver - current done in set_address - newdev_t->init (newdev_t); + newdev_t->init(newdev_t); /* init() may have called usb_detach_device() yet, so check */ return controller->devices[newdev] ? newdev : -1; } static void -usb_generic_destroy (usbdev_t *dev) +usb_generic_destroy(usbdev_t *dev) { if (usb_generic_remove) usb_generic_remove(dev); } void -usb_generic_init (usbdev_t *dev) +usb_generic_init(usbdev_t *dev) { dev->data = NULL; dev->destroy = usb_generic_destroy; diff --git a/payloads/libpayload/drivers/usb/usb_dev.c b/payloads/libpayload/drivers/usb/usb_dev.c index 4398244379..fe6ca8e896 100644 --- a/payloads/libpayload/drivers/usb/usb_dev.c +++ b/payloads/libpayload/drivers/usb/usb_dev.c @@ -29,22 +29,22 @@ #include <usb/usb.h> static void -usb_nop_destroy (usbdev_t *dev) +usb_nop_destroy(usbdev_t *dev) { - usb_nop_init (dev); + usb_nop_init(dev); dev->address = -1; dev->hub = -1; dev->port = -1; } static void -usb_nop_poll (usbdev_t *dev) +usb_nop_poll(usbdev_t *dev) { return; } void -usb_nop_init (usbdev_t *dev) +usb_nop_init(usbdev_t *dev) { dev->descriptor = NULL; dev->configuration = NULL; diff --git a/payloads/libpayload/drivers/usb/usbhid.c b/payloads/libpayload/drivers/usb/usbhid.c index 87e87411fe..4ada62a9d7 100644 --- a/payloads/libpayload/drivers/usb/usbhid.c +++ b/payloads/libpayload/drivers/usb/usbhid.c @@ -62,7 +62,7 @@ typedef struct { #define HID_INST(dev) ((usbhid_inst_t*)(dev)->data) static void -usb_hid_destroy (usbdev_t *dev) +usb_hid_destroy(usbdev_t *dev) { if (HID_INST(dev)->queue) { int i; @@ -82,7 +82,7 @@ usb_hid_destroy (usbdev_t *dev) free(HID_INST(dev)->descriptor); HID_INST(dev)->descriptor = NULL; - free (dev->data); + free(dev->data); } /* keybuffer is global to all USB keyboards */ @@ -268,14 +268,14 @@ usb_hid_process_keyboard_event(usbhid_inst_t *const inst, if (current->modifiers & 0x01) /* Left-Ctrl */ modifiers |= KB_MOD_CTRL; if (current->modifiers & 0x02) /* Left-Shift */ modifiers |= KB_MOD_SHIFT; if (current->modifiers & 0x04) /* Left-Alt */ modifiers |= KB_MOD_ALT; - if (current->modifiers & 0x08) /* Left-GUI */ ; + if (current->modifiers & 0x08) /* Left-GUI */; if (current->modifiers & 0x10) /* Right-Ctrl */ modifiers |= KB_MOD_CTRL; if (current->modifiers & 0x20) /* Right-Shift */ modifiers |= KB_MOD_SHIFT; if (current->modifiers & 0x40) /* Right-AltGr */ modifiers |= KB_MOD_ALT; - if (current->modifiers & 0x80) /* Right-GUI */ ; + if (current->modifiers & 0x80) /* Right-GUI */; if ((current->modifiers & 0x05) && ((current->keys[0] == 0x4c) || - (current->keys[0]==0x63))) { + (current->keys[0] == 0x63))) { /* vulcan nerve pinch */ if (reset_handler) reset_handler(); @@ -297,14 +297,14 @@ usb_hid_process_keyboard_event(usbhid_inst_t *const inst, inst->lastkeypress = 0; - for (i=0; i<6; i++) { + for (i = 0; i < 6; i++) { int j; int skip = 0; // No more keys? skip if (current->keys[i] == 0) return; - for (j=0; j<6; j++) { + for (j = 0; j < 6; j++) { if (current->keys[i] == previous->keys[j]) { skip = 1; break; @@ -328,7 +328,7 @@ usb_hid_process_keyboard_event(usbhid_inst_t *const inst, if (keypress == -1) { /* Debug: Print unknown keys */ - usb_debug ("usbhid: <%x> %x [ %x %x %x %x %x %x ] %d\n", + usb_debug("usbhid: <%x> %x [ %x %x %x %x %x %x ] %d\n", current->modifiers, current->repeats, current->keys[0], current->keys[1], current->keys[2], current->keys[3], @@ -347,12 +347,12 @@ usb_hid_process_keyboard_event(usbhid_inst_t *const inst, } static void -usb_hid_poll (usbdev_t *dev) +usb_hid_poll(usbdev_t *dev) { usb_hid_keyboard_event_t current; const u8 *buf; - while ((buf=dev->controller->poll_intr_queue (HID_INST(dev)->queue))) { + while ((buf = dev->controller->poll_intr_queue (HID_INST(dev)->queue))) { memcpy(¤t.buffer, buf, 8); usb_hid_process_keyboard_event(HID_INST(dev), ¤t); HID_INST(dev)->previous = current; @@ -360,7 +360,7 @@ usb_hid_poll (usbdev_t *dev) } static void -usb_hid_set_idle (usbdev_t *dev, interface_descriptor_t *interface, u16 duration) +usb_hid_set_idle(usbdev_t *dev, interface_descriptor_t *interface, u16 duration) { dev_req_t dr; dr.data_dir = host_to_device; @@ -370,11 +370,11 @@ usb_hid_set_idle (usbdev_t *dev, interface_descriptor_t *interface, u16 duration dr.wValue = (duration >> 2) << 8; dr.wIndex = interface->bInterfaceNumber; dr.wLength = 0; - dev->controller->control (dev, OUT, sizeof (dev_req_t), &dr, 0, 0); + dev->controller->control(dev, OUT, sizeof(dev_req_t), &dr, 0, 0); } static void -usb_hid_set_protocol (usbdev_t *dev, interface_descriptor_t *interface, hid_proto proto) +usb_hid_set_protocol(usbdev_t *dev, interface_descriptor_t *interface, hid_proto proto) { dev_req_t dr; dr.data_dir = host_to_device; @@ -384,7 +384,7 @@ usb_hid_set_protocol (usbdev_t *dev, interface_descriptor_t *interface, hid_prot dr.wValue = proto; dr.wIndex = interface->bInterfaceNumber; dr.wLength = 0; - dev->controller->control (dev, OUT, sizeof (dev_req_t), &dr, 0, 0); + dev->controller->control(dev, OUT, sizeof(dev_req_t), &dr, 0, 0); } static struct console_input_driver cons = { @@ -393,12 +393,12 @@ static struct console_input_driver cons = { .input_type = CONSOLE_INPUT_TYPE_USB, }; -static int usb_hid_set_layout (const char *country) +static int usb_hid_set_layout(const char *country) { /* FIXME should be per keyboard */ int i; - for (i=0; i<ARRAY_SIZE(keyboard_layouts); i++) { + for (i = 0; i < ARRAY_SIZE(keyboard_layouts); i++) { if (strncmp(keyboard_layouts[i].country, country, strlen(keyboard_layouts[i].country))) continue; @@ -417,13 +417,13 @@ static int usb_hid_set_layout (const char *country) } void -usb_hid_init (usbdev_t *dev) +usb_hid_init(usbdev_t *dev) { static int installed = 0; if (!installed) { installed = 1; - console_add_input_driver (&cons); + console_add_input_driver(&cons); } configuration_descriptor_t *cd = (configuration_descriptor_t*)dev->configuration; @@ -431,31 +431,31 @@ usb_hid_init (usbdev_t *dev) if (interface->bInterfaceSubClass == hid_subclass_boot) { u8 countrycode; - usb_debug (" supports boot interface..\n"); - usb_debug (" it's a %s\n", + usb_debug(" supports boot interface..\n"); + usb_debug(" it's a %s\n", boot_protos[interface->bInterfaceProtocol]); switch (interface->bInterfaceProtocol) { case hid_boot_proto_keyboard: - dev->data = xzalloc (sizeof (usbhid_inst_t)); - usb_debug (" configuring...\n"); + dev->data = xzalloc(sizeof(usbhid_inst_t)); + usb_debug(" configuring...\n"); usb_hid_set_protocol(dev, interface, hid_proto_boot); usb_hid_set_idle(dev, interface, KEYBOARD_REPEAT_MS); - usb_debug (" activating...\n"); + usb_debug(" activating...\n"); hid_descriptor_t *desc = malloc(sizeof(hid_descriptor_t)); if (!desc || get_descriptor(dev, gen_bmRequestType( device_to_host, standard_type, iface_recp), 0x21, 0, desc, sizeof(*desc)) != sizeof(*desc)) { - usb_debug ("get_descriptor(HID) failed\n"); - usb_detach_device (dev->controller, dev->address); + usb_debug("get_descriptor(HID) failed\n"); + usb_detach_device(dev->controller, dev->address); return; } - HID_INST (dev)->descriptor = desc; + HID_INST(dev)->descriptor = desc; countrycode = desc->bCountryCode; /* 35 countries defined: */ if (countrycode >= ARRAY_SIZE(countries)) countrycode = 0; - usb_debug (" Keyboard has %s layout (country code %02x)\n", + usb_debug(" Keyboard has %s layout (country code %02x)\n", countries[countrycode][0], countrycode); /* Set keyboard layout accordingly */ @@ -473,15 +473,15 @@ usb_hid_init (usbdev_t *dev) break; } if (i >= dev->num_endp) { - usb_debug ("Could not find HID endpoint\n"); - usb_detach_device (dev->controller, dev->address); + usb_debug("Could not find HID endpoint\n"); + usb_detach_device(dev->controller, dev->address); return; } - usb_debug (" found endpoint %x for interrupt-in\n", i); + usb_debug(" found endpoint %x for interrupt-in\n", i); /* 20 buffers of 8 bytes, for every 10 msecs */ - HID_INST(dev)->queue = dev->controller->create_intr_queue (&dev->endpoints[i], 8, 20, 10); + HID_INST(dev)->queue = dev->controller->create_intr_queue(&dev->endpoints[i], 8, 20, 10); keycount = 0; - usb_debug (" configuration done.\n"); + usb_debug(" configuration done.\n"); break; case hid_boot_proto_mouse: usb_debug("NOTICE: USB mice are not supported.\n"); diff --git a/payloads/libpayload/drivers/usb/usbhub.c b/payloads/libpayload/drivers/usb/usbhub.c index 299ebf4737..b14f979e17 100644 --- a/payloads/libpayload/drivers/usb/usbhub.c +++ b/payloads/libpayload/drivers/usb/usbhub.c @@ -72,11 +72,11 @@ static int usb_hub_port_status_changed(usbdev_t *const dev, const int port) { unsigned short buf[2]; - int ret = get_status (dev, port, DR_PORT, sizeof(buf), buf); + int ret = get_status(dev, port, DR_PORT, sizeof(buf), buf); if (ret >= 0) { ret = buf[1] & PORT_CONNECTION; if (ret) - clear_feature (dev, port, SEL_C_PORT_CONNECTION, + clear_feature(dev, port, SEL_C_PORT_CONNECTION, DR_PORT); } return ret; @@ -86,7 +86,7 @@ static int usb_hub_port_connected(usbdev_t *const dev, const int port) { unsigned short buf[2]; - int ret = get_status (dev, port, DR_PORT, sizeof(buf), buf); + int ret = get_status(dev, port, DR_PORT, sizeof(buf), buf); if (ret >= 0) ret = buf[0] & PORT_CONNECTION; return ret; @@ -96,7 +96,7 @@ static int usb_hub_port_in_reset(usbdev_t *const dev, const int port) { unsigned short buf[2]; - int ret = get_status (dev, port, DR_PORT, sizeof(buf), buf); + int ret = get_status(dev, port, DR_PORT, sizeof(buf), buf); if (ret >= 0) ret = buf[0] & PORT_RESET; return ret; @@ -106,7 +106,7 @@ static int usb_hub_port_enabled(usbdev_t *const dev, const int port) { unsigned short buf[2]; - int ret = get_status (dev, port, DR_PORT, sizeof(buf), buf); + int ret = get_status(dev, port, DR_PORT, sizeof(buf), buf); if (ret >= 0) ret = buf[0] & PORT_ENABLE; return ret; @@ -116,7 +116,7 @@ static usb_speed usb_hub_port_speed(usbdev_t *const dev, const int port) { unsigned short buf[2]; - int ret = get_status (dev, port, DR_PORT, sizeof(buf), buf); + int ret = get_status(dev, port, DR_PORT, sizeof(buf), buf); if (ret >= 0 && (buf[0] & PORT_ENABLE)) { /* SuperSpeed hubs can only have SuperSpeed devices. */ if (is_usb_speed_ss(dev->speed)) @@ -144,7 +144,7 @@ usb_hub_enable_port(usbdev_t *const dev, const int port) static int usb_hub_start_port_reset(usbdev_t *const dev, const int port) { - return set_feature (dev, port, SEL_PORT_RESET, DR_PORT); + return set_feature(dev, port, SEL_PORT_RESET, DR_PORT); } static void usb_hub_set_hub_depth(usbdev_t *const dev) diff --git a/payloads/libpayload/drivers/usb/usbinit.c b/payloads/libpayload/drivers/usb/usbinit.c index 499a46629f..a234b00e4b 100644 --- a/payloads/libpayload/drivers/usb/usbinit.c +++ b/payloads/libpayload/drivers/usb/usbinit.c @@ -52,7 +52,7 @@ static int usb_controller_initialize(int bus, int dev, int func) pcidev_t pci_device; u32 pciid; - pci_device = PCI_DEV (bus, dev, func); + pci_device = PCI_DEV(bus, dev, func); class = pci_read_config32(pci_device, 8); pciid = pci_read_config32(pci_device, 0); @@ -73,7 +73,7 @@ static int usb_controller_initialize(int bus, int dev, int func) case 0x00: #if CONFIG(LP_USB_UHCI) usb_debug("UHCI controller\n"); - uhci_pci_init (pci_device); + uhci_pci_init(pci_device); #else usb_debug("UHCI controller (not supported)\n"); #endif diff --git a/payloads/libpayload/drivers/usb/usbmsc.c b/payloads/libpayload/drivers/usb/usbmsc.c index 75a8804b28..3f249d8bbb 100644 --- a/payloads/libpayload/drivers/usb/usbmsc.c +++ b/payloads/libpayload/drivers/usb/usbmsc.c @@ -67,29 +67,29 @@ static const char *msc_protocol_strings[0x51] = { }; static void -usb_msc_create_disk (usbdev_t *dev) +usb_msc_create_disk(usbdev_t *dev) { if (usbdisk_create) { - usbdisk_create (dev); - MSC_INST (dev)->usbdisk_created = 1; + usbdisk_create(dev); + MSC_INST(dev)->usbdisk_created = 1; } } static void -usb_msc_remove_disk (usbdev_t *dev) +usb_msc_remove_disk(usbdev_t *dev) { - if (MSC_INST (dev)->usbdisk_created && usbdisk_remove) { - usbdisk_remove (dev); - MSC_INST (dev)->usbdisk_created = 0; + if (MSC_INST(dev)->usbdisk_created && usbdisk_remove) { + usbdisk_remove(dev); + MSC_INST(dev)->usbdisk_created = 0; } } static void -usb_msc_destroy (usbdev_t *dev) +usb_msc_destroy(usbdev_t *dev) { if (dev->data) { - usb_msc_remove_disk (dev); - free (dev->data); + usb_msc_remove_disk(dev); + free(dev->data); } dev->data = 0; } @@ -136,17 +136,17 @@ enum { }; static int -request_sense (usbdev_t *dev); +request_sense(usbdev_t *dev); static int -request_sense_no_media (usbdev_t *dev); +request_sense_no_media(usbdev_t *dev); static void -usb_msc_poll (usbdev_t *dev); +usb_msc_poll(usbdev_t *dev); static int -reset_transport (usbdev_t *dev) +reset_transport(usbdev_t *dev) { dev_req_t dr; - memset (&dr, 0, sizeof (dr)); + memset(&dr, 0, sizeof(dr)); dr.bmRequestType = 0; dr.data_dir = host_to_device; #ifndef QEMU @@ -158,15 +158,15 @@ reset_transport (usbdev_t *dev) dr.wIndex = 0; dr.wLength = 0; - if (MSC_INST (dev)->quirks & USB_MSC_QUIRK_NO_RESET) + if (MSC_INST(dev)->quirks & USB_MSC_QUIRK_NO_RESET) return MSC_COMMAND_FAIL; /* if any of these fails, detach device, as we are lost */ - if (dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0) < 0 || - clear_stall (MSC_INST (dev)->bulk_in) || - clear_stall (MSC_INST (dev)->bulk_out)) { - usb_debug ("Detaching unresponsive device.\n"); - usb_detach_device (dev->controller, dev->address); + if (dev->controller->control(dev, OUT, sizeof(dr), &dr, 0, 0) < 0 || + clear_stall(MSC_INST(dev)->bulk_in) || + clear_stall(MSC_INST(dev)->bulk_out)) { + usb_debug("Detaching unresponsive device.\n"); + usb_detach_device(dev->controller, dev->address); return MSC_COMMAND_DETACHED; } /* return fail as we are only called in case of failure */ @@ -175,9 +175,9 @@ reset_transport (usbdev_t *dev) /* device may stall this command, so beware! */ static void -initialize_luns (usbdev_t *dev) +initialize_luns(usbdev_t *dev) { - usbmsc_inst_t *msc = MSC_INST (dev); + usbmsc_inst_t *msc = MSC_INST(dev); dev_req_t dr; dr.bmRequestType = 0; dr.data_dir = device_to_host; @@ -189,9 +189,9 @@ initialize_luns (usbdev_t *dev) dr.wValue = 0; dr.wIndex = 0; dr.wLength = 1; - if (MSC_INST (dev)->quirks & USB_MSC_QUIRK_NO_LUNS || - dev->controller->control (dev, IN, sizeof (dr), &dr, - sizeof (msc->num_luns), &msc->num_luns) < 0) + if (MSC_INST(dev)->quirks & USB_MSC_QUIRK_NO_LUNS || + dev->controller->control(dev, IN, sizeof(dr), &dr, + sizeof(msc->num_luns), &msc->num_luns) < 0) msc->num_luns = 0; /* assume only 1 lun if req fails */ msc->num_luns++; /* Get Max LUN returns number of last LUN */ msc->lun = 0; @@ -200,10 +200,10 @@ initialize_luns (usbdev_t *dev) unsigned int tag; static void -wrap_cbw (cbw_t *cbw, int datalen, cbw_direction dir, const u8 *cmd, +wrap_cbw(cbw_t *cbw, int datalen, cbw_direction dir, const u8 *cmd, int cmdlen, u8 lun) { - memset (cbw, 0, sizeof (cbw_t)); + memset(cbw, 0, sizeof(cbw_t)); /* commands are typically shorter, but we don't want overflows */ if (cmdlen > sizeof(cbw->CBWCB)) { @@ -216,37 +216,37 @@ wrap_cbw (cbw_t *cbw, int datalen, cbw_direction dir, const u8 *cmd, cbw->dCBWDataTransferLength = datalen; cbw->bmCBWFlags = dir; - memcpy (cbw->CBWCB, cmd, cmdlen); + memcpy(cbw->CBWCB, cmd, cmdlen); cbw->bCBWCBLength = cmdlen; } static int -get_csw (endpoint_t *ep, csw_t *csw) +get_csw(endpoint_t *ep, csw_t *csw) { hci_t *ctrlr = ep->dev->controller; - int ret = ctrlr->bulk (ep, sizeof (csw_t), (u8 *) csw, 1); + int ret = ctrlr->bulk(ep, sizeof(csw_t), (u8 *) csw, 1); /* Some broken sticks send a zero-length packet at the end of their data transfer which would show up here. Skip it to get the actual CSW. */ if (ret == 0) - ret = ctrlr->bulk (ep, sizeof (csw_t), (u8 *) csw, 1); + ret = ctrlr->bulk(ep, sizeof(csw_t), (u8 *) csw, 1); if (ret < 0) { - clear_stall (ep); - ret = ctrlr->bulk (ep, sizeof (csw_t), (u8 *) csw, 1); + clear_stall(ep); + ret = ctrlr->bulk(ep, sizeof(csw_t), (u8 *) csw, 1); if (ret < 0) - return reset_transport (ep->dev); + return reset_transport(ep->dev); } if (ret != sizeof(csw_t) || csw->dCSWTag != tag || csw->dCSWSignature != csw_signature) { - usb_debug ("MSC: received malformed CSW\n"); - return reset_transport (ep->dev); + usb_debug("MSC: received malformed CSW\n"); + return reset_transport(ep->dev); } return MSC_COMMAND_OK; } static int -execute_command (usbdev_t *dev, cbw_direction dir, const u8 *cb, int cblen, +execute_command(usbdev_t *dev, cbw_direction dir, const u8 *cb, int cblen, u8 *buf, int buflen, int residue_ok) { cbw_t cbw; @@ -256,23 +256,23 @@ execute_command (usbdev_t *dev, cbw_direction dir, const u8 *cb, int cblen, if ((cb[0] == 0x1b) && (cb[4] == 1)) { //start command, always succeed always_succeed = 1; } - wrap_cbw (&cbw, buflen, dir, cb, cblen, MSC_INST (dev)->lun); + wrap_cbw(&cbw, buflen, dir, cb, cblen, MSC_INST(dev)->lun); if (dev->controller-> - bulk (MSC_INST (dev)->bulk_out, sizeof (cbw), (u8 *) &cbw, 0) < 0) { - return reset_transport (dev); + bulk(MSC_INST(dev)->bulk_out, sizeof(cbw), (u8 *) &cbw, 0) < 0) { + return reset_transport(dev); } if (buflen > 0) { if (dir == cbw_direction_data_in) { if (dev->controller-> - bulk (MSC_INST (dev)->bulk_in, buflen, buf, 0) < 0) - clear_stall (MSC_INST (dev)->bulk_in); + bulk(MSC_INST(dev)->bulk_in, buflen, buf, 0) < 0) + clear_stall(MSC_INST(dev)->bulk_in); } else { if (dev->controller-> - bulk (MSC_INST (dev)->bulk_out, buflen, buf, 0) < 0) - clear_stall (MSC_INST (dev)->bulk_out); + bulk(MSC_INST(dev)->bulk_out, buflen, buf, 0) < 0) + clear_stall(MSC_INST(dev)->bulk_out); } } - int ret = get_csw (MSC_INST (dev)->bulk_in, &csw); + int ret = get_csw(MSC_INST(dev)->bulk_in, &csw); if (ret) { return ret; } else if (always_succeed == 1) { @@ -280,7 +280,7 @@ execute_command (usbdev_t *dev, cbw_direction dir, const u8 *cb, int cblen, return MSC_COMMAND_OK; } else if (csw.bCSWStatus == 2) { /* phase error, reset transport */ - return reset_transport (dev); + return reset_transport(dev); } else if (csw.bCSWStatus == 0) { if ((csw.dCSWDataResidue == 0) || residue_ok) /* no error, exit */ @@ -296,9 +296,9 @@ execute_command (usbdev_t *dev, cbw_direction dir, const u8 *cb, int cblen, /* If command was TEST UNIT READY determine if the * device is of removable type indicating no media * found. */ - return request_sense_no_media (dev); + return request_sense_no_media(dev); /* error "check condition" or reserved error */ - ret = request_sense (dev); + ret = request_sense(dev); /* return fail or the status of request_sense if it's worse */ return ret ? ret : MSC_COMMAND_FAIL; } @@ -342,11 +342,11 @@ typedef struct { * @return 0 on success, 1 on failure */ int -readwrite_blocks_512 (usbdev_t *dev, int start, int n, +readwrite_blocks_512(usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) { int blocksize_divider = MSC_INST(dev)->blocksize / 512; - return readwrite_blocks (dev, start / blocksize_divider, + return readwrite_blocks(dev, start / blocksize_divider, n / blocksize_divider, dir, buf); } @@ -363,10 +363,10 @@ readwrite_blocks_512 (usbdev_t *dev, int start, int n, * @return 0 on success, 1 on failure */ static int -readwrite_chunk (usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) +readwrite_chunk(usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) { cmdblock_t cb; - memset (&cb, 0, sizeof (cb)); + memset(&cb, 0, sizeof(cb)); if (dir == cbw_direction_data_in) { // read cb.command = 0x28; @@ -374,10 +374,10 @@ readwrite_chunk (usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) // write cb.command = 0x2a; } - cb.block = htonl (start); - cb.numblocks = htonw (n); + cb.block = htonl(start); + cb.numblocks = htonw(n); - return execute_command (dev, dir, (u8 *) &cb, sizeof (cb), buf, + return execute_command(dev, dir, (u8 *) &cb, sizeof(cb), buf, n * MSC_INST(dev)->blocksize, 0) != MSC_COMMAND_OK ? 1 : 0; } @@ -399,14 +399,14 @@ readwrite_chunk (usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) * @return 0 on success, 1 on failure */ int -readwrite_blocks (usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) +readwrite_blocks(usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) { int chunk_size = MAX_CHUNK_BYTES / MSC_INST(dev)->blocksize; int chunk; /* Read as many full chunks as needed. */ for (chunk = 0; chunk < (n / chunk_size); chunk++) { - if (readwrite_chunk (dev, start + (chunk * chunk_size), + if (readwrite_chunk(dev, start + (chunk * chunk_size), chunk_size, dir, buf + (chunk * MAX_CHUNK_BYTES)) != MSC_COMMAND_OK) @@ -415,7 +415,7 @@ readwrite_blocks (usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) /* Read any remaining partial chunk at the end. */ if (n % chunk_size) { - if (readwrite_chunk (dev, start + (chunk * chunk_size), + if (readwrite_chunk(dev, start + (chunk * chunk_size), n % chunk_size, dir, buf + (chunk * MAX_CHUNK_BYTES)) != MSC_COMMAND_OK) @@ -429,29 +429,29 @@ readwrite_blocks (usbdev_t *dev, int start, int n, cbw_direction dir, u8 *buf) On certain errors, that's necessary to get devices out of a special state called "Contingent Allegiance Condition" */ static int -request_sense (usbdev_t *dev) +request_sense(usbdev_t *dev) { u8 buf[19]; cmdblock6_t cb; - memset (&cb, 0, sizeof (cb)); + memset(&cb, 0, sizeof(cb)); cb.command = 0x3; - cb.length = sizeof (buf); + cb.length = sizeof(buf); - return execute_command (dev, cbw_direction_data_in, (u8 *) &cb, - sizeof (cb), buf, sizeof (buf), 1); + return execute_command(dev, cbw_direction_data_in, (u8 *) &cb, + sizeof(cb), buf, sizeof(buf), 1); } -static int request_sense_no_media (usbdev_t *dev) +static int request_sense_no_media(usbdev_t *dev) { u8 buf[19]; int ret; cmdblock6_t cb; - memset (&cb, 0, sizeof (cb)); + memset(&cb, 0, sizeof(cb)); cb.command = 0x3; - cb.length = sizeof (buf); + cb.length = sizeof(buf); - ret = execute_command (dev, cbw_direction_data_in, (u8 *) &cb, - sizeof (cb), buf, sizeof (buf), 1); + ret = execute_command(dev, cbw_direction_data_in, (u8 *) &cb, + sizeof(cb), buf, sizeof(buf), 1); if (ret) return ret; @@ -466,45 +466,45 @@ static int request_sense_no_media (usbdev_t *dev) /* No media is present. Return MSC_COMMAND_OK while marking the disk * not ready. */ - usb_debug ("Empty media found.\n"); - MSC_INST (dev)->ready = USB_MSC_NOT_READY; + usb_debug("Empty media found.\n"); + MSC_INST(dev)->ready = USB_MSC_NOT_READY; return MSC_COMMAND_OK; } static int -test_unit_ready (usbdev_t *dev) +test_unit_ready(usbdev_t *dev) { cmdblock6_t cb; - memset (&cb, 0, sizeof (cb)); // full initialization for T-U-R - return execute_command (dev, cbw_direction_data_out, (u8 *) &cb, - sizeof (cb), 0, 0, 0); + memset(&cb, 0, sizeof(cb)); // full initialization for T-U-R + return execute_command(dev, cbw_direction_data_out, (u8 *) &cb, + sizeof(cb), 0, 0, 0); } static int -spin_up (usbdev_t *dev) +spin_up(usbdev_t *dev) { cmdblock6_t cb; - memset (&cb, 0, sizeof (cb)); + memset(&cb, 0, sizeof(cb)); cb.command = 0x1b; cb.start = 1; - return execute_command (dev, cbw_direction_data_out, (u8 *) &cb, - sizeof (cb), 0, 0, 0); + return execute_command(dev, cbw_direction_data_out, (u8 *) &cb, + sizeof(cb), 0, 0, 0); } static int -read_capacity (usbdev_t *dev) +read_capacity(usbdev_t *dev) { cmdblock_t cb; - memset (&cb, 0, sizeof (cb)); + memset(&cb, 0, sizeof(cb)); cb.command = 0x25; // read capacity u32 buf[2]; - usb_debug ("Reading capacity of mass storage device.\n"); + usb_debug("Reading capacity of mass storage device.\n"); int count = 0, ret; while (count++ < 20) { switch (ret = execute_command (dev, cbw_direction_data_in, (u8 *) &cb, - sizeof (cb), (u8 *)buf, 8, 0)) { + sizeof(cb), (u8 *)buf, 8, 0)) { case MSC_COMMAND_OK: break; case MSC_COMMAND_FAIL: @@ -516,24 +516,24 @@ read_capacity (usbdev_t *dev) } if (count >= 20) { // still not successful, assume 2tb in 512byte sectors, which is just the same garbage as any other number, but probably more usable. - usb_debug (" assuming 2 TB with 512-byte sectors as READ CAPACITY didn't answer.\n"); - MSC_INST (dev)->numblocks = 0xffffffff; - MSC_INST (dev)->blocksize = 512; + usb_debug(" assuming 2 TB with 512-byte sectors as READ CAPACITY didn't answer.\n"); + MSC_INST(dev)->numblocks = 0xffffffff; + MSC_INST(dev)->blocksize = 512; } else { - MSC_INST (dev)->numblocks = ntohl(buf[0]) + 1; - MSC_INST (dev)->blocksize = ntohl(buf[1]); + MSC_INST(dev)->numblocks = ntohl(buf[0]) + 1; + MSC_INST(dev)->blocksize = ntohl(buf[1]); } - usb_debug (" %d %d-byte sectors (%d MB)\n", MSC_INST (dev)->numblocks, - MSC_INST (dev)->blocksize, + usb_debug(" %d %d-byte sectors (%d MB)\n", MSC_INST(dev)->numblocks, + MSC_INST(dev)->blocksize, /* round down high block counts to avoid integer overflow */ - MSC_INST (dev)->numblocks > 1000000 - ? (MSC_INST (dev)->numblocks / 1000) * MSC_INST (dev)->blocksize / 1000 : - MSC_INST (dev)->numblocks * MSC_INST (dev)->blocksize / 1000 / 1000); + MSC_INST(dev)->numblocks > 1000000 + ? (MSC_INST(dev)->numblocks / 1000) * MSC_INST(dev)->blocksize / 1000 : + MSC_INST(dev)->numblocks * MSC_INST(dev)->blocksize / 1000 / 1000); return MSC_COMMAND_OK; } static int -usb_msc_test_unit_ready (usbdev_t *dev) +usb_msc_test_unit_ready(usbdev_t *dev) { int i; time_t start_time_secs; @@ -543,21 +543,21 @@ usb_msc_test_unit_ready (usbdev_t *dev) * devices which fail to respond. */ const int timeout_secs = 5; - usb_debug (" Waiting for device to become ready..."); + usb_debug(" Waiting for device to become ready..."); /* Initially mark the device ready. */ - MSC_INST (dev)->ready = USB_MSC_READY; - gettimeofday (&tv, NULL); + MSC_INST(dev)->ready = USB_MSC_READY; + gettimeofday(&tv, NULL); start_time_secs = tv.tv_sec; while (tv.tv_sec - start_time_secs < timeout_secs) { - switch (test_unit_ready (dev)) { + switch (test_unit_ready(dev)) { case MSC_COMMAND_OK: break; case MSC_COMMAND_FAIL: - mdelay (100); - usb_debug ("."); - gettimeofday (&tv, NULL); + mdelay(100); + usb_debug("."); + gettimeofday(&tv, NULL); continue; default: /* Device detached, return immediately */ @@ -566,27 +566,27 @@ usb_msc_test_unit_ready (usbdev_t *dev) break; } if (!(tv.tv_sec - start_time_secs < timeout_secs)) { - usb_debug ("timeout. Device not ready.\n"); - MSC_INST (dev)->ready = USB_MSC_NOT_READY; + usb_debug("timeout. Device not ready.\n"); + MSC_INST(dev)->ready = USB_MSC_NOT_READY; } /* Don't bother spinning up the storage device if the device is not * ready. This can happen when empty card readers are present. * Polling will pick it back up if readiness changes. */ - if (!MSC_INST (dev)->ready) - return MSC_INST (dev)->ready; + if (!MSC_INST(dev)->ready) + return MSC_INST(dev)->ready; - usb_debug ("ok.\n"); + usb_debug("ok.\n"); - usb_debug (" spin up"); + usb_debug(" spin up"); for (i = 0; i < 30; i++) { - usb_debug ("."); - switch (spin_up (dev)) { + usb_debug("."); + switch (spin_up(dev)) { case MSC_COMMAND_OK: - usb_debug (" OK."); + usb_debug(" OK."); break; case MSC_COMMAND_FAIL: - mdelay (100); + mdelay(100); continue; default: /* Device detached, return immediately */ @@ -594,30 +594,30 @@ usb_msc_test_unit_ready (usbdev_t *dev) } break; } - usb_debug ("\n"); + usb_debug("\n"); - if (read_capacity (dev) == MSC_COMMAND_DETACHED) + if (read_capacity(dev) == MSC_COMMAND_DETACHED) return USB_MSC_DETACHED; - return MSC_INST (dev)->ready; + return MSC_INST(dev)->ready; } void -usb_msc_init (usbdev_t *dev) +usb_msc_init(usbdev_t *dev) { configuration_descriptor_t *cd = (configuration_descriptor_t *) dev->configuration; interface_descriptor_t *interface = (interface_descriptor_t *) (((char *) cd) + cd->bLength); - usb_debug (" it uses %s command set\n", + usb_debug(" it uses %s command set\n", msc_subclass_strings[interface->bInterfaceSubClass]); - usb_debug (" it uses %s protocol\n", + usb_debug(" it uses %s protocol\n", msc_protocol_strings[interface->bInterfaceProtocol]); if (interface->bInterfaceProtocol != 0x50) { - usb_debug (" Protocol not supported.\n"); - usb_detach_device (dev->controller, dev->address); + usb_debug(" Protocol not supported.\n"); + usb_detach_device(dev->controller, dev->address); return; } @@ -625,15 +625,15 @@ usb_msc_init (usbdev_t *dev) (interface->bInterfaceSubClass != 5) && // ATAPI 8070 (interface->bInterfaceSubClass != 6)) { // SCSI /* Other protocols, such as ATAPI don't seem to be very popular. looks like ATAPI would be really easy to add, if necessary. */ - usb_debug (" Interface SubClass not supported.\n"); - usb_detach_device (dev->controller, dev->address); + usb_debug(" Interface SubClass not supported.\n"); + usb_detach_device(dev->controller, dev->address); return; } - usb_msc_force_init (dev, 0); + usb_msc_force_init(dev, 0); } -void usb_msc_force_init (usbdev_t *dev, u32 quirks) +void usb_msc_force_init(usbdev_t *dev, u32 quirks) { int i; @@ -643,14 +643,14 @@ void usb_msc_force_init (usbdev_t *dev, u32 quirks) dev->destroy = usb_msc_destroy; dev->poll = usb_msc_poll; - dev->data = malloc (sizeof (usbmsc_inst_t)); + dev->data = malloc(sizeof(usbmsc_inst_t)); if (!dev->data) fatal("Not enough memory for USB MSC device.\n"); - MSC_INST (dev)->bulk_in = 0; - MSC_INST (dev)->bulk_out = 0; - MSC_INST (dev)->usbdisk_created = 0; - MSC_INST (dev)->quirks = quirks; + MSC_INST(dev)->bulk_in = 0; + MSC_INST(dev)->bulk_out = 0; + MSC_INST(dev)->usbdisk_created = 0; + MSC_INST(dev)->quirks = quirks; for (i = 1; i <= dev->num_endp; i++) { if (dev->endpoints[i].endpoint == 0) @@ -658,56 +658,56 @@ void usb_msc_force_init (usbdev_t *dev, u32 quirks) if (dev->endpoints[i].type != BULK) continue; if ((dev->endpoints[i].direction == IN) - && (MSC_INST (dev)->bulk_in == 0)) - MSC_INST (dev)->bulk_in = &dev->endpoints[i]; + && (MSC_INST(dev)->bulk_in == 0)) + MSC_INST(dev)->bulk_in = &dev->endpoints[i]; if ((dev->endpoints[i].direction == OUT) - && (MSC_INST (dev)->bulk_out == 0)) - MSC_INST (dev)->bulk_out = &dev->endpoints[i]; + && (MSC_INST(dev)->bulk_out == 0)) + MSC_INST(dev)->bulk_out = &dev->endpoints[i]; } - if (MSC_INST (dev)->bulk_in == 0) { + if (MSC_INST(dev)->bulk_in == 0) { usb_debug("couldn't find bulk-in endpoint.\n"); - usb_detach_device (dev->controller, dev->address); + usb_detach_device(dev->controller, dev->address); return; } - if (MSC_INST (dev)->bulk_out == 0) { + if (MSC_INST(dev)->bulk_out == 0) { usb_debug("couldn't find bulk-out endpoint.\n"); - usb_detach_device (dev->controller, dev->address); + usb_detach_device(dev->controller, dev->address); return; } - usb_debug (" using endpoint %x as in, %x as out\n", - MSC_INST (dev)->bulk_in->endpoint, - MSC_INST (dev)->bulk_out->endpoint); + usb_debug(" using endpoint %x as in, %x as out\n", + MSC_INST(dev)->bulk_in->endpoint, + MSC_INST(dev)->bulk_out->endpoint); /* Some sticks need a little more time to get ready after SET_CONFIG. */ udelay(50); - initialize_luns (dev); - usb_debug (" has %d luns\n", MSC_INST (dev)->num_luns); + initialize_luns(dev); + usb_debug(" has %d luns\n", MSC_INST(dev)->num_luns); /* Test if unit is ready (nothing to do if it isn't). */ - if (usb_msc_test_unit_ready (dev) != USB_MSC_READY) + if (usb_msc_test_unit_ready(dev) != USB_MSC_READY) return; /* Create the disk. */ - usb_msc_create_disk (dev); + usb_msc_create_disk(dev); } static void -usb_msc_poll (usbdev_t *dev) +usb_msc_poll(usbdev_t *dev) { - usbmsc_inst_t *msc = MSC_INST (dev); + usbmsc_inst_t *msc = MSC_INST(dev); int prev_ready = msc->ready; - if (usb_msc_test_unit_ready (dev) == USB_MSC_DETACHED) + if (usb_msc_test_unit_ready(dev) == USB_MSC_DETACHED) return; if (!prev_ready && msc->ready) { - usb_debug ("USB msc: not ready -> ready (lun %d)\n", msc->lun); - usb_msc_create_disk (dev); + usb_debug("USB msc: not ready -> ready (lun %d)\n", msc->lun); + usb_msc_create_disk(dev); } else if (prev_ready && !msc->ready) { - usb_debug ("USB msc: ready -> not ready (lun %d)\n", msc->lun); - usb_msc_remove_disk (dev); + usb_debug("USB msc: ready -> not ready (lun %d)\n", msc->lun); + usb_msc_remove_disk(dev); } else if (!prev_ready && !msc->ready) { u8 new_lun = (msc->lun + 1) % msc->num_luns; usb_debug("USB msc: not ready (lun %d) -> lun %d\n", msc->lun, diff --git a/payloads/libpayload/drivers/usb/xhci.c b/payloads/libpayload/drivers/usb/xhci.c index c40e641c4c..6737a140ec 100644 --- a/payloads/libpayload/drivers/usb/xhci.c +++ b/payloads/libpayload/drivers/usb/xhci.c @@ -34,17 +34,17 @@ #include "xhci_private.h" #include "xhci.h" -static void xhci_start (hci_t *controller); -static void xhci_stop (hci_t *controller); -static void xhci_reset (hci_t *controller); -static void xhci_reinit (hci_t *controller); -static void xhci_shutdown (hci_t *controller); -static int xhci_bulk (endpoint_t *ep, int size, u8 *data, int finalize); -static int xhci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq, +static void xhci_start(hci_t *controller); +static void xhci_stop(hci_t *controller); +static void xhci_reset(hci_t *controller); +static void xhci_reinit(hci_t *controller); +static void xhci_shutdown(hci_t *controller); +static int xhci_bulk(endpoint_t *ep, int size, u8 *data, int finalize); +static int xhci_control(usbdev_t *dev, direction_t dir, int drlen, void *devreq, int dalen, u8 *data); -static void* xhci_create_intr_queue (endpoint_t *ep, int reqsize, int reqcount, int reqtiming); -static void xhci_destroy_intr_queue (endpoint_t *ep, void *queue); -static u8* xhci_poll_intr_queue (void *queue); +static void* xhci_create_intr_queue(endpoint_t *ep, int reqsize, int reqcount, int reqtiming); +static void xhci_destroy_intr_queue(endpoint_t *ep, void *queue); +static u8* xhci_poll_intr_queue(void *queue); /* * Some structures must not cross page boundaries. To get this, @@ -151,7 +151,7 @@ xhci_wait_ready(xhci_t *const xhci) } hci_t * -xhci_init (unsigned long physical_bar) +xhci_init(unsigned long physical_bar) { int i; @@ -167,7 +167,7 @@ xhci_init (unsigned long physical_bar) controller->bulk = xhci_bulk; controller->control = xhci_control; controller->set_address = xhci_set_address; - controller->finish_device_config= xhci_finish_device_config; + controller->finish_device_config = xhci_finish_device_config; controller->destroy_device = xhci_destroy_dev; controller->create_intr_queue = xhci_create_intr_queue; controller->destroy_intr_queue = xhci_destroy_intr_queue; @@ -306,7 +306,7 @@ _free_xhci: #if CONFIG(LP_USB_PCI) hci_t * -xhci_pci_init (pcidev_t addr) +xhci_pci_init(pcidev_t addr) { u32 reg_addr; hci_t *controller; @@ -358,7 +358,7 @@ xhci_reset(hci_t *const controller) } static void -xhci_reinit (hci_t *controller) +xhci_reinit(hci_t *controller) { xhci_t *const xhci = XHCI_INST(controller); @@ -464,7 +464,7 @@ xhci_shutdown(hci_t *const controller) } static void -xhci_start (hci_t *controller) +xhci_start(hci_t *controller) { xhci_t *const xhci = XHCI_INST(controller); @@ -474,7 +474,7 @@ xhci_start (hci_t *controller) } static void -xhci_stop (hci_t *controller) +xhci_stop(hci_t *controller) { xhci_t *const xhci = XHCI_INST(controller); diff --git a/payloads/libpayload/drivers/usb/xhci.h b/payloads/libpayload/drivers/usb/xhci.h index 37ad1096af..40cec1c1fd 100644 --- a/payloads/libpayload/drivers/usb/xhci.h +++ b/payloads/libpayload/drivers/usb/xhci.h @@ -32,9 +32,9 @@ #include <pci.h> #include <usb/usb.h> -hci_t *xhci_pci_init (pcidev_t addr); -hci_t *xhci_init (unsigned long physical_bar); +hci_t *xhci_pci_init(pcidev_t addr); +hci_t *xhci_init(unsigned long physical_bar); -void xhci_rh_init (usbdev_t *dev); +void xhci_rh_init(usbdev_t *dev); #endif diff --git a/payloads/libpayload/drivers/usb/xhci_devconf.c b/payloads/libpayload/drivers/usb/xhci_devconf.c index ec4c45e26d..2f481f5c1d 100644 --- a/payloads/libpayload/drivers/usb/xhci_devconf.c +++ b/payloads/libpayload/drivers/usb/xhci_devconf.c @@ -124,7 +124,7 @@ xhci_make_inputctx(const size_t ctxsize) } usbdev_t * -xhci_set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) +xhci_set_address(hci_t *controller, usb_speed speed, int hubport, int hubaddr) { xhci_t *const xhci = XHCI_INST(controller); const size_t ctxsize = CTXSIZE(xhci); @@ -162,7 +162,7 @@ xhci_set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr) for (i = 0; i < NUM_EPS; i++, dma_buffer += ctxsize) di->ctx.ep[i] = dma_buffer; - *ic->add = (1 << 0) /* Slot Context */ | (1 << 1) /* EP0 Context */ ; + *ic->add = (1 << 0) /* Slot Context */ | (1 << 1) /* EP0 Context */; SC_SET(ROUTE, ic->dev.slot, xhci_gen_route(xhci, hubport, hubaddr)); SC_SET(SPEED1, ic->dev.slot, speed + 1); @@ -288,7 +288,7 @@ xhci_finish_hub_config(usbdev_t *const dev, inputctx_t *const ic) static size_t xhci_bound_interval(const endpoint_t *const ep) { - if ( (ep->dev->speed == LOW_SPEED && + if ((ep->dev->speed == LOW_SPEED && (ep->type == ISOCHRONOUS || ep->type == INTERRUPT)) || (ep->dev->speed == FULL_SPEED && diff --git a/payloads/libpayload/drivers/usb/xhci_private.h b/payloads/libpayload/drivers/usb/xhci_private.h index 34d3651daf..45c301391e 100644 --- a/payloads/libpayload/drivers/usb/xhci_private.h +++ b/payloads/libpayload/drivers/usb/xhci_private.h @@ -40,7 +40,7 @@ #ifdef XHCI_SPEW_DEBUG # define xhci_spew(fmt, args...) xhci_debug(fmt, ##args) #else -# define xhci_spew(fmt, args...) do {} while(0) +# define xhci_spew(fmt, args...) do {} while (0) #endif #define MASK(startbit, lenbit) (((1<<(lenbit))-1)<<(startbit)) @@ -377,7 +377,7 @@ typedef struct xhci { u32 hccparams; u32 dboff; u32 rtsoff; - } __packed *capreg; + } __packed * capreg; /* opreg is R/W is most places, so volatile access is necessary. volatile means that the compiler seeks byte writes if possible, @@ -444,7 +444,7 @@ typedef struct xhci { u32 portli; /* 0x408 + 4 * port */ u32 res; /* 0x40C + 4 * port */ } __packed prs[]; - } __packed *opreg; + } __packed * opreg; /* R/W, volatile, MMIO -> no bitfields */ volatile struct hcrreg { @@ -460,7 +460,7 @@ typedef struct xhci { u32 erdp_lo; u32 erdp_hi; } __packed intrrs[]; // up to 1024, but maximum host specific, given in capreg->MaxIntrs - } __packed *hcrreg; + } __packed * hcrreg; /* R/W, volatile, MMIO -> no bitfields */ volatile u32 *dbreg; @@ -486,7 +486,7 @@ typedef struct xhci { void *xhci_align(const size_t min_align, const size_t size); void xhci_init_cycle_ring(transfer_ring_t *, const size_t ring_size); -usbdev_t *xhci_set_address (hci_t *, usb_speed speed, int hubport, int hubaddr); +usbdev_t *xhci_set_address(hci_t *, usb_speed speed, int hubport, int hubaddr); int xhci_finish_device_config(usbdev_t *); void xhci_destroy_dev(hci_t *, int slot_id); @@ -523,12 +523,12 @@ void xhci_dump_inputctx(const inputctx_t *); void xhci_dump_transfer_trb(const trb_t *); void xhci_dump_transfer_trbs(const trb_t *first, const trb_t *last); #else -#define xhci_dump_slotctx(args...) do {} while(0) -#define xhci_dump_epctx(args...) do {} while(0) -#define xhci_dump_devctx(args...) do {} while(0) -#define xhci_dump_inputctx(args...) do {} while(0) -#define xhci_dump_transfer_trb(args...) do {} while(0) -#define xhci_dump_transfer_trbs(args...) do {} while(0) +#define xhci_dump_slotctx(args...) do {} while (0) +#define xhci_dump_epctx(args...) do {} while (0) +#define xhci_dump_devctx(args...) do {} while (0) +#define xhci_dump_inputctx(args...) do {} while (0) +#define xhci_dump_transfer_trb(args...) do {} while (0) +#define xhci_dump_transfer_trbs(args...) do {} while (0) #endif #endif diff --git a/payloads/libpayload/drivers/usb/xhci_rh.c b/payloads/libpayload/drivers/usb/xhci_rh.c index bf4c2bc5c1..fe041b4115 100644 --- a/payloads/libpayload/drivers/usb/xhci_rh.c +++ b/payloads/libpayload/drivers/usb/xhci_rh.c @@ -149,7 +149,7 @@ static const generic_hub_ops_t xhci_rh_ops = { }; void -xhci_rh_init (usbdev_t *dev) +xhci_rh_init(usbdev_t *dev) { /* we can set them here because a root hub _really_ shouldn't appear elsewhere */ |