From b3799ff9c7317a20c7b61135c91d206e108f2dcd Mon Sep 17 00:00:00 2001 From: Yuke Peng Date: Thu, 10 Aug 2023 16:18:17 +0800 Subject: [PATCH] Remove InFramePtr --- services/libs/jinux-util/src/frame_ptr.rs | 156 ---------------------- services/libs/jinux-util/src/lib.rs | 1 - 2 files changed, 157 deletions(-) delete mode 100644 services/libs/jinux-util/src/frame_ptr.rs diff --git a/services/libs/jinux-util/src/frame_ptr.rs b/services/libs/jinux-util/src/frame_ptr.rs deleted file mode 100644 index 11be911e8..000000000 --- a/services/libs/jinux-util/src/frame_ptr.rs +++ /dev/null @@ -1,156 +0,0 @@ -extern crate alloc; - -use core::fmt::Debug; -use core::marker::PhantomData; - -use alloc::sync::Arc; -use jinux_frame::{ - io_mem::IoMem, - vm::{HasPaddr, Paddr, VmFrame, VmIo}, - Result, -}; -use pod::Pod; - -#[derive(Debug, Clone)] -enum InFramePtrAccessMethod { - IoMem(IoMem), - VmFrame(Arc), -} - -impl InFramePtrAccessMethod { - fn read_val(&self, offset: usize) -> Result { - match self { - InFramePtrAccessMethod::IoMem(mmio) => mmio.read_val(offset), - InFramePtrAccessMethod::VmFrame(frame) => frame.read_val(offset), - } - } -} - -/// An in-frame pointer to a POD value, enabling safe access -/// to a POD value given its physical memory address. -pub struct InFramePtr { - access_method: InFramePtrAccessMethod, - offset: usize, - marker: PhantomData<&'static mut T>, -} - -impl Debug for InFramePtr { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let inner = self.access_method.read_val::(self.offset).unwrap(); - f.write_fmt(format_args!("{:?}", inner)) - } -} - -impl InFramePtr { - /// This function only allow the physical address in the MMIO region. - /// - /// Panic if the physical address is not in MMIO region. - pub fn new(paddr: Paddr) -> Result { - let limit = core::mem::size_of::(); - Ok(Self { - access_method: InFramePtrAccessMethod::IoMem( - jinux_frame::io_mem::IoMem::new(paddr..paddr + limit).unwrap(), - ), - offset: 0, - marker: PhantomData, - }) - } - - /// Creating a pointer to the inside of VmFrame. - pub fn new_with_vm_frame(vm_frame_vec: VmFrame) -> Result { - Ok(Self { - access_method: InFramePtrAccessMethod::VmFrame(Arc::new(vm_frame_vec)), - offset: 0, - marker: PhantomData, - }) - } - - pub fn read(&self) -> T { - self.access_method - .read_val::(self.offset) - .expect("read inner from frame failed") - } - - pub fn read_at(&self, offset: *const F) -> F { - match &self.access_method { - InFramePtrAccessMethod::IoMem(mmio) => mmio - .read_val::(self.offset + offset as usize) - .expect("write data from frame failed"), - InFramePtrAccessMethod::VmFrame(vm_frame) => vm_frame - .read_val::(self.offset + offset as usize) - .expect("write data from frame failed"), - } - } - - pub fn write_at(&self, offset: *const F, new_val: F) { - match &self.access_method { - InFramePtrAccessMethod::IoMem(mmio) => mmio - .write_val::(self.offset + offset as usize, &new_val) - .expect("write data from frame failed"), - InFramePtrAccessMethod::VmFrame(vm_frame) => vm_frame - .write_val::(self.offset + offset as usize, &new_val) - .expect("write data from frame failed"), - } - } - - pub fn offset(&self) -> usize { - self.offset - } - - pub fn paddr(&self) -> usize { - match &self.access_method { - InFramePtrAccessMethod::IoMem(mmio) => self.offset + mmio.paddr(), - InFramePtrAccessMethod::VmFrame(vm_frame) => self.offset + vm_frame.start_paddr(), - } - } - - /// Clone self and then change the offset to the next `count` one. - /// - /// User can use this function to easily visit POD array. For example: - /// - /// ```rust - /// use pod::Pod - /// - /// #[derive(Pod)] - /// struct Foo{ - /// value1: usize, - /// value2: usize, - /// } - /// - /// fn visit(){ - /// // visit array [Foo1, Foo2, Foo3] - /// let Foo1 : InFramePtr = InFramePtr::alloc().unwrap(); - /// let Foo2 = Foo1.add(1); - /// let Foo3 = Foo2.add(1); - /// } - /// - /// ``` - /// - pub fn add(&self, count: usize) -> Self { - let mut next: InFramePtr = self.clone(); - next.access_method = match next.access_method { - InFramePtrAccessMethod::IoMem(mmio) => InFramePtrAccessMethod::IoMem( - jinux_frame::io_mem::IoMem::new( - mmio.paddr() + count * core::mem::size_of::() - ..mmio.paddr() + (count + 1) * core::mem::size_of::(), - ) - .unwrap(), - ), - InFramePtrAccessMethod::VmFrame(_) => { - next.offset += core::mem::size_of::() * count; - next.access_method - } - }; - next - } -} - -impl Clone for InFramePtr { - fn clone(&self) -> Self { - Self { - access_method: self.access_method.clone(), - offset: self.offset, - marker: self.marker, - } - } -} diff --git a/services/libs/jinux-util/src/lib.rs b/services/libs/jinux-util/src/lib.rs index f1e18e475..48426aef5 100644 --- a/services/libs/jinux-util/src/lib.rs +++ b/services/libs/jinux-util/src/lib.rs @@ -5,7 +5,6 @@ extern crate alloc; pub mod dup; -pub mod frame_ptr; pub mod id_allocator; pub mod safe_ptr; pub mod slot_vec;