blob: 19a9f35b97be9a5cf37685e5c9a8290f07d52bf3 [file] [log] [blame]
Kerry Shehb7993512011-11-15 21:27:07 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 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.
Kerry Shehb7993512011-11-15 21:27:07 +080014 */
15
16
17#include <console/console.h>
18#include <arch/smp/mpspec.h>
19#include <device/pci.h>
20#include <arch/io.h>
Kyösti Mälkkib4261072014-07-22 10:24:20 +030021#include <arch/ioapic.h>
Kerry Shehb7993512011-11-15 21:27:07 +080022#include <string.h>
23#include <stdint.h>
24#include <cpu/amd/amdfam14.h>
25#include <SBPLATFORM.h>
26
Kerry Shehb7993512011-11-15 21:27:07 +080027
Kerry Shehb7993512011-11-15 21:27:07 +080028u8 intr_data[] = {
29 [0x00] = 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, /* INTA# - INTH# */
30 [0x08] = 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F, /* Misc-nil,0,1,2, INT from Serial irq */
31 [0x10] = 0x09,0x1F,0x1F,0x10,0x1F,0x12,0x1F,0x00,0x00,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 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
35 0x10,0x11,0x12,0x13
36};
37
38static void *smp_write_config_table(void *v)
39{
40 struct mp_config_table *mc;
41 int bus_isa;
42
Kyösti Mälkkib4261072014-07-22 10:24:20 +030043 /*
44 * By the time this function gets called, the IOAPIC registers
45 * have been written so they can be read to get the correct
46 * APIC ID and Version
47 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080048 u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24);
49 u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF);
Kyösti Mälkkib4261072014-07-22 10:24:20 +030050
Kerry Shehb7993512011-11-15 21:27:07 +080051 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
52
Patrick Georgic8feedd2012-02-16 18:43:25 +010053 mptable_init(mc, LOCAL_APIC_ADDR);
Kerry Shehb7993512011-11-15 21:27:07 +080054 memcpy(mc->mpc_oem, "AMD ", 8);
55
56 smp_write_processors(mc);
57
Kerry Shehb7993512011-11-15 21:27:07 +080058 mptable_write_buses(mc, NULL, &bus_isa);
59
60 /* I/O APICs: APIC ID Version State Address */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080061 smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR);
Patrick Georgi472efa62012-02-16 20:44:20 +010062
Kerry Shehb7993512011-11-15 21:27:07 +080063 u8 byte;
Patrick Georgi472efa62012-02-16 20:44:20 +010064
Kerry Shehb7993512011-11-15 21:27:07 +080065 for (byte = 0x0; byte < sizeof(intr_data); byte ++) {
66 outb(byte | 0x80, 0xC00);
67 outb(intr_data[byte], 0xC01);
68 }
69
70 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
71#define IO_LOCAL_INT(type, intr, apicid, pin) \
72 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
73
Kyösti Mälkkib4261072014-07-22 10:24:20 +030074 mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0);
Kerry Shehb7993512011-11-15 21:27:07 +080075
76 /* PCI interrupts are level triggered, and are
77 * associated with a specific bus/device/function tuple.
78 */
Kerry Shehb7993512011-11-15 21:27:07 +080079#define PCI_INT(bus, dev, fn, pin) \
Kyösti Mälkkib4261072014-07-22 10:24:20 +030080 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(fn)), ioapic_id, (pin))
Kerry Shehb7993512011-11-15 21:27:07 +080081
Kerry Sheh28f17102011-12-22 12:18:26 +080082 /* APU Internal Graphic Device*/
83 PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]);
84 PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]);
85
Kerry Shehb7993512011-11-15 21:27:07 +080086 //PCI_INT(0x0, 0x14, 0x1, 0x11); /* IDE. */
87 PCI_INT(0x0, 0x14, 0x0, 0x10);
Kerry Sheh28f17102011-12-22 12:18:26 +080088 /* Southbridge HD Audio: */
Kerry Shehb7993512011-11-15 21:27:07 +080089 PCI_INT(0x0, 0x14, 0x2, 0x12);
90
91 PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]); /* USB */
92 PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]);
93 PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]);
94 PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]);
95 PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]);
96 PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]);
97
98 /* sata */
99 PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]);
100
Kerry Shehb7993512011-11-15 21:27:07 +0800101 /* on board NIC & Slot PCIE. */
Patrick Georgi472efa62012-02-16 20:44:20 +0100102
Kerry Shehb7993512011-11-15 21:27:07 +0800103 /* PCI slots */
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300104 device_t dev = dev_find_slot(0, PCI_DEVFN(0x14, 4));
105 if (dev && dev->enabled) {
106 u8 bus_pci = dev->link_list->secondary;
107 /* PCI_SLOT 0. */
108 PCI_INT(bus_pci, 0x5, 0x0, 0x14);
109 PCI_INT(bus_pci, 0x5, 0x1, 0x15);
110 PCI_INT(bus_pci, 0x5, 0x2, 0x16);
111 PCI_INT(bus_pci, 0x5, 0x3, 0x17);
Kerry Shehb7993512011-11-15 21:27:07 +0800112
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300113 /* PCI_SLOT 1. */
114 PCI_INT(bus_pci, 0x6, 0x0, 0x15);
115 PCI_INT(bus_pci, 0x6, 0x1, 0x16);
116 PCI_INT(bus_pci, 0x6, 0x2, 0x17);
117 PCI_INT(bus_pci, 0x6, 0x3, 0x14);
Kerry Shehb7993512011-11-15 21:27:07 +0800118
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300119 /* PCI_SLOT 2. */
120 PCI_INT(bus_pci, 0x7, 0x0, 0x16);
121 PCI_INT(bus_pci, 0x7, 0x1, 0x17);
122 PCI_INT(bus_pci, 0x7, 0x2, 0x14);
123 PCI_INT(bus_pci, 0x7, 0x3, 0x15);
124 }
Kerry Shehb7993512011-11-15 21:27:07 +0800125
126 /* PCIe PortA */
127 PCI_INT(0x0, 0x15, 0x0, 0x10);
128 /* PCIe PortB */
129 PCI_INT(0x0, 0x15, 0x1, 0x11);
130 /* PCIe PortC */
131 PCI_INT(0x0, 0x15, 0x2, 0x12);
132 /* PCIe PortD */
133 PCI_INT(0x0, 0x15, 0x3, 0x13);
134
135 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
136 IO_LOCAL_INT(mp_ExtINT, 0x0, MP_APIC_ALL, 0x0);
137 IO_LOCAL_INT(mp_NMI, 0x0, MP_APIC_ALL, 0x1);
138 /* There is no extension information... */
139
140 /* Compute the checksums */
141 return mptable_finalize(mc);
142}
143
144unsigned long write_smp_table(unsigned long addr)
145{
146 void *v;
147 v = smp_write_floating_table(addr, 0);
148 return (unsigned long)smp_write_config_table(v);
149}