blob: ab63b45b3c59bde5b97995299021834ca15dac18 [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
Stefan Reinauer36a22682008-10-29 04:52:57 +000020#include <device/device.h>
21#include <device/pci.h>
22#include <console/console.h>
23#include <arch/smp/mpspec.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000024#include <arch/ioapic.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000025#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{
Stefan Reinauer36a22682008-10-29 04:52:57 +000030 struct mp_config_table *mc;
Stefan Reinauer762a2302010-01-19 21:15:37 +000031 struct device *riser = NULL, *firewire = NULL;
Patrick Georgiab272662010-06-25 13:43:22 +000032 int firewire_bus = 0, riser_bus = 0, isa_bus;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000033 int ioapic_id;
Stefan Reinauer36a22682008-10-29 04:52:57 +000034
35 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Stefan Reinauer36a22682008-10-29 04:52:57 +000036
Uwe Hermannc36d5062010-12-16 19:51:38 +000037 mptable_init(mc, LAPIC_ADDR);
Stefan Reinauer36a22682008-10-29 04:52:57 +000038
39 smp_write_processors(mc);
40
Stefan Reinauer762a2302010-01-19 21:15:37 +000041 firewire = dev_find_device(0x104c, 0x8023, 0);
42 if (firewire) {
43 firewire_bus = firewire->bus->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000044 }
45
46 // If a riser card is used, this riser is detected on bus 4, so its secondary bus is the
47 // highest bus number on the pci bus.
48 riser = dev_find_device(0x3388, 0x0021, 0);
49 if (!riser)
50 riser = dev_find_device(0x3388, 0x0022, 0);
51 if (riser) {
Myles Watson894a3472010-06-09 22:41:35 +000052 riser_bus = riser->link_list->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000053 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000054
Patrick Georgiab272662010-06-25 13:43:22 +000055 mptable_write_buses(mc, NULL, &isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +000056
57 /* I/O APICs: APIC ID Version State Address */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000058 ioapic_id = 2;
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000059 smp_write_ioapic(mc, ioapic_id, 0x20, IO_APIC_ADDR);
Stefan Reinauer36a22682008-10-29 04:52:57 +000060
61 /* Legacy Interrupts */
Patrick Georgic5b87c82010-05-20 15:28:19 +000062 mptable_add_isa_interrupts(mc, isa_bus, ioapic_id, 0);
Stefan Reinauer36a22682008-10-29 04:52:57 +000063
64 /* Builtin devices on Bus 0 */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000065 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x4, ioapic_id, 0x10);
66 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x8, ioapic_id, 0x10);
67 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x7d, ioapic_id, 0x13);
68 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x74, ioapic_id, 0x17);
69 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x75, ioapic_id, 0x13);
70 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x76, ioapic_id, 0x12);
71 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x77, ioapic_id, 0x10);
72 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x6c, ioapic_id, 0x10);
73 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x70, ioapic_id, 0x10);
74 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 +000075
Stefan Reinauerde3206a2010-02-22 06:09:43 +000076 /* Internal PCI bus (Firewire, PCI slot) */
Stefan Reinauer762a2302010-01-19 21:15:37 +000077 if (firewire) {
Stefan Reinauerde3206a2010-02-22 06:09:43 +000078 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, firewire_bus, 0x0, ioapic_id, 0x10);
79 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 +000080 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000081
Stefan Reinauer762a2302010-01-19 21:15:37 +000082 if (riser) {
83 /* Old riser card */
84 // riser slot top 5:8.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +000085 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 +000086 // riser slot middle 5:9.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +000087 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 +000088 // riser slot bottom 5:a.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +000089 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 +000090
Stefan Reinauer762a2302010-01-19 21:15:37 +000091 /* New Riser Card */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000092 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x30, ioapic_id, 0x14);
93 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x34, ioapic_id, 0x15);
94 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 +000095 }
Stefan Reinauere1025d02009-03-11 15:20:36 +000096
Stefan Reinauerde3206a2010-02-22 06:09:43 +000097 /* PCIe slot */
98 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x1, 0x0, ioapic_id, 0x10);
99 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x1, 0x1, ioapic_id, 0x11);
100
Stefan Reinauer36a22682008-10-29 04:52:57 +0000101 /* Onboard Ethernet */
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000102 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 +0000103
104 /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200105 mptable_lintsrc(mc, isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000106
107 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200108 return mptable_finalize(mc);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000109}
110
111unsigned long write_smp_table(unsigned long addr)
112{
113 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +0200114 v = smp_write_floating_table(addr, 1);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000115 return (unsigned long)smp_write_config_table(v);
116}