2 * Copyright 2007 Nouveau Project
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include "nouveau_drmif.h"
28 #include "nouveau_dma.h"
29 #include "nouveau_local.h"
31 #define READ_GET(ch) ((*(ch)->get - (ch)->dma.base) >> 2)
32 #define WRITE_PUT(ch, val) do { \
34 NOUVEAU_DMA_BARRIER; \
36 *(ch)->put = (((val) << 2) + (ch)->dma.base); \
37 NOUVEAU_DMA_BARRIER; \
40 #ifdef NOUVEAU_DMA_DEBUG
45 nouveau_dma_channel_init(struct nouveau_channel *userchan)
47 struct nouveau_channel_priv *chan = nouveau_channel(userchan);
50 chan->dma.base = chan->drm.put_base;
51 chan->dma.cur = chan->dma.put = RING_SKIPS;
52 chan->dma.max = (chan->drm.cmdbuf_size >> 2) - 2;
53 chan->dma.free = chan->dma.max - chan->dma.cur;
55 for (i = 0; i < RING_SKIPS; i++)
56 chan->pushbuf[i] = 0x00000000;
59 #define CHECK_TIMEOUT() do { \
60 if ((NOUVEAU_TIME_MSEC() - t_start) > NOUVEAU_DMA_TIMEOUT) \
65 nouveau_dma_wait(struct nouveau_channel *userchan, int size)
67 struct nouveau_channel_priv *chan = nouveau_channel(userchan);
68 uint32_t get, t_start;
70 FIRE_RING_CH(userchan);
72 t_start = NOUVEAU_TIME_MSEC();
73 while (chan->dma.free < size) {
76 if (chan->dma.put >= get) {
77 chan->dma.free = chan->dma.max - chan->dma.cur;
79 if (chan->dma.free < size) {
80 #ifdef NOUVEAU_DMA_DEBUG
81 chan->dma.push_free = 1;
84 0x20000000 | chan->dma.base);
85 if (get <= RING_SKIPS) {
86 /*corner case - will be idle*/
87 if (chan->dma.put <= RING_SKIPS)
88 WRITE_PUT(chan, RING_SKIPS + 1);
93 } while (get <= RING_SKIPS);
96 WRITE_PUT(chan, RING_SKIPS);
97 chan->dma.cur = chan->dma.put = RING_SKIPS;
98 chan->dma.free = get - (RING_SKIPS + 1);
101 chan->dma.free = get - chan->dma.cur - 1;
110 #ifdef NOUVEAU_DMA_SUBCHAN_LRU
112 nouveau_dma_subc_bind(struct nouveau_grobj *grobj)
114 struct nouveau_channel_priv *chan = nouveau_channel(grobj->channel);
117 for (i = 0; i < 8; i++) {
118 if (chan->subchannel[i].grobj &&
119 chan->subchannel[i].grobj->bound ==
120 NOUVEAU_GROBJ_EXPLICIT_BIND)
122 if (chan->subchannel[i].seq < chan->subchannel[subc].seq)
127 if (chan->subchannel[subc].grobj)
128 chan->subchannel[subc].grobj->bound = 0;
129 chan->subchannel[subc].grobj = grobj;
131 grobj->bound = NOUVEAU_GROBJ_BOUND;
133 BEGIN_RING_CH(grobj->channel, grobj, 0, 1);
134 nouveau_dma_out (grobj->channel, grobj->handle);
139 nouveau_dma_kickoff(struct nouveau_channel *userchan)
141 struct nouveau_channel_priv *chan = nouveau_channel(userchan);
145 if (chan->dma.cur == chan->dma.put)
148 if (chan->num_relocs) {
149 nouveau_bo_validate(userchan);
151 for (i = 0; i < chan->num_relocs; i++) {
152 struct nouveau_bo_reloc *r = &chan->relocs[i];
155 if (r->flags & NOUVEAU_BO_LOW) {
156 push = r->bo->base.offset + r->data;
158 if (r->flags & NOUVEAU_BO_HIGH) {
159 push = (r->bo->base.offset + r->data) >> 32;
164 if (r->flags & NOUVEAU_BO_OR) {
165 if (r->flags & NOUVEAU_BO_VRAM)
174 chan->num_relocs = 0;
177 #ifdef NOUVEAU_DMA_DEBUG
178 if (chan->dma.push_free) {
179 NOUVEAU_ERR("Packet incomplete: %d left\n", chan->dma.push_free);
184 put_offset = (chan->dma.cur << 2) + chan->dma.base;
185 #ifdef NOUVEAU_DMA_TRACE
186 NOUVEAU_MSG("FIRE_RING %d/0x%08x\n", chan->drm.channel, put_offset);
188 chan->dma.put = chan->dma.cur;
190 *chan->put = put_offset;