|
1 | 1 | //! UEFI services available during boot.
|
2 | 2 |
|
3 | 3 | use super::{Header, Revision};
|
4 | | -use crate::data_types::{Align, PhysicalAddress,VirtualAddress}; |
| 4 | +use crate::data_types::{Align, PhysicalAddress}; |
5 | 5 | use crate::proto::device_path::{DevicePath, FfiDevicePath};
|
6 | 6 | use crate::proto::{Protocol, ProtocolPointer};
|
7 | 7 | use crate::{Char16, Event, Guid, Handle, Result, Status, StatusExt};
|
|
20 | 20 | ::alloc::vec::Vec,
|
21 | 21 | };
|
22 | 22 |
|
23 | | -pub use uefi_raw::table::boot::Tpl; |
| 23 | +pub use uefi_raw::table::boot::{MemoryAttribute,MemoryDescriptor,MemoryType,Tpl}; |
24 | 24 |
|
25 | 25 | // TODO: this similar to `SyncUnsafeCell`. Once that is stabilized we
|
26 | 26 | // can use it instead.
|
@@ -1814,151 +1814,12 @@ pub enum AllocateType {
|
1814 | 1814 | Address(PhysicalAddress),
|
1815 | 1815 | }
|
1816 | 1816 |
|
1817 | | -newtype_enum! { |
1818 | | -/// The type of a memory range. |
1819 | | -/// |
1820 | | -/// UEFI allows firmwares and operating systems to introduce new memory types |
1821 | | -/// in the 0x70000000..0xFFFFFFFF range. Therefore, we don't know the full set |
1822 | | -/// of memory types at compile time, and it is _not_ safe to model this C enum |
1823 | | -/// as a Rust enum. |
1824 | | -pub enum MemoryType: u32 => { |
1825 | | - /// This enum variant is not used. |
1826 | | - RESERVED = 0, |
1827 | | - /// The code portions of a loaded UEFI application. |
1828 | | - LOADER_CODE = 1, |
1829 | | - /// The data portions of a loaded UEFI applications, |
1830 | | - /// as well as any memory allocated by it. |
1831 | | - LOADER_DATA = 2, |
1832 | | - /// Code of the boot drivers. |
1833 | | - /// |
1834 | | - /// Can be reused after OS is loaded. |
1835 | | - BOOT_SERVICES_CODE = 3, |
1836 | | - /// Memory used to store boot drivers' data. |
1837 | | - /// |
1838 | | - /// Can be reused after OS is loaded. |
1839 | | - BOOT_SERVICES_DATA = 4, |
1840 | | - /// Runtime drivers' code. |
1841 | | - RUNTIME_SERVICES_CODE = 5, |
1842 | | - /// Runtime services' code. |
1843 | | - RUNTIME_SERVICES_DATA = 6, |
1844 | | - /// Free usable memory. |
1845 | | - CONVENTIONAL = 7, |
1846 | | - /// Memory in which errors have been detected. |
1847 | | - UNUSABLE = 8, |
1848 | | - /// Memory that holds ACPI tables. |
1849 | | - /// Can be reclaimed after they are parsed. |
1850 | | - ACPI_RECLAIM = 9, |
1851 | | - /// Firmware-reserved addresses. |
1852 | | - ACPI_NON_VOLATILE = 10, |
1853 | | - /// A region used for memory-mapped I/O. |
1854 | | - MMIO = 11, |
1855 | | - /// Address space used for memory-mapped port I/O. |
1856 | | - MMIO_PORT_SPACE = 12, |
1857 | | - /// Address space which is part of the processor. |
1858 | | - PAL_CODE = 13, |
1859 | | - /// Memory region which is usable and is also non-volatile. |
1860 | | - PERSISTENT_MEMORY = 14, |
1861 | | -}} |
1862 | | - |
1863 | | -impl MemoryType { |
1864 | | - /// Construct a custom `MemoryType`. Values in the range `0x80000000..=0xffffffff` are free for use if you are |
1865 | | - /// an OS loader. |
1866 | | - #[must_use] |
1867 | | - pub const fn custom(value: u32) -> MemoryType { |
1868 | | - assert!(value >= 0x80000000); |
1869 | | - MemoryType(value) |
1870 | | - } |
1871 | | -} |
1872 | | - |
1873 | | -/// A structure describing a region of memory. |
1874 | | -#[derive(Debug, Copy, Clone)] |
1875 | | -#[repr(C)] |
1876 | | -pub struct MemoryDescriptor { |
1877 | | - /// Type of memory occupying this range. |
1878 | | - pub ty: MemoryType, |
1879 | | - /// Starting physical address. |
1880 | | - pub phys_start: PhysicalAddress, |
1881 | | - /// Starting virtual address. |
1882 | | - pub virt_start: VirtualAddress, |
1883 | | - /// Number of 4 KiB pages contained in this range. |
1884 | | - pub page_count: u64, |
1885 | | - /// The capability attributes of this memory range. |
1886 | | - pub att: MemoryAttribute, |
1887 | | -} |
1888 | | - |
1889 | | -impl MemoryDescriptor { |
1890 | | - /// Memory descriptor version number. |
1891 | | - pub const VERSION: u32 = 1; |
1892 | | -} |
1893 | | - |
1894 | | -impl Default for MemoryDescriptor { |
1895 | | - fn default() -> MemoryDescriptor { |
1896 | | - MemoryDescriptor { |
1897 | | - ty: MemoryType::RESERVED, |
1898 | | - phys_start: 0, |
1899 | | - virt_start: 0, |
1900 | | - page_count: 0, |
1901 | | - att: MemoryAttribute::empty(), |
1902 | | - } |
1903 | | - } |
1904 | | -} |
1905 | | - |
1906 | 1817 | impl Align for MemoryDescriptor {
|
1907 | 1818 | fn alignment() -> usize {
|
1908 | 1819 | mem::align_of::<Self>()
|
1909 | 1820 | }
|
1910 | 1821 | }
|
1911 | 1822 |
|
1912 | | -bitflags! { |
1913 | | - /// Flags describing the capabilities of a memory range. |
1914 | | - #[repr(transparent)] |
1915 | | - pub struct MemoryAttribute: u64 { |
1916 | | - /// Supports marking as uncacheable. |
1917 | | - const UNCACHEABLE = 0x1; |
1918 | | - /// Supports write-combining. |
1919 | | - const WRITE_COMBINE = 0x2; |
1920 | | - /// Supports write-through. |
1921 | | - const WRITE_THROUGH = 0x4; |
1922 | | - /// Support write-back. |
1923 | | - const WRITE_BACK = 0x8; |
1924 | | - /// Supports marking as uncacheable, exported and |
1925 | | - /// supports the "fetch and add" semaphore mechanism. |
1926 | | - const UNCACHABLE_EXPORTED = 0x10; |
1927 | | - /// Supports write-protection. |
1928 | | - const WRITE_PROTECT = 0x1000; |
1929 | | - /// Supports read-protection. |
1930 | | - const READ_PROTECT = 0x2000; |
1931 | | - /// Supports disabling code execution. |
1932 | | - const EXECUTE_PROTECT = 0x4000; |
1933 | | - /// Persistent memory. |
1934 | | - const NON_VOLATILE = 0x8000; |
1935 | | - /// This memory region is more reliable than other memory. |
1936 | | - const MORE_RELIABLE = 0x10000; |
1937 | | - /// This memory range can be set as read-only. |
1938 | | - const READ_ONLY = 0x20000; |
1939 | | - /// This memory is earmarked for specific purposes such as for specific |
1940 | | - /// device drivers or applications. This serves as a hint to the OS to |
1941 | | - /// avoid this memory for core OS data or code that cannot be relocated. |
1942 | | - const SPECIAL_PURPOSE = 0x4_0000; |
1943 | | - /// This memory region is capable of being protected with the CPU's memory |
1944 | | - /// cryptography capabilities. |
1945 | | - const CPU_CRYPTO = 0x8_0000; |
1946 | | - /// This memory must be mapped by the OS when a runtime service is called. |
1947 | | - const RUNTIME = 0x8000_0000_0000_0000; |
1948 | | - /// This memory region is described with additional ISA-specific memory |
1949 | | - /// attributes as specified in `MemoryAttribute::ISA_MASK`. |
1950 | | - const ISA_VALID = 0x4000_0000_0000_0000; |
1951 | | - /// These bits are reserved for describing optional ISA-specific cache- |
1952 | | - /// ability attributes that are not covered by the standard UEFI Memory |
1953 | | - /// Attribute cacheability bits such as `UNCACHEABLE`, `WRITE_COMBINE`, |
1954 | | - /// `WRITE_THROUGH`, `WRITE_BACK`, and `UNCACHEABLE_EXPORTED`. |
1955 | | - /// |
1956 | | - /// See Section 2.3 "Calling Conventions" in the UEFI Specification |
1957 | | - /// for further information on each ISA that takes advantage of this. |
1958 | | - const ISA_MASK = 0x0FFF_F000_0000_0000; |
1959 | | - } |
1960 | | -} |
1961 | | - |
1962 | 1823 | /// A unique identifier of a memory map.
|
1963 | 1824 | ///
|
1964 | 1825 | /// If the memory map changes, this value is no longer valid.
|
|
0 commit comments