aboutsummaryrefslogtreecommitdiffstats
path: root/meta-fsl-arm/recipes-graphics/xorg-driver/xf86-video-imxfb/Make-video-API-forward-and-backward-compatible.patch
blob: 2ac6311fb13e356497050ad852ffb54d8192d57f (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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
From 5216cb0f14414b5451f58df48a36c1c62c035276 Mon Sep 17 00:00:00 2001
From: Otavio Salvador <otavio@ossystems.com.br>
Date: Sat, 29 Dec 2012 18:02:11 -0200
Subject: [PATCH] Make video API forward and backward compatible

This updates the video API in a forward and backward compatible way
using the "compat-api.h" as used in Xorg maintained drivers.

Upstream-Status: Pending

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 src/compat-api.h        |  106 +++++++++++++++++++++++++++++++++++++++++++++++
 src/imx_display.c       |   22 +++++-----
 src/imx_display.h       |    8 ++--
 src/imx_driver.c        |   60 ++++++++++++++-------------
 src/imx_exa_offscreen.c |   12 +++---
 src/imx_exa_z160.c      |   53 ++++++++++++------------
 src/imx_xv_ipu.c        |    4 +-
 7 files changed, 188 insertions(+), 77 deletions(-)
 create mode 100644 src/compat-api.h

diff --git a/src/compat-api.h b/src/compat-api.h
new file mode 100644
index 0000000..73ac8a2
--- /dev/null
+++ b/src/compat-api.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Dave Airlie <airlied@redhat.com>
+ */
+
+/* this file provides API compat between server post 1.13 and pre it,
+   it should be reused inside as many drivers as possible */
+#ifndef COMPAT_API_H
+#define COMPAT_API_H
+
+#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
+#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
+#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
+#endif
+
+#ifndef XF86_HAS_SCRN_CONV
+#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
+#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
+#endif
+
+#ifndef XF86_SCRN_INTERFACE
+
+#define SCRN_ARG_TYPE int
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = xf86Screens[(arg1)]
+
+#define SCREEN_ARG_TYPE int
+#define SCREEN_PTR(arg1) ScreenPtr pScreen = screenInfo.screens[(arg1)]
+
+#define SCREEN_INIT_ARGS_DECL int index, ScreenPtr pScreen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask
+
+#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen
+#define CLOSE_SCREEN_ARGS scrnIndex, pScreen
+#define CLOSE_SCREEN_DECL_ScrnInfoPtr ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+
+#define FBDEVHWADJUSTFRAME_ARGS(x, y) scrnIndex, (x), (y), 0
+
+#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
+
+#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
+
+#define FREE_SCREEN_ARGS_DECL int arg, int flags
+#define FREE_SCREEN_ARGS(x) (x)->scrnIndex, 0
+
+#define VT_FUNC_ARGS_DECL int arg, int flags
+#define VT_FUNC_ARGS(flags) pScrn->scrnIndex, (flags)
+
+#define ENABLE_DISABLE_FB_ACCESS_ARGS(pScrn, b) pScrn->scrnIndex, b
+
+#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
+#else
+#define SCRN_ARG_TYPE ScrnInfoPtr
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = (arg1)
+
+#define SCREEN_ARG_TYPE ScreenPtr
+#define SCREEN_PTR(arg1) ScreenPtr pScreen = (arg1)
+
+#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask
+
+#define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen
+#define CLOSE_SCREEN_ARGS pScreen
+#define CLOSE_SCREEN_DECL_ScrnInfoPtr ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+#define FBDEVHWADJUSTFRAME_ARGS(x, y) pScrn, (x), (y)
+
+#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
+#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
+
+#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
+#define FREE_SCREEN_ARGS(x) (x)
+
+#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
+#define VT_FUNC_ARGS(flags) pScrn
+
+#define ENABLE_DISABLE_FB_ACCESS_ARGS(pScrn, b) pScrn, b
+
+#define XF86_ENABLEDISABLEFB_ARG(x) (x)
+
+#endif
+
+#endif
diff --git a/src/imx_display.c b/src/imx_display.c
index fcb8195..e2dc36a 100644
--- a/src/imx_display.c
+++ b/src/imx_display.c
@@ -42,6 +42,8 @@
 #include "imx.h"
 #include "imx_display.h"
 
+#include "compat-api.h"
+
 #include <X11/Xatom.h>
 
 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,6,0,0)
