blob: f80b9740f6e80e5415a6549445f5920803c0826c [file] [log] [blame]
Sergej Ivanovd777c782015-04-03 18:10:27 +03001/*
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <console/console.h>
21#include <arch/smp/mpspec.h>
22#include <device/pci.h>
23#include <arch/io.h>
24#include <arch/ioapic.h>
25#include <string.h>
26#include <stdint.h>
27#include <cpu/amd/amdfam16.h>
28#include <arch/cpu.h>
29#include <cpu/x86/lapic.h>
Stefan Reinauer13e41822015-04-27 14:02:36 -070030#include <southbridge/amd/common/amd_pci_util.h>
Sergej Ivanovd777c782015-04-03 18:10:27 +030031#include <drivers/generic/ioapic/chip.h>
32
33static void *smp_write_config_table(void *v)
34{
35 struct mp_config_table *mc;
36 int bus_isa;
37
38 /*
39 * By the time this function gets called, the IOAPIC registers
40 * have been written so they can be read to get the correct
41 * APIC ID and Version
42 */
43 u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24);
44 u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF);
45
46 /* Intialize the MP_Table */
47 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
48
49 mptable_init(mc, LOCAL_APIC_ADDR);
50
51 /*
52 * Type 0: Processor Entries:
53 * LAPIC ID, LAPIC Version, CPU Flags:EN/BP,
54 * CPU Signature (Stepping, Model, Family),
55 * Feature Flags
56 */
57 smp_write_processors(mc);
58
59 /*
60 * Type 1: Bus Entries:
61 * Bus ID, Bus Type
62 */
63 mptable_write_buses(mc, NULL, &bus_isa);
64
65 /*
66 * Type 2: I/O APICs:
67 * APIC ID, Version, APIC Flags:EN, Address
68 */
69 smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR);
70
71 /*
72 * Type 3: I/O Interrupt Table Entries:
73 * Int Type, Int Polarity, Int Level, Source Bus ID,
74 * Source Bus IRQ, Dest APIC ID, Dest PIN#
75 */
76 mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0);
77
78 /* PCI interrupts are level triggered, and are
79 * associated with a specific bus/device/function tuple.
80 */
81#define PCI_INT(bus, dev, fn, pin) \
82 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(fn)), ioapic_id, (pin))
83
84 /* APU Internal Graphic Device */
85 PCI_INT(0x0, 0x01, 0x0, intr_data_ptr[PIRQ_C]);
86 PCI_INT(0x0, 0x01, 0x1, intr_data_ptr[PIRQ_D]);
87
88 /* SMBUS / ACPI */
89 PCI_INT(0x0, 0x14, 0x0, intr_data_ptr[PIRQ_SMBUS]);
90
91 /* Southbridge HD Audio */
92 PCI_INT(0x0, 0x14, 0x2, intr_data_ptr[PIRQ_HDA]);
93
94 /* LPC */
95 PCI_INT(0x0, 0x14, 0x3, intr_data_ptr[PIRQ_C]);
96
97 /* USB */
98 PCI_INT(0x0, 0x12, 0x0, intr_data_ptr[PIRQ_OHCI1]);
99 PCI_INT(0x0, 0x12, 0x2, intr_data_ptr[PIRQ_EHCI1]);
100 PCI_INT(0x0, 0x13, 0x0, intr_data_ptr[PIRQ_OHCI2]);
101 PCI_INT(0x0, 0x13, 0x2, intr_data_ptr[PIRQ_EHCI2]);
102 PCI_INT(0x0, 0x16, 0x0, intr_data_ptr[PIRQ_OHCI3]);
103 PCI_INT(0x0, 0x16, 0x2, intr_data_ptr[PIRQ_EHCI3]);
104 PCI_INT(0x0, 0x14, 0x2, intr_data_ptr[PIRQ_OHCI4]);
105
106 /* SATA */
107 PCI_INT(0x0, 0x11, 0x0, intr_data_ptr[PIRQ_SATA]);
108
109 /* on board NIC & Slot PCIE */
110 PCI_INT(0x1, 0x0, 0x0, intr_data_ptr[PIRQ_E]);
111 PCI_INT(0x2, 0x0, 0x0, intr_data_ptr[PIRQ_F]);
112
113 /* PCI slots */
114 device_t dev = dev_find_slot(0, PCI_DEVFN(0x14, 4));
115 if (dev && dev->enabled) {
116 u8 bus_pci = dev->link_list->secondary;
117 /* PCI_SLOT 0 */
118 PCI_INT(bus_pci, 0x5, 0x0, intr_data_ptr[PIRQ_E]);
119 PCI_INT(bus_pci, 0x5, 0x1, intr_data_ptr[PIRQ_F]);
120 PCI_INT(bus_pci, 0x5, 0x2, intr_data_ptr[PIRQ_G]);
121 PCI_INT(bus_pci, 0x5, 0x3, intr_data_ptr[PIRQ_H]);
122
123 /* PCI_SLOT 1 */
124 PCI_INT(bus_pci, 0x6, 0x0, intr_data_ptr[PIRQ_F]);
125 PCI_INT(bus_pci, 0x6, 0x1, intr_data_ptr[PIRQ_G]);
126 PCI_INT(bus_pci, 0x6, 0x2, intr_data_ptr[PIRQ_H]);
127 PCI_INT(bus_pci, 0x6, 0x3, intr_data_ptr[PIRQ_E]);
128
129 /* PCI_SLOT 2 */
130 PCI_INT(bus_pci, 0x7, 0x0, intr_data_ptr[PIRQ_G]);
131 PCI_INT(bus_pci, 0x7, 0x1, intr_data_ptr[PIRQ_H]);
132 PCI_INT(bus_pci, 0x7, 0x2, intr_data_ptr[PIRQ_E]);
133 PCI_INT(bus_pci, 0x7, 0x3, intr_data_ptr[PIRQ_F]);
134
135 PCI_INT(bus_pci, 0x0, 0x0, intr_data_ptr[PIRQ_C]);
136 PCI_INT(bus_pci, 0x0, 0x1, intr_data_ptr[PIRQ_D]);
137 PCI_INT(bus_pci, 0x0, 0x2, intr_data_ptr[PIRQ_E]);
138 }
139
140 /* PCIe Lan*/
141 //PCI_INT(0x0, 0x06, 0x0, intr_data_ptr[PIRQ_D]);
142
143 /* FCH PCIe PortA */
144 PCI_INT(0x0, 0x15, 0x0, intr_data_ptr[PIRQ_A]);
145 /* FCH PCIe PortB */
146 PCI_INT(0x0, 0x15, 0x1, intr_data_ptr[PIRQ_B]);
147 /* FCH PCIe PortC */
148 PCI_INT(0x0, 0x15, 0x2, intr_data_ptr[PIRQ_C]);
149 /* FCH PCIe PortD */
150 PCI_INT(0x0, 0x15, 0x3, intr_data_ptr[PIRQ_D]);
151
152 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
153#define IO_LOCAL_INT(type, intr, apicid, pin) \
154 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
155
156 IO_LOCAL_INT(mp_ExtINT, 0x0, MP_APIC_ALL, 0x0);
157 IO_LOCAL_INT(mp_NMI, 0x0, MP_APIC_ALL, 0x1);
158 /* There is no extension information... */
159
160 /* Compute the checksums */
161 return mptable_finalize(mc);
162}
163
164unsigned long write_smp_table(unsigned long addr)
165{
166 void *v;
167 v = smp_write_floating_table(addr, 0);
168 return (unsigned long)smp_write_config_table(v);
169}