Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / gpu / drm / nouveau / nvkm / engine / sw / base.c
blob7be3198e11de402e413083729cacbda3f51181f7
1 /*
2 * Copyright 2015 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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
24 #include "priv.h"
25 #include "chan.h"
27 #include <engine/fifo.h>
29 bool
30 nvkm_sw_mthd(struct nvkm_sw *sw, int chid, int subc, u32 mthd, u32 data)
32 struct nvkm_sw_chan *chan;
33 bool handled = false;
34 unsigned long flags;
36 spin_lock_irqsave(&sw->engine.lock, flags);
37 list_for_each_entry(chan, &sw->chan, head) {
38 if (chan->fifo->chid == chid) {
39 handled = nvkm_sw_chan_mthd(chan, subc, mthd, data);
40 list_del(&chan->head);
41 list_add(&chan->head, &sw->chan);
42 break;
45 spin_unlock_irqrestore(&sw->engine.lock, flags);
46 return handled;
49 static int
50 nvkm_sw_oclass_new(const struct nvkm_oclass *oclass, void *data, u32 size,
51 struct nvkm_object **pobject)
53 struct nvkm_sw_chan *chan = nvkm_sw_chan(oclass->parent);
54 const struct nvkm_sw_chan_sclass *sclass = oclass->engn;
55 return sclass->ctor(chan, oclass, data, size, pobject);
58 static int
59 nvkm_sw_oclass_get(struct nvkm_oclass *oclass, int index)
61 struct nvkm_sw *sw = nvkm_sw(oclass->engine);
62 int c = 0;
64 while (sw->func->sclass[c].ctor) {
65 if (c++ == index) {
66 oclass->engn = &sw->func->sclass[index];
67 oclass->base = sw->func->sclass[index].base;
68 oclass->base.ctor = nvkm_sw_oclass_new;
69 return index;
73 return c;
76 static int
77 nvkm_sw_cclass_get(struct nvkm_fifo_chan *fifoch,
78 const struct nvkm_oclass *oclass,
79 struct nvkm_object **pobject)
81 struct nvkm_sw *sw = nvkm_sw(oclass->engine);
82 return sw->func->chan_new(sw, fifoch, oclass, pobject);
85 static void *
86 nvkm_sw_dtor(struct nvkm_engine *engine)
88 return nvkm_sw(engine);
91 static const struct nvkm_engine_func
92 nvkm_sw = {
93 .dtor = nvkm_sw_dtor,
94 .fifo.cclass = nvkm_sw_cclass_get,
95 .fifo.sclass = nvkm_sw_oclass_get,
98 int
99 nvkm_sw_new_(const struct nvkm_sw_func *func, struct nvkm_device *device,
100 int index, struct nvkm_sw **psw)
102 struct nvkm_sw *sw;
104 if (!(sw = *psw = kzalloc(sizeof(*sw), GFP_KERNEL)))
105 return -ENOMEM;
106 INIT_LIST_HEAD(&sw->chan);
107 sw->func = func;
109 return nvkm_engine_ctor(&nvkm_sw, device, index, true, &sw->engine);