summaryrefslogtreecommitdiffstats
path: root/src/vivante.c
blob: ff42a790ffa52a4b65e8d11325c8d540c49795a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/*
 * Vivante GPU Acceleration Xorg driver
 *
 * Written by Russell King, 2012, derived in part from the
 * Intel xorg X server driver.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_DIX_CONFIG_H
#include "dix-config.h"
#endif

#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <unistd.h>

#include <armada_bufmgr.h>

#include "armada_drm.h"

#include "fb.h"
#include "gcstruct.h"
#include "xf86.h"
#include "compat-api.h"

#include <gc_hal.h>

#include "gal_extension.h"

#include "vivante.h"
#include "vivante_accel.h"
#include "vivante_dri2.h"
#include "vivante_unaccel.h"
#include "vivante_utils.h"

vivante_Key vivante_pixmap_index;
vivante_Key vivante_screen_index;

void vivante_free_pixmap(PixmapPtr pixmap)
{
	struct vivante_pixmap *vPix = vivante_get_pixmap_priv(pixmap);

	if (vPix) {
		struct vivante *vivante;

		vivante = vivante_get_screen_priv(pixmap->drawable.pScreen);
		vivante_batch_wait_commit(vivante, vPix);
		if (vPix->bo->type == DRM_ARMADA_BO_SHMEM && vPix->owner == GPU)
			vivante_unmap_gpu(vivante, vPix);
		if (vPix->bo->type != DRM_ARMADA_BO_SHMEM)
			vivante_unmap_from_gpu(vivante, vPix->info,
					       vPix->handle);
		drm_armada_bo_put(vPix->bo);
		free(vPix);
	}
}

void vivante_set_pixmap_bo(PixmapPtr pixmap, struct drm_armada_bo *bo)
{
	struct vivante_pixmap *vPix = vivante_get_pixmap_priv(pixmap);
	struct vivante *vivante = vivante_get_screen_priv(pixmap->drawable.pScreen);

	if (!vPix && !bo)
		return;

	if (vPix) {
		if (vPix->bo == bo)
			return;

		vivante_free_pixmap(pixmap);
		vPix = NULL;
	}

	if (bo) {
		gceSURF_FORMAT format;

		if (bo->pitch != pixmap->devKind) {
			xf86DrvMsg(vivante->scrnIndex, X_ERROR,
				   "%s: bo pitch %u and pixmap pitch %u mismatch\n",
				   __FUNCTION__, bo->pitch, pixmap->devKind);
			goto fail;
		}

		/*
		 * This is an imprecise conversion to the Vivante GAL format.
		 * One important thing here is that Pixmaps don't have an
		 * alpha channel.
		 */
		switch (pixmap->drawable.bitsPerPixel) {
		case 16:
			if (pixmap->drawable.depth == 15)
				format = gcvSURF_X1R5G5B5;
			else
				format = gcvSURF_R5G6B5;
			break;
		case 32:
			format = gcvSURF_X8R8G8B8;
			break;
		default:
			goto fail;
		}

		vPix = calloc(1, sizeof *vPix);
		if (!vPix)
			goto fail;

		vPix->bo = bo;
		vPix->width = pixmap->drawable.width;
		vPix->height = pixmap->drawable.height;
		vPix->pitch = bo->pitch;
		vPix->handle = -1;
		vPix->format = format;
		vPix->owner = NONE;

		/*
		 * If this is not a SHMEM bo, then we need to map it
		 * for the GPU.  As it will not be a fully cached mapping,
		 * we can keep this mapped.
		 */
		if (bo->type != DRM_ARMADA_BO_SHMEM) {
			if (!vivante_map_bo_to_gpu(vivante, bo, &vPix->info,
						   &vPix->handle)) {
				free(vPix);
				goto fail;
			}
		}

#ifdef DEBUG_PIXMAP
		dbg("Pixmap %p: vPix=%p bo=%p\n", pixmap, vPix, bo);
#endif
		drm_armada_bo_get(bo);
	}

 fail:
	vivante_set_pixmap_priv(pixmap, vPix);
}


