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 struct drm_i915_private *dev_priv = dev->dev_private;
42 struct drm_i915_ring_buffer *ring = &(dev_priv->ring);
43 u32 last_head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
44 u32 acthd_reg = IS_I965G(dev) ? ACTHD_I965 : ACTHD;
45 u32 last_acthd = I915_READ(acthd_reg);
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 (ring->head != last_head)
61 if (acthd != last_acthd)
64 last_head = ring->head;
66 msleep_interruptible (10);
72 #if I915_RING_VALIDATE
74 * Validate the cached ring tail value
76 * If the X server writes to the ring and DRM doesn't
77 * reload the head and tail pointers, it will end up writing
78 * data to the wrong place in the ring, causing havoc.
80 void i915_ring_validate(struct drm_device *dev, const char *func, int line)
82 struct drm_i915_private *dev_priv = dev->dev_private;
83 drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
84 u32 tail = I915_READ(LP_RING+RING_TAIL) & HEAD_ADDR;
85 u32 head = I915_READ(LP_RING+RING_HEAD) & HEAD_ADDR;
87 if (tail != ring->tail) {
88 DRM_ERROR("%s:%d head sw %x, hw %x. tail sw %x hw %x\n",
90 ring->head, head, ring->tail, tail);
96 void i915_kernel_lost_context(struct drm_device * dev)
98 struct drm_i915_private *dev_priv = dev->dev_private;
99 struct drm_i915_ring_buffer *ring = &(dev_priv->ring);
101 /* we should never lose context on the ring with modesetting
102 * as we don't expose it to userspace */
103 if (drm_core_check_feature(dev, DRIVER_MODESET))
106 ring->head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
107 ring->tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
108 ring->space = ring->head - (ring->tail + 8);
110 ring->space += ring->Size;
113 int i915_dma_cleanup(struct drm_device * dev)
115 struct drm_i915_private *dev_priv = dev->dev_private;
117 if (drm_core_check_feature(dev, DRIVER_MODESET))
120 /* Make sure interrupts are disabled here because the uninstall ioctl
121 * may not have been called from userspace and after dev_private
122 * is freed, it's too late.
124 if (dev->irq_enabled)
125 drm_irq_uninstall(dev);
127 if (dev_priv->ring.virtual_start) {
128 drm_core_ioremapfree(&dev_priv->ring.map, dev);
129 dev_priv->ring.virtual_start = 0;
130 dev_priv->ring.map.handle = 0;
131 dev_priv->ring.map.size = 0;
132 dev_priv->ring.Size = 0;
139 #define DRI2_SAREA_BLOCK_TYPE(b) ((b) >> 16)
140 #define DRI2_SAREA_BLOCK_SIZE(b) ((b) & 0xffff)
141 #define DRI2_SAREA_BLOCK_NEXT(p) \
142 ((void *) ((unsigned char *) (p) + \
143 DRI2_SAREA_BLOCK_SIZE(*(unsigned int *) p)))
145 #define DRI2_SAREA_BLOCK_END 0x0000
146 #define DRI2_SAREA_BLOCK_LOCK 0x0001
147 #define DRI2_SAREA_BLOCK_EVENT_BUFFER 0x0002
150 setup_dri2_sarea(struct drm_device * dev,
151 struct drm_file *file_priv,
152 drm_i915_init_t * init)
154 struct drm_i915_private *dev_priv = dev->dev_private;
156 unsigned int *p, *end, *next;
158 mutex_lock(&dev->struct_mutex);
160 drm_lookup_buffer_object(file_priv,
161 init->sarea_handle, 1);
162 mutex_unlock(&dev->struct_mutex);
164 if (!dev_priv->sarea_bo) {
165 DRM_ERROR("did not find sarea bo\n");
169 ret = drm_bo_kmap(dev_priv->sarea_bo, 0,
170 dev_priv->sarea_bo->num_pages,
171 &dev_priv->sarea_kmap);
173 DRM_ERROR("could not map sarea bo\n");
177 p = dev_priv->sarea_kmap.virtual;
178 end = (void *) p + (dev_priv->sarea_bo->num_pages << PAGE_SHIFT);
179 while (p < end && DRI2_SAREA_BLOCK_TYPE(*p) != DRI2_SAREA_BLOCK_END) {
180 switch (DRI2_SAREA_BLOCK_TYPE(*p)) {
181 case DRI2_SAREA_BLOCK_LOCK:
182 dev->primary->master->lock.hw_lock = (void *) (p + 1);
183 dev->sigdata.lock = dev->primary->master->lock.hw_lock;
186 next = DRI2_SAREA_BLOCK_NEXT(p);
187 if (next <= p || end < next) {
188 DRM_ERROR("malformed dri2 sarea: next is %p should be within %p-%p\n",
199 static int i915_initialize(struct drm_device * dev,
200 struct drm_file *file_priv,
201 drm_i915_init_t * init)
203 struct drm_i915_private *dev_priv = dev->dev_private;
204 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
206 if (!drm_core_check_feature(dev, DRIVER_MODESET)) {
207 if (init->mmio_offset != 0)
208 dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
209 if (!dev_priv->mmio_map) {
210 i915_dma_cleanup(dev);
211 DRM_ERROR("can not find mmio map!\n");
217 if (init->ring_size != 0) {
218 dev_priv->ring.Size = init->ring_size;
219 dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
220 dev_priv->ring.map.offset = init->ring_start;
221 dev_priv->ring.map.size = init->ring_size;
222 dev_priv->ring.map.type = 0;
223 dev_priv->ring.map.flags = 0;
224 dev_priv->ring.map.mtrr = 0;
225 drm_core_ioremap(&dev_priv->ring.map, dev);
227 if (dev_priv->ring.map.handle == NULL) {
228 i915_dma_cleanup(dev);
229 DRM_ERROR("can not ioremap virtual address for"
233 dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
236 dev_priv->cpp = init->cpp;
237 master_priv->sarea_priv->pf_current_page = 0;
239 /* We are using separate values as placeholders for mechanisms for
240 * private backbuffer/depthbuffer usage.
243 /* Allow hardware batchbuffers unless told otherwise.
245 dev_priv->allow_batchbuffer = 1;
247 /* Enable vblank on pipe A for older X servers
249 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
252 if (init->func == I915_INIT_DMA2) {
253 int ret = setup_dri2_sarea(dev, file_priv, init);
255 i915_dma_cleanup(dev);
256 DRM_ERROR("could not set up dri2 sarea\n");
265 static int i915_dma_resume(struct drm_device * dev)
267 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
271 if (drm_core_check_feature(dev, DRIVER_MODESET))
274 if (dev_priv->ring.map.handle == NULL) {
275 DRM_ERROR("can not ioremap virtual address for"
280 /* Program Hardware Status Page */
281 if (!dev_priv->hw_status_page) {
282 DRM_ERROR("Can not find hardware status page\n");
285 DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
287 if (dev_priv->status_gfx_addr != 0)
288 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
290 I915_WRITE(HWS_PGA, dev_priv->dma_status_page);
291 DRM_DEBUG("Enabled hardware status page\n");
296 static int i915_dma_init(struct drm_device *dev, void *data,
297 struct drm_file *file_priv)
299 struct drm_i915_init *init = data;
302 switch (init->func) {
305 retcode = i915_initialize(dev, file_priv, init);
307 case I915_CLEANUP_DMA:
308 retcode = i915_dma_cleanup(dev);
310 case I915_RESUME_DMA:
311 retcode = i915_dma_resume(dev);
321 /* Implement basically the same security restrictions as hardware does
322 * for MI_BATCH_NON_SECURE. These can be made stricter at any time.
324 * Most of the calculations below involve calculating the size of a
325 * particular instruction. It's important to get the size right as
326 * that tells us where the next instruction to check is. Any illegal
327 * instruction detected will be given a size of zero, which is a
328 * signal to abort the rest of the buffer.
330 static int do_validate_cmd(int cmd)
332 switch (((cmd >> 29) & 0x7)) {
334 switch ((cmd >> 23) & 0x3f) {
336 return 1; /* MI_NOOP */
338 return 1; /* MI_FLUSH */
340 return 0; /* disallow everything else */
344 return 0; /* reserved */
346 return (cmd & 0xff) + 2; /* 2d commands */
348 if (((cmd >> 24) & 0x1f) <= 0x18)
351 switch ((cmd >> 24) & 0x1f) {
355 switch ((cmd >> 16) & 0xff) {
357 return (cmd & 0x1f) + 2;
359 return (cmd & 0xf) + 2;
361 return (cmd & 0xffff) + 2;
365 return (cmd & 0xffff) + 1;
369 if ((cmd & (1 << 23)) == 0) /* inline vertices */
370 return (cmd & 0x1ffff) + 2;
371 else if (cmd & (1 << 17)) /* indirect random */
372 if ((cmd & 0xffff) == 0)
373 return 0; /* unknown length, too hard */
375 return (((cmd & 0xffff) + 1) / 2) + 1;
377 return 2; /* indirect sequential */
388 static int validate_cmd(int cmd)
390 int ret = do_validate_cmd(cmd);
392 /* printk("validate_cmd( %x ): %d\n", cmd, ret); */
397 static int i915_emit_cmds(struct drm_device *dev, int __user *buffer,
400 struct drm_i915_private *dev_priv = dev->dev_private;
404 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
407 BEGIN_LP_RING((dwords+1)&~1);
409 for (i = 0; i < dwords;) {
412 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd)))
415 if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords)
421 if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i],
437 int i915_emit_box(struct drm_device * dev,
438 struct drm_clip_rect __user * boxes,
439 int i, int DR1, int DR4)
441 struct drm_i915_private *dev_priv = dev->dev_private;
442 struct drm_clip_rect box;
445 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
449 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
450 DRM_ERROR("Bad box %d,%d..%d,%d\n",
451 box.x1, box.y1, box.x2, box.y2);
457 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
458 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
459 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
464 OUT_RING(GFX_OP_DRAWRECT_INFO);
466 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
467 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
476 /* XXX: Emitting the counter should really be moved to part of the IRQ
477 * emit. For now, do it in both places:
480 void i915_emit_breadcrumb(struct drm_device *dev)
482 struct drm_i915_private *dev_priv = dev->dev_private;
483 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
486 if (++dev_priv->counter > BREADCRUMB_MASK) {
487 dev_priv->counter = 1;
488 DRM_DEBUG("Breadcrumb counter wrapped around\n");
491 master_priv->sarea_priv->last_enqueue = dev_priv->counter;
494 OUT_RING(MI_STORE_DWORD_INDEX);
495 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
496 OUT_RING(dev_priv->counter);
502 int i915_emit_mi_flush(struct drm_device *dev, uint32_t flush)
504 struct drm_i915_private *dev_priv = dev->dev_private;
505 uint32_t flush_cmd = MI_FLUSH;
510 i915_kernel_lost_context(dev);
523 static int i915_dispatch_cmdbuffer(struct drm_device * dev,
524 struct drm_i915_cmdbuffer * cmd)
526 int nbox = cmd->num_cliprects;
527 int i = 0, count, ret;
530 DRM_ERROR("alignment\n");
534 i915_kernel_lost_context(dev);
536 count = nbox ? nbox : 1;
538 for (i = 0; i < count; i++) {
540 ret = i915_emit_box(dev, cmd->cliprects, i,
546 ret = i915_emit_cmds(dev, (int __user *)cmd->buf, cmd->sz / 4);
551 i915_emit_breadcrumb(dev);
555 int i915_dispatch_batchbuffer(struct drm_device * dev,
556 drm_i915_batchbuffer_t * batch)
558 struct drm_i915_private *dev_priv = dev->dev_private;
559 struct drm_clip_rect __user *boxes = batch->cliprects;
560 int nbox = batch->num_cliprects;
564 if ((batch->start | batch->used) & 0x7) {
565 DRM_ERROR("alignment\n");
569 i915_kernel_lost_context(dev);
571 count = nbox ? nbox : 1;
573 for (i = 0; i < count; i++) {
575 int ret = i915_emit_box(dev, boxes, i,
576 batch->DR1, batch->DR4);
581 if (IS_I830(dev) || IS_845G(dev)) {
583 OUT_RING(MI_BATCH_BUFFER);
584 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
585 OUT_RING(batch->start + batch->used - 4);
591 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
592 OUT_RING(batch->start);
594 OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
595 OUT_RING(batch->start | MI_BATCH_NON_SECURE);
601 i915_emit_breadcrumb(dev);
605 static void i915_do_dispatch_flip(struct drm_device * dev, int plane, int sync)
607 struct drm_i915_private *dev_priv = dev->dev_private;
608 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
609 u32 num_pages, current_page, next_page, dspbase;
610 int shift = 2 * plane, x, y;
613 /* Calculate display base offset */
614 num_pages = master_priv->sarea_priv->third_handle ? 3 : 2;
615 current_page = (master_priv->sarea_priv->pf_current_page >> shift) & 0x3;
616 next_page = (current_page + 1) % num_pages;
621 dspbase = master_priv->sarea_priv->front_offset;
624 dspbase = master_priv->sarea_priv->back_offset;
627 dspbase = master_priv->sarea_priv->third_offset;
632 x = master_priv->sarea_priv->planeA_x;
633 y = master_priv->sarea_priv->planeA_y;
635 x = master_priv->sarea_priv->planeB_x;
636 y = master_priv->sarea_priv->planeB_y;
639 dspbase += (y * master_priv->sarea_priv->pitch + x) * dev_priv->cpp;
641 DRM_DEBUG("plane=%d current_page=%d dspbase=0x%x\n", plane, current_page,
646 (MI_WAIT_FOR_EVENT | (plane ? MI_WAIT_FOR_PLANE_B_FLIP :
647 MI_WAIT_FOR_PLANE_A_FLIP)));
648 OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | (sync ? 0 : ASYNC_FLIP) |
649 (plane ? DISPLAY_PLANE_B : DISPLAY_PLANE_A));
650 OUT_RING(master_priv->sarea_priv->pitch * dev_priv->cpp);
654 master_priv->sarea_priv->pf_current_page &= ~(0x3 << shift);
655 master_priv->sarea_priv->pf_current_page |= next_page << shift;
658 void i915_dispatch_flip(struct drm_device * dev, int planes, int sync)
660 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
663 DRM_DEBUG("planes=0x%x pfCurrentPage=%d\n",
664 planes, master_priv->sarea_priv->pf_current_page);
666 i915_emit_mi_flush(dev, MI_READ_FLUSH | MI_EXE_FLUSH);
668 for (i = 0; i < 2; i++)
669 if (planes & (1 << i))
670 i915_do_dispatch_flip(dev, i, sync);
672 i915_emit_breadcrumb(dev);
675 int i915_quiescent(struct drm_device *dev)
677 struct drm_i915_private *dev_priv = dev->dev_private;
680 i915_kernel_lost_context(dev);
681 ret = i915_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__);
684 i915_kernel_lost_context (dev);
685 DRM_ERROR ("not quiescent head %08x tail %08x space %08x\n",
688 dev_priv->ring.space);
693 static int i915_flush_ioctl(struct drm_device *dev, void *data,
694 struct drm_file *file_priv)
697 LOCK_TEST_WITH_RETURN(dev, file_priv);
699 return i915_quiescent(dev);
702 static int i915_batchbuffer(struct drm_device *dev, void *data,
703 struct drm_file *file_priv)
705 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
706 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
707 drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
708 master_priv->sarea_priv;
709 drm_i915_batchbuffer_t *batch = data;
712 if (!dev_priv->allow_batchbuffer) {
713 DRM_ERROR("Batchbuffer ioctl disabled\n");
717 DRM_DEBUG("i915 batchbuffer, start %x used %d cliprects %d\n",
718 batch->start, batch->used, batch->num_cliprects);
720 LOCK_TEST_WITH_RETURN(dev, file_priv);
722 if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects,
723 batch->num_cliprects *
724 sizeof(struct drm_clip_rect)))
727 ret = i915_dispatch_batchbuffer(dev, batch);
729 sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
733 static int i915_cmdbuffer(struct drm_device *dev, void *data,
734 struct drm_file *file_priv)
736 struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
737 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
738 struct drm_i915_sarea *sarea_priv = (struct drm_i915_sarea *)
739 master_priv->sarea_priv;
740 struct drm_i915_cmdbuffer *cmdbuf = data;
743 DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
744 cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects);
746 LOCK_TEST_WITH_RETURN(dev, file_priv);
748 if (cmdbuf->num_cliprects &&
749 DRM_VERIFYAREA_READ(cmdbuf->cliprects,
750 cmdbuf->num_cliprects *
751 sizeof(struct drm_clip_rect))) {
752 DRM_ERROR("Fault accessing cliprects\n");
756 ret = i915_dispatch_cmdbuffer(dev, cmdbuf);
758 DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
762 sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
766 #if defined(DRM_DEBUG_CODE)
767 #define DRM_DEBUG_RELOCATION (drm_debug != 0)
769 #define DRM_DEBUG_RELOCATION 0
772 int i915_do_cleanup_pageflip(struct drm_device * dev)
774 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
775 int i, planes, num_pages;
778 num_pages = master_priv->sarea_priv->third_handle ? 3 : 2;
779 for (i = 0, planes = 0; i < 2; i++) {
780 if (master_priv->sarea_priv->pf_current_page & (0x3 << (2 * i))) {
781 master_priv->sarea_priv->pf_current_page =
782 (master_priv->sarea_priv->pf_current_page &
783 ~(0x3 << (2 * i))) | ((num_pages - 1) << (2 * i));
790 i915_dispatch_flip(dev, planes, 0);
795 static int i915_flip_bufs(struct drm_device *dev, void *data, struct drm_file *file_priv)
797 struct drm_i915_flip *param = data;
801 LOCK_TEST_WITH_RETURN(dev, file_priv);
803 /* This is really planes */
804 if (param->pipes & ~0x3) {
805 DRM_ERROR("Invalid planes 0x%x, only <= 0x3 is valid\n",
810 i915_dispatch_flip(dev, param->pipes, 0);
816 static int i915_getparam(struct drm_device *dev, void *data,
817 struct drm_file *file_priv)
819 struct drm_i915_private *dev_priv = dev->dev_private;
820 struct drm_i915_getparam *param = data;
824 DRM_ERROR("called with no initialization\n");
828 switch (param->param) {
829 case I915_PARAM_IRQ_ACTIVE:
830 value = dev->irq_enabled ? 1 : 0;
832 case I915_PARAM_ALLOW_BATCHBUFFER:
833 value = dev_priv->allow_batchbuffer ? 1 : 0;
835 case I915_PARAM_LAST_DISPATCH:
836 value = READ_BREADCRUMB(dev_priv);
838 case I915_PARAM_CHIPSET_ID:
839 value = dev->pci_device;
841 case I915_PARAM_HAS_GEM:
845 DRM_ERROR("Unknown parameter %d\n", param->param);
849 if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
850 DRM_ERROR("DRM_COPY_TO_USER failed\n");
857 static int i915_setparam(struct drm_device *dev, void *data,
858 struct drm_file *file_priv)
860 struct drm_i915_private *dev_priv = dev->dev_private;
861 drm_i915_setparam_t *param = data;
864 DRM_ERROR("called with no initialization\n");
868 switch (param->param) {
869 case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
871 case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
872 dev_priv->tex_lru_log_granularity = param->value;
874 case I915_SETPARAM_ALLOW_BATCHBUFFER:
875 dev_priv->allow_batchbuffer = param->value;
878 DRM_ERROR("unknown parameter %d\n", param->param);
885 drm_i915_mmio_entry_t mmio_table[] = {
886 [MMIO_REGS_PS_DEPTH_COUNT] = {
887 I915_MMIO_MAY_READ|I915_MMIO_MAY_WRITE,
891 [MMIO_REGS_DOVSTA] = {
896 [MMIO_REGS_GAMMA] = {
897 I915_MMIO_MAY_READ|I915_MMIO_MAY_WRITE,
901 [MMIO_REGS_FENCE] = {
902 I915_MMIO_MAY_READ|I915_MMIO_MAY_WRITE,
906 [MMIO_REGS_FENCE_NEW] = {
907 I915_MMIO_MAY_READ|I915_MMIO_MAY_WRITE,
913 static int mmio_table_size = sizeof(mmio_table)/sizeof(drm_i915_mmio_entry_t);
915 static int i915_mmio(struct drm_device *dev, void *data,
916 struct drm_file *file_priv)
919 struct drm_i915_private *dev_priv = dev->dev_private;
920 drm_i915_mmio_entry_t *e;
921 drm_i915_mmio_t *mmio = data;
926 DRM_ERROR("called with no initialization\n");
930 if (mmio->reg >= mmio_table_size)
933 e = &mmio_table[mmio->reg];
934 base = (u8 *) dev_priv->mmio_map->handle + e->offset;
936 switch (mmio->read_write) {
938 if (!(e->flag & I915_MMIO_MAY_READ))
940 for (i = 0; i < e->size / 4; i++)
941 buf[i] = I915_READ(e->offset + i * 4);
942 if (DRM_COPY_TO_USER(mmio->data, buf, e->size)) {
943 DRM_ERROR("DRM_COPY_TO_USER failed\n");
948 case I915_MMIO_WRITE:
949 if (!(e->flag & I915_MMIO_MAY_WRITE))
951 if (DRM_COPY_FROM_USER(buf, mmio->data, e->size)) {
952 DRM_ERROR("DRM_COPY_TO_USER failed\n");
955 for (i = 0; i < e->size / 4; i++)
956 I915_WRITE(e->offset + i * 4, buf[i]);
962 static int i915_set_status_page(struct drm_device *dev, void *data,
963 struct drm_file *file_priv)
965 struct drm_i915_private *dev_priv = dev->dev_private;
966 drm_i915_hws_addr_t *hws = data;
968 if (!I915_NEED_GFX_HWS(dev))
972 DRM_ERROR("called with no initialization\n");
976 if (drm_core_check_feature(dev, DRIVER_MODESET))
979 DRM_DEBUG("set status page addr 0x%08x\n", (u32)hws->addr);
981 dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12);
983 dev_priv->hws_map.offset = dev->agp->base + hws->addr;
984 dev_priv->hws_map.size = 4*1024;
985 dev_priv->hws_map.type = 0;
986 dev_priv->hws_map.flags = 0;
987 dev_priv->hws_map.mtrr = 0;
989 drm_core_ioremap(&dev_priv->hws_map, dev);
990 if (dev_priv->hws_map.handle == NULL) {
991 i915_dma_cleanup(dev);
992 dev_priv->status_gfx_addr = 0;
993 DRM_ERROR("can not ioremap virtual address for"
994 " G33 hw status page\n");
998 dev_priv->hw_status_page = dev_priv->hws_map.handle;
1000 memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
1001 I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr);
1002 DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page);
1007 struct drm_ioctl_desc i915_ioctls[] = {
1008 DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER),
1009 DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
1010 DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH),
1011 DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH),
1012 DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH),
1013 DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH),
1014 DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH),
1015 DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER),
1016 DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH),
1017 DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH),
1018 DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1019 DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH),
1020 DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP, i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
1021 DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE, i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
1022 DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH ),
1023 DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH),
1024 DRM_IOCTL_DEF(DRM_I915_MMIO, i915_mmio, DRM_AUTH),
1025 DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH),
1026 DRM_IOCTL_DEF(DRM_I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH),
1027 DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH),
1028 DRM_IOCTL_DEF(DRM_I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
1029 DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
1030 DRM_IOCTL_DEF(DRM_I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH),
1031 DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH),
1032 DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH),
1033 DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH),
1034 DRM_IOCTL_DEF(DRM_I915_GEM_CREATE, i915_gem_create_ioctl, 0),
1035 DRM_IOCTL_DEF(DRM_I915_GEM_PREAD, i915_gem_pread_ioctl, 0),
1036 DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE, i915_gem_pwrite_ioctl, 0),
1037 DRM_IOCTL_DEF(DRM_I915_GEM_MMAP, i915_gem_mmap_ioctl, 0),
1038 DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, 0),
1039 DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, 0),
1040 DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING, i915_gem_set_tiling, 0),
1041 DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING, i915_gem_get_tiling, 0),
1044 int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
1047 * Determine if the device really is AGP or not.
1049 * All Intel graphics chipsets are treated as AGP, even if they are really
1052 * \param dev The device to be tested.
1055 * A value of 1 is always retured to indictate every i9x5 is AGP.
1057 int i915_driver_device_is_agp(struct drm_device * dev)