drm/nv50: fix iommu errors caused by device reading from address 0
[safe/jmp/linux-2.6] / drivers / gpu / drm / nouveau / nv04_fbcon.c
index d2d7f08..1eeac4f 100644 (file)
 #include "nouveau_dma.h"
 #include "nouveau_fbcon.h"
 
-static void
+void
 nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
 {
-       struct nouveau_fbcon_par *par = info->par;
-       struct drm_device *dev = par->dev;
+       struct nouveau_fbdev *nfbdev = info->par;
+       struct drm_device *dev = nfbdev->dev;
        struct drm_nouveau_private *dev_priv = dev->dev_private;
        struct nouveau_channel *chan = dev_priv->channel;
 
@@ -39,8 +39,7 @@ nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
                return;
 
        if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 4)) {
-               NV_ERROR(dev, "GPU lockup - switching to software fbcon\n");
-               info->flags |= FBINFO_HWACCEL_DISABLED;
+               nouveau_fbcon_gpu_lockup(info);
        }
 
        if (info->flags & FBINFO_HWACCEL_DISABLED) {
@@ -55,21 +54,19 @@ nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
        FIRE_RING(chan);
 }
 
-static void
+void
 nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 {
-       struct nouveau_fbcon_par *par = info->par;
-       struct drm_device *dev = par->dev;
+       struct nouveau_fbdev *nfbdev = info->par;
+       struct drm_device *dev = nfbdev->dev;
        struct drm_nouveau_private *dev_priv = dev->dev_private;
        struct nouveau_channel *chan = dev_priv->channel;
-       uint32_t color = ((uint32_t *) info->pseudo_palette)[rect->color];
 
        if (info->state != FBINFO_STATE_RUNNING)
                return;
 
        if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 7)) {
-               NV_ERROR(dev, "GPU lockup - switching to software fbcon\n");
-               info->flags |= FBINFO_HWACCEL_DISABLED;
+               nouveau_fbcon_gpu_lockup(info);
        }
 
        if (info->flags & FBINFO_HWACCEL_DISABLED) {
@@ -80,18 +77,22 @@ nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
        BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
        OUT_RING(chan, (rect->rop != ROP_COPY) ? 1 : 3);
        BEGIN_RING(chan, NvSubGdiRect, 0x03fc, 1);
-       OUT_RING(chan, color);
+       if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
+           info->fix.visual == FB_VISUAL_DIRECTCOLOR)
+               OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
+       else
+               OUT_RING(chan, rect->color);
        BEGIN_RING(chan, NvSubGdiRect, 0x0400, 2);
        OUT_RING(chan, (rect->dx << 16) | rect->dy);
        OUT_RING(chan, (rect->width << 16) | rect->height);
        FIRE_RING(chan);
 }
 
-static void
+void
 nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
 {
-       struct nouveau_fbcon_par *par = info->par;
-       struct drm_device *dev = par->dev;
+       struct nouveau_fbdev *nfbdev = info->par;
+       struct drm_device *dev = nfbdev->dev;
        struct drm_nouveau_private *dev_priv = dev->dev_private;
        struct nouveau_channel *chan = dev_priv->channel;
        uint32_t fg;
@@ -109,8 +110,7 @@ nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
        }
 
        if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 8)) {
-               NV_ERROR(dev, "GPU lockup - switching to software fbcon\n");
-               info->flags |= FBINFO_HWACCEL_DISABLED;
+               nouveau_fbcon_gpu_lockup(info);
        }
 
        if (info->flags & FBINFO_HWACCEL_DISABLED) {
@@ -118,8 +118,8 @@ nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
                return;
        }
 
-       width = (image->width + 31) & ~31;
-       dsize = (width * image->height) >> 5;
+       width = ALIGN(image->width, 8);
+       dsize = ALIGN(width * image->height, 32) >> 5;
 
        if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
            info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
@@ -136,16 +136,15 @@ nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
                         ((image->dx + image->width) & 0xffff));
        OUT_RING(chan, bg);
        OUT_RING(chan, fg);
-       OUT_RING(chan, (image->height << 16) | image->width);
        OUT_RING(chan, (image->height << 16) | width);
+       OUT_RING(chan, (image->height << 16) | image->width);
        OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
 
        while (dsize) {
                int iter_len = dsize > 128 ? 128 : dsize;
 
                if (RING_SPACE(chan, iter_len + 1)) {
-                       NV_ERROR(dev, "GPU lockup - switching to software fbcon\n");
-                       info->flags |= FBINFO_HWACCEL_DISABLED;
+                       nouveau_fbcon_gpu_lockup(info);
                        cfb_imageblit(info, image);
                        return;
                }
@@ -180,8 +179,8 @@ nv04_fbcon_grobj_new(struct drm_device *dev, int class, uint32_t handle)
 int
 nv04_fbcon_accel_init(struct fb_info *info)
 {
-       struct nouveau_fbcon_par *par = info->par;
-       struct drm_device *dev = par->dev;
+       struct nouveau_fbdev *nfbdev = info->par;
+       struct drm_device *dev = nfbdev->dev;
        struct drm_nouveau_private *dev_priv = dev->dev_private;
        struct nouveau_channel *chan = dev_priv->channel;
        const int sub = NvSubCtxSurf2D;
@@ -237,14 +236,13 @@ nv04_fbcon_accel_init(struct fb_info *info)
        if (ret)
                return ret;
 
-       ret = nv04_fbcon_grobj_new(dev, dev_priv->card_type >= NV_10 ?
+       ret = nv04_fbcon_grobj_new(dev, dev_priv->chipset >= 0x11 ?
                                   0x009f : 0x005f, NvImageBlit);
        if (ret)
                return ret;
 
        if (RING_SPACE(chan, 49)) {
-               NV_ERROR(dev, "GPU lockup - switching to software fbcon\n");
-               info->flags |= FBINFO_HWACCEL_DISABLED;
+               nouveau_fbcon_gpu_lockup(info);
                return 0;
        }
 
@@ -309,9 +307,6 @@ nv04_fbcon_accel_init(struct fb_info *info)
 
        FIRE_RING(chan);
 
-       info->fbops->fb_fillrect = nv04_fbcon_fillrect;
-       info->fbops->fb_copyarea = nv04_fbcon_copyarea;
-       info->fbops->fb_imageblit = nv04_fbcon_imageblit;
        return 0;
 }