blob: ebfe7efa6b62e83021b8b5ecfac2ad57d8a0250e [file] [log] [blame]
Philipp Deglercd3afc02007-05-24 20:39:48 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Philipp Deglercd3afc02007-05-24 20:39:48 +00003 *
4 * Copyright (C) 2007 AMD
5 * (Written by Yinghai Lu <yinghailu@amd.com> for AMD)
6 * Copyright (C) 2007 Philipp Degler <pdegler@rumms.uni-mannheim.de>
7 * (Thanks to LSRA University of Mannheim for their support)
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <console/console.h>
25#include <arch/smp/mpspec.h>
26#include <device/pci.h>
27#include <string.h>
28#include <stdint.h>
Philipp Deglercd3afc02007-05-24 20:39:48 +000029#include <cpu/amd/amdk8_sysconf.h>
30
31extern unsigned char bus_isa;
32extern unsigned char bus_ck804[6];
33extern unsigned apicid_ck804;
Philipp Deglercd3afc02007-05-24 20:39:48 +000034extern unsigned bus_type[256];
Philipp Deglercd3afc02007-05-24 20:39:48 +000035extern void get_bus_conf(void);
36
37void *smp_write_config_table(void *v)
38{
39 static const char sig[4] = "PCMP";
40 static const char oem[8] = "ASUS ";
Uwe Hermann336935c2008-09-30 15:02:40 +000041 static const char productid[12] = "A8N-E ";
Philipp Deglercd3afc02007-05-24 20:39:48 +000042 struct mp_config_table *mc;
43 unsigned sbdn;
Uwe Hermann336935c2008-09-30 15:02:40 +000044 int i, bus_num;
Philipp Deglercd3afc02007-05-24 20:39:48 +000045
46 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
47 memset(mc, 0, sizeof(*mc));
48
49 memcpy(mc->mpc_signature, sig, sizeof(sig));
50 mc->mpc_length = sizeof(*mc); /* initially just the header */
51 mc->mpc_spec = 0x04;
52 mc->mpc_checksum = 0; /* not yet computed */
53 memcpy(mc->mpc_oem, oem, sizeof(oem));
54 memcpy(mc->mpc_productid, productid, sizeof(productid));
55 mc->mpc_oemptr = 0;
56 mc->mpc_oemsize = 0;
57 mc->mpc_entry_count = 0; /* No entries yet... */
58 mc->mpc_lapic = LAPIC_ADDR;
59 mc->mpe_length = 0;
60 mc->mpe_checksum = 0;
61 mc->reserved = 0;
62
63 smp_write_processors(mc);
64
65 get_bus_conf();
66 sbdn = sysconf.sbdn;
67
Uwe Hermann336935c2008-09-30 15:02:40 +000068 /* Bus: Bus ID Type */
69 /* Define numbers for PCI and ISA bus. */
Philipp Deglercd3afc02007-05-24 20:39:48 +000070 for (bus_num = 0; bus_num < 256; bus_num++) {
71 if (bus_type[bus_num])
72 smp_write_bus(mc, bus_num, "PCI ");
Uwe Hermann336935c2008-09-30 15:02:40 +000073 }
Philipp Deglercd3afc02007-05-24 20:39:48 +000074 smp_write_bus(mc, bus_isa, "ISA ");
75
Uwe Hermann336935c2008-09-30 15:02:40 +000076 /* I/O APICs: APIC ID Version State Address */
Philipp Deglercd3afc02007-05-24 20:39:48 +000077 {
78 device_t dev;
79 struct resource *res;
80 uint32_t dword;
81
82 dev = dev_find_slot(bus_ck804[0], PCI_DEVFN(sbdn + 0x1, 0));
83 if (dev) {
84 res = find_resource(dev, PCI_BASE_ADDRESS_1);
85 if (res) {
86 smp_write_ioapic(mc, apicid_ck804, 0x11,
87 res->base);
88 }
89
Uwe Hermann336935c2008-09-30 15:02:40 +000090 /* Initialize interrupt mapping. */
Philipp Deglercd3afc02007-05-24 20:39:48 +000091 dword = 0x01200000;
92 pci_write_config32(dev, 0x7c, dword);
93
94 dword = 0x12008009;
95 pci_write_config32(dev, 0x80, dword);
96
97 dword = 0x0002010d;
98 pci_write_config32(dev, 0x84, dword);
99
100 }
101 }
102
Uwe Hermann336935c2008-09-30 15:02:40 +0000103 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Philipp Deglercd3afc02007-05-24 20:39:48 +0000104 smp_write_intsrc(mc, mp_ExtINT,
105 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
106 bus_isa, 0x0, apicid_ck804, 0x0);
107 smp_write_intsrc(mc, mp_INT,
108 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
109 bus_isa, 0x1, apicid_ck804, 0x1);
110 smp_write_intsrc(mc, mp_INT,
111 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
112 bus_isa, 0x0, apicid_ck804, 0x2);
113 smp_write_intsrc(mc, mp_INT,
114 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
115 bus_isa, 0x4, apicid_ck804, 0x4);
116 smp_write_intsrc(mc, mp_INT,
117 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
118 bus_isa, 0x6, apicid_ck804, 0x6);
119 smp_write_intsrc(mc, mp_INT,
120 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
121 bus_isa, 0x7, apicid_ck804, 0x7);
122 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
123 bus_isa, 0x8, apicid_ck804, 0x8);
124 smp_write_intsrc(mc, mp_INT,
125 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
126 bus_isa, 0x9, apicid_ck804, 0x9);
127 smp_write_intsrc(mc, mp_INT,
128 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
129 bus_isa, 0xa, apicid_ck804, 0xa);
130 smp_write_intsrc(mc, mp_INT,
131 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
132 bus_isa, 0xc, apicid_ck804, 0xc);
133 smp_write_intsrc(mc, mp_INT,
134 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
135 bus_isa, 0xd, apicid_ck804, 0xd);
136 smp_write_intsrc(mc, mp_INT,
137 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
138 bus_isa, 0xe, apicid_ck804, 0xe);
139 smp_write_intsrc(mc, mp_INT,
140 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
141 bus_isa, 0xf, apicid_ck804, 0xf);
142
143 // Onboard ck804 smbus
144 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
145 bus_ck804[0], ((sbdn + 1) << 2) | 1, apicid_ck804,
146 0xa);
147
148 // Onboard ck804 USB 1.1
Uwe Hermann336935c2008-09-30 15:02:40 +0000149 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
150 bus_ck804[0], ((sbdn + 2) << 2) | 0, apicid_ck804,
151 0x15);
Philipp Deglercd3afc02007-05-24 20:39:48 +0000152
153 // Onboard ck804 USB 2
Uwe Hermann336935c2008-09-30 15:02:40 +0000154 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
155 bus_ck804[0], ((sbdn + 2) << 2) | 1, apicid_ck804,
156 0x14);
Philipp Deglercd3afc02007-05-24 20:39:48 +0000157
158 // Onboard ck804 SATA 0
Uwe Hermann336935c2008-09-30 15:02:40 +0000159 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
160 bus_ck804[0], ((sbdn + 7) << 2) | 0, apicid_ck804,
161 0x17);
Philipp Deglercd3afc02007-05-24 20:39:48 +0000162
163 // Onboard ck804 SATA 1
Uwe Hermann336935c2008-09-30 15:02:40 +0000164 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
165 bus_ck804[0], ((sbdn + 8) << 2) | 0, apicid_ck804,
166 0x16);
Philipp Deglercd3afc02007-05-24 20:39:48 +0000167
168 // Onboard ck804 NIC
Uwe Hermann336935c2008-09-30 15:02:40 +0000169 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
170 bus_ck804[0], ((sbdn + 10) << 2) | 0, apicid_ck804,
171 0x17);
Philipp Deglercd3afc02007-05-24 20:39:48 +0000172
Uwe Hermann336935c2008-09-30 15:02:40 +0000173 /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Philipp Deglercd3afc02007-05-24 20:39:48 +0000174 smp_write_intsrc(mc, mp_ExtINT,
175 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
176 bus_ck804[0], 0x0, MP_APIC_ALL, 0x0);
177 smp_write_intsrc(mc, mp_NMI,
178 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT,
179 bus_ck804[0], 0x0, MP_APIC_ALL, 0x1);
180
181 /* There is no extension information... */
182
Uwe Hermann336935c2008-09-30 15:02:40 +0000183 /* Compute the checksums. */
Philipp Deglercd3afc02007-05-24 20:39:48 +0000184 mc->mpe_checksum =
185 smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
186 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000187 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
Philipp Deglercd3afc02007-05-24 20:39:48 +0000188 mc, smp_next_mpe_entry(mc));
189 return smp_next_mpe_entry(mc);
190}
191
192unsigned long write_smp_table(unsigned long addr)
193{
Uwe Hermann336935c2008-09-30 15:02:40 +0000194 void *v = smp_write_floating_table(addr);
Philipp Deglercd3afc02007-05-24 20:39:48 +0000195 return (unsigned long)smp_write_config_table(v);
196}