Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 AMD |
| 5 | * Written by Yinghai Lu <yinghailu@amd.com> for AMD. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <console/console.h> |
| 19 | #include <arch/smp/mpspec.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <string.h> |
| 22 | #include <stdint.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 23 | #include <cpu/amd/amdk8_sysconf.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 24 | #include "mb_sysconf.h" |
| 25 | |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 26 | static void *smp_write_config_table(void *v) |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 27 | { |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 28 | struct mp_config_table *mc; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 29 | struct mb_sysconf_t *m; |
| 30 | unsigned sbdn; |
Patrick Georgi | 5244e1b | 2010-11-21 14:41:07 +0000 | [diff] [blame] | 31 | int i, j, bus_isa; |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 32 | unsigned char apicpin[4]; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 33 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 34 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 35 | |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 36 | mptable_init(mc, LOCAL_APIC_ADDR); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 37 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 38 | smp_write_processors(mc); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 39 | |
| 40 | get_bus_conf(); |
| 41 | sbdn = sysconf.sbdn; |
| 42 | m = sysconf.mb; |
| 43 | |
Patrick Georgi | 5244e1b | 2010-11-21 14:41:07 +0000 | [diff] [blame] | 44 | mptable_write_buses(mc, NULL, &bus_isa); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 45 | |
| 46 | /*I/O APICs: APIC ID Version State Address*/ |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 47 | { |
| 48 | device_t dev; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 49 | struct resource *res; |
| 50 | uint32_t dword; |
| 51 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 52 | dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn+ 0x1,0)); |
| 53 | if (dev) { |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 54 | res = find_resource(dev, PCI_BASE_ADDRESS_1); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 55 | if (res) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 56 | smp_write_ioapic(mc, m->apicid_mcp55, 0x11, |
| 57 | res2mmio(res, 0, 0)); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 58 | |
| 59 | /* Initialize interrupt mapping*/ |
| 60 | dword = pci_read_config32(dev, 0x74); |
| 61 | dword &= ~(1<<15); |
| 62 | dword |= 1<<2; |
| 63 | pci_write_config32(dev, 0x74, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 64 | |
| 65 | dword = 0x43c6c643; |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 66 | pci_write_config32(dev, 0x7c, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 67 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 68 | dword = 0x81001a00; |
| 69 | pci_write_config32(dev, 0x80, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 70 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 71 | dword = 0xd00012d2; |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 72 | pci_write_config32(dev, 0x84, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 73 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 74 | } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 75 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 76 | if (m->bus_mcp55b) { |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 77 | dev = dev_find_slot(m->bus_mcp55b, PCI_DEVFN(m->sbdnb + 0x1,0)); |
| 78 | if (dev) { |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 79 | res = find_resource(dev, PCI_BASE_ADDRESS_1); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 80 | if (res) |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 81 | smp_write_ioapic(mc, m->apicid_mcp55b, 0x11, |
| 82 | res2mmio(res, 0, 0)); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 83 | |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 84 | dword = 0x43c60000; |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 85 | pci_write_config32(dev, 0x7c, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 86 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 87 | dword = 0x81000000; |
| 88 | pci_write_config32(dev, 0x80, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 89 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 90 | dword = 0xd00002d0; |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 91 | pci_write_config32(dev, 0x84, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 92 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 93 | } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 94 | |
| 95 | } |
| 96 | |
| 97 | } |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 98 | |
Patrick Georgi | 5244e1b | 2010-11-21 14:41:07 +0000 | [diff] [blame] | 99 | mptable_add_isa_interrupts(mc, bus_isa, m->apicid_mcp55, 0); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 100 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 101 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+1)<<2)|1, m->apicid_mcp55, 0xa); // 10 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 102 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 103 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+2)<<2)|0, m->apicid_mcp55, 0x16); // 22 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 104 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 105 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+2)<<2)|1, m->apicid_mcp55, 0x17); // 23 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 106 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 107 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+6)<<2)|1, m->apicid_mcp55, 0x17); // 23 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 108 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 109 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+5)<<2)|0, m->apicid_mcp55, 0x14); // 20 |
| 110 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+5)<<2)|1, m->apicid_mcp55, 0x17); // 23 |
| 111 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+5)<<2)|2, m->apicid_mcp55, 0x15); // 21 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 112 | |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 113 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+8)<<2)|0, m->apicid_mcp55, 0x16); // 22 |
| 114 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+9)<<2)|0, m->apicid_mcp55, 0x15); // 21 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 115 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 116 | //Slot PCIE |
| 117 | for (j = 2; j < 8; j++) { |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 118 | device_t dev; |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 119 | dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn + 0x0a + j - 2 , 0)); |
| 120 | if (!dev || !dev->enabled) |
| 121 | continue; |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 122 | for (i = 0; i < 4; i++) |
| 123 | apicpin[i] = 0x10 + (2+j+i+4-sbdn%4)%4; |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 124 | smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55, apicpin); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 127 | //Slot PCI 32 |
| 128 | { |
Myles Watson | a643ea3 | 2008-10-06 21:00:46 +0000 | [diff] [blame] | 129 | device_t dev; |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 130 | dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn + 6 , 0)); |
| 131 | if (dev && dev->enabled) { |
| 132 | for (i = 0; i < 4; i++) |
| 133 | apicpin[i] = 0x10 + (2+i)%4; |
| 134 | smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55, apicpin); |
| 135 | } |
| 136 | } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 137 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 138 | if (m->bus_mcp55b) { |
| 139 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+5)<<2)|0, m->apicid_mcp55b, 0x14); // 20 |
| 140 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+5)<<2)|1, m->apicid_mcp55b, 0x17); // 23 |
| 141 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+5)<<2)|2, m->apicid_mcp55b, 0x15); // 21 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 142 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 143 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+8)<<2)|0, m->apicid_mcp55b, 0x16); // 22 |
| 144 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+9)<<2)|0, m->apicid_mcp55b, 0x15); // 21 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 145 | |
| 146 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 147 | //Slot PCIE |
| 148 | for (j = 2; j < 8; j++) { |
| 149 | device_t dev; |
| 150 | dev = dev_find_slot(m->bus_mcp55b, PCI_DEVFN(m->sbdnb + 0x0a + j - 2 , 0)); |
| 151 | if (!dev || !dev->enabled) |
| 152 | continue; |
| 153 | for (i = 0; i < 4; i++) { |
| 154 | apicpin[i] = 0x10 + (2+j+i+4-m->sbdnb%4)%4; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 155 | } |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 156 | smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55b, apicpin); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 157 | } |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 158 | |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 159 | } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 160 | |
| 161 | /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/ |
Patrick Georgi | 6eb7a53 | 2011-10-07 21:42:52 +0200 | [diff] [blame] | 162 | mptable_lintsrc(mc, bus_isa); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 163 | /* There is no extension information... */ |
| 164 | |
| 165 | /* Compute the checksums */ |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 166 | return mptable_finalize(mc); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | unsigned long write_smp_table(unsigned long addr) |
| 170 | { |
| 171 | void *v; |
Patrick Georgi | c75c79b | 2011-10-07 22:41:07 +0200 | [diff] [blame] | 172 | v = smp_write_floating_table(addr, 0); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 173 | return (unsigned long)smp_write_config_table(v); |
| 174 | } |