summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Heider <tobhe@cvs.openbsd.org>2023-07-08 08:01:11 +0000
committerTobias Heider <tobhe@cvs.openbsd.org>2023-07-08 08:01:11 +0000
commit8d8075d866dc1a1354ed5214e871f6041ba0e43e (patch)
treebebd3e6b838e2cc26e67cdeabf350ff5bc36a354
parent45787c261e24661844f7ff5ff0bac4aa88ded024 (diff)
Move /dev/apm related acpi code to acpi_apm.c which is only built on
amd64 and i386. This is the first step towards a machine independent safe sleep API. tested by yasuoka@ bluhm@ ok deraadt@ kettenis@
-rw-r--r--sys/arch/amd64/conf/files.amd643
-rw-r--r--sys/arch/i386/conf/files.i3863
-rw-r--r--sys/dev/acpi/acpi.c211
-rw-r--r--sys/dev/acpi/acpi_apm.c228
4 files changed, 233 insertions, 212 deletions
diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64
index b565f2ed748..a3452d9729c 100644
--- a/sys/arch/amd64/conf/files.amd64
+++ b/sys/arch/amd64/conf/files.amd64
@@ -1,4 +1,4 @@
-# $OpenBSD: files.amd64,v 1.108 2023/04/26 15:11:21 mlarkin Exp $
+# $OpenBSD: files.amd64,v 1.109 2023/07/08 08:01:10 tobhe Exp $
maxpartitions 16
maxusers 2 16 128
@@ -237,6 +237,7 @@ attach acpi at bios
file arch/amd64/amd64/acpi_machdep.c acpi
file arch/amd64/amd64/acpi_wakecode.S acpi & !small_kernel
file dev/acpi/acpi_x86.c acpi & suspend & !small_kernel
+file dev/acpi/acpi_apm.c acpi
device acpipci
attach acpipci at acpi
diff --git a/sys/arch/i386/conf/files.i386 b/sys/arch/i386/conf/files.i386
index a4ae58284ab..f94cb646f7d 100644
--- a/sys/arch/i386/conf/files.i386
+++ b/sys/arch/i386/conf/files.i386
@@ -1,4 +1,4 @@
-# $OpenBSD: files.i386,v 1.249 2023/01/17 10:10:11 jsg Exp $
+# $OpenBSD: files.i386,v 1.250 2023/07/08 08:01:10 tobhe Exp $
#
# new style config file for i386 architecture
#
@@ -377,6 +377,7 @@ attach acpi at bios
file arch/i386/i386/acpi_machdep.c acpi
file arch/i386/i386/acpi_wakecode.S acpi & !small_kernel
file dev/acpi/acpi_x86.c acpi & suspend & !small_kernel
+file dev/acpi/acpi_apm.c acpi
#
# IPMI
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c
index 11bdd85e283..ba6a3c468a4 100644
--- a/sys/dev/acpi/acpi.c
+++ b/sys/dev/acpi/acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpi.c,v 1.424 2023/07/07 07:37:59 claudio Exp $ */
+/* $OpenBSD: acpi.c,v 1.425 2023/07/08 08:01:10 tobhe Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
@@ -28,10 +28,6 @@
#include <sys/kthread.h>
#include <sys/sched.h>
-#ifdef HIBERNATE
-#include <sys/hibernate.h>
-#endif
-
#include <machine/conf.h>
#include <machine/cpufunc.h>
@@ -47,10 +43,6 @@
#include <dev/pci/pciidevar.h>
#include <machine/apmvar.h>
-#define APMUNIT(dev) (minor(dev)&0xf0)
-#define APMDEV(dev) (minor(dev)&0x0f)
-#define APMDEV_NORMAL 0
-#define APMDEV_CTL 8
#include "wd.h"
@@ -3384,134 +3376,6 @@ acpi_apminfo(struct apm_power_info *pi)
return 0;
}
-int
-acpiopen(dev_t dev, int flag, int mode, struct proc *p)
-{
- int error = 0;
- struct acpi_softc *sc;
- int s;
-
- if (!acpi_cd.cd_ndevs || APMUNIT(dev) != 0 ||
- !(sc = acpi_cd.cd_devs[APMUNIT(dev)]))
- return (ENXIO);
-
- s = splbio();
- switch (APMDEV(dev)) {
- case APMDEV_CTL:
- if (!(flag & FWRITE)) {
- error = EINVAL;
- break;
- }
- if (sc->sc_flags & SCFLAG_OWRITE) {
- error = EBUSY;
- break;
- }
- sc->sc_flags |= SCFLAG_OWRITE;
- break;
- case APMDEV_NORMAL:
- if (!(flag & FREAD) || (flag & FWRITE)) {
- error = EINVAL;
- break;
- }
- sc->sc_flags |= SCFLAG_OREAD;
- break;
- default:
- error = ENXIO;
- break;
- }
- splx(s);
- return (error);
-}
-
-int
-acpiclose(dev_t dev, int flag, int mode, struct proc *p)
-{
- int error = 0;
- struct acpi_softc *sc;
- int s;
-
- if (!acpi_cd.cd_ndevs || APMUNIT(dev) != 0 ||
- !(sc = acpi_cd.cd_devs[APMUNIT(dev)]))
- return (ENXIO);
-
- s = splbio();
- switch (APMDEV(dev)) {
- case APMDEV_CTL:
- sc->sc_flags &= ~SCFLAG_OWRITE;
- break;
- case APMDEV_NORMAL:
- sc->sc_flags &= ~SCFLAG_OREAD;
- break;
- default:
- error = ENXIO;
- break;
- }
- splx(s);
- return (error);
-}
-
-int
-acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
-{
- int error = 0;
- struct acpi_softc *sc;
- struct apm_power_info *pi = (struct apm_power_info *)data;
- int s;
-
- if (!acpi_cd.cd_ndevs || APMUNIT(dev) != 0 ||
- !(sc = acpi_cd.cd_devs[APMUNIT(dev)]))
- return (ENXIO);
-
- s = splbio();
- /* fake APM */
- switch (cmd) {
- case APM_IOC_SUSPEND:
- case APM_IOC_STANDBY:
- if ((flag & FWRITE) == 0) {
- error = EBADF;
- break;
- }
- acpi_addtask(sc, acpi_sleep_task, sc, SLEEP_SUSPEND);
- acpi_wakeup(sc);
- break;
-#ifdef HIBERNATE
- case APM_IOC_HIBERNATE:
- if ((error = suser(p)) != 0)
- break;
- if ((flag & FWRITE) == 0) {
- error = EBADF;
- break;
- }
- if (get_hibernate_io_function(swdevt[0].sw_dev) == NULL) {
- error = EOPNOTSUPP;
- break;
- }
- acpi_addtask(sc, acpi_sleep_task, sc, SLEEP_HIBERNATE);
- acpi_wakeup(sc);
- break;
-#endif
- case APM_IOC_GETPOWER:
- error = acpi_apminfo(pi);
- break;
-
- default:
- error = ENOTTY;
- }
-
- splx(s);
- return (error);
-}
-
-void acpi_filtdetach(struct knote *);
-int acpi_filtread(struct knote *, long);
-
-const struct filterops acpiread_filtops = {
- .f_flags = FILTEROP_ISFD,
- .f_attach = NULL,
- .f_detach = acpi_filtdetach,
- .f_event = acpi_filtread,
-};
-
int acpi_evindex;
int
@@ -3525,77 +3389,4 @@ acpi_record_event(struct acpi_softc *sc, u_int type)
return (0);
}
-void
-acpi_filtdetach(struct knote *kn)
-{
- struct acpi_softc *sc = kn->kn_hook;
- int s;
-
- s = splbio();
- klist_remove_locked(&sc->sc_note, kn);
- splx(s);
-}
-
-int
-acpi_filtread(struct knote *kn, long hint)
-{
- /* XXX weird kqueue_scan() semantics */
- if (hint && !kn->kn_data)
- kn->kn_data = hint;
- return (1);
-}
-
-int
-acpikqfilter(dev_t dev, struct knote *kn)
-{
- struct acpi_softc *sc;
- int s;
-
- if (!acpi_cd.cd_ndevs || APMUNIT(dev) != 0 ||
- !(sc = acpi_cd.cd_devs[APMUNIT(dev)]))
- return (ENXIO);
-
- switch (kn->kn_filter) {
- case EVFILT_READ:
- kn->kn_fop = &acpiread_filtops;
- break;
- default:
- return (EINVAL);
- }
-
- kn->kn_hook = sc;
-
- s = splbio();
- klist_insert_locked(&sc->sc_note, kn);
- splx(s);
-
- return (0);
-}
-
-#else /* SMALL_KERNEL */
-
-int
-acpiopen(dev_t dev, int flag, int mode, struct proc *p)
-{
- return (ENXIO);
-}
-
-int
-acpiclose(dev_t dev, int flag, int mode, struct proc *p)
-{
- return (ENXIO);
-}
-
-int
-acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
-{
- return (ENXIO);
-}
-
-int
-acpikqfilter(dev_t dev, struct knote *kn)
-{
- return (EOPNOTSUPP);
-}
-
#endif /* SMALL_KERNEL */
diff --git a/sys/dev/acpi/acpi_apm.c b/sys/dev/acpi/acpi_apm.c
new file mode 100644
index 00000000000..37d5d3e2feb
--- /dev/null
+++ b/sys/dev/acpi/acpi_apm.c
@@ -0,0 +1,228 @@
+/* $OpenBSD: acpi_apm.c,v 1.1 2023/07/08 08:01:10 tobhe Exp $ */
+/*
+ * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
+ * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, 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.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/fcntl.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpidev.h>
+#include <dev/acpi/dsdt.h>
+
+#include <machine/conf.h>
+#include <machine/cpufunc.h>
+
+#ifdef HIBERNATE
+#include <sys/hibernate.h>
+#endif
+
+#include <machine/apmvar.h>
+#define APMUNIT(dev) (minor(dev)&0xf0)
+#define APMDEV(dev) (minor(dev)&0x0f)
+#define APMDEV_NORMAL 0
+#define APMDEV_CTL 8
+
+#ifndef SMALL_KERNEL
+
+int
+acpiopen(dev_t dev, int flag, int mode, struct proc *p)
+{
+ int error = 0;
+ struct acpi_softc *sc = acpi_softc;
+ int s;
+
+ s = splbio();
+ switch (APMDEV(dev)) {
+ case APMDEV_CTL:
+ if (!(flag & FWRITE)) {
+ error = EINVAL;
+ break;
+ }
+ if (sc->sc_flags & SCFLAG_OWRITE) {
+ error = EBUSY;
+ break;
+ }
+ sc->sc_flags |= SCFLAG_OWRITE;
+ break;
+ case APMDEV_NORMAL:
+ if (!(flag & FREAD) || (flag & FWRITE)) {
+ error = EINVAL;
+ break;
+ }
+ sc->sc_flags |= SCFLAG_OREAD;
+ break;
+ default:
+ error = ENXIO;
+ break;
+ }
+ splx(s);
+ return (error);
+}
+
+int
+acpiclose(dev_t dev, int flag, int mode, struct proc *p)
+{
+ int error = 0;
+ struct acpi_softc *sc = acpi_softc;
+ int s;
+
+ s = splbio();
+ switch (APMDEV(dev)) {
+ case APMDEV_CTL:
+ sc->sc_flags &= ~SCFLAG_OWRITE;
+ break;
+ case APMDEV_NORMAL:
+ sc->sc_flags &= ~SCFLAG_OREAD;
+ break;
+ default:
+ error = ENXIO;
+ break;
+ }
+ splx(s);
+ return (error);
+}
+
+int
+acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+ int error = 0;
+ struct acpi_softc *sc = acpi_softc;
+ struct apm_power_info *pi = (struct apm_power_info *)data;
+ int s;
+
+ s = splbio();
+ /* fake APM */
+ switch (cmd) {
+ case APM_IOC_SUSPEND:
+ case APM_IOC_STANDBY:
+ if ((flag & FWRITE) == 0) {
+ error = EBADF;
+ break;
+ }
+ acpi_addtask(sc, acpi_sleep_task, sc, SLEEP_SUSPEND);
+ acpi_wakeup(sc);
+ break;
+#ifdef HIBERNATE
+ case APM_IOC_HIBERNATE:
+ if ((error = suser(p)) != 0)
+ break;
+ if ((flag & FWRITE) == 0) {
+ error = EBADF;
+ break;
+ }
+ if (get_hibernate_io_function(swdevt[0].sw_dev) == NULL) {
+ error = EOPNOTSUPP;
+ break;
+ }
+ acpi_addtask(sc, acpi_sleep_task, sc, SLEEP_HIBERNATE);
+ acpi_wakeup(sc);
+ break;
+#endif
+ case APM_IOC_GETPOWER:
+ error = acpi_apminfo(pi);
+ break;
+
+ default:
+ error = ENOTTY;
+ }
+
+ splx(s);
+ return (error);
+}
+
+void acpi_filtdetach(struct knote *);
+int acpi_filtread(struct knote *, long);
+
+const struct filterops acpiread_filtops = {
+ .f_flags = FILTEROP_ISFD,
+ .f_attach = NULL,
+ .f_detach = acpi_filtdetach,
+ .f_event = acpi_filtread,
+};
+
+int
+acpikqfilter(dev_t dev, struct knote *kn)
+{
+ struct acpi_softc *sc = acpi_softc;
+ int s;
+
+ switch (kn->kn_filter) {
+ case EVFILT_READ:
+ kn->kn_fop = &acpiread_filtops;
+ break;
+ default:
+ return (EINVAL);
+ }
+
+ kn->kn_hook = sc;
+
+ s = splbio();
+ klist_insert_locked(&sc->sc_note, kn);
+ splx(s);
+
+ return (0);
+}
+
+void
+acpi_filtdetach(struct knote *kn)
+{
+ struct acpi_softc *sc = kn->kn_hook;
+ int s;
+
+ s = splbio();
+ klist_remove_locked(&sc->sc_note, kn);
+ splx(s);
+}
+
+int
+acpi_filtread(struct knote *kn, long hint)
+{
+ /* XXX weird kqueue_scan() semantics */
+ if (hint && !kn->kn_data)
+ kn->kn_data = hint;
+ return (1);
+}
+
+#else /* SMALL_KERNEL */
+
+int
+acpiopen(dev_t dev, int flag, int mode, struct proc *p)
+{
+ return (ENXIO);
+}
+
+int
+acpiclose(dev_t dev, int flag, int mode, struct proc *p)
+{
+ return (ENXIO);
+}
+
+int
+acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+ return (ENXIO);
+}
+
+int
+acpikqfilter(dev_t dev, struct knote *kn)
+{
+ return (EOPNOTSUPP);
+}
+
+#endif /* SMALL_KERNEL */