Commit | Line | Data |
---|---|---|
ebb945a9 BS |
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 | #include <core/namedb.h> | |
29 | #include <core/handle.h> | |
30 | #include <core/gpuobj.h> | |
31 | ||
32 | #include <engine/software.h> | |
33 | #include <engine/disp.h> | |
34 | ||
35 | struct nv50_software_priv { | |
36 | struct nouveau_software base; | |
37 | }; | |
38 | ||
39 | struct nv50_software_chan { | |
40 | struct nouveau_software_chan base; | |
41 | }; | |
42 | ||
43 | /******************************************************************************* | |
44 | * software object classes | |
45 | ******************************************************************************/ | |
46 | ||
47 | static int | |
48 | nv50_software_mthd_dma_vblsem(struct nouveau_object *object, u32 mthd, | |
49 | void *args, u32 size) | |
50 | { | |
51 | struct nv50_software_chan *chan = (void *)nv_engctx(object->parent); | |
52 | struct nouveau_fifo_chan *fifo = (void *)nv_object(chan)->parent; | |
53 | struct nouveau_handle *handle; | |
54 | int ret = -EINVAL; | |
55 | ||
56 | handle = nouveau_namedb_get(nv_namedb(fifo), *(u32 *)args); | |
57 | if (!handle) | |
58 | return -ENOENT; | |
59 | ||
60 | if (nv_iclass(handle->object, NV_GPUOBJ_CLASS)) { | |
61 | struct nouveau_gpuobj *gpuobj = nv_gpuobj(handle->object); | |
62 | chan->base.vblank.ctxdma = gpuobj->node->offset >> 4; | |
63 | ret = 0; | |
64 | } | |
65 | nouveau_namedb_put(handle); | |
66 | return ret; | |
67 | } | |
68 | ||
69 | static int | |
70 | nv50_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd, | |
71 | void *args, u32 size) | |
72 | { | |
73 | struct nv50_software_chan *chan = (void *)nv_engctx(object->parent); | |
74 | chan->base.vblank.offset = *(u32 *)args; | |
75 | return 0; | |
76 | } | |
77 | ||
78 | static int | |
79 | nv50_software_mthd_vblsem_value(struct nouveau_object *object, u32 mthd, | |
80 | void *args, u32 size) | |
81 | { | |
82 | struct nv50_software_chan *chan = (void *)nv_engctx(object->parent); | |
83 | chan->base.vblank.value = *(u32 *)args; | |
84 | return 0; | |
85 | } | |
86 | ||
87 | static int | |
88 | nv50_software_mthd_vblsem_release(struct nouveau_object *object, u32 mthd, | |
89 | void *args, u32 size) | |
90 | { | |
91 | struct nv50_software_chan *chan = (void *)nv_engctx(object->parent); | |
92 | struct nouveau_disp *disp = nouveau_disp(object); | |
93 | unsigned long flags; | |
94 | u32 crtc = *(u32 *)args; | |
95 | ||
96 | if (crtc > 1) | |
97 | return -EINVAL; | |
98 | ||
99 | disp->vblank.get(disp->vblank.data, crtc); | |
100 | ||
101 | spin_lock_irqsave(&disp->vblank.lock, flags); | |
102 | list_add(&chan->base.vblank.head, &disp->vblank.list); | |
103 | chan->base.vblank.crtc = crtc; | |
104 | spin_unlock_irqrestore(&disp->vblank.lock, flags); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | static int | |
109 | nv50_software_mthd_flip(struct nouveau_object *object, u32 mthd, | |
110 | void *args, u32 size) | |
111 | { | |
112 | struct nv50_software_chan *chan = (void *)nv_engctx(object->parent); | |
113 | if (chan->base.flip) | |
114 | return chan->base.flip(chan->base.flip_data); | |
115 | return -EINVAL; | |
116 | } | |
117 | ||
118 | static struct nouveau_omthds | |
119 | nv50_software_omthds[] = { | |
120 | { 0x018c, nv50_software_mthd_dma_vblsem }, | |
121 | { 0x0400, nv50_software_mthd_vblsem_offset }, | |
122 | { 0x0404, nv50_software_mthd_vblsem_value }, | |
123 | { 0x0408, nv50_software_mthd_vblsem_release }, | |
124 | { 0x0500, nv50_software_mthd_flip }, | |
125 | {} | |
126 | }; | |
127 | ||
128 | static struct nouveau_oclass | |
129 | nv50_software_sclass[] = { | |
130 | { 0x506e, &nouveau_object_ofuncs, nv50_software_omthds }, | |
131 | {} | |
132 | }; | |
133 | ||
134 | /******************************************************************************* | |
135 | * software context | |
136 | ******************************************************************************/ | |
137 | ||
138 | static int | |
139 | nv50_software_context_ctor(struct nouveau_object *parent, | |
140 | struct nouveau_object *engine, | |
141 | struct nouveau_oclass *oclass, void *data, u32 size, | |
142 | struct nouveau_object **pobject) | |
143 | { | |
144 | struct nv50_software_chan *chan; | |
145 | int ret; | |
146 | ||
147 | ret = nouveau_software_context_create(parent, engine, oclass, &chan); | |
148 | *pobject = nv_object(chan); | |
149 | if (ret) | |
150 | return ret; | |
151 | ||
152 | chan->base.vblank.channel = nv_gpuobj(parent->parent)->addr >> 12; | |
153 | return 0; | |
154 | } | |
155 | ||
156 | static struct nouveau_oclass | |
157 | nv50_software_cclass = { | |
158 | .handle = NV_ENGCTX(SW, 0x50), | |
159 | .ofuncs = &(struct nouveau_ofuncs) { | |
160 | .ctor = nv50_software_context_ctor, | |
161 | .dtor = _nouveau_software_context_dtor, | |
162 | .init = _nouveau_software_context_init, | |
163 | .fini = _nouveau_software_context_fini, | |
164 | }, | |
165 | }; | |
166 | ||
167 | /******************************************************************************* | |
168 | * software engine/subdev functions | |
169 | ******************************************************************************/ | |
170 | ||
171 | static int | |
172 | nv50_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine, | |
173 | struct nouveau_oclass *oclass, void *data, u32 size, | |
174 | struct nouveau_object **pobject) | |
175 | { | |
176 | struct nv50_software_priv *priv; | |
177 | int ret; | |
178 | ||
179 | ret = nouveau_software_create(parent, engine, oclass, &priv); | |
180 | *pobject = nv_object(priv); | |
181 | if (ret) | |
182 | return ret; | |
183 | ||
184 | nv_engine(priv)->cclass = &nv50_software_cclass; | |
185 | nv_engine(priv)->sclass = nv50_software_sclass; | |
186 | return 0; | |
187 | } | |
188 | ||
189 | struct nouveau_oclass | |
190 | nv50_software_oclass = { | |
191 | .handle = NV_ENGINE(SW, 0x50), | |
192 | .ofuncs = &(struct nouveau_ofuncs) { | |
193 | .ctor = nv50_software_ctor, | |
194 | .dtor = _nouveau_software_dtor, | |
195 | .init = _nouveau_software_init, | |
196 | .fini = _nouveau_software_fini, | |
197 | }, | |
198 | }; |