/* Determine whether this GC can be accelerated */
static Bool vivante_GC_can_accel(GCPtr pGC, DrawablePtr pDrawable)
{
	unsigned long fullmask = FbFullMask(pDrawable->depth);

	/* Must be full-planes */
	return !pGC || (pGC->planemask & fullmask) == fullmask;
}

static Bool vivante_GCfill_can_accel(GCPtr pGC, DrawablePtr pDrawable)
{
	switch (pGC->fillStyle) {
	case FillSolid:
		return TRUE;

	case FillTiled:
		/* Single pixel tiles are just solid colours */
		if (pGC->tileIsPixel)
			return TRUE;

		/* If the tile pixmap is a single pixel, it's also a solid fill */
		if (pGC->tile.pixmap->drawable.width == 1 &&
		    pGC->tile.pixmap->drawable.height == 1)
			return TRUE;

		/* In theory, we could do !tileIsPixel as well, which means
		 * copying the tile (possibly) multiple times to the drawable.
		 * This is something we should do, especially if the size of
		 * the tile matches the size of the drawable and the tile
		 * offsets are zero (iow, it's a plain copy.)
		 */
		return FALSE;

	default:
		return FALSE;
	}
}


static void
vivante_FillSpans(DrawablePtr pDrawable, GCPtr pGC, int n, DDXPointPtr ppt,
	int *pwidth, int fSorted)
{
	struct vivante *vivante = vivante_get_screen_priv(pDrawable->pScreen);

	assert(vivante_GC_can_accel(pGC, pDrawable));

	if (vivante->force_fallback ||
	    !vivante_GCfill_can_accel(pGC, pDrawable) ||
	    !vivante_accel_FillSpans(pDrawable, pGC, n, ppt, pwidth, fSorted))
		vivante_unaccel_FillSpans(pDrawable, pGC, n, ppt, pwidth, fSorted);
}

static void
vivante_PutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
	int w, int h, int leftPad, int format, char *bits)
{
	struct vivante *vivante = vivante_get_screen_priv(pDrawable->pScreen);

	assert(vivante_GC_can_accel(pGC, pDrawable));

	if (vivante->force_fallback ||
	    !vivante_accel_PutImage(pDrawable, pGC, depth, x, y, w, h, leftPad,
				    format, bits))
		vivante_unaccel_PutImage(pDrawable, pGC, depth, x, y, w, h, leftPad,
					 format, bits);
}

static RegionPtr
vivante_CopyArea(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
	int srcx, int srcy, int w, int h, int dstx, int dsty)
{
	struct vivante *vivante = vivante_get_screen_priv(pDst->pScreen);

	assert(vivante_GC_can_accel(pGC, pDst));

	if (vivante->force_fallback)
		return vivante_unaccel_CopyArea(pSrc, pDst, pGC, srcx, srcy, w, h,
										dstx, dsty);

	return miDoCopy(pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty,
			vivante_accel_CopyNtoN, 0, NULL);
}

static void
vivante_PolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
	DDXPointPtr ppt)
{
	struct vivante *vivante = vivante_get_screen_priv(pDrawable->pScreen);

	assert(vivante_GC_can_accel(pGC, pDrawable));

	if (vivante->force_fallback ||
	    !vivante_GCfill_can_accel(pGC, pDrawable) ||
	    !vivante_accel_PolyPoint(pDrawable, pGC, mode, npt, ppt))
		vivante_unaccel_PolyPoint(pDrawable, pGC, mode, npt, ppt);
}

static void
vivante_PolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrect,
	xRectangle * prect)
{
	struct vivante *vivante = vivante_get_screen_priv(pDrawable->pScreen);

	if (vivante->force_fallback)
		goto fallback;

	assert(vivante_GC_can_accel(pGC, pDrawable));

	if (vivante_GCfill_can_accel(pGC, pDrawable)) {
		if (vivante_accel_PolyFillRectSolid(pDrawable, pGC, nrect, prect))
			return;
	} else if (pGC->fillStyle == FillTiled) {
		if (vivante_accel_PolyFillRectTiled(pDrawable, pGC, nrect, prect))
			return;
	}

 fallback:
	vivante_unaccel_PolyFillRect(pDrawable, pGC, nrect, prect);
}

