~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/neomagic/neo_dga.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2000 by Alan Hourihane, Sychdyn, North Wales, UK.
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software and its
 
5
 * documentation for any purpose is hereby granted without fee, provided that
 
6
 * the above copyright notice appear in all copies and that both that
 
7
 * copyright notice and this permission notice appear in supporting
 
8
 * documentation, and that the name of Alan Hourihane not be used in
 
9
 * advertising or publicity pertaining to distribution of the software without
 
10
 * specific, written prior permission.  Alan Hourihane makes no representations
 
11
 * about the suitability of this software for any purpose.  It is provided
 
12
 * "as is" without express or implied warranty.
 
13
 *
 
14
 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
15
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
16
 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
17
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
18
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
19
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
20
 * PERFORMANCE OF THIS SOFTWARE.
 
21
 *
 
22
 * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
 
23
 */
 
24
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/neomagic/neo_dga.c,v 1.5 2002/04/04 14:05:44 eich Exp $ */
 
25
 
 
26
#include "xf86.h"
 
27
#include "xf86_OSproc.h"
 
28
#include "xf86_ansic.h"
 
29
#include "xf86Pci.h"
 
30
#include "xf86PciInfo.h"
 
31
#include "xaa.h"
 
32
#include "xaalocal.h"
 
33
#include "neo.h"
 
34
#include "neo_reg.h"
 
35
#include "dgaproc.h"
 
36
#include "vgaHW.h"
 
37
 
 
38
static Bool NEO_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **, 
 
39
                                        int *, int *, int *);
 
40
static Bool NEO_SetMode(ScrnInfoPtr, DGAModePtr);
 
41
static void NEO_Sync(ScrnInfoPtr);
 
42
static int  NEO_GetViewport(ScrnInfoPtr);
 
43
static void NEO_SetViewport(ScrnInfoPtr, int, int, int);
 
44
static void NEO_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long);
 
45
static void NEO_BlitRect(ScrnInfoPtr, int, int, int, int, int, int);
 
46
#if 0
 
47
static void NEO_BlitTransRect(ScrnInfoPtr, int, int, int, int, int, int, 
 
48
                                        unsigned long);
 
49
#endif
 
50
 
 
51
static
 
52
DGAFunctionRec NEODGAFuncs = {
 
53
   NEO_OpenFramebuffer,
 
54
   NULL,
 
55
   NEO_SetMode,
 
56
   NEO_SetViewport,
 
57
   NEO_GetViewport,
 
58
   NEO_Sync,
 
59
   NEO_FillRect,
 
60
   NEO_BlitRect,
 
61
#if 0
 
62
   NEO_BlitTransRect
 
63
#else
 
64
   NULL
 
65
#endif
 
66
};
 
67
 
 
68
Bool
 
69
NEODGAInit(ScreenPtr pScreen)
 
