From patchwork Mon Feb 2 00:14:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 5757861 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 9A249BF6C3 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 A2A6C200E3 for ; Mon, 2 Feb 2015 00:12:16 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 668F02020E for ; Mon, 2 Feb 2015 00:12:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 965F16E399; Sun, 1 Feb 2015 16:12:13 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f172.google.com (mail-we0-f172.google.com [74.125.82.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 356986E39B for ; Sun, 1 Feb 2015 16:12:12 -0800 (PST) Received: by mail-we0-f172.google.com with SMTP id q59so36122259wes.3 for ; Sun, 01 Feb 2015 16:12:11 -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=3S8UPHKlaPKyk+NXDBYDElJJjPqBj9OGJD17SQ1EWuk=; b=Q4AfUld2dRWpef9S6KT+6oZ2PBDY80+ZoZyZeHiO/MGWebSTkM6MPyvF+F/Z6ht8w6 mzlw/KK1JO1HQsvGTkzaTG895qzUuYlrRH06QFi0/MT436DNkWH9cfUu59dtIGII5q/z pPpJXyiyhBQnzQc85PCmsmNHj+tGJBi/C9vmR0EQXpv9CAXtznCXr//bEodPEmY7tw4z +yT5KL75/QB0dXoS20o3CfgFcyTslWUQNVNHklo/G6nXYLlIjr/KnTMFD7XP5zjvNIYv PcyDc559ykMKZFkAr8MCPbqX7tMHFP2mNP5yBYo6XZtO7JKwEkDM67GluZUTSz/Sf/2U AkIg== X-Received: by 10.180.149.197 with SMTP id uc5mr18258102wib.80.1422835931434; Sun, 01 Feb 2015 16:12:11 -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.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 01 Feb 2015 16:12:10 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] libdrm: add drmGetNodeType() helper Date: Mon, 2 Feb 2015 00:14:55 +0000 Message-Id: <1422836095-8547-3-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 The add a simple helper which returns the node type of the opened fd. Likely to be used in conjunction with the previous two helpers. Cc: Daniel Vetter Cc: David Herrmann Signed-off-by: Emil Velikov --- xf86drm.c | 43 +++++++++++++++++++++++++++++++++++++++---- xf86drm.h | 7 +++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 6af7ac0..a70c0dd 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -85,10 +85,6 @@ #define DRM_MSG_VERBOSITY 3 -#define DRM_NODE_CONTROL 0 -#define DRM_NODE_PRIMARY 1 -#define DRM_NODE_RENDER 2 - static drmServerInfoPtr drm_server_info; void drmSetServerInfo(drmServerInfoPtr info) @@ -2607,6 +2603,45 @@ int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) return 0; } +int drmGetNodeType(int fd, drmNodeType *type) +{ + struct stat sbuf; + char name[64]; + dev_t d; + int i; + + if (!fstat(fd, &sbuf)) + return -errno; + + d = sbuf.st_rdev; + + for (i = 0; i < DRM_MAX_MINOR; i++) { + snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME, i); + if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) { + *type = DRM_NODE_PRIMARY; + return 0; + } + } + + for (i = 64; i < (64 + DRM_MAX_MINOR); i++) { + snprintf(name, sizeof(name), DRM_CONTROL_DEV_NAME, DRM_DIR_NAME, i); + if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) { + *type = DRM_NODE_CONTROL; + return 0; + } + } + + for (i = 128; i < (128 + DRM_MAX_MINOR); i++) { + snprintf(name, sizeof(name), DRM_RENDER_DEV_NAME, DRM_DIR_NAME, i); + if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) { + *type = DRM_NODE_RENDER; + return 0; + } + } + + return -EINVAL; +} + char *drmGetDeviceNameFromRenderFD(int fd) { diff --git a/xf86drm.h b/xf86drm.h index bca5887..7d67df9 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -740,6 +740,13 @@ 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); +typedef enum _drmNodeType { + DRM_NODE_CONTROL = 0, + DRM_NODE_PRIMARY = 1, + DRM_NODE_RENDER = 2 +} drmNodeType, *drmNodeTypePtr; + +extern int drmGetNodeType(int fd, drmNodeType *type); extern char *drmGetRenderNameFromDeviceFD(int fd); extern char *drmGetDeviceNameFromRenderFD(int fd);