diff --git a/BaS_gcc/include/pci.h b/BaS_gcc/include/pci.h index 5939d43..b00f9a7 100644 --- a/BaS_gcc/include/pci.h +++ b/BaS_gcc/include/pci.h @@ -44,13 +44,13 @@ #define PCIHTR 0x0E /* PCI Header Type Register */ #define PCIBISTR 0x0F /* PCI Build-In Self Test Register */ #define PCIBAR0 0x10 /* PCI Base Address Register for Memory - Accesses to Local, Runtime, and DMA */ + Accesses to Local, Runtime, and DMA */ #define PCIBAR1 0x14 /* PCI Base Address Register for I/O - Accesses to Local, Runtime, and DMA */ + Accesses to Local, Runtime, and DMA */ #define PCIBAR2 0x18 /* PCI Base Address Register for Memory - Accesses to Local Address Space 0 */ + Accesses to Local Address Space 0 */ #define PCIBAR3 0x1C /* PCI Base Address Register for Memory - Accesses to Local Address Space 1 */ + Accesses to Local Address Space 1 */ #define PCIBAR4 0x20 /* PCI Base Address Register, reserved */ #define PCIBAR5 0x24 /* PCI Base Address Register, reserved */ #define PCICIS 0x28 /* PCI Cardbus CIS Pointer, not support*/ @@ -64,7 +64,7 @@ #define PCIMLR 0x3F /* PCI Max_Lat Register */ #define PMCAPID 0x40 /* Power Management Capability ID */ #define PMNEXT 0x41 /* Power Management Next Capability - Pointer */ + Pointer */ #define PMC 0x42 /* Power Management Capabilities */ #define PMCSR 0x44 /* Power Management Control/Status */ #define PMCSR_BSE 0x46 /* PMCSR Bridge Support Extensions */ @@ -74,7 +74,7 @@ #define HS_CSR 0x4A /* Hot Swap Control/Status */ #define PVPDCNTL 0x4C /* PCI Vital Product Data Control */ #define PVPD_NEXT 0x4D /* PCI Vital Product Data Next - Capability Pointer */ + Capability Pointer */ #define PVPDAD 0x4E /* PCI Vital Product Data Address */ #define PVPDATA 0x50 /* PCI VPD Data */ @@ -125,18 +125,18 @@ struct pci_rd /* structure of resource descriptor */ { - unsigned short next; /* length of the following structure */ - unsigned short flags; /* type of resource and misc. flags */ - unsigned long start; /* start-address of resource */ - unsigned long length; /* length of resource */ - unsigned long offset; /* offset PCI to phys. CPU Address */ - unsigned long dmaoffset; /* offset for DMA-transfers */ + unsigned short next; /* length of the following structure */ + unsigned short flags; /* type of resource and misc. flags */ + unsigned long start; /* start-address of resource */ + unsigned long length; /* length of resource */ + unsigned long offset; /* offset PCI to phys. CPU Address */ + unsigned long dmaoffset; /* offset for DMA-transfers */ } __attribute__ ((packed)); typedef struct /* structure of address conversion */ { - unsigned long adr; /* calculated address (CPU<->PCI) */ - unsigned long len; /* length of memory range */ + unsigned long adr; /* calculated address (CPU<->PCI) */ + unsigned long len; /* length of memory range */ } PCI_CONV_ADR; /******************************************************************************/ @@ -191,8 +191,8 @@ typedef struct /* structure of address conversion */ #define PCI_COMMAND(i) (((i) >> 16) & 0xffff) /* register 0x08 macros */ -#define PCI_CLASS_CODE(i) ((swpl((i)) & 0xff000000) >> 24) -#define PCI_SUBCLASS(i) ((swpl((i)) & 0x00ff0000) >> 16) +#define PCI_CLASS_CODE(i) ((swpl((i)) & 0xffff0000) >> 16) +#define PCI_SUBCLASS(i) ((swpl((i)) & 0xffffff00) >> 8) #define PCI_PROG_IF(i) ((swpl((i)) & 0x0000ff00) >> 8) #define PCI_REVISION_ID(i) ((swpl((i)) & 0x000000ff)) @@ -334,7 +334,7 @@ extern int32_t wrapper_phys_to_virt(uint32_t address, PCI_CONV_ADR *pointer); #define PCI_MK_CONF_ADDR(bus, device, function) (MCF_PCI_PCICAR_E | \ ((bus) << 16) | \ ((device << 8) | \ - (function)) + (function)) #define PCI_HANDLE(bus, slot, function) (0 | ((bus & 0xff) << 10 | (slot & 0x1f) << 3 | (function & 7))) #define PCI_BUS_FROM_HANDLE(h) (((h) & 0xff00) >> 10) diff --git a/BaS_gcc/pci/pci.c b/BaS_gcc/pci/pci.c index b9926c7..ab8e24f 100644 --- a/BaS_gcc/pci/pci.c +++ b/BaS_gcc/pci/pci.c @@ -76,7 +76,7 @@ static int num_pci_classes = sizeof(pci_classes) / sizeof(struct pci_class); #define NUM_CARDS 10 #define NUM_RESOURCES 7 /* holds the handle of a card at position = array index */ -static int32_t handles[NUM_CARDS]; +static int32_t handles[NUM_CARDS]; /* holds the interrupt handler addresses (see pci_hook_interrupt() and pci_unhook_interrupt()) of the PCI cards */ struct pci_interrupt @@ -89,7 +89,7 @@ struct pci_interrupt static struct pci_interrupt interrupts[MAX_INTERRUPTS]; /* holds the card's resource descriptors; filled in pci_device_config() */ -static struct pci_rd resource_descriptors[NUM_CARDS][NUM_RESOURCES]; +static struct pci_rd resource_descriptors[NUM_CARDS][NUM_RESOURCES]; __attribute__((aligned(16))) void chip_errata_135(void) @@ -153,7 +153,7 @@ static int32_t pci_get_interrupt_cause(int32_t *handles) while ((handle = *handles++) != -1) { - uint32_t csr = swpl(pci_read_config_longword(handle, PCICSR)); + uint32_t csr = swpl(pci_read_config_longword(handle, PCICSR)); if ((csr & (1 << 3)) && (csr & !(csr & (1 << 10)))) { @@ -162,7 +162,7 @@ static int32_t pci_get_interrupt_cause(int32_t *handles) return handle; } } - dbg("%s: no interrupt cause found\r\n"); + dbg("%s: no interrupt cause found\r\n"); return -1; } @@ -189,7 +189,7 @@ void irq5_handler(void) newvalue = pci_call_interrupt_chain(handle, value); if (newvalue == value) { - dbg("%s: interrupt not handled!\r\n"); + dbg("%s: interrupt not handled!\r\n"); } } } @@ -211,7 +211,7 @@ void irq7_handler(void) newvalue = pci_call_interrupt_chain(handle, value); if (newvalue == value) { - dbg("%s: interrupt not handled!\r\n"); + dbg("%s: interrupt not handled!\r\n"); } } } @@ -266,7 +266,7 @@ uint32_t pci_read_config_longword(int32_t handle, int offset) MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ MCF_PCI_PCICAR_DWORD(offset / 4); - + __asm__ __volatile__("nop" ::: "memory"); /* this is what the Linux BSP does */ pci_config_wait(); @@ -292,7 +292,7 @@ uint16_t pci_read_config_word(int32_t handle, int offset) MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | MCF_PCI_PCICAR_DWORD(offset / 4); - + __asm__ __volatile("nop" ::: "memory"); /* this is what Linux BSP does */ value = * (volatile uint16_t *) PCI_IO_OFFSET + (offset & 2); @@ -315,7 +315,7 @@ uint8_t pci_read_config_byte(int32_t handle, int offset) MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ MCF_PCI_PCICAR_DWORD(offset / 4); - + __asm__ __volatile__("nop" ::: "memory"); value = * (volatile uint8_t *) (PCI_IO_OFFSET + (offset & 3)); @@ -366,11 +366,11 @@ int32_t pci_write_config_word(int32_t handle, int offset, uint16_t value) MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | MCF_PCI_PCICAR_DWORD(offset / 4); - + __asm__ __volatile__("tpf" ::: "memory"); * (volatile uint16_t *) (PCI_IO_OFFSET + (offset & 2)) = value; - + __asm__ __volatile__("tpf" ::: "memory"); /* finish configuration space access cycle */ @@ -391,7 +391,7 @@ int32_t pci_write_config_byte(int32_t handle, int offset, uint8_t value) MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | MCF_PCI_PCICAR_DWORD(offset / 4); - + __asm__ __volatile__("tpf" ::: "memory"); * (volatile uint8_t *) (PCI_IO_OFFSET + (offset & 3)) = value; @@ -440,7 +440,7 @@ int32_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index) uint16_t n = 0; int32_t handle; - for (bus = 0; bus < 2; bus++) + for (bus = 0; bus < 1; bus++) { for (device = 10; device < 31; device++) { @@ -476,7 +476,7 @@ int32_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index) value = pci_read_config_longword(handle, PCIIDR); if (value != 0xFFFFFFFF) /* device found */ { - if (vendor_id == 0xffff || + if (vendor_id == 0xffff || (PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id)) { if (n == index) @@ -519,11 +519,11 @@ int32_t pci_find_classcode(uint32_t classcode, int index) handle = PCI_HANDLE(bus, device, 0); value = pci_read_config_longword(handle, PCIIDR); - + if (value != 0xffffffff) /* device found */ { value = pci_read_config_longword(handle, PCICCR); - + if ((classcode & (1 << 26) ? ((PCI_CLASS_CODE(value) == (classcode & 0xff))) : true) && (classcode & (1 << 25) ? ((PCI_SUBCLASS(value) == ((classcode & 0xff00) >> 8))) : true) && (classcode & (1 << 24) ? ((PCI_PROG_IF(value) == ((classcode & 0xff0000) >> 16))) : true)) @@ -536,10 +536,10 @@ int32_t pci_find_classcode(uint32_t classcode, int index) } /* - * there is a device at this position, but not the one we are looking for. - * Check to see if it is a multi-function device. We need to look "behind" it - * for the other functions in that case. - */ + * there is a device at this position, but not the one we are looking for. + * Check to see if it is a multi-function device. We need to look "behind" it + * for the other functions in that case. + */ if ((htr = pci_read_config_byte(handle, PCIHTR)) & 0x80) { /* yes, this is a multi-function device, look for more functions */ @@ -783,7 +783,7 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) /* * disable device */ - + cr = swpw(pci_read_config_word(handle, PCICSR)); cr &= ~3; /* disable device response to address */ pci_write_config_word(handle, PCICSR, swpw(cr)); @@ -808,9 +808,9 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) /* * resource descriptor for this device */ - struct pci_rd *rd = &descriptors[barnum]; + struct pci_rd *rd = &descriptors[barnum]; - dbg("%s: address = %08x\r\n", address); + dbg("%s: address = %08x\r\n", address); if (IS_PCI_MEM_BAR(address)) { /* adjust base address to card's alignment requirements */ @@ -825,7 +825,7 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) /* read it back, just to be sure */ value = swpl(pci_read_config_longword(handle, PCIBAR0 + i)) & ~1; - + dbg("set PCIBAR%d on device 0x%02x to 0x%08x\r\n", i / 4, handle, value); @@ -834,7 +834,7 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) rd->flags = 0 | FLG_32BIT | FLG_16BIT | FLG_8BIT | 2; /* little endian, lane swapped */ rd->start = address; rd->length = size; - rd->offset = 0; + rd->offset = 0; rd->dmaoffset = 0; /* adjust memory adress for next turn */ @@ -869,7 +869,7 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) cr |= 1; barnum++; - } + } } } @@ -889,7 +889,7 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) address = swpl(pci_read_config_longword(handle, PCIERBAR)); if (address & 1) { - struct pci_rd *rd = &descriptors[barnum]; + struct pci_rd *rd = &descriptors[barnum]; int size = ~(address & ~0x7ff); /* expansion ROM active and mapped */ @@ -899,10 +899,10 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) /* write it to PCIERBAR and enable ROM */ pci_write_config_longword(handle, PCIERBAR, swpl(address | 1)); - dbg("%s: set PCIERBAR on device 0x%02x to 0x%08x\r\n", handle, address | 1); + dbg("%s: set PCIERBAR on device 0x%02x to 0x%08x\r\n", handle, address | 1); /* read value back just to be sure */ - dbg("%s: PCIERBAR = %p\r\n", swpl(pci_read_config_longword(handle, PCIERBAR))); + dbg("%s: PCIERBAR = %p\r\n", swpl(pci_read_config_longword(handle, PCIERBAR))); rd->next = sizeof(struct pci_rd); @@ -923,11 +923,11 @@ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) /* check if device requests an interrupt */ il = pci_read_config_byte(handle, PCIIPR); dbg("device requests interrupts on interrupt pin %d\r\n", il); - + /* if so, register interrupts */ - + /* TODO: register interrupts here */ - + /* * enable device memory or I/O access */ @@ -1035,7 +1035,7 @@ void init_xlbus_arbiter(void) { MCF_XLB_XARB_CFG = MCF_XLB_XARB_CFG_BA | MCF_XLB_XARB_CFG_DT | - MCF_XLB_XARB_CFG_AT; + MCF_XLB_XARB_CFG_AT; } MCF_XLB_XARB_ADRTO = 0x1fffff; @@ -1049,7 +1049,7 @@ void init_xlbus_arbiter(void) * M2 = Multichannel DMA * M3 = PCI target interface */ - + MCF_XLB_XARB_PRIEN = MCF_XLB_XARB_PRIEN_M0 | /* activate programmed priority for Coldfire core */ MCF_XLB_XARB_PRIEN_M2 | /* activate programmed priority for Multichannel DMA */ MCF_XLB_XARB_PRIEN_M3; /* activate programmed priority for PCI target interface */ @@ -1081,9 +1081,9 @@ void init_pci(void) * setup the PCI arbiter */ MCF_PCIARB_PACR = MCF_PCIARB_PACR_INTMPRI /* internal master priority: high */ - | MCF_PCIARB_PACR_EXTMPRI(0xf) /* external master priority: high */ - | MCF_PCIARB_PACR_INTMINTEN /* enable "internal master broken" interrupt */ - | MCF_PCIARB_PACR_EXTMINTEN(0x0f); /* enable "external master broken" interrupt */ + | MCF_PCIARB_PACR_EXTMPRI(0xf) /* external master priority: high */ + | MCF_PCIARB_PACR_INTMINTEN /* enable "internal master broken" interrupt */ + | MCF_PCIARB_PACR_EXTMINTEN(0x0f); /* enable "external master broken" interrupt */ #ifdef _NOT_USED_ /* since this is already done in sysinit.c */ #if MACHINE_FIREBEE @@ -1100,7 +1100,7 @@ void init_pci(void) MCF_PCI_PCISCR_M | /* mem access enable */ MCF_PCI_PCISCR_MA | /* clear master abort error */ MCF_PCI_PCISCR_MW; /* memory write and invalidate enabled */ - + /* Setup burst parameters */ MCF_PCI_PCICR1 = MCF_PCI_PCICR1_CACHELINESIZE(8) | @@ -1117,14 +1117,14 @@ void init_pci(void) MCF_PCI_PCIICR_IAE; /* initiator abort enable */ #endif /* NOT_USED */ MCF_PCI_PCIICR = 0; /* this is what Linux does */ - + MCF_PCI_PCIGSCR |= MCF_PCI_PCIGSCR_SEE; /* system error interrupt enable */ /* Configure Initiator Windows */ /* initiator window 0 base / translation adress register */ MCF_PCI_PCIIW0BTAR = (PCI_MEMORY_OFFSET | (((PCI_MEMORY_SIZE - 1) >> 8) & 0xffff0000)) - | ((PCI_MEMORY_OFFSET >> 16) & 0xff00); + | ((PCI_MEMORY_OFFSET >> 16) & 0xff00); dbg("PCIIW0BTAR=0x%08x\r\n", MCF_PCI_PCIIW0BTAR); @@ -1216,4 +1216,4 @@ void pci_print_device_config(int32_t handle) } #endif /* DEBUG_PCI */ - + diff --git a/BaS_gcc/sys/driver_mem.c b/BaS_gcc/sys/driver_mem.c index 7a9f5bd..0b917b8 100644 --- a/BaS_gcc/sys/driver_mem.c +++ b/BaS_gcc/sys/driver_mem.c @@ -2,7 +2,7 @@ * driver_mem.c * * based from Emutos / BDOS - * + * * Copyright (c) 2001 Lineo, Inc. * * Authors: Karl T. Braun, Martin Doering, Laurent Vogel @@ -71,7 +71,7 @@ static MPB pmd; static void *xmgetblk(void) { int i; - + for (i = 0; i < MAXMD; i++) { if (tab_md[i].m_own == NULL) @@ -79,7 +79,7 @@ static void *xmgetblk(void) tab_md[i].m_own = (void*)1L; return(&tab_md[i]); } - } + } return NULL; } @@ -97,18 +97,18 @@ static MD *ffit(long amount, MPB *mp) MD *p, *q, *p1; /* free list is composed of MD's */ int maxflg; long maxval; - + if (amount != -1) { amount += 15; /* 16 bytes alignment */ amount &= 0xFFFFFFF0; } - + if ((q = mp->mp_rover) == 0) /* get rotating pointer */ { return 0; } - + maxval = 0; maxflg = ((amount == -1) ? true : false) ; p = q->m_link; /* start with next MD */ @@ -138,7 +138,7 @@ static MD *ffit(long amount, MPB *mp) { return(NULL); } - + /* init new MD */ p1->m_length = p->m_length - amount; p1->m_start = p->m_start + amount; @@ -147,7 +147,7 @@ static MD *ffit(long amount, MPB *mp) q->m_link = p1; } /* link allocate block into allocated list, - mark owner of block, & adjust rover */ + mark owner of block, & adjust rover */ p->m_link = mp->mp_mal; mp->mp_mal = p; mp->mp_rover = (q == (MD *) &mp->mp_mfl ? q->m_link : q); @@ -157,7 +157,7 @@ static MD *ffit(long amount, MPB *mp) maxval = p->m_length; p = ( q=p )->m_link; } while(q != mp->mp_rover); - + /* * return either the max, or 0 (error) */ @@ -179,7 +179,7 @@ static MD *ffit(long amount, MPB *mp) static void freeit(MD *m, MPB *mp) { MD *p, *q; - + q = 0; for (p = mp->mp_mfl; p ; p = (q = p) -> m_link) { @@ -189,7 +189,7 @@ static void freeit(MD *m, MPB *mp) } } m->m_link = p; - + if (q) { q->m_link = m; @@ -198,12 +198,12 @@ static void freeit(MD *m, MPB *mp) { mp->mp_mfl = m; } - + if (!mp->mp_rover) { mp->mp_rover = m; } - + if (p) { if (m->m_start + m->m_length == p->m_start) @@ -241,7 +241,7 @@ int32_t driver_mem_free(void *addr) MPB *mpb; mpb = &pmd; level = set_ipl(7); - + for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link)) { if ((long) addr == p->m_start) @@ -249,19 +249,19 @@ int32_t driver_mem_free(void *addr) break; } } - + if (!p) { set_ipl(level); return(-1); } - + *q = p->m_link; freeit(p, mpb); set_ipl(level); - + dbg("%s: driver_mem_free(0x%08X)\r\n", __FUNCTION__, addr); - + return(0); } @@ -270,33 +270,33 @@ void *driver_mem_alloc(uint32_t amount) void *ret = NULL; int level; MD *m; - + if (amount == -1L) { - return((void *)ffit(-1L, &pmd)); + return (void *) ffit(-1L, &pmd); } - + if (amount <= 0 ) { return(0); } - + if ((amount & 1)) { amount++; } - + level = set_ipl(7); m = ffit(amount, &pmd); - + if (m != NULL) { ret = (void *)m->m_start; } set_ipl(level); dbg("%s: driver_mem_alloc(%d) = 0x%08X\r\n", __FUNCTION__, amount, ret); - - return(ret); + + return ret; } static int use_count = 0; @@ -307,11 +307,11 @@ int driver_mem_init(void) { dbg("%s: initialise driver_mem_buffer[] at %p, size 0x%x\r\n", __FUNCTION__, driver_mem_buffer, DRIVER_MEM_BUFFER_SIZE); memset(driver_mem_buffer, 0, DRIVER_MEM_BUFFER_SIZE); - + pmd.mp_mfl = pmd.mp_rover = &tab_md[0]; tab_md[0].m_link = (MD *) NULL; tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15; - tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE; + tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE; tab_md[0].m_own = (void *) 1L; pmd.mp_mal = (MD *) NULL; memset(driver_mem_buffer, 0, tab_md[0].m_length); @@ -320,7 +320,8 @@ int driver_mem_init(void) } use_count++; dbg("%s: driver_mem now has a use count of %d\r\n", __FUNCTION__, use_count); - return(0); + + return 0; } void driver_mem_release(void) diff --git a/BaS_gcc/sys/sysinit.c b/BaS_gcc/sys/sysinit.c index ab130a6..755ff2e 100644 --- a/BaS_gcc/sys/sysinit.c +++ b/BaS_gcc/sys/sysinit.c @@ -55,7 +55,7 @@ #include "usb.h" #include "video.h" -#define DEBUG_SYSINIT +// #define DEBUG_SYSINIT #ifdef DEBUG_SYSINIT #define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) #else @@ -711,7 +711,7 @@ void init_usb(void) id = pci_read_config_longword(handle, PCIIDR); pci_class = pci_read_config_longword(handle, PCIREV); - dbg("compare class code %d to %d\r\n", PCI_CLASS_CODE(pci_class), PCI_CLASS_SERIAL_USB); + dbg("compare class code 0x%x to 0x%x\r\n", PCI_CLASS_CODE(pci_class), PCI_CLASS_SERIAL_USB); if (PCI_CLASS_CODE(pci_class) == PCI_CLASS_SERIAL_USB) { xprintf("serial USB found at bus=0x%x, dev=0x%x, fnc=0x%x (0x%x)\r\n", @@ -719,17 +719,17 @@ void init_usb(void) PCI_DEVICE_FROM_HANDLE(handle), PCI_FUNCTION_FROM_HANDLE(handle), handle); - dbg("compare %d against %d\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_EHCI); + dbg("compare subclass code 0x%x against 0x%x\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_EHCI); if (PCI_SUBCLASS(pci_class) == PCI_CLASS_SERIAL_USB_EHCI) { board = ehci_usb_pci_table; while (board->vendor) { - dbg("compare vendor id %d against %d\r\n", board->vendor, PCI_VENDOR_ID(id)); - dbg("compare device id %d against %d\r\n", board->device, PCI_DEVICE_ID(id)); + dbg("compare vendor id 0x%x against 0x%x\r\n", board->vendor, PCI_VENDOR_ID(id)); + dbg("compare device id 0x%x against 0x%x\r\n", board->device, PCI_DEVICE_ID(id)); if ((board->vendor == PCI_VENDOR_ID(id)) && board->device == PCI_DEVICE_ID(id)) { - dbg("match. trying to init board\r\n"); + dbg("match. trying to init board\r\n"); if (usb_init(handle, board) >= 0) { usb_found++; @@ -739,15 +739,15 @@ void init_usb(void) } } - dbg("compare %d against %d\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_OHCI); + dbg("compare subclass code 0x%x against 0x%x\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_OHCI); if (PCI_SUBCLASS(pci_class) == PCI_CLASS_SERIAL_USB_OHCI) { board = ohci_usb_pci_table; while (board->vendor) { - dbg("matched. compare vendor id %d against %d\r\n", board->vendor, PCI_VENDOR_ID(id)); - dbg("compare device id %d against %d\r\n", board->device, PCI_DEVICE_ID(id)); + dbg("matched. compare vendor id 0x%x against 0x%x\r\n", board->vendor, PCI_VENDOR_ID(id)); + dbg("compare device id 0x%x against 0x%x\r\n", board->device, PCI_DEVICE_ID(id)); if ((board->vendor == PCI_VENDOR_ID(id)) && board->device == PCI_DEVICE_ID(id)) { if (usb_init(handle, board) >= 0) @@ -758,6 +758,7 @@ void init_usb(void) } } } + dbg("PCI device handle = %x\r\n", handle); } while (handle >= 0); xprintf("finished (found %d USB controller(s))\r\n", usb_found); @@ -1239,10 +1240,8 @@ void initialize_hardware(void) init_pci(); video_init(); - /* do not try to init USB for now on the Firebee, it hangs the machine */ -//#ifndef MACHINE_FIREBEE + /* initialize USB devices */ init_usb(); -//#endif #if MACHINE_FIREBEE init_ac97(); diff --git a/BaS_gcc/usb/usb.c b/BaS_gcc/usb/usb.c index 4f750af..9c9a9de 100644 --- a/BaS_gcc/usb/usb.c +++ b/BaS_gcc/usb/usb.c @@ -76,7 +76,7 @@ struct hci { extern void udelay(long usec); -static struct usb_device *usb_dev; +static struct usb_device *usb_dev; static int bus_index; static int dev_index[USB_MAX_BUS]; static struct hci *controller_priv[USB_MAX_BUS]; @@ -89,9 +89,9 @@ char usb_error_str[256]; typedef struct { - int dest; - void (*func)(char); - char *loc; + int dest; + void (*func)(char); + char *loc; } PRINTK_INFO; #define DEST_CONSOLE (1) @@ -116,22 +116,26 @@ int usb_init(int32_t handle, const struct pci_device_id *ent) void *priv; int res = 0; if (bus_index >= USB_MAX_BUS) - return(-1); + return -1; + dev_index[bus_index] = 0; asynch_allowed = 1; + if (handle && (ent != NULL)) { if (driver_mem_init()) { usb_started = 0; - return -1; /* out of memoy */ + return -1; /* out of memory */ } + if (usb_dev == NULL) usb_dev = (struct usb_device *) driver_mem_alloc(sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE); + if (usb_dev == NULL) { usb_started = 0; - return -1; /* out of memoy */ + return -1; /* out of memory */ } } else /* restart */ @@ -149,10 +153,12 @@ int usb_init(int32_t handle, const struct pci_device_id *ent) } return res; } + usb_hub_reset(bus_index); /* init low_level USB */ debug_printf("USB: "); + switch(ent->class) { case PCI_CLASS_SERIAL_USB_UHCI: @@ -169,20 +175,25 @@ int usb_init(int32_t handle, const struct pci_device_id *ent) break; default: res = -1; break; } + if (!res) { /* if lowlevel init is OK, scan the bus for devices * i.e. search HUBs and configure them */ if (setup_packet == NULL) - setup_packet = (void *)driver_mem_alloc(sizeof(struct devrequest)); + setup_packet = (void *) driver_mem_alloc(sizeof(struct devrequest)); + if (setup_packet == NULL) { usb_started = 0; return -1; /* out of memoy */ } + xprintf("Scanning bus for devices... "); - controller_priv[bus_index] = (struct hci *)priv; + + controller_priv[bus_index] = (struct hci *) priv; controller_priv[bus_index]->usbnum = bus_index; + usb_scan_devices(priv); bus_index++; usb_started = 1; @@ -190,7 +201,7 @@ int usb_init(int32_t handle, const struct pci_device_id *ent) } else { - debug_printf("\r\nError, couldn't init Lowlevel part\r\n"); + xprintf("\r\nError, couldn't init Lowlevel part\r\n"); usb_started = 0; return -1; } @@ -855,7 +866,7 @@ void usb_disconnect(struct usb_device **pdev) dev->devnum = -1; } *pdev = NULL; - } + } } /* returns a pointer to the device with the index [index]. @@ -880,8 +891,8 @@ struct usb_device *usb_alloc_new_device(int bus_index, void *priv) { int i, index = dev_index[bus_index]; struct usb_device *dev; - - debug_printf("USB %d new device %d\r\n", bus_index, index); + + debug_printf("USB %d new device %d\r\n", bus_index, index); if (index >= USB_MAX_DEVICE) { debug_printf("ERROR, too many USB Devices, max=%d\r\n", USB_MAX_DEVICE); @@ -911,7 +922,7 @@ int usb_new_device(struct usb_device *dev) { int addr, err, tmp; unsigned char *tmpbuf; - + #ifndef CONFIG_LEGACY_USB_INIT_SEQ struct usb_device_descriptor *desc; int port = -1; @@ -925,7 +936,7 @@ int usb_new_device(struct usb_device *dev) /* We still haven't set the Address yet */ addr = dev->devnum; dev->devnum = 0; - + tmpbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); if (tmpbuf == NULL) { @@ -1076,6 +1087,7 @@ void usb_scan_devices(void *priv) { int i; struct usb_device *dev; + /* first make all devices unknown */ for (i = 0; i < USB_MAX_DEVICE; i++) { @@ -1083,7 +1095,7 @@ void usb_scan_devices(void *priv) usb_dev[(bus_index * USB_MAX_DEVICE) + i].devnum = -1; } dev_index[bus_index] = 0; - + /* device 0 is always present (root hub, so let it analyze) */ dev = usb_alloc_new_device(bus_index, priv); if (usb_new_device(dev)) @@ -1097,17 +1109,17 @@ void usb_scan_devices(void *priv) xprintf("%d USB Device(s) found\r\n", dev_index[bus_index]); } { +#ifdef _NOT_USED_ /* not implemented yet */ /* insert "driver" if possible */ -#ifdef _NOT_USED_ if (drv_usb_kbd_init() < 0) - debug_printf("No USB keyboard found\r\n"); + xprintf("No USB keyboard found\r\n"); else - debug_printf("USB HID keyboard driver installed\r\n"); + xprintf("USB HID keyboard driver installed\r\n"); #endif /* _NOT_USED */ if (drv_usb_mouse_init() < 0) - debug_printf("No USB mouse found\r\n"); + xprintf("No USB mouse found\r\n"); else - debug_printf("USB HID mouse driver installed\r\n"); + xprintf("USB HID mouse driver installed\r\n"); } xprintf("Scan end\r\n"); } @@ -1168,7 +1180,7 @@ static void usb_hub_power_on(struct usb_hub_device *hub) { int i; struct usb_device *dev; - + dev = hub->pusb_dev; /* Enable power to the ports */ dbg_hub("enabling power on all ports\r\n"); @@ -1210,9 +1222,9 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port int tries; struct usb_port_status portsts; unsigned short portstatus, portchange; - + dbg_hub("hub_port_reset: resetting port %d...\r\n", port + 1); - + for (tries = 0; tries < MAX_TRIES; tries++) { usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET); @@ -1234,10 +1246,10 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0, (portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0, (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0); - + if ((portchange & USB_PORT_STAT_C_CONNECTION) || !(portstatus & USB_PORT_STAT_CONNECTION)) return -1; - + if (portstatus & USB_PORT_STAT_ENABLE) break; @@ -1314,10 +1326,10 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port) else #endif wait(2000); - + /* Allocate a new device struct for it */ usb = usb_alloc_new_device(dev->usbnum, dev->priv_hcd); - + if (portstatus & USB_PORT_STAT_HIGH_SPEED) usb->speed = USB_SPEED_HIGH; else if (portstatus & USB_PORT_STAT_LOW_SPEED) @@ -1327,7 +1339,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port) dbg_hub("%s: usb=%p\r\n", __FUNCTION__, usb); dev->children[port] = usb; usb->parent = dev; - + /* Run it through the hoops (find a driver, etc) */ if (usb_new_device(usb)) { @@ -1335,7 +1347,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port) dbg_hub("USB %d hub: disabling port %d\r\n", dev->usbnum, port + 1); usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE); } - + #ifdef USB_POLL_HUB else if (pxCurrentTCB != NULL) { @@ -1357,12 +1369,12 @@ static void usb_hub_events(struct usb_device *dev) int i; struct usb_hub_device *hub = dev->hub; if (hub == NULL) - return; + return; for (i = 0; i < dev->maxchild; i++) { struct usb_port_status portsts; unsigned short portstatus, portchange; - + if (usb_get_port_status(dev, i + 1, &portsts) < 0) { dbg_hub("get_port_status failed\r\n"); @@ -1412,7 +1424,7 @@ static void usb_hub_events(struct usb_device *dev) void usb_poll_hub_task(void *pvParameters) { int index_bus = 0; - portTickType timeout = configTICK_RATE_HZ/10; + portTickType timeout = configTICK_RATE_HZ/10; if (pvParameters); while(1) { @@ -1439,7 +1451,7 @@ void usb_poll_hub_task(void *pvParameters) for (i = 0; i < USB_MAX_BUS ; i++) { if (controller_priv[i] != NULL) - usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]); + usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]); } #ifdef CONFIG_USB_INTERRUPT_POLLING *vblsem = 1; @@ -1475,7 +1487,7 @@ int usb_hub_configure(struct usb_device *dev) driver_mem_free(buffer); return -1; } - dbg_hub("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); + dbg_hub("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); descriptor = (struct usb_hub_descriptor *)buffer; /* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */ i = descriptor->bLength; @@ -1575,7 +1587,7 @@ int usb_hub_configure(struct usb_device *dev) if (xTaskCreate(usb_poll_hub_task, (void *)"USBHub", configMINIMAL_STACK_SIZE, NULL, 16, NULL) != pdPASS) { vQueueDelete(queue_poll_hub); - queue_poll_hub = NULL; + queue_poll_hub = NULL; } } vTaskDelay(configTICK_RATE_HZ);