Sure.
Tobias Heider <[email protected]> wrote:
> I am planning to restructure the APM/sleep APIs to make it easier to suspend
> from more places like as a suspend keyboard shortcut.
>
> The acpiioctl handler is x86 specific code which is currently built on all
> platforms but only hooked up on i386 and amd64. It is also in the way of
> my plans, so I'd prefer if we move it to acpi_x86.c where all the other
> x86-only acpi code lives.
>
> ok?
>
> Index: dev/acpi//acpi.c
> ===================================================================
> RCS file: /mount/openbsd/cvs/src/sys/dev/acpi/acpi.c,v
> retrieving revision 1.421
> diff -u -p -r1.421 acpi.c
> --- dev/acpi//acpi.c 29 Jun 2023 20:58:08 -0000 1.421
> +++ dev/acpi//acpi.c 5 Jul 2023 13:37:18 -0000
> @@ -3439,58 +3439,6 @@ acpiclose(dev_t dev, int flag, int mode,
> 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);
>
> @@ -3571,12 +3519,6 @@ acpiopen(dev_t dev, int flag, int mode,
>
> 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);
> }
> Index: dev/acpi//acpi_x86.c
> ===================================================================
> RCS file: /mount/openbsd/cvs/src/sys/dev/acpi/acpi_x86.c,v
> retrieving revision 1.15
> diff -u -p -r1.15 acpi_x86.c
> --- dev/acpi//acpi_x86.c 6 Mar 2022 15:12:00 -0000 1.15
> +++ dev/acpi//acpi_x86.c 5 Jul 2023 14:33:40 -0000
> @@ -17,15 +17,86 @@
> */
>
> #include <sys/param.h>
> +#include <sys/fcntl.h>
> #include <sys/systm.h>
> #include <sys/device.h>
>
> +#ifdef HIBERNATE
> +#include <sys/hibernate.h>
> +#endif
> +
> +#include <machine/conf.h>
> +#include <machine/cpufunc.h>
> +
> #include <dev/acpi/acpireg.h>
> #include <dev/acpi/acpivar.h>
> #include <dev/acpi/acpidev.h>
> #include <dev/acpi/dsdt.h>
>
> #include <machine/apmvar.h>
> +#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)
>