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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/i810/i810_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
/*
 
25
 * Reformatted with GNU indent (2.2.8), using the following options:
 
26
 *
 
27
 *    -bad -bap -c41 -cd0 -ncdb -ci6 -cli0 -cp0 -ncs -d0 -di3 -i3 -ip3 -l78
 
28
 *    -lp -npcs -psl -sob -ss -br -ce -sc -hnl
 
29
 *
 
30
 * This provides a good match with the original i810 code and preferred
 
31
 * XFree86 formatting conventions.
 
32
 *
 
33
 * When editing this driver, please follow the existing formatting, and edit
 
34
 * with <TAB> characters expanded at 8-column intervals.
 
35
 */
 
36
 
 
37
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i810/i810_dga.c,v 1.6 2003/02/26 04:19:36 dawes Exp $ */
 
38
 
 
39
#include "xf86.h"
 
40
#include "xf86_OSproc.h"
 
41
#include "xf86_ansic.h"
 
42
#include "xf86Pci.h"
 
43
#include "xf86PciInfo.h"
 
44
#include "xaa.h"
 
45
#include "xaalocal.h"
 
46
#include "i810.h"
 
47
#include "i810_reg.h"
 
48
#include "dgaproc.h"
 
49
#include "vgaHW.h"
 
50
 
 
51
static Bool I810_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **,
 
52
                                 int *, int *, int *);
 
53
static Bool I810_SetMode(ScrnInfoPtr, DGAModePtr);
 
54
static void I810_Sync(ScrnInfoPtr);
 
55
static int I810_GetViewport(ScrnInfoPtr);
 
56
static void I810_SetViewport(ScrnInfoPtr, int, int, int);
 
57
static void I810_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long);
 
58
static void I810_BlitRect(ScrnInfoPtr, int, int, int, int, int, int);
 
59
 
 
60
#if 0
 
61
static void I810_BlitTransRect(ScrnInfoPtr, int, int, int, int, int, int,
 
62
                               unsigned long);
 
63
#endif
 
64
 
 
65
static
 
66
DGAFunctionRec I810DGAFuncs = {
 
67
   I810_OpenFramebuffer,
 
68
   NULL,
 
69
   I810_SetMode,
 
70
   I810_SetViewport,
 
71
   I810_GetViewport,
 
72
   I810_Sync,
 
73
   I810_FillRect,
 
74
   I810_BlitRect,
 
75
#if 0
 
76
   I810_BlitTransRect
 
77
#else
 
78
   NULL
 
79
#endif
 
80
};
 
81
 
 
82
Bool
 
83
I810DGAInit(ScreenPtr pScreen)
 