@@ -1373,19 +1375,19 @@ imxDisplayPreInit(ScrnInfoPtr pScrn)
 Bool
 imxDisplayStartScreenInit(int scrnIndex, ScreenPtr pScreen)
 {
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 	ImxPtr fPtr = IMXPTR(pScrn);
 
 	if (!xf86SetDesiredModes(pScrn)) {
 
-		xf86DrvMsg(scrnIndex, X_ERROR, "mode initialization failed\n");
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "mode initialization failed\n");
 		return FALSE;
 	}
 
 #if 0
 	if (!fbdevHWModeInit(pScrn, pScrn->currentMode)) {
 
-		xf86DrvMsg(scrnIndex, X_ERROR, "mode initialization failed\n");
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "mode initialization failed\n");
 		return FALSE;
 	}
 	pScrn->displayWidth =
@@ -1463,29 +1465,29 @@ imxDisplayFinishScreenInit(int scrnIndex, ScreenPtr pScreen)
 /* -------------------------------------------------------------------- */
 
 Bool
-imxDisplaySwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+imxDisplaySwitchMode(SWITCH_MODE_ARGS_DECL)
 {
-	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+	SCRN_INFO_PTR(arg);
 
 	return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
 }
 
 void
-imxDisplayAdjustFrame(int scrnIndex, int x, int y, int flags)
+imxDisplayAdjustFrame(ADJUST_FRAME_ARGS_DECL)
 {
-//	fbdevHWAdjustFrame(scrnIndex, x, y, flags);
+//	fbdevHWAdjustFrame(pScrn->scrnIndex, x, y, flags);
 }
 
 Bool
-imxDisplayEnterVT(int scrnIndex, int flags)
+imxDisplayEnterVT(VT_FUNC_ARGS_DECL)
 {
-	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+	SCRN_INFO_PTR(arg);
 
 	return xf86SetDesiredModes(pScrn);
 }
 
 void
-imxDisplayLeaveVT(int scrnIndex, int flags)
+imxDisplayLeaveVT(VT_FUNC_ARGS_DECL)
 {
 }
 
diff --git a/src/imx_display.h b/src/imx_display.h
index 4a5d5aa..3a3d43a 100644
--- a/src/imx_display.h
+++ b/src/imx_display.h
@@ -59,16 +59,16 @@ imxDisplayValidMode(int scrnIndex, DisplayModePtr mode,
 			Bool verbose, int flags);
 
 extern Bool
-imxDisplaySwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
+imxDisplaySwitchMode(SWITCH_MODE_ARGS_DECL);
 
 extern void
-imxDisplayAdjustFrame(int scrnIndex, int x, int y, int flags);
+imxDisplayAdjustFrame(ADJUST_FRAME_ARGS_DECL);
 
 extern Bool
-imxDisplayEnterVT(int scrnIndex, int flags);
+imxDisplayEnterVT(VT_FUNC_ARGS_DECL);
 
 extern void
-imxDisplayLeaveVT(int scrnIndex, int flags);
+imxDisplayLeaveVT(VT_FUNC_ARGS_DECL);
 
 extern Bool
 imxDisplayChangeFrameBufferRotateEPDC(int scrnIndex, int fbRotate);
diff --git a/src/imx_driver.c b/src/imx_driver.c
index 178e36e..f4b3e38 100644
--- a/src/imx_driver.c
+++ b/src/imx_driver.c
@@ -46,6 +46,8 @@
 #include "fb.h"
 #include "fbdevhw.h"
 
