Skip to content

Commit 0b18edb

Browse files
committed
feat: 更新 rdif-intc 版本至 0.12.0,重构中断控制器接口实现
1 parent 944074a commit 0b18edb

7 files changed

Lines changed: 71 additions & 197 deletions

File tree

examples/enumerate/src/intc.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use log::debug;
2+
use rdrive::{
3+
PlatformDevice,
4+
driver::intc::*,
5+
probe::OnProbeError,
6+
register::{DriverRegister, FdtInfo, ProbeKind, ProbeLevel, ProbePriority},
7+
};
8+
9+
pub struct IrqTest {}
10+
11+
pub fn register() -> DriverRegister {
12+
DriverRegister {
13+
name: "IrqTest",
14+
probe_kinds: &[ProbeKind::Fdt {
15+
compatibles: &["arm,cortex-a15-gic"],
16+
on_probe: probe_intc,
17+
}],
18+
level: ProbeLevel::PreKernel,
19+
priority: ProbePriority::INTC,
20+
}
21+
}
22+
23+
impl rdrive::DriverGeneric for IrqTest {
24+
fn open(&mut self) -> Result<(), KError> {
25+
Ok(())
26+
}
27+
28+
fn close(&mut self) -> Result<(), KError> {
29+
Ok(())
30+
}
31+
}
32+
33+
impl Interface for IrqTest {
34+
fn parse_dtb_fn(&self) -> Option<rdrive::driver::intc::FuncFdtParseConfig> {
35+
Some(fdt_parse)
36+
}
37+
}
38+
39+
fn fdt_parse(_prop_interrupts_one_cell: &[u32]) -> Result<IrqConfig, String> {
40+
Ok(IrqConfig {
41+
irq: 0.into(),
42+
trigger: Trigger::EdgeBoth,
43+
is_private: false,
44+
})
45+
}
46+
47+
fn probe_intc(fdt: FdtInfo<'_>, plat_dev: PlatformDevice) -> Result<(), OnProbeError> {
48+
debug!(
49+
"on_probe: {}, parent intc {:?}",
50+
fdt.node.name(),
51+
plat_dev.descriptor.irq_parent,
52+
);
53+
plat_dev.register_intc(IrqTest {});
54+
55+
Ok(())
56+
}

examples/enumerate/src/main.rs

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#![feature(used_with_arg)]
22

3-
use std::{error::Error, ptr::NonNull};
3+
use std::ptr::NonNull;
44

55
use log::debug;
6-
use rdrive::{
7-
IrqConfig, IrqId, KError, PlatformDevice, driver, get_list,
8-
probe::OnProbeError,
9-
register::{DriverRegister, FdtInfo, ProbeKind, ProbeLevel, ProbePriority},
10-
};
6+
use rdrive::{driver, get_list};
7+
8+
use crate::intc::IrqTest;
119

1210
pub mod blk;
1311
pub mod clk;
12+
pub mod intc;
1413
pub mod timer;
1514

1615
fn main() {
@@ -25,17 +24,7 @@ fn main() {
2524
})
2625
.unwrap();
2726

