patch-2.4.0-test3 linux/drivers/video/tdfxfb.c

Next file: linux/drivers/video/valkyriefb.c
Previous file: linux/drivers/video/sisfb.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test2/linux/drivers/video/tdfxfb.c linux/drivers/video/tdfxfb.c
@@ -86,23 +86,7 @@
 #include <video/fbcon-cfb24.h>
 #include <video/fbcon-cfb32.h>
 
-#ifndef LINUX_VERSION_CODE
-#include <linux/version.h>
-#endif
-
-#ifndef KERNEL_VERSION
-#define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
-#endif
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-#define PCI_DEVICE_ID_3DFX_VOODOO3      0x0005
-#endif
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-/* nothing? */
-#else
 #include <linux/spinlock.h>
-#endif
 
 /* membase0 register offsets */
 #define STATUS		0x00
@@ -332,10 +316,10 @@
   u32 max_pixclock;
 
   unsigned long regbase_phys;
-  unsigned long regbase_virt;
+  void *regbase_virt;
   unsigned long regbase_size;
   unsigned long bufbase_phys;
-  unsigned long bufbase_virt;
+  void *bufbase_virt;
   unsigned long bufbase_size;
   unsigned long iobase;
 
@@ -368,6 +352,9 @@
   } cursor;
  
   spinlock_t DAClock; 
+#ifdef CONFIG_MTRR
+  int mtrr_idx;
+#endif
 };
 
 /*
@@ -468,11 +455,7 @@
 /*
  *  Interface used by the world
  */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-void tdfxfb_init(void);
-#else
 int tdfxfb_init(void);
-#endif
 void tdfxfb_setup(char *options, 
 		  int *ints);
 
@@ -505,71 +488,8 @@
       0, FB_VMODE_NONINTERLACED
     }
   }
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-  ,
-  { "800x600-8@56", /* @ 56 Hz */
-    {
-      800, 600, 800, 600, 0, 0, 8, 0,
-      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
-      0, FB_ACTIVATE_NOW, -1, -1, FB_ACCELF_TEXT, 
-      27778, 128, 24, 22, 1, 72, 2,
-      0, FB_VMODE_NONINTERLACED
-    }
-  },
-  { "1024x768-8@60", /* @ 60 Hz */
-    {
-      1024, 768, 1024, 768, 0, 0, 8, 0,
-      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
-      0, FB_ACTIVATE_NOW, -1, -1, FB_ACCELF_TEXT, 
-      15385, 168, 8, 29, 3, 144, 6,
-      0, FB_VMODE_NONINTERLACED
-    }
-  },
-  { "1280x1024-8@61", /* @ 61 Hz */
-    {
-      1280, 1024, 1280, 1024, 0, 0, 8, 0,
-      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
-      0, FB_ACTIVATE_NOW, -1, -1, FB_ACCELF_TEXT, 
-      9091, 200, 48, 26, 1, 184, 3,
-      0, FB_VMODE_NONINTERLACED
-    }
-  },
-  { "1024x768-16@60", /* @ 60 Hz */ /* basically for testing */
-    {
-      1024, 768, 1024, 768, 0, 0, 16, 0,
-      {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
-      0, FB_ACTIVATE_NOW, -1, -1, FB_ACCELF_TEXT, 
-      15385, 168, 8, 29, 3, 144, 6,
-      0, FB_VMODE_NONINTERLACED
-    }
-  },
-  { "1024x768-24@60", /* @ 60 Hz */ 
-    {
-      1024, 768, 1024, 768, 0, 0, 24, 0,
-      {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0},
-      0, FB_ACTIVATE_NOW, -1, -1, FB_ACCELF_TEXT, 
-      15385, 168, 8, 29, 3, 144, 6,
-      0, FB_VMODE_NONINTERLACED
-    }
-  },
-  { "1024x768-32@60", /* @ 60 Hz */ 
-    {
-      1024, 768, 1024, 768, 0, 0, 32, 0,
-      {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0},
-      0, FB_ACTIVATE_NOW, -1, -1, FB_ACCELF_TEXT, 
-      15385, 168, 8, 29, 3, 144, 6,
-      0, FB_VMODE_NONINTERLACED
-    }
-  }   
-   
-#endif
 };
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-static int modes = sizeof(default_mode)/sizeof(struct mode);
-static int default_mode_index = 0;
-#endif
-
 static struct fb_info_tdfx fb_info;
 
 static int  noaccel = 0;
@@ -1674,17 +1594,10 @@
 	   info->dev == PCI_DEVICE_ID_3DFX_BANSHEE 
 	   ? "3Dfx Banshee"
 	   : "3Dfx Voodoo3");
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-    fix->smem_start  = (char*)info->bufbase_phys;
-    fix->smem_len    = info->bufbase_size;
-    fix->mmio_start  = (char*)info->regbase_phys;
-    fix->mmio_len    = info->regbase_size;
-#else
     fix->smem_start  = info->bufbase_phys;
     fix->smem_len    = info->bufbase_size;
     fix->mmio_start  = info->regbase_phys;
     fix->mmio_len    = info->regbase_size;
