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

« back to all changes in this revision

Viewing changes to hw/kdrive/ati/ati.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
 * $Id$
 
3
 *
 
4
 * Copyright � 2003 Eric Anholt
 
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 Eric Anholt not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Eric Anholt 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
 * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL ERIC ANHOLT 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
/* $Header$ */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include <kdrive-config.h>
 
28
#endif
 
29
#include "ati.h"
 
30
#include "ati_reg.h"
 
31
#if defined(USE_DRI) && defined(GLXEXT)
 
32
#include "ati_sarea.h"
 
33
#endif
 
34
 
 
35
static Bool ATIIsAGP(ATICardInfo *atic);
 
36
 
 
37
#define CAP_SERIESMASK          0xf
 
38
#define CAP_R128                0x1     /* If it's a Rage 128 */
 
39
#define CAP_R100                0x2     /* If it's an r100 series radeon. */
 
40
#define CAP_R200                0x3     /* If it's an r200 series radeon. */
 
41
#define CAP_R300                0x4     /* If it's an r300 series radeon. */
 
42
 
 
43
#define CAP_FEATURESMASK        0xf0
 
44
#define CAP_NOAGP               0x10    /* If it's a PCI-only card. */
 
45
 
 
46
struct pci_id_entry ati_pci_ids[] = {
 
47
        {0x1002, 0x4136, 0x2, "ATI Radeon RS100"},
 
48
        {0x1002, 0x4137, 0x2, "ATI Radeon RS200"},
 
49
        {0x1002, 0x4237, 0x2, "ATI Radeon RS250"},
 
50
        {0x1002, 0x4144, 0x4, "ATI Radeon R300 AD"},
 
51
        {0x1002, 0x4145, 0x4, "ATI Radeon R300 AE"},
 
52
        {0x1002, 0x4146, 0x4, "ATI Radeon R300 AF"},
 
53
        {0x1002, 0x4147, 0x4, "ATI Radeon R300 AG"},
 
54
        {0x1002, 0x4148, 0x4, "ATI Radeon R350 AH"},
 
55
        {0x1002, 0x4149, 0x4, "ATI Radeon R350 AI"},
 
56
        {0x1002, 0x414a, 0x4, "ATI Radeon R350 AJ"},
 
57
        {0x1002, 0x414b, 0x4, "ATI Radeon R350 AK"},
 
58
        {0x1002, 0x4150, 0x4, "ATI Radeon RV350 AP"},
 
59
        {0x1002, 0x4151, 0x4, "ATI Radeon RV350 AQ"},
 
60
        {0x1002, 0x4152, 0x4, "ATI Radeon RV350 AR"},
 
61
        {0x1002, 0x4153, 0x4, "ATI Radeon RV350 AS"},
 
62
        {0x1002, 0x4154, 0x4, "ATI Radeon RV350 AT"},
 
63
        {0x1002, 0x4156, 0x4, "ATI Radeon RV350 AV"},
 
64
        {0x1002, 0x4242, 0x3, "ATI Radeon R200 BB"},
 
65
        {0x1002, 0x4243, 0x3, "ATI Radeon R200 BC"},
 
66
        {0x1002, 0x4336, 0x2, "ATI Radeon RS100"},
 
67
        {0x1002, 0x4337, 0x2, "ATI Radeon RS200"},
 
68
        {0x1002, 0x4437, 0x2, "ATI Radeon RS250"},
 
69
        {0x1002, 0x4964, 0x2, "ATI Radeon RV250 Id"},
 
70
        {0x1002, 0x4965, 0x2, "ATI Radeon RV250 Ie"},
 
71
        {0x1002, 0x4966, 0x2, "ATI Radeon RV250 If"},
 
72
        {0x1002, 0x4967, 0x2, "ATI Radeon R250 Ig"},
 
73
        {0x1002, 0x4c45, 0x11, "ATI Rage 128 LE"},
 
74
        {0x1002, 0x4c46, 0x1, "ATI Rage 128 LF"},
 
75
        {0x1002, 0x4c57, 0x2, "ATI Radeon Mobiliy M7 RV200 LW (7500)"},
 
76
        {0x1002, 0x4c58, 0x2, "ATI Radeon Mobiliy M7 RV200 LX (7500)"},
 
77
        {0x1002, 0x4c59, 0x2, "ATI Radeon Mobility M6 LY"},
 
78
        {0x1002, 0x4c5a, 0x2, "ATI Radeon Mobility M6 LZ"},
 
79
        {0x1002, 0x4c64, 0x3, "ATI Radeon RV250 Ld"},
 
80
        {0x1002, 0x4c65, 0x3, "ATI Radeon RV250 Le"},
 
81
        {0x1002, 0x4c66, 0x3, "ATI Radeon Mobility M9 RV250 Lf"},
 
82
        {0x1002, 0x4c67, 0x3, "ATI Radeon RV250 Lg"},
 
83
        {0x1002, 0x4d46, 0x1, "ATI Rage 128 MF"},
 
84
        {0x1002, 0x4d46, 0x1, "ATI Rage 128 ML"},
 
85
        {0x1002, 0x4e44, 0x4, "ATI Radeon R300 ND"},
 
86
        {0x1002, 0x4e45, 0x4, "ATI Radeon R300 NE"},
 
87
        {0x1002, 0x4e46, 0x4, "ATI Radeon R300 NF"},
 
88
        {0x1002, 0x4e47, 0x4, "ATI Radeon R300 NG"},
 
89
        {0x1002, 0x4e48, 0x4, "ATI Radeon R350 NH"},
 
90
        {0x1002, 0x4e49, 0x4, "ATI Radeon R350 NI"},
 
91
        {0x1002, 0x4e4a, 0x4, "ATI Radeon R350 NJ"},
 
92
        {0x1002, 0x4e4b, 0x4, "ATI Radeon R350 NK"},
 
93
        {0x1002, 0x4e50, 0x4, "ATI Radeon Mobility RV350 NP"},
 
94
        {0x1002, 0x4e51, 0x4, "ATI Radeon Mobility RV350 NQ"},
 
95
        {0x1002, 0x4e52, 0x4, "ATI Radeon Mobility RV350 NR"},
 
96
        {0x1002, 0x4e53, 0x4, "ATI Radeon Mobility RV350 NS"},
 
97
        {0x1002, 0x4e54, 0x4, "ATI Radeon Mobility RV350 NT"},
 
98
        {0x1002, 0x4e56, 0x4, "ATI Radeon Mobility RV350 NV"},
 
99
        {0x1002, 0x5041, 0x1, "ATI Rage 128 PA"},
 
100
        {0x1002, 0x5042, 0x1, "ATI Rage 128 PB"},
 
101
        {0x1002, 0x5043, 0x1, "ATI Rage 128 PC"},
 
102
        {0x1002, 0x5044, 0x11, "ATI Rage 128 PD"},
 
103
        {0x1002, 0x5045, 0x1, "ATI Rage 128 PE"},
 
104
        {0x1002, 0x5046, 0x1, "ATI Rage 128 PF"},
 
105
        {0x1002, 0x5047, 0x1, "ATI Rage 128 PG"},
 
106
        {0x1002, 0x5048, 0x1, "ATI Rage 128 PH"},
 
107
        {0x1002, 0x5049, 0x1, "ATI Rage 128 PI"},
 
108
        {0x1002, 0x504a, 0x1, "ATI Rage 128 PJ"},
 
109
        {0x1002, 0x504b, 0x1, "ATI Rage 128 PK"},
 
110
        {0x1002, 0x504c, 0x1, "ATI Rage 128 PL"},
 
111
        {0x1002, 0x504d, 0x1, "ATI Rage 128 PM"},
 
112
        {0x1002, 0x504e, 0x1, "ATI Rage 128 PN"},
 
113
        {0x1002, 0x504f, 0x1, "ATI Rage 128 PO"},
 
114
        {0x1002, 0x5050, 0x11, "ATI Rage 128 PP"},
 
115
        {0x1002, 0x5051, 0x1, "ATI Rage 128 PQ"},
 
116
        {0x1002, 0x5052, 0x11, "ATI Rage 128 PR"},
 
117
        {0x1002, 0x5053, 0x1, "ATI Rage 128 PS"},
 
118
        {0x1002, 0x5054, 0x1, "ATI Rage 128 PT"},
 
119
        {0x1002, 0x5055, 0x1, "ATI Rage 128 PU"},
 
120
        {0x1002, 0x5056, 0x1, "ATI Rage 128 PV"},
 
121
        {0x1002, 0x5057, 0x1, "ATI Rage 128 PW"},
 
122
        {0x1002, 0x5058, 0x1, "ATI Rage 128 PX"},
 
123
        {0x1002, 0x5144, 0x2, "ATI Radeon R100 QD"},
 
124
        {0x1002, 0x5145, 0x2, "ATI Radeon R100 QE"},
 
125
        {0x1002, 0x5146, 0x2, "ATI Radeon R100 QF"},
 
126
        {0x1002, 0x5147, 0x2, "ATI Radeon R100 QG"},
 
127
        {0x1002, 0x5148, 0x3, "ATI Radeon R200 QH"},
 
128
        {0x1002, 0x514c, 0x3, "ATI Radeon R200 QL"},
 
129
        {0x1002, 0x514d, 0x3, "ATI Radeon R200 QM"},
 
130
        {0x1002, 0x5157, 0x2, "ATI Radeon RV200 QW (7500)"},
 
131
        {0x1002, 0x5158, 0x2, "ATI Radeon RV200 QX (7500)"},
 
132
        {0x1002, 0x5159, 0x2, "ATI Radeon RV100 QY"},
 
133
        {0x1002, 0x515a, 0x2, "ATI Radeon RV100 QZ"},
 
134
        {0x1002, 0x5245, 0x11, "ATI Rage 128 RE"},
 
135
        {0x1002, 0x5246, 0x1, "ATI Rage 128 RF"},
 
136
        {0x1002, 0x5247, 0x1, "ATI Rage 128 RG"},
 
137
        {0x1002, 0x524b, 0x11, "ATI Rage 128 RK"},
 
138
        {0x1002, 0x524c, 0x1, "ATI Rage 128 RL"},
 
139
        {0x1002, 0x5345, 0x1, "ATI Rage 128 SE"},
 
140
        {0x1002, 0x5346, 0x1, "ATI Rage 128 SF"},
 
141
        {0x1002, 0x5347, 0x1, "ATI Rage 128 SG"},
 
142
        {0x1002, 0x5348, 0x1, "ATI Rage 128 SH"},
 
143
        {0x1002, 0x534b, 0x1, "ATI Rage 128 SK"},
 
144
        {0x1002, 0x534c, 0x1, "ATI Rage 128 SL"},
 
145
        {0x1002, 0x534d, 0x1, "ATI Rage 128 SM"},
 
146
        {0x1002, 0x534e, 0x1, "ATI Rage 128 SN"},
 
147
        {0x1002, 0x5446, 0x1, "ATI Rage 128 TF"},
 
148
        {0x1002, 0x544c, 0x1, "ATI Rage 128 TL"},
 
149
        {0x1002, 0x5452, 0x1, "ATI Rage 128 TR"},
 
150
        {0x1002, 0x5453, 0x1, "ATI Rage 128 TS"},
 
151
        {0x1002, 0x5454, 0x1, "ATI Rage 128 TT"},
 
152
        {0x1002, 0x5455, 0x1, "ATI Rage 128 TU"},
 
153
        {0x1002, 0x5834, 0x3, "ATI Radeon RS300"},
 
154
        {0x1002, 0x5835, 0x3, "ATI Radeon RS300 Mobility"},
 
155
        {0x1002, 0x5941, 0x3, "ATI Radeon RV280 (9200)"},
 
156
        {0x1002, 0x5961, 0x3, "ATI Radeon RV280 (9200 SE)"},
 
157
        {0x1002, 0x5964, 0x3, "ATI Radeon RV280 (9200 SE)"},
 
158
        {0x1002, 0x5c60, 0x3, "ATI Radeon RV280"},
 
159
        {0x1002, 0x5c61, 0x3, "ATI Radeon RV280 Mobility"},
 
160
        {0x1002, 0x5c62, 0x3, "ATI Radeon RV280"},
 
161
        {0x1002, 0x5c63, 0x3, "ATI Radeon RV280 Mobility"},
 
162
        {0x1002, 0x5c64, 0x3, "ATI Radeon RV280"},
 
163
        {0, 0, 0, NULL}
 
164
};
 
