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