Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 1 | /* |
| 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 Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 21 | * 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 23 | */ |
| 24 | |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 25 | #define RAMINIT_SYSINFO 1 |
Stefan Reinauer | 17b60a9 | 2010-04-14 17:11:47 +0000 | [diff] [blame] | 26 | #define PAYLOAD_IS_SEABIOS 0 |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 27 | |
| 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 Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 35 | #include <console/console.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame^] | 36 | #include <lib.h> |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 37 | #include "northbridge/via/vx800/vx800.h" |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 38 | #include "cpu/x86/bist.h" |
| 39 | #include "pc80/udelay_io.c" |
| 40 | #include "lib/delay.c" |
Myles Watson | 42f75c3 | 2009-07-07 17:54:26 +0000 | [diff] [blame] | 41 | #include <string.h> |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 42 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 43 | /* This file contains the board-special SI value for raminit.c. */ |
Uwe Hermann | d64f403 | 2009-06-07 14:38:32 +0000 | [diff] [blame] | 44 | #include "driving_clk_phase_data.c" |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 45 | |
| 46 | #include "northbridge/via/vx800/raminit.h" |
| 47 | #include "northbridge/via/vx800/raminit.c" |
Stefan Reinauer | 853263b | 2010-04-09 10:43:49 +0000 | [diff] [blame] | 48 | |
Uwe Hermann | d64f403 | 2009-06-07 14:38:32 +0000 | [diff] [blame] | 49 | #include "wakeup.h" |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 50 | |
Uwe Hermann | 4e2ffb8 | 2009-07-15 00:03:28 +0000 | [diff] [blame] | 51 | #include "superio/winbond/w83697hf/w83697hf_early_serial.c" |
| 52 | |
| 53 | #define SERIAL_DEV PNP_DEV(0x2e, W83697HF_SP1) |
| 54 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 55 | /* |
| 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 Reinauer | 8816cdf | 2010-04-14 16:39:30 +0000 | [diff] [blame] | 59 | static int acpi_is_wakeup_early_via_vx800(void) |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 60 | { |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 61 | device_t dev; |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 62 | u16 tmp, result; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 63 | |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 64 | print_debug("In acpi_is_wakeup_early_via_vx800\n"); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 65 | /* 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 Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 70 | die("Power management controller not found\n"); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 71 | |
| 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 Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 79 | result = ((tmp & (7 << 10)) >> 10) == 1 ? 3 : 0; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 80 | print_debug(" boot_mode="); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 81 | print_debug_hex16(result); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 82 | print_debug("\n"); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 83 | return result; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 86 | /* All content of this function came from the cx700 port of coreboot. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 87 | static void enable_mainboard_devices(void) |
| 88 | { |
| 89 | device_t dev; |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 90 | #if 0 |
| 91 | /* |
| 92 | * Add and close this switch, since some line cause error, some |
| 93 | * written at elsewhere (stage1 stage2). |
| 94 | */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 95 | u8 regdata; |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 96 | dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, |
| 97 | PCI_DEVICE_ID_VIA_VX855_LPC), 0); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 98 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 99 | /* Disable GP3. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 100 | pci_write_config8(dev, 0x98, 0x00); |
| 101 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 102 | pci_write_config8(dev, 0x50, 0x80); /* Disable mc97. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 103 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 104 | /* |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 111 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 112 | /* 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 119 | pci_write_config8(dev, 0x59, 0x80); |
| 120 | pci_write_config8(dev, 0x5b, 0x01); |
| 121 | #endif |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 122 | |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 123 | print_debug("In enable_mainboard_devices \n"); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 124 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 125 | /* Enable P2P Bridge Header for external PCI bus. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 126 | dev = pci_locate_device(PCI_ID(0x1106, 0xa353), 0); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 127 | pci_write_config8(dev, 0x4f, 0x41); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 128 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 129 | /* |
| 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 Reinauer | 8816cdf | 2010-04-14 16:39:30 +0000 | [diff] [blame] | 139 | |
| 140 | uint16_t values; |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 141 | values = pci_read_config16(dev, 0xBA); |
| 142 | values &= ~0xffff; |
| 143 | values |= 0x5324; |
| 144 | pci_write_config16(dev, 0xBA, values); |
| 145 | #endif |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 148 | /* |
| 149 | * Most content of this function came from the cx700 port of coreboot. |
| 150 | * Turn on the shadow of E-seg. |
| 151 | */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 152 | static void enable_shadow_ram(void) |
| 153 | { |
| 154 | uint8_t shadowreg; |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 155 | |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 160 | pci_write_config8(PCI_DEV(0, 0, 3), 0x80, 0xff); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 161 | |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 162 | /* 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 Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 166 | |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 173 | pci_write_config8(PCI_DEV(0, 0, 3), 0x82, 0xff); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 174 | |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 175 | #if 0 |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 176 | /* Enable shadow RAM as normal DRAM */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 177 | /* 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 Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 181 | /* pci_write_config8(PCI_DEV(0, 0, 3), 0x81, 0xff); */ |
| 182 | /* pci_write_config8(PCI_DEV(0, 0, 7), 0x62, 0xff); */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 183 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 184 | /* Do it again for the vlink controller. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 185 | 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 Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 191 | /* |
| 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 | */ |
| 196 | static const struct VIA_PCI_REG_INIT_TABLE mNbStage1InitTbl[] = { |
| 197 | /* VT3409 no PCI-E */ |
Stefan Reinauer | 8816cdf | 2010-04-14 16:39:30 +0000 | [diff] [blame] | 198 | { 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 Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 201 | // Set ROMSIP value by software |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 202 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 203 | /* |
Stefan Reinauer | 8816cdf | 2010-04-14 16:39:30 +0000 | [diff] [blame] | 204 | { 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 Hermann | d64f403 | 2009-06-07 14:38:32 +0000 | [diff] [blame] | 232 | */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 233 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 234 | // CPU Host Bus Control |
Stefan Reinauer | 8816cdf | 2010-04-14 16:39:30 +0000 | [diff] [blame] | 235 | { 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 255 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 256 | // Set APIC and SMRAM |
Stefan Reinauer | 8816cdf | 2010-04-14 16:39:30 +0000 | [diff] [blame] | 257 | { 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 262 | #define USE_VCP 1 /* 0 means "use DVP". */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 263 | #define USE_COM1 1 |
| 264 | #define USE_COM2 0 |
| 265 | |
| 266 | #define gCom1Base 0x3f8 |
| 267 | #define gCom2Base 0x2f8 |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 268 | |
Stefan Reinauer | 17b60a9 | 2010-04-14 17:11:47 +0000 | [diff] [blame] | 269 | #if 0 |
| 270 | static void EmbedComInit(void) |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 271 | { |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 272 | u8 ByteVal; |
| 273 | u16 ComBase; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 274 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 275 | /* Enable NB multiple function control. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 276 | ByteVal = pci_read_config8(PCI_DEV(0, 0, 0), 0x4f); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 277 | ByteVal = ByteVal | 0x01; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 278 | pci_write_config8(PCI_DEV(0, 0, 0), 0x4f, ByteVal); |
| 279 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 280 | /* VGA enable. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 281 | ByteVal = pci_read_config8(PCI_DEV(0, 0, 3), 0xA1); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 282 | ByteVal = ByteVal | 0x80; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 283 | pci_write_config8(PCI_DEV(0, 0, 3), 0xA1, ByteVal); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 284 | |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 285 | ByteVal = pci_read_config8(PCI_DEV(0, 0, 3), 0xA7); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 286 | ByteVal = ByteVal | 0x08; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 287 | pci_write_config8(PCI_DEV(0, 0, 3), 0xA7, ByteVal); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 288 | |
| 289 | /* Enable P2P IO/mem. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 290 | ByteVal = pci_read_config8(PCI_DEV(0, 1, 0), 0x4); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 291 | ByteVal = ByteVal | 0x07; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 292 | pci_write_config8(PCI_DEV(0, 1, 0), 0x4, ByteVal); |
| 293 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 294 | /* Turn on graphic chip I/O port port access. */ |
| 295 | ByteVal = inb(0x3C3); |
| 296 | ByteVal = ByteVal | 0x01; |
| 297 | outb(ByteVal, 0x3C3); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 298 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 299 | /* Turn off graphic chip register protection. */ |
| 300 | outb(0x10, 0x3C4); |
| 301 | ByteVal = inb(0x3C5); |
| 302 | ByteVal = ByteVal | 0x01; |
| 303 | outb(ByteVal, 0x3C5); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 304 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 305 | /* 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 310 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 311 | /* 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 317 | pci_write_config8(PCI_DEV(0, 17, 0), 0x46, ByteVal); |
| 318 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 319 | /* 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 327 | pci_write_config8(PCI_DEV(0, 17, 0), 0xB0, ByteVal); |
| 328 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 329 | if (USE_COM1 == 1) |
| 330 | ComBase = gCom1Base; |
| 331 | else |
| 332 | ComBase = gCom2Base; |
| 333 | |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 334 | //noharddrive |
| 335 | |
Uwe Hermann | d64f403 | 2009-06-07 14:38:32 +0000 | [diff] [blame] | 336 | /* Set embedded COM1 I/O base = 0x3E8 (D17F0RB4, ByteVal = 0xFD) */ |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 337 | 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 344 | |
Uwe Hermann | d64f403 | 2009-06-07 14:38:32 +0000 | [diff] [blame] | 345 | /* Set embedded COM2 I/O base = 0x2E8 (D17F0RB5, ByteVal = 0xDD). */ |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 346 | 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 354 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 355 | /* Disable interrupt. */ |
| 356 | ByteVal = inb(ComBase + 3); |
| 357 | outb(ByteVal & 0x7F, ComBase + 3); |
| 358 | outb(0x00, ComBase + 1); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 359 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 360 | /* Set BAUD rate. */ |
| 361 | ByteVal = inb(ComBase + 3); |
| 362 | outb(ByteVal | 0x80, ComBase + 3); |
| 363 | outb(0x01, ComBase); |
| 364 | outb(0x00, ComBase + 1); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 365 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 366 | /* 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 372 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 373 | /* SOutput("Embedded COM output\n"); */ |
| 374 | /* while(1); */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 375 | } |
Stefan Reinauer | 17b60a9 | 2010-04-14 17:11:47 +0000 | [diff] [blame] | 376 | #endif |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 377 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 378 | /* cache_as_ram.inc jumps to here. */ |
Stefan Reinauer | 314e551 | 2010-04-09 20:36:29 +0000 | [diff] [blame] | 379 | void main(unsigned long bist) |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 380 | { |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 381 | u16 boot_mode; |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 382 | u8 rambits, Data8, Data; |
| 383 | device_t device; |
| 384 | /* device_t dev; */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 385 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 386 | /* |
| 387 | * Enable multifunction for northbridge. These 4 lines (until |
| 388 | * console_init()) are the same with epia-cn port. |
| 389 | */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 390 | pci_write_config8(PCI_DEV(0, 0, 0), 0x4f, 0x01); |
Uwe Hermann | 4e2ffb8 | 2009-07-15 00:03:28 +0000 | [diff] [blame] | 391 | /* EmbedComInit(); */ |
| 392 | w83697hf_set_clksel_48(SERIAL_DEV); |
| 393 | w83697hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
| 394 | uart_init(); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 395 | /* enable_vx800_serial(); */ |
| 396 | /* uart_init(); */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 397 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 398 | /* |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 414 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 415 | 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 428 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 429 | /* |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 434 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 435 | /* Decide if this is a s3 wakeup or a normal boot. */ |
| 436 | boot_mode = acpi_is_wakeup_early_via_vx800(); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 437 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 438 | /* |
| 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 Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 444 | if ((boot_mode != 3) |
| 445 | && (pci_read_config8(PCI_DEV(0, 0, 3), 0x80) != 0)) { |
| 446 | outb(6, 0xcf9); |
| 447 | } |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 448 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 449 | /* x86 cold boot I/O cmd. */ |
| 450 | /* These 2 lines are the same with epia-cn port. */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 451 | enable_smbus(); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 452 | |
| 453 | /* This fix does help vx800!, but vx855 doesn't need this. */ |
| 454 | /* smbus_fixup(&ctrl); */ |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 455 | |
| 456 | if (bist == 0) { |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 457 | /* |
| 458 | * CAR needs MTRR until memory is ok, so disable this |
| 459 | * early_mtrr_init() call. |
| 460 | */ |
| 461 | #if 0 |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 462 | print_debug("doing early_mtrr\n"); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 463 | early_mtrr_init(); |
| 464 | #endif |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* Halt if there was a built-in self test failure. */ |
| 468 | report_bist_failure(bist); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 469 | |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 470 | print_debug("Enabling mainboard devices\n"); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 471 | enable_mainboard_devices(); |
| 472 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 473 | /* |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 479 | print_debug("NB chip revision ="); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 480 | print_debug_hex8(Data); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 481 | print_debug("\n"); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 482 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 483 | /* 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 492 | #if 1 |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 493 | if (boot_mode == 3) { |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 494 | u8 i; |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 495 | u8 ramregs[] = { 0x43, 0x42, 0x41, 0x40 }; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 496 | DRAM_SYS_ATTR DramAttr; |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 497 | |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 498 | print_debug("This is an S3 wakeup\n"); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 499 | |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 514 | rambits = pci_read_config8(device, ramregs[i]); |
| 515 | if (rambits != 0) |
| 516 | break; |
| 517 | } |
| 518 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 519 | DRAMDRDYSetting(&DramAttr); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 520 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 521 | 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 526 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 527 | /* 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 Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 533 | print_debug("Resume from S3, RAM init was ignored\n"); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 534 | } else { |
| 535 | ddr2_ram_setup(); |
| 536 | ram_check(0, 640 * 1024); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 537 | } |
| 538 | #endif |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 539 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 540 | /* ddr2_ram_setup(); */ |
| 541 | /* This line is the same with cx700 port. */ |
| 542 | enable_shadow_ram(); |
| 543 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 544 | /* |
| 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 547 | * I need to backup the content of mem to top-mem. |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 548 | * |
| 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 569 | */ |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 570 | 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 583 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 584 | "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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 592 | ); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 593 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 594 | __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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 609 | ); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 610 | |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 611 | __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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 625 | ); |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 626 | #endif |
| 627 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 628 | /* |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 629 | * 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 Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 653 | print_debug("Copy memory to high memory to protect s3 wakeup vector code \n"); |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 654 | 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 Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 679 | } |
Uwe Hermann | 0ffff34 | 2009-06-07 13:46:50 +0000 | [diff] [blame] | 680 | |
| 681 | #endif |
| 682 | |
Uwe Hermann | 20a98c9 | 2009-06-05 23:02:43 +0000 | [diff] [blame] | 683 | } |
Stefan Reinauer | 798ef28 | 2010-03-29 22:08:01 +0000 | [diff] [blame] | 684 | |