165
 
 
166
static char *
 
167
make_busid(KdCardAttr *attr)
 
168
{
 
169
        char *busid;
 
170
        
 
171
        busid = xalloc(20);
 
172
        if (busid == NULL)
 
173
                return NULL;
 
174
        snprintf(busid, 20, "pci:%04x:%02x:%02x.%d", attr->domain, attr->bus, 
 
175
            attr->slot, attr->func);
 
176
        return busid;
 
177
}
 
178
 
 
179
static Bool
 
180
ATICardInit(KdCardInfo *card)
 
181
{
 
182
        ATICardInfo *atic;
 
183
        int i;
 
184
        Bool initialized = FALSE;
 
185
 
 
186
        atic = xcalloc(sizeof(ATICardInfo), 1);
 
187
        if (atic == NULL)
 
188
                return FALSE;
 
189
 
 
190
#ifdef KDRIVEFBDEV
 
191
        if (!initialized && fbdevInitialize(card, &atic->backend_priv.fbdev)) {
 
192
                atic->use_fbdev = TRUE;
 
193
                initialized = TRUE;
 
194
                atic->backend_funcs.cardfini = fbdevCardFini;
 
195
                atic->backend_funcs.scrfini = fbdevScreenFini;
 
196
                atic->backend_funcs.initScreen = fbdevInitScreen;
 
197
                atic->backend_funcs.finishInitScreen = fbdevFinishInitScreen;
 
198
                atic->backend_funcs.createRes = fbdevCreateResources;
 
199
                atic->backend_funcs.preserve = fbdevPreserve;
 
200
                atic->backend_funcs.restore = fbdevRestore;
 
201
                atic->backend_funcs.dpms = fbdevDPMS;
 
202
                atic->backend_funcs.enable = fbdevEnable;
 
203
                atic->backend_funcs.disable = fbdevDisable;
 
204
                atic->backend_funcs.getColors = fbdevGetColors;
 
205
                atic->backend_funcs.putColors = fbdevPutColors;
 
206
#ifdef RANDR
 
207
                atic->backend_funcs.randrSetConfig = fbdevRandRSetConfig;
 
208
#endif
 
209
        }
 
210
#endif
 
211
#ifdef KDRIVEVESA
 
212
        if (!initialized && vesaInitialize(card, &atic->backend_priv.vesa)) {
 
213
                atic->use_vesa = TRUE;
 
214
                initialized = TRUE;
 
215
                atic->backend_funcs.cardfini = vesaCardFini;
 
216
                atic->backend_funcs.scrfini = vesaScreenFini;
 
217
                atic->backend_funcs.initScreen = vesaInitScreen;
 
218
                atic->backend_funcs.finishInitScreen = vesaFinishInitScreen;
 
219
                atic->backend_funcs.createRes = vesaCreateResources;
 
220
                atic->backend_funcs.preserve = vesaPreserve;
 
221
                atic->backend_funcs.restore = vesaRestore;
 
222
                atic->backend_funcs.dpms = vesaDPMS;
 
223
                atic->backend_funcs.enable = vesaEnable;
 
224
                atic->backend_funcs.disable = vesaDisable;
 
225
                atic->backend_funcs.getColors = vesaGetColors;
 
226
                atic->backend_funcs.putColors = vesaPutColors;
 
227
#ifdef RANDR
 
228
                atic->backend_funcs.randrSetConfig = vesaRandRSetConfig;
 
229
#endif
 
230
        }
 
231
#endif
 
232
 
 
233
        if (!initialized || !ATIMapReg(card, atic)) {
 
234
                xfree(atic);
 
235
                return FALSE;
 
236
        }
 
237
 
 
238
        atic->busid = make_busid(&card->attr);
 
239
        if (atic->busid == NULL) {
 
240
                xfree(atic);
 
241
                return FALSE;
 
242
        }
 
243
 
 
244
#ifdef USE_DRI
 
245
        /* We demand identification by busid, not driver name */
 
246
        atic->drmFd = drmOpen(NULL, atic->busid);
 
247
        if (atic->drmFd < 0)
 
248
                ErrorF("Failed to open DRM, DRI disabled.\n");
 
249
#endif /* USE_DRI */
 
250
 
 
251
        card->driver = atic;
 
252
 
 
253
        for (i = 0; ati_pci_ids[i].name != NULL; i++) {
 
254
                if (ati_pci_ids[i].device == card->attr.deviceID) {
 
255
                        atic->pci_id = &ati_pci_ids[i];
 
256
                        break;
 
257
                }
 
258
        }
 
259
 
 
260
        if ((atic->pci_id->caps & CAP_SERIESMASK) != CAP_R128)
 
261
                atic->is_radeon = TRUE;
 
262
        if ((atic->pci_id->caps & CAP_SERIESMASK) == CAP_R100)
 
263
                atic->is_r100 = TRUE;
 
264
        if ((atic->pci_id->caps & CAP_SERIESMASK) == CAP_R200)
 
265
                atic->is_r200 = TRUE;
 
266
        if ((atic->pci_id->caps & CAP_SERIESMASK) == CAP_R300)
 
267
                atic->is_r300 = TRUE;
 
268
 
 
269
        atic->is_agp = ATIIsAGP(atic);
 
270
 
 
271
        ErrorF("Using ATI card: %s (%s) at %s\n", atic->pci_id->name,
 
272
            atic->is_agp ? "AGP" : "PCI", atic->busid);
 
273
 
 
274
        return TRUE;
 
275
}
 
