blob: a3c8e517bb007d8d7f4da2dbd27992b6c34e0688 [file] [log] [blame]
WANG Siyuanf77f7342013-08-13 17:09:51 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 *
6 * 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.
9 *
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.
WANG Siyuanf77f7342013-08-13 17:09:51 +080014 */
15
WANG Siyuanf77f7342013-08-13 17:09:51 +080016#include <arch/smp/mpspec.h>
17#include <device/pci.h>
18#include <arch/io.h>
Kyösti Mälkkib4261072014-07-22 10:24:20 +030019#include <arch/ioapic.h>
WANG Siyuanf77f7342013-08-13 17:09:51 +080020#include <string.h>
21#include <stdint.h>
WANG Siyuanf77f7342013-08-13 17:09:51 +080022#include <cpu/x86/lapic.h>
Elyes HAOUAS4ad14462018-06-16 18:29:33 +020023#include <southbridge/amd/agesa/hudson/hudson.h>
WANG Siyuanf77f7342013-08-13 17:09:51 +080024
WANG Siyuanf77f7342013-08-13 17:09:51 +080025
26u8 picr_data[0x54] = {
27 0x03,0x04,0x05,0x07,0x0B,0x0A,0x1F,0x1F,0xFA,0xF1,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
28 0x1F,0x1F,0x1F,0x03,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
29 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
30 0x05,0x04,0x05,0x04,0x04,0x05,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
31 0x04,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32 0x03,0x04,0x05,0x07
33};
34u8 intr_data[0x54] = {
35 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
36 0x09,0x1F,0x1F,0x10,0x1F,0x10,0x1F,0x10,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
37 0x05,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
38 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
39 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40 0x10,0x11,0x12,0x13
41};
42
Martin Rothad0f4852019-10-23 21:41:43 -060043static void smp_add_mpc_entry(struct mp_config_table *mc, unsigned int length)
WANG Siyuanf77f7342013-08-13 17:09:51 +080044{
45 mc->mpc_length += length;
46 mc->mpc_entry_count++;
47}
48
49static void my_smp_write_bus(struct mp_config_table *mc,
50 unsigned char id, const char *bustype)
51{
52 struct mpc_config_bus *mpc;
53 mpc = smp_next_mpc_entry(mc);
54 memset(mpc, '\0', sizeof(*mpc));
55 mpc->mpc_type = MP_BUS;
56 mpc->mpc_busid = id;
57 memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype));
58 smp_add_mpc_entry(mc, sizeof(*mpc));
59}
60
61static void *smp_write_config_table(void *v)
62{
63 struct mp_config_table *mc;
64 int bus_isa;
WANG Siyuanf77f7342013-08-13 17:09:51 +080065 u8 byte;
66
Kyösti Mälkkib4261072014-07-22 10:24:20 +030067 /*
68 * By the time this function gets called, the IOAPIC registers
69 * have been written so they can be read to get the correct
70 * APIC ID and Version
71 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080072 u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24);
73 u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF);
Kyösti Mälkkib4261072014-07-22 10:24:20 +030074
WANG Siyuanf77f7342013-08-13 17:09:51 +080075 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
76
77 mptable_init(mc, LOCAL_APIC_ADDR);
78 memcpy(mc->mpc_oem, "AMD ", 8);
79
80 smp_write_processors(mc);
81
WANG Siyuanf77f7342013-08-13 17:09:51 +080082 //mptable_write_buses(mc, NULL, &bus_isa);
83 my_smp_write_bus(mc, 0, "PCI ");
84 my_smp_write_bus(mc, 1, "PCI ");
85 bus_isa = 0x02;
86 my_smp_write_bus(mc, bus_isa, "ISA ");
87
88 /* I/O APICs: APIC ID Version State Address */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080089 smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR);
WANG Siyuanf77f7342013-08-13 17:09:51 +080090
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080091 smp_write_ioapic(mc, ioapic_id+1, 0x21, (void *)0xFEC20000);
WANG Siyuanf77f7342013-08-13 17:09:51 +080092 /* PIC IRQ routine */
93 for (byte = 0x0; byte < sizeof(picr_data); byte ++) {
94 outb(byte, 0xC00);
95 outb(picr_data[byte], 0xC01);
96 }
97
98 /* APIC IRQ routine */
99 for (byte = 0x0; byte < sizeof(intr_data); byte ++) {
100 outb(byte | 0x80, 0xC00);
101 outb(intr_data[byte], 0xC01);
102 }
103#if 0
104 outb(0x0B, 0xCD6);
105 outb(0x02, 0xCD7);
106
107 outb(0x50, 0xCD6);
108 outb(0x1F, 0xCD7);
109
110 outb(0x48, 0xCD6);
111 outb(0xF2, 0xCD7);
112
113 //outb(0xBE, 0xCD6);
114 //outb(0x52, 0xCD7);
115
116 outb(0xED, 0xCD6);
117 outb(0x17, 0xCD7);
118
119 *(volatile u8 *) (0xFED80D00 + 0x31) = 2;
120 *(volatile u8 *) (0xFED80D00 + 0x32) = 2;
121 *(volatile u8 *) (0xFED80D00 + 0x33) = 2;
122 *(volatile u8 *) (0xFED80D00 + 0x34) = 2;
123
124 *(volatile u8 *) (0xFED80100 + 0x31) = 0xc8;
125 *(volatile u8 *) (0xFED80100 + 0x32) = 0xc8;
126 *(volatile u8 *) (0xFED80100 + 0x33) = 0xc8;
127 *(volatile u8 *) (0xFED80100 + 0x34) = 0xa0;
128
129 *(volatile u8 *) (0xFED80D00 + 0x6c) = 1;
130 *(volatile u8 *) (0xFED80D00 + 0x6E) = 2;
131 *(volatile u8 *) (0xFED80D00 + 0x6f) = 2;
132
133 *(volatile u8 *) (0xFED80100 + 0x6c) = 0xa0;
134 *(volatile u8 *) (0xFED80100 + 0x6E) = 0xa8;
135 *(volatile u8 *) (0xFED80100 + 0x6f) = 0xa0;
136
137 *(volatile u8 *) (0xFED80D00 + 0xA6) = 2;
138 *(volatile u8 *) (0xFED80100 + 0xA6) = 0;
139
140 *(volatile u8 *) (0xFED80100 + 0x40) = 0xC8;
141#endif
142 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
143#define IO_LOCAL_INT(type, intr, apicid, pin) \
144 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
Kyösti Mälkkib4261072014-07-22 10:24:20 +0300145 mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0);
WANG Siyuanf77f7342013-08-13 17:09:51 +0800146
147 /* PCI interrupts are level triggered, and are
148 * associated with a specific bus/device/function tuple.
149 */
150#define PCI_INT(bus, dev, int_sign, pin) \
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200151 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(int_sign)), ioapic_id, (pin))
WANG Siyuanf77f7342013-08-13 17:09:51 +0800152
153 /* Internal VGA */
154 PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]);
155 PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]);
156
157 /* SMBUS */
158 PCI_INT(0x0, 0x14, 0x0, 0x10);
159
160 /* HD Audio */
161 PCI_INT(0x0, 0x14, 0x0, intr_data[0x13]);
162
163 /* USB */
164 PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]);
165 PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]);
166 PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]);
167 PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]);
168 PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]);
169 PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]);
170 PCI_INT(0x0, 0x14, 0x2, intr_data[0x36]);
171
172 /* sata */
173 PCI_INT(0x0, 0x11, 0x0, intr_data[0x40]);
174 PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]);
175
176 /* on board NIC & Slot PCIE. */
177
178 /* PCI slots */
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300179 struct device *dev = pcidev_on_root(0x14, 4);
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300180 if (dev && dev->enabled) {
181 u8 bus_pci = dev->link_list->secondary;
182 /* PCI_SLOT 0. */
183 PCI_INT(bus_pci, 0x5, 0x0, 0x14);
184 PCI_INT(bus_pci, 0x5, 0x1, 0x15);
185 PCI_INT(bus_pci, 0x5, 0x2, 0x16);
186 PCI_INT(bus_pci, 0x5, 0x3, 0x17);
WANG Siyuanf77f7342013-08-13 17:09:51 +0800187
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300188 /* PCI_SLOT 1. */
189 PCI_INT(bus_pci, 0x6, 0x0, 0x15);
190 PCI_INT(bus_pci, 0x6, 0x1, 0x16);
191 PCI_INT(bus_pci, 0x6, 0x2, 0x17);
192 PCI_INT(bus_pci, 0x6, 0x3, 0x14);
WANG Siyuanf77f7342013-08-13 17:09:51 +0800193
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300194 /* PCI_SLOT 2. */
195 PCI_INT(bus_pci, 0x7, 0x0, 0x16);
196 PCI_INT(bus_pci, 0x7, 0x1, 0x17);
197 PCI_INT(bus_pci, 0x7, 0x2, 0x14);
198 PCI_INT(bus_pci, 0x7, 0x3, 0x15);
199 }
WANG Siyuanf77f7342013-08-13 17:09:51 +0800200
201 /* PCIe Lan*/
202 PCI_INT(0x0, 0x06, 0x0, 0x13);
203
204 /* FCH PCIe PortA */
205 PCI_INT(0x0, 0x15, 0x0, 0x10);
206 /* FCH PCIe PortB */
207 PCI_INT(0x0, 0x15, 0x1, 0x11);
208 /* FCH PCIe PortC */
209 PCI_INT(0x0, 0x15, 0x2, 0x12);
210 /* FCH PCIe PortD */
211 PCI_INT(0x0, 0x15, 0x3, 0x13);
212
213 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
214 IO_LOCAL_INT(mp_ExtINT, 0, MP_APIC_ALL, 0x0);
215 IO_LOCAL_INT(mp_NMI, 0, MP_APIC_ALL, 0x1);
216 /* There is no extension information... */
217
218 /* Compute the checksums */
219 return mptable_finalize(mc);
220}
221
222unsigned long write_smp_table(unsigned long addr)
223{
224 void *v;
225 v = smp_write_floating_table(addr, 0);
226 return (unsigned long)smp_write_config_table(v);
227}