1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/nsc_gx2_driver.c,v 1.9tsi Exp $ */ 2/* 3 * $Workfile: nsc_gx2_driver.c $ 4 * $Revision: 1.2 $ 5 * $Author: mrg $ 6 * 7 * File Contents: This is the main module configures the interfacing 8 * with the X server. The individual modules will be 9 * loaded based upon the options selected from the 10 * XF86Config. This file also has modules for finding 11 * supported modes, turning on the modes based on options. 12 * 13 * Project: Geode Xfree Frame buffer device driver. 14 * 15 */ 16 17/* 18 * NSC_LIC_ALTERNATIVE_PREAMBLE 19 * 20 * Revision 1.0 21 * 22 * National Semiconductor Alternative GPL-BSD License 23 * 24 * National Semiconductor Corporation licenses this software 25 * ("Software"): 26 * 27 * National Xfree frame buffer driver 28 * 29 * under one of the two following licenses, depending on how the 30 * Software is received by the Licensee. 31 * 32 * If this Software is received as part of the Linux Framebuffer or 33 * other GPL licensed software, then the GPL license designated 34 * NSC_LIC_GPL applies to this Software; in all other circumstances 35 * then the BSD-style license designated NSC_LIC_BSD shall apply. 36 * 37 * END_NSC_LIC_ALTERNATIVE_PREAMBLE */ 38 39/* NSC_LIC_BSD 40 * 41 * National Semiconductor Corporation Open Source License for 42 * 43 * National Xfree frame buffer driver 44 * 45 * (BSD License with Export Notice) 46 * 47 * Copyright (c) 1999-2001 48 * National Semiconductor Corporation. 49 * All rights reserved. 50 * 51 * Redistribution and use in source and binary forms, with or without 52 * modification, are permitted provided that the following conditions 53 * are met: 54 * 55 * * Redistributions of source code must retain the above copyright 56 * notice, this list of conditions and the following disclaimer. 57 * 58 * * Redistributions in binary form must reproduce the above 59 * copyright notice, this list of conditions and the following 60 * disclaimer in the documentation and/or other materials provided 61 * with the distribution. 62 * 63 * * Neither the name of the National Semiconductor Corporation nor 64 * the names of its contributors may be used to endorse or promote 65 * products derived from this software without specific prior 66 * written permission. 67 * 68 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 69 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 70 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 71 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 72 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY 73 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 74 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 75 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 76 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 77 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE, 78 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY 79 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 80 * OF SUCH DAMAGE. 81 * 82 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF 83 * YOUR JURISDICTION. It is licensee's responsibility to comply with 84 * any export regulations applicable in licensee's jurisdiction. Under 85 * CURRENT (2001) U.S. export regulations this software 86 * is eligible for export from the U.S. and can be downloaded by or 87 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed 88 * destinations which include Cuba, Iraq, Libya, North Korea, Iran, 89 * Syria, Sudan, Afghanistan and any other country to which the U.S. 90 * has embargoed goods and services. 91 * 92 * END_NSC_LIC_BSD */ 93 94/* NSC_LIC_GPL 95 * 96 * National Semiconductor Corporation Gnu General Public License for 97 * 98 * National Xfree frame buffer driver 99 * 100 * (GPL License with Export Notice) 101 * 102 * Copyright (c) 1999-2001 103 * National Semiconductor Corporation. 104 * All rights reserved. 105 * 106 * Redistribution and use in source and binary forms, with or without 107 * modification, are permitted under the terms of the GNU General 108 * Public License as published by the Free Software Foundation; either 109 * version 2 of the License, or (at your option) any later version 110 * 111 * In addition to the terms of the GNU General Public License, neither 112 * the name of the National Semiconductor Corporation nor the names of 113 * its contributors may be used to endorse or promote products derived 114 * from this software without specific prior written permission. 115 * 116 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 117 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 118 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 119 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 120 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY 121 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 122 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 123 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 124 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 125 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE, 126 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY 127 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 128 * OF SUCH DAMAGE. See the GNU General Public License for more details. 129 * 130 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF 131 * YOUR JURISDICTION. It is licensee's responsibility to comply with 132 * any export regulations applicable in licensee's jurisdiction. Under 133 * CURRENT (2001) U.S. export regulations this software 134 * is eligible for export from the U.S. and can be downloaded by or 135 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed 136 * destinations which include Cuba, Iraq, Libya, North Korea, Iran, 137 * Syria, Sudan, Afghanistan and any other country to which the U.S. 138 * has embargoed goods and services. 139 * 140 * You should have received a copy of the GNU General Public License 141 * along with this file; if not, write to the Free Software Foundation, 142 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 143 * 144 * END_NSC_LIC_GPL */ 145 146#ifdef HAVE_CONFIG_H 147#include "config.h" 148#endif 149 150#define DEBUG(x) 151#define GEODE_TRACE 0 152 153/* Includes that are used by all drivers */ 154#include "xf86.h" 155#include "xf86_OSproc.h" 156#include "xf86Resources.h" 157 158/* We may want inb() and outb() */ 159#include "compiler.h" 160 161/* We may want to access the PCI config space */ 162#include "xf86PciInfo.h" 163#include "xf86Pci.h" 164 165#define INT10_SUPPORT 1 166 167/* Colormap handling stuff */ 168#include "xf86cmap.h" 169 170#define RC_MAX_DEPTH 24 171 172/* Frame buffer stuff */ 173#include "fb.h" 174 175#include "shadowfb.h" 176 177/* Machine independent stuff */ 178#include "mipointer.h" 179#include "mibank.h" 180#include "micmap.h" 181#include "vgaHW.h" 182#include "vbe.h" 183 184/* Check for some extensions */ 185#ifdef XFreeXDGA 186#define _XF86_DGA_SERVER_ 187#include <X11/extensions/xf86dgastr.h> 188#endif /* XFreeXDGA */ 189 190#include "globals.h" 191#include "opaque.h" 192#define DPMS_SERVER 193#include <X11/extensions/dpms.h> 194 195/* Our private include file (this also includes the durango headers) */ 196#include "nsc.h" 197#if !defined(STB_X) 198#include "nsc_gx2_vga.c" 199#endif /* STB_X */ 200 201#if GEODE_TRACE 202/* ANSI C does not allow var arg macros */ 203#define GeodeDebug(args) DebugPort(DCount++);ErrorF args 204#else 205#define GeodeDebug(args) 206#endif 207 208extern SymTabRec GeodeChipsets[]; 209extern PciChipsets GeodePCIchipsets[]; 210extern OptionInfoRec GeodeOptions[]; 211 212/* Forward definitions */ 213static Bool GX2PreInit(ScrnInfoPtr, int); 214static Bool GX2ScreenInit(int, ScreenPtr, int, char **); 215static Bool GX2EnterVT(int, int); 216static void GX2LeaveVT(int, int); 217static void GX2FreeScreen(int, int); 218void GX2AdjustFrame(int, int, int, int); 219Bool GX2SwitchMode(int, DisplayModePtr, int); 220static ModeStatus GX2ValidMode(int, DisplayModePtr, Bool, int); 221static void GX2LoadPalette(ScrnInfoPtr pScreenInfo, 222 int numColors, int *indizes, 223 LOCO * colors, VisualPtr pVisual); 224static Bool GX2MapMem(ScrnInfoPtr); 225static Bool GX2UnmapMem(ScrnInfoPtr); 226static void gx2_set_DvLineSize(unsigned int pitch); 227 228extern Bool GX2AccelInit(ScreenPtr pScreen); 229extern Bool GX2HWCursorInit(ScreenPtr pScreen); 230extern void GX2HideCursor(ScrnInfoPtr pScreenInfo); 231extern void GX2ShowCursor(ScrnInfoPtr pScreenInfo); 232extern void GX2PointerMoved(int index, int x, int y); 233extern void GX2RefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox); 234extern void GX2RefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox); 235extern void GX2RefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox); 236extern void GX2RefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox); 237extern void GX2RefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox); 238extern void GX2InitVideo(ScreenPtr pScreen); 239extern Bool GX2DGAInit(ScreenPtr pScreen); 240extern void GX2LoadCursorImage(ScrnInfoPtr pScreenInfo, unsigned char *src); 241 242#if !defined(STB_X) 243extern unsigned char *XpressROMPtr; 244#endif /* STB_X */ 245 246/* Existing Processor Models */ 247#define GX1 0x1 248#define GX2 0x2 249#define GX2_CRT 0x6 250#define GX2_TFT 0xA 251 252/* List of symbols from other modules that this module references.The purpose 253* is that to avoid unresolved symbol warnings 254*/ 255extern const char *nscVgahwSymbols[]; 256extern const char *nscVbeSymbols[]; 257extern const char *nscInt10Symbols[]; 258 259extern const char *nscFbSymbols[]; 260extern const char *nscXaaSymbols[]; 261extern const char *nscRamdacSymbols[]; 262extern const char *nscShadowSymbols[]; 263 264void GX2SetupChipsetFPtr(ScrnInfoPtr pScrn); 265GeodePtr GX2GetRec(ScrnInfoPtr pScreenInfo); 266void get_flatpanel_info(const char *options, int *W, int *H, 267 int *D, int *C, int *T); 268void gx2_clear_screen(int width, int height); 269void EnableDACPower(void); 270void redcloud_gfx_2_vga_fix(void); 271 272void 273GX2SetupChipsetFPtr(ScrnInfoPtr pScrn) 274{ 275 GeodeDebug(("GX2SetupChipsetFPtr!\n")); 276 277 pScrn->PreInit = GX2PreInit; 278 pScrn->ScreenInit = GX2ScreenInit; 279 pScrn->SwitchMode = GX2SwitchMode; 280 pScrn->AdjustFrame = GX2AdjustFrame; 281 pScrn->EnterVT = GX2EnterVT; 282 pScrn->LeaveVT = GX2LeaveVT; 283 pScrn->FreeScreen = GX2FreeScreen; 284 pScrn->ValidMode = GX2ValidMode; 285} 286 287/*---------------------------------------------------------------------------- 288 * GX2GetRec. 289 * 290 * Description :This function allocate an GeodeRec and hooked into 291 * pScreenInfo str driverPrivate member of ScreeenInfo 292 * structure. 293 * Parameters. 294 * pScreenInfo :Pointer handle to the screenonfo structure. 295 * 296 * Returns :allocated pScreeninfo structure. 297 * 298 * Comments :none 299 * 300*---------------------------------------------------------------------------- 301*/ 302GeodePtr 303GX2GetRec(ScrnInfoPtr pScreenInfo) 304{ 305 if (!pScreenInfo->driverPrivate) { 306 GeodePtr pGeode; 307 308 pGeode = pScreenInfo->driverPrivate = xnfcalloc(sizeof(GeodeRec), 1); 309#if INT10_SUPPORT 310 pGeode->vesa = xcalloc(sizeof(VESARec), 1); 311#endif 312 } 313 return GEODEPTR(pScreenInfo); 314} 315 316/*---------------------------------------------------------------------------- 317 * GX2FreeRec. 318 * 319 * Description :This function deallocate an GeodeRec and freed from 320 * pScreenInfo str driverPrivate member of ScreeenInfo 321 * structure. 322 * Parameters. 323 * pScreenInfo :Pointer handle to the screenonfo structure. 324 * 325 * Returns :none 326 * 327 * Comments :none 328 * 329*---------------------------------------------------------------------------- 330*/ 331static void 332GX2FreeRec(ScrnInfoPtr pScreenInfo) 333{ 334 if (pScreenInfo->driverPrivate == NULL) { 335 return; 336 } 337 xfree(pScreenInfo->driverPrivate); 338 pScreenInfo->driverPrivate = NULL; 339} 340 341/*---------------------------------------------------------------------------- 342 * GX2SaveScreen. 343 * 344 * Description :This is todo the screen blanking 345 * 346 * Parameters. 347 * pScreen :Handle to ScreenPtr structure. 348 * mode :mode is used by vgaHWSaveScren to check blnak os on. 349 * 350 * Returns :TRUE on success and FALSE on failure. 351 * 352 * Comments :none 353*---------------------------------------------------------------------------- 354*/ 355static Bool 356GX2SaveScreen(ScreenPtr pScreen, int mode) 357{ 358#if !defined(STB_X) 359 ScrnInfoPtr pScreenInfo = xf86Screens[pScreen->myNum]; 360 361 GeodeDebug(("GX2SaveScreen!\n")); 362 363 if (!pScreenInfo->vtSema) 364 return vgaHWSaveScreen(pScreen, mode); 365 366#endif /* STB_X */ 367 return TRUE; 368} 369 370/*---------------------------------------------------------------------------- 371 * get_flatpanel_info. 372 * 373 * Description :This gets the values of the flatpanel attached. 374 * 375 * Parameters: 376 * options : Pointer to the display options. 377 * W: Pointer to the width of the panel 378 * H: Pointer to the height of the panel 379 * D: Pointer to the depth of the panel. 380 * C: Pointer to the color of the panel. 381 * T: Pointer to the type of the panel. 382 * Returns : none. 383 * 384 * Comments :none 385 *------------------------------------------------------------------------ 386 */ 387void 388get_flatpanel_info(const char *options, int *W, int *H, 389 int *D, int *C, int *T) 390{ 391 char *pnl_opt; 392 393 pnl_opt = strtok((char *)options, ":"); 394 *W = strtoul(pnl_opt, NULL, 0); 395 pnl_opt = strtok(NULL, ":"); 396 *H = strtoul(pnl_opt, NULL, 0); 397 pnl_opt = strtok(NULL, ":"); 398 *D = strtoul(pnl_opt, NULL, 0); 399 pnl_opt = strtok(NULL, ":"); 400 *C = strtoul(pnl_opt, NULL, 0); 401 pnl_opt = strtok(NULL, ":"); 402 *T = strtoul(pnl_opt, NULL, 0); 403 404 *C = (*C) ? PNL_COLOR_PANEL : PNL_MONO_PANEL; 405 406 switch (*T) { 407 case 0: 408 *T = PNL_SSTN; 409 break; 410 case 1: 411 *T = PNL_DSTN; 412 break; 413 case 2: 414 default: 415 *T = PNL_TFT; 416 break; 417 } 418 419 if ((*W != 640) && (*W != 800) && (*W != 1024)) 420 *W = 640; 421 422 if ((*H != 480) && (*H != 600) && (*H != 768)) 423 *H = 480; 424} 425 426static void 427GX2ProbeDDC(ScrnInfoPtr pScrn, int index) 428{ 429 vbeInfoPtr pVbe; 430 431 if (xf86LoadSubModule(pScrn, "vbe")) { 432 pVbe = VBEInit(NULL, index); 433 ConfiguredMonitor = vbeDoEDID(pVbe, NULL); 434 vbeFree(pVbe); 435 } 436} 437 438/*---------------------------------------------------------------------------- 439 * GX2PreInit. 440 * 441 * Description :This function is called only once ate teh server startup 442 * 443 * Parameters. 444 * pScreenInfo :Handle to ScreenPtr structure. 445 * flags :flags may be used to check the probeed one with config. 446 * 447 * Returns :TRUE on success and FALSE on failure. 448 * 449 * Comments :none. 450 *---------------------------------------------------------------------------- 451 */ 452static Bool 453GX2PreInit(ScrnInfoPtr pScreenInfo, int flags) 454{ 455 static ClockRange GeodeClockRange = 456 { NULL, 25175, 229500, 0, FALSE, TRUE, 1, 1, 0 }; 457 MessageType from; 458 int i = 0; 459 GeodePtr pGeode; 460#if defined(STB_X) 461 GAL_ADAPTERINFO sAdapterInfo; 462#endif /* STB_X */ 463 unsigned int PitchInc = 0, minPitch = 0, maxPitch = 0; 464 unsigned int minHeight = 0, maxHeight = 0; 465 unsigned int SupportFlags; 466 const char *s; 467 char **modes; 468 469#if INT10_SUPPORT 470 VESAPtr pVesa; 471#endif 472 473 DCount = 10; 474 GeodeDebug(("GX2PreInit!\n")); 475 /* Allocate driver private structure */ 476 if (!(pGeode = GX2GetRec(pScreenInfo))) 477 return FALSE; 478 479 /* This is the general case */ 480 for (i = 0; i < pScreenInfo->numEntities; i++) { 481 pGeode->pEnt = xf86GetEntityInfo(pScreenInfo->entityList[i]); 482 if (pGeode->pEnt->resources) 483 return FALSE; 484 pGeode->Chipset = pGeode->pEnt->chipset; 485 pScreenInfo->chipset = (char *)xf86TokenToString(GeodeChipsets, 486 pGeode->pEnt->chipset); 487 } 488 489 if (flags & PROBE_DETECT) { 490 GX2ProbeDDC(pScreenInfo, pGeode->pEnt->index); 491 return TRUE; 492 } 493#if INT10_SUPPORT 494 if (!xf86LoadSubModule(pScreenInfo, "int10")) 495 return FALSE; 496 xf86LoaderReqSymLists(nscInt10Symbols, NULL); 497#endif 498 pGeode->FBVGAActive = 0; /* KFB will Knock of VGA */ 499 500#if !defined(STB_X) 501 /* If the vgahw module would be needed it would be loaded here */ 502 if (!xf86LoadSubModule(pScreenInfo, "vgahw")) { 503 return FALSE; 504 } 505 xf86LoaderReqSymLists(nscVgahwSymbols, NULL); 506#endif /* STB_X */ 507 GeodeDebug(("GX2PreInit(1)!\n")); 508 /* Do the durango hardware detection */ 509#if defined(STB_X) 510 if (!Gal_initialize_interface()) { 511 GeodeDebug(("GALintialize fail GX2PreInit(1.00)!\n")); 512 return FALSE; 513 } 514 515 if (Gal_get_adapter_info(&sAdapterInfo)) { 516 pGeode->cpu_version = sAdapterInfo.dwCPUVersion; 517 518 /* find the base chipset core. Currently there can be only one 519 * chip active at any time. 520 */ 521 if ((pGeode->cpu_version & 0xFF) == GFX_CPU_REDCLOUD) { 522 if (sAdapterInfo.dwCPUType) 523 pGeode->DetectedChipSet = GX2_TFT; 524 else 525 pGeode->DetectedChipSet = GX2_CRT; 526 } 527 528 DEBUGMSG(1, 529 (0, X_NONE, "Detected BaseChip %d, %d\n", 530 pGeode->DetectedChipSet, sAdapterInfo.dwCPUType)); 531 532 pGeode->vid_version = sAdapterInfo.dwVideoVersion; 533 pGeode->FBSize = sAdapterInfo.dwFrameBufferSize; 534 /* update the max clock from the one system suports */ 535 GeodeClockRange.maxClock = sAdapterInfo.dwMaxSupportedPixelClock; 536 pGeode->FBLinearAddr = sAdapterInfo.dwFrameBufferBase; 537#if 0 538 pGeode->FBBase = (unsigned char *)xf86MapVidMem(pScreenInfo->scrnIndex, 539 VIDMEM_FRAMEBUFFER, 540 pGeode->FBLinearAddr, 541 pGeode->FBSize); 542#endif 543 if (!GX2MapMem(pScreenInfo)) 544 return FALSE; 545 DEBUGMSG(1, (0, X_NONE, "CPU=%x vid %x FB %x FBAdd %X\n", 546 pGeode->cpu_version, pGeode->vid_version, pGeode->FBSize, 547 pGeode->FBLinearAddr)); 548 } else { 549 return FALSE; 550 } 551#else /* STB */ 552 pGeode->cpu_version = gfx_detect_cpu(); 553 554 /* find the base chipset core. Currently there can be only one 555 * chip active at any time. 556 */ 557/* pGeode->DetectedChipSet = GX1; */ 558 if ((pGeode->cpu_version & 0xFF) == GFX_CPU_REDCLOUD) 559 pGeode->DetectedChipSet = GX2; 560 GeodeDebug(("Detected BaseChip (%d)\n", pGeode->DetectedChipSet)); 561 { 562 Q_WORD msrValue; 563 564 /* GX2 : Can have CRT or TFT only */ 565 gfx_msr_read(RC_ID_DF, MBD_MSR_CONFIG, &msrValue); 566 pGeode->DetectedChipSet = 567 ((msrValue.low & RCDF_CONFIG_FMT_MASK) == 568 RCDF_CONFIG_FMT_FP) ? GX2_TFT : GX2_CRT; 569 GeodeDebug(("Gx2 for %s\n", 570 ((pGeode->DetectedChipSet == GX2_TFT) ? "TFT" : "CRT"))); 571 } 572 GeodeDebug(("GX2PreInit(1.1)!\n")); 573 pGeode->vid_version = gfx_detect_video(); 574 GeodeDebug(("GX2PreInit(1.2)!\n")); 575 pGeode->FBLinearAddr = gfx_get_frame_buffer_base(); 576 GeodeDebug(("GX2PreInit(1.3)!\n")); 577 pGeode->FBSize = gfx_get_frame_buffer_size(); 578 GeodeDebug(("GX2PreInit(1.4)!\n")); 579 /* update the max clock from the one system suports */ 580 GeodeClockRange.maxClock = gfx_get_max_supported_pixel_clock(); 581 582 GeodeDebug(("GX2PreInit(1.5)!\n")); 583 /* SET DURANGO REGISTER POINTERS 584 * * The method of mapping from a physical address to a linear address 585 * * is operating system independent. Set variables to linear address. 586 */ 587 if (pGeode->DetectedChipSet & GX2) { 588 pGeode->cpu_reg_size = 0x4000; 589 pGeode->gp_reg_size = 0x4000; 590 pGeode->vid_reg_size = 0x4000; 591 } else { 592 pGeode->cpu_reg_size = 0x9000; 593 pGeode->vid_reg_size = 0x1000; 594 } 595 596 if (!GX2MapMem(pScreenInfo)) 597 return FALSE; 598 599 /* check if VGA is active */ 600 /* This routine saves the current VGA state in Durango VGA structure */ 601 /* check if VGA is active */ 602 pGeode->FBVGAActive = gu2_get_vga_active(); 603 604#endif /* STB_X */ 605 DEBUGMSG(1, (0, X_PROBED, "VGA = %d\n", pGeode->FBVGAActive)); 606 607 /* Fill in the monitor field */ 608 pScreenInfo->monitor = pScreenInfo->confScreen->monitor; 609 GeodeDebug(("GX2PreInit(2)!\n")); 610 SupportFlags = Support24bppFb | Support32bppFb; 611 GeodeDebug(("GX2PreInit(2)!\n")); 612 /* Determine depth, bpp, etc. */ 613 if (!xf86SetDepthBpp(pScreenInfo, 0, 0, 0, SupportFlags)) { 614 return FALSE; 615 } else { 616 if (!((pScreenInfo->depth == 8) || 617 (pScreenInfo->depth == 16) || 618 (pScreenInfo->depth == 24))) { 619 /* Depth not supported */ 620 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_ERROR, 621 "Given depth (%d bpp) is not supported by this driver\n", 622 pScreenInfo->depth)); 623 return FALSE; 624 } 625 } 626 627 /*This must happen after pScreenInfo->display has been set 628 * * because xf86SetWeight references it. 629 */ 630 if (pScreenInfo->depth > 8) { 631 /* The defaults are OK for us */ 632 rgb BitsPerComponent = { 0, 0, 0 }; 633 rgb BitMask = { 0, 0, 0 }; 634 635 if (pScreenInfo->depth > 16) { 636 /* we are operating in 24 bpp, Readcloud */ 637 BitsPerComponent.red = 8; 638 BitsPerComponent.green = 8; 639 BitsPerComponent.blue = 8; 640 641 BitMask.red = 0xFF0000; 642 BitMask.green = 0x00FF00; 643 BitMask.blue = 0x0000FF; 644 } 645 if (!xf86SetWeight(pScreenInfo, BitsPerComponent, BitMask)) { 646 return FALSE; 647 } else { 648 /* XXX Check if the returned weight is supported */ 649 } 650 } 651 652 xf86PrintDepthBpp(pScreenInfo); 653 654 GeodeDebug(("GX2PreInit(3)!\n")); 655 656 if (!xf86SetDefaultVisual(pScreenInfo, -1)) 657 return FALSE; 658 659 GeodeDebug(("GX2PreInit(4)!\n")); 660 661 /* The new cmap layer needs this to be initialized */ 662 if (pScreenInfo->depth > 1) { 663 Gamma zeros = { 0.0, 0.0, 0.0 }; 664 665 if (!xf86SetGamma(pScreenInfo, zeros)) { 666 return FALSE; 667 } 668 } 669 GeodeDebug(("GX2PreInit(5)!\n")); 670 671 /* We use a programmable clock */ 672 pScreenInfo->progClock = TRUE; 673 674 /*Collect all of the relevant option flags 675 * *(fill in pScreenInfo->options) 676 */ 677 xf86CollectOptions(pScreenInfo, NULL); 678 679 /*Process the options */ 680 xf86ProcessOptions(pScreenInfo->scrnIndex, pScreenInfo->options, 681 GeodeOptions); 682 683#if INT10_SUPPORT 684 pVesa = pGeode->vesa; 685 /* Initialize Vesa record */ 686 687 if ((pVesa->pInt = xf86InitInt10(pGeode->pEnt->index)) == NULL) { 688 xf86DrvMsg(0, X_ERROR, "Int10 initialization failed.\n"); 689 return (FALSE); 690 } 691#endif 692 /*Set the bits per RGB for 8bpp mode */ 693 if (pScreenInfo->depth == 8) { 694 /* Default to 8 */ 695 pScreenInfo->rgbBits = 8; 696 } 697 from = X_DEFAULT; 698 699 /* 700 * *The preferred method is to use the "hw cursor" option as a tri-state 701 * *option, with the default set above. 702 */ 703 pGeode->HWCursor = TRUE; 704 if (xf86GetOptValBool(GeodeOptions, OPTION_HW_CURSOR, &pGeode->HWCursor)) { 705 from = X_CONFIG; 706 } 707 /* For compatibility, accept this too (as an override) */ 708 if (xf86ReturnOptValBool(GeodeOptions, OPTION_SW_CURSOR, FALSE)) { 709 from = X_CONFIG; 710 pGeode->HWCursor = FALSE; 711 } 712 DEBUGMSG(1, (pScreenInfo->scrnIndex, from, "Using %s cursor\n", 713 pGeode->HWCursor ? "HW" : "SW")); 714 715 pGeode->Compression = TRUE; 716 if (xf86ReturnOptValBool(GeodeOptions, OPTION_NOCOMPRESSION, FALSE)) { 717 pGeode->Compression = FALSE; 718 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, "NoCompression\n")); 719 } 720 721 pGeode->NoAccel = FALSE; 722 if (xf86ReturnOptValBool(GeodeOptions, OPTION_NOACCEL, FALSE)) { 723 pGeode->NoAccel = TRUE; 724 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, "Acceleration \ 725 disabled\n")); 726 } 727 728 if (!xf86GetOptValInteger(GeodeOptions, OPTION_OSM_IMG_BUFS, 729 &(pGeode->NoOfImgBuffers))) 730 pGeode->NoOfImgBuffers = DEFAULT_NUM_OF_BUF; /* default # of buffers */ 731 if (pGeode->NoOfImgBuffers <= 0) 732 pGeode->NoOfImgBuffers = 0; 733 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, 734 "NoOfImgBuffers = %d\n", pGeode->NoOfImgBuffers)); 735 736 pGeode->Panel = FALSE; 737 if (xf86ReturnOptValBool(GeodeOptions, OPTION_FLATPANEL, FALSE)) { 738 DEBUGMSG(0, (pScreenInfo->scrnIndex, X_CONFIG, "FlatPanel Selected\n")); 739 pGeode->Panel = TRUE; 740 } 741 742 /* Force the Panel on if on a GX2 TFT part, no crt support */ 743 if (pGeode->DetectedChipSet == GX2_TFT) { 744 pGeode->Panel = TRUE; 745 } 746 747 /* If on a CRT and Panel flag set, disable Panel */ 748 if ((pGeode->DetectedChipSet == GX2_CRT) && (pGeode->Panel)) 749 pGeode->Panel = FALSE; 750 751 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, 752 "Quering FP Bios %d\n", pGeode->Panel)); 753 754 /* if FP not supported in BIOS, then turn off user option */ 755 if (pGeode->Panel) { 756 /* check if bios supports FP */ 757#if defined(STB_X) 758 Gal_pnl_enabled_in_bios(&pGeode->Panel); 759 Gal_pnl_info_from_bios(&pGeode->FPBX, &pGeode->FPBY, 760 &pGeode->FPBB, &pGeode->FPBF); 761#else /* STB_X */ 762 pGeode->Panel = Pnl_IsPanelEnabledInBIOS(); 763 Pnl_GetPanelInfoFromBIOS(&pGeode->FPBX, &pGeode->FPBY, 764 &pGeode->FPBB, &pGeode->FPBF); 765#endif /* STB_X */ 766 } 767 768 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, 769 "Quering FP Bios %d %d %d %d\n", 770 pGeode->FPBX, pGeode->FPBY, pGeode->FPBB, pGeode->FPBF)); 771 772 /* if panel not selected and Panel can be supported. 773 * Power down the panel. 774 */ 775 if (!pGeode->Panel) { 776#if defined(STB_X) 777 Gal_pnl_powerdown(); 778#else /* STB_X */ 779 Pnl_PowerDown(); 780#endif /* STB_X */ 781 } else { 782#if defined(STB_X) 783 Gal_pnl_powerup(); 784#else 785 Pnl_PowerUp(); 786#endif /* STB_X */ 787 } 788 789 pGeode->ShadowFB = FALSE; 790 if (xf86ReturnOptValBool(GeodeOptions, OPTION_SHADOW_FB, FALSE)) { 791 pGeode->ShadowFB = TRUE; 792 pGeode->NoAccel = TRUE; 793 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, 794 "Using \"Shadow Framebuffer\" - acceleration disabled\n")); 795 } 796 797 pGeode->Rotate = 0; 798 if ((s = xf86GetOptValString(GeodeOptions, OPTION_ROTATE))) { 799 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, "Rotating - %s\n", s)); 800 if (!xf86NameCmp(s, "CW")) { 801 pGeode->ShadowFB = TRUE; 802 pGeode->NoAccel = TRUE; 803 pGeode->HWCursor = FALSE; 804 pGeode->Rotate = 1; 805 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, 806 "Rotating screen clockwise - acceleration disabled\n")); 807 } else { 808 if (!xf86NameCmp(s, "CCW")) { 809 pGeode->ShadowFB = TRUE; 810 pGeode->NoAccel = TRUE; 811 pGeode->HWCursor = FALSE; 812 pGeode->Rotate = -1; 813 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, 814 "Rotating screen counter clockwise - acceleration \ 815 disabled\n")); 816 } else { 817 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, 818 "\"%s\" is not a valid value for Option \"Rotate\"\n", 819 s)); 820 DEBUGMSG(1, 821 (pScreenInfo->scrnIndex, X_INFO, 822 "Valid options are \"CW\" or \"CCW\"\n")); 823 } 824 } 825 } 826 827 /* XXX Init further private data here */ 828 829 /* 830 * * This shouldn't happen because such problems should be caught in 831 * * GeodeProbe(), but check it just in case. 832 */ 833 if (pScreenInfo->chipset == NULL) { 834 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_ERROR, 835 "ChipID 0x%04X is not recognised\n", pGeode->Chipset)); 836 return FALSE; 837 } 838 if (pGeode->Chipset < 0) { 839 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_ERROR, 840 "Chipset \"%s\" is not recognised\n", 841 pScreenInfo->chipset)); 842 return FALSE; 843 } 844 GeodeDebug(("GX2PreInit(6)!\n")); 845 846 /* 847 * * Init the screen with some values 848 */ 849#if !defined(STB_X) 850 851 DEBUGMSG(1, (pScreenInfo->scrnIndex, from, 852 "Video I/O registers at 0x%08lX\n", 853 (unsigned long)VGAHW_GET_IOBASE())); 854#endif /* STB_X */ 855 856 if (pScreenInfo->memPhysBase == 0) { 857 from = X_PROBED; 858#if defined(STB_X) 859 pScreenInfo->memPhysBase = sAdapterInfo.dwFrameBufferBase; 860#else /* STB_X */ 861 pScreenInfo->memPhysBase = gfx_get_frame_buffer_base(); 862#endif /* STB_X */ 863 } 864 DEBUGMSG(1, (pScreenInfo->scrnIndex, from, 865 "Linear framebuffer at 0x%08lX\n", 866 (unsigned long)pScreenInfo->memPhysBase)); 867 868 if (pGeode->pEnt->device->videoRam == 0) { 869 from = X_PROBED; 870 pScreenInfo->videoRam = pGeode->FBSize / 1024; 871 } else { 872 pScreenInfo->videoRam = pGeode->pEnt->device->videoRam; 873 from = X_CONFIG; 874 } 875 DEBUGMSG(1, (pScreenInfo->scrnIndex, from, 876 "VideoRam: %d kByte\n", 877 (unsigned long)pScreenInfo->videoRam)); 878 879 GeodeDebug(("GX2PreInit(7)!\n")); 880 881 /* 882 * * xf86ValidateModes will check that the mode HTotal and VTotal values 883 * * don't exceed the chipset's limit if pScreenInfo->maxHValue adn 884 * * pScreenInfo->maxVValue are set. Since our GX2ValidMode() 885 * * already takes care of this, we don't worry about setting them here. 886 */ 887 /* Select valid modes from those available */ 888 /* 889 * * min pitch 1024, max 2048 (Pixel count) 890 * * min height 480, max 1024 (Pixel count) 891 */ 892 minPitch = 1024; 893 maxPitch = 4096; /* Can support upto 1600x1200 32Bpp */ 894 minHeight = 480; 895 maxHeight = 1200; /* Can support upto 1600x1200 32Bpp */ 896 if (pScreenInfo->depth > 16) { 897 PitchInc = 4096; 898 } else if (pScreenInfo->depth == 16) { 899 PitchInc = 2048; 900 } else { 901 PitchInc = 1024; 902 } 903 PitchInc <<= 3; /* in bits */ 904 905 /* by default use what user sets in the XF86Config file */ 906 modes = pScreenInfo->display->modes; 907 908 i = xf86ValidateModes(pScreenInfo, 909 pScreenInfo->monitor->Modes, 910 modes, 911 &GeodeClockRange, 912 NULL, minPitch, maxPitch, 913 PitchInc, minHeight, maxHeight, 914 pScreenInfo->display->virtualX, 915 pScreenInfo->display->virtualY, 916#if defined(STB_X) 917 sAdapterInfo.dwFrameBufferSize, 918#else /* STB_X */ 919 gfx_get_frame_buffer_size(), 920#endif /* STB_X */ 921 LOOKUP_BEST_REFRESH); 922 923 DEBUGMSG(1, (pScreenInfo->scrnIndex, from, 924 "xf86ValidateModes: %d %d %d\n", 925 pScreenInfo->virtualX, 926 pScreenInfo->virtualY, pScreenInfo->displayWidth)); 927 if (i == -1) { 928 GX2FreeRec(pScreenInfo); 929 return FALSE; 930 } 931 GeodeDebug(("GX2PreInit(8)!\n")); 932 933 /* Prune the modes marked as invalid */ 934 xf86PruneDriverModes(pScreenInfo); 935 936 GeodeDebug(("GX2PreInit(9)!\n")); 937 if (i == 0 || pScreenInfo->modes == NULL) { 938 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_ERROR, 939 "No valid modes found\n")); 940 GX2FreeRec(pScreenInfo); 941 return FALSE; 942 } 943 GeodeDebug(("GX2PreInit(10)!\n")); 944 945 xf86SetCrtcForModes(pScreenInfo, 0); 946 GeodeDebug(("GX2PreInit(11)!\n")); 947 948 /* Set the current mode to the first in the list */ 949 pScreenInfo->currentMode = pScreenInfo->modes; 950 GeodeDebug(("GX2PreInit(12)!\n")); 951 952 /* Print the list of modes being used */ 953 xf86PrintModes(pScreenInfo); 954 GeodeDebug(("GX2PreInit(13)!\n")); 955 956 /* Set the display resolution */ 957 xf86SetDpi(pScreenInfo, 0, 0); 958 GeodeDebug(("GX2PreInit(14)!\n")); 959 960 if (xf86LoadSubModule(pScreenInfo, "fb") == NULL) { 961 GX2FreeRec(pScreenInfo); 962 return FALSE; 963 } 964 965 xf86LoaderReqSymLists(nscFbSymbols, NULL); 966 GeodeDebug(("GX2PreInit(15)!\n")); 967 if (pGeode->NoAccel == FALSE) { 968 if (!xf86LoadSubModule(pScreenInfo, "xaa")) { 969 GX2FreeRec(pScreenInfo); 970 return FALSE; 971 } 972 xf86LoaderReqSymLists(nscXaaSymbols, NULL); 973 } 974 GeodeDebug(("GX2PreInit(16)!\n")); 975 if (pGeode->HWCursor == TRUE) { 976 if (!xf86LoadSubModule(pScreenInfo, "ramdac")) { 977 GX2FreeRec(pScreenInfo); 978 return FALSE; 979 } 980 xf86LoaderReqSymLists(nscRamdacSymbols, NULL); 981 } 982 GeodeDebug(("GX2PreInit(17)!\n")); 983 /* Load shadowfb if needed */ 984 if (pGeode->ShadowFB) { 985 if (!xf86LoadSubModule(pScreenInfo, "shadowfb")) { 986 GX2FreeRec(pScreenInfo); 987 return FALSE; 988 } 989 xf86LoaderReqSymLists(nscShadowSymbols, NULL); 990 } 991 GeodeDebug(("GX2PreInit(18)!\n")); 992 if (xf86RegisterResources(pGeode->pEnt->index, NULL, ResExclusive)) { 993 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_ERROR, 994 "xf86RegisterResources() found resource conflicts\n")); 995 GX2FreeRec(pScreenInfo); 996 return FALSE; 997 } 998 GX2UnmapMem(pScreenInfo); 999 GeodeDebug(("GX2PreInit ... done successfully!\n")); 1000 (void) from; 1001 return TRUE; 1002} 1003 1004/*---------------------------------------------------------------------------- 1005 * GX2Restore. 1006 * 1007 * Description :This function restores the mode that was saved on server 1008 entry 1009 * Parameters. 1010 * pScreenInfo :Handle to ScreenPtr structure. 1011 * Pmode :poits to screen mode 1012 * 1013 * Returns :none. 1014 * 1015 * Comments :none. 1016*---------------------------------------------------------------------------- 1017*/ 1018static void 1019GX2Restore(ScrnInfoPtr pScreenInfo) 1020{ 1021 GeodePtr pGeode; 1022 1023 GeodeDebug(("GX2Restore!\n")); 1024 /* Get driver private structure */ 1025 if (!(pGeode = GX2GetRec(pScreenInfo))) 1026 return; 1027 if (pGeode->FBVGAActive) { 1028 vgaHWPtr pvgaHW = VGAHWPTR(pScreenInfo); 1029 1030 vgaHWProtect(pScreenInfo, TRUE); 1031 vgaHWRestore(pScreenInfo, &pvgaHW->SavedReg, VGA_SR_ALL); 1032 vgaHWProtect(pScreenInfo, FALSE); 1033 } 1034} 1035 1036/*---------------------------------------------------------------------------- 1037 * GX2CalculatePitchBytes. 1038 * 1039 * Description :This function restores the mode that was saved on server 1040 * 1041 * Parameters. 1042 * pScreenInfo :Handle to ScreenPtr structure. 1043 * Pmode :Points to screenmode 1044 * 1045 * Returns :none. 1046 * 1047 * Comments :none. 1048*---------------------------------------------------------------------------- 1049*/ 1050static int 1051GX2CalculatePitchBytes(unsigned int width, unsigned int bpp) 1052{ 1053 int lineDelta = width * (bpp >> 3); 1054 1055 if (width < 640) { 1056 /* low resolutions have both pixel and line doubling */ 1057 DEBUGMSG(1, (0, X_PROBED, "lower resolution %d %d\n", 1058 width, lineDelta)); 1059 lineDelta <<= 1; 1060 } 1061 /* needed in Rotate mode when in accel is turned off */ 1062 if (1) { /*!pGeode->NoAccel */ 1063 if (lineDelta > 4096) 1064 lineDelta = 8192; 1065 else if (lineDelta > 2048) 1066 lineDelta = 4096; 1067 else if (lineDelta > 1024) 1068 lineDelta = 2048; 1069 else 1070 lineDelta = 1024; 1071 } 1072 1073 DEBUGMSG(1, (0, X_PROBED, "pitch %d %d\n", width, lineDelta)); 1074 1075 return lineDelta; 1076} 1077 1078/*---------------------------------------------------------------------------- 1079 * GX2GetRefreshRate. 1080 * 1081 * Description :This function restores the mode that saved on server 1082 * 1083 * Parameters. 1084 * Pmode :Pointer to the screen modes 1085 * 1086 * Returns :It returns the selected refresh rate. 1087 * 1088 * Comments :none. 1089*---------------------------------------------------------------------------- 1090*/ 1091static int 1092GX2GetRefreshRate(DisplayModePtr pMode) 1093{ 1094#define THRESHOLD 2 1095 unsigned int i; 1096 static int validRates[] = { 50, 56, 60, 70, 72, 75, 85 }; /* Hz */ 1097 unsigned long dotClock; 1098 int refreshRate; 1099 int selectedRate; 1100 1101 dotClock = pMode->SynthClock * 1000; 1102 refreshRate = dotClock / pMode->CrtcHTotal / pMode->CrtcVTotal; 1103 1104 if ((pMode->CrtcHTotal < 640) && (pMode->CrtcVTotal < 480)) 1105 refreshRate >>= 2; /* double pixel and double scan */ 1106 1107 DEBUGMSG(1, (0, X_PROBED, "dotclock %d %d\n", dotClock, refreshRate)); 1108 1109 selectedRate = validRates[0]; 1110 1111 for (i = 0; i < (sizeof(validRates) / sizeof(validRates[0])); i++) { 1112 if (validRates[i] < (refreshRate + THRESHOLD)) { 1113 selectedRate = validRates[i]; 1114 } 1115 } 1116 return selectedRate; 1117} 1118 1119void 1120gx2_clear_screen(int width, int height) 1121{ 1122 /* clean up the frame buffer memory */ 1123 GFX(set_solid_pattern(0)); 1124 GFX(set_raster_operation(0xF0)); 1125 GFX(pattern_fill(0, 0, width, height)); 1126} 1127 1128void 1129gx2_set_DvLineSize(unsigned int pitch) 1130{ 1131 unsigned long temp, dv_size = MDC_DV_LINE_SIZE_1024; 1132 1133 if (pitch > 1024) { 1134 dv_size = MDC_DV_LINE_SIZE_2048; 1135 } 1136 if (pitch > 2048) { 1137 dv_size = MDC_DV_LINE_SIZE_4096; 1138 } 1139 if (pitch > 4096) { 1140 dv_size = MDC_DV_LINE_SIZE_8192; 1141 } 1142 1143 /* WRITE DIRTY/VALID CONTROL WITH LINE LENGTH */ 1144 1145#if defined(STB_X) 1146 Gal_read_register(GAL_REG, MDC_DV_CTL, &temp, 4); 1147 temp = (temp & ~MDC_DV_LINE_SIZE_MASK) | dv_size; 1148 Gal_write_register(GAL_REG, MDC_DV_CTL, temp, 4); 1149#else 1150 temp = READ_REG32(MDC_DV_CTL); 1151 WRITE_REG32(MDC_DV_CTL, (temp & ~MDC_DV_LINE_SIZE_MASK) | dv_size); 1152#endif 1153} 1154 1155/*---------------------------------------------------------------------------- 1156 * GX2SetMode. 1157 * 1158 * Description :This function sets parametrs for screen mode 1159 * 1160 * Parameters. 1161 * pScreenInfo :Pointer to the screenInfo structure. 1162 * Pmode :Pointer to the screen modes 1163 * 1164 * Returns :TRUE on success and FALSE on Failure. 1165 * 1166 * Comments :none. 1167*---------------------------------------------------------------------------- 1168*/ 1169 1170static Bool 1171GX2SetMode(ScrnInfoPtr pScreenInfo, DisplayModePtr pMode) 1172{ 1173 GeodePtr pGeode = GEODEPTR(pScreenInfo); 1174 1175 DCount = 50; 1176 /* unsigned int compOffset, compPitch, compSize; */ 1177 GeodeDebug(("GX2SetMode!\n")); 1178#if !defined(STB_X) 1179 DEBUGMSG(1, (0, X_NONE, "Set mode %X %X %X %X %X\n", 1180 gfx_virt_regptr, 1181 gfx_virt_gpptr, 1182 gfx_virt_spptr, gfx_virt_vidptr, gfx_virt_fbptr)); 1183#endif /* STB_X */ 1184 1185 /* Set the VT semaphore */ 1186 pScreenInfo->vtSema = TRUE; 1187 DEBUGMSG(1, (0, X_NONE, "Set mode")); 1188 1189 /* The timing will be adjusted later */ 1190 GeodeDebug(("Set display mode: %dx%d-%d (%dHz) Pitch %d\n", 1191 pMode->CrtcHDisplay, 1192 pMode->CrtcVDisplay, 1193 pScreenInfo->bitsPerPixel, 1194 GX2GetRefreshRate(pMode), pGeode->Pitch)); 1195 1196 GeodeDebug(("Before setting the mode\n")); 1197 if (1) { 1198 { /* TV not selected */ 1199 1200 DEBUGMSG(1, (0, X_PROBED, "Setting Display for CRT or TFT\n")); 1201 1202 if (pGeode->Panel) { 1203 DEBUGMSG(0, (0, X_PROBED, "Setting Display for TFT\n")); 1204 DEBUGMSG(1, (0, X_PROBED, "Restore Panel %d %d %d %d %d\n", 1205 pGeode->FPBX, pGeode->FPBY, 1206 pMode->CrtcHDisplay, 1207 pMode->CrtcVDisplay, pScreenInfo->bitsPerPixel)); 1208 1209 DEBUGMSG(1, (pScreenInfo->scrnIndex, X_CONFIG, "FP Bios %d\n", 1210 pGeode->Panel)); 1211 GFX(set_fixed_timings(pGeode->FPBX, pGeode->FPBY, 1212 pMode->CrtcHDisplay, 1213 pMode->CrtcVDisplay, 1214 pScreenInfo->bitsPerPixel)); 1215 } else { 1216 /* display is crt */ 1217 DEBUGMSG(1, (0, X_PROBED, "Setting Display for CRT %dx%d-%d@%d\n", 1218 pMode->CrtcHDisplay, 1219 pMode->CrtcVDisplay, 1220 pScreenInfo->bitsPerPixel, 1221 GX2GetRefreshRate(pMode))); 1222 GFX(set_display_mode(pMode->CrtcHDisplay, 1223 pMode->CrtcVDisplay, 1224 pScreenInfo->bitsPerPixel, 1225 GX2GetRefreshRate(pMode))); 1226 1227 /* adjust the pitch */ 1228 GFX(set_display_pitch(pGeode->Pitch)); 1229 } 1230 GFX(set_bpp(pScreenInfo->bitsPerPixel)); 1231 /* enable crt */ 1232 GFX(set_crt_enable(CRT_ENABLE)); 1233 } 1234 GFX(set_display_offset(0L)); 1235 GFX(wait_vertical_blank()); 1236 1237 DEBUGMSG(1, (0, X_PROBED, "Display mode set\n")); 1238 /* enable compression if option selected */ 1239 if (pGeode->Compression) { 1240 DEBUGMSG(1, (0, X_PROBED, "Compression mode set %d\n", 1241 pGeode->Compression)); 1242 /* set the compression parameters,and it will be turned on later. */ 1243 gx2_set_DvLineSize(pGeode->Pitch); 1244 1245#if defined(STB_X) 1246 Gal_set_compression_parameters(GAL_COMPRESSION_ALL, 1247 pGeode->CBOffset, 1248 pGeode->CBPitch, pGeode->CBSize); 1249 1250 /* set the compression buffer, all parameters already set */ 1251 Gal_set_compression_enable(GAL_COMPRESSION_ENABLE); 1252#else /* STB_X */ 1253 gfx_set_compression_offset(pGeode->CBOffset); 1254 gfx_set_compression_pitch(pGeode->CBPitch); 1255 gfx_set_compression_size(pGeode->CBSize); 1256 1257 /* set the compression buffer, all parameters already set */ 1258 gfx_set_compression_enable(1); 1259#endif /* STB_X */ 1260 1261 } 1262 if (pGeode->HWCursor) { 1263 /* Load blank cursor */ 1264 GX2LoadCursorImage(pScreenInfo, NULL); 1265 GFX(set_cursor_position(pGeode->CursorStartOffset, 0, 0, 0, 0)); 1266 GFX(set_cursor_enable(1)); 1267 } 1268 } else { 1269 GeodeDebug(("GX2Restore ... ")); 1270 GX2Restore(pScreenInfo); 1271 GeodeDebug(("done.\n")); 1272 } 1273 1274 GeodeDebug(("done.\n")); 1275 /* Reenable the hardware cursor after the mode switch */ 1276 if (pGeode->HWCursor == TRUE) { 1277 GeodeDebug(("GX2ShowCursor ... ")); 1278 GX2ShowCursor(pScreenInfo); 1279 GeodeDebug(("done.\n")); 1280 } 1281 /* Restore the contents in the screen info */ 1282 GeodeDebug(("After setting the mode\n")); 1283 return TRUE; 1284} 1285 1286/*---------------------------------------------------------------------------- 1287 * GX2EnterGraphics. 1288 * 1289 * Description :This function will intiallize the displaytiming 1290 structure for nextmode and switch to VGA mode. 1291 * 1292 * Parameters. 1293 * pScreen :Screen information will be stored in this structure. 1294 * pScreenInfo :Pointer to the screenInfo structure. 1295 * 1296 * Returns :TRUE on success and FALSE on Failure. 1297 * 1298 * Comments :gfx_vga_mode_switch() will start and end the 1299 * switching based on the arguments 0 or 1.soft_vga 1300 * is disabled in this function. 1301*---------------------------------------------------------------------------- 1302*/ 1303static Bool 1304GX2EnterGraphics(ScreenPtr pScreen, ScrnInfoPtr pScreenInfo) 1305{ 1306 GeodePtr pGeode = GX2GetRec(pScreenInfo); 1307 1308#if defined(STB_X) 1309 Gal_get_display_timing(&pGeode->FBgfxdisplaytiming); 1310 1311 /* Save Display offset */ 1312 Gal_get_display_offset(&(pGeode->FBDisplayOffset)); 1313 1314 /* Save the current Compression state */ 1315 Gal_get_compression_enable(&(pGeode->FBCompressionEnable)); 1316 Gal_get_compression_parameters(GAL_COMPRESSION_ALL, 1317 &(pGeode->FBCompressionOffset), 1318 &(pGeode->FBCompressionPitch), 1319 &(pGeode->FBCompressionSize)); 1320 1321 /* Save Cursor offset */ 1322 { 1323 unsigned short x, y, xhot, yhot; 1324 1325 Gal_get_cursor_position(&(pGeode->FBCursorOffset), 1326 &x, &y, &xhot, &yhot); 1327 } 1328 /* Save the Panel state */ 1329 Gal_pnl_save(); 1330#else /* STB_X */ 1331 /* Save CRT State */ 1332 pGeode->FBgfxdisplaytiming.dwDotClock = gfx_get_clock_frequency(); 1333 pGeode->FBgfxdisplaytiming.wPitch = gfx_get_display_pitch(); 1334 pGeode->FBgfxdisplaytiming.wBpp = gfx_get_display_bpp(); 1335 pGeode->FBgfxdisplaytiming.wHTotal = gfx_get_htotal(); 1336 pGeode->FBgfxdisplaytiming.wHActive = gfx_get_hactive(); 1337 pGeode->FBgfxdisplaytiming.wHSyncStart = gfx_get_hsync_start(); 1338 pGeode->FBgfxdisplaytiming.wHSyncEnd = gfx_get_hsync_end(); 1339 pGeode->FBgfxdisplaytiming.wHBlankStart = gfx_get_hblank_start(); 1340 pGeode->FBgfxdisplaytiming.wHBlankEnd = gfx_get_hblank_end(); 1341 pGeode->FBgfxdisplaytiming.wVTotal = gfx_get_vtotal(); 1342 pGeode->FBgfxdisplaytiming.wVActive = gfx_get_vactive(); 1343 pGeode->FBgfxdisplaytiming.wVSyncStart = gfx_get_vsync_start(); 1344 pGeode->FBgfxdisplaytiming.wVSyncEnd = gfx_get_vsync_end(); 1345 pGeode->FBgfxdisplaytiming.wVBlankStart = gfx_get_vblank_start(); 1346 pGeode->FBgfxdisplaytiming.wVBlankEnd = gfx_get_vblank_end(); 1347 pGeode->FBgfxdisplaytiming.wPolarity = gfx_get_sync_polarities(); 1348 1349 /* Save Display offset */ 1350 pGeode->FBDisplayOffset = gfx_get_display_offset(); 1351 1352 /* Save the current Compression state */ 1353 pGeode->FBCompressionEnable = gfx_get_compression_enable(); 1354 pGeode->FBCompressionOffset = gfx_get_compression_offset(); 1355 pGeode->FBCompressionPitch = gfx_get_compression_pitch(); 1356 pGeode->FBCompressionSize = gfx_get_compression_size(); 1357 1358 /* Save Cursor offset */ 1359 pGeode->FBCursorOffset = gfx_get_cursor_offset(); 1360 1361 /* Save the Panel state */ 1362 Pnl_SavePanelState(); 1363 1364 /* only if comming from VGA */ 1365 if (pGeode->FBVGAActive) { 1366 unsigned short sequencer; 1367 vgaHWPtr pvgaHW = VGAHWPTR(pScreenInfo); 1368 1369 /* Map VGA aperture */ 1370 if (!vgaHWMapMem(pScreenInfo)) 1371 return FALSE; 1372 1373 /* Unlock VGA registers */ 1374 vgaHWUnlock(pvgaHW); 1375 1376 /* Save the current state and setup the current mode */ 1377 vgaHWSave(pScreenInfo, &VGAHWPTR(pScreenInfo)->SavedReg, VGA_SR_ALL); 1378 1379 /* DISABLE VGA SEQUENCER */ 1380 /* This allows the VGA state machine to terminate. We must delay */ 1381 /* such that there are no pending MBUS requests. */ 1382 1383 gfx_outb(MDC_SEQUENCER_INDEX, MDC_SEQUENCER_CLK_MODE); 1384 sequencer = gfx_inb(MDC_SEQUENCER_DATA); 1385 sequencer |= MDC_CLK_MODE_SCREEN_OFF; 1386 gfx_outb(MDC_SEQUENCER_DATA, sequencer); 1387 1388 gfx_delay_milliseconds(1); 1389 1390 /* BLANK THE VGA DISPLAY */ 1391 gfx_outw(MDC_SEQUENCER_INDEX, MDC_SEQUENCER_RESET); 1392 sequencer = gfx_inb(MDC_SEQUENCER_DATA); 1393 sequencer &= ~MDC_RESET_VGA_DISP_ENABLE; 1394 gfx_outb(MDC_SEQUENCER_DATA, sequencer); 1395 1396 gfx_delay_milliseconds(1); 1397 } 1398#endif /* STB */ 1399 1400 if (!GX2SetMode(pScreenInfo, pScreenInfo->currentMode)) { 1401 return FALSE; 1402 } 1403 1404 /* clear the frame buffer, for annoying noise during mode switch */ 1405 gx2_clear_screen(pScreenInfo->currentMode->CrtcHDisplay, 1406 pScreenInfo->currentMode->CrtcVDisplay); 1407 1408 return TRUE; 1409} 1410 1411#if !defined(STB_X) 1412void 1413EnableDACPower(void) 1414{ 1415 /* enable the DAC POWER */ 1416 gfx_write_vid32(RCDF_VID_MISC, 1417 gfx_read_vid32(RCDF_VID_MISC) & RCDF_GAMMA_BYPASS_BOTH); 1418} 1419 1420void 1421redcloud_gfx_2_vga_fix(void) 1422{ 1423 /* enable the DAC POWER */ 1424 EnableDACPower(); 1425#if 0 1426 int i; 1427 1428 /* set the character width to 9 */ 1429 gfx_outb(0x3C4, 0x1); 1430 gfx_outb(0x3C5, 0x2); 1431 1432 /* clear the gfx mode bit in VGA Attribute controller */ 1433 gfx_inb(0x3DA); 1434 gfx_outb(0x3C0, 0x30); 1435 gfx_outb(0x3C0, 0xC); 1436 1437 /* Re init the EGA Palaette */ 1438 for (i = 0; i < 16; i++) { 1439 gfx_inb(0x3DA); 1440 gfx_outb(0x3C0, i); 1441 gfx_outb(0x3C0, i); 1442 } 1443 1444 /* Re init the Overscan color to black */ 1445 gfx_inb(0x3DA); 1446 gfx_outb(0x3C0, 0x11); 1447 gfx_outb(0x3C0, 0x0); 1448 1449 /* Re Enable all the 4 color planes */ 1450 gfx_inb(0x3DA); 1451 gfx_outb(0x3C0, 0x12); 1452 gfx_outb(0x3C0, 0xF); 1453 1454 /* Clear Pixel Panning in VGA Attribute controller */ 1455 gfx_inb(0x3DA); 1456 gfx_outb(0x3C0, 0x33); 1457 gfx_outb(0x3C0, 0x8); 1458 1459 /* ??????????????????????? */ 1460 gfx_outb(0x3C0, 0x20); 1461 gfx_outb(0x3C0, 0x20); 1462#endif 1463} 1464#endif /* STB_X */ 1465 1466/*---------------------------------------------------------------------------- 1467 * GX2LeaveGraphics: 1468 * 1469 * Description :This function will restore the displaymode parameters 1470 * and switches the VGA mode 1471 * 1472 * Parameters. 1473 * pScreen :Screen information will be stored in this structure. 1474 * pScreenInfo :Pointer to the screenInfo structure. 1475 * 1476 * 1477 * Returns :none. 1478 * 1479 * Comments : gfx_vga_mode_switch() will start and end the switching 1480 * based on the arguments 0 or 1.soft_vga is disabled in 1481 * this function. 1482*---------------------------------------------------------------------------- 1483*/ 1484static void 1485GX2LeaveGraphics(ScrnInfoPtr pScreenInfo) 1486{ 1487 GeodePtr pGeode = GX2GetRec(pScreenInfo); 1488 1489 /* Restore VG registers */ 1490#if defined(STB_X) 1491 Gal_set_display_timing(&pGeode->FBgfxdisplaytiming); 1492 1493 Gal_set_display_offset(pGeode->FBDisplayOffset); 1494 1495 /* Restore Cursor */ 1496 Gal_set_cursor_position(pGeode->FBCursorOffset, 0, 0, 0, 0); 1497 1498 /* Restore the previous Compression state */ 1499 if (pGeode->FBCompressionEnable) { 1500 Gal_set_compression_parameters(GAL_COMPRESSION_ALL, 1501 pGeode->FBCompressionOffset, 1502 pGeode->FBCompressionPitch, 1503 pGeode->FBCompressionSize); 1504 1505 Gal_set_compression_enable(GAL_COMPRESSION_ENABLE); 1506 } 1507#else /* STB_X */ 1508 gfx_set_display_timings(pGeode->FBgfxdisplaytiming.wBpp, 1509 pGeode->FBgfxdisplaytiming.wPolarity, 1510 pGeode->FBgfxdisplaytiming.wHActive, 1511 pGeode->FBgfxdisplaytiming.wHBlankStart, 1512 pGeode->FBgfxdisplaytiming.wHSyncStart, 1513 pGeode->FBgfxdisplaytiming.wHSyncEnd, 1514 pGeode->FBgfxdisplaytiming.wHBlankEnd, 1515 pGeode->FBgfxdisplaytiming.wHTotal, 1516 pGeode->FBgfxdisplaytiming.wVActive, 1517 pGeode->FBgfxdisplaytiming.wVBlankStart, 1518 pGeode->FBgfxdisplaytiming.wVSyncStart, 1519 pGeode->FBgfxdisplaytiming.wVSyncEnd, 1520 pGeode->FBgfxdisplaytiming.wVBlankEnd, 1521 pGeode->FBgfxdisplaytiming.wVTotal, 1522 pGeode->FBgfxdisplaytiming.dwDotClock); 1523 1524 gfx_set_compression_enable(0); 1525 1526 /* Restore the previous Compression state */ 1527 if (pGeode->FBCompressionEnable) { 1528 gfx_set_compression_offset(pGeode->FBCompressionOffset); 1529 gfx_set_compression_pitch(pGeode->FBCompressionPitch); 1530 gfx_set_compression_size(pGeode->FBCompressionSize); 1531 gfx_set_compression_enable(1); 1532 } 1533 1534 gfx_set_display_pitch(pGeode->FBgfxdisplaytiming.wPitch); 1535 1536 gfx_set_display_offset(pGeode->FBDisplayOffset); 1537 1538 /* Restore Cursor */ 1539 gfx_set_cursor_position(pGeode->FBCursorOffset, 0, 0, 0, 0); 1540 1541 GeodeDebug(("FBVGAActive %d\n", pGeode->FBVGAActive)); 1542 if (pGeode->FBVGAActive) { 1543 pGeode->vesa->pInt->num = 0x10; 1544 pGeode->vesa->pInt->ax = 0x3; 1545 pGeode->vesa->pInt->bx = 0; 1546 xf86ExecX86int10(pGeode->vesa->pInt); 1547 gfx_delay_milliseconds(3); 1548 EnableDACPower(); 1549 } 1550#endif /* STB_X */ 1551} 1552 1553/*---------------------------------------------------------------------------- 1554 * GX2CloseScreen. 1555 * 1556 * Description :This function will restore the original mode 1557 * and also it unmap video memory 1558 * 1559 * Parameters. 1560 * ScrnIndex :Screen index value of the screen will be closed. 1561 * pScreen :Pointer to the screen structure. 1562 * 1563 * 1564 * Returns :TRUE on success and FALSE on Failure. 1565 * 1566 * Comments :none. 1567*---------------------------------------------------------------------------- 1568*/ 1569static Bool 1570GX2CloseScreen(int scrnIndex, ScreenPtr pScreen) 1571{ 1572 ScrnInfoPtr pScreenInfo = xf86Screens[scrnIndex]; 1573 GeodePtr pGeode = GEODEPTR(pScreenInfo); 1574 1575 if (pGeode->ShadowPtr) 1576 xfree(pGeode->ShadowPtr); 1577 1578 DEBUGMSG(0, (scrnIndex, X_PROBED, "GX2CloseScreen %d\n", 1579 pScreenInfo->vtSema)); 1580 if (pScreenInfo->vtSema) 1581 GX2LeaveGraphics(pScreenInfo); 1582 1583 if (pGeode->AccelInfoRec) 1584 XAADestroyInfoRec(pGeode->AccelInfoRec); 1585 1586 if (pGeode->AccelImageWriteBufferOffsets) { 1587 xfree(pGeode->AccelImageWriteBufferOffsets); 1588 pGeode->AccelImageWriteBufferOffsets = 0x0; 1589 } 1590 /* free the allocated off screen area */ 1591 xf86FreeOffscreenArea(pGeode->AccelImgArea); 1592 xf86FreeOffscreenArea(pGeode->CompressionArea); 1593 1594 pScreenInfo->vtSema = FALSE; 1595 1596 GX2UnmapMem(pScreenInfo); 1597 if (pGeode && (pScreen->CloseScreen = pGeode->CloseScreen)) { 1598 pGeode->CloseScreen = NULL; 1599 return ((*pScreen->CloseScreen) (scrnIndex, pScreen)); 1600 } 1601 return TRUE; 1602} 1603 1604/*---------------------------------------------------------------------------- 1605 * GX2DPMSSet. 1606 * 1607 * Description :This function sets geode into Power Management 1608 * Signalling mode. 1609 * 1610 * Parameters. 1611 * pScreenInfo :Pointer to screen info strucrure. 1612 * mode :Specifies the power management mode. 1613 * 1614 * Returns :none. 1615 * 1616 * Comments :none. 1617*---------------------------------------------------------------------------- 1618*/ 1619static void 1620GX2DPMSSet(ScrnInfoPtr pScreenInfo, int mode, int flags) 1621{ 1622 GeodePtr pGeode; 1623 1624 pGeode = GEODEPTR(pScreenInfo); 1625 1626 GeodeDebug(("GX2DPMSSet!\n")); 1627 1628 /* Check if we are actively controlling the display */ 1629 if (!pScreenInfo->vtSema) { 1630 ErrorF("GX2DPMSSet called when we not controlling the VT!\n"); 1631 return; 1632 } 1633 switch (mode) { 1634 case DPMSModeOn: 1635 /* Screen: On; HSync: On; VSync: On */ 1636 GFX(set_crt_enable(CRT_ENABLE)); 1637#if defined(STB_X) 1638 if (pGeode->Panel) 1639 Gal_pnl_powerup(); 1640#else /* STB_X */ 1641 if (pGeode->Panel) 1642 Pnl_PowerUp(); 1643#endif /* STB_X */ 1644 break; 1645 1646 case DPMSModeStandby: 1647 /* Screen: Off; HSync: Off; VSync: On */ 1648 GFX(set_crt_enable(CRT_STANDBY)); 1649#if defined(STB_X) 1650 if (pGeode->Panel) 1651 Gal_pnl_powerdown(); 1652#else /* STB_X */ 1653 if (pGeode->Panel) 1654 Pnl_PowerDown(); 1655#endif /* STB_X */ 1656 break; 1657 1658 case DPMSModeSuspend: 1659 /* Screen: Off; HSync: On; VSync: Off */ 1660 GFX(set_crt_enable(CRT_SUSPEND)); 1661#if defined(STB_X) 1662 if (pGeode->Panel) 1663 Gal_pnl_powerdown(); 1664#else /* STB_X */ 1665 if (pGeode->Panel) 1666 Pnl_PowerDown(); 1667#endif /* STB_X */ 1668 break; 1669 case DPMSModeOff: 1670 /* Screen: Off; HSync: Off; VSync: Off */ 1671 GFX(set_crt_enable(CRT_DISABLE)); 1672#if defined(STB_X) 1673 if (pGeode->Panel) 1674 Gal_pnl_powerdown(); 1675#else /* STB_X */ 1676 if (pGeode->Panel) 1677 Pnl_PowerDown(); 1678#endif /* STB_X */ 1679 break; 1680 } 1681} 1682 1683/*---------------------------------------------------------------------------- 1684 * GX2ScreenInit. 1685 * 1686 * Description :This function will be called at the each ofserver 1687 * generation. 1688 * 1689 * Parameters. 1690 * scrnIndex :Specfies the screenindex value during generation. 1691 * pScreen :Pointer to screen info strucrure. 1692 * argc :parameters for command line arguments count 1693 * argv :command line arguments if any it is not used. 1694 * 1695 * Returns :none. 1696 * 1697 * Comments :none. 1698*---------------------------------------------------------------------------- 1699*/ 1700static Bool 1701GX2ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) 1702{ 1703 ScrnInfoPtr pScreenInfo = xf86Screens[pScreen->myNum]; 1704 GeodePtr pGeode; 1705 int i; 1706 Bool Inited = FALSE; 1707 unsigned char *FBStart; 1708 unsigned int req_offscreenmem; 1709 int width, height, displayWidth; 1710 VisualPtr visual; 1711 BoxRec AvailBox; 1712 RegionRec OffscreenRegion; 1713 1714 DCount = 30; 1715 GeodeDebug(("GX2ScreenInit!\n")); 1716 /* Get driver private */ 1717 pGeode = GX2GetRec(pScreenInfo); 1718 GeodeDebug(("GX2ScreenInit(0)!\n")); 1719 /* 1720 * * Allocate a vgaHWRec 1721 */ 1722 GeodeDebug(("FBVGAActive %d\n", pGeode->FBVGAActive)); 1723 if (pGeode->FBVGAActive) { 1724 if (!vgaHWGetHWRec(pScreenInfo)) 1725 return FALSE; 1726 if (!vgaHWMapMem(pScreenInfo)) 1727 return FALSE; 1728 vgaHWGetIOBase(VGAHWPTR(pScreenInfo)); 1729 } 1730 1731 if (!GX2MapMem(pScreenInfo)) 1732 return FALSE; 1733 1734 pGeode->Pitch = GX2CalculatePitchBytes(pScreenInfo->virtualX, 1735 pScreenInfo->bitsPerPixel); 1736 1737 /* SET UP GRAPHICS MEMORY AVAILABLE FOR PIXMAP CACHE */ 1738 AvailBox.x1 = 0; 1739 AvailBox.y1 = pScreenInfo->virtualY; 1740 AvailBox.x2 = pScreenInfo->displayWidth; 1741 AvailBox.y2 = (pGeode->FBSize / pGeode->Pitch); 1742 1743 pGeode->CursorSize = 16 * 64; /* 64x64 */ 1744 1745 if (pGeode->HWCursor) { 1746 /* Compute cursor buffer */ 1747 /* Default cursor offset, end of the frame buffer */ 1748 pGeode->CursorStartOffset = pGeode->FBSize - pGeode->CursorSize; 1749 AvailBox.y2 -= 1; 1750 } 1751 1752 DEBUGMSG(1, (scrnIndex, X_PROBED, 1753 "Memory manager initialized to (%d,%d) (%d,%d) %d %d %d\n", 1754 AvailBox.x1, AvailBox.y1, AvailBox.x2, AvailBox.y2, 1755 pGeode->Pitch, pScreenInfo->displayWidth, 1756 pScreenInfo->bitsPerPixel)); 1757 1758 /* set the offscreen offset accordingly */ 1759 if (pGeode->Compression) { 1760 1761 pGeode->CBPitch = 544; 1762 pGeode->CBSize = 544; 1763 1764 req_offscreenmem = pScreenInfo->virtualY * pGeode->CBPitch; 1765 req_offscreenmem += pGeode->Pitch - 1; 1766 req_offscreenmem /= pGeode->Pitch; 1767 pGeode->CBOffset = AvailBox.y1 * pGeode->Pitch; 1768 AvailBox.y1 += req_offscreenmem; 1769 } 1770 DEBUGMSG(1, (scrnIndex, X_PROBED, 1771 "Memory manager initialized to (%d,%d) (%d,%d)\n", 1772 AvailBox.x1, AvailBox.y1, AvailBox.x2, AvailBox.y2)); 1773 1774 if (!pGeode->NoAccel) { 1775 if (pGeode->NoOfImgBuffers > 0) { 1776 if (pGeode->NoOfImgBuffers <= (AvailBox.y2 - AvailBox.y1)) { 1777 pGeode->AccelImageWriteBufferOffsets = 1778 xalloc(sizeof(unsigned long) * pGeode->NoOfImgBuffers); 1779 1780 pGeode->AccelImageWriteBufferOffsets[0] = 1781 ((unsigned char *)pGeode->FBBase) + 1782 (AvailBox.y1 * pGeode->Pitch); 1783 1784 for (i = 1; i < pGeode->NoOfImgBuffers; i++) { 1785 pGeode->AccelImageWriteBufferOffsets[i] = 1786 pGeode->AccelImageWriteBufferOffsets[i - 1] + 1787 pGeode->Pitch; 1788 } 1789 1790 for (i = 0; i < pGeode->NoOfImgBuffers; i++) { 1791 DEBUGMSG(1, (scrnIndex, X_PROBED, 1792 "memory %d %x\n", i, 1793 pGeode->AccelImageWriteBufferOffsets[i])); 1794 } 1795 AvailBox.y1 += pGeode->NoOfImgBuffers; 1796 } else { 1797 xf86DrvMsg(scrnIndex, X_ERROR, 1798 "Unable to reserve scanline area\n"); 1799 } 1800 } 1801 DEBUGMSG(1, (scrnIndex, X_PROBED, 1802 "Memory manager initialized to (%d,%d) (%d,%d)\n", 1803 AvailBox.x1, AvailBox.y1, AvailBox.x2, AvailBox.y2)); 1804 1805 REGION_INIT(pScreen, &OffscreenRegion, &AvailBox, 2); 1806 1807 if (!xf86InitFBManagerRegion(pScreen, &OffscreenRegion)) { 1808 xf86DrvMsg(scrnIndex, X_ERROR, 1809 "Memory manager initialization to (%d,%d) (%d,%d) failed\n", 1810 AvailBox.x1, AvailBox.y1, AvailBox.x2, AvailBox.y2); 1811 } else { 1812 xf86DrvMsg(scrnIndex, X_INFO, 1813 "Memory manager initialized to (%d,%d) (%d,%d)\n", 1814 AvailBox.x1, AvailBox.y1, AvailBox.x2, AvailBox.y2); 1815 } 1816 REGION_UNINIT(pScreen, &OffscreenRegion); 1817 } 1818 1819 /* Initialise graphics mode */ 1820 if (!GX2EnterGraphics(pScreen, pScreenInfo)) 1821 return FALSE; 1822 1823 GX2AdjustFrame(scrnIndex, pScreenInfo->frameX0, pScreenInfo->frameY0, 0); 1824 GeodeDebug(("GX2ScreenInit(1)!\n")); 1825 1826 /* Reset visual list */ 1827 miClearVisualTypes(); 1828 GeodeDebug(("GX2ScreenInit(2)!\n")); 1829 1830 /* Setup the visual we support */ 1831 if (pScreenInfo->bitsPerPixel > 8) { 1832 DEBUGMSG(1, (scrnIndex, X_PROBED, 1833 "miSetVisualTypes %d %X %X %X\n", 1834 pScreenInfo->depth, 1835 TrueColorMask, 1836 pScreenInfo->rgbBits, pScreenInfo->defaultVisual)); 1837 1838 if (!miSetVisualTypes(pScreenInfo->depth, 1839 TrueColorMask, 1840 pScreenInfo->rgbBits, 1841 pScreenInfo->defaultVisual)) { 1842 return FALSE; 1843 } 1844 } else { 1845 if (!miSetVisualTypes(pScreenInfo->depth, 1846 miGetDefaultVisualMask(pScreenInfo->depth), 1847 pScreenInfo->rgbBits, 1848 pScreenInfo->defaultVisual)) { 1849 return FALSE; 1850 } 1851 } 1852 GeodeDebug(("GX2ScreenInit(3)!\n")); 1853 1854 /* Set for RENDER extensions */ 1855 miSetPixmapDepths(); 1856 1857 /* Call the framebuffer layer's ScreenInit function, and fill in other 1858 * * pScreen fields. 1859 */ 1860 1861 width = pScreenInfo->virtualX; 1862 height = pScreenInfo->virtualY; 1863 1864 displayWidth = pScreenInfo->displayWidth; 1865 if (pGeode->Rotate) { 1866 width = pScreenInfo->virtualY; 1867 height = pScreenInfo->virtualX; 1868 } 1869 if (pGeode->ShadowFB) { 1870 pGeode->ShadowPitch = BitmapBytePad(pScreenInfo->bitsPerPixel * width); 1871 pGeode->ShadowPtr = xalloc(pGeode->ShadowPitch * height); 1872 displayWidth = pGeode->ShadowPitch / (pScreenInfo->bitsPerPixel >> 3); 1873 FBStart = pGeode->ShadowPtr; 1874 } else { 1875 pGeode->ShadowPtr = NULL; 1876 1877 FBStart = pGeode->FBBase; 1878 DEBUGMSG(1, (0, X_PROBED, "FBStart %X \n", FBStart)); 1879 } 1880 1881 switch (pScreenInfo->bitsPerPixel) { 1882 case 8: 1883 case 16: 1884 case 24: 1885 case 32: 1886 Inited = fbScreenInit(pScreen, FBStart, width, height, 1887 pScreenInfo->xDpi, pScreenInfo->yDpi, 1888 displayWidth, pScreenInfo->bitsPerPixel); 1889 break; 1890 default: 1891 xf86DrvMsg(scrnIndex, X_ERROR, 1892 "Internal error: invalid bpp (%d) in ScreenInit\n", 1893 pScreenInfo->bitsPerPixel); 1894 Inited = FALSE; 1895 break; 1896 } 1897 if (!Inited) 1898 return FALSE; 1899 1900 GeodeDebug(("GX2ScreenInit(4)!\n")); 1901 xf86SetBlackWhitePixels(pScreen); 1902 1903 if (!pGeode->ShadowFB) { 1904 GX2DGAInit(pScreen); 1905 } 1906 GeodeDebug(("GX2ScreenInit(5)!\n")); 1907 if (pScreenInfo->bitsPerPixel > 8) { 1908 /* Fixup RGB ordering */ 1909 visual = pScreen->visuals + pScreen->numVisuals; 1910 while (--visual >= pScreen->visuals) { 1911 if ((visual->class | DynamicClass) == DirectColor) { 1912 visual->offsetRed = pScreenInfo->offset.red; 1913 visual->offsetGreen = pScreenInfo->offset.green; 1914 visual->offsetBlue = pScreenInfo->offset.blue; 1915 visual->redMask = pScreenInfo->mask.red; 1916 visual->greenMask = pScreenInfo->mask.green; 1917 visual->blueMask = pScreenInfo->mask.blue; 1918 } 1919 } 1920 } 1921 /* must be after RGB ordering fixed */ 1922 fbPictureInit(pScreen, 0, 0); 1923 1924 GeodeDebug(("GX2ScreenInit(6)!\n")); 1925 if (!pGeode->NoAccel) { 1926 GX2AccelInit(pScreen); 1927 } 1928 GeodeDebug(("GX2ScreenInit(7)!\n")); 1929 xf86SetBackingStore(pScreen); 1930 GeodeDebug(("GX2ScreenInit(8)!\n")); 1931 /* Initialise software cursor */ 1932 miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); 1933 /* Initialize HW cursor layer. 1934 * * Must follow software cursor initialization 1935 */ 1936 if (pGeode->HWCursor) { 1937 if (!GX2HWCursorInit(pScreen)) 1938 xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR, 1939 "Hardware cursor initialization failed\n"); 1940 } 1941 GeodeDebug(("GX2ScreenInit(9)!\n")); 1942 /* Setup default colourmap */ 1943 if (!miCreateDefColormap(pScreen)) { 1944 return FALSE; 1945 } 1946 GeodeDebug(("GX2ScreenInit(10)!\n")); 1947 /* Initialize colormap layer. 1948 * * Must follow initialization of the default colormap 1949 */ 1950 if (!xf86HandleColormaps(pScreen, 256, 8, 1951 GX2LoadPalette, NULL, 1952 CMAP_PALETTED_TRUECOLOR | 1953 CMAP_RELOAD_ON_MODE_SWITCH)) { 1954 return FALSE; 1955 } 1956 1957 GeodeDebug(("GX2ScreenInit(11)!\n")); 1958 1959 if (pGeode->ShadowFB) { 1960 RefreshAreaFuncPtr refreshArea = GX2RefreshArea; 1961 1962 if (pGeode->Rotate) { 1963 if (!pGeode->PointerMoved) { 1964 pGeode->PointerMoved = pScreenInfo->PointerMoved; 1965 pScreenInfo->PointerMoved = GX2PointerMoved; 1966 } 1967 switch (pScreenInfo->bitsPerPixel) { 1968 case 8: 1969 refreshArea = GX2RefreshArea8; 1970 break; 1971 case 16: 1972 refreshArea = GX2RefreshArea16; 1973 break; 1974 case 24: 1975 refreshArea = GX2RefreshArea24; 1976 break; 1977 case 32: 1978 refreshArea = GX2RefreshArea32; 1979 break; 1980 } 1981 } 1982 ShadowFBInit(pScreen, refreshArea); 1983 } 1984 xf86DPMSInit(pScreen, GX2DPMSSet, 0); 1985 GeodeDebug(("GX2ScreenInit(12)!\n")); 1986 1987 pScreenInfo->memPhysBase = (unsigned long)pGeode->FBBase; 1988 pScreenInfo->fbOffset = 0; 1989 1990 GeodeDebug(("GX2ScreenInit(13)!\n")); 1991 GX2InitVideo(pScreen); /* needed for video */ 1992 /* Wrap the screen's CloseScreen vector and set its 1993 * SaveScreen vector 1994 */ 1995 pGeode->CloseScreen = pScreen->CloseScreen; 1996 pScreen->CloseScreen = GX2CloseScreen; 1997 1998 pScreen->SaveScreen = GX2SaveScreen; 1999 GeodeDebug(("GX2ScreenInit(14)!\n")); 2000 2001 /* Report any unused options */ 2002 if (serverGeneration == 1) { 2003 xf86ShowUnusedOptions(pScreenInfo->scrnIndex, pScreenInfo->options); 2004 } 2005 GeodeDebug(("GX2ScreenInit(15)!\n")); 2006 return TRUE; 2007} 2008 2009/*---------------------------------------------------------------------------- 2010 * GX2SwitchMode. 2011 * 2012 * Description :This function will switches the screen mode 2013 * 2014 * Parameters: 2015 * scrnIndex :Specfies the screen index value. 2016 * pMode :pointer to the mode structure. 2017 * flags :may be used for status check?. 2018 * 2019 * Returns :Returns TRUE on success and FALSE on failure. 2020 * 2021 * Comments :none. 2022*---------------------------------------------------------------------------- 2023*/ 2024Bool 2025GX2SwitchMode(int scrnIndex, DisplayModePtr pMode, int flags) 2026{ 2027 GeodeDebug(("GX2SwitchMode!\n")); 2028 return GX2SetMode(xf86Screens[scrnIndex], pMode); 2029} 2030 2031/*---------------------------------------------------------------------------- 2032 * GX2AdjustFrame. 2033 * 2034 * Description :This function is used to intiallize the start 2035 * address of the memory. 2036 * Parameters. 2037 * scrnIndex :Specfies the screen index value. 2038 * x :x co-ordinate value interms of pixels. 2039 * y :y co-ordinate value interms of pixels. 2040 * 2041 * Returns :none. 2042 * 2043 * Comments :none. 2044*---------------------------------------------------------------------------- 2045*/ 2046void 2047GX2AdjustFrame(int scrnIndex, int x, int y, int flags) 2048{ 2049 ScrnInfoPtr pScreenInfo = xf86Screens[scrnIndex]; 2050 GeodePtr pGeode = GX2GetRec(pScreenInfo); 2051 unsigned long offset; 2052 2053 /* y offset */ 2054 offset = (unsigned long)y *(unsigned long)pGeode->Pitch; 2055 2056 /* x offset */ 2057 offset += x * (pScreenInfo->bitsPerPixel >> 3); 2058 2059 GFX(set_display_offset(offset)); 2060} 2061 2062/*---------------------------------------------------------------------------- 2063 * GX2EnterVT. 2064 * 2065 * Description :This is called when VT switching back to the X server 2066 * 2067 * Parameters. 2068 * scrnIndex :Specfies the screen index value. 2069 * flags :Not used inside the function. 2070 * 2071 * Returns :none. 2072 * 2073 * Comments :none. 2074*---------------------------------------------------------------------------- 2075*/ 2076static Bool 2077GX2EnterVT(int scrnIndex, int flags) 2078{ 2079 GeodeDebug(("GX2EnterVT!\n")); 2080 return GX2EnterGraphics(NULL, xf86Screens[scrnIndex]); 2081} 2082 2083/*---------------------------------------------------------------------------- 2084 * GX2LeaveVT. 2085 * 2086 * Description :This is called when VT switching X server text mode. 2087 * 2088 * Parameters. 2089 * scrnIndex :Specfies the screen index value. 2090 * flags :Not used inside the function. 2091 * 2092 * Returns :none. 2093 * 2094 * Comments :none. 2095*---------------------------------------------------------------------------- 2096*/ 2097static void 2098GX2LeaveVT(int scrnIndex, int flags) 2099{ 2100 GeodeDebug(("GX2LeaveVT!\n")); 2101 GX2LeaveGraphics(xf86Screens[scrnIndex]); 2102} 2103 2104/*---------------------------------------------------------------------------- 2105 * GX2FreeScreen. 2106 * 2107 * Description :This is called to free any persistent data structures. 2108 * 2109 * Parameters. 2110 * scrnIndex :Specfies the screen index value. 2111 * flags :Not used inside the function. 2112 * 2113 * Returns :none. 2114 * 2115 * Comments :This will be called only when screen being deleted.. 2116*---------------------------------------------------------------------------- 2117*/ 2118static void 2119GX2FreeScreen(int scrnIndex, int flags) 2120{ 2121 GeodeDebug(("GX2FreeScreen!\n")); 2122 if (xf86LoaderCheckSymbol("vgaHWFreeHWRec")) 2123 vgaHWFreeHWRec(xf86Screens[scrnIndex]); 2124 GX2FreeRec(xf86Screens[scrnIndex]); 2125} 2126 2127/*---------------------------------------------------------------------------- 2128 * GX2ValidMode. 2129 * 2130 * Description :This function checks if a mode is suitable for selected 2131 * chipset. 2132 * Parameters. 2133 * scrnIndex :Specfies the screen index value. 2134 * pMode :Pointer to the screen mode structure.. 2135 * verbose :not used for implementation. 2136 * flags :not used for implementation 2137 * 2138 * Returns :MODE_OK if the specified mode is supported or 2139 * MODE_NO_INTERLACE. 2140 * Comments :none. 2141*---------------------------------------------------------------------------- 2142*/ 2143static ModeStatus 2144GX2ValidMode(int scrnIndex, DisplayModePtr pMode, Bool Verbose, int flags) 2145{ 2146 unsigned int total_memory_required; 2147 ScrnInfoPtr pScreenInfo = xf86Screens[scrnIndex]; 2148 int ret = -1; 2149 GeodePtr pGeode = GX2GetRec(pScreenInfo); 2150 2151 DEBUGMSG(1, (0, X_NONE, "GeodeValidateMode: %dx%d %d %d\n", 2152 pMode->CrtcHDisplay, pMode->CrtcVDisplay, 2153 pScreenInfo->bitsPerPixel, GX2GetRefreshRate(pMode))); 2154 { 2155 DEBUGMSG(1, (0, X_NONE, "CRT mode\n")); 2156 if (pMode->Flags & V_INTERLACE) 2157 return MODE_NO_INTERLACE; 2158 2159#if defined(STB_X) 2160 Gal_is_display_mode_supported(pMode->CrtcHDisplay, pMode->CrtcVDisplay, 2161 pScreenInfo->bitsPerPixel, 2162 GX2GetRefreshRate(pMode), &ret); 2163#else /* STB_X */ 2164 ret = gfx_is_display_mode_supported(pMode->CrtcHDisplay, 2165 pMode->CrtcVDisplay, 2166 pScreenInfo->bitsPerPixel, 2167 GX2GetRefreshRate(pMode)); 2168#endif /* STB_X */ 2169 } 2170 if (ret < 0) 2171 return MODE_NOMODE; 2172 2173 total_memory_required = GX2CalculatePitchBytes(pMode->CrtcHDisplay, 2174 pScreenInfo->bitsPerPixel) * 2175 pMode->CrtcVDisplay; 2176 2177 DEBUGMSG(1, (0, X_NONE, "Total Mem %X %X\n", 2178 total_memory_required, pGeode->FBSize)); 2179 2180 if (total_memory_required > pGeode->FBSize) 2181 return MODE_MEM; 2182 2183 return MODE_OK; 2184} 2185 2186/*---------------------------------------------------------------------------- 2187 * GX2LoadPalette. 2188 * 2189 * Description :This function sets the palette entry used for graphics data 2190 * 2191 * Parameters. 2192 * pScreenInfo:Points the screeninfo structure. 2193 * numColors:Specifies the no of colors it supported. 2194 * indizes :This is used get index value . 2195 * LOCO :to be added. 2196 * pVisual :to be added. 2197 * 2198 * Returns :MODE_OK if the specified mode is supported or 2199 * MODE_NO_INTERLACE. 2200 * Comments :none. 2201*---------------------------------------------------------------------------- 2202*/ 2203 2204static void 2205GX2LoadPalette(ScrnInfoPtr pScreenInfo, 2206 int numColors, int *indizes, LOCO * colors, VisualPtr pVisual) 2207{ 2208 int i, index, color; 2209 2210 for (i = 0; i < numColors; i++) { 2211 index = indizes[i] & 0xFF; 2212 color = (((unsigned long)(colors[index].red & 0xFF)) << 16) | 2213 (((unsigned long)(colors[index].green & 0xFF)) << 8) | 2214 ((unsigned long)(colors[index].blue & 0xFF)); 2215 DEBUGMSG(0, (0, X_NONE, "GX2LoadPalette: %d %d %X\n", 2216 numColors, index, color)); 2217 2218 GFX(set_display_palette_entry(index, color)); 2219 } 2220} 2221 2222static Bool 2223GX2MapMem(ScrnInfoPtr pScreenInfo) 2224{ 2225 GeodePtr pGeode = GEODEPTR(pScreenInfo); 2226 2227#if defined(STB_X) 2228 pGeode->FBBase = (unsigned char *)xf86MapVidMem(pScreenInfo->scrnIndex, 2229 VIDMEM_FRAMEBUFFER, 2230 pGeode->FBLinearAddr, 2231 pGeode->FBSize); 2232 2233#else 2234 gfx_virt_regptr = (unsigned char *)xf86MapVidMem(pScreenInfo->scrnIndex, 2235 VIDMEM_MMIO, 2236 (unsigned int) 2237 gfx_get_cpu_register_base 2238 (), pGeode->cpu_reg_size); 2239 2240 if (pGeode->DetectedChipSet & GX2) { 2241 gfx_virt_gpptr = (unsigned char *)xf86MapVidMem(pScreenInfo->scrnIndex, 2242 VIDMEM_MMIO, 2243 (unsigned int) 2244 gfx_get_graphics_register_base 2245 (), 2246 pGeode->gp_reg_size); 2247 } else { 2248 gfx_virt_spptr = gfx_virt_regptr; 2249 } 2250 2251 gfx_virt_vidptr = (unsigned char *)xf86MapVidMem(pScreenInfo->scrnIndex, 2252 VIDMEM_MMIO, 2253 (unsigned int) 2254 gfx_get_vid_register_base 2255 (), pGeode->vid_reg_size); 2256 2257 gfx_virt_fbptr = (unsigned char *)xf86MapVidMem(pScreenInfo->scrnIndex, 2258 VIDMEM_FRAMEBUFFER, 2259 pGeode->FBLinearAddr, 2260 pGeode->FBSize); 2261 2262 pGeode->FBBase = gfx_virt_fbptr; 2263 2264 DEBUGMSG(1, (0, X_NONE, "Set mode %X %X %X %X %X\n", 2265 gfx_virt_regptr, 2266 gfx_virt_gpptr, 2267 gfx_virt_spptr, gfx_virt_vidptr, gfx_virt_fbptr)); 2268 2269 /* CHECK IF REGISTERS WERE MAPPED SUCCESSFULLY */ 2270 if ((!gfx_virt_regptr) || 2271 (!gfx_virt_gpptr) || (!gfx_virt_vidptr) || (!gfx_virt_fbptr)) { 2272 DEBUGMSG(1, (0, X_NONE, "Could not map hardware registers.\n")); 2273 return (FALSE); 2274 } 2275 2276 /* Map the XpressROM ptr to read what platform are we on */ 2277 XpressROMPtr = (unsigned char *)xf86MapVidMem(pScreenInfo->scrnIndex, 2278 VIDMEM_FRAMEBUFFER, 0xF0000, 2279 0x10000); 2280 2281 DEBUGMSG(1, (0, X_NONE, "adapter info %x %x %x %x, %X\n", 2282 pGeode->cpu_version, 2283 pGeode->vid_version, 2284 pGeode->FBSize, pGeode->FBBase, XpressROMPtr)); 2285#endif 2286 2287 return TRUE; 2288} 2289 2290/* 2291 * Unmap the framebuffer and MMIO memory. 2292 */ 2293 2294static Bool 2295GX2UnmapMem(ScrnInfoPtr pScreenInfo) 2296{ 2297#if !defined(STB_X) 2298 GeodePtr pGeode = GEODEPTR(pScreenInfo); 2299 2300 /* unmap all the memory map's */ 2301 xf86UnMapVidMem(pScreenInfo->scrnIndex, 2302 gfx_virt_regptr, pGeode->cpu_reg_size); 2303 if (pGeode->DetectedChipSet & GX2) { 2304 xf86UnMapVidMem(pScreenInfo->scrnIndex, 2305 gfx_virt_gpptr, pGeode->gp_reg_size); 2306 } 2307 xf86UnMapVidMem(pScreenInfo->scrnIndex, 2308 gfx_virt_vidptr, pGeode->vid_reg_size); 2309 xf86UnMapVidMem(pScreenInfo->scrnIndex, gfx_virt_fbptr, pGeode->FBSize); 2310 xf86UnMapVidMem(pScreenInfo->scrnIndex, XpressROMPtr, 0x10000); 2311#endif /* STB_X */ 2312 return TRUE; 2313} 2314 2315/* End of file */ 2316