static GCOps vivante_GCOps = {
	vivante_FillSpans,
	vivante_unaccel_SetSpans,
	vivante_PutImage,
	vivante_CopyArea,
	vivante_unaccel_CopyPlane,
	vivante_PolyPoint,
	vivante_unaccel_PolyLines,
	vivante_unaccel_PolySegment,
	miPolyRectangle,
	miPolyArc,
	miFillPolygon,
	vivante_PolyFillRect,
	miPolyFillArc,
	miPolyText8,
	miPolyText16,
	miImageText8,
	miImageText16,
	vivante_unaccel_ImageGlyphBlt,
	vivante_unaccel_PolyGlyphBlt,
	vivante_unaccel_PushPixels
};

static GCOps vivante_unaccel_GCOps = {
	vivante_unaccel_FillSpans,
	vivante_unaccel_SetSpans,
	vivante_unaccel_PutImage,
	vivante_unaccel_CopyArea,
	vivante_unaccel_CopyPlane,
	vivante_unaccel_PolyPoint,
	vivante_unaccel_PolyLines,
	vivante_unaccel_PolySegment,
	miPolyRectangle,
	miPolyArc,
	miFillPolygon,
	vivante_unaccel_PolyFillRect,
	miPolyFillArc,
	miPolyText8,
	miPolyText16,
	miImageText8,
	miImageText16,
	vivante_unaccel_ImageGlyphBlt,
	vivante_unaccel_PolyGlyphBlt,
	vivante_unaccel_PushPixels
};

static void
vivante_ValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
{
#ifdef FB_24_32BIT
	if (changes & GCTile && fbGetRotatedPixmap(pGC)) {
		pGC->pScreen->DestroyPixmap(fbGetRotatedPixmap(pGC));
		fbGetRotatedPixmap(pGC) = NULL;
	}
	if (pGC->fillStyle == FillTiled) {
		PixmapPtr pOldTile = pGC->tile.pixmap;
		PixmapPtr pNewTile;

		if (pOldTile->drawable.bitsPerPixel != pDrawable->bitsPerPixel) {
			pNewTile = fbGetRotatedPixmap(pGC);
			if (!pNewTile || pNewTile->drawable.bitsPerPixel != pDrawable->bitsPerPixel) {
				if (pNewTile)
					pGC->pScreen->DestroyPixmap(pNewTile);
				vivante_prepare_drawable(&pOldTile->drawable, ACCESS_RO);
				pNewTile = fb24_32ReformatTile(pOldTile, pDrawable->bitsPerPixel);
				vivante_finish_drawable(&pOldTile->drawable, ACCESS_RO);
			}
			if (pNewTile) {
				fbGetRotatedPixmap(pGC) = pOldTile;
				pGC->tile.pixmap = pNewTile;
				changes |= GCTile;
			}
		}
	}
#endif
	if (changes & GCTile) {
		if (!pGC->tileIsPixel &&
		    FbEvenTile(pGC->tile.pixmap->drawable.width *
			       pDrawable->bitsPerPixel)) {
			vivante_prepare_drawable(&pGC->tile.pixmap->drawable, ACCESS_RW);
			fbPadPixmap(pGC->tile.pixmap);
			vivante_finish_drawable(&pGC->tile.pixmap->drawable, ACCESS_RW);
		}
		/* mask out gctile changes now that we've done the work */
		changes &= ~GCTile;
	}
	if (changes & GCStipple && pGC->stipple) {
		vivante_prepare_drawable(&pGC->stipple->drawable, ACCESS_RW);
		fbValidateGC(pGC, changes, pDrawable);
		vivante_finish_drawable(&pGC->stipple->drawable, ACCESS_RW);
	} else {
		fbValidateGC(pGC, changes, pDrawable);
	}
	/*
	 * Select the GC ops depending on whether we have any
	 * chance to accelerate with this GC.
	 */
	pGC->ops = vivante_GC_can_accel(pGC, pDrawable)
				 ? &vivante_GCOps : &vivante_unaccel_GCOps;
}

