~ubuntu-branches/ubuntu/edgy/xorg-server/edgy-updates

« back to all changes in this revision

Viewing changes to hw/kdrive/mach64/mach64.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Parra Novo
  • Date: 2006-07-25 20:06:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060725200628-gjmmd9gxfxdc4ejs
Tags: 1:1.1.1-0ubuntu1
* New Upstream version
* Changed Build-Depends from mesa-swrast-source to mesa-swx11-source,
  following Debian package nomenclature
* Re-did 12_security_policy_in_etc.diff for 1.1.1
* Dropped 15_security_allocate_local.diff (applied upstream)
* Dropped 16_SECURITY_setuid.diff (applied upstream)
* Dropped 000_ubuntu_fix_read_kernel_mapping.patch (applied upstream)
* Dropped 002_ubuntu_fix_for_certain_intel_chipsets.patch (applied upstream)
* Updated versioned Build-Depends on mesa-swx11-source to version
  6.5.0.cvs.20060725-0ubuntu1
* Added arrayobj.c, arrayobj.h, bitset.h & rbadaptors.h to
  GL/symlink-mesa.sh (linked from mesa-swx11-source)
* Added arrayobj.c to default build target on GL/mesa/main

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright � 2001 Keith Packard
 
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 Keith Packard not be used in
 
9
 * advertising or publicity pertaining to distribution of the software without
 
10
 * specific, written prior permission.  Keith Packard makes no
 
11
 * representations about the suitability of this software for any purpose.  It
 
12
 * is provided "as is" without express or implied warranty.
 
13
 *
 
14
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
15
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
16
 * EVENT SHALL KEITH PACKARD 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
/* $RCSId: xc/programs/Xserver/hw/kdrive/mach64/mach64.c,v 1.10 2002/10/14 18:01:41 keithp Exp $ */
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <kdrive-config.h>
 
26
#endif
 
27
#include "mach64.h"
 
28
#include "kaa.h"
 
29
 
 
30
static Bool
 
31
mach64CardInit (KdCardInfo *card)
 
32
{
 
33
    Mach64CardInfo      *mach64c;
 
34
 
 
35
    mach64c = (Mach64CardInfo *) xalloc (sizeof (Mach64CardInfo));
 
36
    if (!mach64c)
 
37
        return FALSE;
 
38
    
 
39
    (void) mach64MapReg (card, mach64c);
 
40
    mach64c->lcdEnabled = FALSE;
 
41
    
 
42
    if (!vesaInitialize (card, &mach64c->vesa))
 
43
    {
 
44
        xfree (mach64c);
 
45
        return FALSE;
 
46
    }
 
47
 
 
48
    card->driver = mach64c;
 
49
    
 
50
    return TRUE;
 
51
}
 
52
 
 
53
static Bool
 
54
mach64ScreenInit (KdScreenInfo *screen)
 
55
{
 
56
    Mach64CardInfo      *mach64c = screen->card->driver;
 
57
    Mach64ScreenInfo    *mach64s;
 
58
 
 
59
    mach64s = (Mach64ScreenInfo *) xalloc (sizeof (Mach64ScreenInfo));
 
60
    if (!mach64s)
 
61
        return FALSE;
 
62
    memset (mach64s, '\0', sizeof (Mach64ScreenInfo));
 
63
    if (!vesaScreenInitialize (screen, &mach64s->vesa))
 
64
    {
 
65
        xfree (mach64s);
 
66
        return FALSE;
 
67
    }
 
68
    if (!mach64c->reg)
 
69
        screen->dumb = TRUE;
 
70
    if (mach64s->vesa.mapping != VESA_LINEAR)
 
71
        screen->dumb = TRUE;
 
72
    switch (screen->fb[0].depth) {
 
73
    case 8:
 
74
        mach64s->colorKey = 0xff;
 
75
        break;
 
76
    case 15:
 
77
    case 16:
 
78
        mach64s->colorKey = 0x001e;
 
79
        break;
 
80
    case 24:
 
81
        mach64s->colorKey = 0x0000fe;
 
82
        break;
 
83
    default:
 
84
        mach64s->colorKey = 1;
 
85
        break;
 
86
    }
 
87
    screen->driver = mach64s;
 
88
    return TRUE;
 
89
}
 
90
 
 
91
static Bool
 
92
mach64InitScreen (ScreenPtr pScreen)
 
93
{
 
94
#ifdef XV
 
95
    mach64InitVideo(pScreen);
 
96
#endif
 
97
    return vesaInitScreen (pScreen);
 
98
}
 
99
 
 
100
#ifdef RANDR
 
101
static Bool
 
102
mach64RandRSetConfig (ScreenPtr         pScreen,
 
103
                      Rotation          rotation,
 
104
                      int               rate,
 
105
                      RRScreenSizePtr   pSize)
 
106
{
 
107
   kaaWaitSync (pScreen);
 
108
 
 
109
    if (!vesaRandRSetConfig (pScreen, rotation, rate, pSize))
 
110
        return FALSE;
 
111
    
 
112
    return TRUE;
 
113
}
 
114
 
 
115
static void
 
116
mach64RandRInit (ScreenPtr pScreen)
 
117
{
 
118
    rrScrPriv(pScreen);
 
119
 
 
120
    pScrPriv->rrSetConfig = mach64RandRSetConfig;
 
121
}
 
122
#endif
 
123
 
 
124
static Bool
 
125
mach64FinishInitScreen (ScreenPtr pScreen)
 
126
{
 
127
    Bool    ret;
 
128
    ret = vesaFinishInitScreen (pScreen);
 
129
#ifdef RANDR
 
130
    mach64RandRInit (pScreen);
 
131
#endif
 
132
    return ret;
 
133
}
 
134
 
 
135
static Bool
 
136
mach64CreateResources (ScreenPtr pScreen)
 
137
{
 
138
    return vesaCreateResources (pScreen);
 
139
}
 
140
 
 
141
CARD32
 
142
mach64ReadLCD (Reg *reg, int id)
 
143
{
 
144
    CARD32  LCD_INDEX;
 
145
 
 
146
    LCD_INDEX = reg->LCD_INDEX & ~(0x3f);
 
147
    reg->LCD_INDEX = (LCD_INDEX | id);
 
148
    return reg->LCD_DATA;
 
149
}
 
150
 
 
151
void
 
152
mach64WriteLCD (Reg *reg, int id, CARD32 data)
 
153
{
 
154
    CARD32  LCD_INDEX;
 
155
 
 
156
    LCD_INDEX = reg->LCD_INDEX & ~(0x3f);
 
157
    reg->LCD_INDEX = (LCD_INDEX | id);
 
158
    reg->LCD_DATA = data;
 
159
}
 
160
 
 
161
void
 
162
mach64Preserve (KdCardInfo *card)
 
163
{
 
164
    Mach64CardInfo      *mach64c = card->driver;
 
165
    Reg                 *reg = mach64c->reg;
 
166
 
 
167
    vesaPreserve(card);
 
168
    if (reg)
 
169
    {
 
170
        mach64c->save.LCD_GEN_CTRL = mach64ReadLCD (reg, 1);
 
171
    }
 
172
}
 
173
 
 
174
Bool
 
175
mach64MapReg (KdCardInfo *card, Mach64CardInfo *mach64c)
 
176
{
 
177
    mach64c->reg_base = (CARD8 *) KdMapDevice (MACH64_REG_BASE(card),
 
178
                                               MACH64_REG_SIZE(card));
 
179
    
 
180
    if (!mach64c->reg_base)
 
181
    {
 
182
        mach64c->reg = 0;
 
183
        mach64c->media_reg = 0;
 
184
        return FALSE;
 
185
    }
 
186
    
 
187
    KdSetMappedMode (MACH64_REG_BASE(card),
 
188
                     MACH64_REG_SIZE(card),
 
189
                     KD_MAPPED_MODE_REGISTERS);
 
190
    mach64c->reg = (Reg *) (mach64c->reg_base + MACH64_REG_OFF(card));
 
191
    mach64c->media_reg = (MediaReg *) (mach64c->reg_base + MACH64_MEDIA_REG_OFF(card));
 
192
    return TRUE;
 
193
}
 
194
 
 
195
void
 
196
mach64UnmapReg (KdCardInfo *card, Mach64CardInfo *mach64c)
 
197
{
 
198
    if (mach64c->reg_base)
 
199
    {
 
200
        KdResetMappedMode (MACH64_REG_BASE(card),
 
201
                           MACH64_REG_SIZE(card),
 
202
                           KD_MAPPED_MODE_REGISTERS);
 
203
        KdUnmapDevice ((void *) mach64c->reg_base, MACH64_REG_SIZE(card));
 
204
        mach64c->reg_base = 0;
 
205
        mach64c->reg = 0;
 
206
        mach64c->media_reg = 0;
 
207
    }
 
208
}
 
209
 
 
210
void
 
211
mach64SetMMIO (KdCardInfo *card, Mach64CardInfo *mach64c)
 
212
{
 
213
    if (!mach64c->reg_base)
 
214
        mach64MapReg (card, mach64c);
 
215
    if (mach64c->reg)
 
216
    {
 
217
        if (mach64c->reg->GUI_STAT == 0xffffffff)
 
218
            FatalError ("Mach64 REG not visible\n");
 
219
    }
 
220
}
 
221
 
 
222
void
 
223
mach64ResetMMIO (KdCardInfo *card, Mach64CardInfo *mach64c)
 
224
{
 
225
    mach64UnmapReg (card, mach64c);
 
226
}
 
227
 
 
228
Bool
 
229
mach64Enable (ScreenPtr pScreen)
 
230
{
 
231
    KdScreenPriv(pScreen);
 
232
    Mach64CardInfo      *mach64c = pScreenPriv->card->driver;
 
233
 
 
234
    if (!vesaEnable (pScreen))
 
235
        return FALSE;
 
236
    
 
237
    mach64SetMMIO (pScreenPriv->card, mach64c);
 
238
    mach64DPMS (pScreen, KD_DPMS_NORMAL);
 
239
#ifdef XV
 
240
    KdXVEnable (pScreen);
 
241
#endif
 
242
    return TRUE;
 
243
}
 
244
 
 
245
void
 
246
mach64Disable (ScreenPtr pScreen)
 
247
{
 
248
    KdScreenPriv(pScreen);
 
249
    Mach64CardInfo      *mach64c = pScreenPriv->card->driver;
 
250
 
 
251
#ifdef XV
 
252
    KdXVDisable (pScreen);
 
253
#endif
 
254
    mach64ResetMMIO (pScreenPriv->card, mach64c);
 
255
    vesaDisable (pScreen);
 
256
}
 
257
 
 
258
const CARD8     mach64DPMSModes[4] = {
 
259
    0x80,           /* KD_DPMS_NORMAL */
 
260
    0x8c,           /* KD_DPMS_STANDBY */
 
261
    0x8c,           /* KD_DPMS_STANDBY */
 
262
    0x8c,           /* KD_DPMS_STANDBY */
 
263
/*    0xb0,            KD_DPMS_SUSPEND */
 
264
/*    0xbc,            KD_DPMS_POWERDOWN */
 
265
};
 
266
 
 
267
#define PWR_MGT_ON                  (1 << 0)
 
268
#define PWR_MGT_MODE                (3 << 1)
 
269
#define  PWR_MGT_MODE_PIN           (0 << 1)
 
270
#define  PWR_MGT_MODE_REG           (1 << 1)
 
