From c64df68125cc79dd331436be0472a5e4f7da0f4a Mon Sep 17 00:00:00 2001 From: tobhe Date: Wed, 5 Jul 2023 18:51:55 +0000 Subject: [PATCH] Move acpiioctl to acpi_x86.c, it is only used up on i386 and amd64. ok kettenis@ deraadt@ --- sys/dev/acpi/acpi.c | 60 +-------------------------------- sys/dev/acpi/acpi_x86.c | 73 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 60 deletions(-) diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 42cd7bfdb7e..73c053bea7f 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.421 2023/06/29 20:58:08 dv Exp $ */ +/* $OpenBSD: acpi.c,v 1.422 2023/07/05 18:51:55 tobhe Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -3439,58 +3439,6 @@ 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); @@ -3575,12 +3523,6 @@ 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 7a07e482a05..ac6548bda91 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.15 2022/03/06 15:12:00 deraadt Exp $ */ +/* $OpenBSD: acpi_x86.c,v 1.16 2023/07/05 18:51:56 tobhe Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -17,15 +17,86 @@ */ #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