]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/gpu/drm/nouveau/nouveau_display.c
Merge tag 'please-pull-ia64-erratum' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / nouveau_display.c
index b4262ad66b182de48af73965fb3c0ce4af250e4a..3ff030dc1ee35d34925b2fd5464f1236ad10d925 100644 (file)
@@ -68,6 +68,86 @@ nouveau_display_vblank_disable(struct drm_device *dev, int head)
                nouveau_event_put(disp->vblank[head]);
 }
 
+static inline int
+calc(int blanks, int blanke, int total, int line)
+{
+       if (blanke >= blanks) {
+               if (line >= blanks)
+                       line -= total;
+       } else {
+               if (line >= blanks)
+                       line -= total;
+               line -= blanke + 1;
+       }
+       return line;
+}
+
+int
+nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos,
+                               ktime_t *stime, ktime_t *etime)
+{
+       const u32 mthd = NV04_DISP_SCANOUTPOS + nouveau_crtc(crtc)->index;
+       struct nouveau_display *disp = nouveau_display(crtc->dev);
+       struct nv04_display_scanoutpos args;
+       int ret, retry = 1;
+
+       do {
+               ret = nv_exec(disp->core, mthd, &args, sizeof(args));
+               if (ret != 0)
+                       return 0;
+
+               if (args.vline) {
+                       ret |= DRM_SCANOUTPOS_ACCURATE;
+                       ret |= DRM_SCANOUTPOS_VALID;
+                       break;
+               }
+
+               if (retry) ndelay(crtc->linedur_ns);
+       } while (retry--);
+
+       *hpos = args.hline;
+       *vpos = calc(args.vblanks, args.vblanke, args.vtotal, args.vline);
+       if (stime) *stime = ns_to_ktime(args.time[0]);
+       if (etime) *etime = ns_to_ktime(args.time[1]);
+
+       if (*vpos < 0)
+               ret |= DRM_SCANOUTPOS_INVBL;
+       return ret;
+}
+
+int
+nouveau_display_scanoutpos(struct drm_device *dev, int head, unsigned int flags,
+                          int *vpos, int *hpos, ktime_t *stime, ktime_t *etime)
+{
+       struct drm_crtc *crtc;
+
+       list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+               if (nouveau_crtc(crtc)->index == head) {
+                       return nouveau_display_scanoutpos_head(crtc, vpos, hpos,
+                                                              stime, etime);
+               }
+       }
+
+       return 0;
+}
+
+int
+nouveau_display_vblstamp(struct drm_device *dev, int head, int *max_error,
+                        struct timeval *time, unsigned flags)
+{
+       struct drm_crtc *crtc;
+
+       list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+               if (nouveau_crtc(crtc)->index == head) {
+                       return drm_calc_vbltimestamp_from_scanoutpos(dev,
+                                       head, max_error, time, flags, crtc,
+                                       &crtc->hwmode);
+               }
+       }
+
+       return -EINVAL;
+}
+
 static void
 nouveau_display_vblank_fini(struct drm_device *dev)
 {
@@ -339,6 +419,7 @@ int
 nouveau_display_create(struct drm_device *dev)
 {
        struct nouveau_drm *drm = nouveau_drm(dev);
+       struct nouveau_device *device = nouveau_dev(dev);
        struct nouveau_display *disp;
        int ret, gen;
 
@@ -379,7 +460,7 @@ nouveau_display_create(struct drm_device *dev)
        }
 
        dev->mode_config.funcs = &nouveau_mode_config_funcs;
-       dev->mode_config.fb_base = pci_resource_start(dev->pdev, 1);
+       dev->mode_config.fb_base = nv_device_resource_start(device, 1);
 
        dev->mode_config.min_width = 0;
        dev->mode_config.min_height = 0;
@@ -408,6 +489,7 @@ nouveau_display_create(struct drm_device *dev)
 
        if (drm->vbios.dcb.entries) {
                static const u16 oclass[] = {
+                       GM107_DISP_CLASS,
                        NVF0_DISP_CLASS,
                        NVE0_DISP_CLASS,
                        NVD0_DISP_CLASS,
@@ -489,7 +571,7 @@ nouveau_display_suspend(struct drm_device *dev)
        list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
                struct nouveau_framebuffer *nouveau_fb;
 
-               nouveau_fb = nouveau_framebuffer(crtc->fb);
+               nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
                if (!nouveau_fb || !nouveau_fb->nvbo)
                        continue;
 
@@ -516,7 +598,7 @@ nouveau_display_repin(struct drm_device *dev)
        list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
                struct nouveau_framebuffer *nouveau_fb;
 
-               nouveau_fb = nouveau_framebuffer(crtc->fb);
+               nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
                if (!nouveau_fb || !nouveau_fb->nvbo)
                        continue;
 
@@ -613,7 +695,7 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
        const int swap_interval = (flags & DRM_MODE_PAGE_FLIP_ASYNC) ? 0 : 1;
        struct drm_device *dev = crtc->dev;
        struct nouveau_drm *drm = nouveau_drm(dev);
-       struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->fb)->nvbo;
+       struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->primary->fb)->nvbo;
        struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo;
        struct nouveau_page_flip_state *s;
        struct nouveau_channel *chan = drm->channel;
@@ -642,7 +724,7 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
        ret = nouveau_fence_sync(fence, chan);
        nouveau_fence_unref(&fence);
        if (ret)
-               goto fail_free;
+               goto fail_unpin;
 
        ret = ttm_bo_reserve(&old_bo->bo, true, false, false, NULL);
        if (ret)
@@ -687,7 +769,7 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
                goto fail_unreserve;
 
        /* Update the crtc struct and cleanup */
-       crtc->fb = fb;
+       crtc->primary->fb = fb;
 
        nouveau_bo_fence(old_bo, fence);
        ttm_bo_unreserve(&old_bo->bo);