blob: e7ad0b1b6562bde46cac57caaa50f9d6b634cdb7 [file] [log] [blame]
Timothy Pearson80572852015-01-23 20:35:48 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
5 *
6 * Copyright (C) 2007 AMD
7 * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
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.
Timothy Pearson80572852015-01-23 20:35:48 -060018 */
19
20#define FAM10_SCAN_PCI_BUS 0
21#define FAM10_ALLOCATE_IO_RANGE 1
22
23unsigned int get_sbdn(unsigned bus);
24
25#include <stdint.h>
26#include <string.h>
27#include <reset.h>
28#include <device/pci_def.h>
29#include <device/pci_ids.h>
30#include <arch/io.h>
31#include <device/pnp_def.h>
32#include <cpu/x86/lapic.h>
33#include <console/console.h>
Timothy Pearson91e9f672015-03-19 16:44:46 -050034#include <timestamp.h>
Timothy Pearson80572852015-01-23 20:35:48 -060035#include <lib.h>
36#include <spd.h>
37#include <cpu/amd/model_10xxx_rev.h>
38#include "southbridge/nvidia/ck804/early_smbus.h"
39#include <northbridge/amd/amdfam10/raminit.h>
40#include <northbridge/amd/amdfam10/amdfam10.h>
41#include "lib/delay.c"
42#include <cpu/x86/lapic.h>
43#include "northbridge/amd/amdfam10/reset_test.c"
44#include <superio/winbond/common/winbond.h>
45#include <superio/winbond/w83627thg/w83627thg.h>
46#include <cpu/x86/bist.h>
47// #include "northbridge/amd/amdk8/incoherent_ht.c"
48#include "northbridge/amd/amdfam10/debug.c"
49#include "northbridge/amd/amdfam10/setup_resource_map.c"
50
51#define SERIAL_DEV PNP_DEV(0x2e, W83627THG_SP1)
52
53static void activate_spd_rom(const struct mem_controller *ctrl);
54
55static inline int spd_read_byte(unsigned device, unsigned address)
56{
57 return smbus_read_byte(device, address);
58}
59
60#include <northbridge/amd/amdfam10/amdfam10.h>
61#include "northbridge/amd/amdfam10/raminit_sysinfo_in_ram.c"
62#include "northbridge/amd/amdfam10/pci.c"
63#include "resourcemap.c"
64#include "cpu/amd/quadcore/quadcore.c"
65
Timothy Pearson80572852015-01-23 20:35:48 -060066#define CK804_MB_SETUP \
67 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+33, ~(0x0f),(0x04 | 0x01), /* -ENOINFO Proprietary BIOS sets this register; "When in Rome..."*/
68
69#include <southbridge/nvidia/ck804/early_setup_ss.h>
70#include "southbridge/nvidia/ck804/early_setup_car.c"
71#include <cpu/amd/microcode.h>
72
Timothy Pearsonb30d7ed2015-10-16 14:24:06 -050073#include "cpu/amd/family_10h-family_15h/init_cpus.c"
Timothy Pearson80572852015-01-23 20:35:48 -060074#include "northbridge/amd/amdfam10/early_ht.c"
75
76#define GPIO3_DEV PNP_DEV(0x2e, W83627THG_GPIO3)
77
78/**
79 * @brief Get SouthBridge device number
80 * @param[in] bus target bus number
81 * @return southbridge device number
82 */
83unsigned int get_sbdn(unsigned bus)
84{
85 device_t dev;
86
87 dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_NVIDIA,
88 PCI_DEVICE_ID_NVIDIA_CK804_PRO), bus);
89 return (dev >> 15) & 0x1f;
90}
91
92/*
93 * ASUS KFSN4-DRE specific SPD enable/disable magic.
94 *
95 * Setting CK804 GPIO43 and GPIO44 to 0 and 0 respectively will make the
96 * board DIMMs accessible at SMBus/SPD offsets 0x50-0x53. Per default the SPD
97 * offsets 0x50-0x53 are _not_ readable (all SPD reads will return 0xff) which
98 * will make RAM init fail.
99 *
100 * Disable SPD access after RAM init to allow access to standard SMBus/I2C offsets
101 * which is required e.g. by lm-sensors.
102 */
103
104#define CK804_BOARD_BOOT_BASE_UNIT_UID 1
105
106static const unsigned int ctrl_conf_enable_spd_node0[] = {
107 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+42, ~(0x0f),(0x04 | 0x00),/* W2,GPIO43, U6 input S0*/
108 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+43, ~(0x0f),(0x04 | 0x00),/* W3,GPIO44, U6 input S1*/
109};
110
111static const unsigned int ctrl_conf_enable_spd_node1[] = {
112 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+42, ~(0x0f),(0x04 | 0x00),/* W2,GPIO43, U6 input S0*/
113 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+43, ~(0x0f),(0x04 | 0x01),/* W3,GPIO44, U6 input S1*/
114};
115
116static const unsigned int ctrl_conf_disable_spd[] = {
117 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+42, ~(0x0f),(0x04 | 0x01),/* W2,GPIO43, U6 input S0*/
118 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0+43, ~(0x0f),(0x04 | 0x00),/* W3,GPIO44, U6 input S1*/
119};
120
121static const unsigned int ctrl_conf_fix_pci_numbering[] = {
122 RES_PCI_IO, PCI_ADDR(0, 0, 0, 0x44), ~(0x00010000), 0x00000000, /* Force CK804 to start its internal device numbering (Base Unit ID) at 0 instead of the power-on default of 1 */
123};
124
125static const unsigned int ctrl_conf_enable_msi_mapping[] = {
126 RES_PCI_IO, PCI_ADDR(0, 0, 0, 0xe0), ~(0x00000000), 0x00010000, /* Enable MSI mapping on host bridge -- without this Linux cannot use the network device MSI interrupts! */
127};
128
129static void ck804_control(const unsigned int* values, u32 size, uint8_t bus_unit_id)
130{
131 unsigned busn[4], io_base[4];
132 int i, ck804_num = 0;
133
134 for (i = 0; i < 4; i++) {
135 u32 id;
136 device_t dev;
137 if (i == 0) /* SB chain */
138 dev = PCI_DEV(i * 0x40, bus_unit_id, 0);
139 else
140 dev = 0;
141 id = pci_read_config32(dev, PCI_VENDOR_ID);
142 if (id == 0x005e10de) {
143 busn[ck804_num] = i * 0x40;
144 io_base[ck804_num] = i * 0x4000;
145 ck804_num++;
146 }
147 }
148
149 if (ck804_num < 1)
150 printk(BIOS_WARNING, "CK804 not found at device base unit id %02x!\n", bus_unit_id);
151
152 ck804_early_set_port(ck804_num, busn, io_base);
153
154 setup_resource_map_x_offset(values,
155 size,
156 PCI_DEV(0, bus_unit_id, 0), io_base[0]);
157
158 ck804_early_clear_port(ck804_num, busn, io_base);
159}
160
161static void sio_setup(void)
162{
163 u32 dword;
164 u8 byte;
165
166 /* Subject decoding */
167 byte = pci_read_config8(PCI_DEV(0, CK804_BOARD_BOOT_BASE_UNIT_UID + 1, 0), 0x7b);
168 byte |= 0x20;
169 pci_write_config8(PCI_DEV(0, CK804_BOARD_BOOT_BASE_UNIT_UID + 1, 0), 0x7b, byte);
170
171 /* LPC Positive Decode 0 */
172 dword = pci_read_config32(PCI_DEV(0, CK804_BOARD_BOOT_BASE_UNIT_UID + 1, 0), 0xa0);
173 /* Serial 0, Serial 1 */
174 dword |= (1 << 0) | (1 << 1);
175 pci_write_config32(PCI_DEV(0, CK804_BOARD_BOOT_BASE_UNIT_UID + 1, 0), 0xa0, dword);
176}
177
178static const uint8_t spd_addr[] = {
179 // Node 0
180 RC00, DIMM0, DIMM2, DIMM4, DIMM6, DIMM1, DIMM3, DIMM5, DIMM7,
181 // Node 1
182 RC01, DIMM0, DIMM2, DIMM4, DIMM6, DIMM1, DIMM3, DIMM5, DIMM7,
183};
184
185static void activate_spd_rom(const struct mem_controller *ctrl) {
186 printk(BIOS_DEBUG, "activate_spd_rom() for node %02x\n", ctrl->node_id);
187 if (ctrl->node_id == 0) {
188 printk(BIOS_DEBUG, "enable_spd_node0()\n");
189 ck804_control(ctrl_conf_enable_spd_node0, ARRAY_SIZE(ctrl_conf_enable_spd_node0), CK804_DEVN_BASE);
190 }
191 else if (ctrl->node_id == 1) {
192 printk(BIOS_DEBUG, "enable_spd_node1()\n");
193 ck804_control(ctrl_conf_enable_spd_node1, ARRAY_SIZE(ctrl_conf_enable_spd_node1), CK804_DEVN_BASE);
194 }
195}
196
197void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
198{
199 struct sys_info *sysinfo = &sysinfo_car;
200
201 u32 bsp_apicid = 0, val, wants_reset;
202 msr_t msr;
203
Timothy Pearson91e9f672015-03-19 16:44:46 -0500204 timestamp_init(timestamp_get());
205 timestamp_add_now(TS_START_ROMSTAGE);
206
Timothy Pearson80572852015-01-23 20:35:48 -0600207 if (!cpu_init_detectedx && boot_cpu()) {
208 /* Nothing special needs to be done to find bus 0 */
209 /* Allow the HT devices to be found */
210 set_bsp_node_CHtExtNodeCfgEn();
211 enumerate_ht_chain();
212 sio_setup();
213 }
214
215 post_code(0x30);
216
217 if (bist == 0)
218 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
219
220 post_code(0x32);
221
222 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
223 console_init();
224
225 if (CONFIG_MAX_PHYSICAL_CPUS != 2)
226 printk(BIOS_WARNING, "CONFIG_MAX_PHYSICAL_CPUS is %d, but this is a dual socket board!\n", CONFIG_MAX_PHYSICAL_CPUS);
227
228 /* Halt if there was a built in self test failure */
229 report_bist_failure(bist);
230
231 val = cpuid_eax(1);
232 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
233 printk(BIOS_DEBUG, "*sysinfo range: [%p,%p]\n",sysinfo,sysinfo+1);
234 printk(BIOS_DEBUG, "bsp_apicid = %02x\n", bsp_apicid);
235 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
236
237 /* Setup sysinfo defaults */
238 set_sysinfo_in_ram(0);
239
240 update_microcode(val);
241
242 post_code(0x33);
243
Timothy Pearson730a0432015-10-16 13:51:51 -0500244 cpuSetAMDMSR(0);
Timothy Pearson80572852015-01-23 20:35:48 -0600245 post_code(0x34);
246
247 amd_ht_init(sysinfo);
248 post_code(0x35);
249
250 /* Setup nodes PCI space and start core 0 AP init. */
251 finalize_node_setup(sysinfo);
252
253 /* Setup any mainboard PCI settings etc. */
254 setup_mb_resource_map();
255 post_code(0x36);
256
257 /* wait for all the APs core0 started by finalize_node_setup. */
258 /* FIXME: A bunch of cores are going to start output to serial at once.
259 * It would be nice to fix up prink spinlocks for ROM XIP mode.
260 * I think it could be done by putting the spinlock flag in the cache
261 * of the BSP located right after sysinfo.
262 */
263 wait_all_core0_started();
264
Timothy Pearson80572852015-01-23 20:35:48 -0600265 if (IS_ENABLED(CONFIG_SET_FIDVID)) {
266 msr = rdmsr(0xc0010071);
267 printk(BIOS_DEBUG, "\nBegin FIDVID MSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
268
269 post_code(0x39);
270
271 if (!warm_reset_detect(0)) { // BSP is node 0
272 init_fidvid_bsp(bsp_apicid, sysinfo->nodes);
273 } else {
274 init_fidvid_stage2(bsp_apicid, 0); // BSP is node 0
275 }
276
277 post_code(0x3A);
278
279 /* show final fid and vid */
280 msr=rdmsr(0xc0010071);
281 printk(BIOS_DEBUG, "End FIDVIDMSR 0xc0010071 0x%08x 0x%08x\n", msr.hi, msr.lo);
282 }
283
Timothy Pearsonf73179d2015-02-10 00:37:21 -0600284 if (IS_ENABLED(CONFIG_LOGICAL_CPUS)) {
285 /* Core0 on each node is configured. Now setup any additional cores. */
286 printk(BIOS_DEBUG, "start_other_cores()\n");
Timothy Pearson0122afb2015-07-30 14:07:15 -0500287 start_other_cores(bsp_apicid);
Timothy Pearsonf73179d2015-02-10 00:37:21 -0600288 post_code(0x37);
289 wait_all_other_cores_started(bsp_apicid);
290 }
291
292 printk(BIOS_DEBUG, "set_ck804_base_unit_id()\n");
293 ck804_control(ctrl_conf_fix_pci_numbering, ARRAY_SIZE(ctrl_conf_fix_pci_numbering), CK804_BOARD_BOOT_BASE_UNIT_UID);
294
295 post_code(0x38);
296
Timothy Pearson80572852015-01-23 20:35:48 -0600297 init_timer(); // Need to use TMICT to synconize FID/VID
298
299 wants_reset = ck804_early_setup_x();
300
301 /* Reset for HT, FIDVID, PLL and errata changes to take affect. */
302 if (!warm_reset_detect(0)) {
303 printk(BIOS_INFO, "...WARM RESET...\n\n\n");
304 soft_reset();
305 die("After soft_reset_x - shouldn't see this message!!!\n");
306 }
307
308 if (wants_reset) {
309 printk(BIOS_DEBUG, "ck804_early_setup_x wanted additional reset!\n");
310 }
311
312 post_code(0x3B);
313
314 /* It's the time to set ctrl in sysinfo now; */
315 printk(BIOS_DEBUG, "fill_mem_ctrl()\n");
316 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
317 post_code(0x3D);
318
319 printk(BIOS_DEBUG, "enable_smbus()\n");
320 enable_smbus();
321
322#if 0
323 /* FIXME
324 * After the AMD K10 code has been converted to use
325 * IS_ENABLED(CONFIG_DEBUG_SMBUS) uncomment this block
326 */
327 if (IS_ENABLED(CONFIG_DEBUG_SMBUS)) {
328 dump_spd_registers(&cpu[0]);
329 dump_smbus_registers();
330 }
331#endif
332
333 post_code(0x40);
334
Timothy Pearson91e9f672015-03-19 16:44:46 -0500335 timestamp_add_now(TS_BEFORE_INITRAM);
Timothy Pearson80572852015-01-23 20:35:48 -0600336 printk(BIOS_DEBUG, "raminit_amdmct()\n");
337 raminit_amdmct(sysinfo);
Timothy Pearson91e9f672015-03-19 16:44:46 -0500338 timestamp_add_now(TS_AFTER_INITRAM);
339
Timothy Pearson86f4ca52015-03-13 13:27:58 -0500340 cbmem_initialize_empty();
Timothy Pearson80572852015-01-23 20:35:48 -0600341 post_code(0x41);
342
Timothy Pearson22564082015-03-27 22:49:18 -0500343 amdmct_cbmem_store_info(sysinfo);
344
Timothy Pearson80572852015-01-23 20:35:48 -0600345 printk(BIOS_DEBUG, "disable_spd()\n");
346 ck804_control(ctrl_conf_disable_spd, ARRAY_SIZE(ctrl_conf_disable_spd), CK804_DEVN_BASE);
347
348 printk(BIOS_DEBUG, "enable_msi_mapping()\n");
349 ck804_control(ctrl_conf_enable_msi_mapping, ARRAY_SIZE(ctrl_conf_enable_msi_mapping), CK804_DEVN_BASE);
350
351 /* Initialize GPIO */
352 /* Access SuperIO GPI03 logical device */
353 uint16_t port = GPIO3_DEV >> 8;
354 outb(0x87, port);
355 outb(0x87, port);
356 pnp_set_logical_device(GPIO3_DEV);
357 /* Set GP37 (power LED) to output */
358 pnp_write_config(GPIO3_DEV, 0xf0, 0x7f);
359 /* Set GP37 (power LED) on */
360 pnp_write_config(GPIO3_DEV, 0xf1, 0x80);
361 /* Set pin 64 multiplex to GP37 */
362 uint8_t cr2c = pnp_read_config(GPIO3_DEV, 0x2c);
363 pnp_write_config(GPIO3_DEV, 0x2c, (cr2c & 0xf3) | 0x04);
364 /* Restore default SuperIO access */
365 outb(0xaa, port);
366
Timothy Pearson80572852015-01-23 20:35:48 -0600367 post_cache_as_ram(); // BSP switch stack to ram, copy then execute LB.
368 post_code(0x43); // Should never see this post code.
369}
370
371/**
372 * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
373 * Description:
374 * This routine is called every time a non-coherent chain is processed.
375 * BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
376 * swap list. The first part of the list controls the BUID assignment and the
377 * second part of the list provides the device to device linking. Device orientation
378 * can be detected automatically, or explicitly. See documentation for more details.
379 *
380 * Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
381 * based on each device's unit count.
382 *
383 * Parameters:
384 * @param[in] node = The node on which this chain is located
385 * @param[in] link = The link on the host for this chain
386 * @param[out] List = supply a pointer to a list
387 */
388BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, const u8 **List)
389{
390 return 0;
391}