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