1 /* i830_dma.c -- DMA support for the I830 -*- linux-c -*-
2 * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
27 * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
28 * Jeff Hartmann <jhartmann@valinux.com>
29 * Keith Whitwell <keith@tungstengraphics.com>
30 * Abraham vd Merwe <abraham@2d3d.co.za>
38 #include <linux/interrupt.h> /* For task queue support */
39 #include <linux/pagemap.h>
40 #include <linux/delay.h>
41 #include <linux/slab.h>
42 #include <asm/uaccess.h>
44 #define I830_BUF_FREE 2
45 #define I830_BUF_CLIENT 1
46 #define I830_BUF_HARDWARE 0
48 #define I830_BUF_UNMAPPED 0
49 #define I830_BUF_MAPPED 1
51 static struct drm_buf
*i830_freelist_get(struct drm_device
* dev
)
53 struct drm_device_dma
*dma
= dev
->dma
;
57 /* Linear search might not be the best solution */
59 for (i
= 0; i
< dma
->buf_count
; i
++) {
60 struct drm_buf
*buf
= dma
->buflist
[i
];
61 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
62 /* In use is already a pointer */
63 used
= cmpxchg(buf_priv
->in_use
, I830_BUF_FREE
,
65 if (used
== I830_BUF_FREE
) {
72 /* This should only be called if the buffer is not sent to the hardware
73 * yet, the hardware updates in use for us once its on the ring buffer.
76 static int i830_freelist_put(struct drm_device
* dev
, struct drm_buf
* buf
)
78 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
81 /* In use is already a pointer */
82 used
= cmpxchg(buf_priv
->in_use
, I830_BUF_CLIENT
, I830_BUF_FREE
);
83 if (used
!= I830_BUF_CLIENT
) {
84 DRM_ERROR("Freeing buffer thats not in use : %d\n", buf
->idx
);
91 static int i830_mmap_buffers(struct file
*filp
, struct vm_area_struct
*vma
)
93 struct drm_file
*priv
= filp
->private_data
;
94 struct drm_device
*dev
;
95 drm_i830_private_t
*dev_priv
;
97 drm_i830_buf_priv_t
*buf_priv
;
100 dev
= priv
->minor
->dev
;
101 dev_priv
= dev
->dev_private
;
102 buf
= dev_priv
->mmap_buffer
;
103 buf_priv
= buf
->dev_private
;
105 vma
->vm_flags
|= (VM_IO
| VM_DONTCOPY
);
108 buf_priv
->currently_mapped
= I830_BUF_MAPPED
;
111 if (io_remap_pfn_range(vma
, vma
->vm_start
,
113 vma
->vm_end
- vma
->vm_start
, vma
->vm_page_prot
))
118 static const struct file_operations i830_buffer_fops
= {
120 .release
= drm_release
,
121 .unlocked_ioctl
= drm_ioctl
,
122 .mmap
= i830_mmap_buffers
,
123 .fasync
= drm_fasync
,
126 static int i830_map_buffer(struct drm_buf
* buf
, struct drm_file
*file_priv
)
128 struct drm_device
*dev
= file_priv
->minor
->dev
;
129 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
130 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
131 const struct file_operations
*old_fops
;
132 unsigned long virtual;
135 if (buf_priv
->currently_mapped
== I830_BUF_MAPPED
)
138 down_write(¤t
->mm
->mmap_sem
);
139 old_fops
= file_priv
->filp
->f_op
;
140 file_priv
->filp
->f_op
= &i830_buffer_fops
;
141 dev_priv
->mmap_buffer
= buf
;
142 virtual = do_mmap(file_priv
->filp
, 0, buf
->total
, PROT_READ
| PROT_WRITE
,
143 MAP_SHARED
, buf
->bus_address
);
144 dev_priv
->mmap_buffer
= NULL
;
145 file_priv
->filp
->f_op
= old_fops
;
146 if (IS_ERR((void *)virtual)) { /* ugh */
148 DRM_ERROR("mmap error\n");
149 retcode
= PTR_ERR((void *)virtual);
150 buf_priv
->virtual = NULL
;
152 buf_priv
->virtual = (void __user
*)virtual;
154 up_write(¤t
->mm
->mmap_sem
);
159 static int i830_unmap_buffer(struct drm_buf
* buf
)
161 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
164 if (buf_priv
->currently_mapped
!= I830_BUF_MAPPED
)
167 down_write(¤t
->mm
->mmap_sem
);
168 retcode
= do_munmap(current
->mm
,
169 (unsigned long)buf_priv
->virtual,
170 (size_t) buf
->total
);
171 up_write(¤t
->mm
->mmap_sem
);
173 buf_priv
->currently_mapped
= I830_BUF_UNMAPPED
;
174 buf_priv
->virtual = NULL
;
179 static int i830_dma_get_buffer(struct drm_device
* dev
, drm_i830_dma_t
* d
,
180 struct drm_file
*file_priv
)
183 drm_i830_buf_priv_t
*buf_priv
;
186 buf
= i830_freelist_get(dev
);
189 DRM_DEBUG("retcode=%d\n", retcode
);
193 retcode
= i830_map_buffer(buf
, file_priv
);
195 i830_freelist_put(dev
, buf
);
196 DRM_ERROR("mapbuf failed, retcode %d\n", retcode
);
199 buf
->file_priv
= file_priv
;
200 buf_priv
= buf
->dev_private
;
202 d
->request_idx
= buf
->idx
;
203 d
->request_size
= buf
->total
;
204 d
->virtual = buf_priv
->virtual;
209 static int i830_dma_cleanup(struct drm_device
* dev
)
211 struct drm_device_dma
*dma
= dev
->dma
;
213 /* Make sure interrupts are disabled here because the uninstall ioctl
214 * may not have been called from userspace and after dev_private
215 * is freed, it's too late.
217 if (dev
->irq_enabled
)
218 drm_irq_uninstall(dev
);
220 if (dev
->dev_private
) {
222 drm_i830_private_t
*dev_priv
=
223 (drm_i830_private_t
*) dev
->dev_private
;
225 if (dev_priv
->ring
.virtual_start
) {
226 drm_core_ioremapfree(&dev_priv
->ring
.map
, dev
);
228 if (dev_priv
->hw_status_page
) {
229 pci_free_consistent(dev
->pdev
, PAGE_SIZE
,
230 dev_priv
->hw_status_page
,
231 dev_priv
->dma_status_page
);
232 /* Need to rewrite hardware status page */
233 I830_WRITE(0x02080, 0x1ffff000);
236 kfree(dev
->dev_private
);
237 dev
->dev_private
= NULL
;
239 for (i
= 0; i
< dma
->buf_count
; i
++) {
240 struct drm_buf
*buf
= dma
->buflist
[i
];
241 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
242 if (buf_priv
->kernel_virtual
&& buf
->total
)
243 drm_core_ioremapfree(&buf_priv
->map
, dev
);
249 int i830_wait_ring(struct drm_device
* dev
, int n
, const char *caller
)
251 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
252 drm_i830_ring_buffer_t
*ring
= &(dev_priv
->ring
);
255 unsigned int last_head
= I830_READ(LP_RING
+ RING_HEAD
) & HEAD_ADDR
;
257 end
= jiffies
+ (HZ
* 3);
258 while (ring
->space
< n
) {
259 ring
->head
= I830_READ(LP_RING
+ RING_HEAD
) & HEAD_ADDR
;
260 ring
->space
= ring
->head
- (ring
->tail
+ 8);
262 ring
->space
+= ring
->Size
;
264 if (ring
->head
!= last_head
) {
265 end
= jiffies
+ (HZ
* 3);
266 last_head
= ring
->head
;
270 if (time_before(end
, jiffies
)) {
271 DRM_ERROR("space: %d wanted %d\n", ring
->space
, n
);
272 DRM_ERROR("lockup\n");
276 dev_priv
->sarea_priv
->perf_boxes
|= I830_BOX_WAIT
;
283 static void i830_kernel_lost_context(struct drm_device
* dev
)
285 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
286 drm_i830_ring_buffer_t
*ring
= &(dev_priv
->ring
);
288 ring
->head
= I830_READ(LP_RING
+ RING_HEAD
) & HEAD_ADDR
;
289 ring
->tail
= I830_READ(LP_RING
+ RING_TAIL
) & TAIL_ADDR
;
290 ring
->space
= ring
->head
- (ring
->tail
+ 8);
292 ring
->space
+= ring
->Size
;
294 if (ring
->head
== ring
->tail
)
295 dev_priv
->sarea_priv
->perf_boxes
|= I830_BOX_RING_EMPTY
;
298 static int i830_freelist_init(struct drm_device
* dev
, drm_i830_private_t
* dev_priv
)
300 struct drm_device_dma
*dma
= dev
->dma
;
302 u32
*hw_status
= (u32
*) (dev_priv
->hw_status_page
+ my_idx
);
305 if (dma
->buf_count
> 1019) {
306 /* Not enough space in the status page for the freelist */
310 for (i
= 0; i
< dma
->buf_count
; i
++) {
311 struct drm_buf
*buf
= dma
->buflist
[i
];
312 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
314 buf_priv
->in_use
= hw_status
++;
315 buf_priv
->my_use_idx
= my_idx
;
318 *buf_priv
->in_use
= I830_BUF_FREE
;
320 buf_priv
->map
.offset
= buf
->bus_address
;
321 buf_priv
->map
.size
= buf
->total
;
322 buf_priv
->map
.type
= _DRM_AGP
;
323 buf_priv
->map
.flags
= 0;
324 buf_priv
->map
.mtrr
= 0;
326 drm_core_ioremap(&buf_priv
->map
, dev
);
327 buf_priv
->kernel_virtual
= buf_priv
->map
.handle
;
332 static int i830_dma_initialize(struct drm_device
* dev
,
333 drm_i830_private_t
* dev_priv
,
334 drm_i830_init_t
* init
)
336 struct drm_map_list
*r_list
;
338 memset(dev_priv
, 0, sizeof(drm_i830_private_t
));
340 list_for_each_entry(r_list
, &dev
->maplist
, head
) {
342 r_list
->map
->type
== _DRM_SHM
&&
343 r_list
->map
->flags
& _DRM_CONTAINS_LOCK
) {
344 dev_priv
->sarea_map
= r_list
->map
;
349 if (!dev_priv
->sarea_map
) {
350 dev
->dev_private
= (void *)dev_priv
;
351 i830_dma_cleanup(dev
);
352 DRM_ERROR("can not find sarea!\n");
355 dev_priv
->mmio_map
= drm_core_findmap(dev
, init
->mmio_offset
);
356 if (!dev_priv
->mmio_map
) {
357 dev
->dev_private
= (void *)dev_priv
;
358 i830_dma_cleanup(dev
);
359 DRM_ERROR("can not find mmio map!\n");
362 dev
->agp_buffer_token
= init
->buffers_offset
;
363 dev
->agp_buffer_map
= drm_core_findmap(dev
, init
->buffers_offset
);
364 if (!dev
->agp_buffer_map
) {
365 dev
->dev_private
= (void *)dev_priv
;
366 i830_dma_cleanup(dev
);
367 DRM_ERROR("can not find dma buffer map!\n");
371 dev_priv
->sarea_priv
= (drm_i830_sarea_t
*)
372 ((u8
*) dev_priv
->sarea_map
->handle
+ init
->sarea_priv_offset
);
374 dev_priv
->ring
.Start
= init
->ring_start
;
375 dev_priv
->ring
.End
= init
->ring_end
;
376 dev_priv
->ring
.Size
= init
->ring_size
;
378 dev_priv
->ring
.map
.offset
= dev
->agp
->base
+ init
->ring_start
;
379 dev_priv
->ring
.map
.size
= init
->ring_size
;
380 dev_priv
->ring
.map
.type
= _DRM_AGP
;
381 dev_priv
->ring
.map
.flags
= 0;
382 dev_priv
->ring
.map
.mtrr
= 0;
384 drm_core_ioremap(&dev_priv
->ring
.map
, dev
);
386 if (dev_priv
->ring
.map
.handle
== NULL
) {
387 dev
->dev_private
= (void *)dev_priv
;
388 i830_dma_cleanup(dev
);
389 DRM_ERROR("can not ioremap virtual address for"
394 dev_priv
->ring
.virtual_start
= dev_priv
->ring
.map
.handle
;
396 dev_priv
->ring
.tail_mask
= dev_priv
->ring
.Size
- 1;
398 dev_priv
->w
= init
->w
;
399 dev_priv
->h
= init
->h
;
400 dev_priv
->pitch
= init
->pitch
;
401 dev_priv
->back_offset
= init
->back_offset
;
402 dev_priv
->depth_offset
= init
->depth_offset
;
403 dev_priv
->front_offset
= init
->front_offset
;
405 dev_priv
->front_di1
= init
->front_offset
| init
->pitch_bits
;
406 dev_priv
->back_di1
= init
->back_offset
| init
->pitch_bits
;
407 dev_priv
->zi1
= init
->depth_offset
| init
->pitch_bits
;
409 DRM_DEBUG("front_di1 %x\n", dev_priv
->front_di1
);
410 DRM_DEBUG("back_offset %x\n", dev_priv
->back_offset
);
411 DRM_DEBUG("back_di1 %x\n", dev_priv
->back_di1
);
412 DRM_DEBUG("pitch_bits %x\n", init
->pitch_bits
);
414 dev_priv
->cpp
= init
->cpp
;
415 /* We are using separate values as placeholders for mechanisms for
416 * private backbuffer/depthbuffer usage.
419 dev_priv
->back_pitch
= init
->back_pitch
;
420 dev_priv
->depth_pitch
= init
->depth_pitch
;
421 dev_priv
->do_boxes
= 0;
422 dev_priv
->use_mi_batchbuffer_start
= 0;
424 /* Program Hardware Status Page */
425 dev_priv
->hw_status_page
=
426 pci_alloc_consistent(dev
->pdev
, PAGE_SIZE
,
427 &dev_priv
->dma_status_page
);
428 if (!dev_priv
->hw_status_page
) {
429 dev
->dev_private
= (void *)dev_priv
;
430 i830_dma_cleanup(dev
);
431 DRM_ERROR("Can not allocate hardware status page\n");
434 memset(dev_priv
->hw_status_page
, 0, PAGE_SIZE
);
435 DRM_DEBUG("hw status page @ %p\n", dev_priv
->hw_status_page
);
437 I830_WRITE(0x02080, dev_priv
->dma_status_page
);
438 DRM_DEBUG("Enabled hardware status page\n");
440 /* Now we need to init our freelist */
441 if (i830_freelist_init(dev
, dev_priv
) != 0) {
442 dev
->dev_private
= (void *)dev_priv
;
443 i830_dma_cleanup(dev
);
444 DRM_ERROR("Not enough space in the status page for"
448 dev
->dev_private
= (void *)dev_priv
;
453 static int i830_dma_init(struct drm_device
*dev
, void *data
,
454 struct drm_file
*file_priv
)
456 drm_i830_private_t
*dev_priv
;
457 drm_i830_init_t
*init
= data
;
460 switch (init
->func
) {
462 dev_priv
= kmalloc(sizeof(drm_i830_private_t
), GFP_KERNEL
);
463 if (dev_priv
== NULL
)
465 retcode
= i830_dma_initialize(dev
, dev_priv
, init
);
467 case I830_CLEANUP_DMA
:
468 retcode
= i830_dma_cleanup(dev
);
478 #define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16))
479 #define ST1_ENABLE (1<<16)
480 #define ST1_MASK (0xffff)
482 /* Most efficient way to verify state for the i830 is as it is
483 * emitted. Non-conformant state is silently dropped.
485 static void i830EmitContextVerified(struct drm_device
* dev
, unsigned int *code
)
487 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
492 BEGIN_LP_RING(I830_CTX_SETUP_SIZE
+ 4);
494 for (i
= 0; i
< I830_CTXREG_BLENDCOLR0
; i
++) {
496 if ((tmp
& (7 << 29)) == CMD_3D
&&
497 (tmp
& (0x1f << 24)) < (0x1d << 24)) {
501 DRM_ERROR("Skipping %d\n", i
);
505 OUT_RING(STATE3D_CONST_BLEND_COLOR_CMD
);
506 OUT_RING(code
[I830_CTXREG_BLENDCOLR
]);
509 for (i
= I830_CTXREG_VF
; i
< I830_CTXREG_MCSB0
; i
++) {
511 if ((tmp
& (7 << 29)) == CMD_3D
&&
512 (tmp
& (0x1f << 24)) < (0x1d << 24)) {
516 DRM_ERROR("Skipping %d\n", i
);
520 OUT_RING(STATE3D_MAP_COORD_SETBIND_CMD
);
521 OUT_RING(code
[I830_CTXREG_MCSB1
]);
530 static void i830EmitTexVerified(struct drm_device
* dev
, unsigned int *code
)
532 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
537 if (code
[I830_TEXREG_MI0
] == GFX_OP_MAP_INFO
||
538 (code
[I830_TEXREG_MI0
] & ~(0xf * LOAD_TEXTURE_MAP0
)) ==
539 (STATE3D_LOAD_STATE_IMMEDIATE_2
| 4)) {
541 BEGIN_LP_RING(I830_TEX_SETUP_SIZE
);
543 OUT_RING(code
[I830_TEXREG_MI0
]); /* TM0LI */
544 OUT_RING(code
[I830_TEXREG_MI1
]); /* TM0S0 */
545 OUT_RING(code
[I830_TEXREG_MI2
]); /* TM0S1 */
546 OUT_RING(code
[I830_TEXREG_MI3
]); /* TM0S2 */
547 OUT_RING(code
[I830_TEXREG_MI4
]); /* TM0S3 */
548 OUT_RING(code
[I830_TEXREG_MI5
]); /* TM0S4 */
550 for (i
= 6; i
< I830_TEX_SETUP_SIZE
; i
++) {
561 printk("rejected packet %x\n", code
[0]);
564 static void i830EmitTexBlendVerified(struct drm_device
* dev
,
565 unsigned int *code
, unsigned int num
)
567 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
575 BEGIN_LP_RING(num
+ 1);
577 for (i
= 0; i
< num
; i
++) {
589 static void i830EmitTexPalette(struct drm_device
* dev
,
590 unsigned int *palette
, int number
, int is_shared
)
592 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
600 if (is_shared
== 1) {
601 OUT_RING(CMD_OP_MAP_PALETTE_LOAD
|
602 MAP_PALETTE_NUM(0) | MAP_PALETTE_BOTH
);
604 OUT_RING(CMD_OP_MAP_PALETTE_LOAD
| MAP_PALETTE_NUM(number
));
606 for (i
= 0; i
< 256; i
++) {
607 OUT_RING(palette
[i
]);
610 /* KW: WHERE IS THE ADVANCE_LP_RING? This is effectively a noop!
614 /* Need to do some additional checking when setting the dest buffer.
616 static void i830EmitDestVerified(struct drm_device
* dev
, unsigned int *code
)
618 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
622 BEGIN_LP_RING(I830_DEST_SETUP_SIZE
+ 10);
624 tmp
= code
[I830_DESTREG_CBUFADDR
];
625 if (tmp
== dev_priv
->front_di1
|| tmp
== dev_priv
->back_di1
) {
626 if (((int)outring
) & 8) {
631 OUT_RING(CMD_OP_DESTBUFFER_INFO
);
632 OUT_RING(BUF_3D_ID_COLOR_BACK
|
633 BUF_3D_PITCH(dev_priv
->back_pitch
* dev_priv
->cpp
) |
638 OUT_RING(CMD_OP_DESTBUFFER_INFO
);
639 OUT_RING(BUF_3D_ID_DEPTH
| BUF_3D_USE_FENCE
|
640 BUF_3D_PITCH(dev_priv
->depth_pitch
* dev_priv
->cpp
));
641 OUT_RING(dev_priv
->zi1
);
644 DRM_ERROR("bad di1 %x (allow %x or %x)\n",
645 tmp
, dev_priv
->front_di1
, dev_priv
->back_di1
);
651 OUT_RING(GFX_OP_DESTBUFFER_VARS
);
652 OUT_RING(code
[I830_DESTREG_DV1
]);
654 OUT_RING(GFX_OP_DRAWRECT_INFO
);
655 OUT_RING(code
[I830_DESTREG_DR1
]);
656 OUT_RING(code
[I830_DESTREG_DR2
]);
657 OUT_RING(code
[I830_DESTREG_DR3
]);
658 OUT_RING(code
[I830_DESTREG_DR4
]);
660 /* Need to verify this */
661 tmp
= code
[I830_DESTREG_SENABLE
];
662 if ((tmp
& ~0x3) == GFX_OP_SCISSOR_ENABLE
) {
665 DRM_ERROR("bad scissor enable\n");
669 OUT_RING(GFX_OP_SCISSOR_RECT
);
670 OUT_RING(code
[I830_DESTREG_SR1
]);
671 OUT_RING(code
[I830_DESTREG_SR2
]);
677 static void i830EmitStippleVerified(struct drm_device
* dev
, unsigned int *code
)
679 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
683 OUT_RING(GFX_OP_STIPPLE
);
688 static void i830EmitState(struct drm_device
* dev
)
690 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
691 drm_i830_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
692 unsigned int dirty
= sarea_priv
->dirty
;
694 DRM_DEBUG("%s %x\n", __func__
, dirty
);
696 if (dirty
& I830_UPLOAD_BUFFERS
) {
697 i830EmitDestVerified(dev
, sarea_priv
->BufferState
);
698 sarea_priv
->dirty
&= ~I830_UPLOAD_BUFFERS
;
701 if (dirty
& I830_UPLOAD_CTX
) {
702 i830EmitContextVerified(dev
, sarea_priv
->ContextState
);
703 sarea_priv
->dirty
&= ~I830_UPLOAD_CTX
;
706 if (dirty
& I830_UPLOAD_TEX0
) {
707 i830EmitTexVerified(dev
, sarea_priv
->TexState
[0]);
708 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX0
;
711 if (dirty
& I830_UPLOAD_TEX1
) {
712 i830EmitTexVerified(dev
, sarea_priv
->TexState
[1]);
713 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX1
;
716 if (dirty
& I830_UPLOAD_TEXBLEND0
) {
717 i830EmitTexBlendVerified(dev
, sarea_priv
->TexBlendState
[0],
718 sarea_priv
->TexBlendStateWordsUsed
[0]);
719 sarea_priv
->dirty
&= ~I830_UPLOAD_TEXBLEND0
;
722 if (dirty
& I830_UPLOAD_TEXBLEND1
) {
723 i830EmitTexBlendVerified(dev
, sarea_priv
->TexBlendState
[1],
724 sarea_priv
->TexBlendStateWordsUsed
[1]);
725 sarea_priv
->dirty
&= ~I830_UPLOAD_TEXBLEND1
;
728 if (dirty
& I830_UPLOAD_TEX_PALETTE_SHARED
) {
729 i830EmitTexPalette(dev
, sarea_priv
->Palette
[0], 0, 1);
731 if (dirty
& I830_UPLOAD_TEX_PALETTE_N(0)) {
732 i830EmitTexPalette(dev
, sarea_priv
->Palette
[0], 0, 0);
733 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX_PALETTE_N(0);
735 if (dirty
& I830_UPLOAD_TEX_PALETTE_N(1)) {
736 i830EmitTexPalette(dev
, sarea_priv
->Palette
[1], 1, 0);
737 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX_PALETTE_N(1);
743 if (dirty
& I830_UPLOAD_TEX_PALETTE_N(2)) {
744 i830EmitTexPalette(dev
, sarea_priv
->Palette2
[0], 0, 0);
745 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX_PALETTE_N(2);
747 if (dirty
& I830_UPLOAD_TEX_PALETTE_N(3)) {
748 i830EmitTexPalette(dev
, sarea_priv
->Palette2
[1], 1, 0);
749 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX_PALETTE_N(2);
756 if (dirty
& I830_UPLOAD_STIPPLE
) {
757 i830EmitStippleVerified(dev
, sarea_priv
->StippleState
);
758 sarea_priv
->dirty
&= ~I830_UPLOAD_STIPPLE
;
761 if (dirty
& I830_UPLOAD_TEX2
) {
762 i830EmitTexVerified(dev
, sarea_priv
->TexState2
);
763 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX2
;
766 if (dirty
& I830_UPLOAD_TEX3
) {
767 i830EmitTexVerified(dev
, sarea_priv
->TexState3
);
768 sarea_priv
->dirty
&= ~I830_UPLOAD_TEX3
;
771 if (dirty
& I830_UPLOAD_TEXBLEND2
) {
772 i830EmitTexBlendVerified(dev
,
773 sarea_priv
->TexBlendState2
,
774 sarea_priv
->TexBlendStateWordsUsed2
);
776 sarea_priv
->dirty
&= ~I830_UPLOAD_TEXBLEND2
;
779 if (dirty
& I830_UPLOAD_TEXBLEND3
) {
780 i830EmitTexBlendVerified(dev
,
781 sarea_priv
->TexBlendState3
,
782 sarea_priv
->TexBlendStateWordsUsed3
);
783 sarea_priv
->dirty
&= ~I830_UPLOAD_TEXBLEND3
;
787 /* ================================================================
788 * Performance monitoring functions
791 static void i830_fill_box(struct drm_device
* dev
,
792 int x
, int y
, int w
, int h
, int r
, int g
, int b
)
794 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
796 unsigned int BR13
, CMD
;
799 BR13
= (0xF0 << 16) | (dev_priv
->pitch
* dev_priv
->cpp
) | (1 << 24);
800 CMD
= XY_COLOR_BLT_CMD
;
801 x
+= dev_priv
->sarea_priv
->boxes
[0].x1
;
802 y
+= dev_priv
->sarea_priv
->boxes
[0].y1
;
804 if (dev_priv
->cpp
== 4) {
806 CMD
|= (XY_COLOR_BLT_WRITE_ALPHA
| XY_COLOR_BLT_WRITE_RGB
);
807 color
= (((0xff) << 24) | (r
<< 16) | (g
<< 8) | b
);
809 color
= (((r
& 0xf8) << 8) |
810 ((g
& 0xfc) << 3) | ((b
& 0xf8) >> 3));
816 OUT_RING((y
<< 16) | x
);
817 OUT_RING(((y
+ h
) << 16) | (x
+ w
));
819 if (dev_priv
->current_page
== 1) {
820 OUT_RING(dev_priv
->front_offset
);
822 OUT_RING(dev_priv
->back_offset
);
829 static void i830_cp_performance_boxes(struct drm_device
* dev
)
831 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
833 /* Purple box for page flipping
835 if (dev_priv
->sarea_priv
->perf_boxes
& I830_BOX_FLIP
)
836 i830_fill_box(dev
, 4, 4, 8, 8, 255, 0, 255);
838 /* Red box if we have to wait for idle at any point
840 if (dev_priv
->sarea_priv
->perf_boxes
& I830_BOX_WAIT
)
841 i830_fill_box(dev
, 16, 4, 8, 8, 255, 0, 0);
843 /* Blue box: lost context?
845 if (dev_priv
->sarea_priv
->perf_boxes
& I830_BOX_LOST_CONTEXT
)
846 i830_fill_box(dev
, 28, 4, 8, 8, 0, 0, 255);
848 /* Yellow box for texture swaps
850 if (dev_priv
->sarea_priv
->perf_boxes
& I830_BOX_TEXTURE_LOAD
)
851 i830_fill_box(dev
, 40, 4, 8, 8, 255, 255, 0);
853 /* Green box if hardware never idles (as far as we can tell)
855 if (!(dev_priv
->sarea_priv
->perf_boxes
& I830_BOX_RING_EMPTY
))
856 i830_fill_box(dev
, 64, 4, 8, 8, 0, 255, 0);
858 /* Draw bars indicating number of buffers allocated
859 * (not a great measure, easily confused)
861 if (dev_priv
->dma_used
) {
862 int bar
= dev_priv
->dma_used
/ 10240;
867 i830_fill_box(dev
, 4, 16, bar
, 4, 196, 128, 128);
868 dev_priv
->dma_used
= 0;
871 dev_priv
->sarea_priv
->perf_boxes
= 0;
874 static void i830_dma_dispatch_clear(struct drm_device
* dev
, int flags
,
875 unsigned int clear_color
,
876 unsigned int clear_zval
,
877 unsigned int clear_depthmask
)
879 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
880 drm_i830_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
881 int nbox
= sarea_priv
->nbox
;
882 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
883 int pitch
= dev_priv
->pitch
;
884 int cpp
= dev_priv
->cpp
;
886 unsigned int BR13
, CMD
, D_CMD
;
889 if (dev_priv
->current_page
== 1) {
890 unsigned int tmp
= flags
;
892 flags
&= ~(I830_FRONT
| I830_BACK
);
893 if (tmp
& I830_FRONT
)
899 i830_kernel_lost_context(dev
);
903 BR13
= (0xF0 << 16) | (pitch
* cpp
) | (1 << 24);
904 D_CMD
= CMD
= XY_COLOR_BLT_CMD
;
907 BR13
= (0xF0 << 16) | (pitch
* cpp
) | (1 << 24) | (1 << 25);
908 CMD
= (XY_COLOR_BLT_CMD
| XY_COLOR_BLT_WRITE_ALPHA
|
909 XY_COLOR_BLT_WRITE_RGB
);
910 D_CMD
= XY_COLOR_BLT_CMD
;
911 if (clear_depthmask
& 0x00ffffff)
912 D_CMD
|= XY_COLOR_BLT_WRITE_RGB
;
913 if (clear_depthmask
& 0xff000000)
914 D_CMD
|= XY_COLOR_BLT_WRITE_ALPHA
;
917 BR13
= (0xF0 << 16) | (pitch
* cpp
) | (1 << 24);
918 D_CMD
= CMD
= XY_COLOR_BLT_CMD
;
922 if (nbox
> I830_NR_SAREA_CLIPRECTS
)
923 nbox
= I830_NR_SAREA_CLIPRECTS
;
925 for (i
= 0; i
< nbox
; i
++, pbox
++) {
926 if (pbox
->x1
> pbox
->x2
||
927 pbox
->y1
> pbox
->y2
||
928 pbox
->x2
> dev_priv
->w
|| pbox
->y2
> dev_priv
->h
)
931 if (flags
& I830_FRONT
) {
932 DRM_DEBUG("clear front\n");
936 OUT_RING((pbox
->y1
<< 16) | pbox
->x1
);
937 OUT_RING((pbox
->y2
<< 16) | pbox
->x2
);
938 OUT_RING(dev_priv
->front_offset
);
939 OUT_RING(clear_color
);
943 if (flags
& I830_BACK
) {
944 DRM_DEBUG("clear back\n");
948 OUT_RING((pbox
->y1
<< 16) | pbox
->x1
);
949 OUT_RING((pbox
->y2
<< 16) | pbox
->x2
);
950 OUT_RING(dev_priv
->back_offset
);
951 OUT_RING(clear_color
);
955 if (flags
& I830_DEPTH
) {
956 DRM_DEBUG("clear depth\n");
960 OUT_RING((pbox
->y1
<< 16) | pbox
->x1
);
961 OUT_RING((pbox
->y2
<< 16) | pbox
->x2
);
962 OUT_RING(dev_priv
->depth_offset
);
963 OUT_RING(clear_zval
);
969 static void i830_dma_dispatch_swap(struct drm_device
* dev
)
971 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
972 drm_i830_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
973 int nbox
= sarea_priv
->nbox
;
974 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
975 int pitch
= dev_priv
->pitch
;
976 int cpp
= dev_priv
->cpp
;
978 unsigned int CMD
, BR13
;
981 DRM_DEBUG("swapbuffers\n");
983 i830_kernel_lost_context(dev
);
985 if (dev_priv
->do_boxes
)
986 i830_cp_performance_boxes(dev
);
990 BR13
= (pitch
* cpp
) | (0xCC << 16) | (1 << 24);
991 CMD
= XY_SRC_COPY_BLT_CMD
;
994 BR13
= (pitch
* cpp
) | (0xCC << 16) | (1 << 24) | (1 << 25);
995 CMD
= (XY_SRC_COPY_BLT_CMD
| XY_SRC_COPY_BLT_WRITE_ALPHA
|
996 XY_SRC_COPY_BLT_WRITE_RGB
);
999 BR13
= (pitch
* cpp
) | (0xCC << 16) | (1 << 24);
1000 CMD
= XY_SRC_COPY_BLT_CMD
;
1004 if (nbox
> I830_NR_SAREA_CLIPRECTS
)
1005 nbox
= I830_NR_SAREA_CLIPRECTS
;
1007 for (i
= 0; i
< nbox
; i
++, pbox
++) {
1008 if (pbox
->x1
> pbox
->x2
||
1009 pbox
->y1
> pbox
->y2
||
1010 pbox
->x2
> dev_priv
->w
|| pbox
->y2
> dev_priv
->h
)
1013 DRM_DEBUG("dispatch swap %d,%d-%d,%d!\n",
1014 pbox
->x1
, pbox
->y1
, pbox
->x2
, pbox
->y2
);
1019 OUT_RING((pbox
->y1
<< 16) | pbox
->x1
);
1020 OUT_RING((pbox
->y2
<< 16) | pbox
->x2
);
1022 if (dev_priv
->current_page
== 0)
1023 OUT_RING(dev_priv
->front_offset
);
1025 OUT_RING(dev_priv
->back_offset
);
1027 OUT_RING((pbox
->y1
<< 16) | pbox
->x1
);
1028 OUT_RING(BR13
& 0xffff);
1030 if (dev_priv
->current_page
== 0)
1031 OUT_RING(dev_priv
->back_offset
);
1033 OUT_RING(dev_priv
->front_offset
);
1039 static void i830_dma_dispatch_flip(struct drm_device
* dev
)
1041 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1044 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
1046 dev_priv
->current_page
,
1047 dev_priv
->sarea_priv
->pf_current_page
);
1049 i830_kernel_lost_context(dev
);
1051 if (dev_priv
->do_boxes
) {
1052 dev_priv
->sarea_priv
->perf_boxes
|= I830_BOX_FLIP
;
1053 i830_cp_performance_boxes(dev
);
1057 OUT_RING(INST_PARSER_CLIENT
| INST_OP_FLUSH
| INST_FLUSH_MAP_CACHE
);
1062 OUT_RING(CMD_OP_DISPLAYBUFFER_INFO
| ASYNC_FLIP
);
1064 if (dev_priv
->current_page
== 0) {
1065 OUT_RING(dev_priv
->back_offset
);
1066 dev_priv
->current_page
= 1;
1068 OUT_RING(dev_priv
->front_offset
);
1069 dev_priv
->current_page
= 0;
1075 OUT_RING(MI_WAIT_FOR_EVENT
| MI_WAIT_FOR_PLANE_A_FLIP
);
1079 dev_priv
->sarea_priv
->pf_current_page
= dev_priv
->current_page
;
1082 static void i830_dma_dispatch_vertex(struct drm_device
* dev
,
1083 struct drm_buf
* buf
, int discard
, int used
)
1085 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1086 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
1087 drm_i830_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
1088 struct drm_clip_rect
*box
= sarea_priv
->boxes
;
1089 int nbox
= sarea_priv
->nbox
;
1090 unsigned long address
= (unsigned long)buf
->bus_address
;
1091 unsigned long start
= address
- dev
->agp
->base
;
1095 i830_kernel_lost_context(dev
);
1097 if (nbox
> I830_NR_SAREA_CLIPRECTS
)
1098 nbox
= I830_NR_SAREA_CLIPRECTS
;
1101 u
= cmpxchg(buf_priv
->in_use
, I830_BUF_CLIENT
,
1103 if (u
!= I830_BUF_CLIENT
) {
1104 DRM_DEBUG("xxxx 2\n");
1108 if (used
> 4 * 1023)
1111 if (sarea_priv
->dirty
)
1114 DRM_DEBUG("dispatch vertex addr 0x%lx, used 0x%x nbox %d\n",
1115 address
, used
, nbox
);
1117 dev_priv
->counter
++;
1118 DRM_DEBUG("dispatch counter : %ld\n", dev_priv
->counter
);
1119 DRM_DEBUG("i830_dma_dispatch\n");
1120 DRM_DEBUG("start : %lx\n", start
);
1121 DRM_DEBUG("used : %d\n", used
);
1122 DRM_DEBUG("start + used - 4 : %ld\n", start
+ used
- 4);
1124 if (buf_priv
->currently_mapped
== I830_BUF_MAPPED
) {
1125 u32
*vp
= buf_priv
->kernel_virtual
;
1127 vp
[0] = (GFX_OP_PRIMITIVE
|
1128 sarea_priv
->vertex_prim
| ((used
/ 4) - 2));
1130 if (dev_priv
->use_mi_batchbuffer_start
) {
1131 vp
[used
/ 4] = MI_BATCH_BUFFER_END
;
1140 i830_unmap_buffer(buf
);
1147 OUT_RING(GFX_OP_DRAWRECT_INFO
);
1148 OUT_RING(sarea_priv
->
1149 BufferState
[I830_DESTREG_DR1
]);
1150 OUT_RING(box
[i
].x1
| (box
[i
].y1
<< 16));
1151 OUT_RING(box
[i
].x2
| (box
[i
].y2
<< 16));
1152 OUT_RING(sarea_priv
->
1153 BufferState
[I830_DESTREG_DR4
]);
1158 if (dev_priv
->use_mi_batchbuffer_start
) {
1160 OUT_RING(MI_BATCH_BUFFER_START
| (2 << 6));
1161 OUT_RING(start
| MI_BATCH_NON_SECURE
);
1165 OUT_RING(MI_BATCH_BUFFER
);
1166 OUT_RING(start
| MI_BATCH_NON_SECURE
);
1167 OUT_RING(start
+ used
- 4);
1172 } while (++i
< nbox
);
1176 dev_priv
->counter
++;
1178 (void)cmpxchg(buf_priv
->in_use
, I830_BUF_CLIENT
,
1182 OUT_RING(CMD_STORE_DWORD_IDX
);
1184 OUT_RING(dev_priv
->counter
);
1185 OUT_RING(CMD_STORE_DWORD_IDX
);
1186 OUT_RING(buf_priv
->my_use_idx
);
1187 OUT_RING(I830_BUF_FREE
);
1188 OUT_RING(CMD_REPORT_HEAD
);
1194 static void i830_dma_quiescent(struct drm_device
* dev
)
1196 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1199 i830_kernel_lost_context(dev
);
1202 OUT_RING(INST_PARSER_CLIENT
| INST_OP_FLUSH
| INST_FLUSH_MAP_CACHE
);
1203 OUT_RING(CMD_REPORT_HEAD
);
1208 i830_wait_ring(dev
, dev_priv
->ring
.Size
- 8, __func__
);
1211 static int i830_flush_queue(struct drm_device
* dev
)
1213 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1214 struct drm_device_dma
*dma
= dev
->dma
;
1218 i830_kernel_lost_context(dev
);
1221 OUT_RING(CMD_REPORT_HEAD
);
1225 i830_wait_ring(dev
, dev_priv
->ring
.Size
- 8, __func__
);
1227 for (i
= 0; i
< dma
->buf_count
; i
++) {
1228 struct drm_buf
*buf
= dma
->buflist
[i
];
1229 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
1231 int used
= cmpxchg(buf_priv
->in_use
, I830_BUF_HARDWARE
,
1234 if (used
== I830_BUF_HARDWARE
)
1235 DRM_DEBUG("reclaimed from HARDWARE\n");
1236 if (used
== I830_BUF_CLIENT
)
1237 DRM_DEBUG("still on client\n");
1243 /* Must be called with the lock held */
1244 static void i830_reclaim_buffers(struct drm_device
* dev
, struct drm_file
*file_priv
)
1246 struct drm_device_dma
*dma
= dev
->dma
;
1251 if (!dev
->dev_private
)
1256 i830_flush_queue(dev
);
1258 for (i
= 0; i
< dma
->buf_count
; i
++) {
1259 struct drm_buf
*buf
= dma
->buflist
[i
];
1260 drm_i830_buf_priv_t
*buf_priv
= buf
->dev_private
;
1262 if (buf
->file_priv
== file_priv
&& buf_priv
) {
1263 int used
= cmpxchg(buf_priv
->in_use
, I830_BUF_CLIENT
,
1266 if (used
== I830_BUF_CLIENT
)
1267 DRM_DEBUG("reclaimed from client\n");
1268 if (buf_priv
->currently_mapped
== I830_BUF_MAPPED
)
1269 buf_priv
->currently_mapped
= I830_BUF_UNMAPPED
;
1274 static int i830_flush_ioctl(struct drm_device
*dev
, void *data
,
1275 struct drm_file
*file_priv
)
1277 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1279 i830_flush_queue(dev
);
1283 static int i830_dma_vertex(struct drm_device
*dev
, void *data
,
1284 struct drm_file
*file_priv
)
1286 struct drm_device_dma
*dma
= dev
->dma
;
1287 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
1288 u32
*hw_status
= dev_priv
->hw_status_page
;
1289 drm_i830_sarea_t
*sarea_priv
= (drm_i830_sarea_t
*)
1290 dev_priv
->sarea_priv
;
1291 drm_i830_vertex_t
*vertex
= data
;
1293 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1295 DRM_DEBUG("i830 dma vertex, idx %d used %d discard %d\n",
1296 vertex
->idx
, vertex
->used
, vertex
->discard
);
1298 if (vertex
->idx
< 0 || vertex
->idx
> dma
->buf_count
)
1301 i830_dma_dispatch_vertex(dev
,
1302 dma
->buflist
[vertex
->idx
],
1303 vertex
->discard
, vertex
->used
);
1305 sarea_priv
->last_enqueue
= dev_priv
->counter
- 1;
1306 sarea_priv
->last_dispatch
= (int)hw_status
[5];
1311 static int i830_clear_bufs(struct drm_device
*dev
, void *data
,
1312 struct drm_file
*file_priv
)
1314 drm_i830_clear_t
*clear
= data
;
1316 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1318 /* GH: Someone's doing nasty things... */
1319 if (!dev
->dev_private
) {
1323 i830_dma_dispatch_clear(dev
, clear
->flags
,
1325 clear
->clear_depth
, clear
->clear_depthmask
);
1329 static int i830_swap_bufs(struct drm_device
*dev
, void *data
,
1330 struct drm_file
*file_priv
)
1332 DRM_DEBUG("i830_swap_bufs\n");
1334 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1336 i830_dma_dispatch_swap(dev
);
1340 /* Not sure why this isn't set all the time:
1342 static void i830_do_init_pageflip(struct drm_device
* dev
)
1344 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1346 DRM_DEBUG("%s\n", __func__
);
1347 dev_priv
->page_flipping
= 1;
1348 dev_priv
->current_page
= 0;
1349 dev_priv
->sarea_priv
->pf_current_page
= dev_priv
->current_page
;
1352 static int i830_do_cleanup_pageflip(struct drm_device
* dev
)
1354 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1356 DRM_DEBUG("%s\n", __func__
);
1357 if (dev_priv
->current_page
!= 0)
1358 i830_dma_dispatch_flip(dev
);
1360 dev_priv
->page_flipping
= 0;
1364 static int i830_flip_bufs(struct drm_device
*dev
, void *data
,
1365 struct drm_file
*file_priv
)
1367 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1369 DRM_DEBUG("%s\n", __func__
);
1371 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1373 if (!dev_priv
->page_flipping
)
1374 i830_do_init_pageflip(dev
);
1376 i830_dma_dispatch_flip(dev
);
1380 static int i830_getage(struct drm_device
*dev
, void *data
,
1381 struct drm_file
*file_priv
)
1383 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
1384 u32
*hw_status
= dev_priv
->hw_status_page
;
1385 drm_i830_sarea_t
*sarea_priv
= (drm_i830_sarea_t
*)
1386 dev_priv
->sarea_priv
;
1388 sarea_priv
->last_dispatch
= (int)hw_status
[5];
1392 static int i830_getbuf(struct drm_device
*dev
, void *data
,
1393 struct drm_file
*file_priv
)
1396 drm_i830_dma_t
*d
= data
;
1397 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
1398 u32
*hw_status
= dev_priv
->hw_status_page
;
1399 drm_i830_sarea_t
*sarea_priv
= (drm_i830_sarea_t
*)
1400 dev_priv
->sarea_priv
;
1402 DRM_DEBUG("getbuf\n");
1404 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1408 retcode
= i830_dma_get_buffer(dev
, d
, file_priv
);
1410 DRM_DEBUG("i830_dma: %d returning %d, granted = %d\n",
1411 task_pid_nr(current
), retcode
, d
->granted
);
1413 sarea_priv
->last_dispatch
= (int)hw_status
[5];
1418 static int i830_copybuf(struct drm_device
*dev
, void *data
,
1419 struct drm_file
*file_priv
)
1421 /* Never copy - 2.4.x doesn't need it */
1425 static int i830_docopy(struct drm_device
*dev
, void *data
,
1426 struct drm_file
*file_priv
)
1431 static int i830_getparam(struct drm_device
*dev
, void *data
,
1432 struct drm_file
*file_priv
)
1434 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1435 drm_i830_getparam_t
*param
= data
;
1439 DRM_ERROR("%s called with no initialization\n", __func__
);
1443 switch (param
->param
) {
1444 case I830_PARAM_IRQ_ACTIVE
:
1445 value
= dev
->irq_enabled
;
1451 if (copy_to_user(param
->value
, &value
, sizeof(int))) {
1452 DRM_ERROR("copy_to_user\n");
1459 static int i830_setparam(struct drm_device
*dev
, void *data
,
1460 struct drm_file
*file_priv
)
1462 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1463 drm_i830_setparam_t
*param
= data
;
1466 DRM_ERROR("%s called with no initialization\n", __func__
);
1470 switch (param
->param
) {
1471 case I830_SETPARAM_USE_MI_BATCHBUFFER_START
:
1472 dev_priv
->use_mi_batchbuffer_start
= param
->value
;
1481 int i830_driver_load(struct drm_device
*dev
, unsigned long flags
)
1483 /* i830 has 4 more counters */
1485 dev
->types
[6] = _DRM_STAT_IRQ
;
1486 dev
->types
[7] = _DRM_STAT_PRIMARY
;
1487 dev
->types
[8] = _DRM_STAT_SECONDARY
;
1488 dev
->types
[9] = _DRM_STAT_DMA
;
1493 void i830_driver_lastclose(struct drm_device
* dev
)
1495 i830_dma_cleanup(dev
);
1498 void i830_driver_preclose(struct drm_device
* dev
, struct drm_file
*file_priv
)
1500 if (dev
->dev_private
) {
1501 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
1502 if (dev_priv
->page_flipping
) {
1503 i830_do_cleanup_pageflip(dev
);
1508 void i830_driver_reclaim_buffers_locked(struct drm_device
* dev
, struct drm_file
*file_priv
)
1510 i830_reclaim_buffers(dev
, file_priv
);
1513 int i830_driver_dma_quiescent(struct drm_device
* dev
)
1515 i830_dma_quiescent(dev
);
1519 struct drm_ioctl_desc i830_ioctls
[] = {
1520 DRM_IOCTL_DEF(DRM_I830_INIT
, i830_dma_init
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1521 DRM_IOCTL_DEF(DRM_I830_VERTEX
, i830_dma_vertex
, DRM_AUTH
),
1522 DRM_IOCTL_DEF(DRM_I830_CLEAR
, i830_clear_bufs
, DRM_AUTH
),
1523 DRM_IOCTL_DEF(DRM_I830_FLUSH
, i830_flush_ioctl
, DRM_AUTH
),
1524 DRM_IOCTL_DEF(DRM_I830_GETAGE
, i830_getage
, DRM_AUTH
),
1525 DRM_IOCTL_DEF(DRM_I830_GETBUF
, i830_getbuf
, DRM_AUTH
),
1526 DRM_IOCTL_DEF(DRM_I830_SWAP
, i830_swap_bufs
, DRM_AUTH
),
1527 DRM_IOCTL_DEF(DRM_I830_COPY
, i830_copybuf
, DRM_AUTH
),
1528 DRM_IOCTL_DEF(DRM_I830_DOCOPY
, i830_docopy
, DRM_AUTH
),
1529 DRM_IOCTL_DEF(DRM_I830_FLIP
, i830_flip_bufs
, DRM_AUTH
),
1530 DRM_IOCTL_DEF(DRM_I830_IRQ_EMIT
, i830_irq_emit
, DRM_AUTH
),
1531 DRM_IOCTL_DEF(DRM_I830_IRQ_WAIT
, i830_irq_wait
, DRM_AUTH
),
1532 DRM_IOCTL_DEF(DRM_I830_GETPARAM
, i830_getparam
, DRM_AUTH
),
1533 DRM_IOCTL_DEF(DRM_I830_SETPARAM
, i830_setparam
, DRM_AUTH
)
1536 int i830_max_ioctl
= DRM_ARRAY_SIZE(i830_ioctls
);
1539 * Determine if the device really is AGP or not.
1541 * All Intel graphics chipsets are treated as AGP, even if they are really
1544 * \param dev The device to be tested.
1547 * A value of 1 is always retured to indictate every i8xx is AGP.
1549 int i830_driver_device_is_agp(struct drm_device
* dev
)