Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / mainboard / tyan / s2881 / 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_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 apicid_8111;
16 extern  unsigned apicid_8131_1;
17 extern  unsigned apicid_8131_2;
18
19 extern  unsigned sbdn3;
20
21
22
23 static void *smp_write_config_table(void *v)
24 {
25         static const char sig[4] = "PCMP";
26         static const char oem[8] = "COREBOOT";
27         static const char productid[12] = "S2881       ";
28         struct mp_config_table *mc;
29
30         unsigned char bus_num;
31
32         int i;
33
34         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
35         memset(mc, 0, sizeof(*mc));
36
37         memcpy(mc->mpc_signature, sig, sizeof(sig));
38         mc->mpc_length = sizeof(*mc); /* initially just the header */
39         mc->mpc_spec = 0x04;
40         mc->mpc_checksum = 0; /* not yet computed */
41         memcpy(mc->mpc_oem, oem, sizeof(oem));
42         memcpy(mc->mpc_productid, productid, sizeof(productid));
43         mc->mpc_oemptr = 0;
44         mc->mpc_oemsize = 0;
45         mc->mpc_entry_count = 0; /* No entries yet... */
46         mc->mpc_lapic = LAPIC_ADDR;
47         mc->mpe_length = 0;
48         mc->mpe_checksum = 0;
49         mc->reserved = 0;
50
51         smp_write_processors(mc);
52
53         get_bus_conf();
54
55
56 /*Bus:          Bus ID  Type*/
57         /* define bus and isa numbers */
58         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
59                 smp_write_bus(mc, bus_num, "PCI   ");
60         }
61         smp_write_bus(mc, bus_isa, "ISA   ");
62
63
64 /*I/O APICs:    APIC ID Version State           Address*/
65         smp_write_ioapic(mc, apicid_8111, 0x11, 0xfec00000);
66         {
67                 device_t dev;
68                 struct resource *res;
69                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,1));
70                 if (dev) {
71                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
72                         if (res) {
73                                 smp_write_ioapic(mc, apicid_8131_1, 0x11, res->base);
74                         }
75                 }
76                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,1));
77                 if (dev) {
78                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
79                         if (res) {
80                                 smp_write_ioapic(mc, apicid_8131_2, 0x11, res->base);
81                         }
82                 }
83
84         }
85
86 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#
87 */      smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, apicid_8111, 0x0);
88         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x1, apicid_8111, 0x1);
89         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, apicid_8111, 0x2);
90         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x3, apicid_8111, 0x3);
91         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x4, apicid_8111, 0x4);
92         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x6, apicid_8111, 0x6);
93         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x7, apicid_8111, 0x7);
94         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x8, apicid_8111, 0x8);
95         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xc, apicid_8111, 0xc);
96         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xd, apicid_8111, 0xd);
97         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xe, apicid_8111, 0xe);
98         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xf, apicid_8111, 0xf);
99
100 //8111 LPC ????
101         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_0, ((sysconf.sbdn+1)<<2)|0, apicid_8111, 0x13);
102
103 //On Board AMD USB ???
104         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
105
106 //On Board ATI Display Adapter
107         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (6<<2)|0, apicid_8111, 0x12);
108
109 //On Board SI Serial ATA
110         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (5<<2)|0, apicid_8111, 0x11);
111
112 //Slot 3 PCIX 100/66
113         for(i=0;i<4;i++) {
114                 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
115         }
116
117 //On Board NIC and adaptec scsi
118         for(i=0;i<2;i++) {
119                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|i, apicid_8131_1, (0+i)%4); //24
120                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (0xa<<2)|i, apicid_8131_1, (0+i)%4); //24
121         }
122
123 //Slot 1 PCI-X 133/100/66 or Side 1 on raiser card
124         for(i=0;i<4;i++) {
125                 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
126         }
127
128         //Slot 1 PCI-X 133/100/66, Side 2 on raiser card
129         //Fix ME, IRQ Pins?
130         for(i=0;i<4;i++) {
131                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (4<<2)|i, apicid_8131_2, (1+i)%4); //28
132         }
133
134
135
136 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
137         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
138         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
139         /* There is no extension information... */
140
141         /* Compute the checksums */
142         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
143         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
144         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
145                 mc, smp_next_mpe_entry(mc));
146         return smp_next_mpe_entry(mc);
147 }
148
149 unsigned long write_smp_table(unsigned long addr)
150 {
151         void *v;
152         v = smp_write_floating_table(addr);
153         return (unsigned long)smp_write_config_table(v);
154 }