blob: 83549702bbc13a4f26dc4295292f1f2adcb10ee3 [file] [log] [blame]
Ben Skeggs2a7909c2015-08-20 14:54:19 +10001/*
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#include "rootnv50.h"
25#include "dmacnv50.h"
26
27#include <core/client.h>
28#include <core/ramht.h>
29#include <subdev/timer.h>
30
31#include <nvif/class.h>
32#include <nvif/unpack.h>
33
34int
35nv50_disp_root_scanoutpos(NV50_DISP_MTHD_V0)
36{
37 struct nvkm_device *device = disp->base.engine.subdev.device;
38 const u32 blanke = nvkm_rd32(device, 0x610aec + (head * 0x540));
39 const u32 blanks = nvkm_rd32(device, 0x610af4 + (head * 0x540));
40 const u32 total = nvkm_rd32(device, 0x610afc + (head * 0x540));
41 union {
42 struct nv04_disp_scanoutpos_v0 v0;
43 } *args = data;
44 int ret;
45
46 nvif_ioctl(object, "disp scanoutpos size %d\n", size);
47 if (nvif_unpack(args->v0, 0, 0, false)) {
48 nvif_ioctl(object, "disp scanoutpos vers %d\n",
49 args->v0.version);
50 args->v0.vblanke = (blanke & 0xffff0000) >> 16;
51 args->v0.hblanke = (blanke & 0x0000ffff);
52 args->v0.vblanks = (blanks & 0xffff0000) >> 16;
53 args->v0.hblanks = (blanks & 0x0000ffff);
54 args->v0.vtotal = ( total & 0xffff0000) >> 16;
55 args->v0.htotal = ( total & 0x0000ffff);
56 args->v0.time[0] = ktime_to_ns(ktime_get());
57 args->v0.vline = /* vline read locks hline */
58 nvkm_rd32(device, 0x616340 + (head * 0x800)) & 0xffff;
59 args->v0.time[1] = ktime_to_ns(ktime_get());
60 args->v0.hline =
61 nvkm_rd32(device, 0x616344 + (head * 0x800)) & 0xffff;
62 } else
63 return ret;
64
65 return 0;
66}
67
68int
69nv50_disp_root_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
70{
71 const struct nv50_disp_impl *impl = (void *)nv_oclass(object->engine);
72 union {
73 struct nv50_disp_mthd_v0 v0;
74 struct nv50_disp_mthd_v1 v1;
75 } *args = data;
76 struct nv50_disp *disp = (void *)object->engine;
77 struct nvkm_output *outp = NULL;
78 struct nvkm_output *temp;
79 u16 type, mask = 0;
80 int head, ret;
81
82 if (mthd != NV50_DISP_MTHD)
83 return -EINVAL;
84
85 nvif_ioctl(object, "disp mthd size %d\n", size);
86 if (nvif_unpack(args->v0, 0, 0, true)) {
87 nvif_ioctl(object, "disp mthd vers %d mthd %02x head %d\n",
88 args->v0.version, args->v0.method, args->v0.head);
89 mthd = args->v0.method;
90 head = args->v0.head;
91 } else
92 if (nvif_unpack(args->v1, 1, 1, true)) {
93 nvif_ioctl(object, "disp mthd vers %d mthd %02x "
94 "type %04x mask %04x\n",
95 args->v1.version, args->v1.method,
96 args->v1.hasht, args->v1.hashm);
97 mthd = args->v1.method;
98 type = args->v1.hasht;
99 mask = args->v1.hashm;
100 head = ffs((mask >> 8) & 0x0f) - 1;
101 } else
102 return ret;
103
104 if (head < 0 || head >= disp->head.nr)
105 return -ENXIO;
106
107 if (mask) {
108 list_for_each_entry(temp, &disp->base.outp, head) {
109 if ((temp->info.hasht == type) &&
110 (temp->info.hashm & mask) == mask) {
111 outp = temp;
112 break;
113 }
114 }
115 if (outp == NULL)
116 return -ENXIO;
117 }
118
119 switch (mthd) {
120 case NV50_DISP_SCANOUTPOS:
121 return impl->head.scanoutpos(object, disp, data, size, head);
122 default:
123 break;
124 }
125
126 switch (mthd * !!outp) {
127 case NV50_DISP_MTHD_V1_DAC_PWR:
128 return disp->dac.power(object, disp, data, size, head, outp);
129 case NV50_DISP_MTHD_V1_DAC_LOAD:
130 return disp->dac.sense(object, disp, data, size, head, outp);
131 case NV50_DISP_MTHD_V1_SOR_PWR:
132 return disp->sor.power(object, disp, data, size, head, outp);
133 case NV50_DISP_MTHD_V1_SOR_HDA_ELD:
134 if (!disp->sor.hda_eld)
135 return -ENODEV;
136 return disp->sor.hda_eld(object, disp, data, size, head, outp);
137 case NV50_DISP_MTHD_V1_SOR_HDMI_PWR:
138 if (!disp->sor.hdmi)
139 return -ENODEV;
140 return disp->sor.hdmi(object, disp, data, size, head, outp);
141 case NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT: {
142 union {
143 struct nv50_disp_sor_lvds_script_v0 v0;
144 } *args = data;
145 nvif_ioctl(object, "disp sor lvds script size %d\n", size);
146 if (nvif_unpack(args->v0, 0, 0, false)) {
147 nvif_ioctl(object, "disp sor lvds script "
148 "vers %d name %04x\n",
149 args->v0.version, args->v0.script);
150 disp->sor.lvdsconf = args->v0.script;
151 return 0;
152 } else
153 return ret;
154 }
155 break;
156 case NV50_DISP_MTHD_V1_SOR_DP_PWR: {
157 struct nvkm_output_dp *outpdp = nvkm_output_dp(outp);
158 union {
159 struct nv50_disp_sor_dp_pwr_v0 v0;
160 } *args = data;
161 nvif_ioctl(object, "disp sor dp pwr size %d\n", size);
162 if (nvif_unpack(args->v0, 0, 0, false)) {
163 nvif_ioctl(object, "disp sor dp pwr vers %d state %d\n",
164 args->v0.version, args->v0.state);
165 if (args->v0.state == 0) {
166 nvkm_notify_put(&outpdp->irq);
167 outpdp->func->lnk_pwr(outpdp, 0);
168 atomic_set(&outpdp->lt.done, 0);
169 return 0;
170 } else
171 if (args->v0.state != 0) {
172 nvkm_output_dp_train(&outpdp->base, 0, true);
173 return 0;
174 }
175 } else
176 return ret;
177 }
178 break;
179 case NV50_DISP_MTHD_V1_PIOR_PWR:
180 if (!disp->pior.power)
181 return -ENODEV;
182 return disp->pior.power(object, disp, data, size, head, outp);
183 default:
184 break;
185 }
186
187 return -EINVAL;
188}
189
190int
191nv50_disp_root_ctor(struct nvkm_object *parent,
192 struct nvkm_object *engine,
193 struct nvkm_oclass *oclass, void *data, u32 size,
194 struct nvkm_object **pobject)
195{
196 struct nv50_disp *disp = (void *)engine;
197 struct nv50_disp_root *root;
198 struct nvkm_device *device = disp->base.engine.subdev.device;
199 struct nvkm_gpuobj *instmem = (void *)parent;
200 int ret;
201
202 ret = nvkm_parent_create(parent, engine, oclass, 0,
203 disp->sclass, 0, &root);
204 *pobject = nv_object(root);
205 if (ret)
206 return ret;
207
208
209 return nvkm_ramht_new(device, 0x1000, 0, instmem, &root->ramht);
210}
211
212void
213nv50_disp_root_dtor(struct nvkm_object *object)
214{
215 struct nv50_disp_root *root = (void *)object;
216 nvkm_ramht_del(&root->ramht);
217 nvkm_parent_destroy(&root->base);
218}
219
220static int
221nv50_disp_root_init(struct nvkm_object *object)
222{
223 struct nv50_disp *disp = (void *)object->engine;
224 struct nv50_disp_root *root = (void *)object;
225 struct nvkm_device *device = disp->base.engine.subdev.device;
226 int ret, i;
227 u32 tmp;
228
229 ret = nvkm_parent_init(&root->base);
230 if (ret)
231 return ret;
232
233 /* The below segments of code copying values from one register to
234 * another appear to inform EVO of the display capabilities or
235 * something similar. NFI what the 0x614004 caps are for..
236 */
237 tmp = nvkm_rd32(device, 0x614004);
238 nvkm_wr32(device, 0x610184, tmp);
239
240 /* ... CRTC caps */
241 for (i = 0; i < disp->head.nr; i++) {
242 tmp = nvkm_rd32(device, 0x616100 + (i * 0x800));
243 nvkm_wr32(device, 0x610190 + (i * 0x10), tmp);
244 tmp = nvkm_rd32(device, 0x616104 + (i * 0x800));
245 nvkm_wr32(device, 0x610194 + (i * 0x10), tmp);
246 tmp = nvkm_rd32(device, 0x616108 + (i * 0x800));
247 nvkm_wr32(device, 0x610198 + (i * 0x10), tmp);
248 tmp = nvkm_rd32(device, 0x61610c + (i * 0x800));
249 nvkm_wr32(device, 0x61019c + (i * 0x10), tmp);
250 }
251
252 /* ... DAC caps */
253 for (i = 0; i < disp->dac.nr; i++) {
254 tmp = nvkm_rd32(device, 0x61a000 + (i * 0x800));
255 nvkm_wr32(device, 0x6101d0 + (i * 0x04), tmp);
256 }
257
258 /* ... SOR caps */
259 for (i = 0; i < disp->sor.nr; i++) {
260 tmp = nvkm_rd32(device, 0x61c000 + (i * 0x800));
261 nvkm_wr32(device, 0x6101e0 + (i * 0x04), tmp);
262 }
263
264 /* ... PIOR caps */
265 for (i = 0; i < disp->pior.nr; i++) {
266 tmp = nvkm_rd32(device, 0x61e000 + (i * 0x800));
267 nvkm_wr32(device, 0x6101f0 + (i * 0x04), tmp);
268 }
269
270 /* steal display away from vbios, or something like that */
271 if (nvkm_rd32(device, 0x610024) & 0x00000100) {
272 nvkm_wr32(device, 0x610024, 0x00000100);
273 nvkm_mask(device, 0x6194e8, 0x00000001, 0x00000000);
274 if (nvkm_msec(device, 2000,
275 if (!(nvkm_rd32(device, 0x6194e8) & 0x00000002))
276 break;
277 ) < 0)
278 return -EBUSY;
279 }
280
281 /* point at display engine memory area (hash table, objects) */
282 nvkm_wr32(device, 0x610010, (root->ramht->gpuobj->addr >> 8) | 9);
283
284 /* enable supervisor interrupts, disable everything else */
285 nvkm_wr32(device, 0x61002c, 0x00000370);
286 nvkm_wr32(device, 0x610028, 0x00000000);
287 return 0;
288}
289
290static int
291nv50_disp_root_fini(struct nvkm_object *object, bool suspend)
292{
293 struct nv50_disp *disp = (void *)object->engine;
294 struct nv50_disp_root *root = (void *)object;
295 struct nvkm_device *device = disp->base.engine.subdev.device;
296
297 /* disable all interrupts */
298 nvkm_wr32(device, 0x610024, 0x00000000);
299 nvkm_wr32(device, 0x610020, 0x00000000);
300
301 return nvkm_parent_fini(&root->base, suspend);
302}
303
304struct nvkm_ofuncs
305nv50_disp_root_ofuncs = {
306 .ctor = nv50_disp_root_ctor,
307 .dtor = nv50_disp_root_dtor,
308 .init = nv50_disp_root_init,
309 .fini = nv50_disp_root_fini,
310 .mthd = nv50_disp_root_mthd,
311 .ntfy = nvkm_disp_ntfy,
312};
313
314struct nvkm_oclass
315nv50_disp_root_oclass[] = {
316 { NV50_DISP, &nv50_disp_root_ofuncs },
317 {}
318};
319
320struct nvkm_oclass
321nv50_disp_sclass[] = {
322 { NV50_DISP_CORE_CHANNEL_DMA, &nv50_disp_core_ofuncs.base },
323 { NV50_DISP_BASE_CHANNEL_DMA, &nv50_disp_base_ofuncs.base },
324 { NV50_DISP_OVERLAY_CHANNEL_DMA, &nv50_disp_ovly_ofuncs.base },
325 { NV50_DISP_OVERLAY, &nv50_disp_oimm_ofuncs.base },
326 { NV50_DISP_CURSOR, &nv50_disp_curs_ofuncs.base },
327 {}
328};