Skip to content

Commit 589376f

Browse files
committed
Use self instead of &self for consistency
1 parent 4e3daa9 commit 589376f

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

riscv-peripheral/src/aclint.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ impl<C: Clint> CLINT<C> {
4949

5050
/// Returns the [`MSWI`](mswi::MSWI) device.
5151
#[inline]
52-
pub const fn mswi(&self) -> mswi::MSWI<C> {
52+
pub const fn mswi(self) -> mswi::MSWI<C> {
5353
mswi::MSWI::new()
5454
}
5555

5656
/// Returns the [`MTIMER`](mtimer::MTIMER) device.
5757
#[inline]
58-
pub const fn mtimer(&self) -> mtimer::MTIMER<C> {
58+
pub const fn mtimer(self) -> mtimer::MTIMER<C> {
5959
mtimer::MTIMER::new()
6060
}
6161

6262
/// Returns `true` if a machine timer **OR** software interrupt is pending.
6363
#[inline]
64-
pub fn is_interrupting(&self) -> bool {
64+
pub fn is_interrupting(self) -> bool {
6565
self.mswi().is_interrupting() || self.mtimer().is_interrupting()
6666
}
6767

6868
/// Returns `true` if machine timer **OR** software interrupts are enabled.
6969
#[inline]
70-
pub fn is_enabled(&self) -> bool {
70+
pub fn is_enabled(self) -> bool {
7171
self.mswi().is_enabled() || self.mtimer().is_enabled()
7272
}
7373

@@ -77,14 +77,14 @@ impl<C: Clint> CLINT<C> {
7777
///
7878
/// Enabling the `CLINT` may break mask-based critical sections.
7979
#[inline]
80-
pub unsafe fn enable(&self) {
80+
pub unsafe fn enable(self) {
8181
self.mswi().enable();
8282
self.mtimer().enable();
8383
}
8484

8585
/// Disables machine timer **AND** software interrupts to prevent the CLINT from triggering interrupts.
8686
#[inline]
87-
pub fn disable(&self) {
87+
pub fn disable(self) {
8888
self.mswi().disable();
8989
self.mtimer().disable();
9090
}

riscv-peripheral/src/aclint/mswi.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ impl<M: Mswi> MSWI<M> {
4141

4242
/// Returns the base address of the `MSWI` device.
4343
#[inline]
44-
const fn as_ptr(&self) -> *const u32 {
44+
const fn as_ptr(self) -> *const u32 {
4545
M::BASE as *const u32
4646
}
4747

4848
/// Returns `true` if a machine software interrupt is pending.
4949
#[inline]
50-
pub fn is_interrupting(&self) -> bool {
50+
pub fn is_interrupting(self) -> bool {
5151
mip::read().msoft()
5252
}
5353

5454
/// Returns `true` if machine software interrupts are enabled.
5555
#[inline]
56-
pub fn is_enabled(&self) -> bool {
56+
pub fn is_enabled(self) -> bool {
5757
mie::read().msoft()
5858
}
5959

@@ -63,20 +63,20 @@ impl<M: Mswi> MSWI<M> {
6363
///
6464
/// Enabling interrupts may break mask-based critical sections.
6565
#[inline]
66-
pub unsafe fn enable(&self) {
66+
pub unsafe fn enable(self) {
6767
mie::set_msoft();
6868
}
6969

7070
/// Disables machine software interrupts in the current HART.
7171
#[inline]
72-
pub fn disable(&self) {
72+
pub fn disable(self) {
7373
// SAFETY: it is safe to disable interrupts
7474
unsafe { mie::clear_msoft() };
7575
}
7676

7777
/// Returns the `MSIP` register for the HART which ID is `hart_id`.
7878
#[inline]
79-
pub fn msip<H: HartIdNumber>(&self, hart_id: H) -> MSIP {
79+
pub fn msip<H: HartIdNumber>(self, hart_id: H) -> MSIP {
8080
// SAFETY: `hart_id` is valid for the target
8181
unsafe { MSIP::new(self.as_ptr().add(hart_id.number()) as _) }
8282
}
@@ -88,7 +88,7 @@ impl<M: Mswi> MSWI<M> {
8888
/// This function determines the current HART ID by reading the `mhartid` CSR.
8989
/// Thus, it can only be used in M-mode. For S-mode, use [`MSWI::msip`] instead.
9090
#[inline]
91-
pub fn msip_mhartid(&self) -> MSIP {
91+
pub fn msip_mhartid(self) -> MSIP {
9292
let hart_id = mhartid::read();
9393
// SAFETY: `hart_id` is valid for the target and is the current hart
9494
unsafe { MSIP::new(self.as_ptr().add(hart_id) as _) }

riscv-peripheral/src/aclint/mtimer.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ impl<M: Mtimer> MTIMER<M> {
5252

5353
/// Returns the base address of the `MTIMECMP` registers.
5454
#[inline]
55-
const fn mtimecmp_as_ptr(&self) -> *const u64 {
55+
const fn mtimecmp_as_ptr(self) -> *const u64 {
5656
M::MTIMECMP_BASE as *const u64
5757
}
5858

5959
/// Returns `true` if a machine timer interrupt is pending.
6060
#[inline]
61-
pub fn is_interrupting(&self) -> bool {
61+
pub fn is_interrupting(self) -> bool {
6262
mip::read().mtimer()
6363
}
6464

6565
/// Returns `true` if machine timer interrupts are enabled.
6666
#[inline]
67-
pub fn is_enabled(&self) -> bool {
67+
pub fn is_enabled(self) -> bool {
6868
mie::read().mtimer()
6969
}
7070

@@ -74,27 +74,27 @@ impl<M: Mtimer> MTIMER<M> {
7474
///
7575
/// Enabling interrupts may break mask-based critical sections.
7676
#[inline]
77-
pub unsafe fn enable(&self) {
77+
pub unsafe fn enable(self) {
7878
mie::set_mtimer();
7979
}
8080

8181
/// Disables machine timer interrupts in the current HART.
8282
#[inline]
83-
pub fn disable(&self) {
83+
pub fn disable(self) {
8484
// SAFETY: it is safe to disable interrupts
8585
unsafe { mie::clear_mtimer() };
8686
}
8787

8888
/// Returns the `MTIME` register.
8989
#[inline]
90-
pub const fn mtime(&self) -> MTIME {
90+
pub const fn mtime(self) -> MTIME {
9191
// SAFETY: valid base address
9292
unsafe { MTIME::new(M::MTIME_BASE) }
9393
}
9494

9595
/// Returns the `MTIMECMP` register for the HART which ID is `hart_id`.
9696
#[inline]
97-
pub fn mtimecmp<H: HartIdNumber>(&self, hart_id: H) -> MTIMECMP {
97+
pub fn mtimecmp<H: HartIdNumber>(self, hart_id: H) -> MTIMECMP {
9898
// SAFETY: `hart_id` is valid for the target
9999
unsafe { MTIMECMP::new(self.mtimecmp_as_ptr().add(hart_id.number()) as _) }
100100
}
@@ -106,7 +106,7 @@ impl<M: Mtimer> MTIMER<M> {
106106
/// This function determines the current HART ID by reading the [`mhartid`] CSR.
107107
/// Thus, it can only be used in M-mode. For S-mode, use [`MTIMER::mtimecmp`] instead.
108108
#[inline]
109-
pub fn mtimecmp_mhartid(&self) -> MTIMECMP {
109+
pub fn mtimecmp_mhartid(self) -> MTIMECMP {
110110
let hart_id = mhartid::read();
111111
// SAFETY: `hart_id` is valid for the target and is the current hart
112112
unsafe { MTIMECMP::new(self.mtimecmp_as_ptr().add(hart_id) as _) }

riscv-peripheral/src/aclint/sswi.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ impl<S: Sswi> SSWI<S> {
3232

3333
/// Returns the base address of the `SSWI` device.
3434
#[inline]
35-
const fn as_ptr(&self) -> *const u32 {
35+
const fn as_ptr(self) -> *const u32 {
3636
S::BASE as *const u32
3737
}
3838

3939
/// Returns `true` if a supervisor software interrupt is pending.
4040
#[inline]
41-
pub fn is_interrupting() -> bool {
41+
pub fn is_interrupting(self) -> bool {
4242
sip::read().ssoft()
4343
}
4444

4545
/// Returns `true` if supervisor software interrupts are enabled.
4646
#[inline]
47-
pub fn is_enabled() -> bool {
47+
pub fn is_enabled(self) -> bool {
4848
sie::read().ssoft()
4949
}
5050

@@ -54,20 +54,20 @@ impl<S: Sswi> SSWI<S> {
5454
///
5555
/// Enabling interrupts may break mask-based critical sections.
5656
#[inline]
57-
pub unsafe fn enable() {
57+
pub unsafe fn enable(self) {
5858
sie::set_ssoft();
5959
}
6060

6161
/// Disables supervisor software interrupts in the current HART.
6262
#[inline]
63-
pub fn disable() {
63+
pub fn disable(self) {
6464
// SAFETY: it is safe to disable interrupts
6565
unsafe { sie::clear_ssoft() };
6666
}
6767

6868
/// Returns the `SETSSIP` register for the HART which ID is `hart_id`.
6969
#[inline]
70-
pub fn setssip<H: HartIdNumber>(&self, hart_id: H) -> SETSSIP {
70+
pub fn setssip<H: HartIdNumber>(self, hart_id: H) -> SETSSIP {
7171
// SAFETY: `hart_id` is valid for the target
7272
unsafe { SETSSIP::new(self.as_ptr().add(hart_id.number()) as _) }
7373
}

riscv-peripheral/src/plic.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ impl<P: Plic> PLIC<P> {
5555

5656
/// Returns `true` if a machine external interrupt is pending.
5757
#[inline]
58-
pub fn is_interrupting(&self) -> bool {
58+
pub fn is_interrupting(self) -> bool {
5959
mip::read().mext()
6060
}
6161

6262
/// Returns true if machine external interrupts are enabled.
6363
#[inline]
64-
pub fn is_enabled(&self) -> bool {
64+
pub fn is_enabled(self) -> bool {
6565
mie::read().mext()
6666
}
6767

@@ -71,13 +71,13 @@ impl<P: Plic> PLIC<P> {
7171
///
7272
/// Enabling the `PLIC` may break mask-based critical sections.
7373
#[inline]
74-
pub unsafe fn enable(&self) {
74+
pub unsafe fn enable(self) {
7575
mie::set_mext();
7676
}
7777

7878
/// Disables machine external interrupts to prevent the PLIC from triggering interrupts.
7979
#[inline]
80-
pub fn disable(&self) {
80+
pub fn disable(self) {
8181
// SAFETY: it is safe to disable interrupts
8282
unsafe { mie::clear_mext() };
8383
}
@@ -87,7 +87,7 @@ impl<P: Plic> PLIC<P> {
8787
/// This register allows to set the priority level of each interrupt source.
8888
/// The priority level of each interrupt source is shared among all the contexts.
8989
#[inline]
90-
pub const fn priorities(&self) -> priorities::PRIORITIES {
90+
pub const fn priorities(self) -> priorities::PRIORITIES {
9191
// SAFETY: valid address
9292
unsafe { priorities::PRIORITIES::new(P::BASE + Self::PRIORITIES_OFFSET) }
9393
}
@@ -96,14 +96,14 @@ impl<P: Plic> PLIC<P> {
9696
///
9797
/// This register allows to check if a particular interrupt source is pending.
9898
#[inline]
99-
pub const fn pendings(&self) -> pendings::PENDINGS {
99+
pub const fn pendings(self) -> pendings::PENDINGS {
100100
// SAFETY: valid address
101101
unsafe { pendings::PENDINGS::new(P::BASE + Self::PENDINGS_OFFSET) }
102102
}
103103

104104
/// Returns a proxy to access to all the PLIC registers of a given HART context.
105105
#[inline]
106-
pub fn ctx<H: HartIdNumber>(&self, hart_id: H) -> CTX<P> {
106+
pub fn ctx<H: HartIdNumber>(self, hart_id: H) -> CTX<P> {
107107
// SAFETY: valid context number
108108
unsafe { CTX::new(hart_id.number() as _) }
109109
}
@@ -115,7 +115,7 @@ impl<P: Plic> PLIC<P> {
115115
/// This function determines the current HART ID by reading the [`mhartid`] CSR.
116116
/// Thus, it can only be used in M-mode. For S-mode, use [`PLIC::ctx`] instead.
117117
#[inline]
118-
pub fn ctx_mhartid(&self) -> CTX<P> {
118+
pub fn ctx_mhartid(self) -> CTX<P> {
119119
let hart_id = mhartid::read();
120120
// SAFETY: `hart_id` is valid for the target and is the current hart
121121
unsafe { CTX::new(hart_id as _) }

0 commit comments

Comments
 (0)