drm/nouveau: port all engines to new engine module format
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / engine / software / nvc0.c
1 /*
2 * Copyright 2012 Red Hat Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs
23 */
24
25 #include <core/os.h>
26 #include <core/class.h>
27 #include <core/engctx.h>
28
29 #include <engine/software.h>
30 #include <engine/disp.h>
31
32 struct nvc0_software_priv {
33 struct nouveau_software base;
34 };
35
36 struct nvc0_software_chan {
37 struct nouveau_software_chan base;
38 };
39
40 /*******************************************************************************
41 * software object classes
42 ******************************************************************************/
43
44 static int
45 nvc0_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd,
46 void *args, u32 size)
47 {
48 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
49 u64 data = *(u32 *)args;
50 if (mthd == 0x0400) {
51 chan->base.vblank.offset &= 0x00ffffffffULL;
52 chan->base.vblank.offset |= data << 32;
53 } else {
54 chan->base.vblank.offset &= 0xff00000000ULL;
55 chan->base.vblank.offset |= data;
56 }
57 return 0;
58 }
59
60 static int
61 nvc0_software_mthd_vblsem_value(struct nouveau_object *object, u32 mthd,
62 void *args, u32 size)
63 {
64 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
65 chan->base.vblank.value = *(u32 *)args;
66 return 0;
67 }
68
69 static int
70 nvc0_software_mthd_vblsem_release(struct nouveau_object *object, u32 mthd,
71 void *args, u32 size)
72 {
73 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
74 struct nouveau_disp *disp = nouveau_disp(object);
75 unsigned long flags;
76 u32 crtc = *(u32 *)args;
77
78 if ((nv_device(object)->card_type < NV_E0 && crtc > 1) || crtc > 3)
79 return -EINVAL;
80
81 disp->vblank.get(disp->vblank.data, crtc);
82
83 spin_lock_irqsave(&disp->vblank.lock, flags);
84 list_add(&chan->base.vblank.head, &disp->vblank.list);
85 chan->base.vblank.crtc = crtc;
86 spin_unlock_irqrestore(&disp->vblank.lock, flags);
87 return 0;
88 }
89
90 static int
91 nvc0_software_mthd_flip(struct nouveau_object *object, u32 mthd,
92 void *args, u32 size)
93 {
94 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
95 if (chan->base.flip)
96 return chan->base.flip(chan->base.flip_data);
97 return -EINVAL;
98 }
99
100 static struct nouveau_omthds
101 nvc0_software_omthds[] = {
102 { 0x0400, nvc0_software_mthd_vblsem_offset },
103 { 0x0404, nvc0_software_mthd_vblsem_offset },
104 { 0x0408, nvc0_software_mthd_vblsem_value },
105 { 0x040c, nvc0_software_mthd_vblsem_release },
106 { 0x0500, nvc0_software_mthd_flip },
107 {}
108 };
109
110 static struct nouveau_oclass
111 nvc0_software_sclass[] = {
112 { 0x906e, &nouveau_object_ofuncs, nvc0_software_omthds },
113 {}
114 };
115
116 /*******************************************************************************
117 * software context
118 ******************************************************************************/
119
120 static int
121 nvc0_software_context_ctor(struct nouveau_object *parent,
122 struct nouveau_object *engine,
123 struct nouveau_oclass *oclass, void *data, u32 size,
124 struct nouveau_object **pobject)
125 {
126 struct nvc0_software_chan *chan;
127 int ret;
128
129 ret = nouveau_software_context_create(parent, engine, oclass, &chan);
130 *pobject = nv_object(chan);
131 if (ret)
132 return ret;
133
134 chan->base.vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
135 return 0;
136 }
137
138 static struct nouveau_oclass
139 nvc0_software_cclass = {
140 .handle = NV_ENGCTX(SW, 0xc0),
141 .ofuncs = &(struct nouveau_ofuncs) {
142 .ctor = nvc0_software_context_ctor,
143 .dtor = _nouveau_software_context_dtor,
144 .init = _nouveau_software_context_init,
145 .fini = _nouveau_software_context_fini,
146 },
147 };
148
149 /*******************************************************************************
150 * software engine/subdev functions
151 ******************************************************************************/
152
153 static int
154 nvc0_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
155 struct nouveau_oclass *oclass, void *data, u32 size,
156 struct nouveau_object **pobject)
157 {
158 struct nvc0_software_priv *priv;
159 int ret;
160
161 ret = nouveau_software_create(parent, engine, oclass, &priv);
162 *pobject = nv_object(priv);
163 if (ret)
164 return ret;
165
166 nv_engine(priv)->cclass = &nvc0_software_cclass;
167 nv_engine(priv)->sclass = nvc0_software_sclass;
168 return 0;
169 }
170
171 struct nouveau_oclass
172 nvc0_software_oclass = {
173 .handle = NV_ENGINE(SW, 0xc0),
174 .ofuncs = &(struct nouveau_ofuncs) {
175 .ctor = nvc0_software_ctor,
176 .dtor = _nouveau_software_dtor,
177 .init = _nouveau_software_init,
178 .fini = _nouveau_software_fini,
179 },
180 };
This page took 0.076436 seconds and 5 git commands to generate.