• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <cbfs.h>
4 #include <console/console.h>
5 #include <device/dram/ddr4.h>
6 #include <spd.h>
7 
8 #include "spd.h"
9 
10 /* Get SPD data for on-board memory */
mainboard_find_spd_data(void)11 uint8_t *mainboard_find_spd_data(void)
12 {
13 	uint8_t *spd_data;
14 	int spd_index;
15 	size_t spd_file_len;
16 	char *spd_file;
17 
18 	spd_index = 0;
19 
20 	spd_file = cbfs_map("spd.bin", &spd_file_len);
21 	if (!spd_file)
22 		die("SPD data not found.");
23 
24 	if (spd_file_len < ((spd_index + 1) * SPD_SIZE_MAX_DDR4)) {
25 		printk(BIOS_ERR,
26 		       "SPD index override to 0 due to incorrect SPD index.\n");
27 		spd_index = 0;
28 	}
29 
30 	if (spd_file_len < SPD_SIZE_MAX_DDR4)
31 		die("Missing SPD data.");
32 
33 	/* Assume same memory in both channels */
34 	spd_index *= SPD_SIZE_MAX_DDR4;
35 	spd_data = (uint8_t *)(spd_file + spd_index);
36 
37 	/* Make sure a valid SPD was found */
38 	if (spd_data[0] == 0)
39 		die("Invalid SPD data.");
40 
41 	return spd_data;
42 }
43