From nobody Tue Jun 21 15:23:13 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 677A986A2A7; Tue, 21 Jun 2022 15:23:15 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LS9JL5Qp3z4gD4; Tue, 21 Jun 2022 15:23:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655824995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jCfFPcU7/GhmuY+WOZnMNfWUiZhLh0B60XrTw8bH45M=; b=nwwzSoPN+nDwtEKuBuF4/+3y/vAIbqsv9/zchYjqsEclZYJUyZwz+bhR27sFRK795J/hZc tB4PXKVxUu4BOS1TcsM+3GK9oq/G4+gd2n7gPHCdpVNHBCxeGYZz0nteQHTUhk3QUouUmV iqvcmc7+KGC1u8hlHxXxB5M7Ge3QWVs0U1sHkH1ZD9DfcT2wzChPioR25qZ3FcFgnYkPoF SwCcc5P2OTk/nBpiIPURpUkA3j5PBHnW/VxbjsjV7I9vE2fLvEa20PM+5o1H3Vn4e08OB/ JrGYjBF6GFc7x8vIbHmRS+zFffMV9AdWFxV67QX09wPS8Qt+C89AdDQf03azkg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DF14E14644; Tue, 21 Jun 2022 15:23:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25LFNDRo062933; Tue, 21 Jun 2022 15:23:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25LFND1N062932; Tue, 21 Jun 2022 15:23:13 GMT (envelope-from git) Date: Tue, 21 Jun 2022 15:23:13 GMT Message-Id: <202206211523.25LFND1N062932@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: d0d0d14abcab - stable/13 - linuxkpi: Rework detach function List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d0d0d14abcab6427ca747f198d2bcfecc0d142c2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655824995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jCfFPcU7/GhmuY+WOZnMNfWUiZhLh0B60XrTw8bH45M=; b=JjwshHS8Tt6iT3+OQTaAfE35+1yspX6mEJYVBo1U+vRAcAV+tKsEkk0fOQELUhFHjbtLiK JxVE/Dd7N8jDAHZucrATCzeNO46lkPgPSpbZ3XH9CCEp6LffuCkcXJAezbIj6q7OmuVQSn 5XX59h0wWKVz+ST9KJZAw435IkfD/00FeYIJrKmWtAWNuOEGjRtoPYUK6vITYeyO7CWjtI HHLevajwJ22XCPg9xnkA3C2wSSDqzBmY5Df1x64wVKwy1uEey6CPZOJDI2nM6WkVQFRPsH Q3pGR1Ao+69umxDXK5qXFweq4bFxuwmNaRFupG/vYGWlvbsUe9+1ldr+WMp4BA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655824995; a=rsa-sha256; cv=none; b=YE+R806GSFn6ZaQVsFvYRAhcfH6sSWRBBr3OvSZH1T9dFvQC2sLAjMiaTLbSn+SCZi25M/ JdMJACakhBUYMrh+bodvzusFa+JWq493rssgTo6AvJxId/bu/xnSLOC8hv7eTLJ0+M3Ala LAVGOWmgcdW3c27oeqV//+vUndy/DCahnlmi/KrsSNhiVxiijA06/D39ekxsidnBkOLqB0 HpKPqPdr8YPPocEaLnaciFXrGQjuRcXC3J+/m4h0/jPbtaaNyrusjtefq4W5QuxZvoBGQA dkHgeFqu5SqNOKXM7q4cAuqNMSj95jZqynZ8UalFFIpwUaShLewsZzOAJ2LmrA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=d0d0d14abcab6427ca747f198d2bcfecc0d142c2 commit d0d0d14abcab6427ca747f198d2bcfecc0d142c2 Author: Emmanuel Vadot AuthorDate: 2022-05-13 11:56:36 +0000 Commit: Emmanuel Vadot CommitDate: 2022-06-21 15:13:57 +0000 linuxkpi: Rework detach function We need to detach the matching i2c adapter so look for the right one. While here add some locks to protect multiple add/del at the same time. Fixes: 1961a14a47 ("linuxkpi: Add i2c support") Sponsored by: Beckhoff Automation GmbH & Co. KG (cherry picked from commit 25d21a845223ffad189fd2a7831ebf5e298b628a) --- sys/compat/linuxkpi/common/src/linux_i2c.c | 70 ++++++++++++++++++++++++---- sys/compat/linuxkpi/common/src/linux_i2cbb.c | 10 ++++ sys/compat/linuxkpi/common/src/lkpi_iic_if.m | 4 ++ 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_i2c.c b/sys/compat/linuxkpi/common/src/linux_i2c.c index ef264abd3fd4..eedd877f0e0f 100644 --- a/sys/compat/linuxkpi/common/src/linux_i2c.c +++ b/sys/compat/linuxkpi/common/src/linux_i2c.c @@ -53,6 +53,27 @@ struct lkpi_iic_softc { struct i2c_adapter *adapter; }; +static struct sx lkpi_sx_i2c; + +static void +lkpi_sysinit_i2c(void *arg __unused) +{ + + sx_init(&lkpi_sx_i2c, "lkpi-i2c"); +} + +static void +lkpi_sysuninit_i2c(void *arg __unused) +{ + + sx_destroy(&lkpi_sx_i2c); +} + +SYSINIT(lkpi_i2c, SI_SUB_DRIVERS, SI_ORDER_ANY, + lkpi_sysinit_i2c, NULL); +SYSUNINIT(lkpi_i2c, SI_SUB_DRIVERS, SI_ORDER_ANY, + lkpi_sysuninit_i2c, NULL); + static int lkpi_iic_probe(device_t dev) { @@ -98,6 +119,15 @@ lkpi_iic_add_adapter(device_t dev, struct i2c_adapter *adapter) return (0); } +static struct i2c_adapter * +lkpi_iic_get_adapter(device_t dev) +{ + struct lkpi_iic_softc *sc; + + sc = device_get_softc(dev); + return (sc->adapter); +} + static device_method_t lkpi_iic_methods[] = { /* device interface */ DEVMETHOD(device_probe, lkpi_iic_probe), @@ -113,6 +143,7 @@ static device_method_t lkpi_iic_methods[] = { /* lkpi_iic interface */ DEVMETHOD(lkpi_iic_add_adapter, lkpi_iic_add_adapter), + DEVMETHOD(lkpi_iic_get_adapter, lkpi_iic_get_adapter), DEVMETHOD_END }; @@ -179,12 +210,16 @@ lkpi_i2c_add_adapter(struct i2c_adapter *adapter) device_t lkpi_iic; int error; + if (adapter->name[0] == '\0') + return (-EINVAL); if (bootverbose) device_printf(adapter->dev.parent->bsddev, "Adding i2c adapter %s\n", adapter->name); + sx_xlock(&lkpi_sx_i2c); lkpi_iic = device_add_child(adapter->dev.parent->bsddev, "lkpi_iic", -1); if (lkpi_iic == NULL) { device_printf(adapter->dev.parent->bsddev, "Couldn't add lkpi_iic\n"); + sx_xunlock(&lkpi_sx_i2c); return (ENXIO); } @@ -192,9 +227,11 @@ lkpi_i2c_add_adapter(struct i2c_adapter *adapter) if (error) { device_printf(adapter->dev.parent->bsddev, "failed to attach child: error %d\n", error); + sx_xunlock(&lkpi_sx_i2c); return (ENXIO); } LKPI_IIC_ADD_ADAPTER(lkpi_iic, adapter); + sx_xunlock(&lkpi_sx_i2c); return (0); } @@ -202,18 +239,35 @@ int lkpi_i2c_del_adapter(struct i2c_adapter *adapter) { device_t child; + int unit, rv; + if (adapter == NULL) + return (-EINVAL); if (bootverbose) device_printf(adapter->dev.parent->bsddev, "Removing i2c adapter %s\n", adapter->name); + sx_xlock(&lkpi_sx_i2c); + unit = 0; + while ((child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iic", unit++)) != NULL) { + + if (adapter == LKPI_IIC_GET_ADAPTER(child)) { + device_delete_child(adapter->dev.parent->bsddev, child); + rv = 0; + goto out; + } + } - child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iic", -1); - if (child != NULL) - device_delete_child(adapter->dev.parent->bsddev, child); - - child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iicbb", -1); - if (child != NULL) - device_delete_child(adapter->dev.parent->bsddev, child); + unit = 0; + while ((child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iicbb", unit++)) != NULL) { - return (0); + if (adapter == LKPI_IIC_GET_ADAPTER(child)) { + device_delete_child(adapter->dev.parent->bsddev, child); + rv = 0; + goto out; + } + } + rv = -EINVAL; +out: + sx_xunlock(&lkpi_sx_i2c); + return (rv); } diff --git a/sys/compat/linuxkpi/common/src/linux_i2cbb.c b/sys/compat/linuxkpi/common/src/linux_i2cbb.c index e6f851bee103..f7321f060fa0 100644 --- a/sys/compat/linuxkpi/common/src/linux_i2cbb.c +++ b/sys/compat/linuxkpi/common/src/linux_i2cbb.c @@ -100,6 +100,15 @@ lkpi_iicbb_add_adapter(device_t dev, struct i2c_adapter *adapter) return (0); } +static struct i2c_adapter * +lkpi_iicbb_get_adapter(device_t dev) +{ + struct lkpi_iicbb_softc *sc; + + sc = device_get_softc(dev); + return (sc->adapter); +} + static device_method_t lkpi_iicbb_methods[] = { /* device interface */ DEVMETHOD(device_probe, lkpi_iicbb_probe), @@ -117,6 +126,7 @@ static device_method_t lkpi_iicbb_methods[] = { /* lkpi_iicbb interface */ DEVMETHOD(lkpi_iic_add_adapter, lkpi_iicbb_add_adapter), + DEVMETHOD(lkpi_iic_get_adapter, lkpi_iicbb_get_adapter), DEVMETHOD_END }; diff --git a/sys/compat/linuxkpi/common/src/lkpi_iic_if.m b/sys/compat/linuxkpi/common/src/lkpi_iic_if.m index 2379182c409b..c1b4abd79084 100644 --- a/sys/compat/linuxkpi/common/src/lkpi_iic_if.m +++ b/sys/compat/linuxkpi/common/src/lkpi_iic_if.m @@ -35,3 +35,7 @@ METHOD int add_adapter { device_t dev; struct i2c_adapter *adapter; }; + +METHOD struct i2c_adapter * get_adapter { + device_t dev; +};