static GCFuncs vivante_GCFuncs = {
	vivante_ValidateGC,
	miChangeGC,
	miCopyGC,
	miDestroyGC,
	miChangeClip,
	miDestroyClip,
	miCopyClip
};


static Bool vivante_CloseScreen(CLOSE_SCREEN_ARGS_DECL)
{
	struct vivante *vivante = vivante_get_screen_priv(pScreen);
#ifdef RENDER
	PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
#endif

#ifdef RENDER
	/* Restore the Pointers */
	ps->Composite = vivante->Composite;
	ps->Glyphs = vivante->Glyphs;
	ps->UnrealizeGlyph = vivante->UnrealizeGlyph;
	ps->Triangles = vivante->Triangles;
	ps->Trapezoids = vivante->Trapezoids;
	ps->AddTriangles = vivante->AddTriangles;
	ps->AddTraps = vivante->AddTraps;
#endif

	pScreen->CloseScreen = vivante->CloseScreen;
	pScreen->GetImage = vivante->GetImage;
	pScreen->GetSpans = vivante->GetSpans;
	pScreen->ChangeWindowAttributes = vivante->ChangeWindowAttributes;
	pScreen->CopyWindow = vivante->CopyWindow;
	pScreen->CreatePixmap = vivante->CreatePixmap;
	pScreen->DestroyPixmap = vivante->DestroyPixmap;
	pScreen->CreateGC = vivante->CreateGC;
	pScreen->BitmapToRegion = vivante->BitmapToRegion;
	pScreen->BlockHandler = vivante->BlockHandler;

#ifdef HAVE_DRI2
	vivante_dri2_CloseScreen(CLOSE_SCREEN_ARGS);
#endif

#ifdef VIVANTE_BATCH
	vivante_unmap_from_gpu(vivante, vivante->batch_info,
			       vivante->batch_handle);
#endif

	vivante_accel_shutdown(vivante);

#ifdef VIVANTE_BATCH
	drm_armada_bo_put(vivante->batch_bo);
#endif

	free(vivante);

	return pScreen->CloseScreen(CLOSE_SCREEN_ARGS);
}

static void
vivante_CopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
{
	PixmapPtr pPixmap = pWin->drawable.pScreen->GetWindowPixmap(pWin);
	RegionRec rgnDst;
	int dx, dy;

	dx = ptOldOrg.x - pWin->drawable.x;
	dy = ptOldOrg.y - pWin->drawable.y;
	RegionTranslate(prgnSrc, -dx, -dy);
	RegionInit(&rgnDst, NullBox, 0);
	RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);

	miCopyRegion(&pPixmap->drawable, &pPixmap->drawable, NULL,
		     &rgnDst, dx, dy, vivante_accel_CopyNtoN, 0, NULL);

	RegionUninit(&rgnDst);
}

