aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/mga_dma.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/drm/mga_dma.c')
-rw-r--r--drivers/char/drm/mga_dma.c533
1 files changed, 263 insertions, 270 deletions
diff --git a/drivers/char/drm/mga_dma.c b/drivers/char/drm/mga_dma.c
index fc7d4a594bca..70dc7f64b7b9 100644
--- a/drivers/char/drm/mga_dma.c
+++ b/drivers/char/drm/mga_dma.c
@@ -28,7 +28,7 @@
28/** 28/**
29 * \file mga_dma.c 29 * \file mga_dma.c
30 * DMA support for MGA G200 / G400. 30 * DMA support for MGA G200 / G400.
31 * 31 *
32 * \author Rickard E. (Rik) Faith <faith@valinux.com> 32 * \author Rickard E. (Rik) Faith <faith@valinux.com>
33 * \author Jeff Hartmann <jhartmann@valinux.com> 33 * \author Jeff Hartmann <jhartmann@valinux.com>
34 * \author Keith Whitwell <keith@tungstengraphics.com> 34 * \author Keith Whitwell <keith@tungstengraphics.com>
@@ -44,40 +44,40 @@
44#define MGA_DEFAULT_USEC_TIMEOUT 10000 44#define MGA_DEFAULT_USEC_TIMEOUT 10000
45#define MGA_FREELIST_DEBUG 0 45#define MGA_FREELIST_DEBUG 0
46 46
47static int mga_do_cleanup_dma( drm_device_t *dev ); 47static int mga_do_cleanup_dma(drm_device_t * dev);
48 48
49/* ================================================================ 49/* ================================================================
50 * Engine control 50 * Engine control
51 */ 51 */
52 52
53int mga_do_wait_for_idle( drm_mga_private_t *dev_priv ) 53int mga_do_wait_for_idle(drm_mga_private_t * dev_priv)
54{ 54{
55 u32 status = 0; 55 u32 status = 0;
56 int i; 56 int i;
57 DRM_DEBUG( "\n" ); 57 DRM_DEBUG("\n");
58 58
59 for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { 59 for (i = 0; i < dev_priv->usec_timeout; i++) {
60 status = MGA_READ( MGA_STATUS ) & MGA_ENGINE_IDLE_MASK; 60 status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
61 if ( status == MGA_ENDPRDMASTS ) { 61 if (status == MGA_ENDPRDMASTS) {
62 MGA_WRITE8( MGA_CRTC_INDEX, 0 ); 62 MGA_WRITE8(MGA_CRTC_INDEX, 0);
63 return 0; 63 return 0;
64 } 64 }
65 DRM_UDELAY( 1 ); 65 DRM_UDELAY(1);
66 } 66 }
67 67
68#if MGA_DMA_DEBUG 68#if MGA_DMA_DEBUG
69 DRM_ERROR( "failed!\n" ); 69 DRM_ERROR("failed!\n");
70 DRM_INFO( " status=0x%08x\n", status ); 70 DRM_INFO(" status=0x%08x\n", status);
71#endif 71#endif
72 return DRM_ERR(EBUSY); 72 return DRM_ERR(EBUSY);
73} 73}
74 74
75static int mga_do_dma_reset( drm_mga_private_t *dev_priv ) 75static int mga_do_dma_reset(drm_mga_private_t * dev_priv)
76{ 76{
77 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv; 77 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
78 drm_mga_primary_buffer_t *primary = &dev_priv->prim; 78 drm_mga_primary_buffer_t *primary = &dev_priv->prim;
79 79
80 DRM_DEBUG( "\n" ); 80 DRM_DEBUG("\n");
81 81
82 /* The primary DMA stream should look like new right about now. 82 /* The primary DMA stream should look like new right about now.
83 */ 83 */
@@ -100,24 +100,25 @@ static int mga_do_dma_reset( drm_mga_private_t *dev_priv )
100 * Primary DMA stream 100 * Primary DMA stream
101 */ 101 */
102 102
103void mga_do_dma_flush( drm_mga_private_t *dev_priv ) 103void mga_do_dma_flush(drm_mga_private_t * dev_priv)
104{ 104{
105 drm_mga_primary_buffer_t *primary = &dev_priv->prim; 105 drm_mga_primary_buffer_t *primary = &dev_priv->prim;
106 u32 head, tail; 106 u32 head, tail;
107 u32 status = 0; 107 u32 status = 0;
108 int i; 108 int i;
109 DMA_LOCALS; 109 DMA_LOCALS;
110 DRM_DEBUG( "\n" ); 110 DRM_DEBUG("\n");
111 111
112 /* We need to wait so that we can do an safe flush */ 112 /* We need to wait so that we can do an safe flush */
113 for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { 113 for (i = 0; i < dev_priv->usec_timeout; i++) {
114 status = MGA_READ( MGA_STATUS ) & MGA_ENGINE_IDLE_MASK; 114 status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
115 if ( status == MGA_ENDPRDMASTS ) break; 115 if (status == MGA_ENDPRDMASTS)
116 DRM_UDELAY( 1 ); 116 break;
117 DRM_UDELAY(1);
117 } 118 }
118 119
119 if ( primary->tail == primary->last_flush ) { 120 if (primary->tail == primary->last_flush) {
120 DRM_DEBUG( " bailing out...\n" ); 121 DRM_DEBUG(" bailing out...\n");
121 return; 122 return;
122 } 123 }
123 124
@@ -127,48 +128,46 @@ void mga_do_dma_flush( drm_mga_private_t *dev_priv )
127 * actually (partially?) reads the first of these commands. 128 * actually (partially?) reads the first of these commands.
128 * See page 4-16 in the G400 manual, middle of the page or so. 129 * See page 4-16 in the G400 manual, middle of the page or so.
129 */ 130 */
130 BEGIN_DMA( 1 ); 131 BEGIN_DMA(1);
131 132
132 DMA_BLOCK( MGA_DMAPAD, 0x00000000, 133 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
133 MGA_DMAPAD, 0x00000000, 134 MGA_DMAPAD, 0x00000000,
134 MGA_DMAPAD, 0x00000000, 135 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
135 MGA_DMAPAD, 0x00000000 );
136 136
137 ADVANCE_DMA(); 137 ADVANCE_DMA();
138 138
139 primary->last_flush = primary->tail; 139 primary->last_flush = primary->tail;
140 140
141 head = MGA_READ( MGA_PRIMADDRESS ); 141 head = MGA_READ(MGA_PRIMADDRESS);
142 142
143 if ( head <= tail ) { 143 if (head <= tail) {
144 primary->space = primary->size - primary->tail; 144 primary->space = primary->size - primary->tail;
145 } else { 145 } else {
146 primary->space = head - tail; 146 primary->space = head - tail;
147 } 147 }
148 148
149 DRM_DEBUG( " head = 0x%06lx\n", head - dev_priv->primary->offset ); 149 DRM_DEBUG(" head = 0x%06lx\n", head - dev_priv->primary->offset);
150 DRM_DEBUG( " tail = 0x%06lx\n", tail - dev_priv->primary->offset ); 150 DRM_DEBUG(" tail = 0x%06lx\n", tail - dev_priv->primary->offset);
151 DRM_DEBUG( " space = 0x%06x\n", primary->space ); 151 DRM_DEBUG(" space = 0x%06x\n", primary->space);
152 152
153 mga_flush_write_combine(); 153 mga_flush_write_combine();
154 MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access); 154 MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
155 155
156 DRM_DEBUG( "done.\n" ); 156 DRM_DEBUG("done.\n");
157} 157}
158 158
159void mga_do_dma_wrap_start( drm_mga_private_t *dev_priv ) 159void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv)
160{ 160{
161 drm_mga_primary_buffer_t *primary = &dev_priv->prim; 161 drm_mga_primary_buffer_t *primary = &dev_priv->prim;
162 u32 head, tail; 162 u32 head, tail;
163 DMA_LOCALS; 163 DMA_LOCALS;
164 DRM_DEBUG( "\n" ); 164 DRM_DEBUG("\n");
165 165
166 BEGIN_DMA_WRAP(); 166 BEGIN_DMA_WRAP();
167 167
168 DMA_BLOCK( MGA_DMAPAD, 0x00000000, 168 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
169 MGA_DMAPAD, 0x00000000, 169 MGA_DMAPAD, 0x00000000,
170 MGA_DMAPAD, 0x00000000, 170 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
171 MGA_DMAPAD, 0x00000000 );
172 171
173 ADVANCE_DMA(); 172 ADVANCE_DMA();
174 173
@@ -178,45 +177,43 @@ void mga_do_dma_wrap_start( drm_mga_private_t *dev_priv )
178 primary->last_flush = 0; 177 primary->last_flush = 0;
179 primary->last_wrap++; 178 primary->last_wrap++;
180 179
181 head = MGA_READ( MGA_PRIMADDRESS ); 180 head = MGA_READ(MGA_PRIMADDRESS);
182 181
183 if ( head == dev_priv->primary->offset ) { 182 if (head == dev_priv->primary->offset) {
184 primary->space = primary->size; 183 primary->space = primary->size;
185 } else { 184 } else {
186 primary->space = head - dev_priv->primary->offset; 185 primary->space = head - dev_priv->primary->offset;
187 } 186 }
188 187
189 DRM_DEBUG( " head = 0x%06lx\n", 188 DRM_DEBUG(" head = 0x%06lx\n", head - dev_priv->primary->offset);
190 head - dev_priv->primary->offset ); 189 DRM_DEBUG(" tail = 0x%06x\n", primary->tail);
191 DRM_DEBUG( " tail = 0x%06x\n", primary->tail ); 190 DRM_DEBUG(" wrap = %d\n", primary->last_wrap);
192 DRM_DEBUG( " wrap = %d\n", primary->last_wrap ); 191 DRM_DEBUG(" space = 0x%06x\n", primary->space);
193 DRM_DEBUG( " space = 0x%06x\n", primary->space );
194 192
195 mga_flush_write_combine(); 193 mga_flush_write_combine();
196 MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access); 194 MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
197 195
198 set_bit( 0, &primary->wrapped ); 196 set_bit(0, &primary->wrapped);
199 DRM_DEBUG( "done.\n" ); 197 DRM_DEBUG("done.\n");
200} 198}
201 199
202void mga_do_dma_wrap_end( drm_mga_private_t *dev_priv ) 200void mga_do_dma_wrap_end(drm_mga_private_t * dev_priv)
203{ 201{
204 drm_mga_primary_buffer_t *primary = &dev_priv->prim; 202 drm_mga_primary_buffer_t *primary = &dev_priv->prim;
205 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv; 203 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
206 u32 head = dev_priv->primary->offset; 204 u32 head = dev_priv->primary->offset;
207 DRM_DEBUG( "\n" ); 205 DRM_DEBUG("\n");
208 206
209 sarea_priv->last_wrap++; 207 sarea_priv->last_wrap++;
210 DRM_DEBUG( " wrap = %d\n", sarea_priv->last_wrap ); 208 DRM_DEBUG(" wrap = %d\n", sarea_priv->last_wrap);
211 209
212 mga_flush_write_combine(); 210 mga_flush_write_combine();
213 MGA_WRITE( MGA_PRIMADDRESS, head | MGA_DMA_GENERAL ); 211 MGA_WRITE(MGA_PRIMADDRESS, head | MGA_DMA_GENERAL);
214 212
215 clear_bit( 0, &primary->wrapped ); 213 clear_bit(0, &primary->wrapped);
216 DRM_DEBUG( "done.\n" ); 214 DRM_DEBUG("done.\n");
217} 215}
218 216
219
220/* ================================================================ 217/* ================================================================
221 * Freelist management 218 * Freelist management
222 */ 219 */
@@ -225,63 +222,61 @@ void mga_do_dma_wrap_end( drm_mga_private_t *dev_priv )
225#define MGA_BUFFER_FREE 0 222#define MGA_BUFFER_FREE 0
226 223
227#if MGA_FREELIST_DEBUG 224#if MGA_FREELIST_DEBUG
228static void mga_freelist_print( drm_device_t *dev ) 225static void mga_freelist_print(drm_device_t * dev)
229{ 226{
230 drm_mga_private_t *dev_priv = dev->dev_private; 227 drm_mga_private_t *dev_priv = dev->dev_private;
231 drm_mga_freelist_t *entry; 228 drm_mga_freelist_t *entry;
232 229
233 DRM_INFO( "\n" ); 230 DRM_INFO("\n");
234 DRM_INFO( "current dispatch: last=0x%x done=0x%x\n", 231 DRM_INFO("current dispatch: last=0x%x done=0x%x\n",
235 dev_priv->sarea_priv->last_dispatch, 232 dev_priv->sarea_priv->last_dispatch,
236 (unsigned int)(MGA_READ( MGA_PRIMADDRESS ) - 233 (unsigned int)(MGA_READ(MGA_PRIMADDRESS) -
237 dev_priv->primary->offset) ); 234 dev_priv->primary->offset));
238 DRM_INFO( "current freelist:\n" ); 235 DRM_INFO("current freelist:\n");
239 236
240 for ( entry = dev_priv->head->next ; entry ; entry = entry->next ) { 237 for (entry = dev_priv->head->next; entry; entry = entry->next) {
241 DRM_INFO( " %p idx=%2d age=0x%x 0x%06lx\n", 238 DRM_INFO(" %p idx=%2d age=0x%x 0x%06lx\n",
242 entry, entry->buf->idx, entry->age.head, 239 entry, entry->buf->idx, entry->age.head,
243 entry->age.head - dev_priv->primary->offset ); 240 entry->age.head - dev_priv->primary->offset);
244 } 241 }
245 DRM_INFO( "\n" ); 242 DRM_INFO("\n");
246} 243}
247#endif 244#endif
248 245
249static int mga_freelist_init( drm_device_t *dev, drm_mga_private_t *dev_priv ) 246static int mga_freelist_init(drm_device_t * dev, drm_mga_private_t * dev_priv)
250{ 247{
251 drm_device_dma_t *dma = dev->dma; 248 drm_device_dma_t *dma = dev->dma;
252 drm_buf_t *buf; 249 drm_buf_t *buf;
253 drm_mga_buf_priv_t *buf_priv; 250 drm_mga_buf_priv_t *buf_priv;
254 drm_mga_freelist_t *entry; 251 drm_mga_freelist_t *entry;
255 int i; 252 int i;
256 DRM_DEBUG( "count=%d\n", dma->buf_count ); 253 DRM_DEBUG("count=%d\n", dma->buf_count);
257 254
258 dev_priv->head = drm_alloc( sizeof(drm_mga_freelist_t), 255 dev_priv->head = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
259 DRM_MEM_DRIVER ); 256 if (dev_priv->head == NULL)
260 if ( dev_priv->head == NULL )
261 return DRM_ERR(ENOMEM); 257 return DRM_ERR(ENOMEM);
262 258
263 memset( dev_priv->head, 0, sizeof(drm_mga_freelist_t) ); 259 memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
264 SET_AGE( &dev_priv->head->age, MGA_BUFFER_USED, 0 ); 260 SET_AGE(&dev_priv->head->age, MGA_BUFFER_USED, 0);
265 261
266 for ( i = 0 ; i < dma->buf_count ; i++ ) { 262 for (i = 0; i < dma->buf_count; i++) {
267 buf = dma->buflist[i]; 263 buf = dma->buflist[i];
268 buf_priv = buf->dev_private; 264 buf_priv = buf->dev_private;
269 265
270 entry = drm_alloc( sizeof(drm_mga_freelist_t), 266 entry = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
271 DRM_MEM_DRIVER ); 267 if (entry == NULL)
272 if ( entry == NULL )
273 return DRM_ERR(ENOMEM); 268 return DRM_ERR(ENOMEM);
274 269
275 memset( entry, 0, sizeof(drm_mga_freelist_t) ); 270 memset(entry, 0, sizeof(drm_mga_freelist_t));
276 271
277 entry->next = dev_priv->head->next; 272 entry->next = dev_priv->head->next;
278 entry->prev = dev_priv->head; 273 entry->prev = dev_priv->head;
279 SET_AGE( &entry->age, MGA_BUFFER_FREE, 0 ); 274 SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
280 entry->buf = buf; 275 entry->buf = buf;
281 276
282 if ( dev_priv->head->next != NULL ) 277 if (dev_priv->head->next != NULL)
283 dev_priv->head->next->prev = entry; 278 dev_priv->head->next->prev = entry;
284 if ( entry->next == NULL ) 279 if (entry->next == NULL)
285 dev_priv->tail = entry; 280 dev_priv->tail = entry;
286 281
287 buf_priv->list_entry = entry; 282 buf_priv->list_entry = entry;
@@ -294,17 +289,17 @@ static int mga_freelist_init( drm_device_t *dev, drm_mga_private_t *dev_priv )
294 return 0; 289 return 0;
295} 290}
296 291
297static void mga_freelist_cleanup( drm_device_t *dev ) 292static void mga_freelist_cleanup(drm_device_t * dev)
298{ 293{
299 drm_mga_private_t *dev_priv = dev->dev_private; 294 drm_mga_private_t *dev_priv = dev->dev_private;
300 drm_mga_freelist_t *entry; 295 drm_mga_freelist_t *entry;
301 drm_mga_freelist_t *next; 296 drm_mga_freelist_t *next;
302 DRM_DEBUG( "\n" ); 297 DRM_DEBUG("\n");
303 298
304 entry = dev_priv->head; 299 entry = dev_priv->head;
305 while ( entry ) { 300 while (entry) {
306 next = entry->next; 301 next = entry->next;
307 drm_free( entry, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER ); 302 drm_free(entry, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
308 entry = next; 303 entry = next;
309 } 304 }
310 305
@@ -314,71 +309,69 @@ static void mga_freelist_cleanup( drm_device_t *dev )
314#if 0 309#if 0
315/* FIXME: Still needed? 310/* FIXME: Still needed?
316 */ 311 */
317static void mga_freelist_reset( drm_device_t *dev ) 312static void mga_freelist_reset(drm_device_t * dev)
318{ 313{
319 drm_device_dma_t *dma = dev->dma; 314 drm_device_dma_t *dma = dev->dma;
320 drm_buf_t *buf; 315 drm_buf_t *buf;
321 drm_mga_buf_priv_t *buf_priv; 316 drm_mga_buf_priv_t *buf_priv;
322 int i; 317 int i;
323 318
324 for ( i = 0 ; i < dma->buf_count ; i++ ) { 319 for (i = 0; i < dma->buf_count; i++) {
325 buf = dma->buflist[i]; 320 buf = dma->buflist[i];
326 buf_priv = buf->dev_private; 321 buf_priv = buf->dev_private;
327 SET_AGE( &buf_priv->list_entry->age, 322 SET_AGE(&buf_priv->list_entry->age, MGA_BUFFER_FREE, 0);
328 MGA_BUFFER_FREE, 0 );
329 } 323 }
330} 324}
331#endif 325#endif
332 326
333static drm_buf_t *mga_freelist_get( drm_device_t *dev ) 327static drm_buf_t *mga_freelist_get(drm_device_t * dev)
334{ 328{
335 drm_mga_private_t *dev_priv = dev->dev_private; 329 drm_mga_private_t *dev_priv = dev->dev_private;
336 drm_mga_freelist_t *next; 330 drm_mga_freelist_t *next;
337 drm_mga_freelist_t *prev; 331 drm_mga_freelist_t *prev;
338 drm_mga_freelist_t *tail = dev_priv->tail; 332 drm_mga_freelist_t *tail = dev_priv->tail;
339 u32 head, wrap; 333 u32 head, wrap;
340 DRM_DEBUG( "\n" ); 334 DRM_DEBUG("\n");
341 335
342 head = MGA_READ( MGA_PRIMADDRESS ); 336 head = MGA_READ(MGA_PRIMADDRESS);
343 wrap = dev_priv->sarea_priv->last_wrap; 337 wrap = dev_priv->sarea_priv->last_wrap;
344 338
345 DRM_DEBUG( " tail=0x%06lx %d\n", 339 DRM_DEBUG(" tail=0x%06lx %d\n",
346 tail->age.head ? 340 tail->age.head ?
347 tail->age.head - dev_priv->primary->offset : 0, 341 tail->age.head - dev_priv->primary->offset : 0,
348 tail->age.wrap ); 342 tail->age.wrap);
349 DRM_DEBUG( " head=0x%06lx %d\n", 343 DRM_DEBUG(" head=0x%06lx %d\n",
350 head - dev_priv->primary->offset, wrap ); 344 head - dev_priv->primary->offset, wrap);
351 345
352 if ( TEST_AGE( &tail->age, head, wrap ) ) { 346 if (TEST_AGE(&tail->age, head, wrap)) {
353 prev = dev_priv->tail->prev; 347 prev = dev_priv->tail->prev;
354 next = dev_priv->tail; 348 next = dev_priv->tail;
355 prev->next = NULL; 349 prev->next = NULL;
356 next->prev = next->next = NULL; 350 next->prev = next->next = NULL;
357 dev_priv->tail = prev; 351 dev_priv->tail = prev;
358 SET_AGE( &next->age, MGA_BUFFER_USED, 0 ); 352 SET_AGE(&next->age, MGA_BUFFER_USED, 0);
359 return next->buf; 353 return next->buf;
360 } 354 }
361 355
362 DRM_DEBUG( "returning NULL!\n" ); 356 DRM_DEBUG("returning NULL!\n");
363 return NULL; 357 return NULL;
364} 358}
365 359
366int mga_freelist_put( drm_device_t *dev, drm_buf_t *buf ) 360int mga_freelist_put(drm_device_t * dev, drm_buf_t * buf)
367{ 361{
368 drm_mga_private_t *dev_priv = dev->dev_private; 362 drm_mga_private_t *dev_priv = dev->dev_private;
369 drm_mga_buf_priv_t *buf_priv = buf->dev_private; 363 drm_mga_buf_priv_t *buf_priv = buf->dev_private;
370 drm_mga_freelist_t *head, *entry, *prev; 364 drm_mga_freelist_t *head, *entry, *prev;
371 365
372 DRM_DEBUG( "age=0x%06lx wrap=%d\n", 366 DRM_DEBUG("age=0x%06lx wrap=%d\n",
373 buf_priv->list_entry->age.head - 367 buf_priv->list_entry->age.head -
374 dev_priv->primary->offset, 368 dev_priv->primary->offset, buf_priv->list_entry->age.wrap);
375 buf_priv->list_entry->age.wrap );
376 369
377 entry = buf_priv->list_entry; 370 entry = buf_priv->list_entry;
378 head = dev_priv->head; 371 head = dev_priv->head;
379 372
380 if ( buf_priv->list_entry->age.head == MGA_BUFFER_USED ) { 373 if (buf_priv->list_entry->age.head == MGA_BUFFER_USED) {
381 SET_AGE( &entry->age, MGA_BUFFER_FREE, 0 ); 374 SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
382 prev = dev_priv->tail; 375 prev = dev_priv->tail;
383 prev->next = entry; 376 prev->next = entry;
384 entry->prev = prev; 377 entry->prev = prev;
@@ -394,15 +387,13 @@ int mga_freelist_put( drm_device_t *dev, drm_buf_t *buf )
394 return 0; 387 return 0;
395} 388}
396 389
397
398/* ================================================================ 390/* ================================================================
399 * DMA initialization, cleanup 391 * DMA initialization, cleanup
400 */ 392 */
401 393
402 394int mga_driver_preinit(drm_device_t * dev, unsigned long flags)
403int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
404{ 395{
405 drm_mga_private_t * dev_priv; 396 drm_mga_private_t *dev_priv;
406 397
407 dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER); 398 dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
408 if (!dev_priv) 399 if (!dev_priv)
@@ -420,7 +411,7 @@ int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
420#if __OS_HAS_AGP 411#if __OS_HAS_AGP
421/** 412/**
422 * Bootstrap the driver for AGP DMA. 413 * Bootstrap the driver for AGP DMA.
423 * 414 *
424 * \todo 415 * \todo
425 * Investigate whether there is any benifit to storing the WARP microcode in 416 * Investigate whether there is any benifit to storing the WARP microcode in
426 * AGP memory. If not, the microcode may as well always be put in PCI 417 * AGP memory. If not, the microcode may as well always be put in PCI
@@ -436,18 +427,18 @@ int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
436static int mga_do_agp_dma_bootstrap(drm_device_t * dev, 427static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
437 drm_mga_dma_bootstrap_t * dma_bs) 428 drm_mga_dma_bootstrap_t * dma_bs)
438{ 429{
439 drm_mga_private_t * const dev_priv = (drm_mga_private_t *) dev->dev_private; 430 drm_mga_private_t *const dev_priv =
440 const unsigned int warp_size = mga_warp_microcode_size(dev_priv); 431 (drm_mga_private_t *) dev->dev_private;
432 unsigned int warp_size = mga_warp_microcode_size(dev_priv);
441 int err; 433 int err;
442 unsigned offset; 434 unsigned offset;
443 const unsigned secondary_size = dma_bs->secondary_bin_count 435 const unsigned secondary_size = dma_bs->secondary_bin_count
444 * dma_bs->secondary_bin_size; 436 * dma_bs->secondary_bin_size;
445 const unsigned agp_size = (dma_bs->agp_size << 20); 437 const unsigned agp_size = (dma_bs->agp_size << 20);
446 drm_buf_desc_t req; 438 drm_buf_desc_t req;
447 drm_agp_mode_t mode; 439 drm_agp_mode_t mode;
448 drm_agp_info_t info; 440 drm_agp_info_t info;
449 441
450
451 /* Acquire AGP. */ 442 /* Acquire AGP. */
452 err = drm_agp_acquire(dev); 443 err = drm_agp_acquire(dev);
453 if (err) { 444 if (err) {
@@ -468,7 +459,6 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
468 return err; 459 return err;
469 } 460 }
470 461
471
472 /* In addition to the usual AGP mode configuration, the G200 AGP cards 462 /* In addition to the usual AGP mode configuration, the G200 AGP cards
473 * need to have the AGP mode "manually" set. 463 * need to have the AGP mode "manually" set.
474 */ 464 */
@@ -476,68 +466,72 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
476 if (dev_priv->chipset == MGA_CARD_TYPE_G200) { 466 if (dev_priv->chipset == MGA_CARD_TYPE_G200) {
477 if (mode.mode & 0x02) { 467 if (mode.mode & 0x02) {
478 MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_ENABLE); 468 MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_ENABLE);
479 } 469 } else {
480 else {
481 MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_DISABLE); 470 MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_DISABLE);
482 } 471 }
483 } 472 }
484 473
485
486 /* Allocate and bind AGP memory. */ 474 /* Allocate and bind AGP memory. */
487 dev_priv->agp_pages = agp_size / PAGE_SIZE; 475 dev_priv->agp_pages = agp_size / PAGE_SIZE;
488 dev_priv->agp_mem = drm_alloc_agp( dev, dev_priv->agp_pages, 0 ); 476 dev_priv->agp_mem = drm_alloc_agp(dev, dev_priv->agp_pages, 0);
489 if (dev_priv->agp_mem == NULL) { 477 if (dev_priv->agp_mem == NULL) {
490 dev_priv->agp_pages = 0; 478 dev_priv->agp_pages = 0;
491 DRM_ERROR("Unable to allocate %uMB AGP memory\n", 479 DRM_ERROR("Unable to allocate %uMB AGP memory\n",
492 dma_bs->agp_size); 480 dma_bs->agp_size);
493 return DRM_ERR(ENOMEM); 481 return DRM_ERR(ENOMEM);
494 } 482 }
495 483
496 err = drm_bind_agp( dev_priv->agp_mem, 0 ); 484 err = drm_bind_agp(dev_priv->agp_mem, 0);
497 if (err) { 485 if (err) {
498 DRM_ERROR("Unable to bind AGP memory\n"); 486 DRM_ERROR("Unable to bind AGP memory\n");
499 return err; 487 return err;
500 } 488 }
501 489
490 /* Make drm_addbufs happy by not trying to create a mapping for less
491 * than a page.
492 */
493 if (warp_size < PAGE_SIZE)
494 warp_size = PAGE_SIZE;
495
502 offset = 0; 496 offset = 0;
503 err = drm_addmap( dev, offset, warp_size, 497 err = drm_addmap(dev, offset, warp_size,
504 _DRM_AGP, _DRM_READ_ONLY, & dev_priv->warp ); 498 _DRM_AGP, _DRM_READ_ONLY, &dev_priv->warp);
505 if (err) { 499 if (err) {
506 DRM_ERROR("Unable to map WARP microcode\n"); 500 DRM_ERROR("Unable to map WARP microcode\n");
507 return err; 501 return err;
508 } 502 }
509 503
510 offset += warp_size; 504 offset += warp_size;
511 err = drm_addmap( dev, offset, dma_bs->primary_size, 505 err = drm_addmap(dev, offset, dma_bs->primary_size,
512 _DRM_AGP, _DRM_READ_ONLY, & dev_priv->primary ); 506 _DRM_AGP, _DRM_READ_ONLY, &dev_priv->primary);
513 if (err) { 507 if (err) {
514 DRM_ERROR("Unable to map primary DMA region\n"); 508 DRM_ERROR("Unable to map primary DMA region\n");
515 return err; 509 return err;
516 } 510 }
517 511
518 offset += dma_bs->primary_size; 512 offset += dma_bs->primary_size;
519 err = drm_addmap( dev, offset, secondary_size, 513 err = drm_addmap(dev, offset, secondary_size,
520 _DRM_AGP, 0, & dev->agp_buffer_map ); 514 _DRM_AGP, 0, &dev->agp_buffer_map);
521 if (err) { 515 if (err) {
522 DRM_ERROR("Unable to map secondary DMA region\n"); 516 DRM_ERROR("Unable to map secondary DMA region\n");
523 return err; 517 return err;
524 } 518 }
525 519
526 (void) memset( &req, 0, sizeof(req) ); 520 (void)memset(&req, 0, sizeof(req));
527 req.count = dma_bs->secondary_bin_count; 521 req.count = dma_bs->secondary_bin_count;
528 req.size = dma_bs->secondary_bin_size; 522 req.size = dma_bs->secondary_bin_size;
529 req.flags = _DRM_AGP_BUFFER; 523 req.flags = _DRM_AGP_BUFFER;
530 req.agp_start = offset; 524 req.agp_start = offset;
531 525
532 err = drm_addbufs_agp( dev, & req ); 526 err = drm_addbufs_agp(dev, &req);
533 if (err) { 527 if (err) {
534 DRM_ERROR("Unable to add secondary DMA buffers\n"); 528 DRM_ERROR("Unable to add secondary DMA buffers\n");
535 return err; 529 return err;
536 } 530 }
537 531
538 offset += secondary_size; 532 offset += secondary_size;
539 err = drm_addmap( dev, offset, agp_size - offset, 533 err = drm_addmap(dev, offset, agp_size - offset,
540 _DRM_AGP, 0, & dev_priv->agp_textures ); 534 _DRM_AGP, 0, &dev_priv->agp_textures);
541 if (err) { 535 if (err) {
542 DRM_ERROR("Unable to map AGP texture region\n"); 536 DRM_ERROR("Unable to map AGP texture region\n");
543 return err; 537 return err;
@@ -571,7 +565,7 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
571 565
572/** 566/**
573 * Bootstrap the driver for PCI DMA. 567 * Bootstrap the driver for PCI DMA.
574 * 568 *
575 * \todo 569 * \todo
576 * The algorithm for decreasing the size of the primary DMA buffer could be 570 * The algorithm for decreasing the size of the primary DMA buffer could be
577 * better. The size should be rounded up to the nearest page size, then 571 * better. The size should be rounded up to the nearest page size, then
@@ -580,25 +574,31 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
580 * \todo 574 * \todo
581 * Determine whether the maximum address passed to drm_pci_alloc is correct. 575 * Determine whether the maximum address passed to drm_pci_alloc is correct.
582 * The same goes for drm_addbufs_pci. 576 * The same goes for drm_addbufs_pci.
583 * 577 *
584 * \sa mga_do_dma_bootstrap, mga_do_agp_dma_bootstrap 578 * \sa mga_do_dma_bootstrap, mga_do_agp_dma_bootstrap
585 */ 579 */
586static int mga_do_pci_dma_bootstrap(drm_device_t * dev, 580static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
587 drm_mga_dma_bootstrap_t * dma_bs) 581 drm_mga_dma_bootstrap_t * dma_bs)
588{ 582{
589 drm_mga_private_t * const dev_priv = (drm_mga_private_t *) dev->dev_private; 583 drm_mga_private_t *const dev_priv =
590 const unsigned int warp_size = mga_warp_microcode_size(dev_priv); 584 (drm_mga_private_t *) dev->dev_private;
585 unsigned int warp_size = mga_warp_microcode_size(dev_priv);
591 unsigned int primary_size; 586 unsigned int primary_size;
592 unsigned int bin_count; 587 unsigned int bin_count;
593 int err; 588 int err;
594 drm_buf_desc_t req; 589 drm_buf_desc_t req;
595 590
596
597 if (dev->dma == NULL) { 591 if (dev->dma == NULL) {
598 DRM_ERROR("dev->dma is NULL\n"); 592 DRM_ERROR("dev->dma is NULL\n");
599 return DRM_ERR(EFAULT); 593 return DRM_ERR(EFAULT);
600 } 594 }
601 595
596 /* Make drm_addbufs happy by not trying to create a mapping for less
597 * than a page.
598 */
599 if (warp_size < PAGE_SIZE)
600 warp_size = PAGE_SIZE;
601
602 /* The proper alignment is 0x100 for this mapping */ 602 /* The proper alignment is 0x100 for this mapping */
603 err = drm_addmap(dev, 0, warp_size, _DRM_CONSISTENT, 603 err = drm_addmap(dev, 0, warp_size, _DRM_CONSISTENT,
604 _DRM_READ_ONLY, &dev_priv->warp); 604 _DRM_READ_ONLY, &dev_priv->warp);
@@ -612,9 +612,8 @@ static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
612 * alignment of the primary or secondary DMA buffers. 612 * alignment of the primary or secondary DMA buffers.
613 */ 613 */
614 614
615 for ( primary_size = dma_bs->primary_size 615 for (primary_size = dma_bs->primary_size; primary_size != 0;
616 ; primary_size != 0 616 primary_size >>= 1) {
617 ; primary_size >>= 1 ) {
618 /* The proper alignment for this mapping is 0x04 */ 617 /* The proper alignment for this mapping is 0x04 */
619 err = drm_addmap(dev, 0, primary_size, _DRM_CONSISTENT, 618 err = drm_addmap(dev, 0, primary_size, _DRM_CONSISTENT,
620 _DRM_READ_ONLY, &dev_priv->primary); 619 _DRM_READ_ONLY, &dev_priv->primary);
@@ -629,24 +628,23 @@ static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
629 628
630 if (dev_priv->primary->size != dma_bs->primary_size) { 629 if (dev_priv->primary->size != dma_bs->primary_size) {
631 DRM_INFO("Primary DMA buffer size reduced from %u to %u.\n", 630 DRM_INFO("Primary DMA buffer size reduced from %u to %u.\n",
632 dma_bs->primary_size, 631 dma_bs->primary_size,
633 (unsigned) dev_priv->primary->size); 632 (unsigned)dev_priv->primary->size);
634 dma_bs->primary_size = dev_priv->primary->size; 633 dma_bs->primary_size = dev_priv->primary->size;
635 } 634 }
636 635
637 for ( bin_count = dma_bs->secondary_bin_count 636 for (bin_count = dma_bs->secondary_bin_count; bin_count > 0;
638 ; bin_count > 0 637 bin_count--) {
639 ; bin_count-- ) { 638 (void)memset(&req, 0, sizeof(req));
640 (void) memset( &req, 0, sizeof(req) );
641 req.count = bin_count; 639 req.count = bin_count;
642 req.size = dma_bs->secondary_bin_size; 640 req.size = dma_bs->secondary_bin_size;
643 641
644 err = drm_addbufs_pci( dev, & req ); 642 err = drm_addbufs_pci(dev, &req);
645 if (!err) { 643 if (!err) {
646 break; 644 break;
647 } 645 }
648 } 646 }
649 647
650 if (bin_count == 0) { 648 if (bin_count == 0) {
651 DRM_ERROR("Unable to add secondary DMA buffers\n"); 649 DRM_ERROR("Unable to add secondary DMA buffers\n");
652 return err; 650 return err;
@@ -668,38 +666,34 @@ static int mga_do_pci_dma_bootstrap(drm_device_t * dev,
668 return 0; 666 return 0;
669} 667}
670 668
671
672static int mga_do_dma_bootstrap(drm_device_t * dev, 669static int mga_do_dma_bootstrap(drm_device_t * dev,
673 drm_mga_dma_bootstrap_t * dma_bs) 670 drm_mga_dma_bootstrap_t * dma_bs)
674{ 671{
675 const int is_agp = (dma_bs->agp_mode != 0) && drm_device_is_agp(dev); 672 const int is_agp = (dma_bs->agp_mode != 0) && drm_device_is_agp(dev);
676 int err; 673 int err;
677 drm_mga_private_t * const dev_priv = 674 drm_mga_private_t *const dev_priv =
678 (drm_mga_private_t *) dev->dev_private; 675 (drm_mga_private_t *) dev->dev_private;
679
680 676
681 dev_priv->used_new_dma_init = 1; 677 dev_priv->used_new_dma_init = 1;
682 678
683 /* The first steps are the same for both PCI and AGP based DMA. Map 679 /* The first steps are the same for both PCI and AGP based DMA. Map
684 * the cards MMIO registers and map a status page. 680 * the cards MMIO registers and map a status page.
685 */ 681 */
686 err = drm_addmap( dev, dev_priv->mmio_base, dev_priv->mmio_size, 682 err = drm_addmap(dev, dev_priv->mmio_base, dev_priv->mmio_size,
687 _DRM_REGISTERS, _DRM_READ_ONLY, & dev_priv->mmio ); 683 _DRM_REGISTERS, _DRM_READ_ONLY, &dev_priv->mmio);
688 if (err) { 684 if (err) {
689 DRM_ERROR("Unable to map MMIO region\n"); 685 DRM_ERROR("Unable to map MMIO region\n");
690 return err; 686 return err;
691 } 687 }
692 688
693 689 err = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM,
694 err = drm_addmap( dev, 0, SAREA_MAX, _DRM_SHM, 690 _DRM_READ_ONLY | _DRM_LOCKED | _DRM_KERNEL,
695 _DRM_READ_ONLY | _DRM_LOCKED | _DRM_KERNEL, 691 &dev_priv->status);
696 & dev_priv->status );
697 if (err) { 692 if (err) {
698 DRM_ERROR("Unable to map status region\n"); 693 DRM_ERROR("Unable to map status region\n");
699 return err; 694 return err;
700 } 695 }
701 696
702
703 /* The DMA initialization procedure is slightly different for PCI and 697 /* The DMA initialization procedure is slightly different for PCI and
704 * AGP cards. AGP cards just allocate a large block of AGP memory and 698 * AGP cards. AGP cards just allocate a large block of AGP memory and
705 * carve off portions of it for internal uses. The remaining memory 699 * carve off portions of it for internal uses. The remaining memory
@@ -708,7 +702,7 @@ static int mga_do_dma_bootstrap(drm_device_t * dev,
708 if (is_agp) { 702 if (is_agp) {
709 err = mga_do_agp_dma_bootstrap(dev, dma_bs); 703 err = mga_do_agp_dma_bootstrap(dev, dma_bs);
710 } 704 }
711 705
712 /* If we attempted to initialize the card for AGP DMA but failed, 706 /* If we attempted to initialize the card for AGP DMA but failed,
713 * clean-up any mess that may have been created. 707 * clean-up any mess that may have been created.
714 */ 708 */
@@ -717,7 +711,6 @@ static int mga_do_dma_bootstrap(drm_device_t * dev,
717 mga_do_cleanup_dma(dev); 711 mga_do_cleanup_dma(dev);
718 } 712 }
719 713
720
721 /* Not only do we want to try and initialized PCI cards for PCI DMA, 714 /* Not only do we want to try and initialized PCI cards for PCI DMA,
722 * but we also try to initialized AGP cards that could not be 715 * but we also try to initialized AGP cards that could not be
723 * initialized for AGP DMA. This covers the case where we have an AGP 716 * initialized for AGP DMA. This covers the case where we have an AGP
@@ -730,7 +723,6 @@ static int mga_do_dma_bootstrap(drm_device_t * dev,
730 err = mga_do_pci_dma_bootstrap(dev, dma_bs); 723 err = mga_do_pci_dma_bootstrap(dev, dma_bs);
731 } 724 }
732 725
733
734 return err; 726 return err;
735} 727}
736 728
@@ -740,45 +732,42 @@ int mga_dma_bootstrap(DRM_IOCTL_ARGS)
740 drm_mga_dma_bootstrap_t bootstrap; 732 drm_mga_dma_bootstrap_t bootstrap;
741 int err; 733 int err;
742 734
743
744 DRM_COPY_FROM_USER_IOCTL(bootstrap, 735 DRM_COPY_FROM_USER_IOCTL(bootstrap,
745 (drm_mga_dma_bootstrap_t __user *) data, 736 (drm_mga_dma_bootstrap_t __user *) data,
746 sizeof(bootstrap)); 737 sizeof(bootstrap));
747 738
748 err = mga_do_dma_bootstrap(dev, & bootstrap); 739 err = mga_do_dma_bootstrap(dev, &bootstrap);
749 if (! err) { 740 if (!err) {
750 static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 }; 741 static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 };
751 const drm_mga_private_t * const dev_priv = 742 const drm_mga_private_t *const dev_priv =
752 (drm_mga_private_t *) dev->dev_private; 743 (drm_mga_private_t *) dev->dev_private;
753 744
754 if (dev_priv->agp_textures != NULL) { 745 if (dev_priv->agp_textures != NULL) {
755 bootstrap.texture_handle = dev_priv->agp_textures->offset; 746 bootstrap.texture_handle =
747 dev_priv->agp_textures->offset;
756 bootstrap.texture_size = dev_priv->agp_textures->size; 748 bootstrap.texture_size = dev_priv->agp_textures->size;
757 } 749 } else {
758 else {
759 bootstrap.texture_handle = 0; 750 bootstrap.texture_handle = 0;
760 bootstrap.texture_size = 0; 751 bootstrap.texture_size = 0;
761 } 752 }
762 753
763 bootstrap.agp_mode = modes[ bootstrap.agp_mode & 0x07 ]; 754 bootstrap.agp_mode = modes[bootstrap.agp_mode & 0x07];
764 if (DRM_COPY_TO_USER( (void __user *) data, & bootstrap, 755 if (DRM_COPY_TO_USER((void __user *)data, &bootstrap,
765 sizeof(bootstrap))) { 756 sizeof(bootstrap))) {
766 err = DRM_ERR(EFAULT); 757 err = DRM_ERR(EFAULT);
767 } 758 }
768 } 759 } else {
769 else {
770 mga_do_cleanup_dma(dev); 760 mga_do_cleanup_dma(dev);
771 } 761 }
772 762
773 return err; 763 return err;
774} 764}
775 765
776static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init ) 766static int mga_do_init_dma(drm_device_t * dev, drm_mga_init_t * init)
777{ 767{
778 drm_mga_private_t *dev_priv; 768 drm_mga_private_t *dev_priv;
779 int ret; 769 int ret;
780 DRM_DEBUG( "\n" ); 770 DRM_DEBUG("\n");
781
782 771
783 dev_priv = dev->dev_private; 772 dev_priv = dev->dev_private;
784 773
@@ -787,17 +776,17 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
787 } else { 776 } else {
788 dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR; 777 dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR;
789 } 778 }
790 dev_priv->maccess = init->maccess; 779 dev_priv->maccess = init->maccess;
791 780
792 dev_priv->fb_cpp = init->fb_cpp; 781 dev_priv->fb_cpp = init->fb_cpp;
793 dev_priv->front_offset = init->front_offset; 782 dev_priv->front_offset = init->front_offset;
794 dev_priv->front_pitch = init->front_pitch; 783 dev_priv->front_pitch = init->front_pitch;
795 dev_priv->back_offset = init->back_offset; 784 dev_priv->back_offset = init->back_offset;
796 dev_priv->back_pitch = init->back_pitch; 785 dev_priv->back_pitch = init->back_pitch;
797 786
798 dev_priv->depth_cpp = init->depth_cpp; 787 dev_priv->depth_cpp = init->depth_cpp;
799 dev_priv->depth_offset = init->depth_offset; 788 dev_priv->depth_offset = init->depth_offset;
800 dev_priv->depth_pitch = init->depth_pitch; 789 dev_priv->depth_pitch = init->depth_pitch;
801 790
802 /* FIXME: Need to support AGP textures... 791 /* FIXME: Need to support AGP textures...
803 */ 792 */
@@ -811,7 +800,11 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
811 return DRM_ERR(EINVAL); 800 return DRM_ERR(EINVAL);
812 } 801 }
813 802
814 if (! dev_priv->used_new_dma_init) { 803 if (!dev_priv->used_new_dma_init) {
804
805 dev_priv->dma_access = MGA_PAGPXFER;
806 dev_priv->wagp_enable = MGA_WAGP_ENABLE;
807
815 dev_priv->status = drm_core_findmap(dev, init->status_offset); 808 dev_priv->status = drm_core_findmap(dev, init->status_offset);
816 if (!dev_priv->status) { 809 if (!dev_priv->status) {
817 DRM_ERROR("failed to find status page!\n"); 810 DRM_ERROR("failed to find status page!\n");
@@ -833,7 +826,8 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
833 return DRM_ERR(EINVAL); 826 return DRM_ERR(EINVAL);
834 } 827 }
835 dev->agp_buffer_token = init->buffers_offset; 828 dev->agp_buffer_token = init->buffers_offset;
836 dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); 829 dev->agp_buffer_map =
830 drm_core_findmap(dev, init->buffers_offset);
837 if (!dev->agp_buffer_map) { 831 if (!dev->agp_buffer_map) {
838 DRM_ERROR("failed to find dma buffer region!\n"); 832 DRM_ERROR("failed to find dma buffer region!\n");
839 return DRM_ERR(EINVAL); 833 return DRM_ERR(EINVAL);
@@ -845,8 +839,8 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
845 } 839 }
846 840
847 dev_priv->sarea_priv = 841 dev_priv->sarea_priv =
848 (drm_mga_sarea_t *)((u8 *)dev_priv->sarea->handle + 842 (drm_mga_sarea_t *) ((u8 *) dev_priv->sarea->handle +
849 init->sarea_priv_offset); 843 init->sarea_priv_offset);
850 844
851 if (!dev_priv->warp->handle || 845 if (!dev_priv->warp->handle ||
852 !dev_priv->primary->handle || 846 !dev_priv->primary->handle ||
@@ -869,23 +863,20 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
869 return ret; 863 return ret;
870 } 864 }
871 865
872 dev_priv->prim.status = (u32 *)dev_priv->status->handle; 866 dev_priv->prim.status = (u32 *) dev_priv->status->handle;
873 867
874 mga_do_wait_for_idle( dev_priv ); 868 mga_do_wait_for_idle(dev_priv);
875 869
876 /* Init the primary DMA registers. 870 /* Init the primary DMA registers.
877 */ 871 */
878 MGA_WRITE( MGA_PRIMADDRESS, 872 MGA_WRITE(MGA_PRIMADDRESS, dev_priv->primary->offset | MGA_DMA_GENERAL);
879 dev_priv->primary->offset | MGA_DMA_GENERAL );
880#if 0 873#if 0
881 MGA_WRITE( MGA_PRIMPTR, 874 MGA_WRITE(MGA_PRIMPTR, virt_to_bus((void *)dev_priv->prim.status) | MGA_PRIMPTREN0 | /* Soft trap, SECEND, SETUPEND */
882 virt_to_bus((void *)dev_priv->prim.status) | 875 MGA_PRIMPTREN1); /* DWGSYNC */
883 MGA_PRIMPTREN0 | /* Soft trap, SECEND, SETUPEND */
884 MGA_PRIMPTREN1 ); /* DWGSYNC */
885#endif 876#endif
886 877
887 dev_priv->prim.start = (u8 *)dev_priv->primary->handle; 878 dev_priv->prim.start = (u8 *) dev_priv->primary->handle;
888 dev_priv->prim.end = ((u8 *)dev_priv->primary->handle 879 dev_priv->prim.end = ((u8 *) dev_priv->primary->handle
889 + dev_priv->primary->size); 880 + dev_priv->primary->size);
890 dev_priv->prim.size = dev_priv->primary->size; 881 dev_priv->prim.size = dev_priv->primary->size;
891 882
@@ -913,7 +904,7 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
913 return 0; 904 return 0;
914} 905}
915 906
916static int mga_do_cleanup_dma( drm_device_t *dev ) 907static int mga_do_cleanup_dma(drm_device_t * dev)
917{ 908{
918 int err = 0; 909 int err = 0;
919 DRM_DEBUG("\n"); 910 DRM_DEBUG("\n");
@@ -922,16 +913,17 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
922 * may not have been called from userspace and after dev_private 913 * may not have been called from userspace and after dev_private
923 * is freed, it's too late. 914 * is freed, it's too late.
924 */ 915 */
925 if ( dev->irq_enabled ) drm_irq_uninstall(dev); 916 if (dev->irq_enabled)
917 drm_irq_uninstall(dev);
926 918
927 if ( dev->dev_private ) { 919 if (dev->dev_private) {
928 drm_mga_private_t *dev_priv = dev->dev_private; 920 drm_mga_private_t *dev_priv = dev->dev_private;
929 921
930 if ((dev_priv->warp != NULL) 922 if ((dev_priv->warp != NULL)
931 && (dev_priv->mmio->type != _DRM_CONSISTENT)) 923 && (dev_priv->warp->type != _DRM_CONSISTENT))
932 drm_core_ioremapfree(dev_priv->warp, dev); 924 drm_core_ioremapfree(dev_priv->warp, dev);
933 925
934 if ((dev_priv->primary != NULL) 926 if ((dev_priv->primary != NULL)
935 && (dev_priv->primary->type != _DRM_CONSISTENT)) 927 && (dev_priv->primary->type != _DRM_CONSISTENT))
936 drm_core_ioremapfree(dev_priv->primary, dev); 928 drm_core_ioremapfree(dev_priv->primary, dev);
937 929
@@ -944,7 +936,8 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
944 dev_priv->agp_textures = NULL; 936 dev_priv->agp_textures = NULL;
945 drm_unbind_agp(dev_priv->agp_mem); 937 drm_unbind_agp(dev_priv->agp_mem);
946 938
947 drm_free_agp(dev_priv->agp_mem, dev_priv->agp_pages); 939 drm_free_agp(dev_priv->agp_mem,
940 dev_priv->agp_pages);
948 dev_priv->agp_pages = 0; 941 dev_priv->agp_pages = 0;
949 dev_priv->agp_mem = NULL; 942 dev_priv->agp_mem = NULL;
950 } 943 }
@@ -966,7 +959,8 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
966 959
967 memset(&dev_priv->prim, 0, sizeof(dev_priv->prim)); 960 memset(&dev_priv->prim, 0, sizeof(dev_priv->prim));
968 dev_priv->warp_pipe = 0; 961 dev_priv->warp_pipe = 0;
969 memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys)); 962 memset(dev_priv->warp_pipe_phys, 0,
963 sizeof(dev_priv->warp_pipe_phys));
970 964
971 if (dev_priv->head != NULL) { 965 if (dev_priv->head != NULL) {
972 mga_freelist_cleanup(dev); 966 mga_freelist_cleanup(dev);
@@ -976,103 +970,102 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
976 return err; 970 return err;
977} 971}
978 972
979int mga_dma_init( DRM_IOCTL_ARGS ) 973int mga_dma_init(DRM_IOCTL_ARGS)
980{ 974{
981 DRM_DEVICE; 975 DRM_DEVICE;
982 drm_mga_init_t init; 976 drm_mga_init_t init;
983 int err; 977 int err;
984 978
985 LOCK_TEST_WITH_RETURN( dev, filp ); 979 LOCK_TEST_WITH_RETURN(dev, filp);
986 980
987 DRM_COPY_FROM_USER_IOCTL(init, (drm_mga_init_t __user *) data, 981 DRM_COPY_FROM_USER_IOCTL(init, (drm_mga_init_t __user *) data,
988 sizeof(init)); 982 sizeof(init));
989 983
990 switch ( init.func ) { 984 switch (init.func) {
991 case MGA_INIT_DMA: 985 case MGA_INIT_DMA:
992 err = mga_do_init_dma(dev, &init); 986 err = mga_do_init_dma(dev, &init);
993 if (err) { 987 if (err) {
994 (void) mga_do_cleanup_dma(dev); 988 (void)mga_do_cleanup_dma(dev);
995 } 989 }
996 return err; 990 return err;
997 case MGA_CLEANUP_DMA: 991 case MGA_CLEANUP_DMA:
998 return mga_do_cleanup_dma( dev ); 992 return mga_do_cleanup_dma(dev);
999 } 993 }
1000 994
1001 return DRM_ERR(EINVAL); 995 return DRM_ERR(EINVAL);
1002} 996}
1003 997
1004
1005/* ================================================================ 998/* ================================================================
1006 * Primary DMA stream management 999 * Primary DMA stream management
1007 */ 1000 */
1008 1001
1009int mga_dma_flush( DRM_IOCTL_ARGS ) 1002int mga_dma_flush(DRM_IOCTL_ARGS)
1010{ 1003{
1011 DRM_DEVICE; 1004 DRM_DEVICE;
1012 drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private; 1005 drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
1013 drm_lock_t lock; 1006 drm_lock_t lock;
1014 1007
1015 LOCK_TEST_WITH_RETURN( dev, filp ); 1008 LOCK_TEST_WITH_RETURN(dev, filp);
1016 1009
1017 DRM_COPY_FROM_USER_IOCTL( lock, (drm_lock_t __user *)data, sizeof(lock) ); 1010 DRM_COPY_FROM_USER_IOCTL(lock, (drm_lock_t __user *) data,
1011 sizeof(lock));
1018 1012
1019 DRM_DEBUG( "%s%s%s\n", 1013 DRM_DEBUG("%s%s%s\n",
1020 (lock.flags & _DRM_LOCK_FLUSH) ? "flush, " : "", 1014 (lock.flags & _DRM_LOCK_FLUSH) ? "flush, " : "",
1021 (lock.flags & _DRM_LOCK_FLUSH_ALL) ? "flush all, " : "", 1015 (lock.flags & _DRM_LOCK_FLUSH_ALL) ? "flush all, " : "",
1022 (lock.flags & _DRM_LOCK_QUIESCENT) ? "idle, " : "" ); 1016 (lock.flags & _DRM_LOCK_QUIESCENT) ? "idle, " : "");
1023 1017
1024 WRAP_WAIT_WITH_RETURN( dev_priv ); 1018 WRAP_WAIT_WITH_RETURN(dev_priv);
1025 1019
1026 if ( lock.flags & (_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL) ) { 1020 if (lock.flags & (_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL)) {
1027 mga_do_dma_flush( dev_priv ); 1021 mga_do_dma_flush(dev_priv);
1028 } 1022 }
1029 1023
1030 if ( lock.flags & _DRM_LOCK_QUIESCENT ) { 1024 if (lock.flags & _DRM_LOCK_QUIESCENT) {
1031#if MGA_DMA_DEBUG 1025#if MGA_DMA_DEBUG
1032 int ret = mga_do_wait_for_idle( dev_priv ); 1026 int ret = mga_do_wait_for_idle(dev_priv);
1033 if ( ret < 0 ) 1027 if (ret < 0)
1034 DRM_INFO( "%s: -EBUSY\n", __FUNCTION__ ); 1028 DRM_INFO("%s: -EBUSY\n", __FUNCTION__);
1035 return ret; 1029 return ret;
1036#else 1030#else
1037 return mga_do_wait_for_idle( dev_priv ); 1031 return mga_do_wait_for_idle(dev_priv);
1038#endif 1032#endif
1039 } else { 1033 } else {
1040 return 0; 1034 return 0;
1041 } 1035 }
1042} 1036}
1043 1037
1044int mga_dma_reset( DRM_IOCTL_ARGS ) 1038int mga_dma_reset(DRM_IOCTL_ARGS)
1045{ 1039{
1046 DRM_DEVICE; 1040 DRM_DEVICE;
1047 drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private; 1041 drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
1048 1042
1049 LOCK_TEST_WITH_RETURN( dev, filp ); 1043 LOCK_TEST_WITH_RETURN(dev, filp);
1050 1044
1051 return mga_do_dma_reset( dev_priv ); 1045 return mga_do_dma_reset(dev_priv);
1052} 1046}
1053 1047
1054
1055/* ================================================================ 1048/* ================================================================
1056 * DMA buffer management 1049 * DMA buffer management
1057 */ 1050 */
1058 1051
1059static int mga_dma_get_buffers( DRMFILE filp, 1052static int mga_dma_get_buffers(DRMFILE filp, drm_device_t * dev, drm_dma_t * d)
1060 drm_device_t *dev, drm_dma_t *d )
1061{ 1053{
1062 drm_buf_t *buf; 1054 drm_buf_t *buf;
1063 int i; 1055 int i;
1064 1056
1065 for ( i = d->granted_count ; i < d->request_count ; i++ ) { 1057 for (i = d->granted_count; i < d->request_count; i++) {
1066 buf = mga_freelist_get( dev ); 1058 buf = mga_freelist_get(dev);
1067 if ( !buf ) return DRM_ERR(EAGAIN); 1059 if (!buf)
1060 return DRM_ERR(EAGAIN);
1068 1061
1069 buf->filp = filp; 1062 buf->filp = filp;
1070 1063
1071 if ( DRM_COPY_TO_USER( &d->request_indices[i], 1064 if (DRM_COPY_TO_USER(&d->request_indices[i],
1072 &buf->idx, sizeof(buf->idx) ) ) 1065 &buf->idx, sizeof(buf->idx)))
1073 return DRM_ERR(EFAULT); 1066 return DRM_ERR(EFAULT);
1074 if ( DRM_COPY_TO_USER( &d->request_sizes[i], 1067 if (DRM_COPY_TO_USER(&d->request_sizes[i],
1075 &buf->total, sizeof(buf->total) ) ) 1068 &buf->total, sizeof(buf->total)))
1076 return DRM_ERR(EFAULT); 1069 return DRM_ERR(EFAULT);
1077 1070
1078 d->granted_count++; 1071 d->granted_count++;
@@ -1080,44 +1073,44 @@ static int mga_dma_get_buffers( DRMFILE filp,
1080 return 0; 1073 return 0;
1081} 1074}
1082 1075
1083int mga_dma_buffers( DRM_IOCTL_ARGS ) 1076int mga_dma_buffers(DRM_IOCTL_ARGS)
1084{ 1077{
1085 DRM_DEVICE; 1078 DRM_DEVICE;
1086 drm_device_dma_t *dma = dev->dma; 1079 drm_device_dma_t *dma = dev->dma;
1087 drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private; 1080 drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
1088 drm_dma_t __user *argp = (void __user *)data; 1081 drm_dma_t __user *argp = (void __user *)data;
1089 drm_dma_t d; 1082 drm_dma_t d;
1090 int ret = 0; 1083 int ret = 0;
1091 1084
1092 LOCK_TEST_WITH_RETURN( dev, filp ); 1085 LOCK_TEST_WITH_RETURN(dev, filp);
1093 1086
1094 DRM_COPY_FROM_USER_IOCTL( d, argp, sizeof(d) ); 1087 DRM_COPY_FROM_USER_IOCTL(d, argp, sizeof(d));
1095 1088
1096 /* Please don't send us buffers. 1089 /* Please don't send us buffers.
1097 */ 1090 */
1098 if ( d.send_count != 0 ) { 1091 if (d.send_count != 0) {
1099 DRM_ERROR( "Process %d trying to send %d buffers via drmDMA\n", 1092 DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
1100 DRM_CURRENTPID, d.send_count ); 1093 DRM_CURRENTPID, d.send_count);
1101 return DRM_ERR(EINVAL); 1094 return DRM_ERR(EINVAL);
1102 } 1095 }
1103 1096
1104 /* We'll send you buffers. 1097 /* We'll send you buffers.
1105 */ 1098 */
1106 if ( d.request_count < 0 || d.request_count > dma->buf_count ) { 1099 if (d.request_count < 0 || d.request_count > dma->buf_count) {
1107 DRM_ERROR( "Process %d trying to get %d buffers (of %d max)\n", 1100 DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
1108 DRM_CURRENTPID, d.request_count, dma->buf_count ); 1101 DRM_CURRENTPID, d.request_count, dma->buf_count);
1109 return DRM_ERR(EINVAL); 1102 return DRM_ERR(EINVAL);
1110 } 1103 }
1111 1104
1112 WRAP_TEST_WITH_RETURN( dev_priv ); 1105 WRAP_TEST_WITH_RETURN(dev_priv);
1113 1106
1114 d.granted_count = 0; 1107 d.granted_count = 0;
1115 1108
1116 if ( d.request_count ) { 1109 if (d.request_count) {
1117 ret = mga_dma_get_buffers( filp, dev, &d ); 1110 ret = mga_dma_get_buffers(filp, dev, &d);
1118 } 1111 }
1119 1112
1120 DRM_COPY_TO_USER_IOCTL( argp, d, sizeof(d) ); 1113 DRM_COPY_TO_USER_IOCTL(argp, d, sizeof(d));
1121 1114
1122 return ret; 1115 return ret;
1123} 1116}
@@ -1138,11 +1131,11 @@ int mga_driver_postcleanup(drm_device_t * dev)
1138 */ 1131 */
1139void mga_driver_pretakedown(drm_device_t * dev) 1132void mga_driver_pretakedown(drm_device_t * dev)
1140{ 1133{
1141 mga_do_cleanup_dma( dev ); 1134 mga_do_cleanup_dma(dev);
1142} 1135}
1143 1136
1144int mga_driver_dma_quiescent(drm_device_t *dev) 1137int mga_driver_dma_quiescent(drm_device_t * dev)
1145{ 1138{
1146 drm_mga_private_t *dev_priv = dev->dev_private; 1139 drm_mga_private_t *dev_priv = dev->dev_private;
1147 return mga_do_wait_for_idle( dev_priv ); 1140 return mga_do_wait_for_idle(dev_priv);
1148} 1141}