Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 22eae947 authored by Dave Airlie's avatar Dave Airlie Committed by Dave Airlie
Browse files

drm: rename driver hooks more understandably



Rename the driver hooks in the DRM to something a little more understandable:
preinit         ->      load
postinit        ->      (removed)
presetup        ->      firstopen
postsetup       ->      (removed)
open_helper     ->      open
prerelease      ->      preclose
free_filp_priv  ->      postclose
pretakedown     ->      lastclose
postcleanup     ->      unload
release         ->      reclaim_buffers_locked
version         ->      (removed)

postinit and version were replaced with generic code in the Linux DRM (drivers
now set their version numbers and description in the driver structure, like on
BSD).  postsetup wasn't used at all.  Fixes the savage hooks for
initializing and tearing down mappings at the right times.  Testing involved at
least starting X, running glxgears, killing glxgears, exiting X, and repeating.

Tested on:      FreeBSD (g200, g400, r200, r128)
                Linux (r200, savage4)

From: Eric Anholt <anholt@freebsd.org>
Signed-off-by: default avatarDave Airlie <airlied@linux.ie>
parent 3b44f137
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -544,16 +544,14 @@ typedef struct ati_pcigart_info {
struct drm_device;

struct drm_driver {
	int (*preinit) (struct drm_device *, unsigned long flags);
	void (*prerelease) (struct drm_device *, struct file * filp);
	void (*pretakedown) (struct drm_device *);
	int (*postcleanup) (struct drm_device *);
	int (*presetup) (struct drm_device *);
	int (*postsetup) (struct drm_device *);
	int (*load) (struct drm_device *, unsigned long flags);
	int (*firstopen) (struct drm_device *);
	int (*open) (struct drm_device *, drm_file_t *);
	void (*preclose) (struct drm_device *, struct file * filp);
	void (*postclose) (struct drm_device *, drm_file_t *);
	void (*lastclose) (struct drm_device *);
	int (*unload) (struct drm_device *);
	int (*dma_ioctl) (DRM_IOCTL_ARGS);
	int (*open_helper) (struct drm_device *, drm_file_t *);
	void (*free_filp_priv) (struct drm_device *, drm_file_t *);
	void (*release) (struct drm_device *, struct file * filp);
	void (*dma_ready) (struct drm_device *);
	int (*dma_quiescent) (struct drm_device *);
	int (*context_ctor) (struct drm_device * dev, int context);
@@ -579,16 +577,25 @@ struct drm_driver {

	/* these have to be filled in */

	int (*postinit) (struct drm_device *, unsigned long flags);
	irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
	void (*irq_preinstall) (struct drm_device * dev);
	void (*irq_postinstall) (struct drm_device * dev);
	void (*irq_uninstall) (struct drm_device * dev);
	void (*reclaim_buffers) (struct drm_device * dev, struct file * filp);
	void (*reclaim_buffers_locked) (struct drm_device *drv,
					struct file *filp);
	unsigned long (*get_map_ofs) (drm_map_t * map);
	unsigned long (*get_reg_ofs) (struct drm_device * dev);
	void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
	int (*version) (drm_version_t * version);

	int major;
	int minor;
	int patchlevel;
	char *name;
	char *desc;
	char *date;

	u32 driver_features;
	int dev_priv_size;
	drm_ioctl_desc_t *ioctls;
@@ -772,7 +779,7 @@ extern int drm_ioctl(struct inode *inode, struct file *filp,
		     unsigned int cmd, unsigned long arg);
extern long drm_compat_ioctl(struct file *filp,
			     unsigned int cmd, unsigned long arg);
extern int drm_takedown(drm_device_t * dev);
extern int drm_lastclose(drm_device_t *dev);

				/* Device support (drm_fops.h) */
extern int drm_open(struct inode *inode, struct file *filp);
+16 −13
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ static drm_ioctl_desc_t drm_ioctls[] = {
 *
 * \sa drm_device
 */
int drm_takedown(drm_device_t * dev)
int drm_lastclose(drm_device_t * dev)
{
	drm_magic_entry_t *pt, *next;
	drm_map_list_t *r_list;
@@ -138,9 +138,9 @@ int drm_takedown(drm_device_t * dev)

	DRM_DEBUG("\n");

	if (dev->driver->pretakedown)
		dev->driver->pretakedown(dev);
	DRM_DEBUG("driver pretakedown completed\n");
	if (dev->driver->lastclose)
		dev->driver->lastclose(dev);
	DRM_DEBUG("driver lastclose completed\n");

	if (dev->unique) {
		drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
@@ -233,7 +233,7 @@ int drm_takedown(drm_device_t * dev)
	}
	up(&dev->struct_sem);

	DRM_DEBUG("takedown completed\n");
	DRM_DEBUG("lastclose completed\n");
	return 0;
}

@@ -281,7 +281,7 @@ EXPORT_SYMBOL(drm_init);
/**
 * Called via cleanup_module() at module unload time.
 *
 * Cleans up all DRM device, calling takedown().
 * Cleans up all DRM device, calling drm_lastclose().
 *
 * \sa drm_init
 */
@@ -294,7 +294,7 @@ static void drm_cleanup(drm_device_t * dev)
		return;
	}

	drm_takedown(dev);
	drm_lastclose(dev);

	if (dev->maplist) {
		drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
@@ -317,8 +317,8 @@ static void drm_cleanup(drm_device_t * dev)
		dev->agp = NULL;
	}

	if (dev->driver->postcleanup)
		dev->driver->postcleanup(dev);
	if (dev->driver->unload)
		dev->driver->unload(dev);

	drm_put_head(&dev->primary);
	if (drm_put_dev(dev))
@@ -432,14 +432,17 @@ static int drm_version(struct inode *inode, struct file *filp,
	drm_device_t *dev = priv->head->dev;
	drm_version_t __user *argp = (void __user *)arg;
	drm_version_t version;
	int ret;
	int len;

	if (copy_from_user(&version, argp, sizeof(version)))
		return -EFAULT;

	/* version is a required function to return the personality module version */
	if ((ret = dev->driver->version(&version)))
		return ret;
	version.version_major = dev->driver->major;
	version.version_minor = dev->driver->minor;
	version.version_patchlevel = dev->driver->patchlevel;
	DRM_COPY(version.name, dev->driver->name);
	DRM_COPY(version.date, dev->driver->date);
	DRM_COPY(version.desc, dev->driver->desc);

	if (copy_to_user(argp, &version, sizeof(version)))
		return -EFAULT;
+16 −19
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ static int drm_setup(drm_device_t * dev)
	int i;
	int ret;

	if (dev->driver->presetup) {
		ret = dev->driver->presetup(dev);
	if (dev->driver->firstopen) {
		ret = dev->driver->firstopen(dev);
		if (ret != 0)
			return ret;
	}
@@ -109,8 +109,6 @@ static int drm_setup(drm_device_t * dev)
	 * drm_select_queue fails between the time the interrupt is
	 * initialized and the time the queues are initialized.
	 */
	if (dev->driver->postsetup)
		dev->driver->postsetup(dev);

	return 0;
}
@@ -167,7 +165,7 @@ EXPORT_SYMBOL(drm_open);
 * If the hardware lock is held then free it, and take it again for the kernel
 * context since it's necessary to reclaim buffers. Unlink the file private
 * data from its list and free it. Decreases the open count and if it reaches
 * zero calls takedown().
 * zero calls drm_lastclose().
 */
int drm_release(struct inode *inode, struct file *filp)
{
@@ -180,8 +178,8 @@ int drm_release(struct inode *inode, struct file *filp)

	DRM_DEBUG("open_count = %d\n", dev->open_count);

	if (dev->driver->prerelease)
		dev->driver->prerelease(dev, filp);
	if (dev->driver->preclose)
		dev->driver->preclose(dev, filp);

	/* ========================================================
	 * Begin inline drm_release
@@ -197,8 +195,8 @@ int drm_release(struct inode *inode, struct file *filp)
		DRM_DEBUG("File %p released, freeing lock for context %d\n",
			  filp, _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));

		if (dev->driver->release)
			dev->driver->release(dev, filp);
		if (dev->driver->reclaim_buffers_locked)
			dev->driver->reclaim_buffers_locked(dev, filp);

		drm_lock_free(dev, &dev->lock.hw_lock->lock,
			      _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
@@ -207,7 +205,7 @@ int drm_release(struct inode *inode, struct file *filp)
		   hardware at this point, possibly
		   processed via a callback to the X
		   server. */
	} else if (dev->driver->release && priv->lock_count
	} else if (dev->driver->reclaim_buffers_locked && priv->lock_count
		   && dev->lock.hw_lock) {
		/* The lock is required to reclaim buffers */
		DECLARE_WAITQUEUE(entry, current);
@@ -237,15 +235,14 @@ int drm_release(struct inode *inode, struct file *filp)
		__set_current_state(TASK_RUNNING);
		remove_wait_queue(&dev->lock.lock_queue, &entry);
		if (!retcode) {
			if (dev->driver->release)
				dev->driver->release(dev, filp);
			dev->driver->reclaim_buffers_locked(dev, filp);
			drm_lock_free(dev, &dev->lock.hw_lock->lock,
				      DRM_KERNEL_CONTEXT);
		}
	}

	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)
	    && !dev->driver->release) {
	if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
	    !dev->driver->reclaim_buffers_locked) {
		dev->driver->reclaim_buffers(dev, filp);
	}

@@ -292,8 +289,8 @@ int drm_release(struct inode *inode, struct file *filp)
	}
	up(&dev->struct_sem);

	if (dev->driver->free_filp_priv)
		dev->driver->free_filp_priv(dev, priv);
	if (dev->driver->postclose)
		dev->driver->postclose(dev, priv);

	drm_free(priv, sizeof(*priv), DRM_MEM_FILES);

@@ -313,7 +310,7 @@ int drm_release(struct inode *inode, struct file *filp)
		}
		spin_unlock(&dev->count_lock);
		unlock_kernel();
		return drm_takedown(dev);
		return drm_lastclose(dev);
	}
	spin_unlock(&dev->count_lock);

