45cf55c0ba5c31ca381cdda9d7e69245ee0b3f9a
[coreboot.git] / src / mainboard / tyan / s2885 / 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 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
25
26
27 static void *smp_write_config_table(void *v)
28 {
29         static const char sig[4] = "PCMP";
30         static const char oem[8] = "COREBOOT";
31         static const char productid[12] = "S2885       ";
32         struct mp_config_table *mc;
33
34         unsigned char bus_num;
35         int i;
36
37
38         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
39         memset(mc, 0, sizeof(*mc));
40
41         memcpy(mc->mpc_signature, sig, sizeof(sig));
42         mc->mpc_length = sizeof(*mc); /* initially just the header */
43         mc->mpc_spec = 0x04;
44         mc->mpc_checksum = 0; /* not yet computed */
45         memcpy(mc->mpc_oem, oem, sizeof(oem));
46         memcpy(mc->mpc_productid, productid, sizeof(productid));
47         mc->mpc_oemptr = 0;
48         mc->mpc_oemsize = 0;
49         mc->mpc_entry_count = 0; /* No entries yet... */
50         mc->mpc_lapic = LAPIC_ADDR;
51         mc->mpe_length = 0;
52         mc->mpe_checksum = 0;
53         mc->reserved = 0;
54
55         smp_write_processors(mc);
56
57         get_bus_conf();
58
59 /*Bus:          Bus ID  Type*/
60        /* define bus and isa numbers */
61         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
62                 smp_write_bus(mc, bus_num, "PCI   ");
63         }
64         smp_write_bus(mc, bus_isa, "ISA   ");
65
66 /*I/O APICs:    APIC ID Version State           Address*/
67         smp_write_ioapic(mc, apicid_8111, 0x11, 0xfec00000); //8111
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         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
88
89 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
90 //??? What
91         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);
92 //Onboard AMD AC97 Audio
93         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);
94 // Onboard AMD USB
95         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13);
96
97 //  AGP Display Adapter
98         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8151_1, 0x0, apicid_8111, 0x10);
99
100 //Onboard Serial ATA
101         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0b<<2)|0, apicid_8111, 0x11);
102 //Onboard Firewire
103         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0x0c<<2)|0, apicid_8111, 0x13);
104 //Onboard Broadcom NIC
105         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|0, apicid_8131_1, 0x0);
106
107 //Slot 5 PCI 32
108         for(i=0;i<4;i++) {
109                 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
110         }
111
112
113 //Slot 3 PCIX 100/66
114         for(i=0;i<4;i++) {
115                 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
116         }
117
118
119 //Slot 4 PCIX 100/66
120         for(i=0;i<4;i++) {
121                 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
122         }
123
124
125 //Slot 1 PCI-X 133/100/66
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
131 //Slot 2 PCI-X 133/100/66
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, (6<<2)|i, apicid_8131_2, (1+i)%4); //29
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 }