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.
31 #include "drm_crtc_helper.h"
32 #include "drm_fb_helper.h"
33 #include "intel_drv.h"
36 #include "i915_trace.h"
37 #include <linux/vgaarb.h>
38 #include <linux/acpi.h>
39 #include <linux/pnp.h>
40 #include <linux/vga_switcheroo.h>
42 /* Really want an OS-independent resettable timer. Would like to have
43 * this loop run for (eg) 3 sec, but have the timer reset every time
44 * the head pointer changes, so that EBUSY only happens if the ring
45 * actually stalls for (eg) 3 seconds.
47 int i915_wait_ring(struct drm_device
* dev
, int n
, const char *caller
)
49 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
50 drm_i915_ring_buffer_t
*ring
= &(dev_priv
->ring
);
51 u32 acthd_reg
= IS_I965G(dev
) ? ACTHD_I965
: ACTHD
;
52 u32 last_acthd
= I915_READ(acthd_reg
);
54 u32 last_head
= I915_READ(PRB0_HEAD
) & HEAD_ADDR
;
57 trace_i915_ring_wait_begin (dev
);
59 for (i
= 0; i
< 100000; i
++) {
60 ring
->head
= I915_READ(PRB0_HEAD
) & HEAD_ADDR
;
61 acthd
= I915_READ(acthd_reg
);
62 ring
->space
= ring
->head
- (ring
->tail
+ 8);
64 ring
->space
+= ring
->Size
;
65 if (ring
->space
>= n
) {
66 trace_i915_ring_wait_end (dev
);
70 if (dev
->primary
->master
) {
71 struct drm_i915_master_private
*master_priv
= dev
->primary
->master
->driver_priv
;
72 if (master_priv
->sarea_priv
)
73 master_priv
->sarea_priv
->perf_boxes
|= I915_BOX_WAIT
;
77 if (ring
->head
!= last_head
)
79 if (acthd
!= last_acthd
)
82 last_head
= ring
->head
;
84 msleep_interruptible(10);
88 trace_i915_ring_wait_end (dev
);
92 /* As a ringbuffer is only allowed to wrap between instructions, fill
93 * the tail with NOOPs.
95 int i915_wrap_ring(struct drm_device
*dev
)
97 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
98 volatile unsigned int *virt
;
101 rem
= dev_priv
->ring
.Size
- dev_priv
->ring
.tail
;
102 if (dev_priv
->ring
.space
< rem
) {
103 int ret
= i915_wait_ring(dev
, rem
, __func__
);
107 dev_priv
->ring
.space
-= rem
;
109 virt
= (unsigned int *)
110 (dev_priv
->ring
.virtual_start
+ dev_priv
->ring
.tail
);
115 dev_priv
->ring
.tail
= 0;
121 * Sets up the hardware status page for devices that need a physical address
124 static int i915_init_phys_hws(struct drm_device
*dev
)
126 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
127 /* Program Hardware Status Page */
128 dev_priv
->status_page_dmah
=
129 drm_pci_alloc(dev
, PAGE_SIZE
, PAGE_SIZE
);
131 if (!dev_priv
->status_page_dmah
) {
132 DRM_ERROR("Can not allocate hardware status page\n");
135 dev_priv
->hw_status_page
= dev_priv
->status_page_dmah
->vaddr
;
136 dev_priv
->dma_status_page
= dev_priv
->status_page_dmah
->busaddr
;
138 memset(dev_priv
->hw_status_page
, 0, PAGE_SIZE
);
141 dev_priv
->dma_status_page
|= (dev_priv
->dma_status_page
>> 28) &
144 I915_WRITE(HWS_PGA
, dev_priv
->dma_status_page
);
145 DRM_DEBUG_DRIVER("Enabled hardware status page\n");
150 * Frees the hardware status page, whether it's a physical address or a virtual
151 * address set up by the X Server.
153 static void i915_free_hws(struct drm_device
*dev
)
155 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
156 if (dev_priv
->status_page_dmah
) {
157 drm_pci_free(dev
, dev_priv
->status_page_dmah
);
158 dev_priv
->status_page_dmah
= NULL
;
161 if (dev_priv
->status_gfx_addr
) {
162 dev_priv
->status_gfx_addr
= 0;
163 drm_core_ioremapfree(&dev_priv
->hws_map
, dev
);
166 /* Need to rewrite hardware status page */
167 I915_WRITE(HWS_PGA
, 0x1ffff000);
170 void i915_kernel_lost_context(struct drm_device
* dev
)
172 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
173 struct drm_i915_master_private
*master_priv
;
174 drm_i915_ring_buffer_t
*ring
= &(dev_priv
->ring
);
177 * We should never lose context on the ring with modesetting
178 * as we don't expose it to userspace
180 if (drm_core_check_feature(dev
, DRIVER_MODESET
))
183 ring
->head
= I915_READ(PRB0_HEAD
) & HEAD_ADDR
;
184 ring
->tail
= I915_READ(PRB0_TAIL
) & TAIL_ADDR
;
185 ring
->space
= ring
->head
- (ring
->tail
+ 8);
187 ring
->space
+= ring
->Size
;
189 if (!dev
->primary
->master
)
192 master_priv
= dev
->primary
->master
->driver_priv
;
193 if (ring
->head
== ring
->tail
&& master_priv
->sarea_priv
)
194 master_priv
->sarea_priv
->perf_boxes
|= I915_BOX_RING_EMPTY
;
197 static int i915_dma_cleanup(struct drm_device
* dev
)
199 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
200 /* Make sure interrupts are disabled here because the uninstall ioctl
201 * may not have been called from userspace and after dev_private
202 * is freed, it's too late.
204 if (dev
->irq_enabled
)
205 drm_irq_uninstall(dev
);
207 if (dev_priv
->ring
.virtual_start
) {
208 drm_core_ioremapfree(&dev_priv
->ring
.map
, dev
);
209 dev_priv
->ring
.virtual_start
= NULL
;
210 dev_priv
->ring
.map
.handle
= NULL
;
211 dev_priv
->ring
.map
.size
= 0;
214 /* Clear the HWS virtual address at teardown */
215 if (I915_NEED_GFX_HWS(dev
))
221 static int i915_initialize(struct drm_device
* dev
, drm_i915_init_t
* init
)
223 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
224 struct drm_i915_master_private
*master_priv
= dev
->primary
->master
->driver_priv
;
226 master_priv
->sarea
= drm_getsarea(dev
);
227 if (master_priv
->sarea
) {
228 master_priv
->sarea_priv
= (drm_i915_sarea_t
*)
229 ((u8
*)master_priv
->sarea
->handle
+ init
->sarea_priv_offset
);
231 DRM_DEBUG_DRIVER("sarea not found assuming DRI2 userspace\n");
234 if (init
->ring_size
!= 0) {
235 if (dev_priv
->ring
.ring_obj
!= NULL
) {
236 i915_dma_cleanup(dev
);
237 DRM_ERROR("Client tried to initialize ringbuffer in "
242 dev_priv
->ring
.Size
= init
->ring_size
;
244 dev_priv
->ring
.map
.offset
= init
->ring_start
;
245 dev_priv
->ring
.map
.size
= init
->ring_size
;
246 dev_priv
->ring
.map
.type
= 0;
247 dev_priv
->ring
.map
.flags
= 0;
248 dev_priv
->ring
.map
.mtrr
= 0;
250 drm_core_ioremap_wc(&dev_priv
->ring
.map
, dev
);
252 if (dev_priv
->ring
.map
.handle
== NULL
) {
253 i915_dma_cleanup(dev
);
254 DRM_ERROR("can not ioremap virtual address for"
260 dev_priv
->ring
.virtual_start
= dev_priv
->ring
.map
.handle
;
262 dev_priv
->cpp
= init
->cpp
;
263 dev_priv
->back_offset
= init
->back_offset
;
264 dev_priv
->front_offset
= init
->front_offset
;
265 dev_priv
->current_page
= 0;
266 if (master_priv
->sarea_priv
)
267 master_priv
->sarea_priv
->pf_current_page
= 0;
269 /* Allow hardware batchbuffers unless told otherwise.
271 dev_priv
->allow_batchbuffer
= 1;
276 static int i915_dma_resume(struct drm_device
* dev
)
278 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
280 DRM_DEBUG_DRIVER("%s\n", __func__
);
282 if (dev_priv
->ring
.map
.handle
== NULL
) {
283 DRM_ERROR("can not ioremap virtual address for"
288 /* Program Hardware Status Page */
289 if (!dev_priv
->hw_status_page
) {
290 DRM_ERROR("Can not find hardware status page\n");
293 DRM_DEBUG_DRIVER("hw status page @ %p\n",
294 dev_priv
->hw_status_page
);
296 if (dev_priv
->status_gfx_addr
!= 0)
297 I915_WRITE(HWS_PGA
, dev_priv
->status_gfx_addr
);
299 I915_WRITE(HWS_PGA
, dev_priv
->dma_status_page
);
300 DRM_DEBUG_DRIVER("Enabled hardware status page\n");
305 static int i915_dma_init(struct drm_device
*dev
, void *data
,
306 struct drm_file
*file_priv
)
308 drm_i915_init_t
*init
= data
;
311 switch (init
->func
) {
313 retcode
= i915_initialize(dev
, init
);
315 case I915_CLEANUP_DMA
:
316 retcode
= i915_dma_cleanup(dev
);
318 case I915_RESUME_DMA
:
319 retcode
= i915_dma_resume(dev
);
329 /* Implement basically the same security restrictions as hardware does
330 * for MI_BATCH_NON_SECURE. These can be made stricter at any time.
332 * Most of the calculations below involve calculating the size of a
333 * particular instruction. It's important to get the size right as
334 * that tells us where the next instruction to check is. Any illegal
335 * instruction detected will be given a size of zero, which is a
336 * signal to abort the rest of the buffer.
338 static int do_validate_cmd(int cmd
)
340 switch (((cmd
>> 29) & 0x7)) {
342 switch ((cmd
>> 23) & 0x3f) {
344 return 1; /* MI_NOOP */
346 return 1; /* MI_FLUSH */
348 return 0; /* disallow everything else */
352 return 0; /* reserved */
354 return (cmd
& 0xff) + 2; /* 2d commands */
356 if (((cmd
>> 24) & 0x1f) <= 0x18)
359 switch ((cmd
>> 24) & 0x1f) {
363 switch ((cmd
>> 16) & 0xff) {
365 return (cmd
& 0x1f) + 2;
367 return (cmd
& 0xf) + 2;
369 return (cmd
& 0xffff) + 2;
373 return (cmd
& 0xffff) + 1;
377 if ((cmd
& (1 << 23)) == 0) /* inline vertices */
378 return (cmd
& 0x1ffff) + 2;
379 else if (cmd
& (1 << 17)) /* indirect random */
380 if ((cmd
& 0xffff) == 0)
381 return 0; /* unknown length, too hard */
383 return (((cmd
& 0xffff) + 1) / 2) + 1;
385 return 2; /* indirect sequential */
396 static int validate_cmd(int cmd
)
398 int ret
= do_validate_cmd(cmd
);
400 /* printk("validate_cmd( %x ): %d\n", cmd, ret); */
405 static int i915_emit_cmds(struct drm_device
* dev
, int *buffer
, int dwords
)
407 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
411 if ((dwords
+1) * sizeof(int) >= dev_priv
->ring
.Size
- 8)
414 BEGIN_LP_RING((dwords
+1)&~1);
416 for (i
= 0; i
< dwords
;) {
421 if ((sz
= validate_cmd(cmd
)) == 0 || i
+ sz
> dwords
)
440 i915_emit_box(struct drm_device
*dev
,
441 struct drm_clip_rect
*boxes
,
442 int i
, int DR1
, int DR4
)
444 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
445 struct drm_clip_rect box
= boxes
[i
];
448 if (box
.y2
<= box
.y1
|| box
.x2
<= box
.x1
|| box
.y2
<= 0 || box
.x2
<= 0) {
449 DRM_ERROR("Bad box %d,%d..%d,%d\n",
450 box
.x1
, box
.y1
, box
.x2
, box
.y2
);
456 OUT_RING(GFX_OP_DRAWRECT_INFO_I965
);
457 OUT_RING((box
.x1
& 0xffff) | (box
.y1
<< 16));
458 OUT_RING(((box
.x2
- 1) & 0xffff) | ((box
.y2
- 1) << 16));
463 OUT_RING(GFX_OP_DRAWRECT_INFO
);
465 OUT_RING((box
.x1
& 0xffff) | (box
.y1
<< 16));
466 OUT_RING(((box
.x2
- 1) & 0xffff) | ((box
.y2
- 1) << 16));
475 /* XXX: Emitting the counter should really be moved to part of the IRQ
476 * emit. For now, do it in both places:
479 static void i915_emit_breadcrumb(struct drm_device
*dev
)
481 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
482 struct drm_i915_master_private
*master_priv
= dev
->primary
->master
->driver_priv
;
486 if (dev_priv
->counter
> 0x7FFFFFFFUL
)
487 dev_priv
->counter
= 0;
488 if (master_priv
->sarea_priv
)
489 master_priv
->sarea_priv
->last_enqueue
= dev_priv
->counter
;
492 OUT_RING(MI_STORE_DWORD_INDEX
);
493 OUT_RING(I915_BREADCRUMB_INDEX
<< MI_STORE_DWORD_INDEX_SHIFT
);
494 OUT_RING(dev_priv
->counter
);
499 static int i915_dispatch_cmdbuffer(struct drm_device
* dev
,
500 drm_i915_cmdbuffer_t
*cmd
,
501 struct drm_clip_rect
*cliprects
,
504 int nbox
= cmd
->num_cliprects
;
505 int i
= 0, count
, ret
;
508 DRM_ERROR("alignment");
512 i915_kernel_lost_context(dev
);
514 count
= nbox
? nbox
: 1;
516 for (i
= 0; i
< count
; i
++) {
518 ret
= i915_emit_box(dev
, cliprects
, i
,
524 ret
= i915_emit_cmds(dev
, cmdbuf
, cmd
->sz
/ 4);
529 i915_emit_breadcrumb(dev
);
533 static int i915_dispatch_batchbuffer(struct drm_device
* dev
,
534 drm_i915_batchbuffer_t
* batch
,
535 struct drm_clip_rect
*cliprects
)
537 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
538 int nbox
= batch
->num_cliprects
;
542 if ((batch
->start
| batch
->used
) & 0x7) {
543 DRM_ERROR("alignment");
547 i915_kernel_lost_context(dev
);
549 count
= nbox
? nbox
: 1;
551 for (i
= 0; i
< count
; i
++) {
553 int ret
= i915_emit_box(dev
, cliprects
, i
,
554 batch
->DR1
, batch
->DR4
);
559 if (!IS_I830(dev
) && !IS_845G(dev
)) {
562 OUT_RING(MI_BATCH_BUFFER_START
| (2 << 6) | MI_BATCH_NON_SECURE_I965
);
563 OUT_RING(batch
->start
);
565 OUT_RING(MI_BATCH_BUFFER_START
| (2 << 6));
566 OUT_RING(batch
->start
| MI_BATCH_NON_SECURE
);
571 OUT_RING(MI_BATCH_BUFFER
);
572 OUT_RING(batch
->start
| MI_BATCH_NON_SECURE
);
573 OUT_RING(batch
->start
+ batch
->used
- 4);
579 i915_emit_breadcrumb(dev
);
584 static int i915_dispatch_flip(struct drm_device
* dev
)
586 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
587 struct drm_i915_master_private
*master_priv
=
588 dev
->primary
->master
->driver_priv
;
591 if (!master_priv
->sarea_priv
)
594 DRM_DEBUG_DRIVER("%s: page=%d pfCurrentPage=%d\n",
596 dev_priv
->current_page
,
597 master_priv
->sarea_priv
->pf_current_page
);
599 i915_kernel_lost_context(dev
);
602 OUT_RING(MI_FLUSH
| MI_READ_FLUSH
);
607 OUT_RING(CMD_OP_DISPLAYBUFFER_INFO
| ASYNC_FLIP
);
609 if (dev_priv
->current_page
== 0) {
610 OUT_RING(dev_priv
->back_offset
);
611 dev_priv
->current_page
= 1;
613 OUT_RING(dev_priv
->front_offset
);
614 dev_priv
->current_page
= 0;
620 OUT_RING(MI_WAIT_FOR_EVENT
| MI_WAIT_FOR_PLANE_A_FLIP
);
624 master_priv
->sarea_priv
->last_enqueue
= dev_priv
->counter
++;
627 OUT_RING(MI_STORE_DWORD_INDEX
);
628 OUT_RING(I915_BREADCRUMB_INDEX
<< MI_STORE_DWORD_INDEX_SHIFT
);
629 OUT_RING(dev_priv
->counter
);
633 master_priv
->sarea_priv
->pf_current_page
= dev_priv
->current_page
;
637 static int i915_quiescent(struct drm_device
* dev
)
639 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
641 i915_kernel_lost_context(dev
);
642 return i915_wait_ring(dev
, dev_priv
->ring
.Size
- 8, __func__
);
645 static int i915_flush_ioctl(struct drm_device
*dev
, void *data
,
646 struct drm_file
*file_priv
)
650 RING_LOCK_TEST_WITH_RETURN(dev
, file_priv
);
652 mutex_lock(&dev
->struct_mutex
);
653 ret
= i915_quiescent(dev
);
654 mutex_unlock(&dev
->struct_mutex
);
659 static int i915_batchbuffer(struct drm_device
*dev
, void *data
,
660 struct drm_file
*file_priv
)
662 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
663 struct drm_i915_master_private
*master_priv
= dev
->primary
->master
->driver_priv
;
664 drm_i915_sarea_t
*sarea_priv
= (drm_i915_sarea_t
*)
665 master_priv
->sarea_priv
;
666 drm_i915_batchbuffer_t
*batch
= data
;
668 struct drm_clip_rect
*cliprects
= NULL
;
670 if (!dev_priv
->allow_batchbuffer
) {
671 DRM_ERROR("Batchbuffer ioctl disabled\n");
675 DRM_DEBUG_DRIVER("i915 batchbuffer, start %x used %d cliprects %d\n",
676 batch
->start
, batch
->used
, batch
->num_cliprects
);
678 RING_LOCK_TEST_WITH_RETURN(dev
, file_priv
);
680 if (batch
->num_cliprects
< 0)
683 if (batch
->num_cliprects
) {
684 cliprects
= kcalloc(batch
->num_cliprects
,
685 sizeof(struct drm_clip_rect
),
687 if (cliprects
== NULL
)
690 ret
= copy_from_user(cliprects
, batch
->cliprects
,
691 batch
->num_cliprects
*
692 sizeof(struct drm_clip_rect
));
697 mutex_lock(&dev
->struct_mutex
);
698 ret
= i915_dispatch_batchbuffer(dev
, batch
, cliprects
);
699 mutex_unlock(&dev
->struct_mutex
);
702 sarea_priv
->last_dispatch
= READ_BREADCRUMB(dev_priv
);
710 static int i915_cmdbuffer(struct drm_device
*dev
, void *data
,
711 struct drm_file
*file_priv
)
713 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
714 struct drm_i915_master_private
*master_priv
= dev
->primary
->master
->driver_priv
;
715 drm_i915_sarea_t
*sarea_priv
= (drm_i915_sarea_t
*)
716 master_priv
->sarea_priv
;
717 drm_i915_cmdbuffer_t
*cmdbuf
= data
;
718 struct drm_clip_rect
*cliprects
= NULL
;
722 DRM_DEBUG_DRIVER("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
723 cmdbuf
->buf
, cmdbuf
->sz
, cmdbuf
->num_cliprects
);
725 RING_LOCK_TEST_WITH_RETURN(dev
, file_priv
);
727 if (cmdbuf
->num_cliprects
< 0)
730 batch_data
= kmalloc(cmdbuf
->sz
, GFP_KERNEL
);
731 if (batch_data
== NULL
)
734 ret
= copy_from_user(batch_data
, cmdbuf
->buf
, cmdbuf
->sz
);
736 goto fail_batch_free
;
738 if (cmdbuf
->num_cliprects
) {
739 cliprects
= kcalloc(cmdbuf
->num_cliprects
,
740 sizeof(struct drm_clip_rect
), GFP_KERNEL
);
741 if (cliprects
== NULL
) {
743 goto fail_batch_free
;
746 ret
= copy_from_user(cliprects
, cmdbuf
->cliprects
,
747 cmdbuf
->num_cliprects
*
748 sizeof(struct drm_clip_rect
));
753 mutex_lock(&dev
->struct_mutex
);
754 ret
= i915_dispatch_cmdbuffer(dev
, cmdbuf
, cliprects
, batch_data
);
755 mutex_unlock(&dev
->struct_mutex
);
757 DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
762 sarea_priv
->last_dispatch
= READ_BREADCRUMB(dev_priv
);
772 static int i915_flip_bufs(struct drm_device
*dev
, void *data
,
773 struct drm_file
*file_priv
)
777 DRM_DEBUG_DRIVER("%s\n", __func__
);
779 RING_LOCK_TEST_WITH_RETURN(dev
, file_priv
);
781 mutex_lock(&dev
->struct_mutex
);
782 ret
= i915_dispatch_flip(dev
);
783 mutex_unlock(&dev
->struct_mutex
);
788 static int i915_getparam(struct drm_device
*dev
, void *data
,
789 struct drm_file
*file_priv
)
791 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
792 drm_i915_getparam_t
*param
= data
;
796 DRM_ERROR("called with no initialization\n");
800 switch (param
->param
) {
801 case I915_PARAM_IRQ_ACTIVE
:
802 value
= dev
->pdev
->irq
? 1 : 0;
804 case I915_PARAM_ALLOW_BATCHBUFFER
:
805 value
= dev_priv
->allow_batchbuffer
? 1 : 0;
807 case I915_PARAM_LAST_DISPATCH
:
808 value
= READ_BREADCRUMB(dev_priv
);
810 case I915_PARAM_CHIPSET_ID
:
811 value
= dev
->pci_device
;
813 case I915_PARAM_HAS_GEM
:
814 value
= dev_priv
->has_gem
;
816 case I915_PARAM_NUM_FENCES_AVAIL
:
817 value
= dev_priv
->num_fence_regs
- dev_priv
->fence_reg_start
;
819 case I915_PARAM_HAS_OVERLAY
:
820 value
= dev_priv
->overlay
? 1 : 0;
822 case I915_PARAM_HAS_PAGEFLIPPING
:
825 case I915_PARAM_HAS_EXECBUF2
:
827 value
= dev_priv
->has_gem
;
830 DRM_DEBUG_DRIVER("Unknown parameter %d\n",
835 if (DRM_COPY_TO_USER(param
->value
, &value
, sizeof(int))) {
836 DRM_ERROR("DRM_COPY_TO_USER failed\n");
843 static int i915_setparam(struct drm_device
*dev
, void *data
,
844 struct drm_file
*file_priv
)
846 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
847 drm_i915_setparam_t
*param
= data
;
850 DRM_ERROR("called with no initialization\n");
854 switch (param
->param
) {
855 case I915_SETPARAM_USE_MI_BATCHBUFFER_START
:
857 case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY
:
858 dev_priv
->tex_lru_log_granularity
= param
->value
;
860 case I915_SETPARAM_ALLOW_BATCHBUFFER
:
861 dev_priv
->allow_batchbuffer
= param
->value
;
863 case I915_SETPARAM_NUM_USED_FENCES
:
864 if (param
->value
> dev_priv
->num_fence_regs
||
867 /* Userspace can use first N regs */
868 dev_priv
->fence_reg_start
= param
->value
;
871 DRM_DEBUG_DRIVER("unknown parameter %d\n",
879 static int i915_set_status_page(struct drm_device
*dev
, void *data
,
880 struct drm_file
*file_priv
)
882 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
883 drm_i915_hws_addr_t
*hws
= data
;
885 if (!I915_NEED_GFX_HWS(dev
))
889 DRM_ERROR("called with no initialization\n");
893 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
894 WARN(1, "tried to set status page when mode setting active\n");
898 DRM_DEBUG_DRIVER("set status page addr 0x%08x\n", (u32
)hws
->addr
);
900 dev_priv
->status_gfx_addr
= hws
->addr
& (0x1ffff<<12);
902 dev_priv
->hws_map
.offset
= dev
->agp
->base
+ hws
->addr
;
903 dev_priv
->hws_map
.size
= 4*1024;
904 dev_priv
->hws_map
.type
= 0;
905 dev_priv
->hws_map
.flags
= 0;
906 dev_priv
->hws_map
.mtrr
= 0;
908 drm_core_ioremap_wc(&dev_priv
->hws_map
, dev
);
909 if (dev_priv
->hws_map
.handle
== NULL
) {
910 i915_dma_cleanup(dev
);
911 dev_priv
->status_gfx_addr
= 0;
912 DRM_ERROR("can not ioremap virtual address for"
913 " G33 hw status page\n");
916 dev_priv
->hw_status_page
= dev_priv
->hws_map
.handle
;
918 memset(dev_priv
->hw_status_page
, 0, PAGE_SIZE
);
919 I915_WRITE(HWS_PGA
, dev_priv
->status_gfx_addr
);
920 DRM_DEBUG_DRIVER("load hws HWS_PGA with gfx mem 0x%x\n",
921 dev_priv
->status_gfx_addr
);
922 DRM_DEBUG_DRIVER("load hws at %p\n",
923 dev_priv
->hw_status_page
);
927 static int i915_get_bridge_dev(struct drm_device
*dev
)
929 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
931 dev_priv
->bridge_dev
= pci_get_bus_and_slot(0, PCI_DEVFN(0,0));
932 if (!dev_priv
->bridge_dev
) {
933 DRM_ERROR("bridge device not found\n");
939 #define MCHBAR_I915 0x44
940 #define MCHBAR_I965 0x48
941 #define MCHBAR_SIZE (4*4096)
943 #define DEVEN_REG 0x54
944 #define DEVEN_MCHBAR_EN (1 << 28)
946 /* Allocate space for the MCH regs if needed, return nonzero on error */
948 intel_alloc_mchbar_resource(struct drm_device
*dev
)
950 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
951 int reg
= IS_I965G(dev
) ? MCHBAR_I965
: MCHBAR_I915
;
952 u32 temp_lo
, temp_hi
= 0;
957 pci_read_config_dword(dev_priv
->bridge_dev
, reg
+ 4, &temp_hi
);
958 pci_read_config_dword(dev_priv
->bridge_dev
, reg
, &temp_lo
);
959 mchbar_addr
= ((u64
)temp_hi
<< 32) | temp_lo
;
961 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
964 pnp_range_reserved(mchbar_addr
, mchbar_addr
+ MCHBAR_SIZE
)) {
970 /* Get some space for it */
971 ret
= pci_bus_alloc_resource(dev_priv
->bridge_dev
->bus
, &dev_priv
->mch_res
,
972 MCHBAR_SIZE
, MCHBAR_SIZE
,
974 0, pcibios_align_resource
,
975 dev_priv
->bridge_dev
);
977 DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret
);
978 dev_priv
->mch_res
.start
= 0;
983 pci_write_config_dword(dev_priv
->bridge_dev
, reg
+ 4,
984 upper_32_bits(dev_priv
->mch_res
.start
));
986 pci_write_config_dword(dev_priv
->bridge_dev
, reg
,
987 lower_32_bits(dev_priv
->mch_res
.start
));
992 /* Setup MCHBAR if possible, return true if we should disable it again */
994 intel_setup_mchbar(struct drm_device
*dev
)
996 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
997 int mchbar_reg
= IS_I965G(dev
) ? MCHBAR_I965
: MCHBAR_I915
;
1001 dev_priv
->mchbar_need_disable
= false;
1003 if (IS_I915G(dev
) || IS_I915GM(dev
)) {
1004 pci_read_config_dword(dev_priv
->bridge_dev
, DEVEN_REG
, &temp
);
1005 enabled
= !!(temp
& DEVEN_MCHBAR_EN
);
1007 pci_read_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, &temp
);
1011 /* If it's already enabled, don't have to do anything */
1015 if (intel_alloc_mchbar_resource(dev
))
1018 dev_priv
->mchbar_need_disable
= true;
1020 /* Space is allocated or reserved, so enable it. */
1021 if (IS_I915G(dev
) || IS_I915GM(dev
)) {
1022 pci_write_config_dword(dev_priv
->bridge_dev
, DEVEN_REG
,
1023 temp
| DEVEN_MCHBAR_EN
);
1025 pci_read_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, &temp
);
1026 pci_write_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, temp
| 1);
1031 intel_teardown_mchbar(struct drm_device
*dev
)
1033 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
1034 int mchbar_reg
= IS_I965G(dev
) ? MCHBAR_I965
: MCHBAR_I915
;
1037 if (dev_priv
->mchbar_need_disable
) {
1038 if (IS_I915G(dev
) || IS_I915GM(dev
)) {
1039 pci_read_config_dword(dev_priv
->bridge_dev
, DEVEN_REG
, &temp
);
1040 temp
&= ~DEVEN_MCHBAR_EN
;
1041 pci_write_config_dword(dev_priv
->bridge_dev
, DEVEN_REG
, temp
);
1043 pci_read_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, &temp
);
1045 pci_write_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, temp
);
1049 if (dev_priv
->mch_res
.start
)
1050 release_resource(&dev_priv
->mch_res
);
1054 * i915_probe_agp - get AGP bootup configuration
1056 * @aperture_size: returns AGP aperture configured size
1057 * @preallocated_size: returns size of BIOS preallocated AGP space
1059 * Since Intel integrated graphics are UMA, the BIOS has to set aside
1060 * some RAM for the framebuffer at early boot. This code figures out
1061 * how much was set aside so we can use it for our own purposes.
1063 static int i915_probe_agp(struct drm_device
*dev
, uint32_t *aperture_size
,
1064 uint32_t *preallocated_size
,
1067 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1069 unsigned long overhead
;
1070 unsigned long stolen
;
1072 /* Get the fb aperture size and "stolen" memory amount. */
1073 pci_read_config_word(dev_priv
->bridge_dev
, INTEL_GMCH_CTRL
, &tmp
);
1075 *aperture_size
= 1024 * 1024;
1076 *preallocated_size
= 1024 * 1024;
1078 switch (dev
->pdev
->device
) {
1079 case PCI_DEVICE_ID_INTEL_82830_CGC
:
1080 case PCI_DEVICE_ID_INTEL_82845G_IG
:
1081 case PCI_DEVICE_ID_INTEL_82855GM_IG
:
1082 case PCI_DEVICE_ID_INTEL_82865_IG
:
1083 if ((tmp
& INTEL_GMCH_MEM_MASK
) == INTEL_GMCH_MEM_64M
)
1084 *aperture_size
*= 64;
1086 *aperture_size
*= 128;
1089 /* 9xx supports large sizes, just look at the length */
1090 *aperture_size
= pci_resource_len(dev
->pdev
, 2);
1095 * Some of the preallocated space is taken by the GTT
1096 * and popup. GTT is 1K per MB of aperture size, and popup is 4K.
1098 if (IS_G4X(dev
) || IS_PINEVIEW(dev
) || IS_IRONLAKE(dev
) || IS_GEN6(dev
))
1101 overhead
= (*aperture_size
/ 1024) + 4096;
1104 /* SNB has memory control reg at 0x50.w */
1105 pci_read_config_word(dev
->pdev
, SNB_GMCH_CTRL
, &tmp
);
1107 switch (tmp
& SNB_GMCH_GMS_STOLEN_MASK
) {
1108 case INTEL_855_GMCH_GMS_DISABLED
:
1109 DRM_ERROR("video memory is disabled\n");
1111 case SNB_GMCH_GMS_STOLEN_32M
:
1112 stolen
= 32 * 1024 * 1024;
1114 case SNB_GMCH_GMS_STOLEN_64M
:
1115 stolen
= 64 * 1024 * 1024;
1117 case SNB_GMCH_GMS_STOLEN_96M
:
1118 stolen
= 96 * 1024 * 1024;
1120 case SNB_GMCH_GMS_STOLEN_128M
:
1121 stolen
= 128 * 1024 * 1024;
1123 case SNB_GMCH_GMS_STOLEN_160M
:
1124 stolen
= 160 * 1024 * 1024;
1126 case SNB_GMCH_GMS_STOLEN_192M
:
1127 stolen
= 192 * 1024 * 1024;
1129 case SNB_GMCH_GMS_STOLEN_224M
:
1130 stolen
= 224 * 1024 * 1024;
1132 case SNB_GMCH_GMS_STOLEN_256M
:
1133 stolen
= 256 * 1024 * 1024;
1135 case SNB_GMCH_GMS_STOLEN_288M
:
1136 stolen
= 288 * 1024 * 1024;
1138 case SNB_GMCH_GMS_STOLEN_320M
:
1139 stolen
= 320 * 1024 * 1024;
1141 case SNB_GMCH_GMS_STOLEN_352M
:
1142 stolen
= 352 * 1024 * 1024;
1144 case SNB_GMCH_GMS_STOLEN_384M
:
1145 stolen
= 384 * 1024 * 1024;
1147 case SNB_GMCH_GMS_STOLEN_416M
:
1148 stolen
= 416 * 1024 * 1024;
1150 case SNB_GMCH_GMS_STOLEN_448M
:
1151 stolen
= 448 * 1024 * 1024;
1153 case SNB_GMCH_GMS_STOLEN_480M
:
1154 stolen
= 480 * 1024 * 1024;
1156 case SNB_GMCH_GMS_STOLEN_512M
:
1157 stolen
= 512 * 1024 * 1024;
1160 DRM_ERROR("unexpected GMCH_GMS value: 0x%02x\n",
1161 tmp
& SNB_GMCH_GMS_STOLEN_MASK
);
1165 switch (tmp
& INTEL_GMCH_GMS_MASK
) {
1166 case INTEL_855_GMCH_GMS_DISABLED
:
1167 DRM_ERROR("video memory is disabled\n");
1169 case INTEL_855_GMCH_GMS_STOLEN_1M
:
1170 stolen
= 1 * 1024 * 1024;
1172 case INTEL_855_GMCH_GMS_STOLEN_4M
:
1173 stolen
= 4 * 1024 * 1024;
1175 case INTEL_855_GMCH_GMS_STOLEN_8M
:
1176 stolen
= 8 * 1024 * 1024;
1178 case INTEL_855_GMCH_GMS_STOLEN_16M
:
1179 stolen
= 16 * 1024 * 1024;
1181 case INTEL_855_GMCH_GMS_STOLEN_32M
:
1182 stolen
= 32 * 1024 * 1024;
1184 case INTEL_915G_GMCH_GMS_STOLEN_48M
:
1185 stolen
= 48 * 1024 * 1024;
1187 case INTEL_915G_GMCH_GMS_STOLEN_64M
:
1188 stolen
= 64 * 1024 * 1024;
1190 case INTEL_GMCH_GMS_STOLEN_128M
:
1191 stolen
= 128 * 1024 * 1024;
1193 case INTEL_GMCH_GMS_STOLEN_256M
:
1194 stolen
= 256 * 1024 * 1024;
1196 case INTEL_GMCH_GMS_STOLEN_96M
:
1197 stolen
= 96 * 1024 * 1024;
1199 case INTEL_GMCH_GMS_STOLEN_160M
:
1200 stolen
= 160 * 1024 * 1024;
1202 case INTEL_GMCH_GMS_STOLEN_224M
:
1203 stolen
= 224 * 1024 * 1024;
1205 case INTEL_GMCH_GMS_STOLEN_352M
:
1206 stolen
= 352 * 1024 * 1024;
1209 DRM_ERROR("unexpected GMCH_GMS value: 0x%02x\n",
1210 tmp
& INTEL_GMCH_GMS_MASK
);
1215 *preallocated_size
= stolen
- overhead
;
1221 #define PTE_ADDRESS_MASK 0xfffff000
1222 #define PTE_ADDRESS_MASK_HIGH 0x000000f0 /* i915+ */
1223 #define PTE_MAPPING_TYPE_UNCACHED (0 << 1)
1224 #define PTE_MAPPING_TYPE_DCACHE (1 << 1) /* i830 only */
1225 #define PTE_MAPPING_TYPE_CACHED (3 << 1)
1226 #define PTE_MAPPING_TYPE_MASK (3 << 1)
1227 #define PTE_VALID (1 << 0)
1230 * i915_gtt_to_phys - take a GTT address and turn it into a physical one
1232 * @gtt_addr: address to translate
1234 * Some chip functions require allocations from stolen space but need the
1235 * physical address of the memory in question. We use this routine
1236 * to get a physical address suitable for register programming from a given
1239 static unsigned long i915_gtt_to_phys(struct drm_device
*dev
,
1240 unsigned long gtt_addr
)
1243 unsigned long entry
, phys
;
1244 int gtt_bar
= IS_I9XX(dev
) ? 0 : 1;
1245 int gtt_offset
, gtt_size
;
1247 if (IS_I965G(dev
)) {
1248 if (IS_G4X(dev
) || IS_IRONLAKE(dev
) || IS_GEN6(dev
)) {
1249 gtt_offset
= 2*1024*1024;
1250 gtt_size
= 2*1024*1024;
1252 gtt_offset
= 512*1024;
1253 gtt_size
= 512*1024;
1258 gtt_size
= pci_resource_len(dev
->pdev
, gtt_bar
);
1261 gtt
= ioremap_wc(pci_resource_start(dev
->pdev
, gtt_bar
) + gtt_offset
,
1264 DRM_ERROR("ioremap of GTT failed\n");
1268 entry
= *(volatile u32
*)(gtt
+ (gtt_addr
/ 1024));
1270 DRM_DEBUG_DRIVER("GTT addr: 0x%08lx, PTE: 0x%08lx\n", gtt_addr
, entry
);
1272 /* Mask out these reserved bits on this hardware. */
1273 if (!IS_I9XX(dev
) || IS_I915G(dev
) || IS_I915GM(dev
) ||
1274 IS_I945G(dev
) || IS_I945GM(dev
)) {
1275 entry
&= ~PTE_ADDRESS_MASK_HIGH
;
1278 /* If it's not a mapping type we know, then bail. */
1279 if ((entry
& PTE_MAPPING_TYPE_MASK
) != PTE_MAPPING_TYPE_UNCACHED
&&
1280 (entry
& PTE_MAPPING_TYPE_MASK
) != PTE_MAPPING_TYPE_CACHED
) {
1285 if (!(entry
& PTE_VALID
)) {
1286 DRM_ERROR("bad GTT entry in stolen space\n");
1293 phys
=(entry
& PTE_ADDRESS_MASK
) |
1294 ((uint64_t)(entry
& PTE_ADDRESS_MASK_HIGH
) << (32 - 4));
1296 DRM_DEBUG_DRIVER("GTT addr: 0x%08lx, phys addr: 0x%08lx\n", gtt_addr
, phys
);
1301 static void i915_warn_stolen(struct drm_device
*dev
)
1303 DRM_ERROR("not enough stolen space for compressed buffer, disabling\n");
1304 DRM_ERROR("hint: you may be able to increase stolen memory size in the BIOS to avoid this\n");
1307 static void i915_setup_compression(struct drm_device
*dev
, int size
)
1309 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1310 struct drm_mm_node
*compressed_fb
, *compressed_llb
;
1311 unsigned long cfb_base
;
1312 unsigned long ll_base
= 0;
1314 /* Leave 1M for line length buffer & misc. */
1315 compressed_fb
= drm_mm_search_free(&dev_priv
->vram
, size
, 4096, 0);
1316 if (!compressed_fb
) {
1317 dev_priv
->no_fbc_reason
= FBC_STOLEN_TOO_SMALL
;
1318 i915_warn_stolen(dev
);
1322 compressed_fb
= drm_mm_get_block(compressed_fb
, size
, 4096);
1323 if (!compressed_fb
) {
1324 i915_warn_stolen(dev
);
1325 dev_priv
->no_fbc_reason
= FBC_STOLEN_TOO_SMALL
;
1329 cfb_base
= i915_gtt_to_phys(dev
, compressed_fb
->start
);
1331 DRM_ERROR("failed to get stolen phys addr, disabling FBC\n");
1332 drm_mm_put_block(compressed_fb
);
1335 if (!IS_GM45(dev
)) {
1336 compressed_llb
= drm_mm_search_free(&dev_priv
->vram
, 4096,
1338 if (!compressed_llb
) {
1339 i915_warn_stolen(dev
);
1343 compressed_llb
= drm_mm_get_block(compressed_llb
, 4096, 4096);
1344 if (!compressed_llb
) {
1345 i915_warn_stolen(dev
);
1349 ll_base
= i915_gtt_to_phys(dev
, compressed_llb
->start
);
1351 DRM_ERROR("failed to get stolen phys addr, disabling FBC\n");
1352 drm_mm_put_block(compressed_fb
);
1353 drm_mm_put_block(compressed_llb
);
1357 dev_priv
->cfb_size
= size
;
1360 g4x_disable_fbc(dev
);
1361 I915_WRITE(DPFC_CB_BASE
, compressed_fb
->start
);
1363 i8xx_disable_fbc(dev
);
1364 I915_WRITE(FBC_CFB_BASE
, cfb_base
);
1365 I915_WRITE(FBC_LL_BASE
, ll_base
);
1368 DRM_DEBUG("FBC base 0x%08lx, ll base 0x%08lx, size %dM\n", cfb_base
,
1369 ll_base
, size
>> 20);
1372 /* true = enable decode, false = disable decoder */
1373 static unsigned int i915_vga_set_decode(void *cookie
, bool state
)
1375 struct drm_device
*dev
= cookie
;
1377 intel_modeset_vga_set_state(dev
, state
);
1379 return VGA_RSRC_LEGACY_IO
| VGA_RSRC_LEGACY_MEM
|
1380 VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
1382 return VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
1385 static void i915_switcheroo_set_state(struct pci_dev
*pdev
, enum vga_switcheroo_state state
)
1387 struct drm_device
*dev
= pci_get_drvdata(pdev
);
1388 pm_message_t pmm
= { .event
= PM_EVENT_SUSPEND
};
1389 if (state
== VGA_SWITCHEROO_ON
) {
1390 printk(KERN_INFO
"i915: switched off\n");
1391 /* i915 resume handler doesn't set to D0 */
1392 pci_set_power_state(dev
->pdev
, PCI_D0
);
1395 printk(KERN_ERR
"i915: switched off\n");
1396 i915_suspend(dev
, pmm
);
1400 static bool i915_switcheroo_can_switch(struct pci_dev
*pdev
)
1402 struct drm_device
*dev
= pci_get_drvdata(pdev
);
1405 spin_lock(&dev
->count_lock
);
1406 can_switch
= (dev
->open_count
== 0);
1407 spin_unlock(&dev
->count_lock
);
1411 static int i915_load_modeset_init(struct drm_device
*dev
,
1412 unsigned long prealloc_start
,
1413 unsigned long prealloc_size
,
1414 unsigned long agp_size
)
1416 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1417 int fb_bar
= IS_I9XX(dev
) ? 2 : 0;
1420 dev
->mode_config
.fb_base
= drm_get_resource_start(dev
, fb_bar
) &
1423 /* Basic memrange allocator for stolen space (aka vram) */
1424 drm_mm_init(&dev_priv
->vram
, 0, prealloc_size
);
1425 DRM_INFO("set up %ldM of stolen space\n", prealloc_size
/ (1024*1024));
1427 /* We're off and running w/KMS */
1428 dev_priv
->mm
.suspended
= 0;
1430 /* Let GEM Manage from end of prealloc space to end of aperture.
1432 * However, leave one page at the end still bound to the scratch page.
1433 * There are a number of places where the hardware apparently
1434 * prefetches past the end of the object, and we've seen multiple
1435 * hangs with the GPU head pointer stuck in a batchbuffer bound
1436 * at the last page of the aperture. One page should be enough to
1437 * keep any prefetching inside of the aperture.
1439 i915_gem_do_init(dev
, prealloc_size
, agp_size
- 4096);
1441 mutex_lock(&dev
->struct_mutex
);
1442 ret
= i915_gem_init_ringbuffer(dev
);
1443 mutex_unlock(&dev
->struct_mutex
);
1447 /* Try to set up FBC with a reasonable compressed buffer size */
1448 if (I915_HAS_FBC(dev
) && i915_powersave
) {
1451 /* Try to get an 8M buffer... */
1452 if (prealloc_size
> (9*1024*1024))
1453 cfb_size
= 8*1024*1024;
1454 else /* fall back to 7/8 of the stolen space */
1455 cfb_size
= prealloc_size
* 7 / 8;
1456 i915_setup_compression(dev
, cfb_size
);
1459 /* Allow hardware batchbuffers unless told otherwise.
1461 dev_priv
->allow_batchbuffer
= 1;
1463 ret
= intel_init_bios(dev
);
1465 DRM_INFO("failed to find VBIOS tables\n");
1467 /* if we have > 1 VGA cards, then disable the radeon VGA resources */
1468 ret
= vga_client_register(dev
->pdev
, dev
, NULL
, i915_vga_set_decode
);
1470 goto destroy_ringbuffer
;
1472 ret
= vga_switcheroo_register_client(dev
->pdev
,
1473 i915_switcheroo_set_state
,
1474 i915_switcheroo_can_switch
);
1476 goto destroy_ringbuffer
;
1478 intel_modeset_init(dev
);
1480 ret
= drm_irq_install(dev
);
1482 goto destroy_ringbuffer
;
1484 /* Always safe in the mode setting case. */
1485 /* FIXME: do pre/post-mode set stuff in core KMS code */
1486 dev
->vblank_disable_allowed
= 1;
1489 * Initialize the hardware status page IRQ location.
1492 I915_WRITE(INSTPM
, (1 << 5) | (1 << 21));
1494 drm_helper_initial_config(dev
);
1499 mutex_lock(&dev
->struct_mutex
);
1500 i915_gem_cleanup_ringbuffer(dev
);
1501 mutex_unlock(&dev
->struct_mutex
);
1506 int i915_master_create(struct drm_device
*dev
, struct drm_master
*master
)
1508 struct drm_i915_master_private
*master_priv
;
1510 master_priv
= kzalloc(sizeof(*master_priv
), GFP_KERNEL
);
1514 master
->driver_priv
= master_priv
;
1518 void i915_master_destroy(struct drm_device
*dev
, struct drm_master
*master
)
1520 struct drm_i915_master_private
*master_priv
= master
->driver_priv
;
1527 master
->driver_priv
= NULL
;
1530 static void i915_get_mem_freq(struct drm_device
*dev
)
1532 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
1535 if (!IS_PINEVIEW(dev
))
1538 tmp
= I915_READ(CLKCFG
);
1540 switch (tmp
& CLKCFG_FSB_MASK
) {
1541 case CLKCFG_FSB_533
:
1542 dev_priv
->fsb_freq
= 533; /* 133*4 */
1544 case CLKCFG_FSB_800
:
1545 dev_priv
->fsb_freq
= 800; /* 200*4 */
1547 case CLKCFG_FSB_667
:
1548 dev_priv
->fsb_freq
= 667; /* 167*4 */
1550 case CLKCFG_FSB_400
:
1551 dev_priv
->fsb_freq
= 400; /* 100*4 */
1555 switch (tmp
& CLKCFG_MEM_MASK
) {
1556 case CLKCFG_MEM_533
:
1557 dev_priv
->mem_freq
= 533;
1559 case CLKCFG_MEM_667
:
1560 dev_priv
->mem_freq
= 667;
1562 case CLKCFG_MEM_800
:
1563 dev_priv
->mem_freq
= 800;
1569 * i915_driver_load - setup chip and create an initial config
1571 * @flags: startup flags
1573 * The driver load routine has to do several things:
1574 * - drive output discovery via intel_modeset_init()
1575 * - initialize the memory manager
1576 * - allocate initial config memory
1577 * - setup the DRM framebuffer with the allocated memory
1579 int i915_driver_load(struct drm_device
*dev
, unsigned long flags
)
1581 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1582 resource_size_t base
, size
;
1583 int ret
= 0, mmio_bar
;
1584 uint32_t agp_size
, prealloc_size
, prealloc_start
;
1586 /* i915 has 4 more counters */
1588 dev
->types
[6] = _DRM_STAT_IRQ
;
1589 dev
->types
[7] = _DRM_STAT_PRIMARY
;
1590 dev
->types
[8] = _DRM_STAT_SECONDARY
;
1591 dev
->types
[9] = _DRM_STAT_DMA
;
1593 dev_priv
= kzalloc(sizeof(drm_i915_private_t
), GFP_KERNEL
);
1594 if (dev_priv
== NULL
)
1597 dev
->dev_private
= (void *)dev_priv
;
1598 dev_priv
->dev
= dev
;
1599 dev_priv
->info
= (struct intel_device_info
*) flags
;
1601 /* Add register map (needed for suspend/resume) */
1602 mmio_bar
= IS_I9XX(dev
) ? 0 : 1;
1603 base
= drm_get_resource_start(dev
, mmio_bar
);
1604 size
= drm_get_resource_len(dev
, mmio_bar
);
1606 if (i915_get_bridge_dev(dev
)) {
1611 dev_priv
->regs
= ioremap(base
, size
);
1612 if (!dev_priv
->regs
) {
1613 DRM_ERROR("failed to map registers\n");
1618 dev_priv
->mm
.gtt_mapping
=
1619 io_mapping_create_wc(dev
->agp
->base
,
1620 dev
->agp
->agp_info
.aper_size
* 1024*1024);
1621 if (dev_priv
->mm
.gtt_mapping
== NULL
) {
1626 /* Set up a WC MTRR for non-PAT systems. This is more common than
1627 * one would think, because the kernel disables PAT on first
1628 * generation Core chips because WC PAT gets overridden by a UC
1629 * MTRR if present. Even if a UC MTRR isn't present.
1631 dev_priv
->mm
.gtt_mtrr
= mtrr_add(dev
->agp
->base
,
1632 dev
->agp
->agp_info
.aper_size
*
1634 MTRR_TYPE_WRCOMB
, 1);
1635 if (dev_priv
->mm
.gtt_mtrr
< 0) {
1636 DRM_INFO("MTRR allocation failed. Graphics "
1637 "performance may suffer.\n");
1640 ret
= i915_probe_agp(dev
, &agp_size
, &prealloc_size
, &prealloc_start
);
1644 dev_priv
->wq
= create_singlethread_workqueue("i915");
1645 if (dev_priv
->wq
== NULL
) {
1646 DRM_ERROR("Failed to create our workqueue.\n");
1651 /* enable GEM by default */
1652 dev_priv
->has_gem
= 1;
1654 if (prealloc_size
> agp_size
* 3 / 4) {
1655 DRM_ERROR("Detected broken video BIOS with %d/%dkB of video "
1657 prealloc_size
/ 1024, agp_size
/ 1024);
1658 DRM_ERROR("Disabling GEM. (try reducing stolen memory or "
1659 "updating the BIOS to fix).\n");
1660 dev_priv
->has_gem
= 0;
1663 dev
->driver
->get_vblank_counter
= i915_get_vblank_counter
;
1664 dev
->max_vblank_count
= 0xffffff; /* only 24 bits of frame count */
1665 if (IS_G4X(dev
) || IS_IRONLAKE(dev
) || IS_GEN6(dev
)) {
1666 dev
->max_vblank_count
= 0xffffffff; /* full 32 bit counter */
1667 dev
->driver
->get_vblank_counter
= gm45_get_vblank_counter
;
1670 /* Try to make sure MCHBAR is enabled before poking at it */
1671 intel_setup_mchbar(dev
);
1676 if (!I915_NEED_GFX_HWS(dev
)) {
1677 ret
= i915_init_phys_hws(dev
);
1679 goto out_workqueue_free
;
1682 i915_get_mem_freq(dev
);
1684 /* On the 945G/GM, the chipset reports the MSI capability on the
1685 * integrated graphics even though the support isn't actually there
1686 * according to the published specs. It doesn't appear to function
1687 * correctly in testing on 945G.
1688 * This may be a side effect of MSI having been made available for PEG
1689 * and the registers being closely associated.
1691 * According to chipset errata, on the 965GM, MSI interrupts may
1692 * be lost or delayed, but we use them anyways to avoid
1693 * stuck interrupts on some machines.
1695 if (!IS_I945G(dev
) && !IS_I945GM(dev
))
1696 pci_enable_msi(dev
->pdev
);
1698 spin_lock_init(&dev_priv
->user_irq_lock
);
1699 spin_lock_init(&dev_priv
->error_lock
);
1700 dev_priv
->user_irq_refcount
= 0;
1701 dev_priv
->trace_irq_seqno
= 0;
1703 ret
= drm_vblank_init(dev
, I915_NUM_PIPE
);
1706 (void) i915_driver_unload(dev
);
1710 /* Start out suspended */
1711 dev_priv
->mm
.suspended
= 1;
1713 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
1714 ret
= i915_load_modeset_init(dev
, prealloc_start
,
1715 prealloc_size
, agp_size
);
1717 DRM_ERROR("failed to init modeset\n");
1718 goto out_workqueue_free
;
1722 /* Must be done after probing outputs */
1723 intel_opregion_init(dev
, 0);
1725 setup_timer(&dev_priv
->hangcheck_timer
, i915_hangcheck_elapsed
,
1726 (unsigned long) dev
);
1730 destroy_workqueue(dev_priv
->wq
);
1732 io_mapping_free(dev_priv
->mm
.gtt_mapping
);
1734 iounmap(dev_priv
->regs
);
1736 pci_dev_put(dev_priv
->bridge_dev
);
1742 int i915_driver_unload(struct drm_device
*dev
)
1744 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1746 i915_destroy_error_state(dev
);
1748 destroy_workqueue(dev_priv
->wq
);
1749 del_timer_sync(&dev_priv
->hangcheck_timer
);
1751 io_mapping_free(dev_priv
->mm
.gtt_mapping
);
1752 if (dev_priv
->mm
.gtt_mtrr
>= 0) {
1753 mtrr_del(dev_priv
->mm
.gtt_mtrr
, dev
->agp
->base
,
1754 dev
->agp
->agp_info
.aper_size
* 1024 * 1024);
1755 dev_priv
->mm
.gtt_mtrr
= -1;
1758 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
1760 * free the memory space allocated for the child device
1761 * config parsed from VBT
1763 if (dev_priv
->child_dev
&& dev_priv
->child_dev_num
) {
1764 kfree(dev_priv
->child_dev
);
1765 dev_priv
->child_dev
= NULL
;
1766 dev_priv
->child_dev_num
= 0;
1768 drm_irq_uninstall(dev
);
1769 vga_switcheroo_unregister_client(dev
->pdev
);
1770 vga_client_register(dev
->pdev
, NULL
, NULL
, NULL
);
1773 if (dev
->pdev
->msi_enabled
)
1774 pci_disable_msi(dev
->pdev
);
1776 if (dev_priv
->regs
!= NULL
)
1777 iounmap(dev_priv
->regs
);
1779 intel_opregion_free(dev
, 0);
1781 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
1782 intel_modeset_cleanup(dev
);
1784 i915_gem_free_all_phys_object(dev
);
1786 mutex_lock(&dev
->struct_mutex
);
1787 i915_gem_cleanup_ringbuffer(dev
);
1788 mutex_unlock(&dev
->struct_mutex
);
1789 drm_mm_takedown(&dev_priv
->vram
);
1790 i915_gem_lastclose(dev
);
1792 intel_cleanup_overlay(dev
);
1795 intel_teardown_mchbar(dev
);
1797 pci_dev_put(dev_priv
->bridge_dev
);
1798 kfree(dev
->dev_private
);
1803 int i915_driver_open(struct drm_device
*dev
, struct drm_file
*file_priv
)
1805 struct drm_i915_file_private
*i915_file_priv
;
1807 DRM_DEBUG_DRIVER("\n");
1808 i915_file_priv
= (struct drm_i915_file_private
*)
1809 kmalloc(sizeof(*i915_file_priv
), GFP_KERNEL
);
1811 if (!i915_file_priv
)
1814 file_priv
->driver_priv
= i915_file_priv
;
1816 INIT_LIST_HEAD(&i915_file_priv
->mm
.request_list
);
1822 * i915_driver_lastclose - clean up after all DRM clients have exited
1825 * Take care of cleaning up after all DRM clients have exited. In the
1826 * mode setting case, we want to restore the kernel's initial mode (just
1827 * in case the last client left us in a bad state).
1829 * Additionally, in the non-mode setting case, we'll tear down the AGP
1830 * and DMA structures, since the kernel won't be using them, and clea
1833 void i915_driver_lastclose(struct drm_device
* dev
)
1835 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
1837 if (!dev_priv
|| drm_core_check_feature(dev
, DRIVER_MODESET
)) {
1838 drm_fb_helper_restore();
1839 vga_switcheroo_process_delayed_switch();
1843 i915_gem_lastclose(dev
);
1845 if (dev_priv
->agp_heap
)
1846 i915_mem_takedown(&(dev_priv
->agp_heap
));
1848 i915_dma_cleanup(dev
);
1851 void i915_driver_preclose(struct drm_device
* dev
, struct drm_file
*file_priv
)
1853 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
1854 i915_gem_release(dev
, file_priv
);
1855 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1856 i915_mem_release(dev
, file_priv
, dev_priv
->agp_heap
);
1859 void i915_driver_postclose(struct drm_device
*dev
, struct drm_file
*file_priv
)
1861 struct drm_i915_file_private
*i915_file_priv
= file_priv
->driver_priv
;
1863 kfree(i915_file_priv
);
1866 struct drm_ioctl_desc i915_ioctls
[] = {
1867 DRM_IOCTL_DEF(DRM_I915_INIT
, i915_dma_init
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1868 DRM_IOCTL_DEF(DRM_I915_FLUSH
, i915_flush_ioctl
, DRM_AUTH
),
1869 DRM_IOCTL_DEF(DRM_I915_FLIP
, i915_flip_bufs
, DRM_AUTH
),
1870 DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER
, i915_batchbuffer
, DRM_AUTH
),
1871 DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT
, i915_irq_emit
, DRM_AUTH
),
1872 DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT
, i915_irq_wait
, DRM_AUTH
),
1873 DRM_IOCTL_DEF(DRM_I915_GETPARAM
, i915_getparam
, DRM_AUTH
),
1874 DRM_IOCTL_DEF(DRM_I915_SETPARAM
, i915_setparam
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1875 DRM_IOCTL_DEF(DRM_I915_ALLOC
, i915_mem_alloc
, DRM_AUTH
),
1876 DRM_IOCTL_DEF(DRM_I915_FREE
, i915_mem_free
, DRM_AUTH
),
1877 DRM_IOCTL_DEF(DRM_I915_INIT_HEAP
, i915_mem_init_heap
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1878 DRM_IOCTL_DEF(DRM_I915_CMDBUFFER
, i915_cmdbuffer
, DRM_AUTH
),
1879 DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP
, i915_mem_destroy_heap
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1880 DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE
, i915_vblank_pipe_set
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1881 DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE
, i915_vblank_pipe_get
, DRM_AUTH
),
1882 DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP
, i915_vblank_swap
, DRM_AUTH
),
1883 DRM_IOCTL_DEF(DRM_I915_HWS_ADDR
, i915_set_status_page
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1884 DRM_IOCTL_DEF(DRM_I915_GEM_INIT
, i915_gem_init_ioctl
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1885 DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER
, i915_gem_execbuffer
, DRM_AUTH
),
1886 DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER2
, i915_gem_execbuffer2
, DRM_AUTH
),
1887 DRM_IOCTL_DEF(DRM_I915_GEM_PIN
, i915_gem_pin_ioctl
, DRM_AUTH
|DRM_ROOT_ONLY
),
1888 DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN
, i915_gem_unpin_ioctl
, DRM_AUTH
|DRM_ROOT_ONLY
),
1889 DRM_IOCTL_DEF(DRM_I915_GEM_BUSY
, i915_gem_busy_ioctl
, DRM_AUTH
),
1890 DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE
, i915_gem_throttle_ioctl
, DRM_AUTH
),
1891 DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT
, i915_gem_entervt_ioctl
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1892 DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT
, i915_gem_leavevt_ioctl
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1893 DRM_IOCTL_DEF(DRM_I915_GEM_CREATE
, i915_gem_create_ioctl
, 0),
1894 DRM_IOCTL_DEF(DRM_I915_GEM_PREAD
, i915_gem_pread_ioctl
, 0),
1895 DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE
, i915_gem_pwrite_ioctl
, 0),
1896 DRM_IOCTL_DEF(DRM_I915_GEM_MMAP
, i915_gem_mmap_ioctl
, 0),
1897 DRM_IOCTL_DEF(DRM_I915_GEM_MMAP_GTT
, i915_gem_mmap_gtt_ioctl
, 0),
1898 DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN
, i915_gem_set_domain_ioctl
, 0),
1899 DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH
, i915_gem_sw_finish_ioctl
, 0),
1900 DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING
, i915_gem_set_tiling
, 0),
1901 DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING
, i915_gem_get_tiling
, 0),
1902 DRM_IOCTL_DEF(DRM_I915_GEM_GET_APERTURE
, i915_gem_get_aperture_ioctl
, 0),
1903 DRM_IOCTL_DEF(DRM_I915_GET_PIPE_FROM_CRTC_ID
, intel_get_pipe_from_crtc_id
, 0),
1904 DRM_IOCTL_DEF(DRM_I915_GEM_MADVISE
, i915_gem_madvise_ioctl
, 0),
1905 DRM_IOCTL_DEF(DRM_I915_OVERLAY_PUT_IMAGE
, intel_overlay_put_image
, DRM_MASTER
|DRM_CONTROL_ALLOW
),
1906 DRM_IOCTL_DEF(DRM_I915_OVERLAY_ATTRS
, intel_overlay_attrs
, DRM_MASTER
|DRM_CONTROL_ALLOW
),
1909 int i915_max_ioctl
= DRM_ARRAY_SIZE(i915_ioctls
);
1912 * Determine if the device really is AGP or not.
1914 * All Intel graphics chipsets are treated as AGP, even if they are really
1917 * \param dev The device to be tested.
1920 * A value of 1 is always retured to indictate every i9x5 is AGP.
1922 int i915_driver_device_is_agp(struct drm_device
* dev
)