r600g: use CP DMA for buffer clears on evergreen+
[mesa.git] / src / gallium / drivers / nvc0 / nvc0_winsys.h
index 85f8ed4da49001b75daa7a623aacf4bbfb518a56..25183a45f20940fcd80c1c6ab503faf1a1703f23 100644 (file)
 
 #include <stdint.h>
 #include <unistd.h>
-#include "pipe/p_defines.h"
 
-#include "nouveau/nouveau_bo.h"
-#include "nouveau/nouveau_channel.h"
-#include "nouveau/nouveau_grobj.h"
-#include "nouveau/nouveau_device.h"
-#include "nouveau/nouveau_resource.h"
-#include "nouveau/nouveau_reloc.h"
+#include "pipe/p_defines.h"
 
-#include "nvc0_resource.h" /* OUT_RESRC */
+#include "nouveau/nouveau_winsys.h"
+#include "nouveau/nouveau_buffer.h"
 
 #ifndef NV04_PFIFO_MAX_PACKET_LEN
 #define NV04_PFIFO_MAX_PACKET_LEN 2047
 #endif
 
-#define NVC0_SUBCH_3D 1
-#define NVC0_SUBCH_2D 2
-#define NVC0_SUBCH_MF 3
-
-#define NVC0_MF_(n) NVC0_M2MF_##n
-
-#define RING_3D(n) ((NVC0_SUBCH_3D << 13) | (NVC0_3D_##n >> 2))
-#define RING_2D(n) ((NVC0_SUBCH_2D << 13) | (NVC0_2D_##n >> 2))
-#define RING_MF(n) ((NVC0_SUBCH_MF << 13) | (NVC0_MF_(n) >> 2))
-
-#define RING_3D_(m) ((NVC0_SUBCH_3D << 13) | ((m) >> 2))
-#define RING_2D_(m) ((NVC0_SUBCH_2D << 13) | ((m) >> 2))
-#define RING_MF_(m) ((NVC0_SUBCH_MF << 13) | ((m) >> 2))
-
-#define RING_GR(gr, m) (((gr)->subc << 13) | ((m) >> 2))
-
-int nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
-
-static inline uint32_t
-nouveau_bo_tile_layout(struct nouveau_bo *bo)
-{
-   return bo->tile_flags & NOUVEAU_BO_TILE_LAYOUT_MASK;
-}
 
 static INLINE void
-WAIT_RING(struct nouveau_channel *chan, unsigned size)
+nv50_add_bufctx_resident_bo(struct nouveau_bufctx *bufctx, int bin,
+                            unsigned flags, struct nouveau_bo *bo)
 {
-   if (chan->cur + size > chan->end)
-      nouveau_pushbuf_flush(chan, size);
+   nouveau_bufctx_refn(bufctx, bin, bo, flags)->priv = NULL;
 }
 
 static INLINE void
-OUT_RING(struct nouveau_channel *chan, uint32_t data)
+nvc0_add_resident(struct nouveau_bufctx *bufctx, int bin,
+                  struct nv04_resource *res, unsigned flags)
 {
-   *(chan->cur++) = (data);
+   struct nouveau_bufref *ref =
+      nouveau_bufctx_refn(bufctx, bin, res->bo, flags | res->domain);
+   ref->priv = res;
+   ref->priv_data = flags;
 }
 