28-
let register = DriverRegister {
29-
name: "IrqTest",
30-
probe_kinds: &[ProbeKind::Fdt {
31-
compatibles: &["arm,cortex-a15-gic"],
32-
on_probe: probe_intc,
33-
}],
34-
level: ProbeLevel::PreKernel,
35-
priority: ProbePriority::INTC,
36-
};
37-
38-
rdrive::register_add(register);
27+
rdrive::register_add(intc::register());
3928
rdrive::register_add(timer::register());
4029
rdrive::register_add(clk::register());
4130
rdrive::register_add(blk::register());
@@ -50,6 +39,8 @@ fn main() {
5039

5140
let t = g.typed_ref::<IrqTest>();
5241
debug!("intc: {:?}", g.type_name());
42+
43+
5344

5445
assert!(t.is_some(), "Intc should be [IrqTest]");
5546
}
@@ -60,76 +51,3 @@ fn main() {
6051

6152
println!("phandle 0x8000 to device id: {:?}", id);
6253
}
63-
64-
struct IrqTest {}
65-
66-
impl rdrive::DriverGeneric for IrqTest {
67-
fn open(&mut self) -> Result<(), KError> {
68-
Ok(())
69-
}
70-
71-
fn close(&mut self) -> Result<(), KError> {
72-
Ok(())
73-
}
74-
}
75-
76-
impl rdrive::driver::intc::Interface for IrqTest {
77-
fn irq_enable(&mut self, _irq: IrqId) -> Result<(), rdrive::driver::intc::IntcError> {
78-
todo!()
79-
}
80-
81-
fn irq_disable(&mut self, _irq: IrqId) -> Result<(), rdrive::driver::intc::IntcError> {
82-
todo!()
83-
}
84-
85-
fn set_priority(
86-
&mut self,
87-
_irq: IrqId,
88-
_priority: usize,
89-
) -> Result<(), rdrive::driver::intc::IntcError> {
90-
todo!()
91-
}
92-
93-
fn set_trigger(
94-
&mut self,
95-
_irq: IrqId,
96-
_trigger: rdrive::driver::intc::Trigger,
97-
) -> Result<(), rdrive::driver::intc::IntcError> {
98-
todo!()
99-
}
100-
101-
fn set_target_cpu(
102-
&mut self,
103-
_irq: IrqId,
104-
_cpu: rdrive::driver::intc::CpuId,
105-
) -> Result<(), rdrive::driver::intc::IntcError> {
106-
todo!()
107-
}
108-
109-
fn cpu_local(&self) -> Option<rdrive::driver::intc::local::Boxed> {
110-
todo!()
111-
}
112-
113-
fn parse_dtb_fn(&self) -> Option<rdrive::driver::intc::FuncFdtParseConfig> {
114-
Some(fdt_parse)
115-
}
116-
}
117-
118-
fn fdt_parse(_prop_interrupts_one_cell: &[u32]) -> Result<IrqConfig, Box<dyn Error>> {
119-
Ok(IrqConfig {
120-
irq: 0.into(),
121-
trigger: rdrive::driver::intc::Trigger::EdgeBoth,
122-
is_private: false,
123-
})
124-
}
125-
126-
fn probe_intc(fdt: FdtInfo<'_>, plat_dev: PlatformDevice) -> Result<(), OnProbeError> {
127-
debug!(
128-
"on_probe: {}, parent intc {:?}",
129-
fdt.node.name(),
130-
plat_dev.descriptor.irq_parent,
131-
);
132-
plat_dev.register_intc(IrqTest {});
133-
134-
Ok(())
135-
}

interface/rdif-intc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rdif-intc"
3-
version = "0.11.0"
3+
version = "0.12.0"
44
edition.workspace = true
55
authors = ["周睿 <zrufo747@outlook.com>"]
66
repository.workspace = true

interface/rdif-intc/src/lib.rs

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,16 @@
22

33
extern crate alloc;
44

5-
use alloc::boxed::Box;
6-
use core::error::Error;
5+
use alloc::string::String;
76

87
pub use rdif_base::{CpuId, DriverGeneric, KError, irq::*};
98

10-
/// CPU local interrupt controller interface
11-
pub mod local {
12-
use super::*;
13-
14-
/// Boxed interface
15-
pub type Boxed = Box<dyn Interface>;
16-
17-
pub trait Interface: DriverGeneric + Sync {
18-
fn ack(&self) -> Option<IrqId>;
19-
fn eoi(&self, irq: IrqId);
20-
21-
cfg_if::cfg_if! {
22-
if #[cfg(target_arch = "aarch64")]{
23-
fn dir(&self, intid: IrqId);
24-
fn set_eoi_mode(&self, b: bool);
25-
fn get_eoi_mode(&self) -> bool;
26-
}
27-
}
28-
29-
fn capability(&self) -> Capability;
30-
}
31-
32-
/// controller capability
33-
pub enum Capability {
34-
None,
35-
/// Local interface can config local irq.
36-
ConfigLocalIrq(cap::BoxedConfigLocalIrq),
37-
}
38-
39-
pub mod cap {
40-
use super::*;
41-
42-
pub type BoxedConfigLocalIrq = Box<dyn ConfigLocalIrq>;
43-
44-
/// Local interface can config local irq.
45-
pub trait ConfigLocalIrq: Send + Sync {
46-
fn irq_enable(&self, irq: IrqId) -> Result<(), IntcError>;
47-
fn irq_disable(&self, irq: IrqId) -> Result<(), IntcError>;
48-
fn set_priority(&self, irq: IrqId, priority: usize) -> Result<(), IntcError>;
49-
fn set_trigger(&self, irq: IrqId, trigger: Trigger) -> Result<(), IntcError>;
50-
}
51-
}
52-
}
53-
549
/// Fdt 解析 `interrupts` 函数,一次解析一个`cell`
55-
pub type FuncFdtParseConfig =
56-
fn(prop_interrupts_one_cell: &[u32]) -> Result<IrqConfig, Box<dyn Error>>;
10+
pub type FuncFdtParseConfig = fn(prop_interrupts_one_cell: &[u32]) -> Result<IrqConfig, String>;
5711

