From patchwork Mon Jan 25 18:35:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 8114081 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 7A2089F440 for ; Mon, 25 Jan 2016 18:37:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FF8420270 for ; Mon, 25 Jan 2016 18:37:37 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id BA1DD20274 for ; Mon, 25 Jan 2016 18:37:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4026C6E51B; Mon, 25 Jan 2016 10:37:36 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id EBB266E51A for ; Mon, 25 Jan 2016 10:37:34 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 25 Jan 2016 10:37:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,345,1449561600"; d="scan'208";a="641214957" Received: from irsmsx151.ger.corp.intel.com ([163.33.192.59]) by FMSMGA003.fm.intel.com with ESMTP; 25 Jan 2016 10:37:34 -0800 Received: from mwiniars-desk1.ger.corp.intel.com (172.28.173.39) by IRSMSX151.ger.corp.intel.com (163.33.192.59) with Microsoft SMTP Server id 14.3.248.2; Mon, 25 Jan 2016 18:37:33 +0000 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Mon, 25 Jan 2016 19:35:02 +0100 Message-ID: <1453746902-17417-2-git-send-email-michal.winiarski@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1453746902-17417-1-git-send-email-michal.winiarski@intel.com> References: <1453746902-17417-1-git-send-email-michal.winiarski@intel.com> MIME-Version: 1.0 X-Originating-IP: [172.28.173.39] Subject: [Intel-gfx] [PATCH i-g-t v2 2/2] lib/ioctl_wrappers: Add gem_has_softpin 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: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 We can move it from softpin test into lib, and since softpin support is highly unlikely to go away in-between getparam ioctl calls, let's just do a single call and store the value. v2: rebase Signed-off-by: Micha? Winiarski Reviewed-by: Chris Wilson --- lib/ioctl_wrappers.c | 29 +++++++++++++++++++++++++++++ lib/ioctl_wrappers.h | 1 + tests/gem_softpin.c | 22 +--------------------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index b534b03..34351c9 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -1242,6 +1242,35 @@ uint64_t gem_mappable_aperture_size(void) return pci_dev->regions[bar].size; } +#define LOCAL_I915_PARAM_HAS_EXEC_SOFTPIN 37 +/** + * gem_has_softpin: + * @fd: open i915 drm file descriptor + * + * Feature test macro to query whether the softpinning functionality is + * supported. + * + * Returns: Whether softpin support is available + */ +bool gem_has_softpin(int fd) +{ + static int has_softpin = -1; + + if (has_softpin < 0) { + struct drm_i915_getparam gp; + + memset(&gp, 0, sizeof(gp)); + gp.param = LOCAL_I915_PARAM_HAS_EXEC_SOFTPIN; + gp.value = &has_softpin; + + has_softpin = 0; + ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)); + errno = 0; + } + + return has_softpin; +} + /** * gem_require_caching: * @fd: open i915 drm file descriptor diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index a6bf700..04ac9bb 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -132,6 +132,7 @@ int gem_available_fences(int fd); uint64_t gem_available_aperture_size(int fd); uint64_t gem_aperture_size(int fd); uint64_t gem_mappable_aperture_size(void); +bool gem_has_softpin(int fd); /* check functions which auto-skip tests by calling igt_skip() */ void gem_require_caching(int fd); diff --git a/tests/gem_softpin.c b/tests/gem_softpin.c index c2bf37c..bfd02b0 100644 --- a/tests/gem_softpin.c +++ b/tests/gem_softpin.c @@ -31,26 +31,6 @@ #define EXEC_OBJECT_PINNED (1<<4) #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3) -/* has_softpin_support - * Finds if softpin feature is supported - * @fd DRM fd -*/ -static bool has_softpin_support(int fd) -{ - struct drm_i915_getparam gp; - int val = 0; - - memset(&gp, 0, sizeof(gp)); - gp.param = 37; /* I915_PARAM_HAS_EXEC_SOFTPIN */ - gp.value = &val; - - if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp)) - return 0; - - errno = 0; - return (val == 1); -} - /* gen8_canonical_addr * Used to convert any address into canonical form, i.e. [63:48] == [47]. * Based on kernel's sign_extend64 implementation. @@ -494,7 +474,7 @@ igt_main igt_fixture { fd = drm_open_driver_master(DRIVER_INTEL); - igt_require(has_softpin_support(fd)); + igt_require(gem_has_softpin(fd)); } igt_subtest("invalid")