82de11317b71d76d1bef6b480ff99ba2d3837ea2
[coreboot.git] / src / mainboard / tyan / s2881 / 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/dualcore.h>
8 #endif
9
10 #include <cpu/amd/amdk8_sysconf.h>
11
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 = 5 ;
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 apicid_8111 ;
22 unsigned apicid_8131_1;
23 unsigned apicid_8131_2;
24
25 unsigned pci1234x[] = 
26 {        //Here you only need to set value in pci1234 for HT-IO that could be installed or not
27          //You may need to preset pci1234 for HTIO board, please refer to src/northbridge/amd/amdk8/get_sblk_pci1234.c for detail
28         0x0000ff0,
29 //        0x0000ff0,
30 //        0x0000ff0,
31 //        0x0000ff0,
32 //        0x0000ff0,
33 //        0x0000ff0,
34 //        0x0000ff0,
35 //        0x0000ff0
36 };
37 unsigned hcdnx[] = 
38 { //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
39         0x20202020,
40 //      0x20202020,
41 //        0x20202020,
42 //        0x20202020,
43 //        0x20202020,
44 //        0x20202020,
45 //        0x20202020,
46 //        0x20202020,
47 };
48 unsigned sbdn3;
49
50 extern void get_sblk_pci1234(void);
51
52 static unsigned get_bus_conf_done = 0;
53
54 void get_bus_conf(void)
55 {
56
57         unsigned apicid_base;
58
59         device_t dev;
60         int i;
61
62         if(get_bus_conf_done==1) return; //do it only once
63
64         get_bus_conf_done = 1;
65
66         sysconf.hc_possible_num = sizeof(pci1234x)/sizeof(pci1234x[0]);
67         for(i=0;i<sysconf.hc_possible_num; i++) {
68                 sysconf.pci1234[i] = pci1234x[i];
69                 sysconf.hcdn[i] = hcdnx[i];
70         }
71
72         get_sblk_pci1234();
73         
74         sysconf.sbdn = (sysconf.hcdn[0] >> 8) & 0xff;
75         sbdn3 = sysconf.hcdn[0] & 0xff;
76
77         bus_8131_0 = (sysconf.pci1234[0] >> 16) & 0xff;
78         bus_8111_0 = bus_8131_0;
79
80                 /* 8111 */
81         dev = dev_find_slot(bus_8111_0, PCI_DEVFN(sysconf.sbdn,0));
82         if (dev) {
83                 bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
84 #if HT_CHAIN_END_UNITID_BASE >= HT_CHAIN_UNITID_BASE
85                 bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
86                 bus_isa++;
87 //              printk_debug("bus_isa=%d\n",bus_isa);
88 #endif
89         }
90         else {
91                 printk_debug("ERROR - could not find PCI %02x:03.0, using defaults\n", bus_8111_0);
92         }
93
94         /* 8131-1 */
95         dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,0));
96         if (dev) {
97                 bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
98         }
99         else {
100                 printk_debug("ERROR - could not find PCI %02x:01.0, using defaults\n", bus_8131_0);
101         }
102
103         /* 8132-2 */
104         dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,0));
105         if (dev) {
106                 bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
107 #if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE
108                 bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
109                 bus_isa++;
110 //              printk_debug("bus_isa=%d\n",bus_isa);
111 #endif
112         }
113         else {
114                 printk_debug("ERROR - could not find PCI %02x:02.0, using defaults\n", bus_8131_0);
115         }
116
117
118 /*I/O APICs:    APIC ID Version State           Address*/
119 #if CONFIG_LOGICAL_CPUS==1
120         apicid_base = get_apicid_base(3);
121 #else 
122         apicid_base = CONFIG_MAX_PHYSICAL_CPUS; 
123 #endif
124         apicid_8111 = apicid_base+0;
125         apicid_8131_1 = apicid_base+1;
126         apicid_8131_2 = apicid_base+2;
127 }