diff options
-rw-r--r-- | hw/kdrive/linux/linux.c | 82 | ||||
-rw-r--r-- | hw/kdrive/mach64/mach64.c | 4 | ||||
-rw-r--r-- | hw/kdrive/src/kdrive.c | 41 | ||||
-rw-r--r-- | hw/kdrive/src/kdrive.h | 8 | ||||
-rw-r--r-- | hw/kdrive/src/kmap.c | 12 |
5 files changed, 138 insertions, 9 deletions
diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c index 52f6d86cd..d092b0a48 100644 --- a/hw/kdrive/linux/linux.c +++ b/hw/kdrive/linux/linux.c @@ -1,5 +1,5 @@ /* - * $XFree86$ + * $XFree86: xc/programs/Xserver/hw/kdrive/linux/linux.c,v 1.5 2001/03/30 02:15:20 keithp Exp $ * * Copyright © 1999 Keith Packard * @@ -30,9 +30,11 @@ #include <sys/stat.h> #include <sys/ioctl.h> #include <keysym.h> +#include <linux/apm_bios.h> static int vtno; int LinuxConsoleFd; +int LinuxApmFd = -1; static int activeVT; static Bool enabled; @@ -256,6 +258,65 @@ LinuxSetSwitchMode (int mode) } void +LinuxApmBlock (pointer blockData, OSTimePtr pTimeout, pointer pReadmask) +{ +} + +static Bool LinuxApmRunning; + +void +LinuxApmWakeup (pointer blockData, int result, pointer pReadmask) +{ + fd_set *readmask = (fd_set *) pReadmask; + + if (result > 0 && LinuxApmFd >= 0 && FD_ISSET (LinuxApmFd, readmask)) + { + apm_event_t event; + Bool running = LinuxApmRunning; + int cmd = APM_IOC_SUSPEND; + + while (read (LinuxApmFd, &event, sizeof (event)) == sizeof (event)) + { + switch (event) { + case APM_SYS_STANDBY: + case APM_USER_STANDBY: + running = FALSE; + cmd = APM_IOC_STANDBY; + break; + case APM_SYS_SUSPEND: + case APM_USER_SUSPEND: + case APM_CRITICAL_SUSPEND: + running = FALSE; + cmd = APM_IOC_SUSPEND; + break; + case APM_NORMAL_RESUME: + case APM_CRITICAL_RESUME: + case APM_STANDBY_RESUME: + running = TRUE; + break; + } + } + if (running && !LinuxApmRunning) + { + KdResume (); + LinuxApmRunning = TRUE; + } + else if (!running && LinuxApmRunning) + { + KdSuspend (); + LinuxApmRunning = FALSE; + ioctl (LinuxApmFd, cmd, 0); + } + } +} + +#ifdef FNONBLOCK +#define NOBLOCK FNONBLOCK +#else +#define NOBLOCK FNDELAY +#endif + +void LinuxEnable (void) { if (enabled) @@ -266,6 +327,18 @@ LinuxEnable (void) ioctl (LinuxConsoleFd, VT_RELDISP, VT_ACKACQ); } /* + * Open the APM driver + */ + LinuxApmFd = open ("/dev/apm_bios", 0); + if (LinuxApmFd >= 0) + { + LinuxApmRunning = TRUE; + fcntl (LinuxApmFd, F_SETFL, fcntl (LinuxApmFd, F_GETFL) | NOBLOCK); + RegisterBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0); + AddEnabledDevice (LinuxApmFd); + } + + /* * now get the VT */ LinuxSetSwitchMode (VT_AUTO); @@ -314,6 +387,13 @@ LinuxDisable (void) ioctl (LinuxConsoleFd, VT_RELDISP, 1); } enabled = FALSE; + if (LinuxApmFd >= 0) + { + RemoveBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0); + RemoveEnabledDevice (LinuxApmFd); + close (LinuxApmFd); + LinuxApmFd = -1; + } } void diff --git a/hw/kdrive/mach64/mach64.c b/hw/kdrive/mach64/mach64.c index 72e91953e..6e49465c0 100644 --- a/hw/kdrive/mach64/mach64.c +++ b/hw/kdrive/mach64/mach64.c @@ -19,7 +19,7 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -/* $XFree86: xc/programs/Xserver/hw/kdrive/mach64/mach64.c,v 1.6 2001/07/20 19:35:30 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/mach64/mach64.c,v 1.7 2001/07/24 19:06:03 keithp Exp $ */ #include "mach64.h" #include <sys/io.h> @@ -215,10 +215,10 @@ mach64UnmapReg (KdCardInfo *card, Mach64CardInfo *mach64c) { if (mach64c->reg_base) { - KdUnmapDevice ((void *) mach64c->reg_base, MACH64_REG_SIZE(card)); KdResetMappedMode (MACH64_REG_BASE(card), MACH64_REG_SIZE(card), KD_MAPPED_MODE_REGISTERS); + KdUnmapDevice ((void *) mach64c->reg_base, MACH64_REG_SIZE(card)); mach64c->reg_base = 0; mach64c->reg = 0; mach64c->media_reg = 0; diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c index 912607005..0693367d4 100644 --- a/hw/kdrive/src/kdrive.c +++ b/hw/kdrive/src/kdrive.c @@ -21,7 +21,7 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -/* $XFree86: xc/programs/Xserver/hw/kdrive/kdrive.c,v 1.17 2001/06/13 19:18:03 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/kdrive.c,v 1.18 2001/07/20 19:35:29 keithp Exp $ */ #include "kdrive.h" #ifdef PSEUDO8 @@ -233,6 +233,45 @@ KdDisableScreens (void) } } +void +KdSuspend (void) +{ + KdCardInfo *card; + KdScreenInfo *screen; + + if (kdEnabled) + { + for (card = kdCardInfo; card; card = card->next) + { + for (screen = card->screenList; screen; screen = screen->next) + if (screen->mynum == card->selected && screen->pScreen) + KdDisableScreen (screen->pScreen); + if (card->driver) + (*card->cfuncs->restore) (card); + } + KdDisableInput (); + } +} + +void +KdResume (void) +{ + KdCardInfo *card; + KdScreenInfo *screen; + + if (kdEnabled) + { + for (card = kdCardInfo; card; card = card->next) + { + (*card->cfuncs->preserve) (card); + for (screen = card->screenList; screen; screen = screen->next) + if (screen->mynum == card->selected && screen->pScreen) + KdEnableScreen (screen->pScreen); + } + KdEnableInput (); + } +} + Bool KdEnableScreen (ScreenPtr pScreen) { diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h index 321ad2596..125d1d6af 100644 --- a/hw/kdrive/src/kdrive.h +++ b/hw/kdrive/src/kdrive.h @@ -21,7 +21,7 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -/* $XFree86: xc/programs/Xserver/hw/kdrive/kdrive.h,v 1.17 2001/07/11 02:58:19 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/kdrive.h,v 1.18 2001/07/20 19:35:29 keithp Exp $ */ #include <stdio.h> #include "X.h" @@ -466,6 +466,12 @@ void KdEnableScreens (void); void +KdSuspend (void); + +void +KdResume (void); + +void KdProcessSwitch (void); void diff --git a/hw/kdrive/src/kmap.c b/hw/kdrive/src/kmap.c index c7de1852c..9f1f0df2e 100644 --- a/hw/kdrive/src/kmap.c +++ b/hw/kdrive/src/kmap.c @@ -21,7 +21,7 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -/* $XFree86: xc/programs/Xserver/hw/kdrive/kmap.c,v 1.8 2001/05/23 08:56:08 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/kmap.c,v 1.9 2001/06/29 13:57:45 keithp Exp $ */ #include "kdrive.h" @@ -135,7 +135,9 @@ KdSetMappedMode (CARD32 addr, CARD32 size, int mode) sentry.size = bound - base; sentry.type = type; - ioctl (mtrr, MTRRIOC_ADD_ENTRY, &sentry); + if (ioctl (mtrr, MTRRIOC_ADD_ENTRY, &sentry) < 0) + ErrorF ("MTRRIOC_ADD_ENTRY failed 0x%x 0x%x %d (errno %d)\n", + base, bound - base, type, errno); } #endif } @@ -154,7 +156,7 @@ KdResetMappedMode (CARD32 addr, CARD32 size, int mode) mtrr = open ("/proc/mtrr", 2); if (mtrr > 0) { - base = addr & ~((1<22)-1); + base = addr & ~((1<<22)-1); bound = ((addr + size) + ((1<<22) - 1)) & ~((1<<22) - 1); switch (mode) { case KD_MAPPED_MODE_REGISTERS: @@ -168,7 +170,9 @@ KdResetMappedMode (CARD32 addr, CARD32 size, int mode) sentry.size = bound - base; sentry.type = type; - ioctl (mtrr, MTRRIOC_DEL_ENTRY, &sentry); + if (ioctl (mtrr, MTRRIOC_DEL_ENTRY, &sentry) < 0) + ErrorF ("MTRRIOC_DEL_ENTRY failed 0x%x 0x%x %d (errno %d)\n", + base, bound - base, type, errno); } #endif } |