70
{   
 
71
   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
72
   NEOPtr pNEO = NEOPTR(pScrn);
 
73
   DGAModePtr modes = NULL, newmodes = NULL, currentMode;
 
74
   DisplayModePtr pMode, firstMode;
 
75
   int Bpp = pScrn->bitsPerPixel >> 3;
 
76
   int num = 0, imlines, pixlines;
 
77
 
 
78
   imlines =  (pScrn->videoRam * 1024) /
 
79
      (pScrn->displayWidth * (pScrn->bitsPerPixel >> 3));
 
80
 
 
81
   pixlines =  (imlines > 1024 && !pNEO->noAccel)  ? 1024 : imlines;
 
82
 
 
83
   pMode = firstMode = pScrn->modes;
 
84
 
 
85
   while(pMode) {
 
86
 
 
87
        newmodes = xrealloc(modes, (num + 1) * sizeof(DGAModeRec));
 
88
 
 
89
        if(!newmodes) {
 
90
           xfree(modes);
 
91
           return FALSE;
 
92
        }
 
93
        modes = newmodes;
 
94
 
 
95
        currentMode = modes + num;
 
96
        num++;
 
97
 
 
98
        currentMode->mode = pMode;
 
99
        currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;
 
100
        if (!pNEO->noAccel)
 
101
            currentMode->flags |= (DGA_FILL_RECT | DGA_BLIT_RECT);
 
102
        if(pMode->Flags & V_DBLSCAN)
 
103
           currentMode->flags |= DGA_DOUBLESCAN;
 
104
        if(pMode->Flags & V_INTERLACE)
 
105
           currentMode->flags |= DGA_INTERLACED;
 
106
        currentMode->byteOrder = pScrn->imageByteOrder;
 
107
        currentMode->depth = pScrn->depth;
 
108
        currentMode->bitsPerPixel = pScrn->bitsPerPixel;
 
109
        currentMode->red_mask = pScrn->mask.red;
 
110
        currentMode->green_mask = pScrn->mask.green;
 
111
        currentMode->blue_mask = pScrn->mask.blue;
 
112
        currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor;
 
113
        currentMode->viewportWidth = pMode->HDisplay;
 
114
        currentMode->viewportHeight = pMode->VDisplay;
 
115
        currentMode->xViewportStep = 1;
 
116
        currentMode->yViewportStep = 1;
 
117
        currentMode->viewportFlags = DGA_FLIP_RETRACE;
 
118
        currentMode->offset = 0;
 
119
        currentMode->address = pNEO->NeoFbBase;
 
120
 
 
121
        currentMode->bytesPerScanline = 
 
122
                        ((pScrn->displayWidth * Bpp) + 3) & ~3L;
 
123
        currentMode->imageWidth = pScrn->displayWidth;
 
124
        currentMode->imageHeight =  imlines;
 
125
        currentMode->pixmapWidth = currentMode->imageWidth;
 
126
        currentMode->pixmapHeight = pixlines;
 
127
        currentMode->maxViewportX = currentMode->imageWidth - 
 
128
                                        currentMode->viewportWidth;
 
129
        currentMode->maxViewportY = currentMode->imageHeight -
 
130
                                        currentMode->viewportHeight;
 
131
 
 
132
        pMode = pMode->next;
 
133
        if(pMode == firstMode)
 
134
           break;
 
135
   }
 
136
 
 
137
   pNEO->numDGAModes = num;
 
138
   pNEO->DGAModes = modes;
 
139
 
 
140
   return DGAInit(pScreen, &NEODGAFuncs, modes, num);  
 
141
}
 
142
 
 
143
static DisplayModePtr NEOSavedDGAModes[MAXSCREENS];
 
144
 
 
145
static Bool
 
146
NEO_SetMode(
 
147
   ScrnInfoPtr pScrn,
 
148
   DGAModePtr pMode
 
149
){
 
150
   int index = pScrn->pScreen->myNum;
 
151
   NEOPtr pNEO = NEOPTR(pScrn);
 
152
 
 
153
   if(!pMode) { /* restore the original mode */
 
154
        if(pNEO->DGAactive) {   
 
155
            pScrn->currentMode = NEOSavedDGAModes[index];
 
156
            NEOSwitchMode(index, pScrn->currentMode, 0);
 
157
            NEOAdjustFrame(index, 0, 0, 0);
 
158
            pNEO->DGAactive = FALSE;
 
159
        }
 
160
   } else {
 
161
        if(!pNEO->DGAactive) {  /* save the old parameters */
 
162
            NEOSavedDGAModes[index] = pScrn->currentMode;
 
163
            pNEO->DGAactive = TRUE;
 
164
        }
 
165
 
 
166
        NEOSwitchMode(index, pMode->mode, 0);
 
167
   }
 
168
   
 
169
   return TRUE;
 
170
}
 
171
 
 
172
static int  
 
173
NEO_GetViewport(
 
174
  ScrnInfoPtr pScrn
 
175
){
 
176
    NEOPtr pNEO = NEOPTR(pScrn);
 
177
 
 
178
    return pNEO->DGAViewportStatus;
 
179
}
 
180
 
 
181
static void 
 
