Index: 3dfx_driver.c
===================================================================
--- 3dfx_driver.c	(revision 1)
+++ 3dfx_driver.c	(working copy)
@@ -21,6 +21,12 @@
 
    ChangeLog
 
+   2004-02-13	Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
+
+   * Use kernel build system
+   * Use new pci probe present in 2.6.x kernels
+   * Use module auto-loading
+
    2004-01-22   Guillem Jover   <guillem@debian.org>
 
    * Ported to 2.6 kernels.
@@ -203,6 +209,14 @@
 #define PCI_DEVICE_ID_3DFX_VOODOO4 9
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+static char name_3dfx[] = "3dfx";
+
+#define pcibios_read_config_byte(x,y,z,w) pci_read_config_byte(y,z,w)
+#define pcibios_read_config_word(x,y,z,w) pci_read_config_word(y,z,w)
+#define pcibios_read_config_dword(x,y,z,w) pci_read_config_dword(y,z,w)
+#define pcibios_write_config_dword(x,y,z,w) pci_write_config_dword(y,z,w)
+#else	/* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) */
 static struct pci_card {
 	unsigned short	vendor;
 	unsigned short	device;
@@ -214,6 +228,7 @@
 	{PCI_VENDOR_ID_3DFX, 		PCI_DEVICE_ID_3DFX_VOODOO3},
 	{PCI_VENDOR_ID_3DFX, 		PCI_DEVICE_ID_3DFX_VOODOO4}
 };
+#endif	/* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) */
 
 #ifdef DEBUG
 #define DEBUGMSG(x) printk x
@@ -251,7 +266,11 @@
   	int addr1;
 	int addr2;
 	unsigned char bus;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+	struct pci_dev	*dev;
+#else
 	unsigned char dev;
+#endif
 	struct file *curFile;
 #ifdef HAVE_MTRR
 	int mtrr_buf;
@@ -274,6 +293,7 @@
 static devfs_handle_t devfs_handle;
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 static void findCardType(int vendor, int device)
 {
 	struct pci_dev *dev = NULL;
@@ -307,6 +327,7 @@
 		findCardType(pci_card_list[i].vendor, pci_card_list[i].device);
 	return numCards;
 }
+#endif
 
 static int open_3dfx(struct inode *inode, struct file *file)
 {
@@ -796,6 +817,62 @@
 	release:		release_3dfx,		/* release */
 };
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+static int probe_3dfx(struct pci_dev *dev, const struct pci_device_id *id)
+{
+	pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &cards[numCards].addr0);
+	pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, &cards[numCards].addr1);
+	pci_read_config_dword(dev, PCI_BASE_ADDRESS_2, &cards[numCards].addr2);
+	cards[numCards].addr0 &= ~0xF;
+	cards[numCards].addr1 &= ~0xF;
+	cards[numCards].dev = dev;
+	cards[numCards].vendor = dev->vendor;
+	cards[numCards].type = dev->device;
+	cards[numCards].curFile = 0;
+
+
+	DEBUGMSG(("3dfx: board vendor %d type %d located at %x/%x\n",
+		    dev->vendor, dev->device, cards[numCards].addr0,
+		    cards[numCards].addr1));
+	numCards++;
+
+	return 0;
+}
+
+static void remove_3dfx(struct pci_dev *dev)
+{
+
+}
+
+static struct pci_device_id id_table_3dfx[] = {
+	{PCI_VENDOR_ID_3DFX,		PCI_DEVICE_ID_3DFX_VOODOO,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_3DFX, 		PCI_DEVICE_ID_3DFX_VOODOO2,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_ALLIANCE, 	PCI_DEVICE_ID_ALLIANCE_AT3D,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_3DFX, 		PCI_DEVICE_ID_3DFX_BANSHEE,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_3DFX, 		PCI_DEVICE_ID_3DFX_VOODOO3,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_3DFX, 		PCI_DEVICE_ID_3DFX_VOODOO4,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+};
+MODULE_DEVICE_TABLE(pci, id_table_3dfx);
+
+static struct pci_driver driver_3dfx = {
+	.name =		name_3dfx,
+	.id_table =	id_table_3dfx,
+	.probe =	probe_3dfx,
+	.remove =	remove_3dfx,
+};
+
+static void findCards(void)
+{
+	pci_register_driver(&driver_3dfx);
+}
+#endif	/* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
+
 #ifdef MODULE
 int init_module(void)
 {
@@ -854,6 +931,10 @@
 	  DEBUGMSG(("3dfx: unregister_chrdev failed\n"));
 	  return;
 	}
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+	pci_unregister_driver(&driver_3dfx);
+#endif
 }
 #else /* !MODULE */
 
