4
* Copyright � 2003 Eric Anholt
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.
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.
27
#include <kdrive-config.h>
31
#if defined(USE_DRI) && defined(GLXEXT)
32
#include "ati_sarea.h"
35
static Bool ATIIsAGP(ATICardInfo *atic);
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. */
43
#define CAP_FEATURESMASK 0xf0
44
#define CAP_NOAGP 0x10 /* If it's a PCI-only card. */
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"},
167
make_busid(KdCardAttr *attr)
174
snprintf(busid, 20, "pci:%04x:%02x:%02x.%d", attr->domain, attr->bus,
175
attr->slot, attr->func);
180
ATICardInit(KdCardInfo *card)
184
Bool initialized = FALSE;
186
atic = xcalloc(sizeof(ATICardInfo), 1);
191
if (!initialized && fbdevInitialize(card, &atic->backend_priv.fbdev)) {
192
atic->use_fbdev = 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;
207
atic->backend_funcs.randrSetConfig = fbdevRandRSetConfig;
212
if (!initialized && vesaInitialize(card, &atic->backend_priv.vesa)) {
213
atic->use_vesa = 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;
228
atic->backend_funcs.randrSetConfig = vesaRandRSetConfig;
233
if (!initialized || !ATIMapReg(card, atic)) {
238
atic->busid = make_busid(&card->attr);
239
if (atic->busid == NULL) {
245
/* We demand identification by busid, not driver name */
246
atic->drmFd = drmOpen(NULL, atic->busid);
248
ErrorF("Failed to open DRM, DRI disabled.\n");
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];
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;
269
atic->is_agp = ATIIsAGP(atic);
271
ErrorF("Using ATI card: %s (%s) at %s\n", atic->pci_id->name,
272
atic->is_agp ? "AGP" : "PCI", atic->busid);
278
ATICardFini(KdCardInfo *card)
280
ATICardInfo *atic = (ATICardInfo *)card->driver;
282
ATIUnmapReg(card, atic);
283
atic->backend_funcs.cardfini(card);
287
* Once screen->off_screen_base is set, this function
288
* allocates the remaining memory appropriately
292
ATISetOffscreen (KdScreenInfo *screen)
295
#if defined(USE_DRI) && defined(GLXEXT)
296
ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
300
char *mmio = atic->reg_base;
302
/* check (and adjust) pitch */
305
int byteStride = screen->fb[0].byteStride;
308
int bpp = screen->fb[0].bitsPerPixel;
311
* Ensure frame buffer is correctly aligned
313
if (byteStride & 0x3f)
315
byteStride = (byteStride + 0x3f) & ~0x3f;
316
bitStride = byteStride * 8;
317
pixelStride = bitStride / bpp;
319
screen->fb[0].byteStride = byteStride;
320
screen->fb[0].pixelStride = pixelStride;
324
screen_size = screen->fb[0].byteStride * screen->height;
326
screen->off_screen_base = screen_size;
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.
335
atis->frontOffset = 0;
336
atis->frontPitch = screen->fb[0].byteStride;
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;
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;
351
/* Reserve the static depth buffer, which happens to be the same
352
* bitsPerPixel as the screen.
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;
360
/* Reserve approx. half of remaining offscreen memory for local
361
* textures. Round down to a whole number of texture regions.
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;
372
/* Minimum texture size is for 2 256x256x32bpp textures */
373
atis->textureSize = 0;
375
#endif /* USE_DRI && GLXEXT */
379
ATISetPitch (KdScreenInfo *screen)
382
#if defined(USE_DRI) && defined(GLXEXT)
383
ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
386
char *mmio = atic->reg_base;
388
/* check (and adjust) pitch for radeon */
391
int byteStride = screen->fb[0].byteStride;
394
int bpp = screen->fb[0].bitsPerPixel;
398
CARD32 crtc_ext_cntl;
401
bitStride = byteStride * 8;
402
pixelStride = bitStride / bpp;
404
crtc_pitch = (pixelStride >> 3);
405
crtc_pitch |= crtc_pitch << 16;
406
crtc2_pitch = (pixelStride >> 3);
407
crtc2_pitch |= crtc2_pitch << 16;
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,
416
ATI_CRTC_DISPLAY_DIS);
417
MMIO_OUT32 (mmio, ATI_REG_DAC_CNTL,
422
MMIO_OUT32 (mmio, ATI_REG_CRTC_PITCH, crtc_pitch);
423
MMIO_OUT32 (mmio, ATI_REG_CRTC2_PITCH, crtc2_pitch);
425
/* Turn the screen back on */
426
MMIO_OUT32 (mmio, ATI_REG_CRTC_EXT_CNTL,
428
MMIO_OUT32 (mmio, ATI_REG_DAC_CNTL,
435
ATIScreenInit(KdScreenInfo *screen)
439
Bool success = FALSE;
441
atis = xcalloc(sizeof(ATIScreenInfo), 1);
446
atis->screen = screen;
447
screen->driver = atis;
449
if (screen->fb[0].depth == 0)
450
screen->fb[0].depth = 16;
452
if (atic->use_fbdev) {
453
success = fbdevScreenInitialize(screen,
454
&atis->backend_priv.fbdev);
458
if (atic->use_vesa) {
459
success = vesaScreenInitialize(screen,
460
&atis->backend_priv.vesa);
465
screen->driver = NULL;
470
ATISetOffscreen (screen);
477
ATIRandRSetConfig (ScreenPtr pScreen,
480
RRScreenSizePtr pSize)
482
KdScreenPriv(pScreen);
483
KdScreenInfo *screen = pScreenPriv->screen;
484
ATICardInfo *atic = screen->card->driver;
487
ATIDrawDisable (pScreen);
488
ret = atic->backend_funcs.randrSetConfig(pScreen, randr, rate, pSize);
489
ATISetOffscreen (screen);
490
ATISetPitch (screen);
492
* Set frame buffer mapping
494
(*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap (pScreen),
498
screen->fb[0].bitsPerPixel,
499
screen->fb[0].byteStride,
500
screen->fb[0].frameBuffer);
502
ATIDrawEnable (pScreen);
507
ATIRandRInit (ScreenPtr pScreen)
509
rrScrPrivPtr pScrPriv;
511
pScrPriv = rrGetScrPriv(pScreen);
512
pScrPriv->rrSetConfig = ATIRandRSetConfig;
518
ATIScreenFini(KdScreenInfo *screen)
520
ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
521
ATICardInfo *atic = screen->card->driver;
524
ATIFiniVideo(screen->pScreen);
527
atic->backend_funcs.scrfini(screen);
533
ATIMapReg(KdCardInfo *card, ATICardInfo *atic)
535
atic->reg_base = (char *)KdMapDevice(ATI_REG_BASE(card),
538
if (atic->reg_base == NULL)
541
KdSetMappedMode(ATI_REG_BASE(card), ATI_REG_SIZE(card),
542
KD_MAPPED_MODE_REGISTERS);
548
ATIUnmapReg(KdCardInfo *card, ATICardInfo *atic)
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));
559
ATIInitScreen(ScreenPtr pScreen)
561
KdScreenPriv(pScreen);
562
ATICardInfo(pScreenPriv);
565
ATIInitVideo(pScreen);
567
return atic->backend_funcs.initScreen(pScreen);
571
ATIFinishInitScreen(ScreenPtr pScreen)
573
KdScreenPriv(pScreen);
574
ATICardInfo(pScreenPriv);
576
if (!atic->backend_funcs.finishInitScreen(pScreen))
579
if (!ATIRandRInit (pScreen))
586
ATICreateResources(ScreenPtr pScreen)
588
KdScreenPriv(pScreen);
589
ATICardInfo(pScreenPriv);
591
return atic->backend_funcs.createRes(pScreen);
595
ATIPreserve(KdCardInfo *card)
597
ATICardInfo *atic = card->driver;
598
char *mmio = atic->reg_base;
600
atic->backend_funcs.preserve(card);
601
if (atic->is_radeon && mmio)
603
atic->crtc_pitch = MMIO_IN32(mmio, ATI_REG_CRTC_PITCH);
604
atic->crtc2_pitch = MMIO_IN32(mmio, ATI_REG_CRTC2_PITCH);
610
ATIRestore(KdCardInfo *card)
612
ATICardInfo *atic = card->driver;
613
char *mmio = atic->reg_base;
617
MMIO_OUT32(mmio, ATI_REG_CRTC_PITCH, atic->crtc_pitch);
618
MMIO_OUT32(mmio, ATI_REG_CRTC2_PITCH, atic->crtc2_pitch);
620
ATIUnmapReg(card, atic);
622
atic->backend_funcs.restore(card);
626
ATIDPMS(ScreenPtr pScreen, int mode)
628
KdScreenPriv(pScreen);
629
ATICardInfo(pScreenPriv);
631
return atic->backend_funcs.dpms(pScreen, mode);
635
ATIEnable(ScreenPtr pScreen)
637
KdScreenPriv(pScreen);
638
ATICardInfo(pScreenPriv);
640
if (!atic->backend_funcs.enable(pScreen))
643
if ((atic->reg_base == NULL) && !ATIMapReg(pScreenPriv->screen->card,
647
ATISetOffscreen (pScreenPriv->screen);
649
ATISetPitch (pScreenPriv->screen);
655
ATIDisable(ScreenPtr pScreen)
657
KdScreenPriv(pScreen);
658
#if defined(USE_DRI) && defined(GLXEXT)
659
ATIScreenInfo(pScreenPriv);
660
#endif /* USE_DRI && GLXEXT */
661
ATICardInfo(pScreenPriv);
663
ATIUnmapReg(pScreenPriv->card, atic);
665
atic->backend_funcs.disable(pScreen);
669
ATIGetColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
671
KdScreenPriv(pScreen);
672
ATICardInfo(pScreenPriv);
674
atic->backend_funcs.getColors(pScreen, fb, n, pdefs);
678
ATIPutColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
680
KdScreenPriv(pScreen);
681
ATICardInfo(pScreenPriv);
683
atic->backend_funcs.putColors(pScreen, fb, n, pdefs);
686
/* Compute log base 2 of val. */
692
for (bits = 0; val != 0; val >>= 1, ++bits)
698
ATIIsAGP(ATICardInfo *atic)
700
char *mmio = atic->reg_base;
701
CARD32 cap_ptr, cap_id;
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) &
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)
713
cap_ptr = (cap_id >> 8) & ATI_CAP_PTR_MASK;
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.
725
void R300CGWorkaround(ATIScreenInfo *atis) {
726
ATICardInfo *atic = atis->atic;
727
char *mmio = atic->reg_base;
730
save = MMIO_IN32(mmio, ATI_REG_CLOCK_CNTL_INDEX);
731
MMIO_OUT32(mmio, ATI_REG_CLOCK_CNTL_INDEX, save & ~(0x3f |
733
MMIO_IN32(mmio, ATI_REG_CLOCK_CNTL_INDEX);
734
MMIO_OUT32(mmio, ATI_REG_CLOCK_CNTL_INDEX, save);
737
KdCardFuncs ATIFuncs = {
738
ATICardInit, /* cardinit */
739
ATIScreenInit, /* scrinit */
740
ATIInitScreen, /* initScreen */
741
ATIFinishInitScreen, /* finishInitScreen */
742
ATICreateResources, /* createRes */
743
ATIPreserve, /* preserve */
744
ATIEnable, /* enable */
746
ATIDisable, /* disable */
747
ATIRestore, /* restore */
748
ATIScreenFini, /* scrfini */
749
ATICardFini, /* cardfini */
751
ATICursorInit, /* initCursor */
752
ATICursorEnable, /* enableCursor */
753
ATICursorDisable, /* disableCursor */
754
ATICursorFini, /* finiCursor */
755
ATIRecolorCursor, /* recolorCursor */
757
ATIDrawInit, /* initAccel */
758
ATIDrawEnable, /* enableAccel */
759
ATIDrawDisable, /* disableAccel */
760
ATIDrawFini, /* finiAccel */
762
ATIGetColors, /* getColors */
763
ATIPutColors, /* putColors */