From 40f0948bcc05ef442a538b1c5a96a1f3efc21a8a Mon Sep 17 00:00:00 2001 From: deraadt Date: Thu, 6 Jul 2023 06:58:07 +0000 Subject: [PATCH] moving acpiioctl to a different file than acpiopen is not going to work for ramdisks. noticed by anton. this must be reconsidered. --- sys/dev/acpi/acpi.c | 60 ++++++++++++++++++++++++++++++++- sys/dev/acpi/acpi_x86.c | 73 +---------------------------------------- 2 files changed, 60 insertions(+), 73 deletions(-) diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 73c053bea7f..778a3fcf434 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.422 2023/07/05 18:51:55 tobhe Exp $ */ +/* $OpenBSD: acpi.c,v 1.423 2023/07/06 06:58:07 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -3439,6 +3439,58 @@ acpiclose(dev_t dev, int flag, int mode, struct proc *p) 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); @@ -3523,6 +3575,12 @@ 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) { diff --git a/sys/dev/acpi/acpi_x86.c b/sys/dev/acpi/acpi_x86.c index ac6548bda91..b9f19fdb7d1 100644 --- a/sys/dev/acpi/acpi_x86.c +++ b/sys/dev/acpi/acpi_x86.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi_x86.c,v 1.16 2023/07/05 18:51:56 tobhe Exp $ */ +/* $OpenBSD: acpi_x86.c,v 1.17 2023/07/06 06:58:07 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -17,86 +17,15 @@ */ #include -#include #include #include -#ifdef HIBERNATE -#include -#endif - -#include -#include - #include #include #include #include #include -#define APMUNIT(dev) (minor(dev)&0xf0) - -#ifndef SMALL_KERNEL -extern struct cfdriver acpi_cd; - -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); -} -#else /* SMALL_KERNEL */ -int -acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) -{ - return (ENXIO); -} -#endif /* SMALL_KERNEL */ int sleep_showstate(void *v, int sleepmode) -- 2.20.1