Unify Local APIC address definitions
[coreboot.git] / src / mainboard / iwill / dk8x / 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         int bus_isa;
12         unsigned char bus_8131_1;
13         unsigned char bus_8131_2;
14         unsigned char bus_8111_1;
15
16         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
17
18         mptable_init(mc, LOCAL_APIC_ADDR);
19
20         smp_write_processors(mc);
21
22         {
23                 device_t dev;
24
25                 /* 8111 */
26                 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
27                 if (dev) {
28                         bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
29                 }
30                 else {
31                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
32                         bus_8111_1 = 4;
33                 }
34                 /* 8131-1 */
35                 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
36                 if (dev) {
37                         bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
38                 }
39                 else {
40                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
41                         bus_8131_1 = 2;
42                 }
43                 /* 8131-2 */
44                 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
45                 if (dev) {
46                         bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
47                 }
48                 else {
49                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
50                         bus_8131_2 = 3;
51                 }
52         }
53
54         mptable_write_buses(mc, NULL, &bus_isa);
55
56         /* IOAPIC handling */
57         smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
58         {
59                 device_t dev;
60                 struct resource *res;
61                 /* 8131 apic 3 */
62                 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
63                 if (dev) {
64                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
65                         if (res) {
66                                 smp_write_ioapic(mc, 0x03, 0x11, res->base);
67                         }
68                 }
69                 /* 8131 apic 4 */
70                 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
71                 if (dev) {
72                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
73                         if (res) {
74                                 smp_write_ioapic(mc, 0x04, 0x11, res->base);
75                         }
76                 }
77         }
78
79         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
80
81         /* Standard local interrupt assignments */
82         mptable_lintsrc(mc, bus_isa);
83
84
85         /* PCI Slot 1 */
86         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
87                 bus_8131_2, (1<<2)|0, 0x02, 0x11);
88         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
89                 bus_8131_2, (1<<2)|1, 0x02, 0x12);
90         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
91                 bus_8131_2, (1<<2)|2, 0x02, 0x13);
92         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
93                 bus_8131_2, (1<<2)|3, 0x02, 0x10);
94
95         /* PCI Slot 2 */
96         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
97                 bus_8131_2, (2<<2)|0, 0x02, 0x12);
98         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
99                 bus_8131_2, (2<<2)|1, 0x02, 0x13);
100         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
101                 bus_8131_2, (2<<2)|2, 0x02, 0x10);
102         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
103                 bus_8131_2, (2<<2)|3, 0x02, 0x11);
104
105         /* PCI Slot 3 */
106         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
107                 bus_8131_1, (1<<2)|0, 0x02, 0x11);
108         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
109                 bus_8131_1, (1<<2)|1, 0x02, 0x12);
110         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
111                 bus_8131_1, (1<<2)|2, 0x02, 0x13);
112         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
113                 bus_8131_1, (1<<2)|3, 0x02, 0x10);
114
115         /* PCI Slot 4 */
116         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
117                 bus_8131_1, (2<<2)|0, 0x02, 0x12);
118         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
119                 bus_8131_1, (2<<2)|1, 0x02, 0x13);
120         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
121                 bus_8131_1, (2<<2)|2, 0x02, 0x10);
122         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
123                 bus_8131_1, (2<<2)|3, 0x02, 0x11);
124
125         /* PCI Slot 5 */
126         // FIXME get the irqs right, it's just hacked to work for now
127         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
128                 bus_8111_1, (5<<2)|0, 0x02, 0x11);
129         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
130                 bus_8111_1, (5<<2)|1, 0x02, 0x12);
131         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
132                 bus_8111_1, (5<<2)|2, 0x02, 0x13);
133         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
134                 bus_8111_1, (5<<2)|3, 0x02, 0x10);
135
136         /* PCI Slot 6 */
137         // FIXME get the irqs right, it's just hacked to work for now
138         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
139                 bus_8111_1, (4<<2)|0, 0x02, 0x10);
140         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
141                 bus_8111_1, (4<<2)|1, 0x02, 0x11);
142         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
143                 bus_8111_1, (4<<2)|2, 0x02, 0x12);
144         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
145                 bus_8111_1, (4<<2)|3, 0x02, 0x13);
146
147         /* On board nics */
148         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
149                 bus_8131_1, (3<<2)|0, 0x02, 0x13);
150         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
151                 bus_8131_1, (4<<2)|0, 0x02, 0x13);
152
153         /* There is no extension information... */
154
155         /* Compute the checksums */
156         return mptable_finalize(mc);
157 }
158
159 unsigned long write_smp_table(unsigned long addr)
160 {
161         void *v;
162         v = smp_write_floating_table(addr, 0);
163         return (unsigned long)smp_write_config_table(v);
164 }
165