zbao | ea71e81 | 2012-08-02 18:36:36 +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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
zbao | ea71e81 | 2012-08-02 18:36:36 +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> |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 25 | #include <arch/io.h> |
| 26 | #include <arch/stages.h> |
| 27 | #include <device/pnp_def.h> |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 28 | #include <arch/cpu.h> |
| 29 | #include <cpu/x86/lapic.h> |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 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> |
Kyösti Mälkki | f21c2ac | 2014-10-19 09:35:18 +0300 | [diff] [blame] | 33 | #include <northbridge/amd/agesa/agesawrapper.h> |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 34 | #include "cpu/x86/bist.h" |
Kyösti Mälkki | c66f1cb | 2013-08-12 16:09:00 +0300 | [diff] [blame] | 35 | #include "cpu/x86/lapic.h" |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 36 | #include "southbridge/amd/agesa/hudson/hudson.h" |
| 37 | #include "src/superio/smsc/lpc47n217/early_serial.c" |
| 38 | #include "cpu/amd/agesa/s3_resume.h" |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 39 | #include "cbmem.h" |
| 40 | |
| 41 | #define SERIAL_DEV PNP_DEV(0x2e, LPC47N217_SP1) |
| 42 | |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 43 | |
| 44 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
| 45 | { |
| 46 | u32 val; |
| 47 | u8 byte; |
Kyösti Mälkki | 88ff8b5 | 2014-11-21 17:40:37 +0200 | [diff] [blame] | 48 | pci_devfn_t dev; |
| 49 | |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame^] | 50 | agesawrapper_amdinitmmio(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 51 | |
Kyösti Mälkki | 88ff8b5 | 2014-11-21 17:40:37 +0200 | [diff] [blame] | 52 | /* Set LPC decode enables. */ |
| 53 | dev = PCI_DEV(0, 0x14, 3); |
| 54 | pci_write_config32(dev, 0x44, 0xff03ffd5); |
| 55 | |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 56 | hudson_lpc_port80(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 57 | 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 HAOUAS | aedcc10 | 2014-07-21 08:07:19 +0200 | [diff] [blame] | 80 | printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val); |
| 81 | printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 82 | |
| 83 | post_code(0x37); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame^] | 84 | agesawrapper_amdinitreset(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 85 | post_code(0x39); |
| 86 | |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame^] | 87 | agesawrapper_amdinitearly(); |
Kyösti Mälkki | e1b468e | 2014-06-18 09:10:53 +0300 | [diff] [blame] | 88 | int s3resume = acpi_is_wakeup_early() && acpi_s3_resume_allowed(); |
| 89 | if (!s3resume) { |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 90 | post_code(0x40); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame^] | 91 | agesawrapper_amdinitpost(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 92 | post_code(0x41); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame^] | 93 | agesawrapper_amdinitenv(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 94 | disable_cache_as_ram(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 95 | } else { /* S3 detect */ |
| 96 | printk(BIOS_INFO, "S3 detected\n"); |
| 97 | |
| 98 | post_code(0x60); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame^] | 99 | agesawrapper_amdinitresume(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 100 | |
Kyösti Mälkki | b139b5e | 2014-10-20 07:41:20 +0300 | [diff] [blame] | 101 | agesawrapper_amdinitcpuio(); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame^] | 102 | agesawrapper_amds3laterestore(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 103 | |
| 104 | post_code(0x61); |
Kyösti Mälkki | 23b4f0c | 2014-06-18 09:55:26 +0300 | [diff] [blame] | 105 | prepare_for_resume(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 106 | } |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 107 | |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 108 | post_code(0x50); |
Stefan Reinauer | 648d166 | 2013-05-06 18:05:39 -0700 | [diff] [blame] | 109 | copy_and_run(); |
zbao | ea71e81 | 2012-08-02 18:36:36 +0800 | [diff] [blame] | 110 | |
| 111 | post_code(0x54); /* Should never see this post code. */ |
| 112 | } |