51269b1cf65264e3e864d37ed4c6efc605ac3256
[coreboot.git] / src / mainboard / amd / pistachio / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #define RAMINIT_SYSINFO 1
21 #define SET_FIDVID 1
22 #define QRANK_DIMM_SUPPORT 1
23 #if CONFIG_LOGICAL_CPUS==1
24 #define SET_NB_CFG_54 1
25 #endif
26
27 #define DIMM0 0x50
28 #define DIMM1 0x51
29
30 #include <stdint.h>
31 #include <string.h>
32 #include <device/pci_def.h>
33 #include <arch/io.h>
34 #include <device/pnp_def.h>
35 #include <arch/romcc_io.h>
36 #include <cpu/x86/lapic.h>
37 #include <pc80/mc146818rtc.h>
38 #include <console/console.h>
39
40 #include <cpu/amd/model_fxx_rev.h>
41 #include "northbridge/amd/amdk8/raminit.h"
42 #include "cpu/amd/model_fxx/apic_timer.c"
43 #include "lib/delay.c"
44
45 #include "cpu/x86/lapic/boot_cpu.c"
46 #include "northbridge/amd/amdk8/reset_test.c"
47 #include "superio/ite/it8712f/it8712f_early_serial.c"
48 #include <usbdebug.h>
49
50 #include "cpu/x86/mtrr/earlymtrr.c"
51 #include "cpu/x86/bist.h"
52
53 #include "northbridge/amd/amdk8/setup_resource_map.c"
54
55 #include "southbridge/amd/rs690/rs690_early_setup.c"
56 #include "southbridge/amd/sb600/sb600_early_setup.c"
57 #include "northbridge/amd/amdk8/debug.c" /* After sb600_early_setup.c! */
58
59 /* CAN'T BE REMOVED! memory bus reset hook for some broken amd k8 boards. */
60 static void memreset(int controllers, const struct mem_controller *ctrl)
61 {
62 }
63
64 /* called in raminit_f.c */
65 static inline void activate_spd_rom(const struct mem_controller *ctrl)
66 {
67 }
68
69 /*called in raminit_f.c */
70 static inline int spd_read_byte(u32 device, u32 address)
71 {
72         return smbus_read_byte(device, address);
73 }
74
75 #include "northbridge/amd/amdk8/amdk8.h"
76 #include "northbridge/amd/amdk8/incoherent_ht.c"
77 #include "northbridge/amd/amdk8/raminit_f.c"
78 #include "northbridge/amd/amdk8/coherent_ht.c"
79 #include "lib/generic_sdram.c"
80 #include "resourcemap.c"
81
82 #include "cpu/amd/dualcore/dualcore.c"
83
84
85 #include "cpu/amd/car/post_cache_as_ram.c"
86
87 #include "cpu/amd/model_fxx/init_cpus.c"
88
89 #include "cpu/amd/model_fxx/fidvid.c"
90
91 #include "northbridge/amd/amdk8/early_ht.c"
92
93 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
94 {
95         static const u16 spd_addr[] = { DIMM0, 0, 0, 0, DIMM1, 0, 0, 0, };
96         int needs_reset = 0;
97         u32 bsp_apicid = 0;
98         msr_t msr;
99         struct cpuid_result cpuid1;
100         struct sys_info *sysinfo =
101             (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE -
102                                 CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
103
104         if (!cpu_init_detectedx && boot_cpu()) {
105                 /* Nothing special needs to be done to find bus 0 */
106                 /* Allow the HT devices to be found */
107                 enumerate_ht_chain();
108
109                 sb600_lpc_port80();
110                 /* sb600_pci_port80(); */
111         }
112
113         if (bist == 0) {
114                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
115         }
116
117         enable_rs690_dev8();
118         sb600_lpc_init();
119
120         /* Pistachio used a FPGA to enable serial debug instead of a SIO
121          * and it doesn't require any special setup. */
122         uart_init();
123
124 #if CONFIG_USBDEBUG
125         sb600_enable_usbdebug(0);
126         early_usbdebug_init();
127 #endif
128
129         console_init();
130
131         post_code(0x03);
132
133         /* Halt if there was a built in self test failure */
134         report_bist_failure(bist);
135         printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
136
137         setup_pistachio_resource_map();
138
139         setup_coherent_ht_domain();
140
141 #if CONFIG_LOGICAL_CPUS==1
142         /* It is said that we should start core1 after all core0 launched */
143         wait_all_core0_started();
144         start_other_cores();
145 #endif
146         wait_all_aps_started(bsp_apicid);
147
148         /* it will set up chains and store link pair for optimization later,
149          * it will init sblnk and sbbusn, nodes, sbdn */
150         ht_setup_chains_x(sysinfo);
151
152         /* run _early_setup before soft-reset. */
153         rs690_early_setup();
154         sb600_early_setup();
155
156         post_code(0x04);
157
158         /* Check to see if processor is capable of changing FIDVID  */
159         /* otherwise it will throw a GP# when reading FIDVID_STATUS */
160         cpuid1 = cpuid(0x80000007);
161         if( (cpuid1.edx & 0x6) == 0x6 ) {
162
163                 /* Read FIDVID_STATUS */
164                 msr=rdmsr(0xc0010042);
165                 printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
166
167                 enable_fid_change();
168                 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
169                 init_fidvid_bsp(bsp_apicid);
170
171                 /* show final fid and vid */
172                 msr=rdmsr(0xc0010042);
173                 printk(BIOS_DEBUG, "end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
174
175         } else {
176                 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
177         }
178
179         post_code(0x05);
180
181         needs_reset = optimize_link_coherent_ht();
182         needs_reset |= optimize_link_incoherent_ht(sysinfo);
183         rs690_htinit();
184         printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
185
186         post_code(0x06);
187
188         if (needs_reset) {
189                 print_info("ht reset -\n");
190                 soft_reset();
191         }
192
193         allow_all_aps_stop(bsp_apicid);
194
195         /* It's the time to set ctrl now; */
196         printk(BIOS_DEBUG, "sysinfo->nodes: %2x  sysinfo->ctrl: %p  spd_addr: %p\n",
197                      sysinfo->nodes, sysinfo->ctrl, spd_addr);
198         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
199
200         post_code(0x07);
201
202         sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
203
204         post_code(0x08);
205
206         rs690_before_pci_init();
207         sb600_before_pci_init();
208
209         post_cache_as_ram();
210 }
211