From owner-svn-src-head@freebsd.org Mon Jul 9 20:33:50 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BE38F102C68E; Mon, 9 Jul 2018 20:33:49 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6FFF6858B2; Mon, 9 Jul 2018 20:33:49 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 36DF219F6D; Mon, 9 Jul 2018 20:33:49 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w69KXnTN045502; Mon, 9 Jul 2018 20:33:49 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w69KXnqw045501; Mon, 9 Jul 2018 20:33:49 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201807092033.w69KXnqw045501@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Mon, 9 Jul 2018 20:33:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336144 - head/sys/powerpc/powernv X-SVN-Group: head X-SVN-Commit-Author: jhibbits X-SVN-Commit-Paths: head/sys/powerpc/powernv X-SVN-Commit-Revision: 336144 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jul 2018 20:33:50 -0000 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); }