implement device_class to auto create /dev/3dfx

This commit is contained in:
2026-03-20 20:42:31 +01:00
parent df592b464f
commit 759ac19aff

View File

@@ -79,6 +79,13 @@
#else
#define HAVE_DEVFS 0
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
#include <linux/device.h>
#include <linux/err.h>
#define HAVE_CLASS_DEVICE 1
#else
#define HAVE_CLASS_DEVICE 0
#endif
#include <asm/segment.h>
#include <asm/ioctl.h>
#include <asm/io.h>
@@ -256,6 +263,10 @@ static int numCards = 0;
static devfs_handle_t devfs_handle;
#endif
#endif
#if HAVE_CLASS_DEVICE
static struct class *class_3dfx = NULL;
static struct device *device_3dfx = NULL;
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
static void findCardType(int vendor, int device)
@@ -833,6 +844,44 @@ static struct pci_driver driver_3dfx = {
};
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
#if HAVE_CLASS_DEVICE
static int create_device_3dfx(void)
{
class_3dfx = class_create(THIS_MODULE, "3dfx");
if (IS_ERR(class_3dfx)) {
int ret = PTR_ERR(class_3dfx);
class_3dfx = NULL;
printk("3dfx: class_create() failed, returned %d\n", ret);
return ret;
}
device_3dfx = device_create(class_3dfx, NULL,
MKDEV(MAJOR_3DFX, DEVICE_VOODOO),
NULL, "3dfx");
if (IS_ERR(device_3dfx)) {
int ret = PTR_ERR(device_3dfx);
device_3dfx = NULL;
class_destroy(class_3dfx);
class_3dfx = NULL;
printk("3dfx: device_create() failed, returned %d\n", ret);
return ret;
}
return 0;
}
static void destroy_device_3dfx(void)
{
if (device_3dfx)
device_destroy(class_3dfx, MKDEV(MAJOR_3DFX, DEVICE_VOODOO));
if (class_3dfx)
class_destroy(class_3dfx);
device_3dfx = NULL;
class_3dfx = NULL;
}
#endif
#ifdef MODULE
int init_module(void)
{
@@ -856,12 +905,23 @@ int init_module(void)
S_IFCHR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP,
&fops_3dfx, NULL);
#endif
#endif
#if HAVE_CLASS_DEVICE
ret = create_device_3dfx();
if (ret < 0) {
unregister_chrdev(MAJOR_3DFX, "3dfx");
return ret;
}
#endif
DEBUGMSG(("3dfx: Successfully registered device 3dfx\n"));
ret = findCards();
if (ret < 0) {
printk("3dfx: findCards() failed, returned %d\n", ret);
#if HAVE_CLASS_DEVICE
destroy_device_3dfx();
#endif
unregister_chrdev(MAJOR_3DFX, "3dfx");
return ret;
}
@@ -893,7 +953,9 @@ void cleanup_module(void)
devfs_unregister(devfs_handle);
#endif
#endif
#if HAVE_CLASS_DEVICE
destroy_device_3dfx();
#endif
unregister_chrdev(MAJOR_3DFX, "3dfx");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)