@@ -363,8 +360,8 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
	priv->authenticated = capable(CAP_SYS_ADMIN);
	priv->lock_count = 0;

	if (dev->driver->open_helper) {
		ret = dev->driver->open_helper(dev, priv);
	if (dev->driver->open) {
		ret = dev->driver->open(dev, priv);
		if (ret < 0)
			goto out_free;
	}
+4 −8
Original line number Diff line number Diff line
@@ -325,17 +325,13 @@ int drm_setversion(DRM_IOCTL_ARGS)
	drm_set_version_t retv;
	int if_version;
	drm_set_version_t __user *argp = (void __user *)data;
	drm_version_t version;

	DRM_COPY_FROM_USER_IOCTL(sv, argp, sizeof(sv));

	memset(&version, 0, sizeof(version));

	dev->driver->version(&version);
	retv.drm_di_major = DRM_IF_MAJOR;
	retv.drm_di_minor = DRM_IF_MINOR;
	retv.drm_dd_major = version.version_major;
	retv.drm_dd_minor = version.version_minor;
	retv.drm_dd_major = dev->driver->major;
	retv.drm_dd_minor = dev->driver->minor;

	DRM_COPY_TO_USER_IOCTL(argp, retv, sizeof(sv));

@@ -354,9 +350,9 @@ int drm_setversion(DRM_IOCTL_ARGS)
	}

	if (sv.drm_dd_major != -1) {
		if (sv.drm_dd_major != version.version_major ||
		if (sv.drm_dd_major != dev->driver->major ||
		    sv.drm_dd_minor < 0
		    || sv.drm_dd_minor > version.version_minor)
		    || sv.drm_dd_minor > dev->driver->minor)
			return EINVAL;

		if (dev->driver->set_version)
+7 −8
Original line number Diff line number Diff line
@@ -93,8 +93,8 @@ static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev,

	dev->driver = driver;

	if (dev->driver->preinit)
		if ((retcode = dev->driver->preinit(dev, ent->driver_data)))
	if (dev->driver->load)
		if ((retcode = dev->driver->load(dev, ent->driver_data)))
			goto error_out_unreg;

	if (drm_core_has_AGP(dev)) {
@@ -124,7 +124,7 @@ static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev,
	return 0;

      error_out_unreg:
	drm_takedown(dev);
	drm_lastclose(dev);
	return retcode;
}

@@ -259,10 +259,9 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
	if ((ret = drm_get_head(dev, &dev->primary)))
		goto err_g1;
	
	/* postinit is a required function to display the signon banner */
	/* drivers add secondary heads here if needed */
	if ((ret = dev->driver->postinit(dev, ent->driver_data)))
		goto err_g1;
	DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
		 driver->name, driver->major, driver->minor, driver->patchlevel,
		 driver->date, dev->primary.minor);

	return 0;

Loading