-/* incremental methods */
-static INLINE void
-BEGIN_RING(struct nouveau_channel *chan, uint32_t mthd, unsigned size)
-{
-   WAIT_RING(chan, size + 1);
-   OUT_RING (chan, (0x2 << 28) | (size << 16) | mthd);
-}
+#define BCTX_REFN_bo(ctx, bin, fl, bo) \
+   nv50_add_bufctx_resident_bo(ctx, NVC0_BIND_##bin, fl, bo);
 
-/* non-incremental */
-static INLINE void
-BEGIN_RING_NI(struct nouveau_channel *chan, uint32_t mthd, unsigned size)
-{
-   WAIT_RING(chan, size + 1);
-   OUT_RING (chan, (0x6 << 28) | (size << 16) | mthd);
-}
+#define BCTX_REFN(bctx, bin, res, acc) \
+   nvc0_add_resident(bctx, NVC0_BIND_##bin, res, NOUVEAU_BO_##acc)
 
-/* increment-once */
 static INLINE void
-BEGIN_RING_1I(struct nouveau_channel *chan, uint32_t mthd, unsigned size)
+PUSH_REFN(struct nouveau_pushbuf *push, struct nouveau_bo *bo, uint32_t flags)
 {
-   WAIT_RING(chan, size + 1);
-   OUT_RING (chan, (0xa << 28) | (size << 16) | mthd);
+   struct nouveau_pushbuf_refn ref = { bo, flags };
+   nouveau_pushbuf_refn(push, &ref, 1);
 }
 
-/* inline-data */
-static INLINE void
-IMMED_RING(struct nouveau_channel *chan, uint32_t mthd, unsigned data)
-{
-   WAIT_RING(chan, 1);
-   OUT_RING (chan, (0x8 << 28) | (data << 16) | mthd);
-}
 
-int
-nouveau_pushbuf_marker_emit(struct nouveau_channel *chan,
-                            unsigned wait_dwords, unsigned wait_relocs);
-int
-nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
-                           struct nouveau_bo *, uint32_t data, uint32_t data2,
-                           uint32_t flags, uint32_t vor, uint32_t tor);
-int
-nouveau_pushbuf_submit(struct nouveau_channel *chan, struct nouveau_bo *bo,
-                       unsigned offset, unsigned length);
-
-static INLINE int
-MARK_RING(struct nouveau_channel *chan, unsigned dwords, unsigned relocs)
-{
-   return nouveau_pushbuf_marker_emit(chan, dwords, relocs);
-}
+#define SUBC_3D(m) 0, (m)
+#define NVC0_3D(n) SUBC_3D(NVC0_3D_##n)
+#define NVE4_3D(n) SUBC_3D(NVE4_3D_##n)
 
-static INLINE void
-OUT_RINGf(struct nouveau_channel *chan, float data)
+#define SUBC_COMPUTE(m) 1, (m)
+#define NVC0_COMPUTE(n) SUBC_COMPUTE(NVC0_COMPUTE_##n)
+#define NVE4_COMPUTE(n) SUBC_COMPUTE(NVE4_COMPUTE_##n)
+
+#define SUBC_M2MF(m) 2, (m)
+#define SUBC_P2MF(m) 2, (m)
+#define NVC0_M2MF(n) SUBC_M2MF(NVC0_M2MF_##n)
+#define NVE4_P2MF(n) SUBC_P2MF(NVE4_P2MF_##n)
+
+#define SUBC_2D(m) 3, (m)
+#define NVC0_2D(n) SUBC_2D(NVC0_2D_##n)
+
+#define SUBC_COPY(m) 4, (m)
+#define NVE4_COPY(m) SUBC_COPY(NVE4_COPY_##n)
+
+#define SUBC_SW(m) 7, (m)
+
+static INLINE uint32_t
+NVC0_FIFO_PKHDR_SQ(int subc, int mthd, unsigned size)
 {
-   union { uint32_t i; float f; } u;
-   u.f = data;
-   OUT_RING(chan, u.i);
+   return 0x20000000 | (size << 16) | (subc << 13) | (mthd >> 2);
 }
 
-static INLINE unsigned
-AVAIL_RING(struct nouveau_channel *chan)
+static INLINE uint32_t
+NVC0_FIFO_PKHDR_NI(int subc, int mthd, unsigned size)
 {
-   return chan->end - chan->cur;
+   return 0x60000000 | (size << 16) | (subc << 13) | (mthd >> 2);
 }
 
-static INLINE void
-OUT_RINGp(struct nouveau_channel *chan, const void *data, unsigned size)
+static INLINE uint32_t
+NVC0_FIFO_PKHDR_IL(int subc, int mthd, uint8_t data)
 {
-   memcpy(chan->cur, data, size * 4);
-   chan->cur += size;
+   return 0x80000000 | (data << 16) | (subc << 13) | (mthd >> 2);
 }
 
-static INLINE int
-OUT_RELOC(struct nouveau_channel *chan, struct nouveau_bo *bo,
-          unsigned data, unsigned flags, unsigned vor, unsigned tor)
+static INLINE uint32_t
+NVC0_FIFO_PKHDR_1I(int subc, int mthd, unsigned size)
 {
-   return nouveau_pushbuf_emit_reloc(chan, chan->cur++, bo,
-                                     data, 0, flags, vor, tor);
+   return 0xa0000000 | (size << 16) | (subc << 13) | (mthd >> 2);
 }
 
-static INLINE int
-OUT_RELOCl(struct nouveau_channel *chan, struct nouveau_bo *bo,
-           unsigned delta, unsigned flags)
+
+static INLINE uint8_t
+nouveau_bo_memtype(const struct nouveau_bo *bo)
 {
-   return OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_LOW, 0, 0);
+   return bo->config.nvc0.memtype;
 }
 
