mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: John Watts <contact@jookia.org>
To: barebox@lists.infradead.org
Cc: John Watts <contact@jookia.org>
Subject: [PATCH] ddr_dimms: Check spd->mem_type before computing parameters
Date: Wed,  1 Feb 2023 16:33:34 +1100	[thread overview]
Message-ID: <20230201053334.971854-1-contact@jookia.org> (raw)

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




             reply	other threads:[~2023-02-01  5:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01  5:33 John Watts [this message]
2023-02-02  7:23 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230201053334.971854-1-contact@jookia.org \
    --to=contact@jookia.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox