@@ -11,7 +11,8 @@ use core::ops::{Deref, DerefMut};
11
11
use core:: ptr:: { self , NonNull } ;
12
12
use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
13
13
use core:: { mem, slice} ;
14
- use uefi:: { table, Char16 , Event , Handle , Result , Status , StatusExt } ;
14
+ use uefi:: { table, Char16 , Event , Guid , Handle , Result , Status , StatusExt } ;
15
+ use uefi_raw:: table:: boot:: InterfaceType ;
15
16
16
17
#[ cfg( doc) ]
17
18
use {
@@ -299,6 +300,39 @@ pub fn disconnect_controller(
299
300
. to_result_with_err ( |_| ( ) )
300
301
}
301
302
303
+ /// Installs a protocol interface on a device handle.
304
+ ///
305
+ /// When a protocol interface is installed, firmware will call all functions
306
+ /// that have registered to wait for that interface to be installed.
307
+ ///
308
+ /// If `handle` is `None`, a new handle will be created and returned.
309
+ ///
310
+ /// # Safety
311
+ ///
312
+ /// The caller is responsible for ensuring that they pass a valid `Guid` for `protocol`.
313
+ ///
314
+ /// # Errors
315
+ ///
316
+ /// * [`Status::OUT_OF_RESOURCES`]: failed to allocate a new handle.
317
+ /// * [`Status::INVALID_PARAMETER`]: this protocol is already installed on the handle.
318
+ pub unsafe fn install_protocol_interface (
319
+ handle : Option < Handle > ,
320
+ protocol : & Guid ,
321
+ interface : * const c_void ,
322
+ ) -> Result < Handle > {
323
+ let bt = boot_services_raw_panicking ( ) ;
324
+ let bt = unsafe { bt. as_ref ( ) } ;
325
+
326
+ let mut handle = Handle :: opt_to_ptr ( handle) ;
327
+ ( ( bt. install_protocol_interface ) (
328
+ & mut handle,
329
+ protocol,
330
+ InterfaceType :: NATIVE_INTERFACE ,
331
+ interface,
332
+ ) )
333
+ . to_result_with_val ( || Handle :: from_ptr ( handle) . unwrap ( ) )
334
+ }
335
+
302
336
/// Returns an array of handles that support the requested protocol in a
303
337
/// pool-allocated buffer.
304
338
///
0 commit comments