intelfb: fixup p calculation
[safe/jmp/linux-2.6] / drivers / video / intelfb / intelfbdrv.c
index 94f35a6..9e83664 100644 (file)
@@ -1,11 +1,12 @@
 /*
  * intelfb
  *
- * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G
- * integrated graphics chips.
+ * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/
+ * 945G/945GM integrated graphics chips.
  *
  * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
  *                   2004 Sylvain Meyer
+ *                   2006 David Airlie
  *
  * This driver consists of two parts.  The first part (intelfbdrv.c) provides
  * the basic fbdev interfaces, is derived in part from the radeonfb and
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/fb.h>
-#include <linux/console.h>
-#include <linux/selection.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/vmalloc.h>
-#include <linux/kd.h>
-#include <linux/vt_kern.h>
 #include <linux/pagemap.h>
-#include <linux/version.h>
 
 #include <asm/io.h>
 
 static void __devinit get_initial_mode(struct intelfb_info *dinfo);
 static void update_dinfo(struct intelfb_info *dinfo,
                         struct fb_var_screeninfo *var);
-static int intelfb_get_fix(struct fb_fix_screeninfo *fix,
-                          struct fb_info *info);
-
 static int intelfb_check_var(struct fb_var_screeninfo *var,
                             struct fb_info *info);
 static int intelfb_set_par(struct fb_info *info);
@@ -165,9 +158,8 @@ static int intelfb_cursor(struct fb_info *info,
 
 static int intelfb_sync(struct fb_info *info);
 
-static int intelfb_ioctl(struct inode *inode, struct file *file,
-                        unsigned int cmd, unsigned long arg,
-                        struct fb_info *info);
+static int intelfb_ioctl(struct fb_info *info,
+                        unsigned int cmd, unsigned long arg);
 
 static int __devinit intelfb_pci_register(struct pci_dev *pdev,
                                          const struct pci_device_id *ent);
@@ -190,6 +182,9 @@ static struct pci_device_id intelfb_pci_table[] __devinitdata = {
        { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_85XGM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_85XGM },
        { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_865G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_865G },
        { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915G },
+       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915GM },
+       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945G },
+       { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GM },
        { 0, }
 };
 
@@ -230,7 +225,7 @@ MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
 
 static int accel        = 1;
 static int vram         = 4;
-static int hwcursor     = 1;
+static int hwcursor     = 0;
 static int mtrr         = 1;
 static int fixed        = 0;
 static int noinit       = 0;
@@ -238,12 +233,15 @@ static int noregister   = 0;
 static int probeonly    = 0;
 static int idonly       = 0;
 static int bailearly    = 0;
+static int voffset     = 48;
 static char *mode       = NULL;
 
 module_param(accel, bool, S_IRUGO);
-MODULE_PARM_DESC(accel, "Enable console acceleration");
+MODULE_PARM_DESC(accel, "Enable hardware acceleration");
 module_param(vram, int, S_IRUGO);
 MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
+module_param(voffset, int, S_IRUGO);
+MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB");
 module_param(hwcursor, bool, S_IRUGO);
 MODULE_PARM_DESC(hwcursor, "Enable HW cursor");
 module_param(mtrr, bool, S_IRUGO);
@@ -474,9 +472,9 @@ cleanup(struct intelfb_info *dinfo)
        if (dinfo->aperture.virtual)
                iounmap((void __iomem *)dinfo->aperture.virtual);
 
-       if (dinfo->mmio_base_phys)
+       if (dinfo->flag & INTELFB_MMIO_ACQUIRED)
                release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
-       if (dinfo->aperture.physical)
+       if (dinfo->flag & INTELFB_FB_ACQUIRED)
                release_mem_region(dinfo->aperture.physical,
                                   dinfo->aperture.size);
        framebuffer_release(dinfo->info);
@@ -495,7 +493,7 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        struct fb_info *info;
        struct intelfb_info *dinfo;
-       int i, j, err, dvo;
+       int i, err, dvo;
        int aperture_size, stolen_size;
        struct agp_kern_info gtt_info;
        int agp_memtype;
@@ -503,6 +501,7 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
        struct agp_bridge_data *bridge;
        int aperture_bar = 0;
        int mmio_bar = 1;
+       int offset;
 
        DBG_MSG("intelfb_pci_register\n");
 
@@ -549,11 +548,12 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
 
        /* Set base addresses. */
-       if (ent->device == PCI_DEVICE_ID_INTEL_915G) {
+       if ((ent->device == PCI_DEVICE_ID_INTEL_915G) ||
+           (ent->device == PCI_DEVICE_ID_INTEL_915GM) ||
+           (ent->device == PCI_DEVICE_ID_INTEL_945G)  ||
+           (ent->device == PCI_DEVICE_ID_INTEL_945GM)) {
                aperture_bar = 2;
                mmio_bar = 0;
-               /* Disable HW cursor on 915G (not implemented yet) */
-               hwcursor = 0;
        }
        dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar);
        dinfo->aperture.size     = pci_resource_len(pdev, aperture_bar);
