From patchwork Wed Aug 19 00:58:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyungwon Hwang X-Patchwork-Id: 7034341 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 C24DDC05AC for ; Wed, 19 Aug 2015 00:59:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8FD7E20592 for ; Wed, 19 Aug 2015 00:59:01 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5768F2055D for ; Wed, 19 Aug 2015 00:59:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1F7466E75E; Tue, 18 Aug 2015 17:58:59 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8D0396E723 for ; Tue, 18 Aug 2015 17:58:53 -0700 (PDT) Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NTB02SPM1E3B520@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 19 Aug 2015 09:58:51 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.113]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 23.BD.17770.BC4D3D55; Wed, 19 Aug 2015 09:58:51 +0900 (KST) X-AuditID: cbfee691-f79ca6d00000456a-7f-55d3d4cbcc89 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 3E.14.07062.BC4D3D55; Wed, 19 Aug 2015 09:58:51 +0900 (KST) Received: from localhost.localdomain.localdomain ([10.252.82.145]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NTB0003C1DZWBK0@mmp1.samsung.com>; Wed, 19 Aug 2015 09:58:50 +0900 (KST) From: Hyungwon Hwang To: dri-devel@lists.freedesktop.org, human.hwang@samsung.com Subject: [PATCH 5/6] modetest: add atomic modeset support Date: Wed, 19 Aug 2015 09:58:43 +0900 Message-id: <1439945924-22630-5-git-send-email-human.hwang@samsung.com> X-Mailer: git-send-email 2.4.3 In-reply-to: <1439945924-22630-1-git-send-email-human.hwang@samsung.com> References: <1439945924-22630-1-git-send-email-human.hwang@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOLMWRmVeSWpSXmKPExsWyRsSkUPf0lcuhBus+q1hc+fqezWLpjD5W ByaP+93HmTz6tqxiDGCK4rJJSc3JLEst0rdL4Mr4vWolU8Fh94r//34yNTBOtOxi5OSQEDCR +HnqIguELSZx4d56ti5GLg4hgRWMEle3vGKBKZp17iwrRGIpo8TsMw0sEE4bk8TN5Y9ZQarY BPQkFlz7wd7FyMEhImAjMediBkhYWMBSYvWuGcwgNouAqkTfve2MIDavgLtEz7xXjBAL5CTO rf8CtoxTwENixfbHbCC2EFDNzn8nmSBqbrNJTNmfDTFHQOLb5EMsIKskBGQlNh1ghiiRlDi4 4gbLBEahBYwMqxhFUwuSC4qT0otM9YoTc4tL89L1kvNzNzECw+/0v2cTdzDeP2B9iFGAg1GJ h3fGtsuhQqyJZcWVuYcYTYE2TGSWEk3OBwZ5Xkm8obGZkYWpiamxkbmlmZI4r470z2AhgfTE ktTs1NSC1KL4otKc1OJDjEwcnFINjLuYynl38jVOnNryU/3H1aOfbVltt2yN0+HTNrz/kWM2 e9y0p0mtjL7TP9ZMX1Jt2rUm2mH9qvBXn2q63x8/v6DwwZUP98qLTy6X1FiaytVS3Hf3SMWx A7Md5htz/I5eu1ZHOyjmiOeV91cVeP48PmckNmtu2QXvQMGInx6/zjBNVpvafd5bxUKJpTgj 0VCLuag4EQD17AOPOgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrKLMWRmVeSWpSXmKPExsVy+t9jAd3TVy6HGuw/JG9x5et7NoulM/pY HZg87ncfZ/Lo27KKMYApqoHRJiM1MSW1SCE1Lzk/JTMv3VbJOzjeOd7UzMBQ19DSwlxJIS8x N9VWycUnQNctMwdogZJCWWJOKVAoILG4WEnfDtOE0BA3XQuYxghd35AguB4jAzSQsIYx4/eq lUwFh90r/v/7ydTAONGyi5GTQ0LARGLWubOsELaYxIV769m6GLk4hASWMkrMPtPAAuG0MUnc XP4YrIpNQE9iwbUf7F2MHBwiAjYScy5mgISFBSwlVu+awQxiswioSvTd284IYvMKuEv0zHvF CLFATuLc+i8sIDangIfEiu2P2UBsIaCanf9OMk1g5FnAyLCKUSK1ILmgOCk91ygvtVyvODG3 uDQvXS85P3cTIzjIn0nvYDy8y/0QowAHoxIP74xtl0OFWBPLiitzDzFKcDArifD+3AkU4k1J rKxKLcqPLyrNSS0+xGgKdNhEZinR5HxgBOaVxBsam5gZWRqZG1oYGZsrifPqm2wKFRJITyxJ zU5NLUgtgulj4uCUamAMcn2obHz1+9cVt4uv+8/8z7dn6UP2769eBG0L+ClVq2T0y1Hlwq3q W9WHkuZUN71Y9jnkNp9t0Ikf5lVvOFg0YqcX6ATwTu9O/ZWxaMadK558i/nCsvmqpRmfBEaW 99TVbQ52ad3mcU9qZvvcrtrX7zcUXTzpUZH824Fx0h2nIh8Wg0jVtMtKLMUZiYZazEXFiQCT DAk+iAIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@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.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 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 value of each object's property. Signed-off-by: Hyungwon Hwang --- tests/modetest/modetest.c | 237 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 204 insertions(+), 33 deletions(-) diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 43bd06f..bf9222d 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -1433,15 +1433,21 @@ 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 [-acDdefMPpsCvwW]\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 Atomic Test options: [A]\n\n"); + fprintf(stderr, "\t-a\tuse atomic modeset\n"); + fprintf(stderr, "\t-W ::\tset property\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"); @@ -1449,9 +1455,9 @@ static void usage(char *name) 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); @@ -1484,7 +1490,154 @@ static int cursor_supported(void) return 1; } -static char optstr[] = "cdD:efM:P:ps:Cvw:"; +static int parse_atomic_args(drmModeAtomicReqPtr req, const char *p) +{ + uint32_t object_id, property_id; + uint64_t value; + + if (sscanf(p, "%u:%u:%llu", &object_id, &property_id, &value) != 3) + return -1; + + drmModeAtomicAddProperty(req, object_id, property_id, value); + + return 0; +} + +static uint32_t get_atomic_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 uint64_t get_atomic_plane_prop_value_in_request(drmModeAtomicReqPtr req, + struct resources *res, uint32_t obj_id, const char *name) +{ + uint32_t prop_id, i; + drmModeAtomicReqItemPtr item; + + prop_id = get_atomic_plane_prop_id(res, obj_id, name); + + for (i = 0; i < req->cursor; i++) { + item = &req->items[i]; + + if (item->object_id != obj_id) + continue; + + if (item->property_id != prop_id) + continue; + + return item->value; + } + + return -1; +} + +static bool is_atomic_obj_in_request(drmModeAtomicReqPtr req, + uint32_t obj_id) +{ + unsigned int i; + + for (i = 0; i < req->cursor; i++) + if (req->items[i].object_id == obj_id) + return true; + + return false; +} + +static int allocate_fb(struct device *dev, 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(dev->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(dev->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) +{ + uint32_t plane_id, fb_obj_id, fb_id, i, width, height, pixel_format; + struct bo *bo; + int ret; + + for (i = 0; i < res->plane_res->count_planes; i++) { + plane_id = res->planes[i].plane->plane_id; + + if (!is_atomic_obj_in_request(req, plane_id)) + continue; + + fb_obj_id = get_atomic_plane_prop_id(res, plane_id, "FB_ID"); + if (!fb_obj_id) + return -1; + + width = get_atomic_plane_prop_value_in_request(req, res, + plane_id, "SRC_W"); + height = get_atomic_plane_prop_value_in_request(req, res, + plane_id, "SRC_H"); + pixel_format = DRM_FORMAT_XRGB8888; + + ret = allocate_fb(dev, req, res, width, height, pixel_format, + PATTERN_SMPTE, &bo, &fb_id); + if (ret < 0) + return ret; + + dev->mode.bo = bo; + dev->mode.fb_id = fb_id; + + ret = drmModeAtomicAddProperty(req, plane_id, fb_obj_id, fb_id); + if (ret < 0) + return ret; + } + + return 0; +} + +static void atomic_modeset(struct device *dev, drmModeAtomicReqPtr req, + struct resources *res) +{ + uint32_t flags = 0; + + drmModeAtomicCleanup(req); + + allocate_fbs(dev, req, res); + + drmModeAtomicCommit(dev->fd, req, flags, NULL); +} + +static char optstr[] = "acdD:efM:P:ps:Cvw:W:"; int main(int argc, char **argv) { @@ -1504,6 +1657,7 @@ 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; unsigned int args = 0; int ret; @@ -1514,6 +1668,11 @@ int main(int argc, char **argv) args++; switch (c) { + case 'a': + if (!req) + req = drmModeAtomicAlloc(); + args--; + break; case 'c': connectors = 1; break; @@ -1587,6 +1746,10 @@ int main(int argc, char **argv) prop_count++; break; + case 'W': + if (!req || parse_atomic_args(req, optarg) < 0) + usage(argv[0]); + break; default: usage(argv[0]); break; @@ -1635,6 +1798,9 @@ int main(int argc, char **argv) return -1; } + if (req) + drmSetClientCap(dev.fd, DRM_CLIENT_CAP_ATOMIC, 1); + dev.resources = get_resources(&dev); if (!dev.resources) { drmClose(dev.fd); @@ -1649,46 +1815,51 @@ int main(int argc, char **argv) dump_resource(&dev, planes); dump_resource(&dev, framebuffers); - for (i = 0; i < prop_count; ++i) - set_property(&dev, &prop_args[i]); + if (req) { + atomic_modeset(&dev, req, dev.resources); - if (count || plane_count) { - uint64_t cap = 0; + getchar(); + } else { + for (i = 0; i < prop_count; ++i) + set_property(&dev, &prop_args[i]); - ret = drmGetCap(dev.fd, DRM_CAP_DUMB_BUFFER, &cap); - if (ret || cap == 0) { - fprintf(stderr, "driver doesn't support the dumb buffer API\n"); - return 1; - } + if (count || plane_count) { + uint64_t cap = 0; - if (count) - set_mode(&dev, pipe_args, count); + ret = drmGetCap(dev.fd, DRM_CAP_DUMB_BUFFER, &cap); + if (ret || cap == 0) { + fprintf(stderr, "driver doesn't support the dumb buffer API\n"); + return 1; + } - if (plane_count) - set_planes(&dev, plane_args, plane_count); + if (count) + set_mode(&dev, pipe_args, count); - if (test_cursor) - set_cursors(&dev, pipe_args, count); + if (plane_count) + set_planes(&dev, plane_args, plane_count); - if (test_vsync) - test_page_flip(&dev, pipe_args, count); + if (test_cursor) + set_cursors(&dev, pipe_args, count); - if (drop_master) - drmDropMaster(dev.fd); + if (test_vsync) + test_page_flip(&dev, pipe_args, count); - getchar(); + if (drop_master) + drmDropMaster(dev.fd); - if (test_cursor) - clear_cursors(&dev); + getchar(); - if (plane_count) - clear_planes(&dev, plane_args, plane_count); + if (test_cursor) + clear_cursors(&dev); - if (count) - clear_mode(&dev); + if (plane_count) + clear_planes(&dev, plane_args, plane_count); + } } + clear_mode(&dev); free_resources(dev.resources); + drmFree(req); return 0; }