diff --git a/BaS_gcc/include/pci.h b/BaS_gcc/include/pci.h index 1671c6f..69a18da 100644 --- a/BaS_gcc/include/pci.h +++ b/BaS_gcc/include/pci.h @@ -21,6 +21,8 @@ * Author: Markus Fröschle */ +#include + #define PCI_MEMORY_OFFSET (0x80000000) #define PCI_MEMORY_SIZE (0x40000000) /* 1 GByte PCI memory window */ #define PCI_IO_OFFSET (0xD0000000) @@ -197,4 +199,7 @@ extern void init_eport(void); extern void init_xlbus_arbiter(void); extern void init_pci(void); +extern int pci_find_device(uint16_t device_id, uint16_t vendor_id, int index); + + #endif /* _PCI_H_ */ diff --git a/BaS_gcc/sources/ohci-hcd.c b/BaS_gcc/sources/ohci-hcd.c index 717dfa8..06c3d3d 100644 --- a/BaS_gcc/sources/ohci-hcd.c +++ b/BaS_gcc/sources/ohci-hcd.c @@ -1522,12 +1522,8 @@ static int hc_reset(ohci_t *ohci) long handle; do { -#ifdef PCI_XBIOS - handle = find_pci_device(0x0000FFFFL, index++); -#else - handle = Find_pci_device(0x0000FFFFL, index++); -#endif - if(handle >= 0) + handle = pci_find_device(0x0, 0xffff, index++) + if (handle >= 0) { unsigned long id = 0; #ifdef PCI_XBIOS diff --git a/BaS_gcc/sources/pci.c b/BaS_gcc/sources/pci.c index 956adbd..831816f 100644 --- a/BaS_gcc/sources/pci.c +++ b/BaS_gcc/sources/pci.c @@ -101,14 +101,6 @@ uint32_t pci_read_config_longword(uint16_t bus, uint16_t slot, uint16_t function wait(1000); value = * (volatile uint32_t *) PCI_IO_OFFSET; /* access device */ -#ifdef _NOT_USED_ - /* finish config cycle */ - - MCF_PCI_PCICAR = MCF_PCI_PCICAR_DEVNUM(10) | - MCF_PCI_PCICAR_FUNCNUM(function) | - MCF_PCI_PCICAR_DWORD(0); -#endif /* _NOT_USED_ */ - swpl(value); //xprintf("PCISCR after config cycle: %lx\r\n", MCF_PCI_PCISCR); @@ -157,16 +149,46 @@ void pci_write_config_longword(uint16_t bus, uint16_t slot, uint16_t function, u wait(1000); swpl(value); * (volatile uint32_t *) PCI_IO_OFFSET = value; /* access device */ - -#ifdef _NOT_USED_ - /* finish config cycle */ - - MCF_PCI_PCICAR = MCF_PCI_PCICAR_DEVNUM(10) | - MCF_PCI_PCICAR_FUNCNUM(function) | - MCF_PCI_PCICAR_DWORD(0); -#endif /* _NOT_USED_ */ } +int pci_find_device(uint16_t device_id, uint16_t vendor_id, int index) +{ + uint16_t bus; + uint16_t slot; + uint16_t function; + uint16_t pos = 0; + int handle; + + for (bus = 0; bus < 1; bus++) + { + for (slot = 0; slot < 32; slot++) + { + for (function = 0; function < 8; function++) + { + uint32_t value; + + value = pci_read_config_longword(bus, slot, function, 0); + handle = bus << 16 | slot << 8 | function; + if (value != 0xffffffff) /* we have a device at this position */ + { + if (vendor_id == 0xffff) /* ignore vendor id */ + { + return handle; + } + else if (PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id) + { + if (pos == index) + return handle; + pos++; + } + } + } + } + } + return PCI_DEVICE_NOT_FOUND; +} + + static uint32_t mem_address = PCI_MEMORY_OFFSET; static uint32_t io_address = PCI_IO_OFFSET;