1 | /* $NetBSD: nouveau_nv04_fence.c,v 1.1.1.1 2014/08/06 12:36:23 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright 2012 Red Hat Inc. |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | * |
24 | * Authors: Ben Skeggs |
25 | */ |
26 | |
27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_nv04_fence.c,v 1.1.1.1 2014/08/06 12:36:23 riastradh Exp $" ); |
29 | |
30 | #include <engine/fifo.h> |
31 | |
32 | #include "nouveau_drm.h" |
33 | #include "nouveau_dma.h" |
34 | #include "nouveau_fence.h" |
35 | |
36 | struct nv04_fence_chan { |
37 | struct nouveau_fence_chan base; |
38 | }; |
39 | |
40 | struct nv04_fence_priv { |
41 | struct nouveau_fence_priv base; |
42 | }; |
43 | |
44 | static int |
45 | nv04_fence_emit(struct nouveau_fence *fence) |
46 | { |
47 | struct nouveau_channel *chan = fence->channel; |
48 | int ret = RING_SPACE(chan, 2); |
49 | if (ret == 0) { |
50 | BEGIN_NV04(chan, NvSubSw, 0x0150, 1); |
51 | OUT_RING (chan, fence->sequence); |
52 | FIRE_RING (chan); |
53 | } |
54 | return ret; |
55 | } |
56 | |
57 | static int |
58 | nv04_fence_sync(struct nouveau_fence *fence, |
59 | struct nouveau_channel *prev, struct nouveau_channel *chan) |
60 | { |
61 | return -ENODEV; |
62 | } |
63 | |
64 | static u32 |
65 | nv04_fence_read(struct nouveau_channel *chan) |
66 | { |
67 | struct nouveau_fifo_chan *fifo = (void *)chan->object; |
68 | return atomic_read(&fifo->refcnt); |
69 | } |
70 | |
71 | static void |
72 | nv04_fence_context_del(struct nouveau_channel *chan) |
73 | { |
74 | struct nv04_fence_chan *fctx = chan->fence; |
75 | nouveau_fence_context_del(&fctx->base); |
76 | chan->fence = NULL; |
77 | kfree(fctx); |
78 | } |
79 | |
80 | static int |
81 | nv04_fence_context_new(struct nouveau_channel *chan) |
82 | { |
83 | struct nv04_fence_chan *fctx = kzalloc(sizeof(*fctx), GFP_KERNEL); |
84 | if (fctx) { |
85 | nouveau_fence_context_new(&fctx->base); |
86 | fctx->base.emit = nv04_fence_emit; |
87 | fctx->base.sync = nv04_fence_sync; |
88 | fctx->base.read = nv04_fence_read; |
89 | chan->fence = fctx; |
90 | return 0; |
91 | } |
92 | return -ENOMEM; |
93 | } |
94 | |
95 | static void |
96 | nv04_fence_destroy(struct nouveau_drm *drm) |
97 | { |
98 | struct nv04_fence_priv *priv = drm->fence; |
99 | drm->fence = NULL; |
100 | kfree(priv); |
101 | } |
102 | |
103 | int |
104 | nv04_fence_create(struct nouveau_drm *drm) |
105 | { |
106 | struct nv04_fence_priv *priv; |
107 | |
108 | priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL); |
109 | if (!priv) |
110 | return -ENOMEM; |
111 | |
112 | priv->base.dtor = nv04_fence_destroy; |
113 | priv->base.context_new = nv04_fence_context_new; |
114 | priv->base.context_del = nv04_fence_context_del; |
115 | return 0; |
116 | } |
117 | |