Unify Local APIC address definitions
[coreboot.git] / src / mainboard / newisys / khepri / 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
58         smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
59         {
60                 device_t dev;
61                 struct resource *res;
62                 /* 8131 apic 3 */
63                 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
64                 if (dev) {
65                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
66                         if (res) {
67                                 smp_write_ioapic(mc, 0x03, 0x11, res->base);
68                         }
69                 }
70                 /* 8131 apic 4 */
71                 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
72                 if (dev) {
73                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
74                         if (res) {
75                                 smp_write_ioapic(mc, 0x04, 0x11, res->base);
76                         }
77                 }
78         }
79
80         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
81
82         /* Standard local interrupt assignments */
83         mptable_lintsrc(mc, bus_isa);
84
85
86         /* PCI Slot 1 */
87         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
88                 bus_8131_2, (1<<2)|0, 0x02, 0x11);
89         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
90                 bus_8131_2, (1<<2)|1, 0x02, 0x12);
91         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
92                 bus_8131_2, (1<<2)|2, 0x02, 0x13);
93         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
94                 bus_8131_2, (1<<2)|3, 0x02, 0x10);
95
96         /* PCI Slot 2 */
97         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
98                 bus_8131_2, (2<<2)|0, 0x02, 0x12);
99         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
100                 bus_8131_2, (2<<2)|1, 0x02, 0x13);
101         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
102                 bus_8131_2, (2<<2)|2, 0x02, 0x10);
103         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
104                 bus_8131_2, (2<<2)|3, 0x02, 0x11);
105
106         /* PCI Slot 3 */
107         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
108                 bus_8131_1, (1<<2)|0, 0x02, 0x11);
109         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
110                 bus_8131_1, (1<<2)|1, 0x02, 0x12);
111         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
112                 bus_8131_1, (1<<2)|2, 0x02, 0x13);
113         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
114                 bus_8131_1, (1<<2)|3, 0x02, 0x10);
115
116         /* PCI Slot 4 */
117         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
118                 bus_8131_1, (2<<2)|0, 0x02, 0x12);
119         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
120                 bus_8131_1, (2<<2)|1, 0x02, 0x13);
121         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
122                 bus_8131_1, (2<<2)|2, 0x02, 0x10);
123         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
124                 bus_8131_1, (2<<2)|3, 0x02, 0x11);
125
126         /* PCI Slot 5 */
127         // FIXME get the irqs right, it's just hacked to work for now
128         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
129                 bus_8111_1, (5<<2)|0, 0x02, 0x11);
130         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
131                 bus_8111_1, (5<<2)|1, 0x02, 0x12);
132         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
133                 bus_8111_1, (5<<2)|2, 0x02, 0x13);
134         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
135                 bus_8111_1, (5<<2)|3, 0x02, 0x10);
136
137         /* PCI Slot 6 */
138         // FIXME get the irqs right, it's just hacked to work for now
139         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
140                 bus_8111_1, (4<<2)|0, 0x02, 0x10);
141         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
142                 bus_8111_1, (4<<2)|1, 0x02, 0x11);
143         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
144                 bus_8111_1, (4<<2)|2, 0x02, 0x12);
145         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
146                 bus_8111_1, (4<<2)|3, 0x02, 0x13);
147
148         /* On board nics */
149         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
150                 bus_8131_1, (3<<2)|0, 0x02, 0x13);
151         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
152                 bus_8131_1, (4<<2)|0, 0x02, 0x13);
153
154         /* There is no extension information... */
155
156         /* Compute the checksums */
157         return mptable_finalize(mc);
158 }
159
160 unsigned long write_smp_table(unsigned long addr)
161 {
162         void *v;
163         v = smp_write_floating_table(addr, 0);
164         return (unsigned long)smp_write_config_table(v);
165 }
166