1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include <sys/types.h>
34 #include <sys/ioctl.h>
38 #include "swrast/swrast.h"
40 #include "intel_context.h"
41 #include "intel_ioctl.h"
42 #include "intel_batchbuffer.h"
43 #include "intel_blit.h"
44 #include "intel_regions.h"
48 #include "intel_bufmgr.h"
50 #define FILE_DEBUG_FLAG DEBUG_IOCTL
53 intelEmitIrqLocked(struct intel_context
*intel
)
55 struct drm_i915_irq_emit ie
;
62 assert(((*(int *)intel->driHwLock) & ~DRM_LOCK_CONT) ==
63 (DRM_LOCK_HELD|intel->hHWContext));
68 ret
= drmCommandWriteRead(intel
->driFd
, DRM_I915_IRQ_EMIT
, &ie
, sizeof(ie
));
70 fprintf(stderr
, "%s: drm_i915_irq_emit: %d\n", __FUNCTION__
, ret
);
74 DBG("%s --> %d\n", __FUNCTION__
, seq
);
80 intelWaitIrq(struct intel_context
*intel
, int seq
)
82 struct drm_i915_irq_wait iw
;
83 int ret
, lastdispatch
;
84 volatile struct drm_i915_sarea
*sarea
= intel
->sarea
;
89 DBG("%s %d\n", __FUNCTION__
, seq
);
94 lastdispatch
= sarea
->last_dispatch
;
95 ret
= drmCommandWrite(intel
->driFd
, DRM_I915_IRQ_WAIT
, &iw
, sizeof(iw
));
96 } while (ret
== -EAGAIN
||
98 (ret
== -EBUSY
&& lastdispatch
!= sarea
->last_dispatch
) ||
99 (ret
== 0 && seq
> sarea
->last_dispatch
) ||
100 (ret
== 0 && sarea
->last_dispatch
- seq
>= (1 << 24)));
103 fprintf(stderr
, "%s: drm_i915_irq_wait: %d\n", __FUNCTION__
, ret
);
110 intel_batch_ioctl(struct intel_context
*intel
,
113 GLboolean ignore_cliprects
, GLboolean allow_unlock
)
115 struct drm_i915_batchbuffer batch
;
120 assert(intel
->locked
);
123 DBG("%s used %d offset %x..%x ignore_cliprects %d\n",
125 used
, start_offset
, start_offset
+ used
, ignore_cliprects
);
127 /* Throw away non-effective packets. Won't work once we have
128 * hardware contexts which would preserve statechanges beyond a
131 batch
.start
= start_offset
;
133 batch
.cliprects
= intel
->pClipRects
;
134 batch
.num_cliprects
= ignore_cliprects
? 0 : intel
->numClipRects
;
136 batch
.DR4
= ((((GLuint
) intel
->drawX
) & 0xffff) |
137 (((GLuint
) intel
->drawY
) << 16));
139 DBG("%s: 0x%x..0x%x DR4: %x cliprects: %d\n",
142 batch
.start
+ batch
.used
* 4, batch
.DR4
, batch
.num_cliprects
);
144 if (drmCommandWrite(intel
->driFd
, DRM_I915_BATCHBUFFER
, &batch
,
146 fprintf(stderr
, "DRM_I915_BATCHBUFFER: %d\n", -errno
);
154 intel_exec_ioctl(struct intel_context
*intel
,
156 GLboolean ignore_cliprects
, GLboolean allow_unlock
,
157 struct drm_i915_gem_execbuffer
*execbuf
)
161 assert(intel
->locked
);
167 execbuf
->batch_start_offset
= 0;
168 execbuf
->batch_len
= used
;
169 execbuf
->cliprects_ptr
= (uintptr_t)intel
->pClipRects
;
170 execbuf
->num_cliprects
= ignore_cliprects
? 0 : intel
->numClipRects
;
172 execbuf
->DR4
= ((((GLuint
) intel
->drawX
) & 0xffff) |
173 (((GLuint
) intel
->drawY
) << 16));
176 ret
= ioctl(intel
->driFd
, DRM_IOCTL_I915_GEM_EXECBUFFER
, execbuf
);
177 } while (ret
== -EAGAIN
);
180 fprintf(stderr
, "DRM_I915_GEM_EXECBUFFER: %d\n", -errno
);