summaryrefslogtreecommitdiff
path: root/linux-core/drm_bo.c
AgeCommit message (Expand)Author
2006-10-19Make sure delayed delete list is empty on lastclose.Thomas Hellstrom
2006-10-17Remove max number of locked pages check and call, sinceThomas Hellstrom
2006-10-17Lindent.Thomas Hellstrom
2006-10-17Add memory usage accounting to avoid DOS problems.Thomas Hellstrom
2006-10-17Implement mm_lock and mm_unlock functions.Thomas Hellstrom
2006-10-17Remove the memory manager parameter from the put_block function, as thisThomas Hellstrom
2006-10-17Extend generality for more memory types.Thomas Hellstrom
2006-10-12Bugfixes.Thomas Hellstrom
2006-10-12Simplify the AGP backend interface somewhat.Thomas Hellstrom
2006-10-11Compatibility code for 2.6.15-2.6.18. It is ugly but a little comfort is thatThomas Hellstrom
2006-10-11Big update:Thomas Hellstrom
2006-09-29Fix buffer manager takedown error.Thomas Hellstrom
2006-09-27Fix racy buffer object destruction.Thomas Hellstrom
2006-09-27Fix tt fixed size that slipped through in previous commit.Thomas Hellstrom
2006-09-27Adapt to architecture-specific hooks for gatt pages.Thomas Hellstrom
2006-09-25Add /proc filesystem buffer / fence object accounting.Thomas Hellstrom
2006-09-18Alternative implementation of page table zeroing using zap page_range.Thomas Hellstrom
2006-09-15Allow a "native type" to be associated with a fence sequence.Thomas Hellstrom
2006-09-15Some bugfixes.Thomas Hellstrom
2006-09-12Fix some debug messages.Thomas Hellstrom
2006-09-12Use lazy fence wait when possible even for RW fences. Saves some CPU.Thomas Hellstrom
2006-09-12More bugfixes.Thomas Hellstrom
2006-09-08Various bugfixes.Thomas Hellstrom
2006-09-05Fence all unfenced buffers function.Thomas Hellstrom
2006-09-04Buffer object wait IOCTL operation.Thomas Hellstrom
2006-09-04Make memory caches global so that they can be used withThomas Hellstrom
2006-09-01Lindent drm_bo.cThomas Hellstrom
2006-09-01Flag bit pattern bugfixes. Remove some error messages.Thomas Hellstrom
2006-09-01Export buffer info on map and validate ioctls.Thomas Hellstrom
2006-09-01Bugfixes,Thomas Hellstrom
2006-09-01Various bugfixes.Thomas Hellstrom
2006-08-31Validation and fencing.Thomas Hellstrom
2006-08-31Remove the buffer manager mutex. Use dev->struct_mutex instead.Thomas Hellstrom
2006-08-31More mapping synchronization.Thomas Hellstrom
2006-08-30Lindenting drm_bo.c and drm_ttm.cThomas Hellstrom
2006-08-30Buffer object binding.Thomas Hellstrom
2006-08-30Buffer eviction.Thomas Hellstrom
2006-08-30Remove the buffer object hint field and use it onlyThomas Hellstrom
2006-08-30Buffer object mapping and mapping synchronization for multiple clients.Thomas Hellstrom
2006-08-30Memory manager init and takedown.Thomas Hellstrom
2006-08-30Buffer object reply fill in.Thomas Hellstrom
2006-08-29Checkpoint commit. Buffer object flags and IOCTL argument list.Thomas Hellstrom
2006-08-29Checkpoint ttm addition to buffer objects.Thomas Hellstrom
2006-08-2964-bit IOCTL integer (Michel Dänzer & Brian Paul)Thomas Hellstrom
2006-08-28Buffer object creation.Thomas Hellstrom
2006-08-28Proper TTM dereferencingThomas Hellstrom
2006-08-28Buffer object idle and mapping synchronization.Thomas Hellstrom
2006-08-28Checkpoint buffer object IOCTL stub.Thomas Hellstrom
2006-08-27Remove the ioctl multiplexing, and instead allow for genericThomas Hellstrom
2006-08-27ttm create / destroy / ref / unref ioctl.Thomas Hellstrom
id='n392' href='#n392'>392 393 394 395 396 397 398 399 400 401 402 403
/* via_irq.c
 *
 * Copyright 2004 BEAM Ltd.
 * Copyright 2002 Tungsten Graphics, Inc.
 * Copyright 2005 Thomas Hellstrom.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BEAM LTD, TUNGSTEN GRAPHICS  AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *    Terry Barnaby <terry1@beam.ltd.uk>
 *    Keith Whitwell <keith@tungstengraphics.com>
 *    Thomas Hellstrom <unichrome@shipmail.org>
 *
 * This code provides standard DRM access to the Via Unichrome / Pro Vertical blank
 * interrupt, as well as an infrastructure to handle other interrupts of the chip.
 * The refresh rate is also calculated for video playback sync purposes.
 */

#include "drmP.h"
#include "drm.h"
#include "via_drm.h"
#include "via_drv.h"

#define VIA_REG_INTERRUPT       0x200

