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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_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
 * Acceleration for the Creator and Creator3D framebuffer - DGA support.
 
3
 *
 
4
 * Copyright (C) 2000 David S. Miller (davem@redhat.com)
 
5
 *
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 
7
 * of this software and associated documentation files (the "Software"), to deal
 
8
 * in the Software without restriction, including without limitation the rights
 
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
10
 * copies of the Software, and to permit persons to whom the Software is
 
11
 * furnished to do so, subject to the following conditions:
 
12
 *
 
13
 * The above copyright notice and this permission notice shall be included in
 
14
 * all copies or substantial portions of the Software.
 
15
 *
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
19
 * DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 
20
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 *
 
23
 */
 
24
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_dga.c,v 1.2 2000/10/17 16:53:17 tsi Exp $ */
 
25
 
 
26
#include "xf86.h"
 
27
#include "xf86_OSproc.h"
 
28
#include "xf86_ansic.h"
 
29
#include "dgaproc.h"
 
30
 
 
31
#include "ffb.h"
 
32
#include "ffb_regs.h"
 
33
#include "ffb_rcache.h"
 
34
#include "ffb_fifo.h"
 
35
#include "ffb_stip.h"
 
36
#include "ffb_loops.h"
 
37
 
 
38
static Bool FFB_OpenFramebuffer(ScrnInfoPtr pScrn, char **name, unsigned char **mem,
 
39
                                int *size, int *offset, int *extra);
 
40
static void FFB_CloseFramebuffer(ScrnInfoPtr pScrn);
 
41
static Bool FFB_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode);
 
42
static void FFB_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags);
 
43
static int FFB_GetViewport(ScrnInfoPtr pScrn);
 
44
static void FFB_Flush(ScrnInfoPtr pScrn);
 
45
 
 
46
/* Have to disable all this stuff for now until I figure out where
 
47
 * we should get the WID values from... ho hum... -DaveM
 
48
 */
 
49
#if 0
 
50
static void FFB_FillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h, unsigned long color);
 
51
 
 
52
#ifdef USE_VIS
 
53
static void FFB_BlitRect(ScrnInfoPtr pScrn, int srcx, int srcy, int w, int h,
 
54
                         int dstx, int dsty);
 
55
#else
 
56
#define FFB_BlitRect NULL
 
57
#endif
 
58
#else
 
59
#define FFB_FillRect NULL
 
60
#define FFB_BlitRect NULL
 
61
#endif
 
62
 
 
63
static DGAFunctionRec FFB_DGAFuncs = {
 
64
        FFB_OpenFramebuffer,
 
65
        FFB_CloseFramebuffer,
 
66
        FFB_SetMode,
 
67
        FFB_SetViewport,
 
68
        FFB_GetViewport,
 
69
        FFB_Flush,
 
70
        FFB_FillRect,
 
71
        FFB_BlitRect,
 
72
        NULL
 
73
};
 
74
 
 
75
void FFB_InitDGA(ScreenPtr pScreen)
 
