|
1 | 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
2 | 2 |
|
3 | 3 | use uefi::boot::{self, OpenProtocolParams}; |
| 4 | +use uefi::proto::device_path::DevicePath; |
| 5 | +use uefi::proto::driver::ComponentName2; |
4 | 6 | use uefi::proto::loaded_image::LoadedImage; |
5 | 7 | use uefi::{Identify, proto}; |
6 | 8 |
|
@@ -44,6 +46,9 @@ pub fn test() { |
44 | 46 | shim::test(); |
45 | 47 | shell::test(); |
46 | 48 | tcg::test(); |
| 49 | + |
| 50 | + // now test some convenience that combines several things |
| 51 | + test_handle_convenience(); |
47 | 52 | } |
48 | 53 |
|
49 | 54 | fn find_protocol() { |
@@ -74,6 +79,36 @@ fn test_test_protocol() { |
74 | 79 | ); |
75 | 80 | } |
76 | 81 |
|
| 82 | +fn test_handle_convenience() { |
| 83 | + // Handles that implement the following protocols: |
| 84 | + // - component name 2 |
| 85 | + // - device path |
| 86 | + let handles = { |
| 87 | + let mut cn2_handles = boot::find_handles::<ComponentName2>().unwrap(); |
| 88 | + let dvp_handles = boot::find_handles::<DevicePath>().unwrap(); |
| 89 | + |
| 90 | + cn2_handles.retain(|x| dvp_handles.contains(x)); |
| 91 | + cn2_handles |
| 92 | + }; |
| 93 | + for handle in handles { |
| 94 | + let dvp = handle |
| 95 | + .device_path() |
| 96 | + .expect("should succeed to query protocol") |
| 97 | + .expect("should have device path"); |
| 98 | + let cn2 = handle |
| 99 | + .component_name2() |
| 100 | + .expect("should succeed to query protocol") |
| 101 | + .expect("should have component name (v2)"); |
| 102 | + info!("handle: {:x?}", handle); |
| 103 | + info!("|- dvp: {dvp}"); |
| 104 | + info!("|- cn2 driver: {}", cn2.driver_name("en").unwrap()); |
| 105 | + info!( |
| 106 | + "|- cn2 controller: {}", |
| 107 | + cn2.controller_name(handle, None, "en").unwrap() |
| 108 | + ); |
| 109 | + } |
| 110 | +} |
| 111 | + |
77 | 112 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
78 | 113 | mod ata; |
79 | 114 | mod console; |
|
0 commit comments