blob: 2ee28906d301ba688c439fad1b850b3edac59644 [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.
Stefan Reinauer36a22682008-10-29 04:52:57 +000014 */
15
Stefan Reinauer36a22682008-10-29 04:52:57 +000016#include <device/device.h>
17#include <device/pci.h>
18#include <console/console.h>
19#include <arch/smp/mpspec.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000020#include <arch/ioapic.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +000021#include <string.h>
22#include <stdint.h>
23
Stefan Reinauerde3206a2010-02-22 06:09:43 +000024static void *smp_write_config_table(void *v)
Stefan Reinauer36a22682008-10-29 04:52:57 +000025{
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020026 struct mp_config_table *mc;
Stefan Reinauer762a2302010-01-19 21:15:37 +000027 struct device *riser = NULL, *firewire = NULL;
Patrick Georgiab272662010-06-25 13:43:22 +000028 int firewire_bus = 0, riser_bus = 0, isa_bus;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000029 int ioapic_id;
Stefan Reinauer36a22682008-10-29 04:52:57 +000030
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020031 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Stefan Reinauer36a22682008-10-29 04:52:57 +000032
Patrick Georgic8feedd2012-02-16 18:43:25 +010033 mptable_init(mc, LOCAL_APIC_ADDR);
Stefan Reinauer36a22682008-10-29 04:52:57 +000034
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020035 smp_write_processors(mc);
Stefan Reinauer36a22682008-10-29 04:52:57 +000036
Stefan Reinauer762a2302010-01-19 21:15:37 +000037 firewire = dev_find_device(0x104c, 0x8023, 0);
38 if (firewire) {
39 firewire_bus = firewire->bus->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000040 }
41
42 // If a riser card is used, this riser is detected on bus 4, so its secondary bus is the
43 // highest bus number on the pci bus.
44 riser = dev_find_device(0x3388, 0x0021, 0);
45 if (!riser)
46 riser = dev_find_device(0x3388, 0x0022, 0);
47 if (riser) {
Myles Watson894a3472010-06-09 22:41:35 +000048 riser_bus = riser->link_list->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000049 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000050
Patrick Georgiab272662010-06-25 13:43:22 +000051 mptable_write_buses(mc, NULL, &isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +000052
53 /* I/O APICs: APIC ID Version State Address */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000054 ioapic_id = 2;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 smp_write_ioapic(mc, ioapic_id, 0x20, VIO_APIC_VADDR);
Stefan Reinauer36a22682008-10-29 04:52:57 +000056
57 /* Legacy Interrupts */
Patrick Georgic5b87c82010-05-20 15:28:19 +000058 mptable_add_isa_interrupts(mc, isa_bus, ioapic_id, 0);
Stefan Reinauer36a22682008-10-29 04:52:57 +000059
60 /* Builtin devices on Bus 0 */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000061 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x4, ioapic_id, 0x10);
62 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x8, ioapic_id, 0x10);
63 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x7d, ioapic_id, 0x13);
64 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x74, ioapic_id, 0x17);
65 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x75, ioapic_id, 0x13);
66 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x76, ioapic_id, 0x12);
67 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x77, ioapic_id, 0x10);
68 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x6c, ioapic_id, 0x10);
69 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x70, ioapic_id, 0x10);
70 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 +000071
Stefan Reinauerde3206a2010-02-22 06:09:43 +000072 /* Internal PCI bus (Firewire, PCI slot) */
Stefan Reinauer762a2302010-01-19 21:15:37 +000073 if (firewire) {
Stefan Reinauerde3206a2010-02-22 06:09:43 +000074 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, firewire_bus, 0x0, ioapic_id, 0x10);
75 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 +000076 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000077
Stefan Reinauer762a2302010-01-19 21:15:37 +000078 if (riser) {
79 /* Old riser card */
80 // riser slot top 5:8.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +000081 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 +000082 // riser slot middle 5:9.0
Stefan Reinauerde3206a2010-02-22 06:09:43 +000083 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 +000084 // riser slot bottom 5:a.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, 0x28, ioapic_id, 0x16);
Stefan Reinauer36a22682008-10-29 04:52:57 +000086
Stefan Reinauer762a2302010-01-19 21:15:37 +000087 /* New Riser Card */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000088 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x30, ioapic_id, 0x14);
89 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x34, ioapic_id, 0x15);
90 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 +000091 }
Stefan Reinauere1025d02009-03-11 15:20:36 +000092
Stefan Reinauerde3206a2010-02-22 06:09:43 +000093 /* PCIe slot */
94 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x1, 0x0, ioapic_id, 0x10);
95 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x1, 0x1, ioapic_id, 0x11);
96
Stefan Reinauer36a22682008-10-29 04:52:57 +000097 /* Onboard Ethernet */
Stefan Reinauerde3206a2010-02-22 06:09:43 +000098 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 +000099
100 /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200101 mptable_lintsrc(mc, isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000102
103 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200104 return mptable_finalize(mc);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000105}
106
107unsigned long write_smp_table(unsigned long addr)
108{
109 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +0200110 v = smp_write_floating_table(addr, 1);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000111 return (unsigned long)smp_write_config_table(v);
112}