1
1
//! UEFI services available at runtime, even after the OS boots.
2
2
3
- use super :: { Header , Revision } ;
3
+ use super :: Revision ;
4
4
use crate :: table:: boot:: MemoryDescriptor ;
5
- use crate :: { CStr16 , Char16 , Error , Guid , Result , Status , StatusExt } ;
6
- use core:: ffi:: c_void;
5
+ use crate :: { CStr16 , Error , Guid , Result , Status , StatusExt } ;
7
6
use core:: fmt:: { Debug , Formatter } ;
8
7
use core:: mem:: MaybeUninit ;
9
8
use core:: { fmt, ptr} ;
@@ -32,76 +31,21 @@ use {
32
31
///
33
32
/// [`SystemTable::runtime_services`]: crate::table::SystemTable::runtime_services
34
33
#[ repr( C ) ]
35
- pub struct RuntimeServices {
36
- header : Header ,
37
- get_time :
38
- unsafe extern "efiapi" fn ( time : * mut Time , capabilities : * mut TimeCapabilities ) -> Status ,
39
- set_time : unsafe extern "efiapi" fn ( time : & Time ) -> Status ,
40
- get_wakeup_time :
41
- unsafe extern "efiapi" fn ( enabled : * mut u8 , pending : * mut u8 , time : * mut Time ) -> Status ,
42
- set_wakeup_time : unsafe extern "efiapi" fn ( enable : u8 , time : * const Time ) -> Status ,
43
- pub ( crate ) set_virtual_address_map : unsafe extern "efiapi" fn (
44
- map_size : usize ,
45
- desc_size : usize ,
46
- desc_version : u32 ,
47
- virtual_map : * mut MemoryDescriptor ,
48
- ) -> Status ,
49
- convert_pointer :
50
- unsafe extern "efiapi" fn ( debug_disposition : usize , address : * mut * const c_void ) -> Status ,
51
- get_variable : unsafe extern "efiapi" fn (
52
- variable_name : * const Char16 ,
53
- vendor_guid : * const Guid ,
54
- attributes : * mut VariableAttributes ,
55
- data_size : * mut usize ,
56
- data : * mut u8 ,
57
- ) -> Status ,
58
- get_next_variable_name : unsafe extern "efiapi" fn (
59
- variable_name_size : * mut usize ,
60
- variable_name : * mut u16 ,
61
- vendor_guid : * mut Guid ,
62
- ) -> Status ,
63
- set_variable : unsafe extern "efiapi" fn (
64
- variable_name : * const Char16 ,
65
- vendor_guid : * const Guid ,
66
- attributes : VariableAttributes ,
67
- data_size : usize ,
68
- data : * const u8 ,
69
- ) -> Status ,
70
- get_next_high_monotonic_count : unsafe extern "efiapi" fn ( high_count : * mut u32 ) -> Status ,
71
- reset : unsafe extern "efiapi" fn (
72
- rt : ResetType ,
73
-
74
- status : Status ,
75
- data_size : usize ,
76
- data : * const u8 ,
77
- ) -> !,
78
-
79
- // UEFI 2.0 Capsule Services.
80
- update_capsule : usize ,
81
- query_capsule_capabilities : usize ,
82
-
83
- // Miscellaneous UEFI 2.0 Service.
84
- query_variable_info : unsafe extern "efiapi" fn (
85
- attributes : VariableAttributes ,
86
- maximum_variable_storage_size : * mut u64 ,
87
- remaining_variable_storage_size : * mut u64 ,
88
- maximum_variable_size : * mut u64 ,
89
- ) -> Status ,
90
- }
34
+ pub struct RuntimeServices ( uefi_raw:: table:: runtime:: RuntimeServices ) ;
91
35
92
36
impl RuntimeServices {
93
37
/// Query the current time and date information
94
38
pub fn get_time ( & self ) -> Result < Time > {
95
39
let mut time = MaybeUninit :: < Time > :: uninit ( ) ;
96
- unsafe { ( self . get_time ) ( time. as_mut_ptr ( ) , ptr:: null_mut ( ) ) }
40
+ unsafe { ( self . 0 . get_time ) ( time. as_mut_ptr ( ) . cast ( ) , ptr:: null_mut ( ) ) }
97
41
. to_result_with_val ( || unsafe { time. assume_init ( ) } )
98
42
}
99
43
100
44
/// Query the current time and date information and the RTC capabilities
101
45
pub fn get_time_and_caps ( & self ) -> Result < ( Time , TimeCapabilities ) > {
102
46
let mut time = MaybeUninit :: < Time > :: uninit ( ) ;
103
47
let mut caps = MaybeUninit :: < TimeCapabilities > :: uninit ( ) ;
104
- unsafe { ( self . get_time ) ( time. as_mut_ptr ( ) , caps. as_mut_ptr ( ) ) }
48
+ unsafe { ( self . 0 . get_time ) ( time. as_mut_ptr ( ) . cast ( ) , caps. as_mut_ptr ( ) ) }
105
49
. to_result_with_val ( || unsafe { ( time. assume_init ( ) , caps. assume_init ( ) ) } )
106
50
}
107
51
@@ -115,16 +59,17 @@ impl RuntimeServices {
115
59
/// Undefined behavior could happen if multiple tasks try to
116
60
/// use this function at the same time without synchronisation.
117
61
pub unsafe fn set_time ( & mut self , time : & Time ) -> Result {
118
- ( self . set_time ) ( time) . to_result ( )
62
+ let time: * const Time = time;
63
+ ( self . 0 . set_time ) ( time. cast ( ) ) . to_result ( )
119
64
}
120
65
121
66
/// Get the size (in bytes) of a variable. This can be used to find out how
122
67
/// big of a buffer should be passed in to `get_variable`.
123
68
pub fn get_variable_size ( & self , name : & CStr16 , vendor : & VariableVendor ) -> Result < usize > {
124
69
let mut data_size = 0 ;
125
70
let status = unsafe {
126
- ( self . get_variable ) (
127
- name. as_ptr ( ) ,
71
+ ( self . 0 . get_variable ) (
72
+ name. as_ptr ( ) . cast ( ) ,
128
73
& vendor. 0 ,
129
74
ptr:: null_mut ( ) ,
130
75
& mut data_size,
@@ -154,8 +99,8 @@ impl RuntimeServices {
154
99
let mut attributes = VariableAttributes :: empty ( ) ;
155
100
let mut data_size = buf. len ( ) ;
156
101
unsafe {
157
- ( self . get_variable ) (
158
- name. as_ptr ( ) ,
102
+ ( self . 0 . get_variable ) (
103
+ name. as_ptr ( ) . cast ( ) ,
159
104
& vendor. 0 ,
160
105
& mut attributes,
161
106
& mut data_size,
@@ -178,8 +123,8 @@ impl RuntimeServices {
178
123
let mut data = Vec :: with_capacity ( data_size) ;
179
124
180
125
let status = unsafe {
181
- ( self . get_variable ) (
182
- name. as_ptr ( ) ,
126
+ ( self . 0 . get_variable ) (
127
+ name. as_ptr ( ) . cast ( ) ,
183
128
& vendor. 0 ,
184
129
& mut attributes,
185
130
& mut data_size,
@@ -212,7 +157,7 @@ impl RuntimeServices {
212
157
loop {
213
158
let mut name_size_in_bytes = name. len ( ) * mem:: size_of :: < u16 > ( ) ;
214
159
status = unsafe {
215
- ( self . get_next_variable_name ) (
160
+ ( self . 0 . get_next_variable_name ) (
216
161
& mut name_size_in_bytes,
217
162
name. as_mut_ptr ( ) ,
218
163
& mut vendor,
@@ -275,8 +220,8 @@ impl RuntimeServices {
275
220
data : & [ u8 ] ,
276
221
) -> Result {
277
222
unsafe {
278
- ( self . set_variable ) (
279
- name. as_ptr ( ) ,
223
+ ( self . 0 . set_variable ) (
224
+ name. as_ptr ( ) . cast ( ) ,
280
225
& vendor. 0 ,
281
226
attributes,
282
227
data. len ( ) ,
@@ -302,13 +247,13 @@ impl RuntimeServices {
302
247
& self ,
303
248
attributes : VariableAttributes ,
304
249
) -> Result < VariableStorageInfo > {
305
- if self . header . revision < Revision :: EFI_2_00 {
250
+ if self . 0 . header . revision < Revision :: EFI_2_00 {
306
251
return Err ( Status :: UNSUPPORTED . into ( ) ) ;
307
252
}
308
253
309
254
let mut info = VariableStorageInfo :: default ( ) ;
310
255
unsafe {
311
- ( self . query_variable_info ) (
256
+ ( self . 0 . query_variable_info ) (
312
257
attributes,
313
258
& mut info. maximum_variable_storage_size ,
314
259
& mut info. remaining_variable_storage_size ,
@@ -331,7 +276,17 @@ impl RuntimeServices {
331
276
None => ( 0 , ptr:: null ( ) ) ,
332
277
} ;
333
278
334
- unsafe { ( self . reset ) ( rt, status, size, data) }
279
+ unsafe { ( self . 0 . reset_system ) ( rt, status, size, data) }
280
+ }
281
+
282
+ pub ( crate ) unsafe fn set_virtual_address_map (
283
+ & self ,
284
+ map_size : usize ,
285
+ desc_size : usize ,
286
+ desc_version : u32 ,
287
+ virtual_map : * mut MemoryDescriptor ,
288
+ ) -> Status {
289
+ ( self . 0 . set_virtual_address_map ) ( map_size, desc_size, desc_version, virtual_map)
335
290
}
336
291
}
337
292
@@ -342,14 +297,14 @@ impl super::Table for RuntimeServices {
342
297
impl Debug for RuntimeServices {
343
298
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
344
299
f. debug_struct ( "RuntimeServices" )
345
- . field ( "header" , & self . header )
346
- . field ( "get_time" , & ( self . get_time as * const u64 ) )
347
- . field ( "set_time" , & ( self . set_time as * const u64 ) )
300
+ . field ( "header" , & self . 0 . header )
301
+ . field ( "get_time" , & ( self . 0 . get_time as * const u64 ) )
302
+ . field ( "set_time" , & ( self . 0 . set_time as * const u64 ) )
348
303
. field (
349
304
"set_virtual_address_map" ,
350
- & ( self . set_virtual_address_map as * const u64 ) ,
305
+ & ( self . 0 . set_virtual_address_map as * const u64 ) ,
351
306
)
352
- . field ( "reset" , & ( self . reset as * const u64 ) )
307
+ . field ( "reset" , & ( self . 0 . reset_system as * const u64 ) )
353
308
. finish ( )
354
309
}
355
310
}
0 commit comments