Skip to content

Commit bcb1aed

Browse files
committed
rust: use #[vtable] for kernel::irq::Chip
Signed-off-by: Gary Guo <[email protected]>
1 parent 49a9b36 commit bcb1aed

File tree

3 files changed

+9
-43
lines changed

3 files changed

+9
-43
lines changed

Diff for: drivers/gpio/gpio_pl061_rust.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ impl gpio::ChipWithIrqChip for PL061Device {
122122
}
123123
}
124124

125+
#[vtable]
125126
impl irq::Chip for PL061Device {
126127
type Data = Ref<DeviceData>;
127128

128-
kernel::declare_irq_chip_operations!(set_type, set_wake);
129-
130129
fn set_type(
131130
data: RefBorrow<'_, DeviceData>,
132131
irq_data: &mut LockedIrqData,

Diff for: rust/kernel/gpio.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,12 @@ mod irqchip {
427427
/// data is passed as context.
428428
struct IrqChipAdapter<T: irq::Chip>(PhantomData<T>);
429429

430+
#[vtable]
430431
impl<T: irq::Chip> irq::Chip for IrqChipAdapter<T> {
431432
type Data = *mut bindings::gpio_chip;
432-
const TO_USE: irq::ToUse = T::TO_USE;
433+
434+
const HAS_SET_TYPE: bool = T::HAS_SET_TYPE;
435+
const HAS_SET_WAKE: bool = T::HAS_SET_WAKE;
433436

434437
fn ack(gc: *mut bindings::gpio_chip, irq_data: &irq::IrqData) {
435438
// SAFETY: `IrqChipAdapter` is a private struct, only used when the data stored in the

Diff for: rust/kernel/irq.rs

+4-40
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
#![allow(dead_code)]
1111

12+
use crate::prelude::*;
1213
use crate::{bindings, error::from_kernel_result, types::PointerWrapper, Error, Result};
1314
use core::ops::Deref;
1415

@@ -95,14 +96,11 @@ pub enum ExtraResult {
9596
/// It is a trait for the functions defined in [`struct irq_chip`].
9697
///
9798
/// [`struct irq_chip`]: ../../../include/linux/irq.h
99+
#[vtable]
98100
pub trait Chip: Sized {
99101
/// The type of the context data stored in the irq chip and made available on each callback.
100102
type Data: PointerWrapper;
101103

102-
/// The methods to use to populate [`struct irq_chip`]. This is typically populated with
103-
/// [`declare_irq_chip_operations`].
104-
const TO_USE: ToUse;
105-
106104
/// Called at the start of a new interrupt.
107105
fn ack(data: <Self::Data as PointerWrapper>::Borrowed<'_>, irq_data: &IrqData);
108106

@@ -144,49 +142,15 @@ pub(crate) unsafe fn init_chip<T: Chip>(chip: &mut bindings::irq_chip) {
144142
chip.irq_mask = Some(irq_mask_callback::<T>);
145143
chip.irq_unmask = Some(irq_unmask_callback::<T>);
146144

147-
if T::TO_USE.set_type {
145+
if T::HAS_SET_TYPE {
148146
chip.irq_set_type = Some(irq_set_type_callback::<T>);
149147
}
150148

151-
if T::TO_USE.set_wake {
149+
if T::HAS_SET_WAKE {
152150
chip.irq_set_wake = Some(irq_set_wake_callback::<T>);
153151
}
154152
}
155153

156-
/// Represents which fields of [`struct irq_chip`] should be populated with pointers.
157-
///
158-
/// This is typically populated with the [`declare_irq_chip_operations`] macro.
159-
pub struct ToUse {
160-
/// The `irq_set_type` field of [`struct irq_chip`].
161-
pub set_type: bool,
162-
163-
/// The `irq_set_wake` field of [`struct irq_chip`].
164-
pub set_wake: bool,
165-
}
166-
167-
/// A constant version where all values are to set to `false`, that is, all supported fields will
168-
/// be set to null pointers.
169-
pub const USE_NONE: ToUse = ToUse {
170-
set_type: false,
171-
set_wake: false,
172-
};
173-
174-
/// Defines the [`Chip::TO_USE`] field based on a list of fields to be populated.
175-
#[macro_export]
176-
macro_rules! declare_irq_chip_operations {
177-
() => {
178-
const TO_USE: $crate::irq::ToUse = $crate::irq::USE_NONE;
179-
};
180-
($($i:ident),+) => {
181-
#[allow(clippy::needless_update)]
182-
const TO_USE: $crate::irq::ToUse =
183-
$crate::irq::ToUse {
184-
$($i: true),+ ,
185-
..$crate::irq::USE_NONE
186-
};
187-
};
188-
}
189-
190154
/// Enables or disables power-management wake-on for the given irq number.
191155
pub fn set_wake(irq: u32, on: bool) -> Result {
192156
// SAFETY: Just an FFI call, there are no extra requirements for safety.

0 commit comments

Comments
 (0)