blob: a9b6483f8d91302414da528bb3f577bf4b1491a9 [file] [log] [blame]
Angel Pons30a511c2020-04-03 01:22:09 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +00002
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +00003#include <device/device.h>
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +00004#include <console/console.h>
5#include <arch/smp/mpspec.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +00006#include <arch/ioapic.h>
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +00007
8static void *smp_write_config_table(void *v)
9{
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020010 struct mp_config_table *mc;
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000011 struct device *riser = NULL, *firewire = NULL;
Patrick Georgi5244e1b2010-11-21 14:41:07 +000012 int firewire_bus = 0, riser_bus = 0, isa_bus;
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000013
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020014 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000015
Kyösti Mälkkidea42e02021-05-31 20:26:16 +030016 mptable_init(mc);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000017
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020018 smp_write_processors(mc);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000019
20 firewire = dev_find_device(0x104c, 0x8023, 0);
21 if (firewire) {
22 firewire_bus = firewire->bus->secondary;
23 printk(BIOS_SPEW, "Firewire device is on bus %x\n",
24 firewire_bus);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000025 }
26
27 // If a riser card is used, this riser is detected on bus 4, so its secondary bus is the
28 // highest bus number on the pci bus.
29 riser = dev_find_device(0x3388, 0x0021, 0);
30 if (!riser)
31 riser = dev_find_device(0x3388, 0x0022, 0);
32 if (riser) {
Myles Watson894a3472010-06-09 22:41:35 +000033 riser_bus = riser->link_list->secondary;
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000034 printk(BIOS_SPEW, "Riser bus is %x\n", riser_bus);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000035 }
36
Patrick Georgi5244e1b2010-11-21 14:41:07 +000037 mptable_write_buses(mc, NULL, &isa_bus);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000038
39 /* I/O APICs: APIC ID Version State Address */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030040 u8 ioapic_id = smp_write_ioapic_from_hw(mc, VIO_APIC_VADDR);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000041
42 /* Legacy Interrupts */
43
44 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
45 smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, ioapic_id, 0x0);
Kyösti Mälkki860cff92021-06-07 22:20:57 +030046 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x1, ioapic_id, 0x1);
47 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, ioapic_id, 0x2);
48 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x3, ioapic_id, 0x3);
49 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x4, ioapic_id, 0x4);
50 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, isa_bus, 0x8, ioapic_id, 0x8);
51 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x9, ioapic_id, 0x9);
52 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xa, ioapic_id, 0xa);
53 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xb, ioapic_id, 0xb);
54 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xc, ioapic_id, 0xc);
55 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xd, ioapic_id, 0xd);
56 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xe, ioapic_id, 0xe);
57 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xf, ioapic_id, 0xf);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000058
59 /* Builtin devices on Bus 0 */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030060 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x4, ioapic_id, 0x10);
61 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x8, ioapic_id, 0x10);
62 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x7d, ioapic_id, 0x13);
63 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x74, ioapic_id, 0x17);
64 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x75, ioapic_id, 0x13);
65 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x76, ioapic_id, 0x12);
66 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x77, ioapic_id, 0x10);
67 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x6c, ioapic_id, 0x10);
68 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x70, ioapic_id, 0x10);
69 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x71, ioapic_id, 0x11);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000070
71 /* Internal PCI bus (Firewire, PCI slot) */
72 if (firewire) {
Kyösti Mälkki860cff92021-06-07 22:20:57 +030073 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, firewire_bus, 0x0, ioapic_id,
74 0x10);
75 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, firewire_bus, 0x4, ioapic_id,
76 0x14);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000077 }
78
79 if (riser) {
80 /* Old riser card */
81 // riser slot top 5:8.0
Kyösti Mälkki860cff92021-06-07 22:20:57 +030082 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x20, ioapic_id,
83 0x14);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000084 // riser slot middle 5:9.0
Kyösti Mälkki860cff92021-06-07 22:20:57 +030085 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x24, ioapic_id,
86 0x15);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000087 // riser slot bottom 5:a.0
Kyösti Mälkki860cff92021-06-07 22:20:57 +030088 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x28, ioapic_id,
89 0x16);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000090
91 /* New Riser Card */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030092 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x30, ioapic_id,
93 0x14);
94 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x34, ioapic_id,
95 0x15);
96 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x38, ioapic_id,
97 0x16);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +000098 }
99
100 /* PCIe slot */
Kyösti Mälkki860cff92021-06-07 22:20:57 +0300101 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x1, 0x0, ioapic_id, 0x10);
102 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x1, 0x1, ioapic_id, 0x11);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +0000103
104 /* Onboard Ethernet */
Kyösti Mälkki860cff92021-06-07 22:20:57 +0300105 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x2, 0x0, ioapic_id, 0x10);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +0000106
107 /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200108 mptable_lintsrc(mc, isa_bus);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +0000109
110 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200111 return mptable_finalize(mc);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +0000112}
113
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +0000114unsigned long write_smp_table(unsigned long addr)
115{
116 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +0200117 v = smp_write_floating_table(addr, 1);
Bernhard M. Wiedemann6e554de2010-05-30 12:56:17 +0000118 return (unsigned long)smp_write_config_table(v);
119}