blob: d000b1a4e70f85114edc5f92024cda652e2c1794 [file] [log] [blame]
Yinghai Luf55b58d2007-02-17 14:28:11 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Yinghai Luf55b58d2007-02-17 14:28:11 +00003 *
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 Luf55b58d2007-02-17 14:28:11 +000016 */
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 Luf55b58d2007-02-17 14:28:11 +000023#include <cpu/amd/amdk8_sysconf.h>
Yinghai Luf55b58d2007-02-17 14:28:11 +000024#include "mb_sysconf.h"
25
Myles Watson08e0fb82010-03-22 16:33:25 +000026static void *smp_write_config_table(void *v)
Yinghai Luf55b58d2007-02-17 14:28:11 +000027{
Myles Watsona643ea32008-10-06 21:00:46 +000028 struct mp_config_table *mc;
Yinghai Luf55b58d2007-02-17 14:28:11 +000029 struct mb_sysconf_t *m;
30 unsigned sbdn;
Patrick Georgi5244e1b2010-11-21 14:41:07 +000031 int i, j, bus_isa;
Yinghai Luf327d9f2008-02-20 17:41:38 +000032 unsigned char apicpin[4];
Yinghai Luf55b58d2007-02-17 14:28:11 +000033
Myles Watsona643ea32008-10-06 21:00:46 +000034 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Yinghai Luf55b58d2007-02-17 14:28:11 +000035
Patrick Georgic8feedd2012-02-16 18:43:25 +010036 mptable_init(mc, LOCAL_APIC_ADDR);
Yinghai Luf55b58d2007-02-17 14:28:11 +000037
Myles Watsona643ea32008-10-06 21:00:46 +000038 smp_write_processors(mc);
Yinghai Luf55b58d2007-02-17 14:28:11 +000039
40 get_bus_conf();
41 sbdn = sysconf.sbdn;
42 m = sysconf.mb;
43
Patrick Georgi5244e1b2010-11-21 14:41:07 +000044 mptable_write_buses(mc, NULL, &bus_isa);
Yinghai Luf55b58d2007-02-17 14:28:11 +000045
46/*I/O APICs: APIC ID Version State Address*/
Myles Watsona643ea32008-10-06 21:00:46 +000047 {
48 device_t dev;
Yinghai Luf55b58d2007-02-17 14:28:11 +000049 struct resource *res;
50 uint32_t dword;
51
Myles Watsona643ea32008-10-06 21:00:46 +000052 dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn+ 0x1,0));
53 if (dev) {
Yinghai Luf55b58d2007-02-17 14:28:11 +000054 res = find_resource(dev, PCI_BASE_ADDRESS_1);
Yinghai Luf327d9f2008-02-20 17:41:38 +000055 if (res)
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080056 smp_write_ioapic(mc, m->apicid_mcp55, 0x11,
57 res2mmio(res, 0, 0));
Yinghai Luf327d9f2008-02-20 17:41:38 +000058
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 Luf55b58d2007-02-17 14:28:11 +000064
65 dword = 0x43c6c643;
Yinghai Luf327d9f2008-02-20 17:41:38 +000066 pci_write_config32(dev, 0x7c, dword);
Yinghai Luf55b58d2007-02-17 14:28:11 +000067
Myles Watsona643ea32008-10-06 21:00:46 +000068 dword = 0x81001a00;
69 pci_write_config32(dev, 0x80, dword);
Yinghai Luf55b58d2007-02-17 14:28:11 +000070
Yinghai Luf327d9f2008-02-20 17:41:38 +000071 dword = 0xd00012d2;
Myles Watsona643ea32008-10-06 21:00:46 +000072 pci_write_config32(dev, 0x84, dword);
Yinghai Luf55b58d2007-02-17 14:28:11 +000073
Myles Watsona643ea32008-10-06 21:00:46 +000074 }
Yinghai Luf55b58d2007-02-17 14:28:11 +000075
Yinghai Luf327d9f2008-02-20 17:41:38 +000076 if (m->bus_mcp55b) {
Myles Watsona643ea32008-10-06 21:00:46 +000077 dev = dev_find_slot(m->bus_mcp55b, PCI_DEVFN(m->sbdnb + 0x1,0));
78 if (dev) {
Yinghai Luf55b58d2007-02-17 14:28:11 +000079 res = find_resource(dev, PCI_BASE_ADDRESS_1);
Yinghai Luf327d9f2008-02-20 17:41:38 +000080 if (res)
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080081 smp_write_ioapic(mc, m->apicid_mcp55b, 0x11,
82 res2mmio(res, 0, 0));
Yinghai Luf327d9f2008-02-20 17:41:38 +000083
Yinghai Luf55b58d2007-02-17 14:28:11 +000084 dword = 0x43c60000;
Yinghai Luf327d9f2008-02-20 17:41:38 +000085 pci_write_config32(dev, 0x7c, dword);
Yinghai Luf55b58d2007-02-17 14:28:11 +000086
Myles Watsona643ea32008-10-06 21:00:46 +000087 dword = 0x81000000;
88 pci_write_config32(dev, 0x80, dword);
Yinghai Luf55b58d2007-02-17 14:28:11 +000089
Yinghai Luf327d9f2008-02-20 17:41:38 +000090 dword = 0xd00002d0;
Myles Watsona643ea32008-10-06 21:00:46 +000091 pci_write_config32(dev, 0x84, dword);
Yinghai Luf55b58d2007-02-17 14:28:11 +000092
Myles Watsona643ea32008-10-06 21:00:46 +000093 }
Yinghai Luf55b58d2007-02-17 14:28:11 +000094
95 }
96
97 }
Yinghai Luf327d9f2008-02-20 17:41:38 +000098
Patrick Georgi5244e1b2010-11-21 14:41:07 +000099 mptable_add_isa_interrupts(mc, bus_isa, m->apicid_mcp55, 0);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000100
Myles Watsona643ea32008-10-06 21:00:46 +0000101 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 Luf55b58d2007-02-17 14:28:11 +0000102
Myles Watsona643ea32008-10-06 21:00:46 +0000103 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 Luf55b58d2007-02-17 14:28:11 +0000104
Myles Watsona643ea32008-10-06 21:00:46 +0000105 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 Luf55b58d2007-02-17 14:28:11 +0000106
Myles Watsona643ea32008-10-06 21:00:46 +0000107 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 Luf55b58d2007-02-17 14:28:11 +0000108
Myles Watsona643ea32008-10-06 21:00:46 +0000109 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 Luf55b58d2007-02-17 14:28:11 +0000112
Myles Watsona643ea32008-10-06 21:00:46 +0000113 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 Luf55b58d2007-02-17 14:28:11 +0000115
Yinghai Luf327d9f2008-02-20 17:41:38 +0000116//Slot PCIE
117 for (j = 2; j < 8; j++) {
Myles Watsona643ea32008-10-06 21:00:46 +0000118 device_t dev;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000119 dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn + 0x0a + j - 2 , 0));
120 if (!dev || !dev->enabled)
121 continue;
Myles Watsona643ea32008-10-06 21:00:46 +0000122 for (i = 0; i < 4; i++)
123 apicpin[i] = 0x10 + (2+j+i+4-sbdn%4)%4;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000124 smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55, apicpin);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000125 }
126
Yinghai Luf327d9f2008-02-20 17:41:38 +0000127//Slot PCI 32
128 {
Myles Watsona643ea32008-10-06 21:00:46 +0000129 device_t dev;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000130 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 Luf55b58d2007-02-17 14:28:11 +0000137
Yinghai Luf327d9f2008-02-20 17:41:38 +0000138 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 Luf55b58d2007-02-17 14:28:11 +0000142
Yinghai Luf327d9f2008-02-20 17:41:38 +0000143 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 Luf55b58d2007-02-17 14:28:11 +0000145
146
Yinghai Luf327d9f2008-02-20 17:41:38 +0000147 //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 Luf55b58d2007-02-17 14:28:11 +0000155 }
Yinghai Luf327d9f2008-02-20 17:41:38 +0000156 smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55b, apicpin);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000157 }
Yinghai Luf327d9f2008-02-20 17:41:38 +0000158
Yinghai Luf55b58d2007-02-17 14:28:11 +0000159 }
Yinghai Luf55b58d2007-02-17 14:28:11 +0000160
161/*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200162 mptable_lintsrc(mc, bus_isa);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000163 /* There is no extension information... */
164
165 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200166 return mptable_finalize(mc);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000167}
168
169unsigned long write_smp_table(unsigned long addr)
170{
171 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +0200172 v = smp_write_floating_table(addr, 0);
Yinghai Luf55b58d2007-02-17 14:28:11 +0000173 return (unsigned long)smp_write_config_table(v);
174}