blob: 193454542c836be2fc39b3abca6bfb679f9fc428 [file] [log] [blame]
zbaoea71e812012-08-02 18:36:36 +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.
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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
zbaoea71e812012-08-02 18:36:36 +080018 */
19
20#include <stdint.h>
21#include <string.h>
22#include <device/pci_def.h>
23#include <device/pci_ids.h>
Kyösti Mälkki207880c2013-12-10 09:03:17 +020024#include <arch/acpi.h>
zbaoea71e812012-08-02 18:36:36 +080025#include <arch/io.h>
26#include <arch/stages.h>
27#include <device/pnp_def.h>
zbaoea71e812012-08-02 18:36:36 +080028#include <arch/cpu.h>
29#include <cpu/x86/lapic.h>
zbaoea71e812012-08-02 18:36:36 +080030#include <console/console.h>
31#include <console/loglevel.h>
Edward O'Callaghanbf9d1222014-10-29 09:26:00 +110032#include <cpu/amd/car.h>
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030033#include <northbridge/amd/agesa/agesawrapper.h>
zbaoea71e812012-08-02 18:36:36 +080034#include "cpu/x86/bist.h"
Kyösti Mälkkic66f1cb2013-08-12 16:09:00 +030035#include "cpu/x86/lapic.h"
zbaoea71e812012-08-02 18:36:36 +080036#include "southbridge/amd/agesa/hudson/hudson.h"
37#include "src/superio/smsc/lpc47n217/early_serial.c"
38#include "cpu/amd/agesa/s3_resume.h"
zbaoea71e812012-08-02 18:36:36 +080039#include "cbmem.h"
40
41#define SERIAL_DEV PNP_DEV(0x2e, LPC47N217_SP1)
42
zbaoea71e812012-08-02 18:36:36 +080043
44void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
45{
46 u32 val;
47 u8 byte;
Kyösti Mälkki88ff8b52014-11-21 17:40:37 +020048 pci_devfn_t dev;
49
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030050 agesawrapper_amdinitmmio();
zbaoea71e812012-08-02 18:36:36 +080051
Kyösti Mälkki88ff8b52014-11-21 17:40:37 +020052 /* Set LPC decode enables. */
53 dev = PCI_DEV(0, 0x14, 3);
54 pci_write_config32(dev, 0x44, 0xff03ffd5);
55
zbaoea71e812012-08-02 18:36:36 +080056 hudson_lpc_port80();
zbaoea71e812012-08-02 18:36:36 +080057 byte = pci_read_config8(dev, 0x48);
58 byte |= 3; /* 2e, 2f */
59 pci_write_config8(dev, 0x48, byte);
60
61 if (!cpu_init_detectedx && boot_cpu()) {
62 post_code(0x30);
63
64 post_code(0x31);
65 lpc47n217_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
66 outb(0x24, 0xcd6);
67 outb(0x1, 0xcd7);
68 outb(0xea, 0xcd6);
69 outb(0x1, 0xcd7);
70 *(u8 *)0xfed80101 = 0x98;
71 console_init();
72 }
73
74 /* Halt if there was a built in self test failure */
75 post_code(0x34);
76 report_bist_failure(bist);
77
78 /* Load MPB */
79 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +020080 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
81 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
zbaoea71e812012-08-02 18:36:36 +080082
83 post_code(0x37);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030084 agesawrapper_amdinitreset();
zbaoea71e812012-08-02 18:36:36 +080085 post_code(0x39);
86
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030087 agesawrapper_amdinitearly();
Kyösti Mälkkie1b468e2014-06-18 09:10:53 +030088 int s3resume = acpi_is_wakeup_early() && acpi_s3_resume_allowed();
89 if (!s3resume) {
zbaoea71e812012-08-02 18:36:36 +080090 post_code(0x40);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030091 agesawrapper_amdinitpost();
zbaoea71e812012-08-02 18:36:36 +080092 post_code(0x41);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030093 agesawrapper_amdinitenv();
zbaoea71e812012-08-02 18:36:36 +080094 disable_cache_as_ram();
zbaoea71e812012-08-02 18:36:36 +080095 } else { /* S3 detect */
96 printk(BIOS_INFO, "S3 detected\n");
97
98 post_code(0x60);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030099 agesawrapper_amdinitresume();
zbaoea71e812012-08-02 18:36:36 +0800100
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300101 agesawrapper_amdinitcpuio();
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300102 agesawrapper_amds3laterestore();
zbaoea71e812012-08-02 18:36:36 +0800103
104 post_code(0x61);
Kyösti Mälkki23b4f0c2014-06-18 09:55:26 +0300105 prepare_for_resume();
zbaoea71e812012-08-02 18:36:36 +0800106 }
zbaoea71e812012-08-02 18:36:36 +0800107
zbaoea71e812012-08-02 18:36:36 +0800108 post_code(0x50);
Stefan Reinauer648d1662013-05-06 18:05:39 -0700109 copy_and_run();
zbaoea71e812012-08-02 18:36:36 +0800110
111 post_code(0x54); /* Should never see this post code. */
112}