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