+#include "compat-api.h"
+
 #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
 #include "xf86Resources.h"
 #include "xf86RAC.h"
@@ -435,17 +437,17 @@ errorPreInit:
 }
 
 static void
-imxFreeScreen(int scrnIndex, int flags)
+imxFreeScreen(FREE_SCREEN_ARGS_DECL)
 {
-	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+	SCRN_INFO_PTR(arg);
 
 	imxFreeRec(pScrn);
 }
 
 static Bool
-imxCloseScreen(int scrnIndex, ScreenPtr pScreen)
+imxCloseScreen(CLOSE_SCREEN_ARGS_DECL)
 {
-	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+	CLOSE_SCREEN_DECL_ScrnInfoPtr;
 	ImxPtr fPtr = IMXPTR(pScrn);
 
 	fbdevHWRestore(pScrn);
@@ -453,7 +455,7 @@ imxCloseScreen(int scrnIndex, ScreenPtr pScreen)
 	pScrn->vtSema = FALSE;
 
 	pScreen->CloseScreen = fPtr->saveCloseScreen;
-	return (*pScreen->CloseScreen)(scrnIndex, pScreen);
+	return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);
 }
 
 static int
@@ -488,9 +490,9 @@ LCM(a, b)
 }
 
 static Bool
-imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
+imxScreenInit(SCREEN_INIT_ARGS_DECL)
 {
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 	ImxPtr fPtr = IMXPTR(pScrn);
 	VisualPtr visual;
 	int init_picture = 0;
@@ -514,7 +516,7 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	/* Map frame buffer memory */
 	fPtr->fbMemoryBase = fbdevHWMapVidmem(pScrn);
 	if (NULL == fPtr->fbMemoryBase) {
-	        xf86DrvMsg(scrnIndex,X_ERROR,"mapping of video memory"
+	        xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"mapping of video memory"
 			   " failed\n");
 		return FALSE;
 	}
@@ -558,7 +560,7 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	const int fbOffsetScreen2 =
 		IMX_ALIGN(fbMaxScreenSize, fbMaxAlignOffset);
 	fPtr->fbMemoryScreenReserve = fbMaxScreenSize;
-	xf86DrvMsg(scrnIndex, X_INFO,
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		"reserve %d bytes of frame buffer for screen\n",
 		fPtr->fbMemoryScreenReserve);
 	fPtr->fbMemoryStart2 = NULL;
@@ -568,12 +570,12 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
 		fPtr->fbMemoryScreenReserve += fbOffsetScreen2;
 
-		xf86DrvMsg(scrnIndex, X_INFO,
+		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 			"reserve same number of bytes for XRandR rotated screen at offset %d\n",
 			fbOffsetScreen2);
 	}
 
-	if (!imxDisplayStartScreenInit(scrnIndex, pScreen)) {
+	if (!imxDisplayStartScreenInit(pScrn->scrnIndex, pScreen)) {
 
 		return FALSE;
 	}
@@ -582,7 +584,7 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	miClearVisualTypes();
 	if (pScrn->bitsPerPixel > 8) {
 		if (!miSetVisualTypes(pScrn->depth, TrueColorMask, pScrn->rgbBits, TrueColor)) {
-			xf86DrvMsg(scrnIndex,X_ERROR,"visual type setup failed"
+			xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"visual type setup failed"
 				   " for %d bits per pixel [1]\n",
 				   pScrn->bitsPerPixel);
 			return FALSE;
@@ -591,14 +593,14 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 		if (!miSetVisualTypes(pScrn->depth,
 				      miGetDefaultVisualMask(pScrn->depth),
 				      pScrn->rgbBits, pScrn->defaultVisual)) {
-			xf86DrvMsg(scrnIndex,X_ERROR,"visual type setup failed"
+			xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"visual type setup failed"
 				   " for %d bits per pixel [2]\n",
 				   pScrn->bitsPerPixel);
 			return FALSE;
 		}
 	}
 	if (!miSetPixmapDepths()) {
-	  xf86DrvMsg(scrnIndex,X_ERROR,"pixmap depth setup failed\n");
+	  xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"pixmap depth setup failed\n");
 	  return FALSE;
 	}
 
@@ -607,10 +609,10 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 		has a padding which is independent from the depth (controlfb) */
 	pScrn->displayWidth = fbdevHWGetLineLength(pScrn) /
 			      (pScrn->bitsPerPixel / 8);
-	xf86DrvMsg(scrnIndex, X_INFO, "displayWidth = %d\n", pScrn->displayWidth);
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "displayWidth = %d\n", pScrn->displayWidth);
 
 	if (pScrn->displayWidth != pScrn->virtualX) {
-		xf86DrvMsg(scrnIndex, X_INFO,
+		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 			   "Pitch updated to %d after ModeInit\n",
 			   pScrn->displayWidth);
 	}
