summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2009-02-26 17:19:48 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2009-02-26 17:19:48 +0000
commit1b0c7d8f045e292360d8b3b7e0cf000c18ce1cb2 (patch)
tree10398925663347dafd1909d8a4b4492736f22212 /sys/arch
parentea40a2de385d5e8b5b0fb8ebdd11092a68306c43 (diff)
Add a two new ioctls to the apm(4) interface.
APM_IOC_{SUSPEND,STANDBY}_REQ: This is to fix an issue with apm suspend where a call to zzz suspended the machine immediately, not giving anyone listening for apm events (other than apmd) a chance to deal with the upcoming change. This hit X hard since the introduction of drm, since it needs to have time to idle the 3d engine and otherwise get the device into a recoverable state. Such things are needed until we support modesetting in the kernel. Now, instead of forcing a suspend, using ioctl sends out an event similar to if you had put the lid down, giving all userland applications a chance to reply. tested by sthen@ and beck@, especial thanks to sthen for sitting there while I tried to debug this remotely, I owe him beer. Prompted by and ok deraadt@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/amd64/include/apmvar.h4
-rw-r--r--sys/arch/arm/include/apmvar.h4
-rw-r--r--sys/arch/arm/xscale/pxa2x0_apm.c14
-rw-r--r--sys/arch/i386/i386/apm.c17
-rw-r--r--sys/arch/i386/include/apmvar.h5
-rw-r--r--sys/arch/macppc/dev/apm.c11
-rw-r--r--sys/arch/macppc/include/apmvar.h4
-rw-r--r--sys/arch/sparc/dev/tctrl.c15
-rw-r--r--sys/arch/sparc/include/apmvar.h4
-rw-r--r--sys/arch/sparc64/include/apmvar.h4
10 files changed, 68 insertions, 14 deletions
diff --git a/sys/arch/amd64/include/apmvar.h b/sys/arch/amd64/include/apmvar.h
index 7be38bb9db4..b8a27a2ab83 100644
--- a/sys/arch/amd64/include/apmvar.h
+++ b/sys/arch/amd64/include/apmvar.h
@@ -1,5 +1,5 @@
/* XXX - DSR */
-/* $OpenBSD: apmvar.h,v 1.1 2004/01/28 01:39:39 mickey Exp $ */
+/* $OpenBSD: apmvar.h,v 1.2 2009/02/26 17:19:47 oga Exp $ */
/*
* Copyright (c) 1995 John T. Kohl
@@ -288,6 +288,8 @@ struct apm_ctl {
#define APM_PRINT_OFF 1 /* driver power status not displayed */
#define APM_PRINT_PCT 2 /* driver power status only displayed
if the percentage changes */
+#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */
+#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */
#ifdef _KERNEL
extern void apm_cpu_busy(void);
diff --git a/sys/arch/arm/include/apmvar.h b/sys/arch/arm/include/apmvar.h
index 57547b5a36a..b65096ac4c5 100644
--- a/sys/arch/arm/include/apmvar.h
+++ b/sys/arch/arm/include/apmvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: apmvar.h,v 1.1 2005/01/19 02:02:34 uwe Exp $ */
+/* $OpenBSD: apmvar.h,v 1.2 2009/02/26 17:19:47 oga Exp $ */
/*
* Copyright (c) 2001 Alexander Guy
@@ -114,5 +114,7 @@ struct apm_ctl {
#define APM_PRINT_OFF 1 /* driver power status not displayed */
#define APM_PRINT_PCT 2 /* driver power status only displayed
if the percentage changes */
+#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */
+#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */
#endif /* _ARM_APMVAR_H_ */
diff --git a/sys/arch/arm/xscale/pxa2x0_apm.c b/sys/arch/arm/xscale/pxa2x0_apm.c
index d38b571634e..aeeb360b03e 100644
--- a/sys/arch/arm/xscale/pxa2x0_apm.c
+++ b/sys/arch/arm/xscale/pxa2x0_apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pxa2x0_apm.c,v 1.28 2007/03/29 18:42:38 uwe Exp $ */
+/* $OpenBSD: pxa2x0_apm.c,v 1.29 2009/02/26 17:19:47 oga Exp $ */
/*-
* Copyright (c) 2001 Alexander Guy. All rights reserved.
@@ -562,7 +562,17 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
power = (struct apm_power_info *)data;
apm_power_info(sc, power);
break;
-
+ case APM_IOC_STANDBY_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ else if (apm_record_event(sc, APM_USER_STANDBY_REQ))
+ error = EINVAL /* ? */
+ break;
+ case APM_IOC_SUSPEND_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ else if (apm_record_event(sc, APM_USER_SUSPEND_REQ))
+ error = EINVAL /* ? */
default:
error = ENOTTY;
}
diff --git a/sys/arch/i386/i386/apm.c b/sys/arch/i386/i386/apm.c
index a431049518b..2821b2ad42f 100644
--- a/sys/arch/i386/i386/apm.c
+++ b/sys/arch/i386/i386/apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm.c,v 1.82 2008/08/16 00:26:26 krw Exp $ */
+/* $OpenBSD: apm.c,v 1.83 2009/02/26 17:19:47 oga Exp $ */
/*-
* Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
@@ -1145,7 +1145,20 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
error = EIO;
}
break;
-
+ case APM_IOC_STANDBY_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ /* only fails if no one cares. apmd at least should */
+ else if (apm_record_event(sc, APM_USER_STANDBY_REQ))
+ error = EINVAL; /* ? */
+ break;
+ case APM_IOC_SUSPEND_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ /* only fails if no one cares. apmd at least should */
+ else if (apm_record_event(sc, APM_USER_SUSPEND_REQ))
+ error = EINVAL; /* ? */
+ break;
default:
error = ENOTTY;
}
diff --git a/sys/arch/i386/include/apmvar.h b/sys/arch/i386/include/apmvar.h
index f2c1aaf41dc..7afcf85352d 100644
--- a/sys/arch/i386/include/apmvar.h
+++ b/sys/arch/i386/include/apmvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: apmvar.h,v 1.15 2002/03/14 01:26:33 millert Exp $ */
+/* $OpenBSD: apmvar.h,v 1.16 2009/02/26 17:19:47 oga Exp $ */
/*
* Copyright (c) 1995 John T. Kohl
@@ -287,6 +287,9 @@ struct apm_ctl {
#define APM_PRINT_OFF 1 /* driver power status not displayed */
#define APM_PRINT_PCT 2 /* driver power status only displayed
if the percentage changes */
+#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */
+#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */
+
#ifdef _KERNEL
extern void apm_cpu_busy(void);
diff --git a/sys/arch/macppc/dev/apm.c b/sys/arch/macppc/dev/apm.c
index 68b594ed9c2..03b23391551 100644
--- a/sys/arch/macppc/dev/apm.c
+++ b/sys/arch/macppc/dev/apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm.c,v 1.13 2007/12/11 15:44:00 tedu Exp $ */
+/* $OpenBSD: apm.c,v 1.14 2009/02/26 17:19:47 oga Exp $ */
/*-
* Copyright (c) 2001 Alexander Guy. All rights reserved.
@@ -286,7 +286,14 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
power->battery_state = APM_BATT_LOW;
}
break;
-
+ case APM_IOC_STANDBY_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ break;
+ case APM_IOC_SUSPEND_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ break;
default:
error = ENOTTY;
}
diff --git a/sys/arch/macppc/include/apmvar.h b/sys/arch/macppc/include/apmvar.h
index 241bb36fb63..d158467e37a 100644
--- a/sys/arch/macppc/include/apmvar.h
+++ b/sys/arch/macppc/include/apmvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: apmvar.h,v 1.4 2002/09/15 09:01:58 deraadt Exp $ */
+/* $OpenBSD: apmvar.h,v 1.5 2009/02/26 17:19:47 oga Exp $ */
/*
* Copyright (c) 2001 Alexander Guy
@@ -114,5 +114,7 @@ struct apm_ctl {
#define APM_PRINT_OFF 1 /* driver power status not displayed */
#define APM_PRINT_PCT 2 /* driver power status only displayed
if the percentage changes */
+#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */
+#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */
#endif /* _MACPPC_APMVAR_H_ */
diff --git a/sys/arch/sparc/dev/tctrl.c b/sys/arch/sparc/dev/tctrl.c
index 82b10e1e7de..5fc11d2ed3d 100644
--- a/sys/arch/sparc/dev/tctrl.c
+++ b/sys/arch/sparc/dev/tctrl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tctrl.c,v 1.19 2008/06/26 05:42:13 ray Exp $ */
+/* $OpenBSD: tctrl.c,v 1.20 2009/02/26 17:19:47 oga Exp $ */
/* $NetBSD: tctrl.c,v 1.2 1999/08/11 00:46:06 matt Exp $ */
/*-
@@ -1112,7 +1112,18 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
else
power->ac_state = APM_AC_OFF;
break;
-
+ case APM_IOC_STANDBY_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ else
+ error = EOPNOTSUPP; /* XXX */
+ break;
+ case APM_IOC_SUSPEND_REQ:
+ if ((flag & FWRITE) == 0)
+ error = EBADF;
+ else
+ error = EOPNOTSUPP; /* XXX */
+ break;
default:
error = ENOTTY;
}
diff --git a/sys/arch/sparc/include/apmvar.h b/sys/arch/sparc/include/apmvar.h
index 44404357b8f..c0fa7753179 100644
--- a/sys/arch/sparc/include/apmvar.h
+++ b/sys/arch/sparc/include/apmvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: apmvar.h,v 1.1 2005/03/29 16:26:44 miod Exp $ */
+/* $OpenBSD: apmvar.h,v 1.2 2009/02/26 17:19:47 oga Exp $ */
/*
* Copyright (c) 1995 John T. Kohl
@@ -120,5 +120,7 @@ struct apm_ctl {
#define APM_PRINT_OFF 1 /* driver power status not displayed */
#define APM_PRINT_PCT 2 /* driver power status only displayed
if the percentage changes */
+#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */
+#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */
#endif /* _MACHINE_APMVAR_H_ */
diff --git a/sys/arch/sparc64/include/apmvar.h b/sys/arch/sparc64/include/apmvar.h
index 6f603350dc8..1712ce1cd5e 100644
--- a/sys/arch/sparc64/include/apmvar.h
+++ b/sys/arch/sparc64/include/apmvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: apmvar.h,v 1.1 2008/08/11 18:38:10 kettenis Exp $ */
+/* $OpenBSD: apmvar.h,v 1.2 2009/02/26 17:19:47 oga Exp $ */
/*
* Copyright (c) 2001 Alexander Guy
@@ -114,5 +114,7 @@ struct apm_ctl {
#define APM_PRINT_OFF 1 /* driver power status not displayed */
#define APM_PRINT_PCT 2 /* driver power status only displayed
if the percentage changes */
+#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */
+#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */
#endif /* _SPARC64_APMVAR_H_ */