tcx_driver.c revision 59d6bc2b
1/* 2 * TCX framebuffer driver. 3 * 4 * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com) 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24#ifdef HAVE_CONFIG_H 25#include "config.h" 26#endif 27 28#include <fcntl.h> 29#include <sys/types.h> 30#include <sys/time.h> 31#include <string.h> 32#include <sys/ioctl.h> 33#include <dev/sun/fbio.h> 34#include <dev/wscons/wsconsio.h> 35 36#include "xf86.h" 37#include "xf86_OSproc.h" 38#include "mipointer.h" 39#include "micmap.h" 40 41#include "fb.h" 42#include "xf86cmap.h" 43#include "tcx.h" 44 45static const OptionInfoRec * TCXAvailableOptions(int chipid, int busid); 46static void TCXIdentify(int flags); 47static Bool TCXProbe(DriverPtr drv, int flags); 48static Bool TCXPreInit(ScrnInfoPtr pScrn, int flags); 49static Bool TCXScreenInit(SCREEN_INIT_ARGS_DECL); 50static Bool TCXEnterVT(VT_FUNC_ARGS_DECL); 51static void TCXLeaveVT(VT_FUNC_ARGS_DECL); 52static Bool TCXCloseScreen(CLOSE_SCREEN_ARGS_DECL); 53static Bool TCXSaveScreen(ScreenPtr pScreen, int mode); 54static void TCXInitCplane24(ScrnInfoPtr pScrn); 55 56/* Required if the driver supports mode switching */ 57static Bool TCXSwitchMode(SWITCH_MODE_ARGS_DECL); 58/* Required if the driver supports moving the viewport */ 59static void TCXAdjustFrame(ADJUST_FRAME_ARGS_DECL); 60 61/* Optional functions */ 62static void TCXFreeScreen(FREE_SCREEN_ARGS_DECL); 63static ModeStatus TCXValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, 64 Bool verbose, int flags); 65 66void TCXSync(ScrnInfoPtr pScrn); 67 68#define TCX_VERSION 4000 69#define TCX_NAME "SUNTCX" 70#define TCX_DRIVER_NAME "suntcx" 71#define TCX_MAJOR_VERSION PACKAGE_VERSION_MAJOR 72#define TCX_MINOR_VERSION PACKAGE_VERSION_MINOR 73#define TCX_PATCHLEVEL PACKAGE_VERSION_PATCHLEVEL 74 75/* 76 * This contains the functions needed by the server after loading the driver 77 * module. It must be supplied, and gets passed back by the SetupProc 78 * function in the dynamic case. In the static case, a reference to this 79 * is compiled in, and this requires that the name of this DriverRec be 80 * an upper-case version of the driver name. 81 */ 82 83_X_EXPORT DriverRec SUNTCX = { 84 TCX_VERSION, 85 TCX_DRIVER_NAME, 86 TCXIdentify, 87 TCXProbe, 88 TCXAvailableOptions, 89 NULL, 90 0 91}; 92 93typedef enum { 94 OPTION_SW_CURSOR, 95 OPTION_HW_CURSOR, 96 OPTION_NOACCEL 97} TCXOpts; 98 99static const OptionInfoRec TCXOptions[] = { 100 { OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE }, 101 { OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, TRUE }, 102 { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE }, 103 { -1, NULL, OPTV_NONE, {0}, FALSE } 104}; 105 106#ifdef XFree86LOADER 107 108static MODULESETUPPROTO(tcxSetup); 109 110static XF86ModuleVersionInfo suntcxVersRec = 111{ 112 "suntcx", 113 MODULEVENDORSTRING, 114 MODINFOSTRING1, 115 MODINFOSTRING2, 116 XORG_VERSION_CURRENT, 117 TCX_MAJOR_VERSION, TCX_MINOR_VERSION, TCX_PATCHLEVEL, 118 ABI_CLASS_VIDEODRV, 119 ABI_VIDEODRV_VERSION, 120 MOD_CLASS_VIDEODRV, 121 {0,0,0,0} 122}; 123 124_X_EXPORT XF86ModuleData suntcxModuleData = { &suntcxVersRec, tcxSetup, NULL }; 125 126pointer 127tcxSetup(pointer module, pointer opts, int *errmaj, int *errmin) 128{ 129 static Bool setupDone = FALSE; 130 131 if (!setupDone) { 132 setupDone = TRUE; 133 xf86AddDriver(&SUNTCX, module, 0); 134 135 /* 136 * Modules that this driver always requires can be loaded here 137 * by calling LoadSubModule(). 138 */ 139 140 /* 141 * The return value must be non-NULL on success even though there 142 * is no TearDownProc. 143 */ 144 return (pointer)TRUE; 145 } else { 146 if (errmaj) *errmaj = LDR_ONCEONLY; 147 return NULL; 148 } 149} 150 151#endif /* XFree86LOADER */ 152 153static Bool 154TCXGetRec(ScrnInfoPtr pScrn) 155{ 156 /* 157 * Allocate an TcxRec, and hook it into pScrn->driverPrivate. 158 * pScrn->driverPrivate is initialised to NULL, so we can check if 159 * the allocation has already been done. 160 */ 161 if (pScrn->driverPrivate != NULL) 162 return TRUE; 163 164 pScrn->driverPrivate = xnfcalloc(sizeof(TcxRec), 1); 165 return TRUE; 166} 167 168static void 169TCXFreeRec(ScrnInfoPtr pScrn) 170{ 171 TcxPtr pTcx; 172 173 if (pScrn->driverPrivate == NULL) 174 return; 175 176 pTcx = GET_TCX_FROM_SCRN(pScrn); 177 178 free(pScrn->driverPrivate); 179 pScrn->driverPrivate = NULL; 180 181 return; 182} 183 184static const OptionInfoRec * 185TCXAvailableOptions(int chipid, int busid) 186{ 187 return TCXOptions; 188} 189 190/* Mandatory */ 191static void 192TCXIdentify(int flags) 193{ 194 xf86Msg(X_INFO, "%s: driver for TCX\n", TCX_NAME); 195} 196 197 198/* Mandatory */ 199static Bool 200TCXProbe(DriverPtr drv, int flags) 201{ 202 int i; 203 GDevPtr *devSections; 204 int *usedChips; 205 int numDevSections; 206 int numUsed; 207 Bool foundScreen = FALSE; 208 EntityInfoPtr pEnt; 209 210 /* 211 * The aim here is to find all cards that this driver can handle, 212 * and for the ones not already claimed by another driver, claim the 213 * slot, and allocate a ScrnInfoRec. 214 * 215 * This should be a minimal probe, and it should under no circumstances 216 * change the state of the hardware. Because a device is found, don't 217 * assume that it will be used. Don't do any initialisations other than 218 * the required ScrnInfoRec initialisations. Don't allocate any new 219 * data structures. 220 */ 221 222 /* 223 * Next we check, if there has been a chipset override in the config file. 224 * For this we must find out if there is an active device section which 225 * is relevant, i.e., which has no driver specified or has THIS driver 226 * specified. 227 */ 228 229 if ((numDevSections = xf86MatchDevice(TCX_DRIVER_NAME, 230 &devSections)) <= 0) { 231 /* 232 * There's no matching device section in the config file, so quit 233 * now. 234 */ 235 return FALSE; 236 } 237 238 /* 239 * We need to probe the hardware first. We then need to see how this 240 * fits in with what is given in the config file, and allow the config 241 * file info to override any contradictions. 242 */ 243 244 numUsed = xf86MatchSbusInstances(TCX_NAME, SBUS_DEVICE_TCX, 245 devSections, numDevSections, 246 drv, &usedChips); 247 248 free(devSections); 249 if (numUsed <= 0) 250 return FALSE; 251 252 if (flags & PROBE_DETECT) 253 foundScreen = TRUE; 254 else for (i = 0; i < numUsed; i++) { 255 pEnt = xf86GetEntityInfo(usedChips[i]); 256 257 /* 258 * Check that nothing else has claimed the slots. 259 */ 260 if(pEnt->active) { 261 ScrnInfoPtr pScrn; 262 263 /* Allocate a ScrnInfoRec and claim the slot */ 264 pScrn = xf86AllocateScreen(drv, 0); 265 266 /* Fill in what we can of the ScrnInfoRec */ 267 pScrn->driverVersion = TCX_VERSION; 268 pScrn->driverName = TCX_DRIVER_NAME; 269 pScrn->name = TCX_NAME; 270 pScrn->Probe = TCXProbe; 271 pScrn->PreInit = TCXPreInit; 272 pScrn->ScreenInit = TCXScreenInit; 273 pScrn->SwitchMode = TCXSwitchMode; 274 pScrn->AdjustFrame = TCXAdjustFrame; 275 pScrn->EnterVT = TCXEnterVT; 276 pScrn->LeaveVT = TCXLeaveVT; 277 pScrn->FreeScreen = TCXFreeScreen; 278 pScrn->ValidMode = TCXValidMode; 279 xf86AddEntityToScreen(pScrn, pEnt->index); 280 foundScreen = TRUE; 281 } 282 free(pEnt); 283 } 284 free(usedChips); 285 return foundScreen; 286} 287 288/* Mandatory */ 289static Bool 290TCXPreInit(ScrnInfoPtr pScrn, int flags) 291{ 292 TcxPtr pTcx; 293 sbusDevicePtr psdp = NULL; 294 MessageType from; 295 int i, prom; 296 int hwCursor, lowDepth; 297 298 if (flags & PROBE_DETECT) return FALSE; 299 300 /* 301 * Note: This function is only called once at server startup, and 302 * not at the start of each server generation. This means that 303 * only things that are persistent across server generations can 304 * be initialised here. xf86Screens[] is (pScrn is a pointer to one 305 * of these). Privates allocated using xf86AllocateScrnInfoPrivateIndex() 306 * are too, and should be used for data that must persist across 307 * server generations. 308 * 309 * Per-generation data should be allocated with 310 * AllocateScreenPrivateIndex() from the ScreenInit() function. 311 */ 312 313 /* Allocate the TcxRec driverPrivate */ 314 if (!TCXGetRec(pScrn)) { 315 return FALSE; 316 } 317 pTcx = GET_TCX_FROM_SCRN(pScrn); 318 319 /* Set pScrn->monitor */ 320 pScrn->monitor = pScrn->confScreen->monitor; 321 322 /* This driver doesn't expect more than one entity per screen */ 323 if (pScrn->numEntities > 1) 324 return FALSE; 325 /* This is the general case */ 326 for (i = 0; i < pScrn->numEntities; i++) { 327 EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[i]); 328 329 /* TCX is purely AFX, but we handle it like SBUS */ 330 if (pEnt->location.type == BUS_SBUS) { 331 psdp = xf86GetSbusInfoForEntity(pEnt->index); 332 pTcx->psdp = psdp; 333 } else 334 return FALSE; 335 } 336 if (psdp == NULL) 337 return FALSE; 338 339 /********************** 340 check card capabilities 341 **********************/ 342 hwCursor = 0; 343 lowDepth = 1; 344 345 prom = sparcPromInit(); 346 hwCursor = sparcPromGetBool(&psdp->node, "hw-cursor"); 347 lowDepth = sparcPromGetBool(&psdp->node, "tcx-8-bit"); 348 349 pTcx->Is8bit = (lowDepth != 0); 350 /* all S24 support a hardware cursor */ 351 if (!lowDepth) { 352 hwCursor = 1; 353 pTcx->vramsize = 0x100000; /* size of the 8bit fb */ 354 } else { 355 char *b; 356 int len = 4, v = 0; 357 358 /* see if we have more than 1MB vram */ 359 pTcx->vramsize = 0x100000; 360 if ((b = sparcPromGetProperty(&psdp->node, "vram", &len)) != NULL) { 361 memcpy(&v, b, 4); 362 if ((v > 0) && (v < 3)) 363 pTcx->vramsize = 0x100000 * v; 364 } 365 xf86Msg(X_ERROR, "found %d MB video memory\n", v); 366 367 } 368 if (prom) 369 sparcPromClose(); 370 371 xf86Msg(X_ERROR, "hw-cursor: %d\n", hwCursor); 372 373 /********************* 374 deal with depth 375 *********************/ 376 377 if (!xf86SetDepthBpp(pScrn, lowDepth ? 8 : 0, 0, 0, 378 lowDepth ? NoDepth24Support : Support32bppFb)) { 379 return FALSE; 380 } else { 381 /* Check that the returned depth is one we support */ 382 switch (pScrn->depth) { 383 case 8: 384 /* OK */ 385 break; 386 case 32: 387 case 24: 388 /* unless lowDepth OK */ 389 if (lowDepth) { 390 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 391 "Given depth (32) not supported by hardware\n"); 392 return FALSE; 393 } 394 break; 395 default: 396 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 397 "Given depth (%d) is not supported by this driver\n", 398 pScrn->depth); 399 return FALSE; 400 } 401 } 402 403 /* Collect all of the relevant option flags (fill in pScrn->options) */ 404 xf86CollectOptions(pScrn, NULL); 405 /* Process the options */ 406 if (!(pTcx->Options = malloc(sizeof(TCXOptions)))) 407 return FALSE; 408 memcpy(pTcx->Options, TCXOptions, sizeof(TCXOptions)); 409 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pTcx->Options); 410 411 /* 412 * This must happen after pScrn->display has been set because 413 * xf86SetWeight references it. 414 */ 415 if (pScrn->depth > 8) { 416 rgb weight = {0, 0, 0}; 417 rgb mask = {0xff, 0xff00, 0xff0000}; 418 419 if (!xf86SetWeight(pScrn, weight, mask)) { 420 return FALSE; 421 } 422 } 423 424 if (!xf86SetDefaultVisual(pScrn, -1)) 425 return FALSE; 426 else if (pScrn->depth > 8) { 427 /* We don't currently support DirectColor */ 428 if (pScrn->defaultVisual != TrueColor) { 429 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual" 430 " (%s) is not supported\n", 431 xf86GetVisualName(pScrn->defaultVisual)); 432 return FALSE; 433 } 434 } 435 436 /* 437 * The new cmap code requires this to be initialised. 438 */ 439 440 { 441 Gamma zeros = {0.0, 0.0, 0.0}; 442 443 if (!xf86SetGamma(pScrn, zeros)) { 444 return FALSE; 445 } 446 } 447 448 /* determine whether we use hardware or software cursor */ 449 450 from = X_PROBED; 451 pTcx->HWCursor = FALSE; 452 if (hwCursor) { 453 from = X_DEFAULT; 454 pTcx->HWCursor = TRUE; 455 if (xf86GetOptValBool(pTcx->Options, OPTION_HW_CURSOR, &pTcx->HWCursor)) 456 from = X_CONFIG; 457 if (xf86ReturnOptValBool(pTcx->Options, OPTION_SW_CURSOR, FALSE)) { 458 from = X_CONFIG; 459 pTcx->HWCursor = FALSE; 460 } 461 } 462 463 pTcx->NoAccel = FALSE; 464 if (xf86ReturnOptValBool(pTcx->Options, OPTION_NOACCEL, FALSE)) { 465 pTcx->NoAccel = TRUE; 466 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n"); 467 } 468 469 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n", 470 pTcx->HWCursor ? "HW" : "SW"); 471 472 if (xf86LoadSubModule(pScrn, "fb") == NULL) { 473 TCXFreeRec(pScrn); 474 return FALSE; 475 } 476 477 if (pTcx->HWCursor && xf86LoadSubModule(pScrn, "ramdac") == NULL) { 478 TCXFreeRec(pScrn); 479 return FALSE; 480 } 481 482 /********************* 483 set up clock and mode stuff 484 *********************/ 485 486 pScrn->progClock = TRUE; 487 488 if(pScrn->display->virtualX || pScrn->display->virtualY) { 489 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 490 "TCX does not support a virtual desktop\n"); 491 pScrn->display->virtualX = 0; 492 pScrn->display->virtualY = 0; 493 } 494 495 xf86SbusUseBuiltinMode(pScrn, pTcx->psdp); 496 pScrn->currentMode = pScrn->modes; 497 pScrn->displayWidth = pScrn->virtualX; 498 499 /* Set display resolution */ 500 xf86SetDpi(pScrn, 0, 0); 501 502 return TRUE; 503} 504 505/* Mandatory */ 506 507/* This gets called at the start of each server generation */ 508 509static Bool 510TCXScreenInit(SCREEN_INIT_ARGS_DECL) 511{ 512 ScrnInfoPtr pScrn; 513 TcxPtr pTcx; 514 VisualPtr visual; 515 int ret; 516 517 /* 518 * First get the ScrnInfoRec 519 */ 520 pScrn = xf86ScreenToScrn(pScreen); 521 522 pTcx = GET_TCX_FROM_SCRN(pScrn); 523 524 /* Map the TCX memory */ 525 if (pScrn->depth == 8) { 526 pTcx->fb = 527 xf86MapSbusMem (pTcx->psdp, TCX_RAM8_VOFF, pTcx->vramsize); 528 pTcx->pitchshift = 0; 529 } else { 530 pTcx->fb = 531 xf86MapSbusMem (pTcx->psdp, TCX_RAM24_VOFF, 1024 * 1024 * 4); 532 pTcx->cplane = 533 xf86MapSbusMem (pTcx->psdp, TCX_CPLANE_VOFF, 1024 * 1024 * 4); 534 pTcx->pitchshift = 2; 535 if (! pTcx->cplane) 536 return FALSE; 537 } 538 if (pTcx->HWCursor == TRUE) { 539 pTcx->thc = xf86MapSbusMem (pTcx->psdp, TCX_THC_VOFF, 8192); 540 if (! pTcx->thc) 541 return FALSE; 542 } 543 544 if (pTcx->Is8bit) { 545 /* use STIP and BLIT on tcx */ 546 pTcx->rblit = xf86MapSbusMem(pTcx->psdp, TCX_BLIT_VOFF, 8 * pTcx->vramsize); 547 if (pTcx->rblit == NULL) { 548 xf86Msg(X_ERROR, "Couldn't map BLIT space\n"); 549 return FALSE; 550 } 551 pTcx->rstip = xf86MapSbusMem(pTcx->psdp, TCX_STIP_VOFF, 8 * pTcx->vramsize); 552 if (pTcx->rstip == NULL) { 553 xf86Msg(X_ERROR, "Couldn't map STIP space\n"); 554 return FALSE; 555 } 556 } else { 557 /* use RSTIP and RBLIT on S24 */ 558 pTcx->rblit = xf86MapSbusMem(pTcx->psdp, TCX_RBLIT_VOFF, 8 * 1024 * 1024); 559 if (pTcx->rblit == NULL) { 560 xf86Msg(X_ERROR, "Couldn't map RBLIT space\n"); 561 return FALSE; 562 } 563 pTcx->rstip = xf86MapSbusMem(pTcx->psdp, TCX_RSTIP_VOFF, 8 * 1024 * 1024); 564 if (pTcx->rstip == NULL) { 565 xf86Msg(X_ERROR, "Couldn't map RSTIP space\n"); 566 return FALSE; 567 } 568 } 569 570 if (! pTcx->fb) 571 return FALSE; 572 573 /* Darken the screen for aesthetic reasons and set the viewport */ 574 TCXSaveScreen(pScreen, SCREEN_SAVER_ON); 575 576 /* 577 * The next step is to setup the screen's visuals, and initialise the 578 * framebuffer code. In cases where the framebuffer's default 579 * choices for things like visual layouts and bits per RGB are OK, 580 * this may be as simple as calling the framebuffer's ScreenInit() 581 * function. If not, the visuals will need to be setup before calling 582 * a fb ScreenInit() function and fixed up after. 583 */ 584 585 /* 586 * Reset visual list. 587 */ 588 miClearVisualTypes(); 589 590 if (pScrn->depth == 8) 591 /* Set the bits per RGB for 8bpp mode */ 592 pScrn->rgbBits = 8; 593 594 /* Setup the visuals we support. */ 595 596 if (!miSetVisualTypes(pScrn->depth, 597 pScrn->depth != 8 ? TrueColorMask : 598 miGetDefaultVisualMask(pScrn->depth), 599 pScrn->rgbBits, pScrn->defaultVisual)) 600 return FALSE; 601 602 miSetPixmapDepths (); 603 604 /* 605 * Call the framebuffer layer's ScreenInit function, and fill in other 606 * pScreen fields. 607 */ 608 609 if (pScrn->bitsPerPixel != 8) 610 TCXInitCplane24(pScrn); 611 ret = fbScreenInit(pScreen, pTcx->fb, pScrn->virtualX, 612 pScrn->virtualY, pScrn->xDpi, pScrn->yDpi, 613 pScrn->virtualX, pScrn->bitsPerPixel); 614 615 if (!ret) 616 return FALSE; 617 618 xf86SetBlackWhitePixels(pScreen); 619 620 if (pScrn->bitsPerPixel > 8) { 621 /* Fixup RGB ordering */ 622 visual = pScreen->visuals + pScreen->numVisuals; 623 while (--visual >= pScreen->visuals) { 624 if ((visual->class | DynamicClass) == DirectColor) { 625 visual->offsetRed = pScrn->offset.red; 626 visual->offsetGreen = pScrn->offset.green; 627 visual->offsetBlue = pScrn->offset.blue; 628 visual->redMask = pScrn->mask.red; 629 visual->greenMask = pScrn->mask.green; 630 visual->blueMask = pScrn->mask.blue; 631 } 632 } 633 } 634 635#ifdef RENDER 636 /* must be after RGB ordering fixed */ 637 fbPictureInit (pScreen, 0, 0); 638#endif 639 640 if (!pTcx->NoAccel) { 641 XF86ModReqInfo req; 642 int errmaj, errmin; 643 644 memset(&req, 0, sizeof(XF86ModReqInfo)); 645 req.majorversion = 2; 646 req.minorversion = 0; 647 if (!LoadSubModule(pScrn->module, "exa", NULL, NULL, NULL, &req, 648 &errmaj, &errmin)) 649 { 650 LoaderErrorMsg(NULL, "exa", errmaj, errmin); 651 return FALSE; 652 } 653 if (!TcxInitAccel(pScreen)) 654 return FALSE; 655 } 656 657 miInitializeBackingStore(pScreen); 658 659 xf86SetBackingStore(pScreen); 660 xf86SetSilkenMouse(pScreen); 661 662 /* Initialise cursor functions */ 663 miDCInitialize (pScreen, xf86GetPointerScreenFuncs()); 664 665 /* Initialize HW cursor layer. 666 Must follow software cursor initialization*/ 667 if (pTcx->HWCursor) { 668 extern Bool TCXHWCursorInit(ScreenPtr pScreen); 669 670 if(!TCXHWCursorInit(pScreen)) { 671 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 672 "Hardware cursor initialization failed\n"); 673 return(FALSE); 674 } 675 xf86SbusHideOsHwCursor(pTcx->psdp); 676 } 677 678 /* Initialise default colourmap */ 679 if (!miCreateDefColormap(pScreen)) 680 return FALSE; 681 682 if(pScrn->depth == 8 && !xf86SbusHandleColormaps(pScreen, pTcx->psdp)) 683 return FALSE; 684 685 pTcx->CloseScreen = pScreen->CloseScreen; 686 pScreen->CloseScreen = TCXCloseScreen; 687 pScreen->SaveScreen = TCXSaveScreen; 688 689 /* Report any unused options (only for the first generation) */ 690 if (serverGeneration == 1) { 691 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); 692 } 693 694 /* unblank the screen */ 695 TCXSaveScreen(pScreen, SCREEN_SAVER_OFF); 696 697 /* Done */ 698 return TRUE; 699} 700 701 702/* Usually mandatory */ 703static Bool 704TCXSwitchMode(SWITCH_MODE_ARGS_DECL) 705{ 706 return TRUE; 707} 708 709 710/* 711 * This function is used to initialize the Start Address - the first 712 * displayed location in the video memory. 713 */ 714/* Usually mandatory */ 715static void 716TCXAdjustFrame(ADJUST_FRAME_ARGS_DECL) 717{ 718 /* we don't support virtual desktops */ 719 return; 720} 721 722/* 723 * This is called when VT switching back to the X server. Its job is 724 * to reinitialise the video mode. 725 */ 726 727/* Mandatory */ 728static Bool 729TCXEnterVT(VT_FUNC_ARGS_DECL) 730{ 731 SCRN_INFO_PTR(arg); 732 TcxPtr pTcx = GET_TCX_FROM_SCRN(pScrn); 733 734 if (pTcx->HWCursor) { 735 xf86SbusHideOsHwCursor (pTcx->psdp); 736 pTcx->CursorFg = 0; 737 pTcx->CursorBg = 0; 738 } 739 if (pTcx->cplane) { 740 TCXInitCplane24 (pScrn); 741 } 742 return TRUE; 743} 744 745 746/* 747 * This is called when VT switching away from the X server. 748 */ 749 750/* Mandatory */ 751static void 752TCXLeaveVT(VT_FUNC_ARGS_DECL) 753{ 754 return; 755} 756 757 758/* 759 * This is called at the end of each server generation. It restores the 760 * original (text) mode. It should really also unmap the video memory too. 761 */ 762 763/* Mandatory */ 764static Bool 765TCXCloseScreen(CLOSE_SCREEN_ARGS_DECL) 766{ 767 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); 768 TcxPtr pTcx = GET_TCX_FROM_SCRN(pScrn); 769 770 pScrn->vtSema = FALSE; 771 if (pScrn->depth == 8) 772 xf86UnmapSbusMem(pTcx->psdp, pTcx->fb, 773 (pTcx->psdp->width * pTcx->psdp->height)); 774 else { 775 xf86UnmapSbusMem(pTcx->psdp, pTcx->fb, 776 (pTcx->psdp->width * pTcx->psdp->height * 4)); 777 xf86UnmapSbusMem(pTcx->psdp, pTcx->cplane, 778 (pTcx->psdp->width * pTcx->psdp->height * 4)); 779 } 780 if (pTcx->thc) 781 xf86UnmapSbusMem(pTcx->psdp, pTcx->thc, 8192); 782 783 if (pTcx->HWCursor) 784 xf86SbusHideOsHwCursor (pTcx->psdp); 785 786 pScreen->CloseScreen = pTcx->CloseScreen; 787 return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS); 788} 789 790 791/* Free up any per-generation data structures */ 792 793/* Optional */ 794static void 795TCXFreeScreen(FREE_SCREEN_ARGS_DECL) 796{ 797 SCRN_INFO_PTR(arg); 798 TCXFreeRec(pScrn); 799} 800 801 802/* Checks if a mode is suitable for the selected chipset. */ 803 804/* Optional */ 805static ModeStatus 806TCXValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags) 807{ 808 if (mode->Flags & V_INTERLACE) 809 return(MODE_BAD); 810 811 return(MODE_OK); 812} 813 814/* Do screen blanking */ 815 816/* Mandatory */ 817static Bool 818TCXSaveScreen(ScreenPtr pScreen, int mode) 819 /* this function should blank the screen when unblank is FALSE and 820 unblank it when unblank is TRUE -- it doesn't actually seem to be 821 used for much though */ 822{ 823 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 824 TcxPtr pTcx = GET_TCX_FROM_SCRN(pScrn); 825 int fd = pTcx->psdp->fd, state; 826 827 /* 828 * we're using ioctl() instead of just whacking the DAC because the 829 * underlying driver will also turn off the backlight which we couldn't do 830 * from here without adding lots more hardware dependencies 831 */ 832 switch(mode) 833 { 834 case SCREEN_SAVER_ON: 835 case SCREEN_SAVER_CYCLE: 836 state = 0; 837 if(ioctl(fd, FBIOSVIDEO, &state) == -1) 838 { 839 /* complain */ 840 } 841 break; 842 case SCREEN_SAVER_OFF: 843 case SCREEN_SAVER_FORCER: 844 state = 1; 845 if(ioctl(fd, FBIOSVIDEO, &state) == -1) 846 { 847 /* complain */ 848 } 849 break; 850 default: 851 return FALSE; 852 } 853 854 return TRUE; 855} 856 857/* 858 * This is the implementation of the Sync() function. 859 */ 860void 861TCXSync(ScrnInfoPtr pScrn) 862{ 863 return; 864} 865 866/* 867 * This initializes CPLANE for 24 bit mode. 868 */ 869static void 870TCXInitCplane24(ScrnInfoPtr pScrn) 871{ 872 TcxPtr pTcx = GET_TCX_FROM_SCRN(pScrn); 873 int size; 874 unsigned int *p, *q; 875 876 if (!pTcx->cplane) 877 return; 878 879 size = pScrn->virtualX * pScrn->virtualY; 880 memset (pTcx->fb, 0, size * 4); 881 p = pTcx->cplane; 882 for (q = pTcx->cplane + size; p != q; p++) 883 *p = (*p & 0xffffff) | TCX_CPLANE_MODE; 884} 885