276
 
 
277
static void
 
278
ATICardFini(KdCardInfo *card)
 
279
{
 
280
        ATICardInfo *atic = (ATICardInfo *)card->driver;
 
281
 
 
282
        ATIUnmapReg(card, atic);
 
283
        atic->backend_funcs.cardfini(card);
 
284
}
 
285
 
 
286
/*
 
287
 * Once screen->off_screen_base is set, this function
 
288
 * allocates the remaining memory appropriately
 
289
 */
 
290
 
 
291
static void
 
292
ATISetOffscreen (KdScreenInfo *screen)
 
293
{
 
294
        ATICardInfo(screen);
 
295
#if defined(USE_DRI) && defined(GLXEXT)
 
296
        ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
 
297
        int l;
 
298
#endif
 
299
        int screen_size;
 
300
        char *mmio = atic->reg_base;
 
301
    
 
302
        /* check (and adjust) pitch */
 
303
        if (mmio)
 
304
        {
 
305
                int     byteStride = screen->fb[0].byteStride;
 
306
                int     bitStride;
 
307
                int     pixelStride;
 
308
                int     bpp = screen->fb[0].bitsPerPixel;
 
309
                
 
310
                /*
 
311
                 * Ensure frame buffer is correctly aligned
 
312
                 */
 
313
                if (byteStride & 0x3f)
 
314
                {
 
315
                        byteStride = (byteStride + 0x3f) & ~0x3f;
 
316
                        bitStride = byteStride * 8;
 
317
                        pixelStride = bitStride / bpp;
 
318
 
 
319
                        screen->fb[0].byteStride = byteStride;
 
320
                        screen->fb[0].pixelStride = pixelStride;
 
321
                }
 
322
        }
 
323
 
 
324
        screen_size = screen->fb[0].byteStride * screen->height;
 
325
 
 
326
        screen->off_screen_base = screen_size;
 
327
 
 
328
#if defined(USE_DRI) && defined(GLXEXT)
 
329
        /* Reserve a static area for the back buffer the same size as the
 
330
         * visible screen.  XXX: This would be better initialized in ati_dri.c
 
331
         * when GLX is set up, but the offscreen memory manager's allocations
 
332
         * don't last through VT switches, while the kernel's understanding of
 
333
         * offscreen locations does.
 
334
         */
 
335
        atis->frontOffset = 0;
 
336
        atis->frontPitch = screen->fb[0].byteStride;
 
337
 
 
338
        if (screen->off_screen_base + screen_size <= screen->memory_size) {
 
339
                atis->backOffset = screen->off_screen_base;
 
340
                atis->backPitch = screen->fb[0].byteStride;
 
341
                screen->off_screen_base += screen_size;
 
342
        }
 
343
 
 
344
        /* Reserve the depth span for Rage 128 */
 
345
        if (!atic->is_radeon && screen->off_screen_base +
 
346
            screen->fb[0].byteStride <= screen->memory_size) {
 
347
                atis->spanOffset = screen->off_screen_base;
 
348
                screen->off_screen_base += screen->fb[0].byteStride;
 
349
        }
 
350
 
 
351
        /* Reserve the static depth buffer, which happens to be the same
 
352
         * bitsPerPixel as the screen.
 
353
         */
 
354
        if (screen->off_screen_base + screen_size <= screen->memory_size) {
 
355
                atis->depthOffset = screen->off_screen_base;
 
356
                atis->depthPitch = screen->fb[0].byteStride;
 
357
                screen->off_screen_base += screen_size;
 
358
        }
 
359
 
 
360
        /* Reserve approx. half of remaining offscreen memory for local
 
361
         * textures.  Round down to a whole number of texture regions.
 
362
         */
 
363
        atis->textureSize = (screen->memory_size - screen->off_screen_base) / 2;
 
364
        l = ATILog2(atis->textureSize / ATI_NR_TEX_REGIONS);
 
365
        if (l < ATI_LOG_TEX_GRANULARITY)
 
366
                l = ATI_LOG_TEX_GRANULARITY;
 
367
        atis->textureSize = (atis->textureSize >> l) << l;
 
368
        if (atis->textureSize >= 512 * 1024) {
 
369
                atis->textureOffset = screen->off_screen_base;
 
370
                screen->off_screen_base += atis->textureSize;
 
371
        } else {
 
372
                /* Minimum texture size is for 2 256x256x32bpp textures */
 
373
                atis->textureSize = 0;
 
374
        }
 
375
#endif /* USE_DRI && GLXEXT */
 
376
}
 
