Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [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 |
Zheng Bao | 7797ffa | 2013-11-20 15:09:23 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <string.h> |
| 22 | #include <device/pci_def.h> |
| 23 | #include <device/pci_ids.h> |
Kyösti Mälkki | 207880c | 2013-12-10 09:03:17 +0200 | [diff] [blame] | 24 | #include <arch/acpi.h> |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 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> |
Edward O'Callaghan | bf9d122 | 2014-10-29 09:26:00 +1100 | [diff] [blame^] | 32 | #include <cpu/amd/car.h> |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 33 | #include "agesawrapper.h" |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 34 | #include <northbridge/amd/agesa/agesawrapper_call.h> |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 35 | #include "cpu/x86/bist.h" |
Kyösti Mälkki | c66f1cb | 2013-08-12 16:09:00 +0300 | [diff] [blame] | 36 | #include "cpu/x86/lapic.h" |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 37 | #include "southbridge/amd/agesa/hudson/hudson.h" |
| 38 | #include "cpu/amd/agesa/s3_resume.h" |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 39 | #include "cbmem.h" |
| 40 | |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 41 | |
| 42 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
| 43 | { |
| 44 | u32 val; |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 45 | |
| 46 | /* In Hudson RRG, PMIOxD2[5:4] is "Drive strength control for |
| 47 | * LpcClk[1:0]". To be consistent with Parmer, setting to 4mA |
| 48 | * even though the register is not documented in the Kabini BKDG. |
| 49 | * Otherwise the serial output is bad code. |
| 50 | */ |
| 51 | outb(0xD2, 0xcd6); |
| 52 | outb(0x00, 0xcd7); |
| 53 | |
Kyösti Mälkki | 30fbb4c | 2014-10-20 07:04:55 +0300 | [diff] [blame] | 54 | AGESAWRAPPER_PRE_CONSOLE(amdinitmmio); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 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); |
Elyes HAOUAS | aedcc10 | 2014-07-21 08:07:19 +0200 | [diff] [blame] | 71 | printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val); |
| 72 | printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 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); |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 80 | AGESAWRAPPER(amdinitreset); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 81 | post_code(0x38); |
Bruce Griffith | 4e08a95 | 2013-07-07 02:04:16 -0600 | [diff] [blame] | 82 | printk(BIOS_DEBUG, "Got past yangtze_early_setup\n"); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 83 | |
| 84 | post_code(0x39); |
| 85 | |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 86 | AGESAWRAPPER(amdinitearly); |
Kyösti Mälkki | e1b468e | 2014-06-18 09:10:53 +0300 | [diff] [blame] | 87 | int s3resume = acpi_is_wakeup_early() && acpi_s3_resume_allowed(); |
| 88 | if (!s3resume) { |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 89 | post_code(0x40); |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 90 | AGESAWRAPPER(amdinitpost); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 91 | post_code(0x41); |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 92 | AGESAWRAPPER(amdinitenv); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 93 | /* TODO: Disable cache is not ok. */ |
| 94 | disable_cache_as_ram(); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 95 | } else { /* S3 detect */ |
| 96 | printk(BIOS_INFO, "S3 detected\n"); |
| 97 | |
| 98 | post_code(0x60); |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 99 | AGESAWRAPPER(amdinitresume); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 100 | |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 101 | AGESAWRAPPER(amds3laterestore); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 102 | |
| 103 | post_code(0x61); |
Kyösti Mälkki | 23b4f0c | 2014-06-18 09:55:26 +0300 | [diff] [blame] | 104 | prepare_for_resume(); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 105 | } |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 106 | |
| 107 | outb(0xEA, 0xCD6); |
| 108 | outb(0x1, 0xcd7); |
Siyuan Wang | 80cf7d5 | 2013-07-09 17:42:43 +0800 | [diff] [blame] | 109 | |
| 110 | post_code(0x50); |
| 111 | copy_and_run(); |
| 112 | |
| 113 | post_code(0x54); /* Should never see this post code. */ |
| 114 | } |