Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jul 2018 20:33:49 +0000 (UTC)
From:      Justin Hibbits <jhibbits@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r336144 - head/sys/powerpc/powernv
Message-ID:  <201807092033.w69KXnqw045501@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhibbits
Date: Mon Jul  9 20:33:48 2018
New Revision: 336144
URL: https://svnweb.freebsd.org/changeset/base/336144

Log:
  powerpc/powernv: Make opal_i2c driver work with attached i2c drivers
  
  * FreeBSD stores addresses in 8 bit format, but the OPAL API requires the 7-bit
    address, and encodes the direction elsewhere.  Behave like other i2c drivers,
    and shift accordingly.
  * The OPAL API can already handle multiple requests in flight.  Change the async
    token to be private to the thread, so as not to stomp across i2c accesses,
    remove the limitation error message, and use the correct message index to
    transfer all messages in the list.
  * Micro-optimize the async handler to not continuously call pmap_kextract() when
    spin-waiting for the operation to complete.
  
  This has been tested by hexdumping an EEPROM attached via the icee(4) driver.

Modified:
  head/sys/powerpc/powernv/opal_i2c.c

Modified: head/sys/powerpc/powernv/opal_i2c.c
==============================================================================
--- head/sys/powerpc/powernv/opal_i2c.c	Mon Jul  9 20:27:31 2018	(r336143)
+++ head/sys/powerpc/powernv/opal_i2c.c	Mon Jul  9 20:33:48 2018	(r336144)
@@ -167,16 +167,19 @@ static int
 i2c_opal_send_request(uint32_t bus_id, struct opal_i2c_request *req)
 {
 	struct opal_msg msg;
-	int token, rc;
+	uint64_t token;
+	uint64_t msg_addr;
+	int rc;
 
 	/*
 	 * XXX:
-	 * Async tokens should be managed globally. Since there is
-	 * only one place now, use hardcoded value.
+	 * Async tokens should be managed globally. Since there are only a very
+	 * few places now, use a punning of the stack address of the message.
 	 */
-	token = 0x112233;
+	token = (uintptr_t)&msg;
 
 	memset(&msg, 0, sizeof(msg));
+	msg_addr = pmap_kextract((vm_offset_t)&msg);
 
 	rc = opal_call(OPAL_I2C_REQUEST, token, bus_id,
 	    pmap_kextract((uint64_t)req));
@@ -185,7 +188,7 @@ i2c_opal_send_request(uint32_t bus_id, struct opal_i2c
 
 	do {
 		rc = opal_call(OPAL_CHECK_ASYNC_COMPLETION,
-		    pmap_kextract((uint64_t)&msg), sizeof(msg), token);
+		    msg_addr, sizeof(msg), token);
 	} while (rc == OPAL_BUSY);
 
 	if (rc != OPAL_SUCCESS)
@@ -207,20 +210,13 @@ opal_i2c_transfer(device_t dev, struct iic_msg *msgs, 
 
 	memset(&req, 0, sizeof(req));
 
-	/* XXX: Currently OPAL can parse only 1 message */
-	if (nmsgs > 1) {
-		device_printf(dev,
-		    "trying to parse %d messages, while only 1 is supported\n", nmsgs);
-		return (ENOMEM);
-	}
-
 	I2C_LOCK(sc);
 	for (i = 0; i < nmsgs; i++) {
 		req.type = (msgs[i].flags & IIC_M_RD) ?
 		    OPAL_I2C_RAW_READ : OPAL_I2C_RAW_WRITE;
-		req.addr = htobe16(msgs[0].slave);
-		req.size = htobe32(msgs[0].len);
-		req.buffer_pa = htobe64(pmap_kextract((uint64_t)msgs[0].buf));
+		req.addr = htobe16(msgs[i].slave >> 1);
+		req.size = htobe32(msgs[i].len);
+		req.buffer_pa = htobe64(pmap_kextract((uint64_t)msgs[i].buf));
 
 		err = i2c_opal_send_request(sc->opal_id, &req);
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807092033.w69KXnqw045501>