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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/kdrive/sis530/sis.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: sis.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/sis.c,v 1.6 2000/09/03 05:11:19 keithp Exp $ */
 
25
 
 
26
#include "sis.h"
 
27
 
 
28
#define MAX_FB_SIZE     (4096 * 1024)
 
29
 
 
30
#define MMIO_SIZE       (64 * 1024)
 
31
 
 
32
int sisMemoryTable[8] = {
 
33
    1, 2, 4, 0, 0, 2, 4, 8
 
34
};
 
35
 
 
36
Bool
 
37
sisCardInit (KdCardInfo *card)
 
38
{
 
39
    SisCardInfo     *sisc;
 
40
    SisPtr          sis;
 
41
    int             size;
 
42
    CARD8           *registers;
 
43
    CARD8           *temp_buffer;
 
44
    CARD8           save_sr5;
 
45
 
 
46
    sisc = (SisCardInfo *) xalloc (sizeof (SisCardInfo));
 
47
    if (!sisc)
 
48
        goto bail0;
 
49
    
 
50
    sisc->io_base = card->attr.io;
 
51
    /*
 
52
     * enable access to SiS ports (no MMIO available) 
 
53
     */
 
54
    iopl(3);
 
55
    save_sr5 = GetSrtc(sisc,0x5);
 
56
    if (save_sr5 != 0x21)
 
57
        save_sr5 = 0x86;
 
58
    PutSrtc(sisc,0x5,0x86);
 
59
#if 0
 
60
    {
 
61
        int     i;
 
62
 
 
63
        for (i = 0; i <= 0x3f; i++)
 
64
            fprintf (stderr, "SR%02x = %02x\n", i, GetSrtc(sisc,i));
 
65
    }
 
66
#endif
 
67
    sisc->memory = sisMemoryTable[GetSrtc(sisc,0xc)&0x7] * 1024 * 1024;
 
68
 
 
69
    PutSrtc(sisc,0x5,save_sr5);
 
70
    
 
71
    if (!sisc->memory)
 
72
    {
 
73
        ErrorF ("Can't detect SiS530 frame buffer\n");
 
74
        goto bail1;
 
75
    }
 
76
 
 
77
    /*
 
78
     * Map frame buffer and MMIO registers
 
79
     */
 
80
    sisc->frameBuffer = KdMapDevice (card->attr.address[0], sisc->memory);
 
81
    if (!sisc->frameBuffer)
 
82
        goto bail1;
 
83
    
 
84
    sisc->registers = KdMapDevice (card->attr.address[1], MMIO_SIZE);
 
85
    if (!sisc->registers)
 
86
        goto bail2;
 
87
    
 
88
    /*
 
89
     * Offset from base of MMIO to registers
 
90
     */
 
91
    sisc->sis = (SisPtr) (sisc->registers + SIS_MMIO_OFFSET);
 
92
    sisc->cpu_bitblt = (VOL32 *) sisc->registers;
 
93
 
 
94
    card->driver = sisc;
 
95
    
 
96
    return TRUE;
 
97
bail2:
 
98
    KdUnmapDevice (sisc->frameBuffer, sisc->memory);
 
99
bail1:
 
100
    xfree (sisc);
 
101
bail0:
 
102
    return FALSE;
 
103
}
 
104
 
 
105
Bool
 
106
sisModeSupported (KdScreenInfo *screen, const KdMonitorTiming *t)
 
107
{
 
108
    if (t->horizontal != 1600 &&
 
109
        t->horizontal != 1280 &&
 
110
        t->horizontal != 1152 &&
 
111
        t->horizontal != 1024 &&
 
112
        t->horizontal != 800 &&
 
113
        t->horizontal != 640)
 
114
        return FALSE;
 
115
    return TRUE;
 
116
}
 
117
 
 
118
Bool
 
119
sisModeUsable (KdScreenInfo *screen)
 
120
{
 
121
    KdCardInfo      *card = screen->card;
 
122
    SisCardInfo     *sisc = (SisCardInfo *) card->driver;
 
123
    SisScreenInfo   *siss;
 
124
    int             i;
 
125
    KdMonitorTiming *t;
 
126
    CARD32          memory;
 
127
    int             byte_width, pixel_width, screen_size;
 
128
    
 
129
    if (screen->fb[0].depth >= 24)
 
130
    {
 
131
        screen->fb[0].depth = 24;
 
132
        screen->fb[0].bitsPerPixel = 24;
 
133
        screen->dumb = TRUE;
 
134
    }
 
135
    else if (screen->fb[0].depth >= 16)
 
136
    {
 
137
        screen->fb[0].depth = 16;
 
138
        screen->fb[0].bitsPerPixel = 16;
 
139
    }
 
140
    else if (screen->fb[0].depth >= 15)
 
141
    {
 
142
        screen->fb[0].depth = 15;
 
143
        screen->fb[0].bitsPerPixel = 16;
 
144
    }
 
145
    else
 
146
    {
 
147
        screen->fb[0].depth = 8;
 
148
        screen->fb[0].bitsPerPixel = 8;
 
149
    }
 
150
    byte_width = screen->width * (screen->fb[0].bitsPerPixel >> 3);
 
151
    pixel_width = screen->width;
 
152
    screen->fb[0].pixelStride = pixel_width;
 
153
    screen->fb[0].byteStride = byte_width;
 
154
 
 
155
    screen_size = byte_width * screen->height;
 
156
 
 
157
    return screen_size <= sisc->memory;
 
158
}
 
159
 
 
160
Bool
 
161
sisScreenInit (KdScreenInfo *screen)
 
162
{
 
163
    KdCardInfo      *card = screen->card;
 
164
    SisCardInfo     *sisc = (SisCardInfo *) card->driver;
 
165
    SisScreenInfo   *siss;
 
166
    int             i;
 
167
    const KdMonitorTiming *t;
 
168
    CARD32          memory;
 
169
    int             byte_width, pixel_width, screen_size;
 
170
 
 
171
    siss = (SisScreenInfo *) xalloc (sizeof (SisScreenInfo));
 
172
    if (!siss)
 
173
        return FALSE;
 
174
 
 
175
    memset (siss, '\0', sizeof (SisScreenInfo));
 
176
 
 
177
    if (!screen->width || !screen->height)
 
178
    {
 
179
        screen->width = 800;
 
180
        screen->height = 600;
 
181
        screen->rate = 72;
 
182
    }
 
183
    if (!screen->fb[0].depth)
 
184
        screen->fb[0].depth = 8;
 
185
    
 
186
    t = KdFindMode (screen, sisModeSupported);
 
187
    
 
188
    screen->rate = t->rate;
 
189
    screen->width = t->horizontal;
 
190
    screen->height = t->vertical;
 
191
    
 
192
    if (!KdTuneMode (screen, sisModeUsable, sisModeSupported))
 
193
    {
 
194
        xfree (sisc);
 
195
        return FALSE;
 
196
    }
 
197
 
 
198
    memory = sisc->memory - screen_size;
 
199
    
 
200
    screen->fb[0].frameBuffer = sisc->frameBuffer;
 
201
    
 
202
    /*
 
203
     * Cursor lives in the last 16k of memory
 
204
     */
 
205
    if (memory >= 16384 && !screen->softCursor)
 
206
    {
 
207
        siss->cursor_base = sisc->frameBuffer + (sisc->memory - 16384);
 
208
        siss->cursor_off = siss->cursor_base - sisc->frameBuffer;
 
209
        memory -= 16384;
 
210
    }
 
211
    else
 
212
    {
 
213
        screen->softCursor = TRUE;
 
214
        siss->cursor_base = 0;
 
215
        siss->cursor_off = 0;
 
216
    }
 
217
 
 
218
    if (memory > 8192)
 
219
    {
 
220
        siss->expand = screen->fb[0].frameBuffer + screen_size;
 
221
        siss->expand_off = siss->expand - sisc->frameBuffer;
 
222
        siss->expand_len = memory;
 
223
        memory = 0;
 
224
    }
 
225
    else
 
226
    {
 
227
        siss->expand = 0;
 
228
        siss->expand_len = 0;
 
229
    }
 
230
    
 
231
    switch (screen->fb[0].depth) {
 
232
    case 8:
 
233
        screen->fb[0].visuals = ((1 << StaticGray) |
 
234
                           (1 << GrayScale) |
 
235
                           (1 << StaticColor) |
 
236
                           (1 << PseudoColor) |
 
237
                           (1 << TrueColor) |
 
238
                           (1 << DirectColor));
 
239
        screen->fb[0].blueMask  = 0x00;
 
240
        screen->fb[0].greenMask = 0x00;
 
241
        screen->fb[0].redMask   = 0x00;
 
242
        break;
 
243
    case 15:
 
244
        screen->fb[0].visuals = (1 << TrueColor);
 
245
        screen->fb[0].blueMask  = 0x001f;
 
246
        screen->fb[0].greenMask = 0x03e0;
 
247
        screen->fb[0].redMask   = 0x7c00;
 
248
        break;
 
249
    case 16:
 
250
        screen->fb[0].visuals = (1 << TrueColor);
 
251
        screen->fb[0].blueMask  = 0x001f;
 
252
        screen->fb[0].greenMask = 0x07e0;
 
253
        screen->fb[0].redMask   = 0xf800;
 
254
        break;
 
255
    case 24:
 
256
        screen->fb[0].visuals = (1 << TrueColor);
 
257
        screen->fb[0].blueMask  = 0x0000ff;
 
258
        screen->fb[0].greenMask = 0x00ff00;
 
259
        screen->fb[0].redMask   = 0xff0000;
 
260
        break;
 
261
    }
 
262
    
 
263
    screen->driver = siss;
 
264
    
 
265
    return TRUE;
 
266
}
 
267
 
 
268
static void
 
269
_sisGetCrtc (SisCardInfo *sisc, SisCrtc *crtc)
 
270
{
 
271
    crtc->misc_output                   = _sisInb(sisc->io_base+0x4c);
 
272
    crtc->h_total_0_7                   = GetCrtc (sisc, 0x00);
 
273
    crtc->h_display_end_0_7             = GetCrtc (sisc, 0x01);
 
274
    crtc->h_blank_start_0_7             = GetCrtc (sisc, 0x02);
 
275
    crtc->_h_blank_end                  = GetCrtc (sisc, 0x03);
 
276
    crtc->h_sync_start_0_7              = GetCrtc (sisc, 0x04);
 
277
    crtc->_h_sync_end                   = GetCrtc (sisc, 0x05);
 
278
    crtc->v_total_0_7                   = GetCrtc (sisc, 0x06);
 
279
    crtc->crtc_overflow                 = GetCrtc (sisc, 0x07);
 
280
    crtc->preset_row_scan               = GetCrtc (sisc, 0x08);
 
281
    crtc->_max_scan_line                = GetCrtc (sisc, 0x09);
 
282
    crtc->cursor_start                  = GetCrtc (sisc, 0x0a);
 
283
    crtc->cursor_end                    = GetCrtc (sisc, 0x0a);
 
284
    crtc->start_address_8_15            = GetCrtc (sisc, 0x0c);
 
285
    crtc->start_address_0_7             = GetCrtc (sisc, 0x0d);
 
286
    crtc->text_cursor_15_8              = GetCrtc (sisc, 0x0e);
 
287
    crtc->text_cursor_7_0               = GetCrtc (sisc, 0x0f);
 
288
    crtc->v_retrace_start_0_7           = GetCrtc (sisc, 0x10);
 
289
    crtc->_v_retrace_end                = GetCrtc (sisc, 0x11);
 
290
    crtc->v_display_end_0_7             = GetCrtc (sisc, 0x12);
 
291
    crtc->screen_off_0_7                = GetCrtc (sisc, 0x13);
 
292
    crtc->_underline_location           = GetCrtc (sisc, 0x14);
 
293
    crtc->v_blank_start_0_7             = GetCrtc (sisc, 0x15);
 
294
    crtc->v_blank_end_0_7               = GetCrtc (sisc, 0x16);
 
295
    crtc->crtc_mode                     = GetCrtc (sisc, 0x17);
 
296
    
 
297
    crtc->line_compare_0_7              = GetCrtc (sisc, 0x18);
 
298
    
 
299
    crtc->mode_control                  = GetArtc (sisc, 0x10);
 
300
    crtc->screen_border_color           = GetArtc (sisc, 0x11);
 
301
    crtc->enable_color_plane            = GetArtc (sisc, 0x12);
 
302
    crtc->horizontal_pixel_pan          = GetArtc (sisc, 0x13);
 
303
 
 
304
    crtc->mode_register                 = GetGrtc (sisc, 0x5);
 
305
    crtc->misc_register                 = GetGrtc (sisc, 0x6);
 
306
    crtc->color_dont_care               = GetGrtc (sisc, 0x7);
 
307
    
 
308
    crtc->clock_mode                    = GetSrtc (sisc, 0x1);
 
309
    crtc->color_plane_w_enable          = GetSrtc (sisc, 0x2);
 
310
    crtc->memory_mode                   = GetSrtc (sisc, 0x4);
 
311
    
 
312
    crtc->graphics_mode                 = GetSrtc (sisc, 0x6);
 
313
    crtc->misc_control_0                = GetSrtc (sisc, 0x7);
 
314
    crtc->crt_cpu_threshold_control_0   = GetSrtc (sisc, 0x8);
 
315
    crtc->crt_cpu_threshold_control_1   = GetSrtc (sisc, 0x9);
 
316
    crtc->extended_crt_overflow         = GetSrtc (sisc, 0xa);
 
317
    crtc->misc_control_1                = GetSrtc (sisc, 0xb);
 
318
    crtc->misc_control_2                = GetSrtc (sisc, 0xc);
 
319
    
 
320
    crtc->ddc_and_power_control         = GetSrtc (sisc, 0x11);
 
321
    crtc->extended_horizontal_overflow  = GetSrtc (sisc, 0x12);
 
322
    crtc->extended_clock_generator      = GetSrtc (sisc, 0x13);
 
323
    crtc->cursor_0_red                  = GetSrtc (sisc, 0x14);
 
324
    crtc->cursor_0_green                = GetSrtc (sisc, 0x15);
 
325
    crtc->cursor_0_blue                 = GetSrtc (sisc, 0x16);
 
326
    crtc->cursor_1_red                  = GetSrtc (sisc, 0x17);
 
327
    crtc->cursor_1_green                = GetSrtc (sisc, 0x18);
 
328
    crtc->cursor_1_blue                 = GetSrtc (sisc, 0x19);
 
329
    crtc->cursor_h_start_0_7            = GetSrtc (sisc, 0x1a);
 
330
    crtc->cursor_h_start_1              = GetSrtc (sisc, 0x1b);
 
331
    crtc->cursor_h_preset_0_5           = GetSrtc (sisc, 0x1c);
 
332
    crtc->cursor_v_start_0_7            = GetSrtc (sisc, 0x1d);
 
333
    crtc->cursor_v_start_1              = GetSrtc (sisc, 0x1e);
 
334
    crtc->cursor_v_preset_0_5           = GetSrtc (sisc, 0x1f);
 
335
    crtc->linear_base_19_26             = GetSrtc (sisc, 0x20);
 
336
    crtc->linear_base_1                 = GetSrtc (sisc, 0x21);
 
337
 
 
338
    crtc->graphics_engine_0             = GetSrtc (sisc, 0x26);
 
339
    crtc->graphics_engine_1             = GetSrtc (sisc, 0x27);
 
340
    crtc->internal_mclk_0               = GetSrtc (sisc, 0x28);
 
341
    crtc->internal_mclk_1               = GetSrtc (sisc, 0x29);
 
342
    crtc->internal_vclk_0               = GetSrtc (sisc, 0x2A);
 
343
    crtc->internal_vclk_1               = GetSrtc (sisc, 0x2B);
 
344
 
 
345
    crtc->misc_control_7                = GetSrtc (sisc, 0x38);
 
346
    
 
347
    crtc->misc_control_11               = GetSrtc (sisc, 0x3E);
 
348
    crtc->misc_control_12               = GetSrtc (sisc, 0x3F);
 
349
}
 
