From patchwork Tue Jun 9 11:26:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrik Jakobsson X-Patchwork-Id: 6571361 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C17299F3E6 for ; Tue, 9 Jun 2015 11:26:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B3F69204E2 for ; Tue, 9 Jun 2015 11:26:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id CB59F204DE for ; Tue, 9 Jun 2015 11:26:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D1416E392; Tue, 9 Jun 2015 04:26:07 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id EEC2689949 for ; Tue, 9 Jun 2015 04:26:05 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 09 Jun 2015 04:26:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,579,1427785200"; d="scan'208";a="743564430" Received: from rpjakobs-thinkcentre-e73.isw.intel.com ([10.237.180.166]) by orsmga002.jf.intel.com with ESMTP; 09 Jun 2015 04:25:58 -0700 From: Patrik Jakobsson To: strace-devel@lists.sourceforge.net Date: Tue, 9 Jun 2015 13:26:42 +0200 Message-Id: <1433849204-4125-3-git-send-email-patrik.jakobsson@linux.intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433849204-4125-1-git-send-email-patrik.jakobsson@linux.intel.com> References: <1433849204-4125-1-git-send-email-patrik.jakobsson@linux.intel.com> Cc: intel-gfx@lists.freedesktop.org, "Dmitry V. Levin" Subject: [Intel-gfx] [PATCH 2/4] drm: Add dispatcher and driver identification for DRM X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Patrik Jakobsson --- Makefile.am | 1 + defs.h | 6 ++++- drm.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ io.c | 2 +- ioctl.c | 13 ++++++++- 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 drm.c diff --git a/Makefile.am b/Makefile.am index 549aebc..50d5140 100644 --- a/Makefile.am +++ b/Makefile.am @@ -121,6 +121,7 @@ strace_SOURCES = \ utime.c \ utimes.c \ v4l2.c \ + drm.c \ vsprintf.c \ wait.c \ xattr.c diff --git a/defs.h b/defs.h index 77c819c..f77330b 100644 --- a/defs.h +++ b/defs.h @@ -559,7 +559,7 @@ extern const struct_ioctlent *ioctl_lookup(const unsigned int); extern const struct_ioctlent *ioctl_next_match(const struct_ioctlent *); extern void ioctl_print_code(const unsigned int); extern int ioctl_decode(struct tcb *, const unsigned int, long); -extern int ioctl_decode_command_number(const unsigned int); +extern int ioctl_decode_command_number(struct tcb *, const unsigned int); extern int block_ioctl(struct tcb *, const unsigned int, long); extern int evdev_ioctl(struct tcb *, const unsigned int, long); extern int loop_ioctl(struct tcb *, const unsigned int, long); @@ -572,6 +572,10 @@ extern int term_ioctl(struct tcb *, const unsigned int, long); extern int ubi_ioctl(struct tcb *, const unsigned int, long); extern int v4l2_ioctl(struct tcb *, const unsigned int, long); +extern int drm_is_priv(const unsigned int); +extern int drm_is_driver(struct tcb *tcp, const char *name); +extern int drm_ioctl(struct tcb *, const unsigned int, long); + extern int tv_nz(const struct timeval *); extern int tv_cmp(const struct timeval *, const struct timeval *); extern double tv_float(const struct timeval *); diff --git a/drm.c b/drm.c new file mode 100644 index 0000000..56ef98b --- /dev/null +++ b/drm.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Patrik Jakobsson + */ + +#include "defs.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRM_MAX_NAME_LEN 128 + +inline int drm_is_priv(const unsigned int num) +{ + return (_IOC_NR(num) >= DRM_COMMAND_BASE && + _IOC_NR(num) < DRM_COMMAND_END); +} + +static int drm_get_driver_name(struct tcb *tcp, char *name, size_t bufsize) +{ + char path[PATH_MAX]; + char link[PATH_MAX]; + int ret; + + ret = getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1); + if (!ret) + return ret; + + snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver", + basename(path)); + + ret = readlink(link, path, PATH_MAX - 1); + if (ret < 0) + return ret; + + path[ret] = '\0'; + strncpy(name, basename(path), bufsize); + + return 0; +} + +int drm_is_driver(struct tcb *tcp, const char *name) +{ + char drv[DRM_MAX_NAME_LEN]; + int ret; + + ret = drm_get_driver_name(tcp, drv, DRM_MAX_NAME_LEN); + if (ret) + return 0; + + return strcmp(name, drv) == 0; +} + +int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg) +{ + return 0; +} diff --git a/io.c b/io.c index 30ed578..6810a45 100644 --- a/io.c +++ b/io.c @@ -391,7 +391,7 @@ SYS_FUNC(ioctl) if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); tprints(", "); - if (!ioctl_decode_command_number(tcp->u_arg[1])) { + if (!ioctl_decode_command_number(tcp, tcp->u_arg[1])) { iop = ioctl_lookup(tcp->u_arg[1]); if (iop) { tprints(iop->symbol); diff --git a/ioctl.c b/ioctl.c index c67d048..690e7aa 100644 --- a/ioctl.c +++ b/ioctl.c @@ -181,8 +181,14 @@ hiddev_decode_number(unsigned int arg) return 0; } +static int +drm_decode_number(struct tcb *tcp, unsigned int arg) +{ + return 0; +} + int -ioctl_decode_command_number(unsigned int arg) +ioctl_decode_command_number(struct tcb *tcp, unsigned int arg) { switch (_IOC_TYPE(arg)) { case 'E': @@ -216,6 +222,8 @@ ioctl_decode_command_number(unsigned int arg) return 1; } return 0; + case 'd': + return drm_decode_number(tcp, arg); default: return 0; } @@ -252,6 +260,8 @@ ioctl_decode(struct tcb *tcp, unsigned int code, long arg) return ubi_ioctl(tcp, code, arg); case 'V': return v4l2_ioctl(tcp, code, arg); + case 'd': + return drm_ioctl(tcp, code, arg); case '=': return ptp_ioctl(tcp, code, arg); #ifdef HAVE_LINUX_INPUT_H @@ -284,6 +294,7 @@ ioctl_decode(struct tcb *tcp, unsigned int code, long arg) * d sys/des.h (possible overlap) * d vax/dkio.h (possible overlap) * d vaxuba/rxreg.h (possible overlap) + * d drm/drm.h * f sys/filio.h * g sunwindow/win_ioctl.h -no overlap- * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-