[PATCH] Make APM support optional

Mikhail Gusarov dottedmag at dottedmag.net
Mon Mar 15 15:47:14 PDT 2010


Add new --disable-apm configure switch to compile out APM
support in xfree86 and kdrive.

Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
---
 configure.ac                              |    2 +
 hw/kdrive/linux/Makefile.am               |    5 +
 hw/kdrive/linux/apm.c                     |  121 +++++++++++++++++++++++++++++
 hw/kdrive/linux/apm.h                     |    8 ++
 hw/kdrive/linux/linux.c                   |   92 +++-------------------
 hw/xfree86/os-support/bsd/Makefile.am     |   10 ++-
 hw/xfree86/os-support/linux/Makefile.am   |    2 +
 hw/xfree86/os-support/solaris/Makefile.am |    8 ++-
 8 files changed, 163 insertions(+), 85 deletions(-)
 create mode 100644 hw/kdrive/linux/apm.c
 create mode 100644 hw/kdrive/linux/apm.h

diff --git a/configure.ac b/configure.ac
index 3e8ea10..f911f98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -631,6 +631,7 @@ AC_ARG_ENABLE(xaa,               AS_HELP_STRING([--enable-xaa], [Build XAA (defa
 AC_ARG_ENABLE(vgahw,          AS_HELP_STRING([--enable-vgahw], [Build Xorg with vga access (default: enabled)]), [VGAHW=$enableval], [VGAHW=yes])
 AC_ARG_ENABLE(vbe,            AS_HELP_STRING([--enable-vbe], [Build Xorg with VBE module (default: enabled)]), [VBE=$enableval], [VBE=yes])
 AC_ARG_ENABLE(int10-module,     AS_HELP_STRING([--enable-int10-module], [Build Xorg with int10 module (default: enabled)]), [INT10MODULE=$enableval], [INT10MODULE=yes])
+AC_ARG_ENABLE(apm, AS_HELP_STRING([--enable-apm], [Build Xorg with APM support (default: enabled)]), [APM=$enableval], [APM=yes])
 
 dnl DDXes.
 AC_ARG_ENABLE(xorg,    	      AS_HELP_STRING([--enable-xorg], [Build Xorg server (default: auto)]), [XORG=$enableval], [XORG=auto])
@@ -1129,6 +1130,7 @@ AM_CONDITIONAL(XF86UTILS, test "x$XF86UTILS" = xyes)
 AM_CONDITIONAL(XAA, test "x$XAA" = xyes)
 AM_CONDITIONAL(VGAHW, test "x$VGAHW" = xyes)
 AM_CONDITIONAL(VBE, test "x$VBE" = xyes)
+AM_CONDITIONAL(APM, test "x$APM" = xyes)
 AM_CONDITIONAL(INT10MODULE, test "x$INT10MODULE" = xyes)
 
 AC_DEFINE(SHAPE, 1, [Support SHAPE extension])
diff --git a/hw/kdrive/linux/Makefile.am b/hw/kdrive/linux/Makefile.am
index 93e5d2f..e9f311f 100644
--- a/hw/kdrive/linux/Makefile.am
+++ b/hw/kdrive/linux/Makefile.am
@@ -10,6 +10,11 @@ liblinux_la_SOURCES =
 
 liblinux_la_SOURCES += linux.c
 
+if APM
+AM_CFLAGS += -DHAVE_APM
+liblinux_la_SOURCES += apm.c apm.h
+endif
+
 if KDRIVE_KBD
 liblinux_la_SOURCES += keyboard.c
 endif
diff --git a/hw/kdrive/linux/apm.c b/hw/kdrive/linux/apm.c
new file mode 100644
index 0000000..bc51e04
--- /dev/null
+++ b/hw/kdrive/linux/apm.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright © 1999 Keith Packard
+ * Copyright © 2010 Mikhail Gusarov <dottedmag at dottedmag.net>
+ *
+ * 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 name of Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <kdrive-config.h>
+#endif
+#include "kdrive.h"
+
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <linux/apm_bios.h>
+
+#include "apm.h"
+
+#ifdef FNONBLOCK
+#define NOBLOCK FNONBLOCK
+#else
+#define NOBLOCK FNDELAY
+#endif
+
+static int LinuxApmFd = -1;
+static Bool LinuxApmRunning;
+
+static void
+LinuxApmBlock (pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
+{
+}
+
+static 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);
+	}
+    }
+}
+
+void
+LinuxApmOpen(void)
+{
+    LinuxApmFd = open ("/dev/apm_bios", 2);
+    if (LinuxApmFd < 0 && errno == ENOENT)
+	LinuxApmFd = open ("/dev/misc/apm_bios", 2);
+    if (LinuxApmFd >= 0)
+    {
+	LinuxApmRunning = TRUE;
+	fcntl (LinuxApmFd, F_SETFL, fcntl (LinuxApmFd, F_GETFL) | NOBLOCK);
+	RegisterBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0);
+	AddEnabledDevice (LinuxApmFd);
+    }
+}
+
+
+void
+LinuxApmClose(void)
+{
+    if (LinuxApmFd >= 0)
+    {
+	RemoveBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0);
+	RemoveEnabledDevice (LinuxApmFd);
+	close (LinuxApmFd);
+	LinuxApmFd = -1;
+    }
+}
diff --git a/hw/kdrive/linux/apm.h b/hw/kdrive/linux/apm.h
new file mode 100644
index 0000000..9378b40
--- /dev/null
+++ b/hw/kdrive/linux/apm.h
@@ -0,0 +1,8 @@
+#ifndef _KDRIVE_LINUX_APM_H_
+#define _KDRIVE_LINUX_APM_H_
+
+void LinuxApmOpen(void);
+
+void LinuxApmClose(void);
+
+#endif
diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c
index 9863c14..d2e3360 100644
--- a/hw/kdrive/linux/linux.c
+++ b/hw/kdrive/linux/linux.c
@@ -31,7 +31,10 @@
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <X11/keysym.h>
-#include <linux/apm_bios.h>
+
+#ifdef HAVE_APM
+#include "apm.h"
+#endif
 
 #ifdef KDRIVE_MOUSE
 extern KdPointerDriver	LinuxMouseDriver;
