Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* i915_dma.c -- DMA support for the I915 -*- linux-c -*- |
| 2 | */ |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 3 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 5 | * All Rights Reserved. |
Dave Airlie | bc54fd1 | 2005-06-23 22:46:46 +1000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sub license, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial portions |
| 17 | * of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 22 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | * |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 27 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "drmP.h" |
| 32 | #include "drm.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 33 | #include "drm_crtc_helper.h" |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 34 | #include "drm_fb_helper.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 35 | #include "intel_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "i915_drm.h" |
| 37 | #include "i915_drv.h" |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame] | 38 | #include "i915_trace.h" |
Eric Anholt | 63ee41d | 2010-12-20 18:40:06 -0800 | [diff] [blame] | 39 | #include "../../../platform/x86/intel_ips.h" |
Jordan Crouse | dcdb167 | 2010-05-27 13:40:25 -0600 | [diff] [blame] | 40 | #include <linux/pci.h> |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 41 | #include <linux/vgaarb.h> |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 42 | #include <linux/acpi.h> |
| 43 | #include <linux/pnp.h> |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 44 | #include <linux/vga_switcheroo.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 46 | #include <linux/module.h> |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 47 | #include <acpi/video.h> |
Adam Jackson | 9e984bc1 | 2012-03-14 11:22:11 -0400 | [diff] [blame] | 48 | #include <asm/pat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Daniel Vetter | 09422b2 | 2012-04-26 23:28:10 +0200 | [diff] [blame^] | 50 | #define LP_RING(d) (&((struct drm_i915_private *)(d))->ring[RCS]) |
| 51 | |
| 52 | #define BEGIN_LP_RING(n) \ |
| 53 | intel_ring_begin(LP_RING(dev_priv), (n)) |
| 54 | |
| 55 | #define OUT_RING(x) \ |
| 56 | intel_ring_emit(LP_RING(dev_priv), x) |
| 57 | |
| 58 | #define ADVANCE_LP_RING() \ |
| 59 | intel_ring_advance(LP_RING(dev_priv)) |
| 60 | |
| 61 | /** |
| 62 | * Lock test for when it's just for synchronization of ring access. |
| 63 | * |
| 64 | * In that case, we don't need to do it when GEM is initialized as nobody else |
| 65 | * has access to the ring. |
| 66 | */ |
| 67 | #define RING_LOCK_TEST_WITH_RETURN(dev, file) do { \ |
| 68 | if (LP_RING(dev->dev_private)->obj == NULL) \ |
| 69 | LOCK_TEST_WITH_RETURN(dev, file); \ |
| 70 | } while (0) |
| 71 | |
| 72 | #define READ_HWSP(dev_priv, reg) intel_read_status_page(LP_RING(dev_priv), reg) |
| 73 | #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX) |
| 74 | #define I915_BREADCRUMB_INDEX 0x21 |
| 75 | |
Daniel Vetter | d05c617 | 2012-04-26 23:28:09 +0200 | [diff] [blame] | 76 | void i915_update_dri1_breadcrumb(struct drm_device *dev) |
| 77 | { |
| 78 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 79 | struct drm_i915_master_private *master_priv; |
| 80 | |
| 81 | if (dev->primary->master) { |
| 82 | master_priv = dev->primary->master->driver_priv; |
| 83 | if (master_priv->sarea_priv) |
| 84 | master_priv->sarea_priv->last_dispatch = |
| 85 | READ_BREADCRUMB(dev_priv); |
| 86 | } |
| 87 | } |
| 88 | |
Chris Wilson | 4cbf74c | 2011-02-25 22:26:23 +0000 | [diff] [blame] | 89 | static void i915_write_hws_pga(struct drm_device *dev) |
| 90 | { |
| 91 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 92 | u32 addr; |
| 93 | |
| 94 | addr = dev_priv->status_page_dmah->busaddr; |
| 95 | if (INTEL_INFO(dev)->gen >= 4) |
| 96 | addr |= (dev_priv->status_page_dmah->busaddr >> 28) & 0xf0; |
| 97 | I915_WRITE(HWS_PGA, addr); |
| 98 | } |
| 99 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Sets up the hardware status page for devices that need a physical address |
| 102 | * in the register. |
| 103 | */ |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 104 | static int i915_init_phys_hws(struct drm_device *dev) |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 105 | { |
| 106 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 107 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 108 | /* Program Hardware Status Page */ |
| 109 | dev_priv->status_page_dmah = |
Zhenyu Wang | e6be8d9 | 2010-01-05 11:25:05 +0800 | [diff] [blame] | 110 | drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 111 | |
| 112 | if (!dev_priv->status_page_dmah) { |
| 113 | DRM_ERROR("Can not allocate hardware status page\n"); |
| 114 | return -ENOMEM; |
| 115 | } |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 116 | |
Keith Packard | f323470 | 2011-07-22 10:44:39 -0700 | [diff] [blame] | 117 | memset_io((void __force __iomem *)dev_priv->status_page_dmah->vaddr, |
| 118 | 0, PAGE_SIZE); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 119 | |
Chris Wilson | 4cbf74c | 2011-02-25 22:26:23 +0000 | [diff] [blame] | 120 | i915_write_hws_pga(dev); |
Zhenyu Wang | 9b974cc | 2010-01-05 11:25:06 +0800 | [diff] [blame] | 121 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 122 | DRM_DEBUG_DRIVER("Enabled hardware status page\n"); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Frees the hardware status page, whether it's a physical address or a virtual |
| 128 | * address set up by the X Server. |
| 129 | */ |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 130 | static void i915_free_hws(struct drm_device *dev) |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 131 | { |
| 132 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 133 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
| 134 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 135 | if (dev_priv->status_page_dmah) { |
| 136 | drm_pci_free(dev, dev_priv->status_page_dmah); |
| 137 | dev_priv->status_page_dmah = NULL; |
| 138 | } |
| 139 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 140 | if (ring->status_page.gfx_addr) { |
| 141 | ring->status_page.gfx_addr = 0; |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 142 | drm_core_ioremapfree(&dev_priv->hws_map, dev); |
| 143 | } |
| 144 | |
| 145 | /* Need to rewrite hardware status page */ |
| 146 | I915_WRITE(HWS_PGA, 0x1ffff000); |
| 147 | } |
| 148 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 149 | void i915_kernel_lost_context(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 152 | struct drm_i915_master_private *master_priv; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 153 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 155 | /* |
| 156 | * We should never lose context on the ring with modesetting |
| 157 | * as we don't expose it to userspace |
| 158 | */ |
| 159 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 160 | return; |
| 161 | |
Chris Wilson | 8168bd4 | 2010-11-11 17:54:52 +0000 | [diff] [blame] | 162 | ring->head = I915_READ_HEAD(ring) & HEAD_ADDR; |
| 163 | ring->tail = I915_READ_TAIL(ring) & TAIL_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | ring->space = ring->head - (ring->tail + 8); |
| 165 | if (ring->space < 0) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 166 | ring->space += ring->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 168 | if (!dev->primary->master) |
| 169 | return; |
| 170 | |
| 171 | master_priv = dev->primary->master->driver_priv; |
| 172 | if (ring->head == ring->tail && master_priv->sarea_priv) |
| 173 | master_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 176 | static int i915_dma_cleanup(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 178 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 179 | int i; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 182 | * may not have been called from userspace and after dev_private |
| 183 | * is freed, it's too late. |
| 184 | */ |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 185 | if (dev->irq_enabled) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 186 | drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Dan Carpenter | ee0c6bf | 2010-06-23 13:19:55 +0200 | [diff] [blame] | 188 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 189 | for (i = 0; i < I915_NUM_RINGS; i++) |
| 190 | intel_cleanup_ring_buffer(&dev_priv->ring[i]); |
Dan Carpenter | ee0c6bf | 2010-06-23 13:19:55 +0200 | [diff] [blame] | 191 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 193 | /* Clear the HWS virtual address at teardown */ |
| 194 | if (I915_NEED_GFX_HWS(dev)) |
| 195 | i915_free_hws(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 200 | 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] | 201 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 202 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 203 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 204 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Dave Airlie | 3a03ac1 | 2009-01-11 09:03:49 +1000 | [diff] [blame] | 206 | master_priv->sarea = drm_getsarea(dev); |
| 207 | if (master_priv->sarea) { |
| 208 | master_priv->sarea_priv = (drm_i915_sarea_t *) |
| 209 | ((u8 *)master_priv->sarea->handle + init->sarea_priv_offset); |
| 210 | } else { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 211 | DRM_DEBUG_DRIVER("sarea not found assuming DRI2 userspace\n"); |
Dave Airlie | 3a03ac1 | 2009-01-11 09:03:49 +1000 | [diff] [blame] | 212 | } |
| 213 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 214 | if (init->ring_size != 0) { |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 215 | if (LP_RING(dev_priv)->obj != NULL) { |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 216 | i915_dma_cleanup(dev); |
| 217 | DRM_ERROR("Client tried to initialize ringbuffer in " |
| 218 | "GEM mode\n"); |
| 219 | return -EINVAL; |
| 220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 222 | ret = intel_render_ring_init_dri(dev, |
| 223 | init->ring_start, |
| 224 | init->ring_size); |
| 225 | if (ret) { |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 226 | i915_dma_cleanup(dev); |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 227 | return ret; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 231 | dev_priv->cpp = init->cpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | dev_priv->back_offset = init->back_offset; |
| 233 | dev_priv->front_offset = init->front_offset; |
| 234 | dev_priv->current_page = 0; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 235 | if (master_priv->sarea_priv) |
| 236 | master_priv->sarea_priv->pf_current_page = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | /* Allow hardware batchbuffers unless told otherwise. |
| 239 | */ |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 240 | dev_priv->dri1.allow_batchbuffer = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 245 | static int i915_dma_resume(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 248 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 250 | DRM_DEBUG_DRIVER("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 252 | if (ring->map.handle == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | DRM_ERROR("can not ioremap virtual address for" |
| 254 | " ring buffer\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 255 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /* Program Hardware Status Page */ |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 259 | if (!ring->status_page.page_addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | DRM_ERROR("Can not find hardware status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 261 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 263 | DRM_DEBUG_DRIVER("hw status page @ %p\n", |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 264 | ring->status_page.page_addr); |
| 265 | if (ring->status_page.gfx_addr != 0) |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 266 | intel_ring_setup_status_page(ring); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 267 | else |
Chris Wilson | 4cbf74c | 2011-02-25 22:26:23 +0000 | [diff] [blame] | 268 | i915_write_hws_pga(dev); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 269 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 270 | DRM_DEBUG_DRIVER("Enabled hardware status page\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 275 | static int i915_dma_init(struct drm_device *dev, void *data, |
| 276 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 278 | drm_i915_init_t *init = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | int retcode = 0; |
| 280 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 281 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 282 | return -ENODEV; |
| 283 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 284 | switch (init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | case I915_INIT_DMA: |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 286 | retcode = i915_initialize(dev, init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | break; |
| 288 | case I915_CLEANUP_DMA: |
| 289 | retcode = i915_dma_cleanup(dev); |
| 290 | break; |
| 291 | case I915_RESUME_DMA: |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 292 | retcode = i915_dma_resume(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | break; |
| 294 | default: |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 295 | retcode = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | break; |
| 297 | } |
| 298 | |
| 299 | return retcode; |
| 300 | } |
| 301 | |
| 302 | /* Implement basically the same security restrictions as hardware does |
| 303 | * for MI_BATCH_NON_SECURE. These can be made stricter at any time. |
| 304 | * |
| 305 | * Most of the calculations below involve calculating the size of a |
| 306 | * particular instruction. It's important to get the size right as |
| 307 | * that tells us where the next instruction to check is. Any illegal |
| 308 | * instruction detected will be given a size of zero, which is a |
| 309 | * signal to abort the rest of the buffer. |
| 310 | */ |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 311 | static int validate_cmd(int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
| 313 | switch (((cmd >> 29) & 0x7)) { |
| 314 | case 0x0: |
| 315 | switch ((cmd >> 23) & 0x3f) { |
| 316 | case 0x0: |
| 317 | return 1; /* MI_NOOP */ |
| 318 | case 0x4: |
| 319 | return 1; /* MI_FLUSH */ |
| 320 | default: |
| 321 | return 0; /* disallow everything else */ |
| 322 | } |
| 323 | break; |
| 324 | case 0x1: |
| 325 | return 0; /* reserved */ |
| 326 | case 0x2: |
| 327 | return (cmd & 0xff) + 2; /* 2d commands */ |
| 328 | case 0x3: |
| 329 | if (((cmd >> 24) & 0x1f) <= 0x18) |
| 330 | return 1; |
| 331 | |
| 332 | switch ((cmd >> 24) & 0x1f) { |
| 333 | case 0x1c: |
| 334 | return 1; |
| 335 | case 0x1d: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 336 | switch ((cmd >> 16) & 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | case 0x3: |
| 338 | return (cmd & 0x1f) + 2; |
| 339 | case 0x4: |
| 340 | return (cmd & 0xf) + 2; |
| 341 | default: |
| 342 | return (cmd & 0xffff) + 2; |
| 343 | } |
| 344 | case 0x1e: |
| 345 | if (cmd & (1 << 23)) |
| 346 | return (cmd & 0xffff) + 1; |
| 347 | else |
| 348 | return 1; |
| 349 | case 0x1f: |
| 350 | if ((cmd & (1 << 23)) == 0) /* inline vertices */ |
| 351 | return (cmd & 0x1ffff) + 2; |
| 352 | else if (cmd & (1 << 17)) /* indirect random */ |
| 353 | if ((cmd & 0xffff) == 0) |
| 354 | return 0; /* unknown length, too hard */ |
| 355 | else |
| 356 | return (((cmd & 0xffff) + 1) / 2) + 1; |
| 357 | else |
| 358 | return 2; /* indirect sequential */ |
| 359 | default: |
| 360 | return 0; |
| 361 | } |
| 362 | default: |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 369 | 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] | 370 | { |
| 371 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 372 | int i, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 374 | if ((dwords+1) * sizeof(int) >= LP_RING(dev_priv)->size - 8) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 375 | return -EINVAL; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | for (i = 0; i < dwords;) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 378 | int sz = validate_cmd(buffer[i]); |
| 379 | if (sz == 0 || i + sz > dwords) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 380 | return -EINVAL; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 381 | i += sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 384 | ret = BEGIN_LP_RING((dwords+1)&~1); |
| 385 | if (ret) |
| 386 | return ret; |
| 387 | |
| 388 | for (i = 0; i < dwords; i++) |
| 389 | OUT_RING(buffer[i]); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 390 | if (dwords & 1) |
| 391 | OUT_RING(0); |
| 392 | |
| 393 | ADVANCE_LP_RING(); |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 398 | int |
| 399 | i915_emit_box(struct drm_device *dev, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 400 | struct drm_clip_rect *box, |
| 401 | int DR1, int DR4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 403 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 404 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 406 | if (box->y2 <= box->y1 || box->x2 <= box->x1 || |
| 407 | box->y2 <= 0 || box->x2 <= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | DRM_ERROR("Bad box %d,%d..%d,%d\n", |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 409 | box->x1, box->y1, box->x2, box->y2); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 410 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 413 | if (INTEL_INFO(dev)->gen >= 4) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 414 | ret = BEGIN_LP_RING(4); |
| 415 | if (ret) |
| 416 | return ret; |
| 417 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 418 | OUT_RING(GFX_OP_DRAWRECT_INFO_I965); |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 419 | OUT_RING((box->x1 & 0xffff) | (box->y1 << 16)); |
| 420 | OUT_RING(((box->x2 - 1) & 0xffff) | ((box->y2 - 1) << 16)); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 421 | OUT_RING(DR4); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 422 | } else { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 423 | ret = BEGIN_LP_RING(6); |
| 424 | if (ret) |
| 425 | return ret; |
| 426 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 427 | OUT_RING(GFX_OP_DRAWRECT_INFO); |
| 428 | OUT_RING(DR1); |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 429 | OUT_RING((box->x1 & 0xffff) | (box->y1 << 16)); |
| 430 | OUT_RING(((box->x2 - 1) & 0xffff) | ((box->y2 - 1) << 16)); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 431 | OUT_RING(DR4); |
| 432 | OUT_RING(0); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 433 | } |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 434 | ADVANCE_LP_RING(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 439 | /* XXX: Emitting the counter should really be moved to part of the IRQ |
| 440 | * emit. For now, do it in both places: |
| 441 | */ |
| 442 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 443 | static void i915_emit_breadcrumb(struct drm_device *dev) |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 444 | { |
| 445 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 446 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 447 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 448 | dev_priv->counter++; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 449 | if (dev_priv->counter > 0x7FFFFFFFUL) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 450 | dev_priv->counter = 0; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 451 | if (master_priv->sarea_priv) |
| 452 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 453 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 454 | if (BEGIN_LP_RING(4) == 0) { |
| 455 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 456 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 457 | OUT_RING(dev_priv->counter); |
| 458 | OUT_RING(0); |
| 459 | ADVANCE_LP_RING(); |
| 460 | } |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 461 | } |
| 462 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 463 | static int i915_dispatch_cmdbuffer(struct drm_device * dev, |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 464 | drm_i915_cmdbuffer_t *cmd, |
| 465 | struct drm_clip_rect *cliprects, |
| 466 | void *cmdbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
| 468 | int nbox = cmd->num_cliprects; |
| 469 | int i = 0, count, ret; |
| 470 | |
| 471 | if (cmd->sz & 0x3) { |
| 472 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 473 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | i915_kernel_lost_context(dev); |
| 477 | |
| 478 | count = nbox ? nbox : 1; |
| 479 | |
| 480 | for (i = 0; i < count; i++) { |
| 481 | if (i < nbox) { |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 482 | ret = i915_emit_box(dev, &cliprects[i], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | cmd->DR1, cmd->DR4); |
| 484 | if (ret) |
| 485 | return ret; |
| 486 | } |
| 487 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 488 | ret = i915_emit_cmds(dev, cmdbuf, cmd->sz / 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | if (ret) |
| 490 | return ret; |
| 491 | } |
| 492 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 493 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | return 0; |
| 495 | } |
| 496 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 497 | static int i915_dispatch_batchbuffer(struct drm_device * dev, |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 498 | drm_i915_batchbuffer_t * batch, |
| 499 | struct drm_clip_rect *cliprects) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 501 | struct drm_i915_private *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | int nbox = batch->num_cliprects; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 503 | int i, count, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | if ((batch->start | batch->used) & 0x7) { |
| 506 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 507 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | i915_kernel_lost_context(dev); |
| 511 | |
| 512 | count = nbox ? nbox : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | for (i = 0; i < count; i++) { |
| 514 | if (i < nbox) { |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 515 | ret = i915_emit_box(dev, &cliprects[i], |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 516 | batch->DR1, batch->DR4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (ret) |
| 518 | return ret; |
| 519 | } |
| 520 | |
Keith Packard | 0790d5e | 2008-07-30 12:28:47 -0700 | [diff] [blame] | 521 | if (!IS_I830(dev) && !IS_845G(dev)) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 522 | ret = BEGIN_LP_RING(2); |
| 523 | if (ret) |
| 524 | return ret; |
| 525 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 526 | if (INTEL_INFO(dev)->gen >= 4) { |
Dave Airlie | 21f1628 | 2007-08-07 09:09:51 +1000 | [diff] [blame] | 527 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965); |
| 528 | OUT_RING(batch->start); |
| 529 | } else { |
| 530 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6)); |
| 531 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 532 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } else { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 534 | ret = BEGIN_LP_RING(4); |
| 535 | if (ret) |
| 536 | return ret; |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | OUT_RING(MI_BATCH_BUFFER); |
| 539 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 540 | OUT_RING(batch->start + batch->used - 4); |
| 541 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 543 | ADVANCE_LP_RING(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Zou Nan hai | 1cafd34 | 2010-06-25 13:40:24 +0800 | [diff] [blame] | 546 | |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 547 | if (IS_G4X(dev) || IS_GEN5(dev)) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 548 | if (BEGIN_LP_RING(2) == 0) { |
| 549 | OUT_RING(MI_FLUSH | MI_NO_WRITE_FLUSH | MI_INVALIDATE_ISP); |
| 550 | OUT_RING(MI_NOOP); |
| 551 | ADVANCE_LP_RING(); |
| 552 | } |
Zou Nan hai | 1cafd34 | 2010-06-25 13:40:24 +0800 | [diff] [blame] | 553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 555 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 559 | static int i915_dispatch_flip(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
| 561 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 562 | struct drm_i915_master_private *master_priv = |
| 563 | dev->primary->master->driver_priv; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 564 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 566 | if (!master_priv->sarea_priv) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 567 | return -EINVAL; |
| 568 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 569 | DRM_DEBUG_DRIVER("%s: page=%d pfCurrentPage=%d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 570 | __func__, |
| 571 | dev_priv->current_page, |
| 572 | master_priv->sarea_priv->pf_current_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 574 | i915_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 576 | ret = BEGIN_LP_RING(10); |
| 577 | if (ret) |
| 578 | return ret; |
| 579 | |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 580 | OUT_RING(MI_FLUSH | MI_READ_FLUSH); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 581 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 583 | OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP); |
| 584 | OUT_RING(0); |
| 585 | if (dev_priv->current_page == 0) { |
| 586 | OUT_RING(dev_priv->back_offset); |
| 587 | dev_priv->current_page = 1; |
| 588 | } else { |
| 589 | OUT_RING(dev_priv->front_offset); |
| 590 | dev_priv->current_page = 0; |
| 591 | } |
| 592 | OUT_RING(0); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 593 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 594 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP); |
| 595 | OUT_RING(0); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 596 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 597 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 598 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 599 | master_priv->sarea_priv->last_enqueue = dev_priv->counter++; |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 600 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 601 | if (BEGIN_LP_RING(4) == 0) { |
| 602 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 603 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 604 | OUT_RING(dev_priv->counter); |
| 605 | OUT_RING(0); |
| 606 | ADVANCE_LP_RING(); |
| 607 | } |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 608 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 609 | master_priv->sarea_priv->pf_current_page = dev_priv->current_page; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 610 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 613 | static int i915_quiescent(struct drm_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 615 | struct intel_ring_buffer *ring = LP_RING(dev->dev_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | i915_kernel_lost_context(dev); |
Ben Widawsky | 96f298a | 2011-03-19 18:14:27 -0700 | [diff] [blame] | 618 | return intel_wait_ring_idle(ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 621 | static int i915_flush_ioctl(struct drm_device *dev, void *data, |
| 622 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 624 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 626 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 627 | return -ENODEV; |
| 628 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 629 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 630 | |
| 631 | mutex_lock(&dev->struct_mutex); |
| 632 | ret = i915_quiescent(dev); |
| 633 | mutex_unlock(&dev->struct_mutex); |
| 634 | |
| 635 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 638 | static int i915_batchbuffer(struct drm_device *dev, void *data, |
| 639 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 642 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 644 | master_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 645 | drm_i915_batchbuffer_t *batch = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | int ret; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 647 | struct drm_clip_rect *cliprects = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 649 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 650 | return -ENODEV; |
| 651 | |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 652 | if (!dev_priv->dri1.allow_batchbuffer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | DRM_ERROR("Batchbuffer ioctl disabled\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 654 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 657 | DRM_DEBUG_DRIVER("i915 batchbuffer, start %x used %d cliprects %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 658 | batch->start, batch->used, batch->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 660 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 662 | if (batch->num_cliprects < 0) |
| 663 | return -EINVAL; |
| 664 | |
| 665 | if (batch->num_cliprects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 666 | cliprects = kcalloc(batch->num_cliprects, |
| 667 | sizeof(struct drm_clip_rect), |
| 668 | GFP_KERNEL); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 669 | if (cliprects == NULL) |
| 670 | return -ENOMEM; |
| 671 | |
| 672 | ret = copy_from_user(cliprects, batch->cliprects, |
| 673 | batch->num_cliprects * |
| 674 | sizeof(struct drm_clip_rect)); |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 675 | if (ret != 0) { |
| 676 | ret = -EFAULT; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 677 | goto fail_free; |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 678 | } |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 681 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 682 | ret = i915_dispatch_batchbuffer(dev, batch, cliprects); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 683 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 685 | if (sarea_priv) |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 686 | sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 687 | |
| 688 | fail_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 689 | kfree(cliprects); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | return ret; |
| 692 | } |
| 693 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 694 | static int i915_cmdbuffer(struct drm_device *dev, void *data, |
| 695 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 698 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 700 | master_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 701 | drm_i915_cmdbuffer_t *cmdbuf = data; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 702 | struct drm_clip_rect *cliprects = NULL; |
| 703 | void *batch_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | int ret; |
| 705 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 706 | DRM_DEBUG_DRIVER("i915 cmdbuffer, buf %p sz %d cliprects %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 707 | cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 709 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 710 | return -ENODEV; |
| 711 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 712 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 714 | if (cmdbuf->num_cliprects < 0) |
| 715 | return -EINVAL; |
| 716 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 717 | batch_data = kmalloc(cmdbuf->sz, GFP_KERNEL); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 718 | if (batch_data == NULL) |
| 719 | return -ENOMEM; |
| 720 | |
| 721 | ret = copy_from_user(batch_data, cmdbuf->buf, cmdbuf->sz); |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 722 | if (ret != 0) { |
| 723 | ret = -EFAULT; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 724 | goto fail_batch_free; |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 725 | } |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 726 | |
| 727 | if (cmdbuf->num_cliprects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 728 | cliprects = kcalloc(cmdbuf->num_cliprects, |
| 729 | sizeof(struct drm_clip_rect), GFP_KERNEL); |
Owain Ainsworth | a40e8d3 | 2010-02-09 14:25:55 +0000 | [diff] [blame] | 730 | if (cliprects == NULL) { |
| 731 | ret = -ENOMEM; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 732 | goto fail_batch_free; |
Owain Ainsworth | a40e8d3 | 2010-02-09 14:25:55 +0000 | [diff] [blame] | 733 | } |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 734 | |
| 735 | ret = copy_from_user(cliprects, cmdbuf->cliprects, |
| 736 | cmdbuf->num_cliprects * |
| 737 | sizeof(struct drm_clip_rect)); |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 738 | if (ret != 0) { |
| 739 | ret = -EFAULT; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 740 | goto fail_clip_free; |
Dan Carpenter | 9927a40 | 2010-06-19 15:12:51 +0200 | [diff] [blame] | 741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 744 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 745 | ret = i915_dispatch_cmdbuffer(dev, cmdbuf, cliprects, batch_data); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 746 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | if (ret) { |
| 748 | DRM_ERROR("i915_dispatch_cmdbuffer failed\n"); |
Chris Wright | 355d7f3 | 2009-04-17 01:18:55 +0000 | [diff] [blame] | 749 | goto fail_clip_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 752 | if (sarea_priv) |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 753 | sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 754 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 755 | fail_clip_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 756 | kfree(cliprects); |
Chris Wright | 355d7f3 | 2009-04-17 01:18:55 +0000 | [diff] [blame] | 757 | fail_batch_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 758 | kfree(batch_data); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 759 | |
| 760 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Daniel Vetter | 9488867 | 2012-04-26 23:28:08 +0200 | [diff] [blame] | 763 | static int i915_emit_irq(struct drm_device * dev) |
| 764 | { |
| 765 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 766 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 767 | |
| 768 | i915_kernel_lost_context(dev); |
| 769 | |
| 770 | DRM_DEBUG_DRIVER("\n"); |
| 771 | |
| 772 | dev_priv->counter++; |
| 773 | if (dev_priv->counter > 0x7FFFFFFFUL) |
| 774 | dev_priv->counter = 1; |
| 775 | if (master_priv->sarea_priv) |
| 776 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
| 777 | |
| 778 | if (BEGIN_LP_RING(4) == 0) { |
| 779 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 780 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 781 | OUT_RING(dev_priv->counter); |
| 782 | OUT_RING(MI_USER_INTERRUPT); |
| 783 | ADVANCE_LP_RING(); |
| 784 | } |
| 785 | |
| 786 | return dev_priv->counter; |
| 787 | } |
| 788 | |
| 789 | static int i915_wait_irq(struct drm_device * dev, int irq_nr) |
| 790 | { |
| 791 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 792 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 793 | int ret = 0; |
| 794 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
| 795 | |
| 796 | DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr, |
| 797 | READ_BREADCRUMB(dev_priv)); |
| 798 | |
| 799 | if (READ_BREADCRUMB(dev_priv) >= irq_nr) { |
| 800 | if (master_priv->sarea_priv) |
| 801 | master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | if (master_priv->sarea_priv) |
| 806 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
| 807 | |
| 808 | if (ring->irq_get(ring)) { |
| 809 | DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ, |
| 810 | READ_BREADCRUMB(dev_priv) >= irq_nr); |
| 811 | ring->irq_put(ring); |
| 812 | } else if (wait_for(READ_BREADCRUMB(dev_priv) >= irq_nr, 3000)) |
| 813 | ret = -EBUSY; |
| 814 | |
| 815 | if (ret == -EBUSY) { |
| 816 | DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", |
| 817 | READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); |
| 818 | } |
| 819 | |
| 820 | return ret; |
| 821 | } |
| 822 | |
| 823 | /* Needs the lock as it touches the ring. |
| 824 | */ |
| 825 | static int i915_irq_emit(struct drm_device *dev, void *data, |
| 826 | struct drm_file *file_priv) |
| 827 | { |
| 828 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 829 | drm_i915_irq_emit_t *emit = data; |
| 830 | int result; |
| 831 | |
| 832 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 833 | return -ENODEV; |
| 834 | |
| 835 | if (!dev_priv || !LP_RING(dev_priv)->virtual_start) { |
| 836 | DRM_ERROR("called with no initialization\n"); |
| 837 | return -EINVAL; |
| 838 | } |
| 839 | |
| 840 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 841 | |
| 842 | mutex_lock(&dev->struct_mutex); |
| 843 | result = i915_emit_irq(dev); |
| 844 | mutex_unlock(&dev->struct_mutex); |
| 845 | |
| 846 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
| 847 | DRM_ERROR("copy_to_user\n"); |
| 848 | return -EFAULT; |
| 849 | } |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | /* Doesn't need the hardware lock. |
| 855 | */ |
| 856 | static int i915_irq_wait(struct drm_device *dev, void *data, |
| 857 | struct drm_file *file_priv) |
| 858 | { |
| 859 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 860 | drm_i915_irq_wait_t *irqwait = data; |
| 861 | |
| 862 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 863 | return -ENODEV; |
| 864 | |
| 865 | if (!dev_priv) { |
| 866 | DRM_ERROR("called with no initialization\n"); |
| 867 | return -EINVAL; |
| 868 | } |
| 869 | |
| 870 | return i915_wait_irq(dev, irqwait->irq_seq); |
| 871 | } |
| 872 | |
Daniel Vetter | d1c1edb | 2012-04-26 23:28:01 +0200 | [diff] [blame] | 873 | static int i915_vblank_pipe_get(struct drm_device *dev, void *data, |
| 874 | struct drm_file *file_priv) |
| 875 | { |
| 876 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 877 | drm_i915_vblank_pipe_t *pipe = data; |
| 878 | |
| 879 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 880 | return -ENODEV; |
| 881 | |
| 882 | if (!dev_priv) { |
| 883 | DRM_ERROR("called with no initialization\n"); |
| 884 | return -EINVAL; |
| 885 | } |
| 886 | |
| 887 | pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Schedule buffer swap at given vertical blank. |
| 894 | */ |
| 895 | static int i915_vblank_swap(struct drm_device *dev, void *data, |
| 896 | struct drm_file *file_priv) |
| 897 | { |
| 898 | /* The delayed swap mechanism was fundamentally racy, and has been |
| 899 | * removed. The model was that the client requested a delayed flip/swap |
| 900 | * from the kernel, then waited for vblank before continuing to perform |
| 901 | * rendering. The problem was that the kernel might wake the client |
| 902 | * up before it dispatched the vblank swap (since the lock has to be |
| 903 | * held while touching the ringbuffer), in which case the client would |
| 904 | * clear and start the next frame before the swap occurred, and |
| 905 | * flicker would occur in addition to likely missing the vblank. |
| 906 | * |
| 907 | * In the absence of this ioctl, userland falls back to a correct path |
| 908 | * of waiting for a vblank, then dispatching the swap on its own. |
| 909 | * Context switching to userland and back is plenty fast enough for |
| 910 | * meeting the requirements of vblank swapping. |
| 911 | */ |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 915 | static int i915_flip_bufs(struct drm_device *dev, void *data, |
| 916 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 918 | int ret; |
| 919 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 920 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 921 | return -ENODEV; |
| 922 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 923 | DRM_DEBUG_DRIVER("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 925 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 927 | mutex_lock(&dev->struct_mutex); |
| 928 | ret = i915_dispatch_flip(dev); |
| 929 | mutex_unlock(&dev->struct_mutex); |
| 930 | |
| 931 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 934 | static int i915_getparam(struct drm_device *dev, void *data, |
| 935 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 938 | drm_i915_getparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | int value; |
| 940 | |
| 941 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 942 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 943 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 946 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | case I915_PARAM_IRQ_ACTIVE: |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 948 | value = dev->pdev->irq ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | break; |
| 950 | case I915_PARAM_ALLOW_BATCHBUFFER: |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 951 | value = dev_priv->dri1.allow_batchbuffer ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | break; |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 953 | case I915_PARAM_LAST_DISPATCH: |
| 954 | value = READ_BREADCRUMB(dev_priv); |
| 955 | break; |
Kristian Høgsberg | ed4c9c4 | 2008-08-20 11:08:52 -0400 | [diff] [blame] | 956 | case I915_PARAM_CHIPSET_ID: |
| 957 | value = dev->pci_device; |
| 958 | break; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 959 | case I915_PARAM_HAS_GEM: |
Daniel Vetter | 2e895b1 | 2012-04-23 16:50:51 +0200 | [diff] [blame] | 960 | value = 1; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 961 | break; |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 962 | case I915_PARAM_NUM_FENCES_AVAIL: |
| 963 | value = dev_priv->num_fence_regs - dev_priv->fence_reg_start; |
| 964 | break; |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 965 | case I915_PARAM_HAS_OVERLAY: |
| 966 | value = dev_priv->overlay ? 1 : 0; |
| 967 | break; |
Jesse Barnes | e9560f7 | 2009-11-19 10:49:07 -0800 | [diff] [blame] | 968 | case I915_PARAM_HAS_PAGEFLIPPING: |
| 969 | value = 1; |
| 970 | break; |
Jesse Barnes | 76446ca | 2009-12-17 22:05:42 -0500 | [diff] [blame] | 971 | case I915_PARAM_HAS_EXECBUF2: |
| 972 | /* depends on GEM */ |
Daniel Vetter | 2e895b1 | 2012-04-23 16:50:51 +0200 | [diff] [blame] | 973 | value = 1; |
Jesse Barnes | 76446ca | 2009-12-17 22:05:42 -0500 | [diff] [blame] | 974 | break; |
Zou Nan hai | e3a815f | 2010-05-31 13:58:47 +0800 | [diff] [blame] | 975 | case I915_PARAM_HAS_BSD: |
| 976 | value = HAS_BSD(dev); |
| 977 | break; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 978 | case I915_PARAM_HAS_BLT: |
| 979 | value = HAS_BLT(dev); |
| 980 | break; |
Chris Wilson | a00b10c | 2010-09-24 21:15:47 +0100 | [diff] [blame] | 981 | case I915_PARAM_HAS_RELAXED_FENCING: |
| 982 | value = 1; |
| 983 | break; |
Daniel Vetter | bbf0c6b | 2010-12-05 11:30:40 +0100 | [diff] [blame] | 984 | case I915_PARAM_HAS_COHERENT_RINGS: |
| 985 | value = 1; |
| 986 | break; |
Chris Wilson | 72bfa19 | 2010-12-19 11:42:05 +0000 | [diff] [blame] | 987 | case I915_PARAM_HAS_EXEC_CONSTANTS: |
| 988 | value = INTEL_INFO(dev)->gen >= 4; |
| 989 | break; |
Chris Wilson | 271d81b | 2011-03-01 15:24:41 +0000 | [diff] [blame] | 990 | case I915_PARAM_HAS_RELAXED_DELTA: |
| 991 | value = 1; |
| 992 | break; |
Eric Anholt | ae662d3 | 2012-01-03 09:23:29 -0800 | [diff] [blame] | 993 | case I915_PARAM_HAS_GEN7_SOL_RESET: |
| 994 | value = 1; |
| 995 | break; |
Eugeni Dodonov | 3d29b84 | 2012-01-17 14:43:53 -0200 | [diff] [blame] | 996 | case I915_PARAM_HAS_LLC: |
| 997 | value = HAS_LLC(dev); |
| 998 | break; |
Daniel Vetter | 777ee96 | 2012-02-15 23:50:25 +0100 | [diff] [blame] | 999 | case I915_PARAM_HAS_ALIASING_PPGTT: |
| 1000 | value = dev_priv->mm.aliasing_ppgtt ? 1 : 0; |
| 1001 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | default: |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1003 | DRM_DEBUG_DRIVER("Unknown parameter %d\n", |
Jesse Barnes | 76446ca | 2009-12-17 22:05:42 -0500 | [diff] [blame] | 1004 | param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1005 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1008 | if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | DRM_ERROR("DRM_COPY_TO_USER failed\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1010 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1016 | static int i915_setparam(struct drm_device *dev, void *data, |
| 1017 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1020 | drm_i915_setparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
| 1022 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1023 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1024 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1027 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | case I915_SETPARAM_USE_MI_BATCHBUFFER_START: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | break; |
| 1030 | case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | break; |
| 1032 | case I915_SETPARAM_ALLOW_BATCHBUFFER: |
Daniel Vetter | 8781342 | 2012-05-02 11:49:32 +0200 | [diff] [blame] | 1033 | dev_priv->dri1.allow_batchbuffer = param->value ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | break; |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 1035 | case I915_SETPARAM_NUM_USED_FENCES: |
| 1036 | if (param->value > dev_priv->num_fence_regs || |
| 1037 | param->value < 0) |
| 1038 | return -EINVAL; |
| 1039 | /* Userspace can use first N regs */ |
| 1040 | dev_priv->fence_reg_start = param->value; |
| 1041 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | default: |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1043 | DRM_DEBUG_DRIVER("unknown parameter %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 1044 | param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1045 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1051 | static int i915_set_status_page(struct drm_device *dev, void *data, |
| 1052 | struct drm_file *file_priv) |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1053 | { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1054 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1055 | drm_i915_hws_addr_t *hws = data; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1056 | struct intel_ring_buffer *ring = LP_RING(dev_priv); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1057 | |
Daniel Vetter | cd9d4e9 | 2012-04-24 08:29:42 +0200 | [diff] [blame] | 1058 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1059 | return -ENODEV; |
| 1060 | |
Zhenyu Wang | b39d50e | 2008-02-19 20:59:09 +1000 | [diff] [blame] | 1061 | if (!I915_NEED_GFX_HWS(dev)) |
| 1062 | return -EINVAL; |
| 1063 | |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1064 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 1065 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1066 | return -EINVAL; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1067 | } |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1068 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1069 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 1070 | WARN(1, "tried to set status page when mode setting active\n"); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1074 | 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] | 1075 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1076 | ring->status_page.gfx_addr = hws->addr & (0x1ffff<<12); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1077 | |
Eric Anholt | 8b40958 | 2007-11-22 16:40:37 +1000 | [diff] [blame] | 1078 | dev_priv->hws_map.offset = dev->agp->base + hws->addr; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1079 | dev_priv->hws_map.size = 4*1024; |
| 1080 | dev_priv->hws_map.type = 0; |
| 1081 | dev_priv->hws_map.flags = 0; |
| 1082 | dev_priv->hws_map.mtrr = 0; |
| 1083 | |
Dave Airlie | dd0910b | 2009-02-25 14:49:21 +1000 | [diff] [blame] | 1084 | drm_core_ioremap_wc(&dev_priv->hws_map, dev); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1085 | if (dev_priv->hws_map.handle == NULL) { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1086 | i915_dma_cleanup(dev); |
Eric Anholt | e20f9c6 | 2010-05-26 14:51:06 -0700 | [diff] [blame] | 1087 | ring->status_page.gfx_addr = 0; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1088 | DRM_ERROR("can not ioremap virtual address for" |
| 1089 | " G33 hw status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1090 | return -ENOMEM; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1091 | } |
Chris Wilson | 311bd68 | 2011-01-13 19:06:50 +0000 | [diff] [blame] | 1092 | ring->status_page.page_addr = |
| 1093 | (void __force __iomem *)dev_priv->hws_map.handle; |
| 1094 | memset_io(ring->status_page.page_addr, 0, PAGE_SIZE); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1095 | I915_WRITE(HWS_PGA, ring->status_page.gfx_addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1096 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1097 | 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] | 1098 | ring->status_page.gfx_addr); |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1099 | DRM_DEBUG_DRIVER("load hws at %p\n", |
Eric Anholt | e20f9c6 | 2010-05-26 14:51:06 -0700 | [diff] [blame] | 1100 | ring->status_page.page_addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 1101 | return 0; |
| 1102 | } |
| 1103 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1104 | static int i915_get_bridge_dev(struct drm_device *dev) |
| 1105 | { |
| 1106 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1107 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1108 | 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] | 1109 | if (!dev_priv->bridge_dev) { |
| 1110 | DRM_ERROR("bridge device not found\n"); |
| 1111 | return -1; |
| 1112 | } |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1116 | #define MCHBAR_I915 0x44 |
| 1117 | #define MCHBAR_I965 0x48 |
| 1118 | #define MCHBAR_SIZE (4*4096) |
| 1119 | |
| 1120 | #define DEVEN_REG 0x54 |
| 1121 | #define DEVEN_MCHBAR_EN (1 << 28) |
| 1122 | |
| 1123 | /* Allocate space for the MCH regs if needed, return nonzero on error */ |
| 1124 | static int |
| 1125 | intel_alloc_mchbar_resource(struct drm_device *dev) |
| 1126 | { |
| 1127 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1128 | int reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1129 | u32 temp_lo, temp_hi = 0; |
| 1130 | u64 mchbar_addr; |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1131 | int ret; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1132 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1133 | if (INTEL_INFO(dev)->gen >= 4) |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1134 | pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi); |
| 1135 | pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo); |
| 1136 | mchbar_addr = ((u64)temp_hi << 32) | temp_lo; |
| 1137 | |
| 1138 | /* If ACPI doesn't have it, assume we need to allocate it ourselves */ |
| 1139 | #ifdef CONFIG_PNP |
| 1140 | if (mchbar_addr && |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1141 | pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) |
| 1142 | return 0; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1143 | #endif |
| 1144 | |
| 1145 | /* Get some space for it */ |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1146 | dev_priv->mch_res.name = "i915 MCHBAR"; |
| 1147 | dev_priv->mch_res.flags = IORESOURCE_MEM; |
| 1148 | ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus, |
| 1149 | &dev_priv->mch_res, |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1150 | MCHBAR_SIZE, MCHBAR_SIZE, |
| 1151 | PCIBIOS_MIN_MEM, |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1152 | 0, pcibios_align_resource, |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1153 | dev_priv->bridge_dev); |
| 1154 | if (ret) { |
| 1155 | DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret); |
| 1156 | dev_priv->mch_res.start = 0; |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1157 | return ret; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1158 | } |
| 1159 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1160 | if (INTEL_INFO(dev)->gen >= 4) |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1161 | pci_write_config_dword(dev_priv->bridge_dev, reg + 4, |
| 1162 | upper_32_bits(dev_priv->mch_res.start)); |
| 1163 | |
| 1164 | pci_write_config_dword(dev_priv->bridge_dev, reg, |
| 1165 | lower_32_bits(dev_priv->mch_res.start)); |
Chris Wilson | a25c25c | 2010-08-20 14:36:45 +0100 | [diff] [blame] | 1166 | return 0; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | /* Setup MCHBAR if possible, return true if we should disable it again */ |
| 1170 | static void |
| 1171 | intel_setup_mchbar(struct drm_device *dev) |
| 1172 | { |
| 1173 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1174 | int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1175 | u32 temp; |
| 1176 | bool enabled; |
| 1177 | |
| 1178 | dev_priv->mchbar_need_disable = false; |
| 1179 | |
| 1180 | if (IS_I915G(dev) || IS_I915GM(dev)) { |
| 1181 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); |
| 1182 | enabled = !!(temp & DEVEN_MCHBAR_EN); |
| 1183 | } else { |
| 1184 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 1185 | enabled = temp & 1; |
| 1186 | } |
| 1187 | |
| 1188 | /* If it's already enabled, don't have to do anything */ |
| 1189 | if (enabled) |
| 1190 | return; |
| 1191 | |
| 1192 | if (intel_alloc_mchbar_resource(dev)) |
| 1193 | return; |
| 1194 | |
| 1195 | dev_priv->mchbar_need_disable = true; |
| 1196 | |
| 1197 | /* Space is allocated or reserved, so enable it. */ |
| 1198 | if (IS_I915G(dev) || IS_I915GM(dev)) { |
| 1199 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, |
| 1200 | temp | DEVEN_MCHBAR_EN); |
| 1201 | } else { |
| 1202 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 1203 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1); |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | static void |
| 1208 | intel_teardown_mchbar(struct drm_device *dev) |
| 1209 | { |
| 1210 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1211 | int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 1212 | u32 temp; |
| 1213 | |
| 1214 | if (dev_priv->mchbar_need_disable) { |
| 1215 | if (IS_I915G(dev) || IS_I915GM(dev)) { |
| 1216 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); |
| 1217 | temp &= ~DEVEN_MCHBAR_EN; |
| 1218 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, temp); |
| 1219 | } else { |
| 1220 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 1221 | temp &= ~1; |
| 1222 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | if (dev_priv->mch_res.start) |
| 1227 | release_resource(&dev_priv->mch_res); |
| 1228 | } |
| 1229 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1230 | /* true = enable decode, false = disable decoder */ |
| 1231 | static unsigned int i915_vga_set_decode(void *cookie, bool state) |
| 1232 | { |
| 1233 | struct drm_device *dev = cookie; |
| 1234 | |
| 1235 | intel_modeset_vga_set_state(dev, state); |
| 1236 | if (state) |
| 1237 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 1238 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 1239 | else |
| 1240 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 1241 | } |
| 1242 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1243 | static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) |
| 1244 | { |
| 1245 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 1246 | pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; |
| 1247 | if (state == VGA_SWITCHEROO_ON) { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1248 | pr_info("switched on\n"); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1249 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1250 | /* i915 resume handler doesn't set to D0 */ |
| 1251 | pci_set_power_state(dev->pdev, PCI_D0); |
| 1252 | i915_resume(dev); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1253 | dev->switch_power_state = DRM_SWITCH_POWER_ON; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1254 | } else { |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 1255 | pr_err("switched off\n"); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1256 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1257 | i915_suspend(dev, pmm); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1258 | dev->switch_power_state = DRM_SWITCH_POWER_OFF; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | static bool i915_switcheroo_can_switch(struct pci_dev *pdev) |
| 1263 | { |
| 1264 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 1265 | bool can_switch; |
| 1266 | |
| 1267 | spin_lock(&dev->count_lock); |
| 1268 | can_switch = (dev->open_count == 0); |
| 1269 | spin_unlock(&dev->count_lock); |
| 1270 | return can_switch; |
| 1271 | } |
| 1272 | |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1273 | static int i915_load_modeset_init(struct drm_device *dev) |
| 1274 | { |
| 1275 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1276 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1277 | |
Bryan Freed | 6d139a8 | 2010-10-14 09:14:51 +0100 | [diff] [blame] | 1278 | ret = intel_parse_bios(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1279 | if (ret) |
| 1280 | DRM_INFO("failed to find VBIOS tables\n"); |
| 1281 | |
Chris Wilson | 934f992 | 2011-01-20 13:09:12 +0000 | [diff] [blame] | 1282 | /* If we have > 1 VGA cards, then we need to arbitrate access |
| 1283 | * to the common VGA resources. |
| 1284 | * |
| 1285 | * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA), |
| 1286 | * then we do not take part in VGA arbitration and the |
| 1287 | * vga_client_register() fails with -ENODEV. |
| 1288 | */ |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1289 | ret = vga_client_register(dev->pdev, dev, NULL, i915_vga_set_decode); |
Chris Wilson | 934f992 | 2011-01-20 13:09:12 +0000 | [diff] [blame] | 1290 | if (ret && ret != -ENODEV) |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1291 | goto out; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 1292 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 1293 | intel_register_dsm_handler(); |
| 1294 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1295 | ret = vga_switcheroo_register_client(dev->pdev, |
| 1296 | i915_switcheroo_set_state, |
Dave Airlie | 8d608aa | 2010-12-07 08:57:57 +1000 | [diff] [blame] | 1297 | NULL, |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1298 | i915_switcheroo_can_switch); |
| 1299 | if (ret) |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1300 | goto cleanup_vga_client; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1301 | |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 1302 | /* Initialise stolen first so that we may reserve preallocated |
| 1303 | * objects for the BIOS to KMS transition. |
| 1304 | */ |
| 1305 | ret = i915_gem_init_stolen(dev); |
| 1306 | if (ret) |
| 1307 | goto cleanup_vga_switcheroo; |
| 1308 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 1309 | intel_modeset_init(dev); |
| 1310 | |
Chris Wilson | 1070a42 | 2012-04-24 15:47:41 +0100 | [diff] [blame] | 1311 | ret = i915_gem_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1312 | if (ret) |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 1313 | goto cleanup_gem_stolen; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1314 | |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1315 | intel_modeset_gem_init(dev); |
| 1316 | |
| 1317 | ret = drm_irq_install(dev); |
| 1318 | if (ret) |
| 1319 | goto cleanup_gem; |
| 1320 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1321 | /* Always safe in the mode setting case. */ |
| 1322 | /* FIXME: do pre/post-mode set stuff in core KMS code */ |
| 1323 | dev->vblank_disable_allowed = 1; |
| 1324 | |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1325 | ret = intel_fbdev_init(dev); |
| 1326 | if (ret) |
| 1327 | goto cleanup_irq; |
| 1328 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1329 | drm_kms_helper_poll_init(dev); |
Chris Wilson | 87acb0a | 2010-10-19 10:13:00 +0100 | [diff] [blame] | 1330 | |
| 1331 | /* We're off and running w/KMS */ |
| 1332 | dev_priv->mm.suspended = 0; |
| 1333 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1334 | return 0; |
| 1335 | |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1336 | cleanup_irq: |
| 1337 | drm_irq_uninstall(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 1338 | cleanup_gem: |
| 1339 | mutex_lock(&dev->struct_mutex); |
| 1340 | i915_gem_cleanup_ringbuffer(dev); |
| 1341 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1342 | i915_gem_cleanup_aliasing_ppgtt(dev); |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 1343 | cleanup_gem_stolen: |
| 1344 | i915_gem_cleanup_stolen(dev); |
Chris Wilson | 5a79395 | 2010-06-06 10:50:03 +0100 | [diff] [blame] | 1345 | cleanup_vga_switcheroo: |
| 1346 | vga_switcheroo_unregister_client(dev->pdev); |
| 1347 | cleanup_vga_client: |
| 1348 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1349 | out: |
| 1350 | return ret; |
| 1351 | } |
| 1352 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1353 | int i915_master_create(struct drm_device *dev, struct drm_master *master) |
| 1354 | { |
| 1355 | struct drm_i915_master_private *master_priv; |
| 1356 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1357 | master_priv = kzalloc(sizeof(*master_priv), GFP_KERNEL); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1358 | if (!master_priv) |
| 1359 | return -ENOMEM; |
| 1360 | |
| 1361 | master->driver_priv = master_priv; |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
| 1365 | void i915_master_destroy(struct drm_device *dev, struct drm_master *master) |
| 1366 | { |
| 1367 | struct drm_i915_master_private *master_priv = master->driver_priv; |
| 1368 | |
| 1369 | if (!master_priv) |
| 1370 | return; |
| 1371 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1372 | kfree(master_priv); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1373 | |
| 1374 | master->driver_priv = NULL; |
| 1375 | } |
| 1376 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1377 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1378 | { |
| 1379 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1380 | u32 tmp; |
| 1381 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1382 | tmp = I915_READ(CLKCFG); |
| 1383 | |
| 1384 | switch (tmp & CLKCFG_FSB_MASK) { |
| 1385 | case CLKCFG_FSB_533: |
| 1386 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 1387 | break; |
| 1388 | case CLKCFG_FSB_800: |
| 1389 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 1390 | break; |
| 1391 | case CLKCFG_FSB_667: |
| 1392 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 1393 | break; |
| 1394 | case CLKCFG_FSB_400: |
| 1395 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | switch (tmp & CLKCFG_MEM_MASK) { |
| 1400 | case CLKCFG_MEM_533: |
| 1401 | dev_priv->mem_freq = 533; |
| 1402 | break; |
| 1403 | case CLKCFG_MEM_667: |
| 1404 | dev_priv->mem_freq = 667; |
| 1405 | break; |
| 1406 | case CLKCFG_MEM_800: |
| 1407 | dev_priv->mem_freq = 800; |
| 1408 | break; |
| 1409 | } |
Li Peng | 9553426 | 2010-05-18 18:58:44 +0800 | [diff] [blame] | 1410 | |
| 1411 | /* detect pineview DDR3 setting */ |
| 1412 | tmp = I915_READ(CSHRDDR3CTL); |
| 1413 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1414 | } |
| 1415 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1416 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 1417 | { |
| 1418 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1419 | u16 ddrpll, csipll; |
| 1420 | |
| 1421 | ddrpll = I915_READ16(DDRMPLL1); |
| 1422 | csipll = I915_READ16(CSIPLL0); |
| 1423 | |
| 1424 | switch (ddrpll & 0xff) { |
| 1425 | case 0xc: |
| 1426 | dev_priv->mem_freq = 800; |
| 1427 | break; |
| 1428 | case 0x10: |
| 1429 | dev_priv->mem_freq = 1066; |
| 1430 | break; |
| 1431 | case 0x14: |
| 1432 | dev_priv->mem_freq = 1333; |
| 1433 | break; |
| 1434 | case 0x18: |
| 1435 | dev_priv->mem_freq = 1600; |
| 1436 | break; |
| 1437 | default: |
| 1438 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 1439 | ddrpll & 0xff); |
| 1440 | dev_priv->mem_freq = 0; |
| 1441 | break; |
| 1442 | } |
| 1443 | |
| 1444 | dev_priv->r_t = dev_priv->mem_freq; |
| 1445 | |
| 1446 | switch (csipll & 0x3ff) { |
| 1447 | case 0x00c: |
| 1448 | dev_priv->fsb_freq = 3200; |
| 1449 | break; |
| 1450 | case 0x00e: |
| 1451 | dev_priv->fsb_freq = 3733; |
| 1452 | break; |
| 1453 | case 0x010: |
| 1454 | dev_priv->fsb_freq = 4266; |
| 1455 | break; |
| 1456 | case 0x012: |
| 1457 | dev_priv->fsb_freq = 4800; |
| 1458 | break; |
| 1459 | case 0x014: |
| 1460 | dev_priv->fsb_freq = 5333; |
| 1461 | break; |
| 1462 | case 0x016: |
| 1463 | dev_priv->fsb_freq = 5866; |
| 1464 | break; |
| 1465 | case 0x018: |
| 1466 | dev_priv->fsb_freq = 6400; |
| 1467 | break; |
| 1468 | default: |
| 1469 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 1470 | csipll & 0x3ff); |
| 1471 | dev_priv->fsb_freq = 0; |
| 1472 | break; |
| 1473 | } |
| 1474 | |
| 1475 | if (dev_priv->fsb_freq == 3200) { |
| 1476 | dev_priv->c_m = 0; |
| 1477 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
| 1478 | dev_priv->c_m = 1; |
| 1479 | } else { |
| 1480 | dev_priv->c_m = 2; |
| 1481 | } |
| 1482 | } |
| 1483 | |
Chris Wilson | faa60c4 | 2010-11-23 13:50:14 +0000 | [diff] [blame] | 1484 | static const struct cparams { |
| 1485 | u16 i; |
| 1486 | u16 t; |
| 1487 | u16 m; |
| 1488 | u16 c; |
| 1489 | } cparams[] = { |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1490 | { 1, 1333, 301, 28664 }, |
| 1491 | { 1, 1066, 294, 24460 }, |
| 1492 | { 1, 800, 294, 25192 }, |
| 1493 | { 0, 1333, 276, 27605 }, |
| 1494 | { 0, 1066, 276, 27605 }, |
| 1495 | { 0, 800, 231, 23784 }, |
| 1496 | }; |
| 1497 | |
| 1498 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 1499 | { |
| 1500 | u64 total_count, diff, ret; |
| 1501 | u32 count1, count2, count3, m = 0, c = 0; |
| 1502 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 1503 | int i; |
| 1504 | |
| 1505 | diff1 = now - dev_priv->last_time1; |
| 1506 | |
Eugeni Dodonov | 4ed0b57 | 2011-11-10 13:55:15 -0200 | [diff] [blame] | 1507 | /* Prevent division-by-zero if we are asking too fast. |
| 1508 | * Also, we don't get interesting results if we are polling |
| 1509 | * faster than once in 10ms, so just return the saved value |
| 1510 | * in such cases. |
| 1511 | */ |
| 1512 | if (diff1 <= 10) |
| 1513 | return dev_priv->chipset_power; |
| 1514 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1515 | count1 = I915_READ(DMIEC); |
| 1516 | count2 = I915_READ(DDREC); |
| 1517 | count3 = I915_READ(CSIEC); |
| 1518 | |
| 1519 | total_count = count1 + count2 + count3; |
| 1520 | |
| 1521 | /* FIXME: handle per-counter overflow */ |
| 1522 | if (total_count < dev_priv->last_count1) { |
| 1523 | diff = ~0UL - dev_priv->last_count1; |
| 1524 | diff += total_count; |
| 1525 | } else { |
| 1526 | diff = total_count - dev_priv->last_count1; |
| 1527 | } |
| 1528 | |
| 1529 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
| 1530 | if (cparams[i].i == dev_priv->c_m && |
| 1531 | cparams[i].t == dev_priv->r_t) { |
| 1532 | m = cparams[i].m; |
| 1533 | c = cparams[i].c; |
| 1534 | break; |
| 1535 | } |
| 1536 | } |
| 1537 | |
Jesse Barnes | d270ae3 | 2010-09-27 10:35:44 -0700 | [diff] [blame] | 1538 | diff = div_u64(diff, diff1); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1539 | ret = ((m * diff) + c); |
Jesse Barnes | d270ae3 | 2010-09-27 10:35:44 -0700 | [diff] [blame] | 1540 | ret = div_u64(ret, 10); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1541 | |
| 1542 | dev_priv->last_count1 = total_count; |
| 1543 | dev_priv->last_time1 = now; |
| 1544 | |
Eugeni Dodonov | 4ed0b57 | 2011-11-10 13:55:15 -0200 | [diff] [blame] | 1545 | dev_priv->chipset_power = ret; |
| 1546 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1547 | return ret; |
| 1548 | } |
| 1549 | |
| 1550 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 1551 | { |
| 1552 | unsigned long m, x, b; |
| 1553 | u32 tsfs; |
| 1554 | |
| 1555 | tsfs = I915_READ(TSFS); |
| 1556 | |
| 1557 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 1558 | x = I915_READ8(TR1); |
| 1559 | |
| 1560 | b = tsfs & TSFS_INTR_MASK; |
| 1561 | |
| 1562 | return ((m * x) / 127) - b; |
| 1563 | } |
| 1564 | |
Chris Wilson | faa60c4 | 2010-11-23 13:50:14 +0000 | [diff] [blame] | 1565 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1566 | { |
Chris Wilson | faa60c4 | 2010-11-23 13:50:14 +0000 | [diff] [blame] | 1567 | static const struct v_table { |
| 1568 | u16 vd; /* in .1 mil */ |
| 1569 | u16 vm; /* in .1 mil */ |
| 1570 | } v_table[] = { |
| 1571 | { 0, 0, }, |
| 1572 | { 375, 0, }, |
| 1573 | { 500, 0, }, |
| 1574 | { 625, 0, }, |
| 1575 | { 750, 0, }, |
| 1576 | { 875, 0, }, |
| 1577 | { 1000, 0, }, |
| 1578 | { 1125, 0, }, |
| 1579 | { 4125, 3000, }, |
| 1580 | { 4125, 3000, }, |
| 1581 | { 4125, 3000, }, |
| 1582 | { 4125, 3000, }, |
| 1583 | { 4125, 3000, }, |
| 1584 | { 4125, 3000, }, |
| 1585 | { 4125, 3000, }, |
| 1586 | { 4125, 3000, }, |
| 1587 | { 4125, 3000, }, |
| 1588 | { 4125, 3000, }, |
| 1589 | { 4125, 3000, }, |
| 1590 | { 4125, 3000, }, |
| 1591 | { 4125, 3000, }, |
| 1592 | { 4125, 3000, }, |
| 1593 | { 4125, 3000, }, |
| 1594 | { 4125, 3000, }, |
| 1595 | { 4125, 3000, }, |
| 1596 | { 4125, 3000, }, |
| 1597 | { 4125, 3000, }, |
| 1598 | { 4125, 3000, }, |
| 1599 | { 4125, 3000, }, |
| 1600 | { 4125, 3000, }, |
| 1601 | { 4125, 3000, }, |
| 1602 | { 4125, 3000, }, |
| 1603 | { 4250, 3125, }, |
| 1604 | { 4375, 3250, }, |
| 1605 | { 4500, 3375, }, |
| 1606 | { 4625, 3500, }, |
| 1607 | { 4750, 3625, }, |
| 1608 | { 4875, 3750, }, |
| 1609 | { 5000, 3875, }, |
| 1610 | { 5125, 4000, }, |
| 1611 | { 5250, 4125, }, |
| 1612 | { 5375, 4250, }, |
| 1613 | { 5500, 4375, }, |
| 1614 | { 5625, 4500, }, |
| 1615 | { 5750, 4625, }, |
| 1616 | { 5875, 4750, }, |
| 1617 | { 6000, 4875, }, |
| 1618 | { 6125, 5000, }, |
| 1619 | { 6250, 5125, }, |
| 1620 | { 6375, 5250, }, |
| 1621 | { 6500, 5375, }, |
| 1622 | { 6625, 5500, }, |
| 1623 | { 6750, 5625, }, |
| 1624 | { 6875, 5750, }, |
| 1625 | { 7000, 5875, }, |
| 1626 | { 7125, 6000, }, |
| 1627 | { 7250, 6125, }, |
| 1628 | { 7375, 6250, }, |
| 1629 | { 7500, 6375, }, |
| 1630 | { 7625, 6500, }, |
| 1631 | { 7750, 6625, }, |
| 1632 | { 7875, 6750, }, |
| 1633 | { 8000, 6875, }, |
| 1634 | { 8125, 7000, }, |
| 1635 | { 8250, 7125, }, |
| 1636 | { 8375, 7250, }, |
| 1637 | { 8500, 7375, }, |
| 1638 | { 8625, 7500, }, |
| 1639 | { 8750, 7625, }, |
| 1640 | { 8875, 7750, }, |
| 1641 | { 9000, 7875, }, |
| 1642 | { 9125, 8000, }, |
| 1643 | { 9250, 8125, }, |
| 1644 | { 9375, 8250, }, |
| 1645 | { 9500, 8375, }, |
| 1646 | { 9625, 8500, }, |
| 1647 | { 9750, 8625, }, |
| 1648 | { 9875, 8750, }, |
| 1649 | { 10000, 8875, }, |
| 1650 | { 10125, 9000, }, |
| 1651 | { 10250, 9125, }, |
| 1652 | { 10375, 9250, }, |
| 1653 | { 10500, 9375, }, |
| 1654 | { 10625, 9500, }, |
| 1655 | { 10750, 9625, }, |
| 1656 | { 10875, 9750, }, |
| 1657 | { 11000, 9875, }, |
| 1658 | { 11125, 10000, }, |
| 1659 | { 11250, 10125, }, |
| 1660 | { 11375, 10250, }, |
| 1661 | { 11500, 10375, }, |
| 1662 | { 11625, 10500, }, |
| 1663 | { 11750, 10625, }, |
| 1664 | { 11875, 10750, }, |
| 1665 | { 12000, 10875, }, |
| 1666 | { 12125, 11000, }, |
| 1667 | { 12250, 11125, }, |
| 1668 | { 12375, 11250, }, |
| 1669 | { 12500, 11375, }, |
| 1670 | { 12625, 11500, }, |
| 1671 | { 12750, 11625, }, |
| 1672 | { 12875, 11750, }, |
| 1673 | { 13000, 11875, }, |
| 1674 | { 13125, 12000, }, |
| 1675 | { 13250, 12125, }, |
| 1676 | { 13375, 12250, }, |
| 1677 | { 13500, 12375, }, |
| 1678 | { 13625, 12500, }, |
| 1679 | { 13750, 12625, }, |
| 1680 | { 13875, 12750, }, |
| 1681 | { 14000, 12875, }, |
| 1682 | { 14125, 13000, }, |
| 1683 | { 14250, 13125, }, |
| 1684 | { 14375, 13250, }, |
| 1685 | { 14500, 13375, }, |
| 1686 | { 14625, 13500, }, |
| 1687 | { 14750, 13625, }, |
| 1688 | { 14875, 13750, }, |
| 1689 | { 15000, 13875, }, |
| 1690 | { 15125, 14000, }, |
| 1691 | { 15250, 14125, }, |
| 1692 | { 15375, 14250, }, |
| 1693 | { 15500, 14375, }, |
| 1694 | { 15625, 14500, }, |
| 1695 | { 15750, 14625, }, |
| 1696 | { 15875, 14750, }, |
| 1697 | { 16000, 14875, }, |
| 1698 | { 16125, 15000, }, |
| 1699 | }; |
| 1700 | if (dev_priv->info->is_mobile) |
| 1701 | return v_table[pxvid].vm; |
| 1702 | else |
| 1703 | return v_table[pxvid].vd; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 1707 | { |
| 1708 | struct timespec now, diff1; |
| 1709 | u64 diff; |
| 1710 | unsigned long diffms; |
| 1711 | u32 count; |
| 1712 | |
Chris Wilson | 582be6b | 2012-04-30 19:35:02 +0100 | [diff] [blame] | 1713 | if (dev_priv->info->gen != 5) |
| 1714 | return; |
| 1715 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1716 | getrawmonotonic(&now); |
| 1717 | diff1 = timespec_sub(now, dev_priv->last_time2); |
| 1718 | |
| 1719 | /* Don't divide by 0 */ |
| 1720 | diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000; |
| 1721 | if (!diffms) |
| 1722 | return; |
| 1723 | |
| 1724 | count = I915_READ(GFXEC); |
| 1725 | |
| 1726 | if (count < dev_priv->last_count2) { |
| 1727 | diff = ~0UL - dev_priv->last_count2; |
| 1728 | diff += count; |
| 1729 | } else { |
| 1730 | diff = count - dev_priv->last_count2; |
| 1731 | } |
| 1732 | |
| 1733 | dev_priv->last_count2 = count; |
| 1734 | dev_priv->last_time2 = now; |
| 1735 | |
| 1736 | /* More magic constants... */ |
| 1737 | diff = diff * 1181; |
Jesse Barnes | d270ae3 | 2010-09-27 10:35:44 -0700 | [diff] [blame] | 1738 | diff = div_u64(diff, diffms * 10); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1739 | dev_priv->gfx_power = diff; |
| 1740 | } |
| 1741 | |
| 1742 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 1743 | { |
| 1744 | unsigned long t, corr, state1, corr2, state2; |
| 1745 | u32 pxvid, ext_v; |
| 1746 | |
| 1747 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->cur_delay * 4)); |
| 1748 | pxvid = (pxvid >> 24) & 0x7f; |
| 1749 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 1750 | |
| 1751 | state1 = ext_v; |
| 1752 | |
| 1753 | t = i915_mch_val(dev_priv); |
| 1754 | |
| 1755 | /* Revel in the empirically derived constants */ |
| 1756 | |
| 1757 | /* Correction factor in 1/100000 units */ |
| 1758 | if (t > 80) |
| 1759 | corr = ((t * 2349) + 135940); |
| 1760 | else if (t >= 50) |
| 1761 | corr = ((t * 964) + 29317); |
| 1762 | else /* < 50 */ |
| 1763 | corr = ((t * 301) + 1004); |
| 1764 | |
| 1765 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 1766 | corr /= 100000; |
| 1767 | corr2 = (corr * dev_priv->corr); |
| 1768 | |
| 1769 | state2 = (corr2 * state1) / 10000; |
| 1770 | state2 /= 100; /* convert to mW */ |
| 1771 | |
| 1772 | i915_update_gfx_val(dev_priv); |
| 1773 | |
| 1774 | return dev_priv->gfx_power + state2; |
| 1775 | } |
| 1776 | |
| 1777 | /* Global for IPS driver to get at the current i915 device */ |
| 1778 | static struct drm_i915_private *i915_mch_dev; |
| 1779 | /* |
| 1780 | * Lock protecting IPS related data structures |
| 1781 | * - i915_mch_dev |
| 1782 | * - dev_priv->max_delay |
| 1783 | * - dev_priv->min_delay |
| 1784 | * - dev_priv->fmax |
| 1785 | * - dev_priv->gpu_busy |
| 1786 | */ |
Chris Wilson | 995b676 | 2010-08-20 13:23:26 +0100 | [diff] [blame] | 1787 | static DEFINE_SPINLOCK(mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1788 | |
| 1789 | /** |
| 1790 | * i915_read_mch_val - return value for IPS use |
| 1791 | * |
| 1792 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 1793 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 1794 | */ |
| 1795 | unsigned long i915_read_mch_val(void) |
| 1796 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1797 | struct drm_i915_private *dev_priv; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1798 | unsigned long chipset_val, graphics_val, ret = 0; |
| 1799 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1800 | spin_lock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1801 | if (!i915_mch_dev) |
| 1802 | goto out_unlock; |
| 1803 | dev_priv = i915_mch_dev; |
| 1804 | |
| 1805 | chipset_val = i915_chipset_val(dev_priv); |
| 1806 | graphics_val = i915_gfx_val(dev_priv); |
| 1807 | |
| 1808 | ret = chipset_val + graphics_val; |
| 1809 | |
| 1810 | out_unlock: |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1811 | spin_unlock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1812 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1813 | return ret; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1814 | } |
| 1815 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 1816 | |
| 1817 | /** |
| 1818 | * i915_gpu_raise - raise GPU frequency limit |
| 1819 | * |
| 1820 | * Raise the limit; IPS indicates we have thermal headroom. |
| 1821 | */ |
| 1822 | bool i915_gpu_raise(void) |
| 1823 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1824 | struct drm_i915_private *dev_priv; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1825 | bool ret = true; |
| 1826 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1827 | spin_lock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1828 | if (!i915_mch_dev) { |
| 1829 | ret = false; |
| 1830 | goto out_unlock; |
| 1831 | } |
| 1832 | dev_priv = i915_mch_dev; |
| 1833 | |
| 1834 | if (dev_priv->max_delay > dev_priv->fmax) |
| 1835 | dev_priv->max_delay--; |
| 1836 | |
| 1837 | out_unlock: |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1838 | spin_unlock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1839 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1840 | return ret; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1841 | } |
| 1842 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 1843 | |
| 1844 | /** |
| 1845 | * i915_gpu_lower - lower GPU frequency limit |
| 1846 | * |
| 1847 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 1848 | * frequency maximum. |
| 1849 | */ |
| 1850 | bool i915_gpu_lower(void) |
| 1851 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1852 | struct drm_i915_private *dev_priv; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1853 | bool ret = true; |
| 1854 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1855 | spin_lock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1856 | if (!i915_mch_dev) { |
| 1857 | ret = false; |
| 1858 | goto out_unlock; |
| 1859 | } |
| 1860 | dev_priv = i915_mch_dev; |
| 1861 | |
| 1862 | if (dev_priv->max_delay < dev_priv->min_delay) |
| 1863 | dev_priv->max_delay++; |
| 1864 | |
| 1865 | out_unlock: |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1866 | spin_unlock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1867 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1868 | return ret; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1869 | } |
| 1870 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 1871 | |
| 1872 | /** |
| 1873 | * i915_gpu_busy - indicate GPU business to IPS |
| 1874 | * |
| 1875 | * Tell the IPS driver whether or not the GPU is busy. |
| 1876 | */ |
| 1877 | bool i915_gpu_busy(void) |
| 1878 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1879 | struct drm_i915_private *dev_priv; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1880 | bool ret = false; |
| 1881 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1882 | spin_lock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1883 | if (!i915_mch_dev) |
| 1884 | goto out_unlock; |
| 1885 | dev_priv = i915_mch_dev; |
| 1886 | |
| 1887 | ret = dev_priv->busy; |
| 1888 | |
| 1889 | out_unlock: |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1890 | spin_unlock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1891 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1892 | return ret; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1893 | } |
| 1894 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 1895 | |
| 1896 | /** |
| 1897 | * i915_gpu_turbo_disable - disable graphics turbo |
| 1898 | * |
| 1899 | * Disable graphics turbo by resetting the max frequency and setting the |
| 1900 | * current frequency to the default. |
| 1901 | */ |
| 1902 | bool i915_gpu_turbo_disable(void) |
| 1903 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1904 | struct drm_i915_private *dev_priv; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1905 | bool ret = true; |
| 1906 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1907 | spin_lock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1908 | if (!i915_mch_dev) { |
| 1909 | ret = false; |
| 1910 | goto out_unlock; |
| 1911 | } |
| 1912 | dev_priv = i915_mch_dev; |
| 1913 | |
| 1914 | dev_priv->max_delay = dev_priv->fstart; |
| 1915 | |
| 1916 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->fstart)) |
| 1917 | ret = false; |
| 1918 | |
| 1919 | out_unlock: |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1920 | spin_unlock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1921 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1922 | return ret; |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 1923 | } |
| 1924 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 1925 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1926 | /** |
Eric Anholt | 63ee41d | 2010-12-20 18:40:06 -0800 | [diff] [blame] | 1927 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 1928 | * IPS got loaded first. |
| 1929 | * |
| 1930 | * This awkward dance is so that neither module has to depend on the |
| 1931 | * other in order for IPS to do the appropriate communication of |
| 1932 | * GPU turbo limits to i915. |
| 1933 | */ |
| 1934 | static void |
| 1935 | ips_ping_for_i915_load(void) |
| 1936 | { |
| 1937 | void (*link)(void); |
| 1938 | |
| 1939 | link = symbol_get(ips_link_to_i915_driver); |
| 1940 | if (link) { |
| 1941 | link(); |
| 1942 | symbol_put(ips_link_to_i915_driver); |
| 1943 | } |
| 1944 | } |
| 1945 | |
Adam Jackson | e2b665c | 2012-03-14 11:22:10 -0400 | [diff] [blame] | 1946 | static void |
| 1947 | i915_mtrr_setup(struct drm_i915_private *dev_priv, unsigned long base, |
| 1948 | unsigned long size) |
| 1949 | { |
Chris Wilson | 23f54be | 2012-03-23 17:38:49 +0000 | [diff] [blame] | 1950 | dev_priv->mm.gtt_mtrr = -1; |
| 1951 | |
Adam Jackson | 9e984bc1 | 2012-03-14 11:22:11 -0400 | [diff] [blame] | 1952 | #if defined(CONFIG_X86_PAT) |
| 1953 | if (cpu_has_pat) |
| 1954 | return; |
| 1955 | #endif |
| 1956 | |
Adam Jackson | e2b665c | 2012-03-14 11:22:10 -0400 | [diff] [blame] | 1957 | /* Set up a WC MTRR for non-PAT systems. This is more common than |
| 1958 | * one would think, because the kernel disables PAT on first |
| 1959 | * generation Core chips because WC PAT gets overridden by a UC |
| 1960 | * MTRR if present. Even if a UC MTRR isn't present. |
| 1961 | */ |
| 1962 | dev_priv->mm.gtt_mtrr = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1); |
| 1963 | if (dev_priv->mm.gtt_mtrr < 0) { |
| 1964 | DRM_INFO("MTRR allocation failed. Graphics " |
| 1965 | "performance may suffer.\n"); |
| 1966 | } |
| 1967 | } |
| 1968 | |
Eric Anholt | 63ee41d | 2010-12-20 18:40:06 -0800 | [diff] [blame] | 1969 | /** |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1970 | * i915_driver_load - setup chip and create an initial config |
| 1971 | * @dev: DRM device |
| 1972 | * @flags: startup flags |
| 1973 | * |
| 1974 | * The driver load routine has to do several things: |
| 1975 | * - drive output discovery via intel_modeset_init() |
| 1976 | * - initialize the memory manager |
| 1977 | * - allocate initial config memory |
| 1978 | * - setup the DRM framebuffer with the allocated memory |
| 1979 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1980 | int i915_driver_load(struct drm_device *dev, unsigned long flags) |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1981 | { |
Luca Tettamanti | ea059a1 | 2010-04-08 21:41:59 +0200 | [diff] [blame] | 1982 | struct drm_i915_private *dev_priv; |
Daniel Vetter | 26394d9 | 2012-03-26 21:33:18 +0200 | [diff] [blame] | 1983 | struct intel_device_info *info; |
Kristian Høgsberg | cfdf1fa | 2009-12-16 15:16:16 -0500 | [diff] [blame] | 1984 | int ret = 0, mmio_bar; |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 1985 | uint32_t aperture_size; |
Chris Wilson | fe669bf | 2010-11-23 12:09:30 +0000 | [diff] [blame] | 1986 | |
Daniel Vetter | 26394d9 | 2012-03-26 21:33:18 +0200 | [diff] [blame] | 1987 | info = (struct intel_device_info *) flags; |
| 1988 | |
| 1989 | /* Refuse to load on gen6+ without kms enabled. */ |
| 1990 | if (info->gen >= 6 && !drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1991 | return -ENODEV; |
| 1992 | |
Daniel Vetter | ac622a9 | 2010-09-08 21:26:07 +0200 | [diff] [blame] | 1993 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1994 | /* i915 has 4 more counters */ |
| 1995 | dev->counters += 4; |
| 1996 | dev->types[6] = _DRM_STAT_IRQ; |
| 1997 | dev->types[7] = _DRM_STAT_PRIMARY; |
| 1998 | dev->types[8] = _DRM_STAT_SECONDARY; |
| 1999 | dev->types[9] = _DRM_STAT_DMA; |
| 2000 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 2001 | dev_priv = kzalloc(sizeof(drm_i915_private_t), GFP_KERNEL); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 2002 | if (dev_priv == NULL) |
| 2003 | return -ENOMEM; |
| 2004 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 2005 | dev->dev_private = (void *)dev_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2006 | dev_priv->dev = dev; |
Daniel Vetter | 26394d9 | 2012-03-26 21:33:18 +0200 | [diff] [blame] | 2007 | dev_priv->info = info; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 2008 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 2009 | if (i915_get_bridge_dev(dev)) { |
| 2010 | ret = -EIO; |
| 2011 | goto free_priv; |
| 2012 | } |
| 2013 | |
Dave Airlie | 466e69b | 2011-12-19 11:15:29 +0000 | [diff] [blame] | 2014 | pci_set_master(dev->pdev); |
| 2015 | |
Daniel Vetter | 9f82d23 | 2010-08-30 21:25:23 +0200 | [diff] [blame] | 2016 | /* overlay on gen2 is broken and can't address above 1G */ |
| 2017 | if (IS_GEN2(dev)) |
| 2018 | dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(30)); |
| 2019 | |
Jan Niehusmann | 6927faf | 2011-03-01 23:24:16 +0100 | [diff] [blame] | 2020 | /* 965GM sometimes incorrectly writes to hardware status page (HWS) |
| 2021 | * using 32bit addressing, overwriting memory if HWS is located |
| 2022 | * above 4GB. |
| 2023 | * |
| 2024 | * The documentation also mentions an issue with undefined |
| 2025 | * behaviour if any general state is accessed within a page above 4GB, |
| 2026 | * which also needs to be handled carefully. |
| 2027 | */ |
| 2028 | if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
| 2029 | dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(32)); |
| 2030 | |
Chris Wilson | b4ce0f8 | 2010-10-28 11:26:06 +0100 | [diff] [blame] | 2031 | mmio_bar = IS_GEN2(dev) ? 1 : 0; |
| 2032 | dev_priv->regs = pci_iomap(dev->pdev, mmio_bar, 0); |
| 2033 | if (!dev_priv->regs) { |
| 2034 | DRM_ERROR("failed to map registers\n"); |
| 2035 | ret = -EIO; |
| 2036 | goto put_bridge; |
| 2037 | } |
| 2038 | |
Chris Wilson | 71e9339 | 2010-10-27 18:46:52 +0100 | [diff] [blame] | 2039 | dev_priv->mm.gtt = intel_gtt_get(); |
| 2040 | if (!dev_priv->mm.gtt) { |
| 2041 | DRM_ERROR("Failed to initialize GTT\n"); |
| 2042 | ret = -ENODEV; |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 2043 | goto out_rmmap; |
Chris Wilson | 71e9339 | 2010-10-27 18:46:52 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 2046 | aperture_size = dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT; |
Chris Wilson | 71e9339 | 2010-10-27 18:46:52 +0100 | [diff] [blame] | 2047 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2048 | dev_priv->mm.gtt_mapping = |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 2049 | io_mapping_create_wc(dev->agp->base, aperture_size); |
Venkatesh Pallipadi | 6644107 | 2009-02-24 17:35:11 -0800 | [diff] [blame] | 2050 | if (dev_priv->mm.gtt_mapping == NULL) { |
| 2051 | ret = -EIO; |
| 2052 | goto out_rmmap; |
| 2053 | } |
| 2054 | |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 2055 | i915_mtrr_setup(dev_priv, dev->agp->base, aperture_size); |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 2056 | |
Chris Wilson | e642abb | 2010-09-09 12:46:34 +0100 | [diff] [blame] | 2057 | /* The i915 workqueue is primarily used for batched retirement of |
| 2058 | * requests (and thus managing bo) once the task has been completed |
| 2059 | * by the GPU. i915_gem_retire_requests() is called directly when we |
| 2060 | * need high-priority retirement, such as waiting for an explicit |
| 2061 | * bo. |
| 2062 | * |
| 2063 | * It is also used for periodic low-priority events, such as |
Eric Anholt | df9c204 | 2010-11-18 09:31:12 +0800 | [diff] [blame] | 2064 | * idle-timers and recording error state. |
Chris Wilson | e642abb | 2010-09-09 12:46:34 +0100 | [diff] [blame] | 2065 | * |
| 2066 | * All tasks on the workqueue are expected to acquire the dev mutex |
| 2067 | * so there is no point in running more than one instance of the |
| 2068 | * workqueue at any time: max_active = 1 and NON_REENTRANT. |
| 2069 | */ |
| 2070 | dev_priv->wq = alloc_workqueue("i915", |
| 2071 | WQ_UNBOUND | WQ_NON_REENTRANT, |
| 2072 | 1); |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 2073 | if (dev_priv->wq == NULL) { |
| 2074 | DRM_ERROR("Failed to create our workqueue.\n"); |
| 2075 | ret = -ENOMEM; |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 2076 | goto out_mtrrfree; |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Jesse Barnes | f71d4af | 2011-06-28 13:00:41 -0700 | [diff] [blame] | 2079 | intel_irq_init(dev); |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 2080 | |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 2081 | /* Try to make sure MCHBAR is enabled before poking at it */ |
| 2082 | intel_setup_mchbar(dev); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 2083 | intel_setup_gmbus(dev); |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 2084 | intel_opregion_setup(dev); |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 2085 | |
Bryan Freed | 6d139a8 | 2010-10-14 09:14:51 +0100 | [diff] [blame] | 2086 | /* Make sure the bios did its job and set up vital registers */ |
| 2087 | intel_setup_bios(dev); |
| 2088 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2089 | i915_gem_load(dev); |
| 2090 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 2091 | /* Init HWS */ |
| 2092 | if (!I915_NEED_GFX_HWS(dev)) { |
| 2093 | ret = i915_init_phys_hws(dev); |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 2094 | if (ret) |
| 2095 | goto out_gem_unload; |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 2096 | } |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2097 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 2098 | if (IS_PINEVIEW(dev)) |
| 2099 | i915_pineview_get_mem_freq(dev); |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 2100 | else if (IS_GEN5(dev)) |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 2101 | i915_ironlake_get_mem_freq(dev); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 2102 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2103 | /* On the 945G/GM, the chipset reports the MSI capability on the |
| 2104 | * integrated graphics even though the support isn't actually there |
| 2105 | * according to the published specs. It doesn't appear to function |
| 2106 | * correctly in testing on 945G. |
| 2107 | * This may be a side effect of MSI having been made available for PEG |
| 2108 | * and the registers being closely associated. |
Keith Packard | d1ed629 | 2008-10-17 00:44:42 -0700 | [diff] [blame] | 2109 | * |
| 2110 | * According to chipset errata, on the 965GM, MSI interrupts may |
Keith Packard | b60678a | 2008-12-08 11:12:28 -0800 | [diff] [blame] | 2111 | * be lost or delayed, but we use them anyways to avoid |
| 2112 | * stuck interrupts on some machines. |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2113 | */ |
Keith Packard | b60678a | 2008-12-08 11:12:28 -0800 | [diff] [blame] | 2114 | if (!IS_I945G(dev) && !IS_I945GM(dev)) |
Eric Anholt | d3e74d0 | 2008-11-03 14:46:17 -0800 | [diff] [blame] | 2115 | pci_enable_msi(dev->pdev); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2116 | |
Daniel Vetter | 9f1f46a | 2011-12-14 13:57:03 +0100 | [diff] [blame] | 2117 | spin_lock_init(&dev_priv->gt_lock); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 2118 | spin_lock_init(&dev_priv->irq_lock); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 2119 | spin_lock_init(&dev_priv->error_lock); |
Ben Widawsky | 4912d04 | 2011-04-25 11:25:20 -0700 | [diff] [blame] | 2120 | spin_lock_init(&dev_priv->rps_lock); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2121 | |
Eugeni Dodonov | c51ed78 | 2012-04-13 17:08:45 -0300 | [diff] [blame] | 2122 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
Jesse Barnes | 27f8227 | 2011-09-02 12:54:37 -0700 | [diff] [blame] | 2123 | dev_priv->num_pipe = 3; |
| 2124 | else if (IS_MOBILE(dev) || !IS_GEN2(dev)) |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 2125 | dev_priv->num_pipe = 2; |
| 2126 | else |
| 2127 | dev_priv->num_pipe = 1; |
| 2128 | |
| 2129 | ret = drm_vblank_init(dev, dev_priv->num_pipe); |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 2130 | if (ret) |
| 2131 | goto out_gem_unload; |
Keith Packard | 5244021 | 2008-11-18 09:30:25 -0800 | [diff] [blame] | 2132 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 2133 | /* Start out suspended */ |
| 2134 | dev_priv->mm.suspended = 1; |
| 2135 | |
Zhenyu Wang | 3bad078 | 2010-04-07 16:15:53 +0800 | [diff] [blame] | 2136 | intel_detect_pch(dev); |
| 2137 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2138 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Daniel Vetter | 5398463 | 2010-09-22 23:44:24 +0200 | [diff] [blame] | 2139 | ret = i915_load_modeset_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2140 | if (ret < 0) { |
| 2141 | DRM_ERROR("failed to init modeset\n"); |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 2142 | goto out_gem_unload; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2143 | } |
| 2144 | } |
| 2145 | |
Ben Widawsky | 0136db58 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 2146 | i915_setup_sysfs(dev); |
| 2147 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2148 | /* Must be done after probing outputs */ |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 2149 | intel_opregion_init(dev); |
| 2150 | acpi_video_register(); |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2151 | |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 2152 | setup_timer(&dev_priv->hangcheck_timer, i915_hangcheck_elapsed, |
| 2153 | (unsigned long) dev); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 2154 | |
Chris Wilson | 582be6b | 2012-04-30 19:35:02 +0100 | [diff] [blame] | 2155 | if (IS_GEN5(dev)) { |
| 2156 | spin_lock(&mchdev_lock); |
| 2157 | i915_mch_dev = dev_priv; |
| 2158 | dev_priv->mchdev_lock = &mchdev_lock; |
| 2159 | spin_unlock(&mchdev_lock); |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 2160 | |
Chris Wilson | 582be6b | 2012-04-30 19:35:02 +0100 | [diff] [blame] | 2161 | ips_ping_for_i915_load(); |
| 2162 | } |
Eric Anholt | 63ee41d | 2010-12-20 18:40:06 -0800 | [diff] [blame] | 2163 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2164 | return 0; |
| 2165 | |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 2166 | out_gem_unload: |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 2167 | if (dev_priv->mm.inactive_shrinker.shrink) |
| 2168 | unregister_shrinker(&dev_priv->mm.inactive_shrinker); |
| 2169 | |
Chris Wilson | 56e2ea3 | 2010-11-08 17:10:29 +0000 | [diff] [blame] | 2170 | if (dev->pdev->msi_enabled) |
| 2171 | pci_disable_msi(dev->pdev); |
| 2172 | |
| 2173 | intel_teardown_gmbus(dev); |
| 2174 | intel_teardown_mchbar(dev); |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 2175 | destroy_workqueue(dev_priv->wq); |
Keith Packard | a7b85d2 | 2011-07-10 13:12:17 -0700 | [diff] [blame] | 2176 | out_mtrrfree: |
| 2177 | if (dev_priv->mm.gtt_mtrr >= 0) { |
| 2178 | mtrr_del(dev_priv->mm.gtt_mtrr, dev->agp->base, |
| 2179 | dev->agp->agp_info.aper_size * 1024 * 1024); |
| 2180 | dev_priv->mm.gtt_mtrr = -1; |
| 2181 | } |
Venkatesh Pallipadi | 6644107 | 2009-02-24 17:35:11 -0800 | [diff] [blame] | 2182 | io_mapping_free(dev_priv->mm.gtt_mapping); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2183 | out_rmmap: |
Chris Wilson | 6dda569 | 2010-10-29 21:02:18 +0100 | [diff] [blame] | 2184 | pci_iounmap(dev->pdev, dev_priv->regs); |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 2185 | put_bridge: |
| 2186 | pci_dev_put(dev_priv->bridge_dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2187 | free_priv: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 2188 | kfree(dev_priv); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 2189 | return ret; |
| 2190 | } |
| 2191 | |
| 2192 | int i915_driver_unload(struct drm_device *dev) |
| 2193 | { |
| 2194 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 2195 | int ret; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 2196 | |
Jesse Barnes | 7648fa9 | 2010-05-20 14:28:11 -0700 | [diff] [blame] | 2197 | spin_lock(&mchdev_lock); |
| 2198 | i915_mch_dev = NULL; |
| 2199 | spin_unlock(&mchdev_lock); |
| 2200 | |
Ben Widawsky | 0136db58 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 2201 | i915_teardown_sysfs(dev); |
| 2202 | |
Chris Wilson | 17250b7 | 2010-10-28 12:51:39 +0100 | [diff] [blame] | 2203 | if (dev_priv->mm.inactive_shrinker.shrink) |
| 2204 | unregister_shrinker(&dev_priv->mm.inactive_shrinker); |
| 2205 | |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 2206 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | b2da9fe | 2012-04-26 16:02:58 -0700 | [diff] [blame] | 2207 | ret = i915_gpu_idle(dev); |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 2208 | if (ret) |
| 2209 | DRM_ERROR("failed to idle hardware: %d\n", ret); |
Ben Widawsky | b2da9fe | 2012-04-26 16:02:58 -0700 | [diff] [blame] | 2210 | i915_gem_retire_requests(dev); |
Daniel Vetter | c911fc1 | 2010-08-20 21:23:20 +0200 | [diff] [blame] | 2211 | mutex_unlock(&dev->struct_mutex); |
| 2212 | |
Daniel Vetter | 75ef9da | 2010-08-21 00:25:16 +0200 | [diff] [blame] | 2213 | /* Cancel the retire work handler, which should be idle now. */ |
| 2214 | cancel_delayed_work_sync(&dev_priv->mm.retire_work); |
| 2215 | |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 2216 | io_mapping_free(dev_priv->mm.gtt_mapping); |
| 2217 | if (dev_priv->mm.gtt_mtrr >= 0) { |
| 2218 | mtrr_del(dev_priv->mm.gtt_mtrr, dev->agp->base, |
| 2219 | dev->agp->agp_info.aper_size * 1024 * 1024); |
| 2220 | dev_priv->mm.gtt_mtrr = -1; |
| 2221 | } |
| 2222 | |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 2223 | acpi_video_unregister(); |
| 2224 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2225 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Chris Wilson | 7b4f399 | 2010-10-04 15:33:04 +0100 | [diff] [blame] | 2226 | intel_fbdev_fini(dev); |
Jesse Barnes | 3d8620c | 2010-03-26 11:07:21 -0700 | [diff] [blame] | 2227 | intel_modeset_cleanup(dev); |
| 2228 | |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 2229 | /* |
| 2230 | * free the memory space allocated for the child device |
| 2231 | * config parsed from VBT |
| 2232 | */ |
| 2233 | if (dev_priv->child_dev && dev_priv->child_dev_num) { |
| 2234 | kfree(dev_priv->child_dev); |
| 2235 | dev_priv->child_dev = NULL; |
| 2236 | dev_priv->child_dev_num = 0; |
| 2237 | } |
Daniel Vetter | 6c0d9350 | 2010-08-20 18:26:46 +0200 | [diff] [blame] | 2238 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 2239 | vga_switcheroo_unregister_client(dev->pdev); |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 2240 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2241 | } |
| 2242 | |
Daniel Vetter | a8b4899 | 2010-08-20 21:25:11 +0200 | [diff] [blame] | 2243 | /* Free error state after interrupts are fully disabled. */ |
Daniel Vetter | bc0c7f1 | 2010-08-20 18:18:48 +0200 | [diff] [blame] | 2244 | del_timer_sync(&dev_priv->hangcheck_timer); |
| 2245 | cancel_work_sync(&dev_priv->error_work); |
Daniel Vetter | a8b4899 | 2010-08-20 21:25:11 +0200 | [diff] [blame] | 2246 | i915_destroy_error_state(dev); |
Daniel Vetter | bc0c7f1 | 2010-08-20 18:18:48 +0200 | [diff] [blame] | 2247 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 2248 | if (dev->pdev->msi_enabled) |
| 2249 | pci_disable_msi(dev->pdev); |
| 2250 | |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 2251 | intel_opregion_fini(dev); |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 2252 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2253 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 2254 | /* Flush any outstanding unpin_work. */ |
| 2255 | flush_workqueue(dev_priv->wq); |
| 2256 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2257 | mutex_lock(&dev->struct_mutex); |
Hugh Dickins | ecbec53 | 2011-06-27 16:18:20 -0700 | [diff] [blame] | 2258 | i915_gem_free_all_phys_object(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2259 | i915_gem_cleanup_ringbuffer(dev); |
| 2260 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2261 | i915_gem_cleanup_aliasing_ppgtt(dev); |
Chris Wilson | 9797fbf | 2012-04-24 15:47:39 +0100 | [diff] [blame] | 2262 | i915_gem_cleanup_stolen(dev); |
Chris Wilson | fe669bf | 2010-11-23 12:09:30 +0000 | [diff] [blame] | 2263 | drm_mm_takedown(&dev_priv->mm.stolen); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 2264 | |
| 2265 | intel_cleanup_overlay(dev); |
Keith Packard | c2873e9 | 2010-10-07 09:20:12 +0100 | [diff] [blame] | 2266 | |
| 2267 | if (!I915_NEED_GFX_HWS(dev)) |
| 2268 | i915_free_hws(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2269 | } |
| 2270 | |
Daniel Vetter | 701394c | 2010-10-10 18:54:08 +0100 | [diff] [blame] | 2271 | if (dev_priv->regs != NULL) |
Chris Wilson | 6dda569 | 2010-10-29 21:02:18 +0100 | [diff] [blame] | 2272 | pci_iounmap(dev->pdev, dev_priv->regs); |
Daniel Vetter | 701394c | 2010-10-10 18:54:08 +0100 | [diff] [blame] | 2273 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 2274 | intel_teardown_gmbus(dev); |
Zhenyu Wang | c4804411 | 2009-12-17 14:48:43 +0800 | [diff] [blame] | 2275 | intel_teardown_mchbar(dev); |
| 2276 | |
Daniel Vetter | bc0c7f1 | 2010-08-20 18:18:48 +0200 | [diff] [blame] | 2277 | destroy_workqueue(dev_priv->wq); |
| 2278 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 2279 | pci_dev_put(dev_priv->bridge_dev); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 2280 | kfree(dev->dev_private); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 2281 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 2282 | return 0; |
| 2283 | } |
| 2284 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2285 | int i915_driver_open(struct drm_device *dev, struct drm_file *file) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2286 | { |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2287 | struct drm_i915_file_private *file_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2288 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 2289 | DRM_DEBUG_DRIVER("\n"); |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2290 | file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL); |
| 2291 | if (!file_priv) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2292 | return -ENOMEM; |
| 2293 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2294 | file->driver_priv = file_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2295 | |
Chris Wilson | 1c25595 | 2010-09-26 11:03:27 +0100 | [diff] [blame] | 2296 | spin_lock_init(&file_priv->mm.lock); |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2297 | INIT_LIST_HEAD(&file_priv->mm.request_list); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2298 | |
| 2299 | return 0; |
| 2300 | } |
| 2301 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2302 | /** |
| 2303 | * i915_driver_lastclose - clean up after all DRM clients have exited |
| 2304 | * @dev: DRM device |
| 2305 | * |
| 2306 | * Take care of cleaning up after all DRM clients have exited. In the |
| 2307 | * mode setting case, we want to restore the kernel's initial mode (just |
| 2308 | * in case the last client left us in a bad state). |
| 2309 | * |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 2310 | * 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] | 2311 | * and DMA structures, since the kernel won't be using them, and clea |
| 2312 | * up any GEM state. |
| 2313 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 2314 | void i915_driver_lastclose(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 2316 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 2317 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2318 | if (!dev_priv || drm_core_check_feature(dev, DRIVER_MODESET)) { |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 2319 | intel_fb_restore_mode(dev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 2320 | vga_switcheroo_process_delayed_switch(); |
Dave Airlie | 144a75f | 2008-03-30 07:53:58 +1000 | [diff] [blame] | 2321 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2322 | } |
Dave Airlie | 144a75f | 2008-03-30 07:53:58 +1000 | [diff] [blame] | 2323 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2324 | i915_gem_lastclose(dev); |
| 2325 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2326 | i915_dma_cleanup(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 2329 | 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] | 2330 | { |
Eric Anholt | b962442 | 2009-06-03 07:27:35 +0000 | [diff] [blame] | 2331 | i915_gem_release(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2334 | void i915_driver_postclose(struct drm_device *dev, struct drm_file *file) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2335 | { |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2336 | struct drm_i915_file_private *file_priv = file->driver_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2337 | |
Chris Wilson | f787a5f | 2010-09-24 16:02:42 +0100 | [diff] [blame] | 2338 | kfree(file_priv); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 2341 | struct drm_ioctl_desc i915_ioctls[] = { |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 2342 | DRM_IOCTL_DEF_DRV(I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2343 | DRM_IOCTL_DEF_DRV(I915_FLUSH, i915_flush_ioctl, DRM_AUTH), |
| 2344 | DRM_IOCTL_DEF_DRV(I915_FLIP, i915_flip_bufs, DRM_AUTH), |
| 2345 | DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH), |
| 2346 | DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH), |
| 2347 | DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH), |
| 2348 | DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam, DRM_AUTH), |
| 2349 | 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] | 2350 | DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH), |
| 2351 | DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH), |
| 2352 | 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] | 2353 | DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH), |
Daniel Vetter | b2c606f | 2012-01-17 12:50:12 +0100 | [diff] [blame] | 2354 | 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] | 2355 | 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] | 2356 | DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH), |
| 2357 | DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH), |
| 2358 | DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, i915_set_status_page, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2359 | DRM_IOCTL_DEF_DRV(I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 2360 | DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED), |
| 2361 | DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_UNLOCKED), |
| 2362 | DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 2363 | DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 2364 | DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED), |
| 2365 | DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_UNLOCKED), |
| 2366 | DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 2367 | DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), |
| 2368 | DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_UNLOCKED), |
| 2369 | DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_UNLOCKED), |
| 2370 | DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_UNLOCKED), |
| 2371 | DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_UNLOCKED), |
| 2372 | DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_UNLOCKED), |
| 2373 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_UNLOCKED), |
| 2374 | DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_UNLOCKED), |
| 2375 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_UNLOCKED), |
| 2376 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_UNLOCKED), |
| 2377 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_UNLOCKED), |
| 2378 | DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, DRM_UNLOCKED), |
| 2379 | DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED), |
| 2380 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
| 2381 | 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] | 2382 | DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
| 2383 | DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, intel_sprite_get_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), |
Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 2384 | }; |
| 2385 | |
| 2386 | int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 2387 | |
Daniel Vetter | 9021f28 | 2012-03-26 09:45:41 +0200 | [diff] [blame] | 2388 | /* |
| 2389 | * This is really ugly: Because old userspace abused the linux agp interface to |
| 2390 | * manage the gtt, we need to claim that all intel devices are agp. For |
| 2391 | * otherwise the drm core refuses to initialize the agp support code. |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 2392 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 2393 | int i915_driver_device_is_agp(struct drm_device * dev) |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 2394 | { |
| 2395 | return 1; |
| 2396 | } |