Factor out common mptable code to mptable_init().
[coreboot.git] / src / mainboard / tyan / s2885 / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/ioapic.h>
4 #include <device/pci.h>
5 #include <string.h>
6 #include <stdint.h>
7 #include <cpu/amd/amdk8_sysconf.h>
8
9 extern  unsigned char bus_isa;
10 extern  unsigned char bus_8131_0;
11 extern  unsigned char bus_8131_1;
12 extern  unsigned char bus_8131_2;
13 extern  unsigned char bus_8111_0;
14 extern  unsigned char bus_8111_1;
15 extern  unsigned char bus_8151_0;
16 extern  unsigned char bus_8151_1;
17 extern  unsigned apicid_8111;
18 extern  unsigned apicid_8131_1;
19 extern  unsigned apicid_8131_2;
20
21 extern  unsigned sbdn3;
22 extern  unsigned sbdn5;
23
24 static void *smp_write_config_table(void *v)
25 {
26         struct mp_config_table *mc;
27         unsigned char bus_num;
28         int i;
29
30         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
31
32         mptable_init(mc, "S2885       ", LAPIC_ADDR);
33
34         smp_write_processors(mc);
35
36         get_bus_conf();
37
38 /*Bus:          Bus ID  Type*/
39        /* define bus and isa numbers */
40         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
41                 smp_write_bus(mc, bus_num, "PCI   ");
42         }
43         smp_write_bus(mc, bus_isa, "ISA   ");
44
45 /*I/O APICs:    APIC ID Version State           Address*/
46         smp_write_ioapic(mc, apicid_8111, 0x11, IO_APIC_ADDR); //8111
47         {
48                 device_t dev;
49                 struct resource *res;
50                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,1));
51                 if (dev) {
52                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
53                         if (res) {
54                                 smp_write_ioapic(mc, apicid_8131_1, 0x11, res->base);
55                         }
56                 }
57                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,1));
58                 if (dev) {
59                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
60                         if (res) {
61                                 smp_write_ioapic(mc, apicid_8131_2, 0x11, res->base);
62                         }
63                 }
64         }
65
66         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
67
68 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
69 //??? What
70         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_0, ((sysconf.sbdn+1)<<2)|3, apicid_8111, 0x13);
71 //Onboard AMD AC97 Audio
72         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_0, ((sysconf.sbdn+1)<<2)|1, apicid_8111, 0x11);
73 // Onboard AMD USB
74         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
75
76 //  AGP Display Adapter
77         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8151_1, 0x0, apicid_8111, 0x10);
78
79 //Onboard Serial ATA
80         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|0, apicid_8111, 0x11);
81 //Onboard Firewire
82         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0c<<2)|0, apicid_8111, 0x13);
83 //Onboard Broadcom NIC
84         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|0, apicid_8131_1, 0x0);
85
86 //Slot 5 PCI 32
87         for(i=0;i<4;i++) {
88                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0a<<2)|i, apicid_8111, 0x10 + (0+i)%4); //16
89         }
90
91
92 //Slot 3 PCIX 100/66
93         for(i=0;i<4;i++) {
94                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|i, apicid_8131_1, (3+i)%4); //27
95         }
96
97
98 //Slot 4 PCIX 100/66
99         for(i=0;i<4;i++) {
100                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (7<<2)|i, apicid_8131_1, (2+i)%4); //26
101         }
102
103
104 //Slot 1 PCI-X 133/100/66
105         for(i=0;i<4;i++) {
106                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|i, apicid_8131_2, (0+i)%4); //28
107         }
108
109
110 //Slot 2 PCI-X 133/100/66
111         for(i=0;i<4;i++) {
112                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|i, apicid_8131_2, (1+i)%4); //29
113         }
114
115 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
116         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
117         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
118         /* There is no extension information... */
119
120         /* Compute the checksums */
121         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
122         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
123         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
124                 mc, smp_next_mpe_entry(mc));
125         return smp_next_mpe_entry(mc);
126 }
127
128 unsigned long write_smp_table(unsigned long addr)
129 {
130         void *v;
131         v = smp_write_floating_table(addr);
132         return (unsigned long)smp_write_config_table(v);
133 }