350
 
 
351
static void
 
352
_sisSetBlank (SisCardInfo *sisc, Bool blank)
 
353
{
 
354
    CARD8   clock;
 
355
    
 
356
    clock = GetSrtc (sisc, 0x01);
 
357
    if (blank)
 
358
        clock |= 0x20;
 
359
    else
 
360
        clock &= ~0x20;
 
361
    PutSrtc (sisc, 0x01, clock);
 
362
}
 
363
 
 
364
static void
 
365
_sisSetCrtc (SisCardInfo *sisc, SisCrtc *crtc)
 
366
{
 
367
    _sisSetBlank (sisc, TRUE);
 
368
    PutCrtc (sisc, 0x00, crtc->h_total_0_7);
 
369
    PutCrtc (sisc, 0x01, crtc->h_display_end_0_7);
 
370
    PutCrtc (sisc, 0x02, crtc->h_blank_start_0_7);
 
371
    PutCrtc (sisc, 0x03, crtc->_h_blank_end);
 
372
    PutCrtc (sisc, 0x04, crtc->h_sync_start_0_7);
 
373
    PutCrtc (sisc, 0x05, crtc->_h_sync_end);
 
374
    PutCrtc (sisc, 0x06, crtc->v_total_0_7);
 
375
    PutCrtc (sisc, 0x07, crtc->crtc_overflow);
 
376
    PutCrtc (sisc, 0x08, crtc->preset_row_scan);
 
377
    PutCrtc (sisc, 0x09, crtc->_max_scan_line);
 
378
    PutCrtc (sisc, 0x0a, crtc->cursor_start);
 
379
    PutCrtc (sisc, 0x0b, crtc->cursor_end);
 
380
    PutCrtc (sisc, 0x0c, crtc->start_address_8_15);
 
381
    PutCrtc (sisc, 0x0d, crtc->start_address_0_7);
 
382
    PutCrtc (sisc, 0x0e, crtc->text_cursor_15_8);
 
383
    PutCrtc (sisc, 0x0f, crtc->text_cursor_7_0);
 
384
    PutCrtc (sisc, 0x10, crtc->v_retrace_start_0_7);
 
385
    PutCrtc (sisc, 0x11, crtc->_v_retrace_end);
 
386
    PutCrtc (sisc, 0x12, crtc->v_display_end_0_7);
 
387
    PutCrtc (sisc, 0x13, crtc->screen_off_0_7);
 
388
    PutCrtc (sisc, 0x14, crtc->_underline_location);
 
389
    PutCrtc (sisc, 0x15, crtc->v_blank_start_0_7);
 
390
    PutCrtc (sisc, 0x16, crtc->v_blank_end_0_7);
 
391
    PutCrtc (sisc, 0x17, crtc->crtc_mode);
 
392
    PutCrtc (sisc, 0x18, crtc->line_compare_0_7);
 
393
    
 
394
    PutArtc (sisc, 0x10, crtc->mode_control);
 
395
    PutArtc (sisc, 0x11, crtc->screen_border_color);
 
396
    PutArtc (sisc, 0x12, crtc->enable_color_plane);
 
397
    PutArtc (sisc, 0x13, crtc->horizontal_pixel_pan);
 
398
 
 
399
    PutGrtc (sisc, 0x5, crtc->mode_register);
 
400
    PutGrtc (sisc, 0x6, crtc->misc_register);
 
401
    PutGrtc (sisc, 0x7, crtc->color_dont_care);
 
402
    
 
403
    PutSrtc (sisc, 0x1, crtc->clock_mode | 0x20);
 
404
    PutSrtc (sisc, 0x2, crtc->color_plane_w_enable);
 
405
    PutSrtc (sisc, 0x4, crtc->memory_mode);
 
406
    
 
407
    PutSrtc (sisc, 0x6, crtc->graphics_mode);
 
408
    PutSrtc (sisc, 0x7, crtc->misc_control_0);
 
409
    PutSrtc (sisc, 0x8, crtc->crt_cpu_threshold_control_0);
 
410
    PutSrtc (sisc, 0x9, crtc->crt_cpu_threshold_control_1);
 
411
    PutSrtc (sisc, 0xa, crtc->extended_crt_overflow);
 
412
    PutSrtc (sisc, 0xb, crtc->misc_control_1);
 
413
    PutSrtc (sisc, 0xc, crtc->misc_control_2);
 
414
    
 
415
    PutSrtc (sisc, 0x11, crtc->ddc_and_power_control);
 
416
    PutSrtc (sisc, 0x12, crtc->extended_horizontal_overflow);
 
417
    PutSrtc (sisc, 0x13, crtc->extended_clock_generator);
 
418
    PutSrtc (sisc, 0x14, crtc->cursor_0_red);
 
419
    PutSrtc (sisc, 0x15, crtc->cursor_0_green);
 
420
    PutSrtc (sisc, 0x16, crtc->cursor_0_blue);
 
421
    PutSrtc (sisc, 0x17, crtc->cursor_1_red);
 
422
    PutSrtc (sisc, 0x18, crtc->cursor_1_green);
 
423
    PutSrtc (sisc, 0x19, crtc->cursor_1_blue);
 
424
    PutSrtc (sisc, 0x1a, crtc->cursor_h_start_0_7);
 
425
    PutSrtc (sisc, 0x1b, crtc->cursor_h_start_1);
 
426
    PutSrtc (sisc, 0x1c, crtc->cursor_h_preset_0_5);
 
427
    PutSrtc (sisc, 0x1d, crtc->cursor_v_start_0_7);
 
428
    PutSrtc (sisc, 0x1e, crtc->cursor_v_start_1);
 
429
    PutSrtc (sisc, 0x1f, crtc->cursor_v_preset_0_5);
 
430
    PutSrtc (sisc, 0x20, crtc->linear_base_19_26);
 
431
    PutSrtc (sisc, 0x21, crtc->linear_base_1);
 
432
 
 
433
    PutSrtc (sisc, 0x26, crtc->graphics_engine_0);
 
434
    PutSrtc (sisc, 0x27, crtc->graphics_engine_1);
 
435
    PutSrtc (sisc, 0x28, crtc->internal_mclk_0);
 
436
    PutSrtc (sisc, 0x29, crtc->internal_mclk_1);
 
437
    PutSrtc (sisc, 0x2A, crtc->internal_vclk_0);
 
438
    PutSrtc (sisc, 0x2B, crtc->internal_vclk_1);
 
439
 
 
440
    PutSrtc (sisc, 0x38, crtc->misc_control_7);
 
441
    
 
442
    PutSrtc (sisc, 0x3E, crtc->misc_control_11);
 
443
    PutSrtc (sisc, 0x3F, crtc->misc_control_12);
 
444
    
 
445
#if 0
 
446
    PutCrtc (sisc, 0x5b, 0x27);
 
447
    PutCrtc (sisc, 0x5c, 0xe1);
 
448
    PutCrtc (sisc, 0x5d, 0x00);
 
449
 
 
450
    PutSrtc (sisc, 0x5a, 0xe6);
 
451
    PutSrtc (sisc, 0x5d, 0xa1);
 
452
    PutSrtc (sisc, 0x9a, 0xe6);
 
453
    PutSrtc (sisc, 0x9d, 0xa1);
 
454
    PutSrtc (sisc, 0xda, 0xe6);
 
455
    PutSrtc (sisc, 0xdd, 0x6c);
 
456
#endif
 
457
    
 
458
    _sisOutb(crtc->misc_output, sisc->io_base+0x42);
 
459
    
 
460
    outw (0x3c4, 0x0100);
 
461
    outw (0x3c4, 0x0300);
 
462
    
 
463
    _sisSetBlank (sisc, FALSE);
 
464
}
 
