1
1
#![ allow( dead_code) ]
2
2
3
+ use rustsbi:: { HartMask , Ipi , Timer } ;
3
4
// 这部分其实是运行时提供的,不应该做到实现库里面
4
5
use rustsbi:: SbiRet ;
5
6
@@ -8,33 +9,38 @@ pub struct Clint {
8
9
}
9
10
10
11
impl Clint {
12
+ #[ inline]
11
13
pub fn new ( base : * mut u8 ) -> Clint {
12
14
Clint {
13
15
base : base as usize ,
14
16
}
15
17
}
16
18
19
+ #[ inline]
17
20
pub fn get_mtime ( & self ) -> u64 {
18
21
unsafe {
19
22
let base = self . base as * mut u8 ;
20
23
core:: ptr:: read_volatile ( base. add ( 0xbff8 ) as * mut u64 )
21
24
}
22
25
}
23
26
27
+ #[ inline]
24
28
pub fn set_timer ( & self , hart_id : usize , instant : u64 ) {
25
29
unsafe {
26
30
let base = self . base as * mut u8 ;
27
31
core:: ptr:: write_volatile ( ( base. offset ( 0x4000 ) as * mut u64 ) . add ( hart_id) , instant) ;
28
32
}
29
33
}
30
34
35
+ #[ inline]
31
36
pub fn send_soft ( & self , hart_id : usize ) {
32
37
unsafe {
33
38
let base = self . base as * mut u8 ;
34
39
core:: ptr:: write_volatile ( ( base as * mut u32 ) . add ( hart_id) , 1 ) ;
35
40
}
36
41
}
37
42
43
+ #[ inline]
38
44
pub fn clear_soft ( & self , hart_id : usize ) {
39
45
unsafe {
40
46
let base = self . base as * mut u8 ;
@@ -43,14 +49,14 @@ impl Clint {
43
49
}
44
50
}
45
51
46
- use rustsbi:: { HartMask , Ipi , Timer } ;
47
-
48
52
impl Ipi for Clint {
53
+ #[ inline]
49
54
fn max_hart_id ( & self ) -> usize {
50
55
// 这个值将在初始化的时候加载,会从dtb_pa读取设备树,然后数里面有几个核
51
56
* crate :: count_harts:: MAX_HART_ID . lock ( )
52
57
}
53
58
59
+ #[ inline]
54
60
fn send_ipi_many ( & self , hart_mask : HartMask ) -> SbiRet {
55
61
// println!("[rustsbi] send ipi many, {:?}", hart_mask);
56
62
for i in 0 ..=self . max_hart_id ( ) {
@@ -63,6 +69,7 @@ impl Ipi for Clint {
63
69
}
64
70
65
71
impl Timer for Clint {
72
+ #[ inline]
66
73
fn set_timer ( & self , time_value : u64 ) {
67
74
let this_mhartid = riscv:: register:: mhartid:: read ( ) ;
68
75
self . set_timer ( this_mhartid, time_value) ;
0 commit comments