-static INLINE int
-OUT_RELOCh(struct nouveau_channel *chan, struct nouveau_bo *bo,
-           unsigned delta, unsigned flags)
+
+static INLINE void
+PUSH_DATAh(struct nouveau_pushbuf *push, uint64_t data)
 {
-   return OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_HIGH, 0, 0);
+   *push->cur++ = (uint32_t)(data >> 32);
 }
 
-static INLINE int
-OUT_RESRCh(struct nouveau_channel *chan, struct nvc0_resource *res,
-           unsigned delta, unsigned flags)
+static INLINE void
+BEGIN_NVC0(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
 {
-   return OUT_RELOCh(chan, res->bo, res->offset + delta, res->domain | flags);
+#ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
+   PUSH_SPACE(push, size + 1);
+#endif
+   PUSH_DATA (push, NVC0_FIFO_PKHDR_SQ(subc, mthd, size));
 }
 
-static INLINE int
-OUT_RESRCl(struct nouveau_channel *chan, struct nvc0_resource *res,
-           unsigned delta, unsigned flags)
+static INLINE void
+BEGIN_NIC0(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
 {
-   return OUT_RELOCl(chan, res->bo, res->offset + delta, res->domain | flags);
+#ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
+   PUSH_SPACE(push, size + 1);
+#endif
+   PUSH_DATA (push, NVC0_FIFO_PKHDR_NI(subc, mthd, size));
 }
 
 static INLINE void
-FIRE_RING(struct nouveau_channel *chan)
+BEGIN_1IC0(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
 {
-   nouveau_pushbuf_flush(chan, 0);
+#ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
+   PUSH_SPACE(push, size + 1);
+#endif
+   PUSH_DATA (push, NVC0_FIFO_PKHDR_1I(subc, mthd, size));
 }
 
 static INLINE void
-BIND_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr, unsigned s)
+IMMED_NVC0(struct nouveau_pushbuf *push, int subc, int mthd, uint8_t data)
 {
-   struct nouveau_subchannel *subc = &gr->channel->subc[s];
-
-   assert(s < 8);
-   if (subc->gr) {
-      assert(subc->gr->bound != NOUVEAU_GROBJ_BOUND_EXPLICIT);
-      subc->gr->bound = NOUVEAU_GROBJ_UNBOUND;
-   }
-   subc->gr = gr;
-   subc->gr->subc = s;
-   subc->gr->bound = NOUVEAU_GROBJ_BOUND_EXPLICIT;
-
-   BEGIN_RING(chan, RING_GR(gr, 0x0000), 1);
-   OUT_RING  (chan, gr->grclass);
+#ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
+   PUSH_SPACE(push, 1);
+#endif
+   PUSH_DATA (push, NVC0_FIFO_PKHDR_IL(subc, mthd, data));
 }
 
-#endif
+#endif /* __NVC0_WINSYS_H__ */