blob: 4a57d3c00245e1925dc777956d0935d32b758af7 [file] [log] [blame]
Frank Vibrans69da1b62011-02-14 19:04:45 +00001/*
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.
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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Frank Vibrans69da1b62011-02-14 19:04:45 +000018 */
19
20
21#include <console/console.h>
22#include <arch/smp/mpspec.h>
23#include <device/pci.h>
24#include <arch/io.h>
25#include <string.h>
26#include <stdint.h>
Kerry Sheh01f7ab92012-01-19 13:18:36 +080027#include <cpu/amd/amdfam14.h>
Kerry Shefeed3292011-08-18 18:03:44 +080028#include <SBPLATFORM.h>
Frank Vibrans69da1b62011-02-14 19:04:45 +000029
Kerry Sheh01f7ab92012-01-19 13:18:36 +080030extern u32 apicid_sb800;
Frank Vibrans69da1b62011-02-14 19:04:45 +000031
Frank Vibrans69da1b62011-02-14 19:04:45 +000032u8 intr_data[] = {
Kerry Sheh01f7ab92012-01-19 13:18:36 +080033 [0x00] = 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, /* INTA# - INTH# */
34 [0x08] = 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F, /* Misc-nil,0,1,2, INT from Serial irq */
35 [0x10] = 0x09,0x1F,0x1F,0x10,0x1F,0x12,0x1F,0x00,
36 [0x18] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
37 [0x20] = 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,
38 [0x28] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
39 [0x30] = 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,
40 [0x38] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
41 [0x40] = 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,
42 [0x48] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
43 [0x50] = 0x10,0x11,0x12,0x13
Frank Vibrans69da1b62011-02-14 19:04:45 +000044};
45
Frank Vibrans69da1b62011-02-14 19:04:45 +000046static void *smp_write_config_table(void *v)
47{
Kerry Shehf03360f2012-01-19 13:25:55 +080048 struct mp_config_table *mc;
49 int bus_isa;
Frank Vibrans69da1b62011-02-14 19:04:45 +000050
Kerry Shehf03360f2012-01-19 13:25:55 +080051 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Frank Vibrans69da1b62011-02-14 19:04:45 +000052
Patrick Georgic8feedd2012-02-16 18:43:25 +010053 mptable_init(mc, LOCAL_APIC_ADDR);
Kerry Shehf03360f2012-01-19 13:25:55 +080054 memcpy(mc->mpc_oem, "AMD ", 8);
Frank Vibrans69da1b62011-02-14 19:04:45 +000055
Kerry Sheh01f7ab92012-01-19 13:18:36 +080056 smp_write_processors(mc);
Frank Vibrans69da1b62011-02-14 19:04:45 +000057
Kerry Sheh01f7ab92012-01-19 13:18:36 +080058 mptable_write_buses(mc, NULL, &bus_isa);
Frank Vibrans69da1b62011-02-14 19:04:45 +000059
Kerry Shehf03360f2012-01-19 13:25:55 +080060 /* I/O APICs: APIC ID Version State Address */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070061
Kerry Shehf03360f2012-01-19 13:25:55 +080062 u32 dword;
63 u8 byte;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070064
Kerry Shehf03360f2012-01-19 13:25:55 +080065 ReadPMIO(SB_PMIOA_REG34, AccWidthUint32, &dword);
66 dword &= 0xFFFFFFF0;
67 smp_write_ioapic(mc, apicid_sb800, 0x21, dword);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070068
Kerry Shehf03360f2012-01-19 13:25:55 +080069 for (byte = 0x0; byte < sizeof(intr_data); byte ++) {
70 outb(byte | 0x80, 0xC00);
71 outb(intr_data[byte], 0xC01);
72 }
Frank Vibrans69da1b62011-02-14 19:04:45 +000073
Kerry Shehf03360f2012-01-19 13:25:55 +080074 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Frank Vibrans69da1b62011-02-14 19:04:45 +000075#define IO_LOCAL_INT(type, intr, apicid, pin) \
Kerry Shehf03360f2012-01-19 13:25:55 +080076 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
Frank Vibrans69da1b62011-02-14 19:04:45 +000077
Kerry Sheh01f7ab92012-01-19 13:18:36 +080078 mptable_add_isa_interrupts(mc, bus_isa, apicid_sb800, 0);
Frank Vibrans69da1b62011-02-14 19:04:45 +000079
Kerry Shehf03360f2012-01-19 13:25:55 +080080 /* PCI interrupts are level triggered, and are
81 * associated with a specific bus/device/function tuple.
82 */
Kerry Sheh01f7ab92012-01-19 13:18:36 +080083#define PCI_INT(bus, dev, fn, pin) \
Kerry Shehf03360f2012-01-19 13:25:55 +080084 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(fn)), apicid_sb800, (pin))
Frank Vibrans69da1b62011-02-14 19:04:45 +000085
Kerry Shehf03360f2012-01-19 13:25:55 +080086 /* APU Internal Graphic Device*/
87 PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]);
88 PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]);
Kerry Sheh28f17102011-12-22 12:18:26 +080089
Kerry Sheh01f7ab92012-01-19 13:18:36 +080090 //PCI_INT(0x0, 0x14, 0x1, 0x11); /* IDE. */
Kerry Shehf03360f2012-01-19 13:25:55 +080091 PCI_INT(0x0, 0x14, 0x0, 0x10);
Kerry Sheh01f7ab92012-01-19 13:18:36 +080092 /* Southbridge HD Audio: */
93 PCI_INT(0x0, 0x14, 0x2, 0x12);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070094
Kerry Sheh01f7ab92012-01-19 13:18:36 +080095 PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]); /* USB */
Kerry Shehf03360f2012-01-19 13:25:55 +080096 PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]);
97 PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]);
98 PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]);
99 PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]);
100 PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000101
Kerry Shehf03360f2012-01-19 13:25:55 +0800102 /* sata */
103 PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000104
Kerry Shehf03360f2012-01-19 13:25:55 +0800105 /* on board NIC & Slot PCIE. */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700106
Kerry Shehf03360f2012-01-19 13:25:55 +0800107 /* PCI slots */
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300108 device_t dev = dev_find_slot(0, PCI_DEVFN(0x14, 4));
109 if (dev && dev->enabled) {
110 u8 bus_pci = dev->link_list->secondary;
111 /* PCI_SLOT 0. */
112 PCI_INT(bus_pci, 0x5, 0x0, 0x14);
113 PCI_INT(bus_pci, 0x5, 0x1, 0x15);
114 PCI_INT(bus_pci, 0x5, 0x2, 0x16);
115 PCI_INT(bus_pci, 0x5, 0x3, 0x17);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000116
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300117 /* PCI_SLOT 1. */
118 PCI_INT(bus_pci, 0x6, 0x0, 0x15);
119 PCI_INT(bus_pci, 0x6, 0x1, 0x16);
120 PCI_INT(bus_pci, 0x6, 0x2, 0x17);
121 PCI_INT(bus_pci, 0x6, 0x3, 0x14);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000122
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300123 /* PCI_SLOT 2. */
124 PCI_INT(bus_pci, 0x7, 0x0, 0x16);
125 PCI_INT(bus_pci, 0x7, 0x1, 0x17);
126 PCI_INT(bus_pci, 0x7, 0x2, 0x14);
127 PCI_INT(bus_pci, 0x7, 0x3, 0x15);
128 }
Frank Vibrans69da1b62011-02-14 19:04:45 +0000129
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800130 /* PCIe PortA */
Kerry Shehf03360f2012-01-19 13:25:55 +0800131 PCI_INT(0x0, 0x15, 0x0, 0x10);
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800132 /* PCIe PortB */
Kerry Shehf03360f2012-01-19 13:25:55 +0800133 PCI_INT(0x0, 0x15, 0x1, 0x11);
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800134 /* PCIe PortC */
Kerry Shehf03360f2012-01-19 13:25:55 +0800135 PCI_INT(0x0, 0x15, 0x2, 0x12);
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800136 /* PCIe PortD */
Kerry Shehf03360f2012-01-19 13:25:55 +0800137 PCI_INT(0x0, 0x15, 0x3, 0x13);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000138
Kerry Shehf03360f2012-01-19 13:25:55 +0800139 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800140 IO_LOCAL_INT(mp_ExtINT, 0x0, MP_APIC_ALL, 0x0);
141 IO_LOCAL_INT(mp_NMI, 0x0, MP_APIC_ALL, 0x1);
Kerry Shehf03360f2012-01-19 13:25:55 +0800142 /* There is no extension information... */
Frank Vibrans69da1b62011-02-14 19:04:45 +0000143
Kerry Shehf03360f2012-01-19 13:25:55 +0800144 /* Compute the checksums */
145 return mptable_finalize(mc);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000146}
147
148unsigned long write_smp_table(unsigned long addr)
149{
Kerry Shehf03360f2012-01-19 13:25:55 +0800150 void *v;
151 v = smp_write_floating_table(addr, 0);
152 return (unsigned long)smp_write_config_table(v);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000153}