Index: Makefile
===================================================================
--- Makefile	(revision 1)
+++ Makefile	(working copy)
@@ -1,131 +0,0 @@
-###############################################################################
-# Makefile by Carlo Wood (and others)
-
-# Determine the machine type
-ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
-
-# Setup machine dependant compiler flags
-ifeq ($(ARCH), i386)
-CFLAGS ?= -O2 -mcpu=pentium -fomit-frame-pointer -fno-strength-reduce \
-          -falign-loops=2 -falign-jumps=2 -falign-functions=2
-endif
-
-ifeq ($(ARCH), alpha)
-CFLAGS ?= -O2 -mno-fp-regs -mcpu=ev4 -ffixed-8 -Wa,-mev6 \
-          -fomit-frame-pointer -fno-strict-aliasing
-endif
-
-KSRC ?= /usr/src/linux
-KHEADERS ?= $(KSRC)/include
-KVERS ?= $(shell ./kinfo --UTS)
-MODULES_DIR = $(DESTDIR)/lib/modules/$(KVERS)
-
-ALL_CFLAGS := -DMODULE -D__KERNEL__ \
-              -I$(KHEADERS) -I$(KHEADERS)/asm/mach-default \
-              $(CFLAGS)
-
-###############################################################################
-# You should never need to change anything below.
-
-all: sanity module
-
-# Sanity checks
-sanity:
-	@( \
-	if [ ! -r $(KHEADERS)/linux ]; then \
-		echo "Expect readable headers in $(KHEADERS)/linux"; \
-		exit -1; \
-	fi; \
-	if [ ! -r $(KHEADERS)/linux/version.h ]; then \
-		echo "Missing $(KHEADERS)/linux/version.h"; \
-		echo "Configure and install the kernel first"; \
-		exit -1; \
-	fi; \
-	if [ ! -e /proc/cpuinfo ]; then \
-		echo "You need the /proc file system"; \
-		echo "Reconfigure kernel and say Yes to CONFIG_PROC_FS"; \
-		exit -1; \
-	fi; \
-	)
-
-config: kinfo
-	@( \
-	KVER_MAJOR=`echo $(KVERS) | cut -d. -f1`; \
-	KVER_MINOR=`echo $(KVERS) | cut -d. -f2`; \
-	if [ "$$KVER_MAJOR" = 2 -a "$$KVER_MINOR" -ge 6 ]; then \
-	  echo MODULE_TDFX = 3dfx.ko; \
-	else \
-	  echo MODULE_TDFX = 3dfx.o; \
-	fi; \
-	) > config
-	@$(MAKE) $(MAKECMDGOALS) configured-target=1
-
-kinfo: kinfo.c
-	$(CC) -I$(KHEADERS) -o kinfo kinfo.c
-
-kinfo.h: kinfo
-	@echo Generating kernel information header.
-	@./kinfo
-
-###############################################################################
-# kernel 2.1+
-
--include config
-
-ifeq ($(configured-target),0)
-module: config
-else
-module: $(MODULE_TDFX)
-endif
-
-3dfx.o 3dfx.ko: kinfo.h 3dfx_driver.c Makefile
-	$(CC) $(ALL_CFLAGS) -c -o $@ 3dfx_driver.c
-
-###############################################################################
-
-install_modules: module
-	mkdir -p $(MODULES_DIR)/misc
-	cp $(MODULE_TDFX) $(MODULES_DIR)/misc/
-
-install: install_modules
-	@( \
-	if [ -e $(MODULES_DIR)/modules.dep ]; then \
-		indep=`grep 'misc/$(MODULE_TDFX):' $(MODULES_DIR)/modules.dep`; \
-		if [ -z "$$indep" ]; then \
-			echo "$(MODULES_DIR)/misc/$(MODULE_TDFX):" >> $(MODULES_DIR)/modules.dep; \
-			echo "" >> $(MODULES_DIR)/modules.dep; \
-		fi; \
-	fi; \
-	if [ ! -e $(DESTDIR)/dev/.devfsd -a ! -c $(DESTDIR)/dev/3dfx ]; then \
-		mknod $(DESTDIR)/dev/3dfx c 107 0; \
-		chmod go+w $(DESTDIR)/dev/3dfx; \
-	fi; \
-	if [ "$(RPM_INSTALL)" = "1" ]; then \
-		echo "$(MODULES_DIR)/misc/$(MODULE_TDFX)"; \
-	else \
-		inconf=`grep 'alias char-major-107 3dfx' $(DESTDIR)/etc/modules.conf`; \
-		if [ -z "$$inconf" ]; then \
-			echo "alias char-major-107 3dfx" >> $(DESTDIR)/etc/modules.conf; \
-		fi; \
-	fi; \
-	)
-
-###############################################################################
-# This is for debugging purposes by the developers:
-
-clean:
-	rm -f *.o *.ko *.s
-	rm -f kinfo kinfo.h
-	rm -f config
-
-3dfx.s: 3dfx_driver.c Makefile
-	$(CC) $(ALL_CFLAGS) -S -c 3dfx_driver.c
-
-tar:
-	tar czf ../../SOURCES/Dev3Dfx-2.5.tar.gz 3dfx_driver.c Makefile
-
-debug:
-	$(MAKE) CFLAGS="-g -Wall -Wstrict-prototypes -DDEBUG"
-
-.PHONY: all sanity module install_modules install clean tar debug
-
Index: README-2.6
===================================================================
--- README-2.6	(revision 0)
+++ README-2.6	(revision 10)
@@ -0,0 +1,9 @@
+When building this module for 2.6.x kernels, please make a symbolic
+link to Makefile.kbuild:
+	$ rm -f Makefile
+	$ ln -s Makefile.kbuild Makefile
+When building for 2.4.x or earlier kernels, please make a symbolic
+link to Makefile.standard:
+	$ rm -f Makefile
+	$ ln -s Makefile.standard Makefile
+
Index: Makefile.kbuild
===================================================================
--- Makefile.kbuild	(revision 0)
+++ Makefile.kbuild	(revision 10)
@@ -0,0 +1,12 @@
+MAKE=make
+CC=gcc
+KSRC=/usr/src/linux
+
+obj-m += 3dfx_driver.o
+
+all:
+	$(MAKE) -C $(KSRC) CC=$(CC) SUBDIRS=$(shell pwd);
+
+clean:
+	rm -f *.ko *.o *.mod.* .*.mod.* .*.cmd
+
Index: Makefile.standard
===================================================================
--- Makefile.standard	(revision 0)
+++ Makefile.standard	(revision 10)
@@ -0,0 +1,125 @@
+###############################################################################
+# Makefile by Carlo Wood (and others)
+
+# Determine the machine type
+ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
+
+# Setup machine dependant compiler flags
+ifeq ($(ARCH), i386)
+CFLAGS ?= -O2 -mcpu=pentium -fomit-frame-pointer -fno-strength-reduce \
+          -falign-loops=2 -falign-jumps=2 -falign-functions=2
+endif
+
+ifeq ($(ARCH), alpha)
+CFLAGS ?= -O2 -mno-fp-regs -mcpu=ev4 -ffixed-8 -Wa,-mev6 \
+          -fomit-frame-pointer -fno-strict-aliasing
+endif
+
+KSRC ?= /usr/src/linux
+KHEADERS ?= $(KSRC)/include
+KVERS ?= $(shell ./kinfo --UTS)
+MODULES_DIR = $(DESTDIR)/lib/modules/$(KVERS)
+
+ALL_CFLAGS := -DMODULE -D__KERNEL__ \
+              -I$(KHEADERS) -I$(KHEADERS)/asm/mach-default \
+              $(CFLAGS)
+
+###############################################################################
+# You should never need to change anything below.
+
+all: sanity module
+
+# Sanity checks
+sanity:
+	@( \
+	if [ ! -r $(KHEADERS)/linux ]; then \
+		echo "Expect readable headers in $(KHEADERS)/linux"; \
+		exit -1; \
+	fi; \
+	if [ ! -r $(KHEADERS)/linux/version.h ]; then \
+		echo "Missing $(KHEADERS)/linux/version.h"; \
+		echo "Configure and install the kernel first"; \
+		exit -1; \
+	fi; \
+	if [ ! -e /proc/cpuinfo ]; then \
+		echo "You need the /proc file system"; \
+		echo "Reconfigure kernel and say Yes to CONFIG_PROC_FS"; \
+		exit -1; \
+	fi; \
+	)
+
+config: kinfo
+	@( \
+	echo MODULE_TDFX = 3dfx.o; \
+	) > config
+	@$(MAKE) $(MAKECMDGOALS) configured-target=1
+
+kinfo: kinfo.c
+	$(CC) -I$(KHEADERS) -o kinfo kinfo.c
+
+kinfo.h: kinfo
+	@echo Generating kernel information header.
+	@./kinfo
+
+###############################################################################
+# kernel 2.1+
+
+-include config
+
+ifeq ($(configured-target),0)
+module: config
+else
+module: $(MODULE_TDFX)
+endif
+
+3dfx.o: kinfo.h 3dfx_driver.c Makefile
+	$(CC) $(ALL_CFLAGS) -c -o $@ 3dfx_driver.c
+
+###############################################################################
+
+install_modules: module
+	mkdir -p $(MODULES_DIR)/misc
+	cp $(MODULE_TDFX) $(MODULES_DIR)/misc/
+
+install: install_modules
+	@( \
+	if [ -e $(MODULES_DIR)/modules.dep ]; then \
+		indep=`grep 'misc/$(MODULE_TDFX):' $(MODULES_DIR)/modules.dep`; \
+		if [ -z "$$indep" ]; then \
+			echo "$(MODULES_DIR)/misc/$(MODULE_TDFX):" >> $(MODULES_DIR)/modules.dep; \
+			echo "" >> $(MODULES_DIR)/modules.dep; \
+		fi; \
+	fi; \
+	if [ ! -e $(DESTDIR)/dev/.devfsd -a ! -c $(DESTDIR)/dev/3dfx ]; then \
+		mknod $(DESTDIR)/dev/3dfx c 107 0; \
+		chmod go+w $(DESTDIR)/dev/3dfx; \
+	fi; \
+	if [ "$(RPM_INSTALL)" = "1" ]; then \
+		echo "$(MODULES_DIR)/misc/$(MODULE_TDFX)"; \
+	else \
+		inconf=`grep 'alias char-major-107 3dfx' $(DESTDIR)/etc/modules.conf`; \
+		if [ -z "$$inconf" ]; then \
+			echo "alias char-major-107 3dfx" >> $(DESTDIR)/etc/modules.conf; \
+		fi; \
+	fi; \
+	)
+
+###############################################################################
+# This is for debugging purposes by the developers:
+
+clean:
+	rm -f *.o *.ko *.s
+	rm -f kinfo kinfo.h
+	rm -f config
+
+3dfx.s: 3dfx_driver.c Makefile
+	$(CC) $(ALL_CFLAGS) -S -c 3dfx_driver.c
+
+tar:
+	tar czf ../../SOURCES/Dev3Dfx-2.5.tar.gz 3dfx_driver.c Makefile
+
+debug:
+	$(MAKE) CFLAGS="-g -Wall -Wstrict-prototypes -DDEBUG"
+
+.PHONY: all sanity module install_modules install clean tar debug
+