377
 
 
378
static void
 
379
ATISetPitch (KdScreenInfo *screen)
 
380
{
 
381
        ATICardInfo(screen);
 
382
#if defined(USE_DRI) && defined(GLXEXT)
 
383
        ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
 
384
        int l;
 
385
#endif
 
386
        char *mmio = atic->reg_base;
 
387
    
 
388
        /* check (and adjust) pitch for radeon */
 
389
        if (mmio)
 
390
        {
 
391
                int     byteStride = screen->fb[0].byteStride;
 
392
                int     bitStride;
 
393
                int     pixelStride;
 
394
                int     bpp = screen->fb[0].bitsPerPixel;
 
395
                CARD32  crtc_pitch;
 
396
                CARD32  crtc2_pitch;
 
397
#if 0
 
398
                CARD32  crtc_ext_cntl;
 
399
                CARD32  dac_cntl;
 
400
#endif
 
401
                bitStride = byteStride * 8;
 
402
                pixelStride = bitStride / bpp;
 
403
 
 
404
                crtc_pitch = (pixelStride >> 3);
 
405
                crtc_pitch |= crtc_pitch << 16;
 
406
                crtc2_pitch = (pixelStride >> 3);
 
407
                crtc2_pitch |= crtc2_pitch << 16;
 
408
#if 0
 
409
                crtc_ext_cntl = MMIO_IN32 (mmio, ATI_REG_CRTC_EXT_CNTL);
 
410
                dac_cntl = MMIO_IN32 (mmio, ATI_REG_DAC_CNTL);
 
411
                /* Turn off the screen */
 
412
                MMIO_OUT32 (mmio, ATI_REG_CRTC_EXT_CNTL,
 
413
                            crtc_ext_cntl |
 
414
                            ATI_CRTC_VSYNC_DIS |
 
415
                            ATI_CRTC_HSYNC_DIS |
 
416
                            ATI_CRTC_DISPLAY_DIS);
 
417
                MMIO_OUT32 (mmio, ATI_REG_DAC_CNTL,
 
418
                            dac_cntl |
 
419
                            ATI_DAC_RANGE_CNTL |
 
420
                            ATI_DAC_BLANKING);
 
421
#endif
 
422
                MMIO_OUT32 (mmio, ATI_REG_CRTC_PITCH, crtc_pitch);
 
423
                MMIO_OUT32 (mmio, ATI_REG_CRTC2_PITCH, crtc2_pitch);
 
424
#if 0
 
425
                /* Turn the screen back on */
 
426
                MMIO_OUT32 (mmio, ATI_REG_CRTC_EXT_CNTL,
 
427
                            crtc_ext_cntl);
 
428
                MMIO_OUT32 (mmio, ATI_REG_DAC_CNTL,
 
429
                            dac_cntl);
 
430
#endif
 
431
        }
 
432
}
 
