coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spd_util.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #include <cbfs.h>
3 #include <console/console.h>
4 #include <stdint.h>
5 #include <string.h>
6 #include "boardid.h"
7 #include "spd.h"
8 
9 void mainboard_fill_dq_map_data(void *dq_map_ch0, void *dq_map_ch1)
10 {
11  /* DQ byte map */
12  const u8 dq_map[2][12] = {
13  { 0x0F, 0xF0, 0x00, 0xF0, 0x0F, 0xF0,
14  0x0F, 0x00, 0xFF, 0x00, 0xFF, 0x00 },
15  { 0x0F, 0xF0, 0x00, 0xF0, 0x0F, 0xF0,
16  0x0F, 0x00, 0xFF, 0x00, 0xFF, 0x00 } };
17  memcpy(dq_map_ch0, dq_map[0], sizeof(dq_map[0]));
18  memcpy(dq_map_ch1, dq_map[1], sizeof(dq_map[1]));
19 }
20 
21 void mainboard_fill_dqs_map_data(void *dqs_map_ch0, void *dqs_map_ch1)
22 {
23  /* DQS CPU<>DRAM map */
24  const u8 dqs_map[2][8] = {
25  { 0, 1, 3, 2, 6, 5, 4, 7 },
26  { 2, 3, 0, 1, 6, 7, 4, 5 } };
27  memcpy(dqs_map_ch0, dqs_map[0], sizeof(dqs_map[0]));
28  memcpy(dqs_map_ch1, dqs_map[1], sizeof(dqs_map[1]));
29 }
30 
31 void mainboard_fill_rcomp_res_data(void *rcomp_ptr)
32 {
33  /* Rcomp resistor */
34  const u16 RcompResistor[3] = { 200, 81, 162 };
35  memcpy(rcomp_ptr, RcompResistor,
36  sizeof(RcompResistor));
37 }
38 
39 void mainboard_fill_rcomp_strength_data(void *rcomp_strength_ptr)
40 {
41  int mem_cfg_id;
42 
43  mem_cfg_id = get_spd_index();
44  /* Rcomp target */
45  static const u16 RcompTarget[5] = {
46  100, 40, 40, 23, 40 };
47 
48  /* Strengthen the Rcomp Target Ctrl for 8GB K4E6E304EE -EGCF */
49  static const u16 StrengthendRcompTarget[5] = {
50  100, 40, 40, 21, 40 };
51 
52  if (mem_cfg_id == K4E6E304EE_MEM_ID) {
53  memcpy(rcomp_strength_ptr, StrengthendRcompTarget,
54  sizeof(StrengthendRcompTarget));
55  } else {
56  memcpy(rcomp_strength_ptr, RcompTarget, sizeof(RcompTarget));
57  }
58 
59 }
60 
62 {
63  char *spd_file;
64  int spd_index, spd_span;
65  size_t spd_file_len;
66 
68  printk(BIOS_INFO, "SPD index %d\n", spd_index);
69 
70  /* Load SPD data from CBFS */
71  spd_file = cbfs_map("spd.bin", &spd_file_len);
72  if (!spd_file)
73  die("SPD data not found.");
74 
75  /* make sure we have at least one SPD in the file. */
76  if (spd_file_len < SPD_LEN)
77  die("Missing SPD data.");
78 
79  /* Make sure we did not overrun the buffer */
80  if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
81  printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
82  spd_index = 0;
83  }
84 
85  spd_span = spd_index * SPD_LEN;
86  return (uintptr_t)(spd_file + spd_span);
87 }
88 
90 {
91  int spd_index;
92 
94 
96  && spd_index != MIC_SINGLE_CHAN) {
98  "Dual channel SPD detected writing second channel\n");
99  return 1;
100  }
101  return 0;
102 }
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
static void * cbfs_map(const char *name, size_t *size_out)
Definition: cbfs.h:246
#define printk(level,...)
Definition: stdlib.h:16
void __noreturn die(const char *fmt,...)
Definition: die.c:17
void mainboard_fill_dq_map_data(void *dq_map_ptr)
Definition: spd_util.c:8
void mainboard_fill_dqs_map_data(void *dqs_map_ptr)
Definition: spd_util.c:19
void mainboard_fill_rcomp_res_data(void *rcomp_ptr)
Definition: spd_util.c:28
void mainboard_fill_rcomp_strength_data(void *rcomp_strength_ptr)
Definition: spd_util.c:36
#define K4E6E304EE_MEM_ID
Definition: variant.c:8
static uint8_t get_spd_index(void)
Definition: spd_util.c:37
uintptr_t mainboard_get_spd_data(void)
Definition: spd_util.c:61
int mainboard_has_dual_channel_mem(void)
Definition: spd_util.c:89
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define SPD_LEN
Definition: spd.c:22
static const int spd_index[32]
Definition: memory.c:10
static const u8 dqs_map[][8]
Definition: memory.c:17
static const u8 dq_map[][12]
Definition: memory.c:9
#define MIC_SINGLE_CHAN
Definition: spd.h:26
#define SAMSUNG_SINGLE_CHAN
Definition: spd.h:25
#define HYNIX_SINGLE_CHAN
Definition: spd.h:24
unsigned long uintptr_t
Definition: stdint.h:21
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45