mach64_irq.c revision 152909
1/* mach64_irq.c -- IRQ handling for ATI Mach64 -*- linux-c -*- 2 * Created: Tue Feb 25, 2003 by Leif Delgass, based on radeon_irq.c/r128_irq.c 3 */ 4/*- 5 * Copyright (C) The Weather Channel, Inc. 2002. 6 * Copyright 2003 Leif Delgass 7 * All Rights Reserved. 8 * 9 * The Weather Channel (TM) funded Tungsten Graphics to develop the 10 * initial release of the Radeon 8500 driver under the XFree86 license. 11 * This notice must be preserved. 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining a 14 * copy of this software and associated documentation files (the "Software"), 15 * to deal in the Software without restriction, including without limitation 16 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 * and/or sell copies of the Software, and to permit persons to whom the 18 * Software is furnished to do so, subject to the following conditions: 19 * 20 * The above copyright notice and this permission notice (including the next 21 * paragraph) shall be included in all copies or substantial portions of the 22 * Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 27 * THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 30 * DEALINGS IN THE SOFTWARE. 31 * 32 * Authors: 33 * Keith Whitwell <keith@tungstengraphics.com> 34 * Eric Anholt <anholt@FreeBSD.org> 35 * Leif Delgass <ldelgass@retinalburn.net> 36 */ 37 38#include <sys/cdefs.h> 39__FBSDID("$FreeBSD: head/sys/dev/drm/mach64_irq.c 152909 2005-11-28 23:13:57Z anholt $"); 40 41#include "dev/drm/drmP.h" 42#include "dev/drm/drm.h" 43#include "dev/drm/mach64_drm.h" 44#include "dev/drm/mach64_drv.h" 45 46irqreturn_t mach64_driver_irq_handler(DRM_IRQ_ARGS) 47{ 48 drm_device_t *dev = (drm_device_t *) arg; 49 drm_mach64_private_t *dev_priv = 50 (drm_mach64_private_t *) dev->dev_private; 51 int status; 52 53 status = MACH64_READ(MACH64_CRTC_INT_CNTL); 54 55 /* VBLANK interrupt */ 56 if (status & MACH64_CRTC_VBLANK_INT) { 57 /* Mask off all interrupt ack bits before setting the ack bit, since 58 * there may be other handlers outside the DRM. 59 * 60 * NOTE: On mach64, you need to keep the enable bits set when doing 61 * the ack, despite what the docs say about not acking and enabling 62 * in a single write. 63 */ 64 MACH64_WRITE(MACH64_CRTC_INT_CNTL, 65 (status & ~MACH64_CRTC_INT_ACKS) 66 | MACH64_CRTC_VBLANK_INT); 67 68 atomic_inc(&dev->vbl_received); 69 DRM_WAKEUP(&dev->vbl_queue); 70 drm_vbl_send_signals(dev); 71 return IRQ_HANDLED; 72 } 73 return IRQ_NONE; 74} 75 76int mach64_driver_vblank_wait(drm_device_t * dev, unsigned int *sequence) 77{ 78 unsigned int cur_vblank; 79 int ret = 0; 80 81 /* Assume that the user has missed the current sequence number 82 * by about a day rather than she wants to wait for years 83 * using vertical blanks... 84 */ 85 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ, 86 (((cur_vblank = atomic_read(&dev->vbl_received)) 87 - *sequence) <= (1 << 23))); 88 89 *sequence = cur_vblank; 90 91 return ret; 92} 93 94/* drm_dma.h hooks 95*/ 96void mach64_driver_irq_preinstall(drm_device_t * dev) 97{ 98 drm_mach64_private_t *dev_priv = 99 (drm_mach64_private_t *) dev->dev_private; 100 101 u32 status = MACH64_READ(MACH64_CRTC_INT_CNTL); 102 103 DRM_DEBUG("before install CRTC_INT_CTNL: 0x%08x\n", status); 104 105 /* Disable and clear VBLANK interrupt */ 106 MACH64_WRITE(MACH64_CRTC_INT_CNTL, (status & ~MACH64_CRTC_VBLANK_INT_EN) 107 | MACH64_CRTC_VBLANK_INT); 108} 109 110void mach64_driver_irq_postinstall(drm_device_t * dev) 111{ 112 drm_mach64_private_t *dev_priv = 113 (drm_mach64_private_t *) dev->dev_private; 114 115 /* Turn on VBLANK interrupt */ 116 MACH64_WRITE(MACH64_CRTC_INT_CNTL, MACH64_READ(MACH64_CRTC_INT_CNTL) 117 | MACH64_CRTC_VBLANK_INT_EN); 118 119 DRM_DEBUG("after install CRTC_INT_CTNL: 0x%08x\n", 120 MACH64_READ(MACH64_CRTC_INT_CNTL)); 121 122} 123 124void mach64_driver_irq_uninstall(drm_device_t * dev) 125{ 126 drm_mach64_private_t *dev_priv = 127 (drm_mach64_private_t *) dev->dev_private; 128 if (!dev_priv) 129 return; 130 131 /* Disable and clear VBLANK interrupt */ 132 MACH64_WRITE(MACH64_CRTC_INT_CNTL, 133 (MACH64_READ(MACH64_CRTC_INT_CNTL) & 134 ~MACH64_CRTC_VBLANK_INT_EN) 135 | MACH64_CRTC_VBLANK_INT); 136 137 DRM_DEBUG("after uninstall CRTC_INT_CTNL: 0x%08x\n", 138 MACH64_READ(MACH64_CRTC_INT_CNTL)); 139} 140