382bf908f0c1e6137fe66c58c8ecef81797daa0c
[coreboot.git] / src / mainboard / iwill / dk8s2 / 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
8 static void *smp_write_config_table(void *v)
9 {
10         struct mp_config_table *mc;
11         unsigned char bus_num;
12         unsigned char bus_isa;
13         unsigned char bus_8131_1;
14         unsigned char bus_8131_2;
15         unsigned char bus_8111_1;
16
17         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
18
19         mptable_init(mc, "DK8S2       ", LAPIC_ADDR);
20
21         smp_write_processors(mc);
22
23         {
24                 device_t dev;
25
26                 /* 8111 */
27                 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
28                 if (dev) {
29                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
30                         bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
31                         bus_isa++;
32                 }
33                 else {
34                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
35
36                         bus_8111_1 = 4;
37                         bus_isa = 5;
38                 }
39                 /* 8131-1 */
40                 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
41                 if (dev) {
42                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
43
44                 }
45                 else {
46                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
47
48                         bus_8131_1 = 2;
49                 }
50                 /* 8131-2 */
51                 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
52                 if (dev) {
53                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
54
55                 }
56                 else {
57                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
58
59                         bus_8131_2 = 3;
60                 }
61         }
62
63         /* define bus and isa numbers */
64         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
65                 smp_write_bus(mc, bus_num, "PCI   ");
66         }
67         smp_write_bus(mc, bus_isa, "ISA   ");
68
69         /* IOAPIC handling */
70         smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
71         {
72                 device_t dev;
73                 struct resource *res;
74                 /* 8131 apic 3 */
75                 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
76                 if (dev) {
77                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
78                         if (res) {
79                                 smp_write_ioapic(mc, 0x03, 0x11, res->base);
80                         }
81                 }
82                 /* 8131 apic 4 */
83                 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
84                 if (dev) {
85                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
86                         if (res) {
87                                 smp_write_ioapic(mc, 0x04, 0x11, res->base);
88                         }
89                 }
90         }
91
92         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
93
94         /* Standard local interrupt assignments */
95         smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
96                 bus_isa, 0x00, MP_APIC_ALL, 0x00);
97         smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
98                 bus_isa, 0x00, MP_APIC_ALL, 0x01);
99
100
101         /* PCI Slot 1 */
102         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
103                 bus_8131_2, (1<<2)|0, 0x02, 0x11);
104         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
105                 bus_8131_2, (1<<2)|1, 0x02, 0x12);
106         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
107                 bus_8131_2, (1<<2)|2, 0x02, 0x13);
108         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
109                 bus_8131_2, (1<<2)|3, 0x02, 0x10);
110
111         /* PCI Slot 2 */
112         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
113                 bus_8131_2, (2<<2)|0, 0x02, 0x12);
114         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
115                 bus_8131_2, (2<<2)|1, 0x02, 0x13);
116         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
117                 bus_8131_2, (2<<2)|2, 0x02, 0x10);
118         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
119                 bus_8131_2, (2<<2)|3, 0x02, 0x11);
120
121         /* PCI Slot 3 */
122         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
123                 bus_8131_1, (1<<2)|0, 0x02, 0x11);
124         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
125                 bus_8131_1, (1<<2)|1, 0x02, 0x12);
126         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
127                 bus_8131_1, (1<<2)|2, 0x02, 0x13);
128         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
129                 bus_8131_1, (1<<2)|3, 0x02, 0x10);
130
131         /* PCI Slot 4 */
132         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
133                 bus_8131_1, (2<<2)|0, 0x02, 0x12);
134         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
135                 bus_8131_1, (2<<2)|1, 0x02, 0x13);
136         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
137                 bus_8131_1, (2<<2)|2, 0x02, 0x10);
138         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
139                 bus_8131_1, (2<<2)|3, 0x02, 0x11);
140
141         /* PCI Slot 5 */
142         // FIXME get the irqs right, it's just hacked to work for now
143         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
144                 bus_8111_1, (5<<2)|0, 0x02, 0x11);
145         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
146                 bus_8111_1, (5<<2)|1, 0x02, 0x12);
147         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
148                 bus_8111_1, (5<<2)|2, 0x02, 0x13);
149         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
150                 bus_8111_1, (5<<2)|3, 0x02, 0x10);
151
152         /* PCI Slot 6 */
153         // FIXME get the irqs right, it's just hacked to work for now
154         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
155                 bus_8111_1, (4<<2)|0, 0x02, 0x10);
156         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
157                 bus_8111_1, (4<<2)|1, 0x02, 0x11);
158         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
159                 bus_8111_1, (4<<2)|2, 0x02, 0x12);
160         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
161                 bus_8111_1, (4<<2)|3, 0x02, 0x13);
162
163         /* On board nics */
164         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
165                 bus_8131_1, (3<<2)|0, 0x02, 0x13);
166         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
167                 bus_8131_1, (4<<2)|0, 0x02, 0x13);
168
169         /* There is no extension information... */
170
171         /* Compute the checksums */
172         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
173         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
174         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
175                 mc, smp_next_mpe_entry(mc));
176         return smp_next_mpe_entry(mc);
177 }
178
179 unsigned long write_smp_table(unsigned long addr)
180 {
181         void *v;
182         v = smp_write_floating_table(addr);
183         return (unsigned long)smp_write_config_table(v);
184 }
185