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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 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> |
| 27 | #include <arch/cpu.h> |
| 28 | #include <cpu/x86/lapic.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 | |
| 31 | #define IO_APIC_ID CONFIG_MAX_PHYSICAL_CPUS + 1 |
| 32 | extern u8 bus_sb800[2]; |
| 33 | |
| 34 | |
| 35 | extern u32 bus_type[256]; |
| 36 | extern u32 sbdn_sb800; |
| 37 | u32 apicid_sb800; |
| 38 | |
| 39 | u8 picr_data[] = { |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 40 | 0x0B,0x0A,0x0B,0x05,0x1F,0x1F,0x1F,0x1F,0x50,0xF1,0x00,0x00,0x1F,0x1F,0x1F,0x1F, |
| 41 | 0x1F,0x1F,0x1F,0x0B,0x1F,0x0B,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 42 | 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 43 | 0x0B,0x0A,0x0B,0x0A,0x0B,0x0A,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 44 | 0x0A,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 45 | 0x0B,0x0A,0x0B,0x05 |
| 46 | }; |
| 47 | u8 intr_data[] = { |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 48 | 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 49 | 0x1F,0x1F,0x1F,0x10,0x1F,0x12,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 50 | 0x05,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 51 | 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 52 | 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 53 | 0x10,0x11,0x12,0x13 |
| 54 | }; |
| 55 | |
| 56 | static void smp_add_mpc_entry(struct mp_config_table *mc, unsigned length) |
| 57 | { |
| 58 | mc->mpc_length += length; |
| 59 | mc->mpc_entry_count++; |
| 60 | } |
| 61 | static void my_smp_write_bus(struct mp_config_table *mc, |
| 62 | unsigned char id, const char *bustype) |
| 63 | { |
| 64 | struct mpc_config_bus *mpc; |
| 65 | mpc = smp_next_mpc_entry(mc); |
| 66 | memset(mpc, '\0', sizeof(*mpc)); |
| 67 | mpc->mpc_type = MP_BUS; |
| 68 | mpc->mpc_busid = id; |
| 69 | memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype)); |
| 70 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 71 | } |
| 72 | static void *smp_write_config_table(void *v) |
| 73 | { |
| 74 | struct mp_config_table *mc; |
| 75 | int bus_isa; |
| 76 | int boot_apic_id; |
| 77 | unsigned apic_version; |
| 78 | unsigned cpu_features; |
| 79 | unsigned cpu_feature_flags; |
| 80 | struct cpuid_result result; |
| 81 | unsigned long cpu_flag; |
| 82 | |
| 83 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
| 84 | |
| 85 | mptable_init(mc, LAPIC_ADDR); |
| 86 | memcpy(mc->mpc_oem, "AMD ", 8); |
| 87 | |
| 88 | /*Inagua used dure core cpu with one die */ |
| 89 | boot_apic_id = lapicid(); |
| 90 | apic_version = lapic_read(LAPIC_LVR) & 0xff; |
| 91 | result = cpuid(1); |
| 92 | cpu_features = result.eax; |
| 93 | cpu_feature_flags = result.edx; |
| 94 | cpu_flag = MPC_CPU_ENABLED | MPC_CPU_BOOTPROCESSOR; |
| 95 | smp_write_processor(mc, |
| 96 | 0, apic_version, |
| 97 | cpu_flag, cpu_features, cpu_feature_flags |
| 98 | ); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 99 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 100 | cpu_flag = MPC_CPU_ENABLED; |
| 101 | smp_write_processor(mc, |
| 102 | 1, apic_version, |
| 103 | cpu_flag, cpu_features, cpu_feature_flags |
| 104 | ); |
| 105 | |
| 106 | get_bus_conf(); |
| 107 | |
| 108 | //mptable_write_buses(mc, NULL, &bus_isa); |
| 109 | my_smp_write_bus(mc, 0, "PCI "); |
| 110 | my_smp_write_bus(mc, 1, "PCI "); |
| 111 | bus_isa = 0x02; |
| 112 | my_smp_write_bus(mc, bus_isa, "ISA "); |
| 113 | |
| 114 | /* I/O APICs: APIC ID Version State Address */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 115 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 116 | device_t dev; |
| 117 | u32 dword; |
| 118 | u8 byte; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 119 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 120 | ReadPMIO(SB_PMIOA_REG34, AccWidthUint32, &dword); |
| 121 | dword &= 0xFFFFFFF0; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 122 | /* Set IO APIC ID onto IO_APIC_ID */ |
| 123 | write32 (dword, 0x00); |
| 124 | write32 (dword + 0x10, IO_APIC_ID << 24); |
| 125 | apicid_sb800 = IO_APIC_ID; |
| 126 | smp_write_ioapic(mc, apicid_sb800, 0x21, dword); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 127 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 128 | /* PIC IRQ routine */ |
| 129 | for (byte = 0x0; byte < sizeof(picr_data); byte ++) { |
| 130 | outb(byte, 0xC00); |
| 131 | outb(picr_data[byte], 0xC01); |
| 132 | } |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 133 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 134 | /* APIC IRQ routine */ |
| 135 | for (byte = 0x0; byte < sizeof(intr_data); byte ++) { |
| 136 | outb(byte | 0x80, 0xC00); |
| 137 | outb(intr_data[byte], 0xC01); |
| 138 | } |
| 139 | |
| 140 | /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
| 141 | #define IO_LOCAL_INT(type, intr, apicid, pin) \ |
| 142 | smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin)); |
| 143 | |
| 144 | //mptable_add_isa_interrupts(mc, bus_isa, apicid_sb800, 0); |
| 145 | /*I/O Ints: Type Trigger Polarity Bus ID IRQ APIC ID PIN# */ |
| 146 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, apicid_sb800, 0x0); |
| 147 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x1, apicid_sb800, 0x1); |
| 148 | smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x2, apicid_sb800, 0x2); |
| 149 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x3, apicid_sb800, 0x3); |
| 150 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x4, apicid_sb800, 0x4); |
| 151 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0, 0x49, apicid_sb800, 0x11); |
| 152 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x6, apicid_sb800, 0x6); |
| 153 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x7, apicid_sb800, 0x7); |
| 154 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x8, apicid_sb800, 0x8); |
| 155 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x9, apicid_sb800, 0x9); |
| 156 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_isa, 0xa, apicid_sb800, 0xa); |
| 157 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_isa, 0x1c, apicid_sb800, 0x13); |
| 158 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xc, apicid_sb800, 0xc); |
| 159 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xd, apicid_sb800, 0xd); |
| 160 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xe, apicid_sb800, 0xe); |
| 161 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0xf, apicid_sb800, 0xf); |
| 162 | |
| 163 | /* PCI interrupts are level triggered, and are |
| 164 | * associated with a specific bus/device/function tuple. |
| 165 | */ |
| 166 | #define PCI_INT(bus, dev, int_sign, pin) \ |
| 167 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(int_sign)), apicid_sb800, (pin)) |
| 168 | |
Kerry Sheh | 28f1710 | 2011-12-22 12:18:26 +0800 | [diff] [blame^] | 169 | /* APU Internal Graphic Device*/ |
| 170 | PCI_INT(0x0, 0x01, 0x0, intr_data[0x02]); |
| 171 | PCI_INT(0x0, 0x01, 0x1, intr_data[0x03]); |
| 172 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 173 | /* SMBUS */ |
| 174 | PCI_INT(0x0, 0x14, 0x0, 0x10); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 175 | |
Kerry Sheh | 28f1710 | 2011-12-22 12:18:26 +0800 | [diff] [blame^] | 176 | /* Southbridge HD Audio */ |
| 177 | PCI_INT(0x0, 0x14, 0x2, intr_data[0x13]); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 178 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 179 | /* USB */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 180 | PCI_INT(0x0, 0x12, 0x0, intr_data[0x30]); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 181 | PCI_INT(0x0, 0x12, 0x1, intr_data[0x31]); |
| 182 | PCI_INT(0x0, 0x13, 0x0, intr_data[0x32]); |
| 183 | PCI_INT(0x0, 0x13, 0x1, intr_data[0x33]); |
| 184 | PCI_INT(0x0, 0x16, 0x0, intr_data[0x34]); |
| 185 | PCI_INT(0x0, 0x16, 0x1, intr_data[0x35]); |
Kerry Sheh | 28f1710 | 2011-12-22 12:18:26 +0800 | [diff] [blame^] | 186 | PCI_INT(0x0, 0x14, 0x5, intr_data[0x36]); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 187 | |
| 188 | /* sata */ |
| 189 | PCI_INT(0x0, 0x11, 0x0, intr_data[0x40]); |
| 190 | PCI_INT(0x0, 0x11, 0x0, intr_data[0x41]); |
| 191 | |
| 192 | |
| 193 | /* on board NIC & Slot PCIE. */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 194 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 195 | /* PCI slots */ |
| 196 | /* PCI_SLOT 0. */ |
| 197 | PCI_INT(bus_sb800[1], 0x5, 0x0, 0x14); |
| 198 | PCI_INT(bus_sb800[1], 0x5, 0x1, 0x15); |
| 199 | PCI_INT(bus_sb800[1], 0x5, 0x2, 0x16); |
| 200 | PCI_INT(bus_sb800[1], 0x5, 0x3, 0x17); |
| 201 | |
| 202 | /* PCI_SLOT 1. */ |
| 203 | PCI_INT(bus_sb800[1], 0x6, 0x0, 0x15); |
| 204 | PCI_INT(bus_sb800[1], 0x6, 0x1, 0x16); |
| 205 | PCI_INT(bus_sb800[1], 0x6, 0x2, 0x17); |
| 206 | PCI_INT(bus_sb800[1], 0x6, 0x3, 0x14); |
| 207 | |
| 208 | /* PCI_SLOT 2. */ |
| 209 | PCI_INT(bus_sb800[1], 0x7, 0x0, 0x16); |
| 210 | PCI_INT(bus_sb800[1], 0x7, 0x1, 0x17); |
| 211 | PCI_INT(bus_sb800[1], 0x7, 0x2, 0x14); |
| 212 | PCI_INT(bus_sb800[1], 0x7, 0x3, 0x15); |
| 213 | |
| 214 | PCI_INT(bus_sb800[2], 0x0, 0x0, 0x12); |
| 215 | PCI_INT(bus_sb800[2], 0x0, 0x1, 0x13); |
| 216 | PCI_INT(bus_sb800[2], 0x0, 0x2, 0x14); |
| 217 | |
| 218 | /* PCIe Lan*/ |
| 219 | PCI_INT(0x0, 0x06, 0x0, 0x13); |
| 220 | |
| 221 | /* FCH PCIe PortA */ |
| 222 | PCI_INT(0x0, 0x15, 0x0, 0x10); |
| 223 | /* FCH PCIe PortB */ |
| 224 | PCI_INT(0x0, 0x15, 0x1, 0x11); |
| 225 | /* FCH PCIe PortC */ |
| 226 | PCI_INT(0x0, 0x15, 0x2, 0x12); |
| 227 | /* FCH PCIe PortD */ |
| 228 | PCI_INT(0x0, 0x15, 0x3, 0x13); |
| 229 | |
| 230 | /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
| 231 | IO_LOCAL_INT(mp_ExtINT, 0, MP_APIC_ALL, 0x0); |
| 232 | IO_LOCAL_INT(mp_NMI, 0, MP_APIC_ALL, 0x1); |
| 233 | /* There is no extension information... */ |
| 234 | |
| 235 | /* Compute the checksums */ |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 236 | return mptable_finalize(mc); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | unsigned long write_smp_table(unsigned long addr) |
| 240 | { |
| 241 | void *v; |
Patrick Georgi | c75c79b | 2011-10-07 22:41:07 +0200 | [diff] [blame] | 242 | v = smp_write_floating_table(addr, 0); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 243 | return (unsigned long)smp_write_config_table(v); |
| 244 | } |