mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ddr_dimms: Check spd->mem_type before computing parameters
@ 2023-02-01  5:33 John Watts
  2023-02-02  7:23 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: John Watts @ 2023-02-01  5:33 UTC (permalink / raw)
  To: barebox; +Cc: John Watts

Checking the mem_type here as well as the CRC means developers can
just read the SPD and pass it directly to parameter computation.

This makes it so developers can rely fully on parameters for checking
if RAM is compatible with their board and not need to worry about reading
SPD data themselves.

Signed-off-by: John Watts <contact@jookia.org>
---
 common/ddr1_dimm_params.c | 5 +++++
 common/ddr2_dimm_params.c | 7 +++++++
 common/ddr3_dimm_params.c | 5 +++++
 common/ddr4_dimm_params.c | 5 +++++
 4 files changed, 22 insertions(+)

diff --git a/common/ddr1_dimm_params.c b/common/ddr1_dimm_params.c
index 3f8759c351..77e047a051 100644
--- a/common/ddr1_dimm_params.c
+++ b/common/ddr1_dimm_params.c
@@ -221,6 +221,11 @@ unsigned int ddr1_compute_dimm_parameters(unsigned int mclk_ps,
 {
 	int ret;
 
+	if (spd->mem_type != SPD_MEMTYPE_DDR) {
+		printf("DIMM: SPD data is not DDR1\n");
+		return 3;
+	}
+
 	ret = ddr1_spd_check(spd);
 	if (ret) {
 		printf("DIMM: failed checksum\n");
diff --git a/common/ddr2_dimm_params.c b/common/ddr2_dimm_params.c
index 2cec662ecb..b9c0922385 100644
--- a/common/ddr2_dimm_params.c
+++ b/common/ddr2_dimm_params.c
@@ -206,6 +206,13 @@ unsigned int ddr2_compute_dimm_parameters(unsigned int mclk_ps,
 {
 	int ret;
 
+	if (spd->mem_type != SPD_MEMTYPE_DDR2 &&
+	    spd->mem_type != SPD_MEMTYPE_DDR2_FBDIMM &&
+	    spd->mem_type != SPD_MEMTYPE_DDR2_FBDIMM_PROBE) {
+		printf("DIMM: SPD data is not DDR2\n");
+		return 3;
+	}
+
 	ret = ddr2_spd_check(spd);
 	if (ret) {
 		printf("DIMM: failed checksum\n");
diff --git a/common/ddr3_dimm_params.c b/common/ddr3_dimm_params.c
index 6c3dbc6877..1b7512a275 100644
--- a/common/ddr3_dimm_params.c
+++ b/common/ddr3_dimm_params.c
@@ -86,6 +86,11 @@ unsigned int ddr3_compute_dimm_parameters(const struct ddr3_spd_eeprom *spd,
 	int ftb_10th_ps;
 	int i;
 
+	if (spd->mem_type != SPD_MEMTYPE_DDR3) {
+		printf("DIMM: SPD data is not DDR3\n");
+		return 3;
+	}
+
 	ret = ddr3_spd_check(spd);
 	if (ret) {
 		printf("DIMM: failed checksum\n");
diff --git a/common/ddr4_dimm_params.c b/common/ddr4_dimm_params.c
index 9fa3225d90..045cbd457c 100644
--- a/common/ddr4_dimm_params.c
+++ b/common/ddr4_dimm_params.c
@@ -136,6 +136,11 @@ unsigned int ddr4_compute_dimm_parameters(const struct ddr4_spd_eeprom *spd,
 	u8 *ptr;
 	u8 val;
 
+	if (spd->mem_type != SPD_MEMTYPE_DDR4) {
+		printf("DIMM: SPD data is not DDR4\n");
+		return 3;
+	}
+
 	ret = ddr4_spd_check(spd);
 	if (ret) {
 		printf("DIMM: failed checksum\n");
-- 
2.39.1




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-02  7:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01  5:33 [PATCH] ddr_dimms: Check spd->mem_type before computing parameters John Watts
2023-02-02  7:23 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox