Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 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) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 8 | * Copyright (C) 2008 Rudolf Marek <r.marek@assembler.cz> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 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. |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 21 | unsigned int get_sbdn(unsigned bus); |
| 22 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 23 | #include <stdint.h> |
Patrick Georgi | 12aba82 | 2009-04-30 07:07:22 +0000 | [diff] [blame] | 24 | #include <string.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 25 | #include <device/pci_def.h> |
| 26 | #include <arch/io.h> |
| 27 | #include <device/pnp_def.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 28 | #include <cpu/amd/mtrr.h> |
| 29 | #include <cpu/x86/lapic.h> |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 30 | #include <pc80/mc146818rtc.h> |
Patrick Georgi | 12584e2 | 2010-05-08 09:14:51 +0000 | [diff] [blame] | 31 | #include <console/console.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 32 | #include <cpu/amd/model_fxx_rev.h> |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 33 | #include <halt.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 34 | #include <northbridge/amd/amdk8/raminit.h> |
Edward O'Callaghan | ebe3a7a | 2015-01-05 00:27:54 +1100 | [diff] [blame] | 35 | #include <delay.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 36 | #include "northbridge/amd/amdk8/reset_test.c" |
| 37 | #include "northbridge/amd/amdk8/debug.c" |
Edward O'Callaghan | f292002 | 2014-04-27 00:41:50 +1000 | [diff] [blame] | 38 | #include <superio/ite/common/ite.h> |
| 39 | #include <superio/ite/it8712f/it8712f.h> |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 40 | #include "southbridge/via/vt8237r/early_smbus.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 41 | #include <cpu/x86/bist.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 42 | #include "northbridge/amd/amdk8/setup_resource_map.c" |
Uwe Hermann | 6dc92f0 | 2010-11-21 11:36:03 +0000 | [diff] [blame] | 43 | #include <spd.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 44 | |
| 45 | #define SERIAL_DEV PNP_DEV(0x2e, IT8712F_SP1) |
Edward O'Callaghan | 76d8fd6 | 2014-05-14 19:15:08 +1000 | [diff] [blame] | 46 | #define GPIO_DEV PNP_DEV(0x2e, IT8712F_GPIO) |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 47 | |
Uwe Hermann | 7b99705 | 2010-11-21 22:47:22 +0000 | [diff] [blame] | 48 | static void memreset(int controllers, const struct mem_controller *ctrl) { } |
| 49 | static void activate_spd_rom(const struct mem_controller *ctrl) { } |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 50 | |
| 51 | static inline int spd_read_byte(unsigned device, unsigned address) |
| 52 | { |
| 53 | return smbus_read_byte(device, address); |
| 54 | } |
| 55 | |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 56 | #include "southbridge/via/k8t890/early_car.c" |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 57 | #include <northbridge/amd/amdk8/amdk8.h> |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 58 | #include "northbridge/amd/amdk8/incoherent_ht.c" |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 59 | #include "northbridge/amd/amdk8/coherent_ht.c" |
| 60 | #include "northbridge/amd/amdk8/raminit_f.c" |
Stefan Reinauer | c13093b | 2009-09-23 18:51:03 +0000 | [diff] [blame] | 61 | #include "lib/generic_sdram.c" |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 62 | #include "cpu/amd/dualcore/dualcore.c" |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 63 | #include "cpu/amd/model_fxx/init_cpus.c" |
Rudolf Marek | e94e2e3 | 2008-12-04 23:42:36 +0000 | [diff] [blame] | 64 | |
| 65 | #define SB_VFSMAF 0 |
| 66 | |
Rudolf Marek | e94e2e3 | 2008-12-04 23:42:36 +0000 | [diff] [blame] | 67 | static void ldtstop_sb(void) |
| 68 | { |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 69 | printk(BIOS_DEBUG, "toggle LDTSTP#\n"); |
Rudolf Marek | 43358a5 | 2011-06-29 23:59:13 +0200 | [diff] [blame] | 70 | |
| 71 | /* fix errata #181, disable DRAM controller it will get enabled later */ |
| 72 | u8 tmp = pci_read_config8(PCI_DEV(0, 0x18, 2), 0x94); |
| 73 | tmp |= (( 1 << 14) | (1 << 3)); |
| 74 | pci_write_config8(PCI_DEV(0, 0x18, 2), 0x94, tmp); |
| 75 | |
Rudolf Marek | e94e2e3 | 2008-12-04 23:42:36 +0000 | [diff] [blame] | 76 | u8 reg = inb (VT8237R_ACPI_IO_BASE + 0x5c); |
| 77 | reg = reg ^ (1 << 0); |
| 78 | outb(reg, VT8237R_ACPI_IO_BASE + 0x5c); |
| 79 | reg = inb(VT8237R_ACPI_IO_BASE + 0x15); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 80 | printk(BIOS_DEBUG, "done\n"); |
Rudolf Marek | e94e2e3 | 2008-12-04 23:42:36 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 83 | #include "cpu/amd/model_fxx/fidvid.c" |
| 84 | #include "northbridge/amd/amdk8/resourcemap.c" |
| 85 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 86 | void soft_reset(void) |
| 87 | { |
| 88 | uint8_t tmp; |
| 89 | |
| 90 | set_bios_reset(); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 91 | printk(BIOS_DEBUG, "soft reset\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 92 | |
| 93 | /* PCI reset */ |
| 94 | tmp = pci_read_config8(PCI_DEV(0, 0x11, 0), 0x4f); |
| 95 | tmp |= 0x01; |
| 96 | /* FIXME from S3 set bit1 to disable USB reset VT8237A/S */ |
| 97 | pci_write_config8(PCI_DEV(0, 0x11, 0), 0x4f, tmp); |
| 98 | |
Patrick Georgi | bd79c5e | 2014-11-28 22:35:36 +0100 | [diff] [blame] | 99 | halt(); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | unsigned int get_sbdn(unsigned bus) |
| 103 | { |
| 104 | device_t dev; |
| 105 | |
| 106 | dev = pci_locate_device_on_bus(PCI_ID(PCI_VENDOR_ID_VIA, |
| 107 | PCI_DEVICE_ID_VIA_VT8237R_LPC), bus); |
| 108 | return (dev >> 15) & 0x1f; |
| 109 | } |
| 110 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 111 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
| 112 | { |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 113 | static const uint16_t spd_addr[] = { |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 114 | // Node 0 |
Uwe Hermann | 6dc92f0 | 2010-11-21 11:36:03 +0000 | [diff] [blame] | 115 | DIMM0, DIMM2, 0, 0, |
| 116 | DIMM1, DIMM3, 0, 0, |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 117 | // Node 1 |
Uwe Hermann | 6dc92f0 | 2010-11-21 11:36:03 +0000 | [diff] [blame] | 118 | DIMM4, DIMM6, 0, 0, |
| 119 | DIMM5, DIMM7, 0, 0, |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 120 | }; |
| 121 | unsigned bsp_apicid = 0; |
| 122 | int needs_reset = 0; |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame] | 123 | struct sys_info *sysinfo = &sysinfo_car; |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 124 | |
Edward O'Callaghan | f292002 | 2014-04-27 00:41:50 +1000 | [diff] [blame] | 125 | ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Edward O'Callaghan | 76d8fd6 | 2014-05-14 19:15:08 +1000 | [diff] [blame] | 126 | ite_kill_watchdog(GPIO_DEV); |
| 127 | ite_enable_3vsbsw(GPIO_DEV); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 128 | console_init(); |
| 129 | enable_rom_decode(); |
| 130 | |
Elyes HAOUAS | aedcc10 | 2014-07-21 08:07:19 +0200 | [diff] [blame] | 131 | printk(BIOS_INFO, "now booting...\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 132 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 133 | if (bist == 0) |
| 134 | bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo); |
| 135 | |
| 136 | /* Halt if there was a built in self test failure. */ |
| 137 | report_bist_failure(bist); |
| 138 | setup_default_resource_map(); |
| 139 | setup_coherent_ht_domain(); |
| 140 | wait_all_core0_started(); |
| 141 | |
Stefan Reinauer | 64d3baf | 2010-04-22 13:18:09 +0000 | [diff] [blame] | 142 | printk(BIOS_INFO, "now booting... All core 0 started\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 143 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 144 | #if CONFIG_LOGICAL_CPUS |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 145 | /* It is said that we should start core1 after all core0 launched. */ |
| 146 | start_other_cores(); |
| 147 | wait_all_other_cores_started(bsp_apicid); |
| 148 | #endif |
| 149 | init_timer(); |
| 150 | ht_setup_chains_x(sysinfo); /* Init sblnk and sbbusn, nodes, sbdn. */ |
| 151 | |
| 152 | needs_reset = optimize_link_coherent_ht(); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 153 | printk(BIOS_DEBUG, "%02x", needs_reset); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 154 | needs_reset |= optimize_link_incoherent_ht(sysinfo); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 155 | printk(BIOS_DEBUG, "%02x", needs_reset); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 156 | needs_reset |= k8t890_early_setup_ht(); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 157 | printk(BIOS_DEBUG, "%02x", needs_reset); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 158 | |
| 159 | vt8237_early_network_init(NULL); |
| 160 | vt8237_early_spi_init(); |
| 161 | |
| 162 | if (needs_reset) { |
Stefan Reinauer | 64d3baf | 2010-04-22 13:18:09 +0000 | [diff] [blame] | 163 | printk(BIOS_DEBUG, "ht reset -\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 164 | soft_reset(); |
Stefan Reinauer | 64d3baf | 2010-04-22 13:18:09 +0000 | [diff] [blame] | 165 | printk(BIOS_DEBUG, "FAILED!\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 168 | /* the HT settings needs to be OK, because link freq chnage may cause HT disconnect */ |
| 169 | /* allow LDT STOP asserts */ |
| 170 | vt8237_sb_enable_fid_vid(); |
| 171 | |
| 172 | enable_fid_change(); |
Stefan Reinauer | 069f476 | 2015-01-05 13:02:32 -0800 | [diff] [blame] | 173 | printk(BIOS_DEBUG, "after enable_fid_change\n"); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 174 | |
Rudolf Marek | 31e52e6 | 2008-12-04 23:37:12 +0000 | [diff] [blame] | 175 | init_fidvid_bsp(bsp_apicid); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 176 | |
| 177 | /* Stop the APs so we can start them later in init. */ |
| 178 | allow_all_aps_stop(bsp_apicid); |
| 179 | |
| 180 | /* It's the time to set ctrl now. */ |
| 181 | fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr); |
| 182 | enable_smbus(); |
Rudolf Marek | 0583997 | 2008-09-23 20:36:03 +0000 | [diff] [blame] | 183 | sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo); |
| 184 | post_cache_as_ram(); |
| 185 | } |