浏览代码

multiboot2: use type definitions from uefi-raw

Philipp Schuster 1 年之前
父节点
当前提交
ce647821d4
共有 5 个文件被更改,包括 37 次插入149 次删除
  1. 26 2
      Cargo.lock
  2. 1 0
      multiboot2/Cargo.toml
  3. 4 0
      multiboot2/Changelog.md
  4. 3 4
      multiboot2/src/lib.rs
  5. 3 143
      multiboot2/src/memory_map.rs

+ 26 - 2
Cargo.lock

@@ -8,6 +8,12 @@ version = "1.3.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
 
+[[package]]
+name = "bitflags"
+version = "2.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6dbe3c979c178231552ecba20214a8272df4e09f232a87aef4320cf06539aded"
+
 [[package]]
 name = "cfg-if"
 version = "1.0.0"
@@ -40,17 +46,18 @@ version = "0.13.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d408e10189a4b0e1d488a24a19c5c8c9786f011b30c824c8ab02d3ebf5f62ca2"
 dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
 ]
 
 [[package]]
 name = "multiboot2"
 version = "0.15.1"
 dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
  "derive_more",
  "log",
  "ptr_meta",
+ "uefi-raw",
 ]
 
 [[package]]
@@ -109,6 +116,23 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "uefi-raw"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d73e08d8e944b7c7e90a7c8a53213bdd71ceb7b414ee664f522c1cc579888c25"
+dependencies = [
+ "bitflags 2.3.2",
+ "ptr_meta",
+ "uguid",
+]
+
+[[package]]
+name = "uguid"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "594cc87e268a7b43d625d46c63cf1605d0e61bf66e4b1cd58c058ec0191e1f81"
+
 [[package]]
 name = "unicode-ident"
 version = "1.0.8"

+ 1 - 0
multiboot2/Cargo.toml

@@ -43,4 +43,5 @@ unstable = []
 bitflags = "1"
 derive_more = { version = "0.99", default-features = false, features = ["display"] }
 log = { version = "0.4", default-features = false }
+uefi-raw = { version = "0.2.0", default-features = false }
 ptr_meta = { version = "0.2.0", default-features = false }

+ 4 - 0
multiboot2/Changelog.md

@@ -9,6 +9,10 @@
 - renamed `MULTIBOOT2_BOOTLOADER_MAGIC` to `MAGIC`
 - added a `builder` feature and a `builder` module with a `Multiboot2InformationBuilder`
   struct
+- `EFIMemoryDesc` was removed and is now an alias of
+  `uefi_raw::table::boot::MemoryDescriptor`
+- `EFIMemoryAreaType` was removed and is now an alias of
+  `uefi_raw::table::boot::MemoryType`
 
 ## 0.15.1 (2023-03-18)
 - **BREAKING** `MemoryMapTag::all_memory_areas()` was renamed to `memory_areas`

+ 3 - 4
multiboot2/src/lib.rs

