5711859109ec337d70e1422065b7b60d48f466e3
[coreboot.git] / src / mainboard / asus / m2v-mx_se / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 AMD
5  * (Written by Yinghai Lu <yinghailu@amd.com> for AMD)
6  * Copyright (C) 2006 MSI
7  * (Written by Bingxun Shi <bingxunshi@gmail.com> for MSI)
8  * Copyright (C) 2008 Rudolf Marek <r.marek@assembler.cz>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 unsigned int get_sbdn(unsigned bus);
26
27 /* Used by raminit. */
28
29 /* Used by init_cpus and fidvid */
30 #define SET_FIDVID 1
31
32 /* If we want to wait for core1 done before DQS training, set it to 0. */
33 #define SET_FIDVID_CORE0_ONLY 1
34
35 #if CONFIG_K8_REV_F_SUPPORT == 1
36 #define K8_REV_F_SUPPORT_F0_F1_WORKAROUND 0
37 #endif
38
39 #include <stdint.h>
40 #include <string.h>
41 #include <device/pci_def.h>
42 #include <arch/io.h>
43 #include <device/pnp_def.h>
44 #include <arch/romcc_io.h>
45 #include <cpu/amd/mtrr.h>
46 #include <cpu/x86/lapic.h>
47 #include <pc80/mc146818rtc.h>
48 #include <console/console.h>
49 #include <cpu/amd/model_fxx_rev.h>
50 #include "northbridge/amd/amdk8/raminit.h"
51 #include "cpu/amd/model_fxx/apic_timer.c"
52 #include "lib/delay.c"
53 #include "northbridge/amd/amdk8/reset_test.c"
54 #include "northbridge/amd/amdk8/debug.c"
55 #include "superio/ite/it8712f/it8712f_early_serial.c"
56 #include "southbridge/via/vt8237r/vt8237r_early_smbus.c"
57 #include "cpu/x86/mtrr/earlymtrr.c"
58 #include "cpu/x86/bist.h"
59 #include "northbridge/amd/amdk8/setup_resource_map.c"
60
61 #define SERIAL_DEV PNP_DEV(0x2e, IT8712F_SP1)
62 #define WATCHDOG_DEV PNP_DEV(0x2e, IT8712F_GPIO)
63
64 static void memreset(int controllers, const struct mem_controller *ctrl)
65 {
66 }
67
68 static inline int spd_read_byte(unsigned device, unsigned address)
69 {
70         return smbus_read_byte(device, address);
71 }
72
73 static void activate_spd_rom(const struct mem_controller *ctrl)
74 {
75 }
76
77 // defines S3_NVRAM_EARLY:
78 #include "southbridge/via/k8t890/k8t890_early_car.c"
79
80 #include "northbridge/amd/amdk8/amdk8.h"
81 #include "northbridge/amd/amdk8/incoherent_ht.c"
82 #include "northbridge/amd/amdk8/coherent_ht.c"
83 #include "northbridge/amd/amdk8/raminit_f.c"
84 #include "lib/generic_sdram.c"
85
86 #include "cpu/amd/dualcore/dualcore.c"
87
88 #include "cpu/amd/car/post_cache_as_ram.c"
89 #include "cpu/amd/model_fxx/init_cpus.c"
90
91 #define SB_VFSMAF 0
92
93 /* this function might fail on some K8 CPUs with errata #181 */
94 static void ldtstop_sb(void)
95 {
96         print_debug("toggle LDTSTP#\n");
97         u8 reg = inb (VT8237R_ACPI_IO_BASE + 0x5c);
98         reg = reg ^ (1 << 0);
99         outb(reg, VT8237R_ACPI_IO_BASE + 0x5c);
100         reg = inb(VT8237R_ACPI_IO_BASE + 0x15);
101         print_debug("done\n");
102 }
103
104 #include "cpu/amd/model_fxx/fidvid.c"
105 #include "northbridge/amd/amdk8/resourcemap.c"
106
107 void soft_reset(void)
108 {
109         uint8_t tmp;
110
111         set_bios_reset();
112         print_debug("soft reset \n");
113
114         /* PCI reset */
115         tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f);
116         tmp |= 0x01;
117         /* FIXME from S3 set bit1 to disable USB reset VT8237A/S */
118         pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp);
119
120         while (1) {
121                 /* daisy daisy ... */
122                 hlt();
123         }
124 }
125
126 unsigned int get_sbdn(unsigned bus)
127 {
128         device_t dev;
129
130         dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_VIA,
131                                         PCI_DEVICE_ID_VIA_VT8237R_LPC), bus);
132         return (dev >> 15) & 0x1f;
133 }
134
135 void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
136 {
137         static const uint16_t spd_addr[] = {
138                 // Node 0
139                 (0xa << 3) | 0, (0xa << 3) | 2, 0, 0,
140                 (0xa << 3) | 1, (0xa << 3) | 3, 0, 0,
141                 // Node 1
142                 (0xa << 3) | 4, (0xa << 3) | 6, 0, 0,
143                 (0xa << 3) | 5, (0xa << 3) | 7, 0, 0,
144         };
145         unsigned bsp_apicid = 0;
146         int needs_reset = 0;
147         struct sys_info *sysinfo =
148             (struct sys_info *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
149
150         it8712f_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
151         it8712f_kill_watchdog();
152         it8712f_enable_3vsbsw();
153         uart_init();
154         console_init();
155         enable_rom_decode();
156
157         printk(BIOS_INFO, "now booting... \n");
158
159         if (bist == 0)
160                 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
161
162         /* Halt if there was a built in self test failure. */
163         report_bist_failure(bist);
164         setup_default_resource_map();
165         setup_coherent_ht_domain();
166         wait_all_core0_started();
167
168         printk(BIOS_INFO, "now booting... All core 0 started\n");
169
170 #if CONFIG_LOGICAL_CPUS==1
171         /* It is said that we should start core1 after all core0 launched. */
172         start_other_cores();
173         wait_all_other_cores_started(bsp_apicid);
174 #endif
175         init_timer();
176         ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */
177
178         needs_reset = optimize_link_coherent_ht();
179         print_debug_hex8(needs_reset);
180         needs_reset |= optimize_link_incoherent_ht(sysinfo);
181         print_debug_hex8(needs_reset);
182         needs_reset |= k8t890_early_setup_ht();
183         print_debug_hex8(needs_reset);
184
185         vt8237_early_network_init(NULL);
186         vt8237_early_spi_init();
187
188         if (needs_reset) {
189                 printk(BIOS_DEBUG, "ht reset -\n");
190                 soft_reset();
191                 printk(BIOS_DEBUG, "FAILED!\n");
192         }
193
194         /* the HT settings needs to be OK, because link freq chnage may cause HT disconnect */
195         /* allow LDT STOP asserts */
196         vt8237_sb_enable_fid_vid();
197
198         enable_fid_change();
199         print_debug("after enable_fid_change\n");
200
201         init_fidvid_bsp(bsp_apicid);
202
203         /* Stop the APs so we can start them later in init. */
204         allow_all_aps_stop(bsp_apicid);
205
206         /* It's the time to set ctrl now. */
207         fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
208         enable_smbus();
209         sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
210         post_cache_as_ram();
211 }
212