@@ -571,6 +571,9 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
                cleanup(dinfo);
                return -ENODEV;
        }
+
+       dinfo->flag |= INTELFB_FB_ACQUIRED;
+
        if (!request_mem_region(dinfo->mmio_base_phys,
                                INTEL_REG_SIZE,
                                INTELFB_MODULE_NAME)) {
@@ -579,28 +582,12 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
                return -ENODEV;
        }
 
-       /* Map the fb and MMIO regions */
-       dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
-               (dinfo->aperture.physical, dinfo->aperture.size);
-       if (!dinfo->aperture.virtual) {
-               ERR_MSG("Cannot remap FB region.\n");
-               cleanup(dinfo);
-               return -ENODEV;
-       }
-       dinfo->mmio_base =
-               (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
-                                              INTEL_REG_SIZE);
-       if (!dinfo->mmio_base) {
-               ERR_MSG("Cannot remap MMIO region.\n");
-               cleanup(dinfo);
-               return -ENODEV;
-       }
+       dinfo->flag |= INTELFB_MMIO_ACQUIRED;
 
        /* Get the chipset info. */
        dinfo->pci_chipset = pdev->device;
 
-       if (intelfbhw_get_chipset(pdev, &dinfo->name, &dinfo->chipset,
-                                 &dinfo->mobile)) {
+       if (intelfbhw_get_chipset(pdev, dinfo)) {
                cleanup(dinfo);
                return -ENODEV;
        }
@@ -659,22 +646,46 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
                return -ENODEV;
        }
 
+       if (MB(voffset) < stolen_size)
+               offset = (stolen_size >> 12);
+       else
+               offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
+
        /* set the mem offsets - set them after the already used pages */
        if (dinfo->accel) {
-               dinfo->ring.offset = (stolen_size >> 12)
-                       + gtt_info.current_memory;
+               dinfo->ring.offset = offset + gtt_info.current_memory;
        }
        if (dinfo->hwcursor) {
-               dinfo->cursor.offset = (stolen_size >> 12) +
+               dinfo->cursor.offset = offset +
                        + gtt_info.current_memory + (dinfo->ring.size >> 12);
        }
        if (dinfo->fbmem_gart) {
-               dinfo->fb.offset = (stolen_size >> 12) +
+               dinfo->fb.offset = offset +
                        + gtt_info.current_memory + (dinfo->ring.size >> 12)
                        + (dinfo->cursor.size >> 12);
        }
 
        /* Allocate memories (which aren't stolen) */
