[MPlayer-dev-eng] [PATCH] tdfx_vid for 2.6.10

Gergely Szasz szaszg at hu.inter.net
Sat Feb 19 23:15:45 CET 2005


Here is...
#########################################
diff -uN -x 'mga*' -x Makefile -x README -x CVS main/drivers/Makefile.tdfx /home/gergely/src/cvs/mplayer-1/tdfx-vid-2.6.10/Makefile.tdfx
--- main/drivers/Makefile.tdfx	1970-01-01 01:00:00.000000000 +0100
+++ /home/gergely/src/cvs/mplayer-1/tdfx-vid-2.6.10/Makefile.tdfx	2005-02-19 22:16:04.000000000 +0100
@@ -0,0 +1,50 @@
+KERNEL_DIR=/lib/modules/`uname -r`/build
+KERNEL_INCLUDES= $(KERNEL_DIR)/include
+INCLUDES = -I$(KERNEL_INCLUDES) -I$(KERNEL_INCLUDES)/asm
+VERSION = $(shell grep UTS_RELEASE $(KERNEL_INCLUDES)/linux/version.h | cut -d '"' -f2)
+MDIR = /lib/modules/$(VERSION)/misc
+
+ifneq (,$(findstring 2.6, $(VERSION)))
+obj-m += tdfx_vid.o
+CFLAGS = -O2  -D__KERNEL__  -DMODULE  	 -include $(KERNEL_INCLUDES)/config/modversions.h -Wall
+else
+CFLAGS = -O2  -D__KERNEL__  -DMODULE  	 -include $(KERNEL_INCLUDES)/linux/modversions.h -Wall
+endif
+
+all:
+ifneq (,$(findstring 2.6, $(VERSION)))
+	$(MAKE) tdfx_vid.ko
+else
+	$(MAKE) tdfx_vid.o
+endif
+# sis_vid.o
+
+tdfx_vid.o: tdfx_vid.c tdfx_vid.h
+	$(CC) $(CFLAGS) $(INCLUDES) -c $(basename $@).c
+
+tdfx_vid.ko: tdfx_vid.c tdfx_vid.h
+	$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
+
+tdfx_vid_tst: tdfx_vid_tst.c
+	$(CC) -O $(INCLUDES) -o $@ $@.c
+
+install: tdfx_vid.o
+	if test ! -d $(MDIR) ; then mkdir -p $(MDIR) ; fi
+ifneq (,$(findstring 2.6, $(VERSION)))
+	install -m 644 tdfx_vid.ko $(MDIR)/tdfx_vid.ko
+else
+	install -m 644 tdfx_vid.o $(MDIR)/tdfx_vid.o
+endif
+	depmod -a
+
+dep:
+
+clean: 
+	rm -f *.o *~
+ifneq (,$(findstring 2.6, $(VERSION)))
+	rm -f *.ko .mga* tdfx_vid.mod.c
+endif
+
+distclean: clean
+	rm -f tdfx_vid_test
+
diff -uN -x 'mga*' -x Makefile -x README -x CVS main/drivers/README.tdfx /home/gergely/src/cvs/mplayer-1/tdfx-vid-2.6.10/README.tdfx
--- main/drivers/README.tdfx	1970-01-01 01:00:00.000000000 +0100
+++ /home/gergely/src/cvs/mplayer-1/tdfx-vid-2.6.10/README.tdfx	2005-02-19 22:26:35.000000000 +0100
@@ -0,0 +1,51 @@
+
+tdfx_vid  -  3dfx Voodoo Banshee/Voodoo 3 YUV Overlay kernel module
+
+	Author:
+		Albeu
+
+	Make 2.6.10 kernel compatible:
+		Gergely Szasz <szaszg at hu.inter.net>
+
+                       WARNING  -----  WARNING
+
+This code messes with your video card and your xserver. It will probably
+lock up your box, format your hard drive, and cause your video card 
+to spout 6 inch flames. You have been warned.
+
+                       WARNING  -----  WARNING
+
+See the mga_vid section in mplayer HTML docs...
+
+What does this code do?
+
+    See mga_vid README
+    
+How does tdfx_vid work?
+
+    See mga_vid README
+
+How make this kernel module?
+
+    cp Makefile.tdfx Makefile
+    make
+    cp tdfx_vid.ko /lib/modules/2.6.10/kernel
+    depmod -a
+    modprobe tdfx_vid.ko
+    mplayer -vo tdfx_vid ......
+
+What is needed?
+    kernel module support
+    kernel agp support...
+    gcc
+    make
+    mplayer :)
+
+How do I know if tdfx_vid works on my system?
+
+    Try it...
+
+Bug?
+
+    Ok. inter_module_get,
+        inter_module_put are deprecated, what we can use instead???
diff -uN -x 'mga*' -x Makefile -x README -x CVS main/drivers/tdfx_vid.c /home/gergely/src/cvs/mplayer-1/tdfx-vid-2.6.10/tdfx_vid.c
--- main/drivers/tdfx_vid.c	2003-07-09 02:30:21.000000000 +0100
+++ /home/gergely/src/cvs/mplayer-1/tdfx-vid-2.6.10/tdfx_vid.c	2005-02-19 22:21:24.000000000 +0100
@@ -1,7 +1,20 @@
 
