forked from ssvb/xf86-video-fbturbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbdev.c
1404 lines (1198 loc) · 38.9 KB
/
fbdev.c
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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved.
*
* 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 fur-
* nished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice 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, FIT-
* NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
* NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of the XFree86 Project shall not
* be used in advertising or otherwise to promote the sale, use or other deal-
* ings in this Software without prior written authorization from the XFree86
* Project.
*/
/*
* Authors: Alan Hourihane, <alanh@fairlite.demon.co.uk>
* Michel Dänzer, <michel@tungstengraphics.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
/* all driver need this */
#include "xf86.h"
#include "xf86_OSproc.h"
#include "mipointer.h"
#include "micmap.h"
#include "colormapst.h"
#include "xf86cmap.h"
#include "shadow.h"
#include "dgaproc.h"
#include "cpu_backend.h"
#include "fb_copyarea.h"
#include "sunxi_disp.h"
#include "sunxi_disp_hwcursor.h"
#include "sunxi_x_g2d.h"
#include "backing_store_tuner.h"
#include "sunxi_video.h"
#ifdef HAVE_LIBUMP
#include "sunxi_mali_ump_dri2.h"
#endif
/* for visuals */
#include "fb.h"
#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
#include "xf86Resources.h"
#include "xf86RAC.h"
#endif
#include "fbdevhw.h"
#include "xf86xv.h"
#include "compat-api.h"
#ifdef XSERVER_LIBPCIACCESS
#include <pciaccess.h>
#endif
static Bool debug = 0;
#define TRACE_ENTER(str) \
do { if (debug) ErrorF("fbturbo: " str " %d\n",pScrn->scrnIndex); } while (0)
#define TRACE_EXIT(str) \
do { if (debug) ErrorF("fbturbo: " str " done\n"); } while (0)
#define TRACE(str) \
do { if (debug) ErrorF("fbturbo trace: " str "\n"); } while (0)
/* -------------------------------------------------------------------- */
/* prototypes */
static const OptionInfoRec * FBDevAvailableOptions(int chipid, int busid);
static void FBDevIdentify(int flags);
static Bool FBDevProbe(DriverPtr drv, int flags);
#ifdef XSERVER_LIBPCIACCESS
static Bool FBDevPciProbe(DriverPtr drv, int entity_num,
struct pci_device *dev, intptr_t match_data);
#endif
static Bool FBDevPreInit(ScrnInfoPtr pScrn, int flags);
static Bool FBDevScreenInit(SCREEN_INIT_ARGS_DECL);
static Bool FBDevCloseScreen(CLOSE_SCREEN_ARGS_DECL);
static void * FBDevWindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
CARD32 *size, void *closure);
static void FBDevPointerMoved(SCRN_ARG_TYPE arg, int x, int y);
static Bool FBDevDGAInit(ScrnInfoPtr pScrn, ScreenPtr pScreen);
static Bool FBDevDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
pointer ptr);
enum { FBDEV_ROTATE_NONE=0, FBDEV_ROTATE_CW=270, FBDEV_ROTATE_UD=180, FBDEV_ROTATE_CCW=90 };
/* -------------------------------------------------------------------- */
/*
* This is intentionally screen-independent. It indicates the binding
* choice made in the first PreInit.
*/
static int pix24bpp = 0;
#define FBDEV_VERSION 4000
#define FBDEV_NAME "FBTURBO"
#define FBDEV_DRIVER_NAME "fbturbo"
#ifdef XSERVER_LIBPCIACCESS
static const struct pci_id_match fbdev_device_match[] = {
{
PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
0x00030000, 0x00ffffff, 0
},
{ 0, 0, 0 },
};
#endif
_X_EXPORT DriverRec FBDEV = {
FBDEV_VERSION,
FBDEV_DRIVER_NAME,
#if 0
"driver for linux framebuffer devices",
#endif
FBDevIdentify,
FBDevProbe,
FBDevAvailableOptions,
NULL,
0,
FBDevDriverFunc,
#ifdef XSERVER_LIBPCIACCESS
fbdev_device_match,
FBDevPciProbe
#endif
};
/* Supported "chipsets" */
static SymTabRec FBDevChipsets[] = {
{ 0, "fbturbo" },
{-1, NULL }
};
/* Supported options */
typedef enum {
OPTION_SHADOW_FB,
OPTION_ROTATE,
OPTION_FBDEV,
OPTION_DEBUG,
OPTION_HW_CURSOR,
OPTION_SW_CURSOR,
OPTION_DRI2,
OPTION_DRI2_OVERLAY,
OPTION_SWAPBUFFERS_WAIT,
OPTION_ACCELMETHOD,
OPTION_USE_BS,
OPTION_FORCE_BS,
OPTION_XV_OVERLAY,
} FBDevOpts;
static const OptionInfoRec FBDevOptions[] = {
{ OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_ROTATE, "Rotate", OPTV_STRING, {0}, FALSE },
{ OPTION_FBDEV, "fbdev", OPTV_STRING, {0}, FALSE },
{ OPTION_DEBUG, "debug", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_HW_CURSOR, "HWCursor", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_SW_CURSOR, "SWCursor", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_DRI2, "DRI2", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_DRI2_OVERLAY, "DRI2HWOverlay",OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_SWAPBUFFERS_WAIT,"SwapbuffersWait",OPTV_BOOLEAN,{0}, FALSE },
{ OPTION_ACCELMETHOD, "AccelMethod", OPTV_STRING, {0}, FALSE },
{ OPTION_USE_BS, "UseBackingStore",OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_FORCE_BS, "ForceBackingStore",OPTV_BOOLEAN,{0}, FALSE },
{ OPTION_XV_OVERLAY, "XVHWOverlay", OPTV_BOOLEAN, {0}, FALSE },
{ -1, NULL, OPTV_NONE, {0}, FALSE }
};
/* -------------------------------------------------------------------- */
#ifdef XFree86LOADER
MODULESETUPPROTO(FBDevSetup);
static XF86ModuleVersionInfo FBDevVersRec =
{
"fbturbo",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XORG_VERSION_CURRENT,
PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
ABI_CLASS_VIDEODRV,
ABI_VIDEODRV_VERSION,
MOD_CLASS_VIDEODRV,
{0,0,0,0}
};
_X_EXPORT XF86ModuleData fbturboModuleData = { &FBDevVersRec, FBDevSetup, NULL };
pointer
FBDevSetup(pointer module, pointer opts, int *errmaj, int *errmin)
{
static Bool setupDone = FALSE;
if (!setupDone) {
setupDone = TRUE;
xf86AddDriver(&FBDEV, module, HaveDriverFuncs);
return (pointer)1;
} else {
if (errmaj) *errmaj = LDR_ONCEONLY;
return NULL;
}
}
#endif /* XFree86LOADER */
/* -------------------------------------------------------------------- */
/* our private data, and two functions to allocate/free this */
#include "fbdev_priv.h"
static Bool
FBDevGetRec(ScrnInfoPtr pScrn)
{
if (pScrn->driverPrivate != NULL)
return TRUE;
pScrn->driverPrivate = xnfcalloc(sizeof(FBDevRec), 1);
return TRUE;
}
static void
FBDevFreeRec(ScrnInfoPtr pScrn)
{
if (pScrn->driverPrivate == NULL)
return;
free(pScrn->driverPrivate);
pScrn->driverPrivate = NULL;
}
/* -------------------------------------------------------------------- */
static const OptionInfoRec *
FBDevAvailableOptions(int chipid, int busid)
{
return FBDevOptions;
}
static void
FBDevIdentify(int flags)
{
xf86PrintChipsets(FBDEV_NAME, "driver for framebuffer", FBDevChipsets);
}
#ifdef XSERVER_LIBPCIACCESS
static Bool FBDevPciProbe(DriverPtr drv, int entity_num,
struct pci_device *dev, intptr_t match_data)
{
ScrnInfoPtr pScrn = NULL;
if (!xf86LoadDrvSubModule(drv, "fbdevhw"))
return FALSE;
pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, NULL, NULL,
NULL, NULL, NULL, NULL);
if (pScrn) {
char *device;
GDevPtr devSection = xf86GetDevFromEntity(pScrn->entityList[0],
pScrn->entityInstanceList[0]);
device = xf86FindOptionValue(devSection->options, "fbdev");
if (fbdevHWProbe(NULL, device, NULL)) {
pScrn->driverVersion = FBDEV_VERSION;
pScrn->driverName = FBDEV_DRIVER_NAME;
pScrn->name = FBDEV_NAME;
pScrn->Probe = FBDevProbe;
pScrn->PreInit = FBDevPreInit;
pScrn->ScreenInit = FBDevScreenInit;
pScrn->SwitchMode = fbdevHWSwitchModeWeak();
pScrn->AdjustFrame = fbdevHWAdjustFrameWeak();
pScrn->EnterVT = fbdevHWEnterVTWeak();
pScrn->LeaveVT = fbdevHWLeaveVTWeak();
pScrn->ValidMode = fbdevHWValidModeWeak();
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
"claimed PCI slot %d@%d:%d:%d\n",
dev->bus, dev->domain, dev->dev, dev->func);
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"using %s\n", device ? device : "default device");
}
else {
pScrn = NULL;
}
}
return (pScrn != NULL);
}
#endif
static Bool
FBDevProbe(DriverPtr drv, int flags)
{
int i;
ScrnInfoPtr pScrn;
GDevPtr *devSections;
int numDevSections;
#ifndef XSERVER_LIBPCIACCESS
int bus,device,func;
#endif
char *dev;
Bool foundScreen = FALSE;
TRACE("probe start");
/* For now, just bail out for PROBE_DETECT. */
if (flags & PROBE_DETECT)
return FALSE;
if ((numDevSections = xf86MatchDevice(FBDEV_DRIVER_NAME, &devSections)) <= 0)
return FALSE;
if (!xf86LoadDrvSubModule(drv, "fbdevhw"))
return FALSE;
for (i = 0; i < numDevSections; i++) {
Bool isIsa = FALSE;
Bool isPci = FALSE;
dev = xf86FindOptionValue(devSections[i]->options,"fbdev");
if (devSections[i]->busID) {
#ifndef XSERVER_LIBPCIACCESS
if (xf86ParsePciBusString(devSections[i]->busID,&bus,&device,
&func)) {
if (!xf86CheckPciSlot(bus,device,func))
continue;
isPci = TRUE;
} else
#endif
#ifdef HAVE_ISA
if (xf86ParseIsaBusString(devSections[i]->busID))
isIsa = TRUE;
else
#endif
0;
}
if (fbdevHWProbe(NULL,dev,NULL)) {
pScrn = NULL;
if (isPci) {
#ifndef XSERVER_LIBPCIACCESS
/* XXX what about when there's no busID set? */
int entity;
entity = xf86ClaimPciSlot(bus,device,func,drv,
0,devSections[i],
TRUE);
pScrn = xf86ConfigPciEntity(pScrn,0,entity,
NULL,RES_SHARED_VGA,
NULL,NULL,NULL,NULL);
/* xf86DrvMsg() can't be called without setting these */
pScrn->driverName = FBDEV_DRIVER_NAME;
pScrn->name = FBDEV_NAME;
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
"claimed PCI slot %d:%d:%d\n",bus,device,func);
#endif
} else if (isIsa) {
#ifdef HAVE_ISA
int entity;
entity = xf86ClaimIsaSlot(drv, 0,
devSections[i], TRUE);
pScrn = xf86ConfigIsaEntity(pScrn,0,entity,
NULL,RES_SHARED_VGA,
NULL,NULL,NULL,NULL);
#endif
} else {
int entity;
entity = xf86ClaimFbSlot(drv, 0,
devSections[i], TRUE);
pScrn = xf86ConfigFbEntity(pScrn,0,entity,
NULL,NULL,NULL,NULL);
}
if (pScrn) {
foundScreen = TRUE;
pScrn->driverVersion = FBDEV_VERSION;
pScrn->driverName = FBDEV_DRIVER_NAME;
pScrn->name = FBDEV_NAME;
pScrn->Probe = FBDevProbe;
pScrn->PreInit = FBDevPreInit;
pScrn->ScreenInit = FBDevScreenInit;
pScrn->SwitchMode = fbdevHWSwitchModeWeak();
pScrn->AdjustFrame = fbdevHWAdjustFrameWeak();
pScrn->EnterVT = fbdevHWEnterVTWeak();
pScrn->LeaveVT = fbdevHWLeaveVTWeak();
pScrn->ValidMode = fbdevHWValidModeWeak();
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"using %s\n", dev ? dev : "default device");
}
}
}
free(devSections);
TRACE("probe done");
return foundScreen;
}
static Bool
FBDevPreInit(ScrnInfoPtr pScrn, int flags)
{
FBDevPtr fPtr;
int default_depth, fbbpp;
const char *s;
int type;
cpuinfo_t *cpuinfo;
if (flags & PROBE_DETECT) return FALSE;
TRACE_ENTER("PreInit");
/* Check the number of entities, and fail if it isn't one. */
if (pScrn->numEntities != 1)
return FALSE;
pScrn->monitor = pScrn->confScreen->monitor;
FBDevGetRec(pScrn);
fPtr = FBDEVPTR(pScrn);
fPtr->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
#ifndef XSERVER_LIBPCIACCESS
pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
/* XXX Is this right? Can probably remove RAC_FB */
pScrn->racIoFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
if (fPtr->pEnt->location.type == BUS_PCI &&
xf86RegisterResources(fPtr->pEnt->index,NULL,ResExclusive)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"xf86RegisterResources() found resource conflicts\n");
return FALSE;
}
#endif
/* open device */
if (!fbdevHWInit(pScrn,NULL,xf86FindOptionValue(fPtr->pEnt->device->options,"fbdev")))
return FALSE;
default_depth = fbdevHWGetDepth(pScrn,&fbbpp);
if (!xf86SetDepthBpp(pScrn, default_depth, default_depth, fbbpp,
Support24bppFb | Support32bppFb | SupportConvert32to24 | SupportConvert24to32))
return FALSE;
xf86PrintDepthBpp(pScrn);
/* Get the depth24 pixmap format */
if (pScrn->depth == 24 && pix24bpp == 0)
pix24bpp = xf86GetBppFromDepth(pScrn, 24);
/* color weight */
if (pScrn->depth > 8) {
rgb zeros = { 0, 0, 0 };
if (!xf86SetWeight(pScrn, zeros, zeros))
return FALSE;
}
/* visual init */
if (!xf86SetDefaultVisual(pScrn, -1))
return FALSE;
/* We don't currently support DirectColor at > 8bpp */
if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "requested default visual"
" (%s) is not supported at depth %d\n",
xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
return FALSE;
}
{
Gamma zeros = {0.0, 0.0, 0.0};
if (!xf86SetGamma(pScrn,zeros)) {
return FALSE;
}
}
pScrn->progClock = TRUE;
pScrn->rgbBits = 8;
pScrn->chipset = "fbturbo";
pScrn->videoRam = fbdevHWGetVidmem(pScrn);
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "hardware: %s (video memory:"
" %dkB)\n", fbdevHWGetName(pScrn), pScrn->videoRam/1024);
/* handle options */
xf86CollectOptions(pScrn, NULL);
if (!(fPtr->Options = malloc(sizeof(FBDevOptions))))
return FALSE;
memcpy(fPtr->Options, FBDevOptions, sizeof(FBDevOptions));
xf86ProcessOptions(pScrn->scrnIndex, fPtr->pEnt->device->options, fPtr->Options);
/* check the processor type */
cpuinfo = cpuinfo_init();
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "processor: %s\n",
cpuinfo->processor_name);
/* don't use shadow by default if we have VFP/NEON or HW acceleration */
fPtr->shadowFB = !cpuinfo->has_arm_vfp &&
!xf86GetOptValString(fPtr->Options, OPTION_ACCELMETHOD);
cpuinfo_close(cpuinfo);
/* but still honour the settings from xorg.conf */
fPtr->shadowFB = xf86ReturnOptValBool(fPtr->Options, OPTION_SHADOW_FB,
fPtr->shadowFB);
debug = xf86ReturnOptValBool(fPtr->Options, OPTION_DEBUG, FALSE);
/* rotation */
fPtr->rotate = FBDEV_ROTATE_NONE;
if ((s = xf86GetOptValString(fPtr->Options, OPTION_ROTATE)))
{
if(!xf86NameCmp(s, "CW"))
{
fPtr->shadowFB = TRUE;
fPtr->rotate = FBDEV_ROTATE_CW;
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
"rotating screen clockwise\n");
}
else if(!xf86NameCmp(s, "CCW"))
{
fPtr->shadowFB = TRUE;
fPtr->rotate = FBDEV_ROTATE_CCW;
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
"rotating screen counter-clockwise\n");
}
else if(!xf86NameCmp(s, "UD"))
{
fPtr->shadowFB = TRUE;
fPtr->rotate = FBDEV_ROTATE_UD;
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
"rotating screen upside-down\n");
}
else
{
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
"\"%s\" is not a valid value for Option \"Rotate\"\n", s);
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"valid options are \"CW\", \"CCW\" and \"UD\"\n");
}
}
/* select video modes */
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "checking modes against framebuffer device...\n");
fbdevHWSetVideoModes(pScrn);
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "checking modes against monitor...\n");
{
DisplayModePtr mode, first = mode = pScrn->modes;
if (mode != NULL) do {
mode->status = xf86CheckModeForMonitor(mode, pScrn->monitor);
mode = mode->next;
} while (mode != NULL && mode != first);
xf86PruneDriverModes(pScrn);
}
if (NULL == pScrn->modes)
fbdevHWUseBuildinMode(pScrn);
pScrn->currentMode = pScrn->modes;
/* First approximation, may be refined in ScreenInit */
pScrn->displayWidth = pScrn->virtualX;
xf86PrintModes(pScrn);
/* Set display resolution */
xf86SetDpi(pScrn, 0, 0);
/* Load bpp-specific modules */
switch ((type = fbdevHWGetType(pScrn)))
{
case FBDEVHW_PACKED_PIXELS:
switch (pScrn->bitsPerPixel)
{
case 8:
case 16:
case 24:
case 32:
break;
default:
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"unsupported number of bits per pixel: %d",
pScrn->bitsPerPixel);
return FALSE;
}
break;
case FBDEVHW_INTERLEAVED_PLANES:
/* Not supported yet, don't know what to do with this */
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"interleaved planes are not yet supported by the "
"fbdev driver\n");
return FALSE;
case FBDEVHW_TEXT:
/* This should never happen ...
* we should check for this much much earlier ... */
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"text mode is not supported by the fbdev driver\n");
return FALSE;
case FBDEVHW_VGA_PLANES:
/* Not supported yet */
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"EGA/VGA planes are not yet supported by the fbdev "
"driver\n");
return FALSE;
default:
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"unrecognised fbdev hardware type (%d)\n", type);
return FALSE;
}
if (xf86LoadSubModule(pScrn, "fb") == NULL) {
FBDevFreeRec(pScrn);
return FALSE;
}
/* Load shadow if needed */
if (fPtr->shadowFB) {
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "using shadow"
" framebuffer\n");
if (!xf86LoadSubModule(pScrn, "shadow")) {
FBDevFreeRec(pScrn);
return FALSE;
}
}
TRACE_EXIT("PreInit");
return TRUE;
}
static Bool
FBDevCreateScreenResources(ScreenPtr pScreen)
{
PixmapPtr pPixmap;
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
FBDevPtr fPtr = FBDEVPTR(pScrn);
Bool ret;
pScreen->CreateScreenResources = fPtr->CreateScreenResources;
ret = pScreen->CreateScreenResources(pScreen);
pScreen->CreateScreenResources = FBDevCreateScreenResources;
if (!ret)
return FALSE;
pPixmap = pScreen->GetScreenPixmap(pScreen);
if (!shadowAdd(pScreen, pPixmap, fPtr->rotate ?
shadowUpdateRotatePackedWeak() : shadowUpdatePackedWeak(),
FBDevWindowLinear, fPtr->rotate, NULL)) {
return FALSE;
}
return TRUE;
}
static Bool
FBDevShadowInit(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
FBDevPtr fPtr = FBDEVPTR(pScrn);
if (!shadowSetup(pScreen)) {
return FALSE;
}
fPtr->CreateScreenResources = pScreen->CreateScreenResources;
pScreen->CreateScreenResources = FBDevCreateScreenResources;
return TRUE;
}
static Bool
FBDevScreenInit(SCREEN_INIT_ARGS_DECL)
{
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
FBDevPtr fPtr = FBDEVPTR(pScrn);
VisualPtr visual;
int init_picture = 0;
int ret, flags;
int type;
char *accelmethod;
cpu_backend_t *cpu_backend;
Bool useBackingStore = FALSE, forceBackingStore = FALSE;
TRACE_ENTER("FBDevScreenInit");
#if DEBUG
ErrorF("\tbitsPerPixel=%d, depth=%d, defaultVisual=%s\n"
"\tmask: %x,%x,%x, offset: %d,%d,%d\n",
pScrn->bitsPerPixel,
pScrn->depth,
xf86GetVisualName(pScrn->defaultVisual),
pScrn->mask.red,pScrn->mask.green,pScrn->mask.blue,
pScrn->offset.red,pScrn->offset.green,pScrn->offset.blue);
#endif
if (NULL == (fPtr->fbmem = fbdevHWMapVidmem(pScrn))) {
xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"mapping of video memory"
" failed\n");
return FALSE;
}
fPtr->fboff = fbdevHWLinearOffset(pScrn);
fbdevHWSave(pScrn);
if (!fbdevHWModeInit(pScrn, pScrn->currentMode)) {
xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"mode initialization failed\n");
return FALSE;
}
fbdevHWSaveScreen(pScreen, SCREEN_SAVER_ON);
fbdevHWAdjustFrame(ADJUST_FRAME_ARGS(pScrn, 0, 0));
/* mi layer */
miClearVisualTypes();
if (pScrn->bitsPerPixel > 8) {
if (!miSetVisualTypes(pScrn->depth, TrueColorMask, pScrn->rgbBits, TrueColor)) {
xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"visual type setup failed"
" for %d bits per pixel [1]\n",
pScrn->bitsPerPixel);
return FALSE;
}
} else {
if (!miSetVisualTypes(pScrn->depth,
miGetDefaultVisualMask(pScrn->depth),
pScrn->rgbBits, pScrn->defaultVisual)) {
xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"visual type setup failed"
" for %d bits per pixel [2]\n",
pScrn->bitsPerPixel);
return FALSE;
}
}
if (!miSetPixmapDepths()) {
xf86DrvMsg(pScrn->scrnIndex,X_ERROR,"pixmap depth setup failed\n");
return FALSE;
}
if(fPtr->rotate==FBDEV_ROTATE_CW || fPtr->rotate==FBDEV_ROTATE_CCW)
{
int tmp = pScrn->virtualX;
pScrn->virtualX = pScrn->displayWidth = pScrn->virtualY;
pScrn->virtualY = tmp;
} else if (!fPtr->shadowFB) {
/* FIXME: this doesn't work for all cases, e.g. when each scanline
has a padding which is independent from the depth (controlfb) */
pScrn->displayWidth = fbdevHWGetLineLength(pScrn) /
(pScrn->bitsPerPixel / 8);
if (pScrn->displayWidth != pScrn->virtualX) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"Pitch updated to %d after ModeInit\n",
pScrn->displayWidth);
}
}
if(fPtr->rotate && !fPtr->PointerMoved) {
fPtr->PointerMoved = pScrn->PointerMoved;
pScrn->PointerMoved = FBDevPointerMoved;
}
fPtr->fbstart = fPtr->fbmem + fPtr->fboff;
if (fPtr->shadowFB) {
fPtr->shadow = calloc(1, pScrn->virtualX * pScrn->virtualY *
pScrn->bitsPerPixel);
if (!fPtr->shadow) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"Failed to allocate shadow framebuffer\n");
return FALSE;
}
}
switch ((type = fbdevHWGetType(pScrn)))
{
case FBDEVHW_PACKED_PIXELS:
switch (pScrn->bitsPerPixel) {
case 8:
case 16:
case 24:
case 32:
ret = fbScreenInit(pScreen, fPtr->shadowFB ? fPtr->shadow
: fPtr->fbstart, pScrn->virtualX,
pScrn->virtualY, pScrn->xDpi,
pScrn->yDpi, pScrn->displayWidth,
pScrn->bitsPerPixel);
init_picture = 1;
break;
default:
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"internal error: invalid number of bits per"
" pixel (%d) encountered in"
" FBDevScreenInit()\n", pScrn->bitsPerPixel);
ret = FALSE;
break;
}
break;
case FBDEVHW_INTERLEAVED_PLANES:
/* This should never happen ...
* we should check for this much much earlier ... */
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"internal error: interleaved planes are not yet "
"supported by the fbdev driver\n");
ret = FALSE;
break;
case FBDEVHW_TEXT:
/* This should never happen ...
* we should check for this much much earlier ... */
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"internal error: text mode is not supported by the "
"fbdev driver\n");
ret = FALSE;
break;
case FBDEVHW_VGA_PLANES:
/* Not supported yet */
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"internal error: EGA/VGA Planes are not yet "
"supported by the fbdev driver\n");
ret = FALSE;
break;
default:
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"internal error: unrecognised hardware type (%d) "
"encountered in FBDevScreenInit()\n", type);
ret = FALSE;
break;
}
if (!ret)
return FALSE;
if (pScrn->bitsPerPixel > 8) {
/* Fixup RGB ordering */
visual = pScreen->visuals + pScreen->numVisuals;
while (--visual >= pScreen->visuals) {
if ((visual->class | DynamicClass) == DirectColor) {
visual->offsetRed = pScrn->offset.red;
visual->offsetGreen = pScrn->offset.green;
visual->offsetBlue = pScrn->offset.blue;
visual->redMask = pScrn->mask.red;
visual->greenMask = pScrn->mask.green;
visual->blueMask = pScrn->mask.blue;
}
}
}
/* must be after RGB ordering fixed */
if (init_picture && !fbPictureInit(pScreen, NULL, 0))
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Render extension initialisation failed\n");
/*
* by default make use of backing store (the driver decides for which
* windows it is beneficial) if shadow is not enabled.
*/
useBackingStore = xf86ReturnOptValBool(fPtr->Options, OPTION_USE_BS,
!fPtr->shadowFB);
#ifndef __arm__
/*
* right now we can only make "smart" decisions on ARM hardware,
* everything else (for example x86) would take a performance hit
* unless backing store is just used for all windows.
*/
forceBackingStore = useBackingStore;
#endif
/* but still honour the settings from xorg.conf */
forceBackingStore = xf86ReturnOptValBool(fPtr->Options, OPTION_FORCE_BS,
forceBackingStore);
if (useBackingStore || forceBackingStore) {
fPtr->backing_store_tuner_private =
BackingStoreTuner_Init(pScreen, forceBackingStore);
}
/* initialize the 'CPU' backend */
cpu_backend = cpu_backend_init(fPtr->fbmem, pScrn->videoRam);
fPtr->cpu_backend_private = cpu_backend;
/* try to load G2D kernel module before initializing sunxi-disp */
if (!xf86LoadKernelModule("g2d_23"))
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"can't load 'g2d_23' kernel module\n");
fPtr->sunxi_disp_private = sunxi_disp_init(xf86FindOptionValue(
fPtr->pEnt->device->options,"fbdev"),
fPtr->fbmem);
if (!fPtr->sunxi_disp_private) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"failed to enable the use of sunxi display controller\n");
fPtr->fb_copyarea_private = fb_copyarea_init(xf86FindOptionValue(
fPtr->pEnt->device->options,"fbdev"),
fPtr->fbmem);
}
if (!(accelmethod = xf86GetOptValString(fPtr->Options, OPTION_ACCELMETHOD)) ||
strcasecmp(accelmethod, "g2d") == 0) {
sunxi_disp_t *disp = fPtr->sunxi_disp_private;
if (disp && disp->fd_g2d >= 0 &&
(fPtr->SunxiG2D_private = SunxiG2D_Init(pScreen, &disp->blt2d))) {
disp->fallback_blt2d = &cpu_backend->blt2d;
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "enabled G2D acceleration\n");
}
else {
xf86DrvMsg(pScreen->myNum, X_INFO,
"No sunxi-g2d hardware detected (check /dev/disp and /dev/g2d)\n");
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"G2D hardware acceleration can't be enabled\n");
}
}
else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"G2D acceleration is disabled via AccelMethod option\n");
}
if (!fPtr->SunxiG2D_private && fPtr->fb_copyarea_private) {
if (!(accelmethod = xf86GetOptValString(fPtr->Options, OPTION_ACCELMETHOD)) ||
strcasecmp(accelmethod, "copyarea") == 0) {
fb_copyarea_t *fb = fPtr->fb_copyarea_private;
if ((fPtr->SunxiG2D_private = SunxiG2D_Init(pScreen, &fb->blt2d))) {
fb->fallback_blt2d = &cpu_backend->blt2d;
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"enabled fbdev copyarea acceleration\n");
}
else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"failed to enable fbdev copyarea acceleration\n");
}
}
else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"fbdev copyarea acceleration is disabled via AccelMethod option\n");
}
}
if (!fPtr->SunxiG2D_private && cpu_backend->cpuinfo->has_arm_vfp) {
if ((fPtr->SunxiG2D_private = SunxiG2D_Init(pScreen, &cpu_backend->blt2d))) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "enabled VFP/NEON optimizations\n");
}
}
if (fPtr->shadowFB && !FBDevShadowInit(pScreen)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"shadow framebuffer initialization failed\n");
return FALSE;
}
if (!fPtr->rotate)
FBDevDGAInit(pScrn, pScreen);
else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "display rotated; disabling DGA\n");
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "using driver rotation; disabling "
"XRandR\n");
xf86DisableRandR();
if (pScrn->bitsPerPixel == 24)
xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "rotation might be broken at 24 "
"bits per pixel\n");
}
xf86SetBlackWhitePixels(pScreen);
xf86SetBackingStore(pScreen);
/* software cursor */
miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
/* colormap */
switch ((type = fbdevHWGetType(pScrn)))
{
/* XXX It would be simpler to use miCreateDefColormap() in all cases. */
case FBDEVHW_PACKED_PIXELS:
if (!miCreateDefColormap(pScreen)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,