From nobody Mon Apr 07 18:01:24 2025 X-Original-To: dev-commits-src-main@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 4ZWcTd0Mghz5rwRc; Mon, 07 Apr 2025 18:01:25 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZWcTc73HSz3Sbh; Mon, 07 Apr 2025 18:01:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744048885; 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=+NTF9UuxIao6FYE6b0KrzXYxGVO8+w0ry3ULebYLbfw=; b=ORIglBa3eLN0Zw89Jmy6TaQmsuGPa4qbPfXVtn7JwVaWWlqFR15fi9BjeEBMT/ttJrpLYD CRMdvm7thpmNiWYfFvw6TRjU5vumGBQN+Vj15IgDUpCSBwhnDiCSvPo9+bghUFvaCKgC2G zmNYiJ9v0STG5FqZyKieq85w7PJO7hVjE7f7CTR8ZmZwKh20Mu7jaDsDgEkdwSrO50hNdR ba5Fl/SD3VRJe9y504yTQfT39vM6c9tGLaQcbGV+YpGCWS/6zDD6eqAVW4kVYr07AOwZRs RqclmEVxI5Zcg8+6r9SwpUNbMqqVfIelrxS3x5otg9DExURT+Z1VAJsJEfogmg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744048885; a=rsa-sha256; cv=none; b=RlnLTYj00pu9ZEqKiEh2Dry6d9bLkMNuzLS2BimFjeLmF8DP4nCkAY0meh9FXSVqRyXAu+ g1H0TK03bwXqYbAHLmJyc++zTFMSiDV8xl+a3awjO7IHWe/8kqE9duPmOPIYfxWcl5TNe2 yFugYzYfOsJyCxbpd7VF5/Gohq35yka4/A8FPQ1RHdaJyhPmpcBQ0tyFbIX6TEfdquwT7C I2yoCuxI6/MuVo0vbcN1E+5tMggYKMHZWA1sYYn8b0TZ5P2R1oHyBdIGbpXM4qAG5g+627 qHBf3d9flhkDUQAa3Vz1E7ZuUHihzDC9frxDobv5cc4k7wEZJe+Lsj+26TZRIQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744048885; 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=+NTF9UuxIao6FYE6b0KrzXYxGVO8+w0ry3ULebYLbfw=; b=aIsc57fgrgM01HLeq7FlP4/Y9x0HRk0dNDeAaXLoQT6i1XUPNksEWSG28Txa/RVbervpKs EiIaAKT8KIU7S+kqjkn9GtwP4sOs5lT1X3VizXnCKxNUJzoxYBLlGfX1K6s353/5BgO8qS 4VY25rDzwfAXRs9cXSf192N0dkvLvIKm2JBQc/0MmVxsisAC4URR3pIHv34wsCVHZgK/XN w6/VfVN2FPoHQ1B8yKLbmgvhgAFT1oNrGyTT4TzN8Vc70f6D4tg0lwcVbK35w0YNSGlrfb kZY9NaXNnPi0DCjGvldtjht1MInNaivaLS5bHMMZxJo7raiK9uQidor7wMVr3w== 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 4ZWcTc6QrFzx8v; Mon, 07 Apr 2025 18:01:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 537I1OZd028157; Mon, 7 Apr 2025 18:01:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 537I1O69028154; Mon, 7 Apr 2025 18:01:24 GMT (envelope-from git) Date: Mon, 7 Apr 2025 18:01:24 GMT Message-Id: <202504071801.537I1O69028154@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien?= =?utf-8?Q?P=C3=A9dron?= Subject: git: ca4ce6a56f9c - main - linuxkpi: Add `sysfs_create_bin_file()` and `sysfs_remove_bin_file()` List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ca4ce6a56f9c174917ab33191d367a850fc15c89 Auto-Submitted: auto-generated The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=ca4ce6a56f9c174917ab33191d367a850fc15c89 commit ca4ce6a56f9c174917ab33191d367a850fc15c89 Author: Jean-Sébastien Pédron AuthorDate: 2025-02-08 20:28:10 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2025-04-07 17:34:40 +0000 linuxkpi: Add `sysfs_create_bin_file()` and `sysfs_remove_bin_file()` They are used by the i915 DRM driver for quite some time, but that code was commented out. It was moved around in Linux 6.8, so instead of figuring out what should be commented out now, let's add an implementation of these functions. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49068 --- sys/compat/linuxkpi/common/include/linux/sysfs.h | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h b/sys/compat/linuxkpi/common/include/linux/sysfs.h index b5ad73e4460b..c6692b803789 100644 --- a/sys/compat/linuxkpi/common/include/linux/sysfs.h +++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h @@ -50,6 +50,15 @@ struct attribute_group { struct attribute **attrs; }; +struct bin_attribute { + struct attribute attr; + size_t size; + ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, + char *, loff_t, size_t); + ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *, + char *, loff_t, size_t); +}; + #define __ATTR(_name, _mode, _show, _store) { \ .attr = { .name = __stringify(_name), .mode = _mode }, \ .show = _show, .store = _store, \ @@ -155,6 +164,80 @@ sysfs_remove_file(struct kobject *kobj, const struct attribute *attr) sysctl_remove_name(kobj->oidp, attr->name, 1, 1); } +static inline int +sysctl_handle_bin_attr(SYSCTL_HANDLER_ARGS) +{ + struct kobject *kobj; + struct bin_attribute *attr; + char *buf; + int error; + ssize_t len; + + kobj = arg1; + attr = (struct bin_attribute *)(intptr_t)arg2; + if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL) + return (ENODEV); + buf = (char *)get_zeroed_page(GFP_KERNEL); + if (buf == NULL) + return (ENOMEM); + + if (attr->read) { + len = attr->read( + NULL, /* <-- struct file, unimplemented */ + kobj, attr, buf, req->oldidx, PAGE_SIZE); + if (len < 0) { + error = -len; + if (error != EIO) + goto out; + } + } + + error = sysctl_handle_opaque(oidp, buf, PAGE_SIZE, req); + if (error != 0 || req->newptr == NULL || attr->write == NULL) + goto out; + + len = attr->write( + NULL, /* <-- struct file, unimplemented */ + kobj, attr, buf, req->newidx, req->newlen); + if (len < 0) + error = -len; +out: + free_page((unsigned long)buf); + + return (error); +} + +static inline int +sysfs_create_bin_file(struct kobject *kobj, const struct bin_attribute *attr) +{ + struct sysctl_oid *oid; + int ctlflags; + + ctlflags = CTLTYPE_OPAQUE | CTLFLAG_MPSAFE; + if (attr->attr.mode & (S_IRUSR | S_IWUSR)) + ctlflags |= CTLFLAG_RW; + else if (attr->attr.mode & S_IRUSR) + ctlflags |= CTLFLAG_RD; + else if (attr->attr.mode & S_IWUSR) + ctlflags |= CTLFLAG_WR; + + oid = SYSCTL_ADD_OID(NULL, SYSCTL_CHILDREN(kobj->oidp), OID_AUTO, + attr->attr.name, ctlflags, kobj, + (uintptr_t)attr, sysctl_handle_bin_attr, "", ""); + if (oid == NULL) + return (-ENOMEM); + + return (0); +} + +static inline void +sysfs_remove_bin_file(struct kobject *kobj, const struct bin_attribute *attr) +{ + + if (kobj->oidp) + sysctl_remove_name(kobj->oidp, attr->attr.name, 1, 1); +} + static inline int sysfs_create_link(struct kobject *kobj __unused, struct kobject *target __unused, const char *name __unused)