1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <device/pci.h>
7 void *smp_write_config_table(void *v, unsigned long * processor_map)
9 static const char sig[4] = "PCMP";
10 static const char oem[8] = "IBM ";
11 static const char productid[12] = "E325 ";
12 struct mp_config_table *mc;
14 unsigned char bus_num;
15 unsigned char bus_isa;
16 unsigned char bus_8111_0;
17 unsigned char bus_8111_1;
18 unsigned char bus_8131_1;
19 unsigned char bus_8131_2;
21 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
22 memset(mc, 0, sizeof(*mc));
24 memcpy(mc->mpc_signature, sig, sizeof(sig));
25 mc->mpc_length = sizeof(*mc); /* initially just the header */
27 mc->mpc_checksum = 0; /* not yet computed */
28 memcpy(mc->mpc_oem, oem, sizeof(oem));
29 memcpy(mc->mpc_productid, productid, sizeof(productid));
32 mc->mpc_entry_count = 0; /* No entries yet... */
33 mc->mpc_lapic = LAPIC_ADDR;
38 smp_write_processors(mc, processor_map);
44 dev = dev_find_slot(1, PCI_DEVFN(0x03,0));
46 bus_8111_0 = pci_read_config8(dev, PCI_PRIMARY_BUS);
47 bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
48 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
51 printk_debug("ERROR - could not find PCI 1:03.0, using defaults\n");
57 dev = dev_find_slot(1, PCI_DEVFN(0x01,0));
59 bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
62 printk_debug("ERROR - could not find PCI 1:01.0, using defaults\n");
67 dev = dev_find_slot(1, PCI_DEVFN(0x02,0));
69 bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
71 printk_debug("ERROR - could not find PCI 1:02.0, using defaults\n");
76 /* define bus and isa numbers */
77 for (bus_num = 0; bus_num < bus_isa; bus_num++) {
78 smp_write_bus(mc, bus_num, "PCI ");
80 smp_write_bus(mc, bus_isa, "ISA ");
82 /* Legacy IOAPIC #2 */
83 smp_write_ioapic(mc, 2, 0x11, 0xfec00000);
88 dev = dev_find_slot(1, PCI_DEVFN(0x01,1));
90 base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
91 base &= PCI_BASE_ADDRESS_MEM_MASK;
92 smp_write_ioapic(mc, 0x03, 0x11, base);
95 dev = dev_find_slot(1, PCI_DEVFN(0x02,1));
97 base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
98 base &= PCI_BASE_ADDRESS_MEM_MASK;
99 smp_write_ioapic(mc, 0x04, 0x11, base);
103 /* ISA backward compatibility interrupts */
104 smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, 0x02, 0x00);
105 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x01, 0x02, 0x01);
106 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, 0x02, 0x02);
107 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x03, 0x02, 0x03);
108 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x04, 0x02, 0x04);
109 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x05, 0x02, 0x05);
110 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x06, 0x02, 0x06);
111 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x07, 0x02, 0x07);
112 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x08, 0x02, 0x08);
113 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x09, 0x02, 0x09);
114 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x0a, 0x02, 0x0a);
115 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x0b, 0x02, 0x0b);
116 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x0c, 0x02, 0x0c);
117 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x0d, 0x02, 0x0d);
118 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x0e, 0x02, 0x0e);
119 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x0f, 0x02, 0x0f);
121 /* PCI Ints: Type Polarity Trigger Bus ID PCIDEVNUM|IRQ APIC ID PIN# */
122 /* Integrated SMBus 2.0 */
123 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|3, 0x2, 0x13);
124 /* Integrated AMD AC97 Audio */
125 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_0, (0x04<<2)|1, 0x2, 0x11);
127 /* Integrated AMD USB */
128 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x00<<2)|3, 0x2, 0x13);
130 /* On board ATI Rage XL */
131 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8111_1, (0x05<<2)|0, 0x2, 0x10);
133 /* On board Broadcom nics */
134 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|0, 0x3, 0x00);
135 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x01<<2)|1, 0x3, 0x01);
137 /* On board LSI SCSI */
138 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_1, (0x02<<2)|0, 0x3, 0x02);
140 /* PCI Slot 1 PCIX */
141 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|0, 0x2, 0x10);
142 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|1, 0x2, 0x11);
143 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|2, 0x2, 0x12);
144 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x03<<2)|3, 0x2, 0x13);
146 /* PCI Slot 2 PCIX */
147 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|0, 0x2, 0x11);
148 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|1, 0x2, 0x12);
149 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|2, 0x2, 0x13);
150 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_8131_2, (0x04<<2)|3, 0x2, 0x10);
152 /* Standard local interrupt assignments:
153 * Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
154 smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, MP_APIC_ALL, 0x00);
155 smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0x00, MP_APIC_ALL, 0x01);
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_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, unsigned long *processor_map)
170 v = smp_write_floating_table(addr);
171 return (unsigned long)smp_write_config_table(v, processor_map);