+       /* Map the fb and MMIO regions */
+       /* ioremap only up to the end of used aperture */
+       dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
+               (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12)
+                + dinfo->fb.size);
+       if (!dinfo->aperture.virtual) {
+               ERR_MSG("Cannot remap FB region.\n");
+               cleanup(dinfo);
+               return -ENODEV;
+       }
+
+       dinfo->mmio_base =
+               (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
+                                              INTEL_REG_SIZE);
+       if (!dinfo->mmio_base) {
+               ERR_MSG("Cannot remap MMIO region.\n");
+               cleanup(dinfo);
+               return -ENODEV;
+       }
+
        if (dinfo->accel) {
                if (!(dinfo->gtt_ring_mem =
                      agp_allocate_memory(bridge, dinfo->ring.size >> 12,
@@ -833,13 +844,6 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (bailearly == 5)
                bailout(dinfo);
 
-       for (i = 0; i < 16; i++) {
-               j = color_table[i];
-               dinfo->palette[i].red = default_red[j];
-               dinfo->palette[i].green = default_grn[j];
-               dinfo->palette[i].blue = default_blu[j];
-       }
-
        if (bailearly == 6)
                bailout(dinfo);
 
@@ -1083,13 +1087,24 @@ intelfb_set_fbinfo(struct intelfb_info *dinfo)
 
        info->pixmap.size = 64*1024;
        info->pixmap.buf_align = 8;
+       info->pixmap.access_align = 32;
        info->pixmap.flags = FB_PIXMAP_SYSTEM;
 
        if (intelfb_init_var(dinfo))
                return 1;
 
        info->pixmap.scan_align = 1;
-
+       strcpy(info->fix.id, dinfo->name);
+       info->fix.smem_start = dinfo->fb.physical;
+       info->fix.smem_len = dinfo->fb.size;
+       info->fix.type = FB_TYPE_PACKED_PIXELS;
+       info->fix.type_aux = 0;
+       info->fix.xpanstep = 8;
+       info->fix.ypanstep = 1;
+       info->fix.ywrapstep = 0;
+       info->fix.mmio_start = dinfo->mmio_base_phys;
+       info->fix.mmio_len = INTEL_REG_SIZE;
+       info->fix.accel = FB_ACCEL_I830;
        update_dinfo(dinfo, &info->var);
 
        return 0;
@@ -1107,7 +1122,8 @@ update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
        dinfo->yres = var->xres;
        dinfo->pixclock = var->pixclock;
 
-       intelfb_get_fix(&dinfo->info->fix, dinfo->info);
+       dinfo->info->fix.visual = dinfo->visual;
+       dinfo->info->fix.line_length = dinfo->pitch;
 
        switch (dinfo->bpp) {
        case 8:
@@ -1137,30 +1153,6 @@ update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
 
 /* fbops functions */
 
-static int
-intelfb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
-{
-       struct intelfb_info *dinfo = GET_DINFO(info);
-
-       DBG_MSG("intelfb_get_fix\n");
-
-       memset(fix, 0, sizeof(*fix));
-       strcpy(fix->id, dinfo->name);
-       fix->smem_start = dinfo->fb.physical;
-       fix->smem_len = dinfo->fb.size;
-       fix->type = FB_TYPE_PACKED_PIXELS;
-       fix->type_aux = 0;
-       fix->visual = dinfo->visual;
-       fix->xpanstep = 8;
-       fix->ypanstep = 1;
-       fix->ywrapstep = 0;
-       fix->line_length = dinfo->pitch;
-       fix->mmio_start = dinfo->mmio_base_phys;
-       fix->mmio_len = INTEL_REG_SIZE;
-       fix->accel = FB_ACCEL_I830;
-       return 0;
-}
-
 /***************************************************************
  *                       fbdev interface                       *
  ***************************************************************/
@@ -1293,7 +1285,7 @@ intelfb_set_par(struct fb_info *info)
 
        intelfb_blank(FB_BLANK_POWERDOWN, info);
 
-       if (dinfo->accel)
+       if (ACCEL(dinfo, info))
                intelfbhw_2d_stop(dinfo);
 
        memcpy(hw, &dinfo->save_state, sizeof(*hw));
@@ -1309,7 +1301,7 @@ intelfb_set_par(struct fb_info *info)
 
        update_dinfo(dinfo, &info->var);
 
-       if (dinfo->accel)
+       if (ACCEL(dinfo, info))
                intelfbhw_2d_start(dinfo);
 
        intelfb_pan_display(&info->var, info);
@@ -1343,37 +1335,35 @@ intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
        if (regno > 255)
                return 1;
 
-       switch (dinfo->depth) {
-       case 8:
-               {
-                       red >>= 8;
-                       green >>= 8;
-                       blue >>= 8;
+       if (dinfo->depth == 8) {
+               red >>= 8;
+               green >>= 8;
+               blue >>= 8;
 
-                       dinfo->palette[regno].red = red;
-                       dinfo->palette[regno].green = green;
-                       dinfo->palette[regno].blue = blue;
+               intelfbhw_setcolreg(dinfo, regno, red, green, blue,
+                                   transp);
+       }
 
-                       intelfbhw_setcolreg(dinfo, regno, red, green, blue,
-                                           transp);
+       if (regno < 16) {
+               switch (dinfo->depth) {
+               case 15:
+                       dinfo->pseudo_palette[regno] = ((red & 0xf800) >>  1) |
+                               ((green & 0xf800) >>  6) |
+                               ((blue & 0xf800) >> 11);
+                       break;
+               case 16:
+                       dinfo->pseudo_palette[regno] = (red & 0xf800) |
+                               ((green & 0xfc00) >>  5) |
+                               ((blue  & 0xf800) >> 11);
+                       break;
+               case 24:
+                       dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
+                               (green & 0xff00) |
+                               ((blue  & 0xff00) >> 8);
+                       break;
                }
-               break;
-       case 15:
-               dinfo->pseudo_palette[regno] = ((red & 0xf800) >>  1) |
-                                              ((green & 0xf800) >>  6) |
-                                              ((blue & 0xf800) >> 11);
-               break;
-       case 16:
-               dinfo->pseudo_palette[regno] = (red & 0xf800) |
-                                              ((green & 0xfc00) >>  5) |
-                                              ((blue  & 0xf800) >> 11);
-               break;
-       case 24:
-               dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
-                                              (green & 0xff00) |
-                                              ((blue  & 0xff00) >> 8);
-               break;
        }
+
        return 0;
 }
 
@@ -1393,8 +1383,7 @@ intelfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
 
 /* When/if we have our own ioctls. */
 static int
-intelfb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
-             unsigned long arg, struct fb_info *info)
+intelfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
 {
        int retval = 0;
 
@@ -1480,18 +1469,21 @@ static int
 intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
 {
         struct intelfb_info *dinfo = GET_DINFO(info);
-
+       u32 physical;
 #if VERBOSE > 0
        DBG_MSG("intelfb_cursor\n");
 #endif
 
        if (!dinfo->hwcursor)
-               return soft_cursor(info, cursor);
+               return -ENODEV;
 
        intelfbhw_cursor_hide(dinfo);
 
        /* If XFree killed the cursor - restore it */
-       if (INREG(CURSOR_A_BASEADDR) != dinfo->cursor.offset << 12) {
+       physical = (dinfo->mobile || IS_I9XX(dinfo)) ? dinfo->cursor.physical :
+                  (dinfo->cursor.offset << 12);
+
+       if (INREG(CURSOR_A_BASEADDR) != physical) {
                u32 fg, bg;
 
                DBG_MSG("the cursor was killed - restore it !!\n");