summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/accel/ibm8514/ibm8514.c
blob: b71ef6644278dad2c937004f80cc701bcbe825f4 (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
/* $XConsortium: ibm8514.c,v 1.5 95/01/16 13:16:28 kaleb Exp kaleb $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/accel/ibm8514/ibm8514.c,v 3.12 1995/01/26 02:17:19 dawes Exp $ */
/*
 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Thomas Roell not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Thomas Roell makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as is" without express or implied warranty.
 *
 * THOMAS ROELL, KEVIN E. MARTIN AND TIAGO GONS DISCLAIM ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS, IN NO EVENT SHALL THOMAS ROELL, KEVIN E. MARTIN OR TIAGO GONS BE
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  Thomas Roell, roell@informatik.tu-muenchen.de
 *
 * Rewritten for the 8514/A by Kevin E. Martin (martin@cs.unc.edu)
 * Modified by Tiago Gons (tiago@comosjn.hobby.nl)
 *
 * Header: /proj/X11/mit/server/ddx/xf86/vga/RCS/vga.c,v 1.2 1991/06/27 00:02:49 root Exp
 */


#include "X.h"
#include "Xmd.h"
#include "input.h"
#include "pixmapstr.h"
#include "scrnintstr.h"
#include "mipointer.h"
#include "cursorstr.h"

#include "compiler.h"

#include "xf86.h"
#include "xf86Priv.h"
#include "xf86Procs.h"
#include "xf86_OSlib.h"
#include "ibm8514.h"
#include "reg8514.h"
#include "xf86bcache.h"
#include "xf86fcache.h"
#include "xf86text.h"
#include "8514cach.h"
#include "mi.h"
#include "cfb.h"

extern Bool xf86Exiting, xf86Resetting, xf86ProbeFailed, xf86Verbose;

static Bool ibm8514ValidMode(
#if NeedFunctionPrototypes 
    DisplayModePtr 
#endif
);

ScrnInfoRec ibm8514InfoRec = {
    FALSE,		/* Bool configured */
    -1,			/* int tmpIndex */
    -1,			/* int scrnIndex */
    ibm8514Probe,      	/* Bool (* Probe)() */
    ibm8514Initialize,	/* Bool (* Init)() */
    ibm8514ValidMode,	/* Bool (* ValidMode)() */
    ibm8514EnterLeaveVT,/* void (* EnterLeaveVT)() */
    (void (*)())NoopDDA,/* void (* EnterLeaveMonitor)() */
    (void (*)())NoopDDA,/* void (* EnterLeaveCursor)() */
    (void (*)())NoopDDA,/* void (* AdjustFrame)() */
    (Bool (*)())NoopDDA,/* Bool (* SwitchMode)() */
    ibm8514PrintIdent,  /* void (* PrintIdent)() */
    8,			/* int depth */
    {0, 0, 0},          /* xrgb weight */
    8,			/* int bitsPerPixel */
    PseudoColor,       	/* int defaultVisual */
    -1, -1,		/* int virtualX,virtualY */
    -1,                 /* displayWidth */
    -1, -1, -1, -1,	/* int frameX0, frameY0, frameX1, frameY1 */
    {0, },	       	/* OFlagSet options */
    {0, },	       	/* OFlagSet clockOptions */
    {0, },	       	/* OFlagSet xconfigFlag */
    NULL,	       	/* char *chipset */
    NULL,	       	/* char *ramdac */
    0,			/* int dacSpeed */
    0,			/* int clocks */
    {0, },		/* int clock[MAXCLOCKS] */
    0,			/* int maxClock */
    0,			/* int videoRam */
    0,			/* int BIOSbase, 1.3 new */
    0,			/* unsigned long MemBase, unused for this driver */
    240, 180,		/* int width, height */
    0,                  /* unsigned long  speedup */
    NULL,	       	/* DisplayModePtr modes */
    NULL,	       	/* DisplayModePtr pModes */
    NULL,               /* char *clockprog */
    -1,			/* int textclock, 1.3 new */
    FALSE,              /* Bool bankedMono */
    "ibm8514",          /* char *name */
    {0, },		/* xrgb blackColour */
    {0, },		/* xrgb whiteColour */
    ibm8514ValidTokens,	/* int *validTokens */
    IBM8514_PATCHLEVEL,	/* char *patchlevel */
    0,			/* int IObase */
    0,			/* int PALbase */
    0,			/* int COPbase */
    0,			/* int POSbase */
    0,			/* int instance */
    0,			/* int s3Madjust */
    0,			/* int s3Nadjust */
    0,			/* int s3MClk */
};

short ibm8514alu[16] = {
    MIX_0,
    MIX_AND,
    MIX_SRC_AND_NOT_DST,
    MIX_SRC,
    MIX_NOT_SRC_AND_DST,
    MIX_DST,
    MIX_XOR,
    MIX_OR,
    MIX_NOR,
    MIX_XNOR,
    MIX_NOT_DST,
    MIX_SRC_OR_NOT_DST,
    MIX_NOT_SRC,
    MIX_NOT_SRC_OR_DST,
    MIX_NAND,
    MIX_1
};

extern miPointerScreenFuncRec xf86PointerScreenFuncs;

static int AlreadyInited = FALSE;

static int ibm8514ScreenMode;

static ScreenPtr savepScreen = NULL;
static PixmapPtr ppix = NULL;

static unsigned ibm8514_IOPorts[] = {
	DAC_MASK, DAC_R_INDEX, DAC_W_INDEX, DAC_DATA, DISP_STAT,
	H_TOTAL, H_DISP, H_SYNC_STRT, H_SYNC_WID,
	V_TOTAL, V_DISP, V_SYNC_STRT, V_SYNC_WID,
	DISP_CNTL, ADVFUNC_CNTL, SUBSYS_CNTL, ROM_PAGE_SEL,
	CUR_Y, CUR_X, DESTY_AXSTP, DESTX_DIASTP, 
	ERR_TERM, MAJ_AXIS_PCNT, GP_STAT, CMD, SHORT_STROKE,
	BKGD_COLOR, FRGD_COLOR, WRT_MASK, RD_MASK,
	COLOR_CMP, BKGD_MIX, FRGD_MIX, MULTIFUNC_CNTL, PIX_TRANS,
};
static int Num_ibm8514_IOPorts = (sizeof(ibm8514_IOPorts)/
				  sizeof(ibm8514_IOPorts[0]));

/*
 * ibm8514Probe --
 *     probe and initialize the hardware driver
 */
Bool
ibm8514Probe()
{
    OFlagSet       validOptions;

    xf86ClearIOPortList(ibm8514InfoRec.scrnIndex);
    xf86AddIOPorts(ibm8514InfoRec.scrnIndex, Num_ibm8514_IOPorts,
		   ibm8514_IOPorts);

    if (ibm8514InfoRec.chipset) {
	if (StrCaseCmp(ibm8514InfoRec.chipset, "ibm8514")) {
	    ErrorF("Chipset specified in XF86Config is not \"ibm8514\" (%s)!\n",
		   ibm8514InfoRec.chipset);
	    return(FALSE);
	}
	xf86EnableIOPorts(ibm8514InfoRec.scrnIndex);
    }
    else
    {
	xf86EnableIOPorts(ibm8514InfoRec.scrnIndex);

	/* Reset the 8514/A, and disable all interrupts. */
	outw(SUBSYS_CNTL, GPCTRL_RESET | CHPTEST_NORMAL);
	outw(SUBSYS_CNTL, GPCTRL_ENAB | CHPTEST_NORMAL);

	/* Check to see if an 8514/A is actually installed by writing to
	 * the ERR_TERM register, and reading back.  The 0x5a5a value is
	 * entirely arbitrary.
	 */
	outw(ERR_TERM, 0x5a5a);
	if (inw(ERR_TERM) != 0x5a5a) {
	    xf86DisableIOPorts(ibm8514InfoRec.scrnIndex);
	    return(FALSE);
	}
	/* 6 mar 93 TCG : let's make certain */
	outw(ERR_TERM, 0x5555);
	if (inw(ERR_TERM) != 0x5555) {
	    xf86DisableIOPorts(ibm8514InfoRec.scrnIndex);
	    return(FALSE);
	}
    }
    ibm8514InfoRec.chipset = "ibm8514";
    xf86ProbeFailed = FALSE;

    OFLG_ZERO(&validOptions);
    xf86VerifyOptions(&validOptions, &ibm8514InfoRec);

    return(TRUE);
}

void
ibm8514PrintIdent()
{
    ErrorF("  %s: accelerated server for ", ibm8514InfoRec.name);
    ErrorF("8514/A graphics adaptors (Patchlevel %s)\n", 
	   ibm8514InfoRec.patchLevel);
}

/*
 * ibm8514Initialize --
 *      Attempt to find and initialize a VGA framebuffer
 *      Most of the elements of the ScreenRec are filled in.  The
 *      video is enabled for the frame buffer...
 */

Bool
ibm8514Initialize (scr_index, pScreen, argc, argv)
    int            scr_index;    /* The index of pScreen in the ScreenInfo */
    ScreenPtr      pScreen;      /* The Screen to initialize */
    int            argc;         /* The number of the Server's arguments. */
    char           **argv;       /* The arguments themselves. Don't change! */
{
  int displayResolution = 75;    /* default to 75dpi */
  extern int monitorResolution;

    if (ibm8514InfoRec.virtualX == 1024 && ibm8514InfoRec.virtualY == 768) {
	ibm8514ScreenMode = MODE_1024;
    } else if (ibm8514InfoRec.virtualX == 640 &&
	       ibm8514InfoRec.virtualY == 480) {
	ibm8514ScreenMode = MODE_640;
    } else {
	ErrorF("Illegal screen size: (%dx%d)\n",
	       ibm8514InfoRec.virtualX, ibm8514InfoRec.virtualY);
	return FALSE;
    }

    /* Map io ports, map registers, etc. */
    /* Initialize the screen, saving the original state for Save/Restore
       function */
    ibm8514Init(ibm8514ScreenMode);
    InitEnvironment();
    AlreadyInited = TRUE;

#ifdef testing_8514
    if (ibm8514ScreenMode == MODE_1024)
	ibm8514InfoRec.virtualY = 512;
#endif

    xf86InitCache( ibm8514CacheMoveBlock );
    ibm8514FontCache8Init();

    ibm8514ImageInit();

    /*
     * Take display resolution from the -dpi flag if specified
     */

    if (monitorResolution)
        displayResolution = monitorResolution;

    if (!ibm8514ScreenInit(pScreen,
			   (pointer) 0,
			   ibm8514InfoRec.virtualX, ibm8514InfoRec.virtualY,
			   displayResolution, displayResolution,
			   ibm8514InfoRec.virtualX))
	return(FALSE);

    pScreen->CloseScreen = ibm8514CloseScreen;
    pScreen->SaveScreen = ibm8514SaveScreen;
    pScreen->InstallColormap = ibm8514InstallColormap;
    pScreen->UninstallColormap = ibm8514UninstallColormap;
    pScreen->ListInstalledColormaps = ibm8514ListInstalledColormaps;
    pScreen->StoreColors = ibm8514StoreColors;

    mfbRegisterCopyPlaneProc (pScreen, miCopyPlane);
  
    miDCInitialize (pScreen, &xf86PointerScreenFuncs);

    savepScreen = pScreen;

    return (cfbCreateDefColormap(pScreen));
}

/*
 * ibm8514EnterLeaveVT -- 
 *      grab/ungrab the current VT completely.
 */

void
ibm8514EnterLeaveVT(enter, screen_idx)
     Bool enter;
     int screen_idx;
{
  PixmapPtr   pspix;
  ScreenPtr   pScreen = savepScreen;

    if (!xf86Resetting && !xf86Exiting)
    {
        pspix = (PixmapPtr)pScreen->devPrivate;
    }

    if (enter) {
	xf86EnableIOPorts(ibm8514InfoRec.scrnIndex);
	ibm8514Init(ibm8514ScreenMode);
	InitEnvironment();
	ibm8514RestoreDACvalues(); /* 25-4-93 TCG */
	ibm8514FontCache8Init();
	AlreadyInited = TRUE;

        /* 2-5-93 TCG */
        if (!xf86Resetting)
           if ((pointer)pspix->devPrivate.ptr != /*(pointer)*/NULL && ppix)
           {
              pspix->devPrivate.ptr = /*(pointer)*/NULL;
              ibm8514ImageWrite(0, 0, pScreen->width, pScreen->height,
                                ppix->devPrivate.ptr,
                                PixmapBytePad(pScreen->width, pScreen->rootDepth),
                                0, 0, ibm8514alu[GXcopy], 0xFF);

           }
        if (ppix) {
           (pScreen->DestroyPixmap)(ppix);
	   ppix = NULL;
	}
    } else {
        if (!xf86Exiting)
        {
           ppix = (pScreen->CreatePixmap)(pScreen, pScreen->width,
                                          pScreen->height, pScreen->rootDepth);
           if (ppix)
           {
              ibm8514ImageRead(0, 0, pScreen->width, pScreen->height,
                               ppix->devPrivate.ptr,
                               PixmapBytePad(pScreen->width, pScreen->rootDepth),
                               0, 0, 0xff);
              pspix->devPrivate.ptr = ppix->devPrivate.ptr;
           }
        }

	/*
	 * We come here in many cases, but one is special: When the server
	 * aborts abnormaly. Therefore there MUST be a check whether
	 * vgaOrigVideoState is valid or not.
	 */
	/* The above refers to the video state not being set up until the
	   Initialize function (above) is called.  If it has not been called
	   then "vgaOrigVideoState" will not be initialized and thus cannot be
	   restored!  A similar thing must be done in the 8514.
	   */
	if (AlreadyInited) {
	    ibm8514CleanUp();
	}
    }
}

/*
 * ibm8514CloseScreen --
 *      called to ensure video is enabled when server exits.
 */

Bool
ibm8514CloseScreen(screen_idx, pScreen)
     int screen_idx;
     ScreenPtr pScreen;
{
    /*
     * Hmm... The server may shut down even if it is not running on the
     * current vt. Let's catch this case here.
     */
    xf86Exiting = TRUE;
    if (xf86VTSema)
	ibm8514EnterLeaveVT(LEAVE, screen_idx);
    else if (ppix) {
        /*
         * 7-Jan-94 CEG: The server is not running on the current vt.
         * Free the screen snapshot taken when the server vt was left.
	 */
        (savepScreen->DestroyPixmap)(ppix);
        ppix = NULL;
    }
    return(TRUE);
}

/*
 * ibm8514SaveScreen --
 *      blank the screen.
 */

Bool
ibm8514SaveScreen (pScreen, on)
     ScreenPtr     pScreen;
     Bool          on;
{
    if (on)
	SetTimeSinceLastInputEvent();
    if (xf86VTSema) {
	if (on) {
	    ibm8514RestoreColor0(pScreen);

	    outw(DAC_MASK, 0xff);
	} else {
	    outb(DAC_W_INDEX, 0);
	    outb(DAC_DATA, 0);
	    outb(DAC_DATA, 0);
	    outb(DAC_DATA, 0);

	    outw(DAC_MASK, 0x00);
	}
    }
    return(TRUE);
}

/*
 * ibm8514ValidMode --
 *
 */
static Bool
ibm8514ValidMode(mode)
DisplayModePtr mode;
{
return TRUE;
}