1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/*
* Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of Marc Aurele La France not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Marc Aurele La France makes no representations
* about the suitability of this software for any purpose. It is provided
* "as-is" without express or implied warranty.
*
* MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
* EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*************************************************************************/
/*
* Author: Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
*
* This is the ATI driver for XFree86.
*
* John Donne once said "No man is an island", and I am most certainly not an
* exception. Contributions, intentional or not, to this and previous versions
* of this driver by the following are hereby acknowledged:
*
* Thomas Roell, Per Lindqvist, Doug Evans, Rik Faith, Arthur Tateishi,
* Alain Hebert, Ton van Rosmalen, David Chambers, William Shubert,
* ATI Technologies Incorporated, Robert Wolff, David Dawes, Mark Weaver,
* Hans Nasten, Kevin Martin, Frederic Rienthaler, Marc Bolduc, Reuben Sumner,
* Benjamin T. Yang, James Fast Kane, Randall Hopper, W. Marcus Miller,
* Henrik Harmsen, Christian Lupien, Precision Insight Incorporated,
* Mark Vojkovich, Huw D M Davies, Andrew C Aitchison, Ani Joshi,
* Kostas Gewrgiou, Jakub Jelinek, David S. Miller, A E Lawrence,
* Linus Torvalds, William Blew, Ignacio Garcia Etxebarria, Patrick Chase,
* Vladimir Dergachev, Egbert Eich, Mike A. Harris
*
* ... and, many, many others from around the world.
*
* In addition, this work would not have been possible without the active
* support, both moral and otherwise, of the staff and management of Computing
* and Network Services at the University of Alberta, in Edmonton, Alberta,
* Canada.
*
* The driver is intended to support all ATI adapters since their VGA Wonder
* V3, including OEM counterparts.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef XSERVER_LIBPCIACCESS
#include <pciaccess.h>
#endif
#include "atipcirename.h"
#include "ati.h"
#include "ativersion.h"
/* names duplicated from version headers */
#define MACH64_DRIVER_NAME "mach64"
#define R128_DRIVER_NAME "r128"
#define RADEON_DRIVER_NAME "radeon"
enum
{
ATI_CHIP_FAMILY_NONE = 0,
ATI_CHIP_FAMILY_Mach64,
ATI_CHIP_FAMILY_Rage128,
ATI_CHIP_FAMILY_Radeon
};
static int ATIChipID(const uint16_t);
#ifdef XSERVER_LIBPCIACCESS
/* domain defines (stolen from xserver) */
#if (defined(__alpha__) || defined(__ia64__)) && defined (linux)
# define PCI_DOM_MASK 0x01fful
#else
# define PCI_DOM_MASK 0x0ffu
#endif
#define PCI_DOM_FROM_BUS(bus) (((bus) >> 8) & (PCI_DOM_MASK))
#define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu)
static struct pci_device*
ati_device_get_from_busid(int bus, int dev, int func)
{
return pci_device_find_by_slot(PCI_DOM_FROM_BUS(bus),
PCI_BUS_NO_DOMAIN(bus),
dev,
func);
}
static struct pci_device*
ati_device_get_primary(void)
{
struct pci_device *device = NULL;
struct pci_device_iterator *device_iter;
device_iter = pci_slot_match_iterator_create(NULL);
while ((device = pci_device_next(device_iter)) != NULL) {
if (xf86IsPrimaryPci(device))
break;
}
pci_iterator_destroy(device_iter);
return device;
}
#else /* XSERVER_LIBPCIACCESS */
static pciVideoPtr
ati_device_get_from_busid(int bus, int dev, int func)
{
pciVideoPtr pVideo = NULL;
pciVideoPtr *xf86PciVideoInfo;
xf86PciVideoInfo = xf86GetPciVideoInfo();
if (xf86PciVideoInfo == NULL)
return NULL;
while ((pVideo = *xf86PciVideoInfo++) != NULL)
{
if ((pVideo->bus == bus) && (pVideo->device == dev) &&
(pVideo->func == func))
break;
}
return pVideo;
}
static pciVideoPtr
ati_device_get_primary()
{
pciVideoPtr pVideo = NULL;
pciVideoPtr *xf86PciVideoInfo;
xf86PciVideoInfo = xf86GetPciVideoInfo();
if (xf86PciVideoInfo == NULL)
return NULL;
while ((pVideo = *xf86PciVideoInfo++) != NULL)
{
if (xf86IsPrimaryPci(pVideo))
break;
}
return pVideo;
}
#endif /* XSERVER_LIBPCIACCESS */
void
ati_gdev_subdriver(pointer options)
{
int nATIGDev, nMach64GDev, nR128GDev, nRadeonGDev;
GDevPtr *ATIGDevs;
Bool load_mach64 = FALSE, load_r128 = FALSE, load_radeon = FALSE;
int i;
/* let the subdrivers configure for themselves */
if (xf86ServerIsOnlyDetecting())
return;
/* get Device sections with Driver "ati" */
nATIGDev = xf86MatchDevice(ATI_DRIVER_NAME, &ATIGDevs);
nMach64GDev = xf86MatchDevice(MACH64_DRIVER_NAME, NULL);
nR128GDev = xf86MatchDevice(R128_DRIVER_NAME, NULL);
nRadeonGDev = xf86MatchDevice(RADEON_DRIVER_NAME, NULL);
for (i = 0; i < nATIGDev; i++) {
GDevPtr ati_gdev = ATIGDevs[i];
pciVideoPtr device = NULL;
int chip_family;
/* get pci device for the Device section */
if (ati_gdev->busID) {
int bus, dev, func;
if (!xf86ParsePciBusString(ati_gdev->busID, &bus, &dev, &func))
continue;
device = ati_device_get_from_busid(bus, dev, func);
}
else {
device = ati_device_get_primary();
}
if (!device)
continue;
/* check for non-ati devices and prehistoric mach32 */
if ((PCI_DEV_VENDOR_ID(device) != PCI_VENDOR_ATI) ||
(PCI_DEV_DEVICE_ID(device) == PCI_CHIP_MACH32))
continue;
/* replace Driver line in the Device section */
chip_family = ATIChipID(PCI_DEV_DEVICE_ID(device));
if (chip_family == ATI_CHIP_FAMILY_Mach64) {
ati_gdev->driver = MACH64_DRIVER_NAME;
load_mach64 = TRUE;
}
if (chip_family == ATI_CHIP_FAMILY_Rage128) {
ati_gdev->driver = R128_DRIVER_NAME;
load_r128 = TRUE;
}
if (chip_family == ATI_CHIP_FAMILY_Radeon) {
ati_gdev->driver = RADEON_DRIVER_NAME;
load_radeon = TRUE;
}
}
xfree(ATIGDevs);
/* load subdrivers as primary modules and only if they do not get loaded
* from other device sections
*/
if (load_mach64 && (nMach64GDev == 0))
xf86LoadOneModule(MACH64_DRIVER_NAME, options);
if (load_r128 && (nR128GDev == 0))
xf86LoadOneModule(R128_DRIVER_NAME, options);
if (load_radeon && (nRadeonGDev == 0))
xf86LoadOneModule(RADEON_DRIVER_NAME, options);
}
/*
* ATIChipID --
*
* This returns the ATI_CHIP_FAMILY_* value associated with a particular ChipID.
*/
static int
ATIChipID(const uint16_t ChipID)
{
switch (ChipID)
{
case PCI_CHIP_MACH64GX:
case PCI_CHIP_MACH64CX:
case PCI_CHIP_MACH64CT:
case PCI_CHIP_MACH64ET:
case PCI_CHIP_MACH64VT:
case PCI_CHIP_MACH64GT:
case PCI_CHIP_MACH64VU:
case PCI_CHIP_MACH64GU:
case PCI_CHIP_MACH64LG:
case PCI_CHIP_MACH64VV:
case PCI_CHIP_MACH64GV:
case PCI_CHIP_MACH64GW:
case PCI_CHIP_MACH64GY:
case PCI_CHIP_MACH64GZ:
case PCI_CHIP_MACH64GB:
case PCI_CHIP_MACH64GD:
case PCI_CHIP_MACH64GI:
case PCI_CHIP_MACH64GP:
case PCI_CHIP_MACH64GQ:
case PCI_CHIP_MACH64LB:
case PCI_CHIP_MACH64LD:
case PCI_CHIP_MACH64LI:
case PCI_CHIP_MACH64LP:
case PCI_CHIP_MACH64LQ:
case PCI_CHIP_MACH64GL:
case PCI_CHIP_MACH64GM:
case PCI_CHIP_MACH64GN:
case PCI_CHIP_MACH64GO:
case PCI_CHIP_MACH64GR:
case PCI_CHIP_MACH64GS:
case PCI_CHIP_MACH64LM:
case PCI_CHIP_MACH64LN:
case PCI_CHIP_MACH64LR:
case PCI_CHIP_MACH64LS:
return ATI_CHIP_FAMILY_Mach64;
case PCI_CHIP_RAGE128RE:
case PCI_CHIP_RAGE128RF:
case PCI_CHIP_RAGE128RG:
case PCI_CHIP_RAGE128SK:
case PCI_CHIP_RAGE128SL:
case PCI_CHIP_RAGE128SM:
case PCI_CHIP_RAGE128SN:
case PCI_CHIP_RAGE128RK:
case PCI_CHIP_RAGE128RL:
case PCI_CHIP_RAGE128SE:
case PCI_CHIP_RAGE128SF:
case PCI_CHIP_RAGE128SG:
case PCI_CHIP_RAGE128SH:
case PCI_CHIP_RAGE128PA:
case PCI_CHIP_RAGE128PB:
case PCI_CHIP_RAGE128PC:
case PCI_CHIP_RAGE128PD:
case PCI_CHIP_RAGE128PE:
case PCI_CHIP_RAGE128PF:
case PCI_CHIP_RAGE128PG:
case PCI_CHIP_RAGE128PH:
case PCI_CHIP_RAGE128PI:
case PCI_CHIP_RAGE128PJ:
case PCI_CHIP_RAGE128PK:
case PCI_CHIP_RAGE128PL:
case PCI_CHIP_RAGE128PM:
case PCI_CHIP_RAGE128PN:
case PCI_CHIP_RAGE128PO:
case PCI_CHIP_RAGE128PP:
case PCI_CHIP_RAGE128PQ:
case PCI_CHIP_RAGE128PR:
case PCI_CHIP_RAGE128PS:
case PCI_CHIP_RAGE128PT:
case PCI_CHIP_RAGE128PU:
case PCI_CHIP_RAGE128PV:
case PCI_CHIP_RAGE128PW:
case PCI_CHIP_RAGE128PX:
case PCI_CHIP_RAGE128TF:
case PCI_CHIP_RAGE128TL:
case PCI_CHIP_RAGE128TR:
case PCI_CHIP_RAGE128TS:
case PCI_CHIP_RAGE128TT:
case PCI_CHIP_RAGE128TU:
case PCI_CHIP_RAGE128LE:
case PCI_CHIP_RAGE128LF:
#if 0
case PCI_CHIP_RAGE128LK:
case PCI_CHIP_RAGE128LL:
#endif
case PCI_CHIP_RAGE128MF:
case PCI_CHIP_RAGE128ML:
return ATI_CHIP_FAMILY_Rage128;
default:
return ATI_CHIP_FAMILY_Radeon;
}
}
|