From nobody Thu May 16 20:44:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1591146556; cv=none; d=zohomail.com; s=zohoarc; b=FMv9n6tes+ECey9CqQnUsJICWau5kF6QejtFq0b8/4+F7ePjZzAHl4yxJ26LFe6wyk6Sb7/GNxWfE+8+AdArR7QoIno5xGqpriDHnbqPm9YUpBFE5i/Dkh8NErUNBDjcVaxNZepiHMY+EUUBYdZORMrW5C7BMJBepuPpQX7bHZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591146556; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=UUSQxWaDpxyxAtZg1SBV9KmONViHVaSNBJwzdO/oP4k=; b=YiW78Qb8xD1k5N9zm7490aK4LdRTuADgGdvB94LC1Jv3R7lb7V+fRWcn9IcXNXtyaXI+WwhaVRC43LgVBZ37Q08JW2LKd4eAkmw7qyZVcELmUXvEzspw4tWo0s8DNMCdiEx9h6wT41OZ1ZzP0nPR7txTz56NpZ0u32kYcEbnFK4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591146555867844.7118285647534; Tue, 2 Jun 2020 18:09:15 -0700 (PDT) Received: from localhost ([::1]:42858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgHu6-0001ww-If for importer@patchew.org; Tue, 02 Jun 2020 21:09:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgHtM-0001TW-F0 for qemu-devel@nongnu.org; Tue, 02 Jun 2020 21:08:28 -0400 Received: from lucky1.263xmail.com ([211.157.147.133]:54380) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgHtJ-0002rU-SH for qemu-devel@nongnu.org; Tue, 02 Jun 2020 21:08:27 -0400 Received: from localhost (unknown [192.168.167.16]) by lucky1.263xmail.com (Postfix) with ESMTP id BD205BE8D0; Wed, 3 Jun 2020 09:08:17 +0800 (CST) Received: from localhost.localdomain (unknown [223.72.72.58]) by smtp.263.net (postfix) whith ESMTP id P761T139943940695808S1591146491618573_; Wed, 03 Jun 2020 09:08:18 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: chengang@emindsoft.com.cn X-SENDER: chengang@emindsoft.com.cn X-LOGIN-NAME: chengang@emindsoft.com.cn X-FST-TO: laurent@vivier.eu X-SENDER-IP: 223.72.72.58 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: chengang@emindsoft.com.cn To: laurent@vivier.eu, riku.voipio@iki.fi Subject: [PATCH v5] linux-user: syscall: ioctls: support DRM_IOCTL_VERSION Date: Wed, 3 Jun 2020 09:08:09 +0800 Message-Id: <20200603010809.32139-1-chengang@emindsoft.com.cn> X-Mailer: git-send-email 2.24.0.308.g228f53135a MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=211.157.147.133; envelope-from=chengang@emindsoft.com.cn; helo=lucky1.263xmail.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/02 21:08:18 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chengang@emindsoft.com.cn, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Chen Gang Another DRM_IOCTL_* commands will be done later. Signed-off-by: Chen Gang --- configure | 10 ++++ linux-user/ioctls.h | 5 ++ linux-user/syscall.c | 117 +++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 15 +++++ linux-user/syscall_types.h | 11 ++++ 5 files changed, 158 insertions(+) diff --git a/configure b/configure index e225a1e3ff..3cf28a649a 100755 --- a/configure +++ b/configure @@ -3140,6 +3140,13 @@ if ! check_include "ifaddrs.h" ; then have_ifaddrs_h=3Dno fi =20 +######################################### +# libdrm check +have_drm_h=3Dno +if check_include "libdrm/drm.h" ; then + have_drm_h=3Dyes +fi + ########################################## # VTE probe =20 @@ -7149,6 +7156,9 @@ fi if test "$have_ifaddrs_h" =3D "yes" ; then echo "HAVE_IFADDRS_H=3Dy" >> $config_host_mak fi +if test "$have_drm_h" =3D "yes" ; then + echo "HAVE_DRM_H=3Dy" >> $config_host_mak +fi if test "$have_broken_size_max" =3D "yes" ; then echo "HAVE_BROKEN_SIZE_MAX=3Dy" >> $config_host_mak fi diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 0defa1d8c1..f2e2fa9c87 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -574,6 +574,11 @@ IOCTL_SPECIAL(SIOCDELRT, IOC_W, do_ioctl_rt, MK_PTR(MK_STRUCT(STRUCT_rtentry))) =20 +#ifdef HAVE_DRM_H + IOCTL_SPECIAL(DRM_IOCTL_VERSION, IOC_RW, do_ioctl_drm, + MK_PTR(MK_STRUCT(STRUCT_drm_version))) +#endif + #ifdef TARGET_TIOCSTART IOCTL_IGNORE(TIOCSTART) IOCTL_IGNORE(TIOCSTOP) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5af55fca78..07b7596e0f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -112,6 +112,9 @@ #include #include #include +#ifdef HAVE_DRM_H +#include +#endif #include "linux_loop.h" #include "uname.h" =20 @@ -5275,6 +5278,120 @@ static abi_long do_ioctl_tiocgptpeer(const IOCTLEnt= ry *ie, uint8_t *buf_temp, } #endif =20 +#ifdef HAVE_DRM_H + +static void unlock_drm_version(struct drm_version *host_ver) +{ + if (host_ver->name) { + unlock_user(host_ver->name, 0UL, 0); + } + if (host_ver->date) { + unlock_user(host_ver->date, 0UL, 0); + } + if (host_ver->desc) { + unlock_user(host_ver->desc, 0UL, 0); + } +} + +static inline abi_long target_to_host_drmversion(struct drm_version *host_= ver, + abi_long target_addr) +{ + struct target_drm_version *target_ver; + + if (!lock_user_struct(VERIFY_READ, target_ver, target_addr, 0)) { + return -TARGET_EFAULT; + } + + memset(host_ver, 0, sizeof(*host_ver)); + + __get_user(host_ver->name_len, &target_ver->name_len); + if (host_ver->name_len) { + host_ver->name =3D lock_user(VERIFY_WRITE, target_ver->name, + target_ver->name_len, 0); + if (!host_ver->name) { + goto err; + } + } + + __get_user(host_ver->date_len, &target_ver->date_len); + if (host_ver->date_len) { + host_ver->date =3D lock_user(VERIFY_WRITE, target_ver->date, + target_ver->date_len, 0); + if (!host_ver->date) { + goto err; + } + } + + __get_user(host_ver->desc_len, &target_ver->desc_len); + if (host_ver->desc_len) { + host_ver->desc =3D lock_user(VERIFY_WRITE, target_ver->desc, + target_ver->desc_len, 0); + if (!host_ver->desc) { + goto err; + } + } + + unlock_user_struct(target_ver, target_addr, 0); + return 0; +err: + unlock_drm_version(host_ver); + unlock_user_struct(target_ver, target_addr, 0); + return -ENOMEM; +} + +static inline abi_long host_to_target_drmversion(abi_ulong target_addr, + struct drm_version *host_= ver) +{ + struct target_drm_version *target_ver; + + if (!lock_user_struct(VERIFY_WRITE, target_ver, target_addr, 0)) { + unlock_drm_version(host_ver); + return -TARGET_EFAULT; + } + __put_user(host_ver->version_major, &target_ver->version_major); + __put_user(host_ver->version_minor, &target_ver->version_minor); + __put_user(host_ver->version_patchlevel, &target_ver->version_patchlev= el); + __put_user(host_ver->name_len, &target_ver->name_len); + __put_user(host_ver->date_len, &target_ver->date_len); + __put_user(host_ver->desc_len, &target_ver->desc_len); + if (host_ver->name) { + unlock_user(host_ver->name, target_ver->name, host_ver->name_len); + } + if (host_ver->date) { + unlock_user(host_ver->date, target_ver->date, host_ver->date_len); + } + if (host_ver->desc) { + unlock_user(host_ver->desc, target_ver->desc, host_ver->desc_len); + } + unlock_user_struct(target_ver, target_addr, 0); + return 0; +} + +static abi_long do_ioctl_drm(const IOCTLEntry *ie, uint8_t *buf_temp, + int fd, int cmd, abi_long arg) +{ + struct drm_version *ver; + abi_long ret; + + switch (ie->host_cmd) { + case DRM_IOCTL_VERSION: + ver =3D (struct drm_version *)buf_temp; + ret =3D target_to_host_drmversion(ver, arg); + if (is_error(ret)) { + return ret; + } + ret =3D get_errno(safe_ioctl(fd, ie->host_cmd, ver)); + if (is_error(ret)) { + unlock_drm_version(ver); + return ret; + } + return host_to_target_drmversion(arg, ver); + } + return -TARGET_EFAULT; +} + +#endif + static IOCTLEntry ioctl_entries[] =3D { #define IOCTL(cmd, access, ...) \ { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 152ec637cb..3c261cff0e 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1167,6 +1167,9 @@ struct target_rtc_pll_info { #define TARGET_DM_TARGET_MSG TARGET_IOWRU(0xfd, 0x0e) #define TARGET_DM_DEV_SET_GEOMETRY TARGET_IOWRU(0xfd, 0x0f) =20 +/* drm ioctls */ +#define TARGET_DRM_IOCTL_VERSION TARGET_IOWRU('d', 0x00) + /* from asm/termbits.h */ =20 #define TARGET_NCC 8 @@ -2598,6 +2601,18 @@ struct target_mq_attr { abi_long mq_curmsgs; }; =20 +struct target_drm_version { + int version_major; + int version_minor; + int version_patchlevel; + abi_ulong name_len; + abi_ulong name; + abi_ulong date_len; + abi_ulong date; + abi_ulong desc_len; + abi_ulong desc; +}; + #include "socket.h" =20 #include "errno_defs.h" diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 4e12c1661e..e2b0484f50 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -292,6 +292,17 @@ STRUCT(dm_target_versions, STRUCT(dm_target_msg, TYPE_ULONGLONG) /* sector */ =20 +STRUCT(drm_version, + TYPE_INT, /* version_major */ + TYPE_INT, /* version_minor */ + TYPE_INT, /* version_patchlevel */ + TYPE_ULONG, /* name_len */ + TYPE_PTRVOID, /* name */ + TYPE_ULONG, /* date_len */ + TYPE_PTRVOID, /* date */ + TYPE_ULONG, /* desc_len */ + TYPE_PTRVOID) /* desc */ + STRUCT(file_clone_range, TYPE_LONGLONG, /* src_fd */ TYPE_ULONGLONG, /* src_offset */ --=20 2.24.0.308.g228f53135a