blob: caee4574a859d38bd731c54e552cff246e8ac39a [file] [log] [blame]
Uwe Hermann20a98c92009-06-05 23:02:43 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009 One Laptop per Child, Association, 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/*
Uwe Hermann0ffff342009-06-07 13:46:50 +000021 * Part of this file is from cx700 port, part of is from cn700 port,
22 * and acpi_is_wakeup_early_via_VX800() is part of Rudolf's S3 patch.
Uwe Hermann20a98c92009-06-05 23:02:43 +000023 */
24
Uwe Hermann20a98c92009-06-05 23:02:43 +000025#define RAMINIT_SYSINFO 1
Stefan Reinauer17b60a92010-04-14 17:11:47 +000026#define PAYLOAD_IS_SEABIOS 0
Uwe Hermann20a98c92009-06-05 23:02:43 +000027
28#include <stdint.h>
29#include <device/pci_def.h>
30#include <device/pci_ids.h>
31#include <arch/io.h>
32#include <device/pnp_def.h>
33#include <arch/romcc_io.h>
34#include <arch/hlt.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000035#include <console/console.h>
Patrick Georgid0835952010-10-05 09:07:10 +000036#include <lib.h>
Uwe Hermann20a98c92009-06-05 23:02:43 +000037#include "northbridge/via/vx800/vx800.h"
Uwe Hermann20a98c92009-06-05 23:02:43 +000038#include "cpu/x86/bist.h"
39#include "pc80/udelay_io.c"
40#include "lib/delay.c"
Myles Watson42f75c32009-07-07 17:54:26 +000041#include <string.h>
Uwe Hermann20a98c92009-06-05 23:02:43 +000042
Uwe Hermann0ffff342009-06-07 13:46:50 +000043/* This file contains the board-special SI value for raminit.c. */
Uwe Hermannd64f4032009-06-07 14:38:32 +000044#include "driving_clk_phase_data.c"
Uwe Hermann20a98c92009-06-05 23:02:43 +000045
46#include "northbridge/via/vx800/raminit.h"
47#include "northbridge/via/vx800/raminit.c"
Stefan Reinauer853263b2010-04-09 10:43:49 +000048
Uwe Hermannd64f4032009-06-07 14:38:32 +000049#include "wakeup.h"
Uwe Hermann20a98c92009-06-05 23:02:43 +000050
Uwe Hermann4e2ffb82009-07-15 00:03:28 +000051#include "superio/winbond/w83697hf/w83697hf_early_serial.c"
52
53#define SERIAL_DEV PNP_DEV(0x2e, W83697HF_SP1)
54
Uwe Hermann0ffff342009-06-07 13:46:50 +000055/*
56 * This acpi_is_wakeup_early_via_VX800 is from Rudolf's patch on the list:
57 * http://www.coreboot.org/pipermail/coreboot/2008-January/028787.html.
58 */
Stefan Reinauer8816cdf2010-04-14 16:39:30 +000059static int acpi_is_wakeup_early_via_vx800(void)
Uwe Hermann0ffff342009-06-07 13:46:50 +000060{
Uwe Hermann20a98c92009-06-05 23:02:43 +000061 device_t dev;
Uwe Hermann0ffff342009-06-07 13:46:50 +000062 u16 tmp, result;
Uwe Hermann20a98c92009-06-05 23:02:43 +000063
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000064 print_debug("In acpi_is_wakeup_early_via_vx800\n");
Uwe Hermann20a98c92009-06-05 23:02:43 +000065 /* Power management controller */
66 dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA,
67 PCI_DEVICE_ID_VIA_VX855_LPC), 0);
68
69 if (dev == PCI_DEV_INVALID)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000070 die("Power management controller not found\n");
Uwe Hermann20a98c92009-06-05 23:02:43 +000071
72 /* Set ACPI base address to I/O VX800_ACPI_IO_BASE. */
73 pci_write_config16(dev, 0x88, VX800_ACPI_IO_BASE | 0x1);
74
75 /* Enable ACPI accessm RTC signal gated with PSON. */
76 pci_write_config8(dev, 0x81, 0x84);
77
78 tmp = inw(VX800_ACPI_IO_BASE + 0x04);
Uwe Hermann0ffff342009-06-07 13:46:50 +000079 result = ((tmp & (7 << 10)) >> 10) == 1 ? 3 : 0;
Uwe Hermann20a98c92009-06-05 23:02:43 +000080 print_debug(" boot_mode=");
Uwe Hermann0ffff342009-06-07 13:46:50 +000081 print_debug_hex16(result);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000082 print_debug("\n");
Uwe Hermann0ffff342009-06-07 13:46:50 +000083 return result;
Uwe Hermann20a98c92009-06-05 23:02:43 +000084}
85
Uwe Hermann0ffff342009-06-07 13:46:50 +000086/* All content of this function came from the cx700 port of coreboot. */
Uwe Hermann20a98c92009-06-05 23:02:43 +000087static void enable_mainboard_devices(void)
88{
89 device_t dev;
Uwe Hermann0ffff342009-06-07 13:46:50 +000090#if 0
91 /*
92 * Add and close this switch, since some line cause error, some
93 * written at elsewhere (stage1 stage2).
94 */
Uwe Hermann20a98c92009-06-05 23:02:43 +000095 u8 regdata;
Uwe Hermann0ffff342009-06-07 13:46:50 +000096 dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA,
97 PCI_DEVICE_ID_VIA_VX855_LPC), 0);
Uwe Hermann20a98c92009-06-05 23:02:43 +000098
Uwe Hermann0ffff342009-06-07 13:46:50 +000099 /* Disable GP3. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000100 pci_write_config8(dev, 0x98, 0x00);
101
Uwe Hermann0ffff342009-06-07 13:46:50 +0000102 pci_write_config8(dev, 0x50, 0x80); /* Disable mc97. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000103
Uwe Hermann0ffff342009-06-07 13:46:50 +0000104 /*
105 * Martin: Disable internal KBC configuration.
106 *
107 * Internal Config is needed to decide which key can be pressed to
108 * resume from s3.
109 */
110 pci_write_config8(dev, 0x51, 0x2d);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000111
Uwe Hermann0ffff342009-06-07 13:46:50 +0000112 /* This causes irq0 can not be triggerd, since bit 5 was set to 0. */
113 /* pci_write_config8(dev, 0x58, 0x42); */
114
115 /* These writing may... TODO */
116 regdata = pci_read_config8(dev, 0x58);
117 regdata |= 0x41;
118 pci_write_config8(dev, 0x58, regdata);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000119 pci_write_config8(dev, 0x59, 0x80);
120 pci_write_config8(dev, 0x5b, 0x01);
121#endif
Uwe Hermann0ffff342009-06-07 13:46:50 +0000122
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000123 print_debug("In enable_mainboard_devices \n");
Uwe Hermann20a98c92009-06-05 23:02:43 +0000124
Uwe Hermann0ffff342009-06-07 13:46:50 +0000125 /* Enable P2P Bridge Header for external PCI bus. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000126 dev = pci_locate_device(PCI_ID(0x1106, 0xa353), 0);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000127 pci_write_config8(dev, 0x4f, 0x41);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000128
Uwe Hermann0ffff342009-06-07 13:46:50 +0000129 /*
130 * "5324" already is the default value of the PCI IDE device, cancel
131 * this PCI write.
132 *
133 * [william 20080124]: Fix bug that can not boot Ubuntu at the
134 * beginning time.
135 */
136#if 0
137 dev = 0;
138 dev = pci_locate_device(PCI_ID(0x1106, PCI_DEVICE_ID_VIA_VX855_IDE), 0);
Stefan Reinauer8816cdf2010-04-14 16:39:30 +0000139
140 uint16_t values;
Uwe Hermann0ffff342009-06-07 13:46:50 +0000141 values = pci_read_config16(dev, 0xBA);
142 values &= ~0xffff;
143 values |= 0x5324;
144 pci_write_config16(dev, 0xBA, values);
145#endif
Uwe Hermann20a98c92009-06-05 23:02:43 +0000146}
147
Uwe Hermann0ffff342009-06-07 13:46:50 +0000148/*
149 * Most content of this function came from the cx700 port of coreboot.
150 * Turn on the shadow of E-seg.
151 */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000152static void enable_shadow_ram(void)
153{
154 uint8_t shadowreg;
Uwe Hermann0ffff342009-06-07 13:46:50 +0000155
156 /*
157 * Changed the value from 0x2a to 0x3f. "read only" may block "write"?
158 * and maybe in C-seg "write" will be needed?
159 */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000160 pci_write_config8(PCI_DEV(0, 0, 3), 0x80, 0xff);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000161
Uwe Hermann20a98c92009-06-05 23:02:43 +0000162 /* 0xf0000-0xfffff - ACPI tables */
163 shadowreg = pci_read_config8(PCI_DEV(0, 0, 3), 0x83);
164 shadowreg |= 0x30;
165 pci_write_config8(PCI_DEV(0, 0, 3), 0x83, shadowreg);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000166
167 /* 0xe0000-0xeffff - elfload? */
168 /*
169 * In s3 resume process, wakeup.c, I use E-seg to hold the code
170 * (which can not locate in the area to be covered) that will copy
171 * 0-A-seg and F-seg from TOP-mem back to their normal location.
172 */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000173 pci_write_config8(PCI_DEV(0, 0, 3), 0x82, 0xff);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000174
Uwe Hermann20a98c92009-06-05 23:02:43 +0000175#if 0
Uwe Hermann0ffff342009-06-07 13:46:50 +0000176 /* Enable shadow RAM as normal DRAM */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000177 /* 0xc0000-0xcffff - VGA BIOS */
178 pci_write_config8(PCI_DEV(0, 0, 3), 0x80, 0x2a);
179 pci_write_config8(PCI_DEV(0, 0, 7), 0x61, 0x00);
180 /* 0xd0000-0xdffff - ?? */
Uwe Hermann0ffff342009-06-07 13:46:50 +0000181 /* pci_write_config8(PCI_DEV(0, 0, 3), 0x81, 0xff); */
182 /* pci_write_config8(PCI_DEV(0, 0, 7), 0x62, 0xff); */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000183
Uwe Hermann0ffff342009-06-07 13:46:50 +0000184 /* Do it again for the vlink controller. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000185 shadowreg = pci_read_config8(PCI_DEV(0, 0, 7), 0x63);
186 shadowreg |= 0x30;
187 pci_write_config8(PCI_DEV(0, 0, 7), 0x63, shadowreg);
188#endif
189}
190
Uwe Hermann0ffff342009-06-07 13:46:50 +0000191/*
192 * Added this table 2008-11-28.
193 * This table contains the value needed to be set before begin to init DRAM.
194 * Note: REV_Bx should be checked for changes when porting a new board!
195 */
196static const struct VIA_PCI_REG_INIT_TABLE mNbStage1InitTbl[] = {
197 /* VT3409 no PCI-E */
Stefan Reinauer8816cdf2010-04-14 16:39:30 +0000198 { 0x00, 0xFF, NB_APIC_REG(0x61), 0xFF, 0x0E }, // Set Exxxxxxx as pcie mmio config range
199 { 0x00, 0xFF, NB_APIC_REG(0x60), 0xF4, 0x0B }, // Support extended cfg address of pcie
200 // { 0x00, 0xFF, NB_APIC_REG(0x42), 0xF9, 0x02 }, // APIC Interrupt((BT_INTR)) Control
Uwe Hermann0ffff342009-06-07 13:46:50 +0000201 // Set ROMSIP value by software
Uwe Hermann20a98c92009-06-05 23:02:43 +0000202
Uwe Hermann0ffff342009-06-07 13:46:50 +0000203 /*
Stefan Reinauer8816cdf2010-04-14 16:39:30 +0000204 { 0x00, 0xFF, NB_HOST_REG(0x70), 0x77, 0x33 }, // 2x Host Adr Strobe/Pad Pullup Driving = 3
205 { 0x00, 0xFF, NB_HOST_REG(0x71), 0x77, 0x33 }, // 2x Host Adr Strobe/Pad Pulldown Driving = 3
206 { 0x00, 0xFF, NB_HOST_REG(0x72), 0x77, 0x33 }, // 4x Host Dat Strobe/Pad Pullup Driving = 3
207 { 0x00, 0xFF, NB_HOST_REG(0x73), 0x77, 0x33 }, // 4x Host Dat Strobe/Pad Pulldown Driving = 3
208 { 0x00, 0xFF, NB_HOST_REG(0x74), 0xFF, 0x21 }, // Memory I/F timing ctrl
209 { 0x00, 0xFF, NB_HOST_REG(0x74), 0xFF, 0xE1 }, // Memory I/F timing ctrl
210 { 0x00, 0xFF, NB_HOST_REG(0x75), 0xFF, 0x18 }, // AGTL+ I/O Circuit
211 { 0x00, 0xFF, NB_HOST_REG(0x76), 0xFB, 0x0C }, // AGTL+ Compensation Status
212 { 0x00, 0xFF, NB_HOST_REG(0x78), 0xFF, 0x33 }, // 2X AGTL+ Auto Compensation Offset
213 { 0x00, 0xFF, NB_HOST_REG(0x79), 0xFF, 0x33 }, // 4X AGTL+ Auto Compensation Offset
214 { 0x00, 0xFF, NB_HOST_REG(0x7A), 0x3F, 0x72 }, // AGTL Compensation Status
215 { 0x00, 0xFF, NB_HOST_REG(0x7A), 0x3F, 0x77 }, // AGTL Compensation Status
216 { 0x00, 0xFF, NB_HOST_REG(0x7B), 0xFF, 0x44 }, // Input Host Address / Host Strobe Delay Control for HA Group
217 { 0x00, 0xFF, NB_HOST_REG(0x7B), 0xFF, 0x22 }, // Input Host Address / Host Strobe Delay Control for HA Group
218 { 0x00, 0xFF, NB_HOST_REG(0x7C), 0xFF, 0x00 }, // Output Delay Control of PAD for HA Group
219 { 0x00, 0xFF, NB_HOST_REG(0x7D), 0xFF, 0xAA }, // Host Address / Address Clock Output Delay Control (Only for P4 Bus)
220 { 0x00, 0xFF, NB_HOST_REG(0x7E), 0xFF, 0x10 }, // Host Address CKG Rising / Falling Time Control (Only for P4 Bus)
221 { 0x00, 0xFF, NB_HOST_REG(0x7E), 0xFF, 0x40 }, // Host Address CKG Rising / Falling Time Control (Only for P4 Bus)
222 { 0x00, 0xFF, NB_HOST_REG(0x7F), 0xFF, 0x10 }, // Host Address CKG Rising / Falling Time Control (Only for P4 Bus)
223 { 0x00, 0xFF, NB_HOST_REG(0x7F), 0xFF, 0x40 }, // Host Address CKG Rising / Falling Time Control (Only for P4 Bus)
224 { 0x00, 0xFF, NB_HOST_REG(0x80), 0x3F, 0x44 }, // Host Data Receiving Strobe Delay Ctrl 1
225 { 0x00, 0xFF, NB_HOST_REG(0x81), 0xFF, 0x44 }, // Host Data Receiving Strobe Delay Ctrl 2
226 { 0x00, 0xFF, NB_HOST_REG(0x82), 0xFF, 0x00 }, // Output Delay of PAD for HDSTB
227 { 0x00, 0xFF, NB_HOST_REG(0x83), 0xFF, 0x00 }, // Output Delay of PAD for HD
228 { 0x00, 0xFF, NB_HOST_REG(0x84), 0xFF, 0x44 }, // Host Data / Strobe CKG Control (Group 0)
229 { 0x00, 0xFF, NB_HOST_REG(0x85), 0xFF, 0x44 }, // Host Data / Strobe CKG Control (Group 1)
230 { 0x00, 0xFF, NB_HOST_REG(0x86), 0xFF, 0x44 }, // Host Data / Strobe CKG Control (Group 2)
231 { 0x00, 0xFF, NB_HOST_REG(0x87), 0xFF, 0x44 }, // Host Data / Strobe CKG Control (Group 3)
Uwe Hermannd64f4032009-06-07 14:38:32 +0000232 */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000233
Uwe Hermann0ffff342009-06-07 13:46:50 +0000234 // CPU Host Bus Control
Stefan Reinauer8816cdf2010-04-14 16:39:30 +0000235 { 0x00, 0xFF, NB_HOST_REG(0x50), 0x1F, 0x08 }, // Request phase ctrl: Dynamic Defer Snoop Stall Count = 8
236 // { 0x00, 0xFF, NB_HOST_REG(0x51), 0xFF, 0x7F }, // CPU I/F Ctrl-1: Disable Fast DRDY and RAW
237 { 0x00, 0xFF, NB_HOST_REG(0x51), 0xFF, 0x7C }, // CPU I/F Ctrl-1: Disable Fast DRDY and RAW
238 { 0x00, 0xFF, NB_HOST_REG(0x52), 0xCB, 0xCB }, // CPU I/F Ctrl-2: Enable all for performance
239 // { 0x00, 0xFF, NB_HOST_REG(0x53), 0xFF, 0x88 }, // Arbitration: Host/Master Occupancy timer = 8*4 HCLK
240 { 0x00, 0xFF, NB_HOST_REG(0x53), 0xFF, 0x44 }, // Arbitration: Host/Master Occupancy timer = 4*4 HCLK
241 { 0x00, 0xFF, NB_HOST_REG(0x54), 0x1E, 0x1C }, // Misc Ctrl: Enable 8QW burst Mem Access
242 // { 0x00, 0xFF, NB_HOST_REG(0x55), 0x06, 0x06 }, // Miscellaneous Control 2
243 { 0x00, 0xFF, NB_HOST_REG(0x55), 0x06, 0x04 }, // Miscellaneous Control 2
244 { 0x00, 0xFF, NB_HOST_REG(0x56), 0xF7, 0x63 }, // Write Policy 1
245 // { 0x00, 0xFF, NB_HOST_REG(0x59), 0x3D, 0x01 }, // CPU Miscellaneous Control 1, enable Lowest-Priority IPL
246 // { 0x00, 0xFF, NB_HOST_REG(0x5c), 0xFF, 0x00 }, // CPU Miscellaneous Control 2
247 { 0x00, 0xFF, NB_HOST_REG(0x5D), 0xFF, 0xA2 }, // Write Policy
248 { 0x00, 0xFF, NB_HOST_REG(0x5E), 0xFF, 0x88 }, // Bandwidth Timer
249 { 0x00, 0xFF, NB_HOST_REG(0x5F), 0x46, 0x46 }, // CPU Misc Ctrl
250 // { 0x00, 0xFF, NB_HOST_REG(0x90), 0xFF, 0x0B }, // CPU Miscellaneous Control 3
251 // { 0x00, 0xFF, NB_HOST_REG(0x96), 0x0B, 0x0B }, // CPU Miscellaneous Control 2
252 { 0x00, 0xFF, NB_HOST_REG(0x96), 0x0B, 0x0A }, // CPU Miscellaneous Control 2
253 { 0x00, 0xFF, NB_HOST_REG(0x98), 0xC1, 0x41 }, // CPU Miscellaneous Control 3
254 { 0x00, 0xFF, NB_HOST_REG(0x99), 0x0E, 0x06 }, // CPU Miscellaneous Control 4
Uwe Hermann20a98c92009-06-05 23:02:43 +0000255
Uwe Hermann0ffff342009-06-07 13:46:50 +0000256 // Set APIC and SMRAM
Stefan Reinauer8816cdf2010-04-14 16:39:30 +0000257 { 0x00, 0xFF, NB_HOST_REG(0x97), 0xFF, 0x00 }, // APIC Related Control
258 { 0x00, 0xFF, NB_DRAMC_REG(0x86), 0xD6, 0x29 }, // SMM and APIC Decoding: enable APIC, MSI and SMRAM A-Seg
259 { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } // End of the table
Uwe Hermann20a98c92009-06-05 23:02:43 +0000260};
261
Uwe Hermann0ffff342009-06-07 13:46:50 +0000262#define USE_VCP 1 /* 0 means "use DVP". */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000263#define USE_COM1 1
264#define USE_COM2 0
265
266#define gCom1Base 0x3f8
267#define gCom2Base 0x2f8
Uwe Hermann0ffff342009-06-07 13:46:50 +0000268
Stefan Reinauer17b60a92010-04-14 17:11:47 +0000269#if 0
270static void EmbedComInit(void)
Uwe Hermann20a98c92009-06-05 23:02:43 +0000271{
Uwe Hermann0ffff342009-06-07 13:46:50 +0000272 u8 ByteVal;
273 u16 ComBase;
Uwe Hermann20a98c92009-06-05 23:02:43 +0000274
Uwe Hermann0ffff342009-06-07 13:46:50 +0000275 /* Enable NB multiple function control. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000276 ByteVal = pci_read_config8(PCI_DEV(0, 0, 0), 0x4f);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000277 ByteVal = ByteVal | 0x01;
Uwe Hermann20a98c92009-06-05 23:02:43 +0000278 pci_write_config8(PCI_DEV(0, 0, 0), 0x4f, ByteVal);
279
Uwe Hermann0ffff342009-06-07 13:46:50 +0000280 /* VGA enable. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000281 ByteVal = pci_read_config8(PCI_DEV(0, 0, 3), 0xA1);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000282 ByteVal = ByteVal | 0x80;
Uwe Hermann20a98c92009-06-05 23:02:43 +0000283 pci_write_config8(PCI_DEV(0, 0, 3), 0xA1, ByteVal);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000284
Uwe Hermann20a98c92009-06-05 23:02:43 +0000285 ByteVal = pci_read_config8(PCI_DEV(0, 0, 3), 0xA7);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000286 ByteVal = ByteVal | 0x08;
Uwe Hermann20a98c92009-06-05 23:02:43 +0000287 pci_write_config8(PCI_DEV(0, 0, 3), 0xA7, ByteVal);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000288
289 /* Enable P2P IO/mem. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000290 ByteVal = pci_read_config8(PCI_DEV(0, 1, 0), 0x4);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000291 ByteVal = ByteVal | 0x07;
Uwe Hermann20a98c92009-06-05 23:02:43 +0000292 pci_write_config8(PCI_DEV(0, 1, 0), 0x4, ByteVal);
293
Uwe Hermann0ffff342009-06-07 13:46:50 +0000294 /* Turn on graphic chip I/O port port access. */
295 ByteVal = inb(0x3C3);
296 ByteVal = ByteVal | 0x01;
297 outb(ByteVal, 0x3C3);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000298
Uwe Hermann0ffff342009-06-07 13:46:50 +0000299 /* Turn off graphic chip register protection. */
300 outb(0x10, 0x3C4);
301 ByteVal = inb(0x3C5);
302 ByteVal = ByteVal | 0x01;
303 outb(ByteVal, 0x3C5);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000304
Uwe Hermann0ffff342009-06-07 13:46:50 +0000305 /* South module pad share enable 0x3C5.78[7]. */
306 outb(0x78, 0x3C4);
307 ByteVal = inb(0x3C5);
308 ByteVal = ByteVal | 0x80;
309 outb(ByteVal, 0x3C5);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000310
Uwe Hermann0ffff342009-06-07 13:46:50 +0000311 /* Enable UART function multiplex with DVP or VCP pad D17F0Rx46[7,6]. */
312 ByteVal = pci_read_config8(PCI_DEV(0, 17, 0), 0x46);
313 if (USE_VCP == 1)
314 ByteVal = (ByteVal & 0x3F) | 0x40; /* Multiplex with VCP. */
315 else
316 ByteVal = (ByteVal & 0x3F) | 0xC0; /* Multiplex with DVP. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000317 pci_write_config8(PCI_DEV(0, 17, 0), 0x46, ByteVal);
318
Uwe Hermann0ffff342009-06-07 13:46:50 +0000319 /* Enable embedded COM1 and COM2 D17F0RxB0[5,4]. */
320 ByteVal = pci_read_config8(PCI_DEV(0, 17, 0), 0xB0);
321 ByteVal = ByteVal & 0xcf;
322 /* Multiplex with VCP. */
323 if (USE_COM1 == 1)
324 ByteVal = ByteVal | 0x10;
325 if (USE_COM2 == 1)
326 ByteVal = ByteVal | 0x20;
Uwe Hermann20a98c92009-06-05 23:02:43 +0000327 pci_write_config8(PCI_DEV(0, 17, 0), 0xB0, ByteVal);
328
Uwe Hermann0ffff342009-06-07 13:46:50 +0000329 if (USE_COM1 == 1)
330 ComBase = gCom1Base;
331 else
332 ComBase = gCom2Base;
333
Uwe Hermann20a98c92009-06-05 23:02:43 +0000334//noharddrive
335
Uwe Hermannd64f4032009-06-07 14:38:32 +0000336 /* Set embedded COM1 I/O base = 0x3E8 (D17F0RB4, ByteVal = 0xFD) */
Uwe Hermann0ffff342009-06-07 13:46:50 +0000337 if (USE_COM1 == 1) {
338 ByteVal = (u8) ((gCom1Base >> 3) | 0x80);
339 pci_write_config8(PCI_DEV(0, 17, 0), 0xB4, ByteVal);
340 ByteVal = pci_read_config8(PCI_DEV(0, 17, 0), 0xb2);
341 ByteVal = (ByteVal & 0xf0) | 0x04;
342 pci_write_config8(PCI_DEV(0, 17, 0), 0xB2, ByteVal);
343 }
Uwe Hermann20a98c92009-06-05 23:02:43 +0000344
Uwe Hermannd64f4032009-06-07 14:38:32 +0000345 /* Set embedded COM2 I/O base = 0x2E8 (D17F0RB5, ByteVal = 0xDD). */
Uwe Hermann0ffff342009-06-07 13:46:50 +0000346 if (USE_COM2 == 1) {
347 ByteVal = (u8) ((gCom2Base >> 3) | 0x80);
348 pci_write_config8(PCI_DEV(0, 17, 0), 0xB5, ByteVal);
349 ByteVal = pci_read_config8(PCI_DEV(0, 17, 0), 0xb2);
350 ByteVal = (ByteVal & 0x0f) | 0x30;
351 pci_write_config8(PCI_DEV(0, 17, 0), 0xB2, ByteVal);
352 }
353 /* No port 80 biger then 0x10. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000354
Uwe Hermann0ffff342009-06-07 13:46:50 +0000355 /* Disable interrupt. */
356 ByteVal = inb(ComBase + 3);
357 outb(ByteVal & 0x7F, ComBase + 3);
358 outb(0x00, ComBase + 1);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000359
Uwe Hermann0ffff342009-06-07 13:46:50 +0000360 /* Set BAUD rate. */
361 ByteVal = inb(ComBase + 3);
362 outb(ByteVal | 0x80, ComBase + 3);
363 outb(0x01, ComBase);
364 outb(0x00, ComBase + 1);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000365
Uwe Hermann0ffff342009-06-07 13:46:50 +0000366 /* Set frame format. */
367 ByteVal = inb(ComBase + 3);
368 outb(ByteVal & 0x3F, ComBase + 3);
369 outb(0x03, ComBase + 3);
370 outb(0x00, ComBase + 2);
371 outb(0x00, ComBase + 4);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000372
Uwe Hermann0ffff342009-06-07 13:46:50 +0000373 /* SOutput("Embedded COM output\n"); */
374 /* while(1); */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000375}
Stefan Reinauer17b60a92010-04-14 17:11:47 +0000376#endif
Uwe Hermann20a98c92009-06-05 23:02:43 +0000377
Uwe Hermann0ffff342009-06-07 13:46:50 +0000378/* cache_as_ram.inc jumps to here. */
Stefan Reinauer314e5512010-04-09 20:36:29 +0000379void main(unsigned long bist)
Uwe Hermann0ffff342009-06-07 13:46:50 +0000380{
Uwe Hermann20a98c92009-06-05 23:02:43 +0000381 u16 boot_mode;
Uwe Hermann0ffff342009-06-07 13:46:50 +0000382 u8 rambits, Data8, Data;
383 device_t device;
384 /* device_t dev; */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000385
Uwe Hermann0ffff342009-06-07 13:46:50 +0000386 /*
387 * Enable multifunction for northbridge. These 4 lines (until
388 * console_init()) are the same with epia-cn port.
389 */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000390 pci_write_config8(PCI_DEV(0, 0, 0), 0x4f, 0x01);
Uwe Hermann4e2ffb82009-07-15 00:03:28 +0000391 /* EmbedComInit(); */
392 w83697hf_set_clksel_48(SERIAL_DEV);
393 w83697hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
394 uart_init();
Uwe Hermann0ffff342009-06-07 13:46:50 +0000395 /* enable_vx800_serial(); */
396 /* uart_init(); */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000397
Uwe Hermann0ffff342009-06-07 13:46:50 +0000398 /*
399 * 1. D15F0
400 * a) RxBAh = 71h
401 * b) RxBBh = 05h
402 * c) RxBEh = 71h
403 * d) RxBFh = 05h
404 *
405 * 2. D17F0
406 * a) RxA0h = 06h
407 * b) RxA1h = 11h
408 * c) RxA2h = 27h
409 * d) RxA3h = 32h
410 * e) Rx79h = 40h
411 * f) Rx72h = 27h
412 * g) Rx73h = 32h
413 */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000414
Uwe Hermann0ffff342009-06-07 13:46:50 +0000415 pci_write_config16(PCI_DEV(0, 0xf, 0), 0xBA,
416 PCI_DEVICE_ID_VIA_VX855_IDE);
417 pci_write_config16(PCI_DEV(0, 0xf, 0), 0xBE,
418 PCI_DEVICE_ID_VIA_VX855_IDE);
419 pci_write_config16(PCI_DEV(0, 0x11, 0), 0xA0, PCI_VENDOR_ID_VIA);
420 pci_write_config16(PCI_DEV(0, 0x11, 0), 0xA2,
421 PCI_DEVICE_ID_VIA_VX855_LPC);
422 Data8 = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x79);
423 Data8 &= ~0x40;
424 Data8 |= 0x40;
425 pci_write_config8(PCI_DEV(0, 0x11, 0), 0x79, Data8);
426 pci_write_config16(PCI_DEV(0, 0x11, 0), 0x72,
427 PCI_DEVICE_ID_VIA_VX855_LPC);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000428
Uwe Hermann0ffff342009-06-07 13:46:50 +0000429 /*
430 * There are two function definitions of console_init(), while the
431 * src/arch/i386/lib is the right one.
432 */
433 console_init();
Uwe Hermann20a98c92009-06-05 23:02:43 +0000434
Uwe Hermann0ffff342009-06-07 13:46:50 +0000435 /* Decide if this is a s3 wakeup or a normal boot. */
436 boot_mode = acpi_is_wakeup_early_via_vx800();
Uwe Hermann20a98c92009-06-05 23:02:43 +0000437
Uwe Hermann0ffff342009-06-07 13:46:50 +0000438 /*
439 * 2008-11-27 Add this, to transfer "cpu restart" to "cold boot".
440 * When this boot is not a S3 resume, and PCI registers had been
441 * written, then this must be a CPU restart (result of OS reboot cmd),
442 * so we need a real "cold boot".
443 */
Uwe Hermann0ffff342009-06-07 13:46:50 +0000444 if ((boot_mode != 3)
445 && (pci_read_config8(PCI_DEV(0, 0, 3), 0x80) != 0)) {
446 outb(6, 0xcf9);
447 }
Uwe Hermann20a98c92009-06-05 23:02:43 +0000448
Uwe Hermann0ffff342009-06-07 13:46:50 +0000449 /* x86 cold boot I/O cmd. */
450 /* These 2 lines are the same with epia-cn port. */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000451 enable_smbus();
Uwe Hermann0ffff342009-06-07 13:46:50 +0000452
453 /* This fix does help vx800!, but vx855 doesn't need this. */
454 /* smbus_fixup(&ctrl); */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000455
456 if (bist == 0) {
Uwe Hermann0ffff342009-06-07 13:46:50 +0000457 /*
458 * CAR needs MTRR until memory is ok, so disable this
459 * early_mtrr_init() call.
460 */
461#if 0
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000462 print_debug("doing early_mtrr\n");
Uwe Hermann0ffff342009-06-07 13:46:50 +0000463 early_mtrr_init();
464#endif
Uwe Hermann20a98c92009-06-05 23:02:43 +0000465 }
466
467 /* Halt if there was a built-in self test failure. */
468 report_bist_failure(bist);
Uwe Hermann0ffff342009-06-07 13:46:50 +0000469
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000470 print_debug("Enabling mainboard devices\n");
Uwe Hermann20a98c92009-06-05 23:02:43 +0000471 enable_mainboard_devices();
472
Uwe Hermann0ffff342009-06-07 13:46:50 +0000473 /*
474 * Get NB chip revision from D0F4RxF6, revision will be used in
475 * via_pci_inittable.
476 */
477 device = PCI_DEV(0, 0, 4);
478 Data = pci_read_config8(device, 0xf6);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000479 print_debug("NB chip revision =");
Uwe Hermann0ffff342009-06-07 13:46:50 +0000480 print_debug_hex8(Data);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000481 print_debug("\n");
Uwe Hermann20a98c92009-06-05 23:02:43 +0000482
Uwe Hermann0ffff342009-06-07 13:46:50 +0000483 /* Make NB ready before DRAM init. */
484 via_pci_inittable(Data, mNbStage1InitTbl);
485
486 /*
487 * When resume from s3, DRAM init is skipped, so need to recovery
488 * any PCI register related to DRAM init. d0f3 didn't lose its power
489 * during whole s3 time, so any register not belonging to d0f3 needs
490 * to be recovered.
491 */
Uwe Hermann20a98c92009-06-05 23:02:43 +0000492#if 1
Uwe Hermann0ffff342009-06-07 13:46:50 +0000493 if (boot_mode == 3) {
Uwe Hermann20a98c92009-06-05 23:02:43 +0000494 u8 i;
Uwe Hermann0ffff342009-06-07 13:46:50 +0000495 u8 ramregs[] = { 0x43, 0x42, 0x41, 0x40 };
Uwe Hermann20a98c92009-06-05 23:02:43 +0000496 DRAM_SYS_ATTR DramAttr;
Uwe Hermann20a98c92009-06-05 23:02:43 +0000497
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000498 print_debug("This is an S3 wakeup\n");
Uwe Hermann0ffff342009-06-07 13:46:50 +0000499
500 memset(&DramAttr, 0, sizeof(DRAM_SYS_ATTR));
501 /*
502 * Step 1: DRAM detection; DDR1 or DDR2; Get SPD Data;
503 * Rank Presence; 64 or 128bit; Unbuffered or registered;
504 * 1T or 2T.
505 */
506 DRAMDetect(&DramAttr);
507
508 /*
509 * Begin to get RAM size, 43,42 41 40 contains the end
510 * address of last rank in DDR2 slot.
511 */
512 device = PCI_DEV(0, 0, 3);
513 for (rambits = 0, i = 0; i < ARRAY_SIZE(ramregs); i++) {
Uwe Hermann20a98c92009-06-05 23:02:43 +0000514 rambits = pci_read_config8(device, ramregs[i]);
515 if (rambits != 0)
516 break;
517 }
518
Uwe Hermann0ffff342009-06-07 13:46:50 +0000519 DRAMDRDYSetting(&DramAttr);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000520
Uwe Hermann0ffff342009-06-07 13:46:50 +0000521 Data = 0x80; /* This value is same with DevInit.c. */
522 pci_write_config8(PCI_DEV(0, 0, 4), 0xa3, Data);
523 pci_write_config8(PCI_DEV(0, 17, 7), 0x60, rambits << 2);
524 Data = pci_read_config8(MEMCTRL, 0x88);
525 pci_write_config8(PCI_DEV(0, 17, 7), 0xE5, Data);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000526
Uwe Hermann0ffff342009-06-07 13:46:50 +0000527 /* Just copy this function from draminit to here! */
528 DRAMRegFinalValue(&DramAttr);
529
530 /* Just copy this function from draminit to here! */
531 SetUMARam();
532
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000533 print_debug("Resume from S3, RAM init was ignored\n");
Uwe Hermann0ffff342009-06-07 13:46:50 +0000534 } else {
535 ddr2_ram_setup();
536 ram_check(0, 640 * 1024);
Uwe Hermann20a98c92009-06-05 23:02:43 +0000537 }
538#endif
Uwe Hermann20a98c92009-06-05 23:02:43 +0000539
Uwe Hermann0ffff342009-06-07 13:46:50 +0000540 /* ddr2_ram_setup(); */
541 /* This line is the same with cx700 port. */
542 enable_shadow_ram();
543
Uwe Hermann0ffff342009-06-07 13:46:50 +0000544 /*
545 * For coreboot most time of S3 resume is the same as normal boot,
546 * so some memory area under 1M become dirty, so before this happen,
Stefan Reinauer14e22772010-04-27 06:56:47 +0000547 * I need to backup the content of mem to top-mem.
Uwe Hermann0ffff342009-06-07 13:46:50 +0000548 *
549 * I will reserve the 1M top-men in LBIO table in coreboot_table.c
550 * and recovery the content of 1M-mem in wakeup.c.
551 */
552#if PAYLOAD_IS_SEABIOS == 1
553 if (boot_mode == 3) {
554 /* An idea of Libo.Feng at amd.com in http://www.coreboot.org/pipermail/coreboot/2008-December/043111.html
555 *
556 * I want move the 1M data, I have to set some MTRRs myself.
557 * Setting MTRR before back memory save s3 resume time about
558 * 0.14 seconds.
559 *
560 * !!! Since CAR stack uses cache, and we are using cache
561 * here, we must be careful:
562 *
563 * 1. during this MTRR code, must no function call (after
564 * this MTRR, I think it should be OK to use function).
565 * 2. Before stack switch, no use variable that have value
566 * set before this.
567 * 3. Due to 2, take care of "cpu_reset", I directlly set it
568 * to ZERO.
Uwe Hermann20a98c92009-06-05 23:02:43 +0000569 */
Uwe Hermann0ffff342009-06-07 13:46:50 +0000570 u32 memtop = *(u32 *) WAKE_MEM_INFO;
571 u32 memtop1 = *(u32 *) WAKE_MEM_INFO - 0x100000;
572 u32 memtop2 = *(u32 *) WAKE_MEM_INFO - 0x200000;
573 u32 memtop3 = *(u32 *) WAKE_MEM_INFO - 64 * 1024 - 0x100000;
574 u32 memtop4 =
575 *(u32 *) WAKE_MEM_INFO - 64 * 1024 - 0x100000 + 0xe0000;
576#if 0
577 __asm__ volatile (
578 "movl $0x204, %%ecx\n\t"
579 "xorl %%edx, %%edx\n\t"
580 "movl %0,%%eax\n\t"
581 "orl $(0 | 6), %%eax\n\t"
582 "wrmsr\n\t"
Uwe Hermann20a98c92009-06-05 23:02:43 +0000583
Uwe Hermann0ffff342009-06-07 13:46:50 +0000584 "movl $0x205, %%ecx\n\t"
585 "xorl %%edx, %%edx\n\t"
586 "movl $0x100000,%%eax\n\t"
587 "decl %%eax\n\t"
588 "notl %%eax\n\t"
589 "orl $(0 | 0x800), %%eax\n\t"
590 "wrmsr\n\t"
591 ::"g"(memtop2)
Uwe Hermann20a98c92009-06-05 23:02:43 +0000592 );
Uwe Hermann20a98c92009-06-05 23:02:43 +0000593
Uwe Hermann0ffff342009-06-07 13:46:50 +0000594 __asm__ volatile (
595 "movl $0x206, %%ecx\n\t"
596 "xorl %%edx, %%edx\n\t"
597 "movl %0,%%eax\n\t"
598 "orl $(0 | 6), %%eax\n\t"
599 "wrmsr\n\t"
600
601 "movl $0x207, %%ecx\n\t"
602 "xorl %%edx, %%edx\n\t"
603 "movl $0x100000,%%eax\n\t"
604 "decl %%eax\n\t"
605 "notl %%eax\n\t"
606 "orl $(0 | 0x800), %%eax\n\t"
607 "wrmsr\n\t"
608 ::"g"(memtop1)
Uwe Hermann20a98c92009-06-05 23:02:43 +0000609 );
Uwe Hermann20a98c92009-06-05 23:02:43 +0000610
Uwe Hermann0ffff342009-06-07 13:46:50 +0000611 __asm__ volatile (
612 "movl $0x208, %ecx\n\t"
613 "xorl %edx, %edx\n\t"
614 "movl $0,%eax\n\t"
615 "orl $(0 | 6), %eax\n\t"
616 "wrmsr\n\t"
617
618 "movl $0x209, %ecx\n\t"
619 "xorl %edx, %edx\n\t"
620 "movl $0x100000,%eax\n\t"
621 "decl %eax\n\t"
622 "notl %eax\n\t"
623 "orl $(0 | 0x800), %eax\n\t"
624 "wrmsr\n\t"
Uwe Hermann20a98c92009-06-05 23:02:43 +0000625 );
Uwe Hermann20a98c92009-06-05 23:02:43 +0000626#endif
627
Stefan Reinauer14e22772010-04-27 06:56:47 +0000628 /*
Uwe Hermann0ffff342009-06-07 13:46:50 +0000629 * WAKE_MEM_INFO is inited in get_set_top_available_mem()
630 * in tables.c these two memcpy() not not be enabled if set
631 * the MTRR around this two lines.
632 */
633#if 0
634 __asm__ volatile (
635 "movl $0, %%esi\n\t"
636 "movl %0, %%edi\n\t"
637 "movl $0xa0000, %%ecx\n\t"
638 "shrl $2, %%ecx\n\t"
639 "rep movsd\n\t"
640 ::"g"(memtop3)
641 );
642
643 __asm__ volatile (
644 "movl $0xe0000, %%esi\n\t"
645 "movl %0, %%edi\n\t"
646 "movl $0x20000, %%ecx\n\t"
647 "shrl $2, %%ecx\n\t"
648 "rep movsd\n\t"
649 ::"g"(memtop4)
650 );
651#endif
652 /* This can have function call, because no variable used before this. */
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000653 print_debug("Copy memory to high memory to protect s3 wakeup vector code \n");
Uwe Hermann0ffff342009-06-07 13:46:50 +0000654 memcpy((unsigned char *)((*(u32 *) WAKE_MEM_INFO) - 64 * 1024 -
655 0x100000), (unsigned char *)0, 0xa0000);
656 memcpy((unsigned char *)((*(u32 *) WAKE_MEM_INFO) - 64 * 1024 -
657 0x100000 + 0xe0000), (unsigned char *)0xe0000, 0x20000);
658
659 /* Restore the MTRR previously modified. */
660#if 0
661 __asm__ volatile (
662 "wbinvd\n\t"
663 "xorl %edx, %edx\n\t"
664 "xorl %eax, %eax\n\t"
665 "movl $0x204, %ecx\n\t"
666 "wrmsr\n\t"
667 "movl $0x205, %ecx\n\t"
668 "wrmsr\n\t"
669 "movl $0x206, %ecx\n\t"
670 "wrmsr\n\t"
671 "movl $0x207, %ecx\n\t"
672 "wrmsr\n\t"
673 "movl $0x208, %ecx\n\t"
674 "wrmsr\n\t"
675 "movl $0x209, %ecx\n\t"
676 "wrmsr\n\t"
677 );
678#endif
Uwe Hermann20a98c92009-06-05 23:02:43 +0000679 }
Uwe Hermann0ffff342009-06-07 13:46:50 +0000680
681#endif
682
Uwe Hermann20a98c92009-06-05 23:02:43 +0000683}
Stefan Reinauer798ef282010-03-29 22:08:01 +0000684