blob: 903283c339b52e2302aab5ac7c32d06cc41dd09f [file] [log] [blame]
Angel Ponsa21dff62020-04-03 01:22:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer36a22682008-10-29 04:52:57 +00002
Stefan Reinauer36a22682008-10-29 04:52:57 +00003#include <device/device.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +00004#include <arch/smp/mpspec.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +00005#include <arch/ioapic.h>
Stefan Reinauer36a22682008-10-29 04:52:57 +00006
Stefan Reinauerde3206a2010-02-22 06:09:43 +00007static void *smp_write_config_table(void *v)
Stefan Reinauer36a22682008-10-29 04:52:57 +00008{
Elyes HAOUAS8da96e52016-09-22 21:20:54 +02009 struct mp_config_table *mc;
Stefan Reinauer762a2302010-01-19 21:15:37 +000010 struct device *riser = NULL, *firewire = NULL;
Patrick Georgiab272662010-06-25 13:43:22 +000011 int firewire_bus = 0, riser_bus = 0, isa_bus;
Stefan Reinauer36a22682008-10-29 04:52:57 +000012
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020013 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Stefan Reinauer36a22682008-10-29 04:52:57 +000014
Kyösti Mälkkidea42e02021-05-31 20:26:16 +030015 mptable_init(mc);
Stefan Reinauer36a22682008-10-29 04:52:57 +000016
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020017 smp_write_processors(mc);
Stefan Reinauer36a22682008-10-29 04:52:57 +000018
Stefan Reinauer762a2302010-01-19 21:15:37 +000019 firewire = dev_find_device(0x104c, 0x8023, 0);
20 if (firewire) {
21 firewire_bus = firewire->bus->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000022 }
23
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020024 /* If a riser card is used, this riser is detected on bus 4, so its secondary bus is the */
25 /* highest bus number on the pci bus. */
Stefan Reinauer762a2302010-01-19 21:15:37 +000026 riser = dev_find_device(0x3388, 0x0021, 0);
27 if (!riser)
28 riser = dev_find_device(0x3388, 0x0022, 0);
29 if (riser) {
Myles Watson894a3472010-06-09 22:41:35 +000030 riser_bus = riser->link_list->secondary;
Stefan Reinauer762a2302010-01-19 21:15:37 +000031 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000032
Patrick Georgiab272662010-06-25 13:43:22 +000033 mptable_write_buses(mc, NULL, &isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +000034
35 /* I/O APICs: APIC ID Version State Address */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030036 u8 ioapic_id = smp_write_ioapic_from_hw(mc, VIO_APIC_VADDR);
Stefan Reinauer36a22682008-10-29 04:52:57 +000037
38 /* Legacy Interrupts */
Patrick Georgic5b87c82010-05-20 15:28:19 +000039 mptable_add_isa_interrupts(mc, isa_bus, ioapic_id, 0);
Stefan Reinauer36a22682008-10-29 04:52:57 +000040
41 /* Builtin devices on Bus 0 */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030042 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x4, ioapic_id, 0x10);
43 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x8, ioapic_id, 0x10);
44 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x7d, ioapic_id, 0x13);
45 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x74, ioapic_id, 0x17);
46 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x75, ioapic_id, 0x13);
47 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x76, ioapic_id, 0x12);
48 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x77, ioapic_id, 0x10);
49 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x6c, ioapic_id, 0x10);
50 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x0, 0x70, ioapic_id, 0x10);
51 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 +000052
Stefan Reinauerde3206a2010-02-22 06:09:43 +000053 /* Internal PCI bus (Firewire, PCI slot) */
Stefan Reinauer762a2302010-01-19 21:15:37 +000054 if (firewire) {
Kyösti Mälkki860cff92021-06-07 22:20:57 +030055 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, firewire_bus, 0x0, ioapic_id,
56 0x10);
57 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, firewire_bus, 0x4, ioapic_id,
58 0x14);
Stefan Reinauer762a2302010-01-19 21:15:37 +000059 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000060
Stefan Reinauer762a2302010-01-19 21:15:37 +000061 if (riser) {
62 /* Old riser card */
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020063 /* riser slot top 5:8.0 */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030064 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x20, ioapic_id,
65 0x14);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020066 /* riser slot middle 5:9.0 */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030067 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x24, ioapic_id,
68 0x15);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020069 /* riser slot bottom 5:a.0 */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030070 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x28, ioapic_id,
71 0x16);
Stefan Reinauer36a22682008-10-29 04:52:57 +000072
Stefan Reinauer762a2302010-01-19 21:15:37 +000073 /* New Riser Card */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030074 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x30, ioapic_id,
75 0x14);
76 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x34, ioapic_id,
77 0x15);
78 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, riser_bus, 0x38, ioapic_id,
79 0x16);
Stefan Reinauer762a2302010-01-19 21:15:37 +000080 }
Stefan Reinauere1025d02009-03-11 15:20:36 +000081
Stefan Reinauerde3206a2010-02-22 06:09:43 +000082 /* PCIe slot */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030083 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x1, 0x0, ioapic_id, 0x10);
84 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW, 0x1, 0x1, ioapic_id, 0x11);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000085
Stefan Reinauer36a22682008-10-29 04:52:57 +000086 /* Onboard Ethernet */
Kyösti Mälkki860cff92021-06-07 22:20:57 +030087 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 +000088
89 /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Patrick Georgi6eb7a532011-10-07 21:42:52 +020090 mptable_lintsrc(mc, isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +000091
92 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +020093 return mptable_finalize(mc);
Stefan Reinauer36a22682008-10-29 04:52:57 +000094}
95
96unsigned long write_smp_table(unsigned long addr)
97{
98 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +020099 v = smp_write_floating_table(addr, 1);
Stefan Reinauer36a22682008-10-29 04:52:57 +0000100 return (unsigned long)smp_write_config_table(v);
101}