blob: b0bfbe71c5b1aaad813b72c015cdf046ef0bd4da [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) {
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020021 firewire_bus = firewire->upstream->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) {
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020030 riser_bus = riser->downstream->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älkki7742aed2021-06-07 22:18:35 +030042 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x01, 0, ioapic_id, 0x10);
43 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x02, 0, ioapic_id, 0x10);
44 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1f, 1, ioapic_id, 0x13);
45 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1d, 0, ioapic_id, 0x17);
46 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1d, 1, ioapic_id, 0x13);
47 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1d, 2, ioapic_id, 0x12);
48 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1d, 3, ioapic_id, 0x10);
49 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1b, 0, ioapic_id, 0x10);
50 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1c, 0, ioapic_id, 0x10);
51 smp_write_pci_intsrc(mc, mp_INT, 0x0, 0x1c, 1, 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älkki7742aed2021-06-07 22:18:35 +030055 smp_write_pci_intsrc(mc, mp_INT, firewire_bus, 0x00, 0, ioapic_id, 0x10);
56 smp_write_pci_intsrc(mc, mp_INT, firewire_bus, 0x01, 0, ioapic_id, 0x14);
Stefan Reinauer762a2302010-01-19 21:15:37 +000057 }
Stefan Reinauer36a22682008-10-29 04:52:57 +000058
Stefan Reinauer762a2302010-01-19 21:15:37 +000059 if (riser) {
60 /* Old riser card */
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020061 /* riser slot top 5:8.0 */
Kyösti Mälkki7742aed2021-06-07 22:18:35 +030062 smp_write_pci_intsrc(mc, mp_INT, riser_bus, 0x08, 0, ioapic_id, 0x14);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020063 /* riser slot middle 5:9.0 */
Kyösti Mälkki7742aed2021-06-07 22:18:35 +030064 smp_write_pci_intsrc(mc, mp_INT, riser_bus, 0x09, 0, ioapic_id, 0x15);
Elyes HAOUASf10b5ff2016-10-06 19:49:55 +020065 /* riser slot bottom 5:a.0 */
Kyösti Mälkki7742aed2021-06-07 22:18:35 +030066 smp_write_pci_intsrc(mc, mp_INT, riser_bus, 0x0a, 0, ioapic_id, 0x16);
Stefan Reinauer36a22682008-10-29 04:52:57 +000067
Stefan Reinauer762a2302010-01-19 21:15:37 +000068 /* New Riser Card */
Kyösti Mälkki7742aed2021-06-07 22:18:35 +030069 smp_write_pci_intsrc(mc, mp_INT, riser_bus, 0x0c, 0, ioapic_id, 0x14);
70 smp_write_pci_intsrc(mc, mp_INT, riser_bus, 0x0d, 0, ioapic_id, 0x15);
71 smp_write_pci_intsrc(mc, mp_INT, riser_bus, 0x0e, 0, ioapic_id, 0x16);
Stefan Reinauer762a2302010-01-19 21:15:37 +000072 }
Stefan Reinauere1025d02009-03-11 15:20:36 +000073
Stefan Reinauerde3206a2010-02-22 06:09:43 +000074 /* PCIe slot */
Kyösti Mälkki7742aed2021-06-07 22:18:35 +030075 smp_write_pci_intsrc(mc, mp_INT, 0x1, 0x00, 0, ioapic_id, 0x10);
76 smp_write_pci_intsrc(mc, mp_INT, 0x1, 0x00, 1, ioapic_id, 0x11);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000077
Stefan Reinauer36a22682008-10-29 04:52:57 +000078 /* Onboard Ethernet */
Kyösti Mälkki7742aed2021-06-07 22:18:35 +030079 smp_write_pci_intsrc(mc, mp_INT, 0x2, 0x00, 0, ioapic_id, 0x10);
Stefan Reinauer36a22682008-10-29 04:52:57 +000080
81 /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Patrick Georgi6eb7a532011-10-07 21:42:52 +020082 mptable_lintsrc(mc, isa_bus);
Stefan Reinauer36a22682008-10-29 04:52:57 +000083
84 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +020085 return mptable_finalize(mc);
Stefan Reinauer36a22682008-10-29 04:52:57 +000086}
87
88unsigned long write_smp_table(unsigned long addr)
89{
90 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +020091 v = smp_write_floating_table(addr, 1);
Stefan Reinauer36a22682008-10-29 04:52:57 +000092 return (unsigned long)smp_write_config_table(v);
93}