Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: irq: add flags module

Manipulating IRQ flags (i.e.: IRQF_*) will soon be necessary, specially to
register IRQ handlers through bindings::request_irq().

Add a kernel::irq::Flags for that purpose.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Tested-by: Joel Fernandes <joelagnelf@nvidia.com>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://lore.kernel.org/r/20250811-topics-tyr-request_irq2-v9-2-0485dcd9bcbf@collabora.com
[ Use expect(dead_code) for into_inner(), fix broken intra-doc link and
typo. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Daniel Almeida and committed by
Danilo Krummrich
746680ec 1f54d5e5

+130
+5
rust/kernel/irq.rs
··· 9 9 //! drivers to register a handler for a given IRQ line. 10 10 //! 11 11 //! C header: [`include/linux/device.h`](srctree/include/linux/interrupt.h) 12 + 13 + /// Flags to be used when registering IRQ handlers. 14 + mod flags; 15 + 16 + pub use flags::Flags;
+125
rust/kernel/irq/flags.rs
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // SPDX-FileCopyrightText: Copyright 2025 Collabora ltd. 3 + 4 + use crate::bindings; 5 + use crate::prelude::*; 6 + 7 + /// Flags to be used when registering IRQ handlers. 8 + /// 9 + /// Flags can be used to request specific behaviors when registering an IRQ 10 + /// handler, and can be combined using the `|`, `&`, and `!` operators to 11 + /// further control the system's behavior. 12 + /// 13 + /// A common use case is to register a shared interrupt, as sharing the line 14 + /// between devices is increasingly common in modern systems and is even 15 + /// required for some buses. This requires setting [`Flags::SHARED`] when 16 + /// requesting the interrupt. Other use cases include setting the trigger type 17 + /// through `Flags::TRIGGER_*`, which determines when the interrupt fires, or 18 + /// controlling whether the interrupt is masked after the handler runs by using 19 + /// [`Flags::ONESHOT`]. 20 + /// 21 + /// If an invalid combination of flags is provided, the system will refuse to 22 + /// register the handler, and lower layers will enforce certain flags when 23 + /// necessary. This means, for example, that all the 24 + /// `crate::irq::Registration` for a shared interrupt have to agree on 25 + /// [`Flags::SHARED`] and on the same trigger type, if set. 26 + #[derive(Clone, Copy, PartialEq, Eq)] 27 + pub struct Flags(c_ulong); 28 + 29 + impl Flags { 30 + /// Use the interrupt line as already configured. 31 + pub const TRIGGER_NONE: Flags = Flags::new(bindings::IRQF_TRIGGER_NONE); 32 + 33 + /// The interrupt is triggered when the signal goes from low to high. 34 + pub const TRIGGER_RISING: Flags = Flags::new(bindings::IRQF_TRIGGER_RISING); 35 + 36 + /// The interrupt is triggered when the signal goes from high to low. 37 + pub const TRIGGER_FALLING: Flags = Flags::new(bindings::IRQF_TRIGGER_FALLING); 38 + 39 + /// The interrupt is triggered while the signal is held high. 40 + pub const TRIGGER_HIGH: Flags = Flags::new(bindings::IRQF_TRIGGER_HIGH); 41 + 42 + /// The interrupt is triggered while the signal is held low. 43 + pub const TRIGGER_LOW: Flags = Flags::new(bindings::IRQF_TRIGGER_LOW); 44 + 45 + /// Allow sharing the IRQ among several devices. 46 + pub const SHARED: Flags = Flags::new(bindings::IRQF_SHARED); 47 + 48 + /// Set by callers when they expect sharing mismatches to occur. 49 + pub const PROBE_SHARED: Flags = Flags::new(bindings::IRQF_PROBE_SHARED); 50 + 51 + /// Flag to mark this interrupt as timer interrupt. 52 + pub const TIMER: Flags = Flags::new(bindings::IRQF_TIMER); 53 + 54 + /// Interrupt is per CPU. 55 + pub const PERCPU: Flags = Flags::new(bindings::IRQF_PERCPU); 56 + 57 + /// Flag to exclude this interrupt from irq balancing. 58 + pub const NOBALANCING: Flags = Flags::new(bindings::IRQF_NOBALANCING); 59 + 60 + /// Interrupt is used for polling (only the interrupt that is registered 61 + /// first in a shared interrupt is considered for performance reasons). 62 + pub const IRQPOLL: Flags = Flags::new(bindings::IRQF_IRQPOLL); 63 + 64 + /// Interrupt is not re-enabled after the hardirq handler finished. Used by 65 + /// threaded interrupts which need to keep the irq line disabled until the 66 + /// threaded handler has been run. 67 + pub const ONESHOT: Flags = Flags::new(bindings::IRQF_ONESHOT); 68 + 69 + /// Do not disable this IRQ during suspend. Does not guarantee that this 70 + /// interrupt will wake the system from a suspended state. 71 + pub const NO_SUSPEND: Flags = Flags::new(bindings::IRQF_NO_SUSPEND); 72 + 73 + /// Force enable it on resume even if [`Flags::NO_SUSPEND`] is set. 74 + pub const FORCE_RESUME: Flags = Flags::new(bindings::IRQF_FORCE_RESUME); 75 + 76 + /// Interrupt cannot be threaded. 77 + pub const NO_THREAD: Flags = Flags::new(bindings::IRQF_NO_THREAD); 78 + 79 + /// Resume IRQ early during syscore instead of at device resume time. 80 + pub const EARLY_RESUME: Flags = Flags::new(bindings::IRQF_EARLY_RESUME); 81 + 82 + /// If the IRQ is shared with a [`Flags::NO_SUSPEND`] user, execute this 83 + /// interrupt handler after suspending interrupts. For system wakeup devices 84 + /// users need to implement wakeup detection in their interrupt handlers. 85 + pub const COND_SUSPEND: Flags = Flags::new(bindings::IRQF_COND_SUSPEND); 86 + 87 + /// Don't enable IRQ or NMI automatically when users request it. Users will 88 + /// enable it explicitly by `enable_irq` or `enable_nmi` later. 89 + pub const NO_AUTOEN: Flags = Flags::new(bindings::IRQF_NO_AUTOEN); 90 + 91 + /// Exclude from runnaway detection for IPI and similar handlers, depends on 92 + /// `PERCPU`. 93 + pub const NO_DEBUG: Flags = Flags::new(bindings::IRQF_NO_DEBUG); 94 + 95 + #[expect(dead_code)] 96 + pub(crate) fn into_inner(self) -> c_ulong { 97 + self.0 98 + } 99 + 100 + const fn new(value: u32) -> Self { 101 + build_assert!(value as u64 <= c_ulong::MAX as u64); 102 + Self(value as c_ulong) 103 + } 104 + } 105 + 106 + impl core::ops::BitOr for Flags { 107 + type Output = Self; 108 + fn bitor(self, rhs: Self) -> Self::Output { 109 + Self(self.0 | rhs.0) 110 + } 111 + } 112 + 113 + impl core::ops::BitAnd for Flags { 114 + type Output = Self; 115 + fn bitand(self, rhs: Self) -> Self::Output { 116 + Self(self.0 & rhs.0) 117 + } 118 + } 119 + 120 + impl core::ops::Not for Flags { 121 + type Output = Self; 122 + fn not(self) -> Self::Output { 123 + Self(!self.0) 124 + } 125 + }