@@ -4,51 +4,49 @@ use core::ptr::{self, NonNull};
44use core:: mem;
55use uefi:: proto:: unsafe_protocol;
66use uefi:: table:: boot:: {
7- BootServices , EventType , MemoryType , OpenProtocolAttributes , OpenProtocolParams , SearchType ,
8- TimerTrigger , Tpl ,
7+ EventType , MemoryType , OpenProtocolAttributes , OpenProtocolParams , SearchType , TimerTrigger ,
8+ Tpl ,
99} ;
10- use uefi:: table :: { Boot , SystemTable } ;
10+ use uefi:: { boot , system } ;
1111use uefi:: { guid, Event , Guid , Identify } ;
1212
13- pub fn test ( st : & SystemTable < Boot > ) {
14- let bt = st. boot_services ( ) ;
13+ pub fn test ( ) {
1514 info ! ( "Testing timer..." ) ;
16- test_timer ( bt ) ;
15+ test_timer ( ) ;
1716 info ! ( "Testing events..." ) ;
18- test_event_callback ( bt ) ;
19- test_callback_with_ctx ( bt ) ;
17+ test_event_callback ( ) ;
18+ test_callback_with_ctx ( ) ;
2019 info ! ( "Testing watchdog..." ) ;
21- test_watchdog ( bt ) ;
20+ test_watchdog ( ) ;
2221 info ! ( "Testing protocol handler services..." ) ;
23- test_register_protocol_notify ( bt ) ;
24- test_install_protocol_interface ( bt ) ;
25- test_reinstall_protocol_interface ( bt ) ;
26- test_uninstall_protocol_interface ( bt ) ;
27- test_install_configuration_table ( st ) ;
22+ test_register_protocol_notify ( ) ;
23+ test_install_protocol_interface ( ) ;
24+ test_reinstall_protocol_interface ( ) ;
25+ test_uninstall_protocol_interface ( ) ;
26+ test_install_configuration_table ( ) ;
2827}
2928
30- fn test_timer ( bt : & BootServices ) {
31- let timer_event = unsafe { bt . create_event ( EventType :: TIMER , Tpl :: APPLICATION , None , None ) }
29+ fn test_timer ( ) {
30+ let timer_event = unsafe { boot :: create_event ( EventType :: TIMER , Tpl :: APPLICATION , None , None ) }
3231 . expect ( "Failed to create TIMER event" ) ;
3332 let mut events = unsafe { [ timer_event. unsafe_clone ( ) ] } ;
34- bt . set_timer ( & timer_event, TimerTrigger :: Relative ( 5_0 /*00 ns */ ) )
33+ boot :: set_timer ( & timer_event, TimerTrigger :: Relative ( 5_0 /*00 ns */ ) )
3534 . expect ( "Failed to set timer" ) ;
36- bt. wait_for_event ( & mut events)
37- . expect ( "Wait for event failed" ) ;
35+ boot:: wait_for_event ( & mut events) . expect ( "Wait for event failed" ) ;
3836}
3937
40- fn test_event_callback ( bt : & BootServices ) {
38+ fn test_event_callback ( ) {
4139 extern "efiapi" fn callback ( _event : Event , _ctx : Option < NonNull < c_void > > ) {
4240 info ! ( "Inside the event callback" ) ;
4341 }
4442
4543 let event =
46- unsafe { bt . create_event ( EventType :: NOTIFY_WAIT , Tpl :: CALLBACK , Some ( callback) , None ) }
44+ unsafe { boot :: create_event ( EventType :: NOTIFY_WAIT , Tpl :: CALLBACK , Some ( callback) , None ) }
4745 . expect ( "Failed to create custom event" ) ;
48- bt . check_event ( event) . expect ( "Failed to check event" ) ;
46+ boot :: check_event ( event) . expect ( "Failed to check event" ) ;
4947}
5048
51- fn test_callback_with_ctx ( bt : & BootServices ) {
49+ fn test_callback_with_ctx ( ) {
5250 let mut data = 123u32 ;
5351
5452 extern "efiapi" fn callback ( _event : Event , ctx : Option < NonNull < c_void > > ) {
@@ -65,7 +63,7 @@ fn test_callback_with_ctx(bt: &BootServices) {
6563 let ctx = NonNull :: new ( ctx. cast :: < c_void > ( ) ) . unwrap ( ) ;
6664
6765 let event = unsafe {
68- bt . create_event (
66+ boot :: create_event (
6967 EventType :: NOTIFY_WAIT ,
7068 Tpl :: CALLBACK ,
7169 Some ( callback) ,
@@ -74,16 +72,15 @@ fn test_callback_with_ctx(bt: &BootServices) {
7472 . expect ( "Failed to create event with context" )
7573 } ;
7674
77- bt . check_event ( event) . expect ( "Failed to check event" ) ;
75+ boot :: check_event ( event) . expect ( "Failed to check event" ) ;
7876
7977 // Check that `data` was updated inside the event callback.
8078 assert_eq ! ( data, 456 ) ;
8179}
8280
83- fn test_watchdog ( bt : & BootServices ) {
81+ fn test_watchdog ( ) {
8482 // Disable the UEFI watchdog timer
85- bt. set_watchdog_timer ( 0 , 0x10000 , None )
86- . expect ( "Could not set watchdog timer" ) ;
83+ boot:: set_watchdog_timer ( 0 , 0x10000 , None ) . expect ( "Could not set watchdog timer" ) ;
8784}
8885
8986/// Dummy protocol for tests
@@ -96,10 +93,10 @@ unsafe extern "efiapi" fn _test_notify(_event: Event, _context: Option<NonNull<c
9693 info ! ( "Protocol was (re)installed and this function notified." )
9794}
9895
99- fn test_register_protocol_notify ( bt : & BootServices ) {
96+ fn test_register_protocol_notify ( ) {
10097 let protocol = & TestProtocol :: GUID ;
10198 let event = unsafe {
102- bt . create_event (
99+ boot :: create_event (
103100 EventType :: NOTIFY_SIGNAL ,
104101 Tpl :: NOTIFY ,
105102 Some ( _test_notify) ,
@@ -108,41 +105,37 @@ fn test_register_protocol_notify(bt: &BootServices) {
108105 . expect ( "Failed to create an event" )
109106 } ;
110107
111- bt. register_protocol_notify ( protocol, event)
112- . expect ( "Failed to register protocol notify fn" ) ;
108+ boot:: register_protocol_notify ( protocol, event) . expect ( "Failed to register protocol notify fn" ) ;
113109}
114110
115- fn test_install_protocol_interface ( bt : & BootServices ) {
111+ fn test_install_protocol_interface ( ) {
116112 info ! ( "Installing TestProtocol" ) ;
117113
118- let alloc: * mut TestProtocol = bt
119- . allocate_pool (
120- MemoryType :: BOOT_SERVICES_DATA ,
121- mem:: size_of :: < TestProtocol > ( ) ,
122- )
123- . unwrap ( )
124- . cast ( )
125- . as_ptr ( ) ;
114+ let alloc: * mut TestProtocol = boot:: allocate_pool (
115+ MemoryType :: BOOT_SERVICES_DATA ,
116+ mem:: size_of :: < TestProtocol > ( ) ,
117+ )
118+ . unwrap ( )
119+ . as_ptr ( )
120+ . cast ( ) ;
126121 unsafe { alloc. write ( TestProtocol { data : 123 } ) } ;
127122
128123 let _ = unsafe {
129- bt . install_protocol_interface ( None , & TestProtocol :: GUID , alloc. cast ( ) )
124+ boot :: install_protocol_interface ( None , & TestProtocol :: GUID , alloc. cast ( ) )
130125 . expect ( "Failed to install protocol interface" )
131126 } ;
132127
133- let _ = bt
134- . locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
128+ let _ = boot:: locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
135129 . expect ( "Failed to find protocol after it was installed" ) ;
136130}
137131
138- fn test_reinstall_protocol_interface ( bt : & BootServices ) {
132+ fn test_reinstall_protocol_interface ( ) {
139133 info ! ( "Reinstalling TestProtocol" ) ;
140- let handle = bt
141- . locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
134+ let handle = boot:: locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
142135 . expect ( "Failed to find protocol to uninstall" ) [ 0 ] ;
143136
144137 unsafe {
145- let _ = bt . reinstall_protocol_interface (
138+ let _ = boot :: reinstall_protocol_interface (
146139 handle,
147140 & TestProtocol :: GUID ,
148141 ptr:: null_mut ( ) ,
@@ -151,61 +144,57 @@ fn test_reinstall_protocol_interface(bt: &BootServices) {
151144 }
152145}
153146
154- fn test_uninstall_protocol_interface ( bt : & BootServices ) {
147+ fn test_uninstall_protocol_interface ( ) {
155148 info ! ( "Uninstalling TestProtocol" ) ;
156149
157- let handle = bt
158- . locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
150+ let handle = boot:: locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
159151 . expect ( "Failed to find protocol to uninstall" ) [ 0 ] ;
160152
161153 unsafe {
162154 // Uninstalling a protocol interface requires knowing the interface
163155 // pointer. Open the protocol to get that pointer, making sure to drop
164156 // the `ScopedProtocol` _before_ uninstalling the protocol interface.
165157 let interface_ptr: * mut TestProtocol = {
166- let mut sp = bt
167- . open_protocol :: < TestProtocol > (
168- OpenProtocolParams {
169- handle,
170- agent : bt. image_handle ( ) ,
171- controller : None ,
172- } ,
173- OpenProtocolAttributes :: GetProtocol ,
174- )
175- . unwrap ( ) ;
158+ let mut sp = boot:: open_protocol :: < TestProtocol > (
159+ OpenProtocolParams {
160+ handle,
161+ agent : boot:: image_handle ( ) ,
162+ controller : None ,
163+ } ,
164+ OpenProtocolAttributes :: GetProtocol ,
165+ )
166+ . unwrap ( ) ;
176167 assert_eq ! ( sp. data, 123 ) ;
177168 & mut * sp
178169 } ;
179170
180- bt . uninstall_protocol_interface ( handle, & TestProtocol :: GUID , interface_ptr. cast ( ) )
171+ boot :: uninstall_protocol_interface ( handle, & TestProtocol :: GUID , interface_ptr. cast ( ) )
181172 . expect ( "Failed to uninstall protocol interface" ) ;
182173
183- bt . free_pool ( interface_ptr. cast ( ) ) . unwrap ( ) ;
174+ boot :: free_pool ( interface_ptr. cast ( ) ) . unwrap ( ) ;
184175 }
185176}
186177
187- fn test_install_configuration_table ( st : & SystemTable < Boot > ) {
188- let config = st
189- . boot_services ( )
190- . allocate_pool ( MemoryType :: ACPI_RECLAIM , 1 )
178+ fn test_install_configuration_table ( ) {
179+ let config = boot:: allocate_pool ( MemoryType :: ACPI_RECLAIM , 1 )
191180 . expect ( "Failed to allocate config table" )
192181 . as_ptr ( ) ;
193182 unsafe { config. write ( 42 ) } ;
194183
195- let count = st . config_table ( ) . len ( ) ;
184+ let count = system :: with_config_table ( |t| t . len ( ) ) ;
196185 const ID : Guid = guid ! ( "3bdb3089-5662-42df-840e-3922ed6467c9" ) ;
197186
198187 unsafe {
199- st. boot_services ( )
200- . install_configuration_table ( & ID , config. cast ( ) )
188+ boot:: install_configuration_table ( & ID , config. cast ( ) )
201189 . expect ( "Failed to install configuration table" ) ;
202190 }
203191
204- assert_eq ! ( count + 1 , st. config_table( ) . len( ) ) ;
205- let config_entry = st
206- . config_table ( )
207- . iter ( )
208- . find ( |ct| ct. guid == ID )
209- . expect ( "Failed to find test config table" ) ;
210- assert_eq ! ( unsafe { * ( config_entry. address as * const u8 ) } , 42 ) ;
192+ assert_eq ! ( count + 1 , system:: with_config_table( |t| t. len( ) ) ) ;
193+ let entry_addr = system:: with_config_table ( |t| {
194+ t. iter ( )
195+ . find ( |ct| ct. guid == ID )
196+ . expect ( "Failed to find test config table" )
197+ . address
198+ } ) ;
199+ assert_eq ! ( unsafe { * ( entry_addr as * const u8 ) } , 42 ) ;
211200}
0 commit comments