blob: 6d15f56da96a8eb34f314b43d1058d60dfb24478 [file] [log] [blame]
Stefan Reinauer36a22682008-10-29 04:52:57 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2008 coresystems GmbH
5 *
Uwe Hermann2bb4acf2010-03-01 17:19:55 +00006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
Stefan Reinauer36a22682008-10-29 04:52:57 +00009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Uwe Hermann2bb4acf2010-03-01 17:19:55 +000017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer36a22682008-10-29 04:52:57 +000018 */
19
20
21#include <device/device.h>
22#include <device/pci.h>
23#include <console/console.h>
24#include <arch/smp/mpspec.h>
25#include <string.h>
26#include <stdint.h>
27
Stefan Reinauerde3206a2010-02-22 06:09:43 +000028static void *smp_write_config_table(void *v)
Stefan Reinauer36a22682008-10-29 04:52:57 +000029{
30 static const char sig[4] = "PCMP";
31 static const char oem[8] = "COREBOOT";
32 static const char productid[12] = "986LCD-M ";
33 struct mp_config_table *mc;
Stefan Reinauer762a2302010-01-19 21:15:37 +000034 struct device *riser = NULL, *firewire = NULL;
Stefan Reinauer36a22682008-10-29 04:52:57 +000035 int i;
Patrick Georgiab272662010-06-25 13:43:22 +000036 int firewire_bus = 0, riser_bus = 0, isa_bus;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000037 int ioapic_id;
Stefan Reinauer36a22682008-10-29 04:52:57 +000038
39 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
40 memset(mc, 0, sizeof(*mc));
41
42 memcpy(mc->mpc_signature, sig, sizeof(sig));
43 mc->mpc_length = sizeof(*mc); /* initially just the header */
44 mc->mpc_spec = 0x04;
45 mc->mpc_checksum = 0; /* not yet computed */
46 memcpy(mc->mpc_oem, oem, sizeof(oem));
47 memcpy(mc->mpc_productid, productid, sizeof(productid));
48 mc->mpc_oemptr = 0;
49 mc->mpc_oemsize = 0;
50 mc->mpc_entry_count = 0; /* No entries yet... */
51 mc->mpc_lapic = LAPIC_ADDR;
52 mc->mpe_length = 0;
53 mc->mpe_checksum = 0;
54 mc->reserved = 0;
55
56 smp_write_processors(mc);
57
Stefan Reinauer762a2302010-01-19 21:15:37 +000058 firewire = dev_find_device(0x104c, 0x8023, 0);
59 if (firewire) {
60 firewire_bus = firewire->bus->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000061 }
62
63 // If a riser card is used, this riser is detected on bus 4, so its secondary bus is the
64 // highest bus number on the pci bus.
65 riser = dev_find_device(0x3388, 0x0021, 0);
66 if (!riser)
67 riser = dev_find_device(0x3388, 0x0022, 0);
68 if (riser) {
Myles Watson894a3472010-06-09 22:41:35 +000069 riser_bus = riser->link_list->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000070 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000071
Patrick Georgiab272662010-06-25 13:43:22 +000072 mptable_write_buses(mc, NULL, &isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +000073
74 /* I/O APICs: APIC ID Version State Address */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000075 ioapic_id = 2;
76 smp_write_ioapic(mc, ioapic_id, 0x20, 0xfec00000);
Stefan Reinauer36a22682008-10-29 04:52:57 +000077
78 /* Legacy Interrupts */
Patrick Georgic5b87c82010-05-20 15:28:19 +000079 mptable_add_isa_interrupts(mc, isa_bus, ioapic_id, 0);
Stefan Reinauer36a22682008-10-29 04:52:57 +000080
81 /* Builtin devices on Bus 0 */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000082 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x4, ioapic_id, 0x10);
83 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x8, ioapic_id, 0x10);
84 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x7d, ioapic_id, 0x13);
85 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x74, ioapic_id, 0x17);
86 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x75, ioapic_id, 0x13);
87 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x76, ioapic_id, 0x12);
88 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x77, ioapic_id, 0x10);
89 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x6c, ioapic_id, 0x10);
90 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x70, ioapic_id, 0x10);
91 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x71, ioapic_id, 0x11);
Stefan Reinauer36a22682008-10-29 04:52:57 +000092
Stefan Reinauerde3206a2010-02-22 06:09:43 +000093 /* Internal PCI bus (Firewire, PCI slot) */
Stefan Reinauer762a2302010-01-19 21:15:37 +000094 if (firewire) {
Stefan Reinauerde3206a2010-02-22 06:09:43 +000095 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, firewire_bus, 0x0, ioapic_id, 0x10);
96 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, firewire_bus, 0x4, ioapic_id, 0x14);
Stefan Reinauer762a2302010-01-19 21:15:37 +000097 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000098
Stefan Reinauer762a2302010-01-19 21:15:37 +000099 if (riser) {
100 /* Old riser card */
101 // riser slot top 5:8.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000102 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x20, ioapic_id, 0x14);
Stefan Reinauer762a2302010-01-19 21:15:37 +0000103 // riser slot middle 5:9.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000104 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x24, ioapic_id, 0x15);
Stefan Reinauer762a2302010-01-19 21:15:37 +0000105 // riser slot bottom 5:a.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000106 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x28, ioapic_id, 0x16);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000107
Stefan Reinauer762a2302010-01-19 21:15:37 +0000108 /* New Riser Card */
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000109 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x30, ioapic_id, 0x14);
110 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x34, ioapic_id, 0x15);
111 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x38, ioapic_id, 0x16);
Stefan Reinauer762a2302010-01-19 21:15:37 +0000112 }
Stefan Reinauere1025d02009-03-11 15:20:36 +0000113
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000114 /* PCIe slot */
115 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x1, 0x0, ioapic_id, 0x10);
116 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x1, 0x1, ioapic_id, 0x11);
117
Stefan Reinauer36a22682008-10-29 04:52:57 +0000118 /* Onboard Ethernet */
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000119 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x2, 0x0, ioapic_id, 0x10);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000120
121 /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
122 smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, MP_APIC_ALL, 0x0);
123 smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, MP_APIC_ALL, 0x1);
124
125 /* Compute the checksums */
126 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
127 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
128
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000129 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n", mc, smp_next_mpe_entry(mc));
Stefan Reinauer36a22682008-10-29 04:52:57 +0000130
131 return smp_next_mpe_entry(mc);
132}
133
Stefan Reinauer14e22772010-04-27 06:56:47 +0000134/* MP table generation in coreboot is not very well designed;
135 * One of the issues is that it knows nothing about Virtual
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000136 * Wire mode, which everyone uses since a decade or so. This
137 * function fixes up our floating table. This spares us doing
Stefan Reinauer14e22772010-04-27 06:56:47 +0000138 * a half-baked fix of adding a new parameter to 200+ calls
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000139 * to smp_write_floating_table()
140 */
141static void fixup_virtual_wire(void *v)
142{
143 struct intel_mp_floating *mf = v;
144
145 mf->mpf_checksum = 0;
146 mf->mpf_feature2 = MP_FEATURE_VIRTUALWIRE;
147 mf->mpf_checksum = smp_compute_checksum(mf, mf->mpf_length*16);
148}
149
Stefan Reinauer36a22682008-10-29 04:52:57 +0000150unsigned long write_smp_table(unsigned long addr)
151{
152 void *v;
153 v = smp_write_floating_table(addr);
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000154 fixup_virtual_wire(v);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000155 return (unsigned long)smp_write_config_table(v);
156}