|
| 1 | +use crate::firmware_storage::FirmwareVolumeAttributes; |
| 2 | +use crate::protocol::block::Lba; |
| 3 | +use crate::{guid, Guid, Handle, PhysicalAddress, Status}; |
| 4 | +use core::ffi::c_void; |
| 5 | +use core::ops::RangeInclusive; |
| 6 | + |
| 7 | +bitflags::bitflags! { |
| 8 | + /// EFI_FV_ATTRIBUTES |
| 9 | + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| 10 | + #[repr(transparent)] |
| 11 | + pub struct FvAttributes: u64 { |
| 12 | + const READ_DISABLE_CAP = 1 << 0; |
| 13 | + const READ_ENABLE_CAP = 1 << 1; |
| 14 | + const READ_STATUS = 1 << 2; |
| 15 | + |
| 16 | + const WRITE_DISABLE_CAP = 1 << 3; |
| 17 | + const WRITE_ENABLE_CAP = 1 << 4; |
| 18 | + const WRITE_STATUS = 1 << 5; |
| 19 | + |
| 20 | + const LOCK_CAP = 1 << 6; |
| 21 | + const LOCK_STATUS = 1 << 7; |
| 22 | + const WRITE_POLICY_RELIABLE = 1 << 8; |
| 23 | + const READ_LOCK_CAP = 1 << 12; |
| 24 | + const READ_LOCK_STATUS = 1 << 13; |
| 25 | + const WRITE_LOCK_CAP = 1 << 14; |
| 26 | + const WRITE_LOCK_STATUS = 1 << 15; |
| 27 | + |
| 28 | + const ALIGNMENT = 0x1F << 16; |
| 29 | + const ALIGNMENT_1 = 0x00 << 16; |
| 30 | + const ALIGNMENT_2 = 0x01 << 16; |
| 31 | + const ALIGNMENT_4 = 0x02 << 16; |
| 32 | + const ALIGNMENT_8 = 0x03 << 16; |
| 33 | + const ALIGNMENT_16 = 0x04 << 16; |
| 34 | + const ALIGNMENT_32 = 0x05 << 16; |
| 35 | + const ALIGNMENT_64 = 0x06 << 16; |
| 36 | + const ALIGNMENT_128 = 0x07 << 16; |
| 37 | + const ALIGNMENT_256 = 0x08 << 16; |
| 38 | + const ALIGNMENT_512 = 0x09 << 16; |
| 39 | + const ALIGNMENT_1K = 0x0A << 16; |
| 40 | + const ALIGNMENT_2K = 0x0B << 16; |
| 41 | + const ALIGNMENT_4K = 0x0C << 16; |
| 42 | + const ALIGNMENT_8K = 0x0D << 16; |
| 43 | + const ALIGNMENT_16K = 0x0E << 16; |
| 44 | + const ALIGNMENT_32K = 0x0F << 16; |
| 45 | + const ALIGNMENT_64K = 0x10 << 16; |
| 46 | + const ALIGNMENT_128K = 0x11 << 16; |
| 47 | + const ALIGNMENT_256K = 0x12 << 16; |
| 48 | + const ALIGNMENT_512K = 0x13 << 16; |
| 49 | + const ALIGNMENT_1M = 0x14 << 16; |
| 50 | + const ALIGNMENT_2M = 0x15 << 16; |
| 51 | + const ALIGNMENT_4M = 0x16 << 16; |
| 52 | + const ALIGNMENT_8M = 0x17 << 16; |
| 53 | + const ALIGNMENT_16M = 0x18 << 16; |
| 54 | + const ALIGNMENT_32M = 0x19 << 16; |
| 55 | + const ALIGNMENT_64M = 0x1A << 16; |
| 56 | + const ALIGNMENT_128M = 0x1B << 16; |
| 57 | + const ALIGNMENT_256M = 0x1C << 16; |
| 58 | + const ALIGNMENT_512M = 0x1D << 16; |
| 59 | + const ALIGNMENT_1G = 0x1E << 16; |
| 60 | + const ALIGNMENT_2G = 0x1F << 16; |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +bitflags::bitflags! { |
| 65 | + /// EFI_FV_FILE_ATTRIBUTES |
| 66 | + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] |
| 67 | + #[repr(transparent)] |
| 68 | + pub struct FvFileAttributes: u32 { |
| 69 | + const ALIGNMENT = 0x1F; |
| 70 | + const FIXED = 1 << 8; |
| 71 | + const MEMORY_MAPPED = 1 << 9; |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +newtype_enum! { |
| 76 | + /// EFI_FV_WRITE_POLICY |
| 77 | + pub enum FvWritePolicy: u32 => { |
| 78 | + EFI_FV_UNRELIABLE_WRITE = 0, |
| 79 | + EFI_FV_RELIABLE_WRITE = 1, |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +newtype_enum! { |
| 84 | + /// EFI_FV_FILETYPE |
| 85 | + pub enum FvFiletype: u8 => { |
| 86 | + ALL = 0x00, |
| 87 | + RAW = 0x01, |
| 88 | + FREEFORM = 0x02, |
| 89 | + SECURITY_CORE = 0x03, |
| 90 | + PEI_CORE = 0x04, |
| 91 | + DXE_CORE = 0x05, |
| 92 | + PEIM = 0x06, |
| 93 | + DRIVER = 0x07, |
| 94 | + COMBINED_PEIM_DRIVER = 0x08, |
| 95 | + APPLICATION = 0x09, |
| 96 | + MM = 0x0A, |
| 97 | + FIRMWARE_VOLUME_IMAGE = 0x0B, |
| 98 | + COMBINED_MM_DXE = 0x0C, |
| 99 | + MM_CORE = 0x0D, |
| 100 | + MM_STANDALONE = 0x0E, |
| 101 | + MM_CORE_STANDALONE = 0x0F, |
| 102 | + FFS_PAD = 0xF0, |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +impl FvFiletype { |
| 107 | + pub const OEM_RANGE: RangeInclusive<u8> = 0xC0..=0xDF; |
| 108 | + pub const DEBUG_RANGE: RangeInclusive<u8> = 0xE0..=0xEF; |
| 109 | + pub const FFS_RANGE: RangeInclusive<u8> = 0xF0..=0xFF; |
| 110 | +} |
| 111 | + |
| 112 | +newtype_enum! { |
| 113 | + /// EFI_SECTION_TYPE |
| 114 | + pub enum SectionType: u8 => { |
| 115 | + ALL = 0x00, |
| 116 | + COMPRESSION = 0x01, |
| 117 | + GUID_DEFINED = 0x02, |
| 118 | + DISPOSABLE = 0x03, |
| 119 | + PE32 = 0x10, |
| 120 | + PIC = 0x11, |
| 121 | + TE = 0x12, |
| 122 | + DXE_DEPEX = 0x13, |
| 123 | + VERSION = 0x14, |
| 124 | + USER_INTERFACE = 0x15, |
| 125 | + COMPATIBILITY16 = 0x16, |
| 126 | + FIRMWARE_VOLUME_IMAGE = 0x17, |
| 127 | + FREEFORM_SUBTYPE_GUID = 0x18, |
| 128 | + RAW = 0x19, |
| 129 | + PEI_DEPEX = 0x1B, |
| 130 | + MM_DEPEX = 0x1C, |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +/// EFI_FV_WRITE_FILE_DATA |
| 135 | +#[derive(Debug)] |
| 136 | +#[repr(C)] |
| 137 | +pub struct FvWriteFileData { |
| 138 | + pub name_guid: *const Guid, |
| 139 | + pub r#type: FvFiletype, |
| 140 | + pub file_attributes: FvFileAttributes, |
| 141 | + pub buffer: *const u8, |
| 142 | + pub buffer_size: u32, |
| 143 | +} |
| 144 | + |
| 145 | +/// EFI_FIRMWARE_VOLUME2_PROTOCOL |
| 146 | +#[derive(Debug)] |
| 147 | +#[repr(C)] |
| 148 | +pub struct FirmwareVolume2Protocol { |
| 149 | + pub get_volume_attributes: |
| 150 | + unsafe extern "efiapi" fn(this: *const Self, fv_attributes: *mut FvAttributes) -> Status, |
| 151 | + pub set_volume_attributes: |
| 152 | + unsafe extern "efiapi" fn(this: *const Self, fv_attributes: *mut FvAttributes) -> Status, |
| 153 | + pub read_file: unsafe extern "efiapi" fn( |
| 154 | + this: *const Self, |
| 155 | + name_guid: *const Guid, |
| 156 | + buffer: *mut *mut c_void, |
| 157 | + buffer_size: *mut usize, |
| 158 | + found_type: *mut FvFiletype, |
| 159 | + file_attributes: *mut FvFileAttributes, |
| 160 | + authentication_status: *mut u32, |
| 161 | + ) -> Status, |
| 162 | + pub read_section: unsafe extern "efiapi" fn( |
| 163 | + this: *const Self, |
| 164 | + name_guid: *const Guid, |
| 165 | + section_type: SectionType, |
| 166 | + section_instance: usize, |
| 167 | + buffer: *mut *mut c_void, |
| 168 | + buffer_size: *mut usize, |
| 169 | + authentication_status: *mut u32, |
| 170 | + ) -> Status, |
| 171 | + pub write_file: unsafe extern "efiapi" fn( |
| 172 | + this: *const Self, |
| 173 | + number_of_files: u32, |
| 174 | + write_policy: FvWritePolicy, |
| 175 | + file_data: *const FvWriteFileData, |
| 176 | + ) -> Status, |
| 177 | + pub get_next_file: unsafe extern "efiapi" fn( |
| 178 | + this: *const Self, |
| 179 | + key: *mut c_void, |
| 180 | + file_type: *mut FvFiletype, |
| 181 | + name_guid: *mut Guid, |
| 182 | + attributes: *mut FvFileAttributes, |
| 183 | + size: *mut usize, |
| 184 | + ) -> Status, |
| 185 | + pub key_size: u32, |
| 186 | + pub parent_handle: Handle, |
| 187 | + pub get_info: unsafe extern "efiapi" fn( |
| 188 | + this: *const Self, |
| 189 | + information_type: *const Guid, |
| 190 | + buffer_size: *mut usize, |
| 191 | + buffer: *mut c_void, |
| 192 | + ) -> Status, |
| 193 | + pub set_info: unsafe extern "efiapi" fn( |
| 194 | + this: *const Self, |
| 195 | + information_type: *const Guid, |
| 196 | + buffer_size: usize, |
| 197 | + buffer: *const c_void, |
| 198 | + ) -> Status, |
| 199 | +} |
| 200 | + |
| 201 | +impl FirmwareVolume2Protocol { |
| 202 | + pub const GUID: Guid = guid!("220e73b6-6bdb-4413-8405-b974b108619a"); |
| 203 | +} |
| 204 | + |
| 205 | +/// EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL |
| 206 | +#[derive(Debug)] |
| 207 | +#[repr(C)] |
| 208 | +pub struct FirmwareVolumeBlock2Protocol { |
| 209 | + pub get_attributes: unsafe extern "efiapi" fn( |
| 210 | + this: *const Self, |
| 211 | + attributes: *mut FirmwareVolumeAttributes, |
| 212 | + ) -> Status, |
| 213 | + pub set_attributes: unsafe extern "efiapi" fn( |
| 214 | + this: *const Self, |
| 215 | + attributes: *mut FirmwareVolumeAttributes, |
| 216 | + ) -> Status, |
| 217 | + pub get_physical_address: |
| 218 | + unsafe extern "efiapi" fn(this: *const Self, address: *mut PhysicalAddress) -> Status, |
| 219 | + pub get_block_size: unsafe extern "efiapi" fn( |
| 220 | + this: *const Self, |
| 221 | + lba: Lba, |
| 222 | + block_size: *mut usize, |
| 223 | + number_of_blocks: *mut usize, |
| 224 | + ) -> Status, |
| 225 | + pub read: unsafe extern "efiapi" fn( |
| 226 | + this: *const Self, |
| 227 | + lba: Lba, |
| 228 | + offset: usize, |
| 229 | + num_bytes: *mut usize, |
| 230 | + buffer: *mut u8, |
| 231 | + ) -> Status, |
| 232 | + pub write: unsafe extern "efiapi" fn( |
| 233 | + this: *const Self, |
| 234 | + lba: Lba, |
| 235 | + offset: usize, |
| 236 | + num_bytes: *mut usize, |
| 237 | + buffer: *mut u8, |
| 238 | + ) -> Status, |
| 239 | + // TODO: Change to efiapi (https://github.com/rust-lang/rust/issues/100189) |
| 240 | + pub erase_blocks: unsafe extern "C" fn(this: *const Self, ...) -> Status, |
| 241 | + pub parent_handle: Handle, |
| 242 | +} |
| 243 | + |
| 244 | +impl FirmwareVolumeBlock2Protocol { |
| 245 | + pub const GUID: Guid = guid!("8f644fa9-e850-4db1-9ce2-0b44698e8da4"); |
| 246 | + pub const LBA_LIST_TERMINATOR: u64 = u64::MAX; |
| 247 | +} |
0 commit comments