blob: 9e63cafa027da1b86ce3e2a4598d89407193ace6 [file] [log] [blame]
Edward O'Callaghan32960e32014-11-23 17:38:52 +11001/*
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.
Edward O'Callaghan32960e32014-11-23 17:38:52 +110014 */
15
16#include <arch/cpu.h>
17#include <arch/io.h>
18#include <arch/ioapic.h>
19#include <arch/smp/mpspec.h>
20#include <console/console.h>
21#include <cpu/amd/amdfam15.h>
22#include <cpu/x86/lapic.h>
23#include <device/pci.h>
24#include <stdint.h>
25#include <string.h>
Kyösti Mälkki11f34432016-05-26 11:21:02 +030026#include <southbridge/amd/agesa/hudson/hudson.h>
Edward O'Callaghan32960e32014-11-23 17:38:52 +110027
28
29u8 picr_data[0x54] = {
30 0x1F,0x1f,0x1f,0x1F,0x1F,0x1F,0x1F,0x1F,0x0A,0xF1,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
31 0x09,0x1F,0x1F,0x0B,0x1F,0x0B,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
33 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
35 0x1F,0x1F,0x1F,0x1F
36};
37u8 intr_data[0x54] = {
38 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
39 0x09,0x1F,0x1F,0x10,0x1F,0x10,0x1F,0x10,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40 0x05,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
41 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
42 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
43 0x10,0x11,0x12,0x13
44};
45
46static void smp_add_mpc_entry(struct mp_config_table *mc, unsigned length)
47{
48 mc->mpc_length += length;
49 mc->mpc_entry_count++;
50}
51
52static void my_smp_write_bus(struct mp_config_table *mc,
53 unsigned char id, const char *bustype)
54{
55 struct mpc_config_bus *mpc;
56 mpc = smp_next_mpc_entry(mc);
57 memset(mpc, '\0', sizeof(*mpc));
58 mpc->mpc_type = MP_BUS;
59 mpc->mpc_busid = id;
60 memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype));
61 smp_add_mpc_entry(mc, sizeof(*mpc));
62}
63
64static void *smp_write_config_table(void *v)
65{
66 struct mp_config_table *mc;
67 int bus_isa;
68 u8 byte;
69
70 /*
71 * By the time this function gets called, the IOAPIC registers
72 * have been written so they can be read to get the correct
73 * APIC ID and Version
74 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080075 u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24);
76 u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF);
Edward O'Callaghan32960e32014-11-23 17:38:52 +110077
78 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
79
80 mptable_init(mc, LOCAL_APIC_ADDR);
81 memcpy(mc->mpc_oem, "AMD ", 8);
82
83 smp_write_processors(mc);
84
85 //mptable_write_buses(mc, NULL, &bus_isa);
86 my_smp_write_bus(mc, 0, "PCI ");
87 my_smp_write_bus(mc, 1, "PCI ");
88 bus_isa = 0x02;
89 my_smp_write_bus(mc, bus_isa, "ISA ");
90
91 /* I/O APICs: APIC ID Version State Address */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080092 smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR);
Edward O'Callaghan32960e32014-11-23 17:38:52 +110093
94 /* PIC IRQ routine */
95 for (byte = 0x0; byte < sizeof(picr_data); byte ++) {
96 outb(byte, 0xC00);
97 outb(picr_data[byte], 0xC01);
98 }
99
100 /* APIC IRQ routine */
101 for (byte = 0x0; byte < sizeof(intr_data); byte ++) {
102 outb(byte | 0x80, 0xC00);
103 outb(intr_data[byte], 0xC01);
104 }
105
106 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
107#define IO_LOCAL_INT(type, intr, apicid, pin) \
108 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
109 mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0);
110
111 /* PCI interrupts are level triggered, and are
112 * associated with a specific bus/device/function tuple.
113 */
114#define PCI_INT(bus, dev, int_sign, pin) \
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200115 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 +1100116
Edward O'Callaghan14581fc62014-12-05 04:25:44 +1100117 /* IOMMU */
118 PCI_INT(0x0, 0x00, 0x0, 0x10);
119 PCI_INT(0x0, 0x00, 0x1, 0x11);
120 PCI_INT(0x0, 0x00, 0x2, 0x12);
121 PCI_INT(0x0, 0x00, 0x3, 0x13);
122
Edward O'Callaghan32960e32014-11-23 17:38:52 +1100123 /* Internal VGA */
124 PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]);
125 PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]);
126
127 /* SMBUS */
128 PCI_INT(0x0, 0x14, 0x0, 0x10);
129
130 /* HD Audio */
131 PCI_INT(0x0, 0x14, 0x0, intr_data[0x13]);
132
133 /* USB */
134 PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]);
135 PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]);
136 PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]);
137 PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]);
138 PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]);
139 PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]);
140 PCI_INT(0x0, 0x14, 0x2, intr_data[0x36]);
141
142 /* sata */
143 PCI_INT(0x0, 0x11, 0x0, intr_data[0x40]);
144 PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]);
145
146 /* on board NIC & Slot PCIE. */
147
148 /* PCI slots */
149 device_t dev = dev_find_slot(0, PCI_DEVFN(0x14, 4));
150 if (dev && dev->enabled) {
151 u8 bus_pci = dev->link_list->secondary;
152 /* PCI_SLOT 0. */
153 PCI_INT(bus_pci, 0x5, 0x0, 0x14);
154 PCI_INT(bus_pci, 0x5, 0x1, 0x15);
155 PCI_INT(bus_pci, 0x5, 0x2, 0x16);
156 PCI_INT(bus_pci, 0x5, 0x3, 0x17);
157
158 /* PCI_SLOT 1. */
159 PCI_INT(bus_pci, 0x6, 0x0, 0x15);
160 PCI_INT(bus_pci, 0x6, 0x1, 0x16);
161 PCI_INT(bus_pci, 0x6, 0x2, 0x17);
162 PCI_INT(bus_pci, 0x6, 0x3, 0x14);
163
164 /* PCI_SLOT 2. */
165 PCI_INT(bus_pci, 0x7, 0x0, 0x16);
166 PCI_INT(bus_pci, 0x7, 0x1, 0x17);
167 PCI_INT(bus_pci, 0x7, 0x2, 0x14);
168 PCI_INT(bus_pci, 0x7, 0x3, 0x15);
169 }
170
171 /* PCIe Lan*/
172 PCI_INT(0x0, 0x06, 0x0, 0x13);
173
174 /* FCH PCIe PortA */
175 PCI_INT(0x0, 0x15, 0x0, 0x10);
176 /* FCH PCIe PortB */
177 PCI_INT(0x0, 0x15, 0x1, 0x11);
178 /* FCH PCIe PortC */
179 PCI_INT(0x0, 0x15, 0x2, 0x12);
180 /* FCH PCIe PortD */
181 PCI_INT(0x0, 0x15, 0x3, 0x13);
182
183 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
184 IO_LOCAL_INT(mp_ExtINT, 0, MP_APIC_ALL, 0x0);
185 IO_LOCAL_INT(mp_NMI, 0, MP_APIC_ALL, 0x1);
186 /* There is no extension information... */
187
188 /* Compute the checksums */
189 return mptable_finalize(mc);
190}
191
192unsigned long write_smp_table(unsigned long addr)
193{
194 void *v;
195 v = smp_write_floating_table(addr, 0);
196 return (unsigned long)smp_write_config_table(v);
197}