static PixmapPtr
vivante_CreatePixmap(ScreenPtr pScreen, int w, int h, int depth, unsigned usage)
{
	struct vivante *vivante = vivante_get_screen_priv(pScreen);
	struct drm_armada_bo *bo;
	PixmapPtr pixmap;
	int ret, bpp;

	if (w > 32768 || h > 32768)
		return NullPixmap;

	if (depth == 1 || vivante->force_fallback)
		goto fallback;

	if (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE && w <= 32 && h <= 32)
		goto fallback;

	pixmap = vivante->CreatePixmap(pScreen, 0, 0, depth, usage);
	if (pixmap == NullPixmap || w == 0 || h == 0)
		return pixmap;

	bpp = pixmap->drawable.bitsPerPixel;
	if (bpp != 16 && bpp != 32)
		goto fallback_free_pix;

	bo = drm_armada_bo_create(vivante->bufmgr, w, h, bpp);
	if (!bo)
		goto fallback_free_pix;

	ret = drm_armada_bo_map(bo);
	if (ret)
		goto fallback_free_bo;

	/*
	 * Do not store our data pointer in the pixmap - only do so (via
	 * vivante_prepare_drawable()) when required to directly access the
	 * pixmap.  This provides us a way to validate that we do not have
	 * any spurious unchecked accesses to the pixmap data while the GPU
	 * has ownership of the pixmap.
	 */
	pScreen->ModifyPixmapHeader(pixmap, w, h, 0, 0, bo->pitch, NULL);

	vivante_set_pixmap_bo(pixmap, bo);
	if (!vivante_get_pixmap_priv(pixmap))
		goto fallback_free_bo;

	drm_armada_bo_put(bo);
	goto out;

 fallback_free_bo:
	drm_armada_bo_put(bo);
 fallback_free_pix:
	vivante->DestroyPixmap(pixmap);
 fallback:
	pixmap = vivante->CreatePixmap(pScreen, w, h, depth, usage);

 out:
#ifdef DEBUG_PIXMAP
	dbg("Created pixmap %p %dx%d %d %d %x\n",
	    pixmap, w, h, depth, pixmap->drawable.bitsPerPixel, usage);
#endif

	return pixmap;
}

static Bool vivante_DestroyPixmap(PixmapPtr pixmap)
{
	struct vivante *vivante = vivante_get_screen_priv(pixmap->drawable.pScreen);
	if (pixmap->refcnt == 1) {
#ifdef DEBUG_PIXMAP
		dbg("Destroying pixmap %p\n", pixmap);
#endif
		vivante_free_pixmap(pixmap);
		vivante_set_pixmap_priv(pixmap, NULL);
	}
	return vivante->DestroyPixmap(pixmap);
}

static Bool vivante_CreateGC(GCPtr pGC)
{
	struct vivante *vivante = vivante_get_screen_priv(pGC->pScreen);
	Bool ret;

	ret = vivante->CreateGC(pGC);
	if (ret)
		pGC->funcs = &vivante_GCFuncs;

	return ret;
}

/* Commit any pending GPU operations */
static void
vivante_BlockHandler(BLOCKHANDLER_ARGS_DECL)
{
	SCREEN_PTR(arg);
	struct vivante *vivante = vivante_get_screen_priv(pScreen);

	if (vivante->need_commit)
		vivante_commit(vivante, FALSE);

	pScreen->BlockHandler = vivante->BlockHandler;
	pScreen->BlockHandler(BLOCKHANDLER_ARGS);
	vivante->BlockHandler = pScreen->BlockHandler;
	pScreen->BlockHandler = vivante_BlockHandler;
}

#ifdef RENDER
static void
vivante_Composite(CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst,
	INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask, INT16 xDst, INT16 yDst,
	CARD16 width, CARD16 height)
{
	struct vivante *vivante = vivante_get_screen_priv(pDst->pDrawable->pScreen);

	if (vivante->force_fallback ||
	    !vivante_accel_Composite(op, pSrc, pMask, pDst, xSrc, ySrc,
				     xMask, yMask, xDst, yDst, width, height))
		vivante_unaccel_Composite(op, pSrc, pMask, pDst, xSrc, ySrc,
					  xMask, yMask, xDst, yDst, width, height);
}
#endif