84
{
 
85
   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
86
   I810Ptr pI810 = I810PTR(pScrn);
 
87
   DGAModePtr modes = NULL, newmodes = NULL, currentMode;
 
88
   DisplayModePtr pMode, firstMode;
 
89
   int Bpp = pScrn->bitsPerPixel >> 3;
 
90
   int num = 0;
 
91
 
 
92
   MARKER();
 
93
 
 
94
   pMode = firstMode = pScrn->modes;
 
95
 
 
96
   while (pMode) {
 
97
 
 
98
      newmodes = xrealloc(modes, (num + 1) * sizeof(DGAModeRec));
 
99
 
 
100
      if (!newmodes) {
 
101
         xfree(modes);
 
102
         return FALSE;
 
103
      }
 
104
      modes = newmodes;
 
105
 
 
106
      currentMode = modes + num;
 
107
      num++;
 
108
 
 
109
      currentMode->mode = pMode;
 
110
      currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;
 
111
      if (!pI810->noAccel)
 
112
         currentMode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT;
 
113
      if (pMode->Flags & V_DBLSCAN)
 
114
         currentMode->flags |= DGA_DOUBLESCAN;
 
115
      if (pMode->Flags & V_INTERLACE)
 
116
         currentMode->flags |= DGA_INTERLACED;
 
117
      currentMode->byteOrder = pScrn->imageByteOrder;
 
118
      currentMode->depth = pScrn->depth;
 
119
      currentMode->bitsPerPixel = pScrn->bitsPerPixel;
 
120
      currentMode->red_mask = pScrn->mask.red;
 
121
      currentMode->green_mask = pScrn->mask.green;
 
122
      currentMode->blue_mask = pScrn->mask.blue;
 
123
      currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor;
 
124
      currentMode->viewportWidth = pMode->HDisplay;
 
125
      currentMode->viewportHeight = pMode->VDisplay;
 
126
      currentMode->xViewportStep = (Bpp == 3) ? 2 : 1;
 
127
      currentMode->yViewportStep = 1;
 
128
      currentMode->viewportFlags = DGA_FLIP_RETRACE;
 
129
      currentMode->offset = 0;
 
130
      currentMode->address = pI810->FbBase;
 
131
 
 
132
      currentMode->bytesPerScanline = ((pScrn->displayWidth * Bpp) + 3) & ~3L;
 
133
      currentMode->imageWidth = pI810->FbMemBox.x2;
 
134
      currentMode->imageHeight = pI810->FbMemBox.y2;
 
135
      currentMode->pixmapWidth = currentMode->imageWidth;
 
136
      currentMode->pixmapHeight = currentMode->imageHeight;
 
137
      currentMode->maxViewportX = currentMode->imageWidth -
 
138
            currentMode->viewportWidth;
 
139
      /* this might need to get clamped to some maximum */
 
140
      currentMode->maxViewportY = currentMode->imageHeight -
 
141
            currentMode->viewportHeight;
 
142
 
 
143
      pMode = pMode->next;
 
144
      if (pMode == firstMode)
 
145
         break;
 
146
   }
 
147
 
 
148
   pI810->numDGAModes = num;
 
149
   pI810->DGAModes = modes;
 
150
 
 
151
   return DGAInit(pScreen, &I810DGAFuncs, modes, num);
 
152
}
 
153
 
 
154
static DisplayModePtr I810SavedDGAModes[MAXSCREENS];
 
155
 
 
156
static Bool
 
157
I810_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode)
 
158
{
 
159
   int index = pScrn->pScreen->myNum;
 
160
   I810Ptr pI810 = I810PTR(pScrn);
 
161
 
 
162
   MARKER();
 
163
 
 
164
   if (!pMode) {                        /* restore the original mode */
 
165
      DPRINTF(PFX, "Restoring original mode (from DGA mode)\n");
 
166
      if (pI810->DGAactive) {
 
167
         pScrn->currentMode = I810SavedDGAModes[index];
 
168
         pScrn->SwitchMode(index, pScrn->currentMode, 0);
 
169
         pScrn->AdjustFrame(index, 0, 0, 0);
 
170
         pI810->DGAactive = FALSE;
 
171
      }
 
172
   } else {
 
173
      if (!pI810->DGAactive) {
 
174
         DPRINTF(PFX, "Setting DGA mode\n");
 
175
         I810SavedDGAModes[index] = pScrn->currentMode;
 
176
         pI810->DGAactive = TRUE;
 
177
      }
 
178
 
 
179
      pScrn->SwitchMode(index, pMode->mode, 0);
 
180
   }
 
181
 
 
182
   return TRUE;
 
183
}
 
184
 
 
185
static int
 
186
I810_GetViewport(ScrnInfoPtr pScrn)
 
187
{
 
188
   I810Ptr pI810 = I810PTR(pScrn);
 
189
 
 
190
   MARKER();
 
191
 
 
192
   return pI810->DGAViewportStatus;
 
193
}
 
194
 
 
195
static void
 
196
I810_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
 
