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