271
#define  PWR_MGT_MODE_TIMER         (2 << 1)
 
272
#define  PWR_MGR_MODE_PCI           (3 << 1)
 
273
#define AUTO_PWRUP_EN               (1 << 3)
 
274
#define ACTIVITY_PIN_ON             (1 << 4)
 
275
#define STANDBY_POL                 (1 << 5)
 
276
#define SUSPEND_POL                 (1 << 6)
 
277
#define SELF_REFRESH                (1 << 7)
 
278
#define ACTIVITY_PIN_EN             (1 << 8)
 
279
#define KEYBD_SNOOP                 (1 << 9)
 
280
#define DONT_USE_F32KHZ             (1 << 10)
 
281
#define TRISTATE_MEM_EN             (1 << 11)
 
282
#define LCDENG_TEST_MODE            (0xf << 12)
 
283
#define STANDBY_COUNT               (0xf << 16)
 
284
#define SUSPEND_COUNT               (0xf << 20)
 
285
#define BIASON                      (1 << 24)
 
286
#define BLON                        (1 << 25)
 
287
#define DIGON                       (1 << 26)
 
288
#define PM_D3_RST_ENB               (1 << 27)
 
289
#define STANDBY_NOW                 (1 << 28)
 
290
#define SUSPEND_NOW                 (1 << 29)
 
291
#define PWR_MGT_STATUS              (3 << 30)
 
292
#define  PWR_MGT_STATUS_ON          (0 << 30)
 
293
#define  PWR_MGT_STATUS_STANDBY     (1 << 30)
 
294
#define  PWR_MGT_STATUS_SUSPEND     (2 << 30)
 
295
#define  PWR_MGT_STATUS_TRANSITION  (3 << 30)
 
296
 
 
297
Bool
 
298
mach64DPMS (ScreenPtr pScreen, int mode)
 
299
{
 
300
    KdScreenPriv(pScreen);
 
301
    Mach64CardInfo      *mach64c = pScreenPriv->card->driver;
 
302
    int                 hsync_off = 0, vsync_off = 0, blank = 0;
 
303
    CARD32              CRTC_GEN_CNTL;
 
304
    CARD32              LCD_GEN_CTRL;
 
305
    Reg                 *reg = mach64c->reg;
 
306
 
 
307
    if (!reg)
 
308
        return FALSE;
 
309
    
 
310
    CRTC_GEN_CNTL = reg->CRTC_GEN_CNTL;
 
311
    LCD_GEN_CTRL = mach64ReadLCD (reg, 1);
 
312
 
 
313
    switch (mode) {
 
314
    case KD_DPMS_NORMAL:
 
315
        hsync_off = 0;
 
316
        vsync_off = 0;
 
317
        blank = 0;
 
318
        break;
 
319
    case KD_DPMS_STANDBY:
 
320
        hsync_off = 1;
 
321
        vsync_off = 0;
 
322
        blank = 1;
 
323
        break;
 
324
    case KD_DPMS_SUSPEND:
 
325
        hsync_off = 0;
 
326
        vsync_off = 1;
 
327
        blank = 1;
 
328
        break;
 
329
    case KD_DPMS_POWERDOWN:
 
330
        hsync_off = 1;
 
331
        vsync_off = 1;
 
332
        blank = 1;
 
333
    }
 
334
    
 
335
    if (hsync_off)
 
336
        CRTC_GEN_CNTL |= (1 << 2);
 
337
    else
 
338
        CRTC_GEN_CNTL &= ~(1 << 2);
 
339
    if (vsync_off)
 
340
        CRTC_GEN_CNTL |= (1 << 3);
 
341
    else
 
342
        CRTC_GEN_CNTL &= ~(1 << 3);
 
343
    if (blank)
 
344
    {
 
345
        mach64c->lcdEnabled = (LCD_GEN_CTRL & (1 << 1)) != 0;
 
346
        LCD_GEN_CTRL &= ~(1 << 1);
 
347
        CRTC_GEN_CNTL |= (1 << 6);
 
348
        
 
349
    }
 
350
    else
 
351
    {
 
352
        if (!(LCD_GEN_CTRL & 3) || mach64c->lcdEnabled)
 
353
            LCD_GEN_CTRL |= (1 << 1);
 
354
        CRTC_GEN_CNTL &= ~(1 << 6);
 
355
    }
 
356
    
 
357
    kaaWaitSync (pScreen);
 
358
 
 
359
    mach64WriteLCD (reg, 1, LCD_GEN_CTRL);
 
360
    
 
361
    reg->CRTC_GEN_CNTL = CRTC_GEN_CNTL;
 
362
    return TRUE;
 
363
}
 
