coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
romstage.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <soc/cnl_memcfg_init.h>
5 #include <soc/romstage.h>
6 #include <spd_bin.h>
7 #include <spd_cache.h>
8 #include "variant.h"
9 
10 void mainboard_memory_init_params(FSPM_UPD *memupd)
11 {
12  FSP_M_CONFIG *mem_cfg = &memupd->FspmConfig;
13 
14  struct cnl_mb_cfg memcfg = {
15 
16  /*
17  * Rcomp resistor values. These values represent the resistance in
18  * ohms of the three rcomp resistors attached to the DDR_COMP_0,
19  * DDR_COMP_1, and DDR_COMP_2 pins on the DRAM.
20  */
21  .rcomp_resistor = { 121, 81, 100 },
22 
23  /* Rcomp target values */
24  .rcomp_targets = { 100, 40, 20, 20, 26 },
25 
26  /*
27  * Indicates whether memory is interleaved.
28  * Set to 1 for an interleaved design,
29  * set to 0 for non-interleaved design.
30  */
31  .dq_pins_interleaved = 1,
32 
33  /*
34  * VREF_CA configuration.
35  * Set to 0 VREF_CA goes to both CH_A and CH_B,
36  * set to 1 VREF_CA goes to CH_A and VREF_DQ_A goes to CH_B,
37  * set to 2 VREF_CA goes to CH_A and VREF_DQ_B goes to CH_B.
38  */
39  .vref_ca_config = 2,
40 
41  /* Early Command Training */
42  .ect = 0,
43  };
44 
45 
46  /* Read spd block to get memory config */
47  struct spd_block blk = {
48  .addr_map = { 0x50, 0x52, },
49  };
50 
51  uint8_t *spd_cache;
52  size_t spd_cache_sz;
53  bool need_update_cache = false;
54  bool dimm_changed = true;
55 
56  /* load spd cache from RW_SPD_CACHE */
57  if (load_spd_cache(&spd_cache, &spd_cache_sz) == CB_SUCCESS) {
58  if (!spd_cache_is_valid(spd_cache, spd_cache_sz)) {
59  printk(BIOS_WARNING, "Invalid SPD cache\n");
60  } else {
61  dimm_changed = check_if_dimm_changed(spd_cache, &blk);
62  if (dimm_changed && memupd->FspmArchUpd.NvsBufferPtr != 0) {
63  /* Set mrc_cache as invalid */
64  printk(BIOS_INFO, "Set mrc_cache as invalid\n");
65  memupd->FspmArchUpd.NvsBufferPtr = 0;
66  }
67  }
68  need_update_cache = true;
69  }
70 
71  if (!dimm_changed) {
72  spd_fill_from_cache(spd_cache, &blk);
73  } else {
74  /* Access memory info through SMBUS. */
75  get_spd_smbus(&blk);
76 
77  if (need_update_cache && update_spd_cache(&blk) == CB_ERR)
78  printk(BIOS_WARNING, "update SPD cache failed\n");
79  }
80 
81  if (blk.spd_array[0] == NULL) {
83  } else {
87  (uintptr_t)blk.spd_array[0];
88  }
89 
91 
92  if (blk.spd_array[1] == NULL) {
94  } else {
98  (uintptr_t)blk.spd_array[1];
99  }
100 
102  dump_spd_info(&blk);
103 
104  cannonlake_memcfg_init(mem_cfg, &memcfg);
106 }
@ CB_ERR
Generic error code.
Definition: cb_err.h:17
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
void cannonlake_memcfg_init(FSP_M_CONFIG *mem_cfg, const struct cnl_mb_cfg *cnl_cfg)
@ NOT_EXISTING
@ READ_SPD_MEMPTR
#define printk(level,...)
Definition: stdlib.h:16
#define FSP_M_CONFIG
Definition: fsp_upd.h:8
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
void mainboard_memory_init_params(FSPM_UPD *mupd)
Definition: romstage.c:22
static const struct cnl_mb_cfg memcfg
Definition: romstage.c:6
__weak void variant_memory_init_params(MEMORY_INIT_UPD *memory_params)
Definition: romstage.c:18
void get_spd_smbus(struct spd_block *blk)
Definition: smbuslib.c:72
void dump_spd_info(struct spd_block *blk)
Definition: spd_bin.c:10
bool check_if_dimm_changed(u8 *spd_cache, struct spd_block *blk)
Definition: spd_cache.c:150
enum cb_err load_spd_cache(uint8_t **spd_cache, size_t *spd_cache_sz)
Definition: spd_cache.c:92
enum cb_err spd_fill_from_cache(uint8_t *spd_cache, struct spd_block *blk)
Definition: spd_cache.c:195
enum cb_err update_spd_cache(struct spd_block *blk)
Definition: spd_cache.c:35
bool spd_cache_is_valid(uint8_t *spd_cache, size_t spd_cache_sz)
Definition: spd_cache.c:117
#define NULL
Definition: stddef.h:19
unsigned long uintptr_t
Definition: stdint.h:21
unsigned char uint8_t
Definition: stdint.h:8
struct spd_info spd[NUM_DIMM_SLOT]
uint16_t rcomp_resistor[3]
Definition: ddr4.c:86
u8 addr_map[CONFIG_DIMM_MAX]
Definition: spd_bin.h:39
u8 * spd_array[CONFIG_DIMM_MAX]
Definition: spd_bin.h:40
uint16_t len
Definition: ddr4.c:89
uintptr_t spd_data_ptr
union spd_info::spd_data_by spd_spec
enum mem_info_read_type read_type
struct spd_by_pointer spd_data_ptr_info