]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/video/nvidia/nvidia.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/avi/kvm
[linux-2.6-omap-h63xx.git] / drivers / video / nvidia / nvidia.c
index b97ec6901263ab02bef1fd4e77bb8c390b91f2f5..a7fe214f0f77d816308390dd3828ec4fe9af8583 100644 (file)
@@ -37,7 +37,6 @@
 #include "nv_proto.h"
 #include "nv_dma.h"
 
-#undef CONFIG_FB_NVIDIA_DEBUG
 #ifdef CONFIG_FB_NVIDIA_DEBUG
 #define NVTRACE          printk
 #else
@@ -200,7 +199,7 @@ static int nvidia_panel_tweak(struct nvidia_par *par,
    return tweak;
 }
 
-static void nvidia_vga_protect(struct nvidia_par *par, int on)
+static void nvidia_screen_off(struct nvidia_par *par, int on)
 {
        unsigned char tmp;
 
@@ -649,7 +648,7 @@ static int nvidiafb_set_par(struct fb_info *info)
                NVLockUnlock(par, 0);
        }
 
-       nvidia_vga_protect(par, 1);
+       nvidia_screen_off(par, 1);
 
        nvidia_write_regs(par, &par->ModeReg);
        NVSetStartAddress(par, 0);
@@ -675,6 +674,7 @@ static int nvidiafb_set_par(struct fb_info *info)
                info->fbops->fb_sync = nvidiafb_sync;
                info->pixmap.scan_align = 4;
                info->flags &= ~FBINFO_HWACCEL_DISABLED;
+               info->flags |= FBINFO_READS_FAST;
                NVResetGraphics(info);
        } else {
                info->fbops->fb_imageblit = cfb_imageblit;
@@ -683,11 +683,12 @@ static int nvidiafb_set_par(struct fb_info *info)
                info->fbops->fb_sync = NULL;
                info->pixmap.scan_align = 1;
                info->flags |= FBINFO_HWACCEL_DISABLED;
+               info->flags &= ~FBINFO_READS_FAST;
        }
 
        par->cursor_reset = 1;
 
-       nvidia_vga_protect(par, 0);
+       nvidia_screen_off(par, 0);
 
 #ifdef CONFIG_BOOTX_TEXT
        /* Update debug text engine */
@@ -696,6 +697,7 @@ static int nvidiafb_set_par(struct fb_info *info)
                             info->var.bits_per_pixel, info->fix.line_length);
 #endif
 
+       NVLockUnlock(par, 0);
        NVTRACE_LEAVE();
        return 0;
 }
@@ -948,8 +950,80 @@ static int nvidiafb_blank(int blank, struct fb_info *info)
        return 0;
 }
 
+/*
+ * Because the VGA registers are not mapped linearly in its MMIO space,
+ * restrict VGA register saving and restore to x86 only, where legacy VGA IO
+ * access is legal. Consequently, we must also check if the device is the
+ * primary display.
+ */
+#ifdef CONFIG_X86
+static void save_vga_x86(struct nvidia_par *par)
+{
+       struct resource *res= &par->pci_dev->resource[PCI_ROM_RESOURCE];
+
+       if (res && res->flags & IORESOURCE_ROM_SHADOW) {
+               memset(&par->vgastate, 0, sizeof(par->vgastate));
+               par->vgastate.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS |
+                       VGA_SAVE_CMAP;
+               save_vga(&par->vgastate);
+       }
+}
+
+static void restore_vga_x86(struct nvidia_par *par)
+{
+       struct resource *res= &par->pci_dev->resource[PCI_ROM_RESOURCE];
+
+       if (res && res->flags & IORESOURCE_ROM_SHADOW)
+               restore_vga(&par->vgastate);
+}
+#else
+#define save_vga_x86(x) do {} while (0)
+#define restore_vga_x86(x) do {} while (0)
+#endif /* X86 */
+
+static int nvidiafb_open(struct fb_info *info, int user)
+{
+       struct nvidia_par *par = info->par;
+
+       mutex_lock(&par->open_lock);
+
+       if (!par->open_count) {
+               save_vga_x86(par);
+               nvidia_save_vga(par, &par->initial_state);
+       }
+
+       par->open_count++;
+       mutex_unlock(&par->open_lock);
+       return 0;
+}
+
+static int nvidiafb_release(struct fb_info *info, int user)
+{
+       struct nvidia_par *par = info->par;
+       int err = 0;
+
+       mutex_lock(&par->open_lock);
+
+       if (!par->open_count) {
+               err = -EINVAL;
+               goto done;
+       }
+
+       if (par->open_count == 1) {
+               nvidia_write_regs(par, &par->initial_state);
+               restore_vga_x86(par);
+       }
+
+       par->open_count--;
+done:
+       mutex_unlock(&par->open_lock);
+       return err;
+}
+
 static struct fb_ops nvidia_fb_ops = {
        .owner          = THIS_MODULE,
+       .fb_open        = nvidiafb_open,
+       .fb_release     = nvidiafb_release,
        .fb_check_var   = nvidiafb_check_var,
        .fb_set_par     = nvidiafb_set_par,
        .fb_setcolreg   = nvidiafb_setcolreg,
@@ -1121,7 +1195,8 @@ static u32 __devinit nvidia_get_chipset(struct fb_info *info)
 
        printk(KERN_INFO PFX "Device ID: %x \n", id);
 
-       if ((id & 0xfff0) == 0x00f0) {
+       if ((id & 0xfff0) == 0x00f0 ||
+           (id & 0xfff0) == 0x02e0) {
                /* pci-e */
                id = NV_RD32(par->REGS, 0x1800);
 
@@ -1166,17 +1241,16 @@ static u32 __devinit nvidia_get_arch(struct fb_info *info)
        case 0x0040:            /* GeForce 6800 */
        case 0x00C0:            /* GeForce 6800 */
        case 0x0120:            /* GeForce 6800 */
-       case 0x0130:
        case 0x0140:            /* GeForce 6600 */
        case 0x0160:            /* GeForce 6200 */
        case 0x01D0:            /* GeForce 7200, 7300, 7400 */
        case 0x0090:            /* GeForce 7800 */
        case 0x0210:            /* GeForce 6800 */
        case 0x0220:            /* GeForce 6200 */
-       case 0x0230:
        case 0x0240:            /* GeForce 6100 */
        case 0x0290:            /* GeForce 7900 */
        case 0x0390:            /* GeForce 7600 */
+       case 0x03D0:
                arch = NV_ARCH_40;
                break;
        case 0x0020:            /* TNT, TNT2 */
@@ -1207,7 +1281,7 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
 
        par = info->par;
        par->pci_dev = pd;
-
+       mutex_init(&par->open_lock);
        info->pixmap.addr = kzalloc(8 * 1024, GFP_KERNEL);
 
        if (info->pixmap.addr == NULL)