465
 
 
466
CARD8
 
467
_sisReadIndexRegister (CARD32 base, CARD8 index)
 
468
{
 
469
    CARD8   ret;
 
470
 
 
471
    _sisOutb (index, base);
 
472
    ret = _sisInb (base+1);
 
473
    return ret;
 
474
}
 
475
 
 
476
void
 
477
_sisWriteIndexRegister (CARD32 base, CARD8 index, CARD8 value)
 
478
{
 
479
    _sisOutb (index, base);
 
480
    _sisOutb (value, base+1);
 
481
}
 
482
 
 
483
CARD8
 
484
_sisReadArtc (CARD32 base, CARD8 index)
 
485
{
 
486
    CARD8   ret;
 
487
    
 
488
    _sisInb (base+0x1a);
 
489
    _sisOutb (index,base);
 
490
    ret = _sisInb (base+1);
 
491
    _sisInb (base+0x1a);
 
492
    _sisOutb (0x20,base);
 
493
    return ret;
 
494
}
 
495
 
 
496
void
 
497
_sisWriteArtc (CARD32 base, CARD8 index, CARD8 value)
 
498
{
 
499
    _sisInb (base+0x1a);
 
500
    _sisOutb (index|0x20,base);
 
501
    _sisOutb (value,base);
 
502
    _sisInb (base+0x1a);
 
503
    _sisOutb (0x20,base);
 
504
}
 
505
 
 
506
void
 
507
sisPreserve (KdCardInfo *card)
 
508
{
 
509
    SisCardInfo *sisc = card->driver;
 
510
    CARD8       *r = sisc->registers;
 
511
    int         a, i, l;
 
512
    CARD8       line[16];
 
513
    CARD8       prev[16];
 
514
    BOOL        gotone;
 
515
    
 
516
    sisc->save.sr5 = GetSrtc(sisc,0x5);
 
517
    if (sisc->save.sr5 != 0x21)
 
518
        sisc->save.sr5 = 0x86;
 
519
    /* unlock extension registers */
 
520
    PutSrtc(sisc,0x5,0x86);
 
521
    /* unlock CRTC registers */
 
522
    PutCrtc(sisc,0x11,GetCrtc(sisc,0x11)&~0x80);
 
523
    /* enable vga */
 
524
    _sisOutb(0x1,sisc->io_base+0x43);
 
525
    
 
526
    /* enable MMIO access to registers */
 
527
    sisc->save.srb = GetSrtc(sisc,0xb);
 
528
    PutSrtc(sisc, 0xb, sisc->save.srb | 0x60);
 
529
    _sisGetCrtc (sisc, &sisc->save.crtc);
 
530
    memcpy (sisc->save.text_save, sisc->frameBuffer, SIS_TEXT_SAVE);
 
531
}
 
