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