@@ -633,7 +635,7 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 			init_picture = 1;
 			break;
 	 	default:
-			xf86DrvMsg(scrnIndex, X_ERROR,
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 				   "internal error: invalid number of bits per"
 				   " pixel (%d) encountered in"
 				   " imxScreenInit()\n", pScrn->bitsPerPixel);
@@ -644,7 +646,7 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	case FBDEVHW_INTERLEAVED_PLANES:
 		/* This should never happen ...
 		* we should check for this much much earlier ... */
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: interleaved planes are not yet "
 			   "supported by the imx driver\n");
 		ret = FALSE;
@@ -652,20 +654,20 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	case FBDEVHW_TEXT:
 		/* This should never happen ...
 		* we should check for this much much earlier ... */
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: text mode is not supported by the "
 			   "imx driver\n");
 		ret = FALSE;
 		break;
 	case FBDEVHW_VGA_PLANES:
 		/* Not supported yet */
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: EGA/VGA Planes are not yet "
 			   "supported by the imx driver\n");
 		ret = FALSE;
 		break;
 	default:
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: unrecognised hardware type (%d) "
 			   "encountered in imxScreenInit()\n", type);
 		ret = FALSE;
@@ -699,7 +701,7 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	/* INIT ACCELERATION BEFORE INIT FOR BACKING STORE & SOFTWARE CURSOR */ 
 	if (fPtr->useAccel) {
 
-		if (!imxExaZ160Setup(scrnIndex, pScreen)) {
+		if (!imxExaZ160Setup(pScrn->scrnIndex, pScreen)) {
 
 			fPtr->useAccel = FALSE;
 		}
@@ -731,29 +733,29 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	/* XXX It would be simpler to use miCreateDefColormap() in all cases. */
 	case FBDEVHW_PACKED_PIXELS:
 		if (!miCreateDefColormap(pScreen)) {
-			xf86DrvMsg(scrnIndex, X_ERROR,
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                                    "internal error: miCreateDefColormap failed "
 				   "in imxScreenInit()\n");
 			return FALSE;
 		}
 		break;
 	case FBDEVHW_INTERLEAVED_PLANES:
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: interleaved planes are not yet "
 			   "supported by the imx driver\n");
 		return FALSE;
 	case FBDEVHW_TEXT:
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: text mode is not supported by "
 			   "the imx driver\n");
 		return FALSE;
 	case FBDEVHW_VGA_PLANES:
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: EGA/VGA planes are not yet "
 			   "supported by the imx driver\n");
 		return FALSE;
 	default:
-		xf86DrvMsg(scrnIndex, X_ERROR,
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		           "internal error: unrecognised imx hardware type "
 			   "(%d) encountered in imxScreenInit()\n", type);
 		return FALSE;
@@ -782,7 +784,7 @@ imxScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	}
 #endif
 
