Use safe-mmio crate for PhysicalInstance.
Change-Id: Id34d4ee2f7bc6ce155a0b5c8aec2f808148ef7f0
Signed-off-by: Andrew Walbran <qwandor@google.com>
diff --git a/Cargo.lock b/Cargo.lock
index 9d29226..1419f48 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9,6 +9,7 @@
"arm-gic",
"arm-pl011-uart",
"arm-sp805",
+ "safe-mmio",
"spin",
]
@@ -94,6 +95,12 @@
]
[[package]]
+name = "safe-mmio"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "30075950f15d2083592cdb9b5b175d48d332dacdc481c17546910e0c1e9cc4b1"
+
+[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 0f7ee84..5a91093 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,10 +14,9 @@
repository = "https://git.trustedfirmware.org/rust-spmc/rust-spmc.git"
keywords = ["arm", "fvp", "pac", "virtual", "platform"]
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
[dependencies]
arm-gic = { git = "https://git.trustedfirmware.org/rust-spmc/arm-gic.git" }
arm-pl011-uart = "0.1"
arm-sp805 = { git = "https://git.trustedfirmware.org/rust-spmc/arm-sp805.git" }
+safe-mmio = "0.1.0"
spin = { version = "0.9", default-features = false, features = ["spin_mutex"] }
diff --git a/src/lib.rs b/src/lib.rs
index 5c67eaa..f1d02d9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,51 +7,16 @@
#![no_std]
-use core::{
- fmt::{self, Debug, Formatter},
- marker::PhantomData,
-};
+use core::fmt::Debug;
use arm_gic::GICDRegisters;
use arm_pl011_uart::PL011Registers;
use arm_sp805::SP805Registers;
+pub use safe_mmio::PhysicalInstance;
use spin::mutex::Mutex;
static PERIPHERALS_TAKEN: Mutex<bool> = Mutex::new(false);
-/// The physical instance of some device's MMIO space.
-pub struct PhysicalInstance<T> {
- pa: usize,
- _phantom: PhantomData<T>,
-}
-
-impl<T> Debug for PhysicalInstance<T> {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- f.debug_struct("PhysicalInstance")
- .field("pa", &self.pa)
- .field("size", &size_of::<T>())
- .finish()
- }
-}
-
-impl<T> PhysicalInstance<T> {
- /// # Safety
- ///
- /// This must refer to the physical address of a real set of device registers of type `T`, and
- /// there must only ever be a single `PhysicalInstance` for those device registers.
- pub unsafe fn new(pa: usize) -> Self {
- Self {
- pa,
- _phantom: PhantomData,
- }
- }
-
- /// Returns the physical base address of the device's registers.
- pub fn pa(&self) -> usize {
- self.pa
- }
-}
-
/// FVP peripherals
#[derive(Debug)]
pub struct Peripherals {