From eeb0ef1a7076e7744655954e95a65532eb4b7ebe Mon Sep 17 00:00:00 2001 From: Jon Smirl Date: Wed, 15 Sep 2004 17:44:30 +0000 Subject: Back dyn-minor patch out for now. fops handling is broken on some cards --- linux-core/drm_drv.c | 140 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 94 insertions(+), 46 deletions(-) (limited to 'linux-core/drm_drv.c') diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c index df20e2b4..bd0520e5 100644 --- a/linux-core/drm_drv.c +++ b/linux-core/drm_drv.c @@ -62,6 +62,17 @@ static void __exit drm_cleanup( drm_device_t *dev ); +/** Stub information */ +struct drm_stub_info { + int (*info_register)(const char *name, struct file_operations *fops, + drm_device_t *dev); + int (*info_unregister)(int minor); + struct class_simple *drm_class; + int *info_count; + struct proc_dir_entry *proc_root; +}; +extern struct drm_stub_info DRM(stub_info); + #ifndef MODULE /** Use an additional macro to avoid preprocessor troubles */ #define DRM_OPTIONS_FUNC DRM(options) @@ -80,6 +91,9 @@ __setup( DRIVER_NAME "=", DRM_OPTIONS_FUNC ); #undef DRM_OPTIONS_FUNC #endif +#define MAX_DEVICES 4 +drm_device_t DRM(device)[MAX_DEVICES]; +int DRM(numdevs) = 0; int DRM(fb_loaded) = 0; struct file_operations DRM(fops) = { @@ -162,6 +176,15 @@ drm_ioctl_desc_t DRM(ioctls)[] = { #define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( DRM(ioctls) ) +#ifdef MODULE +static char *drm_opts = NULL; +#endif + +MODULE_AUTHOR( DRIVER_AUTHOR ); +MODULE_DESCRIPTION( DRIVER_DESC ); +MODULE_PARM( drm_opts, "s" ); +MODULE_LICENSE("GPL and additional rights"); + static int DRM(setup)( drm_device_t *dev ) { int i; @@ -430,19 +453,37 @@ static struct pci_device_id DRM(pciidlist)[] = { DRM(PCI_IDS) }; -int DRM(fill_in_dev)(drm_device_t *dev, struct pci_dev *pdev, const struct pci_device_id *ent) +static int drm_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { + drm_device_t *dev; int retcode; + DRM_DEBUG( "\n" ); + + if (DRM(numdevs) >= MAX_DEVICES) + return -ENODEV; + + dev = &(DRM(device)[DRM(numdevs)]); + memset( (void *)dev, 0, sizeof(*dev) ); dev->count_lock = SPIN_LOCK_UNLOCKED; init_timer( &dev->timer ); sema_init( &dev->struct_sem, 1 ); sema_init( &dev->ctxlist_sem, 1 ); - dev->name = DRIVER_NAME; + dev->maplist = DRM(alloc)(sizeof(*dev->maplist), DRM_MEM_MAPS); + if(dev->maplist == NULL) + return -ENOMEM; + memset(dev->maplist, 0, sizeof(*dev->maplist)); + INIT_LIST_HEAD(&dev->maplist->head); - dev->pdev = pdev; + if (DRM(fb_loaded)==0) { + pci_set_drvdata(pdev, dev); + pci_request_regions(pdev, DRIVER_NAME); + pci_enable_device(pdev); + } + dev->name = DRIVER_NAME; + dev->pdev = pdev; #ifdef __alpha__ dev->hose = pdev->sysdata; dev->pci_domain = dev->hose->bus->number; @@ -454,10 +495,6 @@ int DRM(fill_in_dev)(drm_device_t *dev, struct pci_dev *pdev, const struct pci_d dev->pci_func = PCI_FUNC(pdev->devfn); dev->irq = pdev->irq; - dev->maplist = DRM(calloc)(1, sizeof(*dev->maplist), DRM_MEM_MAPS); - if(dev->maplist == NULL) return -ENOMEM; - INIT_LIST_HEAD(&dev->maplist->head); - /* dev_priv_size can be changed by a driver in driver_register_fns */ dev->dev_priv_size = sizeof(u32); @@ -467,14 +504,14 @@ int DRM(fill_in_dev)(drm_device_t *dev, struct pci_dev *pdev, const struct pci_d if (dev->fn_tbl.preinit) if ((retcode = dev->fn_tbl.preinit(dev, ent->driver_data))) - goto error_out_unreg; + goto error_out; if (drm_core_has_AGP(dev)) { dev->agp = DRM(agp_init)(); if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) && (dev->agp == NULL)) { DRM_ERROR( "Cannot initialize the agpgart module.\n" ); retcode = -EINVAL; - goto error_out_unreg; + goto error_out; } @@ -490,10 +527,18 @@ int DRM(fill_in_dev)(drm_device_t *dev, struct pci_dev *pdev, const struct pci_d retcode = DRM(ctxbitmap_init)( dev ); if( retcode ) { DRM_ERROR( "Cannot allocate memory for context bitmap.\n" ); - goto error_out_unreg; + goto error_out; } + if ((dev->minor = DRM(stub_register)(DRIVER_NAME, &DRM(fops),dev)) < 0) + { + retcode = -EPERM; + goto error_out; + } + dev->device = MKDEV(DRM_MAJOR, dev->minor ); + + DRM(numdevs)++; /* no errors, mark it reserved */ DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d: %s\n", DRIVER_NAME, @@ -513,7 +558,14 @@ int DRM(fill_in_dev)(drm_device_t *dev, struct pci_dev *pdev, const struct pci_d return 0; error_out_unreg: + DRM(stub_unregister)(dev->minor); DRM(takedown)(dev); + error_out: + if (DRM(fb_loaded)==0) { + pci_set_drvdata(pdev, NULL); + pci_release_regions(pdev); + pci_disable_device(pdev); + } return retcode; } @@ -522,23 +574,17 @@ static void __exit drm_cleanup_pci(struct pci_dev *pdev) drm_device_t *dev = pci_get_drvdata(pdev); pci_set_drvdata(pdev, NULL); + drm_cleanup(dev); pci_release_regions(pdev); - if (dev) - drm_cleanup(dev); } static struct pci_driver drm_driver = { .name = DRIVER_NAME, .id_table = DRM(pciidlist), - .probe = DRM(probe), + .probe = drm_probe, .remove = __devexit_p(drm_cleanup_pci), }; -#ifdef MODULE -static char *drm_opts = NULL; -#endif -MODULE_PARM( drm_opts, "s" ); - /** * Module initialization. Called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). @@ -595,7 +641,7 @@ static int __init drm_init( void ) /* pass back in pdev to account for multiple identical cards */ while ((pdev = pci_get_subsys(pid->vendor, pid->device, pid->subvendor, pid->subdevice, pdev))) { /* stealth mode requires a manual probe */ - DRM(probe)(pdev, &DRM(pciidlist[i])); + drm_probe(pdev, &DRM(pciidlist[i])); } } DRM_INFO("Used old pci detect: framebuffer loaded\n"); @@ -663,6 +709,13 @@ static void __exit drm_cleanup( drm_device_t *dev ) if (DRM(fb_loaded)==0) pci_disable_device(dev->pdev); + DRM(numdevs)--; + if ( DRM(stub_unregister)(dev->minor) ) { + DRM_ERROR( "Cannot unload module\n" ); + } else { + DRM_DEBUG( "minor %d unregistered\n", dev->minor); + } + DRM(ctxbitmap_cleanup)( dev ); if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && dev->agp && dev->agp->agp_mtrr >= 0) { @@ -680,33 +733,25 @@ static void __exit drm_cleanup( drm_device_t *dev ) } if (dev->fn_tbl.postcleanup) dev->fn_tbl.postcleanup(dev); - - if ( DRM(put_minor)(dev) ) - DRM_ERROR( "Cannot unload module\n" ); } static void __exit drm_exit (void) { - int i; - drm_device_t *dev; - drm_minor_t *minor; - DRM_DEBUG( "\n" ); - if (DRM(fb_loaded)) { - if (DRM(global)) { - for (i = 0; i < DRM(global)->cards_limit; i++) { - minor = &DRM(global)->minors[i]; - dev = minor->dev; - DRM_DEBUG("fb loaded release minor %d\n", dev->minor); - if ((minor->class == DRM_MINOR_PRIMARY) && (dev->fops == &DRM(fops))) { - /* release the pci driver */ - if (dev->pdev) - pci_dev_put(dev->pdev); - drm_cleanup(dev); - } - } + if (DRM(fb_loaded)==1) + { + int i; + drm_device_t *dev; + + for (i = DRM(numdevs) - 1; i >= 0; i--) { + dev = &(DRM(device)[i]); + /* release the pci driver */ + if (dev->pdev) + pci_dev_put(dev->pdev); + drm_cleanup(dev); } - } else + } + else pci_unregister_driver(&drm_driver); DRM_INFO( "Module unloaded\n" ); } @@ -773,15 +818,18 @@ int DRM(version)( struct inode *inode, struct file *filp, int DRM(open)( struct inode *inode, struct file *filp ) { drm_device_t *dev = NULL; - int minor = iminor(inode); int retcode = 0; + int i; - if (!((minor >= 0) && (minor < DRM(global)->cards_limit))) - return -ENODEV; - - dev = DRM(global)->minors[minor].dev; - if (!dev) + for (i = 0; i < DRM(numdevs); i++) { + if (iminor(inode) == DRM(device)[i].minor) { + dev = &(DRM(device)[i]); + break; + } + } + if (!dev) { return -ENODEV; + } retcode = DRM(open_helper)( inode, filp, dev ); if ( !retcode ) { -- cgit v1.2.3