-	if (!imxDisplayFinishScreenInit(scrnIndex, pScreen)) {
+	if (!imxDisplayFinishScreenInit(pScrn->scrnIndex, pScreen)) {
 		return FALSE;
 	}
 
@@ -810,7 +812,7 @@ IMXGetPixmapProperties(
 	}
 
 	/* Access screen associated with this pixmap. */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
 
 	/* Check if the screen associated with this pixmap has IMX driver. */
 	if (0 != strcmp(IMX_DRIVER_NAME, pScrn->driverName)) {
diff --git a/src/imx_exa_offscreen.c b/src/imx_exa_offscreen.c
index 3a5c24d..0fbe2fc 100644
--- a/src/imx_exa_offscreen.c
+++ b/src/imx_exa_offscreen.c
@@ -79,7 +79,7 @@ static void
 imxExaOffscreenValidate (ScreenPtr pScreen)
 {
     /* Access the driver specific data. */
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ImxPtr imxPtr = IMXPTR(pScrn);
     ImxExaPtr imxExaPtr = IMXEXAPTR(imxPtr);
     ExaOffscreenArea *prev = 0, *area;
@@ -135,7 +135,7 @@ imxExaOffscreenMerge (ImxExaPtr imxExaPtr, ExaOffscreenArea *area)
 ExaOffscreenArea *
 imxExaOffscreenFree (ScreenPtr pScreen, ExaOffscreenArea *area)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ImxPtr imxPtr = IMXPTR(pScrn);
     ImxExaPtr imxExaPtr = IMXEXAPTR(imxPtr);
     ExaOffscreenArea	*next = area->next;
@@ -281,7 +281,7 @@ imxExaOffscreenAlloc (ScreenPtr pScreen, int size, int align,
                    pointer privData)
 {
     ExaOffscreenArea *area;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ImxPtr imxPtr = IMXPTR(pScrn);
     ImxExaPtr imxExaPtr = IMXEXAPTR(imxPtr);
     int real_size = 0, largest_avail = 0;
@@ -418,7 +418,7 @@ imxExaOffscreenSwapIn (ScreenPtr pScreen)
 Bool
 imxExaOffscreenInit (ScreenPtr pScreen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ImxPtr imxPtr = IMXPTR(pScrn);
     ImxExaPtr imxExaPtr = IMXEXAPTR(imxPtr);
     ExaOffscreenArea *area;
@@ -453,7 +453,7 @@ imxExaOffscreenInit (ScreenPtr pScreen)
 void
 imxExaOffscreenFini (ScreenPtr pScreen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ImxPtr imxPtr = IMXPTR(pScrn);
     ImxExaPtr imxExaPtr = IMXEXAPTR(imxPtr);
     ExaOffscreenArea *area;
@@ -472,7 +472,7 @@ imxExaOffscreenFini (ScreenPtr pScreen)
 void
 imxExaOffscreenSwapOut (ScreenPtr pScreen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ImxPtr imxPtr = IMXPTR(pScrn);
     ImxExaPtr imxExaPtr = IMXEXAPTR(imxPtr);
 
diff --git a/src/imx_exa_z160.c b/src/imx_exa_z160.c
index fb718e0..3d0bc96 100644
--- a/src/imx_exa_z160.c
+++ b/src/imx_exa_z160.c
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <fcntl.h>
 
+#include "compat-api.h"
 
 /* Set if handles pixmap allocation and migration, i.e, EXA_HANDLES_PIXMAPS */
 #define	IMX_EXA_ENABLE_HANDLES_PIXMAPS	\
@@ -299,7 +300,7 @@ imxExaZ160GetPixmapAddress(PixmapPtr pPixmap)
 	return fPixmapPtr->ptr;
 #else
 	/* Access screen associated with this pixmap. */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -344,7 +345,7 @@ imxExaZ160GetPixmapProperties(
 #else
 
 	/* Access screen associated with this pixmap. */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
 
 	/* Make sure pixmap is in framebuffer */
 	if (!exaDrawableIsOffscreen(&(pPixmap->drawable))) {
@@ -856,7 +857,7 @@ imxExaZ160SyncIfBusyPixmap(PixmapPtr pPixmap)
 {
 	/* Access screen associated with this pixmap. */
 	ScreenPtr pScreen = pPixmap->drawable.pScreen;
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 
 	/* Access driver specific data for screen. */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -924,7 +925,7 @@ imxExaZ160CreatePixmap2(ScreenPtr pScreen, int width, int height,
 	}
 
 	/* Access the driver specific data. */
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 	ImxPtr imxPtr = IMXPTR(pScrn);
 	ImxExaZ160Ptr fPtr = IMXEXAZ160PTR(imxPtr);
 	
@@ -1028,7 +1029,7 @@ imxExaZ160DestroyPixmap(ScreenPtr pScreen, void *driverPriv)
 	ImxExaPixmapPtr fPixmapPtr = (ImxExaPixmapPtr)driverPriv;
 
 	/* Access the driver specific data. */
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 	ImxPtr imxPtr = IMXPTR(pScrn);
 	ImxExaZ160Ptr fPtr = IMXEXAZ160PTR(imxPtr);
 
@@ -1068,7 +1069,7 @@ imxExaZ160ModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
 	}
 
 	/* Access screen associated with this pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1194,7 +1195,7 @@ imxExaZ160TrackBusyPixmap(ImxExaZ160Ptr fPtr, PixmapPtr pPixmap)
 static void
 imxExaZ160WaitMarker(ScreenPtr pScreen, int marker)
 {
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 
 	/* Access driver specific data associated with the screen. */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1249,7 +1250,7 @@ imxExaZ160PrepareSolid(PixmapPtr pPixmap, int alu, Pixel planemask, Pixel fg)
 	}
 
 	/* Access screen associated with this pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1352,7 +1353,7 @@ static void
 imxExaZ160Solid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
 {
 	/* Access screen associated with this pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1423,7 +1424,7 @@ static void
 imxExaZ160DoneSolid(PixmapPtr pPixmap)
 {
 	/* Access screen associated with this pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1485,7 +1486,7 @@ imxExaZ160PrepareCopy(
 	}
 
 	/* Access the screen associated with this pixmap. */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmapDst->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmapDst->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1599,7 +1600,7 @@ static void
 imxExaZ160Copy(PixmapPtr pPixmapDst, int srcX, int srcY, int dstX, int dstY, int width, int height)
 {
 	/* Access screen associated with dst pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmapDst->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmapDst->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1661,7 +1662,7 @@ static void
 imxExaZ160DoneCopy(PixmapPtr pPixmapDst)
 {
 	/* Access screen associated with this pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmapDst->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmapDst->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -1770,7 +1771,7 @@ imxExaZ160CheckComposite(int op, PicturePtr pPictureSrc, PicturePtr pPictureMask
 	}
 
 	/* Access screen associated with dst pixmap (same screen as for src pixmap). */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmapDst->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmapDst->drawable.pScreen);
 
 	/* Check the number of entities, and fail if it isn't one. */
 	if (pScrn->numEntities != 1) {
@@ -1987,7 +1988,7 @@ imxExaZ160PrepareComposite(
 {
 	/* Access screen associated with dst pixmap. */
 	/* Should be same screen as for src pixmap. */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmapDst->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmapDst->drawable.pScreen);
 
 	/* NOTE - many preconditions already verified in CheckComposite. */
 
@@ -2196,7 +2197,7 @@ imxExaZ160Composite(
 	int height)
 {
 	/* Access screen associated with dst pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmapDst->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmapDst->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -2275,7 +2276,7 @@ static void
 imxExaZ160DoneComposite(PixmapPtr pPixmapDst)
 {
 	/* Access screen associated with this pixmap */
-	ScrnInfoPtr pScrn = xf86Screens[pPixmapDst->drawable.pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmapDst->drawable.pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -2323,7 +2324,7 @@ imxExaZ160UploadToScreen(
 
 	/* Access screen associated with this pixmap */
 	ScreenPtr pScreen = pPixmapDst->drawable.pScreen;
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -2381,7 +2382,7 @@ imxExaZ160DownloadFromScreen(
 
 	/* Access screen associated with this pixmap */
 	ScreenPtr pScreen = pPixmapSrc->drawable.pScreen;
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 
 	/* Access driver specific data */
 	ImxPtr imxPtr = IMXPTR(pScrn);
@@ -2412,9 +2413,9 @@ imxExaZ160DownloadFromScreen(
 }
 
 Bool
-imxExaZ160CloseScreen(int scrnIndex, ScreenPtr pScreen)
+imxExaZ160CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 {
-	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+	CLOSE_SCREEN_DECL_ScrnInfoPtr;
 	ImxPtr imxPtr = IMXPTR(pScrn);
 
 	ImxExaZ160Ptr fPtr = IMXEXAZ160PTR(imxPtr);
@@ -2504,7 +2505,7 @@ imxExaZ160CloseScreen(int scrnIndex, ScreenPtr pScreen)
 	/* Install our CloseScreen function so that it gets called. */
 	if (NULL != pScreen->CloseScreen) {
 
-		return (*pScreen->CloseScreen)(scrnIndex, pScreen);
+		return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);
 	}
 
 	return TRUE;
@@ -2514,7 +2515,7 @@ Bool
 imxExaZ160Setup(int scrnIndex, ScreenPtr pScreen)
 {
 	/* Access the screen info and then private data structures. */
-	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 	ImxPtr imxPtr = IMXPTR(pScrn);
 
 	/* Private data structure must not already be in use. */
@@ -2582,7 +2583,7 @@ imxExaZ160Setup(int scrnIndex, ScreenPtr pScreen)
 
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 			"Initialize Z160 interfaces failed.\n");
-		imxExaZ160CloseScreen(scrnIndex, pScreen);
+		imxExaZ160CloseScreen(CLOSE_SCREEN_ARGS);
 		return FALSE;
 	}
 
@@ -2592,7 +2593,7 @@ imxExaZ160Setup(int scrnIndex, ScreenPtr pScreen)
 
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 			"Allocate EXA driver structure.\n");
-		imxExaZ160CloseScreen(scrnIndex, pScreen);
+		imxExaZ160CloseScreen(CLOSE_SCREEN_ARGS);
 		return FALSE;
 	}
 
@@ -2657,7 +2658,7 @@ imxExaZ160Setup(int scrnIndex, ScreenPtr pScreen)
 	if (!exaDriverInit(pScreen, exaDriverPtr)) {
 
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "EXA initialization failed.\n");
-		imxExaZ160CloseScreen(scrnIndex, pScreen);
+		imxExaZ160CloseScreen(CLOSE_SCREEN_ARGS);
 		return FALSE;
 	}
 	fPtr->imxExaRec.exaDriverPtr = exaDriverPtr;
diff --git a/src/imx_xv_ipu.c b/src/imx_xv_ipu.c
index a517742..fc8a827 100644
--- a/src/imx_xv_ipu.c
+++ b/src/imx_xv_ipu.c
@@ -398,7 +398,7 @@ xf86XVFillKeyHelper1 (ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes)
 	xRectangle *rects;
 	GCPtr gc;
 
-	if(!xf86Screens[pScreen->myNum]->vtSema) return;
+	if(!xf86ScreenToScrn(pScreen)->vtSema) return;
 
 	gc = GetScratchGC(root->depth, pScreen);
 	pval[0] = key;
@@ -771,7 +771,7 @@ MXXVInitializeAdaptor
 	XF86VideoAdaptorPtr **pppAdaptor
 )
 {
-	ScreenPtr           pScreen    = screenInfo.screens[pScreenInfo->scrnIndex];
+	ScreenPtr           pScreen    = xf86ScrnToScreen(pScreenInfo);
 	XF86VideoAdaptorPtr *ppAdaptor = NULL;
 	IMXPtr fPtr = IMXPTR(pScreenInfo);
 	int                 nAdaptor;
-- 
1.7.10.4