Skip to content

Commit ce64782

Browse files
committed
multiboot2: use type definitions from uefi-raw
1 parent 364d04e commit ce64782

File tree

5 files changed

+37
-149
lines changed

5 files changed

+37
-149
lines changed

Cargo.lock

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

multiboot2/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ unstable = []
4343
bitflags = "1"
4444
derive_more = { version = "0.99", default-features = false, features = ["display"] }
4545
log = { version = "0.4", default-features = false }
46+
uefi-raw = { version = "0.2.0", default-features = false }
4647
ptr_meta = { version = "0.2.0", default-features = false }

multiboot2/Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
- renamed `MULTIBOOT2_BOOTLOADER_MAGIC` to `MAGIC`
1010
- added a `builder` feature and a `builder` module with a `Multiboot2InformationBuilder`
1111
struct
12+
- `EFIMemoryDesc` was removed and is now an alias of
13+
`uefi_raw::table::boot::MemoryDescriptor`
14+
- `EFIMemoryAreaType` was removed and is now an alias of
15+
`uefi_raw::table::boot::MemoryType`
1216

1317
## 0.15.1 (2023-03-18)
1418
- **BREAKING** `MemoryMapTag::all_memory_areas()` was renamed to `memory_areas`

multiboot2/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,6 @@ mod tests {
14831483

14841484
#[test]
14851485
fn efi_memory_map() {
1486-
use memory_map::EFIMemoryAreaType;
14871486
#[repr(C, align(8))]
14881487
struct Bytes([u8; 72]);
14891488
// test that the EFI memory map is detected.
@@ -1516,9 +1515,9 @@ mod tests {
15161515
let efi_memory_map = bi.efi_memory_map_tag().unwrap();
15171516
let mut efi_mmap_iter = efi_memory_map.memory_areas();
15181517
let desc = efi_mmap_iter.next().unwrap();
1519-
assert_eq!(desc.physical_address(), 0x100000);
1520-
assert_eq!(desc.size(), 16384);
1521-
assert_eq!(desc.typ(), EFIMemoryAreaType::EfiConventionalMemory);
1518+
assert_eq!(desc.phys_start, 0x100000);
1519+
assert_eq!(desc.page_count, 4);
1520+
assert_eq!(desc.ty, EFIMemoryAreaType::CONVENTIONAL);
15221521
// test that the EFI memory map is not detected if the boot services
15231522
// are not exited.
15241523
struct Bytes2([u8; 80]);

multiboot2/src/memory_map.rs

Lines changed: 3 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use crate::{Tag, TagTrait, TagType, TagTypeId};
2-
32
use core::convert::TryInto;
43
use core::fmt::Debug;
54
use core::marker::PhantomData;
65
use core::mem;
76

7+
pub use uefi_raw::table::boot::MemoryDescriptor as EFIMemoryDesc;
8+
pub use uefi_raw::table::boot::MemoryType as EFIMemoryAreaType;
9+
810
#[cfg(feature = "builder")]
911
use {crate::builder::boxed_dst_tag, crate::builder::traits::StructAsBytes, alloc::boxed::Box};
1012

@@ -296,155 +298,13 @@ impl StructAsBytes for EFIMemoryMapTag {
296298
}
297299
}
298300

299-
/// EFI Boot Memory Map Descriptor
300-
#[derive(Debug, Clone)]
301-
#[repr(C)]
302-
pub struct EFIMemoryDesc {
303-
typ: u32,
304-
_padding: u32,
305-
phys_addr: u64,
306-
virt_addr: u64,
307-
num_pages: u64,
308-
attr: u64,
309-
}
310-
311301
#[cfg(feature = "builder")]
312302
impl StructAsBytes for EFIMemoryDesc {
313303
fn byte_size(&self) -> usize {
314304
mem::size_of::<Self>()
315305
}
316306
}
317307

318-
/// An enum of possible reported region types.
319-
#[derive(Debug, PartialEq, Eq)]
320-
pub enum EFIMemoryAreaType {
321-
/// Unusable.
322-
EfiReservedMemoryType,
323-
/// Code area of a UEFI application.
324-
EfiLoaderCode,
325-
/// Data area of a UEFI application.
326-
EfiLoaderData,
327-
/// Code area of a UEFI Boot Service Driver.
328-
EfiBootServicesCode,
329-
/// Data area of a UEFI Boot Service Driver.
330-
EfiBootServicesData,
331-
/// Code area of a UEFI Runtime Driver.
332-
///
333-
/// Must be preserved in working and ACPI S1-S3 states.
334-
EfiRuntimeServicesCode,
335-
/// Data area of a UEFI Runtime Driver.
336-
///
337-
/// Must be preserved in working and ACPI S1-S3 states.
338-
EfiRuntimeServicesData,
339-
/// Available memory.
340-
EfiConventionalMemory,
341-
/// Memory with errors, treat as unusable.
342-
EfiUnusableMemory,
343-
/// Memory containing the ACPI tables.
344-
///
345-
/// Must be preserved in working and ACPI S1-S3 states.
346-
EfiACPIReclaimMemory,
347-
/// Memory reserved by firmware.
348-
///
349-
/// Must be preserved in working and ACPI S1-S3 states.
350-
EfiACPIMemoryNVS,
351-
/// Memory used by firmware for requesting memory mapping of IO.
352-
///
353-
/// Should not be used by the OS. Use the ACPI tables for memory mapped IO
354-
/// information.
355-
EfiMemoryMappedIO,
356-
/// Memory used to translate memory cycles to IO cycles.
357-
///
358-
/// Should not be used by the OS. Use the ACPI tables for memory mapped IO
359-
/// information.
360-
EfiMemoryMappedIOPortSpace,
361-
/// Memory used by the processor.
362-
///
363-
/// Must be preserved in working and ACPI S1-S4 states. Processor defined
364-
/// otherwise.
365-
EfiPalCode,
366-
/// Available memory supporting byte-addressable non-volatility.
367-
EfiPersistentMemory,
368-
/// Unknown region type, treat as unusable.
369-
EfiUnknown,
370-
}
371-
372-
impl From<EFIMemoryAreaType> for u32 {
373-
fn from(area: EFIMemoryAreaType) -> Self {
374-
match area {
375-
EFIMemoryAreaType::EfiReservedMemoryType => 0,
376-
EFIMemoryAreaType::EfiLoaderCode => 1,
377-
EFIMemoryAreaType::EfiLoaderData => 2,
378-
EFIMemoryAreaType::EfiBootServicesCode => 3,
379-
EFIMemoryAreaType::EfiBootServicesData => 4,
380-
EFIMemoryAreaType::EfiRuntimeServicesCode => 5,
381-
EFIMemoryAreaType::EfiRuntimeServicesData => 6,
382-
EFIMemoryAreaType::EfiConventionalMemory => 7,
383-
EFIMemoryAreaType::EfiUnusableMemory => 8,
384-
EFIMemoryAreaType::EfiACPIReclaimMemory => 9,
385-
EFIMemoryAreaType::EfiACPIMemoryNVS => 10,
386-
EFIMemoryAreaType::EfiMemoryMappedIO => 11,
387-
EFIMemoryAreaType::EfiMemoryMappedIOPortSpace => 12,
388-
EFIMemoryAreaType::EfiPalCode => 13,
389-
EFIMemoryAreaType::EfiPersistentMemory => 14,
390-
EFIMemoryAreaType::EfiUnknown => panic!("unknown type"),
391-
}
392-
}
393-
}
394-
395-
impl EFIMemoryDesc {
396-
/// The physical address of the memory region.
397-
pub fn physical_address(&self) -> u64 {
398-
self.phys_addr
399-
}
400-
401-
/// The virtual address of the memory region.
402-
pub fn virtual_address(&self) -> u64 {
403-
self.virt_addr
404-
}
405-
406-
/// The size in bytes of the memory region.
407-
pub fn size(&self) -> u64 {
408-
// Spec says this is number of 4KiB pages.
409-
self.num_pages * 4096
410-
}
411-
412-
/// The type of the memory region.
413-
pub fn typ(&self) -> EFIMemoryAreaType {
414-
match self.typ {
415-
0 => EFIMemoryAreaType::EfiReservedMemoryType,
416-
1 => EFIMemoryAreaType::EfiLoaderCode,
417-
2 => EFIMemoryAreaType::EfiLoaderData,
418-
3 => EFIMemoryAreaType::EfiBootServicesCode,
419-
4 => EFIMemoryAreaType::EfiBootServicesData,
420-
5 => EFIMemoryAreaType::EfiRuntimeServicesCode,
421-
6 => EFIMemoryAreaType::EfiRuntimeServicesData,
422-
7 => EFIMemoryAreaType::EfiConventionalMemory,
423-
8 => EFIMemoryAreaType::EfiUnusableMemory,
424-
9 => EFIMemoryAreaType::EfiACPIReclaimMemory,
425-
10 => EFIMemoryAreaType::EfiACPIMemoryNVS,
426-
11 => EFIMemoryAreaType::EfiMemoryMappedIO,
427-
12 => EFIMemoryAreaType::EfiMemoryMappedIOPortSpace,
428-
13 => EFIMemoryAreaType::EfiPalCode,
429-
14 => EFIMemoryAreaType::EfiPersistentMemory,
430-
_ => EFIMemoryAreaType::EfiUnknown,
431-
}
432-
}
433-
}
434-
435-
impl Default for EFIMemoryDesc {
436-
fn default() -> Self {
437-
Self {
438-
typ: EFIMemoryAreaType::EfiReservedMemoryType.into(),
439-
_padding: 0,
440-
phys_addr: 0,
441-
virt_addr: 0,
442-
num_pages: 0,
443-
attr: 0,
444-
}
445-
}
446-
}
447-
448308
/// EFI ExitBootServices was not called
449309
#[derive(Debug)]
450310
#[repr(C)]

0 commit comments

Comments
 (0)