[MPlayer-dev-eng] [FWD] mga_vid.c ported to 2.6.0-test1 (from: algernon at debian.org)

Mark Szabo mw3 at daisy.chains.ch
Sun Jul 20 17:15:26 CEST 2003


----- Forwarded message from Gergely Nagy <algernon at debian.org> -----

From: Gergely Nagy <algernon at debian.org>
Subject: mga_vid.c ported to 2.6.0-test1
To: mplayer-dev-eng at mplayerhq.hu
Cc: Gergely Nagy <algernon at debian.org>
User-Agent: Wanderlust/2.10.1 (Watching The Wheels) Emacs/21.3 Mule/5.0 (SAKAKI)
Date: Sun, 20 Jul 2003 16:36:48 +0200
X-Fortune: Be careful when you bite into your hamburger. -- Derek Bok

(ObCc: Please Cc: me on replies, I'm not subscribed)

Hi!

A friend of mine recently upgraded to 2.6.0-test1 and noticed that
mga_vid.c does not compile, so I took the opportunity, and added a set
of #ifdefs to make it work. I tried to make sure it also continues to
compile with 2.4. However, since I only have 2.6.0-test1-mm1 handy, I
couldn't test it. Oh, and some of the changes (like struct
*pci_dev->name => struct *pci_dev->dev.name) probably appeared earlier
than 2.6.0, but I didn't follow lkml _that_ closely, YMMV. If it
compiles, good, if not, and using an older linux 2.5, try adjusting
the KERNEL_VERSION(2,6,0) stuff.

Anyway, a patch for drivers/mga_vid.c is included below, and I also
attach the Makefile I used to build it (uses the nifty new kbuild
thingy).

-- 
Gergely Nagy

--- drivers/mga_vid.c.orig	2003-07-20 16:32:50.000000000 +0200
+++ drivers/mga_vid.c	2003-07-20 16:23:58.000000000 +0200
@@ -148,7 +148,8 @@
 }
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,5)
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,5)) && \
+    (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
 static long simple_strtol(const char *cp,char **endp,unsigned int base)
 {
         if(*cp=='-')
@@ -287,7 +288,7 @@
 
 static mga_vid_config_t mga_config; 
 
-#ifdef CONFIG_DEVFS_FS
+#if defined(CONFIG_DEVFS_FS) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 static devfs_handle_t dev_handle = NULL;
 #endif
 
@@ -1307,6 +1308,11 @@
 	return 0;
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define PCI_DEV_NAME(d) (d)->name
+#else
+#define PCI_DEV_NAME(d) (d)->dev.name
+#endif
 
 static int mga_vid_find_card(void)
 {
@@ -1338,7 +1344,7 @@
 			break;
 		default:
 			num_found--;
-			printk(KERN_INFO "mga_vid: ignoring matrox device (%d) at %s [%s]\n", dev->device, dev->slot_name, dev->name);
+			printk(KERN_INFO "mga_vid: ignoring matrox device (%d) at %s [%s]\n", dev->device, dev->slot_name, PCI_DEV_NAME(dev));
 			break;
 		}
 		if(num_found == mga_number+1)
@@ -1353,7 +1359,7 @@
 			printk(KERN_ERR "mga_vid: Only %d supported cards found\n", num_found);
 		return FALSE;   
 	}
-	printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name);
+	printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, PCI_DEV_NAME(dev));
 
 	pci_dev = dev;
 
@@ -1549,7 +1555,9 @@
 	mga_vid_write_regs(1);
 	mga_vid_in_use = 0;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 	MOD_DEC_USE_COUNT;
+#endif
 	return 0;
 }
 
@@ -1573,7 +1581,9 @@
 		return(-EBUSY);
 
 	mga_vid_in_use = 1;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 	MOD_INC_USE_COUNT;
+#endif
 	return(0);
 }
 
@@ -1622,7 +1632,7 @@
 			return -EINVAL;
 		}
 	}
-#ifdef CONFIG_DEVFS_FS
+
 /*
 from 2.4.17/2.4.18 linux/devfs_fs_kernel.h:
 extern devfs_handle_t devfs_register (devfs_handle_t dir, const char *name,
@@ -1630,6 +1640,7 @@
 				      unsigned int major, unsigned int minor,
 				      umode_t mode, void *ops, void *info);
 */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION (2,6,0)) && defined (CONFIG_DEVFS_FS)
 	if ((dev_handle = devfs_register(
 					NULL,
 					"mga_vid", DEVFS_FL_NONE,
@@ -1640,18 +1651,34 @@
 		printk(KERN_ERR "mga_vid: unable to get major: %d (devfs) => fallback to non-devfs mode\n", major);
 //		return -EIO;
 	}
-#endif		
+#endif
+
 	if(register_chrdev(major, "mga_vid", &mga_vid_fops))
 	{
 		printk(KERN_ERR "mga_vid: unable to get major: %d\n", major);
 		return -EIO;
 	}
 
+#if defined(CONFIG_DEVFS_FS) && (LINUX_VERSION_CODE < KERNEL_VERSION (2,6,0))
+	if (devfs_mk_cdev (MKDEV (major, 0), 
+			   S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
+			   "mga_vid"))
+	{
+		printk(KERN_ERR "mga_vid: unable to register major: %d (devfs)\n", major);
+//		return -EIO;
+	}
+	
+#endif
+
 	if (!mga_vid_find_card())
 	{
 		printk(KERN_ERR "mga_vid: no supported devices found\n");
 #ifdef CONFIG_DEVFS_FS
+#if (LINUX_VERSION_CODE < KERNEL_VERSION (2,6,0))
 		if(dev_handle) devfs_unregister(dev_handle);
+#else
+		devfs_remove ("mga_vid");
+#endif
 #endif
 		unregister_chrdev(major, "mga_vid");
 		return -EINVAL;
@@ -1683,7 +1710,11 @@
 	//FIXME turn off BES
 	printk(KERN_INFO "mga_vid: Cleaning up module\n");
 #ifdef CONFIG_DEVFS_FS
+#if (LINUX_VERSION_CODE) < KERNEL_VERSION (2,6,0)
 	if(dev_handle) devfs_unregister(dev_handle);
+#else
+	devfs_remove ("mga_vid");
+#endif
 #endif
 	unregister_chrdev(major, "mga_vid");
 }




----- End forwarded message -----

-- 
Mark Szabo
mw3 at bsd.hu



More information about the MPlayer-dev-eng mailing list