@@ -1483,7 +1483,6 @@ mod tests {
 
     #[test]
     fn efi_memory_map() {
-        use memory_map::EFIMemoryAreaType;
         #[repr(C, align(8))]
         struct Bytes([u8; 72]);
         // test that the EFI memory map is detected.
@@ -1516,9 +1515,9 @@ mod tests {
         let efi_memory_map = bi.efi_memory_map_tag().unwrap();
         let mut efi_mmap_iter = efi_memory_map.memory_areas();
         let desc = efi_mmap_iter.next().unwrap();
-        assert_eq!(desc.physical_address(), 0x100000);
-        assert_eq!(desc.size(), 16384);
-        assert_eq!(desc.typ(), EFIMemoryAreaType::EfiConventionalMemory);
+        assert_eq!(desc.phys_start, 0x100000);
+        assert_eq!(desc.page_count, 4);
+        assert_eq!(desc.ty, EFIMemoryAreaType::CONVENTIONAL);
         // test that the EFI memory map is not detected if the boot services
         // are not exited.
         struct Bytes2([u8; 80]);

+ 3 - 143
multiboot2/src/memory_map.rs

@@ -1,10 +1,12 @@
 use crate::{Tag, TagTrait, TagType, TagTypeId};
-
 use core::convert::TryInto;
 use core::fmt::Debug;
 use core::marker::PhantomData;
 use core::mem;
 
+pub use uefi_raw::table::boot::MemoryDescriptor as EFIMemoryDesc;
+pub use uefi_raw::table::boot::MemoryType as EFIMemoryAreaType;
+
 #[cfg(feature = "builder")]
 use {crate::builder::boxed_dst_tag, crate::builder::traits::StructAsBytes, alloc::boxed::Box};
 
@@ -296,18 +298,6 @@ impl StructAsBytes for EFIMemoryMapTag {
     }
 }
 
-/// EFI Boot Memory Map Descriptor
-#[derive(Debug, Clone)]
-#[repr(C)]
-pub struct EFIMemoryDesc {
-    typ: u32,
-    _padding: u32,
-    phys_addr: u64,
-    virt_addr: u64,
-    num_pages: u64,
-    attr: u64,
-}
-
 #[cfg(feature = "builder")]
 impl StructAsBytes for EFIMemoryDesc {
     fn byte_size(&self) -> usize {
@@ -315,136 +305,6 @@ impl StructAsBytes for EFIMemoryDesc {
     }
 }
 
-/// An enum of possible reported region types.
-#[derive(Debug, PartialEq, Eq)]
-pub enum EFIMemoryAreaType {
-    /// Unusable.
-    EfiReservedMemoryType,
-    /// Code area of a UEFI application.
-    EfiLoaderCode,
-    /// Data area of a UEFI application.
-    EfiLoaderData,
-    /// Code area of a UEFI Boot Service Driver.
-    EfiBootServicesCode,
-    /// Data area of a UEFI Boot Service Driver.
-    EfiBootServicesData,
-    /// Code area of a UEFI Runtime Driver.
-    ///
-    /// Must be preserved in working and ACPI S1-S3 states.
-    EfiRuntimeServicesCode,
-    /// Data area of a UEFI Runtime Driver.
-    ///
-    /// Must be preserved in working and ACPI S1-S3 states.
-    EfiRuntimeServicesData,
-    /// Available memory.
-    EfiConventionalMemory,
-    /// Memory with errors, treat as unusable.
-    EfiUnusableMemory,
-    /// Memory containing the ACPI tables.
-    ///
-    /// Must be preserved in working and ACPI S1-S3 states.
-    EfiACPIReclaimMemory,
-    /// Memory reserved by firmware.
-    ///
-    /// Must be preserved in working and ACPI S1-S3 states.
-    EfiACPIMemoryNVS,
-    /// Memory used by firmware for requesting memory mapping of IO.
-    ///
-    /// Should not be used by the OS. Use the ACPI tables for memory mapped IO
-    /// information.
-    EfiMemoryMappedIO,
-    /// Memory used to translate memory cycles to IO cycles.
-    ///
-    /// Should not be used by the OS. Use the ACPI tables for memory mapped IO
-    /// information.
-    EfiMemoryMappedIOPortSpace,
-    /// Memory used by the processor.
-    ///
-    /// Must be preserved in working and ACPI S1-S4 states. Processor defined
-    /// otherwise.
-    EfiPalCode,
-    /// Available memory supporting byte-addressable non-volatility.
-    EfiPersistentMemory,
-    /// Unknown region type, treat as unusable.
-    EfiUnknown,
-}
-
-impl From<EFIMemoryAreaType> for u32 {
-    fn from(area: EFIMemoryAreaType) -> Self {
-        match area {
-            EFIMemoryAreaType::EfiReservedMemoryType => 0,
-            EFIMemoryAreaType::EfiLoaderCode => 1,
-            EFIMemoryAreaType::EfiLoaderData => 2,
-            EFIMemoryAreaType::EfiBootServicesCode => 3,
-            EFIMemoryAreaType::EfiBootServicesData => 4,
-            EFIMemoryAreaType::EfiRuntimeServicesCode => 5,
-            EFIMemoryAreaType::EfiRuntimeServicesData => 6,
-            EFIMemoryAreaType::EfiConventionalMemory => 7,
-            EFIMemoryAreaType::EfiUnusableMemory => 8,
-            EFIMemoryAreaType::EfiACPIReclaimMemory => 9,
-            EFIMemoryAreaType::EfiACPIMemoryNVS => 10,
-            EFIMemoryAreaType::EfiMemoryMappedIO => 11,
-            EFIMemoryAreaType::EfiMemoryMappedIOPortSpace => 12,
-            EFIMemoryAreaType::EfiPalCode => 13,
-            EFIMemoryAreaType::EfiPersistentMemory => 14,
-            EFIMemoryAreaType::EfiUnknown => panic!("unknown type"),
-        }
-    }
-}
-
-impl EFIMemoryDesc {
-    /// The physical address of the memory region.
-    pub fn physical_address(&self) -> u64 {
-        self.phys_addr
-    }
-
-    /// The virtual address of the memory region.
-    pub fn virtual_address(&self) -> u64 {
-        self.virt_addr
-    }
-
-    /// The size in bytes of the memory region.
-    pub fn size(&self) -> u64 {
-        // Spec says this is number of 4KiB pages.
-        self.num_pages * 4096
-    }
-
-    /// The type of the memory region.
-    pub fn typ(&self) -> EFIMemoryAreaType {
-        match self.typ {
-            0 => EFIMemoryAreaType::EfiReservedMemoryType,
-            1 => EFIMemoryAreaType::EfiLoaderCode,
-            2 => EFIMemoryAreaType::EfiLoaderData,
-            3 => EFIMemoryAreaType::EfiBootServicesCode,
-            4 => EFIMemoryAreaType::EfiBootServicesData,
-            5 => EFIMemoryAreaType::EfiRuntimeServicesCode,
-            6 => EFIMemoryAreaType::EfiRuntimeServicesData,
-            7 => EFIMemoryAreaType::EfiConventionalMemory,
-            8 => EFIMemoryAreaType::EfiUnusableMemory,
-            9 => EFIMemoryAreaType::EfiACPIReclaimMemory,
-            10 => EFIMemoryAreaType::EfiACPIMemoryNVS,
-            11 => EFIMemoryAreaType::EfiMemoryMappedIO,
-            12 => EFIMemoryAreaType::EfiMemoryMappedIOPortSpace,
-            13 => EFIMemoryAreaType::EfiPalCode,
-            14 => EFIMemoryAreaType::EfiPersistentMemory,
-            _ => EFIMemoryAreaType::EfiUnknown,
-        }
-    }
-}
-
-impl Default for EFIMemoryDesc {
-    fn default() -> Self {
-        Self {
-            typ: EFIMemoryAreaType::EfiReservedMemoryType.into(),
-            _padding: 0,
-            phys_addr: 0,
-            virt_addr: 0,
-            num_pages: 0,
-            attr: 0,
-        }
-    }
-}
-
 /// EFI ExitBootServices was not called
 #[derive(Debug)]
 #[repr(C)]