433
 
 
434
static Bool
 
435
ATIScreenInit(KdScreenInfo *screen)
 
436
{
 
437
        ATIScreenInfo *atis;
 
438
        ATICardInfo(screen);
 
439
        Bool success = FALSE;
 
440
 
 
441
        atis = xcalloc(sizeof(ATIScreenInfo), 1);
 
442
        if (atis == NULL)
 
443
                return FALSE;
 
444
 
 
445
        atis->atic = atic;
 
446
        atis->screen = screen;
 
447
        screen->driver = atis;
 
448
 
 
449
        if (screen->fb[0].depth == 0)
 
450
                screen->fb[0].depth = 16;
 
451
#ifdef KDRIVEFBDEV
 
452
        if (atic->use_fbdev) {
 
453
                success = fbdevScreenInitialize(screen,
 
454
                                                &atis->backend_priv.fbdev);
 
455
        }
 
456
#endif
 
457
#ifdef KDRIVEVESA
 
458
        if (atic->use_vesa) {
 
459
                success = vesaScreenInitialize(screen,
 
460
                                               &atis->backend_priv.vesa);
 
461
        }
 
462
#endif
 
463
 
 
464
        if (!success) {
 
465
                screen->driver = NULL;
 
466
                xfree(atis);
 
467
                return FALSE;
 
468
        }
 
469
 
 
470
        ATISetOffscreen (screen);
 
471
 
 
472
        return TRUE;
 
473
}
 
