git: 863fe7ae5152 - main - LinuxKPI: re-implement pm_runtime.h

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sat, 10 Oct 2026 18:29:02 UTC
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=863fe7ae5152926fab0380a78ba26b6ba4a2d65f

commit 863fe7ae5152926fab0380a78ba26b6ba4a2d65f
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-07-11 14:36:06 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-10-10 18:28:32 +0000

    LinuxKPI: re-implement pm_runtime.h
    
    The original implementation was based on OpenBSD under public domain
    but just defined the functions to void.
    FreeBSD later extended the file with more inline functions or dealing
    with differences in Linux versions.
    
    This rework tries to group some functions, adds properly typed arguments
    and return values in some cases.
    It further adjusts return values based on the !CONFIG_PM expectations.
    
    Lastly pr_debug() calls are added so we could see if/how much these
    functions are used in new/other works rather than code just compiling
    but the functions entirely being ignored without the knowledge of the
    person porting code.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
    Reviewed by:    dumbbell
    Differential Revision: https://reviews.freebsd.org/D58169
---
 .../linuxkpi/common/include/linux/pm_runtime.h     | 164 +++++++++++++++++----
 1 file changed, 134 insertions(+), 30 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/pm_runtime.h b/sys/compat/linuxkpi/common/include/linux/pm_runtime.h
index 8c7d9f3a8e1c..c4fcfad2860d 100644
--- a/sys/compat/linuxkpi/common/include/linux/pm_runtime.h
+++ b/sys/compat/linuxkpi/common/include/linux/pm_runtime.h
@@ -1,60 +1,164 @@
-/* Public domain. */
+/*
+ * Copyright (c) 2026 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
 
 #ifndef _LINUXKPI_LINUX_PM_RUNTIME_H_
 #define _LINUXKPI_LINUX_PM_RUNTIME_H_
 
+#include <linux/kernel.h>	/* pr_debug */
 #include <linux/device.h>
 #include <linux/pm.h>
 
-#define pm_runtime_mark_last_busy(x) (void)(x)
-#define pm_runtime_use_autosuspend(x) (void)(x)
-#define pm_runtime_dont_use_autosuspend(x) (void)(x)
-#define pm_runtime_put_autosuspend(x) (void)(x)
-#define pm_runtime_set_autosuspend_delay(x, y) (void)(x); (void)(y)
-#define pm_runtime_set_active(x) (void)(x)
-#define pm_runtime_allow(x) (void)(x)
-#define pm_runtime_put_noidle(x) (void)(x)
-#define pm_runtime_forbid(x) (void)(x)
-#define pm_runtime_get_noresume(x) (void)(x)
-#define pm_runtime_put(x) (void)(x)
-#define pm_runtime_enable(x) (void)(x)
-#define pm_runtime_disable(x) (void)(x)
-#define pm_runtime_autosuspend(x) (void)(x)
-#define pm_runtime_resume(x) (void)(x)
+/*
+ * Return values, where needed, are based on the !CONFIG_PM/!CONFIG_PM_SLEEP
+ * assumption given we currently do not support anything in here.
+ * We could #error in case CONFIG_PM or CONFIG_PM_SLEEP are set but that
+ * would likely be too intrusive for now.
+ *
+ * We could likely use dev_dbg() in here instead of pr_debug() if the former
+ * would be mapped to the latter with additional dev information.
+ */
+
+static inline void
+pm_runtime_enable(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline void
+pm_runtime_disable(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline void
+pm_runtime_allow(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline void
+pm_runtime_forbid(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+
+static inline void
+pm_runtime_mark_last_busy(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline void
+pm_runtime_get_noresume(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline void
+pm_runtime_put_noidle(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline bool
+pm_runtime_suspended(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+	return (false);
+}
 
 static inline int
-pm_runtime_get_sync(struct device *dev)
+pm_runtime_autosuspend(struct device *dev)
+{
+	pm_runtime_mark_last_busy(dev);
+	pr_debug("%s TODO\n", __func__);
+	return (-ENOSYS);
+}
+
+static inline void
+pm_runtime_use_autosuspend(struct device *dev __unused)
 {
-	return 0;
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline void
+pm_runtime_dont_use_autosuspend(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
+static inline void
+pm_runtime_set_autosuspend_delay(struct device *dev __unused, int delay __unused)
+{
+	pr_debug("%s TODO\n", __func__);
 }
 
 static inline int
-pm_runtime_get_if_in_use(struct device *dev)
+pm_runtime_put_autosuspend(struct device *dev)
 {
-	return 1;
+	pm_runtime_mark_last_busy(dev);
+	pr_debug("%s TODO\n", __func__);
+	return (-ENOSYS);
 }
 
-#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION < 60900
 static inline int
-pm_runtime_get_if_active(struct device *dev, bool x)
-#else
+pm_runtime_set_active(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+	return (0);
+}
+
+static inline void
+pm_runtime_put(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+}
+
 static inline int
-pm_runtime_get_if_active(struct device *dev)
-#endif
+pm_runtime_resume(struct device *dev __unused)
 {
-	return 1;
+	pr_debug("%s TODO\n", __func__);
+	return (1);
 }
 
 static inline int
-pm_runtime_suspended(struct device *dev)
+pm_runtime_get_sync(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+	return (1);
+}
+
+static inline int
+pm_runtime_get_if_in_use(struct device *dev __unused)
+{
+	pr_debug("%s TODO\n", __func__);
+	return (-EINVAL);
+}
+
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION < 60900
+static inline int
+pm_runtime_get_if_active(struct device *dev __unused, bool x __unused)
+#else
+static inline int
+pm_runtime_get_if_active(struct device *dev __unused)
+#endif
 {
-	return 0;
+	pr_debug("%s TODO\n", __func__);
+	return (-EINVAL);
 }
 
 static inline int
-pm_runtime_resume_and_get(struct device *dev)
+pm_runtime_resume_and_get(struct device *dev __unused)
 {
-	return 0;
+	pr_debug("%s TODO\n", __func__);
+	return (1);
 }
 
 #endif	/* _LINUXKPI_LINUX_PM_RUNTIME_H_ */