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.
28 #include <nvif/class.h>
29 #include <nvif/ioctl.h>
30 #include <nvif/unpack.h>
33 struct nvkm_sw_chan base
;
37 /*******************************************************************************
38 * software object classes
39 ******************************************************************************/
42 nv04_sw_set_ref(struct nvkm_object
*object
, u32 mthd
, void *data
, u32 size
)
44 struct nv04_sw_chan
*chan
= (void *)nv_engctx(object
->parent
);
45 atomic_set(&chan
->ref
, *(u32
*)data
);
50 nv04_sw_flip(struct nvkm_object
*object
, u32 mthd
, void *args
, u32 size
)
52 struct nvkm_sw_chan
*chan
= (void *)nv_engctx(object
->parent
);
53 nvkm_event_send(&chan
->event
, 1, 0, NULL
, 0);
57 static struct nvkm_omthds
59 { 0x0150, 0x0150, nv04_sw_set_ref
},
60 { 0x0500, 0x0500, nv04_sw_flip
},
65 nv04_sw_mthd_get_ref(struct nvkm_object
*object
, void *data
, u32 size
)
67 struct nv04_sw_chan
*chan
= (void *)object
->parent
;
69 struct nv04_nvsw_get_ref_v0 v0
;
73 if (nvif_unpack(args
->v0
, 0, 0, false)) {
74 args
->v0
.ref
= atomic_read(&chan
->ref
);
81 nv04_sw_mthd(struct nvkm_object
*object
, u32 mthd
, void *data
, u32 size
)
84 case NV04_NVSW_GET_REF
:
85 return nv04_sw_mthd_get_ref(object
, data
, size
);
92 static struct nvkm_ofuncs
94 .ctor
= nvkm_nvsw_ctor
,
95 .dtor
= nvkm_object_destroy
,
96 .init
= _nvkm_object_init
,
97 .fini
= _nvkm_object_fini
,
101 static struct nvkm_oclass
103 { NVIF_IOCTL_NEW_V0_SW_NV04
, &nv04_sw_ofuncs
, nv04_sw_omthds
},
107 /*******************************************************************************
109 ******************************************************************************/
112 nv04_sw_context_ctor(struct nvkm_object
*parent
, struct nvkm_object
*engine
,
113 struct nvkm_oclass
*oclass
, void *data
, u32 size
,
114 struct nvkm_object
**pobject
)
116 struct nv04_sw_chan
*chan
;
119 ret
= nvkm_sw_context_create(parent
, engine
, oclass
, &chan
);
120 *pobject
= nv_object(chan
);
124 atomic_set(&chan
->ref
, 0);
128 static struct nvkm_oclass
130 .handle
= NV_ENGCTX(SW
, 0x04),
131 .ofuncs
= &(struct nvkm_ofuncs
) {
132 .ctor
= nv04_sw_context_ctor
,
133 .dtor
= _nvkm_sw_context_dtor
,
134 .init
= _nvkm_sw_context_init
,
135 .fini
= _nvkm_sw_context_fini
,
139 /*******************************************************************************
140 * software engine/subdev functions
141 ******************************************************************************/
144 nv04_sw_intr(struct nvkm_subdev
*subdev
)
146 nvkm_mask(subdev
->device
, 0x000100, 0x80000000, 0x00000000);
150 nv04_sw_ctor(struct nvkm_object
*parent
, struct nvkm_object
*engine
,
151 struct nvkm_oclass
*oclass
, void *data
, u32 size
,
152 struct nvkm_object
**pobject
)
157 ret
= nvkm_sw_create(parent
, engine
, oclass
, &sw
);
158 *pobject
= nv_object(sw
);
162 nv_engine(sw
)->cclass
= &nv04_sw_cclass
;
163 nv_engine(sw
)->sclass
= nv04_sw_sclass
;
164 nv_subdev(sw
)->intr
= nv04_sw_intr
;
169 nv04_sw_oclass
= &(struct nvkm_oclass
) {
170 .handle
= NV_ENGINE(SW
, 0x04),
171 .ofuncs
= &(struct nvkm_ofuncs
) {
172 .ctor
= nv04_sw_ctor
,
173 .dtor
= _nvkm_sw_dtor
,
174 .init
= _nvkm_sw_init
,
175 .fini
= _nvkm_sw_fini
,