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

Commit 9b3a89f8 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
* 'drm-patches' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6: (21 commits)
  Fix http://bugzilla.kernel.org/show_bug.cgi?id=7606
  drm: add flag for mapping PCI DMA buffers read-only.
  drm: fix up irqflags in drm_lock.c
  drm: i915 updates
  drm: i915: fix up irqflags arg
  drm: i915: Only return EBUSY after we've established we need to schedule a new swap.
  drm: i915: Fix 'sequence has passed' condition in i915_vblank_swap().
  drm: i915: Add SAREA fileds for determining which pipe to sync window buffer swaps to.
  drm: Make handling of dev_priv->vblank_pipe more robust.
  drm: DRM_I915_VBLANK_SWAP ioctl: Take drm_vblank_seq_type_t instead
  drm: i915: Add ioctl for scheduling buffer swaps at vertical blanks.
  drm: Core vsync: Don't clobber target sequence number when scheduling signal.
  drm: Core vsync: Add flag DRM_VBLANK_NEXTONMISS.
  drm: Make locked tasklet handling more robust.
  drm: drm_rmdraw: Declare id and idx as signed so testing for < 0 works as intended.
  drm: Change first valid DRM drawable ID to be 1 instead of 0.
  drm: drawable locking + memory management fixes + copyright
  drm: Add support for interrupt triggered driver callback with lock held to DRM core.
  drm: Add support for tracking drawable information to core
  drm: add support for secondary vertical blank interrupt to i915
  ...
parents 4594bf15 d942625c
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -116,6 +116,14 @@ typedef struct drm_clip_rect {
	unsigned short y2;
} drm_clip_rect_t;

/**
 * Drawable information.
 */
typedef struct drm_drawable_info {
	unsigned int num_rects;
	drm_clip_rect_t *rects;
} drm_drawable_info_t;

/**
 * Texture region,
 */
@@ -348,7 +356,8 @@ typedef struct drm_buf_desc {
		_DRM_PAGE_ALIGN = 0x01,	/**< Align on page boundaries for DMA */
		_DRM_AGP_BUFFER = 0x02,	/**< Buffer is in AGP space */
		_DRM_SG_BUFFER = 0x04,	/**< Scatter/gather memory buffer */
		_DRM_FB_BUFFER = 0x08	/**< Buffer is in frame buffer */
		_DRM_FB_BUFFER = 0x08,	/**< Buffer is in frame buffer */
		_DRM_PCI_BUFFER_RO = 0x10 /**< Map PCI DMA buffer read-only */
	} flags;
	unsigned long agp_start; /**<
				  * Start address of where the AGP buffers are
@@ -443,6 +452,20 @@ typedef struct drm_draw {
	drm_drawable_t handle;
} drm_draw_t;

/**
 * DRM_IOCTL_UPDATE_DRAW ioctl argument type.
 */
typedef enum {
	DRM_DRAWABLE_CLIPRECTS,
} drm_drawable_info_type_t;

typedef struct drm_update_draw {
	drm_drawable_t handle;
	unsigned int type;
	unsigned int num;
	unsigned long long data;
} drm_update_draw_t;

/**
 * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
 */
@@ -465,10 +488,14 @@ typedef struct drm_irq_busid {
typedef enum {
	_DRM_VBLANK_ABSOLUTE = 0x0,	/**< Wait for specific vblank sequence number */
	_DRM_VBLANK_RELATIVE = 0x1,	/**< Wait for given number of vblanks */
	_DRM_VBLANK_NEXTONMISS = 0x10000000,	/**< If missed, wait for next vblank */
	_DRM_VBLANK_SECONDARY = 0x20000000,	/**< Secondary display controller */
	_DRM_VBLANK_SIGNAL = 0x40000000	/**< Send signal instead of blocking */
} drm_vblank_seq_type_t;

#define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL
#define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE)
#define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_SIGNAL | _DRM_VBLANK_SECONDARY | \
				_DRM_VBLANK_NEXTONMISS)

