From patchwork Wed Dec 21 00:13:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Kristian_H=C3=B8gsberg?= X-Patchwork-Id: 9482395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2858560237 for ; Wed, 21 Dec 2016 00:13:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1657D28159 for ; Wed, 21 Dec 2016 00:13:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0893428306; Wed, 21 Dec 2016 00:13:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F0D628159 for ; Wed, 21 Dec 2016 00:13:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0B2346EF5C; Wed, 21 Dec 2016 00:13:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 802B46EF5C for ; Wed, 21 Dec 2016 00:13:41 +0000 (UTC) Received: by mail-pg0-x243.google.com with SMTP id w68so7997629pgw.3 for ; Tue, 20 Dec 2016 16:13:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=18d3RxfNiB153EKADbJaLDftDc0xycnj2v/+trax1kQ=; b=lsYm537kNc7KibKn81ZWhkjIwm/9ypIFzvFKQyy0hupzbm85FFfeN9cJR6hS2OgU+T NW/lzjmZCQk53nLknp4fmmUEsPQNM7YmpdfLrzkqw9D+d5MLn2VXY75YxdSdKzZSeIM8 EApWEkKm1Cob7sAZn56xcdz/dmnm52YfjhmXT+sAMGvErNiEzz334Ayp7mlyMN4sh43e ysPWgOETl8OW7d5exq8IGjioGPTlkuqfq3/3KVrMoA+Z4L9Rd0962b8aoJFMpdXLnNvv tTU6T26Mgkbym03V2rL8QFl5PHPTzV17AIGtaonOwWN3hrFH9m6bjWVGz25DlfMQgIO/ fVaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=18d3RxfNiB153EKADbJaLDftDc0xycnj2v/+trax1kQ=; b=ulzfNTw1dnNeSzurpYte0oc7qHSlridxKMuMu97dFE8EzLWtX7tamyU4+lRYPBqGD4 w4dPJ1mtra3DN3j5tx0bBRshYSuOjrNekjHP/YIST/fz5E2vuGYLB85J+8QZxkHtk1+o VR91jWC+H2JhieNHXnZS5FchKSBhyAETtB2aoL2Ci3uNyjIkiq6rUzvN+mmyJqsM2drR /hncDf6k6E1U+SH8CLKHKIUQSjovgKf8ZAu1DWY3MWSiB7E/ajJpgGUd29USsvOt1sly aZeLVbcWclnXcN7jdJmuw9AePXUgFvPoSpdp/AEgvQF6Jgis6275FeEE78IwQYD2CN0I plTQ== X-Gm-Message-State: AIkVDXIp/M+TjBZqFEh9LWUarUmaMM6TQDuP2UCeyCfjtBqYAb0chHX0+5ZbQudqLRRC/A== X-Received: by 10.98.64.195 with SMTP id f64mr1662869pfd.16.1482279220659; Tue, 20 Dec 2016 16:13:40 -0800 (PST) Received: from owl.local ([2620:15c:f:fd00:196b:357f:d485:3c17]) by smtp.gmail.com with ESMTPSA id h185sm41612032pfg.90.2016.12.20.16.13.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Dec 2016 16:13:40 -0800 (PST) From: "Kristian H. Kristensen" To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] Add DRM_IOCTL_MODE_GETPLANE2 ioctl wrapper Date: Tue, 20 Dec 2016 16:13:32 -0800 Message-Id: <20161221001333.21941-1-hoegsberg@gmail.com> X-Mailer: git-send-email 2.9.3 Cc: ben@bwidawsk.net, "Kristian H. Kristensen" 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-Virus-Scanned: ClamAV using ClamSMTP From: "Kristian H. Kristensen" This adds support for the new DRM_IOCTL_MODE_GETPLANE2 ioctl. For older kernels drmModeGetPlane2() falls back to DRM_IOCTL_MODE_GETPLANE and return the new, bigger drmModePlaneRec, reporting 0 modifiers. BUG=chrome-os-partner:56407 TEST=modetest with next commit reports modifiers Change-Id: I9cf9979c0b72933bad661fd03b9beebb36120dfd Reviewed-by: Ben Widawsky --- include/drm/drm.h | 1 + include/drm/drm_mode.h | 27 +++++++++++++++++++++++++++ xf86drmMode.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- xf86drmMode.h | 4 ++++ 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/include/drm/drm.h b/include/drm/drm.h index f6fd5c2..09d4262 100644 --- a/include/drm/drm.h +++ b/include/drm/drm.h @@ -799,6 +799,7 @@ extern "C" { #define DRM_IOCTL_MODE_DESTROY_DUMB DRM_IOWR(0xB4, struct drm_mode_destroy_dumb) #define DRM_IOCTL_MODE_GETPLANERESOURCES DRM_IOWR(0xB5, struct drm_mode_get_plane_res) #define DRM_IOCTL_MODE_GETPLANE DRM_IOWR(0xB6, struct drm_mode_get_plane) +#define DRM_IOCTL_MODE_GETPLANE2 DRM_IOWR(0xB6, struct drm_mode_get_plane2) #define DRM_IOCTL_MODE_SETPLANE DRM_IOWR(0xB7, struct drm_mode_set_plane) #define DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, struct drm_mode_fb_cmd2) #define DRM_IOCTL_MODE_OBJ_GETPROPERTIES DRM_IOWR(0xB9, struct drm_mode_obj_get_properties) diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h index df0e350..ce773fa 100644 --- a/include/drm/drm_mode.h +++ b/include/drm/drm_mode.h @@ -193,6 +193,33 @@ struct drm_mode_get_plane { __u64 format_type_ptr; }; +struct drm_format_modifier { + /* Bitmask of formats in get_plane format list this info + * applies to. */ + __u64 formats; + + /* This modifier can be used with the format for this plane. */ + __u64 modifier; +}; + +struct drm_mode_get_plane2 { + __u32 plane_id; + + __u32 crtc_id; + __u32 fb_id; + + __u32 possible_crtcs; + __u32 gamma_size; + + __u32 count_format_types; + __u64 format_type_ptr; + + /* New in v2 */ + __u32 count_format_modifiers; + __u32 flags; + __u64 format_modifier_ptr; +}; + struct drm_mode_get_plane_res { __u64 plane_id_ptr; __u32 count_planes; diff --git a/xf86drmMode.c b/xf86drmMode.c index fb22f68..298d502 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -990,15 +990,15 @@ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id, return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s); } -drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id) +static drmModePlanePtr get_plane(unsigned long cmd, int fd, uint32_t plane_id) { - struct drm_mode_get_plane ovr, counts; + struct drm_mode_get_plane2 ovr, counts; drmModePlanePtr r = 0; retry: memclear(ovr); ovr.plane_id = plane_id; - if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr)) + if (drmIoctl(fd, cmd, &ovr)) return 0; counts = ovr; @@ -1010,11 +1010,21 @@ retry: goto err_allocs; } - if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr)) + if (ovr.count_format_modifiers) { + ovr.format_modifier_ptr = + VOID2U64(drmMalloc(ovr.count_format_modifiers * + sizeof(struct drm_format_modifier))); + if (!ovr.format_modifier_ptr) + goto err_allocs; + } + + if (drmIoctl(fd, cmd, &ovr)) goto err_allocs; - if (counts.count_format_types < ovr.count_format_types) { + if (counts.count_format_types < ovr.count_format_types || + counts.count_format_modifiers < ovr.count_format_modifiers) { drmFree(U642VOID(ovr.format_type_ptr)); + drmFree(U642VOID(ovr.format_modifier_ptr)); goto retry; } @@ -1022,6 +1032,7 @@ retry: goto err_allocs; r->count_formats = ovr.count_format_types; + r->count_format_modifiers = ovr.count_format_modifiers; r->plane_id = ovr.plane_id; r->crtc_id = ovr.crtc_id; r->fb_id = ovr.fb_id; @@ -1033,20 +1044,48 @@ retry: drmFree(r->formats); drmFree(r); r = 0; + goto err_allocs; + } + + r->format_modifiers = + drmAllocCpy(U642VOID(ovr.format_modifier_ptr), + ovr.count_format_modifiers, + sizeof(struct drm_format_modifier)); + if (ovr.count_format_modifiers && !r->format_modifiers) { + drmFree(r->formats); + drmFree(r); + r = 0; } err_allocs: drmFree(U642VOID(ovr.format_type_ptr)); + drmFree(U642VOID(ovr.format_modifier_ptr)); return r; } +drmModePlanePtr drmModeGetPlane2(int fd, uint32_t plane_id) +{ + drmModePlanePtr r = get_plane(DRM_IOCTL_MODE_GETPLANE2, fd, plane_id); + + if (r || errno != EINVAL) + return r; + + return get_plane(DRM_IOCTL_MODE_GETPLANE, fd, plane_id); +} + +drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id) +{ + return get_plane(DRM_IOCTL_MODE_GETPLANE, fd, plane_id); +} + void drmModeFreePlane(drmModePlanePtr ptr) { if (!ptr) return; drmFree(ptr->formats); + drmFree(ptr->format_modifiers); drmFree(ptr); } diff --git a/xf86drmMode.h b/xf86drmMode.h index b684967..044f38e 100644 --- a/xf86drmMode.h +++ b/xf86drmMode.h @@ -328,6 +328,9 @@ typedef struct _drmModePlane { uint32_t possible_crtcs; uint32_t gamma_size; + + uint32_t count_format_modifiers; + struct drm_format_modifier *format_modifiers; } drmModePlane, *drmModePlanePtr; typedef struct _drmModePlaneRes { @@ -479,6 +482,7 @@ extern int drmModePageFlipTarget(int fd, uint32_t crtc_id, uint32_t fb_id, extern drmModePlaneResPtr drmModeGetPlaneResources(int fd); extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id); +extern drmModePlanePtr drmModeGetPlane2(int fd, uint32_t plane_id); extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id, uint32_t fb_id, uint32_t flags, int32_t crtc_x, int32_t crtc_y,