2005-07-27 14:20:30 -06:00
|
|
|
/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
|
2004-06-10 06:45:38 -06:00
|
|
|
*/
|
2005-11-28 16:10:41 -07:00
|
|
|
/*
|
2004-06-10 06:45:38 -06:00
|
|
|
* Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
* All Rights Reserved.
|
2007-11-04 19:42:22 -07:00
|
|
|
*
|
2005-06-06 03:18:44 -06:00
|
|
|
* 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, sub license, 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:
|
2007-11-04 19:42:22 -07:00
|
|
|
*
|
2005-06-06 03:18:44 -06:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
2007-11-04 19:42:22 -07:00
|
|
|
*
|
2005-06-06 03:18:44 -06:00
|
|
|
* 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 NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL 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.
|
2007-11-04 19:42:22 -07:00
|
|
|
*
|
2005-11-28 16:10:41 -07:00
|
|
|
*/
|
2004-06-10 06:45:38 -06:00
|
|
|
|
|
|
|
#include "drmP.h"
|
|
|
|
#include "drm.h"
|
|
|
|
#include "i915_drm.h"
|
|
|
|
#include "i915_drv.h"
|
|
|
|
|
2007-12-04 07:36:36 -07:00
|
|
|
#include "intel_drv.h"
|
|
|
|
|
2005-12-28 16:49:59 -07:00
|
|
|
#define USER_INT_FLAG (1<<1)
|
|
|
|
#define VSYNC_PIPEB_FLAG (1<<5)
|
|
|
|
#define VSYNC_PIPEA_FLAG (1<<7)
|
2007-12-17 18:09:48 -07:00
|
|
|
#define HOTPLUG_FLAG (1 << 17)
|
2005-12-28 16:49:59 -07:00
|
|
|
|
2004-06-10 06:45:38 -06:00
|
|
|
#define MAX_NOPID ((u32)~0)
|
|
|
|
|
2007-09-12 09:55:33 -06:00
|
|
|
/**
|
|
|
|
* i915_get_pipe - return the the pipe associated with a given plane
|
|
|
|
* @dev: DRM device
|
|
|
|
* @plane: plane to look for
|
|
|
|
*
|
|
|
|
* We need to get the pipe associated with a given plane to correctly perform
|
|
|
|
* vblank driven swapping, and they may not always be equal. So look up the
|
|
|
|
* pipe associated with @plane here.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
i915_get_pipe(struct drm_device *dev, int plane)
|
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2007-09-12 09:55:33 -06:00
|
|
|
u32 dspcntr;
|
|
|
|
|
|
|
|
dspcntr = plane ? I915_READ(DSPBCNTR) : I915_READ(DSPACNTR);
|
|
|
|
|
|
|
|
return dspcntr & DISPPLANE_SEL_PIPE_MASK ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2007-02-22 09:21:18 -07:00
|
|
|
/**
|
|
|
|
* Emit a synchronous flip.
|
|
|
|
*
|
|
|
|
* This function must be called with the drawable spinlock held.
|
|
|
|
*/
|
|
|
|
static void
|
2007-07-15 20:32:51 -06:00
|
|
|
i915_dispatch_vsync_flip(struct drm_device *dev, struct drm_drawable_info *drw,
|
2007-09-11 04:48:46 -06:00
|
|
|
int plane)
|
2007-02-22 09:21:18 -07:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
|
|
|
struct drm_i915_sarea *sarea_priv = dev_priv->sarea_priv;
|
2007-02-22 09:21:18 -07:00
|
|
|
u16 x1, y1, x2, y2;
|
2007-09-11 04:48:46 -06:00
|
|
|
int pf_planes = 1 << plane;
|
2007-02-22 09:21:18 -07:00
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK_ASSERT(&dev->drw_lock);
|
|
|
|
|
2007-09-11 04:48:46 -06:00
|
|
|
/* If the window is visible on the other plane, we have to flip on that
|
|
|
|
* plane as well.
|
2007-02-22 09:21:18 -07:00
|
|
|
*/
|
2007-09-11 04:48:46 -06:00
|
|
|
if (plane == 1) {
|
|
|
|
x1 = sarea_priv->planeA_x;
|
|
|
|
y1 = sarea_priv->planeA_y;
|
|
|
|
x2 = x1 + sarea_priv->planeA_w;
|
|
|
|
y2 = y1 + sarea_priv->planeA_h;
|
2007-02-22 09:21:18 -07:00
|
|
|
} else {
|
2007-09-11 04:48:46 -06:00
|
|
|
x1 = sarea_priv->planeB_x;
|
|
|
|
y1 = sarea_priv->planeB_y;
|
|
|
|
x2 = x1 + sarea_priv->planeB_w;
|
|
|
|
y2 = y1 + sarea_priv->planeB_h;
|
2007-02-22 09:21:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x2 > 0 && y2 > 0) {
|
|
|
|
int i, num_rects = drw->num_rects;
|
2007-07-15 19:22:15 -06:00
|
|
|
struct drm_clip_rect *rect = drw->rects;
|
2007-02-22 09:21:18 -07:00
|
|
|
|
|
|
|
for (i = 0; i < num_rects; i++)
|
2007-02-28 04:33:56 -07:00
|
|
|
if (!(rect[i].x1 >= x2 || rect[i].y1 >= y2 ||
|
|
|
|
rect[i].x2 <= x1 || rect[i].y2 <= y1)) {
|
2007-09-11 04:48:46 -06:00
|
|
|
pf_planes = 0x3;
|
2007-02-22 09:21:18 -07:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 04:48:46 -06:00
|
|
|
i915_dispatch_flip(dev, pf_planes, 1);
|
2007-02-22 09:21:18 -07:00
|
|
|
}
|
|
|
|
|
2006-08-25 11:01:05 -06:00
|
|
|
/**
|
|
|
|
* Emit blits for scheduled buffer swaps.
|
|
|
|
*
|
|
|
|
* This function will be called with the HW lock held.
|
|
|
|
*/
|
2007-07-15 20:32:51 -06:00
|
|
|
static void i915_vblank_tasklet(struct drm_device *dev)
|
2006-08-25 11:01:05 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2006-10-26 05:15:30 -06:00
|
|
|
struct list_head *list, *tmp, hits, *hit;
|
2007-02-19 04:27:54 -07:00
|
|
|
int nhits, nrects, slice[2], upper[2], lower[2], i, num_pages;
|
2006-10-26 05:15:30 -06:00
|
|
|
unsigned counter[2] = { atomic_read(&dev->vbl_received),
|
|
|
|
atomic_read(&dev->vbl_received2) };
|
2007-07-15 19:22:15 -06:00
|
|
|
struct drm_drawable_info *drw;
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_sarea *sarea_priv = dev_priv->sarea_priv;
|
2007-02-19 04:27:54 -07:00
|
|
|
u32 cpp = dev_priv->cpp, offsets[3];
|
2006-10-26 05:15:30 -06:00
|
|
|
u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
|
|
|
|
XY_SRC_COPY_BLT_WRITE_ALPHA |
|
|
|
|
XY_SRC_COPY_BLT_WRITE_RGB)
|
|
|
|
: XY_SRC_COPY_BLT_CMD;
|
|
|
|
u32 pitchropcpp = (sarea_priv->pitch * cpp) | (0xcc << 16) |
|
|
|
|
(cpp << 23) | (1 << 24);
|
|
|
|
RING_LOCALS;
|
2006-08-25 11:01:05 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
INIT_LIST_HEAD(&hits);
|
|
|
|
|
|
|
|
nhits = nrects = 0;
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
/* No irqsave/restore necessary. This tasklet may be run in an
|
|
|
|
* interrupt context or normal context, but we don't have to worry
|
|
|
|
* about getting interrupted by something acquiring the lock, because
|
|
|
|
* we are the interrupt context thing that acquires the lock.
|
|
|
|
*/
|
|
|
|
DRM_SPINLOCK(&dev_priv->swaps_lock);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
/* Find buffer swaps scheduled for this vertical blank */
|
2006-08-25 11:01:05 -06:00
|
|
|
list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_vbl_swap *vbl_swap =
|
|
|
|
list_entry(list, struct drm_i915_vbl_swap, head);
|
2007-09-12 09:55:33 -06:00
|
|
|
int pipe = i915_get_pipe(dev, vbl_swap->plane);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2007-09-11 04:48:46 -06:00
|
|
|
if ((counter[pipe] - vbl_swap->sequence) > (1<<23))
|
2006-10-26 05:15:30 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
list_del(list);
|
|
|
|
dev_priv->swaps_pending--;
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK(&dev_priv->swaps_lock);
|
|
|
|
DRM_SPINLOCK(&dev->drw_lock);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
if (!drw) {
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK(&dev->drw_lock);
|
2006-10-26 05:15:30 -06:00
|
|
|
drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK(&dev_priv->swaps_lock);
|
2006-10-26 05:15:30 -06:00
|
|
|
continue;
|
|
|
|
}
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
list_for_each(hit, &hits) {
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_vbl_swap *swap_cmp =
|
|
|
|
list_entry(hit, struct drm_i915_vbl_swap, head);
|
2007-07-15 19:22:15 -06:00
|
|
|
struct drm_drawable_info *drw_cmp =
|
2006-10-26 05:15:30 -06:00
|
|
|
drm_get_drawable_info(dev, swap_cmp->drw_id);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
if (drw_cmp &&
|
|
|
|
drw_cmp->rects[0].y1 > drw->rects[0].y1) {
|
|
|
|
list_add_tail(list, hit);
|
|
|
|
break;
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
2006-10-26 05:15:30 -06:00
|
|
|
}
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK(&dev->drw_lock);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
/* List of hits was empty, or we reached the end of it */
|
|
|
|
if (hit == &hits)
|
|
|
|
list_add_tail(list, hits.prev);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
nhits++;
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK(&dev_priv->swaps_lock);
|
2006-10-26 05:15:30 -06:00
|
|
|
}
|
|
|
|
|
2007-09-18 13:55:43 -06:00
|
|
|
DRM_SPINUNLOCK(&dev_priv->swaps_lock);
|
2007-07-18 15:22:40 -06:00
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
if (nhits == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
i915_kernel_lost_context(dev);
|
|
|
|
|
|
|
|
upper[0] = upper[1] = 0;
|
2007-09-11 04:48:46 -06:00
|
|
|
slice[0] = max(sarea_priv->planeA_h / nhits, 1);
|
|
|
|
slice[1] = max(sarea_priv->planeB_h / nhits, 1);
|
|
|
|
lower[0] = sarea_priv->planeA_y + slice[0];
|
|
|
|
lower[1] = sarea_priv->planeB_y + slice[0];
|
2006-10-26 05:15:30 -06:00
|
|
|
|
2007-02-19 04:27:54 -07:00
|
|
|
offsets[0] = sarea_priv->front_offset;
|
|
|
|
offsets[1] = sarea_priv->back_offset;
|
|
|
|
offsets[2] = sarea_priv->third_offset;
|
|
|
|
num_pages = sarea_priv->third_handle ? 3 : 2;
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK(&dev->drw_lock);
|
2006-10-26 05:15:30 -06:00
|
|
|
|
|
|
|
/* Emit blits for buffer swaps, partitioning both outputs into as many
|
|
|
|
* slices as there are buffer swaps scheduled in order to avoid tearing
|
|
|
|
* (based on the assumption that a single buffer swap would always
|
|
|
|
* complete before scanout starts).
|
|
|
|
*/
|
|
|
|
for (i = 0; i++ < nhits;
|
|
|
|
upper[0] = lower[0], lower[0] += slice[0],
|
|
|
|
upper[1] = lower[1], lower[1] += slice[1]) {
|
2007-02-22 09:21:18 -07:00
|
|
|
int init_drawrect = 1;
|
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
if (i == nhits)
|
|
|
|
lower[0] = lower[1] = sarea_priv->height;
|
|
|
|
|
|
|
|
list_for_each(hit, &hits) {
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_vbl_swap *swap_hit =
|
|
|
|
list_entry(hit, struct drm_i915_vbl_swap, head);
|
2007-07-15 19:22:15 -06:00
|
|
|
struct drm_clip_rect *rect;
|
2007-09-11 04:48:46 -06:00
|
|
|
int num_rects, plane, front, back;
|
2006-10-26 05:15:30 -06:00
|
|
|
unsigned short top, bottom;
|
|
|
|
|
|
|
|
drw = drm_get_drawable_info(dev, swap_hit->drw_id);
|
|
|
|
|
|
|
|
if (!drw)
|
|
|
|
continue;
|
|
|
|
|
2007-09-11 04:48:46 -06:00
|
|
|
plane = swap_hit->plane;
|
2007-02-22 09:21:18 -07:00
|
|
|
|
|
|
|
if (swap_hit->flip) {
|
2007-09-11 04:48:46 -06:00
|
|
|
i915_dispatch_vsync_flip(dev, drw, plane);
|
2007-02-22 09:21:18 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (init_drawrect) {
|
|
|
|
BEGIN_LP_RING(6);
|
|
|
|
|
|
|
|
OUT_RING(GFX_OP_DRAWRECT_INFO);
|
|
|
|
OUT_RING(0);
|
|
|
|
OUT_RING(0);
|
|
|
|
OUT_RING(sarea_priv->width | sarea_priv->height << 16);
|
|
|
|
OUT_RING(sarea_priv->width | sarea_priv->height << 16);
|
|
|
|
OUT_RING(0);
|
|
|
|
|
|
|
|
ADVANCE_LP_RING();
|
|
|
|
|
|
|
|
sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
|
|
|
|
|
|
|
|
init_drawrect = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect = drw->rects;
|
2007-09-11 04:48:46 -06:00
|
|
|
top = upper[plane];
|
|
|
|
bottom = lower[plane];
|
2006-10-26 05:15:30 -06:00
|
|
|
|
2007-02-28 09:48:56 -07:00
|
|
|
front = (dev_priv->sarea_priv->pf_current_page >>
|
2007-09-11 04:48:46 -06:00
|
|
|
(2 * plane)) & 0x3;
|
2007-02-19 04:27:54 -07:00
|
|
|
back = (front + 1) % num_pages;
|
|
|
|
|
2006-10-26 05:15:30 -06:00
|
|
|
for (num_rects = drw->num_rects; num_rects--; rect++) {
|
|
|
|
int y1 = max(rect->y1, top);
|
|
|
|
int y2 = min(rect->y2, bottom);
|
|
|
|
|
|
|
|
if (y1 >= y2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BEGIN_LP_RING(8);
|
|
|
|
|
|
|
|
OUT_RING(cmd);
|
|
|
|
OUT_RING(pitchropcpp);
|
|
|
|
OUT_RING((y1 << 16) | rect->x1);
|
|
|
|
OUT_RING((y2 << 16) | rect->x2);
|
2007-02-19 04:27:54 -07:00
|
|
|
OUT_RING(offsets[front]);
|
2006-10-26 05:15:30 -06:00
|
|
|
OUT_RING((y1 << 16) | rect->x1);
|
|
|
|
OUT_RING(pitchropcpp & 0xffff);
|
2007-02-19 04:27:54 -07:00
|
|
|
OUT_RING(offsets[back]);
|
2006-10-26 05:15:30 -06:00
|
|
|
|
|
|
|
ADVANCE_LP_RING();
|
|
|
|
}
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK(&dev->drw_lock);
|
2006-10-26 05:15:30 -06:00
|
|
|
|
|
|
|
list_for_each_safe(hit, tmp, &hits) {
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_vbl_swap *swap_hit =
|
|
|
|
list_entry(hit, struct drm_i915_vbl_swap, head);
|
2006-10-26 05:15:30 -06:00
|
|
|
|
|
|
|
list_del(hit);
|
|
|
|
|
|
|
|
drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
|
|
|
|
}
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
|
|
|
|
2007-12-17 18:09:48 -07:00
|
|
|
#define HOTPLUG_CMD_CRT 1
|
|
|
|
#define HOTPLUG_CMD_SDVOB 4
|
|
|
|
#define HOTPLUG_CMD_SDVOC 8
|
|
|
|
|
2007-12-04 07:36:36 -07:00
|
|
|
static struct drm_device *hotplug_dev;
|
|
|
|
static int hotplug_cmd = 0;
|
|
|
|
static spinlock_t hotplug_lock = SPIN_LOCK_UNLOCKED;
|
|
|
|
|
|
|
|
static void i915_hotplug_crt(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_output *output;
|
|
|
|
struct intel_output *iout;
|
|
|
|
|
|
|
|
mutex_lock(&dev->mode_config.mutex);
|
|
|
|
|
|
|
|
/* find the crt output */
|
|
|
|
list_for_each_entry(output, &dev->mode_config.output_list, head) {
|
|
|
|
iout = output->driver_private;
|
|
|
|
if (iout->type == INTEL_OUTPUT_ANALOG)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
iout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iout == 0)
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
drm_hotplug_stage_two(dev, output);
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&dev->mode_config.mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i915_hotplug_sdvo(struct drm_device *dev, int sdvoB)
|
|
|
|
{
|
|
|
|
struct drm_output *output = 0;
|
|
|
|
enum drm_output_status status;
|
|
|
|
|
|
|
|
mutex_lock(&dev->mode_config.mutex);
|
|
|
|
|
|
|
|
output = intel_sdvo_find(dev, sdvoB);
|
|
|
|
|
|
|
|
if (!output) {
|
|
|
|
DRM_ERROR("could not find sdvo%s output\n", sdvoB ? "B" : "C");
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = output->funcs->detect(output);
|
|
|
|
|
|
|
|
if (status != output_status_connected)
|
|
|
|
DRM_DEBUG("disconnect or unkown we don't do anything then\n");
|
|
|
|
else
|
|
|
|
drm_hotplug_stage_two(dev, output);
|
|
|
|
|
|
|
|
/* wierd hw bug, sdvo stop sending interupts */
|
|
|
|
intel_sdvo_set_hotplug(output, 1);
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&dev->mode_config.mutex);
|
|
|
|
}
|
2007-12-17 18:09:48 -07:00
|
|
|
/*
|
|
|
|
* This code is called in a more safe envirmoent to handle the hotplugs.
|
|
|
|
* Add code here for hotplug love to userspace.
|
|
|
|
*/
|
2007-12-04 07:36:36 -07:00
|
|
|
static void i915_hotplug_work_func(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = hotplug_dev;
|
|
|
|
int crt;
|
|
|
|
int sdvoB;
|
|
|
|
int sdvoC;
|
|
|
|
|
|
|
|
spin_lock(&hotplug_lock);
|
2007-12-17 18:09:48 -07:00
|
|
|
crt = hotplug_cmd & HOTPLUG_CMD_CRT;
|
|
|
|
sdvoB = hotplug_cmd & HOTPLUG_CMD_SDVOB;
|
|
|
|
sdvoC = hotplug_cmd & HOTPLUG_CMD_SDVOC;
|
2007-12-04 07:36:36 -07:00
|
|
|
hotplug_cmd = 0;
|
|
|
|
spin_unlock(&hotplug_lock);
|
|
|
|
|
|
|
|
if (crt)
|
|
|
|
i915_hotplug_crt(dev);
|
|
|
|
|
|
|
|
if (sdvoB)
|
|
|
|
i915_hotplug_sdvo(dev, 1);
|
|
|
|
|
|
|
|
if (sdvoC)
|
|
|
|
i915_hotplug_sdvo(dev, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i915_run_hotplug_tasklet(struct drm_device *dev, uint32_t stat)
|
|
|
|
{
|
|
|
|
static DECLARE_WORK(hotplug, i915_hotplug_work_func);
|
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
|
|
|
|
|
|
|
hotplug_dev = dev;
|
|
|
|
|
2007-12-17 18:09:48 -07:00
|
|
|
if (stat & CRT_HOTPLUG_INT_STATUS) {
|
2007-12-04 07:36:36 -07:00
|
|
|
DRM_DEBUG("CRT event\n");
|
|
|
|
|
2007-12-17 18:09:48 -07:00
|
|
|
if (stat & CRT_HOTPLUG_MONITOR_MASK) {
|
2007-12-04 07:36:36 -07:00
|
|
|
spin_lock(&hotplug_lock);
|
2007-12-17 18:09:48 -07:00
|
|
|
hotplug_cmd |= HOTPLUG_CMD_CRT;
|
2007-12-04 07:36:36 -07:00
|
|
|
spin_unlock(&hotplug_lock);
|
|
|
|
} else {
|
|
|
|
/* handle crt disconnects */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-17 18:09:48 -07:00
|
|
|
if (stat & SDVOB_HOTPLUG_INT_STATUS) {
|
2007-12-04 07:36:36 -07:00
|
|
|
DRM_DEBUG("sDVOB event\n");
|
|
|
|
|
|
|
|
spin_lock(&hotplug_lock);
|
2007-12-17 18:09:48 -07:00
|
|
|
hotplug_cmd |= HOTPLUG_CMD_SDVOB;
|
2007-12-04 07:36:36 -07:00
|
|
|
spin_unlock(&hotplug_lock);
|
|
|
|
}
|
|
|
|
|
2007-12-17 18:09:48 -07:00
|
|
|
if (stat & SDVOC_HOTPLUG_INT_STATUS) {
|
2007-12-04 07:36:36 -07:00
|
|
|
DRM_DEBUG("sDVOC event\n");
|
|
|
|
|
|
|
|
spin_lock(&hotplug_lock);
|
2007-12-17 18:09:48 -07:00
|
|
|
hotplug_cmd |= HOTPLUG_CMD_SDVOC;
|
2007-12-04 07:36:36 -07:00
|
|
|
spin_unlock(&hotplug_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
queue_work(dev_priv->wq, &hotplug);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
|
2004-06-10 06:45:38 -06:00
|
|
|
{
|
2007-07-15 20:32:51 -06:00
|
|
|
struct drm_device *dev = (struct drm_device *) arg;
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2007-12-04 07:36:36 -07:00
|
|
|
u32 temp = 0;
|
|
|
|
u32 temp2;
|
2007-01-24 01:33:21 -07:00
|
|
|
u32 pipea_stats, pipeb_stats;
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2007-01-24 01:33:21 -07:00
|
|
|
pipea_stats = I915_READ(I915REG_PIPEASTAT);
|
|
|
|
pipeb_stats = I915_READ(I915REG_PIPEBSTAT);
|
2007-11-04 19:42:22 -07:00
|
|
|
|
2007-12-04 07:36:36 -07:00
|
|
|
/* On i8xx hw the IIR and IER are 16bit on i9xx its 32bit */
|
|
|
|
if (IS_I9XX(dev)) {
|
|
|
|
temp = I915_READ(I915REG_INT_IDENTITY_R);
|
|
|
|
} else {
|
|
|
|
temp = I915_READ16(I915REG_INT_IDENTITY_R);
|
|
|
|
}
|
|
|
|
|
|
|
|
temp2 = temp;
|
2006-09-15 03:18:35 -06:00
|
|
|
temp &= (dev_priv->irq_enable_reg | USER_INT_FLAG);
|
2004-08-27 03:14:30 -06:00
|
|
|
|
2007-12-04 07:36:36 -07:00
|
|
|
#if 0
|
|
|
|
/* ugly despamification of pipeb event irq */
|
|
|
|
if (temp & (0xFFFFFFF ^ ((1 << 5) | (1 << 7)))) {
|
|
|
|
DRM_DEBUG("IIR %08x\n", temp2);
|
|
|
|
DRM_DEBUG("MSK %08x\n", dev_priv->irq_enable_reg | USER_INT_FLAG);
|
|
|
|
DRM_DEBUG("M&I %08x\n", temp);
|
|
|
|
DRM_DEBUG("HOT %08x\n", I915_READ(PORT_HOTPLUG_STAT));
|
|
|
|
}
|
|
|
|
#else
|
2006-09-12 04:01:00 -06:00
|
|
|
#if 0
|
2004-06-10 06:45:38 -06:00
|
|
|
DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
|
2006-09-12 04:01:00 -06:00
|
|
|
#endif
|
2007-12-04 07:36:36 -07:00
|
|
|
#endif
|
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
if (temp == 0)
|
2004-06-10 06:45:38 -06:00
|
|
|
return IRQ_NONE;
|
|
|
|
|
2007-12-04 07:36:36 -07:00
|
|
|
if (IS_I9XX(dev)) {
|
|
|
|
I915_WRITE(I915REG_INT_IDENTITY_R, temp);
|
|
|
|
(void) I915_READ(I915REG_INT_IDENTITY_R);
|
|
|
|
} else {
|
|
|
|
I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
|
|
|
|
(void) I915_READ16(I915REG_INT_IDENTITY_R);
|
|
|
|
}
|
|
|
|
|
2007-04-03 02:21:41 -06:00
|
|
|
DRM_READMEMORYBARRIER();
|
2005-12-28 16:49:59 -07:00
|
|
|
|
2006-02-09 16:14:16 -07:00
|
|
|
dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
|
|
|
|
|
2006-08-21 13:36:00 -06:00
|
|
|
if (temp & USER_INT_FLAG) {
|
2005-12-28 16:49:59 -07:00
|
|
|
DRM_WAKEUP(&dev_priv->irq_queue);
|
2006-08-21 13:36:00 -06:00
|
|
|
#ifdef I915_HAVE_FENCE
|
|
|
|
i915_fence_handler(dev);
|
|
|
|
#endif
|
|
|
|
}
|
2005-12-28 16:49:59 -07:00
|
|
|
|
2006-06-19 14:15:53 -06:00
|
|
|
if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
|
2006-09-27 10:22:10 -06:00
|
|
|
int vblank_pipe = dev_priv->vblank_pipe;
|
|
|
|
|
|
|
|
if ((vblank_pipe &
|
2006-08-11 10:06:46 -06:00
|
|
|
(DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B))
|
|
|
|
== (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) {
|
|
|
|
if (temp & VSYNC_PIPEA_FLAG)
|
|
|
|
atomic_inc(&dev->vbl_received);
|
|
|
|
if (temp & VSYNC_PIPEB_FLAG)
|
|
|
|
atomic_inc(&dev->vbl_received2);
|
2006-09-27 10:22:10 -06:00
|
|
|
} else if (((temp & VSYNC_PIPEA_FLAG) &&
|
|
|
|
(vblank_pipe & DRM_I915_VBLANK_PIPE_A)) ||
|
|
|
|
((temp & VSYNC_PIPEB_FLAG) &&
|
|
|
|
(vblank_pipe & DRM_I915_VBLANK_PIPE_B)))
|
2006-08-11 10:06:46 -06:00
|
|
|
atomic_inc(&dev->vbl_received);
|
|
|
|
|
2005-12-28 16:49:59 -07:00
|
|
|
DRM_WAKEUP(&dev->vbl_queue);
|
|
|
|
drm_vbl_send_signals(dev);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-09-29 02:27:29 -06:00
|
|
|
if (dev_priv->swaps_pending > 0)
|
|
|
|
drm_locked_tasklet(dev, i915_vblank_tasklet);
|
2007-11-04 19:42:22 -07:00
|
|
|
I915_WRITE(I915REG_PIPEASTAT,
|
2007-01-24 01:33:21 -07:00
|
|
|
pipea_stats|I915_VBLANK_INTERRUPT_ENABLE|
|
|
|
|
I915_VBLANK_CLEAR);
|
|
|
|
I915_WRITE(I915REG_PIPEBSTAT,
|
|
|
|
pipeb_stats|I915_VBLANK_INTERRUPT_ENABLE|
|
|
|
|
I915_VBLANK_CLEAR);
|
2005-12-28 16:49:59 -07:00
|
|
|
}
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2007-12-04 07:36:36 -07:00
|
|
|
/* for now lest just ack it */
|
|
|
|
if (temp & (1 << 17)) {
|
2007-12-17 18:09:48 -07:00
|
|
|
DRM_DEBUG("Hotplug event received\n");
|
2007-12-04 07:36:36 -07:00
|
|
|
|
|
|
|
temp2 = I915_READ(PORT_HOTPLUG_STAT);
|
|
|
|
|
|
|
|
i915_run_hotplug_tasklet(dev, temp2);
|
|
|
|
|
|
|
|
I915_WRITE(PORT_HOTPLUG_STAT,temp2);
|
|
|
|
}
|
|
|
|
|
2004-06-10 06:45:38 -06:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2007-11-05 18:32:58 -07:00
|
|
|
int i915_emit_irq(struct drm_device *dev)
|
2004-06-10 06:45:38 -06:00
|
|
|
{
|
2006-08-08 16:05:54 -06:00
|
|
|
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
2006-08-09 22:38:50 -06:00
|
|
|
RING_LOCALS;
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2006-08-09 22:38:50 -06:00
|
|
|
i915_kernel_lost_context(dev);
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2006-08-09 22:38:50 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2007-02-02 09:23:42 -07:00
|
|
|
i915_emit_breadcrumb(dev);
|
2006-08-08 16:05:54 -06:00
|
|
|
|
2007-02-02 09:23:42 -07:00
|
|
|
BEGIN_LP_RING(2);
|
2006-08-09 22:38:50 -06:00
|
|
|
OUT_RING(0);
|
|
|
|
OUT_RING(GFX_OP_USER_INTERRUPT);
|
|
|
|
ADVANCE_LP_RING();
|
2006-08-08 16:05:54 -06:00
|
|
|
|
2006-08-09 22:38:50 -06:00
|
|
|
return dev_priv->counter;
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
2007-09-24 15:41:46 -06:00
|
|
|
void i915_user_irq_on(struct drm_i915_private *dev_priv)
|
2006-09-05 06:23:18 -06:00
|
|
|
{
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK(&dev_priv->user_irq_lock);
|
2006-09-08 09:24:38 -06:00
|
|
|
if (dev_priv->irq_enabled && (++dev_priv->user_irq_refcount == 1)){
|
2006-09-05 06:23:18 -06:00
|
|
|
dev_priv->irq_enable_reg |= USER_INT_FLAG;
|
|
|
|
I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
|
|
|
|
}
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
|
2006-09-05 06:23:18 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-24 15:41:46 -06:00
|
|
|
void i915_user_irq_off(struct drm_i915_private *dev_priv)
|
2006-09-05 06:23:18 -06:00
|
|
|
{
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK(&dev_priv->user_irq_lock);
|
2006-09-05 06:23:18 -06:00
|
|
|
if (dev_priv->irq_enabled && (--dev_priv->user_irq_refcount == 0)) {
|
2006-09-28 11:13:59 -06:00
|
|
|
// dev_priv->irq_enable_reg &= ~USER_INT_FLAG;
|
2006-09-15 03:18:35 -06:00
|
|
|
// I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
|
2006-09-05 06:23:18 -06:00
|
|
|
}
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK(&dev_priv->user_irq_lock);
|
2006-09-05 06:23:18 -06:00
|
|
|
}
|
2007-11-04 19:42:22 -07:00
|
|
|
|
2006-09-05 06:23:18 -06:00
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
static int i915_wait_irq(struct drm_device * dev, int irq_nr)
|
2004-06-10 06:45:38 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2004-06-10 06:45:38 -06:00
|
|
|
int ret = 0;
|
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
|
|
|
|
READ_BREADCRUMB(dev_priv));
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
if (READ_BREADCRUMB(dev_priv) >= irq_nr)
|
|
|
|
return 0;
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2006-09-05 06:23:18 -06:00
|
|
|
i915_user_irq_on(dev_priv);
|
2007-06-03 02:11:44 -06:00
|
|
|
DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
|
|
|
|
READ_BREADCRUMB(dev_priv) >= irq_nr);
|
2006-09-05 06:23:18 -06:00
|
|
|
i915_user_irq_off(dev_priv);
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2007-07-19 18:00:17 -06:00
|
|
|
if (ret == -EBUSY) {
|
2004-08-27 03:14:30 -06:00
|
|
|
DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
|
2004-06-10 06:45:38 -06:00
|
|
|
__FUNCTION__,
|
2004-08-27 03:14:30 -06:00
|
|
|
READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
|
2004-06-10 06:45:38 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
static int i915_driver_vblank_do_wait(struct drm_device *dev,
|
|
|
|
unsigned int *sequence,
|
2006-08-11 10:06:46 -06:00
|
|
|
atomic_t *counter)
|
2005-12-28 16:49:59 -07:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
2005-12-28 16:49:59 -07:00
|
|
|
unsigned int cur_vblank;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!dev_priv) {
|
|
|
|
DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2005-12-28 16:49:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
|
2006-08-11 10:06:46 -06:00
|
|
|
(((cur_vblank = atomic_read(counter))
|
2005-12-28 16:49:59 -07:00
|
|
|
- *sequence) <= (1<<23)));
|
2007-11-04 19:42:22 -07:00
|
|
|
|
2005-12-28 16:49:59 -07:00
|
|
|
*sequence = cur_vblank;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-24 15:41:46 -06:00
|
|
|
void i915_driver_wait_next_vblank(struct drm_device *dev, int pipe)
|
2007-05-22 18:49:04 -06:00
|
|
|
{
|
|
|
|
unsigned int seq;
|
|
|
|
|
|
|
|
seq = pipe ? atomic_read(&dev->vbl_received2) + 1 :
|
|
|
|
atomic_read(&dev->vbl_received) + 1;
|
|
|
|
|
|
|
|
if (!pipe)
|
|
|
|
i915_driver_vblank_do_wait(dev, &seq, &dev->vbl_received);
|
|
|
|
else
|
|
|
|
i915_driver_vblank_do_wait(dev, &seq, &dev->vbl_received2);
|
|
|
|
}
|
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence)
|
2006-08-11 10:06:46 -06:00
|
|
|
{
|
2007-12-07 15:24:45 -07:00
|
|
|
atomic_t *counter;
|
|
|
|
|
|
|
|
if (i915_get_pipe(dev, 0) == 0)
|
|
|
|
counter = &dev->vbl_received;
|
|
|
|
else
|
|
|
|
counter = &dev->vbl_received2;
|
|
|
|
return i915_driver_vblank_do_wait(dev, sequence, counter);
|
2006-08-11 10:06:46 -06:00
|
|
|
}
|
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence)
|
2006-08-11 10:06:46 -06:00
|
|
|
{
|
2007-12-07 15:24:45 -07:00
|
|
|
atomic_t *counter;
|
|
|
|
|
|
|
|
if (i915_get_pipe(dev, 1) == 0)
|
|
|
|
counter = &dev->vbl_received;
|
|
|
|
else
|
|
|
|
counter = &dev->vbl_received2;
|
|
|
|
|
|
|
|
return i915_driver_vblank_do_wait(dev, sequence, counter);
|
2006-08-11 10:06:46 -06:00
|
|
|
}
|
|
|
|
|
2004-06-10 06:45:38 -06:00
|
|
|
/* Needs the lock as it touches the ring.
|
|
|
|
*/
|
2007-11-05 18:32:58 -07:00
|
|
|
int i915_irq_emit(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2004-06-10 06:45:38 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
|
|
|
struct drm_i915_irq_emit *emit = data;
|
2004-06-10 06:45:38 -06:00
|
|
|
int result;
|
|
|
|
|
2007-07-20 07:39:25 -06:00
|
|
|
LOCK_TEST_WITH_RETURN(dev, file_priv);
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
if (!dev_priv) {
|
|
|
|
DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
result = i915_emit_irq(dev);
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
|
2004-08-27 03:14:30 -06:00
|
|
|
DRM_ERROR("copy_to_user\n");
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EFAULT;
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Doesn't need the hardware lock.
|
|
|
|
*/
|
2007-07-19 18:11:11 -06:00
|
|
|
int i915_irq_wait(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2004-06-10 06:45:38 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
|
|
|
struct drm_i915_irq_wait *irqwait = data;
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2004-08-27 03:14:30 -06:00
|
|
|
if (!dev_priv) {
|
|
|
|
DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
return i915_wait_irq(dev, irqwait->irq_seq);
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
2007-09-24 15:41:46 -06:00
|
|
|
void i915_enable_interrupt (struct drm_device *dev)
|
2006-06-20 18:15:10 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2007-12-04 07:36:36 -07:00
|
|
|
struct drm_output *o;
|
2006-06-20 18:15:10 -06:00
|
|
|
|
2006-10-18 09:33:19 -06:00
|
|
|
dev_priv->irq_enable_reg = USER_INT_FLAG;
|
2007-11-04 19:42:22 -07:00
|
|
|
|
2006-06-20 18:15:10 -06:00
|
|
|
if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
|
2006-09-28 11:13:59 -06:00
|
|
|
dev_priv->irq_enable_reg |= VSYNC_PIPEA_FLAG;
|
2006-06-20 18:15:10 -06:00
|
|
|
if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
|
2006-09-28 11:13:59 -06:00
|
|
|
dev_priv->irq_enable_reg |= VSYNC_PIPEB_FLAG;
|
2006-08-31 10:30:55 -06:00
|
|
|
|
2007-12-17 18:09:48 -07:00
|
|
|
if (IS_I9XX(dev) && dev->mode_config.num_output) {
|
|
|
|
dev_priv->irq_enable_reg |= HOTPLUG_FLAG;
|
2007-12-04 07:36:36 -07:00
|
|
|
|
|
|
|
/* Activate the CRT */
|
2007-12-17 18:09:48 -07:00
|
|
|
I915_WRITE(PORT_HOTPLUG_EN, CRT_HOTPLUG_INT_EN);
|
2007-12-04 07:36:36 -07:00
|
|
|
|
|
|
|
/* SDVOB */
|
|
|
|
o = intel_sdvo_find(dev, 1);
|
|
|
|
if (o && intel_sdvo_supports_hotplug(o)) {
|
|
|
|
intel_sdvo_set_hotplug(o, 1);
|
2007-12-17 18:09:48 -07:00
|
|
|
I915_WRITE(PORT_HOTPLUG_EN, SDVOB_HOTPLUG_INT_EN);
|
2007-12-04 07:36:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SDVOC */
|
|
|
|
o = intel_sdvo_find(dev, 0);
|
|
|
|
if (o && intel_sdvo_supports_hotplug(o)) {
|
|
|
|
intel_sdvo_set_hotplug(o, 1);
|
2007-12-17 18:09:48 -07:00
|
|
|
I915_WRITE(PORT_HOTPLUG_EN, SDVOC_HOTPLUG_INT_EN);
|
2007-12-04 07:36:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_I9XX(dev)) {
|
|
|
|
I915_WRITE(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
|
|
|
|
} else {
|
|
|
|
I915_WRITE16(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
DRM_DEBUG("HEN %08x\n",I915_READ(PORT_HOTPLUG_EN));
|
|
|
|
DRM_DEBUG("HST %08x\n",I915_READ(PORT_HOTPLUG_STAT));
|
|
|
|
DRM_DEBUG("IER %08x\n",I915_READ(I915REG_INT_ENABLE_R));
|
|
|
|
DRM_DEBUG("SDB %08x\n",I915_READ(SDVOB));
|
|
|
|
|
|
|
|
I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
|
|
|
|
|
2006-09-05 06:23:18 -06:00
|
|
|
dev_priv->irq_enabled = 1;
|
2006-06-20 18:15:10 -06:00
|
|
|
}
|
|
|
|
|
2006-06-19 14:15:53 -06:00
|
|
|
/* Set the vblank monitor pipe
|
|
|
|
*/
|
2007-07-19 18:11:11 -06:00
|
|
|
int i915_vblank_pipe_set(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2006-06-19 14:15:53 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
|
|
|
struct drm_i915_vblank_pipe *pipe = data;
|
2006-06-19 14:15:53 -06:00
|
|
|
|
|
|
|
if (!dev_priv) {
|
|
|
|
DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-06-19 14:15:53 -06:00
|
|
|
}
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
|
2007-11-04 19:42:22 -07:00
|
|
|
DRM_ERROR("%s called with invalid pipe 0x%x\n",
|
2007-07-19 18:11:11 -06:00
|
|
|
__FUNCTION__, pipe->pipe);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-08-31 10:30:55 -06:00
|
|
|
}
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
dev_priv->vblank_pipe = pipe->pipe;
|
2006-08-31 10:30:55 -06:00
|
|
|
|
|
|
|
i915_enable_interrupt (dev);
|
|
|
|
|
|
|
|
return 0;
|
2006-06-19 14:15:53 -06:00
|
|
|
}
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
int i915_vblank_pipe_get(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2006-06-19 14:15:53 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
|
|
|
struct drm_i915_vblank_pipe *pipe = data;
|
2006-06-19 14:15:53 -06:00
|
|
|
u16 flag;
|
|
|
|
|
|
|
|
if (!dev_priv) {
|
|
|
|
DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-06-19 14:15:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
flag = I915_READ(I915REG_INT_ENABLE_R);
|
2007-07-19 18:11:11 -06:00
|
|
|
pipe->pipe = 0;
|
2006-06-19 14:15:53 -06:00
|
|
|
if (flag & VSYNC_PIPEA_FLAG)
|
2007-07-19 18:11:11 -06:00
|
|
|
pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
|
2006-06-19 14:15:53 -06:00
|
|
|
if (flag & VSYNC_PIPEB_FLAG)
|
2007-07-19 18:11:11 -06:00
|
|
|
pipe->pipe |= DRM_I915_VBLANK_PIPE_B;
|
|
|
|
|
2006-06-19 14:15:53 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-25 11:01:05 -06:00
|
|
|
/**
|
|
|
|
* Schedule buffer swap at given vertical blank.
|
|
|
|
*/
|
2007-07-19 18:11:11 -06:00
|
|
|
int i915_vblank_swap(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2006-08-25 11:01:05 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
|
|
|
struct drm_i915_vblank_swap *swap = data;
|
|
|
|
struct drm_i915_vbl_swap *vbl_swap;
|
2007-09-11 04:48:46 -06:00
|
|
|
unsigned int pipe, seqtype, curseq, plane;
|
2006-10-02 07:33:19 -06:00
|
|
|
unsigned long irqflags;
|
2006-08-25 11:01:05 -06:00
|
|
|
struct list_head *list;
|
|
|
|
|
|
|
|
if (!dev_priv) {
|
|
|
|
DRM_ERROR("%s called with no initialization\n", __func__);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dev_priv->sarea_priv->rotation) {
|
|
|
|
DRM_DEBUG("Rotation not supported\n");
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
|
2007-02-22 09:21:18 -07:00
|
|
|
_DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS |
|
|
|
|
_DRM_VBLANK_FLIP)) {
|
2007-07-19 18:11:11 -06:00
|
|
|
DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-08-30 11:33:28 -06:00
|
|
|
}
|
|
|
|
|
2007-09-11 04:48:46 -06:00
|
|
|
plane = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
|
2007-09-12 09:55:33 -06:00
|
|
|
pipe = i915_get_pipe(dev, plane);
|
2006-08-30 11:33:28 -06:00
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
|
2006-08-30 11:33:28 -06:00
|
|
|
|
|
|
|
if (!(dev_priv->vblank_pipe & (1 << pipe))) {
|
|
|
|
DRM_ERROR("Invalid pipe %d\n", pipe);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
|
|
|
|
2007-09-18 14:03:22 -06:00
|
|
|
DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2007-09-18 14:03:22 -06:00
|
|
|
/* It makes no sense to schedule a swap for a drawable that doesn't have
|
|
|
|
* valid information at this point. E.g. this could mean that the X
|
|
|
|
* server is too old to push drawable information to the DRM, in which
|
|
|
|
* case all such swaps would become ineffective.
|
|
|
|
*/
|
|
|
|
if (!drm_get_drawable_info(dev, swap->drawable)) {
|
|
|
|
DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
|
|
|
|
DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable);
|
|
|
|
return -EINVAL;
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
|
|
|
|
2007-09-18 14:03:22 -06:00
|
|
|
DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-08-30 11:33:28 -06:00
|
|
|
curseq = atomic_read(pipe ? &dev->vbl_received2 : &dev->vbl_received);
|
|
|
|
|
2006-09-13 00:59:35 -06:00
|
|
|
if (seqtype == _DRM_VBLANK_RELATIVE)
|
2007-07-19 18:11:11 -06:00
|
|
|
swap->sequence += curseq;
|
2006-09-13 00:59:35 -06:00
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
if ((curseq - swap->sequence) <= (1<<23)) {
|
|
|
|
if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) {
|
|
|
|
swap->sequence = curseq + 1;
|
2006-09-13 00:59:35 -06:00
|
|
|
} else {
|
2006-08-30 11:33:28 -06:00
|
|
|
DRM_DEBUG("Missed target sequence\n");
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2006-08-30 11:33:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
if (swap->seqtype & _DRM_VBLANK_FLIP) {
|
|
|
|
swap->sequence--;
|
2007-02-22 09:21:18 -07:00
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
if ((curseq - swap->sequence) <= (1<<23)) {
|
2007-07-15 19:22:15 -06:00
|
|
|
struct drm_drawable_info *drw;
|
2007-02-22 09:21:18 -07:00
|
|
|
|
2007-07-20 07:39:25 -06:00
|
|
|
LOCK_TEST_WITH_RETURN(dev, file_priv);
|
2007-02-22 09:21:18 -07:00
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK_IRQSAVE(&dev->drw_lock, irqflags);
|
2007-02-22 09:21:18 -07:00
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
drw = drm_get_drawable_info(dev, swap->drawable);
|
2007-02-22 09:21:18 -07:00
|
|
|
|
|
|
|
if (!drw) {
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock,
|
|
|
|
irqflags);
|
2007-02-22 09:21:18 -07:00
|
|
|
DRM_DEBUG("Invalid drawable ID %d\n",
|
2007-07-19 18:11:11 -06:00
|
|
|
swap->drawable);
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EINVAL;
|
2007-02-22 09:21:18 -07:00
|
|
|
}
|
|
|
|
|
2007-09-11 04:48:46 -06:00
|
|
|
i915_dispatch_vsync_flip(dev, drw, plane);
|
2007-02-22 09:21:18 -07:00
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK_IRQRESTORE(&dev->drw_lock, irqflags);
|
2007-02-22 09:21:18 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
|
2006-09-13 00:59:35 -06:00
|
|
|
|
2006-08-25 11:01:05 -06:00
|
|
|
list_for_each(list, &dev_priv->vbl_swaps.head) {
|
2007-09-24 15:41:46 -06:00
|
|
|
vbl_swap = list_entry(list, struct drm_i915_vbl_swap, head);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
if (vbl_swap->drw_id == swap->drawable &&
|
2007-09-11 04:48:46 -06:00
|
|
|
vbl_swap->plane == plane &&
|
2007-07-19 18:11:11 -06:00
|
|
|
vbl_swap->sequence == swap->sequence) {
|
|
|
|
vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
|
2006-08-25 11:01:05 -06:00
|
|
|
DRM_DEBUG("Already scheduled\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2006-09-01 03:48:07 -06:00
|
|
|
if (dev_priv->swaps_pending >= 100) {
|
|
|
|
DRM_DEBUG("Too many swaps queued\n");
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EBUSY;
|
2006-09-01 03:48:07 -06:00
|
|
|
}
|
|
|
|
|
2007-10-14 05:19:13 -06:00
|
|
|
vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
|
|
|
if (!vbl_swap) {
|
|
|
|
DRM_ERROR("Failed to allocate memory to queue swap\n");
|
2007-07-19 18:00:17 -06:00
|
|
|
return -ENOMEM;
|
2006-08-25 11:01:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
2007-07-19 18:11:11 -06:00
|
|
|
vbl_swap->drw_id = swap->drawable;
|
2007-09-11 04:48:46 -06:00
|
|
|
vbl_swap->plane = plane;
|
2007-07-19 18:11:11 -06:00
|
|
|
vbl_swap->sequence = swap->sequence;
|
|
|
|
vbl_swap->flip = (swap->seqtype & _DRM_VBLANK_FLIP);
|
2007-02-22 09:21:18 -07:00
|
|
|
|
|
|
|
if (vbl_swap->flip)
|
2007-07-19 18:11:11 -06:00
|
|
|
swap->sequence++;
|
2006-08-25 11:01:05 -06:00
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINLOCK_IRQSAVE(&dev_priv->swaps_lock, irqflags);
|
2006-08-25 11:01:05 -06:00
|
|
|
|
|
|
|
list_add_tail((struct list_head *)vbl_swap, &dev_priv->vbl_swaps.head);
|
|
|
|
dev_priv->swaps_pending++;
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPINUNLOCK_IRQRESTORE(&dev_priv->swaps_lock, irqflags);
|
2006-08-30 11:33:28 -06:00
|
|
|
|
2006-08-25 11:01:05 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-10 06:45:38 -06:00
|
|
|
/* drm_dma.h hooks
|
|
|
|
*/
|
2007-07-15 20:32:51 -06:00
|
|
|
void i915_driver_irq_preinstall(struct drm_device * dev)
|
2004-08-27 03:14:30 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2006-08-21 13:36:00 -06:00
|
|
|
I915_WRITE16(I915REG_HWSTAM, 0xeffe);
|
2007-12-04 07:36:36 -07:00
|
|
|
if (IS_I9XX(dev)) {
|
|
|
|
I915_WRITE(I915REG_INT_MASK_R, 0x0);
|
|
|
|
I915_WRITE(I915REG_INT_ENABLE_R, 0x0);
|
|
|
|
} else {
|
|
|
|
I915_WRITE16(I915REG_INT_MASK_R, 0x0);
|
|
|
|
I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
|
|
|
|
}
|
|
|
|
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
void i915_driver_irq_postinstall(struct drm_device * dev)
|
2004-08-27 03:14:30 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2004-06-10 06:45:38 -06:00
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPININIT(&dev_priv->swaps_lock, "swap");
|
2006-10-18 09:33:19 -06:00
|
|
|
INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
|
|
|
|
dev_priv->swaps_pending = 0;
|
|
|
|
|
2007-07-18 15:22:40 -06:00
|
|
|
DRM_SPININIT(&dev_priv->user_irq_lock, "userirq");
|
2006-09-28 11:13:59 -06:00
|
|
|
dev_priv->user_irq_refcount = 0;
|
|
|
|
|
2006-06-20 18:15:10 -06:00
|
|
|
i915_enable_interrupt(dev);
|
2004-06-10 06:45:38 -06:00
|
|
|
DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
|
2006-08-29 10:40:08 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the hardware status page IRQ location.
|
|
|
|
*/
|
|
|
|
|
2007-11-05 18:32:58 -07:00
|
|
|
I915_WRITE(I915REG_INSTPM, (1 << 5) | (1 << 21));
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
void i915_driver_irq_uninstall(struct drm_device * dev)
|
2004-08-27 03:14:30 -06:00
|
|
|
{
|
2007-09-24 15:41:46 -06:00
|
|
|
struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
|
2007-12-04 07:36:36 -07:00
|
|
|
u32 temp;
|
2007-11-05 18:32:58 -07:00
|
|
|
|
2004-06-10 06:45:38 -06:00
|
|
|
if (!dev_priv)
|
|
|
|
return;
|
|
|
|
|
2006-09-05 06:23:18 -06:00
|
|
|
dev_priv->irq_enabled = 0;
|
2006-02-17 21:13:36 -07:00
|
|
|
|
2007-12-04 07:36:36 -07:00
|
|
|
|
|
|
|
if(IS_I9XX(dev)) {
|
|
|
|
I915_WRITE(I915REG_HWSTAM, 0xffffffff);
|
|
|
|
I915_WRITE(I915REG_INT_MASK_R, 0xffffffff);
|
|
|
|
I915_WRITE(I915REG_INT_ENABLE_R, 0x0);
|
|
|
|
|
|
|
|
temp = I915_READ(I915REG_INT_IDENTITY_R);
|
|
|
|
I915_WRITE(I915REG_INT_IDENTITY_R, temp);
|
|
|
|
} else {
|
|
|
|
I915_WRITE16(I915REG_HWSTAM, 0xffff);
|
|
|
|
I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
|
|
|
|
I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
|
|
|
|
|
|
|
|
temp = I915_READ16(I915REG_INT_IDENTITY_R);
|
|
|
|
I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
|
|
|
|
}
|
2004-06-10 06:45:38 -06:00
|
|
|
}
|