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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/ati/ativalid.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
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ati/ativalid.c,v 1.15 2003/01/01 19:16:34 tsi Exp $ */
 
2
/*
 
3
 * Copyright 1997 through 2003 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
 
4
 *
 
5
 * Permission to use, copy, modify, distribute, and sell this software and its
 
6
 * documentation for any purpose is hereby granted without fee, provided that
 
7
 * the above copyright notice appear in all copies and that both that copyright
 
8
 * notice and this permission notice appear in supporting documentation, and
 
9
 * that the name of Marc Aurele La France not be used in advertising or
 
10
 * publicity pertaining to distribution of the software without specific,
 
11
 * written prior permission.  Marc Aurele La France makes no representations
 
12
 * about the suitability of this software for any purpose.  It is provided
 
13
 * "as-is" without express or implied warranty.
 
14
 *
 
15
 * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO
 
17
 * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
19
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
20
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
21
 * PERFORMANCE OF THIS SOFTWARE.
 
22
 */
 
23
 
 
24
#include "atiadapter.h"
 
25
#include "atichip.h"
 
26
#include "aticrtc.h"
 
27
#include "atistruct.h"
 
28
#include "ativalid.h"
 
29
 
 
30
#include "xf86.h"
 
31
 
 
32
/*
 
33
 * ATIValidMode --
 
34
 *
 
35
 * This checks for hardware-related limits on mode timings.
 
36
 */
 
37
int
 
38
ATIValidMode
 
39
(
 
40
    int iScreen,
 
41
    DisplayModePtr pMode,
 
42
    Bool Verbose,
 
43
    int flags
 
44
)
 
45
{
 
46
    ScrnInfoPtr pScreenInfo = xf86Screens[iScreen];
 
47
    ATIPtr      pATI        = ATIPTR(pScreenInfo);
 
48
    Bool        InterlacedSeen;
 
49
    int         HBlankWidth, HAdjust, VScan, VInterlace;
 
50
 
 
51
#ifndef AVOID_CPIO
 
52
 
 
53
    int VDisplay, VTotal;
 
54
 
 
55
#endif /* AVOID_CPIO */
 
56
 
 
57
    if (flags & MODECHECK_FINAL)
 
58
    {
 
59
        /*
 
60
         * This is the final check before the common layer accepts a mode.
 
61
         * pScreenInfo->displayWidth is set to the proposed virtual pitch
 
62
         * should the mode be accepted.  The only check needed here is for
 
63
         * 18800's and 28800's, which don't support interlaced modes if the
 
64
         * pitch is over half the chipset's maximum pitch.
 
65
         */
 
66
        if (pATI->MaximumInterlacedPitch)
 
67
        {
 
68
            /*
 
69
             * Ensure no interlaced modes have a scanline pitch larger than the
 
70
             * limit.
 
71
             */
 
72
            if (pMode->Flags & V_INTERLACE)
 
73
                InterlacedSeen = TRUE;
 
74
            else
 
75
                InterlacedSeen = pATI->InterlacedSeen;
 
76
 
 
77
            if (InterlacedSeen &&
 
78
                (pScreenInfo->displayWidth > pATI->MaximumInterlacedPitch))
 
79
                return MODE_INTERLACE_WIDTH;
 
80
 
 
81
            pATI->InterlacedSeen = InterlacedSeen;
 
82
        }
 
83
 
 
84
        return MODE_OK;
 
85
    }
 
86
 
 
87
    /*
 
88
     * The following is done for every mode in the monitor section that
 
89
     * survives the common layer's basic checks.
 
90
     */
 
91
    if (pMode->VScan <= 1)
 
92
        VScan = 1;
 
93
    else
 
94
        VScan = pMode->VScan;
 
95
 
 
96
    if (pMode->Flags & V_DBLSCAN)
 
97
        VScan <<= 1;
 
98
 
 
99
    if (pATI->OptionPanelDisplay && (pATI->LCDPanelID >= 0))
 
100
    {
 
101
        if ((pMode->CrtcHDisplay > pATI->LCDHorizontal) ||
 
102
            (pMode->CrtcVDisplay > pATI->LCDVertical))
 
103
            return MODE_PANEL;
 
104
 
 
105
        if (!pATI->OptionSync || (pMode->type & M_T_BUILTIN))
 
106
        {
 
107
            if ((pMode->HDisplay > pATI->LCDHorizontal) ||
 
108
                (pMode->VDisplay > pATI->LCDVertical))
 
109
                return MODE_PANEL;
 
110
 
 
111
            return MODE_OK;
 
112
        }
 
113
 
 
114
        /*
 
115
         * Adjust effective timings for monitor checks.  Here the modeline
 
116
         * clock is ignored.  Horizontal timings are scaled by the stretch
 
117
         * ratio used for the displayed area.  The vertical porch is scaled by
 
118
         * the native resolution's aspect ratio.  This seems rather arbitrary,
 
119
         * and it is, but it does make all applicable VESA modes sync on a
 
120
         * panel after stretching.  This has the unfortunate, but necessary,
 
121
         * side-effect of changing the mode's horizontal sync and vertical
 
122
         * refresh rates.  With some exceptions, this tends to increase the
 
123
         * mode's horizontal sync rate, and decrease its vertical refresh rate.
 
124
         */
 
125
        pMode->SynthClock = pATI->LCDClock;
 
126
 
 
127
        pMode->CrtcHTotal = pMode->CrtcHBlankEnd =
 
128
            ATIDivide(pMode->CrtcHTotal * pATI->LCDHorizontal,
 
129
                pMode->CrtcHDisplay, -3, 1) << 3;
 
130
        pMode->CrtcHSyncEnd =
 
131
            ATIDivide(pMode->CrtcHSyncEnd * pATI->LCDHorizontal,
 
132
                pMode->CrtcHDisplay, -3, 1) << 3;
 
133
        pMode->CrtcHSyncStart =
 
134
            ATIDivide(pMode->CrtcHSyncStart * pATI->LCDHorizontal,
 
135
                pMode->CrtcHDisplay, -3, -1) << 3;
 
136
        pMode->CrtcHDisplay = pMode->CrtcHBlankStart = pATI->LCDHorizontal;
 
137
 
 
138
        pMode->CrtcVTotal = pMode->CrtcVBlankEnd =
 
139
            ATIDivide((pMode->CrtcVTotal - pMode->CrtcVDisplay) *
 
140
                pATI->LCDVertical, pATI->LCDHorizontal, 0, 1) +
 
141
                pATI->LCDVertical;
 
142
        pMode->CrtcVSyncEnd =
 
143
            ATIDivide((pMode->CrtcVSyncEnd - pMode->CrtcVDisplay) *
 
144
                pATI->LCDVertical, pATI->LCDHorizontal, 0, 1) +
 
145
                pATI->LCDVertical;
 
146
        pMode->CrtcVSyncStart =
 
147
            ATIDivide((pMode->CrtcVSyncStart - pMode->CrtcVDisplay) *
 
148
                pATI->LCDVertical, pATI->LCDHorizontal, 0, -1) +
 
149
                pATI->LCDVertical;
 
150
        pMode->CrtcVDisplay = pMode->CrtcVBlankStart = pATI->LCDVertical;
 
151
 
 
152
        /*
 
153
         * The CRTC only stretches the mode's displayed area, not its porches.
 
154
         * Reverse-engineer the mode's timings back into the user specified
 
155
         * values so that the stretched mode is produced when the CRTC is
 
156
         * eventually programmed.  The reverse-engineered mode is then checked
 
157
         * against CRTC limits below.
 
158
         */
 
159
        pMode->Clock = pATI->LCDClock;
 
160
 
 
161
        HAdjust = pATI->LCDHorizontal - pMode->HDisplay;
 
162
#       define ATIReverseHorizontal(_x) \
 
163
            (pMode->_x - HAdjust)
 
164
 
 
165
        pMode->HSyncStart = ATIReverseHorizontal(CrtcHSyncStart);
 
166
        pMode->HSyncEnd = ATIReverseHorizontal(CrtcHSyncEnd);
 
167
        pMode->HTotal = ATIReverseHorizontal(CrtcHTotal);
 
168
 
 
169
        VInterlace = GetBits(pMode->Flags, V_INTERLACE) + 1;
 
170
#       define ATIReverseVertical(_y) \
 
171
            ((((pMode->_y - pATI->LCDVertical) * VInterlace) / VScan) + \
 
172
             pMode->VDisplay)
 
173
 
 
174
        pMode->VSyncStart = ATIReverseVertical(CrtcVSyncStart);
 
175
        pMode->VSyncEnd = ATIReverseVertical(CrtcVSyncEnd);
 
176
        pMode->VTotal = ATIReverseVertical(CrtcVTotal);
 
177
 
 
178
#       undef ATIReverseHorizontal
 
179
#       undef ATIReverseVertical
 
180
    }
 
181
 
 
182
    HBlankWidth = (pMode->HTotal >> 3) - (pMode->HDisplay >> 3);
 
183
    if (!HBlankWidth)
 
184
        return MODE_HBLANK_NARROW;
 
185
 
 
186
    switch (pATI->NewHW.crtc)
 
187
    {
 
188
 
 
189
#ifndef AVOID_CPIO
 
190
 
 
191
        case ATI_CRTC_VGA:
 
192
            /* Prevent overscans */
 
193
            if (HBlankWidth > 63)
 
194
                return MODE_HBLANK_WIDE;
 
195
 
 
196
            if (pMode->HDisplay > 2048)
 
197
                return MODE_BAD_HVALUE;
 
198
 
 
199
            if (VScan > 64)
 
200
                return MODE_BAD_VSCAN;
 
201
 
 
202
            VDisplay = pMode->VDisplay * VScan;
 
203
            VTotal = pMode->VTotal * VScan;
 
204
 
 
205
            if ((pMode->Flags & V_INTERLACE) && (pATI->Chip < ATI_CHIP_264CT))
 
206
            {
 
207
                VDisplay >>= 1;
 
208
                VTotal >>= 1;
 
209
            }
 
210
 
 
211
            if ((VDisplay > 2048) || (VTotal > 2050))
 
212
                return MODE_BAD_VVALUE;
 
213
 
 
214
            if (pATI->Adapter != ATI_ADAPTER_VGA)
 
215
                break;
 
216
 
 
217
            if ((VDisplay > 1024) || (VTotal > 1025))
 
218
                return MODE_BAD_VVALUE;
 
219
 
 
220
            break;
 
221
 
 
222
#endif /* AVOID_CPIO */
 
223
 
 
224
        case ATI_CRTC_MACH64:
 
225
            if (VScan > 2)
 
226
                return MODE_NO_VSCAN;
 
227
 
 
228
            break;
 
229
 
 
230
        default:
 
231
            break;
 
232
    }
 
233
 
 
234
    return MODE_OK;
 
235
}