@@ -51,7 +54,6 @@ extern KdKeyboardDriver	LinuxKeyboardDriver;
 
 static int  vtno;
 int  LinuxConsoleFd;
-int  LinuxApmFd = -1;
 static int  activeVT;
 static Bool enabled;
 
@@ -180,65 +182,6 @@ LinuxSetSwitchMode (int mode)
 }
 
 static void
-LinuxApmBlock (pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
-{
-}
-
-static Bool LinuxApmRunning;
-
-static 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
-
-static void
 LinuxEnable (void)
 {
     if (enabled)
@@ -248,19 +191,10 @@ LinuxEnable (void)
 	kdSwitchPending = FALSE;
 	ioctl (LinuxConsoleFd, VT_RELDISP, VT_ACKACQ);
     }
-    /*
-     * Open the APM driver
-     */
-    LinuxApmFd = open ("/dev/apm_bios", 2);
-    if (LinuxApmFd < 0 && errno == ENOENT)
-	LinuxApmFd = open ("/dev/misc/apm_bios", 2);
-    if (LinuxApmFd >= 0)
-    {
-	LinuxApmRunning = TRUE;
-	fcntl (LinuxApmFd, F_SETFL, fcntl (LinuxApmFd, F_GETFL) | NOBLOCK);
-	RegisterBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0);
-	AddEnabledDevice (LinuxApmFd);
-    }
+
+#ifdef HAVE_APM
+    LinuxApmOpen();
+#endif
 
     /*
      * now get the VT
@@ -292,13 +226,9 @@ LinuxDisable (void)
 	ioctl (LinuxConsoleFd, VT_RELDISP, 1);
     }
     enabled = FALSE;
-    if (LinuxApmFd >= 0)
-    {
-	RemoveBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0);
-	RemoveEnabledDevice (LinuxApmFd);
-	close (LinuxApmFd);
-	LinuxApmFd = -1;
-    }
+#ifdef HAVE_APM
+    LinuxApmClose();
+#endif
 }
 
 static void
diff --git a/hw/xfree86/os-support/bsd/Makefile.am b/hw/xfree86/os-support/bsd/Makefile.am
index b6ecdf1..27150b7 100644
--- a/hw/xfree86/os-support/bsd/Makefile.am
+++ b/hw/xfree86/os-support/bsd/Makefile.am
@@ -1,15 +1,19 @@
 noinst_LTLIBRARIES = libbsd.la
 
 # APM support.
+if APM
 if BSD_KQUEUE_APM
-APM_SOURCES = $(srcdir)/bsd_kqueue_apm.c
+  APM_SOURCES = $(srcdir)/bsd_kqueue_apm.c
 else 
 if BSD_APM
-APM_SOURCES = $(srcdir)/bsd_apm.c
+  APM_SOURCES = $(srcdir)/bsd_apm.c
 else
-APM_SOURCES = $(srcdir)/../shared/pm_noop.c
+  APM_SOURCES = $(srcdir)/../shared/pm_noop.c
 endif
 endif
+else
+  APM_SOURCES = $(srcdir)/../shared/pm_noop.c
+endif
 
 if FREEBSD_KLDLOAD
 KMOD_SOURCES = bsd_kmod.c
diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index 7a82627..c578e69 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -20,10 +20,12 @@ ACPI_SRCS = lnx_acpi.c lnx_apm.c
 XORG_CFLAGS += -DHAVE_ACPI
 endif
 
+if APM
 if LNXAPM
 APM_SRCS = lnx_apm.c
 XORG_CFLAGS += -DHAVE_APM
 endif
+endif
 
 liblinux_la_SOURCES = lnx_init.c lnx_video.c \
                      lnx_agp.c lnx_kmod.c lnx_bell.c \
diff --git a/hw/xfree86/os-support/solaris/Makefile.am b/hw/xfree86/os-support/solaris/Makefile.am
index 5163f44..b5bbb85 100644
--- a/hw/xfree86/os-support/solaris/Makefile.am
+++ b/hw/xfree86/os-support/solaris/Makefile.am
@@ -10,6 +10,12 @@ else
 AGP_SRC = $(srcdir)/../shared/agp_noop.c
 endif
 
+if APM
+APM_SRC = sun_apm.c
+else
+APM_SRC = $(srcdir)/../shared/pm_noop.c
+endif
+
 SOLARIS_INOUT_SRC = solaris- at SOLARIS_INOUT_ARCH@.S
 DISTCLEANFILES = solaris- at SOLARIS_INOUT_ARCH@.il
 
@@ -18,7 +24,7 @@ solaris- at SOLARIS_INOUT_ARCH@.il: solaris- at SOLARIS_INOUT_ARCH@.S
 
 noinst_LTLIBRARIES = libsolaris.la
 libsolaris_la_SOURCES = sun_init.c \
-	sun_vid.c sun_bell.c $(AGP_SRC) sun_apm.c \
+	sun_vid.c sun_bell.c $(AGP_SRC) $(APM_SRC) \
 	$(srcdir)/../shared/kmod_noop.c \
 	$(srcdir)/../shared/posix_tty.c \
 	$(srcdir)/../shared/sigio.c \
-- 
1.6.3.3

I would like to get some {Reviewed,Tested}-by on this patch, especially from
people who can test on BSD and Solaris.


More information about the xorg-devel mailing list