blob: 4d56dfd25e04c9ce81e6d24ae3f7a95b16eada86 [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);
Jesse Barnes585fb112008-07-29 11:54:06 -070043 u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 int i;
45
46 for (i = 0; i < 10000; i++) {
Jesse Barnes585fb112008-07-29 11:54:06 -070047 ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 ring->space = ring->head - (ring->tail + 8);
49 if (ring->space < 0)
50 ring->space += ring->Size;
51 if (ring->space >= n)
52 return 0;
53
54 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
55
56 if (ring->head != last_head)
57 i = 0;
58
59 last_head = ring->head;
60 }
61
Eric Anholt20caafa2007-08-25 19:22:43 +100062 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Dave Airlie84b1fd12007-07-11 15:53:27 +100065void i915_kernel_lost_context(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 drm_i915_private_t *dev_priv = dev->dev_private;
68 drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
69
Jesse Barnes585fb112008-07-29 11:54:06 -070070 ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
71 ring->tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 ring->space = ring->head - (ring->tail + 8);
73 if (ring->space < 0)
74 ring->space += ring->Size;
75
76 if (ring->head == ring->tail)
77 dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY;
78}
79
Dave Airlie84b1fd12007-07-11 15:53:27 +100080static int i915_dma_cleanup(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +100082 drm_i915_private_t *dev_priv = dev->dev_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 /* Make sure interrupts are disabled here because the uninstall ioctl
84 * may not have been called from userspace and after dev_private
85 * is freed, it's too late.
86 */
87 if (dev->irq)
Dave Airlieb5e89ed2005-09-25 14:28:13 +100088 drm_irq_uninstall(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Jesse Barnesba8bbcf2007-11-22 14:14:14 +100090 if (dev_priv->ring.virtual_start) {
91 drm_core_ioremapfree(&dev_priv->ring.map, dev);
92 dev_priv->ring.virtual_start = 0;
93 dev_priv->ring.map.handle = 0;
94 dev_priv->ring.map.size = 0;
95 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Jesse Barnesba8bbcf2007-11-22 14:14:14 +100097 if (dev_priv->status_page_dmah) {
98 drm_pci_free(dev, dev_priv->status_page_dmah);
99 dev_priv->status_page_dmah = NULL;
100 /* Need to rewrite hardware status page */
Jesse Barnes585fb112008-07-29 11:54:06 -0700101 I915_WRITE(HWS_PGA, 0x1ffff000);
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000104 if (dev_priv->status_gfx_addr) {
105 dev_priv->status_gfx_addr = 0;
106 drm_core_ioremapfree(&dev_priv->hws_map, dev);
Jesse Barnes585fb112008-07-29 11:54:06 -0700107 I915_WRITE(HWS_PGA, 0x1ffff000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 }
109
110 return 0;
111}
112
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000113static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000115 drm_i915_private_t *dev_priv = dev->dev_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Dave Airlieda509d72007-05-26 05:04:51 +1000117 dev_priv->sarea = drm_getsarea(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 if (!dev_priv->sarea) {
119 DRM_ERROR("can not find sarea!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 i915_dma_cleanup(dev);
Eric Anholt20caafa2007-08-25 19:22:43 +1000121 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 dev_priv->sarea_priv = (drm_i915_sarea_t *)
125 ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset);
126
127 dev_priv->ring.Start = init->ring_start;
128 dev_priv->ring.End = init->ring_end;
129 dev_priv->ring.Size = init->ring_size;
130 dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
131
132 dev_priv->ring.map.offset = init->ring_start;
133 dev_priv->ring.map.size = init->ring_size;
134 dev_priv->ring.map.type = 0;
135 dev_priv->ring.map.flags = 0;
136 dev_priv->ring.map.mtrr = 0;
137
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000138 drm_core_ioremap(&dev_priv->ring.map, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 if (dev_priv->ring.map.handle == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 i915_dma_cleanup(dev);
142 DRM_ERROR("can not ioremap virtual address for"
143 " ring buffer\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000144 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
146
147 dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
148
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000149 dev_priv->cpp = init->cpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 dev_priv->back_offset = init->back_offset;
151 dev_priv->front_offset = init->front_offset;
152 dev_priv->current_page = 0;
153 dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* Allow hardware batchbuffers unless told otherwise.
156 */
157 dev_priv->allow_batchbuffer = 1;
158
159 /* Program Hardware Status Page */
Zhenyu Wangb39d50e2008-02-19 20:59:09 +1000160 if (!I915_NEED_GFX_HWS(dev)) {
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000161 dev_priv->status_page_dmah =
162 drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000164 if (!dev_priv->status_page_dmah) {
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000165 i915_dma_cleanup(dev);
166 DRM_ERROR("Can not allocate hardware status page\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000167 return -ENOMEM;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000168 }
169 dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
170 dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
171
172 memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
Jesse Barnes585fb112008-07-29 11:54:06 -0700173 I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 DRM_DEBUG("Enabled hardware status page\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return 0;
177}
178
Dave Airlie84b1fd12007-07-11 15:53:27 +1000179static int i915_dma_resume(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
182
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700183 DRM_DEBUG("%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 if (!dev_priv->sarea) {
186 DRM_ERROR("can not find sarea!\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000187 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (dev_priv->ring.map.handle == NULL) {
191 DRM_ERROR("can not ioremap virtual address for"
192 " ring buffer\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000193 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195
196 /* Program Hardware Status Page */
197 if (!dev_priv->hw_status_page) {
198 DRM_ERROR("Can not find hardware status page\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000199 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201 DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
202
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000203 if (dev_priv->status_gfx_addr != 0)
Jesse Barnes585fb112008-07-29 11:54:06 -0700204 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000205 else
Jesse Barnes585fb112008-07-29 11:54:06 -0700206 I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 DRM_DEBUG("Enabled hardware status page\n");
208
209 return 0;
210}
211
Eric Anholtc153f452007-09-03 12:06:45 +1000212static int i915_dma_init(struct drm_device *dev, void *data,
213 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Eric Anholtc153f452007-09-03 12:06:45 +1000215 drm_i915_init_t *init = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 int retcode = 0;
217
Eric Anholtc153f452007-09-03 12:06:45 +1000218 switch (init->func) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 case I915_INIT_DMA:
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000220 retcode = i915_initialize(dev, init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 break;
222 case I915_CLEANUP_DMA:
223 retcode = i915_dma_cleanup(dev);
224 break;
225 case I915_RESUME_DMA:
Dave Airlie0d6aa602006-01-02 20:14:23 +1100226 retcode = i915_dma_resume(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 break;
228 default:
Eric Anholt20caafa2007-08-25 19:22:43 +1000229 retcode = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 break;
231 }
232
233 return retcode;
234}
235
236/* Implement basically the same security restrictions as hardware does
237 * for MI_BATCH_NON_SECURE. These can be made stricter at any time.
238 *
239 * Most of the calculations below involve calculating the size of a
240 * particular instruction. It's important to get the size right as
241 * that tells us where the next instruction to check is. Any illegal
242 * instruction detected will be given a size of zero, which is a
243 * signal to abort the rest of the buffer.
244 */
245static int do_validate_cmd(int cmd)
246{
247 switch (((cmd >> 29) & 0x7)) {
248 case 0x0:
249 switch ((cmd >> 23) & 0x3f) {
250 case 0x0:
251 return 1; /* MI_NOOP */
252 case 0x4:
253 return 1; /* MI_FLUSH */
254 default:
255 return 0; /* disallow everything else */
256 }
257 break;
258 case 0x1:
259 return 0; /* reserved */
260 case 0x2:
261 return (cmd & 0xff) + 2; /* 2d commands */
262 case 0x3:
263 if (((cmd >> 24) & 0x1f) <= 0x18)
264 return 1;
265
266 switch ((cmd >> 24) & 0x1f) {
267 case 0x1c:
268 return 1;
269 case 0x1d:
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000270 switch ((cmd >> 16) & 0xff) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 case 0x3:
272 return (cmd & 0x1f) + 2;
273 case 0x4:
274 return (cmd & 0xf) + 2;
275 default:
276 return (cmd & 0xffff) + 2;
277 }
278 case 0x1e:
279 if (cmd & (1 << 23))
280 return (cmd & 0xffff) + 1;
281 else
282 return 1;
283 case 0x1f:
284 if ((cmd & (1 << 23)) == 0) /* inline vertices */
285 return (cmd & 0x1ffff) + 2;
286 else if (cmd & (1 << 17)) /* indirect random */
287 if ((cmd & 0xffff) == 0)
288 return 0; /* unknown length, too hard */
289 else
290 return (((cmd & 0xffff) + 1) / 2) + 1;
291 else
292 return 2; /* indirect sequential */
293 default:
294 return 0;
295 }
296 default:
297 return 0;
298 }
299
300 return 0;
301}
302
303static int validate_cmd(int cmd)
304{
305 int ret = do_validate_cmd(cmd);
306
Dave Airliebc5f4522007-11-05 12:50:58 +1000307/* printk("validate_cmd( %x ): %d\n", cmd, ret); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 return ret;
310}
311
Dave Airlie84b1fd12007-07-11 15:53:27 +1000312static int i915_emit_cmds(struct drm_device * dev, int __user * buffer, int dwords)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
314 drm_i915_private_t *dev_priv = dev->dev_private;
315 int i;
316 RING_LOCALS;
317
Dave Airliede227f52006-01-25 15:31:43 +1100318 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
Eric Anholt20caafa2007-08-25 19:22:43 +1000319 return -EINVAL;
Dave Airliede227f52006-01-25 15:31:43 +1100320
Alan Hourihanec29b6692006-08-12 16:29:24 +1000321 BEGIN_LP_RING((dwords+1)&~1);
Dave Airliede227f52006-01-25 15:31:43 +1100322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 for (i = 0; i < dwords;) {
324 int cmd, sz;
325
326 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd)))
Eric Anholt20caafa2007-08-25 19:22:43 +1000327 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords)
Eric Anholt20caafa2007-08-25 19:22:43 +1000330 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 OUT_RING(cmd);
333
334 while (++i, --sz) {
335 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i],
336 sizeof(cmd))) {
Eric Anholt20caafa2007-08-25 19:22:43 +1000337 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 }
339 OUT_RING(cmd);
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
Dave Airliede227f52006-01-25 15:31:43 +1100343 if (dwords & 1)
344 OUT_RING(0);
345
346 ADVANCE_LP_RING();
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return 0;
349}
350
Dave Airlie84b1fd12007-07-11 15:53:27 +1000351static int i915_emit_box(struct drm_device * dev,
Dave Airliec60ce622007-07-11 15:27:12 +1000352 struct drm_clip_rect __user * boxes,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 int i, int DR1, int DR4)
354{
355 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airliec60ce622007-07-11 15:27:12 +1000356 struct drm_clip_rect box;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 RING_LOCALS;
358
359 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
Eric Anholt20caafa2007-08-25 19:22:43 +1000360 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
363 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
364 DRM_ERROR("Bad box %d,%d..%d,%d\n",
365 box.x1, box.y1, box.x2, box.y2);
Eric Anholt20caafa2007-08-25 19:22:43 +1000366 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
368
Alan Hourihanec29b6692006-08-12 16:29:24 +1000369 if (IS_I965G(dev)) {
370 BEGIN_LP_RING(4);
371 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
372 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
Andrew Morton78eca432006-08-16 09:15:51 +1000373 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
Alan Hourihanec29b6692006-08-12 16:29:24 +1000374 OUT_RING(DR4);
375 ADVANCE_LP_RING();
376 } else {
377 BEGIN_LP_RING(6);
378 OUT_RING(GFX_OP_DRAWRECT_INFO);
379 OUT_RING(DR1);
380 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
381 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
382 OUT_RING(DR4);
383 OUT_RING(0);
384 ADVANCE_LP_RING();
385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 return 0;
388}
389
Alan Hourihanec29b6692006-08-12 16:29:24 +1000390/* XXX: Emitting the counter should really be moved to part of the IRQ
391 * emit. For now, do it in both places:
392 */
393
Dave Airlie84b1fd12007-07-11 15:53:27 +1000394static void i915_emit_breadcrumb(struct drm_device *dev)
Dave Airliede227f52006-01-25 15:31:43 +1100395{
396 drm_i915_private_t *dev_priv = dev->dev_private;
397 RING_LOCALS;
398
Dave Airlieaf6061a2008-05-07 12:15:39 +1000399 dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
Alan Hourihanec29b6692006-08-12 16:29:24 +1000400
Dave Airlieaf6061a2008-05-07 12:15:39 +1000401 if (dev_priv->counter > 0x7FFFFFFFUL)
402 dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
Dave Airliede227f52006-01-25 15:31:43 +1100403
404 BEGIN_LP_RING(4);
Jesse Barnes585fb112008-07-29 11:54:06 -0700405 OUT_RING(MI_STORE_DWORD_INDEX);
406 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
Dave Airliede227f52006-01-25 15:31:43 +1100407 OUT_RING(dev_priv->counter);
408 OUT_RING(0);
409 ADVANCE_LP_RING();
410}
411
Dave Airlie84b1fd12007-07-11 15:53:27 +1000412static int i915_dispatch_cmdbuffer(struct drm_device * dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 drm_i915_cmdbuffer_t * cmd)
414{
415 int nbox = cmd->num_cliprects;
416 int i = 0, count, ret;
417
418 if (cmd->sz & 0x3) {
419 DRM_ERROR("alignment");
Eric Anholt20caafa2007-08-25 19:22:43 +1000420 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422
423 i915_kernel_lost_context(dev);
424
425 count = nbox ? nbox : 1;
426
427 for (i = 0; i < count; i++) {
428 if (i < nbox) {
429 ret = i915_emit_box(dev, cmd->cliprects, i,
430 cmd->DR1, cmd->DR4);
431 if (ret)
432 return ret;
433 }
434
435 ret = i915_emit_cmds(dev, (int __user *)cmd->buf, cmd->sz / 4);
436 if (ret)
437 return ret;
438 }
439
Dave Airliede227f52006-01-25 15:31:43 +1100440 i915_emit_breadcrumb(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return 0;
442}
443
Dave Airlie84b1fd12007-07-11 15:53:27 +1000444static int i915_dispatch_batchbuffer(struct drm_device * dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 drm_i915_batchbuffer_t * batch)
446{
447 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airliec60ce622007-07-11 15:27:12 +1000448 struct drm_clip_rect __user *boxes = batch->cliprects;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 int nbox = batch->num_cliprects;
450 int i = 0, count;
451 RING_LOCALS;
452
453 if ((batch->start | batch->used) & 0x7) {
454 DRM_ERROR("alignment");
Eric Anholt20caafa2007-08-25 19:22:43 +1000455 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457
458 i915_kernel_lost_context(dev);
459
460 count = nbox ? nbox : 1;
461
462 for (i = 0; i < count; i++) {
463 if (i < nbox) {
464 int ret = i915_emit_box(dev, boxes, i,
465 batch->DR1, batch->DR4);
466 if (ret)
467 return ret;
468 }
469
Keith Packard0790d5e2008-07-30 12:28:47 -0700470 if (!IS_I830(dev) && !IS_845G(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 BEGIN_LP_RING(2);
Dave Airlie21f16282007-08-07 09:09:51 +1000472 if (IS_I965G(dev)) {
473 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
474 OUT_RING(batch->start);
475 } else {
476 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
477 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 ADVANCE_LP_RING();
480 } else {
481 BEGIN_LP_RING(4);
482 OUT_RING(MI_BATCH_BUFFER);
483 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
484 OUT_RING(batch->start + batch->used - 4);
485 OUT_RING(0);
486 ADVANCE_LP_RING();
487 }
488 }
489
Dave Airliede227f52006-01-25 15:31:43 +1100490 i915_emit_breadcrumb(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 return 0;
493}
494
Dave Airlieaf6061a2008-05-07 12:15:39 +1000495static int i915_dispatch_flip(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 drm_i915_private_t *dev_priv = dev->dev_private;
498 RING_LOCALS;
499
Dave Airlieaf6061a2008-05-07 12:15:39 +1000500 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
Harvey Harrison80a914d2008-10-15 22:01:25 -0700501 __func__,
Dave Airlieaf6061a2008-05-07 12:15:39 +1000502 dev_priv->current_page,
503 dev_priv->sarea_priv->pf_current_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Dave Airlieaf6061a2008-05-07 12:15:39 +1000505 i915_kernel_lost_context(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Dave Airlieaf6061a2008-05-07 12:15:39 +1000507 BEGIN_LP_RING(2);
Jesse Barnes585fb112008-07-29 11:54:06 -0700508 OUT_RING(MI_FLUSH | MI_READ_FLUSH);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000509 OUT_RING(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 ADVANCE_LP_RING();
511
Dave Airlieaf6061a2008-05-07 12:15:39 +1000512 BEGIN_LP_RING(6);
513 OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
514 OUT_RING(0);
515 if (dev_priv->current_page == 0) {
516 OUT_RING(dev_priv->back_offset);
517 dev_priv->current_page = 1;
518 } else {
519 OUT_RING(dev_priv->front_offset);
520 dev_priv->current_page = 0;
521 }
522 OUT_RING(0);
523 ADVANCE_LP_RING();
Jesse Barnesac741ab2008-04-22 16:03:07 +1000524
Dave Airlieaf6061a2008-05-07 12:15:39 +1000525 BEGIN_LP_RING(2);
526 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
527 OUT_RING(0);
528 ADVANCE_LP_RING();
Jesse Barnesac741ab2008-04-22 16:03:07 +1000529
Dave Airlieaf6061a2008-05-07 12:15:39 +1000530 dev_priv->sarea_priv->last_enqueue = dev_priv->counter++;
Jesse Barnesac741ab2008-04-22 16:03:07 +1000531
Dave Airlieaf6061a2008-05-07 12:15:39 +1000532 BEGIN_LP_RING(4);
Jesse Barnes585fb112008-07-29 11:54:06 -0700533 OUT_RING(MI_STORE_DWORD_INDEX);
534 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000535 OUT_RING(dev_priv->counter);
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->pf_current_page = dev_priv->current_page;
540 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
Dave Airlie84b1fd12007-07-11 15:53:27 +1000543static int i915_quiescent(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 drm_i915_private_t *dev_priv = dev->dev_private;
546
547 i915_kernel_lost_context(dev);
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700548 return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
550
Eric Anholtc153f452007-09-03 12:06:45 +1000551static int i915_flush_ioctl(struct drm_device *dev, void *data,
552 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
Eric Anholt6c340ea2007-08-25 20:23:09 +1000554 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 return i915_quiescent(dev);
557}
558
Eric Anholtc153f452007-09-03 12:06:45 +1000559static int i915_batchbuffer(struct drm_device *dev, void *data,
560 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000563 u32 *hw_status = dev_priv->hw_status_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
565 dev_priv->sarea_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000566 drm_i915_batchbuffer_t *batch = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 int ret;
568
569 if (!dev_priv->allow_batchbuffer) {
570 DRM_ERROR("Batchbuffer ioctl disabled\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000571 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 }
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 DRM_DEBUG("i915 batchbuffer, start %x used %d cliprects %d\n",
Eric Anholtc153f452007-09-03 12:06:45 +1000575 batch->start, batch->used, batch->num_cliprects);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Eric Anholt6c340ea2007-08-25 20:23:09 +1000577 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Eric Anholtc153f452007-09-03 12:06:45 +1000579 if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects,
580 batch->num_cliprects *
Dave Airliec60ce622007-07-11 15:27:12 +1000581 sizeof(struct drm_clip_rect)))
Eric Anholt20caafa2007-08-25 19:22:43 +1000582 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Eric Anholtc153f452007-09-03 12:06:45 +1000584 ret = i915_dispatch_batchbuffer(dev, batch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Dave Airlieaf6061a2008-05-07 12:15:39 +1000586 sarea_priv->last_dispatch = (int)hw_status[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 return ret;
588}
589
Eric Anholtc153f452007-09-03 12:06:45 +1000590static int i915_cmdbuffer(struct drm_device *dev, void *data,
591 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000594 u32 *hw_status = dev_priv->hw_status_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
596 dev_priv->sarea_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000597 drm_i915_cmdbuffer_t *cmdbuf = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 int ret;
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
Eric Anholtc153f452007-09-03 12:06:45 +1000601 cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Eric Anholt6c340ea2007-08-25 20:23:09 +1000603 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Eric Anholtc153f452007-09-03 12:06:45 +1000605 if (cmdbuf->num_cliprects &&
606 DRM_VERIFYAREA_READ(cmdbuf->cliprects,
607 cmdbuf->num_cliprects *
Dave Airliec60ce622007-07-11 15:27:12 +1000608 sizeof(struct drm_clip_rect))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 DRM_ERROR("Fault accessing cliprects\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000610 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
612
Eric Anholtc153f452007-09-03 12:06:45 +1000613 ret = i915_dispatch_cmdbuffer(dev, cmdbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 if (ret) {
615 DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
616 return ret;
617 }
618
Dave Airlieaf6061a2008-05-07 12:15:39 +1000619 sarea_priv->last_dispatch = (int)hw_status[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 return 0;
621}
622
Eric Anholtc153f452007-09-03 12:06:45 +1000623static int i915_flip_bufs(struct drm_device *dev, void *data,
624 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Harvey Harrison80a914d2008-10-15 22:01:25 -0700626 DRM_DEBUG("%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Eric Anholt6c340ea2007-08-25 20:23:09 +1000628 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Dave Airlieaf6061a2008-05-07 12:15:39 +1000630 return i915_dispatch_flip(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631}
632
Eric Anholtc153f452007-09-03 12:06:45 +1000633static int i915_getparam(struct drm_device *dev, void *data,
634 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000637 drm_i915_getparam_t *param = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 int value;
639
640 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000641 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000642 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 }
644
Eric Anholtc153f452007-09-03 12:06:45 +1000645 switch (param->param) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 case I915_PARAM_IRQ_ACTIVE:
647 value = dev->irq ? 1 : 0;
648 break;
649 case I915_PARAM_ALLOW_BATCHBUFFER:
650 value = dev_priv->allow_batchbuffer ? 1 : 0;
651 break;
Dave Airlie0d6aa602006-01-02 20:14:23 +1100652 case I915_PARAM_LAST_DISPATCH:
653 value = READ_BREADCRUMB(dev_priv);
654 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 default:
Eric Anholtc153f452007-09-03 12:06:45 +1000656 DRM_ERROR("Unknown parameter %d\n", param->param);
Eric Anholt20caafa2007-08-25 19:22:43 +1000657 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659
Eric Anholtc153f452007-09-03 12:06:45 +1000660 if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 DRM_ERROR("DRM_COPY_TO_USER failed\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000662 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 }
664
665 return 0;
666}
667
Eric Anholtc153f452007-09-03 12:06:45 +1000668static int i915_setparam(struct drm_device *dev, void *data,
669 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000672 drm_i915_setparam_t *param = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000675 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000676 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 }
678
Eric Anholtc153f452007-09-03 12:06:45 +1000679 switch (param->param) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 break;
682 case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
Eric Anholtc153f452007-09-03 12:06:45 +1000683 dev_priv->tex_lru_log_granularity = param->value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 break;
685 case I915_SETPARAM_ALLOW_BATCHBUFFER:
Eric Anholtc153f452007-09-03 12:06:45 +1000686 dev_priv->allow_batchbuffer = param->value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 break;
688 default:
Eric Anholtc153f452007-09-03 12:06:45 +1000689 DRM_ERROR("unknown parameter %d\n", param->param);
Eric Anholt20caafa2007-08-25 19:22:43 +1000690 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 }
692
693 return 0;
694}
695
Eric Anholtc153f452007-09-03 12:06:45 +1000696static int i915_set_status_page(struct drm_device *dev, void *data,
697 struct drm_file *file_priv)
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000698{
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000699 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000700 drm_i915_hws_addr_t *hws = data;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000701
Zhenyu Wangb39d50e2008-02-19 20:59:09 +1000702 if (!I915_NEED_GFX_HWS(dev))
703 return -EINVAL;
704
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000705 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000706 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000707 return -EINVAL;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000708 }
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000709
Eric Anholtc153f452007-09-03 12:06:45 +1000710 printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws->addr);
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000711
Eric Anholtc153f452007-09-03 12:06:45 +1000712 dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12);
713
Eric Anholt8b409582007-11-22 16:40:37 +1000714 dev_priv->hws_map.offset = dev->agp->base + hws->addr;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000715 dev_priv->hws_map.size = 4*1024;
716 dev_priv->hws_map.type = 0;
717 dev_priv->hws_map.flags = 0;
718 dev_priv->hws_map.mtrr = 0;
719
720 drm_core_ioremap(&dev_priv->hws_map, dev);
721 if (dev_priv->hws_map.handle == NULL) {
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000722 i915_dma_cleanup(dev);
723 dev_priv->status_gfx_addr = 0;
724 DRM_ERROR("can not ioremap virtual address for"
725 " G33 hw status page\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000726 return -ENOMEM;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000727 }
728 dev_priv->hw_status_page = dev_priv->hws_map.handle;
729
730 memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
Jesse Barnes585fb112008-07-29 11:54:06 -0700731 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
732 DRM_DEBUG("load hws HWS_PGA with gfx mem 0x%x\n",
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000733 dev_priv->status_gfx_addr);
734 DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page);
735 return 0;
736}
737
Dave Airlie84b1fd12007-07-11 15:53:27 +1000738int i915_driver_load(struct drm_device *dev, unsigned long flags)
Dave Airlie22eae942005-11-10 22:16:34 +1100739{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000740 struct drm_i915_private *dev_priv = dev->dev_private;
741 unsigned long base, size;
742 int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1;
743
Dave Airlie22eae942005-11-10 22:16:34 +1100744 /* i915 has 4 more counters */
745 dev->counters += 4;
746 dev->types[6] = _DRM_STAT_IRQ;
747 dev->types[7] = _DRM_STAT_PRIMARY;
748 dev->types[8] = _DRM_STAT_SECONDARY;
749 dev->types[9] = _DRM_STAT_DMA;
750
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000751 dev_priv = drm_alloc(sizeof(drm_i915_private_t), DRM_MEM_DRIVER);
752 if (dev_priv == NULL)
753 return -ENOMEM;
754
755 memset(dev_priv, 0, sizeof(drm_i915_private_t));
756
757 dev->dev_private = (void *)dev_priv;
758
759 /* Add register map (needed for suspend/resume) */
760 base = drm_get_resource_start(dev, mmio_bar);
761 size = drm_get_resource_len(dev, mmio_bar);
762
Dave Airliee3236a12007-12-17 09:41:56 +1000763 ret = drm_addmap(dev, base, size, _DRM_REGISTERS,
764 _DRM_KERNEL | _DRM_DRIVER,
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000765 &dev_priv->mmio_map);
766 return ret;
767}
768
769int i915_driver_unload(struct drm_device *dev)
770{
771 struct drm_i915_private *dev_priv = dev->dev_private;
772
773 if (dev_priv->mmio_map)
774 drm_rmmap(dev, dev_priv->mmio_map);
775
776 drm_free(dev->dev_private, sizeof(drm_i915_private_t),
777 DRM_MEM_DRIVER);
778
Dave Airlie22eae942005-11-10 22:16:34 +1100779 return 0;
780}
781
Dave Airlie84b1fd12007-07-11 15:53:27 +1000782void i915_driver_lastclose(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000784 drm_i915_private_t *dev_priv = dev->dev_private;
785
Dave Airlie144a75f2008-03-30 07:53:58 +1000786 if (!dev_priv)
787 return;
788
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000789 if (dev_priv->agp_heap)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000790 i915_mem_takedown(&(dev_priv->agp_heap));
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000791
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000792 i915_dma_cleanup(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
794
Eric Anholt6c340ea2007-08-25 20:23:09 +1000795void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000797 drm_i915_private_t *dev_priv = dev->dev_private;
798 i915_mem_release(dev, file_priv, dev_priv->agp_heap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Eric Anholtc153f452007-09-03 12:06:45 +1000801struct drm_ioctl_desc i915_ioctls[] = {
802 DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
803 DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
804 DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH),
805 DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH),
806 DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH),
807 DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH),
808 DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH),
809 DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
810 DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH),
811 DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH),
812 DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
813 DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH),
814 DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP, i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
815 DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE, i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
816 DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH ),
817 DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH),
818 DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH),
Dave Airliec94f7022005-07-07 21:03:38 +1000819};
820
821int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
Dave Airliecda17382005-07-10 17:31:26 +1000822
823/**
824 * Determine if the device really is AGP or not.
825 *
826 * All Intel graphics chipsets are treated as AGP, even if they are really
827 * PCI-e.
828 *
829 * \param dev The device to be tested.
830 *
831 * \returns
832 * A value of 1 is always retured to indictate every i9x5 is AGP.
833 */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000834int i915_driver_device_is_agp(struct drm_device * dev)
Dave Airliecda17382005-07-10 17:31:26 +1000835{
836 return 1;
837}