Skip to content

Commit

Permalink
drm: rename driver hooks more understandably
Browse files Browse the repository at this point in the history
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: Dave Airlie <airlied@linux.ie>
  • Loading branch information
Dave Airlie authored and Dave Airlie committed Nov 10, 2005
1 parent 3b44f13 commit 22eae94
Show file tree
Hide file tree
Showing 30 changed files with 330 additions and 484 deletions.
31 changes: 19 additions & 12 deletions drivers/char/drm/drmP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
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;
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 16 additions & 13 deletions drivers/char/drm/drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -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);
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 16 additions & 19 deletions drivers/char/drm/drm_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 4 additions & 8 deletions drivers/char/drm/drm_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions drivers/char/drm/drm_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -258,11 +258,10 @@ 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;

Expand Down
18 changes: 15 additions & 3 deletions drivers/char/drm/i810_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,12 +1319,24 @@ static int i810_flip_bufs(struct inode *inode, struct file *filp,
return 0;
}

void i810_driver_pretakedown(drm_device_t * dev)
int i810_driver_load(drm_device_t *dev, unsigned long flags)
{
/* i810 has 4 more counters */
dev->counters += 4;
dev->types[6] = _DRM_STAT_IRQ;
dev->types[7] = _DRM_STAT_PRIMARY;
dev->types[8] = _DRM_STAT_SECONDARY;
dev->types[9] = _DRM_STAT_DMA;

return 0;
}

void i810_driver_lastclose(drm_device_t * dev)
{
i810_dma_cleanup(dev);
}

void i810_driver_prerelease(drm_device_t * dev, DRMFILE filp)
void i810_driver_preclose(drm_device_t * dev, DRMFILE filp)
{
if (dev->dev_private) {
drm_i810_private_t *dev_priv = dev->dev_private;
Expand All @@ -1334,7 +1346,7 @@ void i810_driver_prerelease(drm_device_t * dev, DRMFILE filp)
}
}

void i810_driver_release(drm_device_t * dev, struct file *filp)
void i810_driver_reclaim_buffers_locked(drm_device_t * dev, struct file *filp)
{
i810_reclaim_buffers(dev, filp);
}
Expand Down
Loading

0 comments on commit 22eae94

Please sign in to comment.