blob: 5aeb71dd33d5e5afc25a8aa8f97cb6b43bc26176 [file] [log] [blame]
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2001 Eric W.Biederman<ebiderman@lnxi.com>
5 *
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.
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000024 */
25
26#include <console/console.h>
27#include <arch/smp/mpspec.h>
28#include <arch/io.h>
29#include <device/pci.h>
30#include <string.h>
31#include <stdint.h>
Patrick Georgie1667822012-05-05 15:29:32 +020032#if CONFIG_LOGICAL_CPUS
Stefan Reinauer9a16e3e2010-03-29 14:45:36 +000033#include <cpu/amd/multicore.h>
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000034#endif
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000035#include <cpu/amd/amdk8_sysconf.h>
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000036#include "mb_sysconf.h"
37
Myles Watson08e0fb82010-03-22 16:33:25 +000038static void *smp_write_config_table(void *v)
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000039{
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000040 struct mp_config_table *mc;
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000041 struct mb_sysconf_t *m;
Patrick Georgi5244e1b2010-11-21 14:41:07 +000042 int bus_isa;
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000043
44 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000045
Patrick Georgic8feedd2012-02-16 18:43:25 +010046 mptable_init(mc, LOCAL_APIC_ADDR);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000047
48 smp_write_processors(mc);
49
50 get_bus_conf();
51 m = sysconf.mb;
52
Patrick Georgi5244e1b2010-11-21 14:41:07 +000053 mptable_write_buses(mc, NULL, &bus_isa);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000054
55 /*I/O APICs: APIC ID Version State Address*/
56 {
57 device_t dev = 0;
58 int i;
59 struct resource *res;
60 for(i=0; i<3; i++) {
61 dev = dev_find_device(0x1166, 0x0235, dev);
62 if (dev) {
63 res = find_resource(dev, PCI_BASE_ADDRESS_0);
64 if (res) {
Myles Watson08e0fb82010-03-22 16:33:25 +000065 printk(BIOS_DEBUG, "APIC %d base address: %llx\n",m->apicid_bcm5785[i], res->base);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080066 smp_write_ioapic(mc, m->apicid_bcm5785[i], 0x11,
67 res2mmio(res, 0, 0));
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +000068 }
69 }
70 }
71
72 }
73
74 /* IRQ routing as factory BIOS */
75 outb(0x01, 0xc00); outb(0x0A, 0xc01);
76 outb(0x17, 0xc00); outb(0x05, 0xc01);
77/* outb(0x2E, 0xc00); outb(0x0B, 0xc01); */
78/* outb(0x07, 0xc00); outb(0x07, 0xc01); */
79 outb(0x07, 0xc00); outb(0x0b, 0xc01);
80
81 outb(0x24, 0xc00); outb(0x05, 0xc01);
82 //outb(0x00, 0xc00); outb(0x09, 0xc01);
83 outb(0x02, 0xc00); outb(0x0E, 0xc01);
84
85 // 8259 registers...
86 outb(0xa0, 0x4d0);
87 outb(0x0e, 0x4d1);
88
89 {
90 device_t dev;
91 dev = dev_find_device(0x1166, 0x0205, 0);
92 if(dev) {
93 uint32_t dword;
94 dword = pci_read_config32(dev, 0x64);
95 dword |= (1<<30); // GEVENT14-21 used as PCI IRQ0-7
96 pci_write_config32(dev, 0x64, dword);
97 }
98 // set GEVENT pins to NO OP
99 outb(0x33, 0xcd6); outb(0x00, 0xcd7);
100 outb(0x34, 0xcd6); outb(0x00, 0xcd7);
101 outb(0x35, 0xcd6); outb(0x00, 0xcd7);
102 }
103
104 // hide XIOAPIC PCI configuration space
105 {
106 device_t dev;
107 dev = dev_find_device(0x1166, 0x205, 0);
108 if (dev) {
109 uint32_t dword;
110 dword = pci_read_config32(dev, 0x64);
111 dword |= (1<<26);
112 pci_write_config32(dev, 0x64, dword);
113 }
114 }
115
Patrick Georgi5244e1b2010-11-21 14:41:07 +0000116 mptable_add_isa_interrupts(mc, bus_isa, m->apicid_bcm5785[0], 0);
Patrick Georgic5b87c82010-05-20 15:28:19 +0000117
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000118 //SATA
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000119/* printk(BIOS_DEBUG, "MPTABLE_SATA: bus_id:%d irq:%d apic_id:%d pin:%d\n",m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0x7); */
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000120/* smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0x7); */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000121 printk(BIOS_DEBUG, "MPTABLE_SATA: bus_id:%d irq:%d apic_id:%d pin:%d\n",m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0xb);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000122 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0xb);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000123 //USB
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200124 printk(BIOS_DEBUG, "sysconf.sbdn: %d on bus: %x\n",sysconf.sbdn, m->bus_bcm5785_0);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000125 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x03<<2)|0, m->apicid_bcm5785[0], 0xa);
126
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000127 //VGA
128 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x4<<2)|0, m->apicid_bcm5785[1], 0x7);
129
130 //PCIE
131 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x6<<2)|0, m->apicid_bcm5785[2], 0xe);
132 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x7<<2)|0, m->apicid_bcm5785[2], 0xe);
133 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x8<<2)|0, m->apicid_bcm5785[2], 0xe);
134 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x9<<2)|0, m->apicid_bcm5785[2], 0xe);
135 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0xa<<2)|0, m->apicid_bcm5785[2], 0xe);
136
137 //IDE
138// outb(0x02, 0xc00); outb(0x0e, 0xc01);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000139// printk(BIOS_DEBUG, "MPTABLE_IDE: bus_id:%d irq:%d apic_id:%d pin:%d\n",m->bus_bcm5785_0, ((1+sysconf.sbdn)<<2)|1, m->apicid_bcm5785[0], 0xe);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000140// smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_bcm5785_0, (0x02<<2)|1, m->apicid_bcm5785[0], 0xe);
141
142 //onboard Broadcom GbE
143 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,8, (4<<2)|0, m->apicid_bcm5785[2], 0x4);
144 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,8, (4<<2)|1, m->apicid_bcm5785[2], 0x4);
145
146
147
148 /* enable int */
149 /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
150 {
151 device_t dev;
152 dev = dev_find_device(0x1166, 0x0205, 0);
153 if(dev) {
154 uint32_t dword;
155 dword = pci_read_config32(dev, 0x6c);
156 dword |= (1<<4); // enable interrupts
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000157 printk(BIOS_DEBUG, "6ch: %x\n",dword);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000158 pci_write_config32(dev, 0x6c, dword);
159 }
160 }
161
162/*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
Patrick Georgi5244e1b2010-11-21 14:41:07 +0000163 printk(BIOS_DEBUG, "bus_isa is: %x\n", bus_isa);
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200164 mptable_lintsrc(mc, bus_isa);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000165
166 //extended table entries
167 smp_write_address_space(mc,0 , ADDRESS_TYPE_IO, 0x0, 0x0, 0x0, 0x0001);
168 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0x7f80, 0x0, 0x5e80);
169 smp_write_address_space(mc,0 , ADDRESS_TYPE_PREFETCH, 0x0, 0xde00, 0x0, 0x0100);
170 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0xdf00, 0x0, 0x1fe0);
171 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x1000, 0xfee0, 0xf000, 0x011f);
172 smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0x000a, 0x0, 0x0006);
173 smp_write_bus_hierarchy(mc, 9, 0x01, 0);
174 smp_write_compatibility_address_space(mc, 0, ADDRESS_RANGE_ADD, 0);
175 smp_write_compatibility_address_space(mc, 0, ADDRESS_RANGE_ADD, 1);
176
177
178 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200179 return mptable_finalize(mc);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000180}
181
182unsigned long write_smp_table(unsigned long addr)
183{
184 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +0200185 v = smp_write_floating_table(addr, 0);
Mondrian nuessle5b34bdd2009-04-22 20:34:05 +0000186 return (unsigned long)smp_write_config_table(v);
187}