Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 1 | /* |
| 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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <string.h> |
| 22 | #include <device/pci_def.h> |
| 23 | #include <device/pci_ids.h> |
| 24 | #include <arch/acpi.h> |
| 25 | #include <arch/io.h> |
| 26 | #include <arch/stages.h> |
| 27 | #include <device/pnp_def.h> |
| 28 | #include <arch/cpu.h> |
| 29 | #include <cpu/x86/lapic.h> |
| 30 | #include <console/console.h> |
| 31 | #include <console/loglevel.h> |
| 32 | #include <cpu/amd/car.h> |
| 33 | #include <northbridge/amd/agesa/agesawrapper.h> |
Edward O'Callaghan | 77757c2 | 2015-01-04 21:33:39 +1100 | [diff] [blame] | 34 | #include <cpu/x86/bist.h> |
| 35 | #include <cpu/x86/lapic.h> |
| 36 | #include <southbridge/amd/agesa/hudson/hudson.h> |
| 37 | #include <cpu/amd/agesa/s3_resume.h> |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 38 | #include "cbmem.h" |
| 39 | |
| 40 | |
| 41 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
| 42 | { |
| 43 | u32 val; |
| 44 | |
| 45 | /* In Hudson RRG, PMIOxD2[5:4] is "Drive strength control for |
| 46 | * LpcClk[1:0]". To be consistent with Parmer, setting to 4mA |
| 47 | * even though the register is not documented in the Kabini BKDG. |
| 48 | * Otherwise the serial output is bad code. |
| 49 | */ |
| 50 | outb(0xD2, 0xcd6); |
| 51 | outb(0x00, 0xcd7); |
| 52 | |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 53 | amd_initmmio(); |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 54 | |
| 55 | /* Set LPC decode enables. */ |
| 56 | pci_devfn_t dev = PCI_DEV(0, 0x14, 3); |
| 57 | pci_write_config32(dev, 0x44, 0xff03ffd5); |
| 58 | |
| 59 | hudson_lpc_port80(); |
| 60 | |
| 61 | if (!cpu_init_detectedx && boot_cpu()) { |
| 62 | post_code(0x30); |
| 63 | |
| 64 | post_code(0x31); |
| 65 | console_init(); |
| 66 | } |
| 67 | |
| 68 | /* Halt if there was a built in self test failure */ |
| 69 | post_code(0x34); |
| 70 | report_bist_failure(bist); |
| 71 | |
| 72 | /* Load MPB */ |
| 73 | val = cpuid_eax(1); |
| 74 | printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val); |
| 75 | printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx); |
| 76 | |
| 77 | /* On Larne, after LpcClkDrvSth is set, it needs some time to be stable, because of the buffer ICS551M */ |
| 78 | int i; |
| 79 | for(i = 0; i < 200000; i++) |
| 80 | val = inb(0xcd6); |
| 81 | |
| 82 | post_code(0x37); |
| 83 | agesawrapper_amdinitreset(); |
| 84 | post_code(0x38); |
| 85 | printk(BIOS_DEBUG, "Got past yangtze_early_setup\n"); |
| 86 | |
| 87 | post_code(0x39); |
| 88 | |
| 89 | agesawrapper_amdinitearly(); |
Kyösti Mälkki | 78c5d58 | 2015-01-09 23:48:47 +0200 | [diff] [blame^] | 90 | int s3resume = acpi_is_wakeup_s3(); |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 91 | if (!s3resume) { |
| 92 | post_code(0x40); |
| 93 | agesawrapper_amdinitpost(); |
| 94 | post_code(0x41); |
| 95 | agesawrapper_amdinitenv(); |
| 96 | /* TODO: Disable cache is not ok. */ |
| 97 | disable_cache_as_ram(); |
| 98 | } else { /* S3 detect */ |
| 99 | printk(BIOS_INFO, "S3 detected\n"); |
| 100 | |
| 101 | post_code(0x60); |
| 102 | agesawrapper_amdinitresume(); |
| 103 | |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 104 | amd_initcpuio(); |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 105 | agesawrapper_amds3laterestore(); |
| 106 | |
| 107 | post_code(0x61); |
| 108 | prepare_for_resume(); |
| 109 | } |
| 110 | |
| 111 | outb(0xEA, 0xCD6); |
| 112 | outb(0x1, 0xcd7); |
| 113 | |
| 114 | post_code(0x50); |
| 115 | copy_and_run(); |
| 116 | |
| 117 | post_code(0x54); /* Should never see this post code. */ |
| 118 | } |