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
|
/*
* Leo (ZX) framebuffer driver.
*
* Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
*
* 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 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
* JAKUB JELINEK 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.
*/
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sunleo/leo_driver.c,v 1.8 2001/10/01 13:44:10 eich Exp $ */
#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "xf86Version.h"
#include "mipointer.h"
#include "mibstore.h"
#include "micmap.h"
#define PSZ 32
#include "cfb.h"
#undef PSZ
#include "xf86cmap.h"
#include "leo.h"
static const OptionInfoRec * LeoAvailableOptions(int chipid, int busid);
static void LeoIdentify(int flags);
static Bool LeoProbe(DriverPtr drv, int flags);
static Bool LeoPreInit(ScrnInfoPtr pScrn, int flags);
static Bool LeoScreenInit(int Index, ScreenPtr pScreen, int argc,
char **argv);
static Bool LeoEnterVT(int scrnIndex, int flags);
static void LeoLeaveVT(int scrnIndex, int flags);
static Bool LeoCloseScreen(int scrnIndex, ScreenPtr pScreen);
static Bool LeoSaveScreen(ScreenPtr pScreen, int mode);
/* Required if the driver supports mode switching */
static Bool LeoSwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
/* Required if the driver supports moving the viewport */
static void LeoAdjustFrame(int scrnIndex, int x, int y, int flags);
/* Optional functions */
static void LeoFreeScreen(int scrnIndex, int flags);
static ModeStatus LeoValidMode(int scrnIndex, DisplayModePtr mode,
Bool verbose, int flags);
void LeoSync(ScrnInfoPtr pScrn);
#define VERSION 4000
#define LEO_NAME "SUNLEO"
#define LEO_DRIVER_NAME "sunleo"
#define LEO_MAJOR_VERSION 1
#define LEO_MINOR_VERSION 0
#define LEO_PATCHLEVEL 0
/*
* This contains the functions needed by the server after loading the driver
* module. It must be supplied, and gets passed back by the SetupProc
* function in the dynamic case. In the static case, a reference to this
* is compiled in, and this requires that the name of this DriverRec be
* an upper-case version of the driver name.
*/
DriverRec SUNLEO = {
VERSION,
LEO_DRIVER_NAME,
LeoIdentify,
LeoProbe,
LeoAvailableOptions,
NULL,
0
};
typedef enum {
OPTION_SW_CURSOR,
OPTION_HW_CURSOR,
OPTION_NOACCEL
} LeoOpts;
static const OptionInfoRec LeoOptions[] = {
{ OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE },
{ -1, NULL, OPTV_NONE, {0}, FALSE }
};
#ifdef XFree86LOADER
static MODULESETUPPROTO(leoSetup);
static XF86ModuleVersionInfo sunleoVersRec =
{
"sunleo",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XF86_VERSION_CURRENT,
LEO_MAJOR_VERSION, LEO_MINOR_VERSION, LEO_PATCHLEVEL,
ABI_CLASS_VIDEODRV,
ABI_VIDEODRV_VERSION,
MOD_CLASS_VIDEODRV,
{0,0,0,0}
};
XF86ModuleData sunleoModuleData = { &sunleoVersRec, leoSetup, NULL };
pointer
leoSetup(pointer module, pointer opts, int *errmaj, int *errmin)
{
static Bool setupDone = FALSE;
if (!setupDone) {
setupDone = TRUE;
xf86AddDriver(&SUNLEO, module, 0);
/*
* Modules that this driver always requires can be loaded here
* by calling LoadSubModule().
*/
/*
* The return value must be non-NULL on success even though there
* is no TearDownProc.
*/
return (pointer)TRUE;
} else {
if (errmaj) *errmaj = LDR_ONCEONLY;
return NULL;
}
}
#endif /* XFree86LOADER */
static Bool
LeoGetRec(ScrnInfoPtr pScrn)
{
/*
* Allocate an LeoRec, and hook it into pScrn->driverPrivate.
* pScrn->driverPrivate is initialised to NULL, so we can check if
* the allocation has already been done.
*/
if (pScrn->driverPrivate != NULL)
return TRUE;
pScrn->driverPrivate = xnfcalloc(sizeof(LeoRec), 1);
return TRUE;
}
static void
LeoFreeRec(ScrnInfoPtr pScrn)
{
LeoPtr pLeo;
if (pScrn->driverPrivate == NULL)
return;
pLeo = GET_LEO_FROM_SCRN(pScrn);
xfree(pScrn->driverPrivate);
pScrn->driverPrivate = NULL;
return;
}
static const OptionInfoRec *
LeoAvailableOptions(int chipid, int busid)
{
return LeoOptions;
}
/* Mandatory */
static void
LeoIdentify(int flags)
{
xf86Msg(X_INFO, "%s: driver for Leo (ZX)\n", LEO_NAME);
}
/* Mandatory */
static Bool
LeoProbe(DriverPtr drv, int flags)
{
int i;
GDevPtr *devSections;
int *usedChips;
int numDevSections;
int numUsed;
Bool foundScreen = FALSE;
EntityInfoPtr pEnt;
/*
* The aim here is to find all cards that this driver can handle,
* and for the ones not already claimed by another driver, claim the
* slot, and allocate a ScrnInfoRec.
*
* This should be a minimal probe, and it should under no circumstances
* change the state of the hardware. Because a device is found, don't
* assume that it will be used. Don't do any initialisations other than
* the required ScrnInfoRec initialisations. Don't allocate any new
* data structures.
*/
/*
* Next we check, if there has been a chipset override in the config file.
* For this we must find out if there is an active device section which
* is relevant, i.e., which has no driver specified or has THIS driver
* specified.
*/
if ((numDevSections = xf86MatchDevice(LEO_DRIVER_NAME,
&devSections)) <= 0) {
/*
* There's no matching device section in the config file, so quit
* now.
*/
return FALSE;
}
/*
* We need to probe the hardware first. We then need to see how this
* fits in with what is given in the config file, and allow the config
* file info to override any contradictions.
*/
numUsed = xf86MatchSbusInstances(LEO_NAME, SBUS_DEVICE_LEO,
devSections, numDevSections,
drv, &usedChips);
xfree(devSections);
if (numUsed <= 0)
return FALSE;
if (flags & PROBE_DETECT)
foundScreen = TRUE;
else for (i = 0; i < numUsed; i++) {
pEnt = xf86GetEntityInfo(usedChips[i]);
/*
* Check that nothing else has claimed the slots.
*/
if(pEnt->active) {
ScrnInfoPtr pScrn;
/* Allocate a ScrnInfoRec and claim the slot */
pScrn = xf86AllocateScreen(drv, 0);
/* Fill in what we can of the ScrnInfoRec */
pScrn->driverVersion = VERSION;
pScrn->driverName = LEO_DRIVER_NAME;
pScrn->name = LEO_NAME;
pScrn->Probe = LeoProbe;
pScrn->PreInit = LeoPreInit;
pScrn->ScreenInit = LeoScreenInit;
pScrn->SwitchMode = LeoSwitchMode;
pScrn->AdjustFrame = LeoAdjustFrame;
pScrn->EnterVT = LeoEnterVT;
pScrn->LeaveVT = LeoLeaveVT;
pScrn->FreeScreen = LeoFreeScreen;
pScrn->ValidMode = LeoValidMode;
xf86AddEntityToScreen(pScrn, pEnt->index);
foundScreen = TRUE;
}
xfree(pEnt);
}
xfree(usedChips);
return foundScreen;
}
/* Mandatory */
static Bool
LeoPreInit(ScrnInfoPtr pScrn, int flags)
{
LeoPtr pLeo;
sbusDevicePtr psdp;
MessageType from;
int i;
if (flags & PROBE_DETECT) return FALSE;
/*
* Note: This function is only called once at server startup, and
* not at the start of each server generation. This means that
* only things that are persistent across server generations can
* be initialised here. xf86Screens[] is (pScrn is a pointer to one
* of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex()
* are too, and should be used for data that must persist across
* server generations.
*
* Per-generation data should be allocated with
* AllocateScreenPrivateIndex() from the ScreenInit() function.
*/
/* Allocate the LeoRec driverPrivate */
if (!LeoGetRec(pScrn)) {
return FALSE;
}
pLeo = GET_LEO_FROM_SCRN(pScrn);
/* Set pScrn->monitor */
pScrn->monitor = pScrn->confScreen->monitor;
/* This driver doesn't expect more than one entity per screen */
if (pScrn->numEntities > 1)
return FALSE;
/* This is the general case */
for (i = 0; i < pScrn->numEntities; i++) {
EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[i]);
/* LEO is purely SBUS */
if (pEnt->location.type == BUS_SBUS) {
psdp = xf86GetSbusInfoForEntity(pEnt->index);
pLeo->psdp = psdp;
} else
return FALSE;
}
/*********************
deal with depth
*********************/
if (!xf86SetDepthBpp(pScrn, 32, 0, 32, Support32bppFb)) {
return FALSE;
} else {
/* Check that the returned depth is one we support */
switch (pScrn->depth) {
case 32:
/* OK */
break;
default:
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"Given depth (%d) is not supported by this driver\n",
pScrn->depth);
return FALSE;
}
}
/* Collect all of the relevant option flags (fill in pScrn->options) */
xf86CollectOptions(pScrn, NULL);
/* Process the options */
if (!(pLeo->Options = xalloc(sizeof(LeoOptions))))
return FALSE;
memcpy(pLeo->Options, LeoOptions, sizeof(LeoOptions));
xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pLeo->Options);
/*
* This must happen after pScrn->display has been set because
* xf86SetWeight references it.
*/
if (pScrn->depth > 8) {
rgb weight = {10, 11, 11};
rgb mask = {0xff, 0xff00, 0xff0000};
if (!xf86SetWeight(pScrn, weight, mask)) {
return FALSE;
}
}
if (!xf86SetDefaultVisual(pScrn, -1)) {
return FALSE;
} else {
/* We don't currently support DirectColor */
if (pScrn->defaultVisual != TrueColor) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
" (%s) is not supported\n",
xf86GetVisualName(pScrn->defaultVisual));
return FALSE;
}
}
/*
* The new cmap code requires this to be initialised.
*/
{
Gamma zeros = {0.0, 0.0, 0.0};
if (!xf86SetGamma(pScrn, zeros)) {
return FALSE;
}
}
/* Set the bits per RGB for 8bpp mode */
from = X_DEFAULT;
/* determine whether we use hardware or software cursor */
pLeo->HWCursor = TRUE;
if (xf86GetOptValBool(pLeo->Options, OPTION_HW_CURSOR, &pLeo->HWCursor))
from = X_CONFIG;
if (xf86ReturnOptValBool(pLeo->Options, OPTION_SW_CURSOR, FALSE)) {
from = X_CONFIG;
pLeo->HWCursor = FALSE;
}
xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
pLeo->HWCursor ? "HW" : "SW");
if (xf86ReturnOptValBool(pLeo->Options, OPTION_NOACCEL, FALSE)) {
pLeo->NoAccel = TRUE;
xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
}
if (xf86LoadSubModule(pScrn, "cfb32") == NULL) {
LeoFreeRec(pScrn);
return FALSE;
}
if (pLeo->HWCursor && xf86LoadSubModule(pScrn, "ramdac") == NULL) {
LeoFreeRec(pScrn);
return FALSE;
}
/*********************
set up clock and mode stuff
*********************/
pScrn->progClock = TRUE;
if(pScrn->display->virtualX || pScrn->display->virtualY) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Leo does not support a virtual desktop\n");
pScrn->display->virtualX = 0;
pScrn->display->virtualY = 0;
}
xf86SbusUseBuiltinMode(pScrn, pLeo->psdp);
pScrn->currentMode = pScrn->modes;
pScrn->displayWidth = pScrn->virtualX;
/* Set display resolution */
xf86SetDpi(pScrn, 0, 0);
return TRUE;
}
/* Mandatory */
/* This gets called at the start of each server generation */
static Bool
LeoScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
{
ScrnInfoPtr pScrn;
LeoPtr pLeo;
int ret;
VisualPtr visual;
extern Bool LeoAccelInit(ScreenPtr pScreen, LeoPtr pLeo);
/*
* First get the ScrnInfoRec
*/
pScrn = xf86Screens[pScreen->myNum];
pLeo = GET_LEO_FROM_SCRN(pScrn);
/* Map the Leo memory */
pLeo->fb =
xf86MapSbusMem (pLeo->psdp, LEO_FB0_VOFF, 0x803000);
if (! pLeo->fb)
return FALSE;
/* Darken the screen for aesthetic reasons and set the viewport */
LeoSaveScreen(pScreen, SCREEN_SAVER_ON);
/*
* The next step is to setup the screen's visuals, and initialise the
* framebuffer code. In cases where the framebuffer's default
* choices for things like visual layouts and bits per RGB are OK,
* this may be as simple as calling the framebuffer's ScreenInit()
* function. If not, the visuals will need to be setup before calling
* a fb ScreenInit() function and fixed up after.
*/
/*
* Reset visual list.
*/
miClearVisualTypes();
/* Setup the visuals we support. */
if (!miSetVisualTypes(pScrn->depth, TrueColorMask, pScrn->rgbBits,
pScrn->defaultVisual))
return FALSE;
/*
* Call the framebuffer layer's ScreenInit function, and fill in other
* pScreen fields.
*/
ret = cfb32ScreenInit(pScreen, pLeo->fb, pScrn->virtualX,
pScrn->virtualY, pScrn->xDpi, pScrn->yDpi,
2048);
if (!ret)
return FALSE;
miInitializeBackingStore(pScreen);
xf86SetBackingStore(pScreen);
xf86SetSilkenMouse(pScreen);
xf86SetBlackWhitePixels(pScreen);
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;
}
}
}
if (!LeoAccelInit(pScreen, pLeo))
return FALSE;
if (!pLeo->NoAccel)
xf86Msg(X_INFO, "%s: Using acceleration\n", pLeo->psdp->device);
/* Initialise cursor functions */
miDCInitialize (pScreen, xf86GetPointerScreenFuncs());
/* Initialize HW cursor layer.
Must follow software cursor initialization*/
if (pLeo->HWCursor) {
extern Bool LeoHWCursorInit(ScreenPtr pScreen);
if(!LeoHWCursorInit(pScreen)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"Hardware cursor initialization failed\n");
return(FALSE);
}
xf86SbusHideOsHwCursor(pLeo->psdp);
}
/* Initialise default colourmap */
if (!miCreateDefColormap(pScreen))
return FALSE;
pLeo->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = LeoCloseScreen;
pScreen->SaveScreen = LeoSaveScreen;
/* Report any unused options (only for the first generation) */
if (serverGeneration == 1) {
xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
}
/* unblank the screen */
LeoSaveScreen(pScreen, SCREEN_SAVER_OFF);
/* Done */
return TRUE;
}
/* Usually mandatory */
static Bool
LeoSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
{
return TRUE;
}
/*
* This function is used to initialize the Start Address - the first
* displayed location in the video memory.
*/
/* Usually mandatory */
static void
LeoAdjustFrame(int scrnIndex, int x, int y, int flags)
{
/* we don't support virtual desktops */
return;
}
extern void LeoVtChange (ScreenPtr pScreen, int enter);
/*
* This is called when VT switching back to the X server. Its job is
* to reinitialise the video mode.
*/
/* Mandatory */
static Bool
LeoEnterVT(int scrnIndex, int flags)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
LeoPtr pLeo = GET_LEO_FROM_SCRN(pScrn);
pLeo->vtSema = FALSE;
LeoVtChange (pScrn->pScreen, TRUE);
if (pLeo->HWCursor)
xf86SbusHideOsHwCursor (pLeo->psdp);
return TRUE;
}
/*
* This is called when VT switching away from the X server.
*/
/* Mandatory */
static void
LeoLeaveVT(int scrnIndex, int flags)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
LeoPtr pLeo = GET_LEO_FROM_SCRN(pScrn);
LeoVtChange (pScrn->pScreen, FALSE);
pLeo->vtSema = TRUE;
}
/*
* This is called at the end of each server generation. It restores the
* original (text) mode. It should really also unmap the video memory too.
*/
/* Mandatory */
static Bool
LeoCloseScreen(int scrnIndex, ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
LeoPtr pLeo = GET_LEO_FROM_SCRN(pScrn);
pScrn->vtSema = FALSE;
xf86UnmapSbusMem(pLeo->psdp, pLeo->fb, 0x803000);
if (pLeo->HWCursor)
xf86SbusHideOsHwCursor (pLeo->psdp);
pScreen->CloseScreen = pLeo->CloseScreen;
return (*pScreen->CloseScreen)(scrnIndex, pScreen);
return FALSE;
}
/* Free up any per-generation data structures */
/* Optional */
static void
LeoFreeScreen(int scrnIndex, int flags)
{
LeoFreeRec(xf86Screens[scrnIndex]);
}
/* Checks if a mode is suitable for the selected chipset. */
/* Optional */
static ModeStatus
LeoValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
{
if (mode->Flags & V_INTERLACE)
return(MODE_BAD);
return(MODE_OK);
}
/* Do screen blanking */
/* Mandatory */
static Bool
LeoSaveScreen(ScreenPtr pScreen, int mode)
/* this function should blank the screen when unblank is FALSE and
unblank it when unblank is TRUE -- it doesn't actually seem to be
used for much though */
{
return TRUE;
}
/*
* This is the implementation of the Sync() function.
*/
void
LeoSync(ScrnInfoPtr pScrn)
{
return;
}
|