/* VIA_REG_INTERRUPT */
#define VIA_IRQ_GLOBAL	  (1 << 31)
#define VIA_IRQ_VBLANK_ENABLE   (1 << 19)
#define VIA_IRQ_VBLANK_PENDING  (1 << 3)
#define VIA_IRQ_HQV0_ENABLE     (1 << 11)
#define VIA_IRQ_HQV1_ENABLE     (1 << 25)
#define VIA_IRQ_HQV0_PENDING    (1 << 9)
#define VIA_IRQ_HQV1_PENDING    (1 << 10)
#define VIA_IRQ_DMA0_DD_ENABLE  (1 << 20)
#define VIA_IRQ_DMA0_TD_ENABLE  (1 << 21)
#define VIA_IRQ_DMA1_DD_ENABLE  (1 << 22)
#define VIA_IRQ_DMA1_TD_ENABLE  (1 << 23)
#define VIA_IRQ_DMA0_DD_PENDING (1 << 4)
#define VIA_IRQ_DMA0_TD_PENDING (1 << 5)
#define VIA_IRQ_DMA1_DD_PENDING (1 << 6)
#define VIA_IRQ_DMA1_TD_PENDING (1 << 7)


/*
 * Device-specific IRQs go here. This type might need to be extended with
 * the register if there are multiple IRQ control registers.
 * Currently we activate the HQV interrupts of  Unichrome Pro group A.
 */

static maskarray_t via_pro_group_a_irqs[] = {
	{VIA_IRQ_HQV0_ENABLE, VIA_IRQ_HQV0_PENDING, 0x000003D0, 0x00008010,
	 0x00000000 },
	{VIA_IRQ_HQV1_ENABLE, VIA_IRQ_HQV1_PENDING, 0x000013D0, 0x00008010,
	 0x00000000 },
	{VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0,
	 VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
	{VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1,
	 VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
};
static int via_num_pro_group_a = ARRAY_SIZE(via_pro_group_a_irqs);
static int via_irqmap_pro_group_a[] = {0, 1, -1, 2, -1, 3};

static maskarray_t via_unichrome_irqs[] = {
	{VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0,
	 VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
	{VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1,
	 VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}
};
static int via_num_unichrome = ARRAY_SIZE(via_unichrome_irqs);
static int via_irqmap_unichrome[] = {-1, -1, -1, 0, -1, 1};


static unsigned time_diff(struct timeval *now,struct timeval *then)
{
	return (now->tv_usec >= then->tv_usec) ?
		now->tv_usec - then->tv_usec :
		1000000 - (then->tv_usec - now->tv_usec);
}

u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
{
	drm_via_private_t *dev_priv = dev->dev_private;
	if (crtc != 0)
		return 0;

	return atomic_read(&dev_priv->vbl_received);
}

irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
{
	struct drm_device *dev = (struct drm_device *) arg;
	drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
	u32 status;
	int handled = 0;
	struct timeval cur_vblank;
	drm_via_irq_t *cur_irq = dev_priv->via_irqs;
	int i;

	status = VIA_READ(VIA_REG_INTERRUPT);
	if (status & VIA_IRQ_VBLANK_PENDING) {
		atomic_inc(&dev_priv->vbl_received);
		if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
#ifdef __linux__
			do_gettimeofday(&cur_vblank);
#else
			microtime(&cur_vblank);
#endif
			if (dev_priv->last_vblank_valid) {
				dev_priv->usec_per_vblank =
					time_diff(&cur_vblank,
						  &dev_priv->last_vblank) >> 4;
			}
			dev_priv->last_vblank = cur_vblank;
			dev_priv->last_vblank_valid = 1;
		}
		if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
			DRM_DEBUG("US per vblank is: %u\n",
				  dev_priv->usec_per_vblank);
		}
		drm_handle_vblank(dev, 0);
		handled = 1;
	}

	for (i = 0; i < dev_priv->num_irqs; ++i) {
		if (status & cur_irq->pending_mask) {
			atomic_inc(&cur_irq->irq_received);
			DRM_WAKEUP(&cur_irq->irq_queue);
			handled = 1;
#ifdef VIA_HAVE_DMABLIT
			if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
				via_dmablit_handler(dev, 0, 1);
			} else if (dev_priv->irq_map[drm_via_irq_dma1_td] == i) {
				via_dmablit_handler(dev, 1, 1);
			}
#endif
		}
		cur_irq++;
	}

	/* Acknowlege interrupts */
	VIA_WRITE(VIA_REG_INTERRUPT, status);


	if (handled)
		return IRQ_HANDLED;
	else
		return IRQ_NONE;
}

static __inline__ void viadrv_acknowledge_irqs(drm_via_private_t * dev_priv)
{
	u32 status;

	if (dev_priv) {
		/* Acknowlege interrupts */
		status = VIA_READ(VIA_REG_INTERRUPT);
		VIA_WRITE(VIA_REG_INTERRUPT, status |
			  dev_priv->irq_pending_mask);
	}
}

int via_enable_vblank(struct drm_device *dev, int crtc)
{
	drm_via_private_t *dev_priv = dev->dev_private;
	u32 status;

	if (crtc != 0) {
		DRM_ERROR("%s:  bad crtc %d\n", __FUNCTION__, crtc);
		return -EINVAL;
	}

	status = VIA_READ(VIA_REG_INTERRUPT);
	VIA_WRITE(VIA_REG_INTERRUPT, status & VIA_IRQ_VBLANK_ENABLE);