home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / sun / sunCG6C.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-26  |  5.8 KB  |  204 lines

  1. /*-
  2.  * sunCG6C.c --
  3.  *    Functions to support the sun CG6 board as a memory frame buffer.
  4.  */
  5.  
  6. /****************************************************************/
  7. /* Modified from  sunCG4C.c for X11R3 by Tom Jarmolowski    */
  8. /****************************************************************/
  9.  
  10. /************************************************************
  11. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  12.  
  13.                     All Rights Reserved
  14.  
  15. Permission  to  use,  copy,  modify,  and  distribute   this
  16. software  and  its documentation for any purpose and without
  17. fee is hereby granted, provided that the above copyright no-
  18. tice  appear  in all copies and that both that copyright no-
  19. tice and this permission notice appear in  supporting  docu-
  20. mentation,  and  that the names of Sun or MIT not be used in
  21. advertising or publicity pertaining to distribution  of  the
  22. software  without specific prior written permission. Sun and
  23. M.I.T. make no representations about the suitability of this
  24. software for any purpose. It is provided "as is" without any
  25. express or implied warranty.
  26.  
  27. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  28. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  29. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  30. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  32. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  33. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  34. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  35.  
  36. ********************************************************/
  37.  
  38. #include    "sun.h"
  39.  
  40. #ifdef FBTYPE_SUNFAST_COLOR
  41. #include    <sys/mman.h>
  42. #include    <pixrect/memreg.h>
  43. #include    "colormap.h"
  44. #include    "colormapst.h"
  45. #include    "resource.h"
  46. #include    <cfb.h>
  47. #include    <struct.h>
  48.  
  49. #define CG6_VBASE    0x70000000
  50.  
  51. #define CG6_IMAGE(fb)        ((caddr_t)(&(fb)->cpixel))
  52. #define CG6_IMAGEOFF        ((off_t)0x16000)
  53. #define CG6_GXOFF        ((off_t)0)
  54.  
  55. /*-
  56.  *-----------------------------------------------------------------------
  57.  * sunCG6Init --
  58.  *    Attempt to find and initialize a cg6 framebuffer
  59.  *
  60.  * Results:
  61.  *    TRUE if everything went ok. FALSE if not.
  62.  *
  63.  * Side Effects:
  64.  *    Most of the elements of the ScreenRec are filled in. Memory is
  65.  *    allocated for the frame buffer and the buffer is mapped. The
  66.  *    video is enabled for the frame buffer...
  67.  *
  68.  *-----------------------------------------------------------------------
  69.  */
  70. /*ARGSUSED*/
  71. static Bool
  72. sunCG6CInit (index, pScreen, argc, argv)
  73.     int              index;        /* The index of pScreen in the ScreenInfo */
  74.     ScreenPtr      pScreen;      /* The Screen to initialize */
  75.     int              argc;            /* The number of the Server's arguments. */
  76.     char          **argv;       /* The arguments themselves. Don't change! */
  77. {
  78.     int    i;
  79.     char    *pbits;
  80.     int        w, h;
  81.  
  82.     pbits =  (char *) (sunFbs[index].fb + CG6_IMAGEOFF);
  83.     w = sunFbs[index].info.fb_width;
  84.     h = sunFbs[index].info.fb_height;
  85.     if (!cfbSetupScreen (pScreen, pbits, w, h,
  86.             monitorResolution, monitorResolution, w))
  87.     return FALSE;
  88.  
  89. #ifdef sparc
  90.     if (!sunGXInit (pScreen, &sunFbs[index]))
  91.     return FALSE;
  92. #endif
  93.  
  94.     if (!cfbFinishScreenInit(pScreen, pbits, w, h,
  95.             monitorResolution, monitorResolution, w))
  96.     return FALSE;
  97.  
  98.     if (!sunScreenAllocate (pScreen))
  99.     return FALSE;
  100.  
  101.     sunCGScreenInit (pScreen);
  102.  
  103.     if (!sunScreenInit (pScreen))
  104.     return FALSE;
  105.  
  106.     sunSaveScreen (pScreen, SCREEN_SAVER_OFF);
  107.  
  108.     return cfbCreateDefColormap(pScreen);
  109. }
  110.  
  111. /*-
  112.  *-----------------------------------------------------------------------
  113.  * sunCG6Probe --
  114.  *    Attempt to find and initialize a cg6 framebuffer
  115.  *
  116.  * Results:
  117.  *    TRUE if everything went ok. FALSE if not.
  118.  *
  119.  * Side Effects:
  120.  *    Memory is allocated for the frame buffer and the buffer is mapped.
  121.  *
  122.  *-----------------------------------------------------------------------
  123.  */
  124. Bool
  125. sunCG6CProbe (pScreenInfo, index, fbNum, argc, argv)
  126.     ScreenInfo      *pScreenInfo;    /* The screenInfo struct */
  127.     int              index;        /* The index of pScreen in the ScreenInfo */
  128.     int              fbNum;        /* Index into the sunFbData array */
  129.     int              argc;            /* The number of the Server's arguments. */
  130.     char          **argv;       /* The arguments themselves. Don't change! */
  131. {
  132.     int         fd;
  133.     struct fbtype fbType;
  134.     int        pagemask, mapsize;
  135.     int        imagelen;
  136.     caddr_t    mapaddr;
  137.     caddr_t    addr;
  138.  
  139.     if ((fd = sunOpenFrameBuffer(FBTYPE_SUNFAST_COLOR, &fbType, index, fbNum,
  140.                  argc, argv)) < 0)
  141.     return FALSE;
  142.  
  143.     pagemask = getpagesize() - 1;
  144.     imagelen = CG6_IMAGEOFF + fbType.fb_width * fbType.fb_height;
  145.     mapsize = (imagelen + pagemask) & ~pagemask;
  146.     addr = 0;
  147.  
  148. #ifndef    _MAP_NEW
  149.     addr = (caddr_t) valloc(mapsize);
  150.     if (addr == (caddr_t) NULL) {
  151.     ErrorF("Could not allocate room for frame buffer.\n");
  152.     (void) close (fd);
  153.     return FALSE;
  154.     }
  155. #endif    _MAP_NEW
  156.  
  157.     /*
  158.      * Should always try to MAP_PRIVATE first.  We want to have a private
  159.      * copy of the registers on context switching if possible.
  160.      */
  161.     mapaddr = (caddr_t) mmap((caddr_t) addr,
  162.          mapsize,
  163.          PROT_READ | PROT_WRITE,
  164.          MAP_PRIVATE, fd, CG6_VBASE);
  165.  
  166.     if (mapaddr == (caddr_t) -1)
  167.     {
  168.         mapaddr = (caddr_t) mmap((caddr_t) addr,
  169.               mapsize,
  170.               PROT_READ | PROT_WRITE,
  171.               MAP_SHARED, fd, CG6_VBASE);
  172.     }
  173.  
  174.     if (mapaddr == (caddr_t) -1) {
  175.     Error("Mapping cg6c");
  176.     (void) close(fd);
  177.     return FALSE;
  178.     }
  179.  
  180.     if (mapaddr == 0)
  181.         mapaddr = addr;
  182.  
  183.     sunFbs[index].fd = fd;
  184.     sunFbs[index].info = fbType;
  185.     sunFbs[index].fb = (pointer) mapaddr;
  186.     sunSupportsDepth8 = TRUE;
  187.     return TRUE;
  188. }
  189.  
  190. Bool
  191. sunCG6CCreate(pScreenInfo, argc, argv)
  192.     ScreenInfo      *pScreenInfo;
  193.     int              argc;
  194.     char          **argv;
  195. {
  196.     int i;
  197.  
  198.     i = AddScreen(sunCG6CInit, argc, argv);
  199.     if (i >= 0)
  200.     return TRUE;
  201.     return FALSE;
  202. }
  203. #endif /* FBTYPE_SUNFAST_COLOR */
  204.