474
 
 
475
#ifdef RANDR
 
476
static Bool
 
477
ATIRandRSetConfig (ScreenPtr            pScreen,
 
478
                   Rotation             randr,
 
479
                   int                  rate,
 
480
                   RRScreenSizePtr      pSize)
 
481
{
 
482
        KdScreenPriv(pScreen);
 
483
        KdScreenInfo *screen = pScreenPriv->screen;
 
484
        ATICardInfo *atic = screen->card->driver;
 
485
        Bool ret;
 
486
 
 
487
        ATIDrawDisable (pScreen);
 
488
        ret = atic->backend_funcs.randrSetConfig(pScreen, randr, rate, pSize);
 
489
        ATISetOffscreen (screen);
 
490
        ATISetPitch (screen);
 
491
        /*
 
492
         * Set frame buffer mapping
 
493
         */
 
494
        (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap (pScreen),
 
495
                                        pScreen->width,
 
496
                                        pScreen->height,
 
497
                                        screen->fb[0].depth,
 
498
                                        screen->fb[0].bitsPerPixel,
 
499
                                        screen->fb[0].byteStride,
 
500
                                        screen->fb[0].frameBuffer);
 
501
 
 
502
        ATIDrawEnable (pScreen);
 
503
        return ret;
 
504
}
 
505
 
 
506
static Bool
 
507
ATIRandRInit (ScreenPtr pScreen)
 
508
{
 
509
    rrScrPrivPtr    pScrPriv;
 
510
    
 
511
    pScrPriv = rrGetScrPriv(pScreen);
 
512
    pScrPriv->rrSetConfig = ATIRandRSetConfig;
 
513
    return TRUE;
 
514
}
 
515
#endif
 
516
 
 
517
static void
 
518
ATIScreenFini(KdScreenInfo *screen)
 
519
{
 
520
        ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
 
521
        ATICardInfo *atic = screen->card->driver;
 
522
 
 
523
#ifdef XV
 
524
        ATIFiniVideo(screen->pScreen);
 
525
#endif
 
526
 
 
527
        atic->backend_funcs.scrfini(screen);
 
528
        xfree(atis);
 
529
        screen->driver = 0;
 
530
}
 
531
 
 
532
Bool
 
533
ATIMapReg(KdCardInfo *card, ATICardInfo *atic)
 
