Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[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;
79
80 if (0)
81 fprintf(stderr, "%s %d\n", __FUNCTION__, seq );
82
83 iw.irq_seq = seq;
84
85 do {
86 ret = drmCommandWrite( intel->driFd, DRM_I830_IRQ_WAIT, &iw, sizeof(iw) );
87
88 /* This seems quite often to return before it should!?!
89 */
90 } while (ret == -EAGAIN || ret == -EINTR || (ret == 0 && seq > intel->sarea->last_dispatch));
91
92
93 if ( ret ) {
94 fprintf( stderr, "%s: drmI830IrqWait: %d\n", __FUNCTION__, ret );
95
96 if (intel->aub_file) {
97 intel->vtbl.aub_dump_bmp( intel, intel->ctx.Visual.doubleBufferMode ? 1 : 0 );
98 }
99
100 exit(1);
101 }
102 }
103 }
104
105
106 void intel_batch_ioctl( struct intel_context *intel,
107 GLuint start_offset,
108 GLuint used,
109 GLboolean ignore_cliprects)
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 ignore_cliprects %d\n",
118 __FUNCTION__,
119 used,
120 start_offset,
121 start_offset + used,
122 ignore_cliprects);
123
124 batch.start = start_offset;
125 batch.used = used;
126 batch.cliprects = intel->pClipRects;
127 batch.num_cliprects = ignore_cliprects ? 0 : intel->numClipRects;
128 batch.DR1 = 0;
129 batch.DR4 = ((((GLuint)intel->drawX) & 0xffff) |
130 (((GLuint)intel->drawY) << 16));
131
132 if (INTEL_DEBUG & DEBUG_DMA)
133 fprintf(stderr, "%s: 0x%x..0x%x DR4: %x cliprects: %d\n",
134 __FUNCTION__,
135 batch.start,
136 batch.start + batch.used * 4,
137 batch.DR4, batch.num_cliprects);
138
139 if (!intel->no_hw) {
140 if (drmCommandWrite (intel->driFd, DRM_I830_BATCHBUFFER, &batch,
141 sizeof(batch))) {
142 fprintf(stderr, "DRM_I830_BATCHBUFFER: %d\n", -errno);
143 UNLOCK_HARDWARE(intel);
144 exit(1);
145 }
146 }
147 }
148
149 void intel_cmd_ioctl( struct intel_context *intel,
150 char *buf,
151 GLuint used,
152 GLboolean ignore_cliprects)
153 {
154 drmI830CmdBuffer cmd;
155
156 assert(intel->locked);
157 assert(used);
158
159 cmd.buf = buf;
160 cmd.sz = used;
161 cmd.cliprects = intel->pClipRects;
162 cmd.num_cliprects = ignore_cliprects ? 0 : intel->numClipRects;
163 cmd.DR1 = 0;
164 cmd.DR4 = ((((GLuint)intel->drawX) & 0xffff) |
165 (((GLuint)intel->drawY) << 16));
166
167 if (INTEL_DEBUG & DEBUG_DMA)
168 fprintf(stderr, "%s: 0x%x..0x%x DR4: %x cliprects: %d\n",
169 __FUNCTION__,
170 0,
171 0 + cmd.sz,
172 cmd.DR4, cmd.num_cliprects);
173
174 if (!intel->no_hw) {
175 if (drmCommandWrite (intel->driFd, DRM_I830_CMDBUFFER, &cmd,
176 sizeof(cmd))) {
177 fprintf(stderr, "DRM_I830_CMDBUFFER: %d\n", -errno);
178 UNLOCK_HARDWARE(intel);
179 exit(1);
180 }
181 }
182 }