1 /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
34 /* Really want an OS-independent resettable timer. Would like to have
35 * this loop run for (eg) 3 sec, but have the timer reset every time
36 * the head pointer changes, so that EBUSY only happens if the ring
37 * actually stalls for (eg) 3 seconds.
39 int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
41 drm_i915_private_t *dev_priv = dev->dev_private;
42 drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
43 u32 acthd_reg = IS_I965G(dev) ? ACTHD_I965 : ACTHD;
44 u32 last_acthd = I915_READ(acthd_reg);
46 u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
49 for (i = 0; i < 100000; i++) {
50 ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
51 acthd = I915_READ(acthd_reg);
52 ring->space = ring->head - (ring->tail + 8);
54 ring->space += ring->Size;
58 if (dev_priv->sarea_priv)
59 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
61 if (ring->head != last_head)
63 if (acthd != last_acthd)
66 last_head = ring->head;
68 msleep_interruptible(10);
76 * Sets up the hardware status page for devices that need a physical address
79 static int i915_init_phys_hws(struct drm_device *dev)
81 drm_i915_private_t *dev_priv = dev->dev_private;
82 /* Program Hardware Status Page */
83 dev_priv->status_page_dmah =
84 drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
86 if (!dev_priv->status_page_dmah) {
87 DRM_ERROR("Can not allocate hardware status page\n");
90 dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
91 dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
93 memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
95 I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
96 DRM_DEBUG("Enabled hardware status page\n");
101 * Frees the hardware status page, whether it's a physical address or a virtual
102 * address set up by the X Server.
104 static void i915_free_hws(struct drm_device *dev)
106 drm_i915_private_t *dev_priv = dev->dev_private;
107 if (dev_priv->status_page_dmah) {
108 drm_pci_free(dev, dev_priv->status_page_dmah);
109 dev_priv->status_page_dmah = NULL;
112 if (dev_priv->status_gfx_addr) {
113 dev_priv->status_gfx_addr = 0;
114 drm_core_ioremapfree(&dev_priv->hws_map, dev);
117 /* Need to rewrite hardware status page */
118 I915_WRITE(HWS_PGA, 0x1ffff000);
121 void i915_kernel_lost_context(struct drm_device * dev)
123 drm_i915_private_t *dev_priv = dev->dev_private;
124 drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
126 ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
127 ring->tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
128 ring->space = ring->head - (ring->tail + 8);
130 ring->space += ring->Size;
132 if (ring->head == ring->tail && dev_priv->sarea_priv)
133 dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY;
136 static int i915_dma_cleanup(struct drm_device * dev)
138 drm_i915_private_t *dev_priv = dev->dev_private;
139 /* Make sure interrupts are disabled here because the uninstall ioctl
140 * may not have been called from userspace and after dev_private
141 * is freed, it's too late.
143 if (dev->irq_enabled)
144 drm_irq_uninstall(dev);
146 if (dev_priv->ring.virtual_start) {
147 drm_core_ioremapfree(&dev_priv->ring.map, dev);
148 dev_priv->ring.virtual_start = NULL;
149 dev_priv->ring.map.handle = NULL;
150 dev_priv->ring.map.size = 0;
153 /* Clear the HWS virtual address at teardown */
154 if (I915_NEED_GFX_HWS(dev))
160 static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init)
162 drm_i915_private_t *dev_priv = dev->dev_private;
164 dev_priv->sarea = drm_getsarea(dev);
165 if (!dev_priv->sarea) {
166 DRM_ERROR("can not find sarea!\n");
167 i915_dma_cleanup(dev);
171 dev_priv->sarea_priv = (drm_i915_sarea_t *)
172 ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset);
174 if (init->ring_size != 0) {
175 if (dev_priv->ring.ring_obj != NULL) {
176 i915_dma_cleanup(dev);
177 DRM_ERROR("Client tried to initialize ringbuffer in "
182 dev_priv->ring.Size = init->ring_size;
183 dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
185 dev_priv->ring.map.offset = init->ring_start;
186 dev_priv->ring.map.size = init->ring_size;
187 dev_priv->ring.map.type = 0;
188 dev_priv->ring.map.flags = 0;
189 dev_priv->ring.map.mtrr = 0;
191 drm_core_ioremap(&dev_priv->ring.map, dev);
193 if (dev_priv->ring.map.handle == NULL) {
194 i915_dma_cleanup(dev);
195 DRM_ERROR("can not ioremap virtual address for"
201 dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
203 dev_priv->cpp = init->cpp;
204 dev_priv->back_offset = init->back_offset;
205 dev_priv->front_offset = init->front_offset;
206 dev_priv->current_page = 0;
207 dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
209 /* Allow hardware batchbuffers unless told otherwise.
211 dev_priv->allow_batchbuffer = 1;
216 static int i915_dma_resume(struct drm_device * dev)
218 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
220 DRM_DEBUG("%s\n", __func__);
222 if (!dev_priv->sarea) {
223 DRM_ERROR("can not find sarea!\n");
227 if (dev_priv->ring.map.handle == NULL) {
228 DRM_ERROR("can not ioremap virtual address for"
233 /* Program Hardware Status Page */
234 if (!dev_priv->hw_status_page) {
235 DRM_ERROR("Can not find hardware status page\n");
238 DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
240 if (dev_priv->status_gfx_addr != 0)
241 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
243 I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
244 DRM_DEBUG("Enabled hardware status page\n");
249 static int i915_dma_init(struct drm_device *dev, void *data,
250 struct drm_file *file_priv)
252 drm_i915_init_t *init = data;
255 switch (init->func) {
257 retcode = i915_initialize(dev, init);
259 case I915_CLEANUP_DMA:
260 retcode = i915_dma_cleanup(dev);
262 case I915_RESUME_DMA:
263 retcode = i915_dma_resume(dev);
273 /* Implement basically the same security restrictions as hardware does
274 * for MI_BATCH_NON_SECURE. These can be made stricter at any time.
276 * Most of the calculations below involve calculating the size of a
277 * particular instruction. It's important to get the size right as
278 * that tells us where the next instruction to check is. Any illegal
279 * instruction detected will be given a size of zero, which is a
280 * signal to abort the rest of the buffer.
282 static int do_validate_cmd(int cmd)
284 switch (((cmd >> 29) & 0x7)) {
286 switch ((cmd >> 23) & 0x3f) {
288 return 1; /* MI_NOOP */
290 return 1; /* MI_FLUSH */
292 return 0; /* disallow everything else */
296 return 0; /* reserved */
298 return (cmd & 0xff) + 2; /* 2d commands */
300 if (((cmd >> 24) & 0x1f) <= 0x18)
303 switch ((cmd >> 24) & 0x1f) {
307 switch ((cmd >> 16) & 0xff) {
309 return (cmd & 0x1f) + 2;
311 return (cmd & 0xf) + 2;
313 return (cmd & 0xffff) + 2;
317 return (cmd & 0xffff) + 1;
321 if ((cmd & (1 << 23)) == 0) /* inline vertices */
322 return (cmd & 0x1ffff) + 2;
323 else if (cmd & (1 << 17)) /* indirect random */
324 if ((cmd & 0xffff) == 0)
325 return 0; /* unknown length, too hard */
327 return (((cmd & 0xffff) + 1) / 2) + 1;
329 return 2; /* indirect sequential */
340 static int validate_cmd(int cmd)
342 int ret = do_validate_cmd(cmd);
344 /* printk("validate_cmd( %x ): %d\n", cmd, ret); */
349 static int i915_emit_cmds(struct drm_device * dev, int __user * buffer, int dwords)
351 drm_i915_private_t *dev_priv = dev->dev_private;
355 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
358 BEGIN_LP_RING((dwords+1)&~1);
360 for (i = 0; i < dwords;) {
363 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd)))
366 if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords)
372 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i],
389 i915_emit_box(struct drm_device *dev,
390 struct drm_clip_rect __user *boxes,
391 int i, int DR1, int DR4)
393 drm_i915_private_t *dev_priv = dev->dev_private;
394 struct drm_clip_rect box;
397 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
401 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
402 DRM_ERROR("Bad box %d,%d..%d,%d\n",
403 box.x1, box.y1, box.x2, box.y2);
409 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
410 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
411 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
416 OUT_RING(GFX_OP_DRAWRECT_INFO);
418 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
419 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
428 /* XXX: Emitting the counter should really be moved to part of the IRQ
429 * emit. For now, do it in both places:
432 static void i915_emit_breadcrumb(struct drm_device *dev)
434 drm_i915_private_t *dev_priv = dev->dev_private;
438 if (dev_priv->counter > 0x7FFFFFFFUL)
439 dev_priv->counter = 0;
440 if (dev_priv->sarea_priv)
441 dev_priv->sarea_priv->last_enqueue = dev_priv->counter;
444 OUT_RING(MI_STORE_DWORD_INDEX);
445 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
446 OUT_RING(dev_priv->counter);
451 static int i915_dispatch_cmdbuffer(struct drm_device * dev,
452 drm_i915_cmdbuffer_t * cmd)
454 int nbox = cmd->num_cliprects;
455 int i = 0, count, ret;
458 DRM_ERROR("alignment");
462 i915_kernel_lost_context(dev);
464 count = nbox ? nbox : 1;
466 for (i = 0; i < count; i++) {
468 ret = i915_emit_box(dev, cmd->cliprects, i,
474 ret = i915_emit_cmds(dev, (int __user *)cmd->buf, cmd->sz / 4);
479 i915_emit_breadcrumb(dev);
483 static int i915_dispatch_batchbuffer(struct drm_device * dev,
484 drm_i915_batchbuffer_t * batch)
486 drm_i915_private_t *dev_priv = dev->dev_private;
487 struct drm_clip_rect __user *boxes = batch->cliprects;
488 int nbox = batch->num_cliprects;
492 if ((batch->start | batch->used) & 0x7) {
493 DRM_ERROR("alignment");
497 i915_kernel_lost_context(dev);
499 count = nbox ? nbox : 1;
501 for (i = 0; i < count; i++) {
503 int ret = i915_emit_box(dev, boxes, i,
504 batch->DR1, batch->DR4);
509 if (!IS_I830(dev) && !IS_845G(dev)) {
512 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
513 OUT_RING(batch->start);
515 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
516 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
521 OUT_RING(MI_BATCH_BUFFER);
522 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
523 OUT_RING(batch->start + batch->used - 4);
529 i915_emit_breadcrumb(dev);
534 static int i915_dispatch_flip(struct drm_device * dev)
536 drm_i915_private_t *dev_priv = dev->dev_private;
539 if (!dev_priv->sarea_priv)
542 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
544 dev_priv->current_page,
545 dev_priv->sarea_priv->pf_current_page);
547 i915_kernel_lost_context(dev);
550 OUT_RING(MI_FLUSH | MI_READ_FLUSH);
555 OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
557 if (dev_priv->current_page == 0) {
558 OUT_RING(dev_priv->back_offset);
559 dev_priv->current_page = 1;
561 OUT_RING(dev_priv->front_offset);
562 dev_priv->current_page = 0;
568 OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
572 dev_priv->sarea_priv->last_enqueue = dev_priv->counter++;
575 OUT_RING(MI_STORE_DWORD_INDEX);
576 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
577 OUT_RING(dev_priv->counter);
581 dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
585 static int i915_quiescent(struct drm_device * dev)
587 drm_i915_private_t *dev_priv = dev->dev_private;
589 i915_kernel_lost_context(dev);
590 return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
593 static int i915_flush_ioctl(struct drm_device *dev, void *data,
594 struct drm_file *file_priv)
598 RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
600 mutex_lock(&dev->struct_mutex);
601 ret = i915_quiescent(dev);
602 mutex_unlock(&dev->struct_mutex);
607 static int i915_batchbuffer(struct drm_device *dev, void *data,
608 struct drm_file *file_priv)
610 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
611 u32 *hw_status = dev_priv->hw_status_page;
612 drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
613 dev_priv->sarea_priv;
614 drm_i915_batchbuffer_t *batch = data;
617 if (!dev_priv->allow_batchbuffer) {
618 DRM_ERROR("Batchbuffer ioctl disabled\n");
622 DRM_DEBUG("i915 batchbuffer, start %x used %d cliprects %d\n",
623 batch->start, batch->used, batch->num_cliprects);
625 RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
627 if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects,
628 batch->num_cliprects *
629 sizeof(struct drm_clip_rect)))
632 mutex_lock(&dev->struct_mutex);
633 ret = i915_dispatch_batchbuffer(dev, batch);
634 mutex_unlock(&dev->struct_mutex);
637 sarea_priv->last_dispatch = (int)hw_status[5];
641 static int i915_cmdbuffer(struct drm_device *dev, void *data,
642 struct drm_file *file_priv)
644 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
645 u32 *hw_status = dev_priv->hw_status_page;
646 drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
647 dev_priv->sarea_priv;
648 drm_i915_cmdbuffer_t *cmdbuf = data;
651 DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
652 cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects);
654 RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
656 if (cmdbuf->num_cliprects &&
657 DRM_VERIFYAREA_READ(cmdbuf->cliprects,
658 cmdbuf->num_cliprects *
659 sizeof(struct drm_clip_rect))) {
660 DRM_ERROR("Fault accessing cliprects\n");
664 mutex_lock(&dev->struct_mutex);
665 ret = i915_dispatch_cmdbuffer(dev, cmdbuf);
666 mutex_unlock(&dev->struct_mutex);
668 DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
673 sarea_priv->last_dispatch = (int)hw_status[5];
677 static int i915_flip_bufs(struct drm_device *dev, void *data,
678 struct drm_file *file_priv)
682 DRM_DEBUG("%s\n", __func__);
684 RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
686 mutex_lock(&dev->struct_mutex);
687 ret = i915_dispatch_flip(dev);
688 mutex_unlock(&dev->struct_mutex);
693 static int i915_getparam(struct drm_device *dev, void *data,
694 struct drm_file *file_priv)
696 drm_i915_private_t *dev_priv = dev->dev_private;
697 drm_i915_getparam_t *param = data;
701 DRM_ERROR("called with no initialization\n");
705 switch (param->param) {
706 case I915_PARAM_IRQ_ACTIVE:
707 value = dev->pdev->irq ? 1 : 0;
709 case I915_PARAM_ALLOW_BATCHBUFFER:
710 value = dev_priv->allow_batchbuffer ? 1 : 0;
712 case I915_PARAM_LAST_DISPATCH:
713 value = READ_BREADCRUMB(dev_priv);
715 case I915_PARAM_CHIPSET_ID:
716 value = dev->pci_device;
718 case I915_PARAM_HAS_GEM:
722 DRM_ERROR("Unknown parameter %d\n", param->param);
726 if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
727 DRM_ERROR("DRM_COPY_TO_USER failed\n");
734 static int i915_setparam(struct drm_device *dev, void *data,
735 struct drm_file *file_priv)
737 drm_i915_private_t *dev_priv = dev->dev_private;
738 drm_i915_setparam_t *param = data;
741 DRM_ERROR("called with no initialization\n");
745 switch (param->param) {
746 case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
748 case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
749 dev_priv->tex_lru_log_granularity = param->value;
751 case I915_SETPARAM_ALLOW_BATCHBUFFER:
752 dev_priv->allow_batchbuffer = param->value;
755 DRM_ERROR("unknown parameter %d\n", param->param);
762 static int i915_set_status_page(struct drm_device *dev, void *data,
763 struct drm_file *file_priv)
765 drm_i915_private_t *dev_priv = dev->dev_private;
766 drm_i915_hws_addr_t *hws = data;
768 if (!I915_NEED_GFX_HWS(dev))
772 DRM_ERROR("called with no initialization\n");
776 printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws->addr);
778 dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12);
780 dev_priv->hws_map.offset = dev->agp->base + hws->addr;
781 dev_priv->hws_map.size = 4*1024;
782 dev_priv->hws_map.type = 0;
783 dev_priv->hws_map.flags = 0;
784 dev_priv->hws_map.mtrr = 0;
786 drm_core_ioremap(&dev_priv->hws_map, dev);
787 if (dev_priv->hws_map.handle == NULL) {
788 i915_dma_cleanup(dev);
789 dev_priv->status_gfx_addr = 0;
790 DRM_ERROR("can not ioremap virtual address for"
791 " G33 hw status page\n");
794 dev_priv->hw_status_page = dev_priv->hws_map.handle;
796 memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
797 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
798 DRM_DEBUG("load hws HWS_PGA with gfx mem 0x%x\n",
799 dev_priv->status_gfx_addr);
800 DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page);
804 int i915_driver_load(struct drm_device *dev, unsigned long flags)
806 struct drm_i915_private *dev_priv = dev->dev_private;
807 unsigned long base, size;
808 int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1;
810 /* i915 has 4 more counters */
812 dev->types[6] = _DRM_STAT_IRQ;
813 dev->types[7] = _DRM_STAT_PRIMARY;
814 dev->types[8] = _DRM_STAT_SECONDARY;
815 dev->types[9] = _DRM_STAT_DMA;
817 dev_priv = drm_alloc(sizeof(drm_i915_private_t), DRM_MEM_DRIVER);
818 if (dev_priv == NULL)
821 memset(dev_priv, 0, sizeof(drm_i915_private_t));
823 dev->dev_private = (void *)dev_priv;
826 /* Add register map (needed for suspend/resume) */
827 base = drm_get_resource_start(dev, mmio_bar);
828 size = drm_get_resource_len(dev, mmio_bar);
830 dev_priv->regs = ioremap(base, size);
835 if (!I915_NEED_GFX_HWS(dev)) {
836 ret = i915_init_phys_hws(dev);
841 /* On the 945G/GM, the chipset reports the MSI capability on the
842 * integrated graphics even though the support isn't actually there
843 * according to the published specs. It doesn't appear to function
844 * correctly in testing on 945G.
845 * This may be a side effect of MSI having been made available for PEG
846 * and the registers being closely associated.
848 if (!IS_I945G(dev) && !IS_I945GM(dev))
849 if (pci_enable_msi(dev->pdev))
850 DRM_ERROR("failed to enable MSI\n");
852 intel_opregion_init(dev);
854 spin_lock_init(&dev_priv->user_irq_lock);
859 int i915_driver_unload(struct drm_device *dev)
861 struct drm_i915_private *dev_priv = dev->dev_private;
863 if (dev->pdev->msi_enabled)
864 pci_disable_msi(dev->pdev);
868 if (dev_priv->regs != NULL)
869 iounmap(dev_priv->regs);
871 intel_opregion_free(dev);
873 drm_free(dev->dev_private, sizeof(drm_i915_private_t),
879 int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv)
881 struct drm_i915_file_private *i915_file_priv;
884 i915_file_priv = (struct drm_i915_file_private *)
885 drm_alloc(sizeof(*i915_file_priv), DRM_MEM_FILES);
890 file_priv->driver_priv = i915_file_priv;
892 i915_file_priv->mm.last_gem_seqno = 0;
893 i915_file_priv->mm.last_gem_throttle_seqno = 0;
898 void i915_driver_lastclose(struct drm_device * dev)
900 drm_i915_private_t *dev_priv = dev->dev_private;
905 i915_gem_lastclose(dev);
907 if (dev_priv->agp_heap)
908 i915_mem_takedown(&(dev_priv->agp_heap));
910 i915_dma_cleanup(dev);
913 void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
915 drm_i915_private_t *dev_priv = dev->dev_private;
916 i915_mem_release(dev, file_priv, dev_priv->agp_heap);
919 void i915_driver_postclose(struct drm_device *dev, struct drm_file *file_priv)
921 struct drm_i915_file_private *i915_file_priv = file_priv->driver_priv;
923 drm_free(i915_file_priv, sizeof(*i915_file_priv), DRM_MEM_FILES);
926 struct drm_ioctl_desc i915_ioctls[] = {
927 DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
928 DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
929 DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH),
930 DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH),
931 DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH),
932 DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH),
933 DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH),
934 DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
935 DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH),
936 DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH),
937 DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
938 DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH),
939 DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP, i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
940 DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE, i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
941 DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH ),
942 DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH),
943 DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH),
944 DRM_IOCTL_DEF(DRM_I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
945 DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH),
946 DRM_IOCTL_DEF(DRM_I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
947 DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
948 DRM_IOCTL_DEF(DRM_I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH),
949 DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH),
950 DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
951 DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
952 DRM_IOCTL_DEF(DRM_I915_GEM_CREATE, i915_gem_create_ioctl, 0),
953 DRM_IOCTL_DEF(DRM_I915_GEM_PREAD, i915_gem_pread_ioctl, 0),
954 DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE, i915_gem_pwrite_ioctl, 0),
955 DRM_IOCTL_DEF(DRM_I915_GEM_MMAP, i915_gem_mmap_ioctl, 0),
956 DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, 0),
957 DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, 0),
958 DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING, i915_gem_set_tiling, 0),
959 DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING, i915_gem_get_tiling, 0),
962 int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
965 * Determine if the device really is AGP or not.
967 * All Intel graphics chipsets are treated as AGP, even if they are really
970 * \param dev The device to be tested.
973 * A value of 1 is always retured to indictate every i9x5 is AGP.
975 int i915_driver_device_is_agp(struct drm_device * dev)