5812
pub trait Interface: DriverGeneric {
59-
fn irq_enable(&mut self, irq: IrqId) -> Result<(), IntcError>;
60-
fn irq_disable(&mut self, irq: IrqId) -> Result<(), IntcError>;
61-
fn set_priority(&mut self, irq: IrqId, priority: usize) -> Result<(), IntcError>;
62-
fn set_trigger(&mut self, irq: IrqId, trigger: Trigger) -> Result<(), IntcError>;
63-
fn set_target_cpu(&mut self, irq: IrqId, cpu: CpuId) -> Result<(), IntcError>;
64-
65-
/// Get CPU local interrupt controller, return None if not supported
66-
fn cpu_local(&self) -> Option<local::Boxed>;
6713
/// If not supported, returns None
6814
fn parse_dtb_fn(&self) -> Option<FuncFdtParseConfig> {
6915
None
7016
}
7117
}
72-
73-
#[derive(thiserror::Error, Debug)]
74-
pub enum IntcError {
75-
#[error("irq `{id:?}` not compatible")]
76-
IrqIdNotCompatible { id: IrqId },
77-
#[error("not support")]
78-
NotSupport,
79-
#[error("other error: {0}")]
80-
Other(Box<dyn Error>),
81-
}

rdrive/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [0.15.3](https://github.com/drivercraft/rdrive/compare/rdrive-v0.15.2...rdrive-v0.15.3) - 2025-06-27
10+
## [0.16.0](https://github.com/drivercraft/rdrive/compare/rdrive-v0.15.2...rdrive-v0.16.0) - 2025-06-27
1111

1212
### Added
1313

rdrive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords = ["os", "driver"]
77
license = "MIT"
88
name = "rdrive"
99
repository.workspace = true
10-
version = "0.15.3"
10+
version = "0.16.0"
1111
readme = "../README.md"
1212

1313
[dependencies]
@@ -18,7 +18,7 @@ spin = "0.10"
1818
thiserror = {version = "2", default-features = false}
1919

2020
rdif-base = {workspace = true}
21-
rdif-intc = {version = "0.11", path = "../interface/rdif-intc"}
21+
rdif-intc = { version = "0.12", path = "../interface/rdif-intc"}
2222
rdif-block = {version = "0.5", path = "../interface/rdif-block"}
2323
rdif-clk = {version = "0.4", path = "../interface/rdif-clk"}
2424
rdif-power = {version = "0.6", path = "../interface/rdif-power"}

rdrive/src/manager.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -180,43 +180,7 @@ mod tests {
180180
}
181181
}
182182

183-
impl intc::Interface for IrqTest {
184-
fn irq_enable(&mut self, _irq: rdif_intc::IrqId) -> Result<(), rdif_intc::IntcError> {
185-
todo!()
186-
}
187-
188-
fn irq_disable(&mut self, _irq: rdif_intc::IrqId) -> Result<(), rdif_intc::IntcError> {
189-
todo!()
190-
}
191-
192-
fn set_priority(
193-
&mut self,
194-
_irq: rdif_intc::IrqId,
195-
_priority: usize,
196-
) -> Result<(), rdif_intc::IntcError> {
197-
todo!()
198-
}
199-
200-
fn set_trigger(
201-
&mut self,
202-
_irq: rdif_intc::IrqId,
203-
_trigger: rdif_intc::Trigger,
204-
) -> Result<(), rdif_intc::IntcError> {
205-
todo!()
206-
}
207-
208-
fn set_target_cpu(
209-
&mut self,
210-
_irq: rdif_intc::IrqId,
211-
_cpu: rdif_base::CpuId,
212-
) -> Result<(), rdif_intc::IntcError> {
213-
todo!()
214-
}
215-
216-
fn cpu_local(&self) -> Option<rdif_intc::local::Boxed> {
217-
todo!()
218-
}
219-
}
183+
impl intc::Interface for IrqTest {}
220184

221185
#[test]
222186
fn test_inner_type() {

0 commit comments

Comments
 (0)