blob: 2deb219a0070a1e24308a7f84e4392d37ffaa599 [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.
Frank Vibrans69da1b62011-02-14 19:04:45 +000014 */
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>
Frank Vibrans69da1b62011-02-14 19:04:45 +000022#include <string.h>
23#include <stdint.h>
Kerry Sheh01f7ab92012-01-19 13:18:36 +080024#include <cpu/amd/amdfam14.h>
Kerry Shefeed3292011-08-18 18:03:44 +080025#include <SBPLATFORM.h>
Frank Vibrans69da1b62011-02-14 19:04:45 +000026
Frank Vibrans69da1b62011-02-14 19:04:45 +000027u8 intr_data[] = {
Kerry Sheh01f7ab92012-01-19 13:18:36 +080028 [0x00] = 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, /* INTA# - INTH# */
29 [0x08] = 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F, /* Misc-nil,0,1,2, INT from Serial irq */
30 [0x10] = 0x09,0x1F,0x1F,0x10,0x1F,0x12,0x1F,0x00,
31 [0x18] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32 [0x20] = 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,
33 [0x28] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 [0x30] = 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,
35 [0x38] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
36 [0x40] = 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,
37 [0x48] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
38 [0x50] = 0x10,0x11,0x12,0x13
Frank Vibrans69da1b62011-02-14 19:04:45 +000039};
40
Frank Vibrans69da1b62011-02-14 19:04:45 +000041static void *smp_write_config_table(void *v)
42{
Kerry Shehf03360f2012-01-19 13:25:55 +080043 struct mp_config_table *mc;
44 int bus_isa;
Frank Vibrans69da1b62011-02-14 19:04:45 +000045
Kyösti Mälkkib4261072014-07-22 10:24:20 +030046 /*
47 * By the time this function gets called, the IOAPIC registers
48 * have been written so they can be read to get the correct
49 * APIC ID and Version
50 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080051 u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24);
52 u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF);
Kyösti Mälkkib4261072014-07-22 10:24:20 +030053
Kerry Shehf03360f2012-01-19 13:25:55 +080054 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Frank Vibrans69da1b62011-02-14 19:04:45 +000055
Patrick Georgic8feedd2012-02-16 18:43:25 +010056 mptable_init(mc, LOCAL_APIC_ADDR);
Kerry Shehf03360f2012-01-19 13:25:55 +080057 memcpy(mc->mpc_oem, "AMD ", 8);
Frank Vibrans69da1b62011-02-14 19:04:45 +000058
Kerry Sheh01f7ab92012-01-19 13:18:36 +080059 smp_write_processors(mc);
Frank Vibrans69da1b62011-02-14 19:04:45 +000060
Kerry Sheh01f7ab92012-01-19 13:18:36 +080061 mptable_write_buses(mc, NULL, &bus_isa);
Frank Vibrans69da1b62011-02-14 19:04:45 +000062
Kerry Shehf03360f2012-01-19 13:25:55 +080063 /* I/O APICs: APIC ID Version State Address */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080064 smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070065
Kerry Shehf03360f2012-01-19 13:25:55 +080066 u8 byte;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070067
Kerry Shehf03360f2012-01-19 13:25:55 +080068 for (byte = 0x0; byte < sizeof(intr_data); byte ++) {
69 outb(byte | 0x80, 0xC00);
70 outb(intr_data[byte], 0xC01);
71 }
Frank Vibrans69da1b62011-02-14 19:04:45 +000072
Kerry Shehf03360f2012-01-19 13:25:55 +080073 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Frank Vibrans69da1b62011-02-14 19:04:45 +000074#define IO_LOCAL_INT(type, intr, apicid, pin) \
Kerry Shehf03360f2012-01-19 13:25:55 +080075 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 +000076
Kyösti Mälkkib4261072014-07-22 10:24:20 +030077 mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0);
Frank Vibrans69da1b62011-02-14 19:04:45 +000078
Kerry Shehf03360f2012-01-19 13:25:55 +080079 /* PCI interrupts are level triggered, and are
80 * associated with a specific bus/device/function tuple.
81 */
Kerry Sheh01f7ab92012-01-19 13:18:36 +080082#define PCI_INT(bus, dev, fn, pin) \
Kyösti Mälkkib4261072014-07-22 10:24:20 +030083 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(fn)), ioapic_id, (pin))
Frank Vibrans69da1b62011-02-14 19:04:45 +000084
Kerry Shehf03360f2012-01-19 13:25:55 +080085 /* APU Internal Graphic Device*/
86 PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]);
87 PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]);
Kerry Sheh28f17102011-12-22 12:18:26 +080088
Kerry Sheh01f7ab92012-01-19 13:18:36 +080089 //PCI_INT(0x0, 0x14, 0x1, 0x11); /* IDE. */
Kerry Shehf03360f2012-01-19 13:25:55 +080090 PCI_INT(0x0, 0x14, 0x0, 0x10);
Kerry Sheh01f7ab92012-01-19 13:18:36 +080091 /* Southbridge HD Audio: */
92 PCI_INT(0x0, 0x14, 0x2, 0x12);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070093
Kerry Sheh01f7ab92012-01-19 13:18:36 +080094 PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]); /* USB */
Kerry Shehf03360f2012-01-19 13:25:55 +080095 PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]);
96 PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]);
97 PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]);
98 PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]);
99 PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000100
Kerry Shehf03360f2012-01-19 13:25:55 +0800101 /* sata */
102 PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000103
Kerry Shehf03360f2012-01-19 13:25:55 +0800104 /* on board NIC & Slot PCIE. */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700105
Kerry Shehf03360f2012-01-19 13:25:55 +0800106 /* PCI slots */
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300107 device_t dev = dev_find_slot(0, PCI_DEVFN(0x14, 4));
108 if (dev && dev->enabled) {
109 u8 bus_pci = dev->link_list->secondary;
110 /* PCI_SLOT 0. */
111 PCI_INT(bus_pci, 0x5, 0x0, 0x14);
112 PCI_INT(bus_pci, 0x5, 0x1, 0x15);
113 PCI_INT(bus_pci, 0x5, 0x2, 0x16);
114 PCI_INT(bus_pci, 0x5, 0x3, 0x17);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000115
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300116 /* PCI_SLOT 1. */
117 PCI_INT(bus_pci, 0x6, 0x0, 0x15);
118 PCI_INT(bus_pci, 0x6, 0x1, 0x16);
119 PCI_INT(bus_pci, 0x6, 0x2, 0x17);
120 PCI_INT(bus_pci, 0x6, 0x3, 0x14);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000121
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300122 /* PCI_SLOT 2. */
123 PCI_INT(bus_pci, 0x7, 0x0, 0x16);
124 PCI_INT(bus_pci, 0x7, 0x1, 0x17);
125 PCI_INT(bus_pci, 0x7, 0x2, 0x14);
126 PCI_INT(bus_pci, 0x7, 0x3, 0x15);
127 }
Frank Vibrans69da1b62011-02-14 19:04:45 +0000128
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800129 /* PCIe PortA */
Kerry Shehf03360f2012-01-19 13:25:55 +0800130 PCI_INT(0x0, 0x15, 0x0, 0x10);
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800131 /* PCIe PortB */
Kerry Shehf03360f2012-01-19 13:25:55 +0800132 PCI_INT(0x0, 0x15, 0x1, 0x11);
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800133 /* PCIe PortC */
Kerry Shehf03360f2012-01-19 13:25:55 +0800134 PCI_INT(0x0, 0x15, 0x2, 0x12);
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800135 /* PCIe PortD */
Kerry Shehf03360f2012-01-19 13:25:55 +0800136 PCI_INT(0x0, 0x15, 0x3, 0x13);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000137
Kerry Shehf03360f2012-01-19 13:25:55 +0800138 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Kerry Sheh01f7ab92012-01-19 13:18:36 +0800139 IO_LOCAL_INT(mp_ExtINT, 0x0, MP_APIC_ALL, 0x0);
140 IO_LOCAL_INT(mp_NMI, 0x0, MP_APIC_ALL, 0x1);
Kerry Shehf03360f2012-01-19 13:25:55 +0800141 /* There is no extension information... */
Frank Vibrans69da1b62011-02-14 19:04:45 +0000142
Kerry Shehf03360f2012-01-19 13:25:55 +0800143 /* Compute the checksums */
144 return mptable_finalize(mc);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000145}
146
147unsigned long write_smp_table(unsigned long addr)
148{
Kerry Shehf03360f2012-01-19 13:25:55 +0800149 void *v;
150 v = smp_write_floating_table(addr, 0);
151 return (unsigned long)smp_write_config_table(v);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000152}