Module Name:    src
Committed By:   thorpej
Date:           Sun May 16 05:16:21 UTC 2021

Modified Files:
        src/sys/dev/i2c [thorpej-i2c-spi-conf]: spdmem_i2c.c

Log Message:
SPD stands for "Serial Presence Detect".  This implies that
if we're using direct configuration that we should treat
that as a *hint*... it's entirely possible that a device
tree lists locations where SPD memory can be found, not
necessarily where memory is known to be present.

Accordingly, if we get a direct configuration match based
on compatible data or device name, we still check to see
if the device is there.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.21.4.1 src/sys/dev/i2c/spdmem_i2c.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/spdmem_i2c.c
diff -u src/sys/dev/i2c/spdmem_i2c.c:1.21 src/sys/dev/i2c/spdmem_i2c.c:1.21.4.1
--- src/sys/dev/i2c/spdmem_i2c.c:1.21	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/spdmem_i2c.c	Sun May 16 05:16:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -185,31 +185,45 @@ spdmem_i2c_match(device_t parent, cfdata
 	struct spdmem_i2c_softc sc;
 	int match_result;
 
-	if (iic_use_direct_match(ia, match, compat_data, &match_result))
-		return match_result;
-
 	/*
-	 * XXXJRT
-	 * Should do this with "compatible" strings.  There are also
-	 * other problems with this "match" routine.  Specifically, if
-	 * we are doing direct-config, we know the device is already
-	 * there aren't do need to probe.  I'll leave the logic for
-	 * now and let someone who knows better clean it later.
+	 * SPD stands for "Serial Presence Detect".  This implies that
+	 * if we're using direct configuration that we should treat
+	 * that as a *hint*... it's entirely possible that a device
+	 * tree lists locations where SPD memory can be found, not
+	 * necessarily where memory is known to be present.
+	 *
+	 * Accordingly, if we get a direct configuration match based
+	 * on compatible data or device name, we still check to see
+	 * if the device is there.
 	 */
 
+	if (iic_use_direct_match(ia, match, compat_data, &match_result)) {
+		if (match_result != 0) {
+			goto do_probe;
+		}
+		return 0;
+	}
+
 	if (ia->ia_name) {
 		/* add other names as we find more firmware variations */
-		if (strcmp(ia->ia_name, "dimm-spd") &&
-		    strcmp(ia->ia_name, "dimm"))
-			return 0;
+		if (strcmp(ia->ia_name, "dimm-spd") == 0 ||
+		    strcmp(ia->ia_name, "dimm") == 0) {
+			match_result = I2C_MATCH_DIRECT_SPECIFIC;
+			goto do_probe;
+		}
+		return 0;
 	}
 
-	/* only do this lame test when not using direct config */
-	if (ia->ia_name == NULL) {
-		if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) != SPDMEM_I2C_ADDR)
-			return 0;
+	/* As a last resort, filter out invalid addresses. */
+	if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) == SPDMEM_I2C_ADDR) {
+		match_result = I2C_MATCH_ADDRESS_AND_PROBE;
+		goto do_probe;
 	}
+	
+	/* Not a candidate address. */
+	return 0;
 
+ do_probe:
 	sc.sc_tag = ia->ia_tag;
 	sc.sc_addr = ia->ia_addr;
 	sc.sc_page0 = SPDCTL_SPA0;
@@ -221,8 +235,7 @@ spdmem_i2c_match(device_t parent, cfdata
 		return 0;
 
 	if (spdmem_common_probe(&sc.sc_base)) {
-		return ia->ia_name ? I2C_MATCH_DIRECT_SPECIFIC
-				   : I2C_MATCH_ADDRESS_AND_PROBE;
+		return match_result;
 	}
 	return 0;
 }

Reply via email to