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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/kdrive/sis530/sisclock.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
 * Id: sisclock.c,v 1.1 1999/11/02 08:17:24 keithp Exp $
 
3
 *
 
4
 * Copyright � 1999 Keith Packard
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
/* $XFree86: xc/programs/Xserver/hw/kdrive/sis530/sisclock.c,v 1.2 2000/02/23 20:30:07 dawes Exp $ */
 
25
 
 
26
#include "sis.h"
 
27
#include <stdio.h>
 
28
 
 
29
#define FREF                14318180
 
30
#define MIN_VCO             FREF
 
31
#define MAX_VCO             230000000
 
32
#define MAX_PSN             0 /* no pre scaler for this chip */
 
33
#define TOLERANCE           0.01  /* search smallest M and N in this tolerance */
 
34
#define max_VLD 1
 
35
 
 
36
/*
 
37
 * Compute clock values given target frequency
 
38
 */
 
39
void 
 
40
sisGetClock (unsigned long clock, SisCrtc *crtc)
 
41
{
 
42
    unsigned char   reg7, reg13, reg2a, reg2b;
 
43
    int             M, N, P, VLD;
 
44
 
 
45
    int             bestM, bestN, bestP, bestPSN, bestVLD;
 
46
    double          bestError, abest = 42.0, bestFout;
 
47
 
 
48
    double          Fvco, Fout;
 
49
    double          error, aerror;
 
50
 
 
51
    double          target = (double) clock;
 
52
 
 
53
    int             M_min = 2;
 
54
    int             M_max = 128;
 
55
 
 
56
    int             low_N = 2;
 
57
    int             high_N = 32;
 
58
    int             PSN = 1;
 
59
 
 
60
    /*
 
61
     *  fd = fref*(Numerator/Denumerator)*(Divider/PostScaler)
 
62
     *
 
63
     *  M       = Numerator [1:128]
 
64
     *  N       = DeNumerator [1:32]
 
65
     *  VLD     = Divider (Vco Loop Divider) : divide by 1, 2
 
66
     *  P       = Post Scaler : divide by 1, 2, 3, 4
 
67
     *  PSN     = Pre Scaler (Reference Divisor Select)
 
68
     *
 
69
     * result in vclk[]
 
70
     */
 
71
 
 
72
    P = 1;
 
73
    if (target < MAX_VCO / 2)
 
74
        P = 2;
 
75
    if (target < MAX_VCO / 3)
 
76
        P = 3;
 
77
    if (target < MAX_VCO / 4)
 
78
        P = 4;
 
79
    if (target < MAX_VCO / 6)
 
80
        P = 6;
 
81
    if (target < MAX_VCO / 8)
 
82
        P = 8;
 
83
 
 
84
    Fvco = P * target;
 
85
 
 
86
    for (N = low_N; N <= high_N; N++)
 
87
    {
 
88
        double M_desired = Fvco / FREF * N;
 
89
 
 
90
        if (M_desired > M_max * max_VLD)
 
91
            continue;
 
92
 
 
93
        if ( M_desired > M_max ) 
 
94
        {
 
95
            M = (int)(M_desired / 2 + 0.5);
 
96
            VLD = 2;
 
97
        }
 
98
        else 
 
99
        {
 
100
            M = (int)(M_desired + 0.5);
 
101
            VLD = 1;
 
102
        }
 
103
 
 
104
        Fout = (double)FREF * (M * VLD)/(N * P);
 
105
        error = (target - Fout) / target;
 
106
        aerror = (error < 0) ? -error : error;
 
107
        if (aerror < abest) 
 
108
        {
 
109
            abest = aerror;
 
110
            bestError = error;
 
111
            bestM = M;
 
112
            bestN = N;
 
113
            bestP = P;
 
114
            bestPSN = PSN;
 
115
            bestVLD = VLD;
 
116
            bestFout = Fout;
 
117
        }
 
118
    }
 
119
 
 
120
    crtc->vclk_numerator = bestM - 1;
 
121
    crtc->vclk_divide_by_2 = bestVLD == 2;
 
122
 
 
123
    crtc->vclk_denominator = bestN - 1;
 
124
    switch (bestP) {
 
125
    case 1:
 
126
        crtc->vclk_post_scale = SIS_VCLK_POST_SCALE_1;
 
127
        crtc->vclk_post_scale_2 = 0;
 
128
        break;
 
129
    case 2:
 
130
        crtc->vclk_post_scale = SIS_VCLK_POST_SCALE_2;
 
131
        crtc->vclk_post_scale_2 = 0;
 
132
        break;
 
133
    case 3:
 
134
        crtc->vclk_post_scale = SIS_VCLK_POST_SCALE_3;
 
135
        crtc->vclk_post_scale_2 = 0;
 
136
        break;
 
137
    case 4:
 
138
        crtc->vclk_post_scale = SIS_VCLK_POST_SCALE_4;
 
139
        crtc->vclk_post_scale_2 = 0;
 
140
        break;
 
141
    case 6:
 
142
        crtc->vclk_post_scale = SIS_VCLK_POST_SCALE_3;
 
143
        crtc->vclk_post_scale_2 = 1;
 
144
        break;
 
145
    case 8:
 
146
        crtc->vclk_post_scale = SIS_VCLK_POST_SCALE_4;
 
147
        crtc->vclk_post_scale_2 = 1;
 
148
        break;
 
149
    }
 
150
 
 
151
    crtc->vclk_vco_gain = 1;
 
152
 
 
153
    /*
 
154
     * Don't know how to set mclk for local frame buffer; for
 
155
     * shared frame buffer, mclk is hardwired to bus speed (100MHz)?
 
156
     */
 
157
}
 
158
 
 
159
sisCalcMclk (SisCrtc *crtc)
 
160
{
 
161
    int mclk, Numer, DeNumer;
 
162
    double Divider, Scalar;
 
163
 
 
164
    Numer = crtc->mclk_numerator;
 
165
    DeNumer = crtc->mclk_denominator;
 
166
    Divider = crtc->mclk_divide_by_2 ? 2.0 : 1.0;
 
167
    Scalar = 1.0;
 
168
    if (crtc->mclk_post_scale_2)
 
169
    {
 
170
        switch (crtc->mclk_post_scale) {
 
171
        case 2:
 
172
            Scalar = 6.0;
 
173
            break;
 
174
        case 3:
 
175
            Scalar = 8.0;
 
176
            break;
 
177
        }
 
178
    }
 
179
    else
 
180
    {
 
181
        switch (crtc->mclk_post_scale) {
 
182
        case 0:
 
183
            Scalar = 1.0;
 
184
            break;
 
185
        case 1:
 
186
            Scalar = 2.0;
 
187
            break;
 
188
        case 2:
 
189
            Scalar = 3.0;
 
190
            break;
 
191
        case 3:
 
192
            Scalar = 4.0;
 
193
            break;
 
194
        }
 
195
    }
 
196
 
 
197
    mclk = (int)(FREF*((double)(Numer+1)/(double)(DeNumer+1))*(Divider/Scalar));
 
198
 
 
199
    return(mclk);
 
200
}
 
201
 
 
202
#define UMA_FACTOR      60
 
203
#define LFB_FACTOR      30      // Only if local frame buffer
 
204
#define SIS_SAYS_SO     0x1F    // But how is the performance??
 
205
#define CRT_ENG_THRESH  0x0F    // But how is the performance??
 
206
#define BUS_WIDTH       64
 
207
#define DFP_BUS_WIDTH   32      // rumour has it for digital flat panel ??
 
208
#define MEGAHZ          (1<<20)
 
209
 
 
210
void
 
211
sisEngThresh (SisCrtc *crtc, unsigned long vclk, int bpp)
 
212
{
 
213
    int threshlow, mclk;
 
214
 
 
215
    mclk = sisCalcMclk(crtc) / 1000000;
 
216
    vclk = vclk / 1000000;
 
217
    threshlow = ((((UMA_FACTOR*vclk*bpp)/
 
218
                   (mclk*BUS_WIDTH))+1)/2)+4;
 
219
    
 
220
    crtc->crt_cpu_threshold_low_0_3 = threshlow;
 
221
    crtc->crt_cpu_threshold_low_4 = threshlow >> 4;
 
222
    
 
223
    crtc->crt_cpu_threshold_high_0_3 = (SIS_SAYS_SO & 0xf);
 
224
    crtc->crt_cpu_threshold_high_4 = 0;
 
225
    
 
226
    crtc->crt_engine_threshold_high_0_3 = CRT_ENG_THRESH;
 
227
    crtc->crt_engine_threshold_high_4 = 1;
 
228
    
 
229
    crtc->ascii_attribute_threshold_0_2 = (SIS_SAYS_SO >> 4);
 
230
    
 
231
    crtc->crt_threshold_full_control = SIS_CRT_64_STAGE_THRESHOLD;
 
232
}