blob: d7fa6bcfcb5be0830dd397ee9dc47e24505118f4 [file] [log] [blame]
Edward O'Callaghan4726a872014-01-25 07:40:39 +11001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
Edward O'Callaghan6e56de32014-01-25 21:46:10 +11005 * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com>.
Edward O'Callaghan4726a872014-01-25 07:40:39 +11006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030021#include <northbridge/amd/agesa/agesawrapper.h>
Edward O'Callaghan5ff4b082014-03-29 17:54:26 +110022
Kyösti Mälkki207880c2013-12-10 09:03:17 +020023#include <arch/acpi.h>
Edward O'Callaghan5ff4b082014-03-29 17:54:26 +110024#include <arch/cpu.h>
Edward O'Callaghan4726a872014-01-25 07:40:39 +110025#include <arch/io.h>
26#include <arch/stages.h>
Edward O'Callaghan5ff4b082014-03-29 17:54:26 +110027#include <cbmem.h>
Edward O'Callaghan4726a872014-01-25 07:40:39 +110028#include <console/console.h>
Edward O'Callaghan5ff4b082014-03-29 17:54:26 +110029#include <cpu/amd/agesa/s3_resume.h>
30#include <cpu/x86/lapic.h>
31#include <cpu/x86/bist.h>
32
33#include <device/pci_def.h>
34#include <device/pci_ids.h>
35#include <stdint.h>
36#include <string.h>
37
Edward O'Callaghan4726a872014-01-25 07:40:39 +110038#include <console/loglevel.h>
39#include <cpu/x86/mtrr.h>
Edward O'Callaghan5ff4b082014-03-29 17:54:26 +110040#include <cpu/x86/cache.h>
41#include <cpu/amd/mtrr.h>
Kyösti Mälkki2458f422014-04-22 16:46:31 +030042#include <cpu/amd/car.h>
Edward O'Callaghan5ff4b082014-03-29 17:54:26 +110043#include <sb_cimx.h>
44#include <southbridge/amd/cimx/sb800/SBPLATFORM.h>
Edward O'Callaghancf7b4982014-04-23 21:52:25 +100045#include <superio/fintek/common/fintek.h>
46#include <superio/fintek/f71869ad/f71869ad.h>
Edward O'Callaghan5ff4b082014-03-29 17:54:26 +110047
Edward O'Callaghan6e56de32014-01-25 21:46:10 +110048/* Ensure Super I/O config address (i.e., 0x2e or 0x4e) matches that of devicetree.cb */
49#define SERIAL_DEV PNP_DEV(0x2e, F71869AD_SP1)
Edward O'Callaghan4726a872014-01-25 07:40:39 +110050
Edward O'Callaghan708be1a2014-04-06 12:34:56 +100051/*
52 * Possible AGESA_STATUS values:
53 *
54 * 0x0 = AGESA_SUCCESS
55 * 0x1 = AGESA_UNSUPPORTED
56 * 0x2 = AGESA_BOUNDS_CHK
57 * 0x3 = AGESA_ALERT
58 * 0x4 = AGESA_WARNING
59 * 0x5 = AGESA_ERROR
60 * 0x6 = AGESA_CRITICAL
61 * 0x7 = AGESA_FATAL
62 */
63
64
Edward O'Callaghan4726a872014-01-25 07:40:39 +110065void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
66{
67 u32 val;
68
Edward O'Callaghan4726a872014-01-25 07:40:39 +110069 /*
70 * All cores: allow caching of flash chip code and data
71 * (there are no cache-as-ram reliability concerns with family 14h)
72 */
73 __writemsr (0x20c, (0x0100000000ull - CACHE_ROM_SIZE) | 5);
74 __writemsr (0x20d, (0x1000000000ull - CACHE_ROM_SIZE) | 0x800);
75
76 /* All cores: set pstate 0 (1600 MHz) early to save a few ms of boot time */
77 __writemsr (0xc0010062, 0);
78
Kyösti Mälkkie453b9a2014-11-25 14:03:29 +020079 agesawrapper_amdinitmmio();
80
Edward O'Callaghan4726a872014-01-25 07:40:39 +110081 if (!cpu_init_detectedx && boot_cpu()) {
82 post_code(0x30);
83 sb_Poweron_Init();
84
85 post_code(0x31);
Edward O'Callaghancf7b4982014-04-23 21:52:25 +100086 fintek_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Edward O'Callaghan4726a872014-01-25 07:40:39 +110087 console_init();
88 }
89
90 /* Halt if there was a built in self test failure */
91 post_code(0x34);
92 report_bist_failure(bist);
93
94 /* Load MPB */
95 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +020096 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
97 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
Edward O'Callaghan4726a872014-01-25 07:40:39 +110098
Edward O'Callaghan4726a872014-01-25 07:40:39 +110099 post_code(0x37);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300100 agesawrapper_amdinitreset();
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100101
102 post_code(0x39);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300103 agesawrapper_amdinitearly();
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100104
Kyösti Mälkkie1b468e2014-06-18 09:10:53 +0300105 int s3resume = acpi_is_wakeup_early() && acpi_s3_resume_allowed();
106 if (!s3resume) {
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100107 post_code(0x40);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300108 agesawrapper_amdinitpost();
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100109
110 post_code(0x42);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300111 agesawrapper_amdinitenv();
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100112
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100113 } else { /* S3 detect */
114 printk(BIOS_INFO, "S3 detected\n");
115
116 post_code(0x60);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300117 agesawrapper_amdinitresume();
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100118
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300119 agesawrapper_amds3laterestore();
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100120
121 post_code(0x61);
Kyösti Mälkki23b4f0c2014-06-18 09:55:26 +0300122 prepare_for_resume();
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100123 }
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100124
Edward O'Callaghan4726a872014-01-25 07:40:39 +1100125 post_code(0x50);
126 copy_and_run();
127 printk(BIOS_ERR, "Error: copy_and_run() returned!\n");
128
129 post_code(0x54); /* Should never see this post code. */
130}