-#endif
     fix->accel       = FB_ACCEL_3DFX_BANSHEE;
     fix->type        = FB_TYPE_PACKED_PIXELS;
     fix->type_aux    = 0;
@@ -1815,7 +1728,7 @@
 	 struct fb_fix_screeninfo fix;
 	 
 	 tdfxfb_encode_fix(&fix, &par, info);
-	 display->screen_base    = (char *)info->bufbase_virt;
+	 display->screen_base    = info->bufbase_virt;
 	 display->visual         = fix.visual;
 	 display->type           = fix.type;
 	 display->type_aux       = fix.type_aux;
@@ -1940,20 +1853,10 @@
    return -EINVAL;
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-__initfunc(void tdfxfb_init(void)) {
-#else
 int __init tdfxfb_init(void) {
-#endif
   struct pci_dev *pdev = NULL;
   struct fb_var_screeninfo var;
   
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-  if(!pcibios_present()) return;
-#else
-  if(!pcibios_present()) return -ENXIO;
-#endif
-
   while ((pdev = pci_find_device(PCI_VENDOR_ID_3DFX, PCI_ANY_ID, pdev))) {
     if(((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY) &&
        ((pdev->device == PCI_DEVICE_ID_3DFX_BANSHEE) ||
@@ -1968,67 +1871,38 @@
 	? BANSHEE_MAX_PIXCLOCK
 	: VOODOO3_MAX_PIXCLOCK;
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-      fb_info.regbase_phys = pdev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK;
-      fb_info.regbase_size = 1 << 24;
-      fb_info.regbase_virt = 
-	(unsigned long)ioremap_nocache(fb_info.regbase_phys, 1 << 24);
-      if(!fb_info.regbase_virt) {
-	printk("fb: Can't remap %s register area.\n", name);
-	return;
-      }
-
-      fb_info.bufbase_phys = pdev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK;
-      if(!(fb_info.bufbase_size = do_lfb_size())) {
-	printk("fb: Can't count %s memory.\n", name);
-	iounmap((void*)fb_info.regbase_virt);
-	return;
-      }
-      fb_info.bufbase_virt    = 
-	(unsigned long)ioremap_nocache(fb_info.bufbase_phys, fb_info.bufbase_size);
-      if(!fb_info.regbase_virt) {
-	printk("fb: Can't remap %s framebuffer.\n", name);
-	iounmap((void*)fb_info.regbase_virt);
-	return;
-      }
-
-      fb_info.iobase = pdev->base_address[2] & PCI_BASE_ADDRESS_IO_MASK;
-#else
-      fb_info.regbase_phys = pdev->resource[0].start;
+      fb_info.regbase_phys = pci_resource_start(pdev, 0);
       fb_info.regbase_size = 1 << 24;
-      fb_info.regbase_virt = 
-	(unsigned long)ioremap_nocache(fb_info.regbase_phys, 1 << 24);
+      fb_info.regbase_virt = ioremap_nocache(fb_info.regbase_phys, 1 << 24);
       if(!fb_info.regbase_virt) {
 	printk("fb: Can't remap %s register area.\n", name);
 	return -ENXIO;
       }
       
-      fb_info.bufbase_phys = pdev->resource[1].start;
+      fb_info.bufbase_phys = pci_resource_start (pdev, 1);
       if(!(fb_info.bufbase_size = do_lfb_size())) {
-	iounmap((void*)fb_info.regbase_virt);
+	iounmap(fb_info.regbase_virt);
 	printk("fb: Can't count %s memory.\n", name);
 	return -ENXIO;
       }
-      fb_info.bufbase_virt    = 
-	(unsigned long)ioremap_nocache(fb_info.bufbase_phys, fb_info.bufbase_size);
+      fb_info.bufbase_virt = ioremap_nocache(fb_info.bufbase_phys, fb_info.bufbase_size);
       if(!fb_info.regbase_virt) {
 	printk("fb: Can't remap %s framebuffer.\n", name);
-	iounmap((void*)fb_info.regbase_virt);
+	iounmap(fb_info.regbase_virt);
 	return -ENXIO;
       }
 
-      fb_info.iobase = pdev->resource[2].start;
-#endif
+      fb_info.iobase = pci_resource_start (pdev, 2);
       
       printk("fb: %s memory = %ldK\n", name, fb_info.bufbase_size >> 10);
 
 #ifdef CONFIG_MTRR
        if (!nomtrr) {
-	  if (mtrr_add(fb_info.bufbase_phys, fb_info.bufbase_size, 
-		       MTRR_TYPE_WRCOMB, 1)>=0)
+          fb_info.mtrr_idx = mtrr_add(fb_info.bufbase_phys, fb_info.bufbase_size,
+	  			      MTRR_TYPE_WRCOMB, 1);
 	    printk("fb: MTRR's  turned on\n");
        }
-#endif	  	 
+#endif
 
       /* clear framebuffer memory */
       memset_io(fb_info.bufbase_virt, 0, fb_info.bufbase_size);
@@ -2053,16 +1927,10 @@
       fb_info.fb_info.blank      = &tdfxfb_blank;
       fb_info.fb_info.flags      = FBINFO_FLAG_DEFAULT;
       
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-      var = default_mode[default_mode_index < modes
-			? default_mode_index
-			: 0].var;
-#else
       memset(&var, 0, sizeof(var));
       if(!mode_option || 
 	 !fb_find_mode(&var, &fb_info.fb_info, mode_option, NULL, 0, NULL, 8))
 	var = default_mode[0].var;
-#endif
       
       if(noaccel) var.accel_flags &= ~FB_ACCELF_TEXT;
       else var.accel_flags |= FB_ACCELF_TEXT;
@@ -2081,57 +1949,73 @@
 	if(tdfxfb_decode_var(&var, &fb_info.default_par, &fb_info)) {
 	  /* this is getting really bad!... */
 	  printk("tdfxfb: can't decode default video mode\n");
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-	  return;
-#else
 	  return -ENXIO;
-#endif
 	}
       }
       
-      fb_info.disp.screen_base    = (void*)fb_info.bufbase_virt;
+      fb_info.disp.screen_base    = fb_info.bufbase_virt;
       fb_info.disp.var            = var;
       
       if(tdfxfb_set_var(&var, -1, &fb_info.fb_info)) {
 	printk("tdfxfb: can't set default video mode\n");
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-	return;
-#else
 	return -ENXIO;
-#endif
       }
       
       if(register_framebuffer(&fb_info.fb_info) < 0) {
 	printk("tdfxfb: can't register framebuffer\n");
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-	return;
-#else
 	return -ENXIO;
-#endif
       }
 
       printk("fb%d: %s frame buffer device\n", 
 	     GET_FB_IDX(fb_info.fb_info.node),
 	     fb_info.fb_info.modename);
       
+      /* FIXME: module cannot be unloaded */
+      /* verify tdfxfb_exit before removing this */
       MOD_INC_USE_COUNT;
       
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-      return;
-#else
       return 0;
-#endif
     }
   }
 
   /* hmm, no frame suitable buffer found ... */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-  return;
-#else
   return -ENXIO;
+}
+
+/**
+ *	tdfxfb_exit - Driver cleanup
+ *
+ *	Releases all resources allocated during the
+ *	course of the driver's lifetime.
+ *
+ *	FIXME - do results of fb_alloc_cmap need disposal?
+ */
+static void __exit tdfxfb_exit (void)
+{
+	unregister_framebuffer(&fb_info.fb_info);
+	del_timer_sync(&fb_info.cursor.timer);
+
+#ifdef CONFIG_MTRR
+       if (!nomtrr) {
+          mtrr_del(fb_info.mtrr_idx, fb_info.bufbase_phys, fb_info.bufbase_size);
+	    printk("fb: MTRR's  turned off\n");
+       }
 #endif
+
+	iounmap(fb_info.regbase_virt);
+	iounmap(fb_info.bufbase_virt);
 }
 
+MODULE_AUTHOR("Hannu Mallat <hmallat@cc.hut.fi>");
+MODULE_DESCRIPTION("3Dfx framebuffer device driver");
+
+#ifdef MODULE
+module_init(tdfxfb_init);
+#endif
+module_exit(tdfxfb_exit);
+
+
+#ifndef MODULE
 void tdfxfb_setup(char *options, 
 		  int *ints) {
   char* this_opt;
@@ -2160,19 +2044,11 @@
     } else if (!strncmp(this_opt, "font:", 5)) {
       strncpy(fontname, this_opt + 5, 40);
     } else {
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
-      int i;
-      for(i = 0; i < modes; i++) {
-	if(!strcmp(this_opt, default_mode[i].name)) {
-	  default_mode_index = i;
-	}
-      }
-#else
       mode_option = this_opt;
-#endif
     }
   } 
 }
+#endif
 
 static int tdfxfb_switch_con(int con, 
 			     struct fb_info *fb) {
@@ -2438,7 +2314,7 @@
    start = (fb_info.bufbase_size-1024) & PAGE_MASK;
    fb_info.bufbase_size=start; 
    fb_info.cursor.cursorimage=fb_info.bufbase_size;
-   printk("tdfxfb: reserving 1024 bytes for the hwcursor at 0x%08lx\n",
+   printk("tdfxfb: reserving 1024 bytes for the hwcursor at %p\n",
 	  fb_info.regbase_virt+fb_info.cursor.cursorimage);
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)