Get mptable OEM/product ID from kconfig variables.
[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, LAPIC_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         smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
84                 bus_isa, 0x00, MP_APIC_ALL, 0x00);
85         smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
86                 bus_isa, 0x00, MP_APIC_ALL, 0x01);
87
88
89         /* PCI Slot 1 */
90         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
91                 bus_8131_2, (1<<2)|0, 0x02, 0x11);
92         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
93                 bus_8131_2, (1<<2)|1, 0x02, 0x12);
94         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
95                 bus_8131_2, (1<<2)|2, 0x02, 0x13);
96         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
97                 bus_8131_2, (1<<2)|3, 0x02, 0x10);
98
99         /* PCI Slot 2 */
100         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
101                 bus_8131_2, (2<<2)|0, 0x02, 0x12);
102         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
103                 bus_8131_2, (2<<2)|1, 0x02, 0x13);
104         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
105                 bus_8131_2, (2<<2)|2, 0x02, 0x10);
106         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
107                 bus_8131_2, (2<<2)|3, 0x02, 0x11);
108
109         /* PCI Slot 3 */
110         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
111                 bus_8131_1, (1<<2)|0, 0x02, 0x11);
112         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
113                 bus_8131_1, (1<<2)|1, 0x02, 0x12);
114         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
115                 bus_8131_1, (1<<2)|2, 0x02, 0x13);
116         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
117                 bus_8131_1, (1<<2)|3, 0x02, 0x10);
118
119         /* PCI Slot 4 */
120         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
121                 bus_8131_1, (2<<2)|0, 0x02, 0x12);
122         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
123                 bus_8131_1, (2<<2)|1, 0x02, 0x13);
124         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
125                 bus_8131_1, (2<<2)|2, 0x02, 0x10);
126         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
127                 bus_8131_1, (2<<2)|3, 0x02, 0x11);
128
129         /* PCI Slot 5 */
130         // FIXME get the irqs right, it's just hacked to work for now
131         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
132                 bus_8111_1, (5<<2)|0, 0x02, 0x11);
133         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
134                 bus_8111_1, (5<<2)|1, 0x02, 0x12);
135         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
136                 bus_8111_1, (5<<2)|2, 0x02, 0x13);
137         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
138                 bus_8111_1, (5<<2)|3, 0x02, 0x10);
139
140         /* PCI Slot 6 */
141         // FIXME get the irqs right, it's just hacked to work for now
142         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
143                 bus_8111_1, (4<<2)|0, 0x02, 0x10);
144         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
145                 bus_8111_1, (4<<2)|1, 0x02, 0x11);
146         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
147                 bus_8111_1, (4<<2)|2, 0x02, 0x12);
148         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
149                 bus_8111_1, (4<<2)|3, 0x02, 0x13);
150
151         /* On board nics */
152         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
153                 bus_8131_1, (3<<2)|0, 0x02, 0x13);
154         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT,
155                 bus_8131_1, (4<<2)|0, 0x02, 0x13);
156
157         /* There is no extension information... */
158
159         /* Compute the checksums */
160         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
161         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
162         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
163                 mc, smp_next_mpe_entry(mc));
164         return smp_next_mpe_entry(mc);
165 }
166
167 unsigned long write_smp_table(unsigned long addr)
168 {
169         void *v;
170         v = smp_write_floating_table(addr);
171         return (unsigned long)smp_write_config_table(v);
172 }
173