GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / gpu / drm / nouveau / nouveau_fence.c
blob5151e54e6b98c18858dee2ac77ab0f2588d48f46
1 /*
2 * Copyright (C) 2007 Ben Skeggs.
3 * All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "drmP.h"
28 #include "drm.h"
30 #include "nouveau_drv.h"
31 #include "nouveau_dma.h"
33 #define USE_REFCNT (dev_priv->card_type >= NV_10)
35 struct nouveau_fence {
36 struct nouveau_channel *channel;
37 struct kref refcount;
38 struct list_head entry;
40 uint32_t sequence;
41 bool signalled;
44 static inline struct nouveau_fence *
45 nouveau_fence(void *sync_obj)
47 return (struct nouveau_fence *)sync_obj;
50 static void
51 nouveau_fence_del(struct kref *ref)
53 struct nouveau_fence *fence =
54 container_of(ref, struct nouveau_fence, refcount);
56 kfree(fence);
59 void
60 nouveau_fence_update(struct nouveau_channel *chan)
62 struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
63 struct list_head *entry, *tmp;
64 struct nouveau_fence *fence;
65 uint32_t sequence;
67 spin_lock(&chan->fence.lock);
69 if (USE_REFCNT)
70 sequence = nvchan_rd32(chan, 0x48);
71 else
72 sequence = atomic_read(&chan->fence.last_sequence_irq);
74 if (chan->fence.sequence_ack == sequence)
75 goto out;
76 chan->fence.sequence_ack = sequence;
78 list_for_each_safe(entry, tmp, &chan->fence.pending) {
79 fence = list_entry(entry, struct nouveau_fence, entry);
81 sequence = fence->sequence;
82 fence->signalled = true;
83 list_del(&fence->entry);
84 kref_put(&fence->refcount, nouveau_fence_del);
86 if (sequence == chan->fence.sequence_ack)
87 break;
89 out:
90 spin_unlock(&chan->fence.lock);
93 int
94 nouveau_fence_new(struct nouveau_channel *chan, struct nouveau_fence **pfence,
95 bool emit)
97 struct nouveau_fence *fence;
98 int ret = 0;
100 fence = kzalloc(sizeof(*fence), GFP_KERNEL);
101 if (!fence)
102 return -ENOMEM;
103 kref_init(&fence->refcount);
104 fence->channel = chan;
106 if (emit)
107 ret = nouveau_fence_emit(fence);
109 if (ret)
110 nouveau_fence_unref((void *)&fence);
111 *pfence = fence;
112 return ret;
115 struct nouveau_channel *
116 nouveau_fence_channel(struct nouveau_fence *fence)
118 return fence ? fence->channel : NULL;
122 nouveau_fence_emit(struct nouveau_fence *fence)
124 struct drm_nouveau_private *dev_priv = fence->channel->dev->dev_private;
125 struct nouveau_channel *chan = fence->channel;
126 int ret;
128 ret = RING_SPACE(chan, 2);
129 if (ret)
130 return ret;
132 if (unlikely(chan->fence.sequence == chan->fence.sequence_ack - 1)) {
133 nouveau_fence_update(chan);
135 BUG_ON(chan->fence.sequence ==
136 chan->fence.sequence_ack - 1);
139 fence->sequence = ++chan->fence.sequence;
141 kref_get(&fence->refcount);
142 spin_lock(&chan->fence.lock);
143 list_add_tail(&fence->entry, &chan->fence.pending);
144 spin_unlock(&chan->fence.lock);
146 BEGIN_RING(chan, NvSubSw, USE_REFCNT ? 0x0050 : 0x0150, 1);
147 OUT_RING(chan, fence->sequence);
148 FIRE_RING(chan);
150 return 0;
153 void
154 nouveau_fence_unref(void **sync_obj)
156 struct nouveau_fence *fence = nouveau_fence(*sync_obj);
158 if (fence)
159 kref_put(&fence->refcount, nouveau_fence_del);
160 *sync_obj = NULL;
163 void *
164 nouveau_fence_ref(void *sync_obj)
166 struct nouveau_fence *fence = nouveau_fence(sync_obj);
168 kref_get(&fence->refcount);
169 return sync_obj;
172 bool
173 nouveau_fence_signalled(void *sync_obj, void *sync_arg)
175 struct nouveau_fence *fence = nouveau_fence(sync_obj);
176 struct nouveau_channel *chan = fence->channel;
178 if (fence->signalled)
179 return true;
181 nouveau_fence_update(chan);
182 return fence->signalled;
186 nouveau_fence_wait(void *sync_obj, void *sync_arg, bool lazy, bool intr)
188 unsigned long timeout = jiffies + (3 * DRM_HZ);
189 int ret = 0;
191 while (1) {
192 if (nouveau_fence_signalled(sync_obj, sync_arg))
193 break;
195 if (time_after_eq(jiffies, timeout)) {
196 ret = -EBUSY;
197 break;
200 __set_current_state(intr ? TASK_INTERRUPTIBLE
201 : TASK_UNINTERRUPTIBLE);
202 if (lazy)
203 schedule_timeout(1);
205 if (intr && signal_pending(current)) {
206 ret = -ERESTARTSYS;
207 break;
211 __set_current_state(TASK_RUNNING);
213 return ret;
217 nouveau_fence_flush(void *sync_obj, void *sync_arg)
219 return 0;
223 nouveau_fence_init(struct nouveau_channel *chan)
225 INIT_LIST_HEAD(&chan->fence.pending);
226 spin_lock_init(&chan->fence.lock);
227 atomic_set(&chan->fence.last_sequence_irq, 0);
228 return 0;
231 void
232 nouveau_fence_fini(struct nouveau_channel *chan)
234 struct list_head *entry, *tmp;
235 struct nouveau_fence *fence;
237 list_for_each_safe(entry, tmp, &chan->fence.pending) {
238 fence = list_entry(entry, struct nouveau_fence, entry);
240 fence->signalled = true;
241 list_del(&fence->entry);
242 kref_put(&fence->refcount, nouveau_fence_del);