Merge branch 'nouveau-import'
[mesa.git] / src / mesa / drivers / dri / i965 / intel_ioctl.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <sched.h>
33
34 #include "mtypes.h"
35 #include "context.h"
36 #include "swrast/swrast.h"
37
38 #include "intel_context.h"
39 #include "intel_ioctl.h"
40 #include "intel_batchbuffer.h"
41 #include "intel_blit.h"
42 #include "intel_regions.h"
43 #include "drm.h"
44 #include "bufmgr.h"
45
46
47 int intelEmitIrqLocked( struct intel_context *intel )
48 {
49 int seq = 1;
50
51 if (!intel->no_hw) {
52 drmI830IrqEmit ie;
53 int ret;
54
55 assert(((*(int *)intel->driHwLock) & ~DRM_LOCK_CONT) ==
56 (DRM_LOCK_HELD|intel->hHWContext));
57
58 ie.irq_seq = &seq;
59
60 ret = drmCommandWriteRead( intel->driFd, DRM_I830_IRQ_EMIT,
61 &ie, sizeof(ie) );
62 if ( ret ) {
63 fprintf( stderr, "%s: drmI830IrqEmit: %d\n", __FUNCTION__, ret );
64 exit(1);
65 }
66
67 if (0)
68 fprintf(stderr, "%s --> %d\n", __FUNCTION__, seq );
69 }
70
71 return seq;
72 }
73
74 void intelWaitIrq( struct intel_context *intel, int seq )
75 {
76 if (!intel->no_hw) {
77 drmI830IrqWait iw;
78 int ret, lastdispatch;
79
80 if (0)
81 fprintf(stderr, "%s %d\n", __FUNCTION__, seq );
82
83 iw.irq_seq = seq;
84
85 do {
86 lastdispatch = intel->sarea->last_dispatch;
87 ret = drmCommandWrite( intel->driFd, DRM_I830_IRQ_WAIT, &iw, sizeof(iw) );
88
89 /* This seems quite often to return before it should!?!
90 */
91 } while (ret == -EAGAIN || ret == -EINTR || (ret == -EBUSY && lastdispatch != intel->sarea->last_dispatch) || (ret == 0 && seq > intel->sarea->last_dispatch));
92
93
94 if ( ret ) {
95 fprintf( stderr, "%s: drmI830IrqWait: %d\n", __FUNCTION__, ret );
96
97 if (intel->aub_file) {
98 intel->vtbl.aub_dump_bmp( intel, intel->ctx.Visual.doubleBufferMode ? 1 : 0 );
99 }
100
101 exit(1);
102 }
103 }
104 }
105
106
107 void intel_batch_ioctl( struct intel_context *intel,
108 GLuint start_offset,
109 GLuint used)
110 {
111 drmI830BatchBuffer batch;
112
113 assert(intel->locked);
114 assert(used);
115
116 if (0)
117 fprintf(stderr, "%s used %d offset %x..%x\n",
118 __FUNCTION__,
119 used,
120 start_offset,
121 start_offset + used);
122
123 batch.start = start_offset;
124 batch.used = used;
125 batch.cliprects = NULL;
126 batch.num_cliprects = 0;
127 batch.DR1 = 0;
128 batch.DR4 = 0;
129
130 if (INTEL_DEBUG & DEBUG_DMA)
131 fprintf(stderr, "%s: 0x%x..0x%x\n",
132 __FUNCTION__,
133 batch.start,
134 batch.start + batch.used * 4);
135
136 if (!intel->no_hw) {
137 if (drmCommandWrite (intel->driFd, DRM_I830_BATCHBUFFER, &batch,
138 sizeof(batch))) {
139 fprintf(stderr, "DRM_I830_BATCHBUFFER: %d\n", -errno);
140 UNLOCK_HARDWARE(intel);
141 exit(1);
142 }
143 }
144 }
145
146 void intel_cmd_ioctl( struct intel_context *intel,
147 char *buf,
148 GLuint used)
149 {
150 drmI830CmdBuffer cmd;
151
152 assert(intel->locked);
153 assert(used);
154
155 cmd.buf = buf;
156 cmd.sz = used;
157 cmd.cliprects = intel->pClipRects;
158 cmd.num_cliprects = 0;
159 cmd.DR1 = 0;
160 cmd.DR4 = 0;
161
162 if (INTEL_DEBUG & DEBUG_DMA)
163 fprintf(stderr, "%s: 0x%x..0x%x\n",
164 __FUNCTION__,
165 0,
166 0 + cmd.sz);
167
168 if (!intel->no_hw) {
169 if (drmCommandWrite (intel->driFd, DRM_I830_CMDBUFFER, &cmd,
170 sizeof(cmd))) {
171 fprintf(stderr, "DRM_I830_CMDBUFFER: %d\n", -errno);
172 UNLOCK_HARDWARE(intel);
173 exit(1);
174 }
175 }
176 }