blob: a1ddb5ce6d3049c9d5938232b5e25c9bb8473c8b [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones24484842017-05-04 21:17:45 -06002
3#include <stdint.h>
Marshall Dawsona5f225f2017-08-18 10:07:07 -06004#include <assert.h>
Marshall Dawson9df969a2017-07-25 18:46:46 -06005#include <console/console.h>
Marshall Dawson154239a2017-11-02 09:49:30 -06006#include <cpu/x86/msr.h>
7#include <cpu/x86/mtrr.h>
Marshall Dawson9df969a2017-07-25 18:46:46 -06008#include <smp/node.h>
9#include <bootblock_common.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070010#include <amdblocks/agesawrapper.h>
11#include <amdblocks/agesawrapper_call.h>
Michał Żygowski200d2132019-12-06 12:07:52 +010012#include <amdblocks/amd_pci_mmconf.h>
Michał Żygowski5a662022019-12-02 17:02:00 +010013#include <amdblocks/biosram.h>
Felix Held199b10f2022-08-13 00:29:23 +020014#include <amdblocks/iomap.h>
Martin Roth81804272022-11-20 20:30:18 -070015#include <amdblocks/post_codes.h>
Marshall Dawsonf5e057c2017-10-12 16:10:14 -060016#include <soc/pci_devs.h>
Marshall Dawsond85c4af2018-03-28 19:48:42 -060017#include <soc/cpu.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060018#include <soc/southbridge.h>
Aaron Durbin51e4c1a2018-01-24 17:42:51 -070019#include <timestamp.h>
Richard Spiegel6d61db02018-04-04 10:35:21 -070020#include <halt.h>
Marc Jones24484842017-05-04 21:17:45 -060021
Marshall Dawsonc4be1752018-05-07 09:59:10 -060022#if CONFIG_PI_AGESA_TEMP_RAM_BASE < 0x100000
23#error "Error: CONFIG_PI_AGESA_TEMP_RAM_BASE must be >= 1MB"
24#endif
25#if CONFIG_PI_AGESA_CAR_HEAP_BASE < 0x100000
26#error "Error: CONFIG_PI_AGESA_CAR_HEAP_BASE must be >= 1MB"
27#endif
28
29/* Set the MMIO Configuration Base Address, Bus Range, and misc MTRRs. */
Marshall Dawson154239a2017-11-02 09:49:30 -060030static void amd_initmmio(void)
31{
Marshall Dawson154239a2017-11-02 09:49:30 -060032 msr_t mtrr_cap = rdmsr(MTRR_CAP_MSR);
33 int mtrr;
34
Marshall Dawson154239a2017-11-02 09:49:30 -060035 /*
36 * todo: AGESA currently writes variable MTRRs. Once that is
37 * corrected, un-hardcode this MTRR.
Marshall Dawsonc4be1752018-05-07 09:59:10 -060038 *
39 * Be careful not to use get_free_var_mtrr/set_var_mtrr pairs
40 * where all cores execute the path. Both cores within a compute
41 * unit share MTRRs. Programming core0 has the appearance of
42 * modifying core1 too. Using the pair again will create
43 * duplicate copies.
Marshall Dawson154239a2017-11-02 09:49:30 -060044 */
Marshall Dawsond85c4af2018-03-28 19:48:42 -060045 mtrr = (mtrr_cap.lo & MTRR_CAP_VCNT) - SOC_EARLY_VMTRR_FLASH;
Felix Held199b10f2022-08-13 00:29:23 +020046 set_var_mtrr(mtrr, FLASH_BELOW_4GB_MAPPING_REGION_BASE,
47 FLASH_BELOW_4GB_MAPPING_REGION_SIZE, MTRR_TYPE_WRPROT);
Marshall Dawsonc4be1752018-05-07 09:59:10 -060048
49 mtrr = (mtrr_cap.lo & MTRR_CAP_VCNT) - SOC_EARLY_VMTRR_CAR_HEAP;
50 set_var_mtrr(mtrr, CONFIG_PI_AGESA_CAR_HEAP_BASE,
51 CONFIG_PI_AGESA_HEAP_SIZE, MTRR_TYPE_WRBACK);
52
53 mtrr = (mtrr_cap.lo & MTRR_CAP_VCNT) - SOC_EARLY_VMTRR_TEMPRAM;
54 set_var_mtrr(mtrr, CONFIG_PI_AGESA_TEMP_RAM_BASE,
55 CONFIG_PI_AGESA_HEAP_SIZE, MTRR_TYPE_UNCACHEABLE);
Marshall Dawson154239a2017-11-02 09:49:30 -060056}
57
Richard Spiegel6d61db02018-04-04 10:35:21 -070058asmlinkage void bootblock_c_entry(uint64_t base_timestamp)
Marc Jones24484842017-05-04 21:17:45 -060059{
Michał Żygowski200d2132019-12-06 12:07:52 +010060 enable_pci_mmconf();
Marshall Dawson9df969a2017-07-25 18:46:46 -060061 amd_initmmio();
Richard Spiegel6d61db02018-04-04 10:35:21 -070062 /*
63 * Call lib/bootblock.c main with BSP, shortcut for APs
64 */
65 if (!boot_cpu()) {
66 void (*ap_romstage_entry)(void) =
67 (void (*)(void))get_ap_entry_ptr();
Marshall Dawson9df969a2017-07-25 18:46:46 -060068
Richard Spiegel6d61db02018-04-04 10:35:21 -070069 ap_romstage_entry(); /* execution does not return */
70 halt();
71 }
Marshall Dawson9df969a2017-07-25 18:46:46 -060072
Richard Spiegel6d61db02018-04-04 10:35:21 -070073 /* TSC cannot be relied upon. Override the TSC value passed in. */
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030074 bootblock_main_with_basetime(timestamp_get());
Richard Spiegel6d61db02018-04-04 10:35:21 -070075}
76
77void bootblock_soc_early_init(void)
78{
Felix Held8db77d72021-08-30 18:20:34 +020079 bootblock_fch_early_init();
Yuchen He1e67adb2023-07-25 21:28:36 +020080 post_code(POSTCODE_BOOTBLOCK_SOC_EARLY_INIT);
Felix Held8db77d72021-08-30 18:20:34 +020081}
82
83void bootblock_soc_init(void)
84{
Felix Held91ef9252021-01-12 23:44:05 +010085 if (CONFIG(AMD_SOC_CONSOLE_UART))
Marshall Dawsona5f225f2017-08-18 10:07:07 -060086 assert(CONFIG_UART_FOR_CONSOLE >= 0
87 && CONFIG_UART_FOR_CONSOLE <= 1);
88
Marshall Dawson9df969a2017-07-25 18:46:46 -060089 u32 val = cpuid_eax(1);
90 printk(BIOS_DEBUG, "Family_Model: %08x\n", val);
91
Raul E Rangeld820f4b82018-08-13 10:39:03 -060092 bootblock_fch_init();
Marc Jones24484842017-05-04 21:17:45 -060093}