blob: aa9e8da9f71621227bce846da7abdb52a4841c62 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
2 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
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 Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include "drmP.h"
30#include "drm.h"
31#include "i915_drm.h"
32#include "i915_drv.h"
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/* Really want an OS-independent resettable timer. Would like to have
35 * this loop run for (eg) 3 sec, but have the timer reset every time
36 * the head pointer changes, so that EBUSY only happens if the ring
37 * actually stalls for (eg) 3 seconds.
38 */
Dave Airlie84b1fd12007-07-11 15:53:27 +100039int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 drm_i915_private_t *dev_priv = dev->dev_private;
42 drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
Keith Packardd3a6d442008-07-30 12:21:20 -070043 u32 acthd_reg = IS_I965G(dev) ? ACTHD_I965 : ACTHD;
44 u32 last_acthd = I915_READ(acthd_reg);
45 u32 acthd;
Jesse Barnes585fb112008-07-29 11:54:06 -070046 u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 int i;
48
Keith Packardd3a6d442008-07-30 12:21:20 -070049 for (i = 0; i < 100000; i++) {
Jesse Barnes585fb112008-07-29 11:54:06 -070050 ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
Keith Packardd3a6d442008-07-30 12:21:20 -070051 acthd = I915_READ(acthd_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 ring->space = ring->head - (ring->tail + 8);
53 if (ring->space < 0)
54 ring->space += ring->Size;
55 if (ring->space >= n)
56 return 0;
57
58 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
59
60 if (ring->head != last_head)
61 i = 0;
Keith Packardd3a6d442008-07-30 12:21:20 -070062 if (acthd != last_acthd)
63 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 last_head = ring->head;
Keith Packardd3a6d442008-07-30 12:21:20 -070066 last_acthd = acthd;
67 msleep_interruptible(10);
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70
Eric Anholt20caafa2007-08-25 19:22:43 +100071 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Dave Airlie84b1fd12007-07-11 15:53:27 +100074void i915_kernel_lost_context(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 drm_i915_private_t *dev_priv = dev->dev_private;
77 drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
78
Jesse Barnes585fb112008-07-29 11:54:06 -070079 ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
80 ring->tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 ring->space = ring->head - (ring->tail + 8);
82 if (ring->space < 0)
83 ring->space += ring->Size;
84
85 if (ring->head == ring->tail)
86 dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY;
87}
88
Dave Airlie84b1fd12007-07-11 15:53:27 +100089static int i915_dma_cleanup(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +100091 drm_i915_private_t *dev_priv = dev->dev_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 /* Make sure interrupts are disabled here because the uninstall ioctl
93 * may not have been called from userspace and after dev_private
94 * is freed, it's too late.
95 */
Eric Anholted4cb412008-07-29 12:10:39 -070096 if (dev->irq_enabled)
Dave Airlieb5e89ed2005-09-25 14:28:13 +100097 drm_irq_uninstall(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Jesse Barnesba8bbcf2007-11-22 14:14:14 +100099 if (dev_priv->ring.virtual_start) {
100 drm_core_ioremapfree(&dev_priv->ring.map, dev);
101 dev_priv->ring.virtual_start = 0;
102 dev_priv->ring.map.handle = 0;
103 dev_priv->ring.map.size = 0;
104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000106 if (dev_priv->status_page_dmah) {
107 drm_pci_free(dev, dev_priv->status_page_dmah);
108 dev_priv->status_page_dmah = NULL;
109 /* Need to rewrite hardware status page */
Jesse Barnes585fb112008-07-29 11:54:06 -0700110 I915_WRITE(HWS_PGA, 0x1ffff000);
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000113 if (dev_priv->status_gfx_addr) {
114 dev_priv->status_gfx_addr = 0;
115 drm_core_ioremapfree(&dev_priv->hws_map, dev);
Jesse Barnes585fb112008-07-29 11:54:06 -0700116 I915_WRITE(HWS_PGA, 0x1ffff000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
119 return 0;
120}
121
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000122static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000124 drm_i915_private_t *dev_priv = dev->dev_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Dave Airlieda509d72007-05-26 05:04:51 +1000126 dev_priv->sarea = drm_getsarea(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if (!dev_priv->sarea) {
128 DRM_ERROR("can not find sarea!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 i915_dma_cleanup(dev);
Eric Anholt20caafa2007-08-25 19:22:43 +1000130 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 dev_priv->sarea_priv = (drm_i915_sarea_t *)
134 ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset);
135
136 dev_priv->ring.Start = init->ring_start;
137 dev_priv->ring.End = init->ring_end;
138 dev_priv->ring.Size = init->ring_size;
139 dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
140
141 dev_priv->ring.map.offset = init->ring_start;
142 dev_priv->ring.map.size = init->ring_size;
143 dev_priv->ring.map.type = 0;
144 dev_priv->ring.map.flags = 0;
145 dev_priv->ring.map.mtrr = 0;
146
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000147 drm_core_ioremap(&dev_priv->ring.map, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 if (dev_priv->ring.map.handle == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 i915_dma_cleanup(dev);
151 DRM_ERROR("can not ioremap virtual address for"
152 " ring buffer\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000153 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155
156 dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
157
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000158 dev_priv->cpp = init->cpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 dev_priv->back_offset = init->back_offset;
160 dev_priv->front_offset = init->front_offset;
161 dev_priv->current_page = 0;
162 dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 /* Allow hardware batchbuffers unless told otherwise.
165 */
166 dev_priv->allow_batchbuffer = 1;
167
168 /* Program Hardware Status Page */
Zhenyu Wangb39d50e2008-02-19 20:59:09 +1000169 if (!I915_NEED_GFX_HWS(dev)) {
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000170 dev_priv->status_page_dmah =
171 drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000173 if (!dev_priv->status_page_dmah) {
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000174 i915_dma_cleanup(dev);
175 DRM_ERROR("Can not allocate hardware status page\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000176 return -ENOMEM;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000177 }
178 dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
179 dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
180
181 memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
Jesse Barnes585fb112008-07-29 11:54:06 -0700182 I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 DRM_DEBUG("Enabled hardware status page\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return 0;
186}
187
Dave Airlie84b1fd12007-07-11 15:53:27 +1000188static int i915_dma_resume(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
190 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
191
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700192 DRM_DEBUG("%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 if (!dev_priv->sarea) {
195 DRM_ERROR("can not find sarea!\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000196 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (dev_priv->ring.map.handle == NULL) {
200 DRM_ERROR("can not ioremap virtual address for"
201 " ring buffer\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000202 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 }
204
205 /* Program Hardware Status Page */
206 if (!dev_priv->hw_status_page) {
207 DRM_ERROR("Can not find hardware status page\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000208 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210 DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
211
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000212 if (dev_priv->status_gfx_addr != 0)
Jesse Barnes585fb112008-07-29 11:54:06 -0700213 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000214 else
Jesse Barnes585fb112008-07-29 11:54:06 -0700215 I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 DRM_DEBUG("Enabled hardware status page\n");
217
218 return 0;
219}
220
Eric Anholtc153f452007-09-03 12:06:45 +1000221static int i915_dma_init(struct drm_device *dev, void *data,
222 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Eric Anholtc153f452007-09-03 12:06:45 +1000224 drm_i915_init_t *init = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 int retcode = 0;
226
Eric Anholtc153f452007-09-03 12:06:45 +1000227 switch (init->func) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 case I915_INIT_DMA:
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000229 retcode = i915_initialize(dev, init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 break;
231 case I915_CLEANUP_DMA:
232 retcode = i915_dma_cleanup(dev);
233 break;
234 case I915_RESUME_DMA:
Dave Airlie0d6aa602006-01-02 20:14:23 +1100235 retcode = i915_dma_resume(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 break;
237 default:
Eric Anholt20caafa2007-08-25 19:22:43 +1000238 retcode = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 break;
240 }
241
242 return retcode;
243}
244
245/* Implement basically the same security restrictions as hardware does
246 * for MI_BATCH_NON_SECURE. These can be made stricter at any time.
247 *
248 * Most of the calculations below involve calculating the size of a
249 * particular instruction. It's important to get the size right as
250 * that tells us where the next instruction to check is. Any illegal
251 * instruction detected will be given a size of zero, which is a
252 * signal to abort the rest of the buffer.
253 */
254static int do_validate_cmd(int cmd)
255{
256 switch (((cmd >> 29) & 0x7)) {
257 case 0x0:
258 switch ((cmd >> 23) & 0x3f) {
259 case 0x0:
260 return 1; /* MI_NOOP */
261 case 0x4:
262 return 1; /* MI_FLUSH */
263 default:
264 return 0; /* disallow everything else */
265 }
266 break;
267 case 0x1:
268 return 0; /* reserved */
269 case 0x2:
270 return (cmd & 0xff) + 2; /* 2d commands */
271 case 0x3:
272 if (((cmd >> 24) & 0x1f) <= 0x18)
273 return 1;
274
275 switch ((cmd >> 24) & 0x1f) {
276 case 0x1c:
277 return 1;
278 case 0x1d:
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000279 switch ((cmd >> 16) & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 case 0x3:
281 return (cmd & 0x1f) + 2;
282 case 0x4:
283 return (cmd & 0xf) + 2;
284 default:
285 return (cmd & 0xffff) + 2;
286 }
287 case 0x1e:
288 if (cmd & (1 << 23))
289 return (cmd & 0xffff) + 1;
290 else
291 return 1;
292 case 0x1f:
293 if ((cmd & (1 << 23)) == 0) /* inline vertices */
294 return (cmd & 0x1ffff) + 2;
295 else if (cmd & (1 << 17)) /* indirect random */
296 if ((cmd & 0xffff) == 0)
297 return 0; /* unknown length, too hard */
298 else
299 return (((cmd & 0xffff) + 1) / 2) + 1;
300 else
301 return 2; /* indirect sequential */
302 default:
303 return 0;
304 }
305 default:
306 return 0;
307 }
308
309 return 0;
310}
311
312static int validate_cmd(int cmd)
313{
314 int ret = do_validate_cmd(cmd);
315
Dave Airliebc5f4522007-11-05 12:50:58 +1000316/* printk("validate_cmd( %x ): %d\n", cmd, ret); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 return ret;
319}
320
Dave Airlie84b1fd12007-07-11 15:53:27 +1000321static int i915_emit_cmds(struct drm_device * dev, int __user * buffer, int dwords)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 drm_i915_private_t *dev_priv = dev->dev_private;
324 int i;
325 RING_LOCALS;
326
Dave Airliede227f52006-01-25 15:31:43 +1100327 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
Eric Anholt20caafa2007-08-25 19:22:43 +1000328 return -EINVAL;
Dave Airliede227f52006-01-25 15:31:43 +1100329
Alan Hourihanec29b6692006-08-12 16:29:24 +1000330 BEGIN_LP_RING((dwords+1)&~1);
Dave Airliede227f52006-01-25 15:31:43 +1100331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 for (i = 0; i < dwords;) {
333 int cmd, sz;
334
335 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd)))
Eric Anholt20caafa2007-08-25 19:22:43 +1000336 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords)
Eric Anholt20caafa2007-08-25 19:22:43 +1000339 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 OUT_RING(cmd);
342
343 while (++i, --sz) {
344 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i],
345 sizeof(cmd))) {
Eric Anholt20caafa2007-08-25 19:22:43 +1000346 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
348 OUT_RING(cmd);
349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
Dave Airliede227f52006-01-25 15:31:43 +1100352 if (dwords & 1)
353 OUT_RING(0);
354
355 ADVANCE_LP_RING();
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return 0;
358}
359
Dave Airlie84b1fd12007-07-11 15:53:27 +1000360static int i915_emit_box(struct drm_device * dev,
Dave Airliec60ce622007-07-11 15:27:12 +1000361 struct drm_clip_rect __user * boxes,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 int i, int DR1, int DR4)
363{
364 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airliec60ce622007-07-11 15:27:12 +1000365 struct drm_clip_rect box;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 RING_LOCALS;
367
368 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
Eric Anholt20caafa2007-08-25 19:22:43 +1000369 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
371
372 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
373 DRM_ERROR("Bad box %d,%d..%d,%d\n",
374 box.x1, box.y1, box.x2, box.y2);
Eric Anholt20caafa2007-08-25 19:22:43 +1000375 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
Alan Hourihanec29b6692006-08-12 16:29:24 +1000378 if (IS_I965G(dev)) {
379 BEGIN_LP_RING(4);
380 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
381 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
Andrew Morton78eca432006-08-16 09:15:51 +1000382 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
Alan Hourihanec29b6692006-08-12 16:29:24 +1000383 OUT_RING(DR4);
384 ADVANCE_LP_RING();
385 } else {
386 BEGIN_LP_RING(6);
387 OUT_RING(GFX_OP_DRAWRECT_INFO);
388 OUT_RING(DR1);
389 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
390 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
391 OUT_RING(DR4);
392 OUT_RING(0);
393 ADVANCE_LP_RING();
394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 return 0;
397}
398
Alan Hourihanec29b6692006-08-12 16:29:24 +1000399/* XXX: Emitting the counter should really be moved to part of the IRQ
400 * emit. For now, do it in both places:
401 */
402
Dave Airlie84b1fd12007-07-11 15:53:27 +1000403static void i915_emit_breadcrumb(struct drm_device *dev)
Dave Airliede227f52006-01-25 15:31:43 +1100404{
405 drm_i915_private_t *dev_priv = dev->dev_private;
406 RING_LOCALS;
407
Dave Airlieaf6061a2008-05-07 12:15:39 +1000408 dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
Alan Hourihanec29b6692006-08-12 16:29:24 +1000409
Dave Airlieaf6061a2008-05-07 12:15:39 +1000410 if (dev_priv->counter > 0x7FFFFFFFUL)
411 dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
Dave Airliede227f52006-01-25 15:31:43 +1100412
413 BEGIN_LP_RING(4);
Jesse Barnes585fb112008-07-29 11:54:06 -0700414 OUT_RING(MI_STORE_DWORD_INDEX);
415 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
Dave Airliede227f52006-01-25 15:31:43 +1100416 OUT_RING(dev_priv->counter);
417 OUT_RING(0);
418 ADVANCE_LP_RING();
419}
420
Dave Airlie84b1fd12007-07-11 15:53:27 +1000421static int i915_dispatch_cmdbuffer(struct drm_device * dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 drm_i915_cmdbuffer_t * cmd)
423{
424 int nbox = cmd->num_cliprects;
425 int i = 0, count, ret;
426
427 if (cmd->sz & 0x3) {
428 DRM_ERROR("alignment");
Eric Anholt20caafa2007-08-25 19:22:43 +1000429 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
432 i915_kernel_lost_context(dev);
433
434 count = nbox ? nbox : 1;
435
436 for (i = 0; i < count; i++) {
437 if (i < nbox) {
438 ret = i915_emit_box(dev, cmd->cliprects, i,
439 cmd->DR1, cmd->DR4);
440 if (ret)
441 return ret;
442 }
443
444 ret = i915_emit_cmds(dev, (int __user *)cmd->buf, cmd->sz / 4);
445 if (ret)
446 return ret;
447 }
448
Dave Airliede227f52006-01-25 15:31:43 +1100449 i915_emit_breadcrumb(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return 0;
451}
452
Dave Airlie84b1fd12007-07-11 15:53:27 +1000453static int i915_dispatch_batchbuffer(struct drm_device * dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 drm_i915_batchbuffer_t * batch)
455{
456 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airliec60ce622007-07-11 15:27:12 +1000457 struct drm_clip_rect __user *boxes = batch->cliprects;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 int nbox = batch->num_cliprects;
459 int i = 0, count;
460 RING_LOCALS;
461
462 if ((batch->start | batch->used) & 0x7) {
463 DRM_ERROR("alignment");
Eric Anholt20caafa2007-08-25 19:22:43 +1000464 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466
467 i915_kernel_lost_context(dev);
468
469 count = nbox ? nbox : 1;
470
471 for (i = 0; i < count; i++) {
472 if (i < nbox) {
473 int ret = i915_emit_box(dev, boxes, i,
474 batch->DR1, batch->DR4);
475 if (ret)
476 return ret;
477 }
478
Keith Packard0790d5e2008-07-30 12:28:47 -0700479 if (!IS_I830(dev) && !IS_845G(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 BEGIN_LP_RING(2);
Dave Airlie21f16282007-08-07 09:09:51 +1000481 if (IS_I965G(dev)) {
482 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
483 OUT_RING(batch->start);
484 } else {
485 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
486 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 ADVANCE_LP_RING();
489 } else {
490 BEGIN_LP_RING(4);
491 OUT_RING(MI_BATCH_BUFFER);
492 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
493 OUT_RING(batch->start + batch->used - 4);
494 OUT_RING(0);
495 ADVANCE_LP_RING();
496 }
497 }
498
Dave Airliede227f52006-01-25 15:31:43 +1100499 i915_emit_breadcrumb(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 return 0;
502}
503
Dave Airlieaf6061a2008-05-07 12:15:39 +1000504static int i915_dispatch_flip(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
506 drm_i915_private_t *dev_priv = dev->dev_private;
507 RING_LOCALS;
508
Dave Airlieaf6061a2008-05-07 12:15:39 +1000509 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
Harvey Harrison80a914d2008-10-15 22:01:25 -0700510 __func__,
Dave Airlieaf6061a2008-05-07 12:15:39 +1000511 dev_priv->current_page,
512 dev_priv->sarea_priv->pf_current_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Dave Airlieaf6061a2008-05-07 12:15:39 +1000514 i915_kernel_lost_context(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Dave Airlieaf6061a2008-05-07 12:15:39 +1000516 BEGIN_LP_RING(2);
Jesse Barnes585fb112008-07-29 11:54:06 -0700517 OUT_RING(MI_FLUSH | MI_READ_FLUSH);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000518 OUT_RING(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 ADVANCE_LP_RING();
520
Dave Airlieaf6061a2008-05-07 12:15:39 +1000521 BEGIN_LP_RING(6);
522 OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
523 OUT_RING(0);
524 if (dev_priv->current_page == 0) {
525 OUT_RING(dev_priv->back_offset);
526 dev_priv->current_page = 1;
527 } else {
528 OUT_RING(dev_priv->front_offset);
529 dev_priv->current_page = 0;
530 }
531 OUT_RING(0);
532 ADVANCE_LP_RING();
Jesse Barnesac741ab2008-04-22 16:03:07 +1000533
Dave Airlieaf6061a2008-05-07 12:15:39 +1000534 BEGIN_LP_RING(2);
535 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
536 OUT_RING(0);
537 ADVANCE_LP_RING();
Jesse Barnesac741ab2008-04-22 16:03:07 +1000538
Dave Airlieaf6061a2008-05-07 12:15:39 +1000539 dev_priv->sarea_priv->last_enqueue = dev_priv->counter++;
Jesse Barnesac741ab2008-04-22 16:03:07 +1000540
Dave Airlieaf6061a2008-05-07 12:15:39 +1000541 BEGIN_LP_RING(4);
Jesse Barnes585fb112008-07-29 11:54:06 -0700542 OUT_RING(MI_STORE_DWORD_INDEX);
543 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000544 OUT_RING(dev_priv->counter);
545 OUT_RING(0);
546 ADVANCE_LP_RING();
Jesse Barnesac741ab2008-04-22 16:03:07 +1000547
Dave Airlieaf6061a2008-05-07 12:15:39 +1000548 dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
549 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550}
551
Dave Airlie84b1fd12007-07-11 15:53:27 +1000552static int i915_quiescent(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
554 drm_i915_private_t *dev_priv = dev->dev_private;
555
556 i915_kernel_lost_context(dev);
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700557 return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
Eric Anholtc153f452007-09-03 12:06:45 +1000560static int i915_flush_ioctl(struct drm_device *dev, void *data,
561 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
Eric Anholt6c340ea2007-08-25 20:23:09 +1000563 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 return i915_quiescent(dev);
566}
567
Eric Anholtc153f452007-09-03 12:06:45 +1000568static int i915_batchbuffer(struct drm_device *dev, void *data,
569 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000572 u32 *hw_status = dev_priv->hw_status_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
574 dev_priv->sarea_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000575 drm_i915_batchbuffer_t *batch = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 int ret;
577
578 if (!dev_priv->allow_batchbuffer) {
579 DRM_ERROR("Batchbuffer ioctl disabled\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000580 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 DRM_DEBUG("i915 batchbuffer, start %x used %d cliprects %d\n",
Eric Anholtc153f452007-09-03 12:06:45 +1000584 batch->start, batch->used, batch->num_cliprects);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Eric Anholt6c340ea2007-08-25 20:23:09 +1000586 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Eric Anholtc153f452007-09-03 12:06:45 +1000588 if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects,
589 batch->num_cliprects *
Dave Airliec60ce622007-07-11 15:27:12 +1000590 sizeof(struct drm_clip_rect)))
Eric Anholt20caafa2007-08-25 19:22:43 +1000591 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Eric Anholtc153f452007-09-03 12:06:45 +1000593 ret = i915_dispatch_batchbuffer(dev, batch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Dave Airlieaf6061a2008-05-07 12:15:39 +1000595 sarea_priv->last_dispatch = (int)hw_status[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 return ret;
597}
598
Eric Anholtc153f452007-09-03 12:06:45 +1000599static int i915_cmdbuffer(struct drm_device *dev, void *data,
600 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000603 u32 *hw_status = dev_priv->hw_status_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
605 dev_priv->sarea_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000606 drm_i915_cmdbuffer_t *cmdbuf = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 int ret;
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
Eric Anholtc153f452007-09-03 12:06:45 +1000610 cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Eric Anholt6c340ea2007-08-25 20:23:09 +1000612 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Eric Anholtc153f452007-09-03 12:06:45 +1000614 if (cmdbuf->num_cliprects &&
615 DRM_VERIFYAREA_READ(cmdbuf->cliprects,
616 cmdbuf->num_cliprects *
Dave Airliec60ce622007-07-11 15:27:12 +1000617 sizeof(struct drm_clip_rect))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 DRM_ERROR("Fault accessing cliprects\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000619 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
Eric Anholtc153f452007-09-03 12:06:45 +1000622 ret = i915_dispatch_cmdbuffer(dev, cmdbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (ret) {
624 DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
625 return ret;
626 }
627
Dave Airlieaf6061a2008-05-07 12:15:39 +1000628 sarea_priv->last_dispatch = (int)hw_status[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return 0;
630}
631
Eric Anholtc153f452007-09-03 12:06:45 +1000632static int i915_flip_bufs(struct drm_device *dev, void *data,
633 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Harvey Harrison80a914d2008-10-15 22:01:25 -0700635 DRM_DEBUG("%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Eric Anholt6c340ea2007-08-25 20:23:09 +1000637 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Dave Airlieaf6061a2008-05-07 12:15:39 +1000639 return i915_dispatch_flip(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
Eric Anholtc153f452007-09-03 12:06:45 +1000642static int i915_getparam(struct drm_device *dev, void *data,
643 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000646 drm_i915_getparam_t *param = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 int value;
648
649 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000650 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000651 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Eric Anholtc153f452007-09-03 12:06:45 +1000654 switch (param->param) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 case I915_PARAM_IRQ_ACTIVE:
Eric Anholted4cb412008-07-29 12:10:39 -0700656 value = dev->irq_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 break;
658 case I915_PARAM_ALLOW_BATCHBUFFER:
659 value = dev_priv->allow_batchbuffer ? 1 : 0;
660 break;
Dave Airlie0d6aa602006-01-02 20:14:23 +1100661 case I915_PARAM_LAST_DISPATCH:
662 value = READ_BREADCRUMB(dev_priv);
663 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 default:
Eric Anholtc153f452007-09-03 12:06:45 +1000665 DRM_ERROR("Unknown parameter %d\n", param->param);
Eric Anholt20caafa2007-08-25 19:22:43 +1000666 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
668
Eric Anholtc153f452007-09-03 12:06:45 +1000669 if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 DRM_ERROR("DRM_COPY_TO_USER failed\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000671 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 }
673
674 return 0;
675}
676
Eric Anholtc153f452007-09-03 12:06:45 +1000677static int i915_setparam(struct drm_device *dev, void *data,
678 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000681 drm_i915_setparam_t *param = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000684 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000685 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687
Eric Anholtc153f452007-09-03 12:06:45 +1000688 switch (param->param) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
691 case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
Eric Anholtc153f452007-09-03 12:06:45 +1000692 dev_priv->tex_lru_log_granularity = param->value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 break;
694 case I915_SETPARAM_ALLOW_BATCHBUFFER:
Eric Anholtc153f452007-09-03 12:06:45 +1000695 dev_priv->allow_batchbuffer = param->value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 break;
697 default:
Eric Anholtc153f452007-09-03 12:06:45 +1000698 DRM_ERROR("unknown parameter %d\n", param->param);
Eric Anholt20caafa2007-08-25 19:22:43 +1000699 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
702 return 0;
703}
704
Eric Anholtc153f452007-09-03 12:06:45 +1000705static int i915_set_status_page(struct drm_device *dev, void *data,
706 struct drm_file *file_priv)
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000707{
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000708 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000709 drm_i915_hws_addr_t *hws = data;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000710
Zhenyu Wangb39d50e2008-02-19 20:59:09 +1000711 if (!I915_NEED_GFX_HWS(dev))
712 return -EINVAL;
713
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000714 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000715 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000716 return -EINVAL;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000717 }
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000718
Eric Anholtc153f452007-09-03 12:06:45 +1000719 printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws->addr);
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000720
Eric Anholtc153f452007-09-03 12:06:45 +1000721 dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12);
722
Eric Anholt8b409582007-11-22 16:40:37 +1000723 dev_priv->hws_map.offset = dev->agp->base + hws->addr;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000724 dev_priv->hws_map.size = 4*1024;
725 dev_priv->hws_map.type = 0;
726 dev_priv->hws_map.flags = 0;
727 dev_priv->hws_map.mtrr = 0;
728
729 drm_core_ioremap(&dev_priv->hws_map, dev);
730 if (dev_priv->hws_map.handle == NULL) {
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000731 i915_dma_cleanup(dev);
732 dev_priv->status_gfx_addr = 0;
733 DRM_ERROR("can not ioremap virtual address for"
734 " G33 hw status page\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000735 return -ENOMEM;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000736 }
737 dev_priv->hw_status_page = dev_priv->hws_map.handle;
738
739 memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
Jesse Barnes585fb112008-07-29 11:54:06 -0700740 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
741 DRM_DEBUG("load hws HWS_PGA with gfx mem 0x%x\n",
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000742 dev_priv->status_gfx_addr);
743 DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page);
744 return 0;
745}
746
Dave Airlie84b1fd12007-07-11 15:53:27 +1000747int i915_driver_load(struct drm_device *dev, unsigned long flags)
Dave Airlie22eae942005-11-10 22:16:34 +1100748{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000749 struct drm_i915_private *dev_priv = dev->dev_private;
750 unsigned long base, size;
751 int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1;
752
Dave Airlie22eae942005-11-10 22:16:34 +1100753 /* i915 has 4 more counters */
754 dev->counters += 4;
755 dev->types[6] = _DRM_STAT_IRQ;
756 dev->types[7] = _DRM_STAT_PRIMARY;
757 dev->types[8] = _DRM_STAT_SECONDARY;
758 dev->types[9] = _DRM_STAT_DMA;
759
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000760 dev_priv = drm_alloc(sizeof(drm_i915_private_t), DRM_MEM_DRIVER);
761 if (dev_priv == NULL)
762 return -ENOMEM;
763
764 memset(dev_priv, 0, sizeof(drm_i915_private_t));
765
766 dev->dev_private = (void *)dev_priv;
767
768 /* Add register map (needed for suspend/resume) */
769 base = drm_get_resource_start(dev, mmio_bar);
770 size = drm_get_resource_len(dev, mmio_bar);
771
Dave Airliee3236a12007-12-17 09:41:56 +1000772 ret = drm_addmap(dev, base, size, _DRM_REGISTERS,
773 _DRM_KERNEL | _DRM_DRIVER,
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000774 &dev_priv->mmio_map);
Eric Anholted4cb412008-07-29 12:10:39 -0700775
776
777 /* On the 945G/GM, the chipset reports the MSI capability on the
778 * integrated graphics even though the support isn't actually there
779 * according to the published specs. It doesn't appear to function
780 * correctly in testing on 945G.
781 * This may be a side effect of MSI having been made available for PEG
782 * and the registers being closely associated.
783 */
784 if (!IS_I945G(dev) && !IS_I945GM(dev))
785 pci_enable_msi(dev->pdev);
786
787 spin_lock_init(&dev_priv->user_irq_lock);
788
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000789 return ret;
790}
791
792int i915_driver_unload(struct drm_device *dev)
793{
794 struct drm_i915_private *dev_priv = dev->dev_private;
795
Eric Anholted4cb412008-07-29 12:10:39 -0700796 if (dev->pdev->msi_enabled)
797 pci_disable_msi(dev->pdev);
798
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000799 if (dev_priv->mmio_map)
800 drm_rmmap(dev, dev_priv->mmio_map);
801
802 drm_free(dev->dev_private, sizeof(drm_i915_private_t),
803 DRM_MEM_DRIVER);
804
Dave Airlie22eae942005-11-10 22:16:34 +1100805 return 0;
806}
807
Dave Airlie84b1fd12007-07-11 15:53:27 +1000808void i915_driver_lastclose(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000810 drm_i915_private_t *dev_priv = dev->dev_private;
811
Dave Airlie144a75f2008-03-30 07:53:58 +1000812 if (!dev_priv)
813 return;
814
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000815 if (dev_priv->agp_heap)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000816 i915_mem_takedown(&(dev_priv->agp_heap));
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000817
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000818 i915_dma_cleanup(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
820
Eric Anholt6c340ea2007-08-25 20:23:09 +1000821void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000823 drm_i915_private_t *dev_priv = dev->dev_private;
824 i915_mem_release(dev, file_priv, dev_priv->agp_heap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
Eric Anholtc153f452007-09-03 12:06:45 +1000827struct drm_ioctl_desc i915_ioctls[] = {
828 DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
829 DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
830 DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH),
831 DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH),
832 DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH),
833 DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH),
834 DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH),
835 DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
836 DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH),
837 DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH),
838 DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
839 DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH),
840 DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP, i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
841 DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE, i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
842 DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH ),
843 DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH),
844 DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH),
Dave Airliec94f7022005-07-07 21:03:38 +1000845};
846
847int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
Dave Airliecda17382005-07-10 17:31:26 +1000848
849/**
850 * Determine if the device really is AGP or not.
851 *
852 * All Intel graphics chipsets are treated as AGP, even if they are really
853 * PCI-e.
854 *
855 * \param dev The device to be tested.
856 *
857 * \returns
858 * A value of 1 is always retured to indictate every i9x5 is AGP.
859 */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000860int i915_driver_device_is_agp(struct drm_device * dev)
Dave Airliecda17382005-07-10 17:31:26 +1000861{
862 return 1;
863}