76
{
 
77
        ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
78
        FFBPtr pFfb;
 
79
        DGAModePtr mode;
 
80
        Bool result;
 
81
 
 
82
        pFfb = GET_FFB_FROM_SCRN(pScrn);
 
83
 
 
84
        mode = xnfcalloc(sizeof(DGAModeRec), 1);
 
85
        if (!mode) {
 
86
                xf86Msg(X_WARNING, "%s: DGA init failed, cannot alloc DGAMode.\n",
 
87
                        pFfb->psdp->device);
 
88
                return;
 
89
        }
 
90
 
 
91
        mode->num = 0;
 
92
        mode->mode = pScrn->modes;
 
93
 
 
94
        /* Hmmm, what does concurrent access really mean? -DaveM */
 
95
        mode->flags = (DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE | DGA_FILL_RECT);
 
96
 
 
97
#ifdef USE_VIS
 
98
        mode->flags |= DGA_BLIT_RECT;
 
99
#endif
 
100
 
 
101
        mode->imageWidth = 2048;
 
102
        mode->imageHeight = 2048;
 
103
        mode->pixmapWidth = 2048;
 
104
        mode->pixmapHeight = 2048;
 
105
 
 
106
        /* XXX I would imagine that this value states how many bytes
 
107
         * XXX you add to advance exactly one full horizontal line in
 
108
         * XXX the framebuffer addressing, but the way we set the pScrn
 
109
         * XXX mode values do not match that definition.
 
110
         * XXX
 
111
         * XXX Ask Jakub what is going on here. -DaveM
 
112
         */
 
113
#if 1
 
114
        mode->bytesPerScanline = pScrn->modes->HDisplay * 4;
 
115
#else
 
116
        mode->bytesPerScanline = (2048 * 4);
 
117
#endif
 
118
 
 
119
        mode->byteOrder = pScrn->imageByteOrder;
 
120
        mode->depth = 32;
 
121
        mode->bitsPerPixel = 32;
 
122
        mode->red_mask = 0xff;
 
123
        mode->green_mask = 0xff00;
 
124
        mode->blue_mask = 0xff0000;
 
125
        mode->visualClass = TrueColor;
 
126
        mode->viewportWidth = pScrn->modes->HDisplay;
 
127
        mode->viewportHeight = pScrn->modes->VDisplay;
 
128
 
 
129
        /* Do these values even matter if we do not support
 
130
         * viewports? -DaveM
 
131
         */
 
132
        mode->xViewportStep = 0;
 
133
        mode->yViewportStep = 0;
 
134
        mode->maxViewportX = 0;
 
135
        mode->maxViewportY = 0;
 
136
 
 
137
        mode->viewportFlags = 0;
 
138
        mode->offset = 0;
 
139
 
 
140
        result = DGAInit(pScreen, &FFB_DGAFuncs, mode, 1);
 
141
        if (result == FALSE) {
 
142
                xf86Msg(X_WARNING,
 
143
                        "%s: DGA init failed, DGAInit returns FALSE.\n",
 
144
                        pFfb->psdp->device);
 
145
        } else {
 
146
                xf86Msg(X_INFO, "%s: DGA support initialized.\n",
 
147
                        pFfb->psdp->device);
 
148
        }
 
149
}
 
150
 
 
151
static Bool FFB_OpenFramebuffer(ScrnInfoPtr pScrn, char **name, unsigned char **mem,
 
152
                                int *size, int *offset, int *extra)
 
153
{
 
154
        FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
 
155
 
 
156
        *name = pFfb->psdp->device;
 
157
 
 
158
        /* We give the user the dumb frame buffer. */
 
159
        *mem = (unsigned char *)FFB_DFB24_VOFF;
 
160
        *size = 0x1000000;
 
161
        *offset = 0;
 
162
        *extra = 0;
 
163
 
 
164
        return TRUE;
 
165
}
 
166
 
 
167
static void FFB_CloseFramebuffer(ScrnInfoPtr pScrn)
 
168
{
 
169
}
 
170
 
 
171
static Bool FFB_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode)
 
172
{
 
173
        /* Nothing to do, we currently only support one mode
 
174
         * and we are always in it.
 
175
         */
 
176
        return TRUE;
 
177
}
 
178
 
 
179
static void FFB_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
 
180
{
 
181
        /* We don't support viewports, so... */
 
182
}
 
183
 
 
184
static int FFB_GetViewport(ScrnInfoPtr pScrn)
 
185
{
 
186
        /* No viewports, none pending... */
 
187
        return 0;
 
188
}
 
189
 
 
190
static void FFB_Flush(ScrnInfoPtr pScrn)
 
191
{
 
192
        FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
 
193
        ffb_fbcPtr ffb = pFfb->regs;
 
194
 
 
195
        FFBWait(pFfb, ffb);
 
196
}
 
197
 
 
198
#if 0
 
199
 
 
200
extern void CreatorFillBoxSolid (DrawablePtr pDrawable, int nBox,
 
201
                                 BoxPtr pBox, unsigned long pixel);
 
202
 
 
203
static void FFB_FillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h, unsigned long color)
 
204
{
 
205
        DrawableRec draw;
 
206
        BoxRec box;
 
207
 
 
208
        draw.pScreen = pScrn->pScreen;
 
209
        box.x1 = x;
 
210
        box.y1 = y;
 
211
        box.x2 = x + w;
 
212
        box.y2 = y + h;
 
213
 
 
214
        CreatorFillBoxSolid(&draw, 1, &box, color);
 
215
}
 
216
 
 
217
#ifdef USE_VIS
 
218
extern void VISmoveImageLR(unsigned char *, unsigned char *, long, long, long, long);
 
219
extern void VISmoveImageRL(unsigned char *, unsigned char *, long, long, long, long);
 
220
 
 
221
static void FFB_BlitRect(ScrnInfoPtr pScrn, int srcx, int srcy,
 
222
                         int w, int h, int dstx, int dsty)
 
223
{
 
224
        FFBPtr pFfb = GET_FFB_FROM_SCRN(pScrn);
 
225
        ffb_fbcPtr ffb = pFfb->regs;
 
226
 
 
227
        if (!pFfb->disable_vscroll &&
 
228
            dstx == srcx &&
 
229
            dsty != dsty) {
 
230
                FFB_WRITE_ATTRIBUTES_VSCROLL(pFfb, 0x00ffffff);
 
231
                FFBFifo(pFfb, 7);
 
232
                ffb->drawop = FFB_DRAWOP_VSCROLL;
 
233
                FFB_WRITE64(&ffb->by, srcy, srcx);
 
234
                FFB_WRITE64_2(&ffb->dy, dsty, dstx);
 
235
                FFB_WRITE64_3(&ffb->bh, h, w);
 
236
                pFfb->rp_active = 1;
 
237
        } else {
 
238
                unsigned char *base = (unsigned char *)pFfb->fb;
 
239
                int use_prefetch = pFfb->use_blkread_prefetch;
 
240
 
 
241
                FFB_WRITE_ATTRIBUTES_SFB_VAR(pFfb, 0x00ffffff, GXcopy);
 
242
                FFBWait(pFfb, ffb);
 
243
                if (use_prefetch) {
 
244
                        FFBFifo(pFfb, 1);
 
245
                        ffb->mer = FFB_MER_EIRA;
 
246
                        pFfb->rp_active = 1;
 
247
                        FFBWait(pFfb, ffb);
 
248
                }
 
249
                if (srcx < dstx) {
 
250
                        VISmoveImageRL((base +
 
251
                                        ((srcy + h - 1) * (2048 * 4)) +
 
252
                                        (srcx * (32 / 8))),
 
253
                                       (base +
 
254
                                        ((dsty + h - 1) * (2048 * 4)) +
 
255
                                        (dstx * (32 / 8))),
 
256
                                       (w * (32 / 8)),
 
257
                                       h,
 
258
                                       -(2048 * 4), - (2048 * 4));
 
259
                } else {
 
260
                        VISmoveImageLR((base +
 
261
                                        ((srcy + h - 1) * (2048 * 4)) +
 
262
                                        (srcx * (32 / 8))),
 
263
                                       (base +
 
264
                                        ((dsty + h - 1) * (2048 * 4)) +
 
265
                                        (dstx * (32 / 8))),
 
266
                                       (w * (32 / 8)),
 
267
                                       h,
 
268
                                       -(2048 * 4), - (2048 * 4));
 
269
                }
 
270
                if (use_prefetch) {
 
271
                        FFBFifo(pFfb, 1);
 
272
                        ffb->mer = FFB_MER_DRA;
 
273
                        pFfb->rp_active = 1;
 
274
                        FFBWait(pFfb, pFfb->regs);
 
275
                }
 
276
        }
 
277
}
 
278
#endif
 
279
 
 
280
#endif