Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 1 | /* |
| 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 Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <arch/smp/mpspec.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <arch/io.h> |
Kyösti Mälkki | b426107 | 2014-07-22 10:24:20 +0300 | [diff] [blame] | 25 | #include <arch/ioapic.h> |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <stdint.h> |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 28 | #include <cpu/amd/amdfam14.h> |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 29 | #include <SBPLATFORM.h> |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 30 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 31 | u8 intr_data[] = { |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 32 | [0x00] = 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, /* INTA# - INTH# */ |
| 33 | [0x08] = 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F, /* Misc-nil,0,1,2, INT from Serial irq */ |
| 34 | [0x10] = 0x09,0x1F,0x1F,0x10,0x1F,0x12,0x1F,0x00, |
| 35 | [0x18] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 36 | [0x20] = 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00, |
| 37 | [0x28] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 38 | [0x30] = 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00, |
| 39 | [0x38] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 40 | [0x40] = 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00, |
| 41 | [0x48] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 42 | [0x50] = 0x10,0x11,0x12,0x13 |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 45 | static void *smp_write_config_table(void *v) |
| 46 | { |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 47 | struct mp_config_table *mc; |
| 48 | int bus_isa; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 49 | |
Kyösti Mälkki | b426107 | 2014-07-22 10:24:20 +0300 | [diff] [blame] | 50 | /* |
| 51 | * By the time this function gets called, the IOAPIC registers |
| 52 | * have been written so they can be read to get the correct |
| 53 | * APIC ID and Version |
| 54 | */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 55 | u8 ioapic_id = (io_apic_read(VIO_APIC_VADDR, 0x00) >> 24); |
| 56 | u8 ioapic_ver = (io_apic_read(VIO_APIC_VADDR, 0x01) & 0xFF); |
Kyösti Mälkki | b426107 | 2014-07-22 10:24:20 +0300 | [diff] [blame] | 57 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 58 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 59 | |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 60 | mptable_init(mc, LOCAL_APIC_ADDR); |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 61 | memcpy(mc->mpc_oem, "AMD ", 8); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 62 | |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 63 | smp_write_processors(mc); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 64 | |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 65 | mptable_write_buses(mc, NULL, &bus_isa); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 66 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 67 | /* I/O APICs: APIC ID Version State Address */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame^] | 68 | smp_write_ioapic(mc, ioapic_id, ioapic_ver, VIO_APIC_VADDR); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 69 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 70 | u8 byte; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 71 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 72 | for (byte = 0x0; byte < sizeof(intr_data); byte ++) { |
| 73 | outb(byte | 0x80, 0xC00); |
| 74 | outb(intr_data[byte], 0xC01); |
| 75 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 76 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 77 | /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 78 | #define IO_LOCAL_INT(type, intr, apicid, pin) \ |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 79 | smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin)); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 80 | |
Kyösti Mälkki | b426107 | 2014-07-22 10:24:20 +0300 | [diff] [blame] | 81 | mptable_add_isa_interrupts(mc, bus_isa, ioapic_id, 0); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 82 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 83 | /* PCI interrupts are level triggered, and are |
| 84 | * associated with a specific bus/device/function tuple. |
| 85 | */ |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 86 | #define PCI_INT(bus, dev, fn, pin) \ |
Kyösti Mälkki | b426107 | 2014-07-22 10:24:20 +0300 | [diff] [blame] | 87 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(fn)), ioapic_id, (pin)) |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 88 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 89 | /* APU Internal Graphic Device*/ |
| 90 | PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]); |
| 91 | PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]); |
Kerry Sheh | 28f1710 | 2011-12-22 12:18:26 +0800 | [diff] [blame] | 92 | |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 93 | //PCI_INT(0x0, 0x14, 0x1, 0x11); /* IDE. */ |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 94 | PCI_INT(0x0, 0x14, 0x0, 0x10); |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 95 | /* Southbridge HD Audio: */ |
| 96 | PCI_INT(0x0, 0x14, 0x2, 0x12); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 97 | |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 98 | PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]); /* USB */ |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 99 | PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]); |
| 100 | PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]); |
| 101 | PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]); |
| 102 | PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]); |
| 103 | PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 104 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 105 | /* sata */ |
| 106 | PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 107 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 108 | /* on board NIC & Slot PCIE. */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 109 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 110 | /* PCI slots */ |
Kyösti Mälkki | cdfb462 | 2014-07-22 15:24:15 +0300 | [diff] [blame] | 111 | device_t dev = dev_find_slot(0, PCI_DEVFN(0x14, 4)); |
| 112 | if (dev && dev->enabled) { |
| 113 | u8 bus_pci = dev->link_list->secondary; |
| 114 | /* PCI_SLOT 0. */ |
| 115 | PCI_INT(bus_pci, 0x5, 0x0, 0x14); |
| 116 | PCI_INT(bus_pci, 0x5, 0x1, 0x15); |
| 117 | PCI_INT(bus_pci, 0x5, 0x2, 0x16); |
| 118 | PCI_INT(bus_pci, 0x5, 0x3, 0x17); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 119 | |
Kyösti Mälkki | cdfb462 | 2014-07-22 15:24:15 +0300 | [diff] [blame] | 120 | /* PCI_SLOT 1. */ |
| 121 | PCI_INT(bus_pci, 0x6, 0x0, 0x15); |
| 122 | PCI_INT(bus_pci, 0x6, 0x1, 0x16); |
| 123 | PCI_INT(bus_pci, 0x6, 0x2, 0x17); |
| 124 | PCI_INT(bus_pci, 0x6, 0x3, 0x14); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 125 | |
Kyösti Mälkki | cdfb462 | 2014-07-22 15:24:15 +0300 | [diff] [blame] | 126 | /* PCI_SLOT 2. */ |
| 127 | PCI_INT(bus_pci, 0x7, 0x0, 0x16); |
| 128 | PCI_INT(bus_pci, 0x7, 0x1, 0x17); |
| 129 | PCI_INT(bus_pci, 0x7, 0x2, 0x14); |
| 130 | PCI_INT(bus_pci, 0x7, 0x3, 0x15); |
| 131 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 132 | |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 133 | /* PCIe PortA */ |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 134 | PCI_INT(0x0, 0x15, 0x0, 0x10); |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 135 | /* PCIe PortB */ |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 136 | PCI_INT(0x0, 0x15, 0x1, 0x11); |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 137 | /* PCIe PortC */ |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 138 | PCI_INT(0x0, 0x15, 0x2, 0x12); |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 139 | /* PCIe PortD */ |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 140 | PCI_INT(0x0, 0x15, 0x3, 0x13); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 141 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 142 | /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
Kerry Sheh | 01f7ab9 | 2012-01-19 13:18:36 +0800 | [diff] [blame] | 143 | IO_LOCAL_INT(mp_ExtINT, 0x0, MP_APIC_ALL, 0x0); |
| 144 | IO_LOCAL_INT(mp_NMI, 0x0, MP_APIC_ALL, 0x1); |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 145 | /* There is no extension information... */ |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 146 | |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 147 | /* Compute the checksums */ |
| 148 | return mptable_finalize(mc); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | unsigned long write_smp_table(unsigned long addr) |
| 152 | { |
Kerry Sheh | f03360f | 2012-01-19 13:25:55 +0800 | [diff] [blame] | 153 | void *v; |
| 154 | v = smp_write_floating_table(addr, 0); |
| 155 | return (unsigned long)smp_write_config_table(v); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 156 | } |