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" |
| 31 | #include "i915_drm.h" |
| 32 | #include "i915_drv.h" |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* Really want an OS-independent resettable timer. Would like to have |
| 35 | * this loop run for (eg) 3 sec, but have the timer reset every time |
| 36 | * the head pointer changes, so that EBUSY only happens if the ring |
| 37 | * actually stalls for (eg) 3 seconds. |
| 38 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 39 | 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] | 40 | { |
| 41 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 42 | drm_i915_ring_buffer_t *ring = &(dev_priv->ring); |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 43 | u32 acthd_reg = IS_I965G(dev) ? ACTHD_I965 : ACTHD; |
| 44 | u32 last_acthd = I915_READ(acthd_reg); |
| 45 | u32 acthd; |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 46 | u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | int i; |
| 48 | |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 49 | for (i = 0; i < 100000; i++) { |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 50 | ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR; |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 51 | acthd = I915_READ(acthd_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | ring->space = ring->head - (ring->tail + 8); |
| 53 | if (ring->space < 0) |
| 54 | ring->space += ring->Size; |
| 55 | if (ring->space >= n) |
| 56 | return 0; |
| 57 | |
| 58 | dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
| 59 | |
| 60 | if (ring->head != last_head) |
| 61 | i = 0; |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 62 | if (acthd != last_acthd) |
| 63 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | last_head = ring->head; |
Keith Packard | d3a6d44 | 2008-07-30 12:21:20 -0700 | [diff] [blame] | 66 | last_acthd = acthd; |
| 67 | msleep_interruptible(10); |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 71 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 74 | /** |
| 75 | * Sets up the hardware status page for devices that need a physical address |
| 76 | * in the register. |
| 77 | */ |
| 78 | int i915_init_phys_hws(struct drm_device *dev) |
| 79 | { |
| 80 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 81 | /* Program Hardware Status Page */ |
| 82 | dev_priv->status_page_dmah = |
| 83 | drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff); |
| 84 | |
| 85 | if (!dev_priv->status_page_dmah) { |
| 86 | DRM_ERROR("Can not allocate hardware status page\n"); |
| 87 | return -ENOMEM; |
| 88 | } |
| 89 | dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr; |
| 90 | dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr; |
| 91 | |
| 92 | memset(dev_priv->hw_status_page, 0, PAGE_SIZE); |
| 93 | |
| 94 | I915_WRITE(HWS_PGA, dev_priv->dma_status_page); |
| 95 | DRM_DEBUG("Enabled hardware status page\n"); |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Frees the hardware status page, whether it's a physical address or a virtual |
| 101 | * address set up by the X Server. |
| 102 | */ |
| 103 | void i915_free_hws(struct drm_device *dev) |
| 104 | { |
| 105 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 106 | if (dev_priv->status_page_dmah) { |
| 107 | drm_pci_free(dev, dev_priv->status_page_dmah); |
| 108 | dev_priv->status_page_dmah = NULL; |
| 109 | } |
| 110 | |
| 111 | if (dev_priv->status_gfx_addr) { |
| 112 | dev_priv->status_gfx_addr = 0; |
| 113 | drm_core_ioremapfree(&dev_priv->hws_map, dev); |
| 114 | } |
| 115 | |
| 116 | /* Need to rewrite hardware status page */ |
| 117 | I915_WRITE(HWS_PGA, 0x1ffff000); |
| 118 | } |
| 119 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 120 | void i915_kernel_lost_context(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
| 122 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 123 | drm_i915_ring_buffer_t *ring = &(dev_priv->ring); |
| 124 | |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 125 | ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR; |
| 126 | ring->tail = I915_READ(PRB0_TAIL) & TAIL_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | ring->space = ring->head - (ring->tail + 8); |
| 128 | if (ring->space < 0) |
| 129 | ring->space += ring->Size; |
| 130 | |
| 131 | if (ring->head == ring->tail) |
| 132 | dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY; |
| 133 | } |
| 134 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 135 | static int i915_dma_cleanup(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 137 | drm_i915_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* Make sure interrupts are disabled here because the uninstall ioctl |
| 139 | * may not have been called from userspace and after dev_private |
| 140 | * is freed, it's too late. |
| 141 | */ |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 142 | if (dev->irq_enabled) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 143 | drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 145 | if (dev_priv->ring.virtual_start) { |
| 146 | drm_core_ioremapfree(&dev_priv->ring.map, dev); |
| 147 | dev_priv->ring.virtual_start = 0; |
| 148 | dev_priv->ring.map.handle = 0; |
| 149 | dev_priv->ring.map.size = 0; |
| 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 152 | /* Clear the HWS virtual address at teardown */ |
| 153 | if (I915_NEED_GFX_HWS(dev)) |
| 154 | i915_free_hws(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 159 | 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] | 160 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 161 | drm_i915_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Dave Airlie | da509d7 | 2007-05-26 05:04:51 +1000 | [diff] [blame] | 163 | dev_priv->sarea = drm_getsarea(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | if (!dev_priv->sarea) { |
| 165 | DRM_ERROR("can not find sarea!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | i915_dma_cleanup(dev); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 167 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | dev_priv->sarea_priv = (drm_i915_sarea_t *) |
| 171 | ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset); |
| 172 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 173 | if (init->ring_size != 0) { |
| 174 | if (dev_priv->ring.ring_obj != NULL) { |
| 175 | i915_dma_cleanup(dev); |
| 176 | DRM_ERROR("Client tried to initialize ringbuffer in " |
| 177 | "GEM mode\n"); |
| 178 | return -EINVAL; |
| 179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 181 | dev_priv->ring.Size = init->ring_size; |
| 182 | dev_priv->ring.tail_mask = dev_priv->ring.Size - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 184 | dev_priv->ring.map.offset = init->ring_start; |
| 185 | dev_priv->ring.map.size = init->ring_size; |
| 186 | dev_priv->ring.map.type = 0; |
| 187 | dev_priv->ring.map.flags = 0; |
| 188 | dev_priv->ring.map.mtrr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 190 | drm_core_ioremap(&dev_priv->ring.map, dev); |
| 191 | |
| 192 | if (dev_priv->ring.map.handle == NULL) { |
| 193 | i915_dma_cleanup(dev); |
| 194 | DRM_ERROR("can not ioremap virtual address for" |
| 195 | " ring buffer\n"); |
| 196 | return -ENOMEM; |
| 197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | dev_priv->ring.virtual_start = dev_priv->ring.map.handle; |
| 201 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | a6b54f3 | 2006-10-24 23:37:43 +1000 | [diff] [blame] | 202 | dev_priv->cpp = init->cpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | dev_priv->back_offset = init->back_offset; |
| 204 | dev_priv->front_offset = init->front_offset; |
| 205 | dev_priv->current_page = 0; |
| 206 | dev_priv->sarea_priv->pf_current_page = dev_priv->current_page; |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* Allow hardware batchbuffers unless told otherwise. |
| 209 | */ |
| 210 | dev_priv->allow_batchbuffer = 1; |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 215 | static int i915_dma_resume(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
| 217 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
| 218 | |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 219 | DRM_DEBUG("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | if (!dev_priv->sarea) { |
| 222 | DRM_ERROR("can not find sarea!\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 223 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | if (dev_priv->ring.map.handle == NULL) { |
| 227 | DRM_ERROR("can not ioremap virtual address for" |
| 228 | " ring buffer\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 229 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* Program Hardware Status Page */ |
| 233 | if (!dev_priv->hw_status_page) { |
| 234 | DRM_ERROR("Can not find hardware status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 235 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page); |
| 238 | |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 239 | if (dev_priv->status_gfx_addr != 0) |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 240 | I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 241 | else |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 242 | I915_WRITE(HWS_PGA, dev_priv->dma_status_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | DRM_DEBUG("Enabled hardware status page\n"); |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 248 | static int i915_dma_init(struct drm_device *dev, void *data, |
| 249 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 251 | drm_i915_init_t *init = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | int retcode = 0; |
| 253 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 254 | switch (init->func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | case I915_INIT_DMA: |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 256 | retcode = i915_initialize(dev, init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | break; |
| 258 | case I915_CLEANUP_DMA: |
| 259 | retcode = i915_dma_cleanup(dev); |
| 260 | break; |
| 261 | case I915_RESUME_DMA: |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 262 | retcode = i915_dma_resume(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | break; |
| 264 | default: |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 265 | retcode = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | break; |
| 267 | } |
| 268 | |
| 269 | return retcode; |
| 270 | } |
| 271 | |
| 272 | /* Implement basically the same security restrictions as hardware does |
| 273 | * for MI_BATCH_NON_SECURE. These can be made stricter at any time. |
| 274 | * |
| 275 | * Most of the calculations below involve calculating the size of a |
| 276 | * particular instruction. It's important to get the size right as |
| 277 | * that tells us where the next instruction to check is. Any illegal |
| 278 | * instruction detected will be given a size of zero, which is a |
| 279 | * signal to abort the rest of the buffer. |
| 280 | */ |
| 281 | static int do_validate_cmd(int cmd) |
| 282 | { |
| 283 | switch (((cmd >> 29) & 0x7)) { |
| 284 | case 0x0: |
| 285 | switch ((cmd >> 23) & 0x3f) { |
| 286 | case 0x0: |
| 287 | return 1; /* MI_NOOP */ |
| 288 | case 0x4: |
| 289 | return 1; /* MI_FLUSH */ |
| 290 | default: |
| 291 | return 0; /* disallow everything else */ |
| 292 | } |
| 293 | break; |
| 294 | case 0x1: |
| 295 | return 0; /* reserved */ |
| 296 | case 0x2: |
| 297 | return (cmd & 0xff) + 2; /* 2d commands */ |
| 298 | case 0x3: |
| 299 | if (((cmd >> 24) & 0x1f) <= 0x18) |
| 300 | return 1; |
| 301 | |
| 302 | switch ((cmd >> 24) & 0x1f) { |
| 303 | case 0x1c: |
| 304 | return 1; |
| 305 | case 0x1d: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 306 | switch ((cmd >> 16) & 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | case 0x3: |
| 308 | return (cmd & 0x1f) + 2; |
| 309 | case 0x4: |
| 310 | return (cmd & 0xf) + 2; |
| 311 | default: |
| 312 | return (cmd & 0xffff) + 2; |
| 313 | } |
| 314 | case 0x1e: |
| 315 | if (cmd & (1 << 23)) |
| 316 | return (cmd & 0xffff) + 1; |
| 317 | else |
| 318 | return 1; |
| 319 | case 0x1f: |
| 320 | if ((cmd & (1 << 23)) == 0) /* inline vertices */ |
| 321 | return (cmd & 0x1ffff) + 2; |
| 322 | else if (cmd & (1 << 17)) /* indirect random */ |
| 323 | if ((cmd & 0xffff) == 0) |
| 324 | return 0; /* unknown length, too hard */ |
| 325 | else |
| 326 | return (((cmd & 0xffff) + 1) / 2) + 1; |
| 327 | else |
| 328 | return 2; /* indirect sequential */ |
| 329 | default: |
| 330 | return 0; |
| 331 | } |
| 332 | default: |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int validate_cmd(int cmd) |
| 340 | { |
| 341 | int ret = do_validate_cmd(cmd); |
| 342 | |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 343 | /* printk("validate_cmd( %x ): %d\n", cmd, ret); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | return ret; |
| 346 | } |
| 347 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 348 | static int i915_emit_cmds(struct drm_device * dev, int __user * buffer, int dwords) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 351 | int i; |
| 352 | RING_LOCALS; |
| 353 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 354 | if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 355 | return -EINVAL; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 356 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 357 | BEGIN_LP_RING((dwords+1)&~1); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | for (i = 0; i < dwords;) { |
| 360 | int cmd, sz; |
| 361 | |
| 362 | if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 363 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 366 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | OUT_RING(cmd); |
| 369 | |
| 370 | while (++i, --sz) { |
| 371 | if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], |
| 372 | sizeof(cmd))) { |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 373 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | OUT_RING(cmd); |
| 376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 379 | if (dwords & 1) |
| 380 | OUT_RING(0); |
| 381 | |
| 382 | ADVANCE_LP_RING(); |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 387 | int |
| 388 | i915_emit_box(struct drm_device *dev, |
| 389 | struct drm_clip_rect __user *boxes, |
| 390 | int i, int DR1, int DR4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
| 392 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 393 | struct drm_clip_rect box; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | RING_LOCALS; |
| 395 | |
| 396 | if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) { |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 397 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) { |
| 401 | DRM_ERROR("Bad box %d,%d..%d,%d\n", |
| 402 | box.x1, box.y1, box.x2, box.y2); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 403 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 406 | if (IS_I965G(dev)) { |
| 407 | BEGIN_LP_RING(4); |
| 408 | OUT_RING(GFX_OP_DRAWRECT_INFO_I965); |
| 409 | OUT_RING((box.x1 & 0xffff) | (box.y1 << 16)); |
Andrew Morton | 78eca43 | 2006-08-16 09:15:51 +1000 | [diff] [blame] | 410 | OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16)); |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 411 | OUT_RING(DR4); |
| 412 | ADVANCE_LP_RING(); |
| 413 | } else { |
| 414 | BEGIN_LP_RING(6); |
| 415 | OUT_RING(GFX_OP_DRAWRECT_INFO); |
| 416 | OUT_RING(DR1); |
| 417 | OUT_RING((box.x1 & 0xffff) | (box.y1 << 16)); |
| 418 | OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16)); |
| 419 | OUT_RING(DR4); |
| 420 | OUT_RING(0); |
| 421 | ADVANCE_LP_RING(); |
| 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 427 | /* XXX: Emitting the counter should really be moved to part of the IRQ |
| 428 | * emit. For now, do it in both places: |
| 429 | */ |
| 430 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 431 | static void i915_emit_breadcrumb(struct drm_device *dev) |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 432 | { |
| 433 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 434 | RING_LOCALS; |
| 435 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 436 | dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter; |
Alan Hourihane | c29b669 | 2006-08-12 16:29:24 +1000 | [diff] [blame] | 437 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 438 | if (dev_priv->counter > 0x7FFFFFFFUL) |
| 439 | dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 440 | |
| 441 | BEGIN_LP_RING(4); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 442 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 443 | OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 444 | OUT_RING(dev_priv->counter); |
| 445 | OUT_RING(0); |
| 446 | ADVANCE_LP_RING(); |
| 447 | } |
| 448 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 449 | static int i915_dispatch_cmdbuffer(struct drm_device * dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | drm_i915_cmdbuffer_t * cmd) |
| 451 | { |
| 452 | int nbox = cmd->num_cliprects; |
| 453 | int i = 0, count, ret; |
| 454 | |
| 455 | if (cmd->sz & 0x3) { |
| 456 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 457 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | i915_kernel_lost_context(dev); |
| 461 | |
| 462 | count = nbox ? nbox : 1; |
| 463 | |
| 464 | for (i = 0; i < count; i++) { |
| 465 | if (i < nbox) { |
| 466 | ret = i915_emit_box(dev, cmd->cliprects, i, |
| 467 | cmd->DR1, cmd->DR4); |
| 468 | if (ret) |
| 469 | return ret; |
| 470 | } |
| 471 | |
| 472 | ret = i915_emit_cmds(dev, (int __user *)cmd->buf, cmd->sz / 4); |
| 473 | if (ret) |
| 474 | return ret; |
| 475 | } |
| 476 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 477 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 481 | static int i915_dispatch_batchbuffer(struct drm_device * dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | drm_i915_batchbuffer_t * batch) |
| 483 | { |
| 484 | drm_i915_private_t *dev_priv = dev->dev_private; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 485 | struct drm_clip_rect __user *boxes = batch->cliprects; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | int nbox = batch->num_cliprects; |
| 487 | int i = 0, count; |
| 488 | RING_LOCALS; |
| 489 | |
| 490 | if ((batch->start | batch->used) & 0x7) { |
| 491 | DRM_ERROR("alignment"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 492 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | i915_kernel_lost_context(dev); |
| 496 | |
| 497 | count = nbox ? nbox : 1; |
| 498 | |
| 499 | for (i = 0; i < count; i++) { |
| 500 | if (i < nbox) { |
| 501 | int ret = i915_emit_box(dev, boxes, i, |
| 502 | batch->DR1, batch->DR4); |
| 503 | if (ret) |
| 504 | return ret; |
| 505 | } |
| 506 | |
Keith Packard | 0790d5e | 2008-07-30 12:28:47 -0700 | [diff] [blame] | 507 | if (!IS_I830(dev) && !IS_845G(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | BEGIN_LP_RING(2); |
Dave Airlie | 21f1628 | 2007-08-07 09:09:51 +1000 | [diff] [blame] | 509 | if (IS_I965G(dev)) { |
| 510 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965); |
| 511 | OUT_RING(batch->start); |
| 512 | } else { |
| 513 | OUT_RING(MI_BATCH_BUFFER_START | (2 << 6)); |
| 514 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | ADVANCE_LP_RING(); |
| 517 | } else { |
| 518 | BEGIN_LP_RING(4); |
| 519 | OUT_RING(MI_BATCH_BUFFER); |
| 520 | OUT_RING(batch->start | MI_BATCH_NON_SECURE); |
| 521 | OUT_RING(batch->start + batch->used - 4); |
| 522 | OUT_RING(0); |
| 523 | ADVANCE_LP_RING(); |
| 524 | } |
| 525 | } |
| 526 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 527 | i915_emit_breadcrumb(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 532 | static int i915_dispatch_flip(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { |
| 534 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 535 | RING_LOCALS; |
| 536 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 537 | DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n", |
Harvey Harrison | 80a914d | 2008-10-15 22:01:25 -0700 | [diff] [blame] | 538 | __func__, |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 539 | dev_priv->current_page, |
| 540 | dev_priv->sarea_priv->pf_current_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 542 | i915_kernel_lost_context(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 544 | BEGIN_LP_RING(2); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 545 | OUT_RING(MI_FLUSH | MI_READ_FLUSH); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 546 | OUT_RING(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | ADVANCE_LP_RING(); |
| 548 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 549 | BEGIN_LP_RING(6); |
| 550 | OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP); |
| 551 | OUT_RING(0); |
| 552 | if (dev_priv->current_page == 0) { |
| 553 | OUT_RING(dev_priv->back_offset); |
| 554 | dev_priv->current_page = 1; |
| 555 | } else { |
| 556 | OUT_RING(dev_priv->front_offset); |
| 557 | dev_priv->current_page = 0; |
| 558 | } |
| 559 | OUT_RING(0); |
| 560 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 561 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 562 | BEGIN_LP_RING(2); |
| 563 | OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP); |
| 564 | OUT_RING(0); |
| 565 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 566 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 567 | dev_priv->sarea_priv->last_enqueue = dev_priv->counter++; |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 568 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 569 | BEGIN_LP_RING(4); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 570 | OUT_RING(MI_STORE_DWORD_INDEX); |
| 571 | OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 572 | OUT_RING(dev_priv->counter); |
| 573 | OUT_RING(0); |
| 574 | ADVANCE_LP_RING(); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 575 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 576 | dev_priv->sarea_priv->pf_current_page = dev_priv->current_page; |
| 577 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 580 | static int i915_quiescent(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
| 582 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 583 | |
| 584 | i915_kernel_lost_context(dev); |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 585 | return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 588 | static int i915_flush_ioctl(struct drm_device *dev, void *data, |
| 589 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 591 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 593 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 594 | |
| 595 | mutex_lock(&dev->struct_mutex); |
| 596 | ret = i915_quiescent(dev); |
| 597 | mutex_unlock(&dev->struct_mutex); |
| 598 | |
| 599 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 602 | static int i915_batchbuffer(struct drm_device *dev, void *data, |
| 603 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 606 | u32 *hw_status = dev_priv->hw_status_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
| 608 | dev_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 609 | drm_i915_batchbuffer_t *batch = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | int ret; |
| 611 | |
| 612 | if (!dev_priv->allow_batchbuffer) { |
| 613 | DRM_ERROR("Batchbuffer ioctl disabled\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 614 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | DRM_DEBUG("i915 batchbuffer, start %x used %d cliprects %d\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 618 | batch->start, batch->used, batch->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 620 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 622 | if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects, |
| 623 | batch->num_cliprects * |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 624 | sizeof(struct drm_clip_rect))) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 625 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 627 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 628 | ret = i915_dispatch_batchbuffer(dev, batch); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 629 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 631 | sarea_priv->last_dispatch = (int)hw_status[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | return ret; |
| 633 | } |
| 634 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 635 | static int i915_cmdbuffer(struct drm_device *dev, void *data, |
| 636 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 639 | u32 *hw_status = dev_priv->hw_status_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *) |
| 641 | dev_priv->sarea_priv; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 642 | drm_i915_cmdbuffer_t *cmdbuf = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | int ret; |
| 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 646 | cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 648 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 650 | if (cmdbuf->num_cliprects && |
| 651 | DRM_VERIFYAREA_READ(cmdbuf->cliprects, |
| 652 | cmdbuf->num_cliprects * |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 653 | sizeof(struct drm_clip_rect))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | DRM_ERROR("Fault accessing cliprects\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 655 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 658 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 659 | ret = i915_dispatch_cmdbuffer(dev, cmdbuf); |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 660 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | if (ret) { |
| 662 | DRM_ERROR("i915_dispatch_cmdbuffer failed\n"); |
| 663 | return ret; |
| 664 | } |
| 665 | |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 666 | sarea_priv->last_dispatch = (int)hw_status[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | return 0; |
| 668 | } |
| 669 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 670 | static int i915_flip_bufs(struct drm_device *dev, void *data, |
| 671 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 673 | int ret; |
| 674 | |
Harvey Harrison | 80a914d | 2008-10-15 22:01:25 -0700 | [diff] [blame] | 675 | DRM_DEBUG("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 677 | RING_LOCK_TEST_WITH_RETURN(dev, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Eric Anholt | 546b097 | 2008-09-01 16:45:29 -0700 | [diff] [blame^] | 679 | mutex_lock(&dev->struct_mutex); |
| 680 | ret = i915_dispatch_flip(dev); |
| 681 | mutex_unlock(&dev->struct_mutex); |
| 682 | |
| 683 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 686 | static int i915_getparam(struct drm_device *dev, void *data, |
| 687 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 690 | drm_i915_getparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | int value; |
| 692 | |
| 693 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 694 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 695 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 698 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | case I915_PARAM_IRQ_ACTIVE: |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 700 | value = dev->pdev->irq ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | break; |
| 702 | case I915_PARAM_ALLOW_BATCHBUFFER: |
| 703 | value = dev_priv->allow_batchbuffer ? 1 : 0; |
| 704 | break; |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 705 | case I915_PARAM_LAST_DISPATCH: |
| 706 | value = READ_BREADCRUMB(dev_priv); |
| 707 | break; |
Kristian Høgsberg | ed4c9c4 | 2008-08-20 11:08:52 -0400 | [diff] [blame] | 708 | case I915_PARAM_CHIPSET_ID: |
| 709 | value = dev->pci_device; |
| 710 | break; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 711 | case I915_PARAM_HAS_GEM: |
| 712 | value = 1; |
| 713 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | default: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 715 | DRM_ERROR("Unknown parameter %d\n", param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 716 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 719 | if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | DRM_ERROR("DRM_COPY_TO_USER failed\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 721 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | return 0; |
| 725 | } |
| 726 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 727 | static int i915_setparam(struct drm_device *dev, void *data, |
| 728 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 731 | drm_i915_setparam_t *param = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
| 733 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 734 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 735 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 738 | switch (param->param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | case I915_SETPARAM_USE_MI_BATCHBUFFER_START: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | break; |
| 741 | case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 742 | dev_priv->tex_lru_log_granularity = param->value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | break; |
| 744 | case I915_SETPARAM_ALLOW_BATCHBUFFER: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 745 | dev_priv->allow_batchbuffer = param->value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | break; |
| 747 | default: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 748 | DRM_ERROR("unknown parameter %d\n", param->param); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 749 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 755 | static int i915_set_status_page(struct drm_device *dev, void *data, |
| 756 | struct drm_file *file_priv) |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 757 | { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 758 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 759 | drm_i915_hws_addr_t *hws = data; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 760 | |
Zhenyu Wang | b39d50e | 2008-02-19 20:59:09 +1000 | [diff] [blame] | 761 | if (!I915_NEED_GFX_HWS(dev)) |
| 762 | return -EINVAL; |
| 763 | |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 764 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 765 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 766 | return -EINVAL; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 767 | } |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 768 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 769 | printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws->addr); |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 770 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 771 | dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12); |
| 772 | |
Eric Anholt | 8b40958 | 2007-11-22 16:40:37 +1000 | [diff] [blame] | 773 | dev_priv->hws_map.offset = dev->agp->base + hws->addr; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 774 | dev_priv->hws_map.size = 4*1024; |
| 775 | dev_priv->hws_map.type = 0; |
| 776 | dev_priv->hws_map.flags = 0; |
| 777 | dev_priv->hws_map.mtrr = 0; |
| 778 | |
| 779 | drm_core_ioremap(&dev_priv->hws_map, dev); |
| 780 | if (dev_priv->hws_map.handle == NULL) { |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 781 | i915_dma_cleanup(dev); |
| 782 | dev_priv->status_gfx_addr = 0; |
| 783 | DRM_ERROR("can not ioremap virtual address for" |
| 784 | " G33 hw status page\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 785 | return -ENOMEM; |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 786 | } |
| 787 | dev_priv->hw_status_page = dev_priv->hws_map.handle; |
| 788 | |
| 789 | memset(dev_priv->hw_status_page, 0, PAGE_SIZE); |
Jesse Barnes | 585fb11 | 2008-07-29 11:54:06 -0700 | [diff] [blame] | 790 | I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); |
| 791 | DRM_DEBUG("load hws HWS_PGA with gfx mem 0x%x\n", |
Wang Zhenyu | dc7a931 | 2007-06-10 15:58:19 +1000 | [diff] [blame] | 792 | dev_priv->status_gfx_addr); |
| 793 | DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page); |
| 794 | return 0; |
| 795 | } |
| 796 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 797 | int i915_driver_load(struct drm_device *dev, unsigned long flags) |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 798 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 799 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 800 | unsigned long base, size; |
| 801 | int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1; |
| 802 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 803 | /* i915 has 4 more counters */ |
| 804 | dev->counters += 4; |
| 805 | dev->types[6] = _DRM_STAT_IRQ; |
| 806 | dev->types[7] = _DRM_STAT_PRIMARY; |
| 807 | dev->types[8] = _DRM_STAT_SECONDARY; |
| 808 | dev->types[9] = _DRM_STAT_DMA; |
| 809 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 810 | dev_priv = drm_alloc(sizeof(drm_i915_private_t), DRM_MEM_DRIVER); |
| 811 | if (dev_priv == NULL) |
| 812 | return -ENOMEM; |
| 813 | |
| 814 | memset(dev_priv, 0, sizeof(drm_i915_private_t)); |
| 815 | |
| 816 | dev->dev_private = (void *)dev_priv; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 817 | dev_priv->dev = dev; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 818 | |
| 819 | /* Add register map (needed for suspend/resume) */ |
| 820 | base = drm_get_resource_start(dev, mmio_bar); |
| 821 | size = drm_get_resource_len(dev, mmio_bar); |
| 822 | |
Dave Airlie | e3236a1 | 2007-12-17 09:41:56 +1000 | [diff] [blame] | 823 | ret = drm_addmap(dev, base, size, _DRM_REGISTERS, |
| 824 | _DRM_KERNEL | _DRM_DRIVER, |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 825 | &dev_priv->mmio_map); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 826 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 827 | i915_gem_load(dev); |
| 828 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 829 | /* Init HWS */ |
| 830 | if (!I915_NEED_GFX_HWS(dev)) { |
| 831 | ret = i915_init_phys_hws(dev); |
| 832 | if (ret != 0) |
| 833 | return ret; |
| 834 | } |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 835 | |
| 836 | /* On the 945G/GM, the chipset reports the MSI capability on the |
| 837 | * integrated graphics even though the support isn't actually there |
| 838 | * according to the published specs. It doesn't appear to function |
| 839 | * correctly in testing on 945G. |
| 840 | * This may be a side effect of MSI having been made available for PEG |
| 841 | * and the registers being closely associated. |
| 842 | */ |
| 843 | if (!IS_I945G(dev) && !IS_I945GM(dev)) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 844 | if (pci_enable_msi(dev->pdev)) |
| 845 | DRM_ERROR("failed to enable MSI\n"); |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 846 | |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 847 | intel_opregion_init(dev); |
| 848 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 849 | spin_lock_init(&dev_priv->user_irq_lock); |
| 850 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 851 | return ret; |
| 852 | } |
| 853 | |
| 854 | int i915_driver_unload(struct drm_device *dev) |
| 855 | { |
| 856 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 857 | |
Eric Anholt | ed4cb41 | 2008-07-29 12:10:39 -0700 | [diff] [blame] | 858 | if (dev->pdev->msi_enabled) |
| 859 | pci_disable_msi(dev->pdev); |
| 860 | |
Keith Packard | 398c9cb | 2008-07-30 13:03:43 -0700 | [diff] [blame] | 861 | i915_free_hws(dev); |
| 862 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 863 | if (dev_priv->mmio_map) |
| 864 | drm_rmmap(dev, dev_priv->mmio_map); |
| 865 | |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 866 | intel_opregion_free(dev); |
| 867 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 868 | drm_free(dev->dev_private, sizeof(drm_i915_private_t), |
| 869 | DRM_MEM_DRIVER); |
| 870 | |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 874 | int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv) |
| 875 | { |
| 876 | struct drm_i915_file_private *i915_file_priv; |
| 877 | |
| 878 | DRM_DEBUG("\n"); |
| 879 | i915_file_priv = (struct drm_i915_file_private *) |
| 880 | drm_alloc(sizeof(*i915_file_priv), DRM_MEM_FILES); |
| 881 | |
| 882 | if (!i915_file_priv) |
| 883 | return -ENOMEM; |
| 884 | |
| 885 | file_priv->driver_priv = i915_file_priv; |
| 886 | |
| 887 | i915_file_priv->mm.last_gem_seqno = 0; |
| 888 | i915_file_priv->mm.last_gem_throttle_seqno = 0; |
| 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 893 | void i915_driver_lastclose(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 895 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 896 | |
Dave Airlie | 144a75f | 2008-03-30 07:53:58 +1000 | [diff] [blame] | 897 | if (!dev_priv) |
| 898 | return; |
| 899 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 900 | i915_gem_lastclose(dev); |
| 901 | |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 902 | if (dev_priv->agp_heap) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 903 | i915_mem_takedown(&(dev_priv->agp_heap)); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 904 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 905 | i915_dma_cleanup(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 908 | 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] | 909 | { |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 910 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 911 | i915_mem_release(dev, file_priv, dev_priv->agp_heap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 914 | void i915_driver_postclose(struct drm_device *dev, struct drm_file *file_priv) |
| 915 | { |
| 916 | struct drm_i915_file_private *i915_file_priv = file_priv->driver_priv; |
| 917 | |
| 918 | drm_free(i915_file_priv, sizeof(*i915_file_priv), DRM_MEM_FILES); |
| 919 | } |
| 920 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 921 | struct drm_ioctl_desc i915_ioctls[] = { |
| 922 | DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 923 | DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH), |
| 924 | DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH), |
| 925 | DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH), |
| 926 | DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH), |
| 927 | DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH), |
| 928 | DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH), |
| 929 | DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 930 | DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH), |
| 931 | DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH), |
| 932 | DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 933 | DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH), |
| 934 | DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP, i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ), |
| 935 | DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE, i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ), |
| 936 | DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH ), |
| 937 | DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH), |
| 938 | DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH), |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 939 | DRM_IOCTL_DEF(DRM_I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH), |
| 940 | DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH), |
| 941 | DRM_IOCTL_DEF(DRM_I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), |
| 942 | DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), |
| 943 | DRM_IOCTL_DEF(DRM_I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH), |
| 944 | DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH), |
| 945 | DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH), |
| 946 | DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH), |
| 947 | DRM_IOCTL_DEF(DRM_I915_GEM_CREATE, i915_gem_create_ioctl, 0), |
| 948 | DRM_IOCTL_DEF(DRM_I915_GEM_PREAD, i915_gem_pread_ioctl, 0), |
| 949 | DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE, i915_gem_pwrite_ioctl, 0), |
| 950 | DRM_IOCTL_DEF(DRM_I915_GEM_MMAP, i915_gem_mmap_ioctl, 0), |
| 951 | DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, 0), |
| 952 | DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, 0), |
| 953 | DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING, i915_gem_set_tiling, 0), |
| 954 | DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING, i915_gem_get_tiling, 0), |
Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 955 | }; |
| 956 | |
| 957 | int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 958 | |
| 959 | /** |
| 960 | * Determine if the device really is AGP or not. |
| 961 | * |
| 962 | * All Intel graphics chipsets are treated as AGP, even if they are really |
| 963 | * PCI-e. |
| 964 | * |
| 965 | * \param dev The device to be tested. |
| 966 | * |
| 967 | * \returns |
| 968 | * A value of 1 is always retured to indictate every i9x5 is AGP. |
| 969 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 970 | int i915_driver_device_is_agp(struct drm_device * dev) |
Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 971 | { |
| 972 | return 1; |
| 973 | } |