radeon_driver.c revision 209ff23f
1/* 2 * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and 3 * VA Linux Systems Inc., Fremont, California. 4 * 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining 8 * a copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation on the rights to use, copy, modify, merge, 11 * publish, distribute, sublicense, and/or sell copies of the Software, 12 * and to permit persons to whom the Software is furnished to do so, 13 * subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the 16 * next paragraph) shall be included in all copies or substantial 17 * portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR 23 * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 * DEALINGS IN THE SOFTWARE. 27 */ 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33/* 34 * Authors: 35 * Kevin E. Martin <martin@xfree86.org> 36 * Rickard E. Faith <faith@valinux.com> 37 * Alan Hourihane <alanh@fairlite.demon.co.uk> 38 * 39 * Credits: 40 * 41 * Thanks to Ani Joshi <ajoshi@shell.unixbox.com> for providing source 42 * code to his Radeon driver. Portions of this file are based on the 43 * initialization code for that driver. 44 * 45 * References: 46 * 47 * !!!! FIXME !!!! 48 * RAGE 128 VR/ RAGE 128 GL Register Reference Manual (Technical 49 * Reference Manual P/N RRG-G04100-C Rev. 0.04), ATI Technologies: April 50 * 1999. 51 * 52 * RAGE 128 Software Development Manual (Technical Reference Manual P/N 53 * SDK-G04000 Rev. 0.01), ATI Technologies: June 1999. 54 * 55 * This server does not yet support these XFree86 4.0 features: 56 * !!!! FIXME !!!! 57 * DDC1 & DDC2 58 * shadowfb 59 * overlay planes 60 * 61 * Modified by Marc Aurele La France (tsi@xfree86.org) for ATI driver merge. 62 * 63 * Mergedfb and pseudo xinerama support added by Alex Deucher (agd5f@yahoo.com) 64 * based on the sis driver by Thomas Winischhofer. 65 * 66 */ 67 68#include <string.h> 69#include <stdio.h> 70 71 /* Driver data structures */ 72#include "radeon.h" 73#include "radeon_reg.h" 74#include "radeon_macros.h" 75#include "radeon_probe.h" 76#include "radeon_version.h" 77#include "radeon_atombios.h" 78 79#ifdef XF86DRI 80#define _XF86DRI_SERVER_ 81#include "radeon_dri.h" 82#include "radeon_sarea.h" 83#include "sarea.h" 84#endif 85 86#include "fb.h" 87 88 /* colormap initialization */ 89#include "micmap.h" 90#include "dixstruct.h" 91 92 /* X and server generic header files */ 93#include "xf86.h" 94#include "xf86_OSproc.h" 95#include "xf86RAC.h" 96#include "xf86RandR12.h" 97#include "xf86Resources.h" 98#include "xf86cmap.h" 99#include "vbe.h" 100 101#include "shadow.h" 102 /* vgaHW definitions */ 103#ifdef WITH_VGAHW 104#include "vgaHW.h" 105#endif 106 107#define DPMS_SERVER 108#include <X11/extensions/dpms.h> 109 110#include "atipciids.h" 111#include "radeon_chipset_gen.h" 112 113 114#include "radeon_chipinfo_gen.h" 115 116 /* Forward definitions for driver functions */ 117static Bool RADEONCloseScreen(int scrnIndex, ScreenPtr pScreen); 118static Bool RADEONSaveScreen(ScreenPtr pScreen, int mode); 119static void RADEONSave(ScrnInfoPtr pScrn); 120 121static void RADEONSetDynamicClock(ScrnInfoPtr pScrn, int mode); 122static void RADEONForceSomeClocks(ScrnInfoPtr pScrn); 123static void RADEONSaveMemMapRegisters(ScrnInfoPtr pScrn, RADEONSavePtr save); 124 125#ifdef XF86DRI 126static void RADEONAdjustMemMapRegisters(ScrnInfoPtr pScrn, RADEONSavePtr save); 127#endif 128 129static const OptionInfoRec RADEONOptions[] = { 130 { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE }, 131 { OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE }, 132 { OPTION_DAC_6BIT, "Dac6Bit", OPTV_BOOLEAN, {0}, FALSE }, 133 { OPTION_DAC_8BIT, "Dac8Bit", OPTV_BOOLEAN, {0}, TRUE }, 134#ifdef XF86DRI 135 { OPTION_BUS_TYPE, "BusType", OPTV_ANYSTR, {0}, FALSE }, 136 { OPTION_CP_PIO, "CPPIOMode", OPTV_BOOLEAN, {0}, FALSE }, 137 { OPTION_USEC_TIMEOUT, "CPusecTimeout", OPTV_INTEGER, {0}, FALSE }, 138 { OPTION_AGP_MODE, "AGPMode", OPTV_INTEGER, {0}, FALSE }, 139 { OPTION_AGP_FW, "AGPFastWrite", OPTV_BOOLEAN, {0}, FALSE }, 140 { OPTION_GART_SIZE_OLD, "AGPSize", OPTV_INTEGER, {0}, FALSE }, 141 { OPTION_GART_SIZE, "GARTSize", OPTV_INTEGER, {0}, FALSE }, 142 { OPTION_RING_SIZE, "RingSize", OPTV_INTEGER, {0}, FALSE }, 143 { OPTION_BUFFER_SIZE, "BufferSize", OPTV_INTEGER, {0}, FALSE }, 144 { OPTION_DEPTH_MOVE, "EnableDepthMoves", OPTV_BOOLEAN, {0}, FALSE }, 145 { OPTION_PAGE_FLIP, "EnablePageFlip", OPTV_BOOLEAN, {0}, FALSE }, 146 { OPTION_NO_BACKBUFFER, "NoBackBuffer", OPTV_BOOLEAN, {0}, FALSE }, 147 { OPTION_XV_DMA, "DMAForXv", OPTV_BOOLEAN, {0}, FALSE }, 148 { OPTION_FBTEX_PERCENT, "FBTexPercent", OPTV_INTEGER, {0}, FALSE }, 149 { OPTION_DEPTH_BITS, "DepthBits", OPTV_INTEGER, {0}, FALSE }, 150 { OPTION_PCIAPER_SIZE, "PCIAPERSize", OPTV_INTEGER, {0}, FALSE }, 151#ifdef USE_EXA 152 { OPTION_ACCEL_DFS, "AccelDFS", OPTV_BOOLEAN, {0}, FALSE }, 153#endif 154#endif 155 { OPTION_DDC_MODE, "DDCMode", OPTV_BOOLEAN, {0}, FALSE }, 156 { OPTION_IGNORE_EDID, "IgnoreEDID", OPTV_BOOLEAN, {0}, FALSE }, 157 { OPTION_DISP_PRIORITY, "DisplayPriority", OPTV_ANYSTR, {0}, FALSE }, 158 { OPTION_PANEL_SIZE, "PanelSize", OPTV_ANYSTR, {0}, FALSE }, 159 { OPTION_MIN_DOTCLOCK, "ForceMinDotClock", OPTV_FREQ, {0}, FALSE }, 160 { OPTION_COLOR_TILING, "ColorTiling", OPTV_BOOLEAN, {0}, FALSE }, 161#ifdef XvExtension 162 { OPTION_VIDEO_KEY, "VideoKey", OPTV_INTEGER, {0}, FALSE }, 163 { OPTION_RAGE_THEATRE_CRYSTAL, "RageTheatreCrystal", OPTV_INTEGER, {0}, FALSE }, 164 { OPTION_RAGE_THEATRE_TUNER_PORT, "RageTheatreTunerPort", OPTV_INTEGER, {0}, FALSE }, 165 { OPTION_RAGE_THEATRE_COMPOSITE_PORT, "RageTheatreCompositePort", OPTV_INTEGER, {0}, FALSE }, 166 { OPTION_RAGE_THEATRE_SVIDEO_PORT, "RageTheatreSVideoPort", OPTV_INTEGER, {0}, FALSE }, 167 { OPTION_TUNER_TYPE, "TunerType", OPTV_INTEGER, {0}, FALSE }, 168 { OPTION_RAGE_THEATRE_MICROC_PATH, "RageTheatreMicrocPath", OPTV_STRING, {0}, FALSE }, 169 { OPTION_RAGE_THEATRE_MICROC_TYPE, "RageTheatreMicrocType", OPTV_STRING, {0}, FALSE }, 170 { OPTION_SCALER_WIDTH, "ScalerWidth", OPTV_INTEGER, {0}, FALSE }, 171#endif 172#ifdef RENDER 173 { OPTION_RENDER_ACCEL, "RenderAccel", OPTV_BOOLEAN, {0}, FALSE }, 174 { OPTION_SUBPIXEL_ORDER, "SubPixelOrder", OPTV_ANYSTR, {0}, FALSE }, 175#endif 176 { OPTION_SHOWCACHE, "ShowCache", OPTV_BOOLEAN, {0}, FALSE }, 177 { OPTION_DYNAMIC_CLOCKS, "DynamicClocks", OPTV_BOOLEAN, {0}, FALSE }, 178 { OPTION_VGA_ACCESS, "VGAAccess", OPTV_BOOLEAN, {0}, TRUE }, 179 { OPTION_REVERSE_DDC, "ReverseDDC", OPTV_BOOLEAN, {0}, FALSE }, 180 { OPTION_LVDS_PROBE_PLL, "LVDSProbePLL", OPTV_BOOLEAN, {0}, FALSE }, 181 { OPTION_ACCELMETHOD, "AccelMethod", OPTV_STRING, {0}, FALSE }, 182 { OPTION_DRI, "DRI", OPTV_BOOLEAN, {0}, FALSE }, 183 { OPTION_CONNECTORTABLE, "ConnectorTable", OPTV_STRING, {0}, FALSE }, 184 { OPTION_DEFAULT_CONNECTOR_TABLE, "DefaultConnectorTable", OPTV_BOOLEAN, {0}, FALSE }, 185 { OPTION_DEFAULT_TMDS_PLL, "DefaultTMDSPLL", OPTV_BOOLEAN, {0}, FALSE }, 186#if defined(__powerpc__) 187 { OPTION_MAC_MODEL, "MacModel", OPTV_STRING, {0}, FALSE }, 188#endif 189 { OPTION_TVDAC_LOAD_DETECT, "TVDACLoadDetect", OPTV_BOOLEAN, {0}, FALSE }, 190 { OPTION_FORCE_TVOUT, "ForceTVOut", OPTV_BOOLEAN, {0}, FALSE }, 191 { OPTION_TVSTD, "TVStandard", OPTV_STRING, {0}, FALSE }, 192 { OPTION_IGNORE_LID_STATUS, "IgnoreLidStatus", OPTV_BOOLEAN, {0}, FALSE }, 193 { OPTION_DEFAULT_TVDAC_ADJ, "DefaultTVDACAdj", OPTV_BOOLEAN, {0}, FALSE }, 194 { OPTION_INT10, "Int10", OPTV_BOOLEAN, {0}, FALSE }, 195 { -1, NULL, OPTV_NONE, {0}, FALSE } 196}; 197 198const OptionInfoRec *RADEONOptionsWeak(void) { return RADEONOptions; } 199 200extern _X_EXPORT int gRADEONEntityIndex; 201 202static int getRADEONEntityIndex(void) 203{ 204 return gRADEONEntityIndex; 205} 206 207struct RADEONInt10Save { 208 uint32_t MEM_CNTL; 209 uint32_t MEMSIZE; 210 uint32_t MPP_TB_CONFIG; 211}; 212 213static Bool RADEONMapMMIO(ScrnInfoPtr pScrn); 214static Bool RADEONUnmapMMIO(ScrnInfoPtr pScrn); 215 216static void * 217radeonShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode, 218 CARD32 *size, void *closure) 219{ 220 ScrnInfoPtr pScrn = xf86Screens[screen->myNum]; 221 RADEONInfoPtr info = RADEONPTR(pScrn); 222 int stride; 223 224 stride = (pScrn->displayWidth * pScrn->bitsPerPixel) / 8; 225 *size = stride; 226 227 return ((uint8_t *)info->FB + row * stride + offset); 228} 229static Bool 230RADEONCreateScreenResources (ScreenPtr pScreen) 231{ 232 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 233 RADEONInfoPtr info = RADEONPTR(pScrn); 234 PixmapPtr pixmap; 235 236 pScreen->CreateScreenResources = info->CreateScreenResources; 237 if (!(*pScreen->CreateScreenResources)(pScreen)) 238 return FALSE; 239 pScreen->CreateScreenResources = RADEONCreateScreenResources; 240 241 if (info->r600_shadow_fb) { 242 pixmap = pScreen->GetScreenPixmap(pScreen); 243 244 if (!shadowAdd(pScreen, pixmap, shadowUpdatePackedWeak(), 245 radeonShadowWindow, 0, NULL)) 246 return FALSE; 247 } 248 return TRUE; 249} 250 251RADEONEntPtr RADEONEntPriv(ScrnInfoPtr pScrn) 252{ 253 DevUnion *pPriv; 254 RADEONInfoPtr info = RADEONPTR(pScrn); 255 pPriv = xf86GetEntityPrivate(info->pEnt->index, 256 getRADEONEntityIndex()); 257 return pPriv->ptr; 258} 259 260static void 261RADEONPreInt10Save(ScrnInfoPtr pScrn, void **pPtr) 262{ 263 RADEONInfoPtr info = RADEONPTR(pScrn); 264 unsigned char *RADEONMMIO = info->MMIO; 265 uint32_t CardTmp; 266 static struct RADEONInt10Save SaveStruct = { 0, 0, 0 }; 267 268 if (!IS_AVIVO_VARIANT) { 269 /* Save the values and zap MEM_CNTL */ 270 SaveStruct.MEM_CNTL = INREG(RADEON_MEM_CNTL); 271 SaveStruct.MEMSIZE = INREG(RADEON_CONFIG_MEMSIZE); 272 SaveStruct.MPP_TB_CONFIG = INREG(RADEON_MPP_TB_CONFIG); 273 274 /* 275 * Zap MEM_CNTL and set MPP_TB_CONFIG<31:24> to 4 276 */ 277 OUTREG(RADEON_MEM_CNTL, 0); 278 CardTmp = SaveStruct.MPP_TB_CONFIG & 0x00ffffffu; 279 CardTmp |= 0x04 << 24; 280 OUTREG(RADEON_MPP_TB_CONFIG, CardTmp); 281 } 282 283 *pPtr = (void *)&SaveStruct; 284} 285 286static void 287RADEONPostInt10Check(ScrnInfoPtr pScrn, void *ptr) 288{ 289 RADEONInfoPtr info = RADEONPTR(pScrn); 290 unsigned char *RADEONMMIO = info->MMIO; 291 struct RADEONInt10Save *pSave = ptr; 292 uint32_t CardTmp; 293 294 /* If we don't have a valid (non-zero) saved MEM_CNTL, get out now */ 295 if (!pSave || !pSave->MEM_CNTL) 296 return; 297 298 if (IS_AVIVO_VARIANT) 299 return; 300 301 /* 302 * If either MEM_CNTL is currently zero or inconistent (configured for 303 * two channels with the two channels configured differently), restore 304 * the saved registers. 305 */ 306 CardTmp = INREG(RADEON_MEM_CNTL); 307 if (!CardTmp || 308 ((CardTmp & 1) && 309 (((CardTmp >> 8) & 0xff) != ((CardTmp >> 24) & 0xff)))) { 310 /* Restore the saved registers */ 311 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 312 "Restoring MEM_CNTL (%08lx), setting to %08lx\n", 313 (unsigned long)CardTmp, (unsigned long)pSave->MEM_CNTL); 314 OUTREG(RADEON_MEM_CNTL, pSave->MEM_CNTL); 315 316 CardTmp = INREG(RADEON_CONFIG_MEMSIZE); 317 if (CardTmp != pSave->MEMSIZE) { 318 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 319 "Restoring CONFIG_MEMSIZE (%08lx), setting to %08lx\n", 320 (unsigned long)CardTmp, (unsigned long)pSave->MEMSIZE); 321 OUTREG(RADEON_CONFIG_MEMSIZE, pSave->MEMSIZE); 322 } 323 } 324 325 CardTmp = INREG(RADEON_MPP_TB_CONFIG); 326 if ((CardTmp & 0xff000000u) != (pSave->MPP_TB_CONFIG & 0xff000000u)) { 327 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 328 "Restoring MPP_TB_CONFIG<31:24> (%02lx), setting to %02lx\n", 329 (unsigned long)CardTmp >> 24, 330 (unsigned long)pSave->MPP_TB_CONFIG >> 24); 331 CardTmp &= 0x00ffffffu; 332 CardTmp |= (pSave->MPP_TB_CONFIG & 0xff000000u); 333 OUTREG(RADEON_MPP_TB_CONFIG, CardTmp); 334 } 335} 336 337/* Allocate our private RADEONInfoRec */ 338static Bool RADEONGetRec(ScrnInfoPtr pScrn) 339{ 340 if (pScrn->driverPrivate) return TRUE; 341 342 pScrn->driverPrivate = xnfcalloc(sizeof(RADEONInfoRec), 1); 343 return TRUE; 344} 345 346/* Free our private RADEONInfoRec */ 347static void RADEONFreeRec(ScrnInfoPtr pScrn) 348{ 349 if (!pScrn || !pScrn->driverPrivate) return; 350 xfree(pScrn->driverPrivate); 351 pScrn->driverPrivate = NULL; 352} 353 354/* Memory map the MMIO region. Used during pre-init and by RADEONMapMem, 355 * below 356 */ 357static Bool RADEONMapMMIO(ScrnInfoPtr pScrn) 358{ 359 RADEONInfoPtr info = RADEONPTR(pScrn); 360 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 361 362 if (pRADEONEnt->MMIO) { 363 info->MMIO = pRADEONEnt->MMIO; 364 return TRUE; 365 } 366 367#ifndef XSERVER_LIBPCIACCESS 368 369 info->MMIO = xf86MapPciMem(pScrn->scrnIndex, 370 VIDMEM_MMIO | VIDMEM_READSIDEEFFECT, 371 info->PciTag, 372 info->MMIOAddr, 373 info->MMIOSize); 374 375 if (!info->MMIO) return FALSE; 376#else 377 378 void** result = (void**)&info->MMIO; 379 int err = pci_device_map_range(info->PciInfo, 380 info->MMIOAddr, 381 info->MMIOSize, 382 PCI_DEV_MAP_FLAG_WRITABLE, 383 result); 384 385 if (err) { 386 xf86DrvMsg (pScrn->scrnIndex, X_ERROR, 387 "Unable to map MMIO aperture. %s (%d)\n", 388 strerror (err), err); 389 return FALSE; 390 } 391 392#endif 393 394 pRADEONEnt->MMIO = info->MMIO; 395 return TRUE; 396} 397 398/* Unmap the MMIO region. Used during pre-init and by RADEONUnmapMem, 399 * below 400 */ 401static Bool RADEONUnmapMMIO(ScrnInfoPtr pScrn) 402{ 403 RADEONInfoPtr info = RADEONPTR(pScrn); 404 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 405 406 if (info->IsPrimary || info->IsSecondary) { 407 /* never unmap on zaphod */ 408 info->MMIO = NULL; 409 return TRUE; 410 } 411 412#ifndef XSERVER_LIBPCIACCESS 413 xf86UnMapVidMem(pScrn->scrnIndex, info->MMIO, info->MMIOSize); 414#else 415 pci_device_unmap_range(info->PciInfo, info->MMIO, info->MMIOSize); 416#endif 417 418 pRADEONEnt->MMIO = NULL; 419 info->MMIO = NULL; 420 return TRUE; 421} 422 423/* Memory map the frame buffer. Used by RADEONMapMem, below. */ 424static Bool RADEONMapFB(ScrnInfoPtr pScrn) 425{ 426#ifdef XSERVER_LIBPCIACCESS 427 int err; 428#endif 429 RADEONInfoPtr info = RADEONPTR(pScrn); 430 431 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 432 "Map: 0x%08lx, 0x%08lx\n", info->LinearAddr, info->FbMapSize); 433 434#ifndef XSERVER_LIBPCIACCESS 435 436 info->FB = xf86MapPciMem(pScrn->scrnIndex, 437 VIDMEM_FRAMEBUFFER, 438 info->PciTag, 439 info->LinearAddr, 440 info->FbMapSize); 441 442 if (!info->FB) return FALSE; 443 444#else 445 446 err = pci_device_map_range(info->PciInfo, 447 info->LinearAddr, 448 info->FbMapSize, 449 PCI_DEV_MAP_FLAG_WRITABLE | 450 PCI_DEV_MAP_FLAG_WRITE_COMBINE, 451 &info->FB); 452 453 if (err) { 454 xf86DrvMsg (pScrn->scrnIndex, X_ERROR, 455 "Unable to map FB aperture. %s (%d)\n", 456 strerror (err), err); 457 return FALSE; 458 } 459 460#endif 461 462 return TRUE; 463} 464 465/* Unmap the frame buffer. Used by RADEONUnmapMem, below. */ 466static Bool RADEONUnmapFB(ScrnInfoPtr pScrn) 467{ 468 RADEONInfoPtr info = RADEONPTR(pScrn); 469 470#ifndef XSERVER_LIBPCIACCESS 471 xf86UnMapVidMem(pScrn->scrnIndex, info->FB, info->FbMapSize); 472#else 473 pci_device_unmap_range(info->PciInfo, info->FB, info->FbMapSize); 474#endif 475 476 info->FB = NULL; 477 return TRUE; 478} 479 480/* Memory map the MMIO region and the frame buffer */ 481static Bool RADEONMapMem(ScrnInfoPtr pScrn) 482{ 483 if (!RADEONMapMMIO(pScrn)) return FALSE; 484 if (!RADEONMapFB(pScrn)) { 485 RADEONUnmapMMIO(pScrn); 486 return FALSE; 487 } 488 return TRUE; 489} 490 491/* Unmap the MMIO region and the frame buffer */ 492static Bool RADEONUnmapMem(ScrnInfoPtr pScrn) 493{ 494 if (!RADEONUnmapMMIO(pScrn) || !RADEONUnmapFB(pScrn)) return FALSE; 495 return TRUE; 496} 497 498void RADEONPllErrataAfterIndex(RADEONInfoPtr info) 499{ 500 unsigned char *RADEONMMIO = info->MMIO; 501 502 if (!(info->ChipErrata & CHIP_ERRATA_PLL_DUMMYREADS)) 503 return; 504 505 /* This workaround is necessary on rv200 and RS200 or PLL 506 * reads may return garbage (among others...) 507 */ 508 (void)INREG(RADEON_CLOCK_CNTL_DATA); 509 (void)INREG(RADEON_CRTC_GEN_CNTL); 510} 511 512void RADEONPllErrataAfterData(RADEONInfoPtr info) 513{ 514 unsigned char *RADEONMMIO = info->MMIO; 515 516 /* This workarounds is necessary on RV100, RS100 and RS200 chips 517 * or the chip could hang on a subsequent access 518 */ 519 if (info->ChipErrata & CHIP_ERRATA_PLL_DELAY) { 520 /* we can't deal with posted writes here ... */ 521 usleep(5000); 522 } 523 524 /* This function is required to workaround a hardware bug in some (all?) 525 * revisions of the R300. This workaround should be called after every 526 * CLOCK_CNTL_INDEX register access. If not, register reads afterward 527 * may not be correct. 528 */ 529 if (info->ChipErrata & CHIP_ERRATA_R300_CG) { 530 uint32_t save, tmp; 531 532 save = INREG(RADEON_CLOCK_CNTL_INDEX); 533 tmp = save & ~(0x3f | RADEON_PLL_WR_EN); 534 OUTREG(RADEON_CLOCK_CNTL_INDEX, tmp); 535 tmp = INREG(RADEON_CLOCK_CNTL_DATA); 536 OUTREG(RADEON_CLOCK_CNTL_INDEX, save); 537 } 538} 539 540/* Read PLL register */ 541unsigned RADEONINPLL(ScrnInfoPtr pScrn, int addr) 542{ 543 RADEONInfoPtr info = RADEONPTR(pScrn); 544 unsigned char *RADEONMMIO = info->MMIO; 545 uint32_t data; 546 547 OUTREG8(RADEON_CLOCK_CNTL_INDEX, addr & 0x3f); 548 RADEONPllErrataAfterIndex(info); 549 data = INREG(RADEON_CLOCK_CNTL_DATA); 550 RADEONPllErrataAfterData(info); 551 552 return data; 553} 554 555/* Write PLL information */ 556void RADEONOUTPLL(ScrnInfoPtr pScrn, int addr, uint32_t data) 557{ 558 RADEONInfoPtr info = RADEONPTR(pScrn); 559 unsigned char *RADEONMMIO = info->MMIO; 560 561 OUTREG8(RADEON_CLOCK_CNTL_INDEX, (((addr) & 0x3f) | 562 RADEON_PLL_WR_EN)); 563 RADEONPllErrataAfterIndex(info); 564 OUTREG(RADEON_CLOCK_CNTL_DATA, data); 565 RADEONPllErrataAfterData(info); 566} 567 568/* Read MC register */ 569unsigned RADEONINMC(ScrnInfoPtr pScrn, int addr) 570{ 571 RADEONInfoPtr info = RADEONPTR(pScrn); 572 unsigned char *RADEONMMIO = info->MMIO; 573 uint32_t data; 574 575 if ((info->ChipFamily == CHIP_FAMILY_RS690) || 576 (info->ChipFamily == CHIP_FAMILY_RS740)) { 577 OUTREG(RS690_MC_INDEX, (addr & RS690_MC_INDEX_MASK)); 578 data = INREG(RS690_MC_DATA); 579 } else if (info->ChipFamily == CHIP_FAMILY_RS600) { 580 OUTREG(RS600_MC_INDEX, (addr & RS600_MC_INDEX_MASK)); 581 data = INREG(RS600_MC_DATA); 582 } else if (IS_AVIVO_VARIANT) { 583 OUTREG(AVIVO_MC_INDEX, (addr & 0xff) | 0x7f0000); 584 (void)INREG(AVIVO_MC_INDEX); 585 data = INREG(AVIVO_MC_DATA); 586 587 OUTREG(AVIVO_MC_INDEX, 0); 588 (void)INREG(AVIVO_MC_INDEX); 589 } else { 590 OUTREG(R300_MC_IND_INDEX, addr & 0x3f); 591 (void)INREG(R300_MC_IND_INDEX); 592 data = INREG(R300_MC_IND_DATA); 593 594 OUTREG(R300_MC_IND_INDEX, 0); 595 (void)INREG(R300_MC_IND_INDEX); 596 } 597 598 return data; 599} 600 601/* Write MC information */ 602void RADEONOUTMC(ScrnInfoPtr pScrn, int addr, uint32_t data) 603{ 604 RADEONInfoPtr info = RADEONPTR(pScrn); 605 unsigned char *RADEONMMIO = info->MMIO; 606 607 if ((info->ChipFamily == CHIP_FAMILY_RS690) || 608 (info->ChipFamily == CHIP_FAMILY_RS740)) { 609 OUTREG(RS690_MC_INDEX, ((addr & RS690_MC_INDEX_MASK) | 610 RS690_MC_INDEX_WR_EN)); 611 OUTREG(RS690_MC_DATA, data); 612 OUTREG(RS690_MC_INDEX, RS690_MC_INDEX_WR_ACK); 613 } else if (info->ChipFamily == CHIP_FAMILY_RS600) { 614 OUTREG(RS600_MC_INDEX, ((addr & RS600_MC_INDEX_MASK) | 615 RS600_MC_INDEX_WR_EN)); 616 OUTREG(RS600_MC_DATA, data); 617 OUTREG(RS600_MC_INDEX, RS600_MC_INDEX_WR_ACK); 618 } else if (IS_AVIVO_VARIANT) { 619 OUTREG(AVIVO_MC_INDEX, (addr & 0xff) | 0xff0000); 620 (void)INREG(AVIVO_MC_INDEX); 621 OUTREG(AVIVO_MC_DATA, data); 622 OUTREG(AVIVO_MC_INDEX, 0); 623 (void)INREG(AVIVO_MC_INDEX); 624 } else { 625 OUTREG(R300_MC_IND_INDEX, (((addr) & 0x3f) | 626 R300_MC_IND_WR_EN)); 627 (void)INREG(R300_MC_IND_INDEX); 628 OUTREG(R300_MC_IND_DATA, data); 629 OUTREG(R300_MC_IND_INDEX, 0); 630 (void)INREG(R300_MC_IND_INDEX); 631 } 632} 633 634static Bool avivo_get_mc_idle(ScrnInfoPtr pScrn) 635{ 636 RADEONInfoPtr info = RADEONPTR(pScrn); 637 638 if (info->ChipFamily >= CHIP_FAMILY_R600) { 639 /* no idea where this is on r600 yet */ 640 return TRUE; 641 } else if (info->ChipFamily == CHIP_FAMILY_RV515) { 642 if (INMC(pScrn, RV515_MC_STATUS) & RV515_MC_STATUS_IDLE) 643 return TRUE; 644 else 645 return FALSE; 646 } else if (info->ChipFamily == CHIP_FAMILY_RS600) { 647 if (INMC(pScrn, RS600_MC_STATUS) & RS600_MC_STATUS_IDLE) 648 return TRUE; 649 else 650 return FALSE; 651 } else if ((info->ChipFamily == CHIP_FAMILY_RS690) || 652 (info->ChipFamily == CHIP_FAMILY_RS740)) { 653 if (INMC(pScrn, RS690_MC_STATUS) & RS690_MC_STATUS_IDLE) 654 return TRUE; 655 else 656 return FALSE; 657 } else { 658 if (INMC(pScrn, R520_MC_STATUS) & R520_MC_STATUS_IDLE) 659 return TRUE; 660 else 661 return FALSE; 662 } 663} 664 665#define LOC_FB 0x1 666#define LOC_AGP 0x2 667static void radeon_write_mc_fb_agp_location(ScrnInfoPtr pScrn, int mask, uint32_t fb_loc, uint32_t agp_loc, uint32_t agp_loc_hi) 668{ 669 RADEONInfoPtr info = RADEONPTR(pScrn); 670 unsigned char *RADEONMMIO = info->MMIO; 671 672 if (info->ChipFamily >= CHIP_FAMILY_R600) { 673 if (mask & LOC_FB) 674 OUTREG(R600_MC_VM_FB_LOCATION, fb_loc); 675 if (mask & LOC_AGP) { 676 OUTREG(R600_MC_VM_AGP_BOT, agp_loc); 677 OUTREG(R600_MC_VM_AGP_TOP, agp_loc_hi); 678 } 679 } else if (info->ChipFamily == CHIP_FAMILY_RV515) { 680 if (mask & LOC_FB) 681 OUTMC(pScrn, RV515_MC_FB_LOCATION, fb_loc); 682 if (mask & LOC_AGP) 683 OUTMC(pScrn, RV515_MC_AGP_LOCATION, agp_loc); 684 (void)INMC(pScrn, RV515_MC_AGP_LOCATION); 685 } else if (info->ChipFamily == CHIP_FAMILY_RS600) { 686 if (mask & LOC_FB) 687 OUTMC(pScrn, RS600_MC_FB_LOCATION, fb_loc); 688 /* if (mask & LOC_AGP) 689 OUTMC(pScrn, RS600_MC_AGP_LOCATION, agp_loc);*/ 690 } else if ((info->ChipFamily == CHIP_FAMILY_RS690) || 691 (info->ChipFamily == CHIP_FAMILY_RS740)) { 692 if (mask & LOC_FB) 693 OUTMC(pScrn, RS690_MC_FB_LOCATION, fb_loc); 694 if (mask & LOC_AGP) 695 OUTMC(pScrn, RS690_MC_AGP_LOCATION, agp_loc); 696 } else if (info->ChipFamily >= CHIP_FAMILY_R520) { 697 if (mask & LOC_FB) 698 OUTMC(pScrn, R520_MC_FB_LOCATION, fb_loc); 699 if (mask & LOC_AGP) 700 OUTMC(pScrn, R520_MC_AGP_LOCATION, agp_loc); 701 (void)INMC(pScrn, R520_MC_FB_LOCATION); 702 } else { 703 if (mask & LOC_FB) 704 OUTREG(RADEON_MC_FB_LOCATION, fb_loc); 705 if (mask & LOC_AGP) 706 OUTREG(RADEON_MC_AGP_LOCATION, agp_loc); 707 } 708} 709 710static void radeon_read_mc_fb_agp_location(ScrnInfoPtr pScrn, int mask, uint32_t *fb_loc, uint32_t *agp_loc, uint32_t *agp_loc_hi) 711{ 712 RADEONInfoPtr info = RADEONPTR(pScrn); 713 unsigned char *RADEONMMIO = info->MMIO; 714 715 if (info->ChipFamily >= CHIP_FAMILY_R600) { 716 if (mask & LOC_FB) 717 *fb_loc = INREG(R600_MC_VM_FB_LOCATION); 718 if (mask & LOC_AGP) { 719 *agp_loc = INREG(R600_MC_VM_AGP_BOT); 720 *agp_loc_hi = INREG(R600_MC_VM_AGP_TOP); 721 } 722 } else if (info->ChipFamily == CHIP_FAMILY_RV515) { 723 if (mask & LOC_FB) 724 *fb_loc = INMC(pScrn, RV515_MC_FB_LOCATION); 725 if (mask & LOC_AGP) { 726 *agp_loc = INMC(pScrn, RV515_MC_AGP_LOCATION); 727 *agp_loc_hi = 0; 728 } 729 } else if (info->ChipFamily == CHIP_FAMILY_RS600) { 730 if (mask & LOC_FB) 731 *fb_loc = INMC(pScrn, RS600_MC_FB_LOCATION); 732 if (mask & LOC_AGP) { 733 *agp_loc = 0;//INMC(pScrn, RS600_MC_AGP_LOCATION); 734 *agp_loc_hi = 0; 735 } 736 } else if ((info->ChipFamily == CHIP_FAMILY_RS690) || 737 (info->ChipFamily == CHIP_FAMILY_RS740)) { 738 if (mask & LOC_FB) 739 *fb_loc = INMC(pScrn, RS690_MC_FB_LOCATION); 740 if (mask & LOC_AGP) { 741 *agp_loc = INMC(pScrn, RS690_MC_AGP_LOCATION); 742 *agp_loc_hi = 0; 743 } 744 } else if (info->ChipFamily >= CHIP_FAMILY_R520) { 745 if (mask & LOC_FB) 746 *fb_loc = INMC(pScrn, R520_MC_FB_LOCATION); 747 if (mask & LOC_AGP) { 748 *agp_loc = INMC(pScrn, R520_MC_AGP_LOCATION); 749 *agp_loc_hi = 0; 750 } 751 } else { 752 if (mask & LOC_FB) 753 *fb_loc = INREG(RADEON_MC_FB_LOCATION); 754 if (mask & LOC_AGP) 755 *agp_loc = INREG(RADEON_MC_AGP_LOCATION); 756 } 757} 758 759#if 0 760/* Read PAL information (only used for debugging) */ 761static int RADEONINPAL(int idx) 762{ 763 RADEONInfoPtr info = RADEONPTR(pScrn); 764 unsigned char *RADEONMMIO = info->MMIO; 765 766 OUTREG(RADEON_PALETTE_INDEX, idx << 16); 767 return INREG(RADEON_PALETTE_DATA); 768} 769#endif 770 771/* Wait for vertical sync on primary CRTC */ 772void RADEONWaitForVerticalSync(ScrnInfoPtr pScrn) 773{ 774 RADEONInfoPtr info = RADEONPTR(pScrn); 775 unsigned char *RADEONMMIO = info->MMIO; 776 uint32_t crtc_gen_cntl; 777 struct timeval timeout; 778 779 crtc_gen_cntl = INREG(RADEON_CRTC_GEN_CNTL); 780 if ((crtc_gen_cntl & RADEON_CRTC_DISP_REQ_EN_B) || 781 !(crtc_gen_cntl & RADEON_CRTC_EN)) 782 return; 783 784 /* Clear the CRTC_VBLANK_SAVE bit */ 785 OUTREG(RADEON_CRTC_STATUS, RADEON_CRTC_VBLANK_SAVE_CLEAR); 786 787 /* Wait for it to go back up */ 788 radeon_init_timeout(&timeout, RADEON_VSYNC_TIMEOUT); 789 while (!(INREG(RADEON_CRTC_STATUS) & RADEON_CRTC_VBLANK_SAVE) && 790 !radeon_timedout(&timeout)) 791 usleep(100); 792} 793 794/* Wait for vertical sync on secondary CRTC */ 795void RADEONWaitForVerticalSync2(ScrnInfoPtr pScrn) 796{ 797 RADEONInfoPtr info = RADEONPTR(pScrn); 798 unsigned char *RADEONMMIO = info->MMIO; 799 uint32_t crtc2_gen_cntl; 800 struct timeval timeout; 801 802 crtc2_gen_cntl = INREG(RADEON_CRTC2_GEN_CNTL); 803 if ((crtc2_gen_cntl & RADEON_CRTC2_DISP_REQ_EN_B) || 804 !(crtc2_gen_cntl & RADEON_CRTC2_EN)) 805 return; 806 807 /* Clear the CRTC2_VBLANK_SAVE bit */ 808 OUTREG(RADEON_CRTC2_STATUS, RADEON_CRTC2_VBLANK_SAVE_CLEAR); 809 810 /* Wait for it to go back up */ 811 radeon_init_timeout(&timeout, RADEON_VSYNC_TIMEOUT); 812 while (!(INREG(RADEON_CRTC2_STATUS) & RADEON_CRTC2_VBLANK_SAVE) && 813 !radeon_timedout(&timeout)) 814 usleep(100); 815} 816 817 818/* Compute log base 2 of val */ 819int RADEONMinBits(int val) 820{ 821 int bits; 822 823 if (!val) return 1; 824 for (bits = 0; val; val >>= 1, ++bits); 825 return bits; 826} 827 828/* Compute n/d with rounding */ 829static int RADEONDiv(int n, int d) 830{ 831 return (n + (d / 2)) / d; 832} 833 834static Bool RADEONProbePLLParameters(ScrnInfoPtr pScrn) 835{ 836 RADEONInfoPtr info = RADEONPTR(pScrn); 837 RADEONPLLPtr pll = &info->pll; 838 unsigned char *RADEONMMIO = info->MMIO; 839 unsigned char ppll_div_sel; 840 unsigned mpll_fb_div, spll_fb_div, M; 841 unsigned xclk, tmp, ref_div; 842 int hTotal, vTotal, num, denom, m, n; 843 float hz, prev_xtal, vclk, xtal, mpll, spll; 844 long total_usecs; 845 struct timeval start, stop, to1, to2; 846 unsigned int f1, f2, f3; 847 int tries = 0; 848 849 prev_xtal = 0; 850 again: 851 xtal = 0; 852 if (++tries > 10) 853 goto failed; 854 855 gettimeofday(&to1, NULL); 856 f1 = INREG(RADEON_CRTC_CRNT_FRAME); 857 for (;;) { 858 f2 = INREG(RADEON_CRTC_CRNT_FRAME); 859 if (f1 != f2) 860 break; 861 gettimeofday(&to2, NULL); 862 if ((to2.tv_sec - to1.tv_sec) > 1) { 863 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Clock not counting...\n"); 864 goto failed; 865 } 866 } 867 gettimeofday(&start, NULL); 868 for(;;) { 869 f3 = INREG(RADEON_CRTC_CRNT_FRAME); 870 if (f3 != f2) 871 break; 872 gettimeofday(&to2, NULL); 873 if ((to2.tv_sec - start.tv_sec) > 1) 874 goto failed; 875 } 876 gettimeofday(&stop, NULL); 877 878 if ((stop.tv_sec - start.tv_sec) != 0) 879 goto again; 880 total_usecs = abs(stop.tv_usec - start.tv_usec); 881 if (total_usecs == 0) 882 goto again; 883 hz = 1000000.0/(float)total_usecs; 884 885 hTotal = ((INREG(RADEON_CRTC_H_TOTAL_DISP) & 0x3ff) + 1) * 8; 886 vTotal = ((INREG(RADEON_CRTC_V_TOTAL_DISP) & 0xfff) + 1); 887 vclk = (float)(hTotal * (float)(vTotal * hz)); 888 889 switch((INPLL(pScrn, RADEON_PPLL_REF_DIV) & 0x30000) >> 16) { 890 case 0: 891 default: 892 num = 1; 893 denom = 1; 894 break; 895 case 1: 896 n = ((INPLL(pScrn, RADEON_X_MPLL_REF_FB_DIV) >> 16) & 0xff); 897 m = (INPLL(pScrn, RADEON_X_MPLL_REF_FB_DIV) & 0xff); 898 num = 2*n; 899 denom = 2*m; 900 break; 901 case 2: 902 n = ((INPLL(pScrn, RADEON_X_MPLL_REF_FB_DIV) >> 8) & 0xff); 903 m = (INPLL(pScrn, RADEON_X_MPLL_REF_FB_DIV) & 0xff); 904 num = 2*n; 905 denom = 2*m; 906 break; 907 } 908 909 ppll_div_sel = INREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3; 910 RADEONPllErrataAfterIndex(info); 911 912 n = (INPLL(pScrn, RADEON_PPLL_DIV_0 + ppll_div_sel) & 0x7ff); 913 m = (INPLL(pScrn, RADEON_PPLL_REF_DIV) & 0x3ff); 914 915 num *= n; 916 denom *= m; 917 918 switch ((INPLL(pScrn, RADEON_PPLL_DIV_0 + ppll_div_sel) >> 16) & 0x7) { 919 case 1: 920 denom *= 2; 921 break; 922 case 2: 923 denom *= 4; 924 break; 925 case 3: 926 denom *= 8; 927 break; 928 case 4: 929 denom *= 3; 930 break; 931 case 6: 932 denom *= 6; 933 break; 934 case 7: 935 denom *= 12; 936 break; 937 } 938 939 xtal = (int)(vclk *(float)denom/(float)num); 940 941 if ((xtal > 26900000) && (xtal < 27100000)) 942 xtal = 2700; 943 else if ((xtal > 14200000) && (xtal < 14400000)) 944 xtal = 1432; 945 else if ((xtal > 29400000) && (xtal < 29600000)) 946 xtal = 2950; 947 else 948 goto again; 949 failed: 950 if (xtal == 0) { 951 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Failed to probe xtal value ! " 952 "Using default 27Mhz\n"); 953 xtal = 2700; 954 } else { 955 if (prev_xtal == 0) { 956 prev_xtal = xtal; 957 tries = 0; 958 goto again; 959 } else if (prev_xtal != xtal) { 960 prev_xtal = 0; 961 goto again; 962 } 963 } 964 965 tmp = INPLL(pScrn, RADEON_X_MPLL_REF_FB_DIV); 966 ref_div = INPLL(pScrn, RADEON_PPLL_REF_DIV) & 0x3ff; 967 968 /* Some sanity check based on the BIOS code .... */ 969 if (ref_div < 2) { 970 uint32_t tmp; 971 tmp = INPLL(pScrn, RADEON_PPLL_REF_DIV); 972 if (IS_R300_VARIANT 973 || (info->ChipFamily == CHIP_FAMILY_RS300) 974 || (info->ChipFamily == CHIP_FAMILY_RS400) 975 || (info->ChipFamily == CHIP_FAMILY_RS480)) 976 ref_div = (tmp & R300_PPLL_REF_DIV_ACC_MASK) >> 977 R300_PPLL_REF_DIV_ACC_SHIFT; 978 else 979 ref_div = tmp & RADEON_PPLL_REF_DIV_MASK; 980 if (ref_div < 2) 981 ref_div = 12; 982 } 983 984 /* Calculate "base" xclk straight from MPLL, though that isn't 985 * really useful (hopefully). This isn't called XCLK anymore on 986 * radeon's... 987 */ 988 mpll_fb_div = (tmp & 0xff00) >> 8; 989 spll_fb_div = (tmp & 0xff0000) >> 16; 990 M = (tmp & 0xff); 991 xclk = RADEONDiv((2 * mpll_fb_div * xtal), (M)); 992 993 /* 994 * Calculate MCLK based on MCLK-A 995 */ 996 mpll = (2.0 * (float)mpll_fb_div * (xtal / 100.0)) / (float)M; 997 spll = (2.0 * (float)spll_fb_div * (xtal / 100.0)) / (float)M; 998 999 tmp = INPLL(pScrn, RADEON_MCLK_CNTL) & 0x7; 1000 switch(tmp) { 1001 case 1: info->mclk = mpll; break; 1002 case 2: info->mclk = mpll / 2.0; break; 1003 case 3: info->mclk = mpll / 4.0; break; 1004 case 4: info->mclk = mpll / 8.0; break; 1005 case 7: info->mclk = spll; break; 1006 default: 1007 info->mclk = 200.00; 1008 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Unsupported MCLKA source" 1009 " setting %d, can't probe MCLK value !\n", tmp); 1010 } 1011 1012 /* 1013 * Calculate SCLK 1014 */ 1015 tmp = INPLL(pScrn, RADEON_SCLK_CNTL) & 0x7; 1016 switch(tmp) { 1017 case 1: info->sclk = spll; break; 1018 case 2: info->sclk = spll / 2.0; break; 1019 case 3: info->sclk = spll / 4.0; break; 1020 case 4: info->sclk = spll / 8.0; break; 1021 case 7: info->sclk = mpll; break; 1022 default: 1023 info->sclk = 200.00; 1024 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Unsupported SCLK source" 1025 " setting %d, can't probe SCLK value !\n", tmp); 1026 } 1027 1028 /* we're done, hopefully these are sane values */ 1029 pll->reference_div = ref_div; 1030 pll->xclk = xclk; 1031 pll->reference_freq = xtal; 1032 1033 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Probed PLL values: xtal: %f Mhz, " 1034 "sclk: %f Mhz, mclk: %f Mhz\n", xtal/100.0, info->sclk, info->mclk); 1035 1036 return TRUE; 1037} 1038 1039static void RADEONGetClockInfo(ScrnInfoPtr pScrn) 1040{ 1041 RADEONInfoPtr info = RADEONPTR (pScrn); 1042 RADEONPLLPtr pll = &info->pll; 1043 double min_dotclock; 1044 1045 if (RADEONGetClockInfoFromBIOS(pScrn)) { 1046 if (pll->reference_div < 2) { 1047 /* retrive it from register setting for fitting into current PLL algorithm. 1048 We'll probably need a new routine to calculate the best ref_div from BIOS 1049 provided min_input_pll and max_input_pll 1050 */ 1051 uint32_t tmp; 1052 tmp = INPLL(pScrn, RADEON_PPLL_REF_DIV); 1053 if (IS_R300_VARIANT || 1054 (info->ChipFamily == CHIP_FAMILY_RS300) || 1055 (info->ChipFamily == CHIP_FAMILY_RS400) || 1056 (info->ChipFamily == CHIP_FAMILY_RS480)) { 1057 pll->reference_div = (tmp & R300_PPLL_REF_DIV_ACC_MASK) >> R300_PPLL_REF_DIV_ACC_SHIFT; 1058 } else { 1059 pll->reference_div = tmp & RADEON_PPLL_REF_DIV_MASK; 1060 } 1061 1062 if (pll->reference_div < 2) pll->reference_div = 12; 1063 } 1064 } else { 1065 xf86DrvMsg (pScrn->scrnIndex, X_WARNING, 1066 "Video BIOS not detected, using default clock settings!\n"); 1067 1068 /* Default min/max PLL values */ 1069 if (info->ChipFamily == CHIP_FAMILY_R420 || info->ChipFamily == CHIP_FAMILY_RV410) { 1070 pll->pll_in_min = 100; 1071 pll->pll_in_max = 1350; 1072 pll->pll_out_min = 20000; 1073 pll->pll_out_max = 50000; 1074 } else { 1075 pll->pll_in_min = 40; 1076 pll->pll_in_max = 500; 1077 pll->pll_out_min = 12500; 1078 pll->pll_out_max = 35000; 1079 } 1080 1081 if (!RADEONProbePLLParameters(pScrn)) { 1082 if (info->IsIGP) 1083 pll->reference_freq = 1432; 1084 else 1085 pll->reference_freq = 2700; 1086 1087 pll->reference_div = 12; 1088 pll->xclk = 10300; 1089 1090 info->sclk = 200.00; 1091 info->mclk = 200.00; 1092 } 1093 } 1094 1095 /* card limits for computing PLLs */ 1096 if (IS_AVIVO_VARIANT) { 1097 pll->min_post_div = 2; 1098 pll->max_post_div = 0x7f; 1099 } else { 1100 pll->min_post_div = 1; 1101 pll->max_post_div = 12; //16 on crtc0 1102 } 1103 pll->min_ref_div = 2; 1104 pll->max_ref_div = 0x3ff; 1105 pll->min_feedback_div = 4; 1106 pll->max_feedback_div = 0x7ff; 1107 pll->best_vco = 0; 1108 1109 xf86DrvMsg (pScrn->scrnIndex, X_INFO, 1110 "PLL parameters: rf=%u rd=%u min=%u max=%u; xclk=%u\n", 1111 pll->reference_freq, 1112 pll->reference_div, 1113 (unsigned)pll->pll_out_min, (unsigned)pll->pll_out_max, 1114 pll->xclk); 1115 1116 /* (Some?) Radeon BIOSes seem too lie about their minimum dot 1117 * clocks. Allow users to override the detected minimum dot clock 1118 * value (e.g., and allow it to be suitable for TV sets). 1119 */ 1120 if (xf86GetOptValFreq(info->Options, OPTION_MIN_DOTCLOCK, 1121 OPTUNITS_MHZ, &min_dotclock)) { 1122 if (min_dotclock < 12 || min_dotclock*100 >= pll->pll_out_max) { 1123 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1124 "Illegal minimum dotclock specified %.2f MHz " 1125 "(option ignored)\n", 1126 min_dotclock); 1127 } else { 1128 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1129 "Forced minimum dotclock to %.2f MHz " 1130 "(instead of detected %.2f MHz)\n", 1131 min_dotclock, ((double)pll->pll_out_min/1000)); 1132 pll->pll_out_min = min_dotclock * 1000; 1133 } 1134 } 1135} 1136 1137 1138 1139/* This is called by RADEONPreInit to set up the default visual */ 1140static Bool RADEONPreInitVisual(ScrnInfoPtr pScrn) 1141{ 1142 RADEONInfoPtr info = RADEONPTR(pScrn); 1143 1144 if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) 1145 return FALSE; 1146 1147 switch (pScrn->depth) { 1148 case 8: 1149 case 15: 1150 case 16: 1151 case 24: 1152 break; 1153 1154 default: 1155 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 1156 "Given depth (%d) is not supported by %s driver\n", 1157 pScrn->depth, RADEON_DRIVER_NAME); 1158 return FALSE; 1159 } 1160 1161 xf86PrintDepthBpp(pScrn); 1162 1163 info->fifo_slots = 0; 1164 info->pix24bpp = xf86GetBppFromDepth(pScrn, 1165 pScrn->depth); 1166 info->CurrentLayout.bitsPerPixel = pScrn->bitsPerPixel; 1167 info->CurrentLayout.depth = pScrn->depth; 1168 info->CurrentLayout.pixel_bytes = pScrn->bitsPerPixel / 8; 1169 info->CurrentLayout.pixel_code = (pScrn->bitsPerPixel != 16 1170 ? pScrn->bitsPerPixel 1171 : pScrn->depth); 1172 1173 if (info->pix24bpp == 24) { 1174 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 1175 "Radeon does NOT support 24bpp\n"); 1176 return FALSE; 1177 } 1178 1179 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1180 "Pixel depth = %d bits stored in %d byte%s (%d bpp pixmaps)\n", 1181 pScrn->depth, 1182 info->CurrentLayout.pixel_bytes, 1183 info->CurrentLayout.pixel_bytes > 1 ? "s" : "", 1184 info->pix24bpp); 1185 1186 if (!xf86SetDefaultVisual(pScrn, -1)) return FALSE; 1187 1188 if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) { 1189 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 1190 "Default visual (%s) is not supported at depth %d\n", 1191 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth); 1192 return FALSE; 1193 } 1194 return TRUE; 1195} 1196 1197/* This is called by RADEONPreInit to handle all color weight issues */ 1198static Bool RADEONPreInitWeight(ScrnInfoPtr pScrn) 1199{ 1200 RADEONInfoPtr info = RADEONPTR(pScrn); 1201 1202 /* Save flag for 6 bit DAC to use for 1203 setting CRTC registers. Otherwise use 1204 an 8 bit DAC, even if xf86SetWeight sets 1205 pScrn->rgbBits to some value other than 1206 8. */ 1207 info->dac6bits = FALSE; 1208 1209 if (pScrn->depth > 8) { 1210 rgb defaultWeight = { 0, 0, 0 }; 1211 1212 if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) return FALSE; 1213 } else { 1214 pScrn->rgbBits = 8; 1215 if (xf86ReturnOptValBool(info->Options, OPTION_DAC_6BIT, FALSE)) { 1216 pScrn->rgbBits = 6; 1217 info->dac6bits = TRUE; 1218 } 1219 } 1220 1221 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1222 "Using %d bits per RGB (%d bit DAC)\n", 1223 pScrn->rgbBits, info->dac6bits ? 6 : 8); 1224 1225 return TRUE; 1226} 1227 1228void RADEONInitMemMapRegisters(ScrnInfoPtr pScrn, RADEONSavePtr save, 1229 RADEONInfoPtr info) 1230{ 1231 save->mc_fb_location = info->mc_fb_location; 1232 save->mc_agp_location = info->mc_agp_location; 1233 1234 if (IS_AVIVO_VARIANT) { 1235 save->mc_agp_location_hi = info->mc_agp_location_hi; 1236 } else { 1237 save->display_base_addr = info->fbLocation; 1238 save->display2_base_addr = info->fbLocation; 1239 save->ov0_base_addr = info->fbLocation; 1240 } 1241} 1242 1243static void RADEONInitMemoryMap(ScrnInfoPtr pScrn) 1244{ 1245 RADEONInfoPtr info = RADEONPTR(pScrn); 1246 unsigned char *RADEONMMIO = info->MMIO; 1247 uint32_t mem_size; 1248 uint32_t aper_size; 1249 1250 radeon_read_mc_fb_agp_location(pScrn, LOC_FB | LOC_AGP, &info->mc_fb_location, 1251 &info->mc_agp_location, &info->mc_agp_location_hi); 1252 1253 /* We shouldn't use info->videoRam here which might have been clipped 1254 * but the real video RAM instead 1255 */ 1256 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1257 mem_size = INREG(R600_CONFIG_MEMSIZE); 1258 aper_size = INREG(R600_CONFIG_APER_SIZE); 1259 } else { 1260 mem_size = INREG(RADEON_CONFIG_MEMSIZE); 1261 aper_size = INREG(RADEON_CONFIG_APER_SIZE); 1262 } 1263 1264 if (mem_size == 0) 1265 mem_size = 0x800000; 1266 1267 /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM - 1268 Novell bug 204882 + along with lots of ubuntu ones */ 1269 if (aper_size > mem_size) 1270 mem_size = aper_size; 1271 1272#ifdef XF86DRI 1273 /* Apply memory map limitation if using an old DRI */ 1274 if (info->directRenderingEnabled && !info->newMemoryMap) { 1275 if (aper_size < mem_size) 1276 mem_size = aper_size; 1277 } 1278#endif 1279 1280 if ((info->ChipFamily != CHIP_FAMILY_RS600) && 1281 (info->ChipFamily != CHIP_FAMILY_RS690) && 1282 (info->ChipFamily != CHIP_FAMILY_RS740)) { 1283 if (info->IsIGP) 1284 info->mc_fb_location = INREG(RADEON_NB_TOM); 1285 else 1286#ifdef XF86DRI 1287 /* Old DRI has restrictions on the memory map */ 1288 if ( info->directRenderingEnabled && 1289 info->pKernelDRMVersion->version_minor < 10 ) 1290 info->mc_fb_location = (mem_size - 1) & 0xffff0000U; 1291 else 1292#endif 1293 { 1294 uint32_t aper0_base; 1295 1296 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1297 aper0_base = INREG(R600_CONFIG_F0_BASE); 1298 } else { 1299 aper0_base = INREG(RADEON_CONFIG_APER_0_BASE); 1300 } 1301 1302 /* Recent chips have an "issue" with the memory controller, the 1303 * location must be aligned to the size. We just align it down, 1304 * too bad if we walk over the top of system memory, we don't 1305 * use DMA without a remapped anyway. 1306 * Affected chips are rv280, all r3xx, and all r4xx, but not IGP 1307 */ 1308 if (info->ChipFamily == CHIP_FAMILY_RV280 || 1309 info->ChipFamily == CHIP_FAMILY_R300 || 1310 info->ChipFamily == CHIP_FAMILY_R350 || 1311 info->ChipFamily == CHIP_FAMILY_RV350 || 1312 info->ChipFamily == CHIP_FAMILY_RV380 || 1313 info->ChipFamily == CHIP_FAMILY_R420 || 1314 info->ChipFamily == CHIP_FAMILY_RV410) 1315 aper0_base &= ~(mem_size - 1); 1316 1317 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1318 info->mc_fb_location = (aper0_base >> 24) | 1319 (((aper0_base + mem_size - 1) & 0xff000000U) >> 8); 1320 ErrorF("mc fb loc is %08x\n", (unsigned int)info->mc_fb_location); 1321 } else { 1322 info->mc_fb_location = (aper0_base >> 16) | 1323 ((aper0_base + mem_size - 1) & 0xffff0000U); 1324 } 1325 } 1326 } 1327 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1328 info->fbLocation = (info->mc_fb_location & 0xffff) << 24; 1329 } else { 1330 info->fbLocation = (info->mc_fb_location & 0xffff) << 16; 1331 } 1332 /* Just disable the damn AGP apertures for now, it may be 1333 * re-enabled later by the DRM 1334 */ 1335 1336 if (IS_AVIVO_VARIANT) { 1337 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1338 OUTREG(R600_HDP_NONSURFACE_BASE, (info->mc_fb_location << 16) & 0xff0000); 1339 } else { 1340 OUTREG(AVIVO_HDP_FB_LOCATION, info->mc_fb_location); 1341 } 1342 info->mc_agp_location = 0x003f0000; 1343 } else 1344 info->mc_agp_location = 0xffffffc0; 1345 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1346 "RADEONInitMemoryMap() : \n"); 1347 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1348 " mem_size : 0x%08x\n", (unsigned)mem_size); 1349 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1350 " MC_FB_LOCATION : 0x%08x\n", (unsigned)info->mc_fb_location); 1351 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1352 " MC_AGP_LOCATION : 0x%08x\n", 1353 (unsigned)info->mc_agp_location); 1354} 1355 1356static void RADEONGetVRamType(ScrnInfoPtr pScrn) 1357{ 1358 RADEONInfoPtr info = RADEONPTR(pScrn); 1359 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 1360 unsigned char *RADEONMMIO = info->MMIO; 1361 uint32_t tmp; 1362 1363 if (info->IsIGP || (info->ChipFamily >= CHIP_FAMILY_R300)) 1364 info->IsDDR = TRUE; 1365 else if (INREG(RADEON_MEM_SDRAM_MODE_REG) & RADEON_MEM_CFG_TYPE_DDR) 1366 info->IsDDR = TRUE; 1367 else 1368 info->IsDDR = FALSE; 1369 1370 if ((info->ChipFamily >= CHIP_FAMILY_R600) && 1371 (info->ChipFamily <= CHIP_FAMILY_RV635)) { 1372 int chansize; 1373 /* r6xx */ 1374 tmp = INREG(R600_RAMCFG); 1375 if (tmp & R600_CHANSIZE_OVERRIDE) 1376 chansize = 16; 1377 else if (tmp & R600_CHANSIZE) 1378 chansize = 64; 1379 else 1380 chansize = 32; 1381 if (info->ChipFamily == CHIP_FAMILY_R600) 1382 info->RamWidth = 8 * chansize; 1383 else if (info->ChipFamily == CHIP_FAMILY_RV670) 1384 info->RamWidth = 4 * chansize; 1385 else if ((info->ChipFamily == CHIP_FAMILY_RV610) || 1386 (info->ChipFamily == CHIP_FAMILY_RV620)) 1387 info->RamWidth = chansize; 1388 else if ((info->ChipFamily == CHIP_FAMILY_RV630) || 1389 (info->ChipFamily == CHIP_FAMILY_RV635)) 1390 info->RamWidth = 2 * chansize; 1391 } else if (info->ChipFamily == CHIP_FAMILY_RV515) { 1392 /* rv515/rv550 */ 1393 tmp = INMC(pScrn, RV515_MC_CNTL); 1394 tmp &= RV515_MEM_NUM_CHANNELS_MASK; 1395 switch (tmp) { 1396 case 0: info->RamWidth = 64; break; 1397 case 1: info->RamWidth = 128; break; 1398 default: info->RamWidth = 128; break; 1399 } 1400 } else if ((info->ChipFamily >= CHIP_FAMILY_R520) && 1401 (info->ChipFamily <= CHIP_FAMILY_RV570)){ 1402 /* r520/rv530/rv560/rv570/r580 */ 1403 tmp = INMC(pScrn, R520_MC_CNTL0); 1404 switch ((tmp & R520_MEM_NUM_CHANNELS_MASK) >> R520_MEM_NUM_CHANNELS_SHIFT) { 1405 case 0: info->RamWidth = 32; break; 1406 case 1: info->RamWidth = 64; break; 1407 case 2: info->RamWidth = 128; break; 1408 case 3: info->RamWidth = 256; break; 1409 default: info->RamWidth = 64; break; 1410 } 1411 if (tmp & R520_MC_CHANNEL_SIZE) { 1412 info->RamWidth *= 2; 1413 } 1414 } else if ((info->ChipFamily >= CHIP_FAMILY_R300) && 1415 (info->ChipFamily <= CHIP_FAMILY_RV410)) { 1416 /* r3xx, r4xx */ 1417 tmp = INREG(RADEON_MEM_CNTL); 1418 tmp &= R300_MEM_NUM_CHANNELS_MASK; 1419 switch (tmp) { 1420 case 0: info->RamWidth = 64; break; 1421 case 1: info->RamWidth = 128; break; 1422 case 2: info->RamWidth = 256; break; 1423 default: info->RamWidth = 128; break; 1424 } 1425 } else if ((info->ChipFamily == CHIP_FAMILY_RV100) || 1426 (info->ChipFamily == CHIP_FAMILY_RS100) || 1427 (info->ChipFamily == CHIP_FAMILY_RS200)){ 1428 tmp = INREG(RADEON_MEM_CNTL); 1429 if (tmp & RV100_HALF_MODE) 1430 info->RamWidth = 32; 1431 else 1432 info->RamWidth = 64; 1433 1434 if (!pRADEONEnt->HasCRTC2) { 1435 info->RamWidth /= 4; 1436 info->IsDDR = TRUE; 1437 } 1438 } else if (info->ChipFamily <= CHIP_FAMILY_RV280) { 1439 tmp = INREG(RADEON_MEM_CNTL); 1440 if (tmp & RADEON_MEM_NUM_CHANNELS_MASK) 1441 info->RamWidth = 128; 1442 else 1443 info->RamWidth = 64; 1444 } else { 1445 /* newer IGPs */ 1446 info->RamWidth = 128; 1447 } 1448 1449 /* This may not be correct, as some cards can have half of channel disabled 1450 * ToDo: identify these cases 1451 */ 1452} 1453 1454/* 1455 * Depending on card genertation, chipset bugs, etc... the amount of vram 1456 * accessible to the CPU can vary. This function is our best shot at figuring 1457 * it out. Returns a value in KB. 1458 */ 1459static uint32_t RADEONGetAccessibleVRAM(ScrnInfoPtr pScrn) 1460{ 1461 RADEONInfoPtr info = RADEONPTR(pScrn); 1462 unsigned char *RADEONMMIO = info->MMIO; 1463 uint32_t aper_size; 1464 unsigned char byte; 1465 1466 if (info->ChipFamily >= CHIP_FAMILY_R600) 1467 aper_size = INREG(R600_CONFIG_APER_SIZE) / 1024; 1468 else 1469 aper_size = INREG(RADEON_CONFIG_APER_SIZE) / 1024; 1470 1471#ifdef XF86DRI 1472 /* If we use the DRI, we need to check if it's a version that has the 1473 * bug of always cropping MC_FB_LOCATION to one aperture, in which case 1474 * we need to limit the amount of accessible video memory 1475 */ 1476 if (info->directRenderingEnabled && 1477 info->pKernelDRMVersion->version_minor < 23) { 1478 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 1479 "[dri] limiting video memory to one aperture of %uK\n", 1480 (unsigned)aper_size); 1481 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 1482 "[dri] detected radeon kernel module version 1.%d but" 1483 " 1.23 or newer is required for full memory mapping.\n", 1484 info->pKernelDRMVersion->version_minor); 1485 info->newMemoryMap = FALSE; 1486 return aper_size; 1487 } 1488 info->newMemoryMap = TRUE; 1489#endif /* XF86DRI */ 1490 1491 /* Set HDP_APER_CNTL only on cards that are known not to be broken, 1492 * that is has the 2nd generation multifunction PCI interface 1493 */ 1494 if (info->ChipFamily == CHIP_FAMILY_RV280 || 1495 info->ChipFamily == CHIP_FAMILY_RV350 || 1496 info->ChipFamily == CHIP_FAMILY_RV380 || 1497 info->ChipFamily == CHIP_FAMILY_R420 || 1498 info->ChipFamily == CHIP_FAMILY_RV410 || 1499 IS_AVIVO_VARIANT) { 1500 OUTREGP (RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL, 1501 ~RADEON_HDP_APER_CNTL); 1502 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1503 "Generation 2 PCI interface, using max accessible memory\n"); 1504 return aper_size * 2; 1505 } 1506 1507 /* Older cards have all sorts of funny issues to deal with. First 1508 * check if it's a multifunction card by reading the PCI config 1509 * header type... Limit those to one aperture size 1510 */ 1511 PCI_READ_BYTE(info->PciInfo, &byte, 0xe); 1512 if (byte & 0x80) { 1513 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1514 "Generation 1 PCI interface in multifunction mode" 1515 ", accessible memory limited to one aperture\n"); 1516 return aper_size; 1517 } 1518 1519 /* Single function older card. We read HDP_APER_CNTL to see how the BIOS 1520 * have set it up. We don't write this as it's broken on some ASICs but 1521 * we expect the BIOS to have done the right thing (might be too optimistic...) 1522 */ 1523 if (INREG(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL) 1524 return aper_size * 2; 1525 1526 return aper_size; 1527} 1528 1529static Bool RADEONPreInitVRAM(ScrnInfoPtr pScrn) 1530{ 1531 RADEONInfoPtr info = RADEONPTR(pScrn); 1532 EntityInfoPtr pEnt = info->pEnt; 1533 GDevPtr dev = pEnt->device; 1534 unsigned char *RADEONMMIO = info->MMIO; 1535 MessageType from = X_PROBED; 1536 uint32_t accessible, bar_size; 1537 1538 if ((!IS_AVIVO_VARIANT) && info->IsIGP) { 1539 uint32_t tom = INREG(RADEON_NB_TOM); 1540 1541 pScrn->videoRam = (((tom >> 16) - 1542 (tom & 0xffff) + 1) << 6); 1543 1544 OUTREG(RADEON_CONFIG_MEMSIZE, pScrn->videoRam * 1024); 1545 } else { 1546 if (info->ChipFamily >= CHIP_FAMILY_R600) 1547 pScrn->videoRam = INREG(R600_CONFIG_MEMSIZE) / 1024; 1548 else { 1549 /* Read VRAM size from card */ 1550 pScrn->videoRam = INREG(RADEON_CONFIG_MEMSIZE) / 1024; 1551 1552 /* Some production boards of m6 will return 0 if it's 8 MB */ 1553 if (pScrn->videoRam == 0) { 1554 pScrn->videoRam = 8192; 1555 OUTREG(RADEON_CONFIG_MEMSIZE, 0x800000); 1556 } 1557 } 1558 } 1559 1560 /* Get accessible memory */ 1561 accessible = RADEONGetAccessibleVRAM(pScrn); 1562 1563 /* Crop it to the size of the PCI BAR */ 1564 bar_size = PCI_REGION_SIZE(info->PciInfo, 0) / 1024; 1565 if (bar_size == 0) 1566 bar_size = 0x20000; 1567 if (accessible > bar_size) 1568 accessible = bar_size; 1569 1570 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1571 "Detected total video RAM=%dK, accessible=%uK (PCI BAR=%uK)\n", 1572 pScrn->videoRam, (unsigned)accessible, (unsigned)bar_size); 1573 if (pScrn->videoRam > accessible) 1574 pScrn->videoRam = accessible; 1575 1576 if (!IS_AVIVO_VARIANT) 1577 info->MemCntl = INREG(RADEON_SDRAM_MODE_REG); 1578 info->BusCntl = INREG(RADEON_BUS_CNTL); 1579 1580 RADEONGetVRamType(pScrn); 1581 1582 if (dev->videoRam) { 1583 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1584 "Video RAM override, using %d kB instead of %d kB\n", 1585 dev->videoRam, 1586 pScrn->videoRam); 1587 from = X_CONFIG; 1588 pScrn->videoRam = dev->videoRam; 1589 } 1590 1591 xf86DrvMsg(pScrn->scrnIndex, from, 1592 "Mapped VideoRAM: %d kByte (%d bit %s SDRAM)\n", pScrn->videoRam, info->RamWidth, info->IsDDR?"DDR":"SDR"); 1593 1594 if (info->IsPrimary) { 1595 pScrn->videoRam /= 2; 1596 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1597 "Using %dk of videoram for primary head\n", 1598 pScrn->videoRam); 1599 } 1600 1601 if (info->IsSecondary) { 1602 pScrn->videoRam /= 2; 1603 info->LinearAddr += pScrn->videoRam * 1024; 1604 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1605 "Using %dk of videoram for secondary head\n", 1606 pScrn->videoRam); 1607 } 1608 1609 pScrn->videoRam &= ~1023; 1610 info->FbMapSize = pScrn->videoRam * 1024; 1611 1612 /* if the card is PCI Express reserve the last 32k for the gart table */ 1613#ifdef XF86DRI 1614 if (info->cardType == CARD_PCIE && info->directRenderingEnabled) 1615 /* work out the size of pcie aperture */ 1616 info->FbSecureSize = RADEONDRIGetPciAperTableSize(pScrn); 1617 else 1618#endif 1619 info->FbSecureSize = 0; 1620 1621 return TRUE; 1622} 1623 1624 1625/* This is called by RADEONPreInit to handle config file overrides for 1626 * things like chipset and memory regions. Also determine memory size 1627 * and type. If memory type ever needs an override, put it in this 1628 * routine. 1629 */ 1630static Bool RADEONPreInitChipType(ScrnInfoPtr pScrn) 1631{ 1632 RADEONInfoPtr info = RADEONPTR(pScrn); 1633 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 1634 EntityInfoPtr pEnt = info->pEnt; 1635 GDevPtr dev = pEnt->device; 1636 unsigned char *RADEONMMIO = info->MMIO; 1637 MessageType from = X_PROBED; 1638 int i; 1639#ifdef XF86DRI 1640 const char *s; 1641 uint32_t cmd_stat; 1642#endif 1643 1644 /* Chipset */ 1645 from = X_PROBED; 1646 if (dev->chipset && *dev->chipset) { 1647 info->Chipset = xf86StringToToken(RADEONChipsets, dev->chipset); 1648 from = X_CONFIG; 1649 } else if (dev->chipID >= 0) { 1650 info->Chipset = dev->chipID; 1651 from = X_CONFIG; 1652 } else { 1653 info->Chipset = PCI_DEV_DEVICE_ID(info->PciInfo); 1654 } 1655 1656 pScrn->chipset = (char *)xf86TokenToString(RADEONChipsets, info->Chipset); 1657 if (!pScrn->chipset) { 1658 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 1659 "ChipID 0x%04x is not recognized\n", info->Chipset); 1660 return FALSE; 1661 } 1662 if (info->Chipset < 0) { 1663 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 1664 "Chipset \"%s\" is not recognized\n", pScrn->chipset); 1665 return FALSE; 1666 } 1667 xf86DrvMsg(pScrn->scrnIndex, from, 1668 "Chipset: \"%s\" (ChipID = 0x%04x)\n", 1669 pScrn->chipset, 1670 info->Chipset); 1671 1672 pRADEONEnt->HasCRTC2 = TRUE; 1673 info->IsMobility = FALSE; 1674 info->IsIGP = FALSE; 1675 info->IsDellServer = FALSE; 1676 info->HasSingleDAC = FALSE; 1677 info->InternalTVOut = TRUE; 1678 1679 for (i = 0; i < sizeof(RADEONCards) / sizeof(RADEONCardInfo); i++) { 1680 if (info->Chipset == RADEONCards[i].pci_device_id) { 1681 RADEONCardInfo *card = &RADEONCards[i]; 1682 info->ChipFamily = card->chip_family; 1683 info->IsMobility = card->mobility; 1684 info->IsIGP = card->igp; 1685 pRADEONEnt->HasCRTC2 = !card->nocrtc2; 1686 info->HasSingleDAC = card->singledac; 1687 info->InternalTVOut = !card->nointtvout; 1688 break; 1689 } 1690 } 1691 1692 switch (info->Chipset) { 1693 case PCI_CHIP_RN50_515E: /* RN50 is based on the RV100 but 3D isn't guaranteed to work. YMMV. */ 1694 case PCI_CHIP_RN50_5969: 1695 case PCI_CHIP_RV100_QY: 1696 case PCI_CHIP_RV100_QZ: 1697 /* DELL triple-head configuration. */ 1698 if ((PCI_SUB_VENDOR_ID(info->PciInfo) == PCI_VENDOR_DELL) && 1699 ((PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016c) || 1700 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016d) || 1701 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016e) || 1702 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x016f) || 1703 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x0170) || 1704 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x017d) || 1705 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x017e) || 1706 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x0183) || 1707 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x018a) || 1708 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x019a))) { 1709 info->IsDellServer = TRUE; 1710 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "DELL server detected, force to special setup\n"); 1711 } 1712 break; 1713 case PCI_CHIP_RS482_5974: 1714 /* RH BZ 444586 - non mobility version 1715 * Dell appear to have the Vostro 1100 with a mobility part with the same pci-id */ 1716 if ((PCI_SUB_VENDOR_ID(info->PciInfo) == 0x1462) && 1717 (PCI_SUB_DEVICE_ID(info->PciInfo) == 0x7141)) { 1718 info->IsMobility = FALSE; 1719 } 1720 default: 1721 break; 1722 } 1723 1724 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1725 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 1726 "R600 support is mostly incomplete and very experimental\n"); 1727 } 1728 1729 if ((info->ChipFamily >= CHIP_FAMILY_RV515) && (info->ChipFamily < CHIP_FAMILY_R600)) { 1730 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 1731 "R500 support is under development. Please report any issues to xorg-driver-ati@lists.x.org\n"); 1732 } 1733 1734 from = X_PROBED; 1735 info->LinearAddr = PCI_REGION_BASE(info->PciInfo, 0, REGION_MEM) & ~0x1ffffffUL; 1736 pScrn->memPhysBase = info->LinearAddr; 1737 if (dev->MemBase) { 1738 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1739 "Linear address override, using 0x%016lx instead of 0x%016lx\n", 1740 dev->MemBase, 1741 info->LinearAddr); 1742 info->LinearAddr = dev->MemBase; 1743 from = X_CONFIG; 1744 } else if (!info->LinearAddr) { 1745 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 1746 "No valid linear framebuffer address\n"); 1747 return FALSE; 1748 } 1749 xf86DrvMsg(pScrn->scrnIndex, from, 1750 "Linear framebuffer at 0x%016lx\n", info->LinearAddr); 1751 1752#ifndef XSERVER_LIBPCIACCESS 1753 /* BIOS */ 1754 from = X_PROBED; 1755 info->BIOSAddr = info->PciInfo->biosBase & 0xfffe0000; 1756 if (dev->BiosBase) { 1757 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1758 "BIOS address override, using 0x%08lx instead of 0x%08lx\n", 1759 dev->BiosBase, 1760 info->BIOSAddr); 1761 info->BIOSAddr = dev->BiosBase; 1762 from = X_CONFIG; 1763 } 1764 if (info->BIOSAddr) { 1765 xf86DrvMsg(pScrn->scrnIndex, from, 1766 "BIOS at 0x%08lx\n", info->BIOSAddr); 1767 } 1768#endif 1769 1770 /* Read registers used to determine options */ 1771 /* Check chip errata */ 1772 info->ChipErrata = 0; 1773 1774 if (info->ChipFamily == CHIP_FAMILY_R300 && 1775 (INREG(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) 1776 == RADEON_CFG_ATI_REV_A11) 1777 info->ChipErrata |= CHIP_ERRATA_R300_CG; 1778 1779 if (info->ChipFamily == CHIP_FAMILY_RV200 || 1780 info->ChipFamily == CHIP_FAMILY_RS200) 1781 info->ChipErrata |= CHIP_ERRATA_PLL_DUMMYREADS; 1782 1783 if (info->ChipFamily == CHIP_FAMILY_RV100 || 1784 info->ChipFamily == CHIP_FAMILY_RS100 || 1785 info->ChipFamily == CHIP_FAMILY_RS200) 1786 info->ChipErrata |= CHIP_ERRATA_PLL_DELAY; 1787 1788#ifdef XF86DRI 1789 /* AGP/PCI */ 1790 /* Proper autodetection of an AGP capable device requires examining 1791 * PCI config registers to determine if the device implements extended 1792 * PCI capabilities, and then walking the capability list as indicated 1793 * in the PCI 2.2 and AGP 2.0 specifications, to determine if AGP 1794 * capability is present. The procedure is outlined as follows: 1795 * 1796 * 1) Test bit 4 (CAP_LIST) of the PCI status register of the device 1797 * to determine wether or not this device implements any extended 1798 * capabilities. If this bit is zero, then the device is a PCI 2.1 1799 * or earlier device and is not AGP capable, and we can conclude it 1800 * to be a PCI device. 1801 * 1802 * 2) If bit 4 of the status register is set, then the device implements 1803 * extended capabilities. There is an 8 bit wide capabilities pointer 1804 * register located at offset 0x34 in PCI config space which points to 1805 * the first capability in a linked list of extended capabilities that 1806 * this device implements. The lower two bits of this register are 1807 * reserved and MBZ so must be masked out. 1808 * 1809 * 3) The extended capabilities list is formed by one or more extended 1810 * capabilities structures which are aligned on DWORD boundaries. 1811 * The first byte of the structure is the capability ID (CAP_ID) 1812 * indicating what extended capability this structure refers to. The 1813 * second byte of the structure is an offset from the beginning of 1814 * PCI config space pointing to the next capability in the linked 1815 * list (NEXT_PTR) or NULL (0x00) at the end of the list. The lower 1816 * two bits of this pointer are reserved and MBZ. By examining the 1817 * CAP_ID of each capability and walking through the list, we will 1818 * either find the AGP_CAP_ID (0x02) indicating this device is an 1819 * AGP device, or we'll reach the end of the list, indicating it is 1820 * a PCI device. 1821 * 1822 * Mike A. Harris <mharris@redhat.com> 1823 * 1824 * References: 1825 * - PCI Local Bus Specification Revision 2.2, Chapter 6 1826 * - AGP Interface Specification Revision 2.0, Section 6.1.5 1827 */ 1828 1829 info->cardType = CARD_PCI; 1830 1831 PCI_READ_LONG(info->PciInfo, &cmd_stat, PCI_CMD_STAT_REG); 1832 if (cmd_stat & RADEON_CAP_LIST) { 1833 uint32_t cap_ptr, cap_id; 1834 1835 PCI_READ_LONG(info->PciInfo, &cap_ptr, RADEON_CAPABILITIES_PTR_PCI_CONFIG); 1836 cap_ptr &= RADEON_CAP_PTR_MASK; 1837 1838 while(cap_ptr != RADEON_CAP_ID_NULL) { 1839 PCI_READ_LONG(info->PciInfo, &cap_id, cap_ptr); 1840 if ((cap_id & 0xff)== RADEON_CAP_ID_AGP) { 1841 info->cardType = CARD_AGP; 1842 break; 1843 } 1844 if ((cap_id & 0xff)== RADEON_CAP_ID_EXP) { 1845 info->cardType = CARD_PCIE; 1846 break; 1847 } 1848 cap_ptr = (cap_id >> 8) & RADEON_CAP_PTR_MASK; 1849 } 1850 } 1851 1852 1853 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%s card detected\n", 1854 (info->cardType==CARD_PCI) ? "PCI" : 1855 (info->cardType==CARD_PCIE) ? "PCIE" : "AGP"); 1856 1857 /* treat PCIE IGP cards as PCI */ 1858 if (info->cardType == CARD_PCIE && info->IsIGP) 1859 info->cardType = CARD_PCI; 1860 1861 if ((s = xf86GetOptValString(info->Options, OPTION_BUS_TYPE))) { 1862 if (strcmp(s, "AGP") == 0) { 1863 info->cardType = CARD_AGP; 1864 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Forced into AGP mode\n"); 1865 } else if (strcmp(s, "PCI") == 0) { 1866 info->cardType = CARD_PCI; 1867 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Forced into PCI mode\n"); 1868 } else if (strcmp(s, "PCIE") == 0) { 1869 info->cardType = CARD_PCIE; 1870 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Forced into PCI Express mode\n"); 1871 } else { 1872 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, 1873 "Invalid BusType option, using detected type\n"); 1874 } 1875 } 1876#endif 1877 xf86GetOptValBool(info->Options, OPTION_SHOWCACHE, &info->showCache); 1878 if (info->showCache) 1879 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, 1880 "Option ShowCache enabled\n"); 1881 1882#ifdef RENDER 1883 info->RenderAccel = xf86ReturnOptValBool(info->Options, OPTION_RENDER_ACCEL, 1884 info->Chipset != PCI_CHIP_RN50_515E && 1885 info->Chipset != PCI_CHIP_RN50_5969); 1886#endif 1887 1888 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1889 info->r600_shadow_fb = TRUE; 1890 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 1891 "using shadow framebuffer\n"); 1892 if (!xf86LoadSubModule(pScrn, "shadow")) 1893 return FALSE; 1894 } 1895 1896 1897 if ((info->ChipFamily == CHIP_FAMILY_RS100) || 1898 (info->ChipFamily == CHIP_FAMILY_RS200) || 1899 (info->ChipFamily == CHIP_FAMILY_RS300) || 1900 (info->ChipFamily == CHIP_FAMILY_RS400) || 1901 (info->ChipFamily == CHIP_FAMILY_RS480) || 1902 (info->ChipFamily == CHIP_FAMILY_RS600) || 1903 (info->ChipFamily == CHIP_FAMILY_RS690) || 1904 (info->ChipFamily == CHIP_FAMILY_RS740)) 1905 info->has_tcl = FALSE; 1906 else { 1907 info->has_tcl = TRUE; 1908 } 1909 1910 return TRUE; 1911} 1912 1913 1914static void RADEONPreInitDDC(ScrnInfoPtr pScrn) 1915{ 1916 RADEONInfoPtr info = RADEONPTR(pScrn); 1917 /* vbeInfoPtr pVbe; */ 1918 1919 info->ddc1 = FALSE; 1920 info->ddc_bios = FALSE; 1921 if (!xf86LoadSubModule(pScrn, "ddc")) { 1922 info->ddc2 = FALSE; 1923 } else { 1924 info->ddc2 = TRUE; 1925 } 1926 1927 /* DDC can use I2C bus */ 1928 /* Load I2C if we have the code to use it */ 1929 if (info->ddc2) { 1930 xf86LoadSubModule(pScrn, "i2c"); 1931 } 1932} 1933 1934/* This is called by RADEONPreInit to initialize gamma correction */ 1935static Bool RADEONPreInitGamma(ScrnInfoPtr pScrn) 1936{ 1937 Gamma zeros = { 0.0, 0.0, 0.0 }; 1938 1939 if (!xf86SetGamma(pScrn, zeros)) return FALSE; 1940 return TRUE; 1941} 1942 1943/* This is called by RADEONPreInit to initialize the hardware cursor */ 1944static Bool RADEONPreInitCursor(ScrnInfoPtr pScrn) 1945{ 1946 RADEONInfoPtr info = RADEONPTR(pScrn); 1947 1948 if (!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE)) { 1949 if (!xf86LoadSubModule(pScrn, "ramdac")) return FALSE; 1950 } 1951 return TRUE; 1952} 1953 1954/* This is called by RADEONPreInit to initialize hardware acceleration */ 1955static Bool RADEONPreInitAccel(ScrnInfoPtr pScrn) 1956{ 1957 RADEONInfoPtr info = RADEONPTR(pScrn); 1958 MessageType from; 1959#if defined(USE_EXA) && defined(USE_XAA) 1960 char *optstr; 1961#endif 1962 1963 info->useEXA = FALSE; 1964 1965 if (info->ChipFamily >= CHIP_FAMILY_R600) { 1966 xf86DrvMsg(pScrn->scrnIndex, X_DEFAULT, 1967 "No acceleration support available on R600 yet.\n"); 1968 return TRUE; 1969 } 1970 1971 if (!xf86ReturnOptValBool(info->Options, OPTION_NOACCEL, FALSE)) { 1972 int errmaj = 0, errmin = 0; 1973 1974 from = X_DEFAULT; 1975#if defined(USE_EXA) 1976#if defined(USE_XAA) 1977 optstr = (char *)xf86GetOptValString(info->Options, OPTION_ACCELMETHOD); 1978 if (optstr != NULL) { 1979 if (xf86NameCmp(optstr, "EXA") == 0) { 1980 from = X_CONFIG; 1981 info->useEXA = TRUE; 1982 } else if (xf86NameCmp(optstr, "XAA") == 0) { 1983 from = X_CONFIG; 1984 } 1985 } 1986#else /* USE_XAA */ 1987 info->useEXA = TRUE; 1988#endif /* !USE_XAA */ 1989#endif /* USE_EXA */ 1990 xf86DrvMsg(pScrn->scrnIndex, from, 1991 "Using %s acceleration architecture\n", 1992 info->useEXA ? "EXA" : "XAA"); 1993 1994#ifdef USE_EXA 1995 if (info->useEXA) { 1996 info->exaReq.majorversion = EXA_VERSION_MAJOR; 1997 info->exaReq.minorversion = EXA_VERSION_MINOR; 1998 1999 if (!LoadSubModule(pScrn->module, "exa", NULL, NULL, NULL, 2000 &info->exaReq, &errmaj, &errmin)) { 2001 LoaderErrorMsg(NULL, "exa", errmaj, errmin); 2002 return FALSE; 2003 } 2004 } 2005#endif /* USE_EXA */ 2006#ifdef USE_XAA 2007 if (!info->useEXA) { 2008 info->xaaReq.majorversion = 1; 2009 info->xaaReq.minorversion = 2; 2010 2011 if (!LoadSubModule(pScrn->module, "xaa", NULL, NULL, NULL, 2012 &info->xaaReq, &errmaj, &errmin)) { 2013 info->xaaReq.minorversion = 1; 2014 2015 if (!LoadSubModule(pScrn->module, "xaa", NULL, NULL, NULL, 2016 &info->xaaReq, &errmaj, &errmin)) { 2017 info->xaaReq.minorversion = 0; 2018 2019 if (!LoadSubModule(pScrn->module, "xaa", NULL, NULL, NULL, 2020 &info->xaaReq, &errmaj, &errmin)) { 2021 LoaderErrorMsg(NULL, "xaa", errmaj, errmin); 2022 return FALSE; 2023 } 2024 } 2025 } 2026 } 2027#endif /* USE_XAA */ 2028 } 2029 2030 return TRUE; 2031} 2032 2033static Bool RADEONPreInitInt10(ScrnInfoPtr pScrn, xf86Int10InfoPtr *ppInt10) 2034{ 2035#if !defined(__powerpc__) && !defined(__sparc__) 2036 RADEONInfoPtr info = RADEONPTR(pScrn); 2037 unsigned char *RADEONMMIO = info->MMIO; 2038 uint32_t fp2_gen_ctl_save = 0; 2039 2040#ifdef XSERVER_LIBPCIACCESS 2041#if HAVE_PCI_DEVICE_ENABLE 2042 pci_device_enable(info->PciInfo); 2043#endif 2044#endif 2045 /* don't need int10 on atom cards. 2046 * in theory all radeons, but the older stuff 2047 * isn't 100% yet 2048 * secondary atom cards tend to hang when initializing int10, 2049 * however, on some stom cards, you can't read the bios without 2050 * intitializing int10. 2051 */ 2052 if (!xf86ReturnOptValBool(info->Options, OPTION_INT10, TRUE)) 2053 return TRUE; 2054 2055 if (xf86LoadSubModule(pScrn, "int10")) { 2056 /* The VGA BIOS on the RV100/QY cannot be read when the digital output 2057 * is enabled. Clear and restore FP2_ON around int10 to avoid this. 2058 */ 2059 if (PCI_DEV_DEVICE_ID(info->PciInfo) == PCI_CHIP_RV100_QY) { 2060 fp2_gen_ctl_save = INREG(RADEON_FP2_GEN_CNTL); 2061 if (fp2_gen_ctl_save & RADEON_FP2_ON) { 2062 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "disabling digital out\n"); 2063 OUTREG(RADEON_FP2_GEN_CNTL, fp2_gen_ctl_save & ~RADEON_FP2_ON); 2064 } 2065 } 2066 2067 xf86DrvMsg(pScrn->scrnIndex,X_INFO,"initializing int10\n"); 2068 *ppInt10 = xf86InitInt10(info->pEnt->index); 2069 2070 if (PCI_DEV_DEVICE_ID(info->PciInfo) == PCI_CHIP_RV100_QY) { 2071 if (fp2_gen_ctl_save & RADEON_FP2_ON) { 2072 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "re-enabling digital out\n"); 2073 OUTREG(RADEON_FP2_GEN_CNTL, fp2_gen_ctl_save); 2074 } 2075 } 2076 } 2077#endif 2078 return TRUE; 2079} 2080 2081#ifdef XF86DRI 2082static Bool RADEONPreInitDRI(ScrnInfoPtr pScrn) 2083{ 2084 RADEONInfoPtr info = RADEONPTR(pScrn); 2085 MessageType from; 2086 char *reason; 2087 2088 info->directRenderingEnabled = FALSE; 2089 info->directRenderingInited = FALSE; 2090 info->CPInUse = FALSE; 2091 info->CPStarted = FALSE; 2092 info->pLibDRMVersion = NULL; 2093 info->pKernelDRMVersion = NULL; 2094 2095 if (xf86IsEntityShared(info->pEnt->index)) { 2096 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 2097 "Direct Rendering Disabled -- " 2098 "Dual-head configuration is not working with " 2099 "DRI at present.\n" 2100 "Please use the radeon MergedFB option if you " 2101 "want Dual-head with DRI.\n"); 2102 return FALSE; 2103 } 2104 if (info->IsSecondary) 2105 return FALSE; 2106 2107 if (info->Chipset == PCI_CHIP_RN50_515E || 2108 info->Chipset == PCI_CHIP_RN50_5969 || 2109 info->Chipset == PCI_CHIP_RC410_5A61 || 2110 info->Chipset == PCI_CHIP_RC410_5A62 || 2111 info->Chipset == PCI_CHIP_RS485_5975 || 2112 info->ChipFamily == CHIP_FAMILY_RS600 || 2113 info->ChipFamily >= CHIP_FAMILY_R600) { 2114 if (xf86ReturnOptValBool(info->Options, OPTION_DRI, FALSE)) { 2115 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 2116 "Direct rendering for RN50/RC410/RS485/RS600/R600 forced on -- " 2117 "This is NOT officially supported at the hardware level " 2118 "and may cause instability or lockups\n"); 2119 } else { 2120 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2121 "Direct rendering not officially supported on RN50/RC410/R600\n"); 2122 return FALSE; 2123 } 2124 } 2125 2126 2127 if (!xf86ReturnOptValBool(info->Options, OPTION_DRI, TRUE)) { 2128 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2129 "Direct rendering forced off\n"); 2130 return FALSE; 2131 } 2132 2133 if (xf86ReturnOptValBool(info->Options, OPTION_NOACCEL, FALSE)) { 2134 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 2135 "[dri] Acceleration disabled, not initializing the DRI\n"); 2136 return FALSE; 2137 } 2138 2139 if (!RADEONDRIGetVersion(pScrn)) 2140 return FALSE; 2141 2142 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2143 "[dri] Found DRI library version %d.%d.%d and kernel" 2144 " module version %d.%d.%d\n", 2145 info->pLibDRMVersion->version_major, 2146 info->pLibDRMVersion->version_minor, 2147 info->pLibDRMVersion->version_patchlevel, 2148 info->pKernelDRMVersion->version_major, 2149 info->pKernelDRMVersion->version_minor, 2150 info->pKernelDRMVersion->version_patchlevel); 2151 2152 if (info->Chipset == PCI_CHIP_RS400_5A41 || 2153 info->Chipset == PCI_CHIP_RS400_5A42 || 2154 info->Chipset == PCI_CHIP_RC410_5A61 || 2155 info->Chipset == PCI_CHIP_RC410_5A62 || 2156 info->Chipset == PCI_CHIP_RS480_5954 || 2157 info->Chipset == PCI_CHIP_RS480_5955 || 2158 info->Chipset == PCI_CHIP_RS482_5974 || 2159 info->Chipset == PCI_CHIP_RS485_5975) { 2160 2161 if (info->pKernelDRMVersion->version_minor < 27) { 2162 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2163 "Direct rendering broken on XPRESS 200 and 200M with DRI less than 1.27\n"); 2164 return FALSE; 2165 } 2166 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2167 "Direct rendering experimental on RS400/Xpress 200 enabled\n"); 2168 } 2169 2170 if (xf86ReturnOptValBool(info->Options, OPTION_CP_PIO, FALSE)) { 2171 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Forcing CP into PIO mode\n"); 2172 info->CPMode = RADEON_DEFAULT_CP_PIO_MODE; 2173 } else { 2174 info->CPMode = RADEON_DEFAULT_CP_BM_MODE; 2175 } 2176 2177 info->gartSize = RADEON_DEFAULT_GART_SIZE; 2178 info->ringSize = RADEON_DEFAULT_RING_SIZE; 2179 info->bufSize = RADEON_DEFAULT_BUFFER_SIZE; 2180 info->gartTexSize = RADEON_DEFAULT_GART_TEX_SIZE; 2181 info->pciAperSize = RADEON_DEFAULT_PCI_APER_SIZE; 2182 info->CPusecTimeout = RADEON_DEFAULT_CP_TIMEOUT; 2183 2184 if ((xf86GetOptValInteger(info->Options, 2185 OPTION_GART_SIZE, (int *)&(info->gartSize))) || 2186 (xf86GetOptValInteger(info->Options, 2187 OPTION_GART_SIZE_OLD, (int *)&(info->gartSize)))) { 2188 switch (info->gartSize) { 2189 case 4: 2190 case 8: 2191 case 16: 2192 case 32: 2193 case 64: 2194 case 128: 2195 case 256: 2196 break; 2197 2198 default: 2199 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2200 "Illegal GART size: %d MB\n", info->gartSize); 2201 return FALSE; 2202 } 2203 } 2204 2205 if (xf86GetOptValInteger(info->Options, 2206 OPTION_RING_SIZE, &(info->ringSize))) { 2207 if (info->ringSize < 1 || info->ringSize >= (int)info->gartSize) { 2208 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2209 "Illegal ring buffer size: %d MB\n", 2210 info->ringSize); 2211 return FALSE; 2212 } 2213 } 2214 2215 if (xf86GetOptValInteger(info->Options, 2216 OPTION_PCIAPER_SIZE, &(info->pciAperSize))) { 2217 switch(info->pciAperSize) { 2218 case 32: 2219 case 64: 2220 case 128: 2221 case 256: 2222 break; 2223 default: 2224 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2225 "Illegal pci aper size: %d MB\n", 2226 info->pciAperSize); 2227 return FALSE; 2228 } 2229 } 2230 2231 2232 if (xf86GetOptValInteger(info->Options, 2233 OPTION_BUFFER_SIZE, &(info->bufSize))) { 2234 if (info->bufSize < 1 || info->bufSize >= (int)info->gartSize) { 2235 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2236 "Illegal vertex/indirect buffers size: %d MB\n", 2237 info->bufSize); 2238 return FALSE; 2239 } 2240 if (info->bufSize > 2) { 2241 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2242 "Illegal vertex/indirect buffers size: %d MB\n", 2243 info->bufSize); 2244 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2245 "Clamping vertex/indirect buffers size to 2 MB\n"); 2246 info->bufSize = 2; 2247 } 2248 } 2249 2250 if (info->ringSize + info->bufSize + info->gartTexSize > 2251 (int)info->gartSize) { 2252 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2253 "Buffers are too big for requested GART space\n"); 2254 return FALSE; 2255 } 2256 2257 info->gartTexSize = info->gartSize - (info->ringSize + info->bufSize); 2258 2259 if (xf86GetOptValInteger(info->Options, OPTION_USEC_TIMEOUT, 2260 &(info->CPusecTimeout))) { 2261 /* This option checked by the RADEON DRM kernel module */ 2262 } 2263 2264 /* Two options to try and squeeze as much texture memory as possible 2265 * for dedicated 3d rendering boxes 2266 */ 2267 info->noBackBuffer = xf86ReturnOptValBool(info->Options, 2268 OPTION_NO_BACKBUFFER, 2269 FALSE); 2270 2271 info->allowPageFlip = 0; 2272 2273#ifdef DAMAGE 2274 if (info->noBackBuffer) { 2275 from = X_DEFAULT; 2276 reason = " because back buffer disabled"; 2277 } else { 2278 from = xf86GetOptValBool(info->Options, OPTION_PAGE_FLIP, 2279 &info->allowPageFlip) ? X_CONFIG : X_DEFAULT; 2280 2281 if (IS_AVIVO_VARIANT) { 2282 info->allowPageFlip = 0; 2283 reason = " on r5xx and newer chips.\n"; 2284 } else { 2285 reason = ""; 2286 } 2287 2288 } 2289#else 2290 from = X_DEFAULT; 2291 reason = " because Damage layer not available at build time"; 2292#endif 2293 2294 xf86DrvMsg(pScrn->scrnIndex, from, "Page Flipping %sabled%s\n", 2295 info->allowPageFlip ? "en" : "dis", reason); 2296 2297 info->DMAForXv = TRUE; 2298 from = xf86GetOptValBool(info->Options, OPTION_XV_DMA, &info->DMAForXv) 2299 ? X_CONFIG : X_INFO; 2300 xf86DrvMsg(pScrn->scrnIndex, from, 2301 "Will %stry to use DMA for Xv image transfers\n", 2302 info->DMAForXv ? "" : "not "); 2303 2304 return TRUE; 2305} 2306#endif /* XF86DRI */ 2307 2308static void RADEONPreInitColorTiling(ScrnInfoPtr pScrn) 2309{ 2310 RADEONInfoPtr info = RADEONPTR(pScrn); 2311 2312 info->allowColorTiling = xf86ReturnOptValBool(info->Options, 2313 OPTION_COLOR_TILING, TRUE); 2314 if (IS_R300_VARIANT || IS_AVIVO_VARIANT) { 2315 /* this may be 4096 on r4xx -- need to double check */ 2316 info->MaxSurfaceWidth = 3968; /* one would have thought 4096...*/ 2317 info->MaxLines = 4096; 2318 } else { 2319 info->MaxSurfaceWidth = 2048; 2320 info->MaxLines = 2048; 2321 } 2322 2323 if (!info->allowColorTiling) 2324 return; 2325 2326 if (info->ChipFamily >= CHIP_FAMILY_R600) 2327 info->allowColorTiling = FALSE; 2328 2329 /* for zaphod disable tiling for now */ 2330 if (info->IsPrimary || info->IsSecondary) 2331 info->allowColorTiling = FALSE; 2332 2333#ifdef XF86DRI 2334 if (info->directRenderingEnabled && 2335 info->pKernelDRMVersion->version_minor < 14) { 2336 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 2337 "[dri] color tiling disabled because of version " 2338 "mismatch.\n" 2339 "[dri] radeon.o kernel module version is %d.%d.%d but " 2340 "1.14.0 or later is required for color tiling.\n", 2341 info->pKernelDRMVersion->version_major, 2342 info->pKernelDRMVersion->version_minor, 2343 info->pKernelDRMVersion->version_patchlevel); 2344 info->allowColorTiling = FALSE; 2345 return; 2346 } 2347#endif /* XF86DRI */ 2348 2349 if (info->allowColorTiling) { 2350 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Color tiling enabled by default\n"); 2351 } else { 2352 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Color tiling disabled\n"); 2353 } 2354} 2355 2356 2357static Bool RADEONPreInitXv(ScrnInfoPtr pScrn) 2358{ 2359 RADEONInfoPtr info = RADEONPTR(pScrn); 2360 uint16_t mm_table; 2361 uint16_t bios_header; 2362 uint16_t pll_info_block; 2363#ifdef XvExtension 2364 char* microc_path = NULL; 2365 char* microc_type = NULL; 2366 MessageType from; 2367 2368 if (xf86GetOptValInteger(info->Options, OPTION_VIDEO_KEY, 2369 &(info->videoKey))) { 2370 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "video key set to 0x%x\n", 2371 info->videoKey); 2372 } else { 2373 info->videoKey = 0x1E; 2374 } 2375 2376 if(xf86GetOptValInteger(info->Options, OPTION_RAGE_THEATRE_CRYSTAL, &(info->RageTheatreCrystal))) { 2377 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rage Theatre Crystal frequency was specified as %d.%d Mhz\n", 2378 info->RageTheatreCrystal/100, info->RageTheatreCrystal % 100); 2379 } else { 2380 info->RageTheatreCrystal=-1; 2381 } 2382 2383 if(xf86GetOptValInteger(info->Options, OPTION_RAGE_THEATRE_TUNER_PORT, &(info->RageTheatreTunerPort))) { 2384 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rage Theatre tuner port was specified as %d\n", 2385 info->RageTheatreTunerPort); 2386 } else { 2387 info->RageTheatreTunerPort=-1; 2388 } 2389 2390 if(info->RageTheatreTunerPort>5){ 2391 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Attempt to assign Rage Theatre tuner port to invalid value. Disabling setting\n"); 2392 info->RageTheatreTunerPort=-1; 2393 } 2394 2395 if(xf86GetOptValInteger(info->Options, OPTION_RAGE_THEATRE_COMPOSITE_PORT, &(info->RageTheatreCompositePort))) { 2396 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rage Theatre composite port was specified as %d\n", 2397 info->RageTheatreCompositePort); 2398 } else { 2399 info->RageTheatreCompositePort=-1; 2400 } 2401 2402 if(info->RageTheatreCompositePort>6){ 2403 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Attempt to assign Rage Theatre composite port to invalid value. Disabling setting\n"); 2404 info->RageTheatreCompositePort=-1; 2405 } 2406 2407 if(xf86GetOptValInteger(info->Options, OPTION_RAGE_THEATRE_SVIDEO_PORT, &(info->RageTheatreSVideoPort))) { 2408 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rage Theatre SVideo Port was specified as %d\n", 2409 info->RageTheatreSVideoPort); 2410 } else { 2411 info->RageTheatreSVideoPort=-1; 2412 } 2413 2414 if(info->RageTheatreSVideoPort>6){ 2415 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Attempt to assign Rage Theatre SVideo port to invalid value. Disabling setting\n"); 2416 info->RageTheatreSVideoPort=-1; 2417 } 2418 2419 if(xf86GetOptValInteger(info->Options, OPTION_TUNER_TYPE, &(info->tunerType))) { 2420 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Tuner type was specified as %d\n", 2421 info->tunerType); 2422 } else { 2423 info->tunerType=-1; 2424 } 2425 2426 if(info->tunerType>31){ 2427 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Attempt to set tuner type to invalid value. Disabling setting\n"); 2428 info->tunerType=-1; 2429 } 2430 2431 if((microc_path = xf86GetOptValString(info->Options, OPTION_RAGE_THEATRE_MICROC_PATH)) != NULL) 2432 { 2433 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rage Theatre Microcode path was specified as %s\n", microc_path); 2434 info->RageTheatreMicrocPath = microc_path; 2435 } else { 2436 info->RageTheatreMicrocPath= NULL; 2437 } 2438 2439 if((microc_type = xf86GetOptValString(info->Options, OPTION_RAGE_THEATRE_MICROC_TYPE)) != NULL) 2440 { 2441 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Rage Theatre Microcode type was specified as %s\n", microc_type); 2442 info->RageTheatreMicrocType = microc_type; 2443 } else { 2444 info->RageTheatreMicrocType= NULL; 2445 } 2446 2447 if(xf86GetOptValInteger(info->Options, OPTION_SCALER_WIDTH, &(info->overlay_scaler_buffer_width))) { 2448 if ((info->overlay_scaler_buffer_width < 1024) || 2449 (info->overlay_scaler_buffer_width > 2048) || 2450 ((info->overlay_scaler_buffer_width % 64) != 0)) { 2451 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Attempt to set illegal scaler width. Using default\n"); 2452 from = X_DEFAULT; 2453 info->overlay_scaler_buffer_width = 0; 2454 } else 2455 from = X_CONFIG; 2456 } else { 2457 from = X_DEFAULT; 2458 info->overlay_scaler_buffer_width = 0; 2459 } 2460 if (!info->overlay_scaler_buffer_width) { 2461 /* overlay scaler line length differs for different revisions 2462 this needs to be maintained by hand */ 2463 switch(info->ChipFamily){ 2464 case CHIP_FAMILY_R200: 2465 case CHIP_FAMILY_R300: 2466 case CHIP_FAMILY_RV350: 2467 info->overlay_scaler_buffer_width = 1920; 2468 break; 2469 default: 2470 info->overlay_scaler_buffer_width = 1536; 2471 } 2472 } 2473 xf86DrvMsg(pScrn->scrnIndex, from, "Assuming overlay scaler buffer width is %d\n", 2474 info->overlay_scaler_buffer_width); 2475#endif 2476 2477 /* Rescue MM_TABLE before VBIOS is freed */ 2478 info->MM_TABLE_valid = FALSE; 2479 2480 if((info->VBIOS==NULL)||(info->VBIOS[0]!=0x55)||(info->VBIOS[1]!=0xaa)){ 2481 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Cannot access BIOS or it is not valid.\n" 2482 "\t\tIf your card is TV-in capable you will need to specify options RageTheatreCrystal, RageTheatreTunerPort, \n" 2483 "\t\tRageTheatreSVideoPort and TunerType in /etc/X11/xorg.conf.\n" 2484 ); 2485 info->MM_TABLE_valid = FALSE; 2486 return TRUE; 2487 } 2488 2489 bios_header=info->VBIOS[0x48]; 2490 bios_header+=(((int)info->VBIOS[0x49]+0)<<8); 2491 2492 mm_table=info->VBIOS[bios_header+0x38]; 2493 if(mm_table==0) 2494 { 2495 xf86DrvMsg(pScrn->scrnIndex,X_INFO,"No MM_TABLE found - assuming CARD is not TV-in capable.\n"); 2496 info->MM_TABLE_valid = FALSE; 2497 return TRUE; 2498 } 2499 mm_table+=(((int)info->VBIOS[bios_header+0x39]+0)<<8)-2; 2500 2501 if(mm_table>0) 2502 { 2503 memcpy(&(info->MM_TABLE), &(info->VBIOS[mm_table]), sizeof(info->MM_TABLE)); 2504 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "MM_TABLE: %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n", 2505 info->MM_TABLE.table_revision, 2506 info->MM_TABLE.table_size, 2507 info->MM_TABLE.tuner_type, 2508 info->MM_TABLE.audio_chip, 2509 info->MM_TABLE.product_id, 2510 info->MM_TABLE.tuner_voltage_teletext_fm, 2511 info->MM_TABLE.i2s_config, 2512 info->MM_TABLE.video_decoder_type, 2513 info->MM_TABLE.video_decoder_host_config, 2514 info->MM_TABLE.input[0], 2515 info->MM_TABLE.input[1], 2516 info->MM_TABLE.input[2], 2517 info->MM_TABLE.input[3], 2518 info->MM_TABLE.input[4]); 2519 2520 /* Is it an MM_TABLE we know about ? */ 2521 if(info->MM_TABLE.table_size != 0xc){ 2522 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "This card has MM_TABLE we do not recognize.\n" 2523 "\t\tIf your card is TV-in capable you will need to specify options RageTheatreCrystal, RageTheatreTunerPort, \n" 2524 "\t\tRageTheatreSVideoPort and TunerType in /etc/X11/xorg.conf.\n" 2525 ); 2526 info->MM_TABLE_valid = FALSE; 2527 return TRUE; 2528 } 2529 info->MM_TABLE_valid = TRUE; 2530 } else { 2531 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "No MM_TABLE found - assuming card is not TV-in capable (mm_table=%d).\n", mm_table); 2532 info->MM_TABLE_valid = FALSE; 2533 } 2534 2535 pll_info_block=info->VBIOS[bios_header+0x30]; 2536 pll_info_block+=(((int)info->VBIOS[bios_header+0x31]+0)<<8); 2537 2538 info->video_decoder_type=info->VBIOS[pll_info_block+0x08]; 2539 info->video_decoder_type+=(((int)info->VBIOS[pll_info_block+0x09]+0)<<8); 2540 2541 return TRUE; 2542} 2543 2544static Bool 2545RADEONPreInitBIOS(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10) 2546{ 2547 RADEONInfoPtr info = RADEONPTR(pScrn); 2548 2549 if (!RADEONGetBIOSInfo(pScrn, pInt10)) { 2550 /* Avivo chips require bios for atom */ 2551 if (IS_AVIVO_VARIANT) 2552 return FALSE; 2553 } 2554 return TRUE; 2555} 2556 2557static void RADEONFixZaphodOutputs(ScrnInfoPtr pScrn) 2558{ 2559 RADEONInfoPtr info = RADEONPTR(pScrn); 2560 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); 2561 2562 if (info->IsPrimary) { 2563 xf86OutputDestroy(config->output[0]); 2564 while(config->num_output > 1) { 2565 xf86OutputDestroy(config->output[1]); 2566 } 2567 } else { 2568 while(config->num_output > 1) { 2569 xf86OutputDestroy(config->output[1]); 2570 } 2571 } 2572} 2573 2574static Bool RADEONPreInitControllers(ScrnInfoPtr pScrn) 2575{ 2576 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); 2577 RADEONInfoPtr info = RADEONPTR(pScrn); 2578 int i; 2579 int mask; 2580 int found = 0; 2581 2582 if (!info->IsPrimary && !info->IsSecondary) 2583 mask = 3; 2584 else if (info->IsPrimary) 2585 mask = 1; 2586 else 2587 mask = 2; 2588 2589 if (!RADEONAllocateControllers(pScrn, mask)) 2590 return FALSE; 2591 2592 RADEONGetClockInfo(pScrn); 2593 2594 if (!RADEONSetupConnectors(pScrn)) { 2595 return FALSE; 2596 } 2597 2598 if (info->IsPrimary || info->IsSecondary) { 2599 /* fixup outputs for zaphod */ 2600 RADEONFixZaphodOutputs(pScrn); 2601 } 2602 2603 RADEONPrintPortMap(pScrn); 2604 2605 info->first_load_no_devices = FALSE; 2606 for (i = 0; i < config->num_output; i++) { 2607 xf86OutputPtr output = config->output[i]; 2608 2609 output->status = (*output->funcs->detect) (output); 2610 ErrorF("finished output detect: %d\n", i); 2611 if (info->IsPrimary || info->IsSecondary) { 2612 if (output->status != XF86OutputStatusConnected) 2613 return FALSE; 2614 } 2615 if (output->status != XF86OutputStatusDisconnected) 2616 found++; 2617 } 2618 2619 if (!found) { 2620 /* nothing connected, light up some defaults so the server comes up */ 2621 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No connected devices found!\n"); 2622 info->first_load_no_devices = TRUE; 2623 } 2624 2625 ErrorF("finished all detect\n"); 2626 return TRUE; 2627} 2628 2629static void 2630RADEONProbeDDC(ScrnInfoPtr pScrn, int indx) 2631{ 2632 vbeInfoPtr pVbe; 2633 2634 if (xf86LoadSubModule(pScrn, "vbe")) { 2635 pVbe = VBEInit(NULL,indx); 2636 ConfiguredMonitor = vbeDoEDID(pVbe, NULL); 2637 } 2638} 2639 2640static Bool 2641RADEONCRTCResize(ScrnInfoPtr scrn, int width, int height) 2642{ 2643 scrn->virtualX = width; 2644 scrn->virtualY = height; 2645 /* RADEONSetPitch(scrn); */ 2646 return TRUE; 2647} 2648 2649static const xf86CrtcConfigFuncsRec RADEONCRTCResizeFuncs = { 2650 RADEONCRTCResize 2651}; 2652 2653Bool RADEONPreInit(ScrnInfoPtr pScrn, int flags) 2654{ 2655 xf86CrtcConfigPtr xf86_config; 2656 RADEONInfoPtr info; 2657 xf86Int10InfoPtr pInt10 = NULL; 2658 void *int10_save = NULL; 2659 const char *s; 2660 int crtc_max_X, crtc_max_Y; 2661 RADEONEntPtr pRADEONEnt; 2662 DevUnion* pPriv; 2663 2664 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 2665 "RADEONPreInit\n"); 2666 if (pScrn->numEntities != 1) return FALSE; 2667 2668 if (!RADEONGetRec(pScrn)) return FALSE; 2669 2670 info = RADEONPTR(pScrn); 2671 info->MMIO = NULL; 2672 2673 info->IsSecondary = FALSE; 2674 info->IsPrimary = FALSE; 2675 2676 info->pEnt = xf86GetEntityInfo(pScrn->entityList[pScrn->numEntities - 1]); 2677 if (info->pEnt->location.type != BUS_PCI) goto fail; 2678 2679 pPriv = xf86GetEntityPrivate(pScrn->entityList[0], 2680 getRADEONEntityIndex()); 2681 pRADEONEnt = pPriv->ptr; 2682 2683 if(xf86IsEntityShared(pScrn->entityList[0])) 2684 { 2685 if(xf86IsPrimInitDone(pScrn->entityList[0])) 2686 { 2687 info->IsSecondary = TRUE; 2688 pRADEONEnt->pSecondaryScrn = pScrn; 2689 info->SavedReg = &pRADEONEnt->SavedReg; 2690 info->ModeReg = &pRADEONEnt->ModeReg; 2691 } 2692 else 2693 { 2694 info->IsPrimary = TRUE; 2695 xf86SetPrimInitDone(pScrn->entityList[0]); 2696 pRADEONEnt->pPrimaryScrn = pScrn; 2697 pRADEONEnt->HasSecondary = FALSE; 2698 info->SavedReg = &pRADEONEnt->SavedReg; 2699 info->ModeReg = &pRADEONEnt->ModeReg; 2700 } 2701 } else { 2702 info->SavedReg = &pRADEONEnt->SavedReg; 2703 info->ModeReg = &pRADEONEnt->ModeReg; 2704 } 2705 2706 info->PciInfo = xf86GetPciInfoForEntity(info->pEnt->index); 2707 info->PciTag = pciTag(PCI_DEV_BUS(info->PciInfo), 2708 PCI_DEV_DEV(info->PciInfo), 2709 PCI_DEV_FUNC(info->PciInfo)); 2710 info->MMIOAddr = PCI_REGION_BASE(info->PciInfo, 2, REGION_MEM) & ~0xffUL; 2711 info->MMIOSize = PCI_REGION_SIZE(info->PciInfo, 2); 2712 if (info->pEnt->device->IOBase) { 2713 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, 2714 "MMIO address override, using 0x%08lx instead of 0x%08lx\n", 2715 info->pEnt->device->IOBase, 2716 info->MMIOAddr); 2717 info->MMIOAddr = info->pEnt->device->IOBase; 2718 } else if (!info->MMIOAddr) { 2719 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid MMIO address\n"); 2720 goto fail1; 2721 } 2722 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2723 "MMIO registers at 0x%016lx: size %ldKB\n", info->MMIOAddr, info->MMIOSize / 1024); 2724 2725 if(!RADEONMapMMIO(pScrn)) { 2726 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 2727 "Memory map the MMIO region failed\n"); 2728 goto fail1; 2729 } 2730 2731#if !defined(__alpha__) 2732 if ( 2733#ifndef XSERVER_LIBPCIACCESS 2734 xf86GetPciDomain(info->PciTag) || 2735#endif 2736 !xf86IsPrimaryPci(info->PciInfo)) 2737 RADEONPreInt10Save(pScrn, &int10_save); 2738#else 2739 /* [Alpha] On the primary, the console already ran the BIOS and we're 2740 * going to run it again - so make sure to "fix up" the card 2741 * so that (1) we can read the BIOS ROM and (2) the BIOS will 2742 * get the memory config right. 2743 */ 2744 RADEONPreInt10Save(pScrn, &int10_save); 2745#endif 2746 2747 if (flags & PROBE_DETECT) { 2748 RADEONProbeDDC(pScrn, info->pEnt->index); 2749 RADEONPostInt10Check(pScrn, int10_save); 2750 if(info->MMIO) RADEONUnmapMMIO(pScrn); 2751 return TRUE; 2752 } 2753 2754 2755 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2756 "PCI bus %d card %d func %d\n", 2757 PCI_DEV_BUS(info->PciInfo), 2758 PCI_DEV_DEV(info->PciInfo), 2759 PCI_DEV_FUNC(info->PciInfo)); 2760 2761 if (xf86RegisterResources(info->pEnt->index, 0, ResExclusive)) 2762 goto fail; 2763 2764 xf86SetOperatingState(resVga, info->pEnt->index, ResUnusedOpr); 2765 2766 pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_VIEWPORT | RAC_CURSOR; 2767 pScrn->monitor = pScrn->confScreen->monitor; 2768 2769 /* Allocate an xf86CrtcConfig */ 2770 xf86CrtcConfigInit (pScrn, &RADEONCRTCResizeFuncs); 2771 xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); 2772 2773 2774 if (!RADEONPreInitVisual(pScrn)) 2775 goto fail; 2776 2777 /* We can't do this until we have a 2778 pScrn->display. */ 2779 xf86CollectOptions(pScrn, NULL); 2780 if (!(info->Options = xalloc(sizeof(RADEONOptions)))) 2781 goto fail; 2782 2783 memcpy(info->Options, RADEONOptions, sizeof(RADEONOptions)); 2784 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, info->Options); 2785 2786 /* By default, don't do VGA IOs on ppc/sparc */ 2787#if defined(__powerpc__) || defined(__sparc__) || !defined(WITH_VGAHW) 2788 info->VGAAccess = FALSE; 2789#else 2790 info->VGAAccess = TRUE; 2791#endif 2792 2793#ifdef WITH_VGAHW 2794 xf86GetOptValBool(info->Options, OPTION_VGA_ACCESS, &info->VGAAccess); 2795 if (info->VGAAccess) { 2796 if (!xf86LoadSubModule(pScrn, "vgahw")) 2797 info->VGAAccess = FALSE; 2798 else { 2799 if (!vgaHWGetHWRec(pScrn)) 2800 info->VGAAccess = FALSE; 2801 } 2802 if (!info->VGAAccess) 2803 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Loading VGA module failed," 2804 " trying to run without it\n"); 2805 } else 2806 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "VGAAccess option set to FALSE," 2807 " VGA module load skipped\n"); 2808 if (info->VGAAccess) 2809 vgaHWGetIOBase(VGAHWPTR(pScrn)); 2810#endif 2811 2812 2813 if (!RADEONPreInitWeight(pScrn)) 2814 goto fail; 2815 2816 info->DispPriority = 1; 2817 if ((s = xf86GetOptValString(info->Options, OPTION_DISP_PRIORITY))) { 2818 if (strcmp(s, "AUTO") == 0) { 2819 info->DispPriority = 1; 2820 } else if (strcmp(s, "BIOS") == 0) { 2821 info->DispPriority = 0; 2822 } else if (strcmp(s, "HIGH") == 0) { 2823 info->DispPriority = 2; 2824 } else 2825 info->DispPriority = 1; 2826 } 2827 2828 if (!RADEONPreInitChipType(pScrn)) 2829 goto fail; 2830 2831 if (!RADEONPreInitInt10(pScrn, &pInt10)) 2832 goto fail; 2833 2834 RADEONPostInt10Check(pScrn, int10_save); 2835 2836 if (!RADEONPreInitBIOS(pScrn, pInt10)) 2837 goto fail; 2838 2839#ifdef XF86DRI 2840 /* PreInit DRI first of all since we need that for getting a proper 2841 * memory map 2842 */ 2843 info->directRenderingEnabled = RADEONPreInitDRI(pScrn); 2844#endif 2845 if (!RADEONPreInitVRAM(pScrn)) 2846 goto fail; 2847 2848 RADEONPreInitColorTiling(pScrn); 2849 2850 /* we really need an FB manager... */ 2851 if (pScrn->display->virtualX) { 2852 crtc_max_X = pScrn->display->virtualX; 2853 crtc_max_Y = pScrn->display->virtualY; 2854 if (info->allowColorTiling) { 2855 if (crtc_max_X > info->MaxSurfaceWidth || 2856 crtc_max_Y > info->MaxLines) { 2857 info->allowColorTiling = FALSE; 2858 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 2859 "Requested desktop size exceeds surface limts for tiling, ColorTiling disabled\n"); 2860 } 2861 } 2862 if (crtc_max_X > 8192) 2863 crtc_max_X = 8192; 2864 if (crtc_max_Y > 8192) 2865 crtc_max_Y = 8192; 2866 } else { 2867 /* 2868 * note that these aren't really the CRTC limits, they're just 2869 * heuristics until we have a better memory manager. 2870 */ 2871 if (pScrn->videoRam <= 16384) { 2872 crtc_max_X = 1600; 2873 crtc_max_Y = 1200; 2874 } else if (IS_R300_VARIANT) { 2875 crtc_max_X = 2560; 2876 crtc_max_Y = 1200; 2877 } else if (IS_AVIVO_VARIANT) { 2878 crtc_max_X = 2560; 2879 crtc_max_Y = 1600; 2880 } else { 2881 crtc_max_X = 2048; 2882 crtc_max_Y = 1200; 2883 } 2884 } 2885 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Max desktop size set to %dx%d\n", 2886 crtc_max_X, crtc_max_Y); 2887 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2888 "For a larger or smaller max desktop size, add a Virtual line to your xorg.conf\n"); 2889 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 2890 "If you are having trouble with 3D, " 2891 "reduce the desktop size by adjusting the Virtual line to your xorg.conf\n"); 2892 2893 /*xf86CrtcSetSizeRange (pScrn, 320, 200, info->MaxSurfaceWidth, info->MaxLines);*/ 2894 xf86CrtcSetSizeRange (pScrn, 320, 200, crtc_max_X, crtc_max_Y); 2895 2896 RADEONPreInitDDC(pScrn); 2897 2898 if (!RADEONPreInitControllers(pScrn)) 2899 goto fail; 2900 2901 2902 ErrorF("before xf86InitialConfiguration\n"); 2903 2904 if (!xf86InitialConfiguration (pScrn, FALSE)) 2905 { 2906 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n"); 2907 goto fail; 2908 } 2909 2910 ErrorF("after xf86InitialConfiguration\n"); 2911 2912 RADEONSetPitch(pScrn); 2913 2914 /* Set display resolution */ 2915 xf86SetDpi(pScrn, 0, 0); 2916 2917 /* Get ScreenInit function */ 2918 if (!xf86LoadSubModule(pScrn, "fb")) return FALSE; 2919 2920 if (!RADEONPreInitGamma(pScrn)) goto fail; 2921 2922 if (!RADEONPreInitCursor(pScrn)) goto fail; 2923 2924 if (!RADEONPreInitAccel(pScrn)) goto fail; 2925 2926 if (!IS_AVIVO_VARIANT) { 2927 if (!RADEONPreInitXv(pScrn)) goto fail; 2928 } 2929 2930 if (!xf86RandR12PreInit (pScrn)) 2931 { 2932 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "RandR initialization failure\n"); 2933 goto fail; 2934 } 2935 2936 if (pScrn->modes == NULL) { 2937 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n"); 2938 goto fail; 2939 } 2940 2941 2942 /* Free int10 info */ 2943 if (pInt10) 2944 xf86FreeInt10(pInt10); 2945 2946 if(info->MMIO) RADEONUnmapMMIO(pScrn); 2947 info->MMIO = NULL; 2948 2949 xf86DrvMsg(pScrn->scrnIndex, X_NOTICE, 2950 "For information on using the multimedia capabilities\n\tof this" 2951 " adapter, please see http://gatos.sf.net.\n"); 2952 2953 xf86DrvMsg(pScrn->scrnIndex, X_NOTICE, 2954 "MergedFB support has been removed and replaced with" 2955 " xrandr 1.2 support\n"); 2956 2957 return TRUE; 2958 2959fail: 2960 /* Pre-init failed. */ 2961 /* Free the video bios (if applicable) */ 2962 if (info->VBIOS) { 2963 xfree(info->VBIOS); 2964 info->VBIOS = NULL; 2965 } 2966 2967 /* Free int10 info */ 2968 if (pInt10) 2969 xf86FreeInt10(pInt10); 2970 2971#ifdef WITH_VGAHW 2972 if (info->VGAAccess) 2973 vgaHWFreeHWRec(pScrn); 2974#endif 2975 2976 if(info->MMIO) RADEONUnmapMMIO(pScrn); 2977 info->MMIO = NULL; 2978 2979 fail1: 2980 RADEONFreeRec(pScrn); 2981 2982 return FALSE; 2983} 2984 2985/* Load a palette */ 2986static void RADEONLoadPalette(ScrnInfoPtr pScrn, int numColors, 2987 int *indices, LOCO *colors, VisualPtr pVisual) 2988{ 2989 RADEONInfoPtr info = RADEONPTR(pScrn); 2990 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); 2991 int i; 2992 int index, j; 2993 uint16_t lut_r[256], lut_g[256], lut_b[256]; 2994 int c; 2995 2996#ifdef XF86DRI 2997 if (info->CPStarted && pScrn->pScreen) DRILock(pScrn->pScreen, 0); 2998#endif 2999 3000 if (info->accelOn && pScrn->pScreen) 3001 RADEON_SYNC(info, pScrn); 3002 3003 { 3004 3005 for (c = 0; c < xf86_config->num_crtc; c++) { 3006 xf86CrtcPtr crtc = xf86_config->crtc[c]; 3007 RADEONCrtcPrivatePtr radeon_crtc = crtc->driver_private; 3008 3009 for (i = 0 ; i < 256; i++) { 3010 lut_r[i] = radeon_crtc->lut_r[i] << 8; 3011 lut_g[i] = radeon_crtc->lut_g[i] << 8; 3012 lut_b[i] = radeon_crtc->lut_b[i] << 8; 3013 } 3014 3015 switch (info->CurrentLayout.depth) { 3016 case 15: 3017 for (i = 0; i < numColors; i++) { 3018 index = indices[i]; 3019 for (j = 0; j < 8; j++) { 3020 lut_r[index * 8 + j] = colors[index].red << 8; 3021 lut_g[index * 8 + j] = colors[index].green << 8; 3022 lut_b[index * 8 + j] = colors[index].blue << 8; 3023 } 3024 } 3025 case 16: 3026 for (i = 0; i < numColors; i++) { 3027 index = indices[i]; 3028 3029 if (i <= 31) { 3030 for (j = 0; j < 8; j++) { 3031 lut_r[index * 8 + j] = colors[index].red << 8; 3032 lut_b[index * 8 + j] = colors[index].blue << 8; 3033 } 3034 } 3035 3036 for (j = 0; j < 4; j++) { 3037 lut_g[index * 4 + j] = colors[index].green << 8; 3038 } 3039 } 3040 default: 3041 for (i = 0; i < numColors; i++) { 3042 index = indices[i]; 3043 lut_r[index] = colors[index].red << 8; 3044 lut_g[index] = colors[index].green << 8; 3045 lut_b[index] = colors[index].blue << 8; 3046 } 3047 break; 3048 } 3049 3050 /* Make the change through RandR */ 3051#ifdef RANDR_12_INTERFACE 3052 if (crtc->randr_crtc) 3053 RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b); 3054 else 3055#endif 3056 crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256); 3057 } 3058 } 3059 3060#ifdef XF86DRI 3061 if (info->CPStarted && pScrn->pScreen) DRIUnlock(pScrn->pScreen); 3062#endif 3063} 3064 3065static void RADEONBlockHandler(int i, pointer blockData, 3066 pointer pTimeout, pointer pReadmask) 3067{ 3068 ScreenPtr pScreen = screenInfo.screens[i]; 3069 ScrnInfoPtr pScrn = xf86Screens[i]; 3070 RADEONInfoPtr info = RADEONPTR(pScrn); 3071 3072 pScreen->BlockHandler = info->BlockHandler; 3073 (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask); 3074 pScreen->BlockHandler = RADEONBlockHandler; 3075 3076 if (info->VideoTimerCallback) 3077 (*info->VideoTimerCallback)(pScrn, currentTime.milliseconds); 3078 3079#if defined(RENDER) && defined(USE_XAA) 3080 if(info->RenderCallback) 3081 (*info->RenderCallback)(pScrn); 3082#endif 3083 3084#ifdef USE_EXA 3085 info->engineMode = EXA_ENGINEMODE_UNKNOWN; 3086#endif 3087} 3088 3089static void 3090RADEONPointerMoved(int index, int x, int y) 3091{ 3092 ScrnInfoPtr pScrn = xf86Screens[index]; 3093 RADEONInfoPtr info = RADEONPTR(pScrn); 3094 int newX = x, newY = y; 3095 3096 switch (info->rotation) { 3097 case RR_Rotate_0: 3098 break; 3099 case RR_Rotate_90: 3100 newX = y; 3101 newY = pScrn->pScreen->width - x - 1; 3102 break; 3103 case RR_Rotate_180: 3104 newX = pScrn->pScreen->width - x - 1; 3105 newY = pScrn->pScreen->height - y - 1; 3106 break; 3107 case RR_Rotate_270: 3108 newX = pScrn->pScreen->height - y - 1; 3109 newY = x; 3110 break; 3111 } 3112 3113 (*info->PointerMoved)(index, newX, newY); 3114} 3115 3116static void 3117RADEONInitBIOSRegisters(ScrnInfoPtr pScrn) 3118{ 3119 RADEONInfoPtr info = RADEONPTR(pScrn); 3120 unsigned char *RADEONMMIO = info->MMIO; 3121 RADEONSavePtr save = info->ModeReg; 3122 3123 save->bios_0_scratch = info->SavedReg->bios_0_scratch; 3124 save->bios_1_scratch = info->SavedReg->bios_1_scratch; 3125 save->bios_2_scratch = info->SavedReg->bios_2_scratch; 3126 save->bios_3_scratch = info->SavedReg->bios_3_scratch; 3127 save->bios_4_scratch = info->SavedReg->bios_4_scratch; 3128 save->bios_5_scratch = info->SavedReg->bios_5_scratch; 3129 save->bios_6_scratch = info->SavedReg->bios_6_scratch; 3130 save->bios_7_scratch = info->SavedReg->bios_7_scratch; 3131 3132 if (info->IsAtomBios) { 3133 /* let the bios control the backlight */ 3134 save->bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE; 3135 /* tell the bios not to handle mode switching */ 3136 save->bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | 3137 ATOM_S6_ACC_MODE); 3138 3139 if (info->ChipFamily >= CHIP_FAMILY_R600) { 3140 OUTREG(R600_BIOS_2_SCRATCH, save->bios_2_scratch); 3141 OUTREG(R600_BIOS_6_SCRATCH, save->bios_6_scratch); 3142 } else { 3143 OUTREG(RADEON_BIOS_2_SCRATCH, save->bios_2_scratch); 3144 OUTREG(RADEON_BIOS_6_SCRATCH, save->bios_6_scratch); 3145 } 3146 } else { 3147 /* let the bios control the backlight */ 3148 save->bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN; 3149 /* tell the bios not to handle mode switching */ 3150 save->bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS | 3151 RADEON_ACC_MODE_CHANGE); 3152 /* tell the bios a driver is loaded */ 3153 save->bios_7_scratch |= RADEON_DRV_LOADED; 3154 3155 OUTREG(RADEON_BIOS_0_SCRATCH, save->bios_0_scratch); 3156 OUTREG(RADEON_BIOS_6_SCRATCH, save->bios_6_scratch); 3157 //OUTREG(RADEON_BIOS_7_SCRATCH, save->bios_7_scratch); 3158 } 3159 3160} 3161 3162 3163/* Called at the start of each server generation. */ 3164Bool RADEONScreenInit(int scrnIndex, ScreenPtr pScreen, 3165 int argc, char **argv) 3166{ 3167 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 3168 RADEONInfoPtr info = RADEONPTR(pScrn); 3169 int hasDRI = 0; 3170#ifdef RENDER 3171 int subPixelOrder = SubPixelUnknown; 3172 char* s; 3173#endif 3174 3175 3176 info->accelOn = FALSE; 3177#ifdef USE_XAA 3178 info->accel = NULL; 3179#endif 3180#ifdef XF86DRI 3181 pScrn->fbOffset = info->frontOffset; 3182#endif 3183 3184 if (info->IsSecondary) pScrn->fbOffset = pScrn->videoRam * 1024; 3185#ifdef XF86DRI 3186 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 3187 "RADEONScreenInit %lx %ld %d\n", 3188 pScrn->memPhysBase, pScrn->fbOffset, info->frontOffset); 3189#else 3190 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3191 "RADEONScreenInit %lx %ld\n", 3192 pScrn->memPhysBase, pScrn->fbOffset); 3193#endif 3194 if (!RADEONMapMem(pScrn)) return FALSE; 3195 3196#ifdef XF86DRI 3197 info->fbX = 0; 3198 info->fbY = 0; 3199#endif 3200 3201 info->PaletteSavedOnVT = FALSE; 3202 3203 info->crtc_on = FALSE; 3204 info->crtc2_on = FALSE; 3205 3206 RADEONSave(pScrn); 3207 3208 /* set initial bios scratch reg state */ 3209 RADEONInitBIOSRegisters(pScrn); 3210 3211 /* blank the outputs/crtcs */ 3212 RADEONBlank(pScrn); 3213 3214 if (info->IsMobility && !IS_AVIVO_VARIANT) { 3215 if (xf86ReturnOptValBool(info->Options, OPTION_DYNAMIC_CLOCKS, FALSE)) { 3216 RADEONSetDynamicClock(pScrn, 1); 3217 } else { 3218 RADEONSetDynamicClock(pScrn, 0); 3219 } 3220 } else if (IS_AVIVO_VARIANT) { 3221 if (xf86ReturnOptValBool(info->Options, OPTION_DYNAMIC_CLOCKS, FALSE)) { 3222 atombios_static_pwrmgt_setup(pScrn, 1); 3223 atombios_dyn_clk_setup(pScrn, 1); 3224 } 3225 } 3226 3227 if (IS_R300_VARIANT || IS_RV100_VARIANT) 3228 RADEONForceSomeClocks(pScrn); 3229 3230 if (info->allowColorTiling && (pScrn->virtualX > info->MaxSurfaceWidth)) { 3231 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 3232 "Color tiling not supported with virtual x resolutions larger than %d, disabling\n", 3233 info->MaxSurfaceWidth); 3234 info->allowColorTiling = FALSE; 3235 } 3236 if (info->allowColorTiling) { 3237 info->tilingEnabled = (pScrn->currentMode->Flags & (V_DBLSCAN | V_INTERLACE)) ? FALSE : TRUE; 3238 } 3239 3240 /* Visual setup */ 3241 miClearVisualTypes(); 3242 if (!miSetVisualTypes(pScrn->depth, 3243 miGetDefaultVisualMask(pScrn->depth), 3244 pScrn->rgbBits, 3245 pScrn->defaultVisual)) return FALSE; 3246 miSetPixmapDepths (); 3247 3248#ifdef XF86DRI 3249 if (info->directRenderingEnabled) { 3250 MessageType from; 3251 3252 info->depthBits = pScrn->depth; 3253 3254 from = xf86GetOptValInteger(info->Options, OPTION_DEPTH_BITS, 3255 &info->depthBits) 3256 ? X_CONFIG : X_DEFAULT; 3257 3258 if (info->depthBits != 16 && info->depthBits != 24) { 3259 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3260 "Value for Option \"DepthBits\" must be 16 or 24\n"); 3261 info->depthBits = pScrn->depth; 3262 from = X_DEFAULT; 3263 } 3264 3265 xf86DrvMsg(pScrn->scrnIndex, from, 3266 "Using %d bit depth buffer\n", info->depthBits); 3267 } 3268 3269 3270 hasDRI = info->directRenderingEnabled; 3271#endif /* XF86DRI */ 3272 3273 /* Initialize the memory map, this basically calculates the values 3274 * we'll use later on for MC_FB_LOCATION & MC_AGP_LOCATION 3275 */ 3276 RADEONInitMemoryMap(pScrn); 3277 3278 /* empty the surfaces */ 3279 { 3280 unsigned char *RADEONMMIO = info->MMIO; 3281 unsigned int j; 3282 for (j = 0; j < 8; j++) { 3283 OUTREG(RADEON_SURFACE0_INFO + 16 * j, 0); 3284 OUTREG(RADEON_SURFACE0_LOWER_BOUND + 16 * j, 0); 3285 OUTREG(RADEON_SURFACE0_UPPER_BOUND + 16 * j, 0); 3286 } 3287 } 3288 3289#ifdef XF86DRI 3290 /* Depth moves are disabled by default since they are extremely slow */ 3291 info->depthMoves = xf86ReturnOptValBool(info->Options, 3292 OPTION_DEPTH_MOVE, FALSE); 3293 if (info->depthMoves && info->allowColorTiling) { 3294 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Enabling depth moves\n"); 3295 } else if (info->depthMoves) { 3296 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 3297 "Depth moves don't work without color tiling, disabled\n"); 3298 info->depthMoves = FALSE; 3299 } else { 3300 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 3301 "Depth moves disabled by default\n"); 3302 } 3303#endif 3304 3305 /* Initial setup of surfaces */ 3306 if (info->ChipFamily < CHIP_FAMILY_R600) { 3307 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3308 "Setting up initial surfaces\n"); 3309 RADEONChangeSurfaces(pScrn); 3310 } 3311 3312 /* Memory manager setup */ 3313 3314 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3315 "Setting up accel memmap\n"); 3316 3317#ifdef USE_EXA 3318 if (info->useEXA) { 3319#ifdef XF86DRI 3320 MessageType from = X_DEFAULT; 3321 3322 if (hasDRI) { 3323 info->accelDFS = info->cardType != CARD_AGP; 3324 3325 if (xf86GetOptValInteger(info->Options, OPTION_ACCEL_DFS, 3326 &info->accelDFS)) { 3327 from = X_CONFIG; 3328 } 3329 3330 /* Reserve approx. half of offscreen memory for local textures by 3331 * default, can be overridden with Option "FBTexPercent". 3332 * Round down to a whole number of texture regions. 3333 */ 3334 info->textureSize = 50; 3335 3336 if (xf86GetOptValInteger(info->Options, OPTION_FBTEX_PERCENT, 3337 &(info->textureSize))) { 3338 if (info->textureSize < 0 || info->textureSize > 100) { 3339 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3340 "Illegal texture memory percentage: %dx, setting to default 50%%\n", 3341 info->textureSize); 3342 info->textureSize = 50; 3343 } 3344 } 3345 } 3346 3347 xf86DrvMsg(pScrn->scrnIndex, from, 3348 "%ssing accelerated EXA DownloadFromScreen hook\n", 3349 info->accelDFS ? "U" : "Not u"); 3350#endif /* XF86DRI */ 3351 3352 if (!RADEONSetupMemEXA(pScreen)) 3353 return FALSE; 3354 } 3355#endif 3356 3357#if defined(XF86DRI) && defined(USE_XAA) 3358 if (!info->useEXA && hasDRI) { 3359 info->textureSize = -1; 3360 if (xf86GetOptValInteger(info->Options, OPTION_FBTEX_PERCENT, 3361 &(info->textureSize))) { 3362 if (info->textureSize < 0 || info->textureSize > 100) { 3363 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3364 "Illegal texture memory percentage: %dx, using default behaviour\n", 3365 info->textureSize); 3366 info->textureSize = -1; 3367 } 3368 } 3369 if (!RADEONSetupMemXAA_DRI(scrnIndex, pScreen)) 3370 return FALSE; 3371 pScrn->fbOffset = info->frontOffset; 3372 } 3373#endif 3374 3375#ifdef USE_XAA 3376 if (!info->useEXA && !hasDRI && !RADEONSetupMemXAA(scrnIndex, pScreen)) 3377 return FALSE; 3378#endif 3379 3380 info->dst_pitch_offset = (((pScrn->displayWidth * info->CurrentLayout.pixel_bytes / 64) 3381 << 22) | ((info->fbLocation + pScrn->fbOffset) >> 10)); 3382 3383 /* Setup DRI after visuals have been established, but before fbScreenInit is 3384 * called. fbScreenInit will eventually call the driver's InitGLXVisuals 3385 * call back. */ 3386#ifdef XF86DRI 3387 if (info->directRenderingEnabled) { 3388 /* FIXME: When we move to dynamic allocation of back and depth 3389 * buffers, we will want to revisit the following check for 3 3390 * times the virtual size of the screen below. 3391 */ 3392 int width_bytes = (pScrn->displayWidth * 3393 info->CurrentLayout.pixel_bytes); 3394 int maxy = info->FbMapSize / width_bytes; 3395 3396 if (maxy <= pScrn->virtualY * 3) { 3397 xf86DrvMsg(scrnIndex, X_ERROR, 3398 "Static buffer allocation failed. Disabling DRI.\n"); 3399 xf86DrvMsg(scrnIndex, X_ERROR, 3400 "At least %d kB of video memory needed at this " 3401 "resolution and depth.\n", 3402 (pScrn->displayWidth * pScrn->virtualY * 3403 info->CurrentLayout.pixel_bytes * 3 + 1023) / 1024); 3404 info->directRenderingEnabled = FALSE; 3405 } else { 3406 info->directRenderingEnabled = RADEONDRIScreenInit(pScreen); 3407 } 3408 } 3409 3410 /* Tell DRI about new memory map */ 3411 if (info->directRenderingEnabled && info->newMemoryMap) { 3412 if (RADEONDRISetParam(pScrn, RADEON_SETPARAM_NEW_MEMMAP, 1) < 0) { 3413 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 3414 "[drm] failed to enable new memory map\n"); 3415 RADEONDRICloseScreen(pScreen); 3416 info->directRenderingEnabled = FALSE; 3417 } 3418 } 3419#endif 3420 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3421 "Initializing fb layer\n"); 3422 3423 if (info->r600_shadow_fb) { 3424 info->fb_shadow = xcalloc(1, 3425 pScrn->displayWidth * pScrn->virtualY * 3426 ((pScrn->bitsPerPixel + 7) >> 3)); 3427 if (info->fb_shadow == NULL) { 3428 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3429 "Failed to allocate shadow framebuffer\n"); 3430 info->r600_shadow_fb = FALSE; 3431 } else { 3432 if (!fbScreenInit(pScreen, info->fb_shadow, 3433 pScrn->virtualX, pScrn->virtualY, 3434 pScrn->xDpi, pScrn->yDpi, pScrn->displayWidth, 3435 pScrn->bitsPerPixel)) 3436 return FALSE; 3437 } 3438 } 3439 3440 if (info->r600_shadow_fb == FALSE) { 3441 /* Init fb layer */ 3442 if (!fbScreenInit(pScreen, info->FB, 3443 pScrn->virtualX, pScrn->virtualY, 3444 pScrn->xDpi, pScrn->yDpi, pScrn->displayWidth, 3445 pScrn->bitsPerPixel)) 3446 return FALSE; 3447 } 3448 3449 xf86SetBlackWhitePixels(pScreen); 3450 3451 if (pScrn->bitsPerPixel > 8) { 3452 VisualPtr visual; 3453 3454 visual = pScreen->visuals + pScreen->numVisuals; 3455 while (--visual >= pScreen->visuals) { 3456 if ((visual->class | DynamicClass) == DirectColor) { 3457 visual->offsetRed = pScrn->offset.red; 3458 visual->offsetGreen = pScrn->offset.green; 3459 visual->offsetBlue = pScrn->offset.blue; 3460 visual->redMask = pScrn->mask.red; 3461 visual->greenMask = pScrn->mask.green; 3462 visual->blueMask = pScrn->mask.blue; 3463 } 3464 } 3465 } 3466 3467 /* Must be after RGB order fixed */ 3468 fbPictureInit (pScreen, 0, 0); 3469 3470#ifdef RENDER 3471 if ((s = xf86GetOptValString(info->Options, OPTION_SUBPIXEL_ORDER))) { 3472 if (strcmp(s, "RGB") == 0) subPixelOrder = SubPixelHorizontalRGB; 3473 else if (strcmp(s, "BGR") == 0) subPixelOrder = SubPixelHorizontalBGR; 3474 else if (strcmp(s, "NONE") == 0) subPixelOrder = SubPixelNone; 3475 PictureSetSubpixelOrder (pScreen, subPixelOrder); 3476 } 3477#endif 3478 3479 pScrn->vtSema = TRUE; 3480 3481 /* xf86CrtcRotate() accesses pScrn->pScreen */ 3482 pScrn->pScreen = pScreen; 3483 3484 if (!xf86SetDesiredModes (pScrn)) 3485 return FALSE; 3486 3487 RADEONSaveScreen(pScreen, SCREEN_SAVER_ON); 3488 3489 /* Backing store setup */ 3490 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3491 "Initializing backing store\n"); 3492 miInitializeBackingStore(pScreen); 3493 xf86SetBackingStore(pScreen); 3494 3495 /* DRI finalisation */ 3496#ifdef XF86DRI 3497 if (info->directRenderingEnabled && info->cardType==CARD_PCIE && 3498 info->pKernelDRMVersion->version_minor >= 19) 3499 { 3500 if (RADEONDRISetParam(pScrn, RADEON_SETPARAM_PCIGART_LOCATION, info->pciGartOffset) < 0) 3501 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3502 "[drm] failed set pci gart location\n"); 3503 3504 if (info->pKernelDRMVersion->version_minor >= 26) { 3505 if (RADEONDRISetParam(pScrn, RADEON_SETPARAM_PCIGART_TABLE_SIZE, info->pciGartSize) < 0) 3506 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3507 "[drm] failed set pci gart table size\n"); 3508 } 3509 } 3510 if (info->directRenderingEnabled) { 3511 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3512 "DRI Finishing init !\n"); 3513 info->directRenderingEnabled = RADEONDRIFinishScreenInit(pScreen); 3514 } 3515 if (info->directRenderingEnabled) { 3516 /* DRI final init might have changed the memory map, we need to adjust 3517 * our local image to make sure we restore them properly on mode 3518 * changes or VT switches 3519 */ 3520 RADEONAdjustMemMapRegisters(pScrn, info->ModeReg); 3521 3522 if ((info->DispPriority == 1) && (info->cardType==CARD_AGP)) { 3523 /* we need to re-calculate bandwidth because of AGPMode difference. */ 3524 RADEONInitDispBandwidth(pScrn); 3525 } 3526 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Direct rendering enabled\n"); 3527 3528 /* we might already be in tiled mode, tell drm about it */ 3529 if (info->directRenderingEnabled && info->tilingEnabled) { 3530 if (RADEONDRISetParam(pScrn, RADEON_SETPARAM_SWITCH_TILING, (info->tilingEnabled ? 1 : 0)) < 0) 3531 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3532 "[drm] failed changing tiling status\n"); 3533 } 3534 } else { 3535 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 3536 "Direct rendering disabled\n"); 3537 } 3538#endif 3539 3540 /* Make sure surfaces are allright since DRI setup may have changed them */ 3541 if (info->ChipFamily < CHIP_FAMILY_R600) { 3542 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3543 "Setting up final surfaces\n"); 3544 3545 RADEONChangeSurfaces(pScrn); 3546 } 3547 3548 3549 /* Enable aceleration */ 3550 if (!xf86ReturnOptValBool(info->Options, OPTION_NOACCEL, FALSE)) { 3551 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3552 "Initializing Acceleration\n"); 3553 if (RADEONAccelInit(pScreen)) { 3554 xf86DrvMsg(scrnIndex, X_INFO, "Acceleration enabled\n"); 3555 info->accelOn = TRUE; 3556 } else { 3557 xf86DrvMsg(scrnIndex, X_ERROR, 3558 "Acceleration initialization failed\n"); 3559 xf86DrvMsg(scrnIndex, X_INFO, "Acceleration disabled\n"); 3560 info->accelOn = FALSE; 3561 } 3562 } else { 3563 xf86DrvMsg(scrnIndex, X_INFO, "Acceleration disabled\n"); 3564 info->accelOn = FALSE; 3565 } 3566 3567 /* Init DPMS */ 3568 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3569 "Initializing DPMS\n"); 3570 xf86DPMSInit(pScreen, xf86DPMSSet, 0); 3571 3572 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3573 "Initializing Cursor\n"); 3574 3575 /* Set Silken Mouse */ 3576 xf86SetSilkenMouse(pScreen); 3577 3578 /* Cursor setup */ 3579 miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); 3580 3581 /* Hardware cursor setup */ 3582 if (!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE)) { 3583 if (RADEONCursorInit(pScreen)) { 3584#ifdef USE_XAA 3585 if (!info->useEXA) { 3586 int width, height; 3587 3588 if (xf86QueryLargestOffscreenArea(pScreen, &width, &height, 3589 0, 0, 0)) { 3590 xf86DrvMsg(scrnIndex, X_INFO, 3591 "Largest offscreen area available: %d x %d\n", 3592 width, height); 3593 } 3594 } 3595#endif /* USE_XAA */ 3596 } else { 3597 xf86DrvMsg(scrnIndex, X_ERROR, 3598 "Hardware cursor initialization failed\n"); 3599 xf86DrvMsg(scrnIndex, X_INFO, "Using software cursor\n"); 3600 } 3601 } else { 3602 xf86DrvMsg(scrnIndex, X_INFO, "Using software cursor\n"); 3603 } 3604 3605 /* DGA setup */ 3606 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3607 "Initializing DGA\n"); 3608 RADEONDGAInit(pScreen); 3609 3610 /* Init Xv */ 3611 if (info->ChipFamily < CHIP_FAMILY_R600) { 3612 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3613 "Initializing Xv\n"); 3614 RADEONInitVideo(pScreen); 3615 } 3616 3617 if (info->r600_shadow_fb == TRUE) { 3618 if (!shadowSetup(pScreen)) { 3619 return FALSE; 3620 } 3621 } 3622 3623 /* Provide SaveScreen & wrap BlockHandler and CloseScreen */ 3624 /* Wrap CloseScreen */ 3625 info->CloseScreen = pScreen->CloseScreen; 3626 pScreen->CloseScreen = RADEONCloseScreen; 3627 pScreen->SaveScreen = RADEONSaveScreen; 3628 info->BlockHandler = pScreen->BlockHandler; 3629 pScreen->BlockHandler = RADEONBlockHandler; 3630 info->CreateScreenResources = pScreen->CreateScreenResources; 3631 pScreen->CreateScreenResources = RADEONCreateScreenResources; 3632 3633 if (!xf86CrtcScreenInit (pScreen)) 3634 return FALSE; 3635 3636 /* Wrap pointer motion to flip touch screen around */ 3637 info->PointerMoved = pScrn->PointerMoved; 3638 pScrn->PointerMoved = RADEONPointerMoved; 3639 3640 /* Colormap setup */ 3641 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3642 "Initializing color map\n"); 3643 if (!miCreateDefColormap(pScreen)) return FALSE; 3644 if (!xf86HandleColormaps(pScreen, 256, info->dac6bits ? 6 : 8, 3645 RADEONLoadPalette, NULL, 3646 CMAP_PALETTED_TRUECOLOR 3647#if 0 /* This option messes up text mode! (eich@suse.de) */ 3648 | CMAP_LOAD_EVEN_IF_OFFSCREEN 3649#endif 3650 | CMAP_RELOAD_ON_MODE_SWITCH)) return FALSE; 3651 3652 /* Note unused options */ 3653 if (serverGeneration == 1) 3654 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); 3655 3656 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3657 "RADEONScreenInit finished\n"); 3658 3659 return TRUE; 3660} 3661 3662/* Write memory mapping registers */ 3663void RADEONRestoreMemMapRegisters(ScrnInfoPtr pScrn, 3664 RADEONSavePtr restore) 3665{ 3666 RADEONInfoPtr info = RADEONPTR(pScrn); 3667 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 3668 unsigned char *RADEONMMIO = info->MMIO; 3669 int timeout; 3670 uint32_t mc_fb_loc, mc_agp_loc, mc_agp_loc_hi; 3671 3672 radeon_read_mc_fb_agp_location(pScrn, LOC_FB | LOC_AGP, &mc_fb_loc, 3673 &mc_agp_loc, &mc_agp_loc_hi); 3674 3675 if (info->IsSecondary) 3676 return; 3677 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 3678 "RADEONRestoreMemMapRegisters() : \n"); 3679 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 3680 " MC_FB_LOCATION : 0x%08x 0x%08x\n", 3681 (unsigned)restore->mc_fb_location, (unsigned int)mc_fb_loc); 3682 xf86DrvMsg(pScrn->scrnIndex, X_INFO, 3683 " MC_AGP_LOCATION : 0x%08x\n", 3684 (unsigned)restore->mc_agp_location); 3685 3686 if (IS_AVIVO_VARIANT) { 3687 3688 if (mc_fb_loc != restore->mc_fb_location || 3689 mc_agp_loc != restore->mc_agp_location) { 3690 uint32_t tmp; 3691 3692 RADEONWaitForIdleMMIO(pScrn); 3693 3694 OUTREG(AVIVO_D1VGA_CONTROL, INREG(AVIVO_D1VGA_CONTROL) & ~AVIVO_DVGA_CONTROL_MODE_ENABLE); 3695 OUTREG(AVIVO_D2VGA_CONTROL, INREG(AVIVO_D2VGA_CONTROL) & ~AVIVO_DVGA_CONTROL_MODE_ENABLE); 3696 3697 /* Stop display & memory access */ 3698 tmp = INREG(AVIVO_D1CRTC_CONTROL); 3699 OUTREG(AVIVO_D1CRTC_CONTROL, tmp & ~AVIVO_CRTC_EN); 3700 3701 tmp = INREG(AVIVO_D2CRTC_CONTROL); 3702 OUTREG(AVIVO_D2CRTC_CONTROL, tmp & ~AVIVO_CRTC_EN); 3703 3704 tmp = INREG(AVIVO_D2CRTC_CONTROL); 3705 3706 usleep(10000); 3707 timeout = 0; 3708 while (!(avivo_get_mc_idle(pScrn))) { 3709 if (++timeout > 1000000) { 3710 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3711 "Timeout trying to update memory controller settings !\n"); 3712 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3713 "You will probably crash now ... \n"); 3714 /* Nothing we can do except maybe try to kill the server, 3715 * let's wait 2 seconds to leave the above message a chance 3716 * to maybe hit the disk and continue trying to setup despite 3717 * the MC being non-idle 3718 */ 3719 usleep(2000000); 3720 } 3721 usleep(10); 3722 } 3723 3724 radeon_write_mc_fb_agp_location(pScrn, LOC_FB | LOC_AGP, 3725 restore->mc_fb_location, 3726 restore->mc_agp_location, 3727 restore->mc_agp_location_hi); 3728 3729 if (info->ChipFamily < CHIP_FAMILY_R600) { 3730 OUTREG(AVIVO_HDP_FB_LOCATION, restore->mc_fb_location); 3731 } else { 3732 OUTREG(R600_HDP_NONSURFACE_BASE, (restore->mc_fb_location << 16) & 0xff0000); 3733 } 3734 3735 /* Reset the engine and HDP */ 3736 RADEONEngineReset(pScrn); 3737 } 3738 } else { 3739 3740 /* Write memory mapping registers only if their value change 3741 * since we must ensure no access is done while they are 3742 * reprogrammed 3743 */ 3744 if (mc_fb_loc != restore->mc_fb_location || 3745 mc_agp_loc != restore->mc_agp_location) { 3746 uint32_t crtc_ext_cntl, crtc_gen_cntl, crtc2_gen_cntl=0, ov0_scale_cntl; 3747 uint32_t old_mc_status, status_idle; 3748 3749 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3750 " Map Changed ! Applying ...\n"); 3751 3752 /* Make sure engine is idle. We assume the CCE is stopped 3753 * at this point 3754 */ 3755 RADEONWaitForIdleMMIO(pScrn); 3756 3757 if (info->IsIGP) 3758 goto igp_no_mcfb; 3759 3760 /* Capture MC_STATUS in case things go wrong ... */ 3761 old_mc_status = INREG(RADEON_MC_STATUS); 3762 3763 /* Stop display & memory access */ 3764 ov0_scale_cntl = INREG(RADEON_OV0_SCALE_CNTL); 3765 OUTREG(RADEON_OV0_SCALE_CNTL, ov0_scale_cntl & ~RADEON_SCALER_ENABLE); 3766 crtc_ext_cntl = INREG(RADEON_CRTC_EXT_CNTL); 3767 OUTREG(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl | RADEON_CRTC_DISPLAY_DIS); 3768 crtc_gen_cntl = INREG(RADEON_CRTC_GEN_CNTL); 3769 RADEONWaitForVerticalSync(pScrn); 3770 OUTREG(RADEON_CRTC_GEN_CNTL, 3771 (crtc_gen_cntl 3772 & ~(RADEON_CRTC_CUR_EN | RADEON_CRTC_ICON_EN)) 3773 | RADEON_CRTC_DISP_REQ_EN_B | RADEON_CRTC_EXT_DISP_EN); 3774 3775 if (pRADEONEnt->HasCRTC2) { 3776 crtc2_gen_cntl = INREG(RADEON_CRTC2_GEN_CNTL); 3777 RADEONWaitForVerticalSync2(pScrn); 3778 OUTREG(RADEON_CRTC2_GEN_CNTL, 3779 (crtc2_gen_cntl 3780 & ~(RADEON_CRTC2_CUR_EN | RADEON_CRTC2_ICON_EN)) 3781 | RADEON_CRTC2_DISP_REQ_EN_B); 3782 } 3783 3784 /* Make sure the chip settles down (paranoid !) */ 3785 usleep(100000); 3786 3787 /* Wait for MC idle */ 3788 if (IS_R300_VARIANT) 3789 status_idle = R300_MC_IDLE; 3790 else 3791 status_idle = RADEON_MC_IDLE; 3792 3793 timeout = 0; 3794 while (!(INREG(RADEON_MC_STATUS) & status_idle)) { 3795 if (++timeout > 1000000) { 3796 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3797 "Timeout trying to update memory controller settings !\n"); 3798 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3799 "MC_STATUS = 0x%08x (on entry = 0x%08x)\n", 3800 (unsigned int)INREG(RADEON_MC_STATUS), (unsigned int)old_mc_status); 3801 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3802 "You will probably crash now ... \n"); 3803 /* Nothing we can do except maybe try to kill the server, 3804 * let's wait 2 seconds to leave the above message a chance 3805 * to maybe hit the disk and continue trying to setup despite 3806 * the MC being non-idle 3807 */ 3808 usleep(2000000); 3809 } 3810 usleep(10); 3811 } 3812 3813 /* Update maps, first clearing out AGP to make sure we don't get 3814 * a temporary overlap 3815 */ 3816 OUTREG(RADEON_MC_AGP_LOCATION, 0xfffffffc); 3817 OUTREG(RADEON_MC_FB_LOCATION, restore->mc_fb_location); 3818 radeon_write_mc_fb_agp_location(pScrn, LOC_FB | LOC_AGP, restore->mc_fb_location, 3819 0xfffffffc, 0); 3820 igp_no_mcfb: 3821 radeon_write_mc_fb_agp_location(pScrn, LOC_AGP, 0, 3822 restore->mc_agp_location, 0); 3823 /* Make sure map fully reached the chip */ 3824 (void)INREG(RADEON_MC_FB_LOCATION); 3825 3826 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3827 " Map applied, resetting engine ...\n"); 3828 3829 /* Reset the engine and HDP */ 3830 RADEONEngineReset(pScrn); 3831 3832 /* Make sure we have sane offsets before re-enabling the CRTCs, disable 3833 * stereo, clear offsets, and wait for offsets to catch up with hw 3834 */ 3835 3836 OUTREG(RADEON_CRTC_OFFSET_CNTL, RADEON_CRTC_OFFSET_FLIP_CNTL); 3837 OUTREG(RADEON_CRTC_OFFSET, 0); 3838 OUTREG(RADEON_CUR_OFFSET, 0); 3839 timeout = 0; 3840 while(INREG(RADEON_CRTC_OFFSET) & RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET) { 3841 if (timeout++ > 1000000) { 3842 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3843 "Timeout waiting for CRTC offset to update !\n"); 3844 break; 3845 } 3846 usleep(1000); 3847 } 3848 if (pRADEONEnt->HasCRTC2) { 3849 OUTREG(RADEON_CRTC2_OFFSET_CNTL, RADEON_CRTC2_OFFSET_FLIP_CNTL); 3850 OUTREG(RADEON_CRTC2_OFFSET, 0); 3851 OUTREG(RADEON_CUR2_OFFSET, 0); 3852 timeout = 0; 3853 while(INREG(RADEON_CRTC2_OFFSET) & RADEON_CRTC2_OFFSET__GUI_TRIG_OFFSET) { 3854 if (timeout++ > 1000000) { 3855 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3856 "Timeout waiting for CRTC2 offset to update !\n"); 3857 break; 3858 } 3859 usleep(1000); 3860 } 3861 } 3862 } 3863 3864 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3865 "Updating display base addresses...\n"); 3866 3867 OUTREG(RADEON_DISPLAY_BASE_ADDR, restore->display_base_addr); 3868 if (pRADEONEnt->HasCRTC2) 3869 OUTREG(RADEON_DISPLAY2_BASE_ADDR, restore->display2_base_addr); 3870 OUTREG(RADEON_OV0_BASE_ADDR, restore->ov0_base_addr); 3871 (void)INREG(RADEON_OV0_BASE_ADDR); 3872 3873 /* More paranoia delays, wait 100ms */ 3874 usleep(100000); 3875 3876 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 3877 "Memory map updated.\n"); 3878 } 3879} 3880 3881#ifdef XF86DRI 3882static void RADEONAdjustMemMapRegisters(ScrnInfoPtr pScrn, RADEONSavePtr save) 3883{ 3884 RADEONInfoPtr info = RADEONPTR(pScrn); 3885 uint32_t fb, agp, agp_hi; 3886 int changed = 0; 3887 3888 if (info->IsSecondary) 3889 return; 3890 3891 radeon_read_mc_fb_agp_location(pScrn, LOC_FB | LOC_AGP, &fb, &agp, &agp_hi); 3892 3893 if (fb != save->mc_fb_location || agp != save->mc_agp_location || 3894 agp_hi != save->mc_agp_location_hi) 3895 changed = 1; 3896 3897 if (changed) { 3898 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 3899 "DRI init changed memory map, adjusting ...\n"); 3900 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 3901 " MC_FB_LOCATION was: 0x%08lx is: 0x%08lx\n", 3902 (long unsigned int)info->mc_fb_location, (long unsigned int)fb); 3903 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 3904 " MC_AGP_LOCATION was: 0x%08lx is: 0x%08lx\n", 3905 (long unsigned int)info->mc_agp_location, (long unsigned int)agp); 3906 info->mc_fb_location = fb; 3907 info->mc_agp_location = agp; 3908 if (info->ChipFamily >= CHIP_FAMILY_R600) 3909 info->fbLocation = (info->mc_fb_location & 0xffff) << 24; 3910 else 3911 info->fbLocation = (info->mc_fb_location & 0xffff) << 16; 3912 3913 info->dst_pitch_offset = 3914 (((pScrn->displayWidth * info->CurrentLayout.pixel_bytes / 64) 3915 << 22) | ((info->fbLocation + pScrn->fbOffset) >> 10)); 3916 RADEONInitMemMapRegisters(pScrn, save, info); 3917 RADEONRestoreMemMapRegisters(pScrn, save); 3918 } 3919 3920#ifdef USE_EXA 3921 if (info->accelDFS) 3922 { 3923 drmRadeonGetParam gp; 3924 int gart_base; 3925 3926 memset(&gp, 0, sizeof(gp)); 3927 gp.param = RADEON_PARAM_GART_BASE; 3928 gp.value = &gart_base; 3929 3930 if (drmCommandWriteRead(info->drmFD, DRM_RADEON_GETPARAM, &gp, 3931 sizeof(gp)) < 0) { 3932 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 3933 "Failed to determine GART area MC location, not using " 3934 "accelerated DownloadFromScreen hook!\n"); 3935 info->accelDFS = FALSE; 3936 } else { 3937 info->gartLocation = gart_base; 3938 } 3939 } 3940#endif /* USE_EXA */ 3941} 3942#endif 3943 3944/* restore original surface info (for fb console). */ 3945static void RADEONRestoreSurfaces(ScrnInfoPtr pScrn, RADEONSavePtr restore) 3946{ 3947 RADEONInfoPtr info = RADEONPTR(pScrn); 3948 unsigned char *RADEONMMIO = info->MMIO; 3949 unsigned int surfnr; 3950 3951 for ( surfnr = 0; surfnr < 8; surfnr++ ) { 3952 OUTREG(RADEON_SURFACE0_INFO + 16 * surfnr, restore->surfaces[surfnr][0]); 3953 OUTREG(RADEON_SURFACE0_LOWER_BOUND + 16 * surfnr, restore->surfaces[surfnr][1]); 3954 OUTREG(RADEON_SURFACE0_UPPER_BOUND + 16 * surfnr, restore->surfaces[surfnr][2]); 3955 } 3956} 3957 3958/* save original surface info (for fb console). */ 3959static void RADEONSaveSurfaces(ScrnInfoPtr pScrn, RADEONSavePtr save) 3960{ 3961 RADEONInfoPtr info = RADEONPTR(pScrn); 3962 unsigned char *RADEONMMIO = info->MMIO; 3963 unsigned int surfnr; 3964 3965 for ( surfnr = 0; surfnr < 8; surfnr++ ) { 3966 save->surfaces[surfnr][0] = INREG(RADEON_SURFACE0_INFO + 16 * surfnr); 3967 save->surfaces[surfnr][1] = INREG(RADEON_SURFACE0_LOWER_BOUND + 16 * surfnr); 3968 save->surfaces[surfnr][2] = INREG(RADEON_SURFACE0_UPPER_BOUND + 16 * surfnr); 3969 } 3970} 3971 3972void RADEONChangeSurfaces(ScrnInfoPtr pScrn) 3973{ 3974 /* the idea here is to only set up front buffer as tiled, and back/depth buffer when needed. 3975 Everything else is left as untiled. This means we need to use eplicit src/dst pitch control 3976 when blitting, based on the src/target address, and can no longer use a default offset. 3977 But OTOH we don't need to dynamically change surfaces (for xv for instance), and some 3978 ugly offset / fb reservation (cursor) is gone. And as a bonus, everything actually works... 3979 For simplicity, just always update everything (just let the ioctl fail - could do better). 3980 All surface addresses are relative to RADEON_MC_FB_LOCATION */ 3981 3982 RADEONInfoPtr info = RADEONPTR(pScrn); 3983 int cpp = info->CurrentLayout.pixel_bytes; 3984 /* depth/front/back pitch must be identical (and the same as displayWidth) */ 3985 int width_bytes = pScrn->displayWidth * cpp; 3986 int bufferSize = ((((pScrn->virtualY + 15) & ~15) * width_bytes 3987 + RADEON_BUFFER_ALIGN) & ~RADEON_BUFFER_ALIGN); 3988 unsigned int color_pattern, swap_pattern; 3989 3990 if (!info->allowColorTiling) 3991 return; 3992 3993 swap_pattern = 0; 3994#if X_BYTE_ORDER == X_BIG_ENDIAN 3995 switch (pScrn->bitsPerPixel) { 3996 case 16: 3997 swap_pattern = RADEON_SURF_AP0_SWP_16BPP | RADEON_SURF_AP1_SWP_16BPP; 3998 break; 3999 4000 case 32: 4001 swap_pattern = RADEON_SURF_AP0_SWP_32BPP | RADEON_SURF_AP1_SWP_32BPP; 4002 break; 4003 } 4004#endif 4005 if (info->ChipFamily < CHIP_FAMILY_R200) { 4006 color_pattern = RADEON_SURF_TILE_COLOR_MACRO; 4007 } else if (IS_R300_VARIANT || IS_AVIVO_VARIANT) { 4008 color_pattern = R300_SURF_TILE_COLOR_MACRO; 4009 } else { 4010 color_pattern = R200_SURF_TILE_COLOR_MACRO; 4011 } 4012#ifdef XF86DRI 4013 if (info->directRenderingInited) { 4014 drmRadeonSurfaceFree drmsurffree; 4015 drmRadeonSurfaceAlloc drmsurfalloc; 4016 int retvalue; 4017 int depthCpp = (info->depthBits - 8) / 4; 4018 int depth_width_bytes = pScrn->displayWidth * depthCpp; 4019 int depthBufferSize = ((((pScrn->virtualY + 15) & ~15) * depth_width_bytes 4020 + RADEON_BUFFER_ALIGN) & ~RADEON_BUFFER_ALIGN); 4021 unsigned int depth_pattern; 4022 4023 drmsurffree.address = info->frontOffset; 4024 retvalue = drmCommandWrite(info->drmFD, DRM_RADEON_SURF_FREE, 4025 &drmsurffree, sizeof(drmsurffree)); 4026 4027 if (!((info->ChipFamily == CHIP_FAMILY_RV100) || 4028 (info->ChipFamily == CHIP_FAMILY_RS100) || 4029 (info->ChipFamily == CHIP_FAMILY_RS200))) { 4030 drmsurffree.address = info->depthOffset; 4031 retvalue = drmCommandWrite(info->drmFD, DRM_RADEON_SURF_FREE, 4032 &drmsurffree, sizeof(drmsurffree)); 4033 } 4034 4035 if (!info->noBackBuffer) { 4036 drmsurffree.address = info->backOffset; 4037 retvalue = drmCommandWrite(info->drmFD, DRM_RADEON_SURF_FREE, 4038 &drmsurffree, sizeof(drmsurffree)); 4039 } 4040 4041 drmsurfalloc.size = bufferSize; 4042 drmsurfalloc.address = info->frontOffset; 4043 drmsurfalloc.flags = swap_pattern; 4044 4045 if (info->tilingEnabled) { 4046 if (IS_R300_VARIANT || IS_AVIVO_VARIANT) 4047 drmsurfalloc.flags |= (width_bytes / 8) | color_pattern; 4048 else 4049 drmsurfalloc.flags |= (width_bytes / 16) | color_pattern; 4050 } 4051 retvalue = drmCommandWrite(info->drmFD, DRM_RADEON_SURF_ALLOC, 4052 &drmsurfalloc, sizeof(drmsurfalloc)); 4053 if (retvalue < 0) 4054 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 4055 "drm: could not allocate surface for front buffer!\n"); 4056 4057 if ((info->have3DWindows) && (!info->noBackBuffer)) { 4058 drmsurfalloc.address = info->backOffset; 4059 retvalue = drmCommandWrite(info->drmFD, DRM_RADEON_SURF_ALLOC, 4060 &drmsurfalloc, sizeof(drmsurfalloc)); 4061 if (retvalue < 0) 4062 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 4063 "drm: could not allocate surface for back buffer!\n"); 4064 } 4065 4066 if (info->ChipFamily < CHIP_FAMILY_R200) { 4067 if (depthCpp == 2) 4068 depth_pattern = RADEON_SURF_TILE_DEPTH_16BPP; 4069 else 4070 depth_pattern = RADEON_SURF_TILE_DEPTH_32BPP; 4071 } else if (IS_R300_VARIANT || IS_AVIVO_VARIANT) { 4072 if (depthCpp == 2) 4073 depth_pattern = R300_SURF_TILE_COLOR_MACRO; 4074 else 4075 depth_pattern = R300_SURF_TILE_COLOR_MACRO | R300_SURF_TILE_DEPTH_32BPP; 4076 } else { 4077 if (depthCpp == 2) 4078 depth_pattern = R200_SURF_TILE_DEPTH_16BPP; 4079 else 4080 depth_pattern = R200_SURF_TILE_DEPTH_32BPP; 4081 } 4082 4083 /* rv100 and probably the derivative igps don't have depth tiling on all the time? */ 4084 if (info->have3DWindows && 4085 (!((info->ChipFamily == CHIP_FAMILY_RV100) || 4086 (info->ChipFamily == CHIP_FAMILY_RS100) || 4087 (info->ChipFamily == CHIP_FAMILY_RS200)))) { 4088 drmRadeonSurfaceAlloc drmsurfalloc; 4089 drmsurfalloc.size = depthBufferSize; 4090 drmsurfalloc.address = info->depthOffset; 4091 if (IS_R300_VARIANT || IS_AVIVO_VARIANT) 4092 drmsurfalloc.flags = swap_pattern | (depth_width_bytes / 8) | depth_pattern; 4093 else 4094 drmsurfalloc.flags = swap_pattern | (depth_width_bytes / 16) | depth_pattern; 4095 retvalue = drmCommandWrite(info->drmFD, DRM_RADEON_SURF_ALLOC, 4096 &drmsurfalloc, sizeof(drmsurfalloc)); 4097 if (retvalue < 0) 4098 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 4099 "drm: could not allocate surface for depth buffer!\n"); 4100 } 4101 } 4102 else 4103#endif 4104 { 4105 unsigned int surf_info = swap_pattern; 4106 unsigned char *RADEONMMIO = info->MMIO; 4107 /* we don't need anything like WaitForFifo, no? */ 4108 if (info->tilingEnabled) { 4109 if (IS_R300_VARIANT || IS_AVIVO_VARIANT) 4110 surf_info |= (width_bytes / 8) | color_pattern; 4111 else 4112 surf_info |= (width_bytes / 16) | color_pattern; 4113 } 4114 OUTREG(RADEON_SURFACE0_INFO, surf_info); 4115 OUTREG(RADEON_SURFACE0_LOWER_BOUND, 0); 4116 OUTREG(RADEON_SURFACE0_UPPER_BOUND, bufferSize - 1); 4117/* xf86DrvMsg(pScrn->scrnIndex, X_INFO, 4118 "surface0 set to %x, LB 0x%x UB 0x%x\n", 4119 surf_info, 0, bufferSize - 1024);*/ 4120 } 4121 4122 /* Update surface images */ 4123 if (info->ChipFamily < CHIP_FAMILY_R600) 4124 RADEONSaveSurfaces(pScrn, info->ModeReg); 4125} 4126 4127/* Read memory map */ 4128static void RADEONSaveMemMapRegisters(ScrnInfoPtr pScrn, RADEONSavePtr save) 4129{ 4130 RADEONInfoPtr info = RADEONPTR(pScrn); 4131 unsigned char *RADEONMMIO = info->MMIO; 4132 4133 radeon_read_mc_fb_agp_location(pScrn, LOC_FB | LOC_AGP, &save->mc_fb_location, 4134 &save->mc_agp_location, &save->mc_agp_location_hi); 4135 4136 if (!IS_AVIVO_VARIANT) { 4137 save->display_base_addr = INREG(RADEON_DISPLAY_BASE_ADDR); 4138 save->display2_base_addr = INREG(RADEON_DISPLAY2_BASE_ADDR); 4139 save->ov0_base_addr = INREG(RADEON_OV0_BASE_ADDR); 4140 } 4141} 4142 4143 4144#if 0 4145/* Read palette data */ 4146static void RADEONSavePalette(ScrnInfoPtr pScrn, RADEONSavePtr save) 4147{ 4148 RADEONInfoPtr info = RADEONPTR(pScrn); 4149 unsigned char *RADEONMMIO = info->MMIO; 4150 int i; 4151 4152#ifdef ENABLE_FLAT_PANEL 4153 /* Select palette 0 (main CRTC) if using FP-enabled chip */ 4154 /* if (info->Port1 == MT_DFP) PAL_SELECT(1); */ 4155#endif 4156 PAL_SELECT(1); 4157 INPAL_START(0); 4158 for (i = 0; i < 256; i++) save->palette2[i] = INPAL_NEXT(); 4159 PAL_SELECT(0); 4160 INPAL_START(0); 4161 for (i = 0; i < 256; i++) save->palette[i] = INPAL_NEXT(); 4162 save->palette_valid = TRUE; 4163} 4164#endif 4165 4166static void 4167avivo_save(ScrnInfoPtr pScrn, RADEONSavePtr save) 4168{ 4169 RADEONInfoPtr info = RADEONPTR(pScrn); 4170 unsigned char *RADEONMMIO = info->MMIO; 4171 struct avivo_state *state = &save->avivo; 4172 int i, j; 4173 4174 // state->vga_memory_base = INREG(AVIVO_VGA_MEMORY_BASE); 4175 // state->vga_fb_start = INREG(AVIVO_VGA_FB_START); 4176 state->vga1_cntl = INREG(AVIVO_D1VGA_CONTROL); 4177 state->vga2_cntl = INREG(AVIVO_D2VGA_CONTROL); 4178 4179 state->crtc_master_en = INREG(AVIVO_DC_CRTC_MASTER_EN); 4180 state->crtc_tv_control = INREG(AVIVO_DC_CRTC_TV_CONTROL); 4181 4182 state->pll1.ref_div_src = INREG(AVIVO_EXT1_PPLL_REF_DIV_SRC); 4183 state->pll1.ref_div = INREG(AVIVO_EXT1_PPLL_REF_DIV); 4184 state->pll1.fb_div = INREG(AVIVO_EXT1_PPLL_FB_DIV); 4185 state->pll1.post_div_src = INREG(AVIVO_EXT1_PPLL_POST_DIV_SRC); 4186 state->pll1.post_div = INREG(AVIVO_EXT1_PPLL_POST_DIV); 4187 state->pll1.ext_ppll_cntl = INREG(AVIVO_EXT1_PPLL_CNTL); 4188 state->pll1.pll_cntl = INREG(AVIVO_P1PLL_CNTL); 4189 state->pll1.int_ss_cntl = INREG(AVIVO_P1PLL_INT_SS_CNTL); 4190 4191 state->pll2.ref_div_src = INREG(AVIVO_EXT1_PPLL_REF_DIV_SRC); 4192 state->pll2.ref_div = INREG(AVIVO_EXT2_PPLL_REF_DIV); 4193 state->pll2.fb_div = INREG(AVIVO_EXT2_PPLL_FB_DIV); 4194 state->pll2.post_div_src = INREG(AVIVO_EXT2_PPLL_POST_DIV_SRC); 4195 state->pll2.post_div = INREG(AVIVO_EXT2_PPLL_POST_DIV); 4196 state->pll2.ext_ppll_cntl = INREG(AVIVO_EXT2_PPLL_CNTL); 4197 state->pll2.pll_cntl = INREG(AVIVO_P2PLL_CNTL); 4198 state->pll2.int_ss_cntl = INREG(AVIVO_P2PLL_INT_SS_CNTL); 4199 4200 state->crtc1.pll_source = INREG(AVIVO_PCLK_CRTC1_CNTL); 4201 4202 state->crtc1.h_total = INREG(AVIVO_D1CRTC_H_TOTAL); 4203 state->crtc1.h_blank_start_end = INREG(AVIVO_D1CRTC_H_BLANK_START_END); 4204 state->crtc1.h_sync_a = INREG(AVIVO_D1CRTC_H_SYNC_A); 4205 state->crtc1.h_sync_a_cntl = INREG(AVIVO_D1CRTC_H_SYNC_A_CNTL); 4206 state->crtc1.h_sync_b = INREG(AVIVO_D1CRTC_H_SYNC_B); 4207 state->crtc1.h_sync_b_cntl = INREG(AVIVO_D1CRTC_H_SYNC_B_CNTL); 4208 4209 state->crtc1.v_total = INREG(AVIVO_D1CRTC_V_TOTAL); 4210 state->crtc1.v_blank_start_end = INREG(AVIVO_D1CRTC_V_BLANK_START_END); 4211 state->crtc1.v_sync_a = INREG(AVIVO_D1CRTC_V_SYNC_A); 4212 state->crtc1.v_sync_a_cntl = INREG(AVIVO_D1CRTC_V_SYNC_A_CNTL); 4213 state->crtc1.v_sync_b = INREG(AVIVO_D1CRTC_V_SYNC_B); 4214 state->crtc1.v_sync_b_cntl = INREG(AVIVO_D1CRTC_V_SYNC_B_CNTL); 4215 4216 state->crtc1.control = INREG(AVIVO_D1CRTC_CONTROL); 4217 state->crtc1.blank_control = INREG(AVIVO_D1CRTC_BLANK_CONTROL); 4218 state->crtc1.interlace_control = INREG(AVIVO_D1CRTC_INTERLACE_CONTROL); 4219 state->crtc1.stereo_control = INREG(AVIVO_D1CRTC_STEREO_CONTROL); 4220 4221 state->crtc1.cursor_control = INREG(AVIVO_D1CUR_CONTROL); 4222 4223 state->grph1.enable = INREG(AVIVO_D1GRPH_ENABLE); 4224 state->grph1.control = INREG(AVIVO_D1GRPH_CONTROL); 4225 state->grph1.control = INREG(AVIVO_D1GRPH_CONTROL); 4226 state->grph1.prim_surf_addr = INREG(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS); 4227 state->grph1.sec_surf_addr = INREG(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS); 4228 state->grph1.pitch = INREG(AVIVO_D1GRPH_PITCH); 4229 state->grph1.x_offset = INREG(AVIVO_D1GRPH_SURFACE_OFFSET_X); 4230 state->grph1.y_offset = INREG(AVIVO_D1GRPH_SURFACE_OFFSET_Y); 4231 state->grph1.x_start = INREG(AVIVO_D1GRPH_X_START); 4232 state->grph1.y_start = INREG(AVIVO_D1GRPH_Y_START); 4233 state->grph1.x_end = INREG(AVIVO_D1GRPH_X_END); 4234 state->grph1.y_end = INREG(AVIVO_D1GRPH_Y_END); 4235 4236 state->grph1.viewport_start = INREG(AVIVO_D1MODE_VIEWPORT_START); 4237 state->grph1.viewport_size = INREG(AVIVO_D1MODE_VIEWPORT_SIZE); 4238 4239 state->crtc2.pll_source = INREG(AVIVO_PCLK_CRTC2_CNTL); 4240 4241 state->crtc2.h_total = INREG(AVIVO_D2CRTC_H_TOTAL); 4242 state->crtc2.h_blank_start_end = INREG(AVIVO_D2CRTC_H_BLANK_START_END); 4243 state->crtc2.h_sync_a = INREG(AVIVO_D2CRTC_H_SYNC_A); 4244 state->crtc2.h_sync_a_cntl = INREG(AVIVO_D2CRTC_H_SYNC_A_CNTL); 4245 state->crtc2.h_sync_b = INREG(AVIVO_D2CRTC_H_SYNC_B); 4246 state->crtc2.h_sync_b_cntl = INREG(AVIVO_D2CRTC_H_SYNC_B_CNTL); 4247 4248 state->crtc2.v_total = INREG(AVIVO_D2CRTC_V_TOTAL); 4249 state->crtc2.v_blank_start_end = INREG(AVIVO_D2CRTC_V_BLANK_START_END); 4250 state->crtc2.v_sync_a = INREG(AVIVO_D2CRTC_V_SYNC_A); 4251 state->crtc2.v_sync_a_cntl = INREG(AVIVO_D2CRTC_V_SYNC_A_CNTL); 4252 state->crtc2.v_sync_b = INREG(AVIVO_D2CRTC_V_SYNC_B); 4253 state->crtc2.v_sync_b_cntl = INREG(AVIVO_D2CRTC_V_SYNC_B_CNTL); 4254 4255 state->crtc2.control = INREG(AVIVO_D2CRTC_CONTROL); 4256 state->crtc2.blank_control = INREG(AVIVO_D2CRTC_BLANK_CONTROL); 4257 state->crtc2.interlace_control = INREG(AVIVO_D2CRTC_INTERLACE_CONTROL); 4258 state->crtc2.stereo_control = INREG(AVIVO_D2CRTC_STEREO_CONTROL); 4259 4260 state->crtc2.cursor_control = INREG(AVIVO_D2CUR_CONTROL); 4261 4262 state->grph2.enable = INREG(AVIVO_D2GRPH_ENABLE); 4263 state->grph2.control = INREG(AVIVO_D2GRPH_CONTROL); 4264 state->grph2.control = INREG(AVIVO_D2GRPH_CONTROL); 4265 state->grph2.prim_surf_addr = INREG(AVIVO_D2GRPH_PRIMARY_SURFACE_ADDRESS); 4266 state->grph2.sec_surf_addr = INREG(AVIVO_D2GRPH_SECONDARY_SURFACE_ADDRESS); 4267 state->grph2.pitch = INREG(AVIVO_D2GRPH_PITCH); 4268 state->grph2.x_offset = INREG(AVIVO_D2GRPH_SURFACE_OFFSET_X); 4269 state->grph2.y_offset = INREG(AVIVO_D2GRPH_SURFACE_OFFSET_Y); 4270 state->grph2.x_start = INREG(AVIVO_D2GRPH_X_START); 4271 state->grph2.y_start = INREG(AVIVO_D2GRPH_Y_START); 4272 state->grph2.x_end = INREG(AVIVO_D2GRPH_X_END); 4273 state->grph2.y_end = INREG(AVIVO_D2GRPH_Y_END); 4274 4275 state->grph2.viewport_start = INREG(AVIVO_D2MODE_VIEWPORT_START); 4276 state->grph2.viewport_size = INREG(AVIVO_D2MODE_VIEWPORT_SIZE); 4277 4278 if (IS_DCE3_VARIANT) { 4279 /* save DVOA regs */ 4280 state->dvoa[0] = INREG(0x7080); 4281 state->dvoa[1] = INREG(0x7084); 4282 state->dvoa[2] = INREG(0x708c); 4283 state->dvoa[3] = INREG(0x7090); 4284 state->dvoa[4] = INREG(0x7094); 4285 state->dvoa[5] = INREG(0x70ac); 4286 state->dvoa[6] = INREG(0x70b0); 4287 4288 j = 0; 4289 /* save DAC regs */ 4290 for (i = 0x7000; i <= 0x7040; i += 4) { 4291 state->daca[j] = INREG(i); 4292 state->dacb[j] = INREG(i + 0x100); 4293 j++; 4294 } 4295 for (i = 0x7058; i <= 0x7060; i += 4) { 4296 state->daca[j] = INREG(i); 4297 state->dacb[j] = INREG(i + 0x100); 4298 j++; 4299 } 4300 for (i = 0x7068; i <= 0x706c; i += 4) { 4301 state->daca[j] = INREG(i); 4302 state->dacb[j] = INREG(i + 0x100); 4303 j++; 4304 } 4305 for (i = 0x7ef0; i <= 0x7ef8; i += 4) { 4306 state->daca[j] = INREG(i); 4307 state->dacb[j] = INREG(i + 0x100); 4308 j++; 4309 } 4310 state->daca[j] = INREG(0x7050); 4311 state->dacb[j] = INREG(0x7050 + 0x100); 4312 4313 j = 0; 4314 /* save FMT regs */ 4315 for (i = 0x6700; i <= 0x6744; i += 4) { 4316 state->fmt1[j] = INREG(i); 4317 state->fmt2[j] = INREG(i + 0x800); 4318 j++; 4319 } 4320 4321 j = 0; 4322 /* save DIG regs */ 4323 for (i = 0x75a0; i <= 0x75e0; i += 4) { 4324 state->dig1[j] = INREG(i); 4325 state->dig2[j] = INREG(i + 0x400); 4326 j++; 4327 } 4328 for (i = 0x75e8; i <= 0x75ec; i += 4) { 4329 state->dig1[j] = INREG(i); 4330 state->dig2[j] = INREG(i + 0x400); 4331 j++; 4332 } 4333 4334 j = 0; 4335 /* save HDMI regs */ 4336 for (i = 0x7400; i <= 0x741c; i += 4) { 4337 state->hdmi1[j] = INREG(i); 4338 state->hdmi2[j] = INREG(i + 0x400); 4339 j++; 4340 } 4341 for (i = 0x7430; i <= 0x74ec; i += 4) { 4342 state->hdmi1[j] = INREG(i); 4343 state->hdmi2[j] = INREG(i + 0x400); 4344 j++; 4345 } 4346 state->hdmi1[j] = INREG(0x7428); 4347 state->hdmi2[j] = INREG(0x7828); 4348 4349 j = 0; 4350 /* save AUX regs */ 4351 for (i = 0x7780; i <= 0x77b4; i += 4) { 4352 state->aux_cntl1[j] = INREG(i); 4353 state->aux_cntl2[j] = INREG(i + 0x040); 4354 state->aux_cntl3[j] = INREG(i + 0x400); 4355 state->aux_cntl4[j] = INREG(i + 0x440); 4356 j++; 4357 } 4358 4359 j = 0; 4360 /* save UNIPHY regs */ 4361 for (i = 0x7ec0; i <= 0x7edc; i += 4) { 4362 state->uniphy1[j] = INREG(i); 4363 state->uniphy2[j] = INREG(i + 0x100); 4364 j++; 4365 } 4366 j = 0; 4367 /* save PHY,LINK regs */ 4368 for (i = 0x7f20; i <= 0x7f34; i += 4) { 4369 state->phy[j] = INREG(i); 4370 j++; 4371 } 4372 for (i = 0x7f9c; i <= 0x7fa4; i += 4) { 4373 state->phy[j] = INREG(i); 4374 j++; 4375 } 4376 state->phy[j] = INREG(0x7f40); 4377 4378 j = 0; 4379 /* save LVTMA regs */ 4380 for (i = 0x7f00; i <= 0x7f1c; i += 4) { 4381 state->lvtma[j] = INREG(i); 4382 j++; 4383 } 4384 for (i = 0x7f80; i <= 0x7f98; i += 4) { 4385 state->lvtma[j] = INREG(i); 4386 j++; 4387 } 4388 } else { 4389 j = 0; 4390 /* save DVOA regs */ 4391 for (i = 0x7980; i <= 0x79bc; i += 4) { 4392 state->dvoa[j] = INREG(i); 4393 j++; 4394 } 4395 4396 j = 0; 4397 /* save DAC regs */ 4398 for (i = 0x7800; i <= 0x782c; i += 4) { 4399 state->daca[j] = INREG(i); 4400 state->dacb[j] = INREG(i + 0x200); 4401 j++; 4402 } 4403 for (i = 0x7834; i <= 0x7840; i += 4) { 4404 state->daca[j] = INREG(i); 4405 state->dacb[j] = INREG(i + 0x200); 4406 j++; 4407 } 4408 for (i = 0x7850; i <= 0x7868; i += 4) { 4409 state->daca[j] = INREG(i); 4410 state->dacb[j] = INREG(i + 0x200); 4411 j++; 4412 } 4413 4414 j = 0; 4415 /* save TMDSA regs */ 4416 for (i = 0x7880; i <= 0x78e0; i += 4) { 4417 state->tmdsa[j] = INREG(i); 4418 j++; 4419 } 4420 for (i = 0x7904; i <= 0x7918; i += 4) { 4421 state->tmdsa[j] = INREG(i); 4422 j++; 4423 } 4424 4425 j = 0; 4426 /* save LVTMA regs */ 4427 for (i = 0x7a80; i <= 0x7b18; i += 4) { 4428 state->lvtma[j] = INREG(i); 4429 j++; 4430 } 4431 4432 if ((info->ChipFamily == CHIP_FAMILY_RS600) || 4433 (info->ChipFamily == CHIP_FAMILY_RS690) || 4434 (info->ChipFamily == CHIP_FAMILY_RS740)) { 4435 j = 0; 4436 /* save DDIA regs */ 4437 for (i = 0x7200; i <= 0x7290; i += 4) { 4438 state->ddia[j] = INREG(i); 4439 j++; 4440 } 4441 } 4442 } 4443 4444 /* scalers */ 4445 j = 0; 4446 for (i = 0x6578; i <= 0x65e4; i += 4) { 4447 state->d1scl[j] = INREG(i); 4448 state->d2scl[j] = INREG(i + 0x800); 4449 j++; 4450 } 4451 for (i = 0x6600; i <= 0x662c; i += 4) { 4452 state->d1scl[j] = INREG(i); 4453 state->d2scl[j] = INREG(i + 0x800); 4454 j++; 4455 } 4456 j = 0; 4457 for (i = 0x66e8; i <= 0x66fc; i += 4) { 4458 state->dxscl[j] = INREG(i); 4459 j++; 4460 } 4461 state->dxscl[6] = INREG(0x6e30); 4462 state->dxscl[7] = INREG(0x6e34); 4463 4464 if (state->crtc1.control & AVIVO_CRTC_EN) 4465 info->crtc_on = TRUE; 4466 4467 if (state->crtc2.control & AVIVO_CRTC_EN) 4468 info->crtc2_on = TRUE; 4469 4470} 4471 4472static void 4473avivo_restore(ScrnInfoPtr pScrn, RADEONSavePtr restore) 4474{ 4475 RADEONInfoPtr info = RADEONPTR(pScrn); 4476 unsigned char *RADEONMMIO = info->MMIO; 4477 struct avivo_state *state = &restore->avivo; 4478 int i, j; 4479 4480 // OUTMC(pScrn, AVIVO_MC_MEMORY_MAP, state->mc_memory_map); 4481 // OUTREG(AVIVO_VGA_MEMORY_BASE, state->vga_memory_base); 4482 // OUTREG(AVIVO_VGA_FB_START, state->vga_fb_start); 4483 4484 4485 OUTREG(AVIVO_DC_CRTC_MASTER_EN, state->crtc_master_en); 4486 OUTREG(AVIVO_DC_CRTC_TV_CONTROL, state->crtc_tv_control); 4487 4488 OUTREG(AVIVO_EXT1_PPLL_REF_DIV_SRC, state->pll1.ref_div_src); 4489 OUTREG(AVIVO_EXT1_PPLL_REF_DIV, state->pll1.ref_div); 4490 OUTREG(AVIVO_EXT1_PPLL_FB_DIV, state->pll1.fb_div); 4491 OUTREG(AVIVO_EXT1_PPLL_POST_DIV_SRC, state->pll1.post_div_src); 4492 OUTREG(AVIVO_EXT1_PPLL_POST_DIV, state->pll1.post_div); 4493 OUTREG(AVIVO_EXT1_PPLL_CNTL, state->pll1.ext_ppll_cntl); 4494 OUTREG(AVIVO_P1PLL_CNTL, state->pll1.pll_cntl); 4495 OUTREG(AVIVO_P1PLL_INT_SS_CNTL, state->pll1.int_ss_cntl); 4496 4497 OUTREG(AVIVO_EXT2_PPLL_REF_DIV_SRC, state->pll2.ref_div_src); 4498 OUTREG(AVIVO_EXT2_PPLL_REF_DIV, state->pll2.ref_div); 4499 OUTREG(AVIVO_EXT2_PPLL_FB_DIV, state->pll2.fb_div); 4500 OUTREG(AVIVO_EXT2_PPLL_POST_DIV_SRC, state->pll2.post_div_src); 4501 OUTREG(AVIVO_EXT2_PPLL_POST_DIV, state->pll2.post_div); 4502 OUTREG(AVIVO_EXT2_PPLL_CNTL, state->pll2.ext_ppll_cntl); 4503 OUTREG(AVIVO_P2PLL_CNTL, state->pll2.pll_cntl); 4504 OUTREG(AVIVO_P2PLL_INT_SS_CNTL, state->pll2.int_ss_cntl); 4505 4506 OUTREG(AVIVO_PCLK_CRTC1_CNTL, state->crtc1.pll_source); 4507 4508 OUTREG(AVIVO_D1CRTC_H_TOTAL, state->crtc1.h_total); 4509 OUTREG(AVIVO_D1CRTC_H_BLANK_START_END, state->crtc1.h_blank_start_end); 4510 OUTREG(AVIVO_D1CRTC_H_SYNC_A, state->crtc1.h_sync_a); 4511 OUTREG(AVIVO_D1CRTC_H_SYNC_A_CNTL, state->crtc1.h_sync_a_cntl); 4512 OUTREG(AVIVO_D1CRTC_H_SYNC_B, state->crtc1.h_sync_b); 4513 OUTREG(AVIVO_D1CRTC_H_SYNC_B_CNTL, state->crtc1.h_sync_b_cntl); 4514 4515 OUTREG(AVIVO_D1CRTC_V_TOTAL, state->crtc1.v_total); 4516 OUTREG(AVIVO_D1CRTC_V_BLANK_START_END, state->crtc1.v_blank_start_end); 4517 OUTREG(AVIVO_D1CRTC_V_SYNC_A, state->crtc1.v_sync_a); 4518 OUTREG(AVIVO_D1CRTC_V_SYNC_A_CNTL, state->crtc1.v_sync_a_cntl); 4519 OUTREG(AVIVO_D1CRTC_V_SYNC_B, state->crtc1.v_sync_b); 4520 OUTREG(AVIVO_D1CRTC_V_SYNC_B_CNTL, state->crtc1.v_sync_b_cntl); 4521 4522 OUTREG(AVIVO_D1CRTC_CONTROL, state->crtc1.control); 4523 OUTREG(AVIVO_D1CRTC_BLANK_CONTROL, state->crtc1.blank_control); 4524 OUTREG(AVIVO_D1CRTC_INTERLACE_CONTROL, state->crtc1.interlace_control); 4525 OUTREG(AVIVO_D1CRTC_STEREO_CONTROL, state->crtc1.stereo_control); 4526 4527 OUTREG(AVIVO_D1CUR_CONTROL, state->crtc1.cursor_control); 4528 4529 OUTREG(AVIVO_D1GRPH_ENABLE, state->grph1.enable); 4530 OUTREG(AVIVO_D1GRPH_CONTROL, state->grph1.control); 4531 OUTREG(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS, state->grph1.prim_surf_addr); 4532 OUTREG(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS, state->grph1.sec_surf_addr); 4533 OUTREG(AVIVO_D1GRPH_PITCH, state->grph1.pitch); 4534 OUTREG(AVIVO_D1GRPH_SURFACE_OFFSET_X, state->grph1.x_offset); 4535 OUTREG(AVIVO_D1GRPH_SURFACE_OFFSET_Y, state->grph1.y_offset); 4536 OUTREG(AVIVO_D1GRPH_X_START, state->grph1.x_start); 4537 OUTREG(AVIVO_D1GRPH_Y_START, state->grph1.y_start); 4538 OUTREG(AVIVO_D1GRPH_X_END, state->grph1.x_end); 4539 OUTREG(AVIVO_D1GRPH_Y_END, state->grph1.y_end); 4540 4541 OUTREG(AVIVO_D1MODE_VIEWPORT_START, state->grph1.viewport_start); 4542 OUTREG(AVIVO_D1MODE_VIEWPORT_SIZE, state->grph1.viewport_size); 4543 4544 OUTREG(AVIVO_PCLK_CRTC2_CNTL, state->crtc2.pll_source); 4545 4546 OUTREG(AVIVO_D2CRTC_H_TOTAL, state->crtc2.h_total); 4547 OUTREG(AVIVO_D2CRTC_H_BLANK_START_END, state->crtc2.h_blank_start_end); 4548 OUTREG(AVIVO_D2CRTC_H_SYNC_A, state->crtc2.h_sync_a); 4549 OUTREG(AVIVO_D2CRTC_H_SYNC_A_CNTL, state->crtc2.h_sync_a_cntl); 4550 OUTREG(AVIVO_D2CRTC_H_SYNC_B, state->crtc2.h_sync_b); 4551 OUTREG(AVIVO_D2CRTC_H_SYNC_B_CNTL, state->crtc2.h_sync_b_cntl); 4552 4553 OUTREG(AVIVO_D2CRTC_V_TOTAL, state->crtc2.v_total); 4554 OUTREG(AVIVO_D2CRTC_V_BLANK_START_END, state->crtc2.v_blank_start_end); 4555 OUTREG(AVIVO_D2CRTC_V_SYNC_A, state->crtc2.v_sync_a); 4556 OUTREG(AVIVO_D2CRTC_V_SYNC_A_CNTL, state->crtc2.v_sync_a_cntl); 4557 OUTREG(AVIVO_D2CRTC_V_SYNC_B, state->crtc2.v_sync_b); 4558 OUTREG(AVIVO_D2CRTC_V_SYNC_B_CNTL, state->crtc2.v_sync_b_cntl); 4559 4560 OUTREG(AVIVO_D2CRTC_CONTROL, state->crtc2.control); 4561 OUTREG(AVIVO_D2CRTC_BLANK_CONTROL, state->crtc2.blank_control); 4562 OUTREG(AVIVO_D2CRTC_INTERLACE_CONTROL, state->crtc2.interlace_control); 4563 OUTREG(AVIVO_D2CRTC_STEREO_CONTROL, state->crtc2.stereo_control); 4564 4565 OUTREG(AVIVO_D2CUR_CONTROL, state->crtc2.cursor_control); 4566 4567 OUTREG(AVIVO_D2GRPH_ENABLE, state->grph2.enable); 4568 OUTREG(AVIVO_D2GRPH_CONTROL, state->grph2.control); 4569 OUTREG(AVIVO_D2GRPH_PRIMARY_SURFACE_ADDRESS, state->grph2.prim_surf_addr); 4570 OUTREG(AVIVO_D2GRPH_SECONDARY_SURFACE_ADDRESS, state->grph2.sec_surf_addr); 4571 OUTREG(AVIVO_D2GRPH_PITCH, state->grph2.pitch); 4572 OUTREG(AVIVO_D2GRPH_SURFACE_OFFSET_X, state->grph2.x_offset); 4573 OUTREG(AVIVO_D2GRPH_SURFACE_OFFSET_Y, state->grph2.y_offset); 4574 OUTREG(AVIVO_D2GRPH_X_START, state->grph2.x_start); 4575 OUTREG(AVIVO_D2GRPH_Y_START, state->grph2.y_start); 4576 OUTREG(AVIVO_D2GRPH_X_END, state->grph2.x_end); 4577 OUTREG(AVIVO_D2GRPH_Y_END, state->grph2.y_end); 4578 4579 OUTREG(AVIVO_D2MODE_VIEWPORT_START, state->grph2.viewport_start); 4580 OUTREG(AVIVO_D2MODE_VIEWPORT_SIZE, state->grph2.viewport_size); 4581 4582 4583 if (IS_DCE3_VARIANT) { 4584 /* DVOA regs */ 4585 OUTREG(0x7080, state->dvoa[0]); 4586 OUTREG(0x7084, state->dvoa[1]); 4587 OUTREG(0x708c, state->dvoa[2]); 4588 OUTREG(0x7090, state->dvoa[3]); 4589 OUTREG(0x7094, state->dvoa[4]); 4590 OUTREG(0x70ac, state->dvoa[5]); 4591 OUTREG(0x70b0, state->dvoa[6]); 4592 4593 j = 0; 4594 /* DAC regs */ 4595 for (i = 0x7000; i <= 0x7040; i += 4) { 4596 OUTREG(i, state->daca[j]); 4597 OUTREG((i + 0x100), state->dacb[j]); 4598 j++; 4599 } 4600 for (i = 0x7058; i <= 0x7060; i += 4) { 4601 OUTREG(i, state->daca[j]); 4602 OUTREG((i + 0x100), state->dacb[j]); 4603 j++; 4604 } 4605 for (i = 0x7068; i <= 0x706c; i += 4) { 4606 OUTREG(i, state->daca[j]); 4607 OUTREG((i + 0x100), state->dacb[j]); 4608 j++; 4609 } 4610 for (i = 0x7ef0; i <= 0x7ef8; i += 4) { 4611 OUTREG(i, state->daca[j]); 4612 OUTREG((i + 0x100), state->dacb[j]); 4613 j++; 4614 } 4615 OUTREG(0x7050, state->daca[j]); 4616 OUTREG((0x7050 + 0x100), state->dacb[j]); 4617 4618 j = 0; 4619 /* FMT regs */ 4620 for (i = 0x6700; i <= 0x6744; i += 4) { 4621 OUTREG(i, state->fmt1[j]); 4622 OUTREG((i + 0x800), state->fmt2[j]); 4623 j++; 4624 } 4625 4626 j = 0; 4627 /* DIG regs */ 4628 for (i = 0x75a0; i <= 0x75e0; i += 4) { 4629 OUTREG(i, state->dig1[j]); 4630 OUTREG((i + 0x400), state->dig2[j]); 4631 j++; 4632 } 4633 for (i = 0x75e8; i <= 0x75ec; i += 4) { 4634 OUTREG(i, state->dig1[j]); 4635 OUTREG((i + 0x400), state->dig2[j]); 4636 j++; 4637 } 4638 4639 j = 0; 4640 /* HDMI regs */ 4641 for (i = 0x7400; i <= 0x741c; i += 4) { 4642 OUTREG(i, state->hdmi1[j]); 4643 OUTREG((i + 0x400), state->hdmi2[j]); 4644 j++; 4645 } 4646 for (i = 0x7430; i <= 0x74ec; i += 4) { 4647 OUTREG(i, state->hdmi1[j]); 4648 OUTREG((i + 0x400), state->hdmi2[j]); 4649 j++; 4650 } 4651 OUTREG(0x7428, state->hdmi1[j]); 4652 OUTREG((0x7428 + 0x400), state->hdmi2[j]); 4653 4654 j = 0; 4655 /* save AUX regs */ 4656 for (i = 0x7780; i <= 0x77b4; i += 4) { 4657 OUTREG(i, state->aux_cntl1[j]); 4658 OUTREG((i + 0x040), state->aux_cntl2[j]); 4659 OUTREG((i + 0x400), state->aux_cntl3[j]); 4660 OUTREG((i + 0x440), state->aux_cntl4[j]); 4661 j++; 4662 } 4663 4664 j = 0; 4665 /* save UNIPHY regs */ 4666 for (i = 0x7ec0; i <= 0x7edc; i += 4) { 4667 OUTREG(i, state->uniphy1[j]); 4668 OUTREG((i + 0x100), state->uniphy2[j]); 4669 j++; 4670 } 4671 j = 0; 4672 /* save PHY,LINK regs */ 4673 for (i = 0x7f20; i <= 0x7f34; i += 4) { 4674 OUTREG(i, state->phy[j]); 4675 j++; 4676 } 4677 for (i = 0x7f9c; i <= 0x7fa4; i += 4) { 4678 OUTREG(i, state->phy[j]); 4679 j++; 4680 } 4681 state->phy[j] = INREG(0x7f40); 4682 4683 j = 0; 4684 /* save LVTMA regs */ 4685 for (i = 0x7f00; i <= 0x7f1c; i += 4) { 4686 OUTREG(i, state->lvtma[j]); 4687 j++; 4688 } 4689 for (i = 0x7f80; i <= 0x7f98; i += 4) { 4690 OUTREG(i, state->lvtma[j]); 4691 j++; 4692 } 4693 } else { 4694 j = 0; 4695 /* DVOA regs */ 4696 for (i = 0x7980; i <= 0x79bc; i += 4) { 4697 OUTREG(i, state->dvoa[j]); 4698 j++; 4699 } 4700 4701 j = 0; 4702 /* DAC regs */ 4703 for (i = 0x7800; i <= 0x782c; i += 4) { 4704 OUTREG(i, state->daca[j]); 4705 OUTREG((i + 0x200), state->dacb[j]); 4706 j++; 4707 } 4708 for (i = 0x7834; i <= 0x7840; i += 4) { 4709 OUTREG(i, state->daca[j]); 4710 OUTREG((i + 0x200), state->dacb[j]); 4711 j++; 4712 } 4713 for (i = 0x7850; i <= 0x7868; i += 4) { 4714 OUTREG(i, state->daca[j]); 4715 OUTREG((i + 0x200), state->dacb[j]); 4716 j++; 4717 } 4718 4719 j = 0; 4720 /* TMDSA regs */ 4721 for (i = 0x7880; i <= 0x78e0; i += 4) { 4722 OUTREG(i, state->tmdsa[j]); 4723 j++; 4724 } 4725 for (i = 0x7904; i <= 0x7918; i += 4) { 4726 OUTREG(i, state->tmdsa[j]); 4727 j++; 4728 } 4729 4730 j = 0; 4731 /* LVTMA regs */ 4732 for (i = 0x7a80; i <= 0x7b18; i += 4) { 4733 OUTREG(i, state->lvtma[j]); 4734 j++; 4735 } 4736 4737 /* DDIA regs */ 4738 if ((info->ChipFamily == CHIP_FAMILY_RS600) || 4739 (info->ChipFamily == CHIP_FAMILY_RS690) || 4740 (info->ChipFamily == CHIP_FAMILY_RS740)) { 4741 j = 0; 4742 for (i = 0x7200; i <= 0x7290; i += 4) { 4743 OUTREG(i, state->ddia[j]); 4744 j++; 4745 } 4746 } 4747 } 4748 4749 /* scalers */ 4750 j = 0; 4751 for (i = 0x6578; i <= 0x65e4; i += 4) { 4752 OUTREG(i, state->d1scl[j]); 4753 OUTREG((i + 0x800), state->d2scl[j]); 4754 j++; 4755 } 4756 for (i = 0x6600; i <= 0x662c; i += 4) { 4757 OUTREG(i, state->d1scl[j]); 4758 OUTREG((i + 0x800), state->d2scl[j]); 4759 j++; 4760 } 4761 j = 0; 4762 for (i = 0x66e8; i <= 0x66fc; i += 4) { 4763 OUTREG(i, state->dxscl[j]); 4764 j++; 4765 } 4766 OUTREG(0x6e30, state->dxscl[6]); 4767 OUTREG(0x6e34, state->dxscl[7]); 4768 4769 OUTREG(AVIVO_D1VGA_CONTROL, state->vga1_cntl); 4770 OUTREG(AVIVO_D2VGA_CONTROL, state->vga2_cntl); 4771} 4772 4773static void avivo_restore_vga_regs(ScrnInfoPtr pScrn, RADEONSavePtr restore) 4774{ 4775 RADEONInfoPtr info = RADEONPTR(pScrn); 4776 unsigned char *RADEONMMIO = info->MMIO; 4777 struct avivo_state *state = &restore->avivo; 4778 4779 OUTREG(AVIVO_D1VGA_CONTROL, state->vga1_cntl); 4780 OUTREG(AVIVO_D2VGA_CONTROL, state->vga2_cntl); 4781} 4782 4783static void 4784RADEONRestoreBIOSRegisters(ScrnInfoPtr pScrn, RADEONSavePtr restore) 4785{ 4786 RADEONInfoPtr info = RADEONPTR(pScrn); 4787 unsigned char *RADEONMMIO = info->MMIO; 4788 4789 if (info->ChipFamily >= CHIP_FAMILY_R600) { 4790 OUTREG(R600_BIOS_0_SCRATCH, restore->bios_0_scratch); 4791 OUTREG(R600_BIOS_1_SCRATCH, restore->bios_1_scratch); 4792 OUTREG(R600_BIOS_2_SCRATCH, restore->bios_2_scratch); 4793 OUTREG(R600_BIOS_3_SCRATCH, restore->bios_3_scratch); 4794 OUTREG(R600_BIOS_4_SCRATCH, restore->bios_4_scratch); 4795 OUTREG(R600_BIOS_5_SCRATCH, restore->bios_5_scratch); 4796 OUTREG(R600_BIOS_6_SCRATCH, restore->bios_6_scratch); 4797 OUTREG(R600_BIOS_7_SCRATCH, restore->bios_7_scratch); 4798 } else { 4799 OUTREG(RADEON_BIOS_0_SCRATCH, restore->bios_0_scratch); 4800 OUTREG(RADEON_BIOS_1_SCRATCH, restore->bios_1_scratch); 4801 OUTREG(RADEON_BIOS_2_SCRATCH, restore->bios_2_scratch); 4802 OUTREG(RADEON_BIOS_3_SCRATCH, restore->bios_3_scratch); 4803 OUTREG(RADEON_BIOS_4_SCRATCH, restore->bios_4_scratch); 4804 OUTREG(RADEON_BIOS_5_SCRATCH, restore->bios_5_scratch); 4805 OUTREG(RADEON_BIOS_6_SCRATCH, restore->bios_6_scratch); 4806 OUTREG(RADEON_BIOS_7_SCRATCH, restore->bios_7_scratch); 4807 } 4808} 4809 4810static void 4811RADEONSaveBIOSRegisters(ScrnInfoPtr pScrn, RADEONSavePtr save) 4812{ 4813 RADEONInfoPtr info = RADEONPTR(pScrn); 4814 unsigned char *RADEONMMIO = info->MMIO; 4815 4816 if (info->ChipFamily >= CHIP_FAMILY_R600) { 4817 save->bios_0_scratch = INREG(R600_BIOS_0_SCRATCH); 4818 save->bios_1_scratch = INREG(R600_BIOS_1_SCRATCH); 4819 save->bios_2_scratch = INREG(R600_BIOS_2_SCRATCH); 4820 save->bios_3_scratch = INREG(R600_BIOS_3_SCRATCH); 4821 save->bios_4_scratch = INREG(R600_BIOS_4_SCRATCH); 4822 save->bios_5_scratch = INREG(R600_BIOS_5_SCRATCH); 4823 save->bios_6_scratch = INREG(R600_BIOS_6_SCRATCH); 4824 save->bios_7_scratch = INREG(R600_BIOS_7_SCRATCH); 4825 } else { 4826 save->bios_0_scratch = INREG(RADEON_BIOS_0_SCRATCH); 4827 save->bios_1_scratch = INREG(RADEON_BIOS_1_SCRATCH); 4828 save->bios_2_scratch = INREG(RADEON_BIOS_2_SCRATCH); 4829 save->bios_3_scratch = INREG(RADEON_BIOS_3_SCRATCH); 4830 save->bios_4_scratch = INREG(RADEON_BIOS_4_SCRATCH); 4831 save->bios_5_scratch = INREG(RADEON_BIOS_5_SCRATCH); 4832 save->bios_6_scratch = INREG(RADEON_BIOS_6_SCRATCH); 4833 save->bios_7_scratch = INREG(RADEON_BIOS_7_SCRATCH); 4834 } 4835} 4836 4837/* Save everything needed to restore the original VC state */ 4838static void RADEONSave(ScrnInfoPtr pScrn) 4839{ 4840 RADEONInfoPtr info = RADEONPTR(pScrn); 4841 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 4842 unsigned char *RADEONMMIO = info->MMIO; 4843 RADEONSavePtr save = info->SavedReg; 4844 4845 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 4846 "RADEONSave\n"); 4847 4848#ifdef WITH_VGAHW 4849 if (info->VGAAccess) { 4850 vgaHWPtr hwp = VGAHWPTR(pScrn); 4851 4852 vgaHWUnlock(hwp); 4853# if defined(__powerpc__) 4854 /* temporary hack to prevent crashing on PowerMacs when trying to 4855 * read VGA fonts and colormap, will find a better solution 4856 * in the future. TODO: Check if there's actually some VGA stuff 4857 * setup in the card at all !! 4858 */ 4859 vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_MODE); /* Save mode only */ 4860# elif defined(__linux__) 4861 /* Save only mode * & fonts */ 4862 vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_MODE | VGA_SR_FONTS ); 4863# else 4864 /* Save mode * & fonts & cmap */ 4865 vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_ALL); 4866# endif 4867 vgaHWLock(hwp); 4868 } 4869#endif 4870 4871 if (IS_AVIVO_VARIANT) { 4872 RADEONSaveMemMapRegisters(pScrn, save); 4873 avivo_save(pScrn, save); 4874 } else { 4875 save->dp_datatype = INREG(RADEON_DP_DATATYPE); 4876 save->rbbm_soft_reset = INREG(RADEON_RBBM_SOFT_RESET); 4877 save->clock_cntl_index = INREG(RADEON_CLOCK_CNTL_INDEX); 4878 RADEONPllErrataAfterIndex(info); 4879 4880 RADEONSaveMemMapRegisters(pScrn, save); 4881 RADEONSaveCommonRegisters(pScrn, save); 4882 RADEONSavePLLRegisters(pScrn, save); 4883 RADEONSaveCrtcRegisters(pScrn, save); 4884 RADEONSaveFPRegisters(pScrn, save); 4885 RADEONSaveDACRegisters(pScrn, save); 4886 if (pRADEONEnt->HasCRTC2) { 4887 RADEONSaveCrtc2Registers(pScrn, save); 4888 RADEONSavePLL2Registers(pScrn, save); 4889 } 4890 if (info->InternalTVOut) 4891 RADEONSaveTVRegisters(pScrn, save); 4892 } 4893 4894 RADEONSaveBIOSRegisters(pScrn, save); 4895 if (info->ChipFamily < CHIP_FAMILY_R600) 4896 RADEONSaveSurfaces(pScrn, save); 4897 4898} 4899 4900/* Restore the original (text) mode */ 4901static void RADEONRestore(ScrnInfoPtr pScrn) 4902{ 4903 RADEONInfoPtr info = RADEONPTR(pScrn); 4904 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 4905 unsigned char *RADEONMMIO = info->MMIO; 4906 RADEONSavePtr restore = info->SavedReg; 4907 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); 4908 xf86CrtcPtr crtc; 4909 4910 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 4911 "RADEONRestore\n"); 4912 4913#if X_BYTE_ORDER == X_BIG_ENDIAN 4914 RADEONWaitForFifo(pScrn, 1); 4915 OUTREG(RADEON_RBBM_GUICNTL, RADEON_HOST_DATA_SWAP_NONE); 4916#endif 4917 4918 RADEONBlank(pScrn); 4919 4920 if (IS_AVIVO_VARIANT) { 4921 RADEONRestoreMemMapRegisters(pScrn, restore); 4922 avivo_restore(pScrn, restore); 4923 } else { 4924 OUTREG(RADEON_CLOCK_CNTL_INDEX, restore->clock_cntl_index); 4925 RADEONPllErrataAfterIndex(info); 4926 OUTREG(RADEON_RBBM_SOFT_RESET, restore->rbbm_soft_reset); 4927 OUTREG(RADEON_DP_DATATYPE, restore->dp_datatype); 4928 OUTREG(RADEON_GRPH_BUFFER_CNTL, restore->grph_buffer_cntl); 4929 OUTREG(RADEON_GRPH2_BUFFER_CNTL, restore->grph2_buffer_cntl); 4930 4931 if (!info->IsSecondary) { 4932 RADEONRestoreMemMapRegisters(pScrn, restore); 4933 RADEONRestoreCommonRegisters(pScrn, restore); 4934 4935 if (pRADEONEnt->HasCRTC2) { 4936 RADEONRestoreCrtc2Registers(pScrn, restore); 4937 RADEONRestorePLL2Registers(pScrn, restore); 4938 } 4939 4940 RADEONRestoreCrtcRegisters(pScrn, restore); 4941 RADEONRestorePLLRegisters(pScrn, restore); 4942 RADEONRestoreRMXRegisters(pScrn, restore); 4943 RADEONRestoreFPRegisters(pScrn, restore); 4944 RADEONRestoreFP2Registers(pScrn, restore); 4945 RADEONRestoreLVDSRegisters(pScrn, restore); 4946 4947 if (info->InternalTVOut) 4948 RADEONRestoreTVRegisters(pScrn, restore); 4949 } 4950 4951 RADEONRestoreBIOSRegisters(pScrn, restore); 4952 } 4953 4954 4955#if 1 4956 /* Temp fix to "solve" VT switch problems. When switching VTs on 4957 * some systems, the console can either hang or the fonts can be 4958 * corrupted. This hack solves the problem 99% of the time. A 4959 * correct fix is being worked on. 4960 */ 4961 usleep(100000); 4962#endif 4963 4964 if (info->ChipFamily < CHIP_FAMILY_R600) 4965 RADEONRestoreSurfaces(pScrn, restore); 4966 4967 /* need to make sure we don't enable a crtc by accident or we may get a hang */ 4968 if (pRADEONEnt->HasCRTC2 && !info->IsSecondary) { 4969 if (info->crtc2_on && xf86_config->num_crtc > 1) { 4970 crtc = xf86_config->crtc[1]; 4971 crtc->funcs->dpms(crtc, DPMSModeOn); 4972 } 4973 } 4974 if (info->crtc_on) { 4975 crtc = xf86_config->crtc[0]; 4976 crtc->funcs->dpms(crtc, DPMSModeOn); 4977 } 4978 4979#ifdef WITH_VGAHW 4980 if (info->VGAAccess) { 4981 vgaHWPtr hwp = VGAHWPTR(pScrn); 4982 vgaHWUnlock(hwp); 4983# if defined(__powerpc__) 4984 /* Temporary hack to prevent crashing on PowerMacs when trying to 4985 * write VGA fonts, will find a better solution in the future 4986 */ 4987 vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_MODE ); 4988# elif defined(__linux__) 4989 vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_MODE | VGA_SR_FONTS ); 4990# else 4991 vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_ALL ); 4992# endif 4993 vgaHWLock(hwp); 4994 } 4995#endif 4996 4997 /* to restore console mode, DAC registers should be set after every other registers are set, 4998 * otherwise,we may get blank screen 4999 */ 5000 if (IS_AVIVO_VARIANT) 5001 avivo_restore_vga_regs(pScrn, restore); 5002 5003 if (!IS_AVIVO_VARIANT) 5004 RADEONRestoreDACRegisters(pScrn, restore); 5005 5006#if 0 5007 RADEONWaitForVerticalSync(pScrn); 5008#endif 5009} 5010 5011#if 0 5012/* Define initial palette for requested video mode. This doesn't do 5013 * anything for XFree86 4.0. 5014 */ 5015static void RADEONInitPalette(RADEONSavePtr save) 5016{ 5017 save->palette_valid = FALSE; 5018} 5019#endif 5020 5021static Bool RADEONSaveScreen(ScreenPtr pScreen, int mode) 5022{ 5023 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 5024 Bool unblank; 5025 5026 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5027 "RADEONSaveScreen(%d)\n", mode); 5028 5029 unblank = xf86IsUnblank(mode); 5030 if (unblank) SetTimeSinceLastInputEvent(); 5031 5032 if ((pScrn != NULL) && pScrn->vtSema) { 5033 if (unblank) 5034 RADEONUnblank(pScrn); 5035 else 5036 RADEONBlank(pScrn); 5037 } 5038 return TRUE; 5039} 5040 5041Bool RADEONSwitchMode(int scrnIndex, DisplayModePtr mode, int flags) 5042{ 5043 ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; 5044 RADEONInfoPtr info = RADEONPTR(pScrn); 5045 Bool tilingOld = info->tilingEnabled; 5046 Bool ret; 5047#ifdef XF86DRI 5048 Bool CPStarted = info->CPStarted; 5049 5050 if (CPStarted) { 5051 DRILock(pScrn->pScreen, 0); 5052 RADEONCP_STOP(pScrn, info); 5053 } 5054#endif 5055 5056 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5057 "RADEONSwitchMode() !n"); 5058 5059 if (info->allowColorTiling) { 5060 info->tilingEnabled = (mode->Flags & (V_DBLSCAN | V_INTERLACE)) ? FALSE : TRUE; 5061#ifdef XF86DRI 5062 if (info->directRenderingEnabled && (info->tilingEnabled != tilingOld)) { 5063 RADEONSAREAPrivPtr pSAREAPriv; 5064 if (RADEONDRISetParam(pScrn, RADEON_SETPARAM_SWITCH_TILING, (info->tilingEnabled ? 1 : 0)) < 0) 5065 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 5066 "[drm] failed changing tiling status\n"); 5067 pSAREAPriv = DRIGetSAREAPrivate(pScrn->pScreen); 5068 info->tilingEnabled = pSAREAPriv->tiling_enabled ? TRUE : FALSE; 5069 } 5070#endif 5071 } 5072 5073 if (info->accelOn) 5074 RADEON_SYNC(info, pScrn); 5075 5076 ret = xf86SetSingleMode (pScrn, mode, RR_Rotate_0); 5077 5078 if (info->tilingEnabled != tilingOld) { 5079 /* need to redraw front buffer, I guess this can be considered a hack ? */ 5080 xf86EnableDisableFBAccess(scrnIndex, FALSE); 5081 RADEONChangeSurfaces(pScrn); 5082 xf86EnableDisableFBAccess(scrnIndex, TRUE); 5083 /* xf86SetRootClip would do, but can't access that here */ 5084 } 5085 5086 if (info->accelOn) { 5087 RADEON_SYNC(info, pScrn); 5088 RADEONEngineRestore(pScrn); 5089 } 5090 5091#ifdef XF86DRI 5092 if (CPStarted) { 5093 RADEONCP_START(pScrn, info); 5094 DRIUnlock(pScrn->pScreen); 5095 } 5096#endif 5097 5098 /* reset ecp for overlay */ 5099 info->ecp_div = -1; 5100 5101 return ret; 5102} 5103 5104#ifdef X_XF86MiscPassMessage 5105Bool RADEONHandleMessage(int scrnIndex, const char* msgtype, 5106 const char* msgval, char** retmsg) 5107{ 5108 ErrorF("RADEONHandleMessage(%d, \"%s\", \"%s\", retmsg)\n", scrnIndex, 5109 msgtype, msgval); 5110 *retmsg = ""; 5111 return 0; 5112} 5113#endif 5114 5115#ifndef HAVE_XF86MODEBANDWIDTH 5116/** Calculates the memory bandwidth (in MiB/sec) of a mode. */ 5117_X_HIDDEN unsigned int 5118xf86ModeBandwidth(DisplayModePtr mode, int depth) 5119{ 5120 float a_active, a_total, active_percent, pixels_per_second; 5121 int bytes_per_pixel = (depth + 7) / 8; 5122 5123 if (!mode->HTotal || !mode->VTotal || !mode->Clock) 5124 return 0; 5125 5126 a_active = mode->HDisplay * mode->VDisplay; 5127 a_total = mode->HTotal * mode->VTotal; 5128 active_percent = a_active / a_total; 5129 pixels_per_second = active_percent * mode->Clock * 1000.0; 5130 5131 return (unsigned int)(pixels_per_second * bytes_per_pixel / (1024 * 1024)); 5132} 5133#endif 5134 5135/* Used to disallow modes that are not supported by the hardware */ 5136ModeStatus RADEONValidMode(int scrnIndex, DisplayModePtr mode, 5137 Bool verbose, int flag) 5138{ 5139 ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; 5140 RADEONInfoPtr info = RADEONPTR(pScrn); 5141 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 5142 5143 /* 5144 * RN50 has effective maximum mode bandwidth of about 300MiB/s. 5145 * XXX should really do this for all chips by properly computing 5146 * memory bandwidth and an overhead factor. 5147 */ 5148 if (info->ChipFamily == CHIP_FAMILY_RV100 && !pRADEONEnt->HasCRTC2) { 5149 if (xf86ModeBandwidth(mode, pScrn->bitsPerPixel) > 300) 5150 return MODE_BANDWIDTH; 5151 } 5152 5153 /* There are problems with double scan mode at high clocks 5154 * They're likely related PLL and display buffer settings. 5155 * Disable these modes for now. 5156 */ 5157 if (mode->Flags & V_DBLSCAN) { 5158 if ((mode->CrtcHDisplay >= 1024) || (mode->CrtcVDisplay >= 768)) 5159 return MODE_CLOCK_RANGE; 5160 } 5161 return MODE_OK; 5162} 5163 5164/* Adjust viewport into virtual desktop such that (0,0) in viewport 5165 * space is (x,y) in virtual space. 5166 */ 5167void RADEONDoAdjustFrame(ScrnInfoPtr pScrn, int x, int y, Bool crtc2) 5168{ 5169 RADEONInfoPtr info = RADEONPTR(pScrn); 5170 unsigned char *RADEONMMIO = info->MMIO; 5171 int Base, reg, regcntl, crtcoffsetcntl, xytilereg, crtcxytile = 0; 5172#ifdef XF86DRI 5173 RADEONSAREAPrivPtr pSAREAPriv; 5174 XF86DRISAREAPtr pSAREA; 5175#endif 5176 5177#if 0 /* Verbose */ 5178 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5179 "RADEONDoAdjustFrame(%d,%d,%d)\n", x, y, clone); 5180#endif 5181 5182 if (info->showCache && y) { 5183 int lastline = info->FbMapSize / 5184 ((pScrn->displayWidth * pScrn->bitsPerPixel) / 8); 5185 5186 lastline -= pScrn->currentMode->VDisplay; 5187 y += (pScrn->virtualY - 1) * (y / 3 + 1); 5188 if (y > lastline) y = lastline; 5189 } 5190 5191 Base = pScrn->fbOffset; 5192 5193 /* note we cannot really simply use the info->ModeReg.crtc_offset_cntl value, since the 5194 drm might have set FLIP_CNTL since we wrote that. Unfortunately FLIP_CNTL causes 5195 flickering when scrolling vertically in a virtual screen, possibly because crtc will 5196 pick up the new offset value at the end of each scanline, but the new offset_cntl value 5197 only after a vsync. We'd probably need to wait (in drm) for vsync and only then update 5198 OFFSET and OFFSET_CNTL, if the y coord has changed. Seems hard to fix. */ 5199 if (crtc2) { 5200 reg = RADEON_CRTC2_OFFSET; 5201 regcntl = RADEON_CRTC2_OFFSET_CNTL; 5202 xytilereg = R300_CRTC2_TILE_X0_Y0; 5203 } else { 5204 reg = RADEON_CRTC_OFFSET; 5205 regcntl = RADEON_CRTC_OFFSET_CNTL; 5206 xytilereg = R300_CRTC_TILE_X0_Y0; 5207 } 5208 crtcoffsetcntl = INREG(regcntl) & ~0xf; 5209#if 0 5210 /* try to get rid of flickering when scrolling at least for 2d */ 5211#ifdef XF86DRI 5212 if (!info->have3DWindows) 5213#endif 5214 crtcoffsetcntl &= ~RADEON_CRTC_OFFSET_FLIP_CNTL; 5215#endif 5216 if (info->tilingEnabled) { 5217 if (IS_R300_VARIANT || IS_AVIVO_VARIANT) { 5218 /* On r300/r400 when tiling is enabled crtc_offset is set to the address of 5219 * the surface. the x/y offsets are handled by the X_Y tile reg for each crtc 5220 * Makes tiling MUCH easier. 5221 */ 5222 crtcxytile = x | (y << 16); 5223 Base &= ~0x7ff; 5224 } else { 5225 int byteshift = info->CurrentLayout.bitsPerPixel >> 4; 5226 /* crtc uses 256(bytes)x8 "half-tile" start addresses? */ 5227 int tile_addr = (((y >> 3) * info->CurrentLayout.displayWidth + x) >> (8 - byteshift)) << 11; 5228 Base += tile_addr + ((x << byteshift) % 256) + ((y % 8) << 8); 5229 crtcoffsetcntl = crtcoffsetcntl | (y % 16); 5230 } 5231 } 5232 else { 5233 int offset = y * info->CurrentLayout.displayWidth + x; 5234 switch (info->CurrentLayout.pixel_code) { 5235 case 15: 5236 case 16: offset *= 2; break; 5237 case 24: offset *= 3; break; 5238 case 32: offset *= 4; break; 5239 } 5240 Base += offset; 5241 } 5242 5243 Base &= ~7; /* 3 lower bits are always 0 */ 5244 5245#ifdef XF86DRI 5246 if (info->directRenderingInited) { 5247 /* note cannot use pScrn->pScreen since this is unitialized when called from 5248 RADEONScreenInit, and we need to call from there to get mergedfb + pageflip working */ 5249 /*** NOTE: r3/4xx will need sarea and drm pageflip updates to handle the xytile regs for 5250 *** pageflipping! 5251 ***/ 5252 pSAREAPriv = DRIGetSAREAPrivate(screenInfo.screens[pScrn->scrnIndex]); 5253 /* can't get at sarea in a semi-sane way? */ 5254 pSAREA = (void *)((char*)pSAREAPriv - sizeof(XF86DRISAREARec)); 5255 5256 if (crtc2) { 5257 pSAREAPriv->crtc2_base = Base; 5258 } 5259 else { 5260 pSAREA->frame.x = (Base / info->CurrentLayout.pixel_bytes) 5261 % info->CurrentLayout.displayWidth; 5262 pSAREA->frame.y = (Base / info->CurrentLayout.pixel_bytes) 5263 / info->CurrentLayout.displayWidth; 5264 pSAREA->frame.width = pScrn->frameX1 - x + 1; 5265 pSAREA->frame.height = pScrn->frameY1 - y + 1; 5266 } 5267 5268 if (pSAREAPriv->pfCurrentPage == 1) { 5269 Base += info->backOffset - info->frontOffset; 5270 } 5271 } 5272#endif 5273 5274 if (IS_R300_VARIANT || IS_AVIVO_VARIANT) { 5275 OUTREG(xytilereg, crtcxytile); 5276 } else { 5277 OUTREG(regcntl, crtcoffsetcntl); 5278 } 5279 5280 OUTREG(reg, Base); 5281} 5282 5283void RADEONAdjustFrame(int scrnIndex, int x, int y, int flags) 5284{ 5285 ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; 5286 RADEONInfoPtr info = RADEONPTR(pScrn); 5287 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 5288 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); 5289 xf86OutputPtr output = config->output[config->compat_output]; 5290 xf86CrtcPtr crtc = output->crtc; 5291 5292#ifdef XF86DRI 5293 if (info->CPStarted && pScrn->pScreen) DRILock(pScrn->pScreen, 0); 5294#endif 5295 5296 if (info->accelOn) 5297 RADEON_SYNC(info, pScrn); 5298 5299 if (crtc && crtc->enabled) { 5300 if (crtc == pRADEONEnt->pCrtc[0]) 5301 RADEONDoAdjustFrame(pScrn, crtc->desiredX + x, crtc->desiredY + y, FALSE); 5302 else 5303 RADEONDoAdjustFrame(pScrn, crtc->desiredX + x, crtc->desiredY + y, TRUE); 5304 crtc->x = output->initial_x + x; 5305 crtc->y = output->initial_y + y; 5306 } 5307 5308 5309#ifdef XF86DRI 5310 if (info->CPStarted && pScrn->pScreen) DRIUnlock(pScrn->pScreen); 5311#endif 5312} 5313 5314/* Called when VT switching back to the X server. Reinitialize the 5315 * video mode. 5316 */ 5317Bool RADEONEnterVT(int scrnIndex, int flags) 5318{ 5319 ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; 5320 RADEONInfoPtr info = RADEONPTR(pScrn); 5321 unsigned char *RADEONMMIO = info->MMIO; 5322 uint32_t mem_size; 5323 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); 5324 int i; 5325 5326 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5327 "RADEONEnterVT\n"); 5328 5329 if (info->ChipFamily >= CHIP_FAMILY_R600) 5330 mem_size = INREG(R600_CONFIG_MEMSIZE); 5331 else 5332 mem_size = INREG(RADEON_CONFIG_MEMSIZE); 5333 5334 if (mem_size == 0) { /* Softboot V_BIOS */ 5335 if (info->IsAtomBios) { 5336 rhdAtomASICInit(info->atomBIOS); 5337 } else { 5338 xf86Int10InfoPtr pInt; 5339 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 5340 "zero MEMSIZE, probably at D3cold. Re-POSTing via int10.\n"); 5341 pInt = xf86InitInt10 (info->pEnt->index); 5342 if (pInt) { 5343 pInt->num = 0xe6; 5344 xf86ExecX86int10 (pInt); 5345 xf86FreeInt10 (pInt); 5346 } else { 5347 RADEONGetBIOSInitTableOffsets(pScrn); 5348 RADEONPostCardFromBIOSTables(pScrn); 5349 } 5350 } 5351 } 5352 5353 /* Makes sure the engine is idle before doing anything */ 5354 RADEONWaitForIdleMMIO(pScrn); 5355 5356 if (info->IsMobility && !IS_AVIVO_VARIANT) { 5357 if (xf86ReturnOptValBool(info->Options, OPTION_DYNAMIC_CLOCKS, FALSE)) { 5358 RADEONSetDynamicClock(pScrn, 1); 5359 } else { 5360 RADEONSetDynamicClock(pScrn, 0); 5361 } 5362 } else if (IS_AVIVO_VARIANT) { 5363 if (xf86ReturnOptValBool(info->Options, OPTION_DYNAMIC_CLOCKS, FALSE)) { 5364 atombios_static_pwrmgt_setup(pScrn, 1); 5365 atombios_dyn_clk_setup(pScrn, 1); 5366 } 5367 } 5368 5369 if (IS_R300_VARIANT || IS_RV100_VARIANT) 5370 RADEONForceSomeClocks(pScrn); 5371 5372 for (i = 0; i < config->num_crtc; i++) 5373 radeon_crtc_modeset_ioctl(config->crtc[i], TRUE); 5374 5375 pScrn->vtSema = TRUE; 5376 5377 if (!xf86SetDesiredModes(pScrn)) 5378 return FALSE; 5379 5380 if (info->ChipFamily < CHIP_FAMILY_R600) 5381 RADEONRestoreSurfaces(pScrn, info->ModeReg); 5382#ifdef XF86DRI 5383 if (info->directRenderingEnabled) { 5384 if (info->cardType == CARD_PCIE && 5385 info->pKernelDRMVersion->version_minor >= 19 && 5386 info->FbSecureSize) { 5387 /* we need to backup the PCIE GART TABLE from fb memory */ 5388 memcpy(info->FB + info->pciGartOffset, info->pciGartBackup, info->pciGartSize); 5389 } 5390 5391 /* get the DRI back into shape after resume */ 5392 RADEONDRISetVBlankInterrupt (pScrn, TRUE); 5393 RADEONDRIResume(pScrn->pScreen); 5394 RADEONAdjustMemMapRegisters(pScrn, info->ModeReg); 5395 5396 } 5397#endif 5398 /* this will get XVideo going again, but only if XVideo was initialised 5399 during server startup (hence the info->adaptor if). */ 5400 if (info->adaptor) 5401 RADEONResetVideo(pScrn); 5402 5403 if (info->accelOn) 5404 RADEONEngineRestore(pScrn); 5405 5406#ifdef XF86DRI 5407 if (info->directRenderingEnabled) { 5408 RADEONCP_START(pScrn, info); 5409 DRIUnlock(pScrn->pScreen); 5410 } 5411#endif 5412 5413 return TRUE; 5414} 5415 5416/* Called when VT switching away from the X server. Restore the 5417 * original text mode. 5418 */ 5419void RADEONLeaveVT(int scrnIndex, int flags) 5420{ 5421 ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; 5422 RADEONInfoPtr info = RADEONPTR(pScrn); 5423 xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); 5424 int i; 5425 5426 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5427 "RADEONLeaveVT\n"); 5428#ifdef XF86DRI 5429 if (RADEONPTR(pScrn)->directRenderingInited) { 5430 5431 RADEONDRISetVBlankInterrupt (pScrn, FALSE); 5432 DRILock(pScrn->pScreen, 0); 5433 RADEONCP_STOP(pScrn, info); 5434 5435 if (info->cardType == CARD_PCIE && 5436 info->pKernelDRMVersion->version_minor >= 19 && 5437 info->FbSecureSize) { 5438 /* we need to backup the PCIE GART TABLE from fb memory */ 5439 memcpy(info->pciGartBackup, (info->FB + info->pciGartOffset), info->pciGartSize); 5440 } 5441 5442 /* Make sure 3D clients will re-upload textures to video RAM */ 5443 if (info->textureSize) { 5444 RADEONSAREAPrivPtr pSAREAPriv = 5445 (RADEONSAREAPrivPtr)DRIGetSAREAPrivate(pScrn->pScreen); 5446 drmTextureRegionPtr list = pSAREAPriv->texList[0]; 5447 int age = ++pSAREAPriv->texAge[0]; 5448 5449 i = 0; 5450 5451 do { 5452 list[i].age = age; 5453 i = list[i].next; 5454 } while (i != 0); 5455 } 5456 } 5457#endif 5458 5459#ifndef HAVE_FREE_SHADOW 5460 for (i = 0; i < config->num_crtc; i++) { 5461 xf86CrtcPtr crtc = config->crtc[i]; 5462 5463 if (crtc->rotatedPixmap || crtc->rotatedData) { 5464 crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, 5465 crtc->rotatedData); 5466 crtc->rotatedPixmap = NULL; 5467 crtc->rotatedData = NULL; 5468 } 5469 } 5470#else 5471 xf86RotateFreeShadow(pScrn); 5472#endif 5473 5474 xf86_hide_cursors (pScrn); 5475 5476 RADEONRestore(pScrn); 5477 5478 for (i = 0; i < config->num_crtc; i++) 5479 radeon_crtc_modeset_ioctl(config->crtc[i], FALSE); 5480 5481 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5482 "Ok, leaving now...\n"); 5483} 5484 5485/* Called at the end of each server generation. Restore the original 5486 * text mode, unmap video memory, and unwrap and call the saved 5487 * CloseScreen function. 5488 */ 5489static Bool RADEONCloseScreen(int scrnIndex, ScreenPtr pScreen) 5490{ 5491 ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; 5492 RADEONInfoPtr info = RADEONPTR(pScrn); 5493 5494 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5495 "RADEONCloseScreen\n"); 5496 5497 /* Mark acceleration as stopped or we might try to access the engine at 5498 * wrong times, especially if we had DRI, after DRI has been stopped 5499 */ 5500 info->accelOn = FALSE; 5501 5502#ifdef XF86DRI 5503#ifdef DAMAGE 5504 if (info->pDamage) { 5505 PixmapPtr pPix = pScreen->GetScreenPixmap(pScreen); 5506 5507 DamageUnregister(&pPix->drawable, info->pDamage); 5508 DamageDestroy(info->pDamage); 5509 info->pDamage = NULL; 5510 } 5511#endif 5512 5513 RADEONDRIStop(pScreen); 5514#endif 5515 5516#ifdef USE_XAA 5517 if(!info->useEXA && info->RenderTex) { 5518 xf86FreeOffscreenLinear(info->RenderTex); 5519 info->RenderTex = NULL; 5520 } 5521#endif /* USE_XAA */ 5522 5523 if (pScrn->vtSema) { 5524 RADEONRestore(pScrn); 5525 } 5526 5527 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5528 "Disposing accel...\n"); 5529#ifdef USE_EXA 5530 if (info->exa) { 5531 exaDriverFini(pScreen); 5532 xfree(info->exa); 5533 info->exa = NULL; 5534 } 5535#endif /* USE_EXA */ 5536#ifdef USE_XAA 5537 if (!info->useEXA) { 5538 if (info->accel) 5539 XAADestroyInfoRec(info->accel); 5540 info->accel = NULL; 5541 5542 if (info->scratch_save) 5543 xfree(info->scratch_save); 5544 info->scratch_save = NULL; 5545 } 5546#endif /* USE_XAA */ 5547 5548 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5549 "Disposing cursor info\n"); 5550 if (info->cursor) xf86DestroyCursorInfoRec(info->cursor); 5551 info->cursor = NULL; 5552 5553 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5554 "Disposing DGA\n"); 5555 if (info->DGAModes) xfree(info->DGAModes); 5556 info->DGAModes = NULL; 5557 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5558 "Unmapping memory\n"); 5559 RADEONUnmapMem(pScrn); 5560 5561 pScrn->vtSema = FALSE; 5562 5563 xf86ClearPrimInitDone(info->pEnt->index); 5564 5565 pScreen->BlockHandler = info->BlockHandler; 5566 pScreen->CloseScreen = info->CloseScreen; 5567 return (*pScreen->CloseScreen)(scrnIndex, pScreen); 5568} 5569 5570void RADEONFreeScreen(int scrnIndex, int flags) 5571{ 5572 ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; 5573 RADEONInfoPtr info = RADEONPTR(pScrn); 5574 5575 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG, 5576 "RADEONFreeScreen\n"); 5577 5578 /* when server quits at PreInit, we don't need do this anymore*/ 5579 if (!info) return; 5580 5581#ifdef WITH_VGAHW 5582 if (info->VGAAccess && xf86LoaderCheckSymbol("vgaHWFreeHWRec")) 5583 vgaHWFreeHWRec(pScrn); 5584#endif 5585 RADEONFreeRec(pScrn); 5586} 5587 5588static void RADEONForceSomeClocks(ScrnInfoPtr pScrn) 5589{ 5590 /* It appears from r300 and rv100 may need some clocks forced-on */ 5591 uint32_t tmp; 5592 5593 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5594 tmp |= RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_VIP; 5595 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5596} 5597 5598static void RADEONSetDynamicClock(ScrnInfoPtr pScrn, int mode) 5599{ 5600 RADEONInfoPtr info = RADEONPTR(pScrn); 5601 RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); 5602 unsigned char *RADEONMMIO = info->MMIO; 5603 uint32_t tmp; 5604 switch(mode) { 5605 case 0: /* Turn everything OFF (ForceON to everything)*/ 5606 if ( !pRADEONEnt->HasCRTC2 ) { 5607 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5608 tmp |= (RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_HDP | 5609 RADEON_SCLK_FORCE_DISP1 | RADEON_SCLK_FORCE_TOP | 5610 RADEON_SCLK_FORCE_E2 | RADEON_SCLK_FORCE_SE | 5611 RADEON_SCLK_FORCE_IDCT | RADEON_SCLK_FORCE_VIP | 5612 RADEON_SCLK_FORCE_RE | RADEON_SCLK_FORCE_PB | 5613 RADEON_SCLK_FORCE_TAM | RADEON_SCLK_FORCE_TDM | 5614 RADEON_SCLK_FORCE_RB); 5615 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5616 } else if (info->ChipFamily == CHIP_FAMILY_RV350) { 5617 /* for RV350/M10, no delays are required. */ 5618 tmp = INPLL(pScrn, R300_SCLK_CNTL2); 5619 tmp |= (R300_SCLK_FORCE_TCL | 5620 R300_SCLK_FORCE_GA | 5621 R300_SCLK_FORCE_CBA); 5622 OUTPLL(pScrn, R300_SCLK_CNTL2, tmp); 5623 5624 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5625 tmp |= (RADEON_SCLK_FORCE_DISP2 | RADEON_SCLK_FORCE_CP | 5626 RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1 | 5627 RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_E2 | 5628 R300_SCLK_FORCE_VAP | RADEON_SCLK_FORCE_IDCT | 5629 RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR | 5630 R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX | 5631 R300_SCLK_FORCE_US | RADEON_SCLK_FORCE_TV_SCLK | 5632 R300_SCLK_FORCE_SU | RADEON_SCLK_FORCE_OV0); 5633 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5634 5635 tmp = INPLL(pScrn, RADEON_SCLK_MORE_CNTL); 5636 tmp |= RADEON_SCLK_MORE_FORCEON; 5637 OUTPLL(pScrn, RADEON_SCLK_MORE_CNTL, tmp); 5638 5639 tmp = INPLL(pScrn, RADEON_MCLK_CNTL); 5640 tmp |= (RADEON_FORCEON_MCLKA | 5641 RADEON_FORCEON_MCLKB | 5642 RADEON_FORCEON_YCLKA | 5643 RADEON_FORCEON_YCLKB | 5644 RADEON_FORCEON_MC); 5645 OUTPLL(pScrn, RADEON_MCLK_CNTL, tmp); 5646 5647 tmp = INPLL(pScrn, RADEON_VCLK_ECP_CNTL); 5648 tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb | 5649 RADEON_PIXCLK_DAC_ALWAYS_ONb | 5650 R300_DISP_DAC_PIXCLK_DAC_BLANK_OFF); 5651 OUTPLL(pScrn, RADEON_VCLK_ECP_CNTL, tmp); 5652 5653 tmp = INPLL(pScrn, RADEON_PIXCLKS_CNTL); 5654 tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb | 5655 RADEON_PIX2CLK_DAC_ALWAYS_ONb | 5656 RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb | 5657 R300_DVOCLK_ALWAYS_ONb | 5658 RADEON_PIXCLK_BLEND_ALWAYS_ONb | 5659 RADEON_PIXCLK_GV_ALWAYS_ONb | 5660 R300_PIXCLK_DVO_ALWAYS_ONb | 5661 RADEON_PIXCLK_LVDS_ALWAYS_ONb | 5662 RADEON_PIXCLK_TMDS_ALWAYS_ONb | 5663 R300_PIXCLK_TRANS_ALWAYS_ONb | 5664 R300_PIXCLK_TVO_ALWAYS_ONb | 5665 R300_P2G2CLK_ALWAYS_ONb | 5666 R300_P2G2CLK_ALWAYS_ONb | 5667 R300_DISP_DAC_PIXCLK_DAC2_BLANK_OFF); 5668 OUTPLL(pScrn, RADEON_PIXCLKS_CNTL, tmp); 5669 } else { 5670 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5671 tmp |= (RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_E2); 5672 tmp |= RADEON_SCLK_FORCE_SE; 5673 5674 if ( !pRADEONEnt->HasCRTC2 ) { 5675 tmp |= ( RADEON_SCLK_FORCE_RB | 5676 RADEON_SCLK_FORCE_TDM | 5677 RADEON_SCLK_FORCE_TAM | 5678 RADEON_SCLK_FORCE_PB | 5679 RADEON_SCLK_FORCE_RE | 5680 RADEON_SCLK_FORCE_VIP | 5681 RADEON_SCLK_FORCE_IDCT | 5682 RADEON_SCLK_FORCE_TOP | 5683 RADEON_SCLK_FORCE_DISP1 | 5684 RADEON_SCLK_FORCE_DISP2 | 5685 RADEON_SCLK_FORCE_HDP ); 5686 } else if ((info->ChipFamily == CHIP_FAMILY_R300) || 5687 (info->ChipFamily == CHIP_FAMILY_R350)) { 5688 tmp |= ( RADEON_SCLK_FORCE_HDP | 5689 RADEON_SCLK_FORCE_DISP1 | 5690 RADEON_SCLK_FORCE_DISP2 | 5691 RADEON_SCLK_FORCE_TOP | 5692 RADEON_SCLK_FORCE_IDCT | 5693 RADEON_SCLK_FORCE_VIP); 5694 } 5695 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5696 5697 usleep(16000); 5698 5699 if ((info->ChipFamily == CHIP_FAMILY_R300) || 5700 (info->ChipFamily == CHIP_FAMILY_R350)) { 5701 tmp = INPLL(pScrn, R300_SCLK_CNTL2); 5702 tmp |= ( R300_SCLK_FORCE_TCL | 5703 R300_SCLK_FORCE_GA | 5704 R300_SCLK_FORCE_CBA); 5705 OUTPLL(pScrn, R300_SCLK_CNTL2, tmp); 5706 usleep(16000); 5707 } 5708 5709 if (info->IsIGP) { 5710 tmp = INPLL(pScrn, RADEON_MCLK_CNTL); 5711 tmp &= ~(RADEON_FORCEON_MCLKA | 5712 RADEON_FORCEON_YCLKA); 5713 OUTPLL(pScrn, RADEON_MCLK_CNTL, tmp); 5714 usleep(16000); 5715 } 5716 5717 if ((info->ChipFamily == CHIP_FAMILY_RV200) || 5718 (info->ChipFamily == CHIP_FAMILY_RV250) || 5719 (info->ChipFamily == CHIP_FAMILY_RV280)) { 5720 tmp = INPLL(pScrn, RADEON_SCLK_MORE_CNTL); 5721 tmp |= RADEON_SCLK_MORE_FORCEON; 5722 OUTPLL(pScrn, RADEON_SCLK_MORE_CNTL, tmp); 5723 usleep(16000); 5724 } 5725 5726 tmp = INPLL(pScrn, RADEON_PIXCLKS_CNTL); 5727 tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb | 5728 RADEON_PIX2CLK_DAC_ALWAYS_ONb | 5729 RADEON_PIXCLK_BLEND_ALWAYS_ONb | 5730 RADEON_PIXCLK_GV_ALWAYS_ONb | 5731 RADEON_PIXCLK_DIG_TMDS_ALWAYS_ONb | 5732 RADEON_PIXCLK_LVDS_ALWAYS_ONb | 5733 RADEON_PIXCLK_TMDS_ALWAYS_ONb); 5734 5735 OUTPLL(pScrn, RADEON_PIXCLKS_CNTL, tmp); 5736 usleep(16000); 5737 5738 tmp = INPLL(pScrn, RADEON_VCLK_ECP_CNTL); 5739 tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb | 5740 RADEON_PIXCLK_DAC_ALWAYS_ONb); 5741 OUTPLL(pScrn, RADEON_VCLK_ECP_CNTL, tmp); 5742 } 5743 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Dynamic Clock Scaling Disabled\n"); 5744 break; 5745 case 1: 5746 if (!pRADEONEnt->HasCRTC2) { 5747 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5748 if ((INREG(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) > 5749 RADEON_CFG_ATI_REV_A13) { 5750 tmp &= ~(RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_RB); 5751 } 5752 tmp &= ~(RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1 | 5753 RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_SE | 5754 RADEON_SCLK_FORCE_IDCT | RADEON_SCLK_FORCE_RE | 5755 RADEON_SCLK_FORCE_PB | RADEON_SCLK_FORCE_TAM | 5756 RADEON_SCLK_FORCE_TDM); 5757 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5758 } else if ((info->ChipFamily == CHIP_FAMILY_R300) || 5759 (info->ChipFamily == CHIP_FAMILY_R350) || 5760 (info->ChipFamily == CHIP_FAMILY_RV350)) { 5761 if (info->ChipFamily == CHIP_FAMILY_RV350) { 5762 tmp = INPLL(pScrn, R300_SCLK_CNTL2); 5763 tmp &= ~(R300_SCLK_FORCE_TCL | 5764 R300_SCLK_FORCE_GA | 5765 R300_SCLK_FORCE_CBA); 5766 tmp |= (R300_SCLK_TCL_MAX_DYN_STOP_LAT | 5767 R300_SCLK_GA_MAX_DYN_STOP_LAT | 5768 R300_SCLK_CBA_MAX_DYN_STOP_LAT); 5769 OUTPLL(pScrn, R300_SCLK_CNTL2, tmp); 5770 5771 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5772 tmp &= ~(RADEON_SCLK_FORCE_DISP2 | RADEON_SCLK_FORCE_CP | 5773 RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1 | 5774 RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_E2 | 5775 R300_SCLK_FORCE_VAP | RADEON_SCLK_FORCE_IDCT | 5776 RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR | 5777 R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX | 5778 R300_SCLK_FORCE_US | RADEON_SCLK_FORCE_TV_SCLK | 5779 R300_SCLK_FORCE_SU | RADEON_SCLK_FORCE_OV0); 5780 tmp |= RADEON_DYN_STOP_LAT_MASK; 5781 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5782 5783 tmp = INPLL(pScrn, RADEON_SCLK_MORE_CNTL); 5784 tmp &= ~RADEON_SCLK_MORE_FORCEON; 5785 tmp |= RADEON_SCLK_MORE_MAX_DYN_STOP_LAT; 5786 OUTPLL(pScrn, RADEON_SCLK_MORE_CNTL, tmp); 5787 5788 tmp = INPLL(pScrn, RADEON_VCLK_ECP_CNTL); 5789 tmp |= (RADEON_PIXCLK_ALWAYS_ONb | 5790 RADEON_PIXCLK_DAC_ALWAYS_ONb); 5791 OUTPLL(pScrn, RADEON_VCLK_ECP_CNTL, tmp); 5792 5793 tmp = INPLL(pScrn, RADEON_PIXCLKS_CNTL); 5794 tmp |= (RADEON_PIX2CLK_ALWAYS_ONb | 5795 RADEON_PIX2CLK_DAC_ALWAYS_ONb | 5796 RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb | 5797 R300_DVOCLK_ALWAYS_ONb | 5798 RADEON_PIXCLK_BLEND_ALWAYS_ONb | 5799 RADEON_PIXCLK_GV_ALWAYS_ONb | 5800 R300_PIXCLK_DVO_ALWAYS_ONb | 5801 RADEON_PIXCLK_LVDS_ALWAYS_ONb | 5802 RADEON_PIXCLK_TMDS_ALWAYS_ONb | 5803 R300_PIXCLK_TRANS_ALWAYS_ONb | 5804 R300_PIXCLK_TVO_ALWAYS_ONb | 5805 R300_P2G2CLK_ALWAYS_ONb | 5806 R300_P2G2CLK_ALWAYS_ONb); 5807 OUTPLL(pScrn, RADEON_PIXCLKS_CNTL, tmp); 5808 5809 tmp = INPLL(pScrn, RADEON_MCLK_MISC); 5810 tmp |= (RADEON_MC_MCLK_DYN_ENABLE | 5811 RADEON_IO_MCLK_DYN_ENABLE); 5812 OUTPLL(pScrn, RADEON_MCLK_MISC, tmp); 5813 5814 tmp = INPLL(pScrn, RADEON_MCLK_CNTL); 5815 tmp |= (RADEON_FORCEON_MCLKA | 5816 RADEON_FORCEON_MCLKB); 5817 5818 tmp &= ~(RADEON_FORCEON_YCLKA | 5819 RADEON_FORCEON_YCLKB | 5820 RADEON_FORCEON_MC); 5821 5822 /* Some releases of vbios have set DISABLE_MC_MCLKA 5823 and DISABLE_MC_MCLKB bits in the vbios table. Setting these 5824 bits will cause H/W hang when reading video memory with dynamic clocking 5825 enabled. */ 5826 if ((tmp & R300_DISABLE_MC_MCLKA) && 5827 (tmp & R300_DISABLE_MC_MCLKB)) { 5828 /* If both bits are set, then check the active channels */ 5829 tmp = INPLL(pScrn, RADEON_MCLK_CNTL); 5830 if (info->RamWidth == 64) { 5831 if (INREG(RADEON_MEM_CNTL) & R300_MEM_USE_CD_CH_ONLY) 5832 tmp &= ~R300_DISABLE_MC_MCLKB; 5833 else 5834 tmp &= ~R300_DISABLE_MC_MCLKA; 5835 } else { 5836 tmp &= ~(R300_DISABLE_MC_MCLKA | 5837 R300_DISABLE_MC_MCLKB); 5838 } 5839 } 5840 5841 OUTPLL(pScrn, RADEON_MCLK_CNTL, tmp); 5842 } else { 5843 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5844 tmp &= ~(R300_SCLK_FORCE_VAP); 5845 tmp |= RADEON_SCLK_FORCE_CP; 5846 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5847 usleep(15000); 5848 5849 tmp = INPLL(pScrn, R300_SCLK_CNTL2); 5850 tmp &= ~(R300_SCLK_FORCE_TCL | 5851 R300_SCLK_FORCE_GA | 5852 R300_SCLK_FORCE_CBA); 5853 OUTPLL(pScrn, R300_SCLK_CNTL2, tmp); 5854 } 5855 } else { 5856 tmp = INPLL(pScrn, RADEON_CLK_PWRMGT_CNTL); 5857 5858 tmp &= ~(RADEON_ACTIVE_HILO_LAT_MASK | 5859 RADEON_DISP_DYN_STOP_LAT_MASK | 5860 RADEON_DYN_STOP_MODE_MASK); 5861 5862 tmp |= (RADEON_ENGIN_DYNCLK_MODE | 5863 (0x01 << RADEON_ACTIVE_HILO_LAT_SHIFT)); 5864 OUTPLL(pScrn, RADEON_CLK_PWRMGT_CNTL, tmp); 5865 usleep(15000); 5866 5867 tmp = INPLL(pScrn, RADEON_CLK_PIN_CNTL); 5868 tmp |= RADEON_SCLK_DYN_START_CNTL; 5869 OUTPLL(pScrn, RADEON_CLK_PIN_CNTL, tmp); 5870 usleep(15000); 5871 5872 /* When DRI is enabled, setting DYN_STOP_LAT to zero can cause some R200 5873 to lockup randomly, leave them as set by BIOS. 5874 */ 5875 tmp = INPLL(pScrn, RADEON_SCLK_CNTL); 5876 /*tmp &= RADEON_SCLK_SRC_SEL_MASK;*/ 5877 tmp &= ~RADEON_SCLK_FORCEON_MASK; 5878 5879 /*RAGE_6::A11 A12 A12N1 A13, RV250::A11 A12, R300*/ 5880 if (((info->ChipFamily == CHIP_FAMILY_RV250) && 5881 ((INREG(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) < 5882 RADEON_CFG_ATI_REV_A13)) || 5883 ((info->ChipFamily == CHIP_FAMILY_RV100) && 5884 ((INREG(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) <= 5885 RADEON_CFG_ATI_REV_A13))){ 5886 tmp |= RADEON_SCLK_FORCE_CP; 5887 tmp |= RADEON_SCLK_FORCE_VIP; 5888 } 5889 5890 OUTPLL(pScrn, RADEON_SCLK_CNTL, tmp); 5891 5892 if ((info->ChipFamily == CHIP_FAMILY_RV200) || 5893 (info->ChipFamily == CHIP_FAMILY_RV250) || 5894 (info->ChipFamily == CHIP_FAMILY_RV280)) { 5895 tmp = INPLL(pScrn, RADEON_SCLK_MORE_CNTL); 5896 tmp &= ~RADEON_SCLK_MORE_FORCEON; 5897 5898 /* RV200::A11 A12 RV250::A11 A12 */ 5899 if (((info->ChipFamily == CHIP_FAMILY_RV200) || 5900 (info->ChipFamily == CHIP_FAMILY_RV250)) && 5901 ((INREG(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) < 5902 RADEON_CFG_ATI_REV_A13)) { 5903 tmp |= RADEON_SCLK_MORE_FORCEON; 5904 } 5905 OUTPLL(pScrn, RADEON_SCLK_MORE_CNTL, tmp); 5906 usleep(15000); 5907 } 5908 5909 /* RV200::A11 A12, RV250::A11 A12 */ 5910 if (((info->ChipFamily == CHIP_FAMILY_RV200) || 5911 (info->ChipFamily == CHIP_FAMILY_RV250)) && 5912 ((INREG(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) < 5913 RADEON_CFG_ATI_REV_A13)) { 5914 tmp = INPLL(pScrn, RADEON_PLL_PWRMGT_CNTL); 5915 tmp |= RADEON_TCL_BYPASS_DISABLE; 5916 OUTPLL(pScrn, RADEON_PLL_PWRMGT_CNTL, tmp); 5917 } 5918 usleep(15000); 5919 5920 /*enable dynamic mode for display clocks (PIXCLK and PIX2CLK)*/ 5921 tmp = INPLL(pScrn, RADEON_PIXCLKS_CNTL); 5922 tmp |= (RADEON_PIX2CLK_ALWAYS_ONb | 5923 RADEON_PIX2CLK_DAC_ALWAYS_ONb | 5924 RADEON_PIXCLK_BLEND_ALWAYS_ONb | 5925 RADEON_PIXCLK_GV_ALWAYS_ONb | 5926 RADEON_PIXCLK_DIG_TMDS_ALWAYS_ONb | 5927 RADEON_PIXCLK_LVDS_ALWAYS_ONb | 5928 RADEON_PIXCLK_TMDS_ALWAYS_ONb); 5929 5930 OUTPLL(pScrn, RADEON_PIXCLKS_CNTL, tmp); 5931 usleep(15000); 5932 5933 tmp = INPLL(pScrn, RADEON_VCLK_ECP_CNTL); 5934 tmp |= (RADEON_PIXCLK_ALWAYS_ONb | 5935 RADEON_PIXCLK_DAC_ALWAYS_ONb); 5936 5937 OUTPLL(pScrn, RADEON_VCLK_ECP_CNTL, tmp); 5938 usleep(15000); 5939 } 5940 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Dynamic Clock Scaling Enabled\n"); 5941 break; 5942 default: 5943 break; 5944 } 5945} 5946