1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/ioapic.h>
4 #include <device/pci.h>
8 static void *smp_write_config_table(void *v)
10 struct mp_config_table *mc;
12 unsigned char bus_8131_1;
13 unsigned char bus_8131_2;
14 unsigned char bus_8111_1;
16 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
18 mptable_init(mc, "KHEPRI ", LAPIC_ADDR);
20 smp_write_processors(mc);
26 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
28 bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
31 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n");
35 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
37 bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
40 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n");
44 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
46 bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
49 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
54 mptable_write_buses(mc, NULL, &bus_isa);
58 smp_write_ioapic(mc, 2, 0x11, IO_APIC_ADDR);
63 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
65 res = find_resource(dev, PCI_BASE_ADDRESS_0);
67 smp_write_ioapic(mc, 0x03, 0x11, res->base);
71 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
73 res = find_resource(dev, PCI_BASE_ADDRESS_0);
75 smp_write_ioapic(mc, 0x04, 0x11, res->base);
80 mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
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);
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);
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);
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);
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);
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);
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);
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);
157 /* There is no extension information... */
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);
167 unsigned long write_smp_table(unsigned long addr)
170 v = smp_write_floating_table(addr);
171 return (unsigned long)smp_write_config_table(v);