blob: eef3554dd9e07b6cb740a7d582c0edec81d7d9be [file] [log] [blame]
Scott Duplichana649a962011-02-24 05:00:33 +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.
Scott Duplichana649a962011-02-24 05:00:33 +000014 */
15
16
Scott Duplichana649a962011-02-24 05:00:33 +000017#include <arch/io.h>
Kyösti Mälkkib4261072014-07-22 10:24:20 +030018#include <arch/ioapic.h>
Edward O'Callaghanb53b50b2014-04-29 20:26:02 +100019#include <arch/smp/mpspec.h>
20#include <console/console.h>
Paul Menzelcd966dd2013-03-29 20:20:56 +010021#include <cpu/amd/amdfam14.h>
Edward O'Callaghanb53b50b2014-04-29 20:26:02 +100022#include <device/pci.h>
23#include <stdint.h>
24#include <string.h>
25
26#include <southbridge/amd/cimx/sb800/SBPLATFORM.h>
Scott Duplichana649a962011-02-24 05:00:33 +000027
Scott Duplichana649a962011-02-24 05:00:33 +000028
Scott Duplichana649a962011-02-24 05:00:33 +000029u8 intr_data[] = {
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020030 [0x00] = 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, /* INTA# - INTH# */
31 [0x08] = 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F, /* Misc-nil,0,1,2, INT from Serial irq */
32 [0x10] = 0x09,0x1F,0x1F,0x10,0x1F,0x12,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
33 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
35 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
36 0x10,0x11,0x12,0x13
Scott Duplichana649a962011-02-24 05:00:33 +000037};
38
39static void *smp_write_config_table(void *v)
40{
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020041 struct mp_config_table *mc;
42 int bus_isa;
Scott Duplichana649a962011-02-24 05:00:33 +000043
Kyösti Mälkkib4261072014-07-22 10:24:20 +030044 /*
45 * By the time this function gets called, the IOAPIC registers
46 * have been written so they can be read to get the correct
47 * APIC ID and Version
48 */
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020049 u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24);
50 u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF);
Kyösti Mälkkib4261072014-07-22 10:24:20 +030051
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020052 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Scott Duplichana649a962011-02-24 05:00:33 +000053
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020054 mptable_init(mc, LOCAL_APIC_ADDR);
55 memcpy(mc->mpc_oem, "ASROCK ", 8);
Scott Duplichana649a962011-02-24 05:00:33 +000056
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020057 smp_write_processors(mc);
Scott Duplichana649a962011-02-24 05:00:33 +000058
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020059 mptable_write_buses(mc, NULL, &bus_isa);
Scott Duplichana649a962011-02-24 05:00:33 +000060
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020061 /* I/O APICs: APIC ID Version State Address */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080062 smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070063
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020064 u8 byte;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070065
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020066 for (byte = 0x0; byte < sizeof(intr_data); byte ++) {
67 outb(byte | 0x80, 0xC00);
68 outb(intr_data[byte], 0xC01);
69 }
Scott Duplichana649a962011-02-24 05:00:33 +000070
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020071 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Scott Duplichana649a962011-02-24 05:00:33 +000072#define IO_LOCAL_INT(type, intr, apicid, pin) \
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020073 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
Scott Duplichana649a962011-02-24 05:00:33 +000074
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020075 mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0);
Scott Duplichana649a962011-02-24 05:00:33 +000076
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020077 /* PCI interrupts are level triggered, and are
78 * associated with a specific bus/device/function tuple.
79 */
Scott Duplichana649a962011-02-24 05:00:33 +000080#define PCI_INT(bus, dev, fn, pin) \
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020081 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(fn)), ioapic_id, (pin))
Scott Duplichana649a962011-02-24 05:00:33 +000082
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020083 /* APU Internal Graphic Device*/
84 PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]);
85 PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]);
Kerry Sheh28f17102011-12-22 12:18:26 +080086
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020087 //PCI_INT(0x0, 0x14, 0x1, 0x11); /* IDE. */
88 PCI_INT(0x0, 0x14, 0x0, 0x10);
89 /* Southbridge HD Audio: */
90 PCI_INT(0x0, 0x14, 0x2, 0x12);
Scott Duplichana649a962011-02-24 05:00:33 +000091
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020092 PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]); /* USB */
93 PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]);
94 PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]);
95 PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]);
96 PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]);
97 PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]);
Scott Duplichana649a962011-02-24 05:00:33 +000098
Elyes HAOUAS8da96e52016-09-22 21:20:54 +020099 /* sata */
100 PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]);
Scott Duplichana649a962011-02-24 05:00:33 +0000101
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200102 /* on board NIC & Slot PCIE. */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700103
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200104 /* PCI slots */
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300105 device_t dev = dev_find_slot(0, PCI_DEVFN(0x14, 4));
106 if (dev && dev->enabled) {
107 u8 bus_pci = dev->link_list->secondary;
108 /* PCI_SLOT 0. */
109 PCI_INT(bus_pci, 0x5, 0x0, 0x14);
110 PCI_INT(bus_pci, 0x5, 0x1, 0x15);
111 PCI_INT(bus_pci, 0x5, 0x2, 0x16);
112 PCI_INT(bus_pci, 0x5, 0x3, 0x17);
Scott Duplichana649a962011-02-24 05:00:33 +0000113
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300114 /* PCI_SLOT 1. */
115 PCI_INT(bus_pci, 0x6, 0x0, 0x15);
116 PCI_INT(bus_pci, 0x6, 0x1, 0x16);
117 PCI_INT(bus_pci, 0x6, 0x2, 0x17);
118 PCI_INT(bus_pci, 0x6, 0x3, 0x14);
Scott Duplichana649a962011-02-24 05:00:33 +0000119
Kyösti Mälkkicdfb4622014-07-22 15:24:15 +0300120 /* PCI_SLOT 2. */
121 PCI_INT(bus_pci, 0x7, 0x0, 0x16);
122 PCI_INT(bus_pci, 0x7, 0x1, 0x17);
123 PCI_INT(bus_pci, 0x7, 0x2, 0x14);
124 PCI_INT(bus_pci, 0x7, 0x3, 0x15);
125 }
Scott Duplichana649a962011-02-24 05:00:33 +0000126
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200127 /* PCIe PortA */
128 PCI_INT(0x0, 0x15, 0x0, 0x10);
129 /* PCIe PortB */
130 PCI_INT(0x0, 0x15, 0x1, 0x11);
131 /* PCIe PortC */
132 PCI_INT(0x0, 0x15, 0x2, 0x12);
133 /* PCIe PortD */
134 PCI_INT(0x0, 0x15, 0x3, 0x13);
Scott Duplichana649a962011-02-24 05:00:33 +0000135
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200136 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
137 IO_LOCAL_INT(mp_ExtINT, 0x0, MP_APIC_ALL, 0x0);
138 IO_LOCAL_INT(mp_NMI, 0x0, MP_APIC_ALL, 0x1);
139 /* There is no extension information... */
Scott Duplichana649a962011-02-24 05:00:33 +0000140
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200141 /* Compute the checksums */
142 return mptable_finalize(mc);
Scott Duplichana649a962011-02-24 05:00:33 +0000143}
144
145unsigned long write_smp_table(unsigned long addr)
146{
Elyes HAOUAS8da96e52016-09-22 21:20:54 +0200147 void *v;
148 v = smp_write_floating_table(addr, 0);
149 return (unsigned long)smp_write_config_table(v);
Scott Duplichana649a962011-02-24 05:00:33 +0000150}