Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* i915_dma.c -- DMA support for the I915 -*- linux-c -*- |
| 2 | */ |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 3 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 5 | * All Rights Reserved. |
Dave Airlie | bc54fd1 | 2005-06-23 22:46:46 +1000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sub license, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial portions |
| 17 | * of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 22 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | * |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 27 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "drmP.h" |
| 32 | #include "drm.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 33 | #include "drm_crtc_helper.h" |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 34 | #include "drm_fb_helper.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 35 | #include "intel_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "i915_drm.h" |
| 37 | #include "i915_drv.h" |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame] | 38 | #include "i915_trace.h" |
Jordan Crouse | dcdb167 | 2010-05-27 13:40:25 -0600 | [diff] [blame] | 39 | #include <linux/pci.h> |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 40 | #include <linux/vgaarb.h> |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 41 | #include <linux/acpi.h> |
| 42 | #include <linux/pnp.h> |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 43 | #include <linux/vga_switcheroo.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 45 | #include <acpi/video.h> |
Adam Jackson | 9e984bc1 | 2012-03-14 11:22:11 -0400 | [diff] [blame] | 46 | #include <asm/pat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Daniel Vetter | 09422b2 | 2012-04-26 23:28:10 +0200 | [diff] [blame] | 48 | #define LP_RING(d) (&((struct drm_i915_private *)(d))->ring[RCS]) |
| 49 | |
| 50 | #define BEGIN_LP_RING(n) \ |
| 51 | intel_ring_begin(LP_RING(dev_priv), (n)) |
| 52 | |
| 53 | #define OUT_RING(x) \ |
| 54 | intel_ring_emit(LP_RING(dev_priv), x) |
| 55 | |
| 56 | #define ADVANCE_LP_RING() \ |
| 57 | intel_ring_advance(LP_RING(dev_priv)) |
| 58 | |
| 59 | /** |
| 60 | * Lock test for when it's just for synchronization of ring access. |
| 61 | * |
| 62 | * In that case, we don't need to do it when GEM is initialized as nobody else |
| 63 | * has access to the ring. |
| 64 | */ |
| 65 | #define RING_LOCK_TEST_WITH_RETURN(dev, file) do { \ |
| 66 | if (LP_RING(dev->dev_private)->obj == NULL) \ |
| 67 | LOCK_TEST_WITH_RETURN(dev, file); \ |
| 68 | } while (0) |
| 69 | |
Daniel Vetter | 316d388 | 2012-04-26 23:28:15 +0200 | [diff] [blame] | 70 | static inline u32 |
| 71 | intel_read_legacy_status_page(struct drm_i915_private *dev_priv, int reg) |
| 72 | { |
| 73 | if (I915_NEED_GFX_HWS(dev_priv->dev)) |
| 74 | return ioread32(dev_priv->dri1.gfx_hws_cpu_addr + reg); |
| 75 | else |
| 76 | return intel_read_status_page(LP_RING(dev_priv), reg); |
| 77 | } |
| 78 | |
| 79 | #define READ_HWSP(dev_priv, reg) intel_read_legacy_status_page(dev_priv, reg) |
Daniel Vetter | 09422b2 | 2012-04-26 23:28:10 +0200 | [diff] [blame] | 80 | #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX) |
| 81 | #define I915_BREADCRUMB_INDEX 0x21 |
| 82 | |
Daniel Vetter | d05c617 | 2012-04-26 23:28:09 +0200 | [diff] [blame] | 83 | void i915_update_dri1_breadcrumb(struct drm_device *dev) |
| 84 | { |
| 85 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 86 | struct drm_i915_master_private *master_priv; |
| 87 | |
| 88 | if (dev->primary->master) { |
| 89 | master_priv = dev->primary->master->driver_priv; |
| 90 | if (master_priv->sarea_priv) |
| 91 | master_priv->sarea_priv->last_dispatch = |
| 92 | READ_BREADCRUMB(dev_priv); |
| 93 | } |
| 94 | } |
| 95 | |
Chris Wilson | 4cbf74c | 2011-02-25 22:26:23 +0000 | [diff] [blame] | 96 | static void i915_write_hws_pga(struct drm_device *dev) |
| 97 | { |
| 98 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 99 | u32 addr; |
| 100 | |
| 101 | addr = dev_priv->status_page_dmah->busaddr; |
| 102 | if (INTEL_INFO(dev)->gen >= 4) |
| 103 | addr |= (dev_priv->status_page_dmah->busaddr >> 28) & 0xf0; |
| 104 | I915_WRITE(HWS_PGA, addr); |
| 105 | } |
| 106 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 107 | /** |
| 108 | * Sets up the hardware status page for devices that need a physical address |
| 109 | * in the register. |
| 110 | */ |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 111 | static int i915_init_phys_hws(struct drm_device *dev) |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 112 | { |
| 113 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 114 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 115 | /* Program Hardware Status Page */ |
| 116 | dev_priv->status_page_dmah = |
Zhenyu Wang | e6be8d9 | 2010-01-05 11:25:05 +0800 | [diff] [blame] | 117 | drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 118 | |
| 119 | if (!dev_priv->status_page_dmah) { |
| 120 | DRM_ERROR("Can not allocate hardware status page\n"); |
| 121 | return -ENOMEM; |
| 122 | } |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 123 | |
Keith Packard | f323470 | 2011-07-22 10:44:39 -0700 | [diff] [blame] | 124 | memset_io((void __force __iomem *)dev_priv->status_page_dmah->vaddr, |
| 125 | 0, PAGE_SIZE); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 126 | |
Chris Wilson | 4cbf74c | 2011-02-25 22:26:23 +0000 | [diff] [blame] | 127 | i915_write_hws_pga(dev); |
Zhenyu Wang | 9b974cc | 2010-01-05 11:25:06 +0800 | [diff] [blame] | 128 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 129 | DRM_DEBUG_DRIVER("Enabled hardware status page\n"); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Frees the hardware status page, whether it's a physical address or a virtual |
| 135 | * address set up by the X Server. |
| 136 | */ |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 137 | static void i915_free_hws(struct drm_device *dev) |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 138 | { |
| 139 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 140 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
| 141 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 142 | if (dev_priv->status_page_dmah) { |
| 143 | drm_pci_free(dev, dev_priv->status_page_dmah); |
| 144 | dev_priv->status_page_dmah = NULL; |
| 145 | } |
| 146 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 147 | if (ring->status_page.gfx_addr) { |
| 148 | ring->status_page.gfx_addr = 0; |
Daniel Vetter | 316d388 | 2012-04-26 23:28:15 +0200 | [diff] [blame] | 149 | iounmap(dev_priv->dri1.gfx_hws_cpu_addr); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* Need to rewrite hardware status page */ |
| 153 | I915_WRITE(HWS_PGA, 0x1ffff000); |
| 154 | } |
| 155 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 156 | void i915_kernel_lost_context(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 159 | struct drm_i915_master_private *master_priv; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 160 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 162 | /* |
| 163 | * We should never lose context on the ring with modesetting |
| 164 | * as we don't expose it to userspace |
| 165 | */ |
| 166 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 167 | return; |
| 168 | |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 169 | ring->head = I915_READ_HEAD(ring) & HEAD_ADDR; |
| 170 | ring->tail = I915_READ_TAIL(ring) & TAIL_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | ring->space = ring->head - (ring->tail + 8); |
| 172 | if (ring->space < 0) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 173 | ring->space += ring->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 175 | if (!dev->primary->master) |
| 176 | return; |
| 177 | |
| 178 | master_priv = dev->primary->master->driver_priv; |
| 179 | if (ring->head == ring->tail && master_priv->sarea_priv) |
| 180 | master_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 183 | static int i915_dma_cleanup(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 185 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 186 | int i; |
| 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 189 | * may not have been called from userspace and after dev_private |
| 190 | * is freed, it's too late. |
| 191 | */ |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 192 | if (dev->irq_enabled) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 193 | drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Dan Carpenter | ee0c6bf | 2010-06-23 13:19:55 +0200 | [diff] [blame] | 195 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 196 | for (i = 0; i < I915_NUM_RINGS; i++) |
| 197 | intel_cleanup_ring_buffer(&dev_priv->ring[i]); |
Dan Carpenter | ee0c6bf | 2010-06-23 13:19:55 +0200 | [diff] [blame] | 198 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 200 | /* Clear the HWS virtual address at teardown */ |
| 201 | if (I915_NEED_GFX_HWS(dev)) |
| 202 | i915_free_hws(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 207 | static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 209 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 210 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 211 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Dave Airlie | 3a03ac1 | 2009-01-11 09:03:49 +1000 | [diff] [blame] | 213 | master_priv->sarea = drm_getsarea(dev); |
| 214 | if (master_priv->sarea) { |
| 215 | master_priv->sarea_priv = (drm_i915_sarea_t *) |
| 216 | ((u8 *)master_priv->sarea->handle + init->sarea_priv_offset); |
| 217 | } else { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 218 | DRM_DEBUG_DRIVER("sarea not found assuming DRI2 userspace\n"); |
Dave Airlie | 3a03ac1 | 2009-01-11 09:03:49 +1000 | [diff] [blame] | 219 | } |
| 220 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 221 | if (init->ring_size != 0) { |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 222 | if (LP_RING(dev_priv)->obj != NULL) { |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 223 | i915_dma_cleanup(dev); |
| 224 | DRM_ERROR("Client tried to initialize ringbuffer in " |
| 225 | "GEM mode\n"); |
| 226 | return -EINVAL; |
| 227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 229 | ret = intel_render_ring_init_dri(dev, |
| 230 | init->ring_start, |
| 231 | init->ring_size); |
| 232 | if (ret) { |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 233 | i915_dma_cleanup(dev); |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 234 | return ret; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Daniel Vetter | 5d985ac | 2012-08-12 19:27:13 +0200 | [diff] [blame] | 238 | dev_priv->dri1.cpp = init->cpp; |
| 239 | dev_priv->dri1.back_offset = init->back_offset; |
| 240 | dev_priv->dri1.front_offset = init->front_offset; |
| 241 | dev_priv->dri1.current_page = 0; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 242 | if (master_priv->sarea_priv) |
| 243 | master_priv->sarea_priv->pf_current_page = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | /* Allow hardware batchbuffers unless told otherwise. |
| 246 | */ |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 247 | dev_priv->dri1.allow_batchbuffer = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 252 | static int i915_dma_resume(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
| 254 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 255 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 257 | DRM_DEBUG_DRIVER("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Daniel Vetter | 4225d0f | 2012-04-26 23:28:16 +0200 | [diff] [blame] | 259 | if (ring->virtual_start == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | DRM_ERROR("can not ioremap virtual address for" |
| 261 | " ring buffer\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 262 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* Program Hardware Status Page */ |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 266 | if (!ring->status_page.page_addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | DRM_ERROR("Can not find hardware status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 268 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 270 | DRM_DEBUG_DRIVER("hw status page @ %p\n", |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 271 | ring->status_page.page_addr); |
| 272 | if (ring->status_page.gfx_addr != 0) |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 273 | intel_ring_setup_status_page(ring); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 274 | else |
Chris Wilson | 4cbf74c | 2011-02-25 22:26:23 +0000 | [diff] [blame] | 275 | i915_write_hws_pga(dev); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 276 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 277 | DRM_DEBUG_DRIVER("Enabled hardware status page\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 282 | static int i915_dma_init(struct drm_device *dev, void *data, |
| 283 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 285 | drm_i915_init_t *init = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | int retcode = 0; |
| 287 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 288 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 289 | return -ENODEV; |
| 290 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 291 | switch (init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | case I915_INIT_DMA: |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 293 | retcode = i915_initialize(dev, init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | break; |
| 295 | case I915_CLEANUP_DMA: |
| 296 | retcode = i915_dma_cleanup(dev); |
| 297 | break; |
| 298 | case I915_RESUME_DMA: |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 299 | retcode = i915_dma_resume(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | break; |
| 301 | default: |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 302 | retcode = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | break; |
| 304 | } |
| 305 | |
| 306 | return retcode; |
| 307 | } |
| 308 | |
| 309 | /* Implement basically the same security restrictions as hardware does |
| 310 | * for MI_BATCH_NON_SECURE. These can be made stricter at any time. |
| 311 | * |
| 312 | * Most of the calculations below involve calculating the size of a |
| 313 | * particular instruction. It's important to get the size right as |
| 314 | * that tells us where the next instruction to check is. Any illegal |
| 315 | * instruction detected will be given a size of zero, which is a |
| 316 | * signal to abort the rest of the buffer. |
| 317 | */ |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 318 | static int validate_cmd(int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
| 320 | switch (((cmd >> 29) & 0x7)) { |
| 321 | case 0x0: |
| 322 | switch ((cmd >> 23) & 0x3f) { |
| 323 | case 0x0: |
| 324 | return 1; /* MI_NOOP */ |
| 325 | case 0x4: |
| 326 | return 1; /* MI_FLUSH */ |
| 327 | default: |
| 328 | return 0; /* disallow everything else */ |
| 329 | } |
| 330 | break; |
| 331 | case 0x1: |
| 332 | return 0; /* reserved */ |
| 333 | case 0x2: |
| 334 | return (cmd & 0xff) + 2; /* 2d commands */ |
| 335 | case 0x3: |
| 336 | if (((cmd >> 24) & 0x1f) <= 0x18) |
| 337 | return 1; |
| 338 | |
| 339 | switch ((cmd >> 24) & 0x1f) { |
| 340 | case 0x1c: |
| 341 | return 1; |
| 342 | case 0x1d: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 343 | switch ((cmd >> 16) & 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | case 0x3: |
| 345 | return (cmd & 0x1f) + 2; |
| 346 | case 0x4: |
| 347 | return (cmd & 0xf) + 2; |
| 348 | default: |
| 349 | return (cmd & 0xffff) + 2; |
| 350 | } |
| 351 | case 0x1e: |
| 352 | if (cmd & (1 << 23)) |
| 353 | return (cmd & 0xffff) + 1; |
| 354 | else |
| 355 | return 1; |
| 356 | case 0x1f: |
| 357 | if ((cmd & (1 << 23)) == 0) /* inline vertices */ |
| 358 | return (cmd & 0x1ffff) + 2; |
| 359 | else if (cmd & (1 << 17)) /* indirect random */ |
| 360 | if ((cmd & 0xffff) == 0) |
| 361 | return 0; /* unknown length, too hard */ |
| 362 | else |
| 363 | return (((cmd & 0xffff) + 1) / 2) + 1; |
| 364 | else |
| 365 | return 2; /* indirect sequential */ |
| 366 | default: |
| 367 | return 0; |
| 368 | } |
| 369 | default: |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 376 | static int i915_emit_cmds(struct drm_device * dev, int *buffer, int dwords) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 379 | int i, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 381 | if ((dwords+1) * sizeof(int) >= LP_RING(dev_priv)->size - 8) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 382 | return -EINVAL; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | for (i = 0; i < dwords;) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 385 | int sz = validate_cmd(buffer[i]); |
| 386 | if (sz == 0 || i + sz > dwords) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 387 | return -EINVAL; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 388 | i += sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 391 | ret = BEGIN_LP_RING((dwords+1)&~1); |
| 392 | if (ret) |
| 393 | return ret; |
| 394 | |
| 395 | for (i = 0; i < dwords; i++) |
| 396 | OUT_RING(buffer[i]); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 397 | if (dwords & 1) |
| 398 | OUT_RING(0); |
| 399 | |
| 400 | ADVANCE_LP_RING(); |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 405 | int |
| 406 | i915_emit_box(struct drm_device *dev, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 407 | struct drm_clip_rect *box, |
| 408 | int DR1, int DR4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 410 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 411 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 413 | if (box->y2 <= box->y1 || box->x2 <= box->x1 || |
| 414 | box->y2 <= 0 || box->x2 <= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | DRM_ERROR("Bad box %d,%d..%d,%d\n", |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 416 | box->x1, box->y1, box->x2, box->y2); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 417 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 420 | if (INTEL_INFO(dev)->gen >= 4) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 421 | ret = BEGIN_LP_RING(4); |
| 422 | if (ret) |
| 423 | return ret; |
| 424 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 425 | OUT_RING(GFX_OP_DRAWRECT_INFO_I965); |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 426 | OUT_RING((box->x1 & 0xffff) | (box->y1 << 16)); |
| 427 | OUT_RING(((box->x2 - 1) & 0xffff) | ((box->y2 - 1) << 16)); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 428 | OUT_RING(DR4); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 429 | } else { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 430 | ret = BEGIN_LP_RING(6); |
| 431 | if (ret) |
| 432 | return ret; |
| 433 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 434 | OUT_RING(GFX_OP_DRAWRECT_INFO); |
| 435 | OUT_RING(DR1); |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 436 | OUT_RING((box->x1 & 0xffff) | (box->y1 << 16)); |
| 437 | OUT_RING(((box->x2 - 1) & 0xffff) | ((box->y2 - 1) << 16)); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 438 | OUT_RING(DR4); |
| 439 | OUT_RING(0); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 440 | } |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 441 | ADVANCE_LP_RING(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | return 0; |
| 444 | } |
| 445 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 446 | /* XXX: Emitting the counter should really be moved to part of the IRQ |
| 447 | * emit. For now, do it in both places: |
| 448 | */ |
| 449 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 450 | static void i915_emit_breadcrumb(struct drm_device *dev) |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 451 | { |
| 452 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 453 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 454 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 455 | dev_priv->counter++; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 456 | if (dev_priv->counter > 0x7FFFFFFFUL) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 457 | dev_priv->counter = 0; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 458 | if (master_priv->sarea_priv) |
| 459 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 460 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 461 | if (BEGIN_LP_RING(4) == 0) { |
| 462 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 463 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 464 | OUT_RING(dev_priv->counter); |
| 465 | OUT_RING(0); |
| 466 | ADVANCE_LP_RING(); |
| 467 | } |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 468 | } |
| 469 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 470 | static int i915_dispatch_cmdbuffer(struct drm_device * dev, |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 471 | drm_i915_cmdbuffer_t *cmd, |
| 472 | struct drm_clip_rect *cliprects, |
| 473 | void *cmdbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
| 475 | int nbox = cmd->num_cliprects; |
| 476 | int i = 0, count, ret; |
| 477 | |
| 478 | if (cmd->sz & 0x3) { |
| 479 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 480 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | i915_kernel_lost_context(dev); |
| 484 | |
| 485 | count = nbox ? nbox : 1; |
| 486 | |
| 487 | for (i = 0; i < count; i++) { |
| 488 | if (i < nbox) { |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 489 | ret = i915_emit_box(dev, &cliprects[i], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | cmd->DR1, cmd->DR4); |
| 491 | if (ret) |
| 492 | return ret; |
| 493 | } |
| 494 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 495 | ret = i915_emit_cmds(dev, cmdbuf, cmd->sz / 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | if (ret) |
| 497 | return ret; |
| 498 | } |
| 499 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 500 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 504 | static int i915_dispatch_batchbuffer(struct drm_device * dev, |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 505 | drm_i915_batchbuffer_t * batch, |
| 506 | struct drm_clip_rect *cliprects) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 508 | struct drm_i915_private *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | int nbox = batch->num_cliprects; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 510 | int i, count, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | if ((batch->start | batch->used) & 0x7) { |
| 513 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 514 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | i915_kernel_lost_context(dev); |
| 518 | |
| 519 | count = nbox ? nbox : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | for (i = 0; i < count; i++) { |
| 521 | if (i < nbox) { |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 522 | ret = i915_emit_box(dev, &cliprects[i], |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 523 | batch->DR1, batch->DR4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (ret) |
| 525 | return ret; |
| 526 | } |
| 527 | |
Keith Packard | 0790d5e | 2008-07-30 12:28:47 -0700 | [diff] [blame] | 528 | if (!IS_I830(dev) && !IS_845G(dev)) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 529 | ret = BEGIN_LP_RING(2); |
| 530 | if (ret) |
| 531 | return ret; |
| 532 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 533 | if (INTEL_INFO(dev)->gen >= 4) { |
Dave Airlie | 21f1628 | 2007-08-07 09:09:51 +1000 | [diff] [blame] | 534 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965); |
| 535 | OUT_RING(batch->start); |
| 536 | } else { |
| 537 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6)); |
| 538 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } else { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 541 | ret = BEGIN_LP_RING(4); |
| 542 | if (ret) |
| 543 | return ret; |
| 544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | OUT_RING(MI_BATCH_BUFFER); |
| 546 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 547 | OUT_RING(batch->start + batch->used - 4); |
| 548 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 550 | ADVANCE_LP_RING(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Zou Nan hai | 1cafd34 | 2010-06-25 13:40:24 +0800 | [diff] [blame] | 553 | |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 554 | if (IS_G4X(dev) || IS_GEN5(dev)) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 555 | if (BEGIN_LP_RING(2) == 0) { |
| 556 | OUT_RING(MI_FLUSH | MI_NO_WRITE_FLUSH | MI_INVALIDATE_ISP); |
| 557 | OUT_RING(MI_NOOP); |
| 558 | ADVANCE_LP_RING(); |
| 559 | } |
Zou Nan hai | 1cafd34 | 2010-06-25 13:40:24 +0800 | [diff] [blame] | 560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 562 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return 0; |
| 564 | } |
| 565 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 566 | static int i915_dispatch_flip(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
| 568 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 569 | struct drm_i915_master_private *master_priv = |
| 570 | dev->primary->master->driver_priv; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 571 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 573 | if (!master_priv->sarea_priv) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 574 | return -EINVAL; |
| 575 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 576 | DRM_DEBUG_DRIVER("%s: page=%d pfCurrentPage=%d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 577 | __func__, |
Daniel Vetter | 5d985ac | 2012-08-12 19:27:13 +0200 | [diff] [blame] | 578 | dev_priv->dri1.current_page, |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 579 | master_priv->sarea_priv->pf_current_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 581 | i915_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 583 | ret = BEGIN_LP_RING(10); |
| 584 | if (ret) |
| 585 | return ret; |
| 586 | |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 587 | OUT_RING(MI_FLUSH | MI_READ_FLUSH); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 588 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 590 | OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP); |
| 591 | OUT_RING(0); |
Daniel Vetter | 5d985ac | 2012-08-12 19:27:13 +0200 | [diff] [blame] | 592 | if (dev_priv->dri1.current_page == 0) { |
| 593 | OUT_RING(dev_priv->dri1.back_offset); |
| 594 | dev_priv->dri1.current_page = 1; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 595 | } else { |
Daniel Vetter | 5d985ac | 2012-08-12 19:27:13 +0200 | [diff] [blame] | 596 | OUT_RING(dev_priv->dri1.front_offset); |
| 597 | dev_priv->dri1.current_page = 0; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 598 | } |
| 599 | OUT_RING(0); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 600 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 601 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP); |
| 602 | OUT_RING(0); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 603 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 604 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 605 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 606 | master_priv->sarea_priv->last_enqueue = dev_priv->counter++; |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 607 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 608 | if (BEGIN_LP_RING(4) == 0) { |
| 609 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 610 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 611 | OUT_RING(dev_priv->counter); |
| 612 | OUT_RING(0); |
| 613 | ADVANCE_LP_RING(); |
| 614 | } |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 615 | |
Daniel Vetter | 5d985ac | 2012-08-12 19:27:13 +0200 | [diff] [blame] | 616 | master_priv->sarea_priv->pf_current_page = dev_priv->dri1.current_page; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 617 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 620 | static int i915_quiescent(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 622 | struct intel_ring_buffer *ring = LP_RING(dev->dev_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | i915_kernel_lost_context(dev); |
Ben Widawsky | 96f298a | 2011-03-19 18:14:27 -0700 | [diff] [blame] | 625 | return intel_wait_ring_idle(ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 628 | static int i915_flush_ioctl(struct drm_device *dev, void *data, |
| 629 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 631 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 633 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 634 | return -ENODEV; |
| 635 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 636 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 637 | |
| 638 | mutex_lock(&dev->struct_mutex); |
| 639 | ret = i915_quiescent(dev); |
| 640 | mutex_unlock(&dev->struct_mutex); |
| 641 | |
| 642 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 645 | static int i915_batchbuffer(struct drm_device *dev, void *data, |
| 646 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 649 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 651 | master_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 652 | drm_i915_batchbuffer_t *batch = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | int ret; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 654 | struct drm_clip_rect *cliprects = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 656 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 657 | return -ENODEV; |
| 658 | |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 659 | if (!dev_priv->dri1.allow_batchbuffer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | DRM_ERROR("Batchbuffer ioctl disabled\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 661 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 664 | DRM_DEBUG_DRIVER("i915 batchbuffer, start %x used %d cliprects %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 665 | batch->start, batch->used, batch->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 667 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 669 | if (batch->num_cliprects < 0) |
| 670 | return -EINVAL; |
| 671 | |
| 672 | if (batch->num_cliprects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 673 | cliprects = kcalloc(batch->num_cliprects, |
| 674 | sizeof(struct drm_clip_rect), |
| 675 | GFP_KERNEL); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 676 | if (cliprects == NULL) |
| 677 | return -ENOMEM; |
| 678 | |
| 679 | ret = copy_from_user(cliprects, batch->cliprects, |
| 680 | batch->num_cliprects * |
| 681 | sizeof(struct drm_clip_rect)); |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 682 | if (ret != 0) { |
| 683 | ret = -EFAULT; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 684 | goto fail_free; |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 685 | } |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 688 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 689 | ret = i915_dispatch_batchbuffer(dev, batch, cliprects); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 690 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 692 | if (sarea_priv) |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 693 | sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 694 | |
| 695 | fail_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 696 | kfree(cliprects); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | return ret; |
| 699 | } |
| 700 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 701 | static int i915_cmdbuffer(struct drm_device *dev, void *data, |
| 702 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 705 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 707 | master_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 708 | drm_i915_cmdbuffer_t *cmdbuf = data; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 709 | struct drm_clip_rect *cliprects = NULL; |
| 710 | void *batch_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | int ret; |
| 712 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 713 | DRM_DEBUG_DRIVER("i915 cmdbuffer, buf %p sz %d cliprects %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 714 | cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 716 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 717 | return -ENODEV; |
| 718 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 719 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 721 | if (cmdbuf->num_cliprects < 0) |
| 722 | return -EINVAL; |
| 723 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 724 | batch_data = kmalloc(cmdbuf->sz, GFP_KERNEL); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 725 | if (batch_data == NULL) |
| 726 | return -ENOMEM; |
| 727 | |
| 728 | ret = copy_from_user(batch_data, cmdbuf->buf, cmdbuf->sz); |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 729 | if (ret != 0) { |
| 730 | ret = -EFAULT; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 731 | goto fail_batch_free; |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 732 | } |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 733 | |
| 734 | if (cmdbuf->num_cliprects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 735 | cliprects = kcalloc(cmdbuf->num_cliprects, |
| 736 | sizeof(struct drm_clip_rect), GFP_KERNEL); |
Owain Ainsworth | a40e8d3 | 2010-02-09 14:25:55 +0000 | [diff] [blame] | 737 | if (cliprects == NULL) { |
| 738 | ret = -ENOMEM; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 739 | goto fail_batch_free; |
Owain Ainsworth | a40e8d3 | 2010-02-09 14:25:55 +0000 | [diff] [blame] | 740 | } |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 741 | |
| 742 | ret = copy_from_user(cliprects, cmdbuf->cliprects, |
| 743 | cmdbuf->num_cliprects * |
| 744 | sizeof(struct drm_clip_rect)); |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 745 | if (ret != 0) { |
| 746 | ret = -EFAULT; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 747 | goto fail_clip_free; |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 751 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 752 | ret = i915_dispatch_cmdbuffer(dev, cmdbuf, cliprects, batch_data); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 753 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | if (ret) { |
| 755 | DRM_ERROR("i915_dispatch_cmdbuffer failed\n"); |
Chris Wright | 355d7f3 | 2009-04-17 01:18:55 +0000 | [diff] [blame] | 756 | goto fail_clip_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 759 | if (sarea_priv) |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 760 | sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 761 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 762 | fail_clip_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 763 | kfree(cliprects); |
Chris Wright | 355d7f3 | 2009-04-17 01:18:55 +0000 | [diff] [blame] | 764 | fail_batch_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 765 | kfree(batch_data); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 766 | |
| 767 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Daniel Vetter | 9488867 | 2012-04-26 23:28:08 +0200 | [diff] [blame] | 770 | static int i915_emit_irq(struct drm_device * dev) |
| 771 | { |
| 772 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 773 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 774 | |
| 775 | i915_kernel_lost_context(dev); |
| 776 | |
| 777 | DRM_DEBUG_DRIVER("\n"); |
| 778 | |
| 779 | dev_priv->counter++; |
| 780 | if (dev_priv->counter > 0x7FFFFFFFUL) |
| 781 | dev_priv->counter = 1; |
| 782 | if (master_priv->sarea_priv) |
| 783 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
| 784 | |
| 785 | if (BEGIN_LP_RING(4) == 0) { |
| 786 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 787 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 788 | OUT_RING(dev_priv->counter); |
| 789 | OUT_RING(MI_USER_INTERRUPT); |
| 790 | ADVANCE_LP_RING(); |
| 791 | } |
| 792 | |
| 793 | return dev_priv->counter; |
| 794 | } |
| 795 | |
| 796 | static int i915_wait_irq(struct drm_device * dev, int irq_nr) |
| 797 | { |
| 798 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 799 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 800 | int ret = 0; |
| 801 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
| 802 | |
| 803 | DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr, |
| 804 | READ_BREADCRUMB(dev_priv)); |
| 805 | |
| 806 | if (READ_BREADCRUMB(dev_priv) >= irq_nr) { |
| 807 | if (master_priv->sarea_priv) |
| 808 | master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | if (master_priv->sarea_priv) |
| 813 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
| 814 | |
| 815 | if (ring->irq_get(ring)) { |
| 816 | DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ, |
| 817 | READ_BREADCRUMB(dev_priv) >= irq_nr); |
| 818 | ring->irq_put(ring); |
| 819 | } else if (wait_for(READ_BREADCRUMB(dev_priv) >= irq_nr, 3000)) |
| 820 | ret = -EBUSY; |
| 821 | |
| 822 | if (ret == -EBUSY) { |
| 823 | DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", |
| 824 | READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); |
| 825 | } |
| 826 | |
| 827 | return ret; |
| 828 | } |
| 829 | |
| 830 | /* Needs the lock as it touches the ring. |
| 831 | */ |
| 832 | static int i915_irq_emit(struct drm_device *dev, void *data, |
| 833 | struct drm_file *file_priv) |
| 834 | { |
| 835 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 836 | drm_i915_irq_emit_t *emit = data; |
| 837 | int result; |
| 838 | |
| 839 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 840 | return -ENODEV; |
| 841 | |
| 842 | if (!dev_priv || !LP_RING(dev_priv)->virtual_start) { |
| 843 | DRM_ERROR("called with no initialization\n"); |
| 844 | return -EINVAL; |
| 845 | } |
| 846 | |
| 847 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 848 | |
| 849 | mutex_lock(&dev->struct_mutex); |
| 850 | result = i915_emit_irq(dev); |
| 851 | mutex_unlock(&dev->struct_mutex); |
| 852 | |
| 853 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
| 854 | DRM_ERROR("copy_to_user\n"); |
| 855 | return -EFAULT; |
| 856 | } |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | /* Doesn't need the hardware lock. |
| 862 | */ |
| 863 | static int i915_irq_wait(struct drm_device *dev, void *data, |
| 864 | struct drm_file *file_priv) |
| 865 | { |
| 866 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 867 | drm_i915_irq_wait_t *irqwait = data; |
| 868 | |
| 869 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 870 | return -ENODEV; |
| 871 | |
| 872 | if (!dev_priv) { |
| 873 | DRM_ERROR("called with no initialization\n"); |
| 874 | return -EINVAL; |
| 875 | } |
| 876 | |
| 877 | return i915_wait_irq(dev, irqwait->irq_seq); |
| 878 | } |
| 879 | |
Daniel Vetter | d1c1edb | 2012-04-26 23:28:01 +0200 | [diff] [blame] | 880 | static int i915_vblank_pipe_get(struct drm_device *dev, void *data, |
| 881 | struct drm_file *file_priv) |
| 882 | { |
| 883 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 884 | drm_i915_vblank_pipe_t *pipe = data; |
| 885 | |
| 886 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 887 | return -ENODEV; |
| 888 | |
| 889 | if (!dev_priv) { |
| 890 | DRM_ERROR("called with no initialization\n"); |
| 891 | return -EINVAL; |
| 892 | } |
| 893 | |
| 894 | pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Schedule buffer swap at given vertical blank. |
| 901 | */ |
| 902 | static int i915_vblank_swap(struct drm_device *dev, void *data, |
| 903 | struct drm_file *file_priv) |
| 904 | { |
| 905 | /* The delayed swap mechanism was fundamentally racy, and has been |
| 906 | * removed. The model was that the client requested a delayed flip/swap |
| 907 | * from the kernel, then waited for vblank before continuing to perform |
| 908 | * rendering. The problem was that the kernel might wake the client |
| 909 | * up before it dispatched the vblank swap (since the lock has to be |
| 910 | * held while touching the ringbuffer), in which case the client would |
| 911 | * clear and start the next frame before the swap occurred, and |
| 912 | * flicker would occur in addition to likely missing the vblank. |
| 913 | * |
| 914 | * In the absence of this ioctl, userland falls back to a correct path |
| 915 | * of waiting for a vblank, then dispatching the swap on its own. |
| 916 | * Context switching to userland and back is plenty fast enough for |
| 917 | * meeting the requirements of vblank swapping. |
| 918 | */ |
| 919 | return -EINVAL; |
| 920 | } |
| 921 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 922 | static int i915_flip_bufs(struct drm_device *dev, void *data, |
| 923 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 925 | int ret; |
| 926 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 927 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 928 | return -ENODEV; |
| 929 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 930 | DRM_DEBUG_DRIVER("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 932 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 934 | mutex_lock(&dev->struct_mutex); |
| 935 | ret = i915_dispatch_flip(dev); |
| 936 | mutex_unlock(&dev->struct_mutex); |
| 937 | |
| 938 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 941 | static int i915_getparam(struct drm_device *dev, void *data, |
| 942 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 945 | drm_i915_getparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | int value; |
| 947 | |
| 948 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 949 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 950 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 953 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | case I915_PARAM_IRQ_ACTIVE: |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 955 | value = dev->pdev->irq ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | break; |
| 957 | case I915_PARAM_ALLOW_BATCHBUFFER: |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 958 | value = dev_priv->dri1.allow_batchbuffer ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | break; |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 960 | case I915_PARAM_LAST_DISPATCH: |
| 961 | value = READ_BREADCRUMB(dev_priv); |
| 962 | break; |
Kristian Høgsberg | ed4c9c4 | 2008-08-20 11:08:52 -0400 | [diff] [blame] | 963 | case I915_PARAM_CHIPSET_ID: |
| 964 | value = dev->pci_device; |
| 965 | break; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 966 | case I915_PARAM_HAS_GEM: |
Daniel Vetter | 2e895b1 | 2012-04-23 16:50:51 +0200 | [diff] [blame] | 967 | value = 1; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 968 | break; |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 969 | case I915_PARAM_NUM_FENCES_AVAIL: |
| 970 | value = dev_priv->num_fence_regs - dev_priv->fence_reg_start; |
| 971 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 972 | case I915_PARAM_HAS_OVERLAY: |
| 973 | value = dev_priv->overlay ? 1 : 0; |
| 974 | break; |
Jesse Barnes | e9560f7 | 2009-11-19 10:49:07 -0800 | [diff] [blame] | 975 | case I915_PARAM_HAS_PAGEFLIPPING: |
| 976 | value = 1; |
| 977 | break; |
Jesse Barnes | 76446ca | 2009-12-17 22:05:42 -0500 | [diff] [blame] | 978 | case I915_PARAM_HAS_EXECBUF2: |
| 979 | /* depends on GEM */ |
Daniel Vetter | 2e895b1 | 2012-04-23 16:50:51 +0200 | [diff] [blame] | 980 | value = 1; |
Jesse Barnes | 76446ca | 2009-12-17 22:05:42 -0500 | [diff] [blame] | 981 | break; |
Zou Nan hai | e3a815f | 2010-05-31 13:58:47 +0800 | [diff] [blame] | 982 | case I915_PARAM_HAS_BSD: |
Chris Wilson | edc912f | 2012-05-11 14:29:32 +0100 | [diff] [blame] | 983 | value = intel_ring_initialized(&dev_priv->ring[VCS]); |
Zou Nan hai | e3a815f | 2010-05-31 13:58:47 +0800 | [diff] [blame] | 984 | break; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 985 | case I915_PARAM_HAS_BLT: |
Chris Wilson | edc912f | 2012-05-11 14:29:32 +0100 | [diff] [blame] | 986 | value = intel_ring_initialized(&dev_priv->ring[BCS]); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 987 | break; |
Chris Wilson | a00b10c | 2010-09-24 21:15:47 +0100 | [diff] [blame] | 988 | case I915_PARAM_HAS_RELAXED_FENCING: |
| 989 | value = 1; |
| 990 | break; |
Daniel Vetter | bbf0c6b | 2010-12-05 11:30:40 +0100 | [diff] [blame] | 991 | case I915_PARAM_HAS_COHERENT_RINGS: |
| 992 | value = 1; |
| 993 | break; |
Chris Wilson | 72bfa19 | 2010-12-19 11:42:05 +0000 | [diff] [blame] | 994 | case I915_PARAM_HAS_EXEC_CONSTANTS: |
| 995 | value = INTEL_INFO(dev)->gen >= 4; |
| 996 | break; |
Chris Wilson | 271d81b | 2011-03-01 15:24:41 +0000 | [diff] [blame] | 997 | case I915_PARAM_HAS_RELAXED_DELTA: |
| 998 | value = 1; |
| 999 | break; |
Eric Anholt | ae662d3 | 2012-01-03 09:23:29 -0800 | [diff] [blame] | 1000 | case I915_PARAM_HAS_GEN7_SOL_RESET: |
| 1001 | value = 1; |
| 1002 | break; |
Eugeni Dodonov | 3d29b84 | 2012-01-17 14:43:53 -0200 | [diff] [blame] | 1003 | case I915_PARAM_HAS_LLC: |
| 1004 | value = HAS_LLC(dev); |
| 1005 | break; |
Daniel Vetter | 777ee96 | 2012-02-15 23:50:25 +0100 | [diff] [blame] | 1006 | case I915_PARAM_HAS_ALIASING_PPGTT: |
| 1007 | value = dev_priv->mm.aliasing_ppgtt ? 1 : 0; |
| 1008 | break; |
Ben Widawsky | 172cf15 | 2012-06-05 15:24:25 -0700 | [diff] [blame] | 1009 | case I915_PARAM_HAS_WAIT_TIMEOUT: |
| 1010 | value = 1; |
| 1011 | break; |
Chris Wilson | 2fedbff | 2012-08-08 10:23:22 +0100 | [diff] [blame] | 1012 | case I915_PARAM_HAS_SEMAPHORES: |
| 1013 | value = i915_semaphore_is_enabled(dev); |
| 1014 | break; |
Dave Airlie | ec6f1bb | 2012-08-16 10:15:34 +1000 | [diff] [blame] | 1015 | case I915_PARAM_HAS_PRIME_VMAP_FLUSH: |
| 1016 | value = 1; |
| 1017 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | default: |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1019 | DRM_DEBUG_DRIVER("Unknown parameter %d\n", |
Jesse Barnes | 76446ca | 2009-12-17 22:05:42 -0500 | [diff] [blame] | 1020 | param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1021 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1024 | if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | DRM_ERROR("DRM_COPY_TO_USER failed\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1026 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1032 | static int i915_setparam(struct drm_device *dev, void *data, |
| 1033 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1036 | drm_i915_setparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1039 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1040 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1043 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | case I915_SETPARAM_USE_MI_BATCHBUFFER_START: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | break; |
| 1046 | case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | break; |
| 1048 | case I915_SETPARAM_ALLOW_BATCHBUFFER: |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 1049 | dev_priv->dri1.allow_batchbuffer = param->value ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | break; |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 1051 | case I915_SETPARAM_NUM_USED_FENCES: |
| 1052 | if (param->value > dev_priv->num_fence_regs || |
| 1053 | param->value < 0) |
| 1054 | return -EINVAL; |
| 1055 | /* Userspace can use first N regs */ |
| 1056 | dev_priv->fence_reg_start = param->value; |
| 1057 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | default: |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1059 | DRM_DEBUG_DRIVER("unknown parameter %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 1060 | param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1061 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | return 0; |
| 1065 | } |
| 1066 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1067 | static int i915_set_status_page(struct drm_device *dev, void *data, |
| 1068 | struct drm_file *file_priv) |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1069 | { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1070 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1071 | drm_i915_hws_addr_t *hws = data; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1072 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1073 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 1074 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1075 | return -ENODEV; |
| 1076 | |
Zhenyu Wang | b39d50e | 2008-02-19 20:59:09 +1000 | [diff] [blame] | 1077 | if (!I915_NEED_GFX_HWS(dev)) |
| 1078 | return -EINVAL; |
| 1079 | |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1080 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1081 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1082 | return -EINVAL; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1083 | } |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1084 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1085 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 1086 | WARN(1, "tried to set status page when mode setting active\n"); |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1090 | DRM_DEBUG_DRIVER("set status page addr 0x%08x\n", (u32)hws->addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1091 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1092 | ring->status_page.gfx_addr = hws->addr & (0x1ffff<<12); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1093 | |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 1094 | dev_priv->dri1.gfx_hws_cpu_addr = |
| 1095 | ioremap_wc(dev_priv->mm.gtt_base_addr + hws->addr, 4096); |
Daniel Vetter | 316d388 | 2012-04-26 23:28:15 +0200 | [diff] [blame] | 1096 | if (dev_priv->dri1.gfx_hws_cpu_addr == NULL) { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1097 | i915_dma_cleanup(dev); |
Eric Anholt | e20f9c6 | 2010-05-26 14:51:06 -0700 | [diff] [blame] | 1098 | ring->status_page.gfx_addr = 0; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1099 | DRM_ERROR("can not ioremap virtual address for" |
| 1100 | " G33 hw status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1101 | return -ENOMEM; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1102 | } |
Daniel Vetter | 316d388 | 2012-04-26 23:28:15 +0200 | [diff] [blame] | 1103 | |
| 1104 | memset_io(dev_priv->dri1.gfx_hws_cpu_addr, 0, PAGE_SIZE); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1105 | I915_WRITE(HWS_PGA, ring->status_page.gfx_addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1106 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1107 | DRM_DEBUG_DRIVER("load hws HWS_PGA with gfx mem 0x%x\n", |
Eric Anholt | e20f9c6 | 2010-05-26 14:51:06 -0700 | [diff] [blame] | 1108 | ring->status_page.gfx_addr); |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1109 | DRM_DEBUG_DRIVER("load hws at %p\n", |
Eric Anholt | e20f9c6 | 2010-05-26 14:51:06 -0700 | [diff] [blame] | 1110 | ring->status_page.page_addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1111 | return 0; |
| 1112 | } |
| 1113 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1114 | static int i915_get_bridge_dev(struct drm_device *dev) |
| 1115 | { |
| 1116 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1117 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1118 | dev_priv->bridge_dev = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0)); |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1119 | if (!dev_priv->bridge_dev) { |
| 1120 | DRM_ERROR("bridge device not found\n"); |
| 1121 | return -1; |
| 1122 | } |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1126 | #define MCHBAR_I915 0x44 |
| 1127 | #define MCHBAR_I965 0x48 |
| 1128 | #define MCHBAR_SIZE (4*4096) |
| 1129 | |
| 1130 | #define DEVEN_REG 0x54 |
| 1131 | #define DEVEN_MCHBAR_EN (1 << 28) |
| 1132 | |
| 1133 | /* Allocate space for the MCH regs if needed, return nonzero on error */ |
| 1134 | static int |
| 1135 | intel_alloc_mchbar_resource(struct drm_device *dev) |
| 1136 | { |
| 1137 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1138 | int reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1139 | u32 temp_lo, temp_hi = 0; |
| 1140 | u64 mchbar_addr; |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1141 | int ret; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1142 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1143 | if (INTEL_INFO(dev)->gen >= 4) |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1144 | pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi); |
| 1145 | pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo); |
| 1146 | mchbar_addr = ((u64)temp_hi << 32) | temp_lo; |
| 1147 | |
| 1148 | /* If ACPI doesn't have it, assume we need to allocate it ourselves */ |
| 1149 | #ifdef CONFIG_PNP |
| 1150 | if (mchbar_addr && |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1151 | pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) |
| 1152 | return 0; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1153 | #endif |
| 1154 | |
| 1155 | /* Get some space for it */ |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1156 | dev_priv->mch_res.name = "i915 MCHBAR"; |
| 1157 | dev_priv->mch_res.flags = IORESOURCE_MEM; |
| 1158 | ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus, |
| 1159 | &dev_priv->mch_res, |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1160 | MCHBAR_SIZE, MCHBAR_SIZE, |
| 1161 | PCIBIOS_MIN_MEM, |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1162 | 0, pcibios_align_resource, |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1163 | dev_priv->bridge_dev); |
| 1164 | if (ret) { |
| 1165 | DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret); |
| 1166 | dev_priv->mch_res.start = 0; |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1167 | return ret; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1168 | } |
| 1169 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1170 | if (INTEL_INFO(dev)->gen >= 4) |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1171 | pci_write_config_dword(dev_priv->bridge_dev, reg + 4, |
| 1172 | upper_32_bits(dev_priv->mch_res.start)); |
| 1173 | |
| 1174 | pci_write_config_dword(dev_priv->bridge_dev, reg, |
| 1175 | lower_32_bits(dev_priv->mch_res.start)); |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1176 | return 0; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /* Setup MCHBAR if possible, return true if we should disable it again */ |
| 1180 | static void |
| 1181 | intel_setup_mchbar(struct drm_device *dev) |
| 1182 | { |
| 1183 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1184 | int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1185 | u32 temp; |
| 1186 | bool enabled; |
| 1187 | |
| 1188 | dev_priv->mchbar_need_disable = false; |
| 1189 | |
| 1190 | if (IS_I915G(dev) || IS_I915GM(dev)) { |
| 1191 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); |
| 1192 | enabled = !!(temp & DEVEN_MCHBAR_EN); |
| 1193 | } else { |
| 1194 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 1195 | enabled = temp & 1; |
| 1196 | } |
| 1197 | |
| 1198 | /* If it's already enabled, don't have to do anything */ |
| 1199 | if (enabled) |
| 1200 | return; |
| 1201 | |
| 1202 | if (intel_alloc_mchbar_resource(dev)) |
| 1203 | return; |
| 1204 | |
| 1205 | dev_priv->mchbar_need_disable = true; |
| 1206 | |
| 1207 | /* Space is allocated or reserved, so enable it. */ |
| 1208 | if (IS_I915G(dev) || IS_I915GM(dev)) { |
| 1209 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, |
| 1210 | temp | DEVEN_MCHBAR_EN); |
| 1211 | } else { |
| 1212 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 1213 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | static void |
| 1218 | intel_teardown_mchbar(struct drm_device *dev) |
| 1219 | { |
| 1220 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1221 | int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1222 | u32 temp; |
| 1223 | |
| 1224 | if (dev_priv->mchbar_need_disable) { |
| 1225 | if (IS_I915G(dev) || IS_I915GM(dev)) { |
| 1226 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); |
| 1227 | temp &= ~DEVEN_MCHBAR_EN; |
| 1228 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, temp); |
| 1229 | } else { |
| 1230 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 1231 | temp &= ~1; |
| 1232 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | if (dev_priv->mch_res.start) |
| 1237 | release_resource(&dev_priv->mch_res); |
| 1238 | } |
| 1239 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1240 | /* true = enable decode, false = disable decoder */ |
| 1241 | static unsigned int i915_vga_set_decode(void *cookie, bool state) |
| 1242 | { |
| 1243 | struct drm_device *dev = cookie; |
| 1244 | |
| 1245 | intel_modeset_vga_set_state(dev, state); |
| 1246 | if (state) |
| 1247 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 1248 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 1249 | else |
| 1250 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 1251 | } |
| 1252 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1253 | static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) |
| 1254 | { |
| 1255 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 1256 | pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; |
| 1257 | if (state == VGA_SWITCHEROO_ON) { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1258 | pr_info("switched on\n"); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1259 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1260 | /* i915 resume handler doesn't set to D0 */ |
| 1261 | pci_set_power_state(dev->pdev, PCI_D0); |
| 1262 | i915_resume(dev); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1263 | dev->switch_power_state = DRM_SWITCH_POWER_ON; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1264 | } else { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1265 | pr_err("switched off\n"); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1266 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1267 | i915_suspend(dev, pmm); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1268 | dev->switch_power_state = DRM_SWITCH_POWER_OFF; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | static bool i915_switcheroo_can_switch(struct pci_dev *pdev) |
| 1273 | { |
| 1274 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 1275 | bool can_switch; |
| 1276 | |
| 1277 | spin_lock(&dev->count_lock); |
| 1278 | can_switch = (dev->open_count == 0); |
| 1279 | spin_unlock(&dev->count_lock); |
| 1280 | return can_switch; |
| 1281 | } |
| 1282 | |
Takashi Iwai | 26ec685 | 2012-05-11 07:51:17 +0200 | [diff] [blame] | 1283 | static const struct vga_switcheroo_client_ops i915_switcheroo_ops = { |
| 1284 | .set_gpu_state = i915_switcheroo_set_state, |
| 1285 | .reprobe = NULL, |
| 1286 | .can_switch = i915_switcheroo_can_switch, |
| 1287 | }; |
| 1288 | |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1289 | static int i915_load_modeset_init(struct drm_device *dev) |
| 1290 | { |
| 1291 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1292 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1293 | |
Bryan Freed | 6d139a8 | 2010-10-14 09:14:51 +0100 | [diff] [blame] | 1294 | ret = intel_parse_bios(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1295 | if (ret) |
| 1296 | DRM_INFO("failed to find VBIOS tables\n"); |
| 1297 | |
Chris Wilson | 934f992 | 2011-01-20 13:09:12 +0000 | [diff] [blame] | 1298 | /* If we have > 1 VGA cards, then we need to arbitrate access |
| 1299 | * to the common VGA resources. |
| 1300 | * |
| 1301 | * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA), |
| 1302 | * then we do not take part in VGA arbitration and the |
| 1303 | * vga_client_register() fails with -ENODEV. |
| 1304 | */ |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1305 | ret = vga_client_register(dev->pdev, dev, NULL, i915_vga_set_decode); |
Chris Wilson | 934f992 | 2011-01-20 13:09:12 +0000 | [diff] [blame] | 1306 | if (ret && ret != -ENODEV) |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1307 | goto out; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1308 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 1309 | intel_register_dsm_handler(); |
| 1310 | |
Takashi Iwai | 26ec685 | 2012-05-11 07:51:17 +0200 | [diff] [blame] | 1311 | ret = vga_switcheroo_register_client(dev->pdev, &i915_switcheroo_ops); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1312 | if (ret) |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1313 | goto cleanup_vga_client; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1314 | |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 1315 | /* Initialise stolen first so that we may reserve preallocated |
| 1316 | * objects for the BIOS to KMS transition. |
| 1317 | */ |
| 1318 | ret = i915_gem_init_stolen(dev); |
| 1319 | if (ret) |
| 1320 | goto cleanup_vga_switcheroo; |
| 1321 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 1322 | intel_modeset_init(dev); |
| 1323 | |
Chris Wilson | 1070a42 | 2012-04-24 15:47:41 +0100 | [diff] [blame] | 1324 | ret = i915_gem_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1325 | if (ret) |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 1326 | goto cleanup_gem_stolen; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1327 | |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1328 | intel_modeset_gem_init(dev); |
| 1329 | |
| 1330 | ret = drm_irq_install(dev); |
| 1331 | if (ret) |
| 1332 | goto cleanup_gem; |
| 1333 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1334 | /* Always safe in the mode setting case. */ |
| 1335 | /* FIXME: do pre/post-mode set stuff in core KMS code */ |
| 1336 | dev->vblank_disable_allowed = 1; |
| 1337 | |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1338 | ret = intel_fbdev_init(dev); |
| 1339 | if (ret) |
| 1340 | goto cleanup_irq; |
| 1341 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1342 | drm_kms_helper_poll_init(dev); |
Chris Wilson | 87acb0a | 2010-10-19 10:13:00 +0100 | [diff] [blame] | 1343 | |
| 1344 | /* We're off and running w/KMS */ |
| 1345 | dev_priv->mm.suspended = 0; |
| 1346 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1347 | return 0; |
| 1348 | |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1349 | cleanup_irq: |
| 1350 | drm_irq_uninstall(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1351 | cleanup_gem: |
| 1352 | mutex_lock(&dev->struct_mutex); |
| 1353 | i915_gem_cleanup_ringbuffer(dev); |
| 1354 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1355 | i915_gem_cleanup_aliasing_ppgtt(dev); |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 1356 | cleanup_gem_stolen: |
| 1357 | i915_gem_cleanup_stolen(dev); |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1358 | cleanup_vga_switcheroo: |
| 1359 | vga_switcheroo_unregister_client(dev->pdev); |
| 1360 | cleanup_vga_client: |
| 1361 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1362 | out: |
| 1363 | return ret; |
| 1364 | } |
| 1365 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1366 | int i915_master_create(struct drm_device *dev, struct drm_master *master) |
| 1367 | { |
| 1368 | struct drm_i915_master_private *master_priv; |
| 1369 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1370 | master_priv = kzalloc(sizeof(*master_priv), GFP_KERNEL); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1371 | if (!master_priv) |
| 1372 | return -ENOMEM; |
| 1373 | |
| 1374 | master->driver_priv = master_priv; |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | void i915_master_destroy(struct drm_device *dev, struct drm_master *master) |
| 1379 | { |
| 1380 | struct drm_i915_master_private *master_priv = master->driver_priv; |
| 1381 | |
| 1382 | if (!master_priv) |
| 1383 | return; |
| 1384 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1385 | kfree(master_priv); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1386 | |
| 1387 | master->driver_priv = NULL; |
| 1388 | } |
| 1389 | |
Adam Jackson | e2b665c | 2012-03-14 11:22:10 -0400 | [diff] [blame] | 1390 | static void |
| 1391 | i915_mtrr_setup(struct drm_i915_private *dev_priv, unsigned long base, |
| 1392 | unsigned long size) |
| 1393 | { |
Chris Wilson | 23f54be | 2012-03-23 17:38:49 +0000 | [diff] [blame] | 1394 | dev_priv->mm.gtt_mtrr = -1; |
| 1395 | |
Adam Jackson | 9e984bc1 | 2012-03-14 11:22:11 -0400 | [diff] [blame] | 1396 | #if defined(CONFIG_X86_PAT) |
| 1397 | if (cpu_has_pat) |
| 1398 | return; |
| 1399 | #endif |
| 1400 | |
Adam Jackson | e2b665c | 2012-03-14 11:22:10 -0400 | [diff] [blame] | 1401 | /* Set up a WC MTRR for non-PAT systems. This is more common than |
| 1402 | * one would think, because the kernel disables PAT on first |
| 1403 | * generation Core chips because WC PAT gets overridden by a UC |
| 1404 | * MTRR if present. Even if a UC MTRR isn't present. |
| 1405 | */ |
| 1406 | dev_priv->mm.gtt_mtrr = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1); |
| 1407 | if (dev_priv->mm.gtt_mtrr < 0) { |
| 1408 | DRM_INFO("MTRR allocation failed. Graphics " |
| 1409 | "performance may suffer.\n"); |
| 1410 | } |
| 1411 | } |
| 1412 | |
Daniel Vetter | e188719 | 2012-06-12 11:28:17 +0200 | [diff] [blame] | 1413 | static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv) |
| 1414 | { |
| 1415 | struct apertures_struct *ap; |
| 1416 | struct pci_dev *pdev = dev_priv->dev->pdev; |
| 1417 | bool primary; |
| 1418 | |
| 1419 | ap = alloc_apertures(1); |
| 1420 | if (!ap) |
| 1421 | return; |
| 1422 | |
Daniel Vetter | 87207ca | 2012-06-24 20:51:36 +0200 | [diff] [blame] | 1423 | ap->ranges[0].base = dev_priv->mm.gtt->gma_bus_addr; |
Daniel Vetter | e188719 | 2012-06-12 11:28:17 +0200 | [diff] [blame] | 1424 | ap->ranges[0].size = |
| 1425 | dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; |
| 1426 | primary = |
| 1427 | pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; |
| 1428 | |
| 1429 | remove_conflicting_framebuffers(ap, "inteldrmfb", primary); |
| 1430 | |
| 1431 | kfree(ap); |
| 1432 | } |
| 1433 | |
Daniel Vetter | c96ea64 | 2012-08-08 22:01:51 +0200 | [diff] [blame] | 1434 | static void i915_dump_device_info(struct drm_i915_private *dev_priv) |
| 1435 | { |
| 1436 | const struct intel_device_info *info = dev_priv->info; |
| 1437 | |
| 1438 | #define DEV_INFO_FLAG(name) info->name ? #name "," : "" |
| 1439 | #define DEV_INFO_SEP , |
| 1440 | DRM_DEBUG_DRIVER("i915 device info: gen=%i, pciid=0x%04x flags=" |
| 1441 | "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", |
| 1442 | info->gen, |
| 1443 | dev_priv->dev->pdev->device, |
| 1444 | DEV_INFO_FLAGS); |
| 1445 | #undef DEV_INFO_FLAG |
| 1446 | #undef DEV_INFO_SEP |
| 1447 | } |
| 1448 | |
Eric Anholt | 63ee41d | 2010-12-20 18:40:06 -0800 | [diff] [blame] | 1449 | /** |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1450 | * i915_driver_load - setup chip and create an initial config |
| 1451 | * @dev: DRM device |
| 1452 | * @flags: startup flags |
| 1453 | * |
| 1454 | * The driver load routine has to do several things: |
| 1455 | * - drive output discovery via intel_modeset_init() |
| 1456 | * - initialize the memory manager |
| 1457 | * - allocate initial config memory |
| 1458 | * - setup the DRM framebuffer with the allocated memory |
| 1459 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1460 | int i915_driver_load(struct drm_device *dev, unsigned long flags) |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1461 | { |
Luca Tettamanti | ea059a1 | 2010-04-08 21:41:59 +0200 | [diff] [blame] | 1462 | struct drm_i915_private *dev_priv; |
Daniel Vetter | 26394d9 | 2012-03-26 21:33:18 +0200 | [diff] [blame] | 1463 | struct intel_device_info *info; |
Kristian Høgsberg | cfdf1fa | 2009-12-16 15:16:16 -0500 | [diff] [blame] | 1464 | int ret = 0, mmio_bar; |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 1465 | uint32_t aperture_size; |
Chris Wilson | fe669bf | 2010-11-23 12:09:30 +0000 | [diff] [blame] | 1466 | |
Daniel Vetter | 26394d9 | 2012-03-26 21:33:18 +0200 | [diff] [blame] | 1467 | info = (struct intel_device_info *) flags; |
| 1468 | |
| 1469 | /* Refuse to load on gen6+ without kms enabled. */ |
| 1470 | if (info->gen >= 6 && !drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1471 | return -ENODEV; |
| 1472 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1473 | /* i915 has 4 more counters */ |
| 1474 | dev->counters += 4; |
| 1475 | dev->types[6] = _DRM_STAT_IRQ; |
| 1476 | dev->types[7] = _DRM_STAT_PRIMARY; |
| 1477 | dev->types[8] = _DRM_STAT_SECONDARY; |
| 1478 | dev->types[9] = _DRM_STAT_DMA; |
| 1479 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1480 | dev_priv = kzalloc(sizeof(drm_i915_private_t), GFP_KERNEL); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1481 | if (dev_priv == NULL) |
| 1482 | return -ENOMEM; |
| 1483 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1484 | dev->dev_private = (void *)dev_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1485 | dev_priv->dev = dev; |
Daniel Vetter | 26394d9 | 2012-03-26 21:33:18 +0200 | [diff] [blame] | 1486 | dev_priv->info = info; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1487 | |
Daniel Vetter | c96ea64 | 2012-08-08 22:01:51 +0200 | [diff] [blame] | 1488 | i915_dump_device_info(dev_priv); |
| 1489 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1490 | if (i915_get_bridge_dev(dev)) { |
| 1491 | ret = -EIO; |
| 1492 | goto free_priv; |
| 1493 | } |
| 1494 | |
Daniel Vetter | e188719 | 2012-06-12 11:28:17 +0200 | [diff] [blame] | 1495 | ret = intel_gmch_probe(dev_priv->bridge_dev, dev->pdev, NULL); |
| 1496 | if (!ret) { |
| 1497 | DRM_ERROR("failed to set up gmch\n"); |
| 1498 | ret = -EIO; |
| 1499 | goto put_bridge; |
| 1500 | } |
| 1501 | |
| 1502 | dev_priv->mm.gtt = intel_gtt_get(); |
| 1503 | if (!dev_priv->mm.gtt) { |
| 1504 | DRM_ERROR("Failed to initialize GTT\n"); |
| 1505 | ret = -ENODEV; |
| 1506 | goto put_gmch; |
| 1507 | } |
| 1508 | |
| 1509 | i915_kick_out_firmware_fb(dev_priv); |
| 1510 | |
Dave Airlie | 466e69b | 2011-12-19 11:15:29 +0000 | [diff] [blame] | 1511 | pci_set_master(dev->pdev); |
| 1512 | |
Daniel Vetter | 9f82d23 | 2010-08-30 21:25:23 +0200 | [diff] [blame] | 1513 | /* overlay on gen2 is broken and can't address above 1G */ |
| 1514 | if (IS_GEN2(dev)) |
| 1515 | dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(30)); |
| 1516 | |
Jan Niehusmann | 6927faf | 2011-03-01 23:24:16 +0100 | [diff] [blame] | 1517 | /* 965GM sometimes incorrectly writes to hardware status page (HWS) |
| 1518 | * using 32bit addressing, overwriting memory if HWS is located |
| 1519 | * above 4GB. |
| 1520 | * |
| 1521 | * The documentation also mentions an issue with undefined |
| 1522 | * behaviour if any general state is accessed within a page above 4GB, |
| 1523 | * which also needs to be handled carefully. |
| 1524 | */ |
| 1525 | if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
| 1526 | dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(32)); |
| 1527 | |
Chris Wilson | b4ce0f8 | 2010-10-28 11:26:06 +0100 | [diff] [blame] | 1528 | mmio_bar = IS_GEN2(dev) ? 1 : 0; |
| 1529 | dev_priv->regs = pci_iomap(dev->pdev, mmio_bar, 0); |
| 1530 | if (!dev_priv->regs) { |
| 1531 | DRM_ERROR("failed to map registers\n"); |
| 1532 | ret = -EIO; |
Daniel Vetter | 14be93d | 2012-06-08 15:55:40 +0200 | [diff] [blame] | 1533 | goto put_gmch; |
Chris Wilson | 71e9339 | 2010-10-27 18:46:52 +0100 | [diff] [blame] | 1534 | } |
| 1535 | |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 1536 | aperture_size = dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 1537 | dev_priv->mm.gtt_base_addr = dev_priv->mm.gtt->gma_bus_addr; |
Chris Wilson | 71e9339 | 2010-10-27 18:46:52 +0100 | [diff] [blame] | 1538 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1539 | dev_priv->mm.gtt_mapping = |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 1540 | io_mapping_create_wc(dev_priv->mm.gtt_base_addr, |
| 1541 | aperture_size); |
Venkatesh Pallipadi | 6644107d | 2009-02-24 17:35:11 -0800 | [diff] [blame] | 1542 | if (dev_priv->mm.gtt_mapping == NULL) { |
| 1543 | ret = -EIO; |
Daniel Vetter | e188719 | 2012-06-12 11:28:17 +0200 | [diff] [blame] | 1544 | goto out_rmmap; |
Venkatesh Pallipadi | 6644107d | 2009-02-24 17:35:11 -0800 | [diff] [blame] | 1545 | } |
| 1546 | |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 1547 | i915_mtrr_setup(dev_priv, dev_priv->mm.gtt_base_addr, |
| 1548 | aperture_size); |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 1549 | |
Chris Wilson | e642abb | 2010-09-09 12:46:34 +0100 | [diff] [blame] | 1550 | /* The i915 workqueue is primarily used for batched retirement of |
| 1551 | * requests (and thus managing bo) once the task has been completed |
| 1552 | * by the GPU. i915_gem_retire_requests() is called directly when we |
| 1553 | * need high-priority retirement, such as waiting for an explicit |
| 1554 | * bo. |
| 1555 | * |
| 1556 | * It is also used for periodic low-priority events, such as |
Eric Anholt | df9c204 | 2010-11-18 09:31:12 +0800 | [diff] [blame] | 1557 | * idle-timers and recording error state. |
Chris Wilson | e642abb | 2010-09-09 12:46:34 +0100 | [diff] [blame] | 1558 | * |
| 1559 | * All tasks on the workqueue are expected to acquire the dev mutex |
| 1560 | * so there is no point in running more than one instance of the |
Tejun Heo | 5362186 | 2012-08-22 16:40:57 -0700 | [diff] [blame] | 1561 | * workqueue at any time. Use an ordered one. |
Chris Wilson | e642abb | 2010-09-09 12:46:34 +0100 | [diff] [blame] | 1562 | */ |
Tejun Heo | 5362186 | 2012-08-22 16:40:57 -0700 | [diff] [blame] | 1563 | dev_priv->wq = alloc_ordered_workqueue("i915", 0); |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1564 | if (dev_priv->wq == NULL) { |
| 1565 | DRM_ERROR("Failed to create our workqueue.\n"); |
| 1566 | ret = -ENOMEM; |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 1567 | goto out_mtrrfree; |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Paulo Zanoni | 45e6e3a | 2012-07-03 15:57:32 -0300 | [diff] [blame] | 1570 | /* This must be called before any calls to HAS_PCH_* */ |
| 1571 | intel_detect_pch(dev); |
| 1572 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 1573 | intel_irq_init(dev); |
Chris Wilson | 990bbda | 2012-07-02 11:51:02 -0300 | [diff] [blame] | 1574 | intel_gt_init(dev); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 1575 | |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1576 | /* Try to make sure MCHBAR is enabled before poking at it */ |
| 1577 | intel_setup_mchbar(dev); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 1578 | intel_setup_gmbus(dev); |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1579 | intel_opregion_setup(dev); |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1580 | |
Bryan Freed | 6d139a8 | 2010-10-14 09:14:51 +0100 | [diff] [blame] | 1581 | /* Make sure the bios did its job and set up vital registers */ |
| 1582 | intel_setup_bios(dev); |
| 1583 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1584 | i915_gem_load(dev); |
| 1585 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 1586 | /* Init HWS */ |
| 1587 | if (!I915_NEED_GFX_HWS(dev)) { |
| 1588 | ret = i915_init_phys_hws(dev); |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 1589 | if (ret) |
| 1590 | goto out_gem_unload; |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 1591 | } |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1592 | |
| 1593 | /* On the 945G/GM, the chipset reports the MSI capability on the |
| 1594 | * integrated graphics even though the support isn't actually there |
| 1595 | * according to the published specs. It doesn't appear to function |
| 1596 | * correctly in testing on 945G. |
| 1597 | * This may be a side effect of MSI having been made available for PEG |
| 1598 | * and the registers being closely associated. |
Keith Packard | d1ed629 | 2008-10-17 00:44:42 -0700 | [diff] [blame] | 1599 | * |
| 1600 | * According to chipset errata, on the 965GM, MSI interrupts may |
Keith Packard | b60678a | 2008-12-08 11:12:28 -0800 | [diff] [blame] | 1601 | * be lost or delayed, but we use them anyways to avoid |
| 1602 | * stuck interrupts on some machines. |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1603 | */ |
Keith Packard | b60678a | 2008-12-08 11:12:28 -0800 | [diff] [blame] | 1604 | if (!IS_I945G(dev) && !IS_I945GM(dev)) |
Eric Anholt | d3e74d0 | 2008-11-03 14:46:17 -0800 | [diff] [blame] | 1605 | pci_enable_msi(dev->pdev); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1606 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1607 | spin_lock_init(&dev_priv->irq_lock); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1608 | spin_lock_init(&dev_priv->error_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 1609 | spin_lock_init(&dev_priv->rps.lock); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1610 | |
Eugeni Dodonov | c51ed78 | 2012-04-13 17:08:45 -0300 | [diff] [blame] | 1611 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
Jesse Barnes | 27f8227 | 2011-09-02 12:54:37 -0700 | [diff] [blame] | 1612 | dev_priv->num_pipe = 3; |
| 1613 | else if (IS_MOBILE(dev) || !IS_GEN2(dev)) |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1614 | dev_priv->num_pipe = 2; |
| 1615 | else |
| 1616 | dev_priv->num_pipe = 1; |
| 1617 | |
| 1618 | ret = drm_vblank_init(dev, dev_priv->num_pipe); |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 1619 | if (ret) |
| 1620 | goto out_gem_unload; |
Keith Packard | 5244021 | 2008-11-18 09:30:25 -0800 | [diff] [blame] | 1621 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1622 | /* Start out suspended */ |
| 1623 | dev_priv->mm.suspended = 1; |
| 1624 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1625 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Daniel Vetter | 5398463 | 2010-09-22 23:44:24 +0200 | [diff] [blame] | 1626 | ret = i915_load_modeset_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1627 | if (ret < 0) { |
| 1628 | DRM_ERROR("failed to init modeset\n"); |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 1629 | goto out_gem_unload; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 1633 | i915_setup_sysfs(dev); |
| 1634 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1635 | /* Must be done after probing outputs */ |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1636 | intel_opregion_init(dev); |
| 1637 | acpi_video_register(); |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1638 | |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1639 | setup_timer(&dev_priv->hangcheck_timer, i915_hangcheck_elapsed, |
| 1640 | (unsigned long) dev); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1641 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 1642 | if (IS_GEN5(dev)) |
| 1643 | intel_gpu_ips_init(dev_priv); |
Eric Anholt | 63ee41d | 2010-12-20 18:40:06 -0800 | [diff] [blame] | 1644 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1645 | return 0; |
| 1646 | |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 1647 | out_gem_unload: |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 1648 | if (dev_priv->mm.inactive_shrinker.shrink) |
| 1649 | unregister_shrinker(&dev_priv->mm.inactive_shrinker); |
| 1650 | |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 1651 | if (dev->pdev->msi_enabled) |
| 1652 | pci_disable_msi(dev->pdev); |
| 1653 | |
| 1654 | intel_teardown_gmbus(dev); |
| 1655 | intel_teardown_mchbar(dev); |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1656 | destroy_workqueue(dev_priv->wq); |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 1657 | out_mtrrfree: |
| 1658 | if (dev_priv->mm.gtt_mtrr >= 0) { |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 1659 | mtrr_del(dev_priv->mm.gtt_mtrr, |
| 1660 | dev_priv->mm.gtt_base_addr, |
| 1661 | aperture_size); |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 1662 | dev_priv->mm.gtt_mtrr = -1; |
| 1663 | } |
Venkatesh Pallipadi | 6644107d | 2009-02-24 17:35:11 -0800 | [diff] [blame] | 1664 | io_mapping_free(dev_priv->mm.gtt_mapping); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1665 | out_rmmap: |
Chris Wilson | 6dda569 | 2010-10-29 21:02:18 +0100 | [diff] [blame] | 1666 | pci_iounmap(dev->pdev, dev_priv->regs); |
Daniel Vetter | e188719 | 2012-06-12 11:28:17 +0200 | [diff] [blame] | 1667 | put_gmch: |
| 1668 | intel_gmch_remove(); |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1669 | put_bridge: |
| 1670 | pci_dev_put(dev_priv->bridge_dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1671 | free_priv: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1672 | kfree(dev_priv); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1673 | return ret; |
| 1674 | } |
| 1675 | |
| 1676 | int i915_driver_unload(struct drm_device *dev) |
| 1677 | { |
| 1678 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 1679 | int ret; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1680 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 1681 | intel_gpu_ips_teardown(); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1682 | |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 1683 | i915_teardown_sysfs(dev); |
| 1684 | |
Chris Wilson | 17250b7 | 2010-10-28 12:51:39 +0100 | [diff] [blame] | 1685 | if (dev_priv->mm.inactive_shrinker.shrink) |
| 1686 | unregister_shrinker(&dev_priv->mm.inactive_shrinker); |
| 1687 | |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 1688 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | b2da9fe | 2012-04-26 16:02:58 -0700 | [diff] [blame] | 1689 | ret = i915_gpu_idle(dev); |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 1690 | if (ret) |
| 1691 | DRM_ERROR("failed to idle hardware: %d\n", ret); |
Ben Widawsky | b2da9fe | 2012-04-26 16:02:58 -0700 | [diff] [blame] | 1692 | i915_gem_retire_requests(dev); |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 1693 | mutex_unlock(&dev->struct_mutex); |
| 1694 | |
Daniel Vetter | 75ef9da | 2010-08-21 00:25:16 +0200 | [diff] [blame] | 1695 | /* Cancel the retire work handler, which should be idle now. */ |
| 1696 | cancel_delayed_work_sync(&dev_priv->mm.retire_work); |
| 1697 | |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 1698 | io_mapping_free(dev_priv->mm.gtt_mapping); |
| 1699 | if (dev_priv->mm.gtt_mtrr >= 0) { |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 1700 | mtrr_del(dev_priv->mm.gtt_mtrr, |
| 1701 | dev_priv->mm.gtt_base_addr, |
| 1702 | dev_priv->mm.gtt->gtt_mappable_entries * PAGE_SIZE); |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 1703 | dev_priv->mm.gtt_mtrr = -1; |
| 1704 | } |
| 1705 | |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1706 | acpi_video_unregister(); |
| 1707 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1708 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Chris Wilson | 7b4f399 | 2010-10-04 15:33:04 +0100 | [diff] [blame] | 1709 | intel_fbdev_fini(dev); |
Jesse Barnes | 3d8620c | 2010-03-26 11:07:21 -0700 | [diff] [blame] | 1710 | intel_modeset_cleanup(dev); |
| 1711 | |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1712 | /* |
| 1713 | * free the memory space allocated for the child device |
| 1714 | * config parsed from VBT |
| 1715 | */ |
| 1716 | if (dev_priv->child_dev && dev_priv->child_dev_num) { |
| 1717 | kfree(dev_priv->child_dev); |
| 1718 | dev_priv->child_dev = NULL; |
| 1719 | dev_priv->child_dev_num = 0; |
| 1720 | } |
Daniel Vetter | 6c0d9350 | 2010-08-20 18:26:46 +0200 | [diff] [blame] | 1721 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1722 | vga_switcheroo_unregister_client(dev->pdev); |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1723 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1724 | } |
| 1725 | |
Daniel Vetter | a8b4899 | 2010-08-20 21:25:11 +0200 | [diff] [blame] | 1726 | /* Free error state after interrupts are fully disabled. */ |
Daniel Vetter | bc0c7f1 | 2010-08-20 18:18:48 +0200 | [diff] [blame] | 1727 | del_timer_sync(&dev_priv->hangcheck_timer); |
| 1728 | cancel_work_sync(&dev_priv->error_work); |
Daniel Vetter | a8b4899 | 2010-08-20 21:25:11 +0200 | [diff] [blame] | 1729 | i915_destroy_error_state(dev); |
Daniel Vetter | bc0c7f1 | 2010-08-20 18:18:48 +0200 | [diff] [blame] | 1730 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1731 | if (dev->pdev->msi_enabled) |
| 1732 | pci_disable_msi(dev->pdev); |
| 1733 | |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1734 | intel_opregion_fini(dev); |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1735 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1736 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 1737 | /* Flush any outstanding unpin_work. */ |
| 1738 | flush_workqueue(dev_priv->wq); |
| 1739 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1740 | mutex_lock(&dev->struct_mutex); |
Hugh Dickins | ecbec53 | 2011-06-27 16:18:20 -0700 | [diff] [blame] | 1741 | i915_gem_free_all_phys_object(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1742 | i915_gem_cleanup_ringbuffer(dev); |
Daniel Vetter | 55a6662 | 2012-06-19 21:55:32 +0200 | [diff] [blame] | 1743 | i915_gem_context_fini(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1744 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1745 | i915_gem_cleanup_aliasing_ppgtt(dev); |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 1746 | i915_gem_cleanup_stolen(dev); |
Chris Wilson | fe669bf | 2010-11-23 12:09:30 +0000 | [diff] [blame] | 1747 | drm_mm_takedown(&dev_priv->mm.stolen); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 1748 | |
| 1749 | intel_cleanup_overlay(dev); |
Keith Packard | c2873e9 | 2010-10-07 09:20:12 +0100 | [diff] [blame] | 1750 | |
| 1751 | if (!I915_NEED_GFX_HWS(dev)) |
| 1752 | i915_free_hws(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1753 | } |
| 1754 | |
Daniel Vetter | 701394c | 2010-10-10 18:54:08 +0100 | [diff] [blame] | 1755 | if (dev_priv->regs != NULL) |
Chris Wilson | 6dda569 | 2010-10-29 21:02:18 +0100 | [diff] [blame] | 1756 | pci_iounmap(dev->pdev, dev_priv->regs); |
Daniel Vetter | 701394c | 2010-10-10 18:54:08 +0100 | [diff] [blame] | 1757 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 1758 | intel_teardown_gmbus(dev); |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1759 | intel_teardown_mchbar(dev); |
| 1760 | |
Daniel Vetter | bc0c7f1 | 2010-08-20 18:18:48 +0200 | [diff] [blame] | 1761 | destroy_workqueue(dev_priv->wq); |
| 1762 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1763 | pci_dev_put(dev_priv->bridge_dev); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1764 | kfree(dev->dev_private); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1765 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1766 | return 0; |
| 1767 | } |
| 1768 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1769 | int i915_driver_open(struct drm_device *dev, struct drm_file *file) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1770 | { |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1771 | struct drm_i915_file_private *file_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1772 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1773 | DRM_DEBUG_DRIVER("\n"); |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1774 | file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL); |
| 1775 | if (!file_priv) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1776 | return -ENOMEM; |
| 1777 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1778 | file->driver_priv = file_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1779 | |
Chris Wilson | 1c25595 | 2010-09-26 11:03:27 +0100 | [diff] [blame] | 1780 | spin_lock_init(&file_priv->mm.lock); |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1781 | INIT_LIST_HEAD(&file_priv->mm.request_list); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1782 | |
Daniel Vetter | df12c6d | 2012-06-19 16:52:30 +0200 | [diff] [blame] | 1783 | idr_init(&file_priv->context_idr); |
Ben Widawsky | 254f965 | 2012-06-04 14:42:42 -0700 | [diff] [blame] | 1784 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1785 | return 0; |
| 1786 | } |
| 1787 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1788 | /** |
| 1789 | * i915_driver_lastclose - clean up after all DRM clients have exited |
| 1790 | * @dev: DRM device |
| 1791 | * |
| 1792 | * Take care of cleaning up after all DRM clients have exited. In the |
| 1793 | * mode setting case, we want to restore the kernel's initial mode (just |
| 1794 | * in case the last client left us in a bad state). |
| 1795 | * |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 1796 | * Additionally, in the non-mode setting case, we'll tear down the GTT |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1797 | * and DMA structures, since the kernel won't be using them, and clea |
| 1798 | * up any GEM state. |
| 1799 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1800 | void i915_driver_lastclose(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1802 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1803 | |
Daniel Vetter | e8aeaee | 2012-07-21 16:47:09 +0200 | [diff] [blame] | 1804 | /* On gen6+ we refuse to init without kms enabled, but then the drm core |
| 1805 | * goes right around and calls lastclose. Check for this and don't clean |
| 1806 | * up anything. */ |
| 1807 | if (!dev_priv) |
| 1808 | return; |
| 1809 | |
| 1810 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 1811 | intel_fb_restore_mode(dev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1812 | vga_switcheroo_process_delayed_switch(); |
Dave Airlie | 144a75f | 2008-03-30 07:53:58 +1000 | [diff] [blame] | 1813 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1814 | } |
Dave Airlie | 144a75f | 2008-03-30 07:53:58 +1000 | [diff] [blame] | 1815 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1816 | i915_gem_lastclose(dev); |
| 1817 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1818 | i915_dma_cleanup(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1821 | void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | { |
Ben Widawsky | 254f965 | 2012-06-04 14:42:42 -0700 | [diff] [blame] | 1823 | i915_gem_context_close(dev, file_priv); |
Eric Anholt | b962442 | 2009-06-03 07:27:35 +0000 | [diff] [blame] | 1824 | i915_gem_release(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1827 | void i915_driver_postclose(struct drm_device *dev, struct drm_file *file) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1828 | { |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1829 | struct drm_i915_file_private *file_priv = file->driver_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1830 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 1831 | kfree(file_priv); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1834 | struct drm_ioctl_desc i915_ioctls[] = { |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 1835 | DRM_IOCTL_DEF_DRV(I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1836 | DRM_IOCTL_DEF_DRV(I915_FLUSH, i915_flush_ioctl, DRM_AUTH), |
| 1837 | DRM_IOCTL_DEF_DRV(I915_FLIP, i915_flip_bufs, DRM_AUTH), |
| 1838 | DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH), |
| 1839 | DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH), |
| 1840 | DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH), |
| 1841 | DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam, DRM_AUTH), |
| 1842 | DRM_IOCTL_DEF_DRV(I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Daniel Vetter | b2c606f | 2012-01-17 12:50:12 +0100 | [diff] [blame] | 1843 | DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH), |
| 1844 | DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH), |
| 1845 | DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 1846 | DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH), |
Daniel Vetter | b2c606f | 2012-01-17 12:50:12 +0100 | [diff] [blame] | 1847 | DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Daniel Vetter | d1c1edb | 2012-04-26 23:28:01 +0200 | [diff] [blame] | 1848 | DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 1849 | DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH), |
| 1850 | DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH), |
| 1851 | DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, i915_set_status_page, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1852 | DRM_IOCTL_DEF_DRV(I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 1853 | DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED), |
| 1854 | DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_UNLOCKED), |
| 1855 | DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 1856 | DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 1857 | DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED), |
Chris Wilson | e6994ae | 2012-07-10 10:27:08 +0100 | [diff] [blame] | 1858 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHEING, i915_gem_set_cacheing_ioctl, DRM_UNLOCKED), |
| 1859 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHEING, i915_gem_get_cacheing_ioctl, DRM_UNLOCKED), |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 1860 | DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_UNLOCKED), |
| 1861 | DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 1862 | DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 1863 | DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_UNLOCKED), |
| 1864 | DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_UNLOCKED), |
| 1865 | DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_UNLOCKED), |
| 1866 | DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_UNLOCKED), |
| 1867 | DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_UNLOCKED), |
| 1868 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_UNLOCKED), |
| 1869 | DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_UNLOCKED), |
| 1870 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_UNLOCKED), |
| 1871 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_UNLOCKED), |
| 1872 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_UNLOCKED), |
| 1873 | DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, DRM_UNLOCKED), |
| 1874 | DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED), |
| 1875 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
| 1876 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1877 | DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
| 1878 | DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, intel_sprite_get_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
Ben Widawsky | 23ba4fd | 2012-05-24 15:03:10 -0700 | [diff] [blame] | 1879 | DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED), |
Ben Widawsky | 8462481 | 2012-06-04 14:42:54 -0700 | [diff] [blame] | 1880 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE, i915_gem_context_create_ioctl, DRM_UNLOCKED), |
| 1881 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_UNLOCKED), |
Ben Widawsky | c0c7bab | 2012-07-12 11:01:05 -0700 | [diff] [blame] | 1882 | DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_UNLOCKED), |
Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 1883 | }; |
| 1884 | |
| 1885 | int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 1886 | |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 1887 | /* |
| 1888 | * This is really ugly: Because old userspace abused the linux agp interface to |
| 1889 | * manage the gtt, we need to claim that all intel devices are agp. For |
| 1890 | * otherwise the drm core refuses to initialize the agp support code. |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 1891 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1892 | int i915_driver_device_is_agp(struct drm_device * dev) |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 1893 | { |
| 1894 | return 1; |
| 1895 | } |