1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/nsc_gx1_dga.c,v 1.1 2002/12/10 15:12:23 alanh Exp $ */ 2/* 3 * $Workfile: nsc_gx1_dga.c $ 4 * $Revision: 1.1.1.1 $ 5 * $Author: mrg $ 6 * 7 * File contents: DGA(Direct Acess Graphics mode) is feature of 8 * XFree86 that allows the program to access directly to video 9 * memory on the graphics card.DGA supports the double 10 * flickering.This file has the functions to support the DGA 11 * modes. 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#include "xf86.h" 151#include "xf86_OSproc.h" 152#include "xf86Pci.h" 153#include "xf86PciInfo.h" 154#include "xaa.h" 155#include "xaalocal.h" 156#include "nsc.h" 157#include "dgaproc.h" 158 159/* forward declarations */ 160static Bool GX1_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **, 161 int *, int *, int *); 162static void GX1_CloseFramebuffer(ScrnInfoPtr pScrn); 163static Bool GX1_SetMode(ScrnInfoPtr, DGAModePtr); 164static int GX1_GetViewport(ScrnInfoPtr); 165static void GX1_SetViewport(ScrnInfoPtr, int, int, int); 166static void GX1_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long); 167static void GX1_BlitRect(ScrnInfoPtr, int, int, int, int, int, int); 168 169extern void GX1AdjustFrame(int, int, int, int); 170extern Bool GX1SwitchMode(int, DisplayModePtr, int); 171extern void GX1AccelSync(ScrnInfoPtr pScreenInfo); 172 173Bool GX1DGAInit(ScreenPtr pScreen); 174 175static DGAFunctionRec GeodeDGAFuncs = { 176 GX1_OpenFramebuffer, 177 GX1_CloseFramebuffer, 178 GX1_SetMode, 179 GX1_SetViewport, 180 GX1_GetViewport, 181 GX1AccelSync, 182 GX1_FillRect, 183 GX1_BlitRect, 184 NULL 185}; 186 187/*---------------------------------------------------------------------------- 188 * GX1DGAInit. 189 * 190 * Description :This function is used to intiallize the DGA modes and sets the 191 viewport based on the screen mode. 192 * Parameters. 193 * pScreeen :Pointer to screen info structure. 194 * 195 * Returns :TRUE on success and FALSE on failure. 196 * 197 * Comments :This function prepares the DGA mode settings for 198 * other func reference. 199 * 200*---------------------------------------------------------------------------- 201*/ 202Bool 203GX1DGAInit(ScreenPtr pScreen) 204{ 205 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 206 GeodePtr pGeode = GEODEPTR(pScrn); 207 DGAModePtr modes = NULL, newmodes = NULL, currentMode; 208 DisplayModePtr pMode, firstMode; 209 int Bpp = pScrn->bitsPerPixel >> 3; 210 int num = 0; 211 Bool oneMore; 212 213 pMode = firstMode = pScrn->modes; 214 DEBUGMSG(0, (0, X_NONE, "GX1DGAInit\n")); 215 while (pMode) { 216 217 /* redundant but it can be used in future:if(0). */ 218 if (0) { /*pScrn->displayWidth != pMode->HDisplay */ 219 /* memory is allocated for dga to 220 *setup the viewport and mode parameters 221 */ 222 newmodes = xrealloc(modes, (num + 2) * sizeof(DGAModeRec)); 223 oneMore = TRUE; 224 } else { 225 /* one record is allocated here */ 226 newmodes = xrealloc(modes, (num + 1) * sizeof(DGAModeRec)); 227 oneMore = FALSE; 228 } 229 if (!newmodes) { 230 xfree(modes); 231 return FALSE; 232 } 233 modes = newmodes; 234 235 SECOND_PASS: /* DGA mode flgas and viewport parametrs are set here. */ 236 237 currentMode = modes + num; 238 num++; 239 currentMode->mode = pMode; 240 currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE; 241 currentMode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT; 242 if (pMode->Flags & V_DBLSCAN) 243 currentMode->flags |= DGA_DOUBLESCAN; 244 if (pMode->Flags & V_INTERLACE) 245 currentMode->flags |= DGA_INTERLACED; 246 currentMode->byteOrder = pScrn->imageByteOrder; 247 currentMode->depth = pScrn->depth; 248 currentMode->bitsPerPixel = pScrn->bitsPerPixel; 249 currentMode->red_mask = pScrn->mask.red; 250 currentMode->green_mask = pScrn->mask.green; 251 currentMode->blue_mask = pScrn->mask.blue; 252 currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor; 253 currentMode->viewportWidth = pMode->HDisplay; 254 currentMode->viewportHeight = pMode->VDisplay; 255 currentMode->xViewportStep = 1; 256 currentMode->yViewportStep = 1; 257 currentMode->viewportFlags = DGA_FLIP_RETRACE; 258 currentMode->offset = 0; 259 currentMode->address = pGeode->FBBase; 260 if (oneMore) { /* first one is narrow width */ 261 currentMode->bytesPerScanline = ((pMode->HDisplay * Bpp) + 3) & ~3L; 262 currentMode->imageWidth = pMode->HDisplay; 263 currentMode->imageHeight = pMode->VDisplay; 264 currentMode->pixmapWidth = currentMode->imageWidth; 265 currentMode->pixmapHeight = currentMode->imageHeight; 266 currentMode->maxViewportX = currentMode->imageWidth - 267 currentMode->viewportWidth; 268 /* this might need to get clamped to some maximum */ 269 currentMode->maxViewportY = currentMode->imageHeight - 270 currentMode->viewportHeight; 271 oneMore = FALSE; 272 goto SECOND_PASS; 273 } else { 274 currentMode->bytesPerScanline = 275 ((pScrn->displayWidth * Bpp) + 3) & ~3L; 276 currentMode->imageWidth = pScrn->displayWidth; 277 currentMode->imageHeight = pMode->VDisplay; 278 currentMode->pixmapWidth = currentMode->imageWidth; 279 currentMode->pixmapHeight = currentMode->imageHeight; 280 currentMode->maxViewportX = currentMode->imageWidth - 281 currentMode->viewportWidth; 282 /* this might need to get clamped to some maximum */ 283 currentMode->maxViewportY = currentMode->imageHeight - 284 currentMode->viewportHeight; 285 } 286 pMode = pMode->next; 287 if (pMode == firstMode) 288 break; 289 } 290 pGeode->numDGAModes = num; 291 pGeode->DGAModes = modes; 292 return DGAInit(pScreen, &GeodeDGAFuncs, modes, num); 293} 294 295/*---------------------------------------------------------------------------- 296 * GX1_SetMode. 297 * 298 * Description :This function is sets into the DGA mode. 299 *. 300 * Parameters. 301 * pScreeen :Pointer to screen info structure. 302 * pMode :Points to the DGAmode ptr data 303 * Returns :TRUE on success and FALSE on failure. 304 * 305 * Comments :none. 306 * 307 * 308*---------------------------------------------------------------------------- 309*/ 310static Bool 311GX1_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode) 312{ 313 static int OldDisplayWidth[MAXSCREENS]; 314 int index = pScrn->pScreen->myNum; 315 GeodePtr pGeode = GEODEPTR(pScrn); 316 317 DEBUGMSG(0, (0, X_NONE, "GX1_SetMode\n")); 318 if (!pMode) { 319 /* restore the original mode 320 * * put the ScreenParameters back 321 */ 322 pScrn->displayWidth = OldDisplayWidth[index]; 323 GX1SwitchMode(index, pScrn->currentMode, 0); 324 pGeode->DGAactive = FALSE; 325 } else { 326 if (!pGeode->DGAactive) { /* save the old parameters */ 327 OldDisplayWidth[index] = pScrn->displayWidth; 328 pGeode->DGAactive = TRUE; 329 } 330 pScrn->displayWidth = pMode->bytesPerScanline / 331 (pMode->bitsPerPixel >> 3); 332 GX1SwitchMode(index, pMode->mode, 0); 333 } 334 /* enable/disable cursor */ 335 if (pGeode->HWCursor) { 336#if defined(STB_X) 337 Gal_set_compression_enable(((pGeode->DGAactive) ? 338 GAL_COMPRESSION_DISABLE : 339 GAL_COMPRESSION_ENABLE)); 340 Gal_set_cursor_enable(!pGeode->DGAactive); 341#else 342 gfx_set_cursor_enable(!pGeode->DGAactive); 343 gfx_set_compression_enable(!pGeode->DGAactive); 344#endif /* STB_X */ 345 } 346 347 return TRUE; 348} 349 350/*---------------------------------------------------------------------------- 351 * GX1_GetViewPort. 352 * 353 * Description :This function is Gets the viewport window memory. 354 *. 355 * Parameters. 356 * pScrn :Pointer to screen info structure. 357 * 358 * Returns :returns the viewport status. 359 * 360 * Comments :none. 361 * 362 * 363*---------------------------------------------------------------------------- 364*/ 365static int 366GX1_GetViewport(ScrnInfoPtr pScrn) 367{ 368 GeodePtr pGeode = GEODEPTR(pScrn); 369 370 return pGeode->DGAViewportStatus; 371} 372 373/*---------------------------------------------------------------------------- 374 * GX1_SetViewPort. 375 * 376 * Description :This function is Gets the viewport window memory. 377 * 378 * Parameters. 379 * pScrn :Pointer to screen info structure. 380 x :x-cordinate of viewport window 381 * y :y-codinate of the viewport window. 382 * flags :indicates the viewport to be flipped or not. 383 * Returns :returns the viewport status as zero. 384 * 385 * Comments :none. 386 * 387*---------------------------------------------------------------------------- 388*/ 389static void 390GX1_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags) 391{ 392 GeodePtr pGeode = GEODEPTR(pScrn); 393 394 GX1AdjustFrame(pScrn->pScreen->myNum, x, y, flags); 395 pGeode->DGAViewportStatus = 0; /*GX1AdjustFrame loops until finished */ 396} 397 398/*---------------------------------------------------------------------------- 399 * GX1_FillRect. 400 * 401 * Description :This function is Gets the viewport window memory. 402 *. 403 * Parameters. 404 * pScrn :Pointer to screen info structure. 405 * x :x-cordinate of viewport window 406 * y :y-codinate of the viewport window. 407 * w :width of the rectangle 408 * h :height of the rectangle. 409 * color :color to be filled in rectangle. 410 * 411 * Returns :returns the viewport status as zero. 412 * 413 * Comments :This function is implemented by solidfill routines.. 414 * 415*---------------------------------------------------------------------------- 416*/ 417static void 418GX1_FillRect(ScrnInfoPtr pScrn, int x, int y, 419 int w, int h, unsigned long color) 420{ 421 GeodePtr pGeode = GEODEPTR(pScrn); 422 423 if (pGeode->AccelInfoRec) { 424 (*pGeode->AccelInfoRec->SetupForSolidFill) (pScrn, color, GXcopy, ~0); 425 (*pGeode->AccelInfoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h); 426 SET_SYNC_FLAG(pGeode->AccelInfoRec); 427 } 428} 429 430/*---------------------------------------------------------------------------- 431 * GX1_BlitRect. 432 * 433 * Description :This function implementing Blit and it moves a 434 * Rectangular block of data from one location to other 435 * Location. 436 * 437 * Parameters. 438 * pScrn :Pointer to screen info structure. 439 * srcx :x-cordinate of the src rectangle 440 * srcy :y-codinate of src rectangle. 441 * w :width of the rectangle 442 * h :height of the rectangle. 443 * dstx :x-cordinate of the dst rectangle. 444 * dsty :y -coordinates of the dst rectangle. 445 * Returns :none. 446 * 447 * Comments :none 448 * 449*---------------------------------------------------------------------------- 450*/ 451static void 452GX1_BlitRect(ScrnInfoPtr pScrn, int srcx, int srcy, int w, 453 int h, int dstx, int dsty) 454{ 455 GeodePtr pGeode = GEODEPTR(pScrn); 456 457 if (pGeode->AccelInfoRec) { 458 int xdir = ((srcx < dstx) && (srcy == dsty)) ? -1 : 1; 459 int ydir = (srcy < dsty) ? -1 : 1; 460 461 (*pGeode->AccelInfoRec->SetupForScreenToScreenCopy) 462 (pScrn, xdir, ydir, GXcopy, ~0, -1); 463 (*pGeode->AccelInfoRec->SubsequentScreenToScreenCopy) (pScrn, srcx, 464 srcy, dstx, dsty, 465 w, h); 466 SET_SYNC_FLAG(pGeode->AccelInfoRec); 467 } 468} 469 470/*---------------------------------------------------------------------------- 471 * GX1_OpenFramebuffer. 472 * 473 * Description :This function open the framebuffer driver for DGA. 474 * 475 * Parameters. 476 * pScrn :Pointer to screen info structure. 477 * srcx :x-cordinate of the src rectangle 478 * srcy :y-codinate of src rectangle. 479 * w :width of the rectangle 480 * h :height of the rectangle. 481 * dstx :x-cordinate of the dst rectangle. 482 * dsty :y -coordinates of the dst rectangle. 483 * Returns :none. 484 * 485 * Comments :none 486 * 487*---------------------------------------------------------------------------- 488*/ 489static Bool 490GX1_OpenFramebuffer(ScrnInfoPtr pScrn, 491 char **name, unsigned char **mem, 492 int *size, int *offset, int *flags) 493{ 494 GeodePtr pGeode = GEODEPTR(pScrn); 495 496 *name = NULL; /* no special device */ 497 *mem = (unsigned char *)pGeode->FBLinearAddr; 498 *size = pGeode->FBSize; 499 *offset = 0; 500 *flags = DGA_NEED_ROOT; 501 return TRUE; 502} 503 504static void 505GX1_CloseFramebuffer(ScrnInfoPtr pScrn) 506{ 507} 508 509/* end of file */ 510