hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/gpu/drm/i915/i915_memcpy.c
....@@ -25,16 +25,20 @@
2525 #include <linux/kernel.h>
2626 #include <asm/fpu/api.h>
2727
28
-#include "i915_drv.h"
28
+#include "i915_memcpy.h"
29
+
30
+#if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
31
+#define CI_BUG_ON(expr) BUG_ON(expr)
32
+#else
33
+#define CI_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
34
+#endif
2935
3036 static DEFINE_STATIC_KEY_FALSE(has_movntdqa);
3137
32
-#ifdef CONFIG_AS_MOVNTDQA
3338 static void __memcpy_ntdqa(void *dst, const void *src, unsigned long len)
3439 {
3540 kernel_fpu_begin();
3641
37
- len >>= 4;
3842 while (len >= 4) {
3943 asm("movntdqa (%0), %%xmm0\n"
4044 "movntdqa 16(%0), %%xmm1\n"
....@@ -59,7 +63,35 @@
5963
6064 kernel_fpu_end();
6165 }
62
-#endif
66
+
67
+static void __memcpy_ntdqu(void *dst, const void *src, unsigned long len)
68
+{
69
+ kernel_fpu_begin();
70
+
71
+ while (len >= 4) {
72
+ asm("movntdqa (%0), %%xmm0\n"
73
+ "movntdqa 16(%0), %%xmm1\n"
74
+ "movntdqa 32(%0), %%xmm2\n"
75
+ "movntdqa 48(%0), %%xmm3\n"
76
+ "movups %%xmm0, (%1)\n"
77
+ "movups %%xmm1, 16(%1)\n"
78
+ "movups %%xmm2, 32(%1)\n"
79
+ "movups %%xmm3, 48(%1)\n"
80
+ :: "r" (src), "r" (dst) : "memory");
81
+ src += 64;
82
+ dst += 64;
83
+ len -= 4;
84
+ }
85
+ while (len--) {
86
+ asm("movntdqa (%0), %%xmm0\n"
87
+ "movups %%xmm0, (%1)\n"
88
+ :: "r" (src), "r" (dst) : "memory");
89
+ src += 16;
90
+ dst += 16;
91
+ }
92
+
93
+ kernel_fpu_end();
94
+}
6395
6496 /**
6597 * i915_memcpy_from_wc: perform an accelerated *aligned* read from WC
....@@ -83,17 +115,47 @@
83115 if (unlikely(((unsigned long)dst | (unsigned long)src | len) & 15))
84116 return false;
85117
86
-#ifdef CONFIG_AS_MOVNTDQA
87118 if (static_branch_likely(&has_movntdqa)) {
88119 if (likely(len))
89
- __memcpy_ntdqa(dst, src, len);
120
+ __memcpy_ntdqa(dst, src, len >> 4);
90121 return true;
91122 }
92
-#endif
93123
94124 return false;
95125 }
96126
127
+/**
128
+ * i915_unaligned_memcpy_from_wc: perform a mostly accelerated read from WC
129
+ * @dst: destination pointer
130
+ * @src: source pointer
131
+ * @len: how many bytes to copy
132
+ *
133
+ * Like i915_memcpy_from_wc(), the unaligned variant copies @len bytes from
134
+ * @src to @dst using * non-temporal instructions where available, but
135
+ * accepts that its arguments may not be aligned, but are valid for the
136
+ * potential 16-byte read past the end.
137
+ */
138
+void i915_unaligned_memcpy_from_wc(void *dst, void *src, unsigned long len)
139
+{
140
+ unsigned long addr;
141
+
142
+ CI_BUG_ON(!i915_has_memcpy_from_wc());
143
+
144
+ addr = (unsigned long)src;
145
+ if (!IS_ALIGNED(addr, 16)) {
146
+ unsigned long x = min(ALIGN(addr, 16) - addr, len);
147
+
148
+ memcpy(dst, src, x);
149
+
150
+ len -= x;
151
+ dst += x;
152
+ src += x;
153
+ }
154
+
155
+ if (likely(len))
156
+ __memcpy_ntdqu(dst, src, DIV_ROUND_UP(len, 16));
157
+}
158
+
97159 void i915_memcpy_init_early(struct drm_i915_private *dev_priv)
98160 {
99161 /*