coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
bootblock.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stdint.h>
4 #include <assert.h>
5 #include <console/console.h>
6 #include <cpu/x86/msr.h>
7 #include <cpu/amd/msr.h>
8 #include <cpu/x86/mtrr.h>
9 #include <smp/node.h>
10 #include <bootblock_common.h>
11 #include <amdblocks/agesawrapper.h>
14 #include <amdblocks/biosram.h>
15 #include <amdblocks/i2c.h>
16 #include <soc/pci_devs.h>
17 #include <soc/cpu.h>
18 #include <soc/southbridge.h>
19 #include <timestamp.h>
20 #include <halt.h>
21 
22 #include "chip.h"
23 
24 #if CONFIG_PI_AGESA_TEMP_RAM_BASE < 0x100000
25 #error "Error: CONFIG_PI_AGESA_TEMP_RAM_BASE must be >= 1MB"
26 #endif
27 #if CONFIG_PI_AGESA_CAR_HEAP_BASE < 0x100000
28 #error "Error: CONFIG_PI_AGESA_CAR_HEAP_BASE must be >= 1MB"
29 #endif
30 
31 /* Table to switch SCL pins to outputs to initially reset the I2C peripherals */
32 static const struct soc_i2c_scl_pin i2c_scl_pins[] = {
37 };
38 
39 /* Set the MMIO Configuration Base Address, Bus Range, and misc MTRRs. */
40 static void amd_initmmio(void)
41 {
42  msr_t mtrr_cap = rdmsr(MTRR_CAP_MSR);
43  int mtrr;
44 
45  /*
46  * todo: AGESA currently writes variable MTRRs. Once that is
47  * corrected, un-hardcode this MTRR.
48  *
49  * Be careful not to use get_free_var_mtrr/set_var_mtrr pairs
50  * where all cores execute the path. Both cores within a compute
51  * unit share MTRRs. Programming core0 has the appearance of
52  * modifying core1 too. Using the pair again will create
53  * duplicate copies.
54  */
55  mtrr = (mtrr_cap.lo & MTRR_CAP_VCNT) - SOC_EARLY_VMTRR_FLASH;
56  set_var_mtrr(mtrr, FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
57 
58  mtrr = (mtrr_cap.lo & MTRR_CAP_VCNT) - SOC_EARLY_VMTRR_CAR_HEAP;
59  set_var_mtrr(mtrr, CONFIG_PI_AGESA_CAR_HEAP_BASE,
60  CONFIG_PI_AGESA_HEAP_SIZE, MTRR_TYPE_WRBACK);
61 
62  mtrr = (mtrr_cap.lo & MTRR_CAP_VCNT) - SOC_EARLY_VMTRR_TEMPRAM;
63  set_var_mtrr(mtrr, CONFIG_PI_AGESA_TEMP_RAM_BASE,
64  CONFIG_PI_AGESA_HEAP_SIZE, MTRR_TYPE_UNCACHEABLE);
65 }
66 
67 static void reset_i2c_peripherals(void)
68 {
69  const struct soc_amd_stoneyridge_config *cfg = config_of_soc();
70  struct soc_i2c_peripheral_reset_info reset_info;
71 
73  reset_info.i2c_scl = i2c_scl_pins;
74  reset_info.num_pins = ARRAY_SIZE(i2c_scl_pins);
75  sb_reset_i2c_peripherals(&reset_info);
76 }
77 
79 {
81  amd_initmmio();
82  /*
83  * Call lib/bootblock.c main with BSP, shortcut for APs
84  */
85  if (!boot_cpu()) {
86  void (*ap_romstage_entry)(void) =
87  (void (*)(void))get_ap_entry_ptr();
88 
89  ap_romstage_entry(); /* execution does not return */
90  halt();
91  }
92 
93  /* TSC cannot be relied upon. Override the TSC value passed in. */
95 }
96 
98 {
99  /*
100  * This call (sb_reset_i2c_peripherals) was originally early at
101  * bootblock_c_entry, but had to be moved here. There was an
102  * unexplained delay in the middle of the i2c transaction when
103  * we had it in bootblock_c_entry. Moving it to this point
104  * (or adding delays) fixes the issue. It seems like the processor
105  * just pauses but we don't know why.
106  */
109  post_code(0x90);
110 }
111 
113 {
114  if (CONFIG(AMD_SOC_CONSOLE_UART))
115  assert(CONFIG_UART_FOR_CONSOLE >= 0
116  && CONFIG_UART_FOR_CONSOLE <= 1);
117 
118  u32 val = cpuid_eax(1);
119  printk(BIOS_DEBUG, "Family_Model: %08x\n", val);
120 
122 
123  /* Initialize any early i2c buses. */
125 }
void enable_pci_mmconf(void)
Definition: amd_pci_mmconf.c:8
#define asmlinkage
Definition: cpu.h:8
#define FLASH_BASE_ADDR
Definition: io.h:13
static unsigned int cpuid_eax(unsigned int op)
Definition: cpu.h:79
#define assert(statement)
Definition: assert.h:74
void * get_ap_entry_ptr(void)
Definition: biosram.c:51
#define ARRAY_SIZE(a)
Definition: helpers.h:12
int boot_cpu(void)
Definition: psp.c:5
#define printk(level,...)
Definition: stdlib.h:16
void bootblock_soc_early_init(void)
Definition: bootblock.c:20
void bootblock_soc_init(void)
Definition: bootblock.c:27
asmlinkage void bootblock_c_entry(uint64_t base_timestamp)
Definition: bootblock.c:26
@ CONFIG
Definition: dsi_common.h:201
void __noreturn halt(void)
halt the system reliably
Definition: halt.c:6
static __always_inline msr_t rdmsr(unsigned int index)
Definition: msr.h:146
#define config_of_soc()
Definition: device.h:394
void bootblock_main_with_basetime(uint64_t base_timestamp)
Definition: bootblock.c:71
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
void set_var_mtrr(unsigned int reg, unsigned int base, unsigned int size, unsigned int type)
Definition: mtrrlib.c:30
#define post_code(value)
Definition: post_code.h:12
#define I2C0_SCL_PIN
Definition: i2c.h:16
#define GPIO_I2C0_SCL
Definition: i2c.h:9
#define GPIO_I2C1_SCL
Definition: i2c.h:10
#define GPIO_I2C2_SCL
Definition: i2c.h:11
#define GPIO_I2C3_SCL
Definition: i2c.h:12
#define GPIO_I2C_MASK
Definition: i2c.h:13
#define I2C2_SCL_PIN
Definition: i2c.h:18
#define I2C3_SCL_PIN
Definition: i2c.h:19
#define I2C1_SCL_PIN
Definition: i2c.h:17
void sb_reset_i2c_peripherals(const struct soc_i2c_peripheral_reset_info *reset_info)
Definition: i2c.c:148
void i2c_soc_early_init(void)
Definition: i2c.c:108
#define I2C_RESET_SCL_PIN(pin_name, pin_mask_value)
Definition: i2c.h:39
static const struct soc_i2c_scl_pin i2c_scl_pins[]
Definition: bootblock.c:32
static void reset_i2c_peripherals(void)
Definition: bootblock.c:67
static void amd_initmmio(void)
Definition: bootblock.c:40
#define SOC_EARLY_VMTRR_FLASH
Definition: cpu.h:13
#define SOC_EARLY_VMTRR_CAR_HEAP
Definition: cpu.h:14
#define SOC_EARLY_VMTRR_TEMPRAM
Definition: cpu.h:15
uint32_t u32
Definition: stdint.h:51
unsigned long long uint64_t
Definition: stdint.h:17
void bootblock_fch_init(void)
Definition: early_fch.c:145
void bootblock_fch_early_init(void)
Definition: early_fch.c:114
unsigned int lo
Definition: msr.h:111
Information about I2C peripherals that need to be reset.
Definition: i2c.h:53
const struct soc_i2c_scl_pin * i2c_scl
Definition: i2c.h:55
uint8_t i2c_scl_reset_mask
Definition: i2c.h:54
Data structure to identify GPIO to be toggled to reset peripherals on an I2C bus.
Definition: i2c.h:33
u8 val
Definition: sys.c:300
#define timestamp_get()
Workaround for guard combination above.
Definition: timestamp.h:52
#define MTRR_TYPE_WRPROT
Definition: mtrr.h:13
#define MTRR_CAP_VCNT
Definition: mtrr.h:23
#define MTRR_CAP_MSR
Definition: mtrr.h:17
#define MTRR_TYPE_UNCACHEABLE
Definition: mtrr.h:10
#define MTRR_TYPE_WRBACK
Definition: mtrr.h:14
typedef void(X86APIP X86EMU_intrFuncs)(int num)