blob: 5d8eb4d3aa2e2e0e9ef54d39b23db69fccd6e32c [file] [log] [blame]
Angel Pons89ab2502020-04-03 01:22:28 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Edward O'Callaghan32960e32014-11-23 17:38:52 +11002
Edward O'Callaghan32960e32014-11-23 17:38:52 +11003#include <arch/io.h>
4#include <arch/ioapic.h>
5#include <arch/smp/mpspec.h>
Edward O'Callaghan32960e32014-11-23 17:38:52 +11006#include <stdint.h>
7#include <string.h>
Kyösti Mälkki11f34432016-05-26 11:21:02 +03008#include <southbridge/amd/agesa/hudson/hudson.h>
Edward O'Callaghan32960e32014-11-23 17:38:52 +11009
Edward O'Callaghan32960e32014-11-23 17:38:52 +110010u8 picr_data[0x54] = {
11 0x1F,0x1f,0x1f,0x1F,0x1F,0x1F,0x1F,0x1F,0x0A,0xF1,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
12 0x09,0x1F,0x1F,0x0B,0x1F,0x0B,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
13 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
14 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
15 0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
16 0x1F,0x1F,0x1F,0x1F
17};
18u8 intr_data[0x54] = {
19 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
20 0x09,0x1F,0x1F,0x10,0x1F,0x10,0x1F,0x10,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
21 0x05,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
22 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
23 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
24 0x10,0x11,0x12,0x13
25};
26
Martin Rothad0f4852019-10-23 21:41:43 -060027static void smp_add_mpc_entry(struct mp_config_table *mc, unsigned int length)
Edward O'Callaghan32960e32014-11-23 17:38:52 +110028{
29 mc->mpc_length += length;
30 mc->mpc_entry_count++;
31}
32
33static void my_smp_write_bus(struct mp_config_table *mc,
34 unsigned char id, const char *bustype)
35{
36 struct mpc_config_bus *mpc;
37 mpc = smp_next_mpc_entry(mc);
38 memset(mpc, '\0', sizeof(*mpc));
39 mpc->mpc_type = MP_BUS;
40 mpc->mpc_busid = id;
41 memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype));
42 smp_add_mpc_entry(mc, sizeof(*mpc));
43}
44
45static void *smp_write_config_table(void *v)
46{
47 struct mp_config_table *mc;
48 int bus_isa;
49 u8 byte;
50
51 /*
52 * By the time this function gets called, the IOAPIC registers
53 * have been written so they can be read to get the correct
54 * APIC ID and Version
55 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080056 u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24);
57 u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF);
Edward O'Callaghan32960e32014-11-23 17:38:52 +110058
59 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
60
61 mptable_init(mc, LOCAL_APIC_ADDR);
62 memcpy(mc->mpc_oem, "AMD ", 8);
63
64 smp_write_processors(mc);
65
66 //mptable_write_buses(mc, NULL, &bus_isa);
67 my_smp_write_bus(mc, 0, "PCI ");
68 my_smp_write_bus(mc, 1, "PCI ");
69 bus_isa = 0x02;
70 my_smp_write_bus(mc, bus_isa, "ISA ");
71
72 /* I/O APICs: APIC ID Version State Address */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080073 smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR);
Edward O'Callaghan32960e32014-11-23 17:38:52 +110074
75 /* PIC IRQ routine */
76 for (byte = 0x0; byte < sizeof(picr_data); byte ++) {
77 outb(byte, 0xC00);
78 outb(picr_data[byte], 0xC01);
79 }
80
81 /* APIC IRQ routine */
82 for (byte = 0x0; byte < sizeof(intr_data); byte ++) {
83 outb(byte | 0x80, 0xC00);
84 outb(intr_data[byte], 0xC01);
85 }
86
87 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
88#define IO_LOCAL_INT(type, intr, apicid, pin) \
89 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
90 mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0);
91
92 /* PCI interrupts are level triggered, and are
93 * associated with a specific bus/device/function tuple.
94 */
95#define PCI_INT(bus, dev, int_sign, pin) \
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020096 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(int_sign)), ioapic_id, (pin))
Edward O'Callaghan32960e32014-11-23 17:38:52 +110097
Edward O'Callaghan14581fc62014-12-05 04:25:44 +110098 /* IOMMU */
99 PCI_INT(0x0, 0x00, 0x0, 0x10);
100 PCI_INT(0x0, 0x00, 0x1, 0x11);
101 PCI_INT(0x0, 0x00, 0x2, 0x12);
102 PCI_INT(0x0, 0x00, 0x3, 0x13);
103
Edward O'Callaghan32960e32014-11-23 17:38:52 +1100104 /* Internal VGA */
105 PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]);
106 PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]);
107
108 /* SMBUS */
109 PCI_INT(0x0, 0x14, 0x0, 0x10);
110
111 /* HD Audio */
112 PCI_INT(0x0, 0x14, 0x0, intr_data[0x13]);
113
114 /* USB */
115 PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]);
116 PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]);
117 PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]);
118 PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]);
119 PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]);
120 PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]);
121 PCI_INT(0x0, 0x14, 0x2, intr_data[0x36]);
122
123 /* sata */
124 PCI_INT(0x0, 0x11, 0x0, intr_data[0x40]);
125 PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]);
126
Edward O'Callaghan32960e32014-11-23 17:38:52 +1100127 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
128 IO_LOCAL_INT(mp_ExtINT, 0, MP_APIC_ALL, 0x0);
129 IO_LOCAL_INT(mp_NMI, 0, MP_APIC_ALL, 0x1);
130 /* There is no extension information... */
131
132 /* Compute the checksums */
133 return mptable_finalize(mc);
134}
135
136unsigned long write_smp_table(unsigned long addr)
137{
138 void *v;
139 v = smp_write_floating_table(addr, 0);
140 return (unsigned long)smp_write_config_table(v);
141}