2 * Copyright 2012 Red Hat Inc.
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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <core/object.h>
26 #include <core/handle.h>
28 #include <engine/dmaobj.h>
29 #include <engine/fifo.h>
32 nouveau_fifo_channel_create_(struct nouveau_object *parent,
33 struct nouveau_object *engine,
34 struct nouveau_oclass *oclass,
35 int bar, u32 addr, u32 size, u32 pushbuf,
36 u32 engmask, int len, void **ptr)
38 struct nouveau_device *device = nv_device(engine);
39 struct nouveau_fifo *priv = (void *)engine;
40 struct nouveau_fifo_chan *chan;
41 struct nouveau_dmaeng *dmaeng;
45 /* create base object class */
46 ret = nouveau_namedb_create_(parent, engine, oclass, 0, NULL,
52 /* validate dma object representing push buffer */
53 chan->pushdma = (void *)nouveau_handle_ref(parent, pushbuf);
57 dmaeng = (void *)chan->pushdma->base.engine;
58 switch (chan->pushdma->base.oclass->handle) {
67 ret = dmaeng->bind(dmaeng, parent, chan->pushdma, &chan->pushgpu);
72 /* find a free fifo channel */
73 spin_lock_irqsave(&priv->lock, flags);
74 for (chan->chid = priv->min; chan->chid < priv->max; chan->chid++) {
75 if (!priv->channel[chan->chid]) {
76 priv->channel[chan->chid] = nv_object(chan);
80 spin_unlock_irqrestore(&priv->lock, flags);
82 if (chan->chid == priv->max) {
83 nv_error(priv, "no free channels\n");
87 /* map fifo control registers */
88 chan->user = ioremap(pci_resource_start(device->pdev, bar) + addr +
89 (chan->chid * size), size);
98 nouveau_fifo_channel_destroy(struct nouveau_fifo_chan *chan)
100 struct nouveau_fifo *priv = (void *)nv_object(chan)->engine;
105 spin_lock_irqsave(&priv->lock, flags);
106 priv->channel[chan->chid] = NULL;
107 spin_unlock_irqrestore(&priv->lock, flags);
109 nouveau_gpuobj_ref(NULL, &chan->pushgpu);
110 nouveau_object_ref(NULL, (struct nouveau_object **)&chan->pushdma);
111 nouveau_namedb_destroy(&chan->base);
115 _nouveau_fifo_channel_dtor(struct nouveau_object *object)
117 struct nouveau_fifo_chan *chan = (void *)object;
118 nouveau_fifo_channel_destroy(chan);
122 _nouveau_fifo_channel_rd32(struct nouveau_object *object, u32 addr)
124 struct nouveau_fifo_chan *chan = (void *)object;
125 return ioread32_native(chan->user + addr);
129 _nouveau_fifo_channel_wr32(struct nouveau_object *object, u32 addr, u32 data)
131 struct nouveau_fifo_chan *chan = (void *)object;
132 iowrite32_native(data, chan->user + addr);
136 nouveau_fifo_chid(struct nouveau_fifo *priv, struct nouveau_object *object)
138 int engidx = nv_hclass(priv) & 0xff;
140 while (object && object->parent) {
141 if ( nv_iclass(object->parent, NV_ENGCTX_CLASS) &&
142 (nv_hclass(object->parent) & 0xff) == engidx)
143 return nouveau_fifo_chan(object)->chid;
144 object = object->parent;
151 nouveau_fifo_destroy(struct nouveau_fifo *priv)
153 kfree(priv->channel);
154 nouveau_engine_destroy(&priv->base);
158 nouveau_fifo_create_(struct nouveau_object *parent,
159 struct nouveau_object *engine,
160 struct nouveau_oclass *oclass,
161 int min, int max, int length, void **pobject)
163 struct nouveau_fifo *priv;
166 ret = nouveau_engine_create_(parent, engine, oclass, true, "PFIFO",
167 "fifo", length, pobject);
174 priv->channel = kzalloc(sizeof(*priv->channel) * (max + 1), GFP_KERNEL);
178 priv->chid = nouveau_fifo_chid;
179 spin_lock_init(&priv->lock);