534
{
 
535
        atic->reg_base = (char *)KdMapDevice(ATI_REG_BASE(card),
 
536
            ATI_REG_SIZE(card));
 
537
 
 
538
        if (atic->reg_base == NULL)
 
539
                return FALSE;
 
540
 
 
541
        KdSetMappedMode(ATI_REG_BASE(card), ATI_REG_SIZE(card),
 
542
            KD_MAPPED_MODE_REGISTERS);
 
543
 
 
544
        return TRUE;
 
545
}
 
546
 
 
547
void
 
548
ATIUnmapReg(KdCardInfo *card, ATICardInfo *atic)
 
549
{
 
550
        if (atic->reg_base) {
 
551
                KdResetMappedMode(ATI_REG_BASE(card), ATI_REG_SIZE(card),
 
552
                    KD_MAPPED_MODE_REGISTERS);
 
553
                KdUnmapDevice((void *)atic->reg_base, ATI_REG_SIZE(card));
 
554
                atic->reg_base = 0;
 
555
        }
 
556
}
 
557
 
 
558
static Bool
 
559
ATIInitScreen(ScreenPtr pScreen)
 
560
{
 
561
        KdScreenPriv(pScreen);
 
562
        ATICardInfo(pScreenPriv);
 
563
 
 
564
#ifdef XV
 
565
        ATIInitVideo(pScreen);
 
566
#endif
 
567
        return atic->backend_funcs.initScreen(pScreen);
 
568
}
 
569
 
 
570
static Bool
 
571
ATIFinishInitScreen(ScreenPtr pScreen)
 
572
{
 
573
        KdScreenPriv(pScreen);
 
574
        ATICardInfo(pScreenPriv);
 
575
 
 
576
        if (!atic->backend_funcs.finishInitScreen(pScreen))
 
577
                return FALSE;
 
578
#ifdef RANDR
 
579
        if (!ATIRandRInit (pScreen))
 
580
                return FALSE;
 
581
#endif
 
582
        return TRUE;
 
583
}
 
584
 
 
585
static Bool
 
586
ATICreateResources(ScreenPtr pScreen)
 
587
{
 
588
        KdScreenPriv(pScreen);
 
589
        ATICardInfo(pScreenPriv);
 
590
 
 
591
        return atic->backend_funcs.createRes(pScreen);
 
592
}
 
593
 
 
594
static void
 
595
ATIPreserve(KdCardInfo *card)
 
596
{
 
597
        ATICardInfo *atic = card->driver;
 
598
        char *mmio = atic->reg_base;
 
599
 
 
600
        atic->backend_funcs.preserve(card);
 
601
        if (atic->is_radeon && mmio)
 
602
        {
 
603
                atic->crtc_pitch = MMIO_IN32(mmio, ATI_REG_CRTC_PITCH);
 
604
                atic->crtc2_pitch = MMIO_IN32(mmio, ATI_REG_CRTC2_PITCH);
 
605
                
 
606
        }
 
607
}
 
608
 
 
609
static void
 
610
ATIRestore(KdCardInfo *card)
 
611
{
 
612
        ATICardInfo *atic = card->driver;
 
613
        char *mmio = atic->reg_base;
 
614
 
 
615
        if (mmio)
 
616
        {
 
617
                MMIO_OUT32(mmio, ATI_REG_CRTC_PITCH, atic->crtc_pitch);
 
618
                MMIO_OUT32(mmio, ATI_REG_CRTC2_PITCH, atic->crtc2_pitch);
 
619
        }
 
620
        ATIUnmapReg(card, atic);
 
621
 
 
622
        atic->backend_funcs.restore(card);
 
623
}
 
624
 
 
625
static Bool
 
626
ATIDPMS(ScreenPtr pScreen, int mode)
 
627
{
 
628
        KdScreenPriv(pScreen);
 
629
        ATICardInfo(pScreenPriv);
 
630
 
 
631
        return atic->backend_funcs.dpms(pScreen, mode);
 
632
}
 
633
 
 
634
static Bool
 
635
ATIEnable(ScreenPtr pScreen)
 
636
{
 
637
        KdScreenPriv(pScreen);
 
638
        ATICardInfo(pScreenPriv);
 
639
 
 
640
        if (!atic->backend_funcs.enable(pScreen))
 
641
                return FALSE;
 
642
 
 
643
        if ((atic->reg_base == NULL) && !ATIMapReg(pScreenPriv->screen->card,
 
644
            atic))
 
645
                return FALSE;
 
646
 
 
647
        ATISetOffscreen (pScreenPriv->screen);
 
648
 
 
649
        ATISetPitch (pScreenPriv->screen);
 
650
 
 
651
        return TRUE;
 
652
}
 
653
 
 
654
static void
 
655
ATIDisable(ScreenPtr pScreen)
 
