|
1 | 1 | use crate::{Tag, TagTrait, TagType, TagTypeId}; |
2 | | - |
3 | 2 | use core::convert::TryInto; |
4 | 3 | use core::fmt::Debug; |
5 | 4 | use core::marker::PhantomData; |
6 | 5 | use core::mem; |
7 | 6 |
|
| 7 | +pub use uefi_raw::table::boot::MemoryDescriptor as EFIMemoryDesc; |
| 8 | +pub use uefi_raw::table::boot::MemoryType as EFIMemoryAreaType; |
| 9 | + |
8 | 10 | #[cfg(feature = "builder")] |
9 | 11 | use {crate::builder::boxed_dst_tag, crate::builder::traits::StructAsBytes, alloc::boxed::Box}; |
10 | 12 |
|
@@ -296,155 +298,13 @@ impl StructAsBytes for EFIMemoryMapTag { |
296 | 298 | } |
297 | 299 | } |
298 | 300 |
|
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 | | - |
311 | 301 | #[cfg(feature = "builder")] |
312 | 302 | impl StructAsBytes for EFIMemoryDesc { |
313 | 303 | fn byte_size(&self) -> usize { |
314 | 304 | mem::size_of::<Self>() |
315 | 305 | } |
316 | 306 | } |
317 | 307 |
|
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 | | - |
448 | 308 | /// EFI ExitBootServices was not called |
449 | 309 | #[derive(Debug)] |
450 | 310 | #[repr(C)] |
|
0 commit comments