Skip to content

Commit ea09e6d

Browse files
committed
feat(port_riscv): rename use_timer!use_mtime!,
To make room for the SBI-based timer driver.
1 parent 08d3a57 commit ea09e6d

File tree

5 files changed

+44
-40
lines changed

5 files changed

+44
-40
lines changed

src/r3_port_riscv/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- The new option `ThreadingOptions::PRIVILEGE_LEVEL` allows for running the kernel in other privilege levels than M-mode.
1313

14+
### Changed
15+
16+
- Rename `use_timer!``use_mtime!`, `TimerOptions``MtimeOptions`
17+
1418
### Fixed
1519

1620
- The default stack alignment (`PortThreading::STACK_ALIGN`) now conforms to the standard ABI requirement (128-bit alignment).

src/r3_port_riscv/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ pub mod threading {
6868
pub mod imp;
6969
}
7070

71-
/// The standard timer driver.
71+
/// The `mtime`-based timer driver.
7272
#[doc(hidden)]
73-
pub mod timer {
73+
pub mod mtime {
7474
pub mod cfg;
7575
pub mod imp;
7676
}
7777

78+
pub use self::mtime::cfg::*;
7879
pub use self::plic::cfg::*;
7980
pub use self::rt::cfg::*;
8081
pub use self::threading::cfg::*;
81-
pub use self::timer::cfg::*;
8282

8383
/// Defines the entry points of a port instantiation. Implemented by
8484
/// [`use_port!`].
@@ -110,7 +110,7 @@ pub trait EntryPoint {
110110
}
111111

112112
/// An abstract inferface to a port timer driver. Implemented by
113-
/// [`use_timer!`].
113+
/// [`use_mtime!`].
114114
pub trait Timer {
115115
/// Initialize the driver. This will be called just before entering
116116
/// [`PortToKernel::boot`].

src/r3_port_riscv/src/timer/cfg.rs renamed to src/r3_port_riscv/src/mtime/cfg.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
//! The public interface for the RISC-V timer.
1+
//! The public interface for the `mtime`-based timer driver.
22
use r3_core::kernel::InterruptNum;
33

4-
/// Attach the implementation of [`PortTimer`] that is based on the RISC-V timer
5-
/// (`mtime`/`mtimecfg`) to a given kernel trait type. This macro also
4+
/// Attach the implementation of [`PortTimer`] based on the RISC-V machine-mode
5+
/// timer (`mtime`/`mtimecfg`) to a given kernel trait type. This macro also
66
/// implements [`Timer`] on the system type.
7-
/// **Requires [`TimerOptions`].**
7+
/// **Requires [`MtimeOptions`].**
88
///
99
/// [`PortTimer`]: r3_kernel::PortTimer
1010
/// [`Timer`]: crate::Timer
1111
///
1212
/// You should do the following:
1313
///
14-
/// - Implement [`TimerOptions`] on the system type `$Traits`.
14+
/// - Implement [`MtimeOptions`] on the system type `$Traits`.
1515
/// - Call `$Traits::configure_timer()` in your configuration function.
1616
/// See the following example.
1717
///
1818
/// ```rust,ignore
19-
/// r3_port_riscv::use_timer!(unsafe impl PortTimer for System);
19+
/// r3_port_riscv::use_mtime!(unsafe impl PortTimer for System);
2020
///
21-
/// impl r3_port_riscv::TimerOptions for System {
21+
/// impl r3_port_riscv::MtimeOptions for System {
2222
/// const MTIME_PTR: usize = 0x1001_1000;
2323
/// const MTIMECMP_PTR: usize = 0x1001_1000;
2424
/// const FREQUENCY: u64 = 1_000_000;
@@ -32,10 +32,10 @@ use r3_core::kernel::InterruptNum;
3232
///
3333
/// # Safety
3434
///
35-
/// - `TimerOptions` must be configured correctly.
35+
/// - `MtimeOptions` must be configured correctly.
3636
///
3737
#[macro_export]
38-
macro_rules! use_timer {
38+
macro_rules! use_mtime {
3939
(unsafe impl PortTimer for $Traits:ty) => {
4040
const _: () = {
4141
use $crate::r3_core::{
@@ -44,55 +44,55 @@ macro_rules! use_timer {
4444
};
4545
use $crate::r3_kernel::{PortTimer, System, UTicks};
4646
use $crate::r3_portkit::tickless;
47-
use $crate::{timer, Timer, TimerOptions};
47+
use $crate::{mtime, MtimeOptions, Timer};
4848

4949
impl PortTimer for $Traits {
5050
const MAX_TICK_COUNT: UTicks = u32::MAX;
5151
const MAX_TIMEOUT: UTicks = u32::MAX;
5252

5353
unsafe fn tick_count() -> UTicks {
5454
// Safety: We are just forwarding the call
55-
unsafe { timer::imp::tick_count::<Self>() }
55+
unsafe { mtime::imp::tick_count::<Self>() }
5656
}
5757

5858
unsafe fn pend_tick() {
5959
// Safety: We are just forwarding the call
60-
unsafe { timer::imp::pend_tick::<Self>() }
60+
unsafe { mtime::imp::pend_tick::<Self>() }
6161
}
6262

6363
unsafe fn pend_tick_after(tick_count_delta: UTicks) {
6464
// Safety: We are just forwarding the call
65-
unsafe { timer::imp::pend_tick_after::<Self>(tick_count_delta) }
65+
unsafe { mtime::imp::pend_tick_after::<Self>(tick_count_delta) }
6666
}
6767
}
6868

6969
impl Timer for $Traits {
7070
unsafe fn init() {
71-
unsafe { timer::imp::init::<Self>() }
71+
unsafe { mtime::imp::init::<Self>() }
7272
}
7373
}
7474

7575
const TICKLESS_CFG: tickless::TicklessCfg =
7676
match tickless::TicklessCfg::new(tickless::TicklessOptions {
77-
hw_freq_num: <$Traits as TimerOptions>::FREQUENCY,
78-
hw_freq_denom: <$Traits as TimerOptions>::FREQUENCY_DENOMINATOR,
79-
hw_headroom_ticks: <$Traits as TimerOptions>::HEADROOM,
77+
hw_freq_num: <$Traits as MtimeOptions>::FREQUENCY,
78+
hw_freq_denom: <$Traits as MtimeOptions>::FREQUENCY_DENOMINATOR,
79+
hw_headroom_ticks: <$Traits as MtimeOptions>::HEADROOM,
8080
// `mtime` is a 64-bit free-running counter and it is
8181
// expensive to create a 32-bit timer with an arbitrary
8282
// period out of it.
8383
force_full_hw_period: true,
8484
// If clearing `mtime` is not allowed, we must record the
8585
// starting value of `mtime` by calling `reset`.
86-
resettable: !<$Traits as TimerOptions>::RESET_MTIME,
86+
resettable: !<$Traits as MtimeOptions>::RESET_MTIME,
8787
}) {
8888
Ok(x) => x,
8989
Err(e) => e.panic(),
9090
};
9191

9292
static mut TIMER_STATE: tickless::TicklessState<TICKLESS_CFG> = Init::INIT;
9393

94-
// Safety: Only `use_timer!` is allowed to `impl` this
95-
unsafe impl timer::imp::TimerInstance for $Traits {
94+
// Safety: Only `use_mtime!` is allowed to `impl` this
95+
unsafe impl mtime::imp::TimerInstance for $Traits {
9696
const TICKLESS_CFG: tickless::TicklessCfg = TICKLESS_CFG;
9797

9898
type TicklessState = tickless::TicklessState<TICKLESS_CFG>;
@@ -107,15 +107,15 @@ macro_rules! use_timer {
107107
where
108108
C: ~const traits::CfgInterruptLine<System = System<Self>>,
109109
{
110-
timer::imp::configure(b);
110+
mtime::imp::configure(b);
111111
}
112112
}
113113
};
114114
};
115115
}
116116

117-
/// The options for [`use_timer!`].
118-
pub trait TimerOptions {
117+
/// The options for [`use_mtime!`].
118+
pub trait MtimeOptions {
119119
/// The memory address of the `mtime` register.
120120
const MTIME_PTR: usize;
121121

src/r3_port_riscv/src/timer/imp.rs renamed to src/r3_port_riscv/src/mtime/imp.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! The implementation of the RISC-V timer driver.
1+
//! The implementation of the `mtime`-based timer driver.
22
use r3_core::kernel::{traits, Cfg, StaticInterruptHandler};
33
use r3_kernel::{KernelTraits, PortToKernel, System, UTicks};
44
use r3_portkit::tickless::{TicklessCfg, TicklessStateTrait};
@@ -7,14 +7,14 @@ use tock_registers::{
77
registers::ReadWrite,
88
};
99

10-
use crate::timer::cfg::TimerOptions;
10+
use crate::mtime::cfg::MtimeOptions;
1111

12-
/// Implemented on a system type by [`use_timer!`].
12+
/// Implemented on a system type by [`use_mtime!`].
1313
///
1414
/// # Safety
1515
///
16-
/// Only meant to be implemented by [`use_timer!`].
17-
pub unsafe trait TimerInstance: KernelTraits + TimerOptions {
16+
/// Only meant to be implemented by [`use_mtime!`].
17+
pub unsafe trait TimerInstance: KernelTraits + MtimeOptions {
1818
// FIXME: Specifying `TicklessCfg::new(...)` here causes a "cycle
1919
// detected" error
2020
const TICKLESS_CFG: TicklessCfg;
@@ -30,19 +30,19 @@ pub unsafe trait TimerInstance: KernelTraits + TimerOptions {
3030
trait TimerInstanceExt: TimerInstance {
3131
#[inline(always)]
3232
fn mtime_reg32() -> &'static [ReadWrite<u32>; 2] {
33-
// Safety: Verified by the user of `use_timer!`
33+
// Safety: Verified by the user of `use_mtime!`
3434
unsafe { &*(Self::MTIME_PTR as *const _) }
3535
}
3636

3737
#[inline(always)]
3838
fn mtime_reg64() -> &'static ReadWrite<u64> {
39-
// Safety: Verified by the user of `use_timer!`
39+
// Safety: Verified by the user of `use_mtime!`
4040
unsafe { &*(Self::MTIME_PTR as *const _) }
4141
}
4242

4343
#[inline(always)]
4444
fn mtimecmp_reg32() -> &'static [ReadWrite<u32>; 2] {
45-
// Safety: Verified by the user of `use_timer!`
45+
// Safety: Verified by the user of `use_mtime!`
4646
unsafe { &*(Self::MTIMECMP_PTR as *const _) }
4747
}
4848

@@ -97,7 +97,7 @@ pub fn init<Traits: TimerInstance>() {
9797
///
9898
/// # Safety
9999
///
100-
/// Only meant to be referenced by `use_timer!`.
100+
/// Only meant to be referenced by `use_mtime!`.
101101
pub unsafe fn tick_count<Traits: TimerInstance>() -> UTicks {
102102
let tcfg = &Traits::TICKLESS_CFG;
103103

@@ -112,7 +112,7 @@ pub unsafe fn tick_count<Traits: TimerInstance>() -> UTicks {
112112
///
113113
/// # Safety
114114
///
115-
/// Only meant to be referenced by `use_timer!`.
115+
/// Only meant to be referenced by `use_mtime!`.
116116
pub unsafe fn pend_tick<Traits: TimerInstance>() {
117117
Traits::mtimecmp_reg32()[0].set(0);
118118
Traits::mtimecmp_reg32()[1].set(0);
@@ -122,7 +122,7 @@ pub unsafe fn pend_tick<Traits: TimerInstance>() {
122122
///
123123
/// # Safety
124124
///
125-
/// Only meant to be referenced by `use_timer!`.
125+
/// Only meant to be referenced by `use_mtime!`.
126126
pub unsafe fn pend_tick_after<Traits: TimerInstance>(tick_count_delta: UTicks) {
127127
let tcfg = &Traits::TICKLESS_CFG;
128128
// Safety: CPU Lock protects it from concurrent access

src/r3_port_riscv_test_driver/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ macro_rules! instantiate_test {
7979
type System = r3_kernel::System<SystemTraits>;
8080
port::use_port!(unsafe struct SystemTraits);
8181
port::use_rt!(unsafe SystemTraits);
82-
port::use_timer!(unsafe impl PortTimer for SystemTraits);
82+
port::use_mtime!(unsafe impl PortTimer for SystemTraits);
8383

8484
impl port::ThreadingOptions for SystemTraits {}
8585

@@ -106,7 +106,7 @@ macro_rules! instantiate_test {
106106
const CONTEXT: usize = 0;
107107
}
108108

109-
impl port::TimerOptions for SystemTraits {
109+
impl port::MtimeOptions for SystemTraits {
110110
const MTIME_PTR: usize = 0x0200_bff8;
111111

112112
#[cfg(any(

0 commit comments

Comments
 (0)