blob: b1addb3db3df644cb85dc0b3565562c105a078e1 [file] [log] [blame]
Siyuan Wang80cf7d52013-07-09 17:42:43 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, 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.
Siyuan Wang80cf7d52013-07-09 17:42:43 +080014 */
15
16#include <stdint.h>
17#include <string.h>
18#include <device/pci_def.h>
19#include <device/pci_ids.h>
Kyösti Mälkki207880c2013-12-10 09:03:17 +020020#include <arch/acpi.h>
Siyuan Wang80cf7d52013-07-09 17:42:43 +080021#include <arch/io.h>
22#include <arch/stages.h>
23#include <device/pnp_def.h>
24#include <arch/cpu.h>
25#include <cpu/x86/lapic.h>
26#include <console/console.h>
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050027#include <commonlib/loglevel.h>
Edward O'Callaghanbf9d1222014-10-29 09:26:00 +110028#include <cpu/amd/car.h>
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030029#include <northbridge/amd/agesa/agesawrapper.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110030#include <cpu/x86/bist.h>
31#include <cpu/x86/lapic.h>
32#include <southbridge/amd/agesa/hudson/hudson.h>
33#include <cpu/amd/agesa/s3_resume.h>
Siyuan Wang80cf7d52013-07-09 17:42:43 +080034#include "cbmem.h"
35
Siyuan Wang80cf7d52013-07-09 17:42:43 +080036
37void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
38{
39 u32 val;
Siyuan Wang80cf7d52013-07-09 17:42:43 +080040
41 /* In Hudson RRG, PMIOxD2[5:4] is "Drive strength control for
42 * LpcClk[1:0]". To be consistent with Parmer, setting to 4mA
43 * even though the register is not documented in the Kabini BKDG.
44 * Otherwise the serial output is bad code.
45 */
46 outb(0xD2, 0xcd6);
47 outb(0x00, 0xcd7);
48
Kyösti Mälkki48518f02014-11-25 14:20:57 +020049 amd_initmmio();
Siyuan Wang80cf7d52013-07-09 17:42:43 +080050
Kyösti Mälkki88ff8b52014-11-21 17:40:37 +020051 /* Set LPC decode enables. */
52 pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
53 pci_write_config32(dev, 0x44, 0xff03ffd5);
54
Siyuan Wang80cf7d52013-07-09 17:42:43 +080055 hudson_lpc_port80();
56
57 if (!cpu_init_detectedx && boot_cpu()) {
58 post_code(0x30);
59
60 post_code(0x31);
61 console_init();
62 }
63
64 /* Halt if there was a built in self test failure */
65 post_code(0x34);
66 report_bist_failure(bist);
67
68 /* Load MPB */
69 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +020070 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
71 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
Siyuan Wang80cf7d52013-07-09 17:42:43 +080072
73 /* On Larne, after LpcClkDrvSth is set, it needs some time to be stable, because of the buffer ICS551M */
74 int i;
75 for(i = 0; i < 200000; i++)
76 val = inb(0xcd6);
77
78 post_code(0x37);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030079 agesawrapper_amdinitreset();
Siyuan Wang80cf7d52013-07-09 17:42:43 +080080 post_code(0x38);
Bruce Griffith4e08a952013-07-07 02:04:16 -060081 printk(BIOS_DEBUG, "Got past yangtze_early_setup\n");
Siyuan Wang80cf7d52013-07-09 17:42:43 +080082
83 post_code(0x39);
84
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030085 agesawrapper_amdinitearly();
Kyösti Mälkki78c5d582015-01-09 23:48:47 +020086 int s3resume = acpi_is_wakeup_s3();
Kyösti Mälkkie1b468e2014-06-18 09:10:53 +030087 if (!s3resume) {
Siyuan Wang80cf7d52013-07-09 17:42:43 +080088 post_code(0x40);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030089 agesawrapper_amdinitpost();
Siyuan Wang80cf7d52013-07-09 17:42:43 +080090 post_code(0x41);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030091 agesawrapper_amdinitenv();
Siyuan Wang80cf7d52013-07-09 17:42:43 +080092 /* TODO: Disable cache is not ok. */
93 disable_cache_as_ram();
Siyuan Wang80cf7d52013-07-09 17:42:43 +080094 } else { /* S3 detect */
95 printk(BIOS_INFO, "S3 detected\n");
96
97 post_code(0x60);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030098 agesawrapper_amdinitresume();
Siyuan Wang80cf7d52013-07-09 17:42:43 +080099
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200100 amd_initcpuio();
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300101 agesawrapper_amds3laterestore();
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800102
103 post_code(0x61);
Kyösti Mälkki23b4f0c2014-06-18 09:55:26 +0300104 prepare_for_resume();
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800105 }
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800106
107 outb(0xEA, 0xCD6);
108 outb(0x1, 0xcd7);
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800109
110 post_code(0x50);
111 copy_and_run();
112
113 post_code(0x54); /* Should never see this post code. */
114}