Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / mainboard / tyan / s2885 / get_bus_conf.c
1 #include <console/console.h>
2 #include <device/pci.h>
3 #include <device/pci_ids.h>
4 #include <string.h>
5 #include <stdint.h>
6 #if CONFIG_LOGICAL_CPUS==1
7 #include <cpu/amd/multicore.h>
8 #endif
9
10 #include <cpu/amd/amdk8_sysconf.h>
11 #include <stdlib.h>
12
13 // Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables
14 //busnum is default
15 unsigned char bus_isa = 7 ;
16 unsigned char bus_8131_0 = 1;
17 unsigned char bus_8131_1 = 2;
18 unsigned char bus_8131_2 = 3;
19 unsigned char bus_8111_0 = 1;
20 unsigned char bus_8111_1 = 4;
21 unsigned char bus_8151_0 = 5;
22 unsigned char bus_8151_1 = 6;
23 unsigned apicid_8111 ;
24 unsigned apicid_8131_1;
25 unsigned apicid_8131_2;
26
27 unsigned pci1234x[] =
28 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
29          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
30         0x0000ff0,
31         0x0000ff0,
32 //        0x0000ff0,
33 //        0x0000ff0,
34 //        0x0000ff0,
35 //        0x0000ff0,
36 //        0x0000ff0,
37 //        0x0000ff0
38 };
39 unsigned hcdnx[] =
40 { //HT Chain device num, actually it is unit id base of every ht device in chain, assume every chain only have 4 ht device at most
41         0x20202020,
42         0x20202020,
43 //        0x20202020,
44 //        0x20202020,
45 //        0x20202020,
46 //        0x20202020,
47 //        0x20202020,
48 //        0x20202020,
49 };
50 unsigned sbdn3;
51 unsigned sbdn5;
52
53
54
55 static unsigned get_bus_conf_done = 0;
56
57 void get_bus_conf(void)
58 {
59
60         unsigned apicid_base;
61
62         device_t dev;
63         int i;
64
65         if(get_bus_conf_done==1) return; //do it only once
66
67         get_bus_conf_done = 1;
68
69         sysconf.hc_possible_num = ARRAY_SIZE(pci1234x);
70         for(i=0;i<sysconf.hc_possible_num; i++) {
71                 sysconf.pci1234[i] = pci1234x[i];
72                 sysconf.hcdn[i] = hcdnx[i];
73         }
74
75         get_sblk_pci1234();
76
77         sysconf.sbdn = (sysconf.hcdn[0] >> 8) & 0xff;
78         sbdn3 = sysconf.hcdn[0] & 0xff;
79         sbdn5 = sysconf.hcdn[1] & 0xff;
80
81         bus_8131_0 = (sysconf.pci1234[0] >> 16) & 0xff;
82         bus_8111_0 = bus_8131_0;
83
84                 /* 8111 */
85         dev = dev_find_slot(bus_8111_0, PCI_DEVFN(sysconf.sbdn,0));
86         if (dev) {
87                 bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
88 #if CONFIG_HT_CHAIN_END_UNITID_BASE >= CONFIG_HT_CHAIN_UNITID_BASE
89                 bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
90                 bus_isa++;
91 //              printk(BIOS_DEBUG, "bus_isa=%d\n",bus_isa);
92 #endif
93         }
94         else {
95                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:03.0, using defaults\n", bus_8111_0);
96         }
97
98         /* 8131-1 */
99         dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
100         if (dev) {
101                 bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
102         }
103         else {
104                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:01.0, using defaults\n", bus_8131_0);
105         }
106
107         /* 8132-2 */
108         dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,0));
109         if (dev) {
110                 bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
111 #if CONFIG_HT_CHAIN_END_UNITID_BASE < CONFIG_HT_CHAIN_UNITID_BASE
112                 bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
113                 bus_isa++;
114 //              printk(BIOS_DEBUG, "bus_isa=%d\n",bus_isa);
115 #endif
116
117         }
118         else {
119                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:02.0, using defaults\n", bus_8131_0);
120         }
121
122         /* HT chain 1 */
123         // it is on node0, so it must be there
124         bus_8151_0 = (sysconf.pci1234[1] >> 16) & 0xff;
125         /* 8151 */
126         dev = dev_find_slot(bus_8151_0, PCI_DEVFN(sbdn5+1, 0));
127
128         if (dev) {
129                 bus_8151_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
130 //              printk(BIOS_DEBUG, "bus_8151_1=%d\n",bus_8151_1);
131                 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
132                 bus_isa++;
133         }
134
135 /*I/O APICs:    APIC ID Version State           Address*/
136 #if CONFIG_LOGICAL_CPUS==1
137         apicid_base = get_apicid_base(3);
138 #else
139         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
140 #endif
141         apicid_8111 = apicid_base+0;
142         apicid_8131_1 = apicid_base+1;
143         apicid_8131_2 = apicid_base+2;
144 }