From owner-svn-src-head@freebsd.org Sun Nov 3 20:45:25 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E84B81A2377; Sun, 3 Nov 2019 20:45:25 +0000 (UTC) (envelope-from wulf@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 475nxd5mzjz4178; Sun, 3 Nov 2019 20:45:25 +0000 (UTC) (envelope-from wulf@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 AA6EF196A8; Sun, 3 Nov 2019 20:45:25 +0000 (UTC) (envelope-from wulf@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xA3KjPHh058947; Sun, 3 Nov 2019 20:45:25 GMT (envelope-from wulf@FreeBSD.org) Received: (from wulf@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xA3KjPaX058945; Sun, 3 Nov 2019 20:45:25 GMT (envelope-from wulf@FreeBSD.org) Message-Id: <201911032045.xA3KjPaX058945@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: wulf set sender to wulf@FreeBSD.org using -f From: Vladimir Kondratyev Date: Sun, 3 Nov 2019 20:45:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354296 - head/sys/dev/ichiic X-SVN-Group: head X-SVN-Commit-Author: wulf X-SVN-Commit-Paths: head/sys/dev/ichiic X-SVN-Commit-Revision: 354296 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.29 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: Sun, 03 Nov 2019 20:45:26 -0000 Author: wulf Date: Sun Nov 3 20:45:25 2019 New Revision: 354296 URL: https://svnweb.freebsd.org/changeset/base/354296 Log: [ig4] Reduce scope of io_lock Now io_lock is used as condition variable to synchronize active process with the interrupt handler. It is not used for tasks other than waiting for interrupt and passing parameters to and from it's handler. Modified: head/sys/dev/ichiic/ig4_iic.c head/sys/dev/ichiic/ig4_var.h Modified: head/sys/dev/ichiic/ig4_iic.c ============================================================================== --- head/sys/dev/ichiic/ig4_iic.c Sun Nov 3 20:44:16 2019 (r354295) +++ head/sys/dev/ichiic/ig4_iic.c Sun Nov 3 20:45:25 2019 (r354296) @@ -188,10 +188,12 @@ wait_status(ig4iic_softc_t *sc, uint32_t status) * work, otherwise poll with the lock held. */ if (status & IG4_STATUS_RX_NOTEMPTY) { + mtx_lock(&sc->io_lock); set_intr_mask(sc, IG4_INTR_STOP_DET | IG4_INTR_RX_FULL); mtx_sleep(sc, &sc->io_lock, 0, "i2cwait", (hz + 99) / 100); /* sleep up to 10ms */ set_intr_mask(sc, 0); + mtx_unlock(&sc->io_lock); count_us += 10000; } else { DELAY(25); @@ -405,7 +407,6 @@ ig4iic_transfer(device_t dev, struct iic_msg *msgs, ui } sx_xlock(&sc->call_lock); - mtx_lock(&sc->io_lock); /* Debugging - dump registers. */ if (ig4_dump) { @@ -453,7 +454,6 @@ ig4iic_transfer(device_t dev, struct iic_msg *msgs, ui rpstart = !stop; } - mtx_unlock(&sc->io_lock); sx_unlock(&sc->call_lock); return (error); } @@ -464,7 +464,6 @@ ig4iic_reset(device_t dev, u_char speed, u_char addr, ig4iic_softc_t *sc = device_get_softc(dev); sx_xlock(&sc->call_lock); - mtx_lock(&sc->io_lock); /* TODO handle speed configuration? */ if (oldaddr != NULL) @@ -473,7 +472,6 @@ ig4iic_reset(device_t dev, u_char speed, u_char addr, if (addr == IIC_UNKNOWN) sc->slave_valid = false; - mtx_unlock(&sc->io_lock); sx_unlock(&sc->call_lock); return (0); } @@ -664,14 +662,12 @@ ig4iic_detach(ig4iic_softc_t *sc) bus_teardown_intr(sc->dev, sc->intr_res, sc->intr_handle); sx_xlock(&sc->call_lock); - mtx_lock(&sc->io_lock); sc->iicbus = NULL; sc->intr_handle = NULL; reg_write(sc, IG4_REG_INTR_MASK, 0); set_controller(sc, 0); - mtx_unlock(&sc->io_lock); sx_xunlock(&sc->call_lock); mtx_destroy(&sc->io_lock); Modified: head/sys/dev/ichiic/ig4_var.h ============================================================================== --- head/sys/dev/ichiic/ig4_var.h Sun Nov 3 20:44:16 2019 (r354295) +++ head/sys/dev/ichiic/ig4_var.h Sun Nov 3 20:45:25 2019 (r354296) @@ -73,8 +73,12 @@ struct ig4iic_softc { * * Functions implementing the icbus interface that interact * with the controller acquire an exclusive lock on call_lock - * to prevent interleaving of calls to the interface and a lock on - * io_lock right afterwards, to synchronize controller I/O activity. + * to prevent interleaving of calls to the interface. + * + * io_lock is used as condition variable to synchronize active process + * with the interrupt handler. It should not be used for tasks other + * than waiting for interrupt and passing parameters to and from + * it's handler. */ struct sx call_lock; struct mtx io_lock;