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