From nobody Wed Dec 17 10:42:36 2025 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C69812367D1 for ; Fri, 9 May 2025 16:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746806435; cv=none; b=gQzsEEgDkWZiFHgE/lpipghqafuQuoBB+XlVqAwJWJnOr/pnw8WPP56xQtd4j0PaMMPFJ7dqyRMjVjn7/+XBcZyILDNurdDaZpQ8t1nNKYcSqg9NoB0TlR8qEBk25kvVYWUIiDpRhBUaJYqxHwT8rpe45A3C74Z0spGhEaPe5Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746806435; c=relaxed/simple; bh=FDDQG0MN20LfYi2hnLXORGrSUhznvJcn/YYRyhDFSeU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PYGEaL86iGJvLaAdFmoEszSJCPUKLB6N2Y63mZcDSP1YXzs2Kq9w2PPQYnmkHHCdie/8cMsHhqS9GAkVu99Oa6Et7MjMANh/iRGuyF652cXNru80ETO3xJbhQ/VZUKU6feLfKuaoxzMtB0uZypypYGTKqTSgCKMK+qZJR6beLwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=amp9iI5l; arc=none smtp.client-ip=91.218.175.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="amp9iI5l" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1746806431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q6rNWKa3yBqbjYl0but82CIqRVti48Mb1G+HhwjvMLI=; b=amp9iI5ldtnWZe6TLLmjdWwTI5VFbsHP9pTu53NiBRPxA1q0iph7Dcgmi2ZjAzXdtW87K4 jWe5edtE1nTVXndNvCXCCLvQ4RcPwm5ROE2GW10fiVWsbM6jpfODGg8qiAJNrLdU06ifZQ Ut7FlJk4bOn3z2H6TdxtGohH5+K0H6c= From: Dawei Li To: andersson@kernel.org, mathieu.poirier@linaro.org Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, dawei.li@linux.dev, set_pte_at@outlook.com Subject: [PATCH v2 2/3] rpmsg: char: Implement eptdev based on anon inode Date: Fri, 9 May 2025 23:59:26 +0800 Message-Id: <20250509155927.109258-3-dawei.li@linux.dev> In-Reply-To: <20250509155927.109258-1-dawei.li@linux.dev> References: <20250509155927.109258-1-dawei.li@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Introduce new eptdev abstraction based on anon inode. The new API is exactly same with legacy one except: - It's anonymous and devnode/path free. - Its fops->open() is empty. Signed-off-by: Dawei Li --- drivers/rpmsg/rpmsg_char.c | 44 ++++++++++++++++++++++++++++++++++++++ drivers/rpmsg/rpmsg_char.h | 19 ++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index 5b2a883d6236..b0ec05f88013 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -13,6 +13,7 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include @@ -517,6 +518,49 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rp= dev, struct device *parent } EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create); =20 +static const struct file_operations rpmsg_eptdev_anon_fops =3D { + .owner =3D THIS_MODULE, + .release =3D rpmsg_eptdev_release, + .read_iter =3D rpmsg_eptdev_read_iter, + .write_iter =3D rpmsg_eptdev_write_iter, + .poll =3D rpmsg_eptdev_poll, + .unlocked_ioctl =3D rpmsg_eptdev_ioctl, + .compat_ioctl =3D compat_ptr_ioctl, +}; + +int rpmsg_eptdev_create(struct rpmsg_device *rpdev, struct device *parent, + struct rpmsg_channel_info chinfo, int *pfd) +{ + struct rpmsg_eptdev *eptdev; + int ret, fd; + + eptdev =3D __rpmsg_chrdev_eptdev_alloc(rpdev, parent, false); + if (IS_ERR(eptdev)) + return PTR_ERR(eptdev); + + ret =3D __rpmsg_chrdev_eptdev_add(eptdev, chinfo, false); + if (ret) { + dev_err(&eptdev->dev, "failed to add %s\n", eptdev->chinfo.name); + return ret; + } + + fd =3D anon_inode_getfd("rpmsg-eptdev", &rpmsg_eptdev_anon_fops, eptdev, = O_RDWR | O_CLOEXEC); + if (fd < 0) { + put_device(&eptdev->dev); + return fd; + } + + mutex_lock(&eptdev->ept_lock); + ret =3D __rpmsg_eptdev_open(eptdev); + mutex_unlock(&eptdev->ept_lock); + + if (!ret) + *pfd =3D fd; + + return ret; +} +EXPORT_SYMBOL(rpmsg_eptdev_create); + static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev) { struct rpmsg_channel_info chinfo; diff --git a/drivers/rpmsg/rpmsg_char.h b/drivers/rpmsg/rpmsg_char.h index 117d9cbc52f0..8cc2c14537da 100644 --- a/drivers/rpmsg/rpmsg_char.h +++ b/drivers/rpmsg/rpmsg_char.h @@ -19,6 +19,19 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *= parent, struct rpmsg_channel_info chinfo); =20 +/** + * rpmsg_eptdev_create() - register ep device and its associated fd based = on an endpoint + * @rpdev: prepared rpdev to be used for creating endpoints + * @parent: parent device + * @chinfo: associated endpoint channel information. + * @pfd: fd in represent of endpoint device + * + * This function create a new rpmsg endpoint device and its associated fd = to instantiate a new + * endpoint based on chinfo information. + */ +int rpmsg_eptdev_create(struct rpmsg_device *rpdev, struct device *parent, + struct rpmsg_channel_info chinfo, int *pfd); + /** * rpmsg_chrdev_eptdev_destroy() - destroy created char device endpoint. * @data: private data associated to the endpoint device @@ -36,6 +49,12 @@ static inline int rpmsg_chrdev_eptdev_create(struct rpms= g_device *rpdev, struct return -ENXIO; } =20 +static inline int rpmsg_eptdev_create(struct rpmsg_device *rpdev, struct d= evice *parent, + struct rpmsg_channel_info chinfo, int *pfd) +{ + return -ENXIO; +} + static inline int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *da= ta) { return -ENXIO; --=20 2.25.1