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 <hwilib.h>
5 #include <string.h>
6 #include <soc/meminit.h>
7 #include <soc/romstage.h>
8 #include <fsp/api.h>
9 #include <FspmUpd.h>
10 #include <baseboard/variants.h>
11 
12 void mainboard_memory_init_params(FSPM_UPD *memupd)
13 {
14  const struct lpddr4_swizzle_cfg *cfg;
15  const struct lpddr4_chan_swizzle_cfg *chan;
16  uint8_t spd[0x80];
17 
18  /*
19  * Get DRAM configuration data from hwinfo block.
20  * The configuration data from hwinfo block is a one-to-one
21  * representation of the FSPM_UPD data starting with parameter
22  * 'Package' (offset 0x4d) and ending before parameter
23  * 'Ch0_Bit_swizzling' (offset 0x88).
24  */
25  if (hwilib_find_blocks("hwinfo.hex")) {
27  "HWInfo not found, use default values for FSP-M.\n");
28  return;
29  }
30 
31  if (hwilib_get_field(SPD, spd, sizeof(spd)) != sizeof(spd)) {
33  "SPD not found in HWInfo, use defaults for FSP-M.\n");
34  return;
35  }
36 
37  memcpy(&memupd->FspmConfig.Package, &spd,
38  (((uint8_t *)memupd->FspmConfig.Ch0_Bit_swizzling)-
39  (&memupd->FspmConfig.Package)));
40 
41  /*
42  * Some of the mc_apl1 boards use LPDDR4 memory. In this case, the
43  * correct swizzle configuration is necessary. The default settings
44  * for swizzling are 0, since the baseboard does not use LPDDR4 memory.
45  */
47 
48  /*
49  * CH0_DQB byte lanes in the bit swizzle configuration field are
50  * not 1:1. The mapping within the swizzling field is:
51  * indices [0:7] - byte lane 1 (DQS1) DQ[8:15]
52  * indices [8:15] - byte lane 0 (DQS0) DQ[0:7]
53  * indices [16:23] - byte lane 3 (DQS3) DQ[24:31]
54  * indices [24:31] - byte lane 2 (DQS2) DQ[16:23]
55  */
56  chan = &cfg->phys[LP4_PHYS_CH0B];
57  memcpy(&memupd->FspmConfig.Ch0_Bit_swizzling[0], &chan->dqs[LP4_DQS1],
58  (size_t)DQ_BITS_PER_DQS);
59  memcpy(&memupd->FspmConfig.Ch0_Bit_swizzling[8], &chan->dqs[LP4_DQS0],
60  (size_t)DQ_BITS_PER_DQS);
61  memcpy(&memupd->FspmConfig.Ch0_Bit_swizzling[16], &chan->dqs[LP4_DQS3],
62  (size_t)DQ_BITS_PER_DQS);
63  memcpy(&memupd->FspmConfig.Ch0_Bit_swizzling[24], &chan->dqs[LP4_DQS2],
64  (size_t)DQ_BITS_PER_DQS);
65 
66  /* CH0_DQA byte lanes in the bit swizzle configuration field are 1:1. */
67  chan = &cfg->phys[LP4_PHYS_CH0A];
68  memcpy(&memupd->FspmConfig.Ch1_Bit_swizzling[0], &chan->dqs[LP4_DQS0],
69  (size_t)DQ_BITS_PER_DQS);
70  memcpy(&memupd->FspmConfig.Ch1_Bit_swizzling[8], &chan->dqs[LP4_DQS1],
71  (size_t)DQ_BITS_PER_DQS);
72  memcpy(&memupd->FspmConfig.Ch1_Bit_swizzling[16], &chan->dqs[LP4_DQS2],
73  (size_t)DQ_BITS_PER_DQS);
74  memcpy(&memupd->FspmConfig.Ch1_Bit_swizzling[24], &chan->dqs[LP4_DQS3],
75  (size_t)DQ_BITS_PER_DQS);
76 
77  /*
78  * CH1_DQB byte lanes in the bit swizzle configuration field are
79  * not 1:1. The mapping within the swizzling field is:
80  * indices [0:7] - byte lane 1 (DQS1) DQ[8:15]
81  * indices [8:15] - byte lane 0 (DQS0) DQ[0:7]
82  * indices [16:23] - byte lane 3 (DQS3) DQ[24:31]
83  * indices [24:31] - byte lane 2 (DQS2) DQ[16:23]
84  */
85  chan = &cfg->phys[LP4_PHYS_CH1B];
86  memcpy(&memupd->FspmConfig.Ch2_Bit_swizzling[0], &chan->dqs[LP4_DQS1],
87  (size_t)DQ_BITS_PER_DQS);
88  memcpy(&memupd->FspmConfig.Ch2_Bit_swizzling[8], &chan->dqs[LP4_DQS0],
89  (size_t)DQ_BITS_PER_DQS);
90  memcpy(&memupd->FspmConfig.Ch2_Bit_swizzling[16], &chan->dqs[LP4_DQS3],
91  (size_t)DQ_BITS_PER_DQS);
92  memcpy(&memupd->FspmConfig.Ch2_Bit_swizzling[24], &chan->dqs[LP4_DQS2],
93  (size_t)DQ_BITS_PER_DQS);
94 
95  /* CH1_DQA byte lanes in the bit swizzle configuration field are 1:1. */
96  chan = &cfg->phys[LP4_PHYS_CH1A];
97  memcpy(&memupd->FspmConfig.Ch3_Bit_swizzling[0], &chan->dqs[LP4_DQS0],
98  (size_t)DQ_BITS_PER_DQS);
99  memcpy(&memupd->FspmConfig.Ch3_Bit_swizzling[8], &chan->dqs[LP4_DQS1],
100  (size_t)DQ_BITS_PER_DQS);
101  memcpy(&memupd->FspmConfig.Ch3_Bit_swizzling[16], &chan->dqs[LP4_DQS2],
102  (size_t)DQ_BITS_PER_DQS);
103  memcpy(&memupd->FspmConfig.Ch3_Bit_swizzling[24], &chan->dqs[LP4_DQS3],
104  (size_t)DQ_BITS_PER_DQS);
105 
106  memupd->FspmConfig.MsgLevelMask = 0x0;
107  memupd->FspmConfig.MrcDataSaving = 0x0;
108  memupd->FspmConfig.MrcFastBoot = 0x1;
109 }
@ LP4_PHYS_CH0B
Definition: meminit.h:19
@ LP4_PHYS_CH0A
Definition: meminit.h:18
@ LP4_PHYS_CH1A
Definition: meminit.h:20
@ LP4_PHYS_CH1B
Definition: meminit.h:21
@ LP4_DQS3
Definition: meminit.h:40
@ LP4_DQS1
Definition: meminit.h:38
@ LP4_DQS0
Definition: meminit.h:37
@ DQ_BITS_PER_DQS
Definition: meminit.h:42
@ LP4_DQS2
Definition: meminit.h:39
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
#define printk(level,...)
Definition: stdlib.h:16
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
void mainboard_memory_init_params(FSPM_UPD *mupd)
Definition: romstage.c:22
const struct lpddr4_swizzle_cfg * variant_lpddr4_swizzle_config(void)
Definition: memory.c:51
unsigned char uint8_t
Definition: stdint.h:8
uint8_t dqs[LP4_NUM_BYTE_LANES][DQ_BITS_PER_DQS]
Definition: meminit.h:78
struct lpddr4_chan_swizzle_cfg phys[LP4_NUM_PHYS_CHANNELS]
Definition: meminit.h:82