1
+ use alloc:: sync:: Arc ;
2
+
1
3
use crate :: acpi:: fadt;
2
4
use crate :: acpi:: get_acpi_table;
3
5
4
6
use crate :: mem:: paging:: PhysAddr ;
5
7
8
+ use crate :: userland:: scheduler;
9
+ use crate :: utils:: io;
10
+
6
11
struct LaiHost ;
7
12
8
13
impl lai:: Host for LaiHost {
@@ -25,16 +30,55 @@ impl lai::Host for LaiHost {
25
30
}
26
31
. unwrap_or ( core:: ptr:: null ( ) )
27
32
}
33
+
34
+ fn sleep ( & self , ms : u64 ) {
35
+ scheduler:: get_scheduler ( )
36
+ . inner
37
+ . sleep ( Some ( ms as usize * 1_000_000 ) )
38
+ . expect ( "lai: unexpected signal during sleep" )
39
+ }
40
+
41
+ // Port I/O functions:
42
+ #[ inline]
43
+ fn outb ( & self , port : u16 , value : u8 ) {
44
+ unsafe { io:: outb ( port, value) }
45
+ }
46
+
47
+ #[ inline]
48
+ fn outw ( & self , port : u16 , value : u16 ) {
49
+ unsafe { io:: outw ( port, value) }
50
+ }
51
+
52
+ #[ inline]
53
+ fn outd ( & self , port : u16 , value : u32 ) {
54
+ unsafe { io:: outl ( port, value) }
55
+ }
56
+
57
+ #[ inline]
58
+ fn inb ( & self , port : u16 ) -> u8 {
59
+ unsafe { io:: inb ( port) }
60
+ }
61
+
62
+ #[ inline]
63
+ fn inw ( & self , port : u16 ) -> u16 {
64
+ unsafe { io:: inw ( port) }
65
+ }
66
+
67
+ #[ inline]
68
+ fn ind ( & self , port : u16 ) -> u32 {
69
+ unsafe { io:: inl ( port) }
70
+ }
28
71
}
29
72
30
73
pub fn init_lai ( ) {
31
- let lai_host = box LaiHost ;
74
+ let lai_host = Arc :: new ( LaiHost ) ;
32
75
lai:: init ( lai_host) ;
33
76
34
- unsafe {
35
- lai:: lai_set_acpi_revision ( get_acpi_table ( ) . revision ( ) as _ ) ;
36
- lai:: lai_create_namespace ( ) ;
37
- }
77
+ lai:: set_acpi_revision ( get_acpi_table ( ) . revision ( ) as _ ) ;
78
+ lai:: create_namespace ( ) ;
79
+
80
+ lai:: enable_acpi ( 1 ) ;
81
+ lai:: enter_sleep ( 5 ) ;
38
82
}
39
83
40
84
crate :: module_init!( init_lai) ;
0 commit comments