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