blob: d7796f80dd1ea81faa496a24df5194a71e417c72 [file] [log] [blame]
Yinghai Luafd34e62006-02-16 17:22:19 +00001#define ASSEMBLY 1
Myles Watson1d6d45e2009-11-06 17:02:51 +00002#define __PRE_RAM__
Yinghai Luafd34e62006-02-16 17:22:19 +00003
Yinghai Lu6d74d762006-10-04 23:57:49 +00004#define QRANK_DIMM_SUPPORT 1
Yinghai Luafd34e62006-02-16 17:22:19 +00005
6#if CONFIG_LOGICAL_CPUS==1
7#define SET_NB_CFG_54 1
8#endif
9
10#include <stdint.h>
Patrick Georgi12aba822009-04-30 07:07:22 +000011#include <string.h>
Yinghai Luafd34e62006-02-16 17:22:19 +000012#include <device/pci_def.h>
13#include <arch/io.h>
14#include <device/pnp_def.h>
15#include <arch/romcc_io.h>
16#include <cpu/x86/lapic.h>
17#include "option_table.h"
18#include "pc80/mc146818rtc_early.c"
19#include "pc80/serial.c"
20#include "arch/i386/lib/console.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000021#include "lib/ramtest.c"
Yinghai Luafd34e62006-02-16 17:22:19 +000022
23#if 0
24static void post_code(uint8_t value) {
25#if 0
26 int i;
27 for(i=0;i<0x80000;i++) {
28 outb(value, 0x80);
29 }
30#endif
31}
32#endif
33
34#include <cpu/amd/model_fxx_rev.h>
35#include "northbridge/amd/amdk8/incoherent_ht.c"
36#include "southbridge/broadcom/bcm5785/bcm5785_early_smbus.c"
37#include "northbridge/amd/amdk8/raminit.h"
38#include "cpu/amd/model_fxx/apic_timer.c"
39#include "lib/delay.c"
40
Yinghai Luafd34e62006-02-16 17:22:19 +000041#include "cpu/x86/lapic/boot_cpu.c"
42#include "northbridge/amd/amdk8/reset_test.c"
43#include "northbridge/amd/amdk8/debug.c"
Uwe Hermannd86417b2006-10-24 23:00:42 +000044#include "superio/nsc/pc87417/pc87417_early_serial.c"
Yinghai Luafd34e62006-02-16 17:22:19 +000045
46#include "cpu/amd/mtrr/amd_earlymtrr.c"
47#include "cpu/x86/bist.h"
48
49#include "northbridge/amd/amdk8/setup_resource_map.c"
50
51#define SERIAL_DEV PNP_DEV(0x2e, PC87417_SP1)
52#define RTC_DEV PNP_DEV(0x2e, PC87417_RTC)
53
54#include "southbridge/broadcom/bcm5785/bcm5785_early_setup.c"
55
56static void memreset_setup(void)
57{
58}
59
60static void memreset(int controllers, const struct mem_controller *ctrl)
61{
62}
63
64static inline void activate_spd_rom(const struct mem_controller *ctrl)
65{
66#define SMBUS_HUB 0x71
67 int ret,i;
68 unsigned device=(ctrl->channel0[0])>>8;
69 smbus_send_byte(SMBUS_HUB, device);
70}
71#if 0
72static inline void change_i2c_mux(unsigned device)
73{
74#define SMBUS_HUB 0x71
75 int ret;
76 print_debug("change_i2c_mux i="); print_debug_hex8(device); print_debug("\r\n");
77 ret = smbus_send_byte(SMBUS_HUB, device);
78 print_debug("change_i2c_mux ret="); print_debug_hex32(ret); print_debug("\r\n");
79}
80#endif
81
82static inline int spd_read_byte(unsigned device, unsigned address)
83{
84 return smbus_read_byte(device, address);
85}
86
87#include "northbridge/amd/amdk8/raminit.c"
88#include "northbridge/amd/amdk8/coherent_ht.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000089#include "lib/generic_sdram.c"
Yinghai Luafd34e62006-02-16 17:22:19 +000090
91 /* tyan does not want the default */
92#include "resourcemap.c"
93
94#include "cpu/amd/dualcore/dualcore.c"
95
96#define RC0 (6<<8)
97#define RC1 (7<<8)
98
99#define DIMM0 0x50
100#define DIMM1 0x51
101#define DIMM2 0x52
102#define DIMM3 0x53
103
104#include "cpu/amd/car/copy_and_run.c"
105#include "cpu/amd/car/post_cache_as_ram.c"
106
107#include "cpu/amd/model_fxx/init_cpus.c"
108
Yinghai Luafd34e62006-02-16 17:22:19 +0000109#include "northbridge/amd/amdk8/early_ht.c"
110
Yinghai Luafd34e62006-02-16 17:22:19 +0000111void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
112{
Yinghai Luafd34e62006-02-16 17:22:19 +0000113 static const uint16_t spd_addr[] = {
114 RC0|DIMM0, RC0|DIMM2, 0, 0,
115 RC0|DIMM1, RC0|DIMM3, 0, 0,
116#if CONFIG_MAX_PHYSICAL_CPUS > 1
117 RC1|DIMM0, RC1|DIMM2, 0, 0,
118 RC1|DIMM1, RC1|DIMM3, 0, 0,
119#endif
120 };
121
122 int needs_reset;
Yinghai Luafd34e62006-02-16 17:22:19 +0000123 unsigned bsp_apicid = 0;
124
125 struct mem_controller ctrl[8];
126 unsigned nodes;
127
Patrick Georgi2bd91002010-03-18 16:46:50 +0000128 if (!cpu_init_detectedx && boot_cpu()) {
Patrick Georgi776b85b2010-03-18 16:18:58 +0000129 /* Nothing special needs to be done to find bus 0 */
130 /* Allow the HT devices to be found */
131
132 enumerate_ht_chain();
133
134 bcm5785_enable_rom();
135
136 bcm5785_enable_lpc();
137
138 //enable RTC
139 pc87417_enable_dev(RTC_DEV);
140 }
141
Yinghai Luafd34e62006-02-16 17:22:19 +0000142 if (bist == 0) {
143 bsp_apicid = init_cpus(cpu_init_detectedx);
144 }
145// post_code(0x32);
146
Stefan Reinauer08670622009-06-30 15:17:49 +0000147 pc87417_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Yinghai Luafd34e62006-02-16 17:22:19 +0000148// post_code(0x33);
149
150 uart_init();
151// post_code(0x34);
152
153 console_init();
154
155 /* Halt if there was a built in self test failure */
156 report_bist_failure(bist);
157
158 print_debug("bsp_apicid="); print_debug_hex8(bsp_apicid); print_debug("\r\n");
159
160 setup_blast_resource_map();
161
162#if 0
163 dump_pci_device(PCI_DEV(0, 0x18, 0));
164 dump_pci_device(PCI_DEV(0, 0x19, 0));
165#endif
166
167 needs_reset = setup_coherent_ht_domain();
168
169#if CONFIG_LOGICAL_CPUS==1
170 // It is said that we should start core1 after all core0 launched
171 wait_all_core0_started();
172 start_other_cores();
173#endif
174 wait_all_aps_started(bsp_apicid);
175
176 needs_reset |= ht_setup_chains_x();
177
178 bcm5785_early_setup();
179
180 if (needs_reset) {
181 print_info("ht reset -\r\n");
182 soft_reset();
183 }
184
185 allow_all_aps_stop(bsp_apicid);
186
187 nodes = get_nodes();
188 //It's the time to set ctrl now;
189 fill_mem_ctrl(nodes, ctrl, spd_addr);
190
191 enable_smbus();
192
193#if 0
194 int i;
195 for(i=4;i<8;i++) {
196 change_i2c_mux(i);
197 dump_smbus_registers();
198 }
199#endif
200
201 memreset_setup();
202
203// init_timer();
204
205 sdram_initialize(nodes, ctrl);
206
207#if 0
208 print_pci_devices();
209#endif
210
211#if 0
212 dump_pci_devices();
213#endif
214
Yinghai Lu9a791df2006-04-03 20:38:34 +0000215 post_cache_as_ram();
Yinghai Luafd34e62006-02-16 17:22:19 +0000216
217}