printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / mainboard / tyan / s2895 / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <device/pci.h>
4 #include <string.h>
5 #include <stdint.h>
6
7 #include <cpu/amd/amdk8_sysconf.h>
8
9 extern  unsigned char bus_isa;
10 extern  unsigned char bus_ck804_0; //1
11 extern  unsigned char bus_ck804_1; //2
12 extern  unsigned char bus_ck804_2; //3
13 extern  unsigned char bus_ck804_3; //4
14 extern  unsigned char bus_ck804_4; //5
15 extern  unsigned char bus_ck804_5; //6
16 extern  unsigned char bus_8131_0;  //7
17 extern  unsigned char bus_8131_1;  //8
18 extern  unsigned char bus_8131_2;  //9
19 extern  unsigned char bus_ck804b_0;//a
20 extern  unsigned char bus_ck804b_1;//b
21 extern  unsigned char bus_ck804b_2;//c
22 extern  unsigned char bus_ck804b_3;//d
23 extern  unsigned char bus_ck804b_4;//e
24 extern  unsigned char bus_ck804b_5;//f
25 extern  unsigned apicid_ck804;
26 extern  unsigned apicid_8131_1;
27 extern  unsigned apicid_8131_2;
28 extern  unsigned apicid_ck804b;
29
30 extern  unsigned sbdn3;
31 extern  unsigned sbdnb;
32
33 extern void get_bus_conf(void);
34
35 static void *smp_write_config_table(void *v)
36 {
37         static const char sig[4] = "PCMP";
38         static const char oem[8] = "TYAN    ";
39         static const char productid[12] = "S2895       ";
40         struct mp_config_table *mc;
41         unsigned sbdn;
42
43         unsigned char bus_num;
44         int i;
45
46         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
47         memset(mc, 0, sizeof(*mc));
48
49         memcpy(mc->mpc_signature, sig, sizeof(sig));
50         mc->mpc_length = sizeof(*mc); /* initially just the header */
51         mc->mpc_spec = 0x04;
52         mc->mpc_checksum = 0; /* not yet computed */
53         memcpy(mc->mpc_oem, oem, sizeof(oem));
54         memcpy(mc->mpc_productid, productid, sizeof(productid));
55         mc->mpc_oemptr = 0;
56         mc->mpc_oemsize = 0;
57         mc->mpc_entry_count = 0; /* No entries yet... */
58         mc->mpc_lapic = LAPIC_ADDR;
59         mc->mpe_length = 0;
60         mc->mpe_checksum = 0;
61         mc->reserved = 0;
62
63         smp_write_processors(mc);
64
65         get_bus_conf();
66         sbdn = sysconf.sbdn;
67
68 /*Bus:          Bus ID  Type*/
69        /* define bus and isa numbers */
70         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
71                 smp_write_bus(mc, bus_num, "PCI   ");
72         }
73         smp_write_bus(mc, bus_isa, "ISA   ");
74
75 /*I/O APICs:    APIC ID Version State           Address*/
76         {
77                 device_t dev;
78                 struct resource *res;
79                 uint32_t dword;
80
81                 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn+ 0x1,0));
82                 if (dev) {
83                         res = find_resource(dev, PCI_BASE_ADDRESS_1);
84                         if (res) {
85                                 smp_write_ioapic(mc, apicid_ck804, 0x11, res->base);
86                         }
87
88         /* Initialize interrupt mapping*/
89
90                         dword = 0x0120d218;
91                         pci_write_config32(dev, 0x7c, dword);
92
93                         dword = 0x12008a00;
94                         pci_write_config32(dev, 0x80, dword);
95
96                         dword = 0x00080d7d;
97                         pci_write_config32(dev, 0x84, dword);
98
99                 }
100
101                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,1));
102                 if (dev) {
103                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
104                         if (res) {
105                                 smp_write_ioapic(mc, apicid_8131_1, 0x11, res->base);
106                         }
107                 }
108                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,1));
109                 if (dev) {
110                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
111                         if (res) {
112                                 smp_write_ioapic(mc, apicid_8131_2, 0x11, res->base);
113                         }
114                 }
115
116             if(sysconf.pci1234[2] & 0xf) {
117                 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x1,0));
118                 if (dev) {
119                         res = find_resource(dev, PCI_BASE_ADDRESS_1);
120                         if (res) {
121                                 smp_write_ioapic(mc, apicid_ck804b, 0x11, res->base);
122                         }
123
124                         dword = 0x0000d218; // Why does the factory BIOS have 0?
125                         pci_write_config32(dev, 0x7c, dword);
126
127                         dword = 0x00000000;
128                         pci_write_config32(dev, 0x80, dword);
129
130                         dword = 0x00000d00; // Same here.
131                         pci_write_config32(dev, 0x84, dword);
132
133                 }
134             }
135
136         }
137
138 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#
139 */      smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, apicid_ck804, 0x0);
140         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x1, apicid_ck804, 0x1);
141         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x0, apicid_ck804, 0x2);
142         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x3, apicid_ck804, 0x3);
143         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x4, apicid_ck804, 0x4);
144         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x6, apicid_ck804, 0x6);
145         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x7, apicid_ck804, 0x7);
146         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x8, apicid_ck804, 0x8);
147         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xc, apicid_ck804, 0xc);
148         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xd, apicid_ck804, 0xd);
149         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xe, apicid_ck804, 0xe);
150         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xf, apicid_ck804, 0xf);
151
152 // Onboard ck804 smbus
153         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+1)<<2)|1, apicid_ck804, 0xa);
154 // 10
155
156 // Onboard ck804 USB 1.1
157         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+2)<<2)|0, apicid_ck804, 0x15); // 21
158
159 // Onboard ck804 USB 2
160         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+2)<<2)|1, apicid_ck804, 0x14); // 20
161
162 // Onboard ck804 Audio
163         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+4)<<2)|0, apicid_ck804, 0x14); // 20
164
165 // Onboard ck804 SATA 0
166         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn +7)<<2)|0, apicid_ck804, 0x17); // 23
167
168 // Onboard ck804 SATA 1
169         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn +8)<<2)|0, apicid_ck804, 0x16); // 22
170
171 // Onboard ck804 NIC
172         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn +0x0a)<<2)|0, apicid_ck804, 0x15); // 21
173
174 //Slot PCIE x16
175         for(i=0;i<4;i++) {
176                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_5, (0x00<<2)|i, apicid_ck804, 0x10 + (2+i+4-sbdn%4)%4);
177         }
178
179 //Onboard Firewire
180         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_1, (0x05<<2)|0, apicid_ck804, 0x13); // 19
181
182 //Slot 2 PCI 32
183         for(i=0;i<4;i++) {
184                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_1, (0x04<<2)|i, apicid_ck804, 0x10 + (0+i)%4); //16
185         }
186
187         if(sysconf.pci1234[2] & 0xf) {
188 //Onboard ck804b NIC
189         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804b_0, ((sbdnb+0x0a)<<2)|0, apicid_ck804b, 0x15);//24+4+4+21=53
190
191 //Slot 3 PCIE x16
192         for(i=0;i<4;i++) {
193                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804b_5, (0x00<<2)|i, apicid_ck804b, 0x10 + (2+i+4-sbdnb%4)%4);
194         }
195         }
196
197 //Channel B of 8131
198
199 //Slot 4 PCI-X 100/66
200         for(i=0;i<4;i++) {
201                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (4<<2)|i, apicid_8131_2, (0+i)%4);
202         }
203
204 //Slot 5 PCIX 100/66
205         for(i=0;i<4;i++) {
206                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (9<<2)|i, apicid_8131_2, (1+i)%4); // 29
207         }
208
209 //OnBoard LSI SCSI
210         for(i=0;i<2;i++) {
211                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|i, apicid_8131_2, (2+i)%4); //30
212         }
213
214 //Channel A of 8131
215
216 //Slot 6 PCIX 133/100/66
217         for(i=0;i<4;i++) {
218                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (4<<2)|i, apicid_8131_1, (0+i)%4); //24
219         }
220
221 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
222         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
223         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
224         /* There is no extension information... */
225
226         /* Compute the checksums */
227         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
228         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
229         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
230                 mc, smp_next_mpe_entry(mc));
231         return smp_next_mpe_entry(mc);
232 }
233
234 unsigned long write_smp_table(unsigned long addr)
235 {
236         void *v;
237         v = smp_write_floating_table(addr);
238         return (unsigned long)smp_write_config_table(v);
239 }