Bool vivante_ScreenInit(ScreenPtr pScreen, struct drm_armada_bufmgr *mgr)
{
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
#ifdef RENDER
	PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
#endif
	struct vivante *vivante;

	if (!vivante_CreateKey(&vivante_pixmap_index, PRIVATE_PIXMAP) ||
	    !vivante_CreateKey(&vivante_screen_index, PRIVATE_SCREEN))
		return FALSE;

	vivante = calloc(1, sizeof *vivante);
	if (!vivante)
		return FALSE;

	vivante->drm_fd = GET_DRM_INFO(pScrn)->fd;
	vivante->scrnIndex = pScrn->scrnIndex;
	vivante->bufmgr = mgr;

#ifdef VIVANTE_BATCH
	xorg_list_init(&vivante->batch_list);
	vivante->batch_bo = drm_armada_bo_dumb_create(mgr, 64, 64, 32);
	if (!vivante->batch_bo) {
		xf86DrvMsg(vivante->scrnIndex, X_ERROR,
			   "vivante: unable to create batch bo: %s\n",
			   strerror(errno));
		goto fail;
	}

	if (drm_armada_bo_map(vivante->batch_bo)) {
		xf86DrvMsg(vivante->scrnIndex, X_ERROR,
			   "vivante: unable to map batch bo: %s\n",
			   strerror(errno));
		goto fail;
	}
#endif

	if (!vivante_accel_init(vivante))
		goto fail;

#ifdef VIVANTE_BATCH
	if (!vivante_map_bo_to_gpu(vivante, vivante->batch_bo,
				   &vivante->batch_info,
				   &vivante->batch_handle))
		goto fail;

	vivante->batch_ptr = vivante->batch_bo->ptr;
	vivante->batch_idx_max = vivante->batch_bo->size / sizeof(uint32_t);

//	xf86DrvMsg(vivante->scrnIndex, X_INFO,
//		   "vivante: created batch at v%p p0x%08x max idx %u\n",
//		   vivante->batch_ptr, vivante->batch_handle,
//		   vivante->batch_idx_max);
#endif

	vivante_set_screen_priv(pScreen, vivante);

#ifdef HAVE_DRI2
	if (!vivante_dri2_ScreenInit(pScreen))
		goto fail;
#endif

	vivante->CloseScreen = pScreen->CloseScreen;
	pScreen->CloseScreen = vivante_CloseScreen;
	vivante->GetImage = pScreen->GetImage;
	pScreen->GetImage = vivante_unaccel_GetImage;
	vivante->GetSpans = pScreen->GetSpans;
	pScreen->GetSpans = vivante_unaccel_GetSpans;
	vivante->ChangeWindowAttributes = pScreen->ChangeWindowAttributes;
	pScreen->ChangeWindowAttributes = vivante_unaccel_ChangeWindowAttributes;
	vivante->CopyWindow = pScreen->CopyWindow;
	pScreen->CopyWindow = vivante_CopyWindow;
	vivante->CreatePixmap = pScreen->CreatePixmap;
	pScreen->CreatePixmap = vivante_CreatePixmap;
	vivante->DestroyPixmap = pScreen->DestroyPixmap;
	pScreen->DestroyPixmap = vivante_DestroyPixmap;
	vivante->CreateGC = pScreen->CreateGC;
	pScreen->CreateGC = vivante_CreateGC;
	vivante->BitmapToRegion = pScreen->BitmapToRegion;
	pScreen->BitmapToRegion = vivante_unaccel_BitmapToRegion;
	vivante->BlockHandler = pScreen->BlockHandler;
	pScreen->BlockHandler = vivante_BlockHandler;

#ifdef RENDER
	vivante->Composite = ps->Composite;
	ps->Composite = vivante_Composite;
	vivante->Glyphs = ps->Glyphs;
	ps->Glyphs = vivante_unaccel_Glyphs;
	vivante->UnrealizeGlyph = ps->UnrealizeGlyph;
	vivante->Triangles = ps->Triangles;
	ps->Triangles = vivante_unaccel_Triangles;
	vivante->Trapezoids = ps->Trapezoids;
	ps->Trapezoids = vivante_unaccel_Trapezoids;
	vivante->AddTriangles = ps->AddTriangles;
	ps->AddTriangles = vivante_unaccel_AddTriangles;
	vivante->AddTraps = ps->AddTraps;
	ps->AddTraps = vivante_unaccel_AddTraps;
#endif

	return TRUE;

fail:
#ifdef VIVANTE_BATCH
	if (vivante->batch_info)
		vivante_unmap_from_gpu(vivante, vivante->batch_info,
				       vivante->batch_handle);
#endif
	vivante_accel_shutdown(vivante);
#ifdef VIVANTE_BATCH
	if (vivante->batch_bo)
		drm_armada_bo_put(vivante->batch_bo);
#endif
	free(vivante);
	return FALSE;
}