[RFC PATCH i-g-t v3 1/4] lib: Move redundant local helpers to lib/

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <janusz.krzysztofik@xxxxxxxxxxxxxxx>
Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
---
 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 <stdint.h>
+
 #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;
-- 
2.21.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux