From nobody Fri Dec 01 01:33:55 2023 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 4ShFvm14K2z5352v; Fri, 1 Dec 2023 01:33:56 +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 4ShFvm0V6cz4WcC; Fri, 1 Dec 2023 01:33:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701394436; 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=ltbGgvs1mFoDF1XfRjf8ehXTTbHIa4X9VeSx2PUI1S8=; b=tU7kPIWZsothLTiKxoJLDPhDStpLtWqbKj3b/KgDgZjZbJl3LrmV3fl82TvpMH1TP7WKqx gKpEyqJz796eKyEwxV97+SdhHy8JLX7Pp0uRpkRV6SSQa3DhWhR1PCa89drWnVQjAMRryE C09628wF83qrb0rMwkTrVWghDlJDGuzxmugIH8nsf1yakjNULnM5VvZvQGs9jksQqGEnNm XpxbHyzbTj8gAnWUTsbKo2W1B6apVaW2Mmd1SLcL3Pzm5QyssliBstPHM1qwj/1gDbxbjM x+x2mydAIrcw3Q2v5sHoU+lynuGvihwEqyAqhS1NxggmbZkth1qD75WeZ4M8tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701394436; 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=ltbGgvs1mFoDF1XfRjf8ehXTTbHIa4X9VeSx2PUI1S8=; b=O7rPU/+ILmXYKC9HNceTMH3AXtte7iGaugdyt0lQVFXE/azhCqSNymmtk3HjyUAkoivLsk nVlZD9EZQXbNfMdSUNwAyb+BzC5OGHcJ1s3X+9b3TX5pgURYmoqaqNuRs9gekAUtBWGtS4 kIRMdx73yZd+W1ZvbULtY7XXRnidi+RrXXjo2h1wwIki0pFa3OsUmxMdn1P+/ay3062sA4 O8JEfRBp1Nd0R1UWb7k+Pi6yQ25/GrnSSwrPafNvVhOcu7UZJTzNrNfUg/PuWv/gA0kRiX yk85YwOkyuufI8uFLYLBl9esS6ifOsyXgv9jWWmqvlJ2bPa6n/bGbasIMDI2hw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701394436; a=rsa-sha256; cv=none; b=auny8Zf7vswlP48XY8QOx8aMhy3F8KNl/uNNK3kZYnvN86FVblxPfCdbifowBMEuY8rPMA naQI70TU1hIyqi2xIq4mpgoHcXsWGY7aUjW14Wojl1NWnhHhNKmFXuzYUH09CCfq8Kz2Mc 5UV6tWoykvyOH81/PDD15HvwNNGALChdjRYbiF11hsBcC97z1wFVjY58AAX8FrXY9g4X90 xBd4IDYF0Mr0MCtuRq0hEKIbfIxqwebvQXltN3a08b9zfddOrPjcoS6MdNJeaMwQGohoIS rhvXYV36LE6IfRCXTePksCjyFxI9UST5skVhop96d+5AlSkwB4ZCLzdMeGTj+A== 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 4ShFvl6gR5z1CSk; Fri, 1 Dec 2023 01:33:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3B11XtIw057329; Fri, 1 Dec 2023 01:33:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B11XtOU057326; Fri, 1 Dec 2023 01:33:55 GMT (envelope-from git) Date: Fri, 1 Dec 2023 01:33:55 GMT Message-Id: <202312010133.3B11XtOU057326@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Stephen J. Kiernan" Subject: git: 682b069c5c56 - main - iicbus: add compat32 support for I2C ioctls 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: stevek X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 682b069c5c5643d26199cc1b65717f99c98bce9d Auto-Submitted: auto-generated The branch main has been updated by stevek: URL: https://cgit.FreeBSD.org/src/commit/?id=682b069c5c5643d26199cc1b65717f99c98bce9d commit 682b069c5c5643d26199cc1b65717f99c98bce9d Author: Stephen J. Kiernan AuthorDate: 2023-11-29 19:20:45 +0000 Commit: Stephen J. Kiernan CommitDate: 2023-12-01 01:33:46 +0000 iicbus: add compat32 support for I2C ioctls Some of the I2C ioctl request structures contain pointers and need to handle requests from 32-bit applications on 64-bit kernels. Obtained from: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D42836 --- sys/dev/iicbus/iic.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/sys/dev/iicbus/iic.c b/sys/dev/iicbus/iic.c index baaa7a096a14..8c9dbb6bc145 100644 --- a/sys/dev/iicbus/iic.c +++ b/sys/dev/iicbus/iic.c @@ -2,6 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 1998, 2001 Nicolas Souchu + * Copyright (c) 2023 Juniper Networks, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,6 +28,7 @@ * */ #include +#include #include #include #include @@ -57,6 +59,30 @@ struct iic_cdevpriv { uint8_t addr; }; +#ifdef COMPAT_FREEBSD32 +struct iic_msg32 { + uint16_t slave; + uint16_t flags; + uint16_t len; + uint32_t buf; +}; + +struct iiccmd32 { + u_char slave; + uint32_t count; + uint32_t last; + uint32_t buf; +}; + +struct iic_rdwr_data32 { + uint32_t msgs; + uint32_t nmsgs; +}; + +#define I2CWRITE32 _IOW('i', 4, struct iiccmd32) +#define I2CREAD32 _IOW('i', 5, struct iiccmd32) +#define I2CRDWR32 _IOW('i', 6, struct iic_rdwr_data32) +#endif #define IIC_LOCK(cdp) sx_xlock(&(cdp)->lock) #define IIC_UNLOCK(cdp) sx_xunlock(&(cdp)->lock) @@ -70,7 +96,7 @@ static void iic_identify(driver_t *driver, device_t parent); static void iicdtor(void *data); static int iicuio_move(struct iic_cdevpriv *priv, struct uio *uio, int last); static int iicuio(struct cdev *dev, struct uio *uio, int ioflag); -static int iicrdwr(struct iic_cdevpriv *priv, struct iic_rdwr_data *d, int flags); +static int iicrdwr(struct iic_cdevpriv *priv, struct iic_rdwr_data *d, int flags, bool compat32); static device_method_t iic_methods[] = { /* device interface */ @@ -285,9 +311,36 @@ iicuio(struct cdev *dev, struct uio *uio, int ioflag) return (error); } +#ifdef COMPAT_FREEBSD32 +static int +iic_copyinmsgs32(struct iic_rdwr_data *d, struct iic_msg *buf) +{ + struct iic_msg32 msg32; + struct iic_msg32 *m32; + int error, i; + + m32 = (struct iic_msg32 *)d->msgs; + for (i = 0; i < d->nmsgs; i++) { + error = copyin(&m32[i], &msg32, sizeof(msg32)); + if (error != 0) + return (error); + CP(msg32, buf[i], slave); + CP(msg32, buf[i], flags); + CP(msg32, buf[i], len); + PTRIN_CP(msg32, buf[i], buf); + } + return (0); +} +#endif + static int -iicrdwr(struct iic_cdevpriv *priv, struct iic_rdwr_data *d, int flags) +iicrdwr(struct iic_cdevpriv *priv, struct iic_rdwr_data *d, int flags, + bool compat32 __unused) { +#ifdef COMPAT_FREEBSD32 + struct iic_rdwr_data dswab; + struct iic_rdwr_data32 *d32; +#endif struct iic_msg *buf, *m; void **usrbufs; device_t iicdev, parent; @@ -297,12 +350,25 @@ iicrdwr(struct iic_cdevpriv *priv, struct iic_rdwr_data *d, int flags) iicdev = priv->sc->sc_dev; parent = device_get_parent(iicdev); error = 0; +#ifdef COMPAT_FREEBSD32 + if (compat32) { + d32 = (struct iic_rdwr_data32 *)d; + PTRIN_CP(*d32, dswab, msgs); + CP(*d32, dswab, nmsgs); + d = &dswab; + } +#endif if (d->nmsgs > IIC_RDRW_MAX_MSGS) return (EINVAL); buf = malloc(sizeof(*d->msgs) * d->nmsgs, M_IIC, M_WAITOK); +#ifdef COMPAT_FREEBSD32 + if (compat32) + error = iic_copyinmsgs32(d, buf); + else +#endif error = copyin(d->msgs, buf, sizeof(*d->msgs) * d->nmsgs); if (error != 0) { free(buf, M_IIC); @@ -355,14 +421,24 @@ iicrdwr(struct iic_cdevpriv *priv, struct iic_rdwr_data *d, int flags) static int iicioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td) { +#ifdef COMPAT_FREEBSD32 + struct iiccmd iicswab; +#endif device_t parent, iicdev; struct iiccmd *s; +#ifdef COMPAT_FREEBSD32 + struct iiccmd32 *s32; +#endif struct uio ubuf; struct iovec uvec; struct iic_cdevpriv *priv; int error; + bool compat32; s = (struct iiccmd *)data; +#ifdef COMPAT_FREEBSD32 + s32 = (struct iiccmd32 *)data; +#endif error = devfs_get_cdevpriv((void**)&priv); if (error != 0) return (error); @@ -373,6 +449,20 @@ iicioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *t parent = device_get_parent(iicdev); IIC_LOCK(priv); +#ifdef COMPAT_FREEBSD32 + switch (cmd) { + case I2CWRITE32: + case I2CREAD32: + CP(*s32, iicswab, slave); + CP(*s32, iicswab, count); + CP(*s32, iicswab, last); + PTRIN_CP(*s32, iicswab, buf); + s = &iicswab; + break; + default: + break; + } +#endif switch (cmd) { case I2CSTART: @@ -428,6 +518,9 @@ iicioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *t break; case I2CWRITE: +#ifdef COMPAT_FREEBSD32 + case I2CWRITE32: +#endif if (!priv->started) { error = EINVAL; break; @@ -445,6 +538,9 @@ iicioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *t break; case I2CREAD: +#ifdef COMPAT_FREEBSD32 + case I2CREAD32: +#endif if (!priv->started) { error = EINVAL; break; @@ -461,6 +557,9 @@ iicioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *t error = iicuio_move(priv, &ubuf, s->last); break; +#ifdef COMPAT_FREEBSD32 + case I2CRDWR32: +#endif case I2CRDWR: /* * The rdwr list should be a self-contained set of @@ -471,7 +570,13 @@ iicioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *t break; } - error = iicrdwr(priv, (struct iic_rdwr_data *)data, flags); +#ifdef COMPAT_FREEBSD32 + compat32 = (cmd == I2CRDWR32); +#else + compat32 = false; +#endif + error = iicrdwr(priv, (struct iic_rdwr_data *)data, flags, + compat32); break;