drm/nouveau/core/memory: add some useful accessor macros
authorBen Skeggs <bskeggs@redhat.com>
Tue, 31 Oct 2017 17:56:19 +0000 (03:56 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Thu, 2 Nov 2017 03:32:22 +0000 (13:32 +1000)
Adds support for 64-bit writes, and optimised filling of buffers with
fixed 32/64-bit values.

These will all be used by the upcoming MMU changes.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvif/os.h
drivers/gpu/drm/nouveau/include/nvkm/core/memory.h
drivers/gpu/drm/nouveau/include/nvkm/core/os.h

index 9fcab67c85577ee380b5fae43ad2a9be8c708de9..5efdf80d5abcbca75039de4a8deae3cc1142d064 100644 (file)
 
 #include <soc/tegra/fuse.h>
 #include <soc/tegra/pmc.h>
-
-#ifndef ioread32_native
-#ifdef __BIG_ENDIAN
-#define ioread16_native ioread16be
-#define iowrite16_native iowrite16be
-#define ioread32_native  ioread32be
-#define iowrite32_native iowrite32be
-#else /* def __BIG_ENDIAN */
-#define ioread16_native ioread16
-#define iowrite16_native iowrite16
-#define ioread32_native  ioread32
-#define iowrite32_native iowrite32
-#endif /* def __BIG_ENDIAN else */
-#endif /* !ioread32_native */
 #endif
index 9c9c400bea984f338aa8ac54f0eb3573015ecf87..13ebf4da2b963324f4a24e9d26d923777e048e54 100644 (file)
@@ -65,6 +65,8 @@ void nvkm_memory_tags_put(struct nvkm_memory *, struct nvkm_device *,
  * macros to guarantee correct behaviour across all chipsets
  */
 #define nvkm_kmap(o)     (o)->func->acquire(o)
+#define nvkm_done(o)     (o)->func->release(o)
+
 #define nvkm_ro32(o,a)   (o)->ptrs->rd32((o), (a))
 #define nvkm_wo32(o,a,d) (o)->ptrs->wr32((o), (a), (d))
 #define nvkm_mo32(o,a,m,d) ({                                                  \
@@ -72,5 +74,29 @@ void nvkm_memory_tags_put(struct nvkm_memory *, struct nvkm_device *,
        nvkm_wo32((o), _addr, (_data & ~(m)) | (d));                           \
        _data;                                                                 \
 })
-#define nvkm_done(o)     (o)->func->release(o)
+
+#define nvkm_wo64(o,a,d) do {                                                  \
+       u64 __a = (a), __d = (d);                                              \
+       nvkm_wo32((o), __a + 0, lower_32_bits(__d));                           \
+       nvkm_wo32((o), __a + 4, upper_32_bits(__d));                           \
+} while(0)
+
+#define nvkm_fill(t,s,o,a,d,c) do {                                            \
+       u64 _a = (a), _c = (c), _d = (d), _o = _a >> s, _s = _c << s;          \
+       u##t __iomem *_m = nvkm_kmap(o);                                       \
+       if (likely(_m)) {                                                      \
+               if (_d) {                                                      \
+                       while (_c--)                                           \
+                               iowrite##t##_native(_d, &_m[_o++]);            \
+               } else {                                                       \
+                       memset_io(&_m[_o], _d, _s);                            \
+               }                                                              \
+       } else {                                                               \
+               for (; _c; _c--, _a += BIT(s))                                 \
+                       nvkm_wo##t((o), _a, _d);                               \
+       }                                                                      \
+       nvkm_done(o);                                                          \
+} while(0)
+#define nvkm_fo32(o,a,d,c) nvkm_fill(32, 2, (o), (a), (d), (c))
+#define nvkm_fo64(o,a,d,c) nvkm_fill(64, 3, (o), (a), (d), (c))
 #endif
index cfd9ed361c44144a1ec8c168682876b9f493e447..70c5c47300b40076a8bcd35106dee16a07ff1154 100644 (file)
@@ -2,4 +2,24 @@
 #define __NVKM_OS_H__
 #include <nvif/os.h>
 #define nvkm_vmm nvkm_vm
+
+#ifdef __BIG_ENDIAN
+#define ioread16_native ioread16be
+#define iowrite16_native iowrite16be
+#define ioread32_native  ioread32be
+#define iowrite32_native iowrite32be
+#else
+#define ioread16_native ioread16
+#define iowrite16_native iowrite16
+#define ioread32_native  ioread32
+#define iowrite32_native iowrite32
+#endif
+
+#define iowrite64_native(v,p) do {                                             \
+       u32 __iomem *_p = (u32 __iomem *)(p);                                  \
+       u64 _v = (v);                                                          \
+       iowrite32_native(lower_32_bits(_v), &_p[0]);                           \
+       iowrite32_native(upper_32_bits(_v), &_p[1]);                           \
+} while(0)
+
 #endif