From patchwork Wed Feb 4 16:42:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 5778141 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6B9D09F302 for ; Wed, 4 Feb 2015 16:42:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74AB4200F0 for ; Wed, 4 Feb 2015 16:42:39 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 663FD201EC for ; Wed, 4 Feb 2015 16:42:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AF7526E115; Wed, 4 Feb 2015 08:42:37 -0800 (PST) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C7ED6E2B2 for ; Wed, 4 Feb 2015 08:42:36 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 04 Feb 2015 08:37:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="449790622" Received: from tursulin-linux.isw.intel.com ([10.102.226.48]) by FMSMGA003.fm.intel.com with ESMTP; 04 Feb 2015 08:28:06 -0800 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Wed, 4 Feb 2015 16:42:14 +0000 Message-Id: <1423068134-12884-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.2.2 Subject: [Intel-gfx] [PATCH] tests/kms_addfb: Add support for fb modifiers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_MED, 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 From: Tvrtko Ursulin Just a few basic tests to make sure fb modifiers can be used and behave sanely when mixed with the old set_tiling API. Signed-off-by: Tvrtko Ursulin --- lib/ioctl_wrappers.c | 45 ++++++++++++++++++++++++++++++++++++++ lib/ioctl_wrappers.h | 36 ++++++++++++++++++++++++++++++ tests/kms_addfb.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index 19a457a..bca6d2a 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -1091,3 +1091,48 @@ int gem_context_has_param(int fd, uint64_t param) return gem_context_get_param(fd, &p) == 0; } + +int _drmModeAddFB2(int fd, uint32_t width, uint32_t height, + uint32_t pixel_format, uint32_t bo_handles[4], + uint32_t pitches[4], uint32_t offsets[4], + uint64_t modifier[0], uint32_t *buf_id, uint32_t flags) +{ + struct local_drm_mode_fb_cmd2 f; + int ret; + + f.width = width; + f.height = height; + f.pixel_format = pixel_format; + f.flags = flags; + + memcpy(f.handles, bo_handles, 4 * sizeof(bo_handles[0])); + memcpy(f.pitches, pitches, 4 * sizeof(pitches[0])); + memcpy(f.offsets, offsets, 4 * sizeof(offsets[0])); + memcpy(f.modifier, modifier, 4 * sizeof(modifier[0])); + + if ((ret = drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f))) + return ret < 0 ? -errno : ret; + + *buf_id = f.fb_id; + return 0; +} + +unsigned int has_drm_fb_modifiers(int fd) +{ + static unsigned int has_modifiers, cap_modifiers_tested; + uint64_t cap_modifiers; + int ret; + + if (cap_modifiers_tested) + return has_modifiers; + + ret = drmGetCap(fd, LOCAL_DRM_CAP_ADDFB2_MODIFIERS, &cap_modifiers); + igt_assert(ret == 0 || errno == EINVAL); + has_modifiers = ret == 0 && cap_modifiers == 1; + cap_modifiers_tested = 1; + + if (has_modifiers) + igt_debug("DRM_CAP_ADDFB2_MODIFIERS\n"); + + return has_modifiers; +} diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index 30ab836..c277012 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -117,4 +117,40 @@ int gem_context_has_param(int fd, uint64_t param); int gem_context_get_param(int fd, struct local_i915_gem_context_param *p); int gem_context_set_param(int fd, struct local_i915_gem_context_param *p); +struct local_drm_mode_fb_cmd2 { + uint32_t fb_id; + uint32_t width, height; + uint32_t pixel_format; + uint32_t flags; + uint32_t handles[4]; + uint32_t pitches[4]; + uint32_t offsets[4]; + uint64_t modifier[4]; +}; + +#define LOCAL_DRM_MODE_FB_MODIFIERS (1<<1) + +#define LOCAL_DRM_FORMAT_MOD_VENDOR_INTEL 0x01 + +#define local_fourcc_mod_code(vendor, val) \ + ((((uint64_t)LOCAL_DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | \ + (val & 0x00ffffffffffffffL)) + +#define LOCAL_I915_FORMAT_MOD_NONE local_fourcc_mod_code(INTEL, \ + 0x00000000000000L) +#define LOCAL_I915_FORMAT_MOD_X_TILED local_fourcc_mod_code(INTEL, \ + 0x00000000000001L) + +#define LOCAL_DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, \ + struct local_drm_mode_fb_cmd2) + +int _drmModeAddFB2(int fd, uint32_t width, uint32_t height, + uint32_t pixel_format, uint32_t bo_handles[4], + uint32_t pitches[4], uint32_t offsets[4], + uint64_t modifier[0], uint32_t *buf_id, uint32_t flags); + +#define LOCAL_DRM_CAP_ADDFB2_MODIFIERS 0x10 + +unsigned int has_drm_fb_modifiers(int fd); + #endif /* IOCTL_WRAPPERS_H */ diff --git a/tests/kms_addfb.c b/tests/kms_addfb.c index 756589e..9b0f77c 100644 --- a/tests/kms_addfb.c +++ b/tests/kms_addfb.c @@ -213,6 +213,66 @@ static void size_tests(int fd) } } +static void addfb25_tests(int fd) +{ + struct local_drm_mode_fb_cmd2 f = {}; + + + igt_require(has_drm_fb_modifiers(fd)); + + memset(&f, 0, sizeof(f)); + + f.width = 1024; + f.height = 1024; + f.pixel_format = DRM_FORMAT_XRGB8888; + f.pitches[0] = 1024*4; + f.flags = LOCAL_DRM_MODE_FB_MODIFIERS; + f.modifier[0] = LOCAL_I915_FORMAT_MOD_NONE; + + igt_fixture { + gem_bo = gem_create(fd, 1024*1024*4); + igt_assert(gem_bo); + } + + f.handles[0] = gem_bo; + + igt_subtest("addfb25-X-tiled") { + f.modifier[0] = LOCAL_I915_FORMAT_MOD_X_TILED; + igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) == 0); + igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0); + f.fb_id = 0; + } + + igt_subtest("addfb25-framebuffer-vs-set-tiling") { + igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) == 0); + igt_assert(__gem_set_tiling(fd, gem_bo, I915_TILING_X, 512*4) == -EBUSY); + igt_assert(__gem_set_tiling(fd, gem_bo, I915_TILING_X, 1024*4) == -EBUSY); + igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0); + f.fb_id = 0; + } + + igt_fixture + gem_set_tiling(fd, gem_bo, I915_TILING_X, 1024*4); + f.pitches[0] = 1024*4; + + igt_subtest("addfb25-X-tiled-both") { + f.modifier[0] = LOCAL_I915_FORMAT_MOD_X_TILED; + igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) == 0); + igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0); + f.fb_id = 0; + } + + igt_subtest("addfb25-X-tiled-mismatch") { + f.modifier[0] = LOCAL_I915_FORMAT_MOD_NONE; + igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) < 0 && errno == EINVAL); + f.fb_id = 0; + } + + igt_fixture { + gem_close(fd, gem_bo); + } +} + int fd; igt_main @@ -224,6 +284,8 @@ igt_main size_tests(fd); + addfb25_tests(fd); + igt_fixture close(fd); }