2 * Copyright 2011 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.
25 #include <linux/dma-mapping.h>
28 #include <drm/drm_crtc_helper.h>
29 #include <drm/drm_plane_helper.h>
30 #include <drm/drm_dp_helper.h>
32 #include <nvif/class.h>
34 #include "nouveau_drm.h"
35 #include "nouveau_dma.h"
36 #include "nouveau_gem.h"
37 #include "nouveau_connector.h"
38 #include "nouveau_encoder.h"
39 #include "nouveau_crtc.h"
40 #include "nouveau_fence.h"
41 #include "nv50_display.h"
45 #define EVO_MASTER (0x00)
46 #define EVO_FLIP(c) (0x01 + (c))
47 #define EVO_OVLY(c) (0x05 + (c))
48 #define EVO_OIMM(c) (0x09 + (c))
49 #define EVO_CURS(c) (0x0d + (c))
51 /* offsets in shared sync bo of various structures */
52 #define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
53 #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
54 #define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
55 #define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
57 /******************************************************************************
59 *****************************************************************************/
62 struct nvif_object user;
66 nv50_chan_create(struct nvif_object *disp, const u32 *oclass, u8 head,
67 void *data, u32 size, struct nv50_chan *chan)
69 const u32 handle = (oclass[0] << 16) | head;
73 ret = nvif_object_sclass(disp, sclass, ARRAY_SIZE(sclass));
74 WARN_ON(ret > ARRAY_SIZE(sclass));
79 for (i = 0; i < ARRAY_SIZE(sclass); i++) {
80 if (sclass[i] == oclass[0]) {
81 ret = nvif_object_init(disp, NULL, handle,
82 oclass[0], data, size,
85 nvif_object_map(&chan->user);
96 nv50_chan_destroy(struct nv50_chan *chan)
98 nvif_object_fini(&chan->user);
101 /******************************************************************************
103 *****************************************************************************/
106 struct nv50_chan base;
110 nv50_pioc_destroy(struct nv50_pioc *pioc)
112 nv50_chan_destroy(&pioc->base);
116 nv50_pioc_create(struct nvif_object *disp, const u32 *oclass, u8 head,
117 void *data, u32 size, struct nv50_pioc *pioc)
119 return nv50_chan_create(disp, oclass, head, data, size, &pioc->base);
122 /******************************************************************************
124 *****************************************************************************/
127 struct nv50_pioc base;
131 nv50_curs_create(struct nvif_object *disp, int head, struct nv50_curs *curs)
133 struct nv50_disp_cursor_v0 args = {
136 static const u32 oclass[] = {
145 return nv50_pioc_create(disp, oclass, head, &args, sizeof(args),
149 /******************************************************************************
151 *****************************************************************************/
154 struct nv50_pioc base;
158 nv50_oimm_create(struct nvif_object *disp, int head, struct nv50_oimm *oimm)
160 struct nv50_disp_cursor_v0 args = {
163 static const u32 oclass[] = {
172 return nv50_pioc_create(disp, oclass, head, &args, sizeof(args),
176 /******************************************************************************
178 *****************************************************************************/
181 struct nv50_chan base;
185 struct nvif_object sync;
186 struct nvif_object vram;
188 /* Protects against concurrent pushbuf access to this channel, lock is
189 * grabbed by evo_wait (if the pushbuf reservation is successful) and
190 * dropped again by evo_kick. */
195 nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp)
197 nvif_object_fini(&dmac->vram);
198 nvif_object_fini(&dmac->sync);
200 nv50_chan_destroy(&dmac->base);
203 struct pci_dev *pdev = nvkm_device(nvif_device(disp))->pdev;
204 pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle);
209 nv50_dmac_create(struct nvif_object *disp, const u32 *oclass, u8 head,
210 void *data, u32 size, u64 syncbuf,
211 struct nv50_dmac *dmac)
213 struct nvif_device *device = nvif_device(disp);
214 struct nv50_disp_core_channel_dma_v0 *args = data;
215 struct nvif_object pushbuf;
218 mutex_init(&dmac->lock);
220 dmac->ptr = pci_alloc_consistent(nvkm_device(device)->pdev,
221 PAGE_SIZE, &dmac->handle);
225 ret = nvif_object_init(nvif_object(device), NULL,
226 args->pushbuf, NV_DMA_FROM_MEMORY,
227 &(struct nv_dma_v0) {
228 .target = NV_DMA_V0_TARGET_PCI_US,
229 .access = NV_DMA_V0_ACCESS_RD,
230 .start = dmac->handle + 0x0000,
231 .limit = dmac->handle + 0x0fff,
232 }, sizeof(struct nv_dma_v0), &pushbuf);
236 ret = nv50_chan_create(disp, oclass, head, data, size, &dmac->base);
237 nvif_object_fini(&pushbuf);
241 ret = nvif_object_init(&dmac->base.user, NULL, 0xf0000000,
243 &(struct nv_dma_v0) {
244 .target = NV_DMA_V0_TARGET_VRAM,
245 .access = NV_DMA_V0_ACCESS_RDWR,
246 .start = syncbuf + 0x0000,
247 .limit = syncbuf + 0x0fff,
248 }, sizeof(struct nv_dma_v0),
253 ret = nvif_object_init(&dmac->base.user, NULL, 0xf0000001,
255 &(struct nv_dma_v0) {
256 .target = NV_DMA_V0_TARGET_VRAM,
257 .access = NV_DMA_V0_ACCESS_RDWR,
259 .limit = device->info.ram_user - 1,
260 }, sizeof(struct nv_dma_v0),
268 /******************************************************************************
270 *****************************************************************************/
273 struct nv50_dmac base;
277 nv50_core_create(struct nvif_object *disp, u64 syncbuf, struct nv50_mast *core)
279 struct nv50_disp_core_channel_dma_v0 args = {
280 .pushbuf = 0xb0007d00,
282 static const u32 oclass[] = {
283 GM204_DISP_CORE_CHANNEL_DMA,
284 GM107_DISP_CORE_CHANNEL_DMA,
285 GK110_DISP_CORE_CHANNEL_DMA,
286 GK104_DISP_CORE_CHANNEL_DMA,
287 GF110_DISP_CORE_CHANNEL_DMA,
288 GT214_DISP_CORE_CHANNEL_DMA,
289 GT206_DISP_CORE_CHANNEL_DMA,
290 GT200_DISP_CORE_CHANNEL_DMA,
291 G82_DISP_CORE_CHANNEL_DMA,
292 NV50_DISP_CORE_CHANNEL_DMA,
296 return nv50_dmac_create(disp, oclass, 0, &args, sizeof(args), syncbuf,
300 /******************************************************************************
302 *****************************************************************************/
305 struct nv50_dmac base;
311 nv50_base_create(struct nvif_object *disp, int head, u64 syncbuf,
312 struct nv50_sync *base)
314 struct nv50_disp_base_channel_dma_v0 args = {
315 .pushbuf = 0xb0007c00 | head,
318 static const u32 oclass[] = {
319 GK110_DISP_BASE_CHANNEL_DMA,
320 GK104_DISP_BASE_CHANNEL_DMA,
321 GF110_DISP_BASE_CHANNEL_DMA,
322 GT214_DISP_BASE_CHANNEL_DMA,
323 GT200_DISP_BASE_CHANNEL_DMA,
324 G82_DISP_BASE_CHANNEL_DMA,
325 NV50_DISP_BASE_CHANNEL_DMA,
329 return nv50_dmac_create(disp, oclass, head, &args, sizeof(args),
330 syncbuf, &base->base);
333 /******************************************************************************
335 *****************************************************************************/
338 struct nv50_dmac base;
342 nv50_ovly_create(struct nvif_object *disp, int head, u64 syncbuf,
343 struct nv50_ovly *ovly)
345 struct nv50_disp_overlay_channel_dma_v0 args = {
346 .pushbuf = 0xb0007e00 | head,
349 static const u32 oclass[] = {
350 GK104_DISP_OVERLAY_CONTROL_DMA,
351 GF110_DISP_OVERLAY_CONTROL_DMA,
352 GT214_DISP_OVERLAY_CHANNEL_DMA,
353 GT200_DISP_OVERLAY_CHANNEL_DMA,
354 G82_DISP_OVERLAY_CHANNEL_DMA,
355 NV50_DISP_OVERLAY_CHANNEL_DMA,
359 return nv50_dmac_create(disp, oclass, head, &args, sizeof(args),
360 syncbuf, &ovly->base);
364 struct nouveau_crtc base;
365 struct nouveau_bo *image;
366 struct nv50_curs curs;
367 struct nv50_sync sync;
368 struct nv50_ovly ovly;
369 struct nv50_oimm oimm;
372 #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
373 #define nv50_curs(c) (&nv50_head(c)->curs)
374 #define nv50_sync(c) (&nv50_head(c)->sync)
375 #define nv50_ovly(c) (&nv50_head(c)->ovly)
376 #define nv50_oimm(c) (&nv50_head(c)->oimm)
377 #define nv50_chan(c) (&(c)->base.base)
378 #define nv50_vers(c) nv50_chan(c)->user.oclass
381 struct list_head head;
382 struct nvif_object core;
383 struct nvif_object base[4];
387 struct nvif_object *disp;
388 struct nv50_mast mast;
390 struct list_head fbdma;
392 struct nouveau_bo *sync;
395 static struct nv50_disp *
396 nv50_disp(struct drm_device *dev)
398 return nouveau_display(dev)->priv;
401 #define nv50_mast(d) (&nv50_disp(d)->mast)
403 static struct drm_crtc *
404 nv50_display_crtc_get(struct drm_encoder *encoder)
406 return nouveau_encoder(encoder)->crtc;
409 /******************************************************************************
410 * EVO channel helpers
411 *****************************************************************************/
413 evo_wait(void *evoc, int nr)
415 struct nv50_dmac *dmac = evoc;
416 u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
418 mutex_lock(&dmac->lock);
419 if (put + nr >= (PAGE_SIZE / 4) - 8) {
420 dmac->ptr[put] = 0x20000000;
422 nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
423 if (!nvkm_wait(&dmac->base.user, 0x0004, ~0, 0x00000000)) {
424 mutex_unlock(&dmac->lock);
425 nv_error(nvkm_object(&dmac->base.user), "channel stalled\n");
432 return dmac->ptr + put;
436 evo_kick(u32 *push, void *evoc)
438 struct nv50_dmac *dmac = evoc;
439 nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
440 mutex_unlock(&dmac->lock);
443 #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
444 #define evo_data(p,d) *((p)++) = (d)
447 evo_sync_wait(void *data)
449 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
456 evo_sync(struct drm_device *dev)
458 struct nvif_device *device = &nouveau_drm(dev)->device;
459 struct nv50_disp *disp = nv50_disp(dev);
460 struct nv50_mast *mast = nv50_mast(dev);
461 u32 *push = evo_wait(mast, 8);
463 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
464 evo_mthd(push, 0x0084, 1);
465 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
466 evo_mthd(push, 0x0080, 2);
467 evo_data(push, 0x00000000);
468 evo_data(push, 0x00000000);
469 evo_kick(push, mast);
470 if (nv_wait_cb(nvkm_device(device), evo_sync_wait, disp->sync))
477 /******************************************************************************
478 * Page flipping channel
479 *****************************************************************************/
481 nv50_display_crtc_sema(struct drm_device *dev, int crtc)
483 return nv50_disp(dev)->sync;
486 struct nv50_display_flip {
487 struct nv50_disp *disp;
488 struct nv50_sync *chan;
492 nv50_display_flip_wait(void *data)
494 struct nv50_display_flip *flip = data;
495 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
503 nv50_display_flip_stop(struct drm_crtc *crtc)
505 struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
506 struct nv50_display_flip flip = {
507 .disp = nv50_disp(crtc->dev),
508 .chan = nv50_sync(crtc),
512 push = evo_wait(flip.chan, 8);
514 evo_mthd(push, 0x0084, 1);
515 evo_data(push, 0x00000000);
516 evo_mthd(push, 0x0094, 1);
517 evo_data(push, 0x00000000);
518 evo_mthd(push, 0x00c0, 1);
519 evo_data(push, 0x00000000);
520 evo_mthd(push, 0x0080, 1);
521 evo_data(push, 0x00000000);
522 evo_kick(push, flip.chan);
525 nv_wait_cb(nvkm_device(device), nv50_display_flip_wait, &flip);
529 nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
530 struct nouveau_channel *chan, u32 swap_interval)
532 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
533 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
534 struct nv50_head *head = nv50_head(crtc);
535 struct nv50_sync *sync = nv50_sync(crtc);
540 if (swap_interval == 0)
541 swap_interval |= 0x100;
545 push = evo_wait(sync, 128);
546 if (unlikely(push == NULL))
549 if (chan && chan->object->oclass < G82_CHANNEL_GPFIFO) {
550 ret = RING_SPACE(chan, 8);
554 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
555 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
556 OUT_RING (chan, sync->addr ^ 0x10);
557 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
558 OUT_RING (chan, sync->data + 1);
559 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
560 OUT_RING (chan, sync->addr);
561 OUT_RING (chan, sync->data);
563 if (chan && chan->object->oclass < FERMI_CHANNEL_GPFIFO) {
564 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
565 ret = RING_SPACE(chan, 12);
569 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
570 OUT_RING (chan, chan->vram.handle);
571 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
572 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
573 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
574 OUT_RING (chan, sync->data + 1);
575 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
576 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
577 OUT_RING (chan, upper_32_bits(addr));
578 OUT_RING (chan, lower_32_bits(addr));
579 OUT_RING (chan, sync->data);
580 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
583 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
584 ret = RING_SPACE(chan, 10);
588 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
589 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
590 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
591 OUT_RING (chan, sync->data + 1);
592 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
593 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
594 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
595 OUT_RING (chan, upper_32_bits(addr));
596 OUT_RING (chan, lower_32_bits(addr));
597 OUT_RING (chan, sync->data);
598 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
599 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
609 evo_mthd(push, 0x0100, 1);
610 evo_data(push, 0xfffe0000);
611 evo_mthd(push, 0x0084, 1);
612 evo_data(push, swap_interval);
613 if (!(swap_interval & 0x00000100)) {
614 evo_mthd(push, 0x00e0, 1);
615 evo_data(push, 0x40000000);
617 evo_mthd(push, 0x0088, 4);
618 evo_data(push, sync->addr);
619 evo_data(push, sync->data++);
620 evo_data(push, sync->data);
621 evo_data(push, sync->base.sync.handle);
622 evo_mthd(push, 0x00a0, 2);
623 evo_data(push, 0x00000000);
624 evo_data(push, 0x00000000);
625 evo_mthd(push, 0x00c0, 1);
626 evo_data(push, nv_fb->r_handle);
627 evo_mthd(push, 0x0110, 2);
628 evo_data(push, 0x00000000);
629 evo_data(push, 0x00000000);
630 if (nv50_vers(sync) < GF110_DISP_BASE_CHANNEL_DMA) {
631 evo_mthd(push, 0x0800, 5);
632 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
634 evo_data(push, (fb->height << 16) | fb->width);
635 evo_data(push, nv_fb->r_pitch);
636 evo_data(push, nv_fb->r_format);
638 evo_mthd(push, 0x0400, 5);
639 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
641 evo_data(push, (fb->height << 16) | fb->width);
642 evo_data(push, nv_fb->r_pitch);
643 evo_data(push, nv_fb->r_format);
645 evo_mthd(push, 0x0080, 1);
646 evo_data(push, 0x00000000);
647 evo_kick(push, sync);
649 nouveau_bo_ref(nv_fb->nvbo, &head->image);
653 /******************************************************************************
655 *****************************************************************************/
657 nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
659 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
660 struct nouveau_connector *nv_connector;
661 struct drm_connector *connector;
662 u32 *push, mode = 0x00;
664 nv_connector = nouveau_crtc_connector_get(nv_crtc);
665 connector = &nv_connector->base;
666 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
667 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
668 mode = DITHERING_MODE_DYNAMIC2X2;
670 mode = nv_connector->dithering_mode;
673 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
674 if (connector->display_info.bpc >= 8)
675 mode |= DITHERING_DEPTH_8BPC;
677 mode |= nv_connector->dithering_depth;
680 push = evo_wait(mast, 4);
682 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
683 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
684 evo_data(push, mode);
686 if (nv50_vers(mast) < GK104_DISP_CORE_CHANNEL_DMA) {
687 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
688 evo_data(push, mode);
690 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
691 evo_data(push, mode);
695 evo_mthd(push, 0x0080, 1);
696 evo_data(push, 0x00000000);
698 evo_kick(push, mast);
705 nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
707 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
708 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
709 struct drm_crtc *crtc = &nv_crtc->base;
710 struct nouveau_connector *nv_connector;
711 int mode = DRM_MODE_SCALE_NONE;
714 /* start off at the resolution we programmed the crtc for, this
715 * effectively handles NONE/FULL scaling
717 nv_connector = nouveau_crtc_connector_get(nv_crtc);
718 if (nv_connector && nv_connector->native_mode)
719 mode = nv_connector->scaling_mode;
721 if (mode != DRM_MODE_SCALE_NONE)
722 omode = nv_connector->native_mode;
726 oX = omode->hdisplay;
727 oY = omode->vdisplay;
728 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
731 /* add overscan compensation if necessary, will keep the aspect
732 * ratio the same as the backend mode unless overridden by the
733 * user setting both hborder and vborder properties.
735 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
736 (nv_connector->underscan == UNDERSCAN_AUTO &&
737 nv_connector->edid &&
738 drm_detect_hdmi_monitor(nv_connector->edid)))) {
739 u32 bX = nv_connector->underscan_hborder;
740 u32 bY = nv_connector->underscan_vborder;
741 u32 aspect = (oY << 19) / oX;
745 if (bY) oY -= (bY * 2);
746 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
748 oX -= (oX >> 4) + 32;
749 if (bY) oY -= (bY * 2);
750 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
754 /* handle CENTER/ASPECT scaling, taking into account the areas
755 * removed already for overscan compensation
758 case DRM_MODE_SCALE_CENTER:
759 oX = min((u32)umode->hdisplay, oX);
760 oY = min((u32)umode->vdisplay, oY);
762 case DRM_MODE_SCALE_ASPECT:
764 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
765 oX = ((oY * aspect) + (aspect / 2)) >> 19;
767 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
768 oY = ((oX * aspect) + (aspect / 2)) >> 19;
775 push = evo_wait(mast, 8);
777 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
778 /*XXX: SCALE_CTRL_ACTIVE??? */
779 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
780 evo_data(push, (oY << 16) | oX);
781 evo_data(push, (oY << 16) | oX);
782 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
783 evo_data(push, 0x00000000);
784 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
785 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
787 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
788 evo_data(push, (oY << 16) | oX);
789 evo_data(push, (oY << 16) | oX);
790 evo_data(push, (oY << 16) | oX);
791 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
792 evo_data(push, 0x00000000);
793 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
794 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
797 evo_kick(push, mast);
800 nv50_display_flip_stop(crtc);
801 nv50_display_flip_next(crtc, crtc->primary->fb,
810 nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
812 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
816 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
817 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
818 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
820 push = evo_wait(mast, 16);
822 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
823 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
824 evo_data(push, (hue << 20) | (vib << 8));
826 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
827 evo_data(push, (hue << 20) | (vib << 8));
831 evo_mthd(push, 0x0080, 1);
832 evo_data(push, 0x00000000);
834 evo_kick(push, mast);
841 nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
842 int x, int y, bool update)
844 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
845 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
848 push = evo_wait(mast, 16);
850 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
851 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
852 evo_data(push, nvfb->nvbo->bo.offset >> 8);
853 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
854 evo_data(push, (fb->height << 16) | fb->width);
855 evo_data(push, nvfb->r_pitch);
856 evo_data(push, nvfb->r_format);
857 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
858 evo_data(push, (y << 16) | x);
859 if (nv50_vers(mast) > NV50_DISP_CORE_CHANNEL_DMA) {
860 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
861 evo_data(push, nvfb->r_handle);
864 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
865 evo_data(push, nvfb->nvbo->bo.offset >> 8);
866 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
867 evo_data(push, (fb->height << 16) | fb->width);
868 evo_data(push, nvfb->r_pitch);
869 evo_data(push, nvfb->r_format);
870 evo_data(push, nvfb->r_handle);
871 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
872 evo_data(push, (y << 16) | x);
876 evo_mthd(push, 0x0080, 1);
877 evo_data(push, 0x00000000);
879 evo_kick(push, mast);
882 nv_crtc->fb.handle = nvfb->r_handle;
887 nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
889 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
890 u32 *push = evo_wait(mast, 16);
892 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
893 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
894 evo_data(push, 0x85000000);
895 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
897 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
898 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
899 evo_data(push, 0x85000000);
900 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
901 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
902 evo_data(push, mast->base.vram.handle);
904 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
905 evo_data(push, 0x85000000);
906 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
907 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
908 evo_data(push, mast->base.vram.handle);
910 evo_kick(push, mast);
915 nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
917 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
918 u32 *push = evo_wait(mast, 16);
920 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
921 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
922 evo_data(push, 0x05000000);
924 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
925 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
926 evo_data(push, 0x05000000);
927 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
928 evo_data(push, 0x00000000);
930 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
931 evo_data(push, 0x05000000);
932 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
933 evo_data(push, 0x00000000);
935 evo_kick(push, mast);
940 nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
942 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
945 nv50_crtc_cursor_show(nv_crtc);
947 nv50_crtc_cursor_hide(nv_crtc);
950 u32 *push = evo_wait(mast, 2);
952 evo_mthd(push, 0x0080, 1);
953 evo_data(push, 0x00000000);
954 evo_kick(push, mast);
960 nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
965 nv50_crtc_prepare(struct drm_crtc *crtc)
967 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
968 struct nv50_mast *mast = nv50_mast(crtc->dev);
971 nv50_display_flip_stop(crtc);
973 push = evo_wait(mast, 6);
975 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
976 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
977 evo_data(push, 0x00000000);
978 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
979 evo_data(push, 0x40000000);
981 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
982 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
983 evo_data(push, 0x00000000);
984 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
985 evo_data(push, 0x40000000);
986 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
987 evo_data(push, 0x00000000);
989 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
990 evo_data(push, 0x00000000);
991 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
992 evo_data(push, 0x03000000);
993 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
994 evo_data(push, 0x00000000);
997 evo_kick(push, mast);
1000 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
1004 nv50_crtc_commit(struct drm_crtc *crtc)
1006 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1007 struct nv50_mast *mast = nv50_mast(crtc->dev);
1010 push = evo_wait(mast, 32);
1012 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
1013 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1014 evo_data(push, nv_crtc->fb.handle);
1015 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1016 evo_data(push, 0xc0000000);
1017 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1019 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
1020 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1021 evo_data(push, nv_crtc->fb.handle);
1022 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1023 evo_data(push, 0xc0000000);
1024 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1025 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
1026 evo_data(push, mast->base.vram.handle);
1028 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
1029 evo_data(push, nv_crtc->fb.handle);
1030 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
1031 evo_data(push, 0x83000000);
1032 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1033 evo_data(push, 0x00000000);
1034 evo_data(push, 0x00000000);
1035 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
1036 evo_data(push, mast->base.vram.handle);
1037 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
1038 evo_data(push, 0xffffff00);
1041 evo_kick(push, mast);
1044 nv50_crtc_cursor_show_hide(nv_crtc, nv_crtc->cursor.visible, true);
1045 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
1049 nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
1050 struct drm_display_mode *adjusted_mode)
1052 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
1057 nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
1059 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
1060 struct nv50_head *head = nv50_head(crtc);
1063 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
1066 nouveau_bo_unpin(head->image);
1067 nouveau_bo_ref(nvfb->nvbo, &head->image);
1074 nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
1075 struct drm_display_mode *mode, int x, int y,
1076 struct drm_framebuffer *old_fb)
1078 struct nv50_mast *mast = nv50_mast(crtc->dev);
1079 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1080 struct nouveau_connector *nv_connector;
1081 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
1082 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
1083 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
1084 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
1085 u32 vblan2e = 0, vblan2s = 1, vblankus = 0;
1089 hactive = mode->htotal;
1090 hsynce = mode->hsync_end - mode->hsync_start - 1;
1091 hbackp = mode->htotal - mode->hsync_end;
1092 hblanke = hsynce + hbackp;
1093 hfrontp = mode->hsync_start - mode->hdisplay;
1094 hblanks = mode->htotal - hfrontp - 1;
1096 vactive = mode->vtotal * vscan / ilace;
1097 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
1098 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
1099 vblanke = vsynce + vbackp;
1100 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
1101 vblanks = vactive - vfrontp - 1;
1102 /* XXX: Safe underestimate, even "0" works */
1103 vblankus = (vactive - mode->vdisplay - 2) * hactive;
1105 vblankus /= mode->clock;
1107 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1108 vblan2e = vactive + vsynce + vbackp;
1109 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
1110 vactive = (vactive * 2) + 1;
1113 ret = nv50_crtc_swap_fbs(crtc, old_fb);
1117 push = evo_wait(mast, 64);
1119 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
1120 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1121 evo_data(push, 0x00800000 | mode->clock);
1122 evo_data(push, (ilace == 2) ? 2 : 0);
1123 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 8);
1124 evo_data(push, 0x00000000);
1125 evo_data(push, (vactive << 16) | hactive);
1126 evo_data(push, ( vsynce << 16) | hsynce);
1127 evo_data(push, (vblanke << 16) | hblanke);
1128 evo_data(push, (vblanks << 16) | hblanks);
1129 evo_data(push, (vblan2e << 16) | vblan2s);
1130 evo_data(push, vblankus);
1131 evo_data(push, 0x00000000);
1132 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1133 evo_data(push, 0x00000311);
1134 evo_data(push, 0x00000100);
1136 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
1137 evo_data(push, 0x00000000);
1138 evo_data(push, (vactive << 16) | hactive);
1139 evo_data(push, ( vsynce << 16) | hsynce);
1140 evo_data(push, (vblanke << 16) | hblanke);
1141 evo_data(push, (vblanks << 16) | hblanks);
1142 evo_data(push, (vblan2e << 16) | vblan2s);
1143 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1144 evo_data(push, 0x00000000); /* ??? */
1145 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1146 evo_data(push, mode->clock * 1000);
1147 evo_data(push, 0x00200000); /* ??? */
1148 evo_data(push, mode->clock * 1000);
1149 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1150 evo_data(push, 0x00000311);
1151 evo_data(push, 0x00000100);
1154 evo_kick(push, mast);
1157 nv_connector = nouveau_crtc_connector_get(nv_crtc);
1158 nv50_crtc_set_dither(nv_crtc, false);
1159 nv50_crtc_set_scale(nv_crtc, false);
1160 nv50_crtc_set_color_vibrance(nv_crtc, false);
1161 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
1166 nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
1167 struct drm_framebuffer *old_fb)
1169 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
1170 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1173 if (!crtc->primary->fb) {
1174 NV_DEBUG(drm, "No FB bound\n");
1178 ret = nv50_crtc_swap_fbs(crtc, old_fb);
1182 nv50_display_flip_stop(crtc);
1183 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1184 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
1189 nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
1190 struct drm_framebuffer *fb, int x, int y,
1191 enum mode_set_atomic state)
1193 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1194 nv50_display_flip_stop(crtc);
1195 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
1200 nv50_crtc_lut_load(struct drm_crtc *crtc)
1202 struct nv50_disp *disp = nv50_disp(crtc->dev);
1203 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1204 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1207 for (i = 0; i < 256; i++) {
1208 u16 r = nv_crtc->lut.r[i] >> 2;
1209 u16 g = nv_crtc->lut.g[i] >> 2;
1210 u16 b = nv_crtc->lut.b[i] >> 2;
1212 if (disp->disp->oclass < GF110_DISP) {
1213 writew(r + 0x0000, lut + (i * 0x08) + 0);
1214 writew(g + 0x0000, lut + (i * 0x08) + 2);
1215 writew(b + 0x0000, lut + (i * 0x08) + 4);
1217 writew(r + 0x6000, lut + (i * 0x20) + 0);
1218 writew(g + 0x6000, lut + (i * 0x20) + 2);
1219 writew(b + 0x6000, lut + (i * 0x20) + 4);
1225 nv50_crtc_disable(struct drm_crtc *crtc)
1227 struct nv50_head *head = nv50_head(crtc);
1228 evo_sync(crtc->dev);
1230 nouveau_bo_unpin(head->image);
1231 nouveau_bo_ref(NULL, &head->image);
1235 nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
1236 uint32_t handle, uint32_t width, uint32_t height)
1238 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1239 struct drm_device *dev = crtc->dev;
1240 struct drm_gem_object *gem;
1241 struct nouveau_bo *nvbo;
1242 bool visible = (handle != 0);
1246 if (width != 64 || height != 64)
1249 gem = drm_gem_object_lookup(dev, file_priv, handle);
1252 nvbo = nouveau_gem_object(gem);
1254 ret = nouveau_bo_map(nvbo);
1256 for (i = 0; i < 64 * 64; i++) {
1257 u32 v = nouveau_bo_rd32(nvbo, i);
1258 nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
1260 nouveau_bo_unmap(nvbo);
1263 drm_gem_object_unreference_unlocked(gem);
1266 if (visible != nv_crtc->cursor.visible) {
1267 nv50_crtc_cursor_show_hide(nv_crtc, visible, true);
1268 nv_crtc->cursor.visible = visible;
1275 nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
1277 struct nv50_curs *curs = nv50_curs(crtc);
1278 struct nv50_chan *chan = nv50_chan(curs);
1279 nvif_wr32(&chan->user, 0x0084, (y << 16) | (x & 0xffff));
1280 nvif_wr32(&chan->user, 0x0080, 0x00000000);
1285 nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
1286 uint32_t start, uint32_t size)
1288 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1289 u32 end = min_t(u32, start + size, 256);
1292 for (i = start; i < end; i++) {
1293 nv_crtc->lut.r[i] = r[i];
1294 nv_crtc->lut.g[i] = g[i];
1295 nv_crtc->lut.b[i] = b[i];
1298 nv50_crtc_lut_load(crtc);
1302 nv50_crtc_destroy(struct drm_crtc *crtc)
1304 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1305 struct nv50_disp *disp = nv50_disp(crtc->dev);
1306 struct nv50_head *head = nv50_head(crtc);
1307 struct nv50_fbdma *fbdma;
1309 list_for_each_entry(fbdma, &disp->fbdma, head) {
1310 nvif_object_fini(&fbdma->base[nv_crtc->index]);
1313 nv50_dmac_destroy(&head->ovly.base, disp->disp);
1314 nv50_pioc_destroy(&head->oimm.base);
1315 nv50_dmac_destroy(&head->sync.base, disp->disp);
1316 nv50_pioc_destroy(&head->curs.base);
1318 /*XXX: this shouldn't be necessary, but the core doesn't call
1319 * disconnect() during the cleanup paths
1322 nouveau_bo_unpin(head->image);
1323 nouveau_bo_ref(NULL, &head->image);
1325 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
1326 if (nv_crtc->cursor.nvbo)
1327 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1328 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
1330 nouveau_bo_unmap(nv_crtc->lut.nvbo);
1331 if (nv_crtc->lut.nvbo)
1332 nouveau_bo_unpin(nv_crtc->lut.nvbo);
1333 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
1335 drm_crtc_cleanup(crtc);
1339 static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1340 .dpms = nv50_crtc_dpms,
1341 .prepare = nv50_crtc_prepare,
1342 .commit = nv50_crtc_commit,
1343 .mode_fixup = nv50_crtc_mode_fixup,
1344 .mode_set = nv50_crtc_mode_set,
1345 .mode_set_base = nv50_crtc_mode_set_base,
1346 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1347 .load_lut = nv50_crtc_lut_load,
1348 .disable = nv50_crtc_disable,
1351 static const struct drm_crtc_funcs nv50_crtc_func = {
1352 .cursor_set = nv50_crtc_cursor_set,
1353 .cursor_move = nv50_crtc_cursor_move,
1354 .gamma_set = nv50_crtc_gamma_set,
1355 .set_config = nouveau_crtc_set_config,
1356 .destroy = nv50_crtc_destroy,
1357 .page_flip = nouveau_crtc_page_flip,
1361 nv50_crtc_create(struct drm_device *dev, int index)
1363 struct nv50_disp *disp = nv50_disp(dev);
1364 struct nv50_head *head;
1365 struct drm_crtc *crtc;
1368 head = kzalloc(sizeof(*head), GFP_KERNEL);
1372 head->base.index = index;
1373 head->base.set_dither = nv50_crtc_set_dither;
1374 head->base.set_scale = nv50_crtc_set_scale;
1375 head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
1376 head->base.color_vibrance = 50;
1377 head->base.vibrant_hue = 0;
1378 for (i = 0; i < 256; i++) {
1379 head->base.lut.r[i] = i << 8;
1380 head->base.lut.g[i] = i << 8;
1381 head->base.lut.b[i] = i << 8;
1384 crtc = &head->base.base;
1385 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1386 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
1387 drm_mode_crtc_set_gamma_size(crtc, 256);
1389 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
1390 0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
1392 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM);
1394 ret = nouveau_bo_map(head->base.lut.nvbo);
1396 nouveau_bo_unpin(head->base.lut.nvbo);
1399 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
1405 nv50_crtc_lut_load(crtc);
1407 /* allocate cursor resources */
1408 ret = nv50_curs_create(disp->disp, index, &head->curs);
1412 ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
1413 0, 0x0000, NULL, NULL, &head->base.cursor.nvbo);
1415 ret = nouveau_bo_pin(head->base.cursor.nvbo, TTM_PL_FLAG_VRAM);
1417 ret = nouveau_bo_map(head->base.cursor.nvbo);
1419 nouveau_bo_unpin(head->base.lut.nvbo);
1422 nouveau_bo_ref(NULL, &head->base.cursor.nvbo);
1428 /* allocate page flip / sync resources */
1429 ret = nv50_base_create(disp->disp, index, disp->sync->bo.offset,
1434 head->sync.addr = EVO_FLIP_SEM0(index);
1435 head->sync.data = 0x00000000;
1437 /* allocate overlay resources */
1438 ret = nv50_oimm_create(disp->disp, index, &head->oimm);
1442 ret = nv50_ovly_create(disp->disp, index, disp->sync->bo.offset,
1449 nv50_crtc_destroy(crtc);
1453 /******************************************************************************
1455 *****************************************************************************/
1457 nv50_dac_dpms(struct drm_encoder *encoder, int mode)
1459 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1460 struct nv50_disp *disp = nv50_disp(encoder->dev);
1462 struct nv50_disp_mthd_v1 base;
1463 struct nv50_disp_dac_pwr_v0 pwr;
1466 .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
1467 .base.hasht = nv_encoder->dcb->hasht,
1468 .base.hashm = nv_encoder->dcb->hashm,
1471 .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
1472 mode != DRM_MODE_DPMS_OFF),
1473 .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
1474 mode != DRM_MODE_DPMS_OFF),
1477 nvif_mthd(disp->disp, 0, &args, sizeof(args));
1481 nv50_dac_mode_fixup(struct drm_encoder *encoder,
1482 const struct drm_display_mode *mode,
1483 struct drm_display_mode *adjusted_mode)
1485 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1486 struct nouveau_connector *nv_connector;
1488 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1489 if (nv_connector && nv_connector->native_mode) {
1490 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
1491 int id = adjusted_mode->base.id;
1492 *adjusted_mode = *nv_connector->native_mode;
1493 adjusted_mode->base.id = id;
1501 nv50_dac_commit(struct drm_encoder *encoder)
1506 nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
1507 struct drm_display_mode *adjusted_mode)
1509 struct nv50_mast *mast = nv50_mast(encoder->dev);
1510 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1511 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1514 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
1516 push = evo_wait(mast, 8);
1518 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
1519 u32 syncs = 0x00000000;
1521 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1522 syncs |= 0x00000001;
1523 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1524 syncs |= 0x00000002;
1526 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1527 evo_data(push, 1 << nv_crtc->index);
1528 evo_data(push, syncs);
1530 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1531 u32 syncs = 0x00000001;
1533 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1534 syncs |= 0x00000008;
1535 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1536 syncs |= 0x00000010;
1538 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1539 magic |= 0x00000001;
1541 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1542 evo_data(push, syncs);
1543 evo_data(push, magic);
1544 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1545 evo_data(push, 1 << nv_crtc->index);
1548 evo_kick(push, mast);
1551 nv_encoder->crtc = encoder->crtc;
1555 nv50_dac_disconnect(struct drm_encoder *encoder)
1557 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1558 struct nv50_mast *mast = nv50_mast(encoder->dev);
1559 const int or = nv_encoder->or;
1562 if (nv_encoder->crtc) {
1563 nv50_crtc_prepare(nv_encoder->crtc);
1565 push = evo_wait(mast, 4);
1567 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
1568 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1569 evo_data(push, 0x00000000);
1571 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1572 evo_data(push, 0x00000000);
1574 evo_kick(push, mast);
1578 nv_encoder->crtc = NULL;
1581 static enum drm_connector_status
1582 nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
1584 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1585 struct nv50_disp *disp = nv50_disp(encoder->dev);
1587 struct nv50_disp_mthd_v1 base;
1588 struct nv50_disp_dac_load_v0 load;
1591 .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
1592 .base.hasht = nv_encoder->dcb->hasht,
1593 .base.hashm = nv_encoder->dcb->hashm,
1597 args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
1598 if (args.load.data == 0)
1599 args.load.data = 340;
1601 ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
1602 if (ret || !args.load.load)
1603 return connector_status_disconnected;
1605 return connector_status_connected;
1609 nv50_dac_destroy(struct drm_encoder *encoder)
1611 drm_encoder_cleanup(encoder);
1615 static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1616 .dpms = nv50_dac_dpms,
1617 .mode_fixup = nv50_dac_mode_fixup,
1618 .prepare = nv50_dac_disconnect,
1619 .commit = nv50_dac_commit,
1620 .mode_set = nv50_dac_mode_set,
1621 .disable = nv50_dac_disconnect,
1622 .get_crtc = nv50_display_crtc_get,
1623 .detect = nv50_dac_detect
1626 static const struct drm_encoder_funcs nv50_dac_func = {
1627 .destroy = nv50_dac_destroy,
1631 nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
1633 struct nouveau_drm *drm = nouveau_drm(connector->dev);
1634 struct nouveau_i2c *i2c = nvkm_i2c(&drm->device);
1635 struct nouveau_encoder *nv_encoder;
1636 struct drm_encoder *encoder;
1637 int type = DRM_MODE_ENCODER_DAC;
1639 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1642 nv_encoder->dcb = dcbe;
1643 nv_encoder->or = ffs(dcbe->or) - 1;
1644 nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
1646 encoder = to_drm_encoder(nv_encoder);
1647 encoder->possible_crtcs = dcbe->heads;
1648 encoder->possible_clones = 0;
1649 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type);
1650 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
1652 drm_mode_connector_attach_encoder(connector, encoder);
1656 /******************************************************************************
1658 *****************************************************************************/
1660 nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
1662 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1663 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1664 struct nouveau_connector *nv_connector;
1665 struct nv50_disp *disp = nv50_disp(encoder->dev);
1668 struct nv50_disp_mthd_v1 mthd;
1669 struct nv50_disp_sor_hda_eld_v0 eld;
1671 u8 data[sizeof(nv_connector->base.eld)];
1673 .base.mthd.version = 1,
1674 .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1675 .base.mthd.hasht = nv_encoder->dcb->hasht,
1676 .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1677 (0x0100 << nv_crtc->index),
1680 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1681 if (!drm_detect_monitor_audio(nv_connector->edid))
1684 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
1685 memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
1687 nvif_mthd(disp->disp, 0, &args, sizeof(args.base) + args.data[2] * 4);
1691 nv50_audio_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
1693 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1694 struct nv50_disp *disp = nv50_disp(encoder->dev);
1696 struct nv50_disp_mthd_v1 base;
1697 struct nv50_disp_sor_hda_eld_v0 eld;
1700 .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1701 .base.hasht = nv_encoder->dcb->hasht,
1702 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1703 (0x0100 << nv_crtc->index),
1706 nvif_mthd(disp->disp, 0, &args, sizeof(args));
1709 /******************************************************************************
1711 *****************************************************************************/
1713 nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
1715 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1716 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1717 struct nv50_disp *disp = nv50_disp(encoder->dev);
1719 struct nv50_disp_mthd_v1 base;
1720 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1723 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1724 .base.hasht = nv_encoder->dcb->hasht,
1725 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1726 (0x0100 << nv_crtc->index),
1728 .pwr.rekey = 56, /* binary driver, and tegra, constant */
1730 struct nouveau_connector *nv_connector;
1733 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1734 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1737 max_ac_packet = mode->htotal - mode->hdisplay;
1738 max_ac_packet -= args.pwr.rekey;
1739 max_ac_packet -= 18; /* constant from tegra */
1740 args.pwr.max_ac_packet = max_ac_packet / 32;
1742 nvif_mthd(disp->disp, 0, &args, sizeof(args));
1743 nv50_audio_mode_set(encoder, mode);
1747 nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
1749 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1750 struct nv50_disp *disp = nv50_disp(encoder->dev);
1752 struct nv50_disp_mthd_v1 base;
1753 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1756 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1757 .base.hasht = nv_encoder->dcb->hasht,
1758 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1759 (0x0100 << nv_crtc->index),
1762 nvif_mthd(disp->disp, 0, &args, sizeof(args));
1765 /******************************************************************************
1767 *****************************************************************************/
1769 nv50_sor_dpms(struct drm_encoder *encoder, int mode)
1771 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1772 struct nv50_disp *disp = nv50_disp(encoder->dev);
1774 struct nv50_disp_mthd_v1 base;
1775 struct nv50_disp_sor_pwr_v0 pwr;
1778 .base.method = NV50_DISP_MTHD_V1_SOR_PWR,
1779 .base.hasht = nv_encoder->dcb->hasht,
1780 .base.hashm = nv_encoder->dcb->hashm,
1781 .pwr.state = mode == DRM_MODE_DPMS_ON,
1784 struct nv50_disp_mthd_v1 base;
1785 struct nv50_disp_sor_dp_pwr_v0 pwr;
1788 .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
1789 .base.hasht = nv_encoder->dcb->hasht,
1790 .base.hashm = nv_encoder->dcb->hashm,
1791 .pwr.state = mode == DRM_MODE_DPMS_ON,
1793 struct drm_device *dev = encoder->dev;
1794 struct drm_encoder *partner;
1796 nv_encoder->last_dpms = mode;
1798 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1799 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1801 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1804 if (nv_partner != nv_encoder &&
1805 nv_partner->dcb->or == nv_encoder->dcb->or) {
1806 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1812 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
1814 nvif_mthd(disp->disp, 0, &args, sizeof(args));
1815 nvif_mthd(disp->disp, 0, &link, sizeof(link));
1817 nvif_mthd(disp->disp, 0, &args, sizeof(args));
1822 nv50_sor_mode_fixup(struct drm_encoder *encoder,
1823 const struct drm_display_mode *mode,
1824 struct drm_display_mode *adjusted_mode)
1826 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1827 struct nouveau_connector *nv_connector;
1829 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1830 if (nv_connector && nv_connector->native_mode) {
1831 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
1832 int id = adjusted_mode->base.id;
1833 *adjusted_mode = *nv_connector->native_mode;
1834 adjusted_mode->base.id = id;
1842 nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1844 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1845 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1846 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
1847 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
1848 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1849 evo_data(push, (nv_encoder->ctrl = temp));
1851 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1852 evo_data(push, (nv_encoder->ctrl = temp));
1854 evo_kick(push, mast);
1859 nv50_sor_disconnect(struct drm_encoder *encoder)
1861 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1862 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
1864 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1865 nv_encoder->crtc = NULL;
1868 nv50_crtc_prepare(&nv_crtc->base);
1869 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
1870 nv50_audio_disconnect(encoder, nv_crtc);
1871 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1876 nv50_sor_commit(struct drm_encoder *encoder)
1881 nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
1882 struct drm_display_mode *mode)
1884 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1885 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1887 struct nv50_disp_mthd_v1 base;
1888 struct nv50_disp_sor_lvds_script_v0 lvds;
1891 .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
1892 .base.hasht = nv_encoder->dcb->hasht,
1893 .base.hashm = nv_encoder->dcb->hashm,
1895 struct nv50_disp *disp = nv50_disp(encoder->dev);
1896 struct nv50_mast *mast = nv50_mast(encoder->dev);
1897 struct drm_device *dev = encoder->dev;
1898 struct nouveau_drm *drm = nouveau_drm(dev);
1899 struct nouveau_connector *nv_connector;
1900 struct nvbios *bios = &drm->vbios;
1902 u8 owner = 1 << nv_crtc->index;
1906 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1907 nv_encoder->crtc = encoder->crtc;
1909 switch (nv_encoder->dcb->type) {
1910 case DCB_OUTPUT_TMDS:
1911 if (nv_encoder->dcb->sorconf.link & 1) {
1912 if (mode->clock < 165000)
1920 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
1922 case DCB_OUTPUT_LVDS:
1925 if (bios->fp_no_ddc) {
1926 if (bios->fp.dual_link)
1927 lvds.lvds.script |= 0x0100;
1928 if (bios->fp.if_is_24bit)
1929 lvds.lvds.script |= 0x0200;
1931 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
1932 if (((u8 *)nv_connector->edid)[121] == 2)
1933 lvds.lvds.script |= 0x0100;
1935 if (mode->clock >= bios->fp.duallink_transition_clk) {
1936 lvds.lvds.script |= 0x0100;
1939 if (lvds.lvds.script & 0x0100) {
1940 if (bios->fp.strapless_is_24bit & 2)
1941 lvds.lvds.script |= 0x0200;
1943 if (bios->fp.strapless_is_24bit & 1)
1944 lvds.lvds.script |= 0x0200;
1947 if (nv_connector->base.display_info.bpc == 8)
1948 lvds.lvds.script |= 0x0200;
1951 nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds));
1954 if (nv_connector->base.display_info.bpc == 6) {
1955 nv_encoder->dp.datarate = mode->clock * 18 / 8;
1958 if (nv_connector->base.display_info.bpc == 8) {
1959 nv_encoder->dp.datarate = mode->clock * 24 / 8;
1962 nv_encoder->dp.datarate = mode->clock * 30 / 8;
1966 if (nv_encoder->dcb->sorconf.link & 1)
1970 nv50_audio_mode_set(encoder, mode);
1977 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
1979 if (nv50_vers(mast) >= GF110_DISP) {
1980 u32 *push = evo_wait(mast, 3);
1982 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1983 u32 syncs = 0x00000001;
1985 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1986 syncs |= 0x00000008;
1987 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1988 syncs |= 0x00000010;
1990 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1991 magic |= 0x00000001;
1993 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1994 evo_data(push, syncs | (depth << 6));
1995 evo_data(push, magic);
1996 evo_kick(push, mast);
2002 ctrl = (depth << 16) | (proto << 8);
2003 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2005 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2010 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
2014 nv50_sor_destroy(struct drm_encoder *encoder)
2016 drm_encoder_cleanup(encoder);
2020 static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
2021 .dpms = nv50_sor_dpms,
2022 .mode_fixup = nv50_sor_mode_fixup,
2023 .prepare = nv50_sor_disconnect,
2024 .commit = nv50_sor_commit,
2025 .mode_set = nv50_sor_mode_set,
2026 .disable = nv50_sor_disconnect,
2027 .get_crtc = nv50_display_crtc_get,
2030 static const struct drm_encoder_funcs nv50_sor_func = {
2031 .destroy = nv50_sor_destroy,
2035 nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
2037 struct nouveau_drm *drm = nouveau_drm(connector->dev);
2038 struct nouveau_i2c *i2c = nvkm_i2c(&drm->device);
2039 struct nouveau_encoder *nv_encoder;
2040 struct drm_encoder *encoder;
2043 switch (dcbe->type) {
2044 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
2045 case DCB_OUTPUT_TMDS:
2048 type = DRM_MODE_ENCODER_TMDS;
2052 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2055 nv_encoder->dcb = dcbe;
2056 nv_encoder->or = ffs(dcbe->or) - 1;
2057 nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
2058 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
2060 encoder = to_drm_encoder(nv_encoder);
2061 encoder->possible_crtcs = dcbe->heads;
2062 encoder->possible_clones = 0;
2063 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type);
2064 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
2066 drm_mode_connector_attach_encoder(connector, encoder);
2070 /******************************************************************************
2072 *****************************************************************************/
2075 nv50_pior_dpms(struct drm_encoder *encoder, int mode)
2077 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2078 struct nv50_disp *disp = nv50_disp(encoder->dev);
2080 struct nv50_disp_mthd_v1 base;
2081 struct nv50_disp_pior_pwr_v0 pwr;
2084 .base.method = NV50_DISP_MTHD_V1_PIOR_PWR,
2085 .base.hasht = nv_encoder->dcb->hasht,
2086 .base.hashm = nv_encoder->dcb->hashm,
2087 .pwr.state = mode == DRM_MODE_DPMS_ON,
2088 .pwr.type = nv_encoder->dcb->type,
2091 nvif_mthd(disp->disp, 0, &args, sizeof(args));
2095 nv50_pior_mode_fixup(struct drm_encoder *encoder,
2096 const struct drm_display_mode *mode,
2097 struct drm_display_mode *adjusted_mode)
2099 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2100 struct nouveau_connector *nv_connector;
2102 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2103 if (nv_connector && nv_connector->native_mode) {
2104 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
2105 int id = adjusted_mode->base.id;
2106 *adjusted_mode = *nv_connector->native_mode;
2107 adjusted_mode->base.id = id;
2111 adjusted_mode->clock *= 2;
2116 nv50_pior_commit(struct drm_encoder *encoder)
2121 nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
2122 struct drm_display_mode *adjusted_mode)
2124 struct nv50_mast *mast = nv50_mast(encoder->dev);
2125 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2126 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
2127 struct nouveau_connector *nv_connector;
2128 u8 owner = 1 << nv_crtc->index;
2132 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2133 switch (nv_connector->base.display_info.bpc) {
2134 case 10: depth = 0x6; break;
2135 case 8: depth = 0x5; break;
2136 case 6: depth = 0x2; break;
2137 default: depth = 0x0; break;
2140 switch (nv_encoder->dcb->type) {
2141 case DCB_OUTPUT_TMDS:
2150 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
2152 push = evo_wait(mast, 8);
2154 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
2155 u32 ctrl = (depth << 16) | (proto << 8) | owner;
2156 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2158 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2160 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
2161 evo_data(push, ctrl);
2164 evo_kick(push, mast);
2167 nv_encoder->crtc = encoder->crtc;
2171 nv50_pior_disconnect(struct drm_encoder *encoder)
2173 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2174 struct nv50_mast *mast = nv50_mast(encoder->dev);
2175 const int or = nv_encoder->or;
2178 if (nv_encoder->crtc) {
2179 nv50_crtc_prepare(nv_encoder->crtc);
2181 push = evo_wait(mast, 4);
2183 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
2184 evo_mthd(push, 0x0700 + (or * 0x040), 1);
2185 evo_data(push, 0x00000000);
2187 evo_kick(push, mast);
2191 nv_encoder->crtc = NULL;
2195 nv50_pior_destroy(struct drm_encoder *encoder)
2197 drm_encoder_cleanup(encoder);
2201 static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
2202 .dpms = nv50_pior_dpms,
2203 .mode_fixup = nv50_pior_mode_fixup,
2204 .prepare = nv50_pior_disconnect,
2205 .commit = nv50_pior_commit,
2206 .mode_set = nv50_pior_mode_set,
2207 .disable = nv50_pior_disconnect,
2208 .get_crtc = nv50_display_crtc_get,
2211 static const struct drm_encoder_funcs nv50_pior_func = {
2212 .destroy = nv50_pior_destroy,
2216 nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2218 struct nouveau_drm *drm = nouveau_drm(connector->dev);
2219 struct nouveau_i2c *i2c = nvkm_i2c(&drm->device);
2220 struct nouveau_i2c_port *ddc = NULL;
2221 struct nouveau_encoder *nv_encoder;
2222 struct drm_encoder *encoder;
2225 switch (dcbe->type) {
2226 case DCB_OUTPUT_TMDS:
2227 ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTDDC(dcbe->extdev));
2228 type = DRM_MODE_ENCODER_TMDS;
2231 ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(dcbe->extdev));
2232 type = DRM_MODE_ENCODER_TMDS;
2238 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2241 nv_encoder->dcb = dcbe;
2242 nv_encoder->or = ffs(dcbe->or) - 1;
2243 nv_encoder->i2c = ddc;
2245 encoder = to_drm_encoder(nv_encoder);
2246 encoder->possible_crtcs = dcbe->heads;
2247 encoder->possible_clones = 0;
2248 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type);
2249 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2251 drm_mode_connector_attach_encoder(connector, encoder);
2255 /******************************************************************************
2257 *****************************************************************************/
2260 nv50_fbdma_fini(struct nv50_fbdma *fbdma)
2263 for (i = 0; i < ARRAY_SIZE(fbdma->base); i++)
2264 nvif_object_fini(&fbdma->base[i]);
2265 nvif_object_fini(&fbdma->core);
2266 list_del(&fbdma->head);
2271 nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind)
2273 struct nouveau_drm *drm = nouveau_drm(dev);
2274 struct nv50_disp *disp = nv50_disp(dev);
2275 struct nv50_mast *mast = nv50_mast(dev);
2276 struct __attribute__ ((packed)) {
2277 struct nv_dma_v0 base;
2279 struct nv50_dma_v0 nv50;
2280 struct gf100_dma_v0 gf100;
2281 struct gf110_dma_v0 gf110;
2284 struct nv50_fbdma *fbdma;
2285 struct drm_crtc *crtc;
2286 u32 size = sizeof(args.base);
2289 list_for_each_entry(fbdma, &disp->fbdma, head) {
2290 if (fbdma->core.handle == name)
2294 fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL);
2297 list_add(&fbdma->head, &disp->fbdma);
2299 args.base.target = NV_DMA_V0_TARGET_VRAM;
2300 args.base.access = NV_DMA_V0_ACCESS_RDWR;
2301 args.base.start = offset;
2302 args.base.limit = offset + length - 1;
2304 if (drm->device.info.chipset < 0x80) {
2305 args.nv50.part = NV50_DMA_V0_PART_256;
2306 size += sizeof(args.nv50);
2308 if (drm->device.info.chipset < 0xc0) {
2309 args.nv50.part = NV50_DMA_V0_PART_256;
2310 args.nv50.kind = kind;
2311 size += sizeof(args.nv50);
2313 if (drm->device.info.chipset < 0xd0) {
2314 args.gf100.kind = kind;
2315 size += sizeof(args.gf100);
2317 args.gf110.page = GF110_DMA_V0_PAGE_LP;
2318 args.gf110.kind = kind;
2319 size += sizeof(args.gf110);
2322 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2323 struct nv50_head *head = nv50_head(crtc);
2324 int ret = nvif_object_init(&head->sync.base.base.user, NULL,
2325 name, NV_DMA_IN_MEMORY, &args, size,
2326 &fbdma->base[head->base.index]);
2328 nv50_fbdma_fini(fbdma);
2333 ret = nvif_object_init(&mast->base.base.user, NULL, name,
2334 NV_DMA_IN_MEMORY, &args, size,
2337 nv50_fbdma_fini(fbdma);
2345 nv50_fb_dtor(struct drm_framebuffer *fb)
2350 nv50_fb_ctor(struct drm_framebuffer *fb)
2352 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
2353 struct nouveau_drm *drm = nouveau_drm(fb->dev);
2354 struct nouveau_bo *nvbo = nv_fb->nvbo;
2355 struct nv50_disp *disp = nv50_disp(fb->dev);
2356 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
2357 u8 tile = nvbo->tile_mode;
2359 if (nvbo->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG) {
2360 NV_ERROR(drm, "framebuffer requires contiguous bo\n");
2364 if (drm->device.info.chipset >= 0xc0)
2365 tile >>= 4; /* yep.. */
2367 switch (fb->depth) {
2368 case 8: nv_fb->r_format = 0x1e00; break;
2369 case 15: nv_fb->r_format = 0xe900; break;
2370 case 16: nv_fb->r_format = 0xe800; break;
2372 case 32: nv_fb->r_format = 0xcf00; break;
2373 case 30: nv_fb->r_format = 0xd100; break;
2375 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
2379 if (disp->disp->oclass < G82_DISP) {
2380 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2381 (fb->pitches[0] | 0x00100000);
2382 nv_fb->r_format |= kind << 16;
2384 if (disp->disp->oclass < GF110_DISP) {
2385 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2386 (fb->pitches[0] | 0x00100000);
2388 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2389 (fb->pitches[0] | 0x01000000);
2391 nv_fb->r_handle = 0xffff0000 | kind;
2393 return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0,
2394 drm->device.info.ram_user, kind);
2397 /******************************************************************************
2399 *****************************************************************************/
2402 nv50_display_fini(struct drm_device *dev)
2407 nv50_display_init(struct drm_device *dev)
2409 struct nv50_disp *disp = nv50_disp(dev);
2410 struct drm_crtc *crtc;
2413 push = evo_wait(nv50_mast(dev), 32);
2417 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2418 struct nv50_sync *sync = nv50_sync(crtc);
2419 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
2422 evo_mthd(push, 0x0088, 1);
2423 evo_data(push, nv50_mast(dev)->base.sync.handle);
2424 evo_kick(push, nv50_mast(dev));
2429 nv50_display_destroy(struct drm_device *dev)
2431 struct nv50_disp *disp = nv50_disp(dev);
2432 struct nv50_fbdma *fbdma, *fbtmp;
2434 list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) {
2435 nv50_fbdma_fini(fbdma);
2438 nv50_dmac_destroy(&disp->mast.base, disp->disp);
2440 nouveau_bo_unmap(disp->sync);
2442 nouveau_bo_unpin(disp->sync);
2443 nouveau_bo_ref(NULL, &disp->sync);
2445 nouveau_display(dev)->priv = NULL;
2450 nv50_display_create(struct drm_device *dev)
2452 struct nvif_device *device = &nouveau_drm(dev)->device;
2453 struct nouveau_drm *drm = nouveau_drm(dev);
2454 struct dcb_table *dcb = &drm->vbios.dcb;
2455 struct drm_connector *connector, *tmp;
2456 struct nv50_disp *disp;
2457 struct dcb_output *dcbe;
2460 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2463 INIT_LIST_HEAD(&disp->fbdma);
2465 nouveau_display(dev)->priv = disp;
2466 nouveau_display(dev)->dtor = nv50_display_destroy;
2467 nouveau_display(dev)->init = nv50_display_init;
2468 nouveau_display(dev)->fini = nv50_display_fini;
2469 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
2470 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
2471 disp->disp = &nouveau_display(dev)->disp;
2473 /* small shared memory area we use for notifiers and semaphores */
2474 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
2475 0, 0x0000, NULL, NULL, &disp->sync);
2477 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM);
2479 ret = nouveau_bo_map(disp->sync);
2481 nouveau_bo_unpin(disp->sync);
2484 nouveau_bo_ref(NULL, &disp->sync);
2490 /* allocate master evo channel */
2491 ret = nv50_core_create(disp->disp, disp->sync->bo.offset,
2496 /* create crtc objects to represent the hw heads */
2497 if (disp->disp->oclass >= GF110_DISP)
2498 crtcs = nvif_rd32(device, 0x022448);
2502 for (i = 0; i < crtcs; i++) {
2503 ret = nv50_crtc_create(dev, i);
2508 /* create encoder/connector objects based on VBIOS DCB table */
2509 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2510 connector = nouveau_connector_create(dev, dcbe->connector);
2511 if (IS_ERR(connector))
2514 if (dcbe->location == DCB_LOC_ON_CHIP) {
2515 switch (dcbe->type) {
2516 case DCB_OUTPUT_TMDS:
2517 case DCB_OUTPUT_LVDS:
2519 ret = nv50_sor_create(connector, dcbe);
2521 case DCB_OUTPUT_ANALOG:
2522 ret = nv50_dac_create(connector, dcbe);
2529 ret = nv50_pior_create(connector, dcbe);
2533 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2534 dcbe->location, dcbe->type,
2535 ffs(dcbe->or) - 1, ret);
2540 /* cull any connectors we created that don't have an encoder */
2541 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2542 if (connector->encoder_ids[0])
2545 NV_WARN(drm, "%s has no encoders, removing\n",
2547 connector->funcs->destroy(connector);
2552 nv50_display_destroy(dev);