Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs
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 }