blob: 711128c42de88518d8b90f430bc0cb4b2645b3c0 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright (C) 2008 Maarten Maathuis.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27#include "nv50_display.h"
28#include "nouveau_crtc.h"
29#include "nouveau_encoder.h"
30#include "nouveau_connector.h"
31#include "nouveau_fb.h"
Dave Airlie4abe3522010-03-30 05:34:18 +000032#include "nouveau_fbcon.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100033#include "drm_crtc_helper.h"
34
35static void
36nv50_evo_channel_del(struct nouveau_channel **pchan)
37{
38 struct nouveau_channel *chan = *pchan;
39
40 if (!chan)
41 return;
42 *pchan = NULL;
43
44 nouveau_gpuobj_channel_takedown(chan);
45 nouveau_bo_ref(NULL, &chan->pushbuf_bo);
46
47 if (chan->user)
48 iounmap(chan->user);
49
50 kfree(chan);
51}
52
53static int
54nv50_evo_dmaobj_new(struct nouveau_channel *evo, uint32_t class, uint32_t name,
55 uint32_t tile_flags, uint32_t magic_flags,
56 uint32_t offset, uint32_t limit)
57{
58 struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
59 struct drm_device *dev = evo->dev;
60 struct nouveau_gpuobj *obj = NULL;
61 int ret;
62
63 ret = nouveau_gpuobj_new(dev, evo, 6*4, 32, 0, &obj);
64 if (ret)
65 return ret;
66 obj->engine = NVOBJ_ENGINE_DISPLAY;
67
68 ret = nouveau_gpuobj_ref_add(dev, evo, name, obj, NULL);
69 if (ret) {
70 nouveau_gpuobj_del(dev, &obj);
71 return ret;
72 }
73
74 dev_priv->engine.instmem.prepare_access(dev, true);
75 nv_wo32(dev, obj, 0, (tile_flags << 22) | (magic_flags << 16) | class);
76 nv_wo32(dev, obj, 1, limit);
77 nv_wo32(dev, obj, 2, offset);
78 nv_wo32(dev, obj, 3, 0x00000000);
79 nv_wo32(dev, obj, 4, 0x00000000);
80 nv_wo32(dev, obj, 5, 0x00010000);
81 dev_priv->engine.instmem.finish_access(dev);
82
83 return 0;
84}
85
86static int
87nv50_evo_channel_new(struct drm_device *dev, struct nouveau_channel **pchan)
88{
89 struct drm_nouveau_private *dev_priv = dev->dev_private;
90 struct nouveau_channel *chan;
91 int ret;
92
93 chan = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
94 if (!chan)
95 return -ENOMEM;
96 *pchan = chan;
97
98 chan->id = -1;
99 chan->dev = dev;
100 chan->user_get = 4;
101 chan->user_put = 0;
102
103 INIT_LIST_HEAD(&chan->ramht_refs);
104
105 ret = nouveau_gpuobj_new_ref(dev, NULL, NULL, 0, 32768, 0x1000,
106 NVOBJ_FLAG_ZERO_ALLOC, &chan->ramin);
107 if (ret) {
108 NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
109 nv50_evo_channel_del(pchan);
110 return ret;
111 }
112
Ben Skeggsb833ac22010-06-01 15:32:24 +1000113 ret = drm_mm_init(&chan->ramin_heap,
114 chan->ramin->gpuobj->im_pramin->start, 32768);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000115 if (ret) {
116 NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
117 nv50_evo_channel_del(pchan);
118 return ret;
119 }
120
121 ret = nouveau_gpuobj_new_ref(dev, chan, chan, 0, 4096, 16,
122 0, &chan->ramht);
123 if (ret) {
124 NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
125 nv50_evo_channel_del(pchan);
126 return ret;
127 }
128
129 if (dev_priv->chipset != 0x50) {
130 ret = nv50_evo_dmaobj_new(chan, 0x3d, NvEvoFB16, 0x70, 0x19,
131 0, 0xffffffff);
132 if (ret) {
133 nv50_evo_channel_del(pchan);
134 return ret;
135 }
136
137
138 ret = nv50_evo_dmaobj_new(chan, 0x3d, NvEvoFB32, 0x7a, 0x19,
139 0, 0xffffffff);
140 if (ret) {
141 nv50_evo_channel_del(pchan);
142 return ret;
143 }
144 }
145
146 ret = nv50_evo_dmaobj_new(chan, 0x3d, NvEvoVRAM, 0, 0x19,
Ben Skeggsa76fb4e2010-03-18 09:45:20 +1000147 0, dev_priv->vram_size);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000148 if (ret) {
149 nv50_evo_channel_del(pchan);
150 return ret;
151 }
152
153 ret = nouveau_bo_new(dev, NULL, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
154 false, true, &chan->pushbuf_bo);
155 if (ret == 0)
156 ret = nouveau_bo_pin(chan->pushbuf_bo, TTM_PL_FLAG_VRAM);
157 if (ret) {
158 NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
159 nv50_evo_channel_del(pchan);
160 return ret;
161 }
162
163 ret = nouveau_bo_map(chan->pushbuf_bo);
164 if (ret) {
165 NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
166 nv50_evo_channel_del(pchan);
167 return ret;
168 }
169
170 chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
171 NV50_PDISPLAY_USER(0), PAGE_SIZE);
172 if (!chan->user) {
173 NV_ERROR(dev, "Error mapping EVO control regs.\n");
174 nv50_evo_channel_del(pchan);
175 return -ENOMEM;
176 }
177
178 return 0;
179}
180
181int
182nv50_display_init(struct drm_device *dev)
183{
184 struct drm_nouveau_private *dev_priv = dev->dev_private;
185 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
186 struct nouveau_channel *evo = dev_priv->evo;
187 struct drm_connector *connector;
188 uint32_t val, ram_amount, hpd_en[2];
189 uint64_t start;
190 int ret, i;
191
Maarten Maathuisef2bb502009-12-13 16:53:12 +0100192 NV_DEBUG_KMS(dev, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000193
194 nv_wr32(dev, 0x00610184, nv_rd32(dev, 0x00614004));
195 /*
196 * I think the 0x006101XX range is some kind of main control area
197 * that enables things.
198 */
199 /* CRTC? */
200 for (i = 0; i < 2; i++) {
201 val = nv_rd32(dev, 0x00616100 + (i * 0x800));
202 nv_wr32(dev, 0x00610190 + (i * 0x10), val);
203 val = nv_rd32(dev, 0x00616104 + (i * 0x800));
204 nv_wr32(dev, 0x00610194 + (i * 0x10), val);
205 val = nv_rd32(dev, 0x00616108 + (i * 0x800));
206 nv_wr32(dev, 0x00610198 + (i * 0x10), val);
207 val = nv_rd32(dev, 0x0061610c + (i * 0x800));
208 nv_wr32(dev, 0x0061019c + (i * 0x10), val);
209 }
210 /* DAC */
211 for (i = 0; i < 3; i++) {
212 val = nv_rd32(dev, 0x0061a000 + (i * 0x800));
213 nv_wr32(dev, 0x006101d0 + (i * 0x04), val);
214 }
215 /* SOR */
216 for (i = 0; i < 4; i++) {
217 val = nv_rd32(dev, 0x0061c000 + (i * 0x800));
218 nv_wr32(dev, 0x006101e0 + (i * 0x04), val);
219 }
220 /* Something not yet in use, tv-out maybe. */
221 for (i = 0; i < 3; i++) {
222 val = nv_rd32(dev, 0x0061e000 + (i * 0x800));
223 nv_wr32(dev, 0x006101f0 + (i * 0x04), val);
224 }
225
226 for (i = 0; i < 3; i++) {
227 nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(i), 0x00550000 |
228 NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING);
229 nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL1(i), 0x00000001);
230 }
231
232 /* This used to be in crtc unblank, but seems out of place there. */
233 nv_wr32(dev, NV50_PDISPLAY_UNK_380, 0);
234 /* RAM is clamped to 256 MiB. */
Ben Skeggsa76fb4e2010-03-18 09:45:20 +1000235 ram_amount = dev_priv->vram_size;
Maarten Maathuisef2bb502009-12-13 16:53:12 +0100236 NV_DEBUG_KMS(dev, "ram_amount %d\n", ram_amount);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000237 if (ram_amount > 256*1024*1024)
238 ram_amount = 256*1024*1024;
239 nv_wr32(dev, NV50_PDISPLAY_RAM_AMOUNT, ram_amount - 1);
240 nv_wr32(dev, NV50_PDISPLAY_UNK_388, 0x150000);
241 nv_wr32(dev, NV50_PDISPLAY_UNK_38C, 0);
242
243 /* The precise purpose is unknown, i suspect it has something to do
244 * with text mode.
245 */
246 if (nv_rd32(dev, NV50_PDISPLAY_INTR_1) & 0x100) {
247 nv_wr32(dev, NV50_PDISPLAY_INTR_1, 0x100);
248 nv_wr32(dev, 0x006194e8, nv_rd32(dev, 0x006194e8) & ~1);
249 if (!nv_wait(0x006194e8, 2, 0)) {
250 NV_ERROR(dev, "timeout: (0x6194e8 & 2) != 0\n");
251 NV_ERROR(dev, "0x6194e8 = 0x%08x\n",
252 nv_rd32(dev, 0x6194e8));
253 return -EBUSY;
254 }
255 }
256
257 /* taken from nv bug #12637, attempts to un-wedge the hw if it's
258 * stuck in some unspecified state
259 */
260 start = ptimer->read(dev);
261 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_STAT(0), 0x2b00);
262 while ((val = nv_rd32(dev, NV50_PDISPLAY_CHANNEL_STAT(0))) & 0x1e0000) {
263 if ((val & 0x9f0000) == 0x20000)
264 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_STAT(0),
265 val | 0x800000);
266
267 if ((val & 0x3f0000) == 0x30000)
268 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_STAT(0),
269 val | 0x200000);
270
271 if (ptimer->read(dev) - start > 1000000000ULL) {
272 NV_ERROR(dev, "timeout: (0x610200 & 0x1e0000) != 0\n");
273 NV_ERROR(dev, "0x610200 = 0x%08x\n", val);
274 return -EBUSY;
275 }
276 }
277
278 nv_wr32(dev, NV50_PDISPLAY_CTRL_STATE, NV50_PDISPLAY_CTRL_STATE_ENABLE);
279 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_STAT(0), 0x1000b03);
280 if (!nv_wait(NV50_PDISPLAY_CHANNEL_STAT(0), 0x40000000, 0x40000000)) {
281 NV_ERROR(dev, "timeout: (0x610200 & 0x40000000) == 0x40000000\n");
282 NV_ERROR(dev, "0x610200 = 0x%08x\n",
283 nv_rd32(dev, NV50_PDISPLAY_CHANNEL_STAT(0)));
284 return -EBUSY;
285 }
286
287 for (i = 0; i < 2; i++) {
288 nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), 0x2000);
289 if (!nv_wait(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
290 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS, 0)) {
291 NV_ERROR(dev, "timeout: CURSOR_CTRL2_STATUS == 0\n");
292 NV_ERROR(dev, "CURSOR_CTRL2 = 0x%08x\n",
293 nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
294 return -EBUSY;
295 }
296
297 nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
298 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON);
299 if (!nv_wait(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
300 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS,
301 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE)) {
302 NV_ERROR(dev, "timeout: "
303 "CURSOR_CTRL2_STATUS_ACTIVE(%d)\n", i);
304 NV_ERROR(dev, "CURSOR_CTRL2(%d) = 0x%08x\n", i,
305 nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
306 return -EBUSY;
307 }
308 }
309
310 nv_wr32(dev, NV50_PDISPLAY_OBJECTS, (evo->ramin->instance >> 8) | 9);
311
312 /* initialise fifo */
313 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_DMA_CB(0),
314 ((evo->pushbuf_bo->bo.mem.mm_node->start << PAGE_SHIFT) >> 8) |
315 NV50_PDISPLAY_CHANNEL_DMA_CB_LOCATION_VRAM |
316 NV50_PDISPLAY_CHANNEL_DMA_CB_VALID);
317 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_UNK2(0), 0x00010000);
318 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_UNK3(0), 0x00000002);
319 if (!nv_wait(0x610200, 0x80000000, 0x00000000)) {
320 NV_ERROR(dev, "timeout: (0x610200 & 0x80000000) == 0\n");
321 NV_ERROR(dev, "0x610200 = 0x%08x\n", nv_rd32(dev, 0x610200));
322 return -EBUSY;
323 }
324 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_STAT(0),
325 (nv_rd32(dev, NV50_PDISPLAY_CHANNEL_STAT(0)) & ~0x00000003) |
326 NV50_PDISPLAY_CHANNEL_STAT_DMA_ENABLED);
327 nv_wr32(dev, NV50_PDISPLAY_USER_PUT(0), 0);
328 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_STAT(0), 0x01000003 |
329 NV50_PDISPLAY_CHANNEL_STAT_DMA_ENABLED);
330 nv_wr32(dev, 0x610300, nv_rd32(dev, 0x610300) & ~1);
331
332 evo->dma.max = (4096/4) - 2;
333 evo->dma.put = 0;
334 evo->dma.cur = evo->dma.put;
335 evo->dma.free = evo->dma.max - evo->dma.cur;
336
337 ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
338 if (ret)
339 return ret;
340
341 for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
342 OUT_RING(evo, 0);
343
344 ret = RING_SPACE(evo, 11);
345 if (ret)
346 return ret;
347 BEGIN_RING(evo, 0, NV50_EVO_UNK84, 2);
348 OUT_RING(evo, NV50_EVO_UNK84_NOTIFY_DISABLED);
349 OUT_RING(evo, NV50_EVO_DMA_NOTIFY_HANDLE_NONE);
350 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, FB_DMA), 1);
351 OUT_RING(evo, NV50_EVO_CRTC_FB_DMA_HANDLE_NONE);
352 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, UNK0800), 1);
353 OUT_RING(evo, 0);
354 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, DISPLAY_START), 1);
355 OUT_RING(evo, 0);
356 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, UNK082C), 1);
357 OUT_RING(evo, 0);
358 FIRE_RING(evo);
359 if (!nv_wait(0x640004, 0xffffffff, evo->dma.put << 2))
360 NV_ERROR(dev, "evo pushbuf stalled\n");
361
362 /* enable clock change interrupts. */
363 nv_wr32(dev, 0x610028, 0x00010001);
364 nv_wr32(dev, NV50_PDISPLAY_INTR_EN, (NV50_PDISPLAY_INTR_EN_CLK_UNK10 |
365 NV50_PDISPLAY_INTR_EN_CLK_UNK20 |
366 NV50_PDISPLAY_INTR_EN_CLK_UNK40));
367
368 /* enable hotplug interrupts */
369 hpd_en[0] = hpd_en[1] = 0;
370 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
371 struct nouveau_connector *conn = nouveau_connector(connector);
372 struct dcb_gpio_entry *gpio;
373
Ben Skeggs11575632010-02-24 13:45:57 +1000374 if (conn->dcb->gpio_tag == 0xff)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000375 continue;
376
377 gpio = nouveau_bios_gpio_entry(dev, conn->dcb->gpio_tag);
378 if (!gpio)
379 continue;
380
381 hpd_en[gpio->line >> 4] |= (0x00010001 << (gpio->line & 0xf));
382 }
383
384 nv_wr32(dev, 0xe054, 0xffffffff);
385 nv_wr32(dev, 0xe050, hpd_en[0]);
386 if (dev_priv->chipset >= 0x90) {
387 nv_wr32(dev, 0xe074, 0xffffffff);
388 nv_wr32(dev, 0xe070, hpd_en[1]);
389 }
390
391 return 0;
392}
393
394static int nv50_display_disable(struct drm_device *dev)
395{
396 struct drm_nouveau_private *dev_priv = dev->dev_private;
397 struct drm_crtc *drm_crtc;
398 int ret, i;
399
Maarten Maathuisef2bb502009-12-13 16:53:12 +0100400 NV_DEBUG_KMS(dev, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000401
402 list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
403 struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
404
405 nv50_crtc_blank(crtc, true);
406 }
407
408 ret = RING_SPACE(dev_priv->evo, 2);
409 if (ret == 0) {
410 BEGIN_RING(dev_priv->evo, 0, NV50_EVO_UPDATE, 1);
411 OUT_RING(dev_priv->evo, 0);
412 }
413 FIRE_RING(dev_priv->evo);
414
415 /* Almost like ack'ing a vblank interrupt, maybe in the spirit of
416 * cleaning up?
417 */
418 list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
419 struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
420 uint32_t mask = NV50_PDISPLAY_INTR_1_VBLANK_CRTC_(crtc->index);
421
422 if (!crtc->base.enabled)
423 continue;
424
425 nv_wr32(dev, NV50_PDISPLAY_INTR_1, mask);
426 if (!nv_wait(NV50_PDISPLAY_INTR_1, mask, mask)) {
427 NV_ERROR(dev, "timeout: (0x610024 & 0x%08x) == "
428 "0x%08x\n", mask, mask);
429 NV_ERROR(dev, "0x610024 = 0x%08x\n",
430 nv_rd32(dev, NV50_PDISPLAY_INTR_1));
431 }
432 }
433
434 nv_wr32(dev, NV50_PDISPLAY_CHANNEL_STAT(0), 0);
435 nv_wr32(dev, NV50_PDISPLAY_CTRL_STATE, 0);
436 if (!nv_wait(NV50_PDISPLAY_CHANNEL_STAT(0), 0x1e0000, 0)) {
437 NV_ERROR(dev, "timeout: (0x610200 & 0x1e0000) == 0\n");
438 NV_ERROR(dev, "0x610200 = 0x%08x\n",
439 nv_rd32(dev, NV50_PDISPLAY_CHANNEL_STAT(0)));
440 }
441
442 for (i = 0; i < 3; i++) {
443 if (!nv_wait(NV50_PDISPLAY_SOR_DPMS_STATE(i),
444 NV50_PDISPLAY_SOR_DPMS_STATE_WAIT, 0)) {
445 NV_ERROR(dev, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i);
446 NV_ERROR(dev, "SOR_DPMS_STATE(%d) = 0x%08x\n", i,
447 nv_rd32(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i)));
448 }
449 }
450
451 /* disable interrupts. */
452 nv_wr32(dev, NV50_PDISPLAY_INTR_EN, 0x00000000);
453
454 /* disable hotplug interrupts */
455 nv_wr32(dev, 0xe054, 0xffffffff);
456 nv_wr32(dev, 0xe050, 0x00000000);
457 if (dev_priv->chipset >= 0x90) {
458 nv_wr32(dev, 0xe074, 0xffffffff);
459 nv_wr32(dev, 0xe070, 0x00000000);
460 }
461 return 0;
462}
463
464int nv50_display_create(struct drm_device *dev)
465{
466 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs04a39c52010-02-24 10:03:05 +1000467 struct dcb_table *dcb = &dev_priv->vbios.dcb;
Ben Skeggs8f1a6082010-06-28 14:35:50 +1000468 struct drm_connector *connector, *ct;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000469 int ret, i;
470
Maarten Maathuisef2bb502009-12-13 16:53:12 +0100471 NV_DEBUG_KMS(dev, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000472
473 /* init basic kernel modesetting */
474 drm_mode_config_init(dev);
475
476 /* Initialise some optional connector properties. */
477 drm_mode_create_scaling_mode_property(dev);
478 drm_mode_create_dithering_property(dev);
479
480 dev->mode_config.min_width = 0;
481 dev->mode_config.min_height = 0;
482
483 dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
484
485 dev->mode_config.max_width = 8192;
486 dev->mode_config.max_height = 8192;
487
488 dev->mode_config.fb_base = dev_priv->fb_phys;
489
490 /* Create EVO channel */
491 ret = nv50_evo_channel_new(dev, &dev_priv->evo);
492 if (ret) {
493 NV_ERROR(dev, "Error creating EVO channel: %d\n", ret);
494 return ret;
495 }
496
497 /* Create CRTC objects */
498 for (i = 0; i < 2; i++)
499 nv50_crtc_create(dev, i);
500
501 /* We setup the encoders from the BIOS table */
502 for (i = 0 ; i < dcb->entries; i++) {
503 struct dcb_entry *entry = &dcb->entry[i];
504
505 if (entry->location != DCB_LOC_ON_CHIP) {
506 NV_WARN(dev, "Off-chip encoder %d/%d unsupported\n",
507 entry->type, ffs(entry->or) - 1);
508 continue;
509 }
510
Ben Skeggs8f1a6082010-06-28 14:35:50 +1000511 connector = nouveau_connector_create(dev, entry->connector);
512 if (IS_ERR(connector))
513 continue;
514
Ben Skeggs6ee73862009-12-11 19:24:15 +1000515 switch (entry->type) {
516 case OUTPUT_TMDS:
517 case OUTPUT_LVDS:
518 case OUTPUT_DP:
Ben Skeggs8f1a6082010-06-28 14:35:50 +1000519 nv50_sor_create(connector, entry);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000520 break;
521 case OUTPUT_ANALOG:
Ben Skeggs8f1a6082010-06-28 14:35:50 +1000522 nv50_dac_create(connector, entry);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000523 break;
524 default:
525 NV_WARN(dev, "DCB encoder %d unknown\n", entry->type);
526 continue;
527 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000528 }
529
Ben Skeggs8f1a6082010-06-28 14:35:50 +1000530 list_for_each_entry_safe(connector, ct,
531 &dev->mode_config.connector_list, head) {
532 if (!connector->encoder_ids[0]) {
533 NV_WARN(dev, "%s has no encoders, removing\n",
534 drm_get_connector_name(connector));
535 connector->funcs->destroy(connector);
536 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000537 }
538
539 ret = nv50_display_init(dev);
Ben Skeggsa1663ed2010-03-25 16:01:04 +1000540 if (ret) {
541 nv50_display_destroy(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000542 return ret;
Ben Skeggsa1663ed2010-03-25 16:01:04 +1000543 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000544
545 return 0;
546}
547
548int nv50_display_destroy(struct drm_device *dev)
549{
550 struct drm_nouveau_private *dev_priv = dev->dev_private;
551
Maarten Maathuisef2bb502009-12-13 16:53:12 +0100552 NV_DEBUG_KMS(dev, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000553
554 drm_mode_config_cleanup(dev);
555
556 nv50_display_disable(dev);
557 nv50_evo_channel_del(&dev_priv->evo);
558
559 return 0;
560}
561
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000562static u16
563nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb,
564 u32 mc, int pxclk)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000565{
566 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs75c722d2009-12-21 12:16:52 +1000567 struct nouveau_connector *nv_connector = NULL;
568 struct drm_encoder *encoder;
Ben Skeggs04a39c52010-02-24 10:03:05 +1000569 struct nvbios *bios = &dev_priv->vbios;
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000570 u32 script = 0, or;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000571
Ben Skeggs75c722d2009-12-21 12:16:52 +1000572 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
573 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
574
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000575 if (nv_encoder->dcb != dcb)
Ben Skeggs75c722d2009-12-21 12:16:52 +1000576 continue;
577
578 nv_connector = nouveau_encoder_connector_get(nv_encoder);
579 break;
580 }
581
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000582 or = ffs(dcb->or) - 1;
583 switch (dcb->type) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000584 case OUTPUT_LVDS:
585 script = (mc >> 8) & 0xf;
Ben Skeggs04a39c52010-02-24 10:03:05 +1000586 if (bios->fp_no_ddc) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000587 if (bios->fp.dual_link)
588 script |= 0x0100;
589 if (bios->fp.if_is_24bit)
590 script |= 0x0200;
591 } else {
592 if (pxclk >= bios->fp.duallink_transition_clk) {
593 script |= 0x0100;
594 if (bios->fp.strapless_is_24bit & 2)
595 script |= 0x0200;
596 } else
597 if (bios->fp.strapless_is_24bit & 1)
598 script |= 0x0200;
Ben Skeggs75c722d2009-12-21 12:16:52 +1000599
600 if (nv_connector && nv_connector->edid &&
601 (nv_connector->edid->revision >= 4) &&
602 (nv_connector->edid->input & 0x70) >= 0x20)
603 script |= 0x0200;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000604 }
605
606 if (nouveau_uscript_lvds >= 0) {
607 NV_INFO(dev, "override script 0x%04x with 0x%04x "
608 "for output LVDS-%d\n", script,
609 nouveau_uscript_lvds, or);
610 script = nouveau_uscript_lvds;
611 }
612 break;
613 case OUTPUT_TMDS:
614 script = (mc >> 8) & 0xf;
615 if (pxclk >= 165000)
616 script |= 0x0100;
617
618 if (nouveau_uscript_tmds >= 0) {
619 NV_INFO(dev, "override script 0x%04x with 0x%04x "
620 "for output TMDS-%d\n", script,
621 nouveau_uscript_tmds, or);
622 script = nouveau_uscript_tmds;
623 }
624 break;
625 case OUTPUT_DP:
626 script = (mc >> 8) & 0xf;
627 break;
628 case OUTPUT_ANALOG:
629 script = 0xff;
630 break;
631 default:
632 NV_ERROR(dev, "modeset on unsupported output type!\n");
633 break;
634 }
635
636 return script;
637}
638
639static void
640nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc)
641{
642 struct drm_nouveau_private *dev_priv = dev->dev_private;
643 struct nouveau_channel *chan;
644 struct list_head *entry, *tmp;
645
646 list_for_each_safe(entry, tmp, &dev_priv->vbl_waiting) {
647 chan = list_entry(entry, struct nouveau_channel, nvsw.vbl_wait);
648
649 nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset,
650 chan->nvsw.vblsem_rval);
651 list_del(&chan->nvsw.vbl_wait);
652 }
653}
654
655static void
656nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr)
657{
658 intr &= NV50_PDISPLAY_INTR_1_VBLANK_CRTC;
659
660 if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0)
661 nv50_display_vblank_crtc_handler(dev, 0);
662
663 if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1)
664 nv50_display_vblank_crtc_handler(dev, 1);
665
666 nv_wr32(dev, NV50_PDISPLAY_INTR_EN, nv_rd32(dev,
667 NV50_PDISPLAY_INTR_EN) & ~intr);
668 nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr);
669}
670
671static void
672nv50_display_unk10_handler(struct drm_device *dev)
673{
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000674 struct drm_nouveau_private *dev_priv = dev->dev_private;
675 u32 unk30 = nv_rd32(dev, 0x610030), mc;
676 int i, crtc, or, type = OUTPUT_ANY;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000677
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000678 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
679 dev_priv->evo_irq.dcb = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000680
681 nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8);
682
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000683 /* Determine which CRTC we're dealing with, only 1 ever will be
684 * signalled at the same time with the current nouveau code.
685 */
686 crtc = ffs((unk30 & 0x00000060) >> 5) - 1;
687 if (crtc < 0)
688 goto ack;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000689
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000690 /* Nothing needs to be done for the encoder */
691 crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
692 if (crtc < 0)
693 goto ack;
694
695 /* Find which encoder was connected to the CRTC */
696 for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
697 mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i));
698 NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
699 if (!(mc & (1 << crtc)))
700 continue;
701
702 switch ((mc & 0x00000f00) >> 8) {
703 case 0: type = OUTPUT_ANALOG; break;
704 case 1: type = OUTPUT_TV; break;
705 default:
706 NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
707 goto ack;
708 }
709
710 or = i;
711 }
712
713 for (i = 0; type == OUTPUT_ANY && i < 4; i++) {
714 if (dev_priv->chipset < 0x90 ||
715 dev_priv->chipset == 0x92 ||
716 dev_priv->chipset == 0xa0)
717 mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i));
718 else
719 mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i));
720
721 NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
722 if (!(mc & (1 << crtc)))
723 continue;
724
725 switch ((mc & 0x00000f00) >> 8) {
726 case 0: type = OUTPUT_LVDS; break;
727 case 1: type = OUTPUT_TMDS; break;
728 case 2: type = OUTPUT_TMDS; break;
729 case 5: type = OUTPUT_TMDS; break;
730 case 8: type = OUTPUT_DP; break;
731 case 9: type = OUTPUT_DP; break;
732 default:
733 NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
734 goto ack;
735 }
736
737 or = i;
738 }
739
740 /* There was no encoder to disable */
741 if (type == OUTPUT_ANY)
742 goto ack;
743
744 /* Disable the encoder */
745 for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
746 struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
747
748 if (dcb->type == type && (dcb->or & (1 << or))) {
749 nouveau_bios_run_display_table(dev, dcb, 0, -1);
750 dev_priv->evo_irq.dcb = dcb;
751 goto ack;
752 }
753 }
754
755 NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000756ack:
757 nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10);
758 nv_wr32(dev, 0x610030, 0x80000000);
759}
760
761static void
Ben Skeggsafa3b4c2010-04-23 08:21:48 +1000762nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb)
763{
764 int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
765 struct drm_encoder *encoder;
766 uint32_t tmp, unk0 = 0, unk1 = 0;
767
768 if (dcb->type != OUTPUT_DP)
769 return;
770
771 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
772 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
773
774 if (nv_encoder->dcb == dcb) {
775 unk0 = nv_encoder->dp.unk0;
776 unk1 = nv_encoder->dp.unk1;
777 break;
778 }
779 }
780
781 if (unk0 || unk1) {
782 tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
783 tmp &= 0xfffffe03;
784 nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0);
785
786 tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link));
787 tmp &= 0xfef080c0;
788 nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1);
789 }
790}
791
Ben Skeggs7149eee2010-06-30 15:25:57 +1000792/* If programming a TMDS output on a SOR that can also be configured for
793 * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
794 *
795 * It looks like the VBIOS TMDS scripts make an attempt at this, however,
796 * the VBIOS scripts on at least one board I have only switch it off on
797 * link 0, causing a blank display if the output has previously been
798 * programmed for DisplayPort.
799 */
800static void
801nv50_display_unk20_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb)
802{
803 int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
804 struct drm_encoder *encoder;
805 u32 tmp;
806
807 if (dcb->type != OUTPUT_TMDS)
808 return;
809
810 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
811 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
812
813 if (nv_encoder->dcb->type == OUTPUT_DP) {
814 tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
815 tmp &= ~NV50_SOR_DP_CTRL_ENABLED;
816 nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp);
817 break;
818 }
819 }
820}
821
Ben Skeggsafa3b4c2010-04-23 08:21:48 +1000822static void
Ben Skeggs6ee73862009-12-11 19:24:15 +1000823nv50_display_unk20_handler(struct drm_device *dev)
824{
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000825 struct drm_nouveau_private *dev_priv = dev->dev_private;
826 u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc;
827 struct dcb_entry *dcb;
828 int i, crtc, or, type = OUTPUT_ANY;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000829
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000830 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
831 dcb = dev_priv->evo_irq.dcb;
832 if (dcb) {
833 nouveau_bios_run_display_table(dev, dcb, 0, -2);
834 dev_priv->evo_irq.dcb = NULL;
835 }
836
837 /* CRTC clock change requested? */
838 crtc = ffs((unk30 & 0x00000600) >> 9) - 1;
839 if (crtc >= 0) {
840 pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK));
841 pclk &= 0x003fffff;
842
843 nv50_crtc_set_clock(dev, crtc, pclk);
844
845 tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc));
846 tmp &= ~0x000000f;
847 nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp);
848 }
849
850 /* Nothing needs to be done for the encoder */
851 crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
852 if (crtc < 0)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000853 goto ack;
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000854 pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000855
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000856 /* Find which encoder is connected to the CRTC */
857 for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
858 mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i));
859 NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
860 if (!(mc & (1 << crtc)))
861 continue;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000862
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000863 switch ((mc & 0x00000f00) >> 8) {
864 case 0: type = OUTPUT_ANALOG; break;
865 case 1: type = OUTPUT_TV; break;
866 default:
867 NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
868 goto ack;
869 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000870
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000871 or = i;
872 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000873
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000874 for (i = 0; type == OUTPUT_ANY && i < 4; i++) {
875 if (dev_priv->chipset < 0x90 ||
876 dev_priv->chipset == 0x92 ||
877 dev_priv->chipset == 0xa0)
878 mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i));
879 else
880 mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000881
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000882 NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
883 if (!(mc & (1 << crtc)))
884 continue;
Ben Skeggsafa3b4c2010-04-23 08:21:48 +1000885
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000886 switch ((mc & 0x00000f00) >> 8) {
887 case 0: type = OUTPUT_LVDS; break;
888 case 1: type = OUTPUT_TMDS; break;
889 case 2: type = OUTPUT_TMDS; break;
890 case 5: type = OUTPUT_TMDS; break;
891 case 8: type = OUTPUT_DP; break;
892 case 9: type = OUTPUT_DP; break;
893 default:
894 NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
895 goto ack;
896 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000897
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000898 or = i;
899 }
900
901 if (type == OUTPUT_ANY)
902 goto ack;
903
904 /* Enable the encoder */
905 for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
906 dcb = &dev_priv->vbios.dcb.entry[i];
907 if (dcb->type == type && (dcb->or & (1 << or)))
908 break;
909 }
910
911 if (i == dev_priv->vbios.dcb.entries) {
912 NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
913 goto ack;
914 }
915
916 script = nv50_display_script_select(dev, dcb, mc, pclk);
917 nouveau_bios_run_display_table(dev, dcb, script, pclk);
918
919 nv50_display_unk20_dp_hack(dev, dcb);
920 nv50_display_unk20_dp_set_tmds(dev, dcb);
921
922 if (dcb->type != OUTPUT_ANALOG) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000923 tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or));
924 tmp &= ~0x00000f0f;
925 if (script & 0x0100)
926 tmp |= 0x00000101;
927 nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp);
928 } else {
929 nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0);
930 }
931
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000932 dev_priv->evo_irq.dcb = dcb;
933 dev_priv->evo_irq.pclk = pclk;
934 dev_priv->evo_irq.script = script;
935
Ben Skeggs6ee73862009-12-11 19:24:15 +1000936ack:
937 nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20);
938 nv_wr32(dev, 0x610030, 0x80000000);
939}
940
941static void
942nv50_display_unk40_handler(struct drm_device *dev)
943{
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000944 struct drm_nouveau_private *dev_priv = dev->dev_private;
945 struct dcb_entry *dcb = dev_priv->evo_irq.dcb;
946 u16 script = dev_priv->evo_irq.script;
947 u32 unk30 = nv_rd32(dev, 0x610030), pclk = dev_priv->evo_irq.pclk;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000948
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000949 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
950 dev_priv->evo_irq.dcb = NULL;
951 if (!dcb)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000952 goto ack;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000953
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000954 nouveau_bios_run_display_table(dev, dcb, script, -pclk);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000955ack:
956 nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40);
957 nv_wr32(dev, 0x610030, 0x80000000);
958 nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8);
959}
960
961void
962nv50_display_irq_handler_bh(struct work_struct *work)
963{
964 struct drm_nouveau_private *dev_priv =
965 container_of(work, struct drm_nouveau_private, irq_work);
966 struct drm_device *dev = dev_priv->dev;
967
968 for (;;) {
969 uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
970 uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
971
Maarten Maathuisef2bb502009-12-13 16:53:12 +0100972 NV_DEBUG_KMS(dev, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0, intr1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000973
974 if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10)
975 nv50_display_unk10_handler(dev);
976 else
977 if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20)
978 nv50_display_unk20_handler(dev);
979 else
980 if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40)
981 nv50_display_unk40_handler(dev);
982 else
983 break;
984 }
985
986 nv_wr32(dev, NV03_PMC_INTR_EN_0, 1);
987}
988
989static void
990nv50_display_error_handler(struct drm_device *dev)
991{
992 uint32_t addr, data;
993
994 nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000);
995 addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR);
996 data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA);
997
998 NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x (0x%04x 0x%02x)\n",
999 0, addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf);
1000
1001 nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR, 0x90000000);
1002}
1003
Ben Skeggsa5acac62010-03-30 15:14:41 +10001004void
1005nv50_display_irq_hotplug_bh(struct work_struct *work)
Ben Skeggs6ee73862009-12-11 19:24:15 +10001006{
Ben Skeggsa5acac62010-03-30 15:14:41 +10001007 struct drm_nouveau_private *dev_priv =
1008 container_of(work, struct drm_nouveau_private, hpd_work);
1009 struct drm_device *dev = dev_priv->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +10001010 struct drm_connector *connector;
1011 const uint32_t gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 };
1012 uint32_t unplug_mask, plug_mask, change_mask;
1013 uint32_t hpd0, hpd1 = 0;
1014
1015 hpd0 = nv_rd32(dev, 0xe054) & nv_rd32(dev, 0xe050);
1016 if (dev_priv->chipset >= 0x90)
1017 hpd1 = nv_rd32(dev, 0xe074) & nv_rd32(dev, 0xe070);
1018
1019 plug_mask = (hpd0 & 0x0000ffff) | (hpd1 << 16);
1020 unplug_mask = (hpd0 >> 16) | (hpd1 & 0xffff0000);
1021 change_mask = plug_mask | unplug_mask;
1022
1023 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1024 struct drm_encoder_helper_funcs *helper;
1025 struct nouveau_connector *nv_connector =
1026 nouveau_connector(connector);
1027 struct nouveau_encoder *nv_encoder;
1028 struct dcb_gpio_entry *gpio;
1029 uint32_t reg;
1030 bool plugged;
1031
1032 if (!nv_connector->dcb)
1033 continue;
1034
1035 gpio = nouveau_bios_gpio_entry(dev, nv_connector->dcb->gpio_tag);
1036 if (!gpio || !(change_mask & (1 << gpio->line)))
1037 continue;
1038
1039 reg = nv_rd32(dev, gpio_reg[gpio->line >> 3]);
1040 plugged = !!(reg & (4 << ((gpio->line & 7) << 2)));
1041 NV_INFO(dev, "%splugged %s\n", plugged ? "" : "un",
1042 drm_get_connector_name(connector)) ;
1043
1044 if (!connector->encoder || !connector->encoder->crtc ||
1045 !connector->encoder->crtc->enabled)
1046 continue;
1047 nv_encoder = nouveau_encoder(connector->encoder);
1048 helper = connector->encoder->helper_private;
1049
1050 if (nv_encoder->dcb->type != OUTPUT_DP)
1051 continue;
1052
1053 if (plugged)
1054 helper->dpms(connector->encoder, DRM_MODE_DPMS_ON);
1055 else
1056 helper->dpms(connector->encoder, DRM_MODE_DPMS_OFF);
1057 }
1058
1059 nv_wr32(dev, 0xe054, nv_rd32(dev, 0xe054));
1060 if (dev_priv->chipset >= 0x90)
1061 nv_wr32(dev, 0xe074, nv_rd32(dev, 0xe074));
Dave Airlie4abe3522010-03-30 05:34:18 +00001062
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001063 drm_helper_hpd_irq_event(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001064}
1065
1066void
1067nv50_display_irq_handler(struct drm_device *dev)
1068{
1069 struct drm_nouveau_private *dev_priv = dev->dev_private;
1070 uint32_t delayed = 0;
1071
Ben Skeggsa5acac62010-03-30 15:14:41 +10001072 if (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_HOTPLUG) {
1073 if (!work_pending(&dev_priv->hpd_work))
1074 queue_work(dev_priv->wq, &dev_priv->hpd_work);
1075 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001076
1077 while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) {
1078 uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
1079 uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
1080 uint32_t clock;
1081
Maarten Maathuisef2bb502009-12-13 16:53:12 +01001082 NV_DEBUG_KMS(dev, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0, intr1);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001083
1084 if (!intr0 && !(intr1 & ~delayed))
1085 break;
1086
1087 if (intr0 & 0x00010000) {
1088 nv50_display_error_handler(dev);
1089 intr0 &= ~0x00010000;
1090 }
1091
1092 if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) {
1093 nv50_display_vblank_handler(dev, intr1);
1094 intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC;
1095 }
1096
1097 clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 |
1098 NV50_PDISPLAY_INTR_1_CLK_UNK20 |
1099 NV50_PDISPLAY_INTR_1_CLK_UNK40));
1100 if (clock) {
1101 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
1102 if (!work_pending(&dev_priv->irq_work))
1103 queue_work(dev_priv->wq, &dev_priv->irq_work);
1104 delayed |= clock;
1105 intr1 &= ~clock;
1106 }
1107
1108 if (intr0) {
1109 NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0);
1110 nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0);
1111 }
1112
1113 if (intr1) {
1114 NV_ERROR(dev,
1115 "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1);
1116 nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1);
1117 }
1118 }
1119}
1120