(nearly) fixed pci_find_device()

This commit is contained in:
Markus Fröschle
2013-11-07 07:45:54 +00:00
parent 6707428b92
commit 967ba02f67

View File

@@ -111,6 +111,7 @@ uint32_t pci_read_config_longword(uint16_t handle, uint16_t offset)
uint16_t device = PCI_DEVICE_FROM_HANDLE(handle); uint16_t device = PCI_DEVICE_FROM_HANDLE(handle);
uint16_t function = PCI_FUNCTION_FROM_HANDLE(handle); uint16_t function = PCI_FUNCTION_FROM_HANDLE(handle);
#ifdef _NOT_USED_
/* clear PCI status/command register */ /* clear PCI status/command register */
MCF_PCI_PCISCR = MCF_PCI_PCISCR_PE | /* clear parity error bit */ MCF_PCI_PCISCR = MCF_PCI_PCISCR_PE | /* clear parity error bit */
MCF_PCI_PCISCR_SE | /* clear system error */ MCF_PCI_PCISCR_SE | /* clear system error */
@@ -118,6 +119,7 @@ uint32_t pci_read_config_longword(uint16_t handle, uint16_t offset)
MCF_PCI_PCISCR_TR | /* clear target abort */ MCF_PCI_PCISCR_TR | /* clear target abort */
MCF_PCI_PCISCR_TS | /* clear target abort signalling (as target) */ MCF_PCI_PCISCR_TS | /* clear target abort signalling (as target) */
MCF_PCI_PCISCR_DP; /* clear parity error */ MCF_PCI_PCISCR_DP; /* clear parity error */
#endif /* _NOT_USED_ */
/* initiate PCI configuration access to device */ /* initiate PCI configuration access to device */
@@ -136,16 +138,17 @@ uint16_t pci_read_config_word(uint16_t handle, uint16_t offset)
{ {
uint32_t value; uint32_t value;
value = pci_read_config_longword(handle, offset / 2); value = pci_read_config_longword(handle, offset);
return((value >> (1 - offset % 2) * 8) & 0xffff); return value >> ((1 - offset % 2) * 16) & 0xffff;
} }
uint8_t pci_read_config_byte(uint16_t handle, uint16_t offset) uint8_t pci_read_config_byte(uint16_t handle, uint16_t offset)
{ {
uint32_t value; uint32_t value;
value = pci_read_config_longword(handle, offset / 4); value = pci_read_config_longword(handle, offset);
return ((value >> (3 - offset % 4) * 8) & 0xff); //xprintf("pci_read_config_longword(0x%x, 0x%x) = 0x%04x\r\n", handle, offset, value);
return value >> ((3 - offset % 4) * 8) & 0xff;
} }
/* /*
@@ -203,13 +206,13 @@ int16_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index)
{ {
uint16_t bus; uint16_t bus;
uint16_t device; uint16_t device;
uint16_t function; uint16_t function = 0;
uint16_t pos = 0; uint16_t pos = 0;
int handle; int handle;
for (bus = 0; bus < 255; bus++) for (bus = 0; bus < 255; bus++)
{ {
for (device = 0; device < 32; device++) for (device = 10; device < 32; device++)
{ {
uint32_t value; uint32_t value;
uint8_t htr; uint8_t htr;
@@ -218,27 +221,23 @@ int16_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index)
value = pci_read_config_longword(handle, PCIIDR); value = pci_read_config_longword(handle, PCIIDR);
if (value != 0xffffffff) /* we have a device at this position */ if (value != 0xffffffff) /* we have a device at this position */
{ {
if (vendor_id == 0xffff || (PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id)) if (vendor_id == 0xffff ||
(PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id))
{ {
if (pos == index) if (pos == index)
{ {
return handle; return handle;
} }
else }
if (pci_read_config_byte(handle, PCIHTR) & 0x80)
{ {
/* we found a match, but at wrong position */
pos++;
continue;
}
}
/* check if we have a multi-function device at this position */ /* check if we have a multi-function device at this position */
htr = pci_read_config_byte(handle, PCIHTR); htr = pci_read_config_byte(handle, PCIHTR);
xprintf("bus = %02x, dev = %02x, func = %02x PCIHTR=%02x\r\n", bus, device, function, htr);
if (htr & 0x80) /* multi-function device found */
{
for (function = 1; function < 8; function++) for (function = 1; function < 8; function++)
{ {
pos++;
handle = PCI_HANDLE(bus, device, function); handle = PCI_HANDLE(bus, device, function);
value = pci_read_config_longword(handle, PCIIDR); value = pci_read_config_longword(handle, PCIIDR);
if (value != 0xFFFFFFFF) /* device found */ if (value != 0xFFFFFFFF) /* device found */
@@ -252,14 +251,14 @@ int16_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index)
} }
else else
{ {
/* found a match, but at wrong position */ //pos++;
}
}
}
}
}
/* we found a match, but at wrong position */
pos++; pos++;
continue;
}
}
}
}
}
} }
} }
} }
@@ -411,12 +410,13 @@ void pci_scan(void)
uint32_t value; uint32_t value;
value = pci_read_config_longword(handle, PCIIDR); value = pci_read_config_longword(handle, PCIIDR);
xprintf(" %02x | %02x | %02x |%04x|%04x| %s\r\n", xprintf(" %02x | %02x | %02x |%04x|%04x| %s (0x%02x)\r\n",
PCI_BUS_FROM_HANDLE(handle), PCI_BUS_FROM_HANDLE(handle),
PCI_DEVICE_FROM_HANDLE(handle), PCI_DEVICE_FROM_HANDLE(handle),
PCI_FUNCTION_FROM_HANDLE(handle), PCI_FUNCTION_FROM_HANDLE(handle),
PCI_VENDOR_ID(value), PCI_DEVICE_ID(value), PCI_VENDOR_ID(value), PCI_DEVICE_ID(value),
device_class(pci_read_config_byte(handle, PCICCR))); device_class(pci_read_config_byte(handle, PCICCR)),
pci_read_config_byte(handle, PCICCR));
if (PCI_VENDOR_ID(value) != 0x1057 && PCI_DEVICE_ID(value) != 0x5806) /* do not configure bridge */ if (PCI_VENDOR_ID(value) != 0x1057 && PCI_DEVICE_ID(value) != 0x5806) /* do not configure bridge */
{ {