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