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