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