ati.c revision 18781e08
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#include <pciaccess.h> 61#include "atipcirename.h" 62 63#include "ati.h" 64#include "atipciids.h" 65#include "ativersion.h" 66 67/* names duplicated from version headers */ 68#define MACH64_DRIVER_NAME "mach64" 69#define R128_DRIVER_NAME "r128" 70#define RADEON_DRIVER_NAME "radeon" 71 72enum 73{ 74 ATI_CHIP_FAMILY_NONE = 0, 75 ATI_CHIP_FAMILY_Mach64, 76 ATI_CHIP_FAMILY_Rage128, 77 ATI_CHIP_FAMILY_Radeon 78}; 79 80static int ATIChipID(const uint16_t); 81 82/* domain defines (stolen from xserver) */ 83#if (defined(__alpha__) || defined(__ia64__)) && defined (linux) 84# define PCI_DOM_MASK 0x01fful 85#else 86# define PCI_DOM_MASK 0x0ffu 87#endif 88 89#define PCI_DOM_FROM_BUS(bus) (((bus) >> 8) & (PCI_DOM_MASK)) 90#define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu) 91 92static struct pci_device* 93ati_device_get_from_busid(int bus, int dev, int func) 94{ 95 return pci_device_find_by_slot(PCI_DOM_FROM_BUS(bus), 96 PCI_BUS_NO_DOMAIN(bus), 97 dev, 98 func); 99} 100 101#ifndef XSERVER_PLATFORM_BUS 102static struct pci_device* 103ati_device_get_primary(void) 104{ 105 struct pci_device *device = NULL; 106 struct pci_device_iterator *device_iter; 107 108 device_iter = pci_slot_match_iterator_create(NULL); 109 110 while ((device = pci_device_next(device_iter)) != NULL) { 111 if (xf86IsPrimaryPci(device)) 112 break; 113 } 114 115 pci_iterator_destroy(device_iter); 116 117 return device; 118} 119#else 120static struct pci_device * 121ati_device_get_indexed(int index) 122{ 123 struct pci_device *device = NULL; 124 struct pci_device_iterator *device_iter; 125 int count = 0; 126 127 device_iter = pci_slot_match_iterator_create(NULL); 128 129 while ((device = pci_device_next(device_iter)) != NULL) { 130 if (device->vendor_id == PCI_VENDOR_ATI) { 131 if (count == index) 132 return device; 133 count++; 134 } 135 } 136 return NULL; 137} 138#endif 139 140void 141ati_gdev_subdriver(pointer options) 142{ 143 int nATIGDev, nMach64GDev, nR128GDev, nRadeonGDev; 144 GDevPtr *ATIGDevs; 145 Bool load_mach64 = FALSE, load_r128 = FALSE, load_radeon = FALSE; 146 int i; 147 148 /* let the subdrivers configure for themselves */ 149 if (xf86ServerIsOnlyDetecting()) 150 return; 151 152 /* get Device sections with Driver "ati" */ 153 nATIGDev = xf86MatchDevice(ATI_DRIVER_NAME, &ATIGDevs); 154 nMach64GDev = xf86MatchDevice(MACH64_DRIVER_NAME, NULL); 155 nR128GDev = xf86MatchDevice(R128_DRIVER_NAME, NULL); 156 nRadeonGDev = xf86MatchDevice(RADEON_DRIVER_NAME, NULL); 157 158 for (i = 0; i < nATIGDev; i++) { 159 GDevPtr ati_gdev = ATIGDevs[i]; 160 pciVideoPtr device = NULL; 161 int chip_family; 162 163 /* get pci device for the Device section */ 164 if (ati_gdev->busID) { 165 int bus, dev, func; 166 167 if (!xf86ParsePciBusString(ati_gdev->busID, &bus, &dev, &func)) 168 continue; 169 170 device = ati_device_get_from_busid(bus, dev, func); 171 } 172#ifdef XSERVER_PLATFORM_BUS 173 else 174 device = ati_device_get_indexed(i); 175#else 176 else { 177 device = ati_device_get_primary(); 178 } 179#endif 180 181 if (!device) 182 continue; 183 184 /* check for non-ati devices and prehistoric mach32 */ 185 if ((PCI_DEV_VENDOR_ID(device) != PCI_VENDOR_ATI) || 186 (PCI_DEV_DEVICE_ID(device) == PCI_CHIP_MACH32)) 187 continue; 188 189 /* replace Driver line in the Device section */ 190 chip_family = ATIChipID(PCI_DEV_DEVICE_ID(device)); 191 192 if (chip_family == ATI_CHIP_FAMILY_Mach64) { 193 ati_gdev->driver = MACH64_DRIVER_NAME; 194 load_mach64 = TRUE; 195 } 196 197 if (chip_family == ATI_CHIP_FAMILY_Rage128) { 198 ati_gdev->driver = R128_DRIVER_NAME; 199 load_r128 = TRUE; 200 } 201 202 if (chip_family == ATI_CHIP_FAMILY_Radeon) { 203 ati_gdev->driver = RADEON_DRIVER_NAME; 204 load_radeon = TRUE; 205 } 206 } 207 208 free(ATIGDevs); 209 210 /* load subdrivers as primary modules and only if they do not get loaded 211 * from other device sections 212 */ 213 214 if (load_mach64 && (nMach64GDev == 0)) 215 xf86LoadOneModule(MACH64_DRIVER_NAME, options); 216 217 if (load_r128 && (nR128GDev == 0)) 218 xf86LoadOneModule(R128_DRIVER_NAME, options); 219 220 if (load_radeon && (nRadeonGDev == 0)) 221 xf86LoadOneModule(RADEON_DRIVER_NAME, options); 222} 223 224/* 225 * ATIChipID -- 226 * 227 * This returns the ATI_CHIP_FAMILY_* value associated with a particular ChipID. 228 */ 229static int 230ATIChipID(const uint16_t ChipID) 231{ 232 switch (ChipID) 233 { 234 case PCI_CHIP_MACH64GX: 235 case PCI_CHIP_MACH64CX: 236 case PCI_CHIP_MACH64CT: 237 case PCI_CHIP_MACH64ET: 238 case PCI_CHIP_MACH64VT: 239 case PCI_CHIP_MACH64GT: 240 case PCI_CHIP_MACH64VU: 241 case PCI_CHIP_MACH64GU: 242 case PCI_CHIP_MACH64LG: 243 case PCI_CHIP_MACH64VV: 244 case PCI_CHIP_MACH64GV: 245 case PCI_CHIP_MACH64GW: 246 case PCI_CHIP_MACH64GY: 247 case PCI_CHIP_MACH64GZ: 248 case PCI_CHIP_MACH64GB: 249 case PCI_CHIP_MACH64GD: 250 case PCI_CHIP_MACH64GI: 251 case PCI_CHIP_MACH64GP: 252 case PCI_CHIP_MACH64GQ: 253 case PCI_CHIP_MACH64LB: 254 case PCI_CHIP_MACH64LD: 255 case PCI_CHIP_MACH64LI: 256 case PCI_CHIP_MACH64LP: 257 case PCI_CHIP_MACH64LQ: 258 case PCI_CHIP_MACH64GL: 259 case PCI_CHIP_MACH64GM: 260 case PCI_CHIP_MACH64GN: 261 case PCI_CHIP_MACH64GO: 262 case PCI_CHIP_MACH64GR: 263 case PCI_CHIP_MACH64GS: 264 case PCI_CHIP_MACH64LM: 265 case PCI_CHIP_MACH64LN: 266 case PCI_CHIP_MACH64LR: 267 case PCI_CHIP_MACH64LS: 268 return ATI_CHIP_FAMILY_Mach64; 269 270 case PCI_CHIP_RAGE128RE: 271 case PCI_CHIP_RAGE128RF: 272 case PCI_CHIP_RAGE128RG: 273 case PCI_CHIP_RAGE128SK: 274 case PCI_CHIP_RAGE128SL: 275 case PCI_CHIP_RAGE128SM: 276 case PCI_CHIP_RAGE128SN: 277 case PCI_CHIP_RAGE128RK: 278 case PCI_CHIP_RAGE128RL: 279 case PCI_CHIP_RAGE128SE: 280 case PCI_CHIP_RAGE128SF: 281 case PCI_CHIP_RAGE128SG: 282 case PCI_CHIP_RAGE128SH: 283 case PCI_CHIP_RAGE128PA: 284 case PCI_CHIP_RAGE128PB: 285 case PCI_CHIP_RAGE128PC: 286 case PCI_CHIP_RAGE128PD: 287 case PCI_CHIP_RAGE128PE: 288 case PCI_CHIP_RAGE128PF: 289 case PCI_CHIP_RAGE128PG: 290 case PCI_CHIP_RAGE128PH: 291 case PCI_CHIP_RAGE128PI: 292 case PCI_CHIP_RAGE128PJ: 293 case PCI_CHIP_RAGE128PK: 294 case PCI_CHIP_RAGE128PL: 295 case PCI_CHIP_RAGE128PM: 296 case PCI_CHIP_RAGE128PN: 297 case PCI_CHIP_RAGE128PO: 298 case PCI_CHIP_RAGE128PP: 299 case PCI_CHIP_RAGE128PQ: 300 case PCI_CHIP_RAGE128PR: 301 case PCI_CHIP_RAGE128PS: 302 case PCI_CHIP_RAGE128PT: 303 case PCI_CHIP_RAGE128PU: 304 case PCI_CHIP_RAGE128PV: 305 case PCI_CHIP_RAGE128PW: 306 case PCI_CHIP_RAGE128PX: 307 case PCI_CHIP_RAGE128TF: 308 case PCI_CHIP_RAGE128TL: 309 case PCI_CHIP_RAGE128TR: 310 case PCI_CHIP_RAGE128TS: 311 case PCI_CHIP_RAGE128TT: 312 case PCI_CHIP_RAGE128TU: 313 case PCI_CHIP_RAGE128LE: 314 case PCI_CHIP_RAGE128LF: 315#if 0 316 case PCI_CHIP_RAGE128LK: 317 case PCI_CHIP_RAGE128LL: 318#endif 319 case PCI_CHIP_RAGE128MF: 320 case PCI_CHIP_RAGE128ML: 321 return ATI_CHIP_FAMILY_Rage128; 322 323 default: 324 return ATI_CHIP_FAMILY_Radeon; 325 } 326} 327