Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-30
[coreboot.git] / src / northbridge / amd / amdk8 / early_ht.c
1 static int enumerate_ht_chain(void)
2 {
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.
7          */
8         unsigned next_unitid, last_unitid;
9         int reset_needed = 0;
10
11         next_unitid = 1;
12         do {
13                 uint32_t id;
14                 uint8_t hdr_type, pos;
15                 last_unitid = next_unitid;
16
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)) {
22                         break;
23                 }
24
25 #if CK804_DEVN_BASE==0 
26                 //CK804 workaround: 
27                 // CK804 UnitID changes not use
28                 if(id == 0x005e10de) {
29                         break;
30                 }
31 #endif
32
33                 hdr_type = pci_read_config8(PCI_DEV(0,0,0), PCI_HEADER_TYPE);
34                 pos = 0;
35                 hdr_type &= 0x7f;
36
37                 if ((hdr_type == PCI_HEADER_TYPE_NORMAL) ||
38                     (hdr_type == PCI_HEADER_TYPE_BRIDGE)) {
39                         pos = pci_read_config8(PCI_DEV(0,0,0), PCI_CAPABILITY_LIST);
40                 }
41                 while(pos != 0) {
42                         uint8_t cap;
43                         cap = pci_read_config8(PCI_DEV(0,0,0), pos + PCI_CAP_LIST_ID);
44                         if (cap == PCI_CAP_ID_HT) {
45                                 uint16_t flags;
46                                 flags = pci_read_config16(PCI_DEV(0,0,0), pos + PCI_CAP_FLAGS);
47                                 if ((flags >> 13) == 0) {
48                                         unsigned count;
49
50                                         flags &= ~0x1f;
51                                         flags |= next_unitid & 0x1f;
52                                         count = (flags >> 5) & 0x1f;
53                                         
54                                         pci_write_config16(PCI_DEV(0, 0, 0), pos + PCI_CAP_FLAGS, flags);
55
56                                         next_unitid += count;
57                                         break;
58                                 }
59                         }
60                         pos = pci_read_config8(PCI_DEV(0, 0, 0), pos + PCI_CAP_LIST_NEXT);
61                 }
62         } while((last_unitid != next_unitid) && (next_unitid <= 0x1f));  
63         
64
65         return reset_needed;
66 }
67