sunFbs.c revision 9c576acf
1ee7c6486Stsutsui 2ee7c6486Stsutsui/* $Xorg: sunFbs.c,v 1.4 2001/02/09 02:04:43 xorgcvs Exp $ */ 3ee7c6486Stsutsui 4ee7c6486Stsutsui/* 5ee7c6486StsutsuiCopyright 1990, 1993, 1998 The Open Group 6ee7c6486Stsutsui 7ee7c6486StsutsuiPermission to use, copy, modify, distribute, and sell this software and its 8ee7c6486Stsutsuidocumentation for any purpose is hereby granted without fee, provided that 9ee7c6486Stsutsuithe above copyright notice appear in all copies and that both that 10ee7c6486Stsutsuicopyright notice and this permission notice appear in supporting 11ee7c6486Stsutsuidocumentation. 12ee7c6486Stsutsui 13ee7c6486StsutsuiThe above copyright notice and this permission notice shall be included in 14ee7c6486Stsutsuiall copies or substantial portions of the Software. 15ee7c6486Stsutsui 16ee7c6486StsutsuiTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17ee7c6486StsutsuiIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18ee7c6486StsutsuiFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19ee7c6486StsutsuiOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20ee7c6486StsutsuiAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21ee7c6486StsutsuiCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22ee7c6486Stsutsui 23ee7c6486StsutsuiExcept as contained in this notice, the name of The Open Group shall not be 24ee7c6486Stsutsuiused in advertising or otherwise to promote the sale, use or other dealings 25ee7c6486Stsutsuiin this Software without prior written authorization from The Open Group. 26ee7c6486Stsutsui */ 27ee7c6486Stsutsui 28ee7c6486Stsutsui/************************************************************ 29ee7c6486StsutsuiCopyright 1987 by Sun Microsystems, Inc. Mountain View, CA. 30ee7c6486Stsutsui 31ee7c6486Stsutsui All Rights Reserved 32ee7c6486Stsutsui 33ee7c6486StsutsuiPermission to use, copy, modify, and distribute this 34ee7c6486Stsutsuisoftware and its documentation for any purpose and without 35ee7c6486Stsutsuifee is hereby granted, provided that the above copyright no- 36ee7c6486Stsutsuitice appear in all copies and that both that copyright no- 37ee7c6486Stsutsuitice and this permission notice appear in supporting docu- 38ee7c6486Stsutsuimentation, and that the names of Sun or The Open Group 39ee7c6486Stsutsuinot be used in advertising or publicity pertaining to 40ee7c6486Stsutsuidistribution of the software without specific prior 41ee7c6486Stsutsuiwritten permission. Sun and The Open Group make no 42ee7c6486Stsutsuirepresentations about the suitability of this software for 43ee7c6486Stsutsuiany purpose. It is provided "as is" without any express or 44ee7c6486Stsutsuiimplied warranty. 45ee7c6486Stsutsui 46ee7c6486StsutsuiSUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 47ee7c6486StsutsuiINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 48ee7c6486StsutsuiNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 49ee7c6486StsutsuiABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 50ee7c6486StsutsuiANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 51ee7c6486StsutsuiPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 52ee7c6486StsutsuiOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 53ee7c6486StsutsuiTHE USE OR PERFORMANCE OF THIS SOFTWARE. 54ee7c6486Stsutsui 55ee7c6486Stsutsui********************************************************/ 56ee7c6486Stsutsui 57ee7c6486Stsutsui/* 58ee7c6486Stsutsui * Copyright 1987 by the Regents of the University of California 59ee7c6486Stsutsui * Copyright 1987 by Adam de Boor, UC Berkeley 60ee7c6486Stsutsui * 61ee7c6486Stsutsui * Permission to use, copy, modify, and distribute this 62ee7c6486Stsutsui * software and its documentation for any purpose and without 63ee7c6486Stsutsui * fee is hereby granted, provided that the above copyright 64ee7c6486Stsutsui * notice appear in all copies. The University of California 65ee7c6486Stsutsui * makes no representations about the suitability of this 66ee7c6486Stsutsui * software for any purpose. It is provided "as is" without 67ee7c6486Stsutsui * express or implied warranty. 68ee7c6486Stsutsui */ 69ee7c6486Stsutsui 70ee7c6486Stsutsui/* $XFree86: xc/programs/Xserver/hw/sun/sunFbs.c,v 1.8 2003/11/17 22:20:36 dawes Exp $ */ 71ee7c6486Stsutsui 72ee7c6486Stsutsui/****************************************************************/ 73ee7c6486Stsutsui/* Modified from sunCG4C.c for X11R3 by Tom Jarmolowski */ 74ee7c6486Stsutsui/****************************************************************/ 75ee7c6486Stsutsui 76ee7c6486Stsutsui#include "sun.h" 77ee7c6486Stsutsui#include <sys/mman.h> 78ee7c6486Stsutsui 79ee7c6486Stsutsuistatic Bool closeScreen(ScreenPtr pScreen); 80ee7c6486Stsutsui 81ee7c6486Stsutsuiint sunScreenIndex; 82ee7c6486Stsutsui 83ee7c6486StsutsuiDevPrivateKeyRec sunScreenPrivateKeyRec; 84ee7c6486Stsutsui 85ee7c6486Stsutsuivoid * 86ee7c6486StsutsuisunMemoryMap(size_t len, off_t off, int fd) 87ee7c6486Stsutsui{ 88ee7c6486Stsutsui int pagemask, mapsize; 89ee7c6486Stsutsui caddr_t addr; 90ee7c6486Stsutsui void *mapaddr; 91ee7c6486Stsutsui 92ee7c6486Stsutsui#ifdef SVR4 93ee7c6486Stsutsui pagemask = sysconf(_SC_PAGESIZE) - 1; 94ee7c6486Stsutsui#else 95ee7c6486Stsutsui pagemask = getpagesize() - 1; 96ee7c6486Stsutsui#endif 97ee7c6486Stsutsui mapsize = ((int) len + pagemask) & ~pagemask; 98ee7c6486Stsutsui addr = 0; 99ee7c6486Stsutsui 100ee7c6486Stsutsui#if !defined(__bsdi__) && !defined(_MAP_NEW) && !defined(__NetBSD__) && !defined(__OpenBSD__) 101ee7c6486Stsutsui if ((addr = (caddr_t) valloc (mapsize)) == NULL) { 1029c576acfStsutsui ErrorF("Couldn't allocate frame buffer memory\n"); 103ee7c6486Stsutsui (void) close (fd); 104ee7c6486Stsutsui return NULL; 105ee7c6486Stsutsui } 106ee7c6486Stsutsui#endif 107ee7c6486Stsutsui 108ee7c6486Stsutsui#if !defined(__NetBSD__) && !defined(__OpenBSD__) 109ee7c6486Stsutsui /* 110ee7c6486Stsutsui * try and make it private first, that way once we get it, an 111ee7c6486Stsutsui * interloper, e.g. another server, can't get this frame buffer, 112ee7c6486Stsutsui * and if another server already has it, this one won't. 113ee7c6486Stsutsui */ 114ee7c6486Stsutsui if ((int)(mapaddr = (void *) mmap (addr, 115ee7c6486Stsutsui mapsize, 116ee7c6486Stsutsui PROT_READ | PROT_WRITE, MAP_PRIVATE, 117ee7c6486Stsutsui fd, off)) == -1) 118ee7c6486Stsutsui#endif 119ee7c6486Stsutsui mapaddr = mmap (addr, 120ee7c6486Stsutsui mapsize, 121ee7c6486Stsutsui PROT_READ | PROT_WRITE, MAP_SHARED, 122ee7c6486Stsutsui fd, off); 123ee7c6486Stsutsui if (mapaddr == (void *) -1) { 1249c576acfStsutsui ErrorF("mapping frame buffer memory\n"); 125ee7c6486Stsutsui (void) close (fd); 126ee7c6486Stsutsui mapaddr = NULL; 127ee7c6486Stsutsui } 128ee7c6486Stsutsui return mapaddr; 129ee7c6486Stsutsui} 130ee7c6486Stsutsui 131ee7c6486StsutsuiBool 132ee7c6486StsutsuisunScreenAllocate(ScreenPtr pScreen) 133ee7c6486Stsutsui{ 134ee7c6486Stsutsui sunScreenPtr pPrivate; 135ee7c6486Stsutsui 136ee7c6486Stsutsui if (!dixRegisterPrivateKey(&sunScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) { 1379c576acfStsutsui ErrorF("dixRegisterPrivateKey failed\n"); 138ee7c6486Stsutsui return FALSE; 139ee7c6486Stsutsui } 14097c02368Stsutsui pPrivate = calloc(1, sizeof (sunScreenRec)); 141ee7c6486Stsutsui if (!pPrivate) 142ee7c6486Stsutsui return FALSE; 143ee7c6486Stsutsui 1441a0e0615Stsutsui pPrivate->origColormapValid = FALSE; 145ee7c6486Stsutsui sunSetScreenPrivate(pScreen, pPrivate); 146ee7c6486Stsutsui return TRUE; 147ee7c6486Stsutsui} 148ee7c6486Stsutsui 149ee7c6486StsutsuiBool 150ee7c6486StsutsuisunSaveScreen(ScreenPtr pScreen, int on) 151ee7c6486Stsutsui{ 152ee7c6486Stsutsui int state; 153ee7c6486Stsutsui 154ee7c6486Stsutsui if (on != SCREEN_SAVER_FORCER) 155ee7c6486Stsutsui { 156ee7c6486Stsutsui if (on == SCREEN_SAVER_ON) 157ee7c6486Stsutsui state = 0; 158ee7c6486Stsutsui else 159ee7c6486Stsutsui state = 1; 160ee7c6486Stsutsui (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state); 161ee7c6486Stsutsui } 162ee7c6486Stsutsui return( TRUE ); 163ee7c6486Stsutsui} 164ee7c6486Stsutsui 165ee7c6486Stsutsuistatic Bool 166ee7c6486StsutsuicloseScreen(ScreenPtr pScreen) 167ee7c6486Stsutsui{ 168ee7c6486Stsutsui sunScreenPtr pPrivate = sunGetScreenPrivate(pScreen); 169ee7c6486Stsutsui Bool ret; 170ee7c6486Stsutsui 171ee7c6486Stsutsui (void) OsSignal (SIGIO, SIG_IGN); 172ee7c6486Stsutsui#if 0 /* XXX GX is disabled for now */ 173ee7c6486Stsutsui sunDisableCursor (pScreen); 174ee7c6486Stsutsui#endif 17597c02368Stsutsui if (pPrivate->origColormapValid) 17697c02368Stsutsui (*pPrivate->RestoreColormap)(pScreen); 177ee7c6486Stsutsui pScreen->CloseScreen = pPrivate->CloseScreen; 178ee7c6486Stsutsui ret = (*pScreen->CloseScreen) (pScreen); 179ee7c6486Stsutsui (void) (*pScreen->SaveScreen) (pScreen, SCREEN_SAVER_OFF); 180ee7c6486Stsutsui free (pPrivate); 181ee7c6486Stsutsui return ret; 182ee7c6486Stsutsui} 183ee7c6486Stsutsui 184ee7c6486StsutsuiBool 185ee7c6486StsutsuisunScreenInit(ScreenPtr pScreen) 186ee7c6486Stsutsui{ 187ee7c6486Stsutsui sunScreenPtr pPrivate = sunGetScreenPrivate(pScreen); 188ee7c6486Stsutsui 189ee7c6486Stsutsui pPrivate->installedMap = 0; 190ee7c6486Stsutsui pPrivate->CloseScreen = pScreen->CloseScreen; 191ee7c6486Stsutsui pScreen->CloseScreen = closeScreen; 192ee7c6486Stsutsui pScreen->SaveScreen = sunSaveScreen; 193ee7c6486Stsutsui#if 0 /* XXX GX is disabled for now */ 194ee7c6486Stsutsui if (!sunCursorInitialize (pScreen)) 195ee7c6486Stsutsui#endif 196ee7c6486Stsutsui miDCInitialize (pScreen, &sunPointerScreenFuncs); 197ee7c6486Stsutsui return TRUE; 198ee7c6486Stsutsui} 199ee7c6486Stsutsui 200ee7c6486StsutsuiBool 201ee7c6486StsutsuisunInitCommon( 202ee7c6486Stsutsui int scrn, 203ee7c6486Stsutsui ScreenPtr pScrn, 204ee7c6486Stsutsui off_t offset, 205ee7c6486Stsutsui Bool (*init1)(ScreenPtr, void *, int, int, int, int, int, int), 206ee7c6486Stsutsui void (*init2)(ScreenPtr), 207ee7c6486Stsutsui Bool (*cr_cm)(ScreenPtr), 208ee7c6486Stsutsui Bool (*save)(ScreenPtr, int), 209ee7c6486Stsutsui int fb_off 210ee7c6486Stsutsui) 211ee7c6486Stsutsui{ 212ee7c6486Stsutsui unsigned char* fb = sunFbs[scrn].fb; 213ee7c6486Stsutsui 214ee7c6486Stsutsui if (!sunScreenAllocate (pScrn)) 215ee7c6486Stsutsui return FALSE; 216ee7c6486Stsutsui if (!fb) { 217ee7c6486Stsutsui if ((fb = sunMemoryMap ((size_t) sunFbs[scrn].info.fb_size, 218ee7c6486Stsutsui offset, 219ee7c6486Stsutsui sunFbs[scrn].fd)) == NULL) 220ee7c6486Stsutsui return FALSE; 221ee7c6486Stsutsui sunFbs[scrn].fb = fb; 222ee7c6486Stsutsui } 223ee7c6486Stsutsui /* mfbScreenInit() or cfbScreenInit() */ 224ee7c6486Stsutsui if (!(*init1)(pScrn, fb + fb_off, 225ee7c6486Stsutsui sunFbs[scrn].info.fb_width, 226ee7c6486Stsutsui sunFbs[scrn].info.fb_height, 227ee7c6486Stsutsui monitorResolution, monitorResolution, 228ee7c6486Stsutsui sunFbs[scrn].info.fb_width, 229ee7c6486Stsutsui sunFbs[scrn].info.fb_depth)) 230ee7c6486Stsutsui return FALSE; 231ee7c6486Stsutsui /* sunCGScreenInit() if cfb... */ 232ee7c6486Stsutsui if (init2) 233ee7c6486Stsutsui (*init2)(pScrn); 234ee7c6486Stsutsui if (!sunScreenInit(pScrn)) 235ee7c6486Stsutsui return FALSE; 236ee7c6486Stsutsui (void) (*save) (pScrn, SCREEN_SAVER_OFF); 237ee7c6486Stsutsui return (*cr_cm)(pScrn); 238ee7c6486Stsutsui} 239ee7c6486Stsutsui 240