197
{
 
198
   I810Ptr pI810 = I810PTR(pScrn);
 
199
   vgaHWPtr hwp = VGAHWPTR(pScrn);
 
200
 
 
201
   MARKER();
 
202
 
 
203
   pScrn->AdjustFrame(pScrn->pScreen->myNum, x, y, flags);
 
204
 
 
205
   /* wait for retrace */
 
206
   while ((hwp->readST01(hwp) & 0x08)) ;
 
207
   while (!(hwp->readST01(hwp) & 0x08)) ;
 
208
 
 
209
   pI810->DGAViewportStatus = 0;
 
210
}
 
211
 
 
212
static void
 
213
I810_FillRect(ScrnInfoPtr pScrn,
 
214
              int x, int y, int w, int h, unsigned long color)
 
215
{
 
216
   I810Ptr pI810 = I810PTR(pScrn);
 
217
 
 
218
   MARKER();
 
219
 
 
220
   if (pI810->AccelInfoRec) {
 
221
      (*pI810->AccelInfoRec->SetupForSolidFill) (pScrn, color, GXcopy, ~0);
 
222
      (*pI810->AccelInfoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
 
223
      SET_SYNC_FLAG(pI810->AccelInfoRec);
 
224
   }
 
225
}
 
226
 
 
227
static void
 
228
I810_Sync(ScrnInfoPtr pScrn)
 
229
{
 
230
   I810Ptr pI810 = I810PTR(pScrn);
 
231
 
 
232
   MARKER();
 
233
 
 
234
   if (pI810->AccelInfoRec) {
 
235
      (*pI810->AccelInfoRec->Sync) (pScrn);
 
236
   }
 
237
}
 
238
 
 
239
static void
 
240
I810_BlitRect(ScrnInfoPtr pScrn,
 
241
              int srcx, int srcy, int w, int h, int dstx, int dsty)
 
242
{
 
243
   I810Ptr pI810 = I810PTR(pScrn);
 
244
 
 
245
   MARKER();
 
246
 
 
247
   if (pI810->AccelInfoRec) {
 
248
      int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1;
 
249
      int ydir = (srcy < dsty) ? -1 : 1;
 
250
 
 
251
      (*pI810->AccelInfoRec->SetupForScreenToScreenCopy) (pScrn, xdir, ydir,
 
252
                                                          GXcopy, ~0, -1);
 
253
      (*pI810->AccelInfoRec->SubsequentScreenToScreenCopy) (pScrn, srcx, srcy,
 
254
                                                            dstx, dsty, w, h);
 
255
      SET_SYNC_FLAG(pI810->AccelInfoRec);
 
256
   }
 
257
}
 
258
 
 
259
#if 0
 
260
static void
 
261
I810_BlitTransRect(ScrnInfoPtr pScrn,
 
262
                   int srcx, int srcy,
 
263
                   int w, int h, int dstx, int dsty, unsigned long color)
 
264
{
 
265
 
 
266
   MARKER();
 
267
 
 
268
   /* this one should be separate since the XAA function would
 
269
    * prohibit usage of ~0 as the key */
 
270
}
 
271
#endif
 
272
 
 
273
static Bool
 
274
I810_OpenFramebuffer(ScrnInfoPtr pScrn,
 
275
                     char **name,
 
276
                     unsigned char **mem, int *size, int *offset, int *flags)
 
277
{
 
278
   I810Ptr pI810 = I810PTR(pScrn);
 
279
 
 
280
   MARKER();
 
281
 
 
282
   *name = NULL;                        /* no special device */
 
283
   *mem = (unsigned char *)pI810->LinearAddr;
 
284
   *size = pI810->FbMapSize;
 
285
   *offset = 0;
 
286
   *flags = DGA_NEED_ROOT;
 
287
 
 
288
   DPRINTF(PFX,
 
289
           " mem == 0x%.8x (pI810->LinearAddr)\n"
 
290
           "size == %lu (pI810->FbMapSize)\n", *mem, *size);
 
291
 
 
292
   return TRUE;
 
293
}