git: 4f2f26fb1e8a - main - linuxkpi: implement irqs_disabled
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 16 Oct 2026 20:39:14 UTC
The branch main has been updated by ashafer:
URL: https://cgit.FreeBSD.org/src/commit/?id=4f2f26fb1e8aefb529e6186d8f39e1255dc98036
commit 4f2f26fb1e8aefb529e6186d8f39e1255dc98036
Author: Austin Shafer <ashafer@FreeBSD.org>
AuthorDate: 2026-06-23 18:55:31 +0000
Commit: Austin Shafer <ashafer@FreeBSD.org>
CommitDate: 2026-10-16 20:32:53 +0000
linuxkpi: implement irqs_disabled
This adds a function which is used from various places in drm-kmod
to detect if the code can sleep or not. Currently, these locations
(such as intel_guc_send_busy_loop) are ifdeffed to freebsd specific
solutions (usually drm_can_sleep).
This change implements irqs_disabled. We check td_pinned as spinlocks
will call sched_pin, and td_critnest to check if we are in a critical
section.
Approved by: wulf, khng (mentor)
Differential Revision: https://reviews.freebsd.org/D57782
---
sys/compat/linuxkpi/common/include/linux/hardirq.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/sys/compat/linuxkpi/common/include/linux/hardirq.h b/sys/compat/linuxkpi/common/include/linux/hardirq.h
index c6cbf1a34f14..97dc387b3e2e 100644
--- a/sys/compat/linuxkpi/common/include/linux/hardirq.h
+++ b/sys/compat/linuxkpi/common/include/linux/hardirq.h
@@ -36,6 +36,8 @@
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/interrupt.h>
+#include <sys/proc.h>
+#include <sys/lock.h>
#define synchronize_irq(irq) _intr_drain((irq))
@@ -49,4 +51,22 @@
*/
#define synchronize_hardirq(irq) _intr_drain((irq))
+/*
+ * irqs_disabled - returns true if the caller should not sleep
+ *
+ * This was originally implemented in drm-kmod in commit 530462939f6.
+ */
+static inline bool
+irqs_disabled(void)
+{
+ return (curthread->td_critnest != 0 || curthread->td_intr_nesting_level != 0);
+}
+
+/*
+ * local_irq_disable / local_irq_enable - disable/enable hardware interrupts
+ * on the current CPU.
+ */
+#define local_irq_disable() preempt_disable()
+#define local_irq_enable() preempt_enable()
+
#endif /* _LINUXKPI_LINUX_HARDIRQ_H_ */