struct drm_wait_vblank_request {
	drm_vblank_seq_type_t type;
@@ -623,6 +650,8 @@ typedef struct drm_set_version {

#define DRM_IOCTL_WAIT_VBLANK		DRM_IOWR(0x3a, drm_wait_vblank_t)

#define DRM_IOCTL_UPDATE_DRAW		DRM_IOW(0x3f, drm_update_draw_t)

/**
 * Device specific ioctls should only be in their respective headers
 * The device specific ioctl range is from 0x40 to 0x79.
+22 −1
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@
#define DRIVER_IRQ_VBL     0x100
#define DRIVER_DMA_QUEUE   0x200
#define DRIVER_FB_DMA      0x400
#define DRIVER_IRQ_VBL2    0x800

/***********************************************************************/
/** \name Begin the DRM... */
@@ -430,7 +431,8 @@ typedef struct drm_device_dma {
	enum {
		_DRM_DMA_USE_AGP = 0x01,
		_DRM_DMA_USE_SG = 0x02,
		_DRM_DMA_USE_FB = 0x04
		_DRM_DMA_USE_FB = 0x04,
		_DRM_DMA_USE_PCI_RO = 0x08
	} flags;

} drm_device_dma_t;
@@ -562,6 +564,7 @@ struct drm_driver {
	void (*kernel_context_switch_unlock) (struct drm_device * dev,
					      drm_lock_t *lock);
	int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
	int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
	int (*dri_library_name) (struct drm_device *dev, char *buf);

	/**
@@ -708,9 +711,13 @@ typedef struct drm_device {

	wait_queue_head_t vbl_queue;	/**< VBLANK wait queue */
	atomic_t vbl_received;
	atomic_t vbl_received2;		/**< number of secondary VBLANK interrupts */
	spinlock_t vbl_lock;
	drm_vbl_sig_t vbl_sigs;		/**< signal list to send on VBLANK */
	drm_vbl_sig_t vbl_sigs2;	/**< signals to send on secondary VBLANK */
	unsigned int vbl_pending;
	spinlock_t tasklet_lock;	/**< For drm_locked_tasklet */
	void (*locked_tasklet_func)(struct drm_device *dev);

	/*@} */
	cycles_t ctx_start;
@@ -738,6 +745,15 @@ typedef struct drm_device {
	drm_local_map_t *agp_buffer_map;
	unsigned int agp_buffer_token;
	drm_head_t primary;		/**< primary screen head */

	/** \name Drawable information */
	/*@{ */
	spinlock_t drw_lock;
	unsigned int drw_bitfield_length;
	u32 *drw_bitfield;
	unsigned int drw_info_length;
	drm_drawable_info_t **drw_info;
	/*@} */
} drm_device_t;

static __inline__ int drm_core_check_feature(struct drm_device *dev,
@@ -885,6 +901,10 @@ extern int drm_adddraw(struct inode *inode, struct file *filp,
		       unsigned int cmd, unsigned long arg);
extern int drm_rmdraw(struct inode *inode, struct file *filp,
		      unsigned int cmd, unsigned long arg);
extern int drm_update_drawable_info(struct inode *inode, struct file *filp,
		       unsigned int cmd, unsigned long arg);
extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev,
						  drm_drawable_t id);

				/* Authentication IOCTL support (drm_auth.h) */
extern int drm_getmagic(struct inode *inode, struct file *filp,
@@ -949,6 +969,7 @@ extern int drm_wait_vblank(struct inode *inode, struct file *filp,
			   unsigned int cmd, unsigned long arg);
extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
extern void drm_vbl_send_signals(drm_device_t * dev);
extern void drm_locked_tasklet(drm_device_t *dev, void(*func)(drm_device_t*));

				/* AGP/GART support (drm_agpsupport.h) */
extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
+7 −3
Original line number Diff line number Diff line
@@ -887,6 +887,9 @@ int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
	request->count = entry->buf_count;
	request->size = size;

	if (request->flags & _DRM_PCI_BUFFER_RO)
		dma->flags = _DRM_DMA_USE_PCI_RO;

	atomic_dec(&dev->buf_alloc);
	return 0;

@@ -1471,9 +1474,10 @@ int drm_freebufs(struct inode *inode, struct file *filp,
 * \param arg pointer to a drm_buf_map structure.
 * \return zero on success or a negative number on failure.
 *
 * Maps the AGP or SG buffer region with do_mmap(), and copies information
 * about each buffer into user space. The PCI buffers are already mapped on the
 * addbufs_pci() call.
 * Maps the AGP, SG or PCI buffer region with do_mmap(), and copies information
 * about each buffer into user space. For PCI buffers, it calls do_mmap() with
 * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
 * drm_mmap_dma().
 */
int drm_mapbufs(struct inode *inode, struct file *filp,
		unsigned int cmd, unsigned long arg)
+4 −4
Original line number Diff line number Diff line
@@ -24,11 +24,11 @@

#define CORE_NAME		"drm"
#define CORE_DESC		"DRM shared core routines"
#define CORE_DATE		"20051102"
#define CORE_DATE		"20060810"

#define DRM_IF_MAJOR	1
#define DRM_IF_MINOR	2
#define DRM_IF_MINOR	3

#define CORE_MAJOR	1
#define CORE_MINOR	0
#define CORE_PATCHLEVEL 1
#define CORE_MINOR	1
#define CORE_PATCHLEVEL 0
+284 −10
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
 *
 * \author Rickard E. (Rik) Faith <faith@valinux.com>
 * \author Gareth Hughes <gareth@valinux.com>
 * \author Michel Dänzer <michel@tungstengraphics.com>
 */

/*
@@ -11,6 +12,7 @@
 *
 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, North Dakota.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,22 +37,294 @@

#include "drmP.h"

/** No-op. */
int drm_adddraw(struct inode *inode, struct file *filp,
		unsigned int cmd, unsigned long arg)
/**
 * Allocate drawable ID and memory to store information about it.
 */
int drm_adddraw(DRM_IOCTL_ARGS)
{
	DRM_DEVICE;
	unsigned long irqflags;
	int i, j;
	u32 *bitfield = dev->drw_bitfield;
	unsigned int bitfield_length = dev->drw_bitfield_length;
	drm_drawable_info_t **info = dev->drw_info;
	unsigned int info_length = dev->drw_info_length;
	drm_draw_t draw;

	draw.handle = 0;	/* NOOP */
	for (i = 0, j = 0; i < bitfield_length; i++) {
		if (bitfield[i] == ~0)
			continue;

		for (; j < 8 * sizeof(*bitfield); j++)
			if (!(bitfield[i] & (1 << j)))
				goto done;
	}
done:

	if (i == bitfield_length) {
		bitfield_length++;

		bitfield = drm_alloc(bitfield_length * sizeof(*bitfield),
				     DRM_MEM_BUFS);

		if (!bitfield) {
			DRM_ERROR("Failed to allocate new drawable bitfield\n");
			return DRM_ERR(ENOMEM);
		}

		if (8 * sizeof(*bitfield) * bitfield_length > info_length) {
			info_length += 8 * sizeof(*bitfield);

			info = drm_alloc(info_length * sizeof(*info),
					 DRM_MEM_BUFS);

			if (!info) {
				DRM_ERROR("Failed to allocate new drawable info"
					  " array\n");

				drm_free(bitfield,
					 bitfield_length * sizeof(*bitfield),
					 DRM_MEM_BUFS);
				return DRM_ERR(ENOMEM);
			}
		}

		bitfield[i] = 0;
	}

	draw.handle = i * 8 * sizeof(*bitfield) + j + 1;
	DRM_DEBUG("%d\n", draw.handle);
	if (copy_to_user((drm_draw_t __user *) arg, &draw, sizeof(draw)))
		return -EFAULT;

	spin_lock_irqsave(&dev->drw_lock, irqflags);

	bitfield[i] |= 1 << j;
	info[draw.handle - 1] = NULL;

	if (bitfield != dev->drw_bitfield) {
		memcpy(bitfield, dev->drw_bitfield, dev->drw_bitfield_length *
		       sizeof(*bitfield));
		drm_free(dev->drw_bitfield, sizeof(*bitfield) *
			 dev->drw_bitfield_length, DRM_MEM_BUFS);
		dev->drw_bitfield = bitfield;
		dev->drw_bitfield_length = bitfield_length;
	}

	if (info != dev->drw_info) {
		memcpy(info, dev->drw_info, dev->drw_info_length *
		       sizeof(*info));
		drm_free(dev->drw_info, sizeof(*info) * dev->drw_info_length,
			 DRM_MEM_BUFS);
		dev->drw_info = info;
		dev->drw_info_length = info_length;
	}

	spin_unlock_irqrestore(&dev->drw_lock, irqflags);

	DRM_COPY_TO_USER_IOCTL((drm_draw_t __user *)data, draw, sizeof(draw));

	return 0;
}

/** No-op. */
int drm_rmdraw(struct inode *inode, struct file *filp,
	       unsigned int cmd, unsigned long arg)
/**
 * Free drawable ID and memory to store information about it.
 */
int drm_rmdraw(DRM_IOCTL_ARGS)
{
	return 0;		/* NOOP */
	DRM_DEVICE;
	drm_draw_t draw;
 	int id, idx;
 	unsigned int shift;
	unsigned long irqflags;
	u32 *bitfield = dev->drw_bitfield;
	unsigned int bitfield_length = dev->drw_bitfield_length;
	drm_drawable_info_t **info = dev->drw_info;
	unsigned int info_length = dev->drw_info_length;

	DRM_COPY_FROM_USER_IOCTL(draw, (drm_draw_t __user *) data,
				 sizeof(draw));

	id = draw.handle - 1;
	idx = id / (8 * sizeof(*bitfield));
	shift = id % (8 * sizeof(*bitfield));

	if (idx < 0 || idx >= bitfield_length ||
	    !(bitfield[idx] & (1 << shift))) {
		DRM_DEBUG("No such drawable %d\n", draw.handle);
		return 0;
	}

	spin_lock_irqsave(&dev->drw_lock, irqflags);

	bitfield[idx] &= ~(1 << shift);

	spin_unlock_irqrestore(&dev->drw_lock, irqflags);

	if (info[id]) {
		drm_free(info[id]->rects, info[id]->num_rects *
			 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
		drm_free(info[id], sizeof(**info), DRM_MEM_BUFS);
	}

	/* Can we shrink the arrays? */
	if (idx == bitfield_length - 1) {
		while (idx >= 0 && !bitfield[idx])
			--idx;

		bitfield_length = idx + 1;

		if (idx != id / (8 * sizeof(*bitfield)))
			bitfield = drm_alloc(bitfield_length *
					     sizeof(*bitfield), DRM_MEM_BUFS);

		if (!bitfield && bitfield_length) {
			bitfield = dev->drw_bitfield;
			bitfield_length = dev->drw_bitfield_length;
		}
	}

	if (bitfield != dev->drw_bitfield) {
		info_length = 8 * sizeof(*bitfield) * bitfield_length;

		info = drm_alloc(info_length * sizeof(*info), DRM_MEM_BUFS);

		if (!info && info_length) {
			info = dev->drw_info;
			info_length = dev->drw_info_length;
		}

		spin_lock_irqsave(&dev->drw_lock, irqflags);

		memcpy(bitfield, dev->drw_bitfield, bitfield_length *
		       sizeof(*bitfield));
		drm_free(dev->drw_bitfield, sizeof(*bitfield) *
			 dev->drw_bitfield_length, DRM_MEM_BUFS);
		dev->drw_bitfield = bitfield;
		dev->drw_bitfield_length = bitfield_length;

		if (info != dev->drw_info) {
			memcpy(info, dev->drw_info, info_length *
			       sizeof(*info));
			drm_free(dev->drw_info, sizeof(*info) *
				 dev->drw_info_length, DRM_MEM_BUFS);
			dev->drw_info = info;
			dev->drw_info_length = info_length;
		}

		spin_unlock_irqrestore(&dev->drw_lock, irqflags);
	}

	DRM_DEBUG("%d\n", draw.handle);
	return 0;
}

int drm_update_drawable_info(DRM_IOCTL_ARGS) {
	DRM_DEVICE;
	drm_update_draw_t update;
	unsigned int id, idx, shift;
	u32 *bitfield = dev->drw_bitfield;
	unsigned long irqflags, bitfield_length = dev->drw_bitfield_length;
	drm_drawable_info_t *info;
	drm_clip_rect_t *rects;
	int err;

	DRM_COPY_FROM_USER_IOCTL(update, (drm_update_draw_t __user *) data,
				 sizeof(update));

	id = update.handle - 1;
	idx = id / (8 * sizeof(*bitfield));
	shift = id % (8 * sizeof(*bitfield));

	if (idx < 0 || idx >= bitfield_length ||
	    !(bitfield[idx] & (1 << shift))) {
		DRM_ERROR("No such drawable %d\n", update.handle);
		return DRM_ERR(EINVAL);
	}

	info = dev->drw_info[id];

	if (!info) {
		info = drm_calloc(1, sizeof(drm_drawable_info_t), DRM_MEM_BUFS);

		if (!info) {
			DRM_ERROR("Failed to allocate drawable info memory\n");
			return DRM_ERR(ENOMEM);
		}
	}

	switch (update.type) {
	case DRM_DRAWABLE_CLIPRECTS:
		if (update.num != info->num_rects) {
			rects = drm_alloc(update.num * sizeof(drm_clip_rect_t),
					 DRM_MEM_BUFS);
		} else
			rects = info->rects;

		if (update.num && !rects) {
			DRM_ERROR("Failed to allocate cliprect memory\n");
			err = DRM_ERR(ENOMEM);
			goto error;
		}

		if (update.num && DRM_COPY_FROM_USER(rects,
						     (drm_clip_rect_t __user *)
						     (unsigned long)update.data,
						     update.num *
						     sizeof(*rects))) {
			DRM_ERROR("Failed to copy cliprects from userspace\n");
			err = DRM_ERR(EFAULT);
			goto error;
		}

		spin_lock_irqsave(&dev->drw_lock, irqflags);

		if (rects != info->rects) {
			drm_free(info->rects, info->num_rects *
				 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
		}

		info->rects = rects;
		info->num_rects = update.num;
		dev->drw_info[id] = info;

		spin_unlock_irqrestore(&dev->drw_lock, irqflags);

		DRM_DEBUG("Updated %d cliprects for drawable %d\n",
			  info->num_rects, id);
		break;
	default:
		DRM_ERROR("Invalid update type %d\n", update.type);
		return DRM_ERR(EINVAL);
	}

	return 0;

error:
	if (!dev->drw_info[id])
		drm_free(info, sizeof(*info), DRM_MEM_BUFS);
	else if (rects != dev->drw_info[id]->rects)
		drm_free(rects, update.num *
			 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);

	return err;
}

/**
 * Caller must hold the drawable spinlock!
 */
drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev, drm_drawable_t id) {
	u32 *bitfield = dev->drw_bitfield;
	unsigned int idx, shift;

	id--;
	idx = id / (8 * sizeof(*bitfield));
	shift = id % (8 * sizeof(*bitfield));

	if (idx < 0 || idx >= dev->drw_bitfield_length ||
	    !(bitfield[idx] & (1 << shift))) {
		DRM_DEBUG("No such drawable %d\n", id);
		return NULL;
	}

	return dev->drw_info[id];
}
EXPORT_SYMBOL(drm_get_drawable_info);
Loading