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