From patchwork Mon Oct 28 15:53:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11215797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5081314DB for ; Mon, 28 Oct 2019 15:53:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 38A8220830 for ; Mon, 28 Oct 2019 15:53:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38A8220830 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D22506E970; Mon, 28 Oct 2019 15:53:38 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id A38D26E96C; Mon, 28 Oct 2019 15:53:30 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Oct 2019 08:53:30 -0700 X-IronPort-AV: E=Sophos;i="5.68,240,1569308400"; d="scan'208";a="193299010" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.17]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Oct 2019 08:53:27 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Mon, 28 Oct 2019 16:53:15 +0100 Message-Id: <20191028155318.23416-2-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191028155318.23416-1-janusz.krzysztofik@linux.intel.com> References: <20191028155318.23416-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH i-g-t v3 1/4] lib: Move redundant local helpers to lib/ X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Two tests - gem_exec_reloc and gem_softpin - define local helpers for calculation of softpin offset canonical addresses. As more users are expected, replace those local instances with a single shared one under lib/. Signed-off-by: Janusz Krzysztofik Cc: Chris Wilson --- lib/igt_x86.c | 13 +++++++++++++ lib/igt_x86.h | 5 +++++ tests/i915/gem_exec_reloc.c | 16 +++------------- tests/i915/gem_softpin.c | 13 +------------ 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/igt_x86.c b/lib/igt_x86.c index 6ac700df..13d7c6e5 100644 --- a/lib/igt_x86.c +++ b/lib/igt_x86.c @@ -190,6 +190,19 @@ char *igt_x86_features_to_string(unsigned features, char *line) } #endif +/** + * gen8_canonical_addr + * Used to convert any address into canonical form, i.e. [63:48] == [47]. + * Based on kernel's sign_extend64 implementation. + * @address - a virtual address + */ +uint64_t gen8_canonical_addr(uint64_t address) +{ + int shift = 63 - GEN8_HIGH_ADDRESS_BIT; + + return (int64_t)(address << shift) >> shift; +} + #if defined(__x86_64__) && !defined(__clang__) #pragma GCC push_options #pragma GCC target("sse4.1") diff --git a/lib/igt_x86.h b/lib/igt_x86.h index c7b84dec..8c7eb5e8 100644 --- a/lib/igt_x86.h +++ b/lib/igt_x86.h @@ -30,6 +30,8 @@ #ifndef IGT_X86_H #define IGT_X86_H +#include + #define MMX 0x1 #define SSE 0x2 #define SSE2 0x4 @@ -56,6 +58,9 @@ static inline char *igt_x86_features_to_string(unsigned features, char *line) } #endif +#define GEN8_HIGH_ADDRESS_BIT 47 +uint64_t gen8_canonical_addr(uint64_t address); + void igt_memcpy_from_wc(void *dst, const void *src, unsigned long len); #endif /* IGT_X86_H */ diff --git a/tests/i915/gem_exec_reloc.c b/tests/i915/gem_exec_reloc.c index fdd9661d..61f8b755 100644 --- a/tests/i915/gem_exec_reloc.c +++ b/tests/i915/gem_exec_reloc.c @@ -23,6 +23,7 @@ #include "igt.h" #include "igt_dummyload.h" +#include "igt_x86.h" IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl relocations."); @@ -500,17 +501,6 @@ static void basic_reloc(int fd, unsigned before, unsigned after, unsigned flags) gem_close(fd, obj.handle); } -static inline uint64_t sign_extend(uint64_t x, int index) -{ - int shift = 63 - index; - return (int64_t)(x << shift) >> shift; -} - -static uint64_t gen8_canonical_address(uint64_t address) -{ - return sign_extend(address, 47); -} - static void basic_range(int fd, unsigned flags) { struct drm_i915_gem_relocation_entry reloc[128]; @@ -537,7 +527,7 @@ static void basic_range(int fd, unsigned flags) for (int i = 0; i <= count; i++) { obj[n].handle = gem_create(fd, 4096); obj[n].offset = (1ull << (i + 12)) - 4096; - obj[n].offset = gen8_canonical_address(obj[n].offset); + obj[n].offset = gen8_canonical_addr(obj[n].offset); obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS; gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe)); execbuf.buffers_ptr = to_user_pointer(&obj[n]); @@ -557,7 +547,7 @@ static void basic_range(int fd, unsigned flags) for (int i = 1; i < count; i++) { obj[n].handle = gem_create(fd, 4096); obj[n].offset = 1ull << (i + 12); - obj[n].offset = gen8_canonical_address(obj[n].offset); + obj[n].offset = gen8_canonical_addr(obj[n].offset); obj[n].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS; gem_write(fd, obj[n].handle, 0, &bbe, sizeof(bbe)); execbuf.buffers_ptr = to_user_pointer(&obj[n]); diff --git a/tests/i915/gem_softpin.c b/tests/i915/gem_softpin.c index b9ff532e..17bd40a4 100644 --- a/tests/i915/gem_softpin.c +++ b/tests/i915/gem_softpin.c @@ -27,22 +27,11 @@ */ #include "igt.h" +#include "igt_x86.h" #define EXEC_OBJECT_PINNED (1<<4) #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3) -/* gen8_canonical_addr - * Used to convert any address into canonical form, i.e. [63:48] == [47]. - * Based on kernel's sign_extend64 implementation. - * @address - a virtual address -*/ -#define GEN8_HIGH_ADDRESS_BIT 47 -static uint64_t gen8_canonical_addr(uint64_t address) -{ - __u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT; - return (__s64)(address << shift) >> shift; -} - static void test_invalid(int fd) { const uint32_t bbe = MI_BATCH_BUFFER_END;