Page MenuHomeFreeBSD

D55508.id172866.diff
No OneTemporary

D55508.id172866.diff

diff --git a/sys/kern/subr_power.c b/sys/kern/subr_power.c
--- a/sys/kern/subr_power.c
+++ b/sys/kern/subr_power.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2001 Mitsuru IWASAKI
* All rights reserved.
- * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025-2026 The FreeBSD Foundation
*
* Portions of this software were developed by Aymeric Wibo
* <obiwac@freebsd.org> under sponsorship from the FreeBSD Foundation.
@@ -31,7 +31,10 @@
*/
#include <sys/param.h>
+#include <sys/conf.h>
#include <sys/eventhandler.h>
+#include <sys/fcntl.h>
+#include <sys/kernel.h>
#include <sys/power.h>
#include <sys/proc.h>
#include <sys/sbuf.h>
@@ -49,6 +52,52 @@
static bool power_pm_supported[POWER_STYPE_COUNT] = {0};
static struct task power_pm_task;
+static d_ioctl_t power_ioctl;
+
+static struct cdevsw power_cdevsw = {
+ .d_version = D_VERSION,
+ .d_ioctl = power_ioctl,
+ .d_name = "power",
+};
+
+static void
+power_init(void *unused)
+{
+ struct make_dev_args args;
+ struct cdev *dev;
+
+ make_dev_args_init(&args);
+ args.mda_devsw = &power_cdevsw;
+ args.mda_uid = UID_ROOT;
+ args.mda_gid = GID_OPERATOR;
+ args.mda_mode = 0660;
+ if (make_dev_s(&args, &dev, "power") != 0)
+ printf("Failed to create power device");
+}
+SYSINIT(powerdev, SI_SUB_CONFIGURE, SI_ORDER_ANY, power_init, NULL);
+
+static int
+power_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
+ struct thread *td)
+{
+ uint32_t trans;
+
+ if ((fflag & FWRITE) == 0)
+ return (EPERM);
+
+ switch (cmd) {
+ case PIOTRANSITION:
+ trans = *(uint32_t *)data;
+ if (trans >= POWER_SSTATE_TRANSITION_COUNT)
+ return (EINVAL);
+ power_pm_suspend((enum power_sstate_transition)trans);
+ break;
+ default:
+ return (EINVAL);
+ }
+ return (0);
+}
+
enum power_stype
power_name_to_stype(const char *name)
{
diff --git a/sys/sys/power.h b/sys/sys/power.h
--- a/sys/sys/power.h
+++ b/sys/sys/power.h
@@ -3,7 +3,7 @@
*
* Copyright (c) 2001 Mitsuru IWASAKI
* All rights reserved.
- * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025-2026 The FreeBSD Foundation
*
* Portions of this software were developed by Aymeric Wibo
* <obiwac@freebsd.org> under sponsorship from the FreeBSD Foundation.
@@ -32,17 +32,9 @@
#ifndef _SYS_POWER_H_
#define _SYS_POWER_H_
-#ifdef _KERNEL
-#include <sys/_eventhandler.h>
#include <sys/types.h>
-
-/* Power management system type */
-#define POWER_PM_TYPE_ACPI 0x01
-#define POWER_PM_TYPE_NONE 0xff
-
-/* Commands for Power management function */
-#define POWER_CMD_SUSPEND 0x00
+#include <sys/ioccom.h>
/*
* Sleep state transition requests.
@@ -54,8 +46,25 @@
POWER_SSTATE_TRANSITION_STANDBY,
POWER_SSTATE_TRANSITION_SUSPEND,
POWER_SSTATE_TRANSITION_HIBERNATE,
+ POWER_SSTATE_TRANSITION_COUNT,
};
+/*
+ * Power ioctls.
+ */
+#define PIOTRANSITION _IOW('P', 1, uint32_t)
+
+#ifdef _KERNEL
+
+#include <sys/_eventhandler.h>
+
+/* Power management system type */
+#define POWER_PM_TYPE_ACPI 0x01
+#define POWER_PM_TYPE_NONE 0xff
+
+/* Commands for Power management function */
+#define POWER_CMD_SUSPEND 0x00
+
/*
* Sleep type.
*

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 21, 2:30 AM (10 h, 16 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31880904
Default Alt Text
D55508.id172866.diff (3 KB)

Event Timeline