182
NEO_SetViewport(
 
183
   ScrnInfoPtr pScrn, 
 
184
   int x, int y, 
 
185
   int flags
 
186
){
 
187
   NEOPtr pNEO = NEOPTR(pScrn);
 
188
   vgaHWPtr hwp = VGAHWPTR(pScrn);
 
189
   
 
190
   NEOAdjustFrame(pScrn->pScreen->myNum, x, y, flags);
 
191
   /* wait for retrace */
 
192
   while((hwp->readST01(hwp) & 0x08));
 
193
   while(!(hwp->readST01(hwp) & 0x08));
 
194
 
 
195
   pNEO->DGAViewportStatus = 0;  
 
196
}
 
197
 
 
198
static void 
 
199
NEO_FillRect (
 
200
   ScrnInfoPtr pScrn, 
 
201
   int x, int y, int w, int h, 
 
202
   unsigned long color
 
203
){
 
204
    NEOPtr pNEO = NEOPTR(pScrn);
 
205
 
 
206
    if(pNEO->AccelInfoRec) {
 
207
        (*pNEO->AccelInfoRec->SetupForSolidFill)(pScrn, color, GXcopy, ~0);
 
208
        (*pNEO->AccelInfoRec->SubsequentSolidFillRect)(pScrn, x, y, w, h);
 
209
        SET_SYNC_FLAG(pNEO->AccelInfoRec);
 
210
    }
 
211
}
 
212
 
 
213
static void 
 
214
NEO_Sync(
 
215
   ScrnInfoPtr pScrn
 
216
){
 
217
    NEOPtr pNEO = NEOPTR(pScrn);
 
218
 
 
219
    if(pNEO->AccelInfoRec) {
 
220
        (*pNEO->AccelInfoRec->Sync)(pScrn);
 
221
    }
 
222
}
 
223
 
 
224
static void 
 
225
NEO_BlitRect(
 
226
   ScrnInfoPtr pScrn, 
 
227
   int srcx, int srcy, 
 
228
   int w, int h, 
 
229
   int dstx, int dsty
 
230
){
 
231
    NEOPtr pNEO = NEOPTR(pScrn);
 
232
 
 
233
    if(pNEO->AccelInfoRec) {
 
234
        int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1;
 
235
        int ydir = (srcy < dsty) ? -1 : 1;
 
236
 
 
237
        (*pNEO->AccelInfoRec->SetupForScreenToScreenCopy)(
 
238
                pScrn, xdir, ydir, GXcopy, ~0, -1);
 
239
        (*pNEO->AccelInfoRec->SubsequentScreenToScreenCopy)(
 
240
                pScrn, srcx, srcy, dstx, dsty, w, h);
 
241
        SET_SYNC_FLAG(pNEO->AccelInfoRec);
 
242
    }
 
243
}
 
244
 
 
245
#if 0
 
246
static void 
 
247
NEO_BlitTransRect(
 
248
   ScrnInfoPtr pScrn, 
 
249
   int srcx, int srcy, 
 
250
   int w, int h, 
 
251
   int dstx, int dsty,
 
252
   unsigned long color
 
253
){
 
254
  /* this one should be separate since the XAA function would
 
255
     prohibit usage of ~0 as the key */
 
256
}
 
257
#endif
 
258
 
 
259
static Bool 
 
260
NEO_OpenFramebuffer(
 
261
   ScrnInfoPtr pScrn, 
 
262
   char **name,
 
263
   unsigned char **mem,
 
264
   int *size,
 
265
   int *offset,
 
266
   int *flags
 
267
){
 
268
    NEOPtr pNEO = NEOPTR(pScrn);
 
269
 
 
270
    *name = NULL;               /* no special device */
 
271
    *mem = (unsigned char*)pNEO->NeoLinearAddr;
 
272
    *size = pNEO->NeoFbMapSize;
 
273
    *offset = 0;
 
274
    *flags = DGA_NEED_ROOT;
 
275
 
 
276
    return TRUE;
 
277
}