From patchwork Mon Aug 24 12:42:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrik Jakobsson X-Patchwork-Id: 7063941 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6962EC05AC for ; Mon, 24 Aug 2015 12:42:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 72F4B20642 for ; Mon, 24 Aug 2015 12:42:16 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5FAE22073E for ; Mon, 24 Aug 2015 12:42:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AEC806E96B; Mon, 24 Aug 2015 05:42:13 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 92B926E96D for ; Mon, 24 Aug 2015 05:42:10 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 24 Aug 2015 05:42:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,737,1432623600"; d="scan'208";a="789846392" Received: from patrik-desktop.isw.intel.com ([10.237.180.143]) by orsmga002.jf.intel.com with ESMTP; 24 Aug 2015 05:42:09 -0700 From: Patrik Jakobsson To: strace-devel@lists.sourceforge.net Date: Mon, 24 Aug 2015 14:42:48 +0200 Message-Id: <1440420170-13337-4-git-send-email-patrik.jakobsson@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1440420170-13337-1-git-send-email-patrik.jakobsson@linux.intel.com> References: <1440420170-13337-1-git-send-email-patrik.jakobsson@linux.intel.com> Cc: intel-gfx@lists.freedesktop.org, ldv@altlinux.org Subject: [Intel-gfx] [PATCH v4 3/5] 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=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 * Makefile.am: Add compilation of drm.c. * defs.h: Add extern declaration of drm_ioctl when drm headers are found. * drm.c: New file. * ioctl.c (ioctl_decode): Dispatch drm ioctls when drm headers are found. Signed-off-by: Patrik Jakobsson --- Makefile.am | 1 + defs.h | 3 ++ drm.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ioctl.c | 4 +++ 4 files changed, 115 insertions(+) create mode 100644 drm.c diff --git a/Makefile.am b/Makefile.am index f70f6d2..c7c6080 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,6 +42,7 @@ strace_SOURCES = \ count.c \ desc.c \ dirent.c \ + drm.c \ epoll.c \ evdev.c \ eventfd.c \ diff --git a/defs.h b/defs.h index bc3bd83..dd3c720 100644 --- a/defs.h +++ b/defs.h @@ -612,6 +612,9 @@ extern const char *sprint_open_modes(int); extern void print_seccomp_filter(struct tcb *tcp, unsigned long); extern int block_ioctl(struct tcb *, const unsigned int, long); +#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H) +extern int drm_ioctl(struct tcb *, const unsigned int, long); +#endif extern int evdev_ioctl(struct tcb *, const unsigned int, long); extern int loop_ioctl(struct tcb *, const unsigned int, long); extern int mtd_ioctl(struct tcb *, const unsigned int, long); diff --git a/drm.c b/drm.c new file mode 100644 index 0000000..0829803 --- /dev/null +++ b/drm.c @@ -0,0 +1,107 @@ +/* + * 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" + +#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H) + +#ifdef HAVE_DRM_H +#include +#else +#include +#endif + +#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 char *drm_get_driver_name(struct tcb *tcp) +{ + char path[PATH_MAX]; + char link[PATH_MAX]; + int ret; + + if (getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1) < 0) + return NULL; + + snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver", + basename(path)); + + ret = readlink(link, path, PATH_MAX - 1); + if (ret < 0) + return NULL; + + path[ret] = '\0'; + return strdup(basename(path)); +} + +static void drm_free_priv(void *data) +{ + free(data); +} + +int drm_is_driver(struct tcb *tcp, const char *name) +{ + char *priv; + + /* + * If no private data is allocated we are detecting the driver name for + * the first time and must resolve it. + */ + if (tcp->priv_data == NULL) { + tcp->priv_data = drm_get_driver_name(tcp); + if (tcp->priv_data == NULL) + return 0; + + tcp->free_priv_data = drm_free_priv; + } + + priv = tcp->priv_data; + + return strncmp(name, priv, DRM_MAX_NAME_LEN) == 0; +} + +int drm_decode_number(struct tcb *tcp, unsigned int code) +{ + return 0; +} + +int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg) +{ + return 0; +} + +#endif /* HAVE_DRM_H || HAVE_DRM_DRM_H */ diff --git a/ioctl.c b/ioctl.c index 284828a..dfd35d8 100644 --- a/ioctl.c +++ b/ioctl.c @@ -248,6 +248,10 @@ ioctl_decode(struct tcb *tcp) case 0x22: return scsi_ioctl(tcp, code, arg); #endif +#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H) + case 'd': + return drm_ioctl(tcp, code, arg); +#endif case 'L': return loop_ioctl(tcp, code, arg); case 'M':