0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "nouveau_drv.h"
0025 #include "nouveau_dma.h"
0026 #include "nouveau_fence.h"
0027
0028 #include <nvif/if0004.h>
0029 #include <nvif/push006c.h>
0030
0031 struct nv04_fence_chan {
0032 struct nouveau_fence_chan base;
0033 };
0034
0035 struct nv04_fence_priv {
0036 struct nouveau_fence_priv base;
0037 };
0038
0039 static int
0040 nv04_fence_emit(struct nouveau_fence *fence)
0041 {
0042 struct nvif_push *push = fence->channel->chan.push;
0043 int ret = PUSH_WAIT(push, 2);
0044 if (ret == 0) {
0045 PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
0046 PUSH_KICK(push);
0047 }
0048 return ret;
0049 }
0050
0051 static int
0052 nv04_fence_sync(struct nouveau_fence *fence,
0053 struct nouveau_channel *prev, struct nouveau_channel *chan)
0054 {
0055 return -ENODEV;
0056 }
0057
0058 static u32
0059 nv04_fence_read(struct nouveau_channel *chan)
0060 {
0061 struct nv04_nvsw_get_ref_v0 args = {};
0062 WARN_ON(nvif_object_mthd(&chan->nvsw, NV04_NVSW_GET_REF,
0063 &args, sizeof(args)));
0064 return args.ref;
0065 }
0066
0067 static void
0068 nv04_fence_context_del(struct nouveau_channel *chan)
0069 {
0070 struct nv04_fence_chan *fctx = chan->fence;
0071 nouveau_fence_context_del(&fctx->base);
0072 chan->fence = NULL;
0073 nouveau_fence_context_free(&fctx->base);
0074 }
0075
0076 static int
0077 nv04_fence_context_new(struct nouveau_channel *chan)
0078 {
0079 struct nv04_fence_chan *fctx = kzalloc(sizeof(*fctx), GFP_KERNEL);
0080 if (fctx) {
0081 nouveau_fence_context_new(chan, &fctx->base);
0082 fctx->base.emit = nv04_fence_emit;
0083 fctx->base.sync = nv04_fence_sync;
0084 fctx->base.read = nv04_fence_read;
0085 chan->fence = fctx;
0086 return 0;
0087 }
0088 return -ENOMEM;
0089 }
0090
0091 static void
0092 nv04_fence_destroy(struct nouveau_drm *drm)
0093 {
0094 struct nv04_fence_priv *priv = drm->fence;
0095 drm->fence = NULL;
0096 kfree(priv);
0097 }
0098
0099 int
0100 nv04_fence_create(struct nouveau_drm *drm)
0101 {
0102 struct nv04_fence_priv *priv;
0103
0104 priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
0105 if (!priv)
0106 return -ENOMEM;
0107
0108 priv->base.dtor = nv04_fence_destroy;
0109 priv->base.context_new = nv04_fence_context_new;
0110 priv->base.context_del = nv04_fence_context_del;
0111 return 0;
0112 }