From 0f834b91a4768673833ab4917e87d86c237bb1a6 Mon Sep 17 00:00:00 2001 From: marha Date: Fri, 23 Mar 2012 10:05:55 +0100 Subject: libX11 xserver fontconfig mesa pixman xkbcomp xkeyboard-config git update 23 Mar 2012 --- .../hw/xfree86/os-support/solaris/sun_VTsw.c | 271 ++++++----- .../hw/xfree86/os-support/solaris/sun_apm.c | 453 +++++++++--------- .../hw/xfree86/os-support/solaris/sun_bell.c | 363 +++++++-------- .../hw/xfree86/os-support/solaris/sun_init.c | 502 ++++++++++---------- .../hw/xfree86/os-support/solaris/sun_vid.c | 505 ++++++++++----------- 5 files changed, 1033 insertions(+), 1061 deletions(-) (limited to 'xorg-server/hw/xfree86/os-support/solaris') diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c b/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c index d145ac77b..573358b43 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c @@ -1,137 +1,134 @@ -/* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#include -#include - -/* - * Handle the VT-switching interface for Solaris/OpenSolaris - */ - -static int xf86VTPruneDoor = 0; - -void -xf86VTRelease(int sig) -{ - if (xf86Info.vtPendingNum == -1) - { - xf86VTPruneDoor = 1; - xf86Info.vtRequestsPending = TRUE; - return; - } - - ioctl(xf86Info.consoleFd, VT_RELDISP, 1); - xf86Info.vtPendingNum = -1; - - return; -} - -void -xf86VTAcquire(int sig) -{ - xf86Info.vtRequestsPending = TRUE; - return; -} - -Bool -xf86VTSwitchPending(void) -{ - return xf86Info.vtRequestsPending ? TRUE : FALSE; -} - -Bool -xf86VTSwitchAway(void) -{ - int door_fd; - vt_cmd_arg_t vt_door_arg; - door_arg_t door_arg; - - xf86Info.vtRequestsPending = FALSE; - - if (xf86VTPruneDoor) { - xf86VTPruneDoor = 0; - ioctl(xf86Info.consoleFd, VT_RELDISP, 1); - return TRUE; - } - - vt_door_arg.vt_ev = VT_EV_HOTKEYS; - vt_door_arg.vt_num = xf86Info.vtPendingNum; - door_arg.data_ptr = (char *)&vt_door_arg; - door_arg.data_size = sizeof (vt_cmd_arg_t); - door_arg.rbuf = NULL; - door_arg.rsize = 0; - door_arg.desc_ptr = NULL; - door_arg.desc_num = 0; - - if ((door_fd = open(VT_DAEMON_DOOR_FILE, O_RDONLY)) < 0) - return FALSE; - - if (door_call(door_fd, &door_arg) != 0) { - close(door_fd); - return FALSE; - } - - close(door_fd); - return TRUE; -} - -Bool -xf86VTSwitchTo(void) -{ - xf86Info.vtRequestsPending = FALSE; - if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) - { - return FALSE; - } - else - { - return TRUE; - } -} - -Bool -xf86VTActivate(int vtno) -{ - struct vt_stat state; - - if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0) - return FALSE; - - if ((state.v_state & (1 << vtno)) == 0) - return FALSE; - - xf86Info.vtRequestsPending = TRUE; - xf86Info.vtPendingNum = vtno; - - return TRUE; -} +/* + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#include +#include + +/* + * Handle the VT-switching interface for Solaris/OpenSolaris + */ + +static int xf86VTPruneDoor = 0; + +void +xf86VTRelease(int sig) +{ + if (xf86Info.vtPendingNum == -1) { + xf86VTPruneDoor = 1; + xf86Info.vtRequestsPending = TRUE; + return; + } + + ioctl(xf86Info.consoleFd, VT_RELDISP, 1); + xf86Info.vtPendingNum = -1; + + return; +} + +void +xf86VTAcquire(int sig) +{ + xf86Info.vtRequestsPending = TRUE; + return; +} + +Bool +xf86VTSwitchPending(void) +{ + return xf86Info.vtRequestsPending ? TRUE : FALSE; +} + +Bool +xf86VTSwitchAway(void) +{ + int door_fd; + vt_cmd_arg_t vt_door_arg; + door_arg_t door_arg; + + xf86Info.vtRequestsPending = FALSE; + + if (xf86VTPruneDoor) { + xf86VTPruneDoor = 0; + ioctl(xf86Info.consoleFd, VT_RELDISP, 1); + return TRUE; + } + + vt_door_arg.vt_ev = VT_EV_HOTKEYS; + vt_door_arg.vt_num = xf86Info.vtPendingNum; + door_arg.data_ptr = (char *) &vt_door_arg; + door_arg.data_size = sizeof(vt_cmd_arg_t); + door_arg.rbuf = NULL; + door_arg.rsize = 0; + door_arg.desc_ptr = NULL; + door_arg.desc_num = 0; + + if ((door_fd = open(VT_DAEMON_DOOR_FILE, O_RDONLY)) < 0) + return FALSE; + + if (door_call(door_fd, &door_arg) != 0) { + close(door_fd); + return FALSE; + } + + close(door_fd); + return TRUE; +} + +Bool +xf86VTSwitchTo(void) +{ + xf86Info.vtRequestsPending = FALSE; + if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) { + return FALSE; + } + else { + return TRUE; + } +} + +Bool +xf86VTActivate(int vtno) +{ + struct vt_stat state; + + if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0) + return FALSE; + + if ((state.v_state & (1 << vtno)) == 0) + return FALSE; + + xf86Info.vtRequestsPending = TRUE; + xf86Info.vtPendingNum = vtno; + + return TRUE; +} diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c b/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c index 7a5128ffb..4ff64649a 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c @@ -1,226 +1,227 @@ -/* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit - * copyright notice, so is covered by the following notice: - * - * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF - * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Except as contained in this notice, the name of the XFree86 Project shall - * not be used in advertising or otherwise to promote the sale, use or other - * dealings in this Software without prior written authorization from the - * XFree86 Project. - */ - -/* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" -#include "xf86_OSlib.h" - -#ifndef PLEASE_FIX_THIS -#define APM_STANDBY_REQ 0xa01 -#define APM_SUSPEND_REQ 0xa02 -#define APM_NORMAL_RESUME 0xa03 -#define APM_CRIT_RESUME 0xa04 -#define APM_BATTERY_LOW 0xa05 -#define APM_POWER_CHANGE 0xa06 -#define APM_UPDATE_TIME 0xa07 -#define APM_CRIT_SUSPEND_REQ 0xa08 -#define APM_USER_STANDBY_REQ 0xa09 -#define APM_USER_SUSPEND_REQ 0xa0a -#define APM_SYS_STANDBY_RESUME 0xa0b -#define APM_IOC_NEXTEVENT 0xa0c -#define APM_IOC_RESUME 0xa0d -#define APM_IOC_SUSPEND 0xa0e -#define APM_IOC_STANDBY 0xa0f -#endif - -typedef struct apm_event_info -{ - int type; -} apm_event_info; - -/* - This may be replaced with a better device name - very soon... -*/ -#define APM_DEVICE "/dev/srn" -#define APM_DEVICE1 "/dev/apm" - -static pointer APMihPtr = NULL; -static void sunCloseAPM(void); - -static struct { - u_int apmBsd; - pmEvent xf86; -} sunToXF86Array [] = { - { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY }, - { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND }, - { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME }, - { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME }, - { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY }, - { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE }, - { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME }, - { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND }, - { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY }, - { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND }, - { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME }, -#ifdef APM_CAPABILITY_CHANGE - { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED }, -#endif -}; - -#define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0])) - -static pmEvent -sunToXF86(int type) -{ - int i; - - for (i = 0; i < numApmEvents; i++) { - if (type == sunToXF86Array[i].apmBsd) { - return sunToXF86Array[i].xf86; - } - } - return XF86_APM_UNKNOWN; -} - -/* - * APM events can be requested direclty from /dev/apm - */ -static int -sunPMGetEventFromOS(int fd, pmEvent *events, int num) -{ - struct apm_event_info sunEvent; - int i; - - for (i = 0; i < num; i++) { - - if (ioctl(fd, APM_IOC_NEXTEVENT, &sunEvent) < 0) { - if (errno != EAGAIN) { - xf86Msg(X_WARNING, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT" - " %s\n", strerror(errno)); - } - break; - } - events[i] = sunToXF86(sunEvent.type); - } - xf86Msg(X_WARNING, "Got some events\n"); - return i; -} - -static pmWait -sunPMConfirmEventToOs(int fd, pmEvent event) -{ - switch (event) { -/* XXX: NOT CURRENTLY RETURNED FROM OS */ - case XF86_APM_SYS_STANDBY: - case XF86_APM_USER_STANDBY: - if (ioctl( fd, APM_IOC_STANDBY, NULL ) == 0) - return PM_WAIT; /* should we stop the Xserver in standby, too? */ - else - return PM_NONE; - case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: - case XF86_APM_USER_SUSPEND: - xf86Msg(X_WARNING, "Got SUSPENDED\n"); - if (ioctl( fd, APM_IOC_SUSPEND, NULL ) == 0) - return PM_CONTINUE; - else { - xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_SUSPEND" - " %s\n", strerror(errno)); - return PM_FAILED; - } - case XF86_APM_STANDBY_RESUME: - case XF86_APM_NORMAL_RESUME: - case XF86_APM_CRITICAL_RESUME: - case XF86_APM_STANDBY_FAILED: - case XF86_APM_SUSPEND_FAILED: - xf86Msg(X_WARNING, "Got RESUME\n"); - if (ioctl( fd, APM_IOC_RESUME, NULL ) == 0) - return PM_CONTINUE; - else { - xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_RESUME" - " %s\n", strerror(errno)); - return PM_FAILED; - } - default: - return PM_NONE; - } -} - -PMClose -xf86OSPMOpen(void) -{ - int fd; - - if (APMihPtr || !xf86Info.pmFlag) { - return NULL; - } - - if ((fd = open(APM_DEVICE, O_RDWR)) == -1) { - if ((fd = open(APM_DEVICE1, O_RDWR)) == -1) { - return NULL; - } - } - xf86PMGetEventFromOs = sunPMGetEventFromOS; - xf86PMConfirmEventToOs = sunPMConfirmEventToOs; - APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); - return sunCloseAPM; -} - -static void -sunCloseAPM(void) -{ - int fd; - - if (APMihPtr) { - fd = xf86RemoveGeneralHandler(APMihPtr); - close(fd); - APMihPtr = NULL; - } -} +/* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit + * copyright notice, so is covered by the following notice: + * + * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of the XFree86 Project shall + * not be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization from the + * XFree86 Project. + */ + +/* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS +#include "xf86_OSproc.h" +#include "xf86_OSlib.h" + +#ifndef PLEASE_FIX_THIS +#define APM_STANDBY_REQ 0xa01 +#define APM_SUSPEND_REQ 0xa02 +#define APM_NORMAL_RESUME 0xa03 +#define APM_CRIT_RESUME 0xa04 +#define APM_BATTERY_LOW 0xa05 +#define APM_POWER_CHANGE 0xa06 +#define APM_UPDATE_TIME 0xa07 +#define APM_CRIT_SUSPEND_REQ 0xa08 +#define APM_USER_STANDBY_REQ 0xa09 +#define APM_USER_SUSPEND_REQ 0xa0a +#define APM_SYS_STANDBY_RESUME 0xa0b +#define APM_IOC_NEXTEVENT 0xa0c +#define APM_IOC_RESUME 0xa0d +#define APM_IOC_SUSPEND 0xa0e +#define APM_IOC_STANDBY 0xa0f +#endif + +typedef struct apm_event_info { + int type; +} apm_event_info; + +/* + This may be replaced with a better device name + very soon... +*/ +#define APM_DEVICE "/dev/srn" +#define APM_DEVICE1 "/dev/apm" + +static pointer APMihPtr = NULL; +static void sunCloseAPM(void); + +static struct { + u_int apmBsd; + pmEvent xf86; +} sunToXF86Array[] = { + { + APM_STANDBY_REQ, XF86_APM_SYS_STANDBY}, { + APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND}, { + APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME}, { + APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME}, { + APM_BATTERY_LOW, XF86_APM_LOW_BATTERY}, { + APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE}, { + APM_UPDATE_TIME, XF86_APM_UPDATE_TIME}, { + APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND}, { + APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY}, { + APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND}, { + APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME}, +#ifdef APM_CAPABILITY_CHANGE + { + APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED}, +#endif +}; + +#define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0])) + +static pmEvent +sunToXF86(int type) +{ + int i; + + for (i = 0; i < numApmEvents; i++) { + if (type == sunToXF86Array[i].apmBsd) { + return sunToXF86Array[i].xf86; + } + } + return XF86_APM_UNKNOWN; +} + +/* + * APM events can be requested direclty from /dev/apm + */ +static int +sunPMGetEventFromOS(int fd, pmEvent * events, int num) +{ + struct apm_event_info sunEvent; + int i; + + for (i = 0; i < num; i++) { + + if (ioctl(fd, APM_IOC_NEXTEVENT, &sunEvent) < 0) { + if (errno != EAGAIN) { + xf86Msg(X_WARNING, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT" + " %s\n", strerror(errno)); + } + break; + } + events[i] = sunToXF86(sunEvent.type); + } + xf86Msg(X_WARNING, "Got some events\n"); + return i; +} + +static pmWait +sunPMConfirmEventToOs(int fd, pmEvent event) +{ + switch (event) { +/* XXX: NOT CURRENTLY RETURNED FROM OS */ + case XF86_APM_SYS_STANDBY: + case XF86_APM_USER_STANDBY: + if (ioctl(fd, APM_IOC_STANDBY, NULL) == 0) + return PM_WAIT; /* should we stop the Xserver in standby, too? */ + else + return PM_NONE; + case XF86_APM_SYS_SUSPEND: + case XF86_APM_CRITICAL_SUSPEND: + case XF86_APM_USER_SUSPEND: + xf86Msg(X_WARNING, "Got SUSPENDED\n"); + if (ioctl(fd, APM_IOC_SUSPEND, NULL) == 0) + return PM_CONTINUE; + else { + xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_SUSPEND" + " %s\n", strerror(errno)); + return PM_FAILED; + } + case XF86_APM_STANDBY_RESUME: + case XF86_APM_NORMAL_RESUME: + case XF86_APM_CRITICAL_RESUME: + case XF86_APM_STANDBY_FAILED: + case XF86_APM_SUSPEND_FAILED: + xf86Msg(X_WARNING, "Got RESUME\n"); + if (ioctl(fd, APM_IOC_RESUME, NULL) == 0) + return PM_CONTINUE; + else { + xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_RESUME" + " %s\n", strerror(errno)); + return PM_FAILED; + } + default: + return PM_NONE; + } +} + +PMClose +xf86OSPMOpen(void) +{ + int fd; + + if (APMihPtr || !xf86Info.pmFlag) { + return NULL; + } + + if ((fd = open(APM_DEVICE, O_RDWR)) == -1) { + if ((fd = open(APM_DEVICE1, O_RDWR)) == -1) { + return NULL; + } + } + xf86PMGetEventFromOs = sunPMGetEventFromOS; + xf86PMConfirmEventToOs = sunPMConfirmEventToOs; + APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); + return sunCloseAPM; +} + +static void +sunCloseAPM(void) +{ + int fd; + + if (APMihPtr) { + fd = xf86RemoveGeneralHandler(APMihPtr); + close(fd); + APMihPtr = NULL; + } +} diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c b/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c index 8cd4de25b..beb13d2e9 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c @@ -1,180 +1,183 @@ -/* Copyright (c) 2004-2005, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#define BELL_RATE 48000 /* Samples per second */ -#define BELL_HZ 50 /* Fraction of a second i.e. 1/x */ -#define BELL_MS (1000/BELL_HZ) /* MS */ -#define BELL_SAMPLES (BELL_RATE / BELL_HZ) -#define BELL_MIN 3 /* Min # of repeats */ - -#define AUDIO_DEVICE "/dev/audio" - -void -xf86OSRingBell(int loudness, int pitch, int duration) -{ - static short samples[BELL_SAMPLES]; - static short silence[BELL_SAMPLES]; /* "The Sound of Silence" */ - static int lastFreq; - int cnt; - int i; - int written; - int repeats; - int freq; - audio_info_t audioInfo; - struct iovec iov[IOV_MAX]; - int iovcnt; - double ampl, cyclen, phase; - int audioFD; - - if ((loudness <= 0) || (pitch <= 0) || (duration <= 0)) { - return; - } - - lastFreq = 0; - memset(silence, 0, sizeof(silence)); - - audioFD = open(AUDIO_DEVICE, O_WRONLY | O_NONBLOCK); - if (audioFD == -1) { - xf86Msg(X_ERROR, "Bell: cannot open audio device \"%s\": %s\n", - AUDIO_DEVICE, strerror(errno)); - return; - } - - freq = pitch; - freq = min(freq, (BELL_RATE / 2) - 1); - freq = max(freq, 2 * BELL_HZ); - - /* - * Ensure full waves per buffer - */ - freq -= freq % BELL_HZ; - - if (freq != lastFreq) { - lastFreq = freq; - ampl = 16384.0; - - cyclen = (double) freq / (double) BELL_RATE; - phase = 0.0; - - for (i = 0; i < BELL_SAMPLES; i++) { - samples[i] = (short) (ampl * sin(2.0 * M_PI * phase)); - phase += cyclen; - if (phase >= 1.0) - phase -= 1.0; - } - } - - repeats = (duration + (BELL_MS / 2)) / BELL_MS; - repeats = max(repeats, BELL_MIN); - - loudness = max(0, loudness); - loudness = min(loudness, 100); - -#ifdef DEBUG - ErrorF("BELL : freq %d volume %d duration %d repeats %d\n", - freq, loudness, duration, repeats); -#endif - - AUDIO_INITINFO(&audioInfo); - audioInfo.play.encoding = AUDIO_ENCODING_LINEAR; - audioInfo.play.sample_rate = BELL_RATE; - audioInfo.play.channels = 2; - audioInfo.play.precision = 16; - audioInfo.play.gain = min(AUDIO_MAX_GAIN, AUDIO_MAX_GAIN * loudness / 100); - - if (ioctl(audioFD, AUDIO_SETINFO, &audioInfo) < 0){ - xf86Msg(X_ERROR, - "Bell: AUDIO_SETINFO failed on audio device \"%s\": %s\n", - AUDIO_DEVICE, strerror(errno)); - close(audioFD); - return; - } - - iovcnt = 0; - - for (cnt = 0; cnt <= repeats; cnt++) { - if (cnt == repeats) { - /* Insert a bit of silence so that multiple beeps are distinct and - * not compressed into a single tone. - */ - iov[iovcnt].iov_base = (char *) silence; - iov[iovcnt++].iov_len = sizeof(silence); - } else { - iov[iovcnt].iov_base = (char *) samples; - iov[iovcnt++].iov_len = sizeof(samples); - } - if ((iovcnt >= IOV_MAX) || (cnt == repeats)) { - written = writev(audioFD, iov, iovcnt); - - if ((written < ((int)(sizeof(samples) * iovcnt)))) { - /* audio buffer was full! */ - - int naptime; - - if (written == -1) { - if (errno != EAGAIN) { - xf86Msg(X_ERROR, - "Bell: writev failed on audio device \"%s\": %s\n", - AUDIO_DEVICE, strerror(errno)); - close(audioFD); - return; - } - i = iovcnt; - } else { - i = ((sizeof(samples) * iovcnt) - written) - / sizeof(samples); - } - cnt -= i; - - /* sleep a little to allow audio buffer to drain */ - naptime = BELL_MS * i; - poll(NULL, 0, naptime); - - i = ((sizeof(samples) * iovcnt) - written) % sizeof(samples); - iovcnt = 0; - if ((written != -1) && (i > 0)) { - iov[iovcnt].iov_base = ((char *) samples) + i; - iov[iovcnt++].iov_len = sizeof(samples) - i; - } - } else { - iovcnt = 0; - } - } - } - - close(audioFD); - return; -} +/* Copyright (c) 2004-2005, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#define BELL_RATE 48000 /* Samples per second */ +#define BELL_HZ 50 /* Fraction of a second i.e. 1/x */ +#define BELL_MS (1000/BELL_HZ) /* MS */ +#define BELL_SAMPLES (BELL_RATE / BELL_HZ) +#define BELL_MIN 3 /* Min # of repeats */ + +#define AUDIO_DEVICE "/dev/audio" + +void +xf86OSRingBell(int loudness, int pitch, int duration) +{ + static short samples[BELL_SAMPLES]; + static short silence[BELL_SAMPLES]; /* "The Sound of Silence" */ + static int lastFreq; + int cnt; + int i; + int written; + int repeats; + int freq; + audio_info_t audioInfo; + struct iovec iov[IOV_MAX]; + int iovcnt; + double ampl, cyclen, phase; + int audioFD; + + if ((loudness <= 0) || (pitch <= 0) || (duration <= 0)) { + return; + } + + lastFreq = 0; + memset(silence, 0, sizeof(silence)); + + audioFD = open(AUDIO_DEVICE, O_WRONLY | O_NONBLOCK); + if (audioFD == -1) { + xf86Msg(X_ERROR, "Bell: cannot open audio device \"%s\": %s\n", + AUDIO_DEVICE, strerror(errno)); + return; + } + + freq = pitch; + freq = min(freq, (BELL_RATE / 2) - 1); + freq = max(freq, 2 * BELL_HZ); + + /* + * Ensure full waves per buffer + */ + freq -= freq % BELL_HZ; + + if (freq != lastFreq) { + lastFreq = freq; + ampl = 16384.0; + + cyclen = (double) freq / (double) BELL_RATE; + phase = 0.0; + + for (i = 0; i < BELL_SAMPLES; i++) { + samples[i] = (short) (ampl * sin(2.0 * M_PI * phase)); + phase += cyclen; + if (phase >= 1.0) + phase -= 1.0; + } + } + + repeats = (duration + (BELL_MS / 2)) / BELL_MS; + repeats = max(repeats, BELL_MIN); + + loudness = max(0, loudness); + loudness = min(loudness, 100); + +#ifdef DEBUG + ErrorF("BELL : freq %d volume %d duration %d repeats %d\n", + freq, loudness, duration, repeats); +#endif + + AUDIO_INITINFO(&audioInfo); + audioInfo.play.encoding = AUDIO_ENCODING_LINEAR; + audioInfo.play.sample_rate = BELL_RATE; + audioInfo.play.channels = 2; + audioInfo.play.precision = 16; + audioInfo.play.gain = min(AUDIO_MAX_GAIN, AUDIO_MAX_GAIN * loudness / 100); + + if (ioctl(audioFD, AUDIO_SETINFO, &audioInfo) < 0) { + xf86Msg(X_ERROR, + "Bell: AUDIO_SETINFO failed on audio device \"%s\": %s\n", + AUDIO_DEVICE, strerror(errno)); + close(audioFD); + return; + } + + iovcnt = 0; + + for (cnt = 0; cnt <= repeats; cnt++) { + if (cnt == repeats) { + /* Insert a bit of silence so that multiple beeps are distinct and + * not compressed into a single tone. + */ + iov[iovcnt].iov_base = (char *) silence; + iov[iovcnt++].iov_len = sizeof(silence); + } + else { + iov[iovcnt].iov_base = (char *) samples; + iov[iovcnt++].iov_len = sizeof(samples); + } + if ((iovcnt >= IOV_MAX) || (cnt == repeats)) { + written = writev(audioFD, iov, iovcnt); + + if ((written < ((int) (sizeof(samples) * iovcnt)))) { + /* audio buffer was full! */ + + int naptime; + + if (written == -1) { + if (errno != EAGAIN) { + xf86Msg(X_ERROR, + "Bell: writev failed on audio device \"%s\": %s\n", + AUDIO_DEVICE, strerror(errno)); + close(audioFD); + return; + } + i = iovcnt; + } + else { + i = ((sizeof(samples) * iovcnt) - written) + / sizeof(samples); + } + cnt -= i; + + /* sleep a little to allow audio buffer to drain */ + naptime = BELL_MS * i; + poll(NULL, 0, naptime); + + i = ((sizeof(samples) * iovcnt) - written) % sizeof(samples); + iovcnt = 0; + if ((written != -1) && (i > 0)) { + iov[iovcnt].iov_base = ((char *) samples) + i; + iov[iovcnt++].iov_len = sizeof(samples) - i; + } + } + else { + iovcnt = 0; + } + } + } + + close(audioFD); + return; +} diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_init.c b/xorg-server/hw/xfree86/os-support/solaris/sun_init.c index 800fc1c3d..4b75a98ac 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_init.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_init.c @@ -30,7 +30,7 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" #ifdef HAVE_SYS_KD_H -# include +#include #endif /* @@ -48,6 +48,7 @@ static Bool KeepTty = FALSE; static Bool Protect0 = FALSE; static Bool UseConsole = FALSE; + #ifdef HAS_USL_VTS static int VTnum = -1; static int xf86StartVT = -1; @@ -71,18 +72,19 @@ switch_to(int vt, const char *from) SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt)); if (ret != 0) xf86Msg(X_WARNING, "%s: VT_ACTIVATE failed: %s\n", - from, strerror(errno)); + from, strerror(errno)); SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt)); if (ret != 0) xf86Msg(X_WARNING, "%s: VT_WAITACTIVE failed: %s\n", - from, strerror(errno)); + from, strerror(errno)); } void xf86OpenConsole(void) { int i; + #ifdef HAS_USL_VTS int fd; struct vt_mode VT; @@ -90,209 +92,192 @@ xf86OpenConsole(void) MessageType from = X_PROBED; #endif - if (serverGeneration == 1) - { - /* Check if we're run with euid==0 */ - if (geteuid() != 0) - FatalError("xf86OpenConsole: Server must be suid root\n"); - - /* Protect page 0 to help find NULL dereferencing */ - /* mprotect() doesn't seem to work */ - if (Protect0) - { - int fd = -1; - - if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) - { - xf86Msg(X_WARNING, - "xf86OpenConsole: cannot open /dev/zero (%s)\n", - strerror(errno)); - } - else - { - if (mmap(0, 0x1000, PROT_NONE, - MAP_FIXED | MAP_SHARED, fd, 0) == MAP_FAILED) - xf86Msg(X_WARNING, - "xf86OpenConsole: failed to protect page 0 (%s)\n", - strerror(errno)); - - close(fd); - } - } + if (serverGeneration == 1) { + /* Check if we're run with euid==0 */ + if (geteuid() != 0) + FatalError("xf86OpenConsole: Server must be suid root\n"); + + /* Protect page 0 to help find NULL dereferencing */ + /* mprotect() doesn't seem to work */ + if (Protect0) { + int fd = -1; + + if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: cannot open /dev/zero (%s)\n", + strerror(errno)); + } + else { + if (mmap(0, 0x1000, PROT_NONE, + MAP_FIXED | MAP_SHARED, fd, 0) == MAP_FAILED) + xf86Msg(X_WARNING, + "xf86OpenConsole: failed to protect page 0 (%s)\n", + strerror(errno)); + + close(fd); + } + } #ifdef HAS_USL_VTS - /* - * Setup the virtual terminal manager - */ - if ((fd = open("/dev/vt/0",O_RDWR,0)) == -1) - { - xf86ErrorF("xf86OpenConsole: Cannot open /dev/vt/0 (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - else - { - if (ioctl(fd, VT_ENABLED, &vtEnabled) < 0) - { - xf86ErrorF("xf86OpenConsole: VT_ENABLED failed (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - } -#endif /* HAS_USL_VTS */ - - if (UseConsole) - { - strlcpy(consoleDev, SOL_CONSOLE_DEV, sizeof(consoleDev)); + /* + * Setup the virtual terminal manager + */ + if ((fd = open("/dev/vt/0", O_RDWR, 0)) == -1) { + xf86ErrorF("xf86OpenConsole: Cannot open /dev/vt/0 (%s)\n", + strerror(errno)); + vtEnabled = 0; + } + else { + if (ioctl(fd, VT_ENABLED, &vtEnabled) < 0) { + xf86ErrorF("xf86OpenConsole: VT_ENABLED failed (%s)\n", + strerror(errno)); + vtEnabled = 0; + } + } +#endif /* HAS_USL_VTS */ + + if (UseConsole) { + strlcpy(consoleDev, SOL_CONSOLE_DEV, sizeof(consoleDev)); #ifdef HAS_USL_VTS - xf86Info.vtno = CONSOLE_VTNO; - - if (vtEnabled == 0) - { - xf86StartVT = 0; - } - else - { - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError("xf86OpenConsole: Cannot determine current VT\n"); - xf86StartVT = vtinfo.v_active; - } -#endif /* HAS_USL_VTS */ - goto OPENCONSOLE; - } + xf86Info.vtno = CONSOLE_VTNO; + + if (vtEnabled == 0) { + xf86StartVT = 0; + } + else { + if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) + FatalError + ("xf86OpenConsole: Cannot determine current VT\n"); + xf86StartVT = vtinfo.v_active; + } +#endif /* HAS_USL_VTS */ + goto OPENCONSOLE; + } #ifdef HAS_USL_VTS - if (vtEnabled == 0) - { - /* VT not enabled - kernel too old or Sparc platforms - without visual_io support */ - xf86Msg(from, "VT infrastructure is not available\n"); - - xf86StartVT = 0; - xf86Info.vtno = 0; - strlcpy(consoleDev, xf86SolarisFbDev, sizeof(consoleDev)); - goto OPENCONSOLE; - } - - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError("xf86OpenConsole: Cannot determine current VT\n"); - - xf86StartVT = vtinfo.v_active; - - if (VTnum != -1) - { - xf86Info.vtno = VTnum; - from = X_CMDLINE; - } - else if (xf86Info.ShareVTs) - { - xf86Info.vtno = vtinfo.v_active; - from = X_CMDLINE; - } - else - { - if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || - (xf86Info.vtno == -1)) - { - FatalError("xf86OpenConsole: Cannot find a free VT\n"); - } - } - - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - snprintf(consoleDev, PATH_MAX, "/dev/vt/%d", xf86Info.vtno); - - if (fd != -1) - { - close(fd); - } - -#endif /* HAS_USL_VTS */ - -OPENCONSOLE: - if (!KeepTty) - setpgrp(); - - if (((xf86Info.consoleFd = open(consoleDev, O_RDWR | O_NDELAY, 0)) < 0)) - FatalError("xf86OpenConsole: Cannot open %s (%s)\n", - consoleDev, strerror(errno)); - - /* Change ownership of the vt or console */ - chown(consoleDev, getuid(), getgid()); + if (vtEnabled == 0) { + /* VT not enabled - kernel too old or Sparc platforms + without visual_io support */ + xf86Msg(from, "VT infrastructure is not available\n"); + + xf86StartVT = 0; + xf86Info.vtno = 0; + strlcpy(consoleDev, xf86SolarisFbDev, sizeof(consoleDev)); + goto OPENCONSOLE; + } + + if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) + FatalError("xf86OpenConsole: Cannot determine current VT\n"); + + xf86StartVT = vtinfo.v_active; + + if (VTnum != -1) { + xf86Info.vtno = VTnum; + from = X_CMDLINE; + } + else if (xf86Info.ShareVTs) { + xf86Info.vtno = vtinfo.v_active; + from = X_CMDLINE; + } + else { + if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || + (xf86Info.vtno == -1)) { + FatalError("xf86OpenConsole: Cannot find a free VT\n"); + } + } + + xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); + snprintf(consoleDev, PATH_MAX, "/dev/vt/%d", xf86Info.vtno); + + if (fd != -1) { + close(fd); + } + +#endif /* HAS_USL_VTS */ + + OPENCONSOLE: + if (!KeepTty) + setpgrp(); + + if (((xf86Info.consoleFd = open(consoleDev, O_RDWR | O_NDELAY, 0)) < 0)) + FatalError("xf86OpenConsole: Cannot open %s (%s)\n", + consoleDev, strerror(errno)); + + /* Change ownership of the vt or console */ + chown(consoleDev, getuid(), getgid()); #ifdef HAS_USL_VTS - if (xf86Info.ShareVTs) - return; - - if (vtEnabled) - { - /* - * Now get the VT - */ - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); + if (xf86Info.ShareVTs) + return; + + if (vtEnabled) { + /* + * Now get the VT + */ + switch_to(xf86Info.vtno, "xf86OpenConsole"); + +#ifdef VT_SET_CONSUSER /* added in snv_139 */ + if (strcmp(display, "0") == 0) + if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_SET_CONSUSER failed\n"); #endif - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_GETMODE failed\n"); + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_GETMODE failed\n"); - OsSignal(SIGUSR1, xf86VTAcquire); - OsSignal(SIGUSR2, xf86VTRelease); + OsSignal(SIGUSR1, xf86VTAcquire); + OsSignal(SIGUSR2, xf86VTRelease); - VT.mode = VT_PROCESS; - VT.acqsig = SIGUSR1; - VT.relsig = SIGUSR2; + VT.mode = VT_PROCESS; + VT.acqsig = SIGUSR1; + VT.relsig = SIGUSR2; - if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); - if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0) - xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n"); - } + if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n"); + } #endif #ifdef KDSETMODE - SYSCALL(i = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); - if (i < 0) { - xf86Msg(X_WARNING, - "xf86OpenConsole: KDSETMODE KD_GRAPHICS failed on %s (%s)\n", - consoleDev, strerror(errno)); - } + SYSCALL(i = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); + if (i < 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: KDSETMODE KD_GRAPHICS failed on %s (%s)\n", + consoleDev, strerror(errno)); + } #endif } - else /* serverGeneration != 1 */ - { + else { /* serverGeneration != 1 */ + #ifdef HAS_USL_VTS - if (vtEnabled && !xf86Info.ShareVTs) - { - /* - * Now re-get the VT - */ - if (xf86Info.autoVTSwitch) - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); + if (vtEnabled && !xf86Info.ShareVTs) { + /* + * Now re-get the VT + */ + if (xf86Info.autoVTSwitch) + switch_to(xf86Info.vtno, "xf86OpenConsole"); + +#ifdef VT_SET_CONSUSER /* added in snv_139 */ + if (strcmp(display, "0") == 0) + if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_SET_CONSUSER failed\n"); #endif - /* - * If the server doesn't have the VT when the reset occurs, - * this is to make sure we don't continue until the activate - * signal is received. - */ - if (!xf86Screens[0]->vtSema) - sleep(5); - } -#endif /* HAS_USL_VTS */ + /* + * If the server doesn't have the VT when the reset occurs, + * this is to make sure we don't continue until the activate + * signal is received. + */ + if (!xf86Screens[0]->vtSema) + sleep(5); + } +#endif /* HAS_USL_VTS */ } } @@ -307,44 +292,47 @@ xf86CloseConsole(void) #if !defined(__i386__) && !defined(__i386) && !defined(__x86) if (!xf86DoConfigure) { - int fd; - - /* - * Wipe out framebuffer just like the non-SI Xsun server does. This - * could be improved by saving framebuffer contents in - * xf86OpenConsole() above and restoring them here. Also, it's unclear - * at this point whether this should be done for all framebuffers in - * the system, rather than only the console. - */ - if ((fd = open(xf86SolarisFbDev, O_RDWR, 0)) < 0) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to open framebuffer (%s)\n", - strerror(errno)); - } else { - struct fbgattr fbattr; - - if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) && - (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to retrieve framebuffer" - " attributes (%s)\n", strerror(errno)); - } else { - pointer fbdata; - - fbdata = mmap(NULL, fbattr.fbtype.fb_size, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (fbdata == MAP_FAILED) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to mmap framebuffer" - " (%s)\n", strerror(errno)); - } else { - memset(fbdata, 0, fbattr.fbtype.fb_size); - munmap(fbdata, fbattr.fbtype.fb_size); - } - } - - close(fd); - } + int fd; + + /* + * Wipe out framebuffer just like the non-SI Xsun server does. This + * could be improved by saving framebuffer contents in + * xf86OpenConsole() above and restoring them here. Also, it's unclear + * at this point whether this should be done for all framebuffers in + * the system, rather than only the console. + */ + if ((fd = open(xf86SolarisFbDev, O_RDWR, 0)) < 0) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to open framebuffer (%s)\n", + strerror(errno)); + } + else { + struct fbgattr fbattr; + + if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) && + (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to retrieve framebuffer" + " attributes (%s)\n", strerror(errno)); + } + else { + pointer fbdata; + + fbdata = mmap(NULL, fbattr.fbtype.fb_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (fbdata == MAP_FAILED) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to mmap framebuffer" + " (%s)\n", strerror(errno)); + } + else { + memset(fbdata, 0, fbattr.fbtype.fb_size); + munmap(fbdata, fbattr.fbtype.fb_size); + } + } + + close(fd); + } } #endif @@ -355,19 +343,17 @@ xf86CloseConsole(void) #endif #ifdef HAS_USL_VTS - if (vtEnabled) - { - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) - { - VT.mode = VT_AUTO; /* Set default vt handling */ - ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); - } - - /* Activate the VT that X was started on */ - if (xf86Info.autoVTSwitch) - switch_to(xf86StartVT, "xf86CloseConsole"); + if (vtEnabled) { + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { + VT.mode = VT_AUTO; /* Set default vt handling */ + ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); + } + + /* Activate the VT that X was started on */ + if (xf86Info.autoVTSwitch) + switch_to(xf86StartVT, "xf86CloseConsole"); } -#endif /* HAS_USL_VTS */ +#endif /* HAS_USL_VTS */ close(xf86Info.consoleFd); } @@ -379,58 +365,54 @@ xf86ProcessArgument(int argc, char **argv, int i) * Keep server from detaching from controlling tty. This is useful when * debugging, so the server can receive keyboard signals. */ - if (!strcmp(argv[i], "-keeptty")) - { - KeepTty = TRUE; - return 1; + if (!strcmp(argv[i], "-keeptty")) { + KeepTty = TRUE; + return 1; } /* * Undocumented flag to protect page 0 from read/write to help catch NULL * pointer dereferences. This is purely a debugging flag. */ - if (!strcmp(argv[i], "-protect0")) - { - Protect0 = TRUE; - return 1; + if (!strcmp(argv[i], "-protect0")) { + Protect0 = TRUE; + return 1; } /* * Use /dev/console as the console device. */ - if (!strcmp(argv[i], "-C")) - { - UseConsole = TRUE; - return 1; + if (!strcmp(argv[i], "-C")) { + UseConsole = TRUE; + return 1; } #ifdef HAS_USL_VTS - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) - { - if (sscanf(argv[i], "vt%d", &VTnum) == 0) - { - UseMsg(); - VTnum = -1; - return 0; - } + if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { + if (sscanf(argv[i], "vt%d", &VTnum) == 0) { + UseMsg(); + VTnum = -1; + return 0; + } - return 1; + return 1; } -#endif /* HAS_USL_VTS */ +#endif /* HAS_USL_VTS */ if ((i + 1) < argc) { - if (!strcmp(argv[i], "-dev")) { - strlcpy(xf86SolarisFbDev, argv[i+1], sizeof(xf86SolarisFbDev)); - return 2; - } + if (!strcmp(argv[i], "-dev")) { + strlcpy(xf86SolarisFbDev, argv[i + 1], sizeof(xf86SolarisFbDev)); + return 2; + } } return 0; } -void xf86UseMsg(void) +void +xf86UseMsg(void) { #ifdef HAS_USL_VTS ErrorF("vtX Use the specified VT number\n"); diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c b/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c index b7b7c0ed7..67ef17689 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c @@ -1,258 +1,247 @@ -/* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany - * Copyright 1993 by David Wexelblat - * Copyright 1999 by David Holland - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the names of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT - * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - * - */ -/* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include /* get __x86 definition if not set by compiler */ - -#if defined(__i386__) || defined(__i386) || defined(__x86) -# define _NEED_SYSI86 -#endif -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" -#include - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -static char *apertureDevName = NULL; -static int apertureDevFD_ro = -1; -static int apertureDevFD_rw = -1; - -static Bool -solOpenAperture(void) -{ - if (apertureDevName == NULL) - { - apertureDevName = "/dev/xsvc"; - if ((apertureDevFD_rw = open(apertureDevName, O_RDWR)) < 0) - { - xf86MsgVerb(X_WARNING, 0, - "solOpenAperture: failed to open %s (%s)\n", - apertureDevName, strerror(errno)); - apertureDevName = "/dev/fbs/aperture"; - apertureDevFD_rw = open(apertureDevName, O_RDWR); - } - apertureDevFD_ro = open(apertureDevName, O_RDONLY); - - if ((apertureDevFD_rw < 0) || (apertureDevFD_ro < 0)) - { - xf86MsgVerb(X_WARNING, 0, - "solOpenAperture: failed to open %s (%s)\n", - apertureDevName, strerror(errno)); - xf86MsgVerb(X_WARNING, 0, - "solOpenAperture: either /dev/fbs/aperture" - " or /dev/xsvc required\n"); - - apertureDevName = NULL; - - if (apertureDevFD_rw >= 0) - { - close(apertureDevFD_rw); - } - apertureDevFD_rw = -1; - - if (apertureDevFD_ro >= 0) - { - close(apertureDevFD_ro); - } - apertureDevFD_ro = -1; - - return FALSE; - } - } - return TRUE; -} - -static pointer -solMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags) -{ - pointer base; - int fd; - int prot; - - if (Flags & VIDMEM_READONLY) - { - fd = apertureDevFD_ro; - prot = PROT_READ; - } - else - { - fd = apertureDevFD_rw; - prot = PROT_READ | PROT_WRITE; - } - - if (fd < 0) - { - xf86DrvMsg(ScreenNum, X_ERROR, - "solMapVidMem: failed to open %s (%s)\n", - apertureDevName, strerror(errno)); - return NULL; - } - - base = mmap(NULL, Size, prot, MAP_SHARED, fd, (off_t)Base); - - if (base == MAP_FAILED) { - xf86DrvMsg(ScreenNum, X_ERROR, - "solMapVidMem: failed to mmap %s (0x%08lx,0x%lx) (%s)\n", - apertureDevName, Base, Size, strerror(errno)); - return NULL; - } - - return base; -} - -/* ARGSUSED */ -static void -solUnMapVidMem(int ScreenNum, pointer Base, unsigned long Size) -{ - if (munmap(Base, Size) != 0) { - xf86DrvMsgVerb(ScreenNum, X_WARNING, 0, - "solUnMapVidMem: failed to unmap %s" - " (0x%p,0x%lx) (%s)\n", - apertureDevName, Base, Size, - strerror(errno)); - } -} - -_X_HIDDEN void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - pVidMem->linearSupported = solOpenAperture(); - if (pVidMem->linearSupported) { - pVidMem->mapMem = solMapVidMem; - pVidMem->unmapMem = solUnMapVidMem; - } else { - xf86MsgVerb(X_WARNING, 0, - "xf86OSInitVidMem: linear memory access disabled\n"); - } - pVidMem->initialised = TRUE; -} - -/* - * Read BIOS via mmap()ing physical memory. - */ -int -xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) -{ - unsigned char *ptr; - int psize; - int mlen; - - psize = getpagesize(); - Offset += Base & (psize - 1); - Base &= ~(psize - 1); - mlen = (Offset + Len + psize - 1) & ~(psize - 1); - - if (solOpenAperture() == FALSE) - { - xf86Msg(X_WARNING, - "xf86ReadBIOS: Failed to open aperture to read BIOS\n"); - return -1; - } - - ptr = (unsigned char *)mmap(NULL, mlen, PROT_READ, - MAP_SHARED, apertureDevFD_ro, (off_t)Base); - if (ptr == MAP_FAILED) - { - xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed [0x%08lx, 0x%04x]\n", - apertureDevName, Base, mlen); - return -1; - } - - (void)memcpy(Buf, (void *)(ptr + Offset), Len); - if (munmap((caddr_t)ptr, mlen) != 0) { - xf86MsgVerb(X_WARNING, 0, - "xf86ReadBIOS: failed to unmap %s (0x%p,0x%x) (%s)\n", - apertureDevName, ptr, mlen, strerror(errno)); - } - - return Len; -} - - -/***************************************************************************/ -/* I/O Permissions section */ -/***************************************************************************/ - -#if defined(__i386__) || defined(__i386) || defined(__x86) -static Bool ExtendedEnabled = FALSE; -#endif - -Bool -xf86EnableIO(void) -{ -#if defined(__i386__) || defined(__i386) || defined(__x86) - if (ExtendedEnabled) - return TRUE; - - if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) { - xf86Msg(X_WARNING, "xf86EnableIOPorts: Failed to set IOPL for I/O\n"); - return FALSE; - } - ExtendedEnabled = TRUE; -#endif /* i386 */ - return TRUE; -} - -void -xf86DisableIO(void) -{ -#if defined(__i386__) || defined(__i386) || defined(__x86) - if(!ExtendedEnabled) - return; - - sysi86(SI86V86, V86SC_IOPL, 0); - - ExtendedEnabled = FALSE; -#endif /* i386 */ -} +/* + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany + * Copyright 1993 by David Wexelblat + * Copyright 1999 by David Holland + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the names of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT + * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + */ +/* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include /* get __x86 definition if not set by compiler */ + +#if defined(__i386__) || defined(__i386) || defined(__x86) +#define _NEED_SYSI86 +#endif +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" +#include + +/***************************************************************************/ +/* Video Memory Mapping section */ +/***************************************************************************/ + +static char *apertureDevName = NULL; +static int apertureDevFD_ro = -1; +static int apertureDevFD_rw = -1; + +static Bool +solOpenAperture(void) +{ + if (apertureDevName == NULL) { + apertureDevName = "/dev/xsvc"; + if ((apertureDevFD_rw = open(apertureDevName, O_RDWR)) < 0) { + xf86MsgVerb(X_WARNING, 0, + "solOpenAperture: failed to open %s (%s)\n", + apertureDevName, strerror(errno)); + apertureDevName = "/dev/fbs/aperture"; + apertureDevFD_rw = open(apertureDevName, O_RDWR); + } + apertureDevFD_ro = open(apertureDevName, O_RDONLY); + + if ((apertureDevFD_rw < 0) || (apertureDevFD_ro < 0)) { + xf86MsgVerb(X_WARNING, 0, + "solOpenAperture: failed to open %s (%s)\n", + apertureDevName, strerror(errno)); + xf86MsgVerb(X_WARNING, 0, + "solOpenAperture: either /dev/fbs/aperture" + " or /dev/xsvc required\n"); + + apertureDevName = NULL; + + if (apertureDevFD_rw >= 0) { + close(apertureDevFD_rw); + } + apertureDevFD_rw = -1; + + if (apertureDevFD_ro >= 0) { + close(apertureDevFD_ro); + } + apertureDevFD_ro = -1; + + return FALSE; + } + } + return TRUE; +} + +static pointer +solMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags) +{ + pointer base; + int fd; + int prot; + + if (Flags & VIDMEM_READONLY) { + fd = apertureDevFD_ro; + prot = PROT_READ; + } + else { + fd = apertureDevFD_rw; + prot = PROT_READ | PROT_WRITE; + } + + if (fd < 0) { + xf86DrvMsg(ScreenNum, X_ERROR, + "solMapVidMem: failed to open %s (%s)\n", + apertureDevName, strerror(errno)); + return NULL; + } + + base = mmap(NULL, Size, prot, MAP_SHARED, fd, (off_t) Base); + + if (base == MAP_FAILED) { + xf86DrvMsg(ScreenNum, X_ERROR, + "solMapVidMem: failed to mmap %s (0x%08lx,0x%lx) (%s)\n", + apertureDevName, Base, Size, strerror(errno)); + return NULL; + } + + return base; +} + +/* ARGSUSED */ +static void +solUnMapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + if (munmap(Base, Size) != 0) { + xf86DrvMsgVerb(ScreenNum, X_WARNING, 0, + "solUnMapVidMem: failed to unmap %s" + " (0x%p,0x%lx) (%s)\n", + apertureDevName, Base, Size, strerror(errno)); + } +} + +_X_HIDDEN void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + pVidMem->linearSupported = solOpenAperture(); + if (pVidMem->linearSupported) { + pVidMem->mapMem = solMapVidMem; + pVidMem->unmapMem = solUnMapVidMem; + } + else { + xf86MsgVerb(X_WARNING, 0, + "xf86OSInitVidMem: linear memory access disabled\n"); + } + pVidMem->initialised = TRUE; +} + +/* + * Read BIOS via mmap()ing physical memory. + */ +int +xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, + int Len) +{ + unsigned char *ptr; + int psize; + int mlen; + + psize = getpagesize(); + Offset += Base & (psize - 1); + Base &= ~(psize - 1); + mlen = (Offset + Len + psize - 1) & ~(psize - 1); + + if (solOpenAperture() == FALSE) { + xf86Msg(X_WARNING, + "xf86ReadBIOS: Failed to open aperture to read BIOS\n"); + return -1; + } + + ptr = (unsigned char *) mmap(NULL, mlen, PROT_READ, + MAP_SHARED, apertureDevFD_ro, (off_t) Base); + if (ptr == MAP_FAILED) { + xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed [0x%08lx, 0x%04x]\n", + apertureDevName, Base, mlen); + return -1; + } + + (void) memcpy(Buf, (void *) (ptr + Offset), Len); + if (munmap((caddr_t) ptr, mlen) != 0) { + xf86MsgVerb(X_WARNING, 0, + "xf86ReadBIOS: failed to unmap %s (0x%p,0x%x) (%s)\n", + apertureDevName, ptr, mlen, strerror(errno)); + } + + return Len; +} + +/***************************************************************************/ +/* I/O Permissions section */ +/***************************************************************************/ + +#if defined(__i386__) || defined(__i386) || defined(__x86) +static Bool ExtendedEnabled = FALSE; +#endif + +Bool +xf86EnableIO(void) +{ +#if defined(__i386__) || defined(__i386) || defined(__x86) + if (ExtendedEnabled) + return TRUE; + + if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) { + xf86Msg(X_WARNING, "xf86EnableIOPorts: Failed to set IOPL for I/O\n"); + return FALSE; + } + ExtendedEnabled = TRUE; +#endif /* i386 */ + return TRUE; +} + +void +xf86DisableIO(void) +{ +#if defined(__i386__) || defined(__i386) || defined(__x86) + if (!ExtendedEnabled) + return; + + sysi86(SI86V86, V86SC_IOPL, 0); + + ExtendedEnabled = FALSE; +#endif /* i386 */ +} -- cgit v1.2.3