656
{
 
657
        KdScreenPriv(pScreen);
 
658
#if defined(USE_DRI) && defined(GLXEXT)
 
659
        ATIScreenInfo(pScreenPriv);
 
660
#endif /* USE_DRI && GLXEXT */
 
661
        ATICardInfo(pScreenPriv);
 
662
 
 
663
        ATIUnmapReg(pScreenPriv->card, atic);
 
664
 
 
665
        atic->backend_funcs.disable(pScreen);
 
666
}
 
667
 
 
668
static void
 
669
ATIGetColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
 
670
{
 
671
        KdScreenPriv(pScreen);
 
672
        ATICardInfo(pScreenPriv);
 
673
 
 
674
        atic->backend_funcs.getColors(pScreen, fb, n, pdefs);
 
675
}
 
676
 
 
677
static void
 
678
ATIPutColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
 
679
{
 
680
        KdScreenPriv(pScreen);
 
681
        ATICardInfo(pScreenPriv);
 
682
 
 
683
        atic->backend_funcs.putColors(pScreen, fb, n, pdefs);
 
684
}
 
685
 
 
686
/* Compute log base 2 of val. */
 
687
int
 
688
ATILog2(int val)
 
689
{
 
690
        int bits;
 
691
 
 
692
        for (bits = 0; val != 0; val >>= 1, ++bits)
 
693
                ;
 
694
        return bits - 1;
 
695
}
 
696
 
 
697
static Bool
 
698
ATIIsAGP(ATICardInfo *atic)
 
699
{
 
700
        char *mmio = atic->reg_base;
 
701
        CARD32 cap_ptr, cap_id;
 
702
 
 
703
        if (mmio == NULL)
 
704
                return FALSE;
 
705
 
 
706
        if (MMIO_IN32(mmio, ATI_REG_PCI_CFG_STATUS) & ATI_CAP_LIST) {
 
707
                cap_ptr = MMIO_IN32(mmio, ATI_REG_PCI_CFG_CAPABILITIES_PTR) &
 
708
                    ATI_CAP_PTR_MASK;
 
709
                while (cap_ptr != ATI_CAP_ID_NULL) {
 
710
                        cap_id = MMIO_IN32(mmio, ATI_PCI_CFG_OFFSET + cap_ptr);
 
711
                        if ((cap_id & 0xff) == ATI_CAP_ID_AGP)
 
712
                                return TRUE;
 
713
                        cap_ptr = (cap_id >> 8) & ATI_CAP_PTR_MASK;
 
714
                }
 
715
        }
 
716
 
 
717
        return FALSE;
 
718
}
 
719
 
 
720
/* This function is required to work around a hardware bug in some (all?)
 
721
 * revisions of the R300.  This workaround should be called after every
 
722
 * CLOCK_CNTL_INDEX register access.  If not, register reads afterward
 
723
 * may not be correct.
 
724
 */
 
725
void R300CGWorkaround(ATIScreenInfo *atis) {
 
726
        ATICardInfo *atic = atis->atic;
 
727
        char *mmio = atic->reg_base;
 
728
        CARD32 save;
 
729
 
 
730
        save = MMIO_IN32(mmio, ATI_REG_CLOCK_CNTL_INDEX);
 
731
        MMIO_OUT32(mmio, ATI_REG_CLOCK_CNTL_INDEX, save & ~(0x3f |
 
732
            ATI_PLL_WR_EN));
 
733
        MMIO_IN32(mmio, ATI_REG_CLOCK_CNTL_INDEX);
 
734
        MMIO_OUT32(mmio, ATI_REG_CLOCK_CNTL_INDEX, save);
 
735
}
 
736
 
 
737
KdCardFuncs ATIFuncs = {
 
738
        ATICardInit,            /* cardinit */
 
739
        ATIScreenInit,          /* scrinit */
 
740
        ATIInitScreen,          /* initScreen */
 
741
        ATIFinishInitScreen,    /* finishInitScreen */
 
742
        ATICreateResources,     /* createRes */
 
743
        ATIPreserve,            /* preserve */
 
744
        ATIEnable,              /* enable */
 
745
        ATIDPMS,                /* dpms */
 
746
        ATIDisable,             /* disable */
 
747
        ATIRestore,             /* restore */
 
748
        ATIScreenFini,          /* scrfini */
 
749
        ATICardFini,            /* cardfini */
 
750
 
 
751
        ATICursorInit,          /* initCursor */
 
752
        ATICursorEnable,        /* enableCursor */
 
753
        ATICursorDisable,       /* disableCursor */
 
754
        ATICursorFini,          /* finiCursor */
 
755
        ATIRecolorCursor,       /* recolorCursor */
 
756
 
 
757
        ATIDrawInit,            /* initAccel */
 
758
        ATIDrawEnable,          /* enableAccel */
 
759
        ATIDrawDisable,         /* disableAccel */
 
760
        ATIDrawFini,            /* finiAccel */
 
761
 
 
762
        ATIGetColors,           /* getColors */
 
763
        ATIPutColors,           /* putColors */
 
764
};