blob: bb1ad30f7f1558ee9b3dcaff31ebbb83fe51a8f4 [file] [log] [blame]
Dave Frodinc43bce52014-12-03 08:22:46 -07001/*
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.
Dave Frodinc43bce52014-12-03 08:22:46 -070014 */
15
16#include <stdint.h>
17#include <string.h>
18#include <device/pci_def.h>
19#include <device/pci_ids.h>
20#include <arch/acpi.h>
21#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>
Dave Frodinc43bce52014-12-03 08:22:46 -070028#include <cpu/amd/car.h>
29#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>
Dave Frodinc43bce52014-12-03 08:22:46 -070034#include "cbmem.h"
35
36
37void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
38{
39 u32 val;
40
Kyösti Mälkki59e03342016-11-20 11:03:13 +020041 /* Must come first to enable PCI MMCONF. */
42 amd_initmmio();
43
Dave Frodinc43bce52014-12-03 08:22:46 -070044 /* In Hudson RRG, PMIOxD2[5:4] is "Drive strength control for
45 * LpcClk[1:0]". To be consistent with Parmer, setting to 4mA
46 * even though the register is not documented in the Kabini BKDG.
47 * Otherwise the serial output is bad code.
48 */
49 outb(0xD2, 0xcd6);
50 outb(0x00, 0xcd7);
51
Dave Frodinc43bce52014-12-03 08:22:46 -070052 /* Set LPC decode enables. */
53 pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
54 pci_write_config32(dev, 0x44, 0xff03ffd5);
55
56 hudson_lpc_port80();
57
58 if (!cpu_init_detectedx && boot_cpu()) {
59 post_code(0x30);
60
61 post_code(0x31);
62 console_init();
63 }
64
65 /* Halt if there was a built in self test failure */
66 post_code(0x34);
67 report_bist_failure(bist);
68
69 /* Load MPB */
70 val = cpuid_eax(1);
71 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
72 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
73
74 /* On Larne, after LpcClkDrvSth is set, it needs some time to be stable, because of the buffer ICS551M */
75 int i;
76 for(i = 0; i < 200000; i++)
77 val = inb(0xcd6);
78
79 post_code(0x37);
80 agesawrapper_amdinitreset();
81 post_code(0x38);
82 printk(BIOS_DEBUG, "Got past yangtze_early_setup\n");
83
84 post_code(0x39);
85
86 agesawrapper_amdinitearly();
Kyösti Mälkki78c5d582015-01-09 23:48:47 +020087 int s3resume = acpi_is_wakeup_s3();
Dave Frodinc43bce52014-12-03 08:22:46 -070088 if (!s3resume) {
89 post_code(0x40);
90 agesawrapper_amdinitpost();
91 post_code(0x41);
92 agesawrapper_amdinitenv();
93 /* TODO: Disable cache is not ok. */
94 disable_cache_as_ram();
95 } else { /* S3 detect */
96 printk(BIOS_INFO, "S3 detected\n");
97
98 post_code(0x60);
99 agesawrapper_amdinitresume();
100
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200101 amd_initcpuio();
Dave Frodinc43bce52014-12-03 08:22:46 -0700102 agesawrapper_amds3laterestore();
103
104 post_code(0x61);
105 prepare_for_resume();
106 }
107
108 outb(0xEA, 0xCD6);
109 outb(0x1, 0xcd7);
110
111 post_code(0x50);
112 copy_and_run();
113
114 post_code(0x54); /* Should never see this post code. */
115}