364
 
 
365
static void
 
366
mach64Restore (KdCardInfo *card)
 
367
{
 
368
    Mach64CardInfo      *mach64c = card->driver;
 
369
    Reg                 *reg = mach64c->reg;
 
370
 
 
371
    if (reg)
 
372
    {
 
373
        mach64WriteLCD (reg, 1, mach64c->save.LCD_GEN_CTRL);
 
374
    }
 
375
    mach64ResetMMIO (card, mach64c);
 
376
    vesaRestore (card);
 
377
}
 
378
 
 
379
static void
 
380
mach64ScreenFini (KdScreenInfo *screen)
 
381
{
 
382
    Mach64ScreenInfo    *mach64s = (Mach64ScreenInfo *) screen->driver;
 
383
#ifdef XV
 
384
    mach64FiniVideo(screen->pScreen);
 
385
#endif
 
386
    vesaScreenFini (screen);
 
387
    xfree (mach64s);
 
388
    screen->driver = 0;
 
389
}
 
390
 
 
391
static void
 
392
mach64CardFini (KdCardInfo *card)
 
393
{
 
394
    Mach64CardInfo      *mach64c = card->driver;
 
395
 
 
396
    mach64UnmapReg (card, mach64c);
 
397
    vesaCardFini (card);
 
398
    xfree (mach64c);
 
399
}
 
400
 
 
401
#define mach64CursorInit 0       /* initCursor */
 
402
#define mach64CursorEnable 0    /* enableCursor */
 
403
#define mach64CursorDisable 0   /* disableCursor */
 
404
#define mach64CursorFini 0       /* finiCursor */
 
405
#define mach64RecolorCursor 0   /* recolorCursor */
 
406
 
 
407
KdCardFuncs     mach64Funcs = {
 
408
    mach64CardInit,         /* cardinit */
 
409
    mach64ScreenInit,       /* scrinit */
 
410
    mach64InitScreen,       /* initScreen */
 
411
    mach64FinishInitScreen, /* finishInitScreen */
 
412
    mach64CreateResources,  /* createRes */
 
413
    mach64Preserve,         /* preserve */
 
414
    mach64Enable,           /* enable */
 
415
    mach64DPMS,             /* dpms */
 
416
    mach64Disable,          /* disable */
 
417
    mach64Restore,          /* restore */
 
418
    mach64ScreenFini,       /* scrfini */
 
419
    mach64CardFini,         /* cardfini */
 
420
    
 
421
    mach64CursorInit,       /* initCursor */
 
422
    mach64CursorEnable,     /* enableCursor */
 
423
    mach64CursorDisable,    /* disableCursor */
 
424
    mach64CursorFini,       /* finiCursor */
 
425
    mach64RecolorCursor,    /* recolorCursor */
 
426
    
 
427
    mach64DrawInit,         /* initAccel */
 
428
    mach64DrawEnable,       /* enableAccel */
 
429
    mach64DrawDisable,      /* disableAccel */
 
430
    mach64DrawFini,         /* finiAccel */
 
431
    
 
432
    vesaGetColors,          /* getColors */
 
433
    vesaPutColors,          /* putColors */
 
434
};