-
-
-
-#if __HAVE_DMA_IRQ
-
-/**
- * Install IRQ handler.
- *
- * \param dev DRM device.
- * \param irq IRQ number.
- *
- * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver
- * \c DRM(driver_irq_preinstall)() and \c DRM(driver_irq_postinstall)() functions
- * before and after the installation.
- */
-int DRM(irq_install)( drm_device_t *dev, int irq )
-{
- int ret;
-
- if ( !irq )
- return -EINVAL;
-
- down( &dev->struct_sem );
-
- /* Driver must have been initialized */
- if ( !dev->dev_private ) {
- up( &dev->struct_sem );
- return -EINVAL;
- }
-
- if ( dev->irq ) {
- up( &dev->struct_sem );
- return -EBUSY;
- }
- dev->irq = irq;
- up( &dev->struct_sem );
-
- DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
- dev->context_flag = 0;
- dev->interrupt_flag = 0;
- dev->dma_flag = 0;
-
- dev->dma->next_buffer = NULL;
- dev->dma->next_queue = NULL;
- dev->dma->this_buffer = NULL;
-
-#if __HAVE_DMA_IRQ_BH
- INIT_WORK(&dev->work, DRM(dma_immediate_bh), dev);
-#endif
-
-#if __HAVE_VBL_IRQ
- init_waitqueue_head(&dev->vbl_queue);
-
- spin_lock_init( &dev->vbl_lock );
-
- INIT_LIST_HEAD( &dev->vbl_sigs.head );
-
- dev->vbl_pending = 0;
-#endif
-
- /* Before installing handler */
- DRM(driver_irq_preinstall)(dev);
-
- /* Install handler */
- ret = request_irq( dev->irq, DRM(dma_service),
- DRM_IRQ_TYPE, dev->devname, dev );
- if ( ret < 0 ) {
- down( &dev->struct_sem );
- dev->irq = 0;
- up( &dev->struct_sem );
- return ret;
- }
-
- /* After installing handler */
- DRM(driver_irq_postinstall)(dev);
-
- return 0;
-}
-
-/**
- * Uninstall the IRQ handler.
- *
- * \param dev DRM device.
- *
- * Calls the driver's \c DRM(driver_irq_uninstall)() function, and stops the irq.
- */
-int DRM(irq_uninstall)( drm_device_t *dev )
-{
- int irq;
-
- down( &dev->struct_sem );
- irq = dev->irq;
- dev->irq = 0;
- up( &dev->struct_sem );
-
- if ( !irq )
- return -EINVAL;
-
- DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
- DRM(driver_irq_uninstall)( dev );
-
- free_irq( irq, dev );
-
- return 0;
-}
-
-/**
- * IRQ control ioctl.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_control structure.
- * \return zero on success or a negative number on failure.
- *
- * Calls irq_install() or irq_uninstall() according to \p arg.
- */
-int DRM(control)( struct inode *inode, struct file *filp,
- unsigned int cmd, unsigned long arg )
-{
- drm_file_t *priv = filp->private_data;
- drm_device_t *dev = priv->dev;
- drm_control_t ctl;
-
- if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) )
- return -EFAULT;
-
- switch ( ctl.func ) {
- case DRM_INST_HANDLER:
- return DRM(irq_install)( dev, ctl.irq );
- case DRM_UNINST_HANDLER:
- return DRM(irq_uninstall)( dev );
- default:
- return -EINVAL;
- }
-}
-
-#if __HAVE_VBL_IRQ
-
-/**
- * Wait for VBLANK.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param data user argument, pointing to a drm_wait_vblank structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the IRQ is installed.
- *
- * If a signal is requested checks if this task has already scheduled the same signal
- * for the same vblank sequence number - nothing to be done in
- * that case. If the number of tasks waiting for the interrupt exceeds 100 the
- * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this
- * task.
- *
- * If a signal is not requested, then calls vblank_wait().