+#define MODULENAME "tdfx_vid"
+
+#define DEFAULT_TDFX_VID_MAJOR 178
+
+//It's entirely possible this major conflicts with something else
+//use the 'major' parameter to override the default major number (178)
+/* mknod /dev/tdfx_vid c 178 0 */
+
+
 #include <linux/config.h>
 #include <linux/version.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kobject.h>
+#include <linux/kobj_map.h>
+#include <linux/cdev.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
@@ -28,19 +41,20 @@
 #include "3dfx.h"
 
 
-#define TDFX_VID_MAJOR 178
-
 MODULE_AUTHOR("Albeu");
-MODULE_DESCRIPTION("A driver for Banshee targeted for video app");
+MODULE_DESCRIPTION("A driver for 3dfx cards for video app /2.6.10/");
 
-#ifdef MODULE_LICENSE
 MODULE_LICENSE("GPL");
-#endif
 
 #ifndef min
 #define min(x,y) (((x)<(y))?(x):(y))
 #endif
 
+/* Global handles for cdev */
+static struct cdev *tdfx_vid_cdev;
+static dev_t tdfx_cdev_handle;
+
+
 static struct pci_dev *pci_dev;
 
 static uint8_t *tdfx_mmio_base = 0;
@@ -52,20 +66,23 @@
 static int tdfx_vid_in_use = 0;
 
 static drm_agp_t *drm_agp = NULL;
-static agp_kern_info agp_info;
-static agp_memory *agp_mem = NULL;
+static struct agp_kern_info agp_info;
+static struct agp_memory *agp_mem = NULL;
+
+static int major = DEFAULT_TDFX_VID_MAJOR;
+static int tdfx_map_io = 1;
+static unsigned long map_start = 0; //0x7300000;
+static unsigned long map_max = (10*1024*1024);
+//static unsigned long map_base = 0;
+
+module_param(tdfx_map_io, int, 0);
+//MODULE_PARM_DESC(tdfx_map_io, "Set to 0 to use the page fault handler (you need to patch agpgart_be.c to allow the mapping in user space)\n");
+module_param(map_start, long, 0);
+//MODULE_PARM_DESC(map_start,"Use a block of physical mem instead of the agp arerture.");
+module_param(map_max, long, 0);
+//MODULE_PARM_DESC(map_max, "Maximum amout of physical memory (in bytes) that can be used\n");
+module_param(major, int, 0);
 
-static __initdata int tdfx_map_io = 1;
-static __initdata unsigned long map_start = 0; //0x7300000;
-static __initdata unsigned long map_max = (10*1024*1024);
-static unsigned long map_base = 0;
-
-MODULE_PARM(tdfx_map_io,"i");
-MODULE_PARM_DESC(tdfx_map_io, "Set to 0 to use the page fault handler (you need to patch agpgart_be.c to allow the mapping in user space)\n");
-MODULE_PARM(map_start,"l");
-MODULE_PARM_DESC(map_start,"Use a block of physical mem instead of the agp arerture.");
-MODULE_PARM(map_max,"l");
-MODULE_PARM_DESC(map_max, "Maximum amout of physical memory (in bytes) that can be used\n");
 
 static inline u32 tdfx_inl(unsigned int reg) {
   return readl(tdfx_mmio_base + reg);
@@ -172,7 +189,7 @@
       struct resource *res=&pci_dev->resource[temp];
       if(res->flags){
 	int size=(1+res->end-res->start)>>20;
-	printk(KERN_DEBUG "res %d:  start: 0x%X   end: 0x%X  (%d MB) flags=0x%X\n",temp,res->start,res->end,size,res->flags);
+	printk(KERN_DEBUG "res %d:  start: 0x%lX   end: 0x%lX  (%d MB) flags=0x%lX\n",temp,res->start,res->end,size,res->flags);
 	if(res->flags&(IORESOURCE_MEM|IORESOURCE_PREFETCH)){
 	  if(size>tdfx_ram_size && size<=64) tdfx_ram_size=size;
 	}
@@ -202,20 +219,20 @@
 
   drm_agp->copy_info(&agp_info);
 #if 0
-  printk(KERN_DEBUG "AGP Version : %d %d\n"
-	 "AGP Mode: %#X\nAperture Base: %p\nAperture Size: %d\n"
-	 "Max memory = %d\nCurrent mem = %d\nCan use perture : %s\n"
-	 "Page mask = %#X\n",
-	 agp_info.version.major,agp_info.version.minor,
-	 agp_info.mode,agp_info.aper_base,agp_info.aper_size,
-	 agp_info.max_memory,agp_info.current_memory,
+  printk(KERN_DEBUG "tdfx_vid: AGP Version : %d %d\n"
+	 "     AGP Mode: %#lX\n     Aperture Base: %p\n     Aperture Size: %d\n"
+	 "     Max memory = %d\n     Current mem = %d\n     Can use perture : %s\n"
+	 "     Page mask = %#lX\n",
+	 agp_info.version.major, agp_info.version.minor,
+	 agp_info.mode, (void *) agp_info.aper_base, agp_info.aper_size,
+	 agp_info.max_memory, agp_info.current_memory,
 	 agp_info.cant_use_aperture ? "no" : "yes",
 	 agp_info.page_mask);
 #endif
   drm_agp->enable(agp_info.mode);
 
   
-  printk(KERN_INFO "AGP Enabled\n");
+  printk(KERN_INFO "tdfx_vid: AGP Enabled\n");
 
   return 1;
 }
@@ -792,7 +809,6 @@
     }
     get_page(page);
   }
-  MOD_INC_USE_COUNT;
 }
 
 static void tdfx_vid_mclose(struct vm_area_struct *vma)  {
@@ -812,12 +828,10 @@
     put_page(page);
   }
 
-  MOD_DEC_USE_COUNT;
 }
-
 static struct page *tdfx_vid_nopage(struct vm_area_struct *vma,
 				    unsigned long address, 
-				    int write_access) {
+				    int *type) {
   unsigned long off;
   uint32_t n;
   struct page *page;
@@ -861,8 +875,12 @@
       printk(KERN_ERR "tdfx_vid: Not enouth mem\n");
       return(-EAGAIN);
     }
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,3)
-    if(remap_page_range(vma, vma->vm_start,map_start,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
+    if(remap_pfn_range(vma, vma->vm_start, map_start >> PAGE_SHIFT,
+			 vma->vm_end - vma->vm_start,
+			 vma->vm_page_prot))
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,3)
+    if(remap_page_range(vma, vma->vm_start, map_start,
 			vma->vm_end - vma->vm_start, vma->vm_page_prot)) 
 #else
     if(remap_page_range(vma->vm_start, (unsigned long)map_start,
@@ -897,8 +915,12 @@
 
 
   if(tdfx_map_io) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,3)
-    if(remap_page_range(vma, vma->vm_start,agp_info.aper_base,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
+    if(remap_pfn_range(vma, vma->vm_start, agp_info.aper_base >> PAGE_SHIFT,
+			 vma->vm_end - vma->vm_start,
+			 vma->vm_page_prot))
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,3)
+    if(remap_page_range(vma, vma->vm_start, agp_info.aper_base,
 			vma->vm_end - vma->vm_start, vma->vm_page_prot)) 
 #else
     if(remap_page_range(vma->vm_start, (unsigned long)agp_info.aper_base,
@@ -935,7 +957,6 @@
   
   tdfx_vid_in_use = 0;
 
-  MOD_DEC_USE_COUNT;
   return 0;
 }
 
@@ -946,21 +967,22 @@
 
 static int tdfx_vid_open(struct inode *inode, struct file *file)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
+	int minor = iminor(inode);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2)
 	int minor = MINOR(inode->i_rdev.value);
 #else
 	int minor = MINOR(inode->i_rdev);
 #endif
 
-	if(minor != 0)
-	 return(-ENXIO);
+	if(minor >= 1)
+	  return(-ENXIO);
 
 	if(tdfx_vid_in_use == 1) 
-		return(-EBUSY);
+	  return(-EBUSY);
 
 	tdfx_vid_in_use = 1;
-	MOD_INC_USE_COUNT;
-	return(0);
+	return 0;
 }
 
 #if LINUX_VERSION_CODE >= 0x020400
@@ -991,39 +1013,82 @@
 #endif
 
 
-int init_module(void)
+int tdfx_vid_initialize(void)
 {
   tdfx_vid_in_use = 0;
 
-  if(register_chrdev(TDFX_VID_MAJOR, "tdfx_vid", &tdfx_vid_fops)) {
-    printk(KERN_ERR "tdfx_vid: unable to get major: %d\n", TDFX_VID_MAJOR);
+  printk(KERN_INFO "3dfx Voodoo Banshee/Voodoo 3 YUV Video interface v2.01\n");
+	
+  if(tdfx_vid_find_card()) 
+    {
+      if(!agp_init())
+        {
+	  printk(KERN_ERR "tdfx_vid: AGP init failed\n");
+	  return -EINVAL;
+	}
+
+	/* Have the kernel generate a major device number */
+      if(major == 0)
+        {
+	  if(!alloc_chrdev_region(&tdfx_cdev_handle, 0, 1, "tdfx_vid"))
+	    {
+	      major = MAJOR(tdfx_cdev_handle);
+	      printk(KERN_INFO "tdfx_vid: using major: %d (dynamically alocated!)\n", major);
+	    }
+	} 
+      else
+	{
+	  tdfx_cdev_handle = MKDEV(major, 0);
+	  if(!register_chrdev_region(tdfx_cdev_handle, 1, "tdfx_vid"))
+	    printk(KERN_INFO "tdfx_vid: using major: %d (assigned or default!)\n", major);
+	}
+      /* Allocate a cdev for this character device, and fill in some parameters it needs */
+      tdfx_vid_cdev = cdev_alloc();
+      tdfx_vid_cdev->owner = THIS_MODULE;
+      strcpy(tdfx_vid_cdev->kobj.name, MODULENAME);
+      tdfx_vid_cdev->ops = &tdfx_vid_fops;
+      /* Add this character device to the system */
+      cdev_add(tdfx_vid_cdev, tdfx_cdev_handle, 1);
+	
+      return 0;
+    }
+  else
+    {
+      return -EFAULT;
+    }
+/*
+  if(register_chrdev(DEFAULT_TDFX_VID_MAJOR, "tdfx_vid", &tdfx_vid_fops)) {
+    printk(KERN_ERR "tdfx_vid: unable to get major: %d\n", DEFAULT_TDFX_VID_MAJOR);
     return -EIO;
   }
 
   if(!agp_init()) {
     printk(KERN_ERR "tdfx_vid: AGP init failed\n");
-    unregister_chrdev(TDFX_VID_MAJOR, "tdfx_vid");
+    unregister_chrdev(DEFAULT_TDFX_VID_MAJOR, "tdfx_vid");
     return -EINVAL;
   }
 
   if (!tdfx_vid_find_card()) {
     printk(KERN_ERR "tdfx_vid: no supported devices found\n");
     agp_close();
-    unregister_chrdev(TDFX_VID_MAJOR, "tdfx_vid");
+    unregister_chrdev(DEFAULT_TDFX_VID_MAJOR, "tdfx_vid");
     return -EINVAL;
   }
+*/
+}
 
-  
+module_init(tdfx_vid_initialize);
 
-  return (0);
 
-}
-
-void cleanup_module(void)
+void tdfx_cleanup_module(void)
 {
   if(tdfx_mmio_base)
     iounmap(tdfx_mmio_base);
   agp_close();
   printk(KERN_INFO "tdfx_vid: Cleaning up module\n");
-  unregister_chrdev(TDFX_VID_MAJOR, "tdfx_vid");
+  cdev_del(tdfx_vid_cdev);
+  unregister_chrdev_region(tdfx_cdev_handle, 1);
+//  unregister_chrdev(DEFAULT_TDFX_VID_MAJOR, "tdfx_vid");
 }
+
+module_exit(tdfx_cleanup_module);




More information about the MPlayer-dev-eng mailing list