1 static int enumerate_ht_chain(void)
3 /* Assumption the HT chain that is bus 0 has the HT I/O Hub on it.
4 * On most boards this just happens. If a cpu has multiple
5 * non Coherent links the appropriate bus registers for the
6 * links needs to be programed to point at bus 0.
8 unsigned next_unitid, last_unitid;
14 uint8_t hdr_type, pos;
15 last_unitid = next_unitid;
17 id = pci_read_config32(PCI_DEV(0,0,0), PCI_VENDOR_ID);
18 /* If the chain is enumerated quit */
19 if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
20 (((id >> 16) & 0xffff) == 0xffff) ||
21 (((id >> 16) & 0xffff) == 0x0000))
26 hdr_type = pci_read_config8(PCI_DEV(0,0,0), PCI_HEADER_TYPE);
30 if ((hdr_type == PCI_HEADER_TYPE_NORMAL) ||
31 (hdr_type == PCI_HEADER_TYPE_BRIDGE))
33 pos = pci_read_config8(PCI_DEV(0,0,0), PCI_CAPABILITY_LIST);
37 cap = pci_read_config8(PCI_DEV(0,0,0), pos + PCI_CAP_LIST_ID);
38 if (cap == PCI_CAP_ID_HT) {
40 /* Read and write and reread flags so the link
41 * direction bit is valid.
43 flags = pci_read_config16(PCI_DEV(0,0,0), pos + PCI_CAP_FLAGS);
44 pci_write_config16(PCI_DEV(0,0,0), pos + PCI_CAP_FLAGS, flags);
45 flags = pci_read_config16(PCI_DEV(0,0,0), pos + PCI_CAP_FLAGS);
46 if ((flags >> 13) == 0) {
48 unsigned ctrl, ctrl_off;
51 flags |= next_unitid & 0x1f;
52 count = (flags >> 5) & 0x1f;
55 /* Test for end of chain */
56 ctrl_off = ((flags >> 10) & 1)?
57 PCI_HT_CAP_SLAVE_CTRL1 : PCI_HT_CAP_SLAVE_CTRL0;
58 ctrl = pci_read_config16(PCI_DEV(0,0,0), pos + ctrl_off);
59 /* Is this the end of the hypertransport chain.
60 * or has the link failed?
62 if (ctrl & ((1 << 6)|(1 << 4))) {
66 pci_write_config16(PCI_DEV(0, 0, 0), pos + PCI_CAP_FLAGS, flags);
70 pos = pci_read_config8(PCI_DEV(0, 0, 0), pos + PCI_CAP_LIST_NEXT);
72 } while((last_unitid != next_unitid) && (next_unitid <= 0x1f));