posix-clock: Fix return code on the poll method's error path
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvkm / engine / sw / nv04.c
blob445217ffa7911c73ea0ab6a12eb3a11ebe58d190
1 /*
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.
22 * Authors: Ben Skeggs
24 #define nv04_sw_chan(p) container_of((p), struct nv04_sw_chan, base)
25 #include "priv.h"
26 #include "chan.h"
27 #include "nvsw.h"
29 #include <nvif/class.h>
30 #include <nvif/ioctl.h>
31 #include <nvif/unpack.h>
33 struct nv04_sw_chan {
34 struct nvkm_sw_chan base;
35 atomic_t ref;
38 /*******************************************************************************
39 * software object classes
40 ******************************************************************************/
42 static int
43 nv04_nvsw_mthd_get_ref(struct nvkm_nvsw *nvsw, void *data, u32 size)
45 struct nv04_sw_chan *chan = nv04_sw_chan(nvsw->chan);
46 union {
47 struct nv04_nvsw_get_ref_v0 v0;
48 } *args = data;
49 int ret;
51 if (nvif_unpack(args->v0, 0, 0, false)) {
52 args->v0.ref = atomic_read(&chan->ref);
55 return ret;
58 static int
59 nv04_nvsw_mthd(struct nvkm_nvsw *nvsw, u32 mthd, void *data, u32 size)
61 switch (mthd) {
62 case NV04_NVSW_GET_REF:
63 return nv04_nvsw_mthd_get_ref(nvsw, data, size);
64 default:
65 break;
67 return -EINVAL;
70 static const struct nvkm_nvsw_func
71 nv04_nvsw = {
72 .mthd = nv04_nvsw_mthd,
75 static int
76 nv04_nvsw_new(struct nvkm_sw_chan *chan, const struct nvkm_oclass *oclass,
77 void *data, u32 size, struct nvkm_object **pobject)
79 return nvkm_nvsw_new_(&nv04_nvsw, chan, oclass, data, size, pobject);
82 /*******************************************************************************
83 * software context
84 ******************************************************************************/
86 static bool
87 nv04_sw_chan_mthd(struct nvkm_sw_chan *base, int subc, u32 mthd, u32 data)
89 struct nv04_sw_chan *chan = nv04_sw_chan(base);
91 switch (mthd) {
92 case 0x0150:
93 atomic_set(&chan->ref, data);
94 return true;
95 default:
96 break;
99 return false;
102 static const struct nvkm_sw_chan_func
103 nv04_sw_chan = {
104 .mthd = nv04_sw_chan_mthd,
107 static int
108 nv04_sw_chan_new(struct nvkm_sw *sw, struct nvkm_fifo_chan *fifo,
109 const struct nvkm_oclass *oclass, struct nvkm_object **pobject)
111 struct nv04_sw_chan *chan;
113 if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
114 return -ENOMEM;
115 atomic_set(&chan->ref, 0);
116 *pobject = &chan->base.object;
118 return nvkm_sw_chan_ctor(&nv04_sw_chan, sw, fifo, oclass, &chan->base);
121 /*******************************************************************************
122 * software engine/subdev functions
123 ******************************************************************************/
125 static const struct nvkm_sw_func
126 nv04_sw = {
127 .chan_new = nv04_sw_chan_new,
128 .sclass = {
129 { nv04_nvsw_new, { -1, -1, NVIF_IOCTL_NEW_V0_SW_NV04 } },
135 nv04_sw_new(struct nvkm_device *device, int index, struct nvkm_sw **psw)
137 return nvkm_sw_new_(&nv04_sw, device, index, psw);