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 | |
| 29 | #include "drmP.h" |
| 30 | #include "drm.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 31 | #include "drm_crtc_helper.h" |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 32 | #include "drm_fb_helper.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 33 | #include "intel_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "i915_drm.h" |
| 35 | #include "i915_drv.h" |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame^] | 36 | #include "i915_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | /* Really want an OS-independent resettable timer. Would like to have |
| 39 | * this loop run for (eg) 3 sec, but have the timer reset every time |
| 40 | * the head pointer changes, so that EBUSY only happens if the ring |
| 41 | * actually stalls for (eg) 3 seconds. |
| 42 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 43 | int i915_wait_ring(struct drm_device * dev, int n, const char *caller) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 46 | drm_i915_ring_buffer_t *ring = &(dev_priv->ring); |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 47 | u32 acthd_reg = IS_I965G(dev) ? ACTHD_I965 : ACTHD; |
| 48 | u32 last_acthd = I915_READ(acthd_reg); |
| 49 | u32 acthd; |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 50 | u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | int i; |
| 52 | |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame^] | 53 | trace_i915_ring_wait_begin (dev); |
| 54 | |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 55 | for (i = 0; i < 100000; i++) { |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 56 | ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR; |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 57 | acthd = I915_READ(acthd_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | ring->space = ring->head - (ring->tail + 8); |
| 59 | if (ring->space < 0) |
| 60 | ring->space += ring->Size; |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame^] | 61 | if (ring->space >= n) { |
| 62 | trace_i915_ring_wait_end (dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | return 0; |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame^] | 64 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Chris Wilson | 98787c0 | 2009-03-06 23:27:52 +0000 | [diff] [blame] | 66 | if (dev->primary->master) { |
| 67 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 68 | if (master_priv->sarea_priv) |
| 69 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
| 70 | } |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | if (ring->head != last_head) |
| 74 | i = 0; |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 75 | if (acthd != last_acthd) |
| 76 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | last_head = ring->head; |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 79 | last_acthd = acthd; |
| 80 | msleep_interruptible(10); |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Chris Wilson | 1c5d22f | 2009-08-25 11:15:50 +0100 | [diff] [blame^] | 84 | trace_i915_ring_wait_end (dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 85 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Chris Wilson | 0ef82af | 2009-09-05 18:07:06 +0100 | [diff] [blame] | 88 | /* As a ringbuffer is only allowed to wrap between instructions, fill |
| 89 | * the tail with NOOPs. |
| 90 | */ |
| 91 | int i915_wrap_ring(struct drm_device *dev) |
| 92 | { |
| 93 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 94 | volatile unsigned int *virt; |
| 95 | int rem; |
| 96 | |
| 97 | rem = dev_priv->ring.Size - dev_priv->ring.tail; |
| 98 | if (dev_priv->ring.space < rem) { |
| 99 | int ret = i915_wait_ring(dev, rem, __func__); |
| 100 | if (ret) |
| 101 | return ret; |
| 102 | } |
| 103 | dev_priv->ring.space -= rem; |
| 104 | |
| 105 | virt = (unsigned int *) |
| 106 | (dev_priv->ring.virtual_start + dev_priv->ring.tail); |
| 107 | rem /= 4; |
| 108 | while (rem--) |
| 109 | *virt++ = MI_NOOP; |
| 110 | |
| 111 | dev_priv->ring.tail = 0; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 116 | /** |
| 117 | * Sets up the hardware status page for devices that need a physical address |
| 118 | * in the register. |
| 119 | */ |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 120 | static int i915_init_phys_hws(struct drm_device *dev) |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 121 | { |
| 122 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 123 | /* Program Hardware Status Page */ |
| 124 | dev_priv->status_page_dmah = |
| 125 | drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff); |
| 126 | |
| 127 | if (!dev_priv->status_page_dmah) { |
| 128 | DRM_ERROR("Can not allocate hardware status page\n"); |
| 129 | return -ENOMEM; |
| 130 | } |
| 131 | dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr; |
| 132 | dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr; |
| 133 | |
| 134 | memset(dev_priv->hw_status_page, 0, PAGE_SIZE); |
| 135 | |
| 136 | I915_WRITE(HWS_PGA, dev_priv->dma_status_page); |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 137 | DRM_DEBUG_DRIVER("Enabled hardware status page\n"); |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Frees the hardware status page, whether it's a physical address or a virtual |
| 143 | * address set up by the X Server. |
| 144 | */ |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 145 | static void i915_free_hws(struct drm_device *dev) |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 146 | { |
| 147 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 148 | if (dev_priv->status_page_dmah) { |
| 149 | drm_pci_free(dev, dev_priv->status_page_dmah); |
| 150 | dev_priv->status_page_dmah = NULL; |
| 151 | } |
| 152 | |
| 153 | if (dev_priv->status_gfx_addr) { |
| 154 | dev_priv->status_gfx_addr = 0; |
| 155 | drm_core_ioremapfree(&dev_priv->hws_map, dev); |
| 156 | } |
| 157 | |
| 158 | /* Need to rewrite hardware status page */ |
| 159 | I915_WRITE(HWS_PGA, 0x1ffff000); |
| 160 | } |
| 161 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 162 | void i915_kernel_lost_context(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
| 164 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 165 | struct drm_i915_master_private *master_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | drm_i915_ring_buffer_t *ring = &(dev_priv->ring); |
| 167 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 168 | /* |
| 169 | * We should never lose context on the ring with modesetting |
| 170 | * as we don't expose it to userspace |
| 171 | */ |
| 172 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 173 | return; |
| 174 | |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 175 | ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR; |
| 176 | ring->tail = I915_READ(PRB0_TAIL) & TAIL_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | ring->space = ring->head - (ring->tail + 8); |
| 178 | if (ring->space < 0) |
| 179 | ring->space += ring->Size; |
| 180 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 181 | if (!dev->primary->master) |
| 182 | return; |
| 183 | |
| 184 | master_priv = dev->primary->master->driver_priv; |
| 185 | if (ring->head == ring->tail && master_priv->sarea_priv) |
| 186 | master_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 189 | static int i915_dma_cleanup(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 191 | drm_i915_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 193 | * may not have been called from userspace and after dev_private |
| 194 | * is freed, it's too late. |
| 195 | */ |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 196 | if (dev->irq_enabled) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 197 | drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 199 | if (dev_priv->ring.virtual_start) { |
| 200 | drm_core_ioremapfree(&dev_priv->ring.map, dev); |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 201 | dev_priv->ring.virtual_start = NULL; |
| 202 | dev_priv->ring.map.handle = NULL; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 203 | dev_priv->ring.map.size = 0; |
| 204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 206 | /* Clear the HWS virtual address at teardown */ |
| 207 | if (I915_NEED_GFX_HWS(dev)) |
| 208 | i915_free_hws(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 213 | 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] | 214 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 215 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 216 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Dave Airlie | 3a03ac1 | 2009-01-11 09:03:49 +1000 | [diff] [blame] | 218 | master_priv->sarea = drm_getsarea(dev); |
| 219 | if (master_priv->sarea) { |
| 220 | master_priv->sarea_priv = (drm_i915_sarea_t *) |
| 221 | ((u8 *)master_priv->sarea->handle + init->sarea_priv_offset); |
| 222 | } else { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 223 | DRM_DEBUG_DRIVER("sarea not found assuming DRI2 userspace\n"); |
Dave Airlie | 3a03ac1 | 2009-01-11 09:03:49 +1000 | [diff] [blame] | 224 | } |
| 225 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 226 | if (init->ring_size != 0) { |
| 227 | if (dev_priv->ring.ring_obj != NULL) { |
| 228 | i915_dma_cleanup(dev); |
| 229 | DRM_ERROR("Client tried to initialize ringbuffer in " |
| 230 | "GEM mode\n"); |
| 231 | return -EINVAL; |
| 232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 234 | dev_priv->ring.Size = init->ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 236 | dev_priv->ring.map.offset = init->ring_start; |
| 237 | dev_priv->ring.map.size = init->ring_size; |
| 238 | dev_priv->ring.map.type = 0; |
| 239 | dev_priv->ring.map.flags = 0; |
| 240 | dev_priv->ring.map.mtrr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Jesse Barnes | 6fb8858 | 2009-02-23 10:08:21 +1000 | [diff] [blame] | 242 | drm_core_ioremap_wc(&dev_priv->ring.map, dev); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 243 | |
| 244 | if (dev_priv->ring.map.handle == NULL) { |
| 245 | i915_dma_cleanup(dev); |
| 246 | DRM_ERROR("can not ioremap virtual address for" |
| 247 | " ring buffer\n"); |
| 248 | return -ENOMEM; |
| 249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | dev_priv->ring.virtual_start = dev_priv->ring.map.handle; |
| 253 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 254 | dev_priv->cpp = init->cpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | dev_priv->back_offset = init->back_offset; |
| 256 | dev_priv->front_offset = init->front_offset; |
| 257 | dev_priv->current_page = 0; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 258 | if (master_priv->sarea_priv) |
| 259 | master_priv->sarea_priv->pf_current_page = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | /* Allow hardware batchbuffers unless told otherwise. |
| 262 | */ |
| 263 | dev_priv->allow_batchbuffer = 1; |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 268 | static int i915_dma_resume(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
| 270 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 271 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 272 | DRM_DEBUG_DRIVER("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | if (dev_priv->ring.map.handle == NULL) { |
| 275 | DRM_ERROR("can not ioremap virtual address for" |
| 276 | " ring buffer\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 277 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* Program Hardware Status Page */ |
| 281 | if (!dev_priv->hw_status_page) { |
| 282 | DRM_ERROR("Can not find hardware status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 283 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 285 | DRM_DEBUG_DRIVER("hw status page @ %p\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 286 | dev_priv->hw_status_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 288 | if (dev_priv->status_gfx_addr != 0) |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 289 | I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 290 | else |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 291 | I915_WRITE(HWS_PGA, dev_priv->dma_status_page); |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 292 | DRM_DEBUG_DRIVER("Enabled hardware status page\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 297 | static int i915_dma_init(struct drm_device *dev, void *data, |
| 298 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 300 | drm_i915_init_t *init = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | int retcode = 0; |
| 302 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 303 | switch (init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | case I915_INIT_DMA: |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 305 | retcode = i915_initialize(dev, init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | break; |
| 307 | case I915_CLEANUP_DMA: |
| 308 | retcode = i915_dma_cleanup(dev); |
| 309 | break; |
| 310 | case I915_RESUME_DMA: |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 311 | retcode = i915_dma_resume(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | break; |
| 313 | default: |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 314 | retcode = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | break; |
| 316 | } |
| 317 | |
| 318 | return retcode; |
| 319 | } |
| 320 | |
| 321 | /* Implement basically the same security restrictions as hardware does |
| 322 | * for MI_BATCH_NON_SECURE. These can be made stricter at any time. |
| 323 | * |
| 324 | * Most of the calculations below involve calculating the size of a |
| 325 | * particular instruction. It's important to get the size right as |
| 326 | * that tells us where the next instruction to check is. Any illegal |
| 327 | * instruction detected will be given a size of zero, which is a |
| 328 | * signal to abort the rest of the buffer. |
| 329 | */ |
| 330 | static int do_validate_cmd(int cmd) |
| 331 | { |
| 332 | switch (((cmd >> 29) & 0x7)) { |
| 333 | case 0x0: |
| 334 | switch ((cmd >> 23) & 0x3f) { |
| 335 | case 0x0: |
| 336 | return 1; /* MI_NOOP */ |
| 337 | case 0x4: |
| 338 | return 1; /* MI_FLUSH */ |
| 339 | default: |
| 340 | return 0; /* disallow everything else */ |
| 341 | } |
| 342 | break; |
| 343 | case 0x1: |
| 344 | return 0; /* reserved */ |
| 345 | case 0x2: |
| 346 | return (cmd & 0xff) + 2; /* 2d commands */ |
| 347 | case 0x3: |
| 348 | if (((cmd >> 24) & 0x1f) <= 0x18) |
| 349 | return 1; |
| 350 | |
| 351 | switch ((cmd >> 24) & 0x1f) { |
| 352 | case 0x1c: |
| 353 | return 1; |
| 354 | case 0x1d: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 355 | switch ((cmd >> 16) & 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | case 0x3: |
| 357 | return (cmd & 0x1f) + 2; |
| 358 | case 0x4: |
| 359 | return (cmd & 0xf) + 2; |
| 360 | default: |
| 361 | return (cmd & 0xffff) + 2; |
| 362 | } |
| 363 | case 0x1e: |
| 364 | if (cmd & (1 << 23)) |
| 365 | return (cmd & 0xffff) + 1; |
| 366 | else |
| 367 | return 1; |
| 368 | case 0x1f: |
| 369 | if ((cmd & (1 << 23)) == 0) /* inline vertices */ |
| 370 | return (cmd & 0x1ffff) + 2; |
| 371 | else if (cmd & (1 << 17)) /* indirect random */ |
| 372 | if ((cmd & 0xffff) == 0) |
| 373 | return 0; /* unknown length, too hard */ |
| 374 | else |
| 375 | return (((cmd & 0xffff) + 1) / 2) + 1; |
| 376 | else |
| 377 | return 2; /* indirect sequential */ |
| 378 | default: |
| 379 | return 0; |
| 380 | } |
| 381 | default: |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | static int validate_cmd(int cmd) |
| 389 | { |
| 390 | int ret = do_validate_cmd(cmd); |
| 391 | |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 392 | /* printk("validate_cmd( %x ): %d\n", cmd, ret); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | return ret; |
| 395 | } |
| 396 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 397 | 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] | 398 | { |
| 399 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 400 | int i; |
| 401 | RING_LOCALS; |
| 402 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 403 | if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 404 | return -EINVAL; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 405 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 406 | BEGIN_LP_RING((dwords+1)&~1); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | for (i = 0; i < dwords;) { |
| 409 | int cmd, sz; |
| 410 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 411 | cmd = buffer[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 414 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | OUT_RING(cmd); |
| 417 | |
| 418 | while (++i, --sz) { |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 419 | OUT_RING(buffer[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 423 | if (dwords & 1) |
| 424 | OUT_RING(0); |
| 425 | |
| 426 | ADVANCE_LP_RING(); |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return 0; |
| 429 | } |
| 430 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 431 | int |
| 432 | i915_emit_box(struct drm_device *dev, |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 433 | struct drm_clip_rect *boxes, |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 434 | int i, int DR1, int DR4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
| 436 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 437 | struct drm_clip_rect box = boxes[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | RING_LOCALS; |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) { |
| 441 | DRM_ERROR("Bad box %d,%d..%d,%d\n", |
| 442 | box.x1, box.y1, box.x2, box.y2); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 443 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 446 | if (IS_I965G(dev)) { |
| 447 | BEGIN_LP_RING(4); |
| 448 | OUT_RING(GFX_OP_DRAWRECT_INFO_I965); |
| 449 | OUT_RING((box.x1 & 0xffff) | (box.y1 << 16)); |
Andrew Morton | 78eca43 | 2006-08-16 09:15:51 +1000 | [diff] [blame] | 450 | OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16)); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 451 | OUT_RING(DR4); |
| 452 | ADVANCE_LP_RING(); |
| 453 | } else { |
| 454 | BEGIN_LP_RING(6); |
| 455 | OUT_RING(GFX_OP_DRAWRECT_INFO); |
| 456 | OUT_RING(DR1); |
| 457 | OUT_RING((box.x1 & 0xffff) | (box.y1 << 16)); |
| 458 | OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16)); |
| 459 | OUT_RING(DR4); |
| 460 | OUT_RING(0); |
| 461 | ADVANCE_LP_RING(); |
| 462 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 467 | /* XXX: Emitting the counter should really be moved to part of the IRQ |
| 468 | * emit. For now, do it in both places: |
| 469 | */ |
| 470 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 471 | static void i915_emit_breadcrumb(struct drm_device *dev) |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 472 | { |
| 473 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 474 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 475 | RING_LOCALS; |
| 476 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 477 | dev_priv->counter++; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 478 | if (dev_priv->counter > 0x7FFFFFFFUL) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 479 | dev_priv->counter = 0; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 480 | if (master_priv->sarea_priv) |
| 481 | master_priv->sarea_priv->last_enqueue = dev_priv->counter; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 482 | |
| 483 | BEGIN_LP_RING(4); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 484 | OUT_RING(MI_STORE_DWORD_INDEX); |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 485 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 486 | OUT_RING(dev_priv->counter); |
| 487 | OUT_RING(0); |
| 488 | ADVANCE_LP_RING(); |
| 489 | } |
| 490 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 491 | static int i915_dispatch_cmdbuffer(struct drm_device * dev, |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 492 | drm_i915_cmdbuffer_t *cmd, |
| 493 | struct drm_clip_rect *cliprects, |
| 494 | void *cmdbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
| 496 | int nbox = cmd->num_cliprects; |
| 497 | int i = 0, count, ret; |
| 498 | |
| 499 | if (cmd->sz & 0x3) { |
| 500 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 501 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | i915_kernel_lost_context(dev); |
| 505 | |
| 506 | count = nbox ? nbox : 1; |
| 507 | |
| 508 | for (i = 0; i < count; i++) { |
| 509 | if (i < nbox) { |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 510 | ret = i915_emit_box(dev, cliprects, i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | cmd->DR1, cmd->DR4); |
| 512 | if (ret) |
| 513 | return ret; |
| 514 | } |
| 515 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 516 | ret = i915_emit_cmds(dev, cmdbuf, cmd->sz / 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (ret) |
| 518 | return ret; |
| 519 | } |
| 520 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 521 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | return 0; |
| 523 | } |
| 524 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 525 | static int i915_dispatch_batchbuffer(struct drm_device * dev, |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 526 | drm_i915_batchbuffer_t * batch, |
| 527 | struct drm_clip_rect *cliprects) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | drm_i915_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | int nbox = batch->num_cliprects; |
| 531 | int i = 0, count; |
| 532 | RING_LOCALS; |
| 533 | |
| 534 | if ((batch->start | batch->used) & 0x7) { |
| 535 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 536 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | i915_kernel_lost_context(dev); |
| 540 | |
| 541 | count = nbox ? nbox : 1; |
| 542 | |
| 543 | for (i = 0; i < count; i++) { |
| 544 | if (i < nbox) { |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 545 | int ret = i915_emit_box(dev, cliprects, i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | batch->DR1, batch->DR4); |
| 547 | if (ret) |
| 548 | return ret; |
| 549 | } |
| 550 | |
Keith Packard | 0790d5e | 2008-07-30 12:28:47 -0700 | [diff] [blame] | 551 | if (!IS_I830(dev) && !IS_845G(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | BEGIN_LP_RING(2); |
Dave Airlie | 21f1628 | 2007-08-07 09:09:51 +1000 | [diff] [blame] | 553 | if (IS_I965G(dev)) { |
| 554 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965); |
| 555 | OUT_RING(batch->start); |
| 556 | } else { |
| 557 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6)); |
| 558 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | ADVANCE_LP_RING(); |
| 561 | } else { |
| 562 | BEGIN_LP_RING(4); |
| 563 | OUT_RING(MI_BATCH_BUFFER); |
| 564 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 565 | OUT_RING(batch->start + batch->used - 4); |
| 566 | OUT_RING(0); |
| 567 | ADVANCE_LP_RING(); |
| 568 | } |
| 569 | } |
| 570 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 571 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 576 | static int i915_dispatch_flip(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
| 578 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 579 | struct drm_i915_master_private *master_priv = |
| 580 | dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | RING_LOCALS; |
| 582 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 583 | if (!master_priv->sarea_priv) |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 584 | return -EINVAL; |
| 585 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 586 | DRM_DEBUG_DRIVER("%s: page=%d pfCurrentPage=%d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 587 | __func__, |
| 588 | dev_priv->current_page, |
| 589 | master_priv->sarea_priv->pf_current_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 591 | i915_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 593 | BEGIN_LP_RING(2); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 594 | OUT_RING(MI_FLUSH | MI_READ_FLUSH); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 595 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | ADVANCE_LP_RING(); |
| 597 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 598 | BEGIN_LP_RING(6); |
| 599 | OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP); |
| 600 | OUT_RING(0); |
| 601 | if (dev_priv->current_page == 0) { |
| 602 | OUT_RING(dev_priv->back_offset); |
| 603 | dev_priv->current_page = 1; |
| 604 | } else { |
| 605 | OUT_RING(dev_priv->front_offset); |
| 606 | dev_priv->current_page = 0; |
| 607 | } |
| 608 | OUT_RING(0); |
| 609 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 610 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 611 | BEGIN_LP_RING(2); |
| 612 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP); |
| 613 | OUT_RING(0); |
| 614 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 615 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 616 | master_priv->sarea_priv->last_enqueue = dev_priv->counter++; |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 617 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 618 | BEGIN_LP_RING(4); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 619 | OUT_RING(MI_STORE_DWORD_INDEX); |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 620 | OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 621 | OUT_RING(dev_priv->counter); |
| 622 | OUT_RING(0); |
| 623 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 624 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 625 | master_priv->sarea_priv->pf_current_page = dev_priv->current_page; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 626 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 629 | static int i915_quiescent(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 632 | |
| 633 | i915_kernel_lost_context(dev); |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 634 | return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 637 | static int i915_flush_ioctl(struct drm_device *dev, void *data, |
| 638 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 640 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 642 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 643 | |
| 644 | mutex_lock(&dev->struct_mutex); |
| 645 | ret = i915_quiescent(dev); |
| 646 | mutex_unlock(&dev->struct_mutex); |
| 647 | |
| 648 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 651 | static int i915_batchbuffer(struct drm_device *dev, void *data, |
| 652 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | 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] | 655 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 657 | master_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 658 | drm_i915_batchbuffer_t *batch = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | int ret; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 660 | struct drm_clip_rect *cliprects = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
| 662 | if (!dev_priv->allow_batchbuffer) { |
| 663 | DRM_ERROR("Batchbuffer ioctl disabled\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 664 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 667 | DRM_DEBUG_DRIVER("i915 batchbuffer, start %x used %d cliprects %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 668 | batch->start, batch->used, batch->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 670 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 672 | if (batch->num_cliprects < 0) |
| 673 | return -EINVAL; |
| 674 | |
| 675 | if (batch->num_cliprects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 676 | cliprects = kcalloc(batch->num_cliprects, |
| 677 | sizeof(struct drm_clip_rect), |
| 678 | GFP_KERNEL); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 679 | if (cliprects == NULL) |
| 680 | return -ENOMEM; |
| 681 | |
| 682 | ret = copy_from_user(cliprects, batch->cliprects, |
| 683 | batch->num_cliprects * |
| 684 | sizeof(struct drm_clip_rect)); |
| 685 | if (ret != 0) |
| 686 | goto fail_free; |
| 687 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 689 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 690 | ret = i915_dispatch_batchbuffer(dev, batch, cliprects); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 691 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 693 | if (sarea_priv) |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 694 | sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 695 | |
| 696 | fail_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 697 | kfree(cliprects); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return ret; |
| 700 | } |
| 701 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 702 | static int i915_cmdbuffer(struct drm_device *dev, void *data, |
| 703 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | 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] | 706 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 708 | master_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 709 | drm_i915_cmdbuffer_t *cmdbuf = data; |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 710 | struct drm_clip_rect *cliprects = NULL; |
| 711 | void *batch_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | int ret; |
| 713 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 714 | DRM_DEBUG_DRIVER("i915 cmdbuffer, buf %p sz %d cliprects %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 715 | cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 717 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 719 | if (cmdbuf->num_cliprects < 0) |
| 720 | return -EINVAL; |
| 721 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 722 | batch_data = kmalloc(cmdbuf->sz, GFP_KERNEL); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 723 | if (batch_data == NULL) |
| 724 | return -ENOMEM; |
| 725 | |
| 726 | ret = copy_from_user(batch_data, cmdbuf->buf, cmdbuf->sz); |
| 727 | if (ret != 0) |
| 728 | goto fail_batch_free; |
| 729 | |
| 730 | if (cmdbuf->num_cliprects) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 731 | cliprects = kcalloc(cmdbuf->num_cliprects, |
| 732 | sizeof(struct drm_clip_rect), GFP_KERNEL); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 733 | if (cliprects == NULL) |
| 734 | goto fail_batch_free; |
| 735 | |
| 736 | ret = copy_from_user(cliprects, cmdbuf->cliprects, |
| 737 | cmdbuf->num_cliprects * |
| 738 | sizeof(struct drm_clip_rect)); |
| 739 | if (ret != 0) |
| 740 | goto fail_clip_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 743 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 744 | ret = i915_dispatch_cmdbuffer(dev, cmdbuf, cliprects, batch_data); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 745 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | if (ret) { |
| 747 | DRM_ERROR("i915_dispatch_cmdbuffer failed\n"); |
Chris Wright | 355d7f3 | 2009-04-17 01:18:55 +0000 | [diff] [blame] | 748 | goto fail_clip_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Kristian Høgsberg | c99b058 | 2008-08-20 11:20:13 -0400 | [diff] [blame] | 751 | if (sarea_priv) |
Keith Packard | 0baf823 | 2008-11-08 11:44:14 +1000 | [diff] [blame] | 752 | sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 753 | |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 754 | fail_clip_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 755 | kfree(cliprects); |
Chris Wright | 355d7f3 | 2009-04-17 01:18:55 +0000 | [diff] [blame] | 756 | fail_batch_free: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 757 | kfree(batch_data); |
Eric Anholt | 201361a | 2009-03-11 12:30:04 -0700 | [diff] [blame] | 758 | |
| 759 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 762 | static int i915_flip_bufs(struct drm_device *dev, void *data, |
| 763 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 765 | int ret; |
| 766 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 767 | DRM_DEBUG_DRIVER("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 769 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame] | 771 | mutex_lock(&dev->struct_mutex); |
| 772 | ret = i915_dispatch_flip(dev); |
| 773 | mutex_unlock(&dev->struct_mutex); |
| 774 | |
| 775 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 778 | static int i915_getparam(struct drm_device *dev, void *data, |
| 779 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 782 | drm_i915_getparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | int value; |
| 784 | |
| 785 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 786 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 787 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 790 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | case I915_PARAM_IRQ_ACTIVE: |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 792 | value = dev->pdev->irq ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | break; |
| 794 | case I915_PARAM_ALLOW_BATCHBUFFER: |
| 795 | value = dev_priv->allow_batchbuffer ? 1 : 0; |
| 796 | break; |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 797 | case I915_PARAM_LAST_DISPATCH: |
| 798 | value = READ_BREADCRUMB(dev_priv); |
| 799 | break; |
Kristian Høgsberg | ed4c9c4 | 2008-08-20 11:08:52 -0400 | [diff] [blame] | 800 | case I915_PARAM_CHIPSET_ID: |
| 801 | value = dev->pci_device; |
| 802 | break; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 803 | case I915_PARAM_HAS_GEM: |
Dave Airlie | ac5c4e7 | 2008-12-19 15:38:34 +1000 | [diff] [blame] | 804 | value = dev_priv->has_gem; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 805 | break; |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 806 | case I915_PARAM_NUM_FENCES_AVAIL: |
| 807 | value = dev_priv->num_fence_regs - dev_priv->fence_reg_start; |
| 808 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | default: |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 810 | DRM_DEBUG_DRIVER("Unknown parameter %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 811 | param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 812 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 815 | if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | DRM_ERROR("DRM_COPY_TO_USER failed\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 817 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 823 | static int i915_setparam(struct drm_device *dev, void *data, |
| 824 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 827 | drm_i915_setparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
| 829 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 830 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 831 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 834 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | case I915_SETPARAM_USE_MI_BATCHBUFFER_START: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | break; |
| 837 | case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 838 | dev_priv->tex_lru_log_granularity = param->value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | break; |
| 840 | case I915_SETPARAM_ALLOW_BATCHBUFFER: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 841 | dev_priv->allow_batchbuffer = param->value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | break; |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 843 | case I915_SETPARAM_NUM_USED_FENCES: |
| 844 | if (param->value > dev_priv->num_fence_regs || |
| 845 | param->value < 0) |
| 846 | return -EINVAL; |
| 847 | /* Userspace can use first N regs */ |
| 848 | dev_priv->fence_reg_start = param->value; |
| 849 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | default: |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 851 | DRM_DEBUG_DRIVER("unknown parameter %d\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 852 | param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 853 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 859 | static int i915_set_status_page(struct drm_device *dev, void *data, |
| 860 | struct drm_file *file_priv) |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 861 | { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 862 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 863 | drm_i915_hws_addr_t *hws = data; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 864 | |
Zhenyu Wang | b39d50e | 2008-02-19 20:59:09 +1000 | [diff] [blame] | 865 | if (!I915_NEED_GFX_HWS(dev)) |
| 866 | return -EINVAL; |
| 867 | |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 868 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 869 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 870 | return -EINVAL; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 871 | } |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 872 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 873 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 874 | WARN(1, "tried to set status page when mode setting active\n"); |
| 875 | return 0; |
| 876 | } |
| 877 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 878 | 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] | 879 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 880 | dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12); |
| 881 | |
Eric Anholt | 8b40958 | 2007-11-22 16:40:37 +1000 | [diff] [blame] | 882 | dev_priv->hws_map.offset = dev->agp->base + hws->addr; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 883 | dev_priv->hws_map.size = 4*1024; |
| 884 | dev_priv->hws_map.type = 0; |
| 885 | dev_priv->hws_map.flags = 0; |
| 886 | dev_priv->hws_map.mtrr = 0; |
| 887 | |
Dave Airlie | dd0910b | 2009-02-25 14:49:21 +1000 | [diff] [blame] | 888 | drm_core_ioremap_wc(&dev_priv->hws_map, dev); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 889 | if (dev_priv->hws_map.handle == NULL) { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 890 | i915_dma_cleanup(dev); |
| 891 | dev_priv->status_gfx_addr = 0; |
| 892 | DRM_ERROR("can not ioremap virtual address for" |
| 893 | " G33 hw status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 894 | return -ENOMEM; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 895 | } |
| 896 | dev_priv->hw_status_page = dev_priv->hws_map.handle; |
| 897 | |
| 898 | memset(dev_priv->hw_status_page, 0, PAGE_SIZE); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 899 | I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 900 | DRM_DEBUG_DRIVER("load hws HWS_PGA with gfx mem 0x%x\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 901 | dev_priv->status_gfx_addr); |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 902 | DRM_DEBUG_DRIVER("load hws at %p\n", |
yakui_zhao | be25ed9 | 2009-06-02 14:13:55 +0800 | [diff] [blame] | 903 | dev_priv->hw_status_page); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 904 | return 0; |
| 905 | } |
| 906 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 907 | static int i915_get_bridge_dev(struct drm_device *dev) |
| 908 | { |
| 909 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 910 | |
| 911 | dev_priv->bridge_dev = pci_get_bus_and_slot(0, PCI_DEVFN(0,0)); |
| 912 | if (!dev_priv->bridge_dev) { |
| 913 | DRM_ERROR("bridge device not found\n"); |
| 914 | return -1; |
| 915 | } |
| 916 | return 0; |
| 917 | } |
| 918 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 919 | /** |
| 920 | * i915_probe_agp - get AGP bootup configuration |
| 921 | * @pdev: PCI device |
| 922 | * @aperture_size: returns AGP aperture configured size |
| 923 | * @preallocated_size: returns size of BIOS preallocated AGP space |
| 924 | * |
| 925 | * Since Intel integrated graphics are UMA, the BIOS has to set aside |
| 926 | * some RAM for the framebuffer at early boot. This code figures out |
| 927 | * how much was set aside so we can use it for our own purposes. |
| 928 | */ |
Eric Anholt | 2a34f5e6 | 2009-07-02 09:30:50 -0700 | [diff] [blame] | 929 | static int i915_probe_agp(struct drm_device *dev, uint32_t *aperture_size, |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 930 | uint32_t *preallocated_size, |
| 931 | uint32_t *start) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 932 | { |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 933 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 934 | u16 tmp = 0; |
| 935 | unsigned long overhead; |
Eric Anholt | 241fa85 | 2009-01-02 18:05:51 -0800 | [diff] [blame] | 936 | unsigned long stolen; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 937 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 938 | /* Get the fb aperture size and "stolen" memory amount. */ |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 939 | pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &tmp); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 940 | |
| 941 | *aperture_size = 1024 * 1024; |
| 942 | *preallocated_size = 1024 * 1024; |
| 943 | |
Eric Anholt | 60fd99e | 2008-12-03 22:50:02 -0800 | [diff] [blame] | 944 | switch (dev->pdev->device) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 945 | case PCI_DEVICE_ID_INTEL_82830_CGC: |
| 946 | case PCI_DEVICE_ID_INTEL_82845G_IG: |
| 947 | case PCI_DEVICE_ID_INTEL_82855GM_IG: |
| 948 | case PCI_DEVICE_ID_INTEL_82865_IG: |
| 949 | if ((tmp & INTEL_GMCH_MEM_MASK) == INTEL_GMCH_MEM_64M) |
| 950 | *aperture_size *= 64; |
| 951 | else |
| 952 | *aperture_size *= 128; |
| 953 | break; |
| 954 | default: |
| 955 | /* 9xx supports large sizes, just look at the length */ |
Eric Anholt | 60fd99e | 2008-12-03 22:50:02 -0800 | [diff] [blame] | 956 | *aperture_size = pci_resource_len(dev->pdev, 2); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 957 | break; |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | * Some of the preallocated space is taken by the GTT |
| 962 | * and popup. GTT is 1K per MB of aperture size, and popup is 4K. |
| 963 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 964 | if (IS_G4X(dev) || IS_IGD(dev) || IS_IGDNG(dev)) |
Eric Anholt | 60fd99e | 2008-12-03 22:50:02 -0800 | [diff] [blame] | 965 | overhead = 4096; |
| 966 | else |
| 967 | overhead = (*aperture_size / 1024) + 4096; |
| 968 | |
Eric Anholt | 241fa85 | 2009-01-02 18:05:51 -0800 | [diff] [blame] | 969 | switch (tmp & INTEL_GMCH_GMS_MASK) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 970 | case INTEL_855_GMCH_GMS_DISABLED: |
| 971 | DRM_ERROR("video memory is disabled\n"); |
| 972 | return -1; |
Eric Anholt | 241fa85 | 2009-01-02 18:05:51 -0800 | [diff] [blame] | 973 | case INTEL_855_GMCH_GMS_STOLEN_1M: |
| 974 | stolen = 1 * 1024 * 1024; |
| 975 | break; |
| 976 | case INTEL_855_GMCH_GMS_STOLEN_4M: |
| 977 | stolen = 4 * 1024 * 1024; |
| 978 | break; |
| 979 | case INTEL_855_GMCH_GMS_STOLEN_8M: |
| 980 | stolen = 8 * 1024 * 1024; |
| 981 | break; |
| 982 | case INTEL_855_GMCH_GMS_STOLEN_16M: |
| 983 | stolen = 16 * 1024 * 1024; |
| 984 | break; |
| 985 | case INTEL_855_GMCH_GMS_STOLEN_32M: |
| 986 | stolen = 32 * 1024 * 1024; |
| 987 | break; |
| 988 | case INTEL_915G_GMCH_GMS_STOLEN_48M: |
| 989 | stolen = 48 * 1024 * 1024; |
| 990 | break; |
| 991 | case INTEL_915G_GMCH_GMS_STOLEN_64M: |
| 992 | stolen = 64 * 1024 * 1024; |
| 993 | break; |
| 994 | case INTEL_GMCH_GMS_STOLEN_128M: |
| 995 | stolen = 128 * 1024 * 1024; |
| 996 | break; |
| 997 | case INTEL_GMCH_GMS_STOLEN_256M: |
| 998 | stolen = 256 * 1024 * 1024; |
| 999 | break; |
| 1000 | case INTEL_GMCH_GMS_STOLEN_96M: |
| 1001 | stolen = 96 * 1024 * 1024; |
| 1002 | break; |
| 1003 | case INTEL_GMCH_GMS_STOLEN_160M: |
| 1004 | stolen = 160 * 1024 * 1024; |
| 1005 | break; |
| 1006 | case INTEL_GMCH_GMS_STOLEN_224M: |
| 1007 | stolen = 224 * 1024 * 1024; |
| 1008 | break; |
| 1009 | case INTEL_GMCH_GMS_STOLEN_352M: |
| 1010 | stolen = 352 * 1024 * 1024; |
| 1011 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1012 | default: |
| 1013 | DRM_ERROR("unexpected GMCH_GMS value: 0x%02x\n", |
Eric Anholt | 241fa85 | 2009-01-02 18:05:51 -0800 | [diff] [blame] | 1014 | tmp & INTEL_GMCH_GMS_MASK); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1015 | return -1; |
| 1016 | } |
Eric Anholt | 241fa85 | 2009-01-02 18:05:51 -0800 | [diff] [blame] | 1017 | *preallocated_size = stolen - overhead; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1018 | *start = overhead; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1023 | #define PTE_ADDRESS_MASK 0xfffff000 |
| 1024 | #define PTE_ADDRESS_MASK_HIGH 0x000000f0 /* i915+ */ |
| 1025 | #define PTE_MAPPING_TYPE_UNCACHED (0 << 1) |
| 1026 | #define PTE_MAPPING_TYPE_DCACHE (1 << 1) /* i830 only */ |
| 1027 | #define PTE_MAPPING_TYPE_CACHED (3 << 1) |
| 1028 | #define PTE_MAPPING_TYPE_MASK (3 << 1) |
| 1029 | #define PTE_VALID (1 << 0) |
| 1030 | |
| 1031 | /** |
| 1032 | * i915_gtt_to_phys - take a GTT address and turn it into a physical one |
| 1033 | * @dev: drm device |
| 1034 | * @gtt_addr: address to translate |
| 1035 | * |
| 1036 | * Some chip functions require allocations from stolen space but need the |
| 1037 | * physical address of the memory in question. We use this routine |
| 1038 | * to get a physical address suitable for register programming from a given |
| 1039 | * GTT address. |
| 1040 | */ |
| 1041 | static unsigned long i915_gtt_to_phys(struct drm_device *dev, |
| 1042 | unsigned long gtt_addr) |
| 1043 | { |
| 1044 | unsigned long *gtt; |
| 1045 | unsigned long entry, phys; |
| 1046 | int gtt_bar = IS_I9XX(dev) ? 0 : 1; |
| 1047 | int gtt_offset, gtt_size; |
| 1048 | |
| 1049 | if (IS_I965G(dev)) { |
| 1050 | if (IS_G4X(dev) || IS_IGDNG(dev)) { |
| 1051 | gtt_offset = 2*1024*1024; |
| 1052 | gtt_size = 2*1024*1024; |
| 1053 | } else { |
| 1054 | gtt_offset = 512*1024; |
| 1055 | gtt_size = 512*1024; |
| 1056 | } |
| 1057 | } else { |
| 1058 | gtt_bar = 3; |
| 1059 | gtt_offset = 0; |
| 1060 | gtt_size = pci_resource_len(dev->pdev, gtt_bar); |
| 1061 | } |
| 1062 | |
| 1063 | gtt = ioremap_wc(pci_resource_start(dev->pdev, gtt_bar) + gtt_offset, |
| 1064 | gtt_size); |
| 1065 | if (!gtt) { |
| 1066 | DRM_ERROR("ioremap of GTT failed\n"); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | entry = *(volatile u32 *)(gtt + (gtt_addr / 1024)); |
| 1071 | |
| 1072 | DRM_DEBUG("GTT addr: 0x%08lx, PTE: 0x%08lx\n", gtt_addr, entry); |
| 1073 | |
| 1074 | /* Mask out these reserved bits on this hardware. */ |
| 1075 | if (!IS_I9XX(dev) || IS_I915G(dev) || IS_I915GM(dev) || |
| 1076 | IS_I945G(dev) || IS_I945GM(dev)) { |
| 1077 | entry &= ~PTE_ADDRESS_MASK_HIGH; |
| 1078 | } |
| 1079 | |
| 1080 | /* If it's not a mapping type we know, then bail. */ |
| 1081 | if ((entry & PTE_MAPPING_TYPE_MASK) != PTE_MAPPING_TYPE_UNCACHED && |
| 1082 | (entry & PTE_MAPPING_TYPE_MASK) != PTE_MAPPING_TYPE_CACHED) { |
| 1083 | iounmap(gtt); |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | if (!(entry & PTE_VALID)) { |
| 1088 | DRM_ERROR("bad GTT entry in stolen space\n"); |
| 1089 | iounmap(gtt); |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | iounmap(gtt); |
| 1094 | |
| 1095 | phys =(entry & PTE_ADDRESS_MASK) | |
| 1096 | ((uint64_t)(entry & PTE_ADDRESS_MASK_HIGH) << (32 - 4)); |
| 1097 | |
| 1098 | DRM_DEBUG("GTT addr: 0x%08lx, phys addr: 0x%08lx\n", gtt_addr, phys); |
| 1099 | |
| 1100 | return phys; |
| 1101 | } |
| 1102 | |
| 1103 | static void i915_warn_stolen(struct drm_device *dev) |
| 1104 | { |
| 1105 | DRM_ERROR("not enough stolen space for compressed buffer, disabling\n"); |
| 1106 | DRM_ERROR("hint: you may be able to increase stolen memory size in the BIOS to avoid this\n"); |
| 1107 | } |
| 1108 | |
| 1109 | static void i915_setup_compression(struct drm_device *dev, int size) |
| 1110 | { |
| 1111 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1112 | struct drm_mm_node *compressed_fb, *compressed_llb; |
| 1113 | unsigned long cfb_base, ll_base; |
| 1114 | |
| 1115 | /* Leave 1M for line length buffer & misc. */ |
| 1116 | compressed_fb = drm_mm_search_free(&dev_priv->vram, size, 4096, 0); |
| 1117 | if (!compressed_fb) { |
| 1118 | i915_warn_stolen(dev); |
| 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | compressed_fb = drm_mm_get_block(compressed_fb, size, 4096); |
| 1123 | if (!compressed_fb) { |
| 1124 | i915_warn_stolen(dev); |
| 1125 | return; |
| 1126 | } |
| 1127 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1128 | cfb_base = i915_gtt_to_phys(dev, compressed_fb->start); |
| 1129 | if (!cfb_base) { |
| 1130 | DRM_ERROR("failed to get stolen phys addr, disabling FBC\n"); |
| 1131 | drm_mm_put_block(compressed_fb); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1134 | if (!IS_GM45(dev)) { |
| 1135 | compressed_llb = drm_mm_search_free(&dev_priv->vram, 4096, |
| 1136 | 4096, 0); |
| 1137 | if (!compressed_llb) { |
| 1138 | i915_warn_stolen(dev); |
| 1139 | return; |
| 1140 | } |
| 1141 | |
| 1142 | compressed_llb = drm_mm_get_block(compressed_llb, 4096, 4096); |
| 1143 | if (!compressed_llb) { |
| 1144 | i915_warn_stolen(dev); |
| 1145 | return; |
| 1146 | } |
| 1147 | |
| 1148 | ll_base = i915_gtt_to_phys(dev, compressed_llb->start); |
| 1149 | if (!ll_base) { |
| 1150 | DRM_ERROR("failed to get stolen phys addr, disabling FBC\n"); |
| 1151 | drm_mm_put_block(compressed_fb); |
| 1152 | drm_mm_put_block(compressed_llb); |
| 1153 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | dev_priv->cfb_size = size; |
| 1157 | |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1158 | if (IS_GM45(dev)) { |
| 1159 | g4x_disable_fbc(dev); |
| 1160 | I915_WRITE(DPFC_CB_BASE, compressed_fb->start); |
| 1161 | } else { |
| 1162 | i8xx_disable_fbc(dev); |
| 1163 | I915_WRITE(FBC_CFB_BASE, cfb_base); |
| 1164 | I915_WRITE(FBC_LL_BASE, ll_base); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1167 | DRM_DEBUG("FBC base 0x%08lx, ll base 0x%08lx, size %dM\n", cfb_base, |
| 1168 | ll_base, size >> 20); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Eric Anholt | 2a34f5e6 | 2009-07-02 09:30:50 -0700 | [diff] [blame] | 1171 | static int i915_load_modeset_init(struct drm_device *dev, |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1172 | unsigned long prealloc_start, |
Eric Anholt | 2a34f5e6 | 2009-07-02 09:30:50 -0700 | [diff] [blame] | 1173 | unsigned long prealloc_size, |
| 1174 | unsigned long agp_size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1175 | { |
| 1176 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1177 | int fb_bar = IS_I9XX(dev) ? 2 : 0; |
| 1178 | int ret = 0; |
| 1179 | |
| 1180 | dev->mode_config.fb_base = drm_get_resource_start(dev, fb_bar) & |
| 1181 | 0xff000000; |
| 1182 | |
Jesse Barnes | 2906f02 | 2009-01-20 19:10:54 -0800 | [diff] [blame] | 1183 | if (IS_MOBILE(dev) || IS_I9XX(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1184 | dev_priv->cursor_needs_physical = true; |
| 1185 | else |
| 1186 | dev_priv->cursor_needs_physical = false; |
| 1187 | |
Jesse Barnes | 2906f02 | 2009-01-20 19:10:54 -0800 | [diff] [blame] | 1188 | if (IS_I965G(dev) || IS_G33(dev)) |
| 1189 | dev_priv->cursor_needs_physical = false; |
| 1190 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1191 | /* Basic memrange allocator for stolen space (aka vram) */ |
| 1192 | drm_mm_init(&dev_priv->vram, 0, prealloc_size); |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1193 | DRM_INFO("set up %ldM of stolen space\n", prealloc_size / (1024*1024)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1194 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1195 | /* We're off and running w/KMS */ |
| 1196 | dev_priv->mm.suspended = 0; |
| 1197 | |
Eric Anholt | 13f4c43 | 2009-05-12 15:27:36 -0700 | [diff] [blame] | 1198 | /* Let GEM Manage from end of prealloc space to end of aperture. |
| 1199 | * |
| 1200 | * However, leave one page at the end still bound to the scratch page. |
| 1201 | * There are a number of places where the hardware apparently |
| 1202 | * prefetches past the end of the object, and we've seen multiple |
| 1203 | * hangs with the GPU head pointer stuck in a batchbuffer bound |
| 1204 | * at the last page of the aperture. One page should be enough to |
| 1205 | * keep any prefetching inside of the aperture. |
| 1206 | */ |
| 1207 | i915_gem_do_init(dev, prealloc_size, agp_size - 4096); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1208 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1209 | mutex_lock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1210 | ret = i915_gem_init_ringbuffer(dev); |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1211 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1212 | if (ret) |
Dave Airlie | b8da7de | 2009-06-02 16:50:35 +1000 | [diff] [blame] | 1213 | goto out; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1214 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1215 | /* Try to set up FBC with a reasonable compressed buffer size */ |
Jesse Barnes | 74dff28 | 2009-09-14 15:39:40 -0700 | [diff] [blame] | 1216 | if (IS_MOBILE(dev) && (IS_I9XX(dev) || IS_I965G(dev) || IS_GM45(dev)) && |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1217 | i915_powersave) { |
| 1218 | int cfb_size; |
| 1219 | |
| 1220 | /* Try to get an 8M buffer... */ |
| 1221 | if (prealloc_size > (9*1024*1024)) |
| 1222 | cfb_size = 8*1024*1024; |
| 1223 | else /* fall back to 7/8 of the stolen space */ |
| 1224 | cfb_size = prealloc_size * 7 / 8; |
| 1225 | i915_setup_compression(dev, cfb_size); |
| 1226 | } |
| 1227 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1228 | /* Allow hardware batchbuffers unless told otherwise. |
| 1229 | */ |
| 1230 | dev_priv->allow_batchbuffer = 1; |
| 1231 | |
| 1232 | ret = intel_init_bios(dev); |
| 1233 | if (ret) |
| 1234 | DRM_INFO("failed to find VBIOS tables\n"); |
| 1235 | |
| 1236 | ret = drm_irq_install(dev); |
| 1237 | if (ret) |
| 1238 | goto destroy_ringbuffer; |
| 1239 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1240 | /* Always safe in the mode setting case. */ |
| 1241 | /* FIXME: do pre/post-mode set stuff in core KMS code */ |
| 1242 | dev->vblank_disable_allowed = 1; |
| 1243 | |
| 1244 | /* |
| 1245 | * Initialize the hardware status page IRQ location. |
| 1246 | */ |
| 1247 | |
| 1248 | I915_WRITE(INSTPM, (1 << 5) | (1 << 21)); |
| 1249 | |
| 1250 | intel_modeset_init(dev); |
| 1251 | |
Jesse Barnes | 7a1fb5d | 2009-03-27 13:05:19 -0700 | [diff] [blame] | 1252 | drm_helper_initial_config(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1253 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1254 | return 0; |
| 1255 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1256 | destroy_ringbuffer: |
| 1257 | i915_gem_cleanup_ringbuffer(dev); |
| 1258 | out: |
| 1259 | return ret; |
| 1260 | } |
| 1261 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1262 | int i915_master_create(struct drm_device *dev, struct drm_master *master) |
| 1263 | { |
| 1264 | struct drm_i915_master_private *master_priv; |
| 1265 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1266 | master_priv = kzalloc(sizeof(*master_priv), GFP_KERNEL); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1267 | if (!master_priv) |
| 1268 | return -ENOMEM; |
| 1269 | |
| 1270 | master->driver_priv = master_priv; |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
| 1274 | void i915_master_destroy(struct drm_device *dev, struct drm_master *master) |
| 1275 | { |
| 1276 | struct drm_i915_master_private *master_priv = master->driver_priv; |
| 1277 | |
| 1278 | if (!master_priv) |
| 1279 | return; |
| 1280 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1281 | kfree(master_priv); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 1282 | |
| 1283 | master->driver_priv = NULL; |
| 1284 | } |
| 1285 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1286 | static void i915_get_mem_freq(struct drm_device *dev) |
| 1287 | { |
| 1288 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1289 | u32 tmp; |
| 1290 | |
| 1291 | if (!IS_IGD(dev)) |
| 1292 | return; |
| 1293 | |
| 1294 | tmp = I915_READ(CLKCFG); |
| 1295 | |
| 1296 | switch (tmp & CLKCFG_FSB_MASK) { |
| 1297 | case CLKCFG_FSB_533: |
| 1298 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 1299 | break; |
| 1300 | case CLKCFG_FSB_800: |
| 1301 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 1302 | break; |
| 1303 | case CLKCFG_FSB_667: |
| 1304 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 1305 | break; |
| 1306 | case CLKCFG_FSB_400: |
| 1307 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | switch (tmp & CLKCFG_MEM_MASK) { |
| 1312 | case CLKCFG_MEM_533: |
| 1313 | dev_priv->mem_freq = 533; |
| 1314 | break; |
| 1315 | case CLKCFG_MEM_667: |
| 1316 | dev_priv->mem_freq = 667; |
| 1317 | break; |
| 1318 | case CLKCFG_MEM_800: |
| 1319 | dev_priv->mem_freq = 800; |
| 1320 | break; |
| 1321 | } |
| 1322 | } |
| 1323 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1324 | /** |
| 1325 | * i915_driver_load - setup chip and create an initial config |
| 1326 | * @dev: DRM device |
| 1327 | * @flags: startup flags |
| 1328 | * |
| 1329 | * The driver load routine has to do several things: |
| 1330 | * - drive output discovery via intel_modeset_init() |
| 1331 | * - initialize the memory manager |
| 1332 | * - allocate initial config memory |
| 1333 | * - setup the DRM framebuffer with the allocated memory |
| 1334 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1335 | int i915_driver_load(struct drm_device *dev, unsigned long flags) |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1336 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1337 | struct drm_i915_private *dev_priv = dev->dev_private; |
Benjamin Herrenschmidt | d883f7f | 2009-02-02 16:55:45 +1100 | [diff] [blame] | 1338 | resource_size_t base, size; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1339 | int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1340 | uint32_t agp_size, prealloc_size, prealloc_start; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1341 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1342 | /* i915 has 4 more counters */ |
| 1343 | dev->counters += 4; |
| 1344 | dev->types[6] = _DRM_STAT_IRQ; |
| 1345 | dev->types[7] = _DRM_STAT_PRIMARY; |
| 1346 | dev->types[8] = _DRM_STAT_SECONDARY; |
| 1347 | dev->types[9] = _DRM_STAT_DMA; |
| 1348 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1349 | dev_priv = kzalloc(sizeof(drm_i915_private_t), GFP_KERNEL); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1350 | if (dev_priv == NULL) |
| 1351 | return -ENOMEM; |
| 1352 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1353 | dev->dev_private = (void *)dev_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1354 | dev_priv->dev = dev; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1355 | |
| 1356 | /* Add register map (needed for suspend/resume) */ |
| 1357 | base = drm_get_resource_start(dev, mmio_bar); |
| 1358 | size = drm_get_resource_len(dev, mmio_bar); |
| 1359 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1360 | if (i915_get_bridge_dev(dev)) { |
| 1361 | ret = -EIO; |
| 1362 | goto free_priv; |
| 1363 | } |
| 1364 | |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 1365 | dev_priv->regs = ioremap(base, size); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1366 | if (!dev_priv->regs) { |
| 1367 | DRM_ERROR("failed to map registers\n"); |
| 1368 | ret = -EIO; |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1369 | goto put_bridge; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1370 | } |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1371 | |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 1372 | dev_priv->mm.gtt_mapping = |
| 1373 | io_mapping_create_wc(dev->agp->base, |
| 1374 | dev->agp->agp_info.aper_size * 1024*1024); |
Venkatesh Pallipadi | 6644107 | 2009-02-24 17:35:11 -0800 | [diff] [blame] | 1375 | if (dev_priv->mm.gtt_mapping == NULL) { |
| 1376 | ret = -EIO; |
| 1377 | goto out_rmmap; |
| 1378 | } |
| 1379 | |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 1380 | /* Set up a WC MTRR for non-PAT systems. This is more common than |
| 1381 | * one would think, because the kernel disables PAT on first |
| 1382 | * generation Core chips because WC PAT gets overridden by a UC |
| 1383 | * MTRR if present. Even if a UC MTRR isn't present. |
| 1384 | */ |
| 1385 | dev_priv->mm.gtt_mtrr = mtrr_add(dev->agp->base, |
| 1386 | dev->agp->agp_info.aper_size * |
| 1387 | 1024 * 1024, |
| 1388 | MTRR_TYPE_WRCOMB, 1); |
| 1389 | if (dev_priv->mm.gtt_mtrr < 0) { |
Eric Anholt | 040aefa | 2009-03-10 12:31:12 -0700 | [diff] [blame] | 1390 | DRM_INFO("MTRR allocation failed. Graphics " |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 1391 | "performance may suffer.\n"); |
| 1392 | } |
| 1393 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1394 | ret = i915_probe_agp(dev, &agp_size, &prealloc_size, &prealloc_start); |
Eric Anholt | 2a34f5e6 | 2009-07-02 09:30:50 -0700 | [diff] [blame] | 1395 | if (ret) |
| 1396 | goto out_iomapfree; |
| 1397 | |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1398 | dev_priv->wq = create_workqueue("i915"); |
| 1399 | if (dev_priv->wq == NULL) { |
| 1400 | DRM_ERROR("Failed to create our workqueue.\n"); |
| 1401 | ret = -ENOMEM; |
| 1402 | goto out_iomapfree; |
| 1403 | } |
| 1404 | |
Dave Airlie | ac5c4e7 | 2008-12-19 15:38:34 +1000 | [diff] [blame] | 1405 | /* enable GEM by default */ |
| 1406 | dev_priv->has_gem = 1; |
Dave Airlie | ac5c4e7 | 2008-12-19 15:38:34 +1000 | [diff] [blame] | 1407 | |
Eric Anholt | 2a34f5e6 | 2009-07-02 09:30:50 -0700 | [diff] [blame] | 1408 | if (prealloc_size > agp_size * 3 / 4) { |
| 1409 | DRM_ERROR("Detected broken video BIOS with %d/%dkB of video " |
| 1410 | "memory stolen.\n", |
| 1411 | prealloc_size / 1024, agp_size / 1024); |
| 1412 | DRM_ERROR("Disabling GEM. (try reducing stolen memory or " |
| 1413 | "updating the BIOS to fix).\n"); |
| 1414 | dev_priv->has_gem = 0; |
| 1415 | } |
| 1416 | |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 1417 | dev->driver->get_vblank_counter = i915_get_vblank_counter; |
Jesse Barnes | 42c2798 | 2009-05-05 13:13:16 -0700 | [diff] [blame] | 1418 | dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ |
Zhenyu Wang | 036a4a7 | 2009-06-08 14:40:19 +0800 | [diff] [blame] | 1419 | if (IS_G4X(dev) || IS_IGDNG(dev)) { |
Jesse Barnes | 42c2798 | 2009-05-05 13:13:16 -0700 | [diff] [blame] | 1420 | dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 1421 | dev->driver->get_vblank_counter = gm45_get_vblank_counter; |
Jesse Barnes | 42c2798 | 2009-05-05 13:13:16 -0700 | [diff] [blame] | 1422 | } |
Jesse Barnes | 9880b7a | 2009-02-06 10:22:41 -0800 | [diff] [blame] | 1423 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1424 | i915_gem_load(dev); |
| 1425 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 1426 | /* Init HWS */ |
| 1427 | if (!I915_NEED_GFX_HWS(dev)) { |
| 1428 | ret = i915_init_phys_hws(dev); |
| 1429 | if (ret != 0) |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1430 | goto out_workqueue_free; |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 1431 | } |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1432 | |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 1433 | i915_get_mem_freq(dev); |
| 1434 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1435 | /* On the 945G/GM, the chipset reports the MSI capability on the |
| 1436 | * integrated graphics even though the support isn't actually there |
| 1437 | * according to the published specs. It doesn't appear to function |
| 1438 | * correctly in testing on 945G. |
| 1439 | * This may be a side effect of MSI having been made available for PEG |
| 1440 | * and the registers being closely associated. |
Keith Packard | d1ed629 | 2008-10-17 00:44:42 -0700 | [diff] [blame] | 1441 | * |
| 1442 | * According to chipset errata, on the 965GM, MSI interrupts may |
Keith Packard | b60678a | 2008-12-08 11:12:28 -0800 | [diff] [blame] | 1443 | * be lost or delayed, but we use them anyways to avoid |
| 1444 | * stuck interrupts on some machines. |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1445 | */ |
Keith Packard | b60678a | 2008-12-08 11:12:28 -0800 | [diff] [blame] | 1446 | if (!IS_I945G(dev) && !IS_I945GM(dev)) |
Eric Anholt | d3e74d0 | 2008-11-03 14:46:17 -0800 | [diff] [blame] | 1447 | pci_enable_msi(dev->pdev); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1448 | |
| 1449 | spin_lock_init(&dev_priv->user_irq_lock); |
Jesse Barnes | 63eeaf3 | 2009-06-18 16:56:52 -0700 | [diff] [blame] | 1450 | spin_lock_init(&dev_priv->error_lock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1451 | dev_priv->user_irq_refcount = 0; |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1452 | |
Keith Packard | 5244021 | 2008-11-18 09:30:25 -0800 | [diff] [blame] | 1453 | ret = drm_vblank_init(dev, I915_NUM_PIPE); |
| 1454 | |
| 1455 | if (ret) { |
| 1456 | (void) i915_driver_unload(dev); |
| 1457 | return ret; |
| 1458 | } |
| 1459 | |
Ben Gamari | 11ed50e | 2009-09-14 17:48:45 -0400 | [diff] [blame] | 1460 | /* Start out suspended */ |
| 1461 | dev_priv->mm.suspended = 1; |
| 1462 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1463 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 1464 | ret = i915_load_modeset_init(dev, prealloc_start, |
| 1465 | prealloc_size, agp_size); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1466 | if (ret < 0) { |
| 1467 | DRM_ERROR("failed to init modeset\n"); |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1468 | goto out_workqueue_free; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1472 | /* Must be done after probing outputs */ |
Zhenyu Wang | e170b03 | 2009-06-05 15:38:40 +0800 | [diff] [blame] | 1473 | /* FIXME: verify on IGDNG */ |
| 1474 | if (!IS_IGDNG(dev)) |
| 1475 | intel_opregion_init(dev, 0); |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1476 | |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1477 | setup_timer(&dev_priv->hangcheck_timer, i915_hangcheck_elapsed, |
| 1478 | (unsigned long) dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1479 | return 0; |
| 1480 | |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1481 | out_workqueue_free: |
| 1482 | destroy_workqueue(dev_priv->wq); |
Venkatesh Pallipadi | 6644107 | 2009-02-24 17:35:11 -0800 | [diff] [blame] | 1483 | out_iomapfree: |
| 1484 | io_mapping_free(dev_priv->mm.gtt_mapping); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1485 | out_rmmap: |
| 1486 | iounmap(dev_priv->regs); |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1487 | put_bridge: |
| 1488 | pci_dev_put(dev_priv->bridge_dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1489 | free_priv: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1490 | kfree(dev_priv); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1491 | return ret; |
| 1492 | } |
| 1493 | |
| 1494 | int i915_driver_unload(struct drm_device *dev) |
| 1495 | { |
| 1496 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1497 | |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1498 | destroy_workqueue(dev_priv->wq); |
Ben Gamari | f65d942 | 2009-09-14 17:48:44 -0400 | [diff] [blame] | 1499 | del_timer_sync(&dev_priv->hangcheck_timer); |
Eric Anholt | 9c9fe1f | 2009-08-03 16:09:16 -0700 | [diff] [blame] | 1500 | |
Eric Anholt | ab657db1 | 2009-01-23 12:57:47 -0800 | [diff] [blame] | 1501 | io_mapping_free(dev_priv->mm.gtt_mapping); |
| 1502 | if (dev_priv->mm.gtt_mtrr >= 0) { |
| 1503 | mtrr_del(dev_priv->mm.gtt_mtrr, dev->agp->base, |
| 1504 | dev->agp->agp_info.aper_size * 1024 * 1024); |
| 1505 | dev_priv->mm.gtt_mtrr = -1; |
| 1506 | } |
| 1507 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1508 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1509 | drm_irq_uninstall(dev); |
| 1510 | } |
| 1511 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 1512 | if (dev->pdev->msi_enabled) |
| 1513 | pci_disable_msi(dev->pdev); |
| 1514 | |
Eric Anholt | 3043c60 | 2008-10-02 12:24:47 -0700 | [diff] [blame] | 1515 | if (dev_priv->regs != NULL) |
| 1516 | iounmap(dev_priv->regs); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1517 | |
Zhenyu Wang | e170b03 | 2009-06-05 15:38:40 +0800 | [diff] [blame] | 1518 | if (!IS_IGDNG(dev)) |
| 1519 | intel_opregion_free(dev, 0); |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1520 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1521 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 1522 | intel_modeset_cleanup(dev); |
| 1523 | |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 1524 | i915_gem_free_all_phys_object(dev); |
| 1525 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1526 | mutex_lock(&dev->struct_mutex); |
| 1527 | i915_gem_cleanup_ringbuffer(dev); |
| 1528 | mutex_unlock(&dev->struct_mutex); |
| 1529 | drm_mm_takedown(&dev_priv->vram); |
| 1530 | i915_gem_lastclose(dev); |
| 1531 | } |
| 1532 | |
Dave Airlie | ec2a4c3 | 2009-08-04 11:43:41 +1000 | [diff] [blame] | 1533 | pci_dev_put(dev_priv->bridge_dev); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1534 | kfree(dev->dev_private); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1535 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1536 | return 0; |
| 1537 | } |
| 1538 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1539 | int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv) |
| 1540 | { |
| 1541 | struct drm_i915_file_private *i915_file_priv; |
| 1542 | |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1543 | DRM_DEBUG_DRIVER("\n"); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1544 | i915_file_priv = (struct drm_i915_file_private *) |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1545 | kmalloc(sizeof(*i915_file_priv), GFP_KERNEL); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1546 | |
| 1547 | if (!i915_file_priv) |
| 1548 | return -ENOMEM; |
| 1549 | |
| 1550 | file_priv->driver_priv = i915_file_priv; |
| 1551 | |
Eric Anholt | b962442 | 2009-06-03 07:27:35 +0000 | [diff] [blame] | 1552 | INIT_LIST_HEAD(&i915_file_priv->mm.request_list); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1553 | |
| 1554 | return 0; |
| 1555 | } |
| 1556 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1557 | /** |
| 1558 | * i915_driver_lastclose - clean up after all DRM clients have exited |
| 1559 | * @dev: DRM device |
| 1560 | * |
| 1561 | * Take care of cleaning up after all DRM clients have exited. In the |
| 1562 | * mode setting case, we want to restore the kernel's initial mode (just |
| 1563 | * in case the last client left us in a bad state). |
| 1564 | * |
| 1565 | * Additionally, in the non-mode setting case, we'll tear down the AGP |
| 1566 | * and DMA structures, since the kernel won't be using them, and clea |
| 1567 | * up any GEM state. |
| 1568 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1569 | void i915_driver_lastclose(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1571 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1572 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1573 | if (!dev_priv || drm_core_check_feature(dev, DRIVER_MODESET)) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1574 | drm_fb_helper_restore(); |
Dave Airlie | 144a75f | 2008-03-30 07:53:58 +1000 | [diff] [blame] | 1575 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1576 | } |
Dave Airlie | 144a75f | 2008-03-30 07:53:58 +1000 | [diff] [blame] | 1577 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1578 | i915_gem_lastclose(dev); |
| 1579 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1580 | if (dev_priv->agp_heap) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1581 | i915_mem_takedown(&(dev_priv->agp_heap)); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1582 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1583 | i915_dma_cleanup(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1586 | 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] | 1587 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1588 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | b962442 | 2009-06-03 07:27:35 +0000 | [diff] [blame] | 1589 | i915_gem_release(dev, file_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1590 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1591 | i915_mem_release(dev, file_priv, dev_priv->agp_heap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1594 | void i915_driver_postclose(struct drm_device *dev, struct drm_file *file_priv) |
| 1595 | { |
| 1596 | struct drm_i915_file_private *i915_file_priv = file_priv->driver_priv; |
| 1597 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1598 | kfree(i915_file_priv); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1601 | struct drm_ioctl_desc i915_ioctls[] = { |
| 1602 | DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1603 | DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH), |
| 1604 | DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH), |
| 1605 | DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH), |
| 1606 | DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH), |
| 1607 | DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH), |
| 1608 | DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH), |
| 1609 | DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1610 | DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH), |
| 1611 | DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH), |
| 1612 | DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1613 | DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH), |
| 1614 | DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP, i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ), |
| 1615 | DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE, i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ), |
| 1616 | DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH ), |
| 1617 | DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH), |
Matthias Hopf | 4b40893 | 2008-10-18 07:18:05 +1000 | [diff] [blame] | 1618 | DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Dave Airlie | 2bdf00b | 2008-10-07 13:40:10 +1000 | [diff] [blame] | 1619 | DRM_IOCTL_DEF(DRM_I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1620 | DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH), |
| 1621 | DRM_IOCTL_DEF(DRM_I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), |
| 1622 | DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), |
| 1623 | DRM_IOCTL_DEF(DRM_I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH), |
| 1624 | DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH), |
Dave Airlie | 2bdf00b | 2008-10-07 13:40:10 +1000 | [diff] [blame] | 1625 | DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1626 | DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1627 | DRM_IOCTL_DEF(DRM_I915_GEM_CREATE, i915_gem_create_ioctl, 0), |
| 1628 | DRM_IOCTL_DEF(DRM_I915_GEM_PREAD, i915_gem_pread_ioctl, 0), |
| 1629 | DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE, i915_gem_pwrite_ioctl, 0), |
| 1630 | DRM_IOCTL_DEF(DRM_I915_GEM_MMAP, i915_gem_mmap_ioctl, 0), |
Jesse Barnes | de151cf | 2008-11-12 10:03:55 -0800 | [diff] [blame] | 1631 | DRM_IOCTL_DEF(DRM_I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, 0), |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1632 | DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, 0), |
| 1633 | DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, 0), |
| 1634 | DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING, i915_gem_set_tiling, 0), |
| 1635 | DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING, i915_gem_get_tiling, 0), |
Eric Anholt | 5a125c3 | 2008-10-22 21:40:13 -0700 | [diff] [blame] | 1636 | DRM_IOCTL_DEF(DRM_I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, 0), |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 1637 | DRM_IOCTL_DEF(DRM_I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, 0), |
Chris Wilson | 3ef94da | 2009-09-14 16:50:29 +0100 | [diff] [blame] | 1638 | DRM_IOCTL_DEF(DRM_I915_GEM_MADVISE, i915_gem_madvise_ioctl, 0), |
Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 1639 | }; |
| 1640 | |
| 1641 | int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 1642 | |
| 1643 | /** |
| 1644 | * Determine if the device really is AGP or not. |
| 1645 | * |
| 1646 | * All Intel graphics chipsets are treated as AGP, even if they are really |
| 1647 | * PCI-e. |
| 1648 | * |
| 1649 | * \param dev The device to be tested. |
| 1650 | * |
| 1651 | * \returns |
| 1652 | * A value of 1 is always retured to indictate every i9x5 is AGP. |
| 1653 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 1654 | int i915_driver_device_is_agp(struct drm_device * dev) |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 1655 | { |
| 1656 | return 1; |
| 1657 | } |