From patchwork Mon Feb 2 00:14:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 5757871 Return-Path: X-Original-To: patchwork-dri-devel@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 97B64BF440 for ; Mon, 2 Feb 2015 00:12:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD91720253 for ; Mon, 2 Feb 2015 00:12:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 861E520109 for ; Mon, 2 Feb 2015 00:12:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 646146E398; Sun, 1 Feb 2015 16:12:12 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by gabe.freedesktop.org (Postfix) with ESMTP id F1A1B6E396 for ; Sun, 1 Feb 2015 16:12:10 -0800 (PST) Received: by mail-wi0-f173.google.com with SMTP id r20so13272322wiv.0 for ; Sun, 01 Feb 2015 16:12:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LnqZ6NfWGqj8+Days7e3rcjd4I1bTVVQggm3rxygLG4=; b=du3f3g/ptJzpIlCrCF7Z2Cx4/zncYgU0717m01qtMD5BprhvNMPk7vlpxJiM1Xyaq2 VuI4Wer8Lprys0rxwkvWBOQ60icATtB2fUM4l/1h+0/n07kz4svGRbQ/fisE455KDs6h 5a9ikSmntgbGIAIXiOTKyp0Jz3/2ogFuyXPpueoA7swTBP2oVadeBU9gsM9ydNuUhkmv hMwxv3w7MzDzl4zScxzCtpiRDVaLSf2bES1wtdUHdgp1bnlMdei32U196QRiTMfg6QE0 W6JegSpB7FbLQRL0bZ/dFG8JmyoxxmiV+HTjbY4BFkmWNb3svOhcqWKqNyo/KBtUH+T7 2JJw== X-Received: by 10.180.103.102 with SMTP id fv6mr19106637wib.38.1422835930306; Sun, 01 Feb 2015 16:12:10 -0800 (PST) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by mx.google.com with ESMTPSA id g8sm12967743wiy.6.2015.02.01.16.12.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 01 Feb 2015 16:12:09 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm: add drmGet{Device, Render}NameFrom{Render, Device}Fd helpers Date: Mon, 2 Feb 2015 00:14:54 +0000 Message-Id: <1422836095-8547-2-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422836095-8547-1-git-send-email-emil.l.velikov@gmail.com> References: <1422836095-8547-1-git-send-email-emil.l.velikov@gmail.com> Cc: David Herrmann , Daniel Vetter , emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, 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 Currently most places assume reliable primary <> render node mapping. Although this may work in some cases, it is not correct. Add a couple of helpers that hide the details and safes all the guesswork for the user. Cc: Daniel Vetter Cc: David Herrmann Signed-off-by: Emil Velikov --- xf86drm.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ xf86drm.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/xf86drm.c b/xf86drm.c index 345325a..6af7ac0 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2607,3 +2607,57 @@ int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) return 0; } +char *drmGetDeviceNameFromRenderFD(int fd) +{ + + struct stat sbuf; + char name[64], buf[64]; + int maj, min, i; + + if (!fstat(fd, &sbuf)) + return NULL; + + if (!S_ISCHR(sbuf.st_mode)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min); + + for (i = 0; i < DRM_MAX_MINOR; i++) { + snprintf(name, sizeof(name), DRM_DEV_NAME, buf, i); + if (stat(name, &sbuf) == 0) { + snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME, i); + return strdup(name); + } + } + return NULL; +} + +char *drmGetRenderNameFromDeviceFD(int fd) +{ + struct stat sbuf; + char name[64], buf[64]; + int maj, min, i; + + if (!fstat(fd, &sbuf)) + return NULL; + + if (!S_ISCHR(sbuf.st_mode)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min); + + for (i = 128; i < (128 + DRM_MAX_MINOR); i++) { + snprintf(name, sizeof(name), DRM_DEV_NAME, buf, i); + if (stat(name, &sbuf) == 0) { + snprintf(name, sizeof(name), DRM_RENDER_DEV_NAME, DRM_DIR_NAME, i); + return strdup(name); + } + } + return NULL; +} diff --git a/xf86drm.h b/xf86drm.h index bfd0670..bca5887 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -740,6 +740,9 @@ extern char *drmGetDeviceNameFromFd(int fd); extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd); extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle); +extern char *drmGetRenderNameFromDeviceFD(int fd); +extern char *drmGetDeviceNameFromRenderFD(int fd); + #if defined(__cplusplus) || defined(c_plusplus) } #endif