532
 
 
533
Bool
 
534
sisEnable (ScreenPtr pScreen)
 
535
{
 
536
    KdScreenPriv(pScreen);
 
537
    KdScreenInfo    *screen = pScreenPriv->screen;
 
538
    KdCardInfo      *card = pScreenPriv->card;
 
539
    SisCardInfo     *sisc = card->driver;
 
540
    SisScreenInfo   *siss = screen->driver;
 
541
    const KdMonitorTiming *t;
 
542
    SisCrtc         crtc;
 
543
    unsigned long   pixel;
 
544
    
 
545
    int     hactive;
 
546
    int     hblank;
 
547
    int     hfp;
 
548
    int     hbp;
 
549
 
 
550
    int     vactive;
 
551
    int     vblank;
 
552
    int     vfp;
 
553
    int     vbp;
 
554
 
 
555
    int     h_total;
 
556
    int     h_display_end;
 
557
    int     h_blank_start;
 
558
    int     h_blank_end;
 
559
    int     h_sync_start;
 
560
    int     h_sync_end;
 
561
    int     h_screen_off;
 
562
 
 
563
    int     h_adjust;
 
564
 
 
565
    int     v_total;
 
566
    int     v_retrace_start;
 
567
    int     v_retrace_end;
 
568
    int     v_display_end;
 
569
    int     v_blank_start;
 
570
    int     v_blank_end;
 
571
 
 
572
    crtc = sisc->save.crtc;
 
573
    
 
574
    t = KdFindMode (screen, sisModeSupported);
 
575
    
 
576
    /* CR9 */
 
577
    crtc.max_scan_line = 0;
 
578
    
 
579
    /* CRA */
 
580
    crtc.cursor_start = 0;
 
581
 
 
582
    /* CRB */
 
583
    crtc.cursor_end = 0;
 
584
    
 
585
    /* CRE */
 
586
    crtc.text_cursor_15_8 = 0;
 
587
 
 
588
    /* CRF */
 
589
    crtc.text_cursor_7_0 = 0;
 
590
    
 
591
    /* CR11 */
 
592
    crtc.disable_v_retrace_int = 1;
 
593
    
 
594
    /* CR14 */
 
595
    crtc.underline_location = 0;
 
596
    crtc.count_by_four = 0;
 
597
    crtc.doubleword_mode = 1;
 
598
    
 
599
    /* 3CC/3C2 */
 
600
    crtc.io_address_select = 1;
 
601
    crtc.display_ram_enable = 1;
 
602
    crtc.clock_select = 3;
 
603
    
 
604
    /* SR1 */
 
605
    crtc.clock_mode = 0;
 
606
    crtc.dot_clock_8_9 = 1;
 
607
 
 
608
    /* SR2 */
 
609
    crtc.color_plane_w_enable = 0xf;
 
610
 
 
611
    /* SR4 */
 
612
    crtc.memory_mode = 0;
 
613
    crtc.chain_4_enable = 1;
 
614
    crtc.odd_even_disable = 1;
 
615
    crtc.extended_memory_sz = 1;
 
616
 
 
617
    /* SR6 */
 
618
    crtc.graphics_mode_linear = 1;
 
619
    crtc.enhanced_graphics_mode = 1;
 
620
    
 
621
    /* SR9 */
 
622
    crtc.crt_cpu_threshold_control_1 = 0;
 
623
 
 
624
    /* SRB */
 
625
#if 0
 
626
    crtc.cpu_bitblt_enable = 1;
 
627
#endif
 
628
    crtc.memory_mapped_mode = 3;
 
629
    
 
630
    /* SRC */
 
631
    crtc.graphics_mode_32bit_enable = 1;
 
632
    crtc.read_ahead_enable = 1;
 
633
    
 
634
    /* SR11 */
 
635
    crtc.acpi_enable = 0;
 
636
    crtc.kbd_cursor_activate = 0;
 
637
    crtc.video_memory_activate = 0;
 
638
    crtc.vga_standby = 0;
 
639
    crtc.vga_suspend = 0;
 
640
    
 
641
    crtc.cursor_0_red = 0x3f;
 
642
    crtc.cursor_0_green = 0x3f;
 
643
    crtc.cursor_0_blue = 0x3f;
 
644
 
 
645
    /* SR20 */
 
646
    crtc.linear_base_19_26 = (card->attr.address[0] & 0x07f80000) >> 19;
 
647
 
 
648
    /* SR21 */
 
649
    crtc.linear_base_27_31 = (card->attr.address[0] & 0xf8000000) >> 27;
 
650
    crtc.linear_aperture   = SIS_LINEAR_APERTURE_4M;
 
651
     
 
652
    /* SR27 */
 
653
    crtc.logical_screen_width = 3;
 
654
    crtc.graphics_prog_enable = 1;
 
655
    
 
656
    /* SR38 */
 
657
    crtc.extended_clock_select = 0;
 
658
    
 
659
    /* AR10 */
 
660
    crtc.mode_control = 0;
 
661
    crtc.graphics_mode_enable = 1;
 
662
    /* AR11 */
 
663
    crtc.screen_border_color = 0;
 
664
    /* AR12 */
 
665
    crtc.enable_color_plane = 0xf;
 
666
    /* AR13 */
 
667
    crtc.horizontal_pixel_pan = 0;
 
668
    
 
669
    /* GR5 */
 
670
    crtc.mode_register = 0;
 
671
 
 
672
    /* GR6 */
 
673
    crtc.graphics_enable = 1;
 
674
    crtc.chain_odd_even = 0;
 
675
    crtc.memory_address_select = 1;
 
676
 
 
677
    /* GR7 */
 
678
    crtc.color_dont_care = 0xf;
 
679
    if (siss->cursor_base)
 
680
    {
 
681
        crtc_set_cursor_start_addr (&crtc, siss->cursor_off);
 
682
        crtc.graphics_mode_hw_cursor = 0;
 
683
    }
 
684
    
 
685
    hactive = t->horizontal;
 
686
    hblank = t->hblank;
 
687
    hbp = t->hbp;
 
688
    hfp = t->hfp;
 
689
    
 
690
    vactive = t->vertical;
 
691
    vblank = t->vblank;
 
692
    vbp = t->vbp;
 
693
    vfp = t->vfp;
 
694
    
 
695
    pixel = (hactive + hblank) * (vactive + vblank) * t->rate;
 
696
    
 
697
    switch (screen->fb[0].bitsPerPixel) {
 
698
    case 8:
 
699
        hactive /= 8;
 
700
        hblank /= 8;
 
701
        hfp /= 8;
 
702
        hbp /= 8;
 
703
 
 
704
        crtc.color_mode_256 = 1;
 
705
        h_screen_off = hactive;
 
706
        h_adjust = 1;
 
707
        
 
708
        break;
 
709
    case 16:
 
710
        hactive /= 8;
 
711
        hblank /= 8;
 
712
        hfp /= 8;
 
713
        hbp /= 8;
 
714
 
 
715
        h_screen_off = hactive * 2;
 
716
        h_adjust = 1;
 
717
        
 
718
        crtc.color_mode_256 = 0;
 
719
        
 
720
        if (screen->fb[0].depth == 15)
 
721
            crtc.graphics_mode_32k = 1;
 
722
        else
 
723
            crtc.graphics_mode_64k = 1;
 
724
        break;
 
725
    case 24:
 
726
        hactive /= 8;
 
727
        hblank /= 8;
 
728
        hfp /= 8;
 
729
        hbp /= 8;
 
730
        
 
731
        h_screen_off = hactive * 3;
 
732
        h_adjust = 1;
 
733
 
 
734
        crtc.color_mode_256 = 0;
 
735
        
 
736
        /* SR6 */
 
737
        crtc.graphics_mode_true = 1;
 
738
        /* SR7 */
 
739
        crtc.direct_color_24bit = 0;
 
740
        /* SR9 */
 
741
        crtc.true_color_32bpp = 0;
 
742
        /* SRB */
 
743
        crtc.true_color_order = 1;
 
744
        break;
 
745
    case 32:
 
746
        hactive /= 8;
 
747
        hblank /= 8;
 
748
        hfp /= 8;
 
749
        hbp /= 8;
 
750
        
 
751
        h_screen_off = hactive * 4;
 
752
        h_adjust = 1;
 
753
 
 
754
        crtc.color_mode_256 = 0;
 
755
        
 
756
        /* SR6 */
 
757
        crtc.graphics_mode_true = 1;
 
758
        /* SR7 */
 
759
        crtc.direct_color_24bit = 0;
 
760
        /* SR9 */
 
761
        crtc.true_color_32bpp = 1;
 
762
        /* SRB */
 
763
        crtc.true_color_order = 1;
 
764
        break;
 
765
    }
 
766
        
 
767
    sisGetClock (pixel, &crtc);
 
768
    
 
769
    crtc.high_speed_dac_0 = crtc.high_speed_dac_1 = pixel > 135000000;
 
770
    
 
771
    sisEngThresh (&crtc, pixel, screen->fb[0].bitsPerPixel);
 
772
    
 
773
    /*
 
774
     * Compute horizontal register values from timings
 
775
     */
 
776
    h_total = hactive + hblank - 5;
 
777
    h_display_end = hactive - 1;
 
778
    h_blank_start = h_display_end;
 
779
    h_blank_end = h_blank_start + hblank;
 
780
    
 
781
    h_sync_start = hactive + hfp + h_adjust;
 
782
    h_sync_end = h_sync_start + hblank - hbp - hfp;
 
783
 
 
784
    crtc_set_h_total(&crtc, h_total);
 
785
    crtc_set_h_display_end (&crtc, h_display_end);
 
786
    crtc_set_h_blank_start (&crtc, h_blank_start);
 
787
    crtc_set_h_blank_end (&crtc, h_blank_end);
 
788
    crtc_set_h_sync_start (&crtc, h_sync_start);
 
789
    crtc_set_h_sync_end (&crtc, h_sync_end);
 
790
    crtc_set_screen_off (&crtc, h_screen_off);
 
791
 
 
792
    v_total = vactive + vblank - 2;
 
793
    v_retrace_start = vactive + vfp - 1;
 
794
    v_retrace_end = v_retrace_start + vblank - vbp - vfp;
 
795
    v_display_end = vactive - 1;
 
796
    v_blank_start = vactive - 1;
 
797
    v_blank_end = v_blank_start + vblank /* - 1 */;
 
798
    
 
799
    crtc_set_v_total(&crtc, v_total);
 
800
    crtc_set_v_retrace_start (&crtc, v_retrace_start);
 
801
    crtc.v_retrace_end_0_3 = v_retrace_end;
 
802
    crtc_set_v_display_end (&crtc, v_display_end);
 
803
    crtc_set_v_blank_start (&crtc, v_blank_start);
 
804
    crtc.v_blank_end_0_7 = v_blank_end;
 
805
    
 
806
#if 0
 
807
    crtc.h_blank_start_0_7 = 0x6a;
 
808
    crtc._h_blank_end = 0x9a;
 
809
    crtc.h_sync_start_0_7 = 0x6b;
 
810
    crtc._h_sync_end = 0x9a;
 
811
    
 
812
    crtc.v_retrace_start_0_7 = 0x7d;
 
813
    crtc._v_retrace_end = 0x23;
 
814
    crtc.v_blank_start_0_7 = 0x7d;
 
815
    crtc.v_blank_end_0_7 = 0x84;
 
816
 
 
817
    crtc.crt_cpu_threshold_control_0 = 0xdf;    /* SR8 */
 
818
    crtc.crt_cpu_threshold_control_1 = 0x00;    /* SR9 */
 
819
    crtc.extended_clock_generator = 0x40;       /* SR13 */
 
820
 
 
821
    crtc.cursor_h_start_0_7 = 0x83;
 
822
    crtc.cursor_v_start_0_7 = 0x6c;
 
823
 
 
824
    crtc.internal_vclk_0 = 0x68;
 
825
    crtc.internal_vclk_1 = 0xc4;
 
826
    crtc.misc_control_7 = 0x70;
 
827
#endif
 
828
    
 
829
    _sisSetCrtc (sisc, &crtc);
 
830
    return TRUE;
 
831
}
 
832
 
 
833
Bool
 
834
sisDPMS (ScreenPtr pScreen, int mode)
 
835
{
 
836
    KdScreenPriv(pScreen);
 
837
    sisCardInfo(pScreenPriv);
 
838
    union ddc_and_power_control_u   _ddc_and_power_control_u;
 
839
 
 
840
    ddc_and_power_control = sisc->save.crtc.ddc_and_power_control;
 
841
 
 
842
    kbd_cursor_activate = 0;
 
843
    video_memory_activate = 0;
 
844
    vga_standby = 0;
 
845
    vga_suspend = 0;
 
846
    acpi_enable = 0;
 
847
    switch (mode) {
 
848
    case KD_DPMS_NORMAL:
 
849
        break;
 
850
    case KD_DPMS_STANDBY:
 
851
        vga_standby = 1;
 
852
        break;
 
853
    case KD_DPMS_SUSPEND:
 
854
        vga_suspend = 1;
 
855
        break;
 
856
    case KD_DPMS_POWERDOWN:
 
857
        acpi_enable = 1;
 
858
        break;
 
859
    }
 
860
    PutSrtc (sisc, 0x11, ddc_and_power_control);
 
861
    return TRUE;
 
862
}
 
863
 
 
864
void
 
865
sisDisable (ScreenPtr pScreen)
 
866
{
 
867
}
 
868
 
 
869
void
 
870
sisRestore (KdCardInfo *card)
 
871
{
 
872
    SisCardInfo *sisc = (SisCardInfo *) card->driver;
 
873
    
 
874
    memcpy (sisc->frameBuffer, sisc->save.text_save, SIS_TEXT_SAVE);
 
875
    _sisSetCrtc (sisc, &sisc->save.crtc);
 
876
    PutSrtc (sisc, 0xb, sisc->save.srb);
 
877
    PutSrtc (sisc, 0x5, sisc->save.sr5);
 
878
}
 
879
 
 
880
void
 
881
sisScreenFini (KdScreenInfo *screen)
 
882
{
 
883
    SisScreenInfo   *siss = (SisScreenInfo *) screen->driver;
 
884
    
 
885
    xfree (siss);
 
886
    screen->driver = 0;
 
887
}
 
888
 
 
889
void
 
890
sisCardFini (KdCardInfo *card)
 
891
{
 
892
    SisCardInfo *sisc = (SisCardInfo *) card->driver;
 
893
    
 
894
    KdUnmapDevice (sisc->frameBuffer, sisc->memory);
 
895
    KdUnmapDevice (sisc->registers, sizeof (SisRec));
 
896
}
 
897
 
 
898
KdCardFuncs     sisFuncs = {
 
899
    sisCardInit,
 
900
    sisScreenInit,
 
901
    0,
 
902
    sisPreserve,
 
903
    sisEnable,
 
904
    sisDPMS,
 
905
    sisDisable,
 
906
    sisRestore,
 
907
    sisScreenFini,
 
908
    sisCardFini,
 
909
    sisCursorInit,
 
910
    sisCursorEnable,
 
911
    sisCursorDisable,
 
912
    sisCursorFini,
 
913
    0,
 
914
    sisDrawInit,
 
915
    sisDrawEnable,
 
916
    sisDrawSync,
 
917
    sisDrawDisable,
 
918
    sisDrawFini,
 
919
    sisGetColors,
 
920
    sisPutColors,
 
921
};