From patchwork Wed Sep 23 02:45:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyungwon Hwang X-Patchwork-Id: 7247091 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 77F25BEEC1 for ; Wed, 23 Sep 2015 02:45:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5062A20A8A for ; Wed, 23 Sep 2015 02:45:31 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F115B20A8F for ; Wed, 23 Sep 2015 02:45:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F5C36EBBC; Tue, 22 Sep 2015 19:45:25 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 323A26EBBA for ; Tue, 22 Sep 2015 19:45:23 -0700 (PDT) Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NV301F57ZNKWI90@mailout2.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 23 Sep 2015 11:45:20 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.112]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 58.8B.05274.04212065; Wed, 23 Sep 2015 11:45:20 +0900 (KST) X-AuditID: cbfee68d-f79ae6d00000149a-b2-560212404610 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id FD.08.18629.F3212065; Wed, 23 Sep 2015 11:45:20 +0900 (KST) Received: from localhost.localdomain.localdomain ([10.252.82.145]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NV300GR1ZNG6Y00@mmp2.samsung.com>; Wed, 23 Sep 2015 11:45:19 +0900 (KST) From: Hyungwon Hwang To: dri-devel@lists.freedesktop.org, ppaalanen@gmail.com, emil.l.velikov@gmail.com Subject: [PATCH v3 2/3] modetest: add atomic modeset support Date: Wed, 23 Sep 2015 11:45:13 +0900 Message-id: <1442976314-5792-2-git-send-email-human.hwang@samsung.com> X-Mailer: git-send-email 2.4.3 In-reply-to: <1442976314-5792-1-git-send-email-human.hwang@samsung.com> References: <1442976314-5792-1-git-send-email-human.hwang@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrILMWRmVeSWpSXmKPExsWyRsSkQNdBiCnMoPsjp8WVr+/ZLPZcvcdk sXRGH6tFa1u1A4vHzll32T3udx9n8ujbsooxgDmKyyYlNSezLLVI3y6BK2P98hVMBZO9K+Y3 vWRuYGyz6WLk4JAQMJFo6fHsYuQEMsUkLtxbzwZiCwmsYJR4tKUMIm4i8X/5NaA4F1B8FqPE 5x9vmCGcNiaJS1/vsINUsQnoSSy49gPMFhEIkdiwZSOYzSygI3H95hZmEFtYwEZixpyzLCA2 i4CqxNPZOxhBbF4BN4nD9/cyQWyTkzi3/gtYDaeAu8S6hltMEBe5Sdz+8IcVZLGEwGc2iXX3 DrBBDBKQ+Db5EAvEN7ISmw4wQ8yRlDi44gbLBEbhBYwMqxhFUwuSC4qT0osM9YoTc4tL89L1 kvNzNzECQ/b0v2e9OxhvH7A+xCjAwajEw/vgC2OYEGtiWXFl7iFGU6ANE5mlRJPzgZGRVxJv aGxmZGFqYmpsZG5ppiTOqyj1M1hIID2xJDU7NbUgtSi+qDQntfgQIxMHp1QDY6k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000@CPGS X-CFilter-Loop: Reflected 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.2 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 This patch adds support for atomic modeset. Using -a option, user can make modeset to use DRM_IOCTL_MODE_ATOMIC instead of legacy IOCTLs. Also, by using -w option, user can set the property as before. Signed-off-by: Hyungwon Hwang --- tests/modetest/modetest.c | 273 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 265 insertions(+), 8 deletions(-) -- 2.4.3 diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 08ecf58..bc5a227 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -1477,25 +1477,32 @@ static int parse_property(struct property_arg *p, const char *arg) static void usage(char *name) { - fprintf(stderr, "usage: %s [-cDdefMPpsCvw]\n", name); + fprintf(stderr, "usage: %s [-acDdefMPpsCvw]\n", name); + fprintf(stderr, "\tA: supported in atomic modeset\n"); + fprintf(stderr, "\tL: supported in legacy modeset\n"); - fprintf(stderr, "\n Query options:\n\n"); + fprintf(stderr, "\n Query options: [AL]\n\n"); fprintf(stderr, "\t-c\tlist connectors\n"); fprintf(stderr, "\t-e\tlist encoders\n"); fprintf(stderr, "\t-f\tlist framebuffers\n"); fprintf(stderr, "\t-p\tlist CRTCs and planes (pipes)\n"); - fprintf(stderr, "\n Test options:\n\n"); + fprintf(stderr, "\n Common Test options: [AL]\n\n"); + fprintf(stderr, "\t-w ::\tset property\n"); + + fprintf(stderr, "\n Atomic Test options: [A]\n\n"); + fprintf(stderr, "\t-a\tuse atomic modeset\n"); + + fprintf(stderr, "\n Legacy test options: [L]\n\n"); fprintf(stderr, "\t-P :x[++][*][@]\tset a plane\n"); fprintf(stderr, "\t-s [,][@]:[-][@]\tset a mode\n"); fprintf(stderr, "\t-C\ttest hw cursor\n"); fprintf(stderr, "\t-v\ttest vsynced page flipping\n"); - fprintf(stderr, "\t-w ::\tset property\n"); fprintf(stderr, "\n Generic options:\n\n"); - fprintf(stderr, "\t-d\tdrop master after mode set\n"); - fprintf(stderr, "\t-M module\tuse the given driver\n"); - fprintf(stderr, "\t-D device\tuse the given device\n"); + fprintf(stderr, "\t-d\tdrop master after mode set [L]\n"); + fprintf(stderr, "\t-M module\tuse the given driver [AL]\n"); + fprintf(stderr, "\t-D device\tuse the given device [AL]\n"); fprintf(stderr, "\n\tDefault is to dump all info.\n"); exit(0); @@ -1554,7 +1561,224 @@ static int pipe_resolve_connectors(struct device *dev, struct pipe_arg *pipe) return 0; } -static char optstr[] = "cdD:efM:P:ps:Cvw:"; +static bool is_obj_id_in_prop_args(struct property_arg *prop_args, + unsigned int prop_count, uint32_t obj_id) +{ + unsigned int i; + + for (i = 0; i < prop_count; i++) + if (obj_id == prop_args[i].obj_id) + return true; + + return false; +} + +static int get_value_in_prop_args(struct property_arg *prop_args, + unsigned int prop_count, uint32_t obj_id, + const char *name, uint64_t *out) +{ + unsigned int i; + + for (i = 0; i < prop_count; i++) { + if (prop_args[i].obj_id == obj_id && + !strcmp(prop_args[i].name, name)) { + *out = prop_args[i].value; + return 0; + } + } + + return -1; +} + +static uint32_t get_plane_prop_id(struct resources *res, uint32_t obj_id, + const char *name) +{ + drmModePropertyRes *props_info; + struct plane *plane; + unsigned int i, j; + + for (i = 0; i < res->plane_res->count_planes; i++) { + plane = &res->planes[i]; + if (plane->plane->plane_id != obj_id) + continue; + + for (j = 0; j < plane->props->count_props; j++) { + props_info = plane->props_info[j]; + if (!strcmp(props_info->name, name)) + return props_info->prop_id; + } + } + + return 0; +} + +static int allocate_fb(int fd, drmModeAtomicReqPtr req, struct resources *res, + uint32_t width, uint32_t height, uint32_t pixel_format, + int pattern, struct bo **bo, uint32_t *fb_id) +{ + uint32_t handles[4] = {0}, pitches[4] = {0}, offsets[4] = {0}; + int ret; + + *bo = bo_create(fd, pixel_format, width, height, + handles, pitches, offsets, pattern); + if (*bo == NULL) { + fprintf(stderr, "failed to create bo (%ux%u): %s\n", + width, height, strerror(errno)); + return -1; + } + + ret = drmModeAddFB2(fd, width, height, pixel_format, + handles, pitches, offsets, fb_id, 0); + if (ret) { + fprintf(stderr, "failed to add fb (%ux%u): %s\n", + width, height, strerror(errno)); + bo_destroy(*bo); + return ret; + } + + return 0; +} + +static int allocate_fbs(struct device *dev, drmModeAtomicReqPtr req, + struct resources *res, struct property_arg *prop_args, + unsigned int prop_count, struct bo **bo, uint32_t *fb_id) +{ + uint32_t plane_id, fb_obj_id, pixel_format; + uint64_t width, height; + int ret = 0, i; + + for (i = 0; i < (int)res->plane_res->count_planes; i++) { + plane_id = res->planes[i].plane->plane_id; + if (!is_obj_id_in_prop_args(prop_args, prop_count, plane_id)) + continue; + + fb_obj_id = get_plane_prop_id(res, plane_id, "FB_ID"); + if (!fb_obj_id) { + fprintf(stderr, "plane(%u) does not exist\n", plane_id); + goto err; + } + + ret = get_value_in_prop_args(prop_args, prop_count, plane_id, + "SRC_W", &width); + if (ret < 0) { + fprintf(stderr, "SRC_W for plane (%u) must be set\n", plane_id); + goto err; + } + + ret = get_value_in_prop_args(prop_args, prop_count, plane_id, + "SRC_H", &height); + if (ret < 0) { + fprintf(stderr, "SRC_H for plane (%u) must be set\n", plane_id); + goto err; + } + + pixel_format = DRM_FORMAT_XRGB8888; + + ret = allocate_fb(dev->fd, req, res, width, height, pixel_format, + PATTERN_SMPTE, &bo[i], &fb_id[i]); + if (ret < 0) + goto err; + + ret = drmModeAtomicAddProperty(req, plane_id, fb_obj_id, fb_id[i]); + if (ret < 0) { + fprintf(stderr, "failed to add atomic property for atomic modeset\n"); + goto err; + } + } + + return 0; + +err: + while (i > -1) { + if (!fb_id[i]) + continue; + + drmModeRmFB(dev->fd, fb_id[i]); + bo_destroy(bo[i]); + i--; + } + + return ret; +} + +static void deallocate_fbs(int fd, int num_planes, uint32_t *fb_id, struct bo **bo) +{ + int i; + + for (i = 0; i < num_planes; i++) { + if (!fb_id[i]) + continue; + + drmModeRmFB(fd, fb_id[i]); + bo_destroy(bo[i]); + } +} + +static int atomic_modeset(struct device *dev, drmModeAtomicReqPtr req, + struct property_arg *prop_args, unsigned int prop_count) +{ + unsigned int num_planes; + const char *obj_type = NULL; + uint32_t flags = 0; + uint32_t *fb_id; + struct bo **bo; + int ret, i; + + for (i = 0; (unsigned int)i < prop_count; ++i) { + ret = get_prop_info(dev->resources, &prop_args[i], obj_type); + if (ret < 0) + return ret; + + ret = drmModeAtomicAddProperty(req, prop_args[i].obj_id, + prop_args[i].prop_id, prop_args[i].value); + if (ret < 0) { + fprintf(stderr, "failed to add property for atomic modeset (%d)\n", + ret); + return ret; + } + } + + num_planes = dev->resources->plane_res->count_planes; + + bo = calloc(num_planes, sizeof(*bo)); + if (!bo) { + fprintf(stderr, "failed to allocate memory fo bo array\n"); + return -1; + } + + fb_id = calloc(num_planes, sizeof(*fb_id)); + if (!fb_id) { + fprintf(stderr, "failed to allocate memory fo fb_id array\n"); + free(bo); + return -1; + } + + ret = allocate_fbs(dev, req, dev->resources, prop_args, prop_count, bo, fb_id); + if (ret < 0) { + free(fb_id); + free(bo); + return ret; + } + + ret = drmModeAtomicCommit(dev->fd, req, flags, NULL); + if (ret < 0) { + fprintf(stderr, "failed to commit for atomic modeset\n"); + deallocate_fbs(dev->fd, num_planes, fb_id, bo); + free(fb_id); + free(bo); + return ret; + } + + getchar(); + + deallocate_fbs(dev->fd, num_planes, fb_id, bo); + free(fb_id); + free(bo); + + return 0; +} + +static char optstr[] = "acdD:efM:P:ps:Cvw:"; int main(int argc, char **argv) { @@ -1574,6 +1798,8 @@ int main(int argc, char **argv) struct pipe_arg *pipe_args = NULL; struct plane_arg *plane_args = NULL; struct property_arg *prop_args = NULL; + drmModeAtomicReqPtr req = NULL; + bool is_atomic = false; unsigned int args = 0; int ret; @@ -1584,6 +1810,10 @@ int main(int argc, char **argv) args++; switch (c) { + case 'a': + is_atomic = true; + args--; + break; case 'c': connectors = 1; break; @@ -1705,6 +1935,22 @@ int main(int argc, char **argv) return -1; } + if (is_atomic) { + req = drmModeAtomicAlloc(); + if (req == NULL) { + fprintf(stderr, "failed to allocate drmModeAtomicReqPtr\n"); + return 1; + } + + ret = drmSetClientCap(dev.fd, DRM_CLIENT_CAP_ATOMIC, 1); + if (ret) { + fprintf(stderr, "Kernel DRM driver is not capable of atomic modeset\n"); + drmModeAtomicFree(req); + + return 1; + } + } + dev.resources = get_resources(&dev); if (!dev.resources) { drmClose(dev.fd); @@ -1727,6 +1973,17 @@ int main(int argc, char **argv) dump_resource(&dev, planes); dump_resource(&dev, framebuffers); + if (is_atomic) { + ret = atomic_modeset(&dev, req, prop_args, prop_count); + if (ret < 0) + fprintf(stderr, "failed to atomic modeset (%s)\n", + strerror(errno)); + + free_resources(dev.resources); + drmModeAtomicFree(req); + return ret; + } + for (i = 0; i < prop_count; ++i) set_property(&dev, &prop_args[i]);