blob: f204632078d91a3bd620a35e46cbe4574992f5c7 [file] [log] [blame]
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +00001/*
2 * This file is part of the coreboot project.
3 *
Elyes HAOUAS531b87a2016-09-19 09:46:33 -06004 * Copyright (C) 2001 Eric W.Biederman < ebiderman@lnxi.com>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +00005 *
6 * Copyright (C) 2006 AMD
7 * Written by Yinghai Lu <yinghailu@gmail.com> for AMD.
8 *
9 * Copyright (C) 2007 University of Mannheim
10 * Written by Philipp Degler <pdegler@rumms.uni-mannheim.e> for Uni of Mannheim
11 *
12 * Copyright (C) 2009 University of Heidelberg
13 * Written by Mondrian Nuessle <nuessle@uni-hd.de> for Uni of Heidelberg
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000024 */
25
26#include <console/console.h>
27#include <arch/smp/mpspec.h>
28#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020029#include <device/pci_ops.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000030#include <device/pci.h>
31#include <string.h>
32#include <stdint.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080033#if CONFIG(LOGICAL_CPUS)
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000034#include <cpu/amd/multicore.h>
35#endif
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000036#include <cpu/amd/amdfam10_sysconf.h>
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000037#include "mb_sysconf.h"
38
39static void *smp_write_config_table(void *v)
40{
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000041 struct mp_config_table *mc;
42 int isa_bus;
43
44 struct mb_sysconf_t *m;
45
46 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000047
Patrick Georgic8feedd2012-02-16 18:43:25 +010048 mptable_init(mc, LOCAL_APIC_ADDR);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000049
50 smp_write_processors(mc);
51
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000052 m = sysconf.mb;
53
54 mptable_write_buses(mc, NULL, &isa_bus);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000055
56 /*I/O APICs: APIC ID Version State Address*/
57 {
Elyes HAOUAS56f172d2018-05-04 20:41:40 +020058 struct device *dev = NULL;
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000059 int i;
60 struct resource *res;
Elyes HAOUAS36ece932018-02-01 09:18:58 +010061 for (i = 0; i < 3; i++) {
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000062 dev = dev_find_device(0x1166, 0x0235, dev);
63 if (dev) {
64 res = find_resource(dev, PCI_BASE_ADDRESS_0);
65 if (res) {
66 printk(BIOS_DEBUG, "APIC %d base address: %x\n",m->apicid_bcm5785[i], (int)res->base);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080067 smp_write_ioapic(mc, m->apicid_bcm5785[i], 0x11,
68 res2mmio(res, 0, 0));
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000069 }
70 }
71 }
72
73 }
74
75 /* IRQ routing as factory BIOS */
76 outb(0x00, 0xc00); outb(0x09, 0xc01);
77 outb(0x01, 0xc00); outb(0x0a, 0xc01);
78 outb(0x02, 0xc00); outb(0x0e, 0xc01);
79 outb(0x03, 0xc00); outb(0x07, 0xc01);
80 outb(0x07, 0xc00); outb(0x05, 0xc01);
81
82 // 8259 registers...
83 outb(0xa0, 0x4d0);
84 outb(0x0e, 0x4d1);
85
86 {
Elyes HAOUAS56f172d2018-05-04 20:41:40 +020087 struct device *dev;
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000088 dev = dev_find_device(0x1166, 0x0205, 0);
Elyes HAOUAS36ece932018-02-01 09:18:58 +010089 if (dev) {
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000090 uint32_t dword;
91 dword = pci_read_config32(dev, 0x64);
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060092 dword |= (1 << 30); // GEVENT14-21 used as PCI IRQ0-7
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +000093 pci_write_config32(dev, 0x64, dword);
94 }
95 // set GEVENT pins to NO OP
96 /* outb(0x33, 0xcd6); outb(0x00, 0xcd7);
97 outb(0x34, 0xcd6); outb(0x00, 0xcd7);
98 outb(0x35, 0xcd6); outb(0x00, 0xcd7); */
99 }
100
101 // hide XIOAPIC PCI configuration space
102 {
Elyes HAOUAS56f172d2018-05-04 20:41:40 +0200103 struct device *dev;
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000104 dev = dev_find_device(0x1166, 0x205, 0);
105 if (dev) {
106 uint32_t dword;
107 dword = pci_read_config32(dev, 0x64);
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600108 dword |= (1 << 26);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000109 pci_write_config32(dev, 0x64, dword);
110 }
111 }
112
113 mptable_add_isa_interrupts(mc, isa_bus, m->apicid_bcm5785[0], 0);
114
115 /* I/O Ints: Type Polarity/Trigger Bus ID IRQ APIC ID PIN# */
Kyösti Mälkki993bc702019-01-04 06:02:22 +0200116 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_1, 0xe, 0, m->apicid_bcm5785[0], 0x5);
117 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_0, 0x3, 0, m->apicid_bcm5785[0], 0xa);
118 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_0, 0x6, 0, m->apicid_bcm5785[2], 0x4);
119 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_0, 0x7, 0, m->apicid_bcm5785[2], 0x3);
120 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_0, 0x8, 0, m->apicid_bcm5785[2], 0x2);
121 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_0, 0x9, 0, m->apicid_bcm5785[2], 0x1);
122 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_0, 0xa, 0, m->apicid_bcm5785[2], 0x0);
123 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_1_1, 0x2, 0, m->apicid_bcm5785[2], 0x8);
124 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5785_1_1, 0x2, 1, m->apicid_bcm5785[2], 0x7);
125 smp_write_pci_intsrc(mc, mp_INT, m->bus_bcm5780[5], 0x0, 0, m->apicid_bcm5785[2], 0xa);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000126
127 /* enable int */
128 /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
129 {
Elyes HAOUAS56f172d2018-05-04 20:41:40 +0200130 struct device *dev;
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000131 dev = dev_find_device(0x1166, 0x0205, 0);
Elyes HAOUAS36ece932018-02-01 09:18:58 +0100132 if (dev) {
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000133 uint32_t dword;
134 dword = pci_read_config32(dev, 0x6c);
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600135 dword |= (1 << 4); // enable interrupts
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000136 printk(BIOS_DEBUG, "6ch: %x\n",dword);
137 pci_write_config32(dev, 0x6c, dword);
138 }
139 }
140
141 /* Local Ints: Type Polarity/Trigger Bus ID IRQ APIC ID PIN# */
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200142 mptable_lintsrc(mc, isa_bus);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000143
144 //extended table entries
145 smp_write_address_space(mc,0 , ADDRESS_TYPE_IO, 0x0, 0x0, 0x0, 0x0001);
146 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0x7f80, 0x0, 0x5e80);
147 smp_write_address_space(mc,0 , ADDRESS_TYPE_PREFETCH, 0x0, 0xde00, 0x0, 0x0100);
148 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0xdf00, 0x0, 0x1fe0);
149 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x1000, 0xfee0, 0xf000, 0x011f);
150 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0x000a, 0x0, 0x0006);
151 smp_write_bus_hierarchy(mc, 8, 0x01, 0);
152 smp_write_compatibility_address_space(mc, 0, ADDRESS_RANGE_ADD, 0);
153 smp_write_compatibility_address_space(mc, 0, ADDRESS_RANGE_ADD, 1);
154
155
156 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200157 return mptable_finalize(mc);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000158}
159
160unsigned long write_smp_table(unsigned long addr)
161{
162 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +0200163 v = smp_write_floating_table(addr, 0);
Arne Georg Gleditsch9139e7b2010-09-24 17:35:32 +0000164 return (unsigned long)smp_write_config_table(v);
165}