Rename mmio to IoMem

This commit is contained in:
Yuke Peng
2023-07-23 03:40:41 -07:00
committed by Tate, Hongliang Tian
parent a6dcdf6952
commit 49f2750108
6 changed files with 34 additions and 34 deletions

View File

@ -69,15 +69,15 @@ impl CapabilityMsixData {
for i in 0..table_size {
// Set message address and disable this msix entry
table_bar
.mmio()
.io_mem()
.write_val((16 * i) as usize, &message_address)
.unwrap();
table_bar
.mmio()
.io_mem()
.write_val((16 * i + 4) as usize, &message_upper_address)
.unwrap();
table_bar
.mmio()
.io_mem()
.write_val((16 * i + 12) as usize, &(1 as u32))
.unwrap();
}
@ -130,7 +130,7 @@ impl CapabilityMsixData {
core::mem::replace(&mut self.irq_allocate_handles[index as usize], Some(vector));
// Enable this msix vector
self.table_bar
.mmio()
.io_mem()
.write_val((16 * index + 12) as usize, &(0 as u32))
.unwrap();
}

View File

@ -1,7 +1,7 @@
use alloc::sync::Arc;
use bitflags::bitflags;
use crate::{mmio::Mmio, Error, Result};
use crate::{io_mem::IoMem, Error, Result};
use super::PciDeviceLocation;
@ -104,7 +104,7 @@ pub struct MemoryBar {
/// in advance.
prefetchable: bool,
address_length: AddrLen,
mmio: Mmio,
io_memory: IoMem,
}
impl MemoryBar {
@ -125,8 +125,8 @@ impl MemoryBar {
self.size
}
pub fn mmio(&self) -> &Mmio {
&self.mmio
pub fn io_mem(&self) -> &IoMem {
&self.io_memory
}
/// Create a memory BAR structure.
@ -159,7 +159,7 @@ impl MemoryBar {
size,
prefetchable,
address_length,
mmio: Mmio::new((base as usize)..((base + size as u64) as usize)).unwrap(),
io_memory: IoMem::new((base as usize)..((base + size as u64) as usize)).unwrap(),
})
}
}

View File

@ -22,12 +22,12 @@ pub(crate) fn init() {
}
#[derive(Debug, Clone)]
pub struct Mmio {
pub struct IoMem {
virtual_address: Vaddr,
limit: usize,
}
impl VmIo for Mmio {
impl VmIo for IoMem {
fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> crate::Result<()> {
self.check_range(offset, buf.len())?;
unsafe {
@ -60,10 +60,10 @@ impl VmIo for Mmio {
}
}
impl Mmio {
pub fn new(range: Range<Paddr>) -> Option<Mmio> {
impl IoMem {
pub fn new(range: Range<Paddr>) -> Option<IoMem> {
if CHECKER.get().unwrap().check(&range) {
Some(Mmio {
Some(IoMem {
virtual_address: crate::vm::paddr_to_vaddr(range.start),
limit: range.len(),
})

View File

@ -24,7 +24,7 @@ pub mod config;
pub mod cpu;
mod error;
pub mod logger;
pub mod mmio;
pub mod io_mem;
pub mod prelude;
pub mod sync;
pub mod task;
@ -52,7 +52,7 @@ pub fn init() {
vm::init();
trap::init();
arch::after_all_init();
mmio::init();
io_mem::init();
bus::init();
register_irq_common_callback();
invoke_c_init_funcs();

View File

@ -13,7 +13,7 @@ use core::{
};
use font8x8::UnicodeFonts;
use jinux_frame::{
config::PAGE_SIZE, mmio::Mmio, sync::SpinLock, vm::VmIo, LimineFramebufferRequest,
config::PAGE_SIZE, io_mem::IoMem, sync::SpinLock, vm::VmIo, LimineFramebufferRequest,
};
use spin::Once;
@ -42,8 +42,8 @@ pub(crate) fn init() {
let page_size = size / PAGE_SIZE;
let start_paddr = i.address.as_ptr().unwrap().addr();
let mmio =
Mmio::new(start_paddr..(start_paddr + jinux_frame::config::PAGE_SIZE * page_size))
let io_mem =
IoMem::new(start_paddr..(start_paddr + jinux_frame::config::PAGE_SIZE * page_size))
.unwrap();
let mut buffer: Vec<u8> = Vec::with_capacity(size);
@ -53,7 +53,7 @@ pub(crate) fn init() {
log::debug!("Found framebuffer:{:?}", *i);
writer = Some(Writer {
mmio,
io_mem,
x_pos: 0,
y_pos: 0,
bytes_per_pixel: (i.bpp / 8) as usize,
@ -70,7 +70,7 @@ pub(crate) fn init() {
}
pub(crate) struct Writer {
mmio: Mmio,
io_mem: IoMem,
/// FIXME: remove buffer. The meaning of buffer is to facilitate the various operations of framebuffer
buffer: &'static mut [u8],
@ -97,14 +97,14 @@ impl Writer {
self.x_pos = 0;
self.y_pos = 0;
self.buffer.fill(0);
self.mmio.write_bytes(0, self.buffer).unwrap();
self.io_mem.write_bytes(0, self.buffer).unwrap();
}
/// Everything moves up one letter in size
fn shift_lines_up(&mut self) {
let offset = self.bytes_per_pixel * 8;
self.buffer.copy_within(offset.., 0);
self.mmio.write_bytes(0, self.buffer).unwrap();
self.io_mem.write_bytes(0, self.buffer).unwrap();
self.y_pos -= 8;
}
@ -157,7 +157,7 @@ impl Writer {
self.buffer
.index_mut(byte_offset..(byte_offset + bytes_per_pixel))
.copy_from_slice(&color[..bytes_per_pixel]);
self.mmio
self.io_mem
.write_bytes(
byte_offset,
self.buffer

View File

@ -5,7 +5,7 @@ use core::marker::PhantomData;
use alloc::sync::Arc;
use jinux_frame::{
mmio::Mmio,
io_mem::IoMem,
vm::{Paddr, VmFrame, VmIo},
Result,
};
@ -13,14 +13,14 @@ use pod::Pod;
#[derive(Debug, Clone)]
enum InFramePtrAccessMethod {
Mmio(Mmio),
IoMem(IoMem),
VmFrame(Arc<VmFrame>),
}
impl InFramePtrAccessMethod {
fn read_val<T: Pod>(&self, offset: usize) -> Result<T> {
match self {
InFramePtrAccessMethod::Mmio(mmio) => mmio.read_val(offset),
InFramePtrAccessMethod::IoMem(mmio) => mmio.read_val(offset),
InFramePtrAccessMethod::VmFrame(frame) => frame.read_val(offset),
}
}
@ -48,8 +48,8 @@ impl<T: Pod> InFramePtr<T> {
pub fn new(paddr: Paddr) -> Result<Self> {
let limit = core::mem::size_of::<T>();
Ok(Self {
access_method: InFramePtrAccessMethod::Mmio(
jinux_frame::mmio::Mmio::new(paddr..paddr + limit).unwrap(),
access_method: InFramePtrAccessMethod::IoMem(
jinux_frame::io_mem::IoMem::new(paddr..paddr + limit).unwrap(),
),
offset: 0,
marker: PhantomData,
@ -73,7 +73,7 @@ impl<T: Pod> InFramePtr<T> {
pub fn read_at<F: Pod>(&self, offset: *const F) -> F {
match &self.access_method {
InFramePtrAccessMethod::Mmio(mmio) => mmio
InFramePtrAccessMethod::IoMem(mmio) => mmio
.read_val::<F>(self.offset + offset as usize)
.expect("write data from frame failed"),
InFramePtrAccessMethod::VmFrame(vm_frame) => vm_frame
@ -84,7 +84,7 @@ impl<T: Pod> InFramePtr<T> {
pub fn write_at<F: Pod>(&self, offset: *const F, new_val: F) {
match &self.access_method {
InFramePtrAccessMethod::Mmio(mmio) => mmio
InFramePtrAccessMethod::IoMem(mmio) => mmio
.write_val::<F>(self.offset + offset as usize, &new_val)
.expect("write data from frame failed"),
InFramePtrAccessMethod::VmFrame(vm_frame) => vm_frame
@ -99,7 +99,7 @@ impl<T: Pod> InFramePtr<T> {
pub fn paddr(&self) -> usize {
match &self.access_method {
InFramePtrAccessMethod::Mmio(mmio) => self.offset + mmio.paddr(),
InFramePtrAccessMethod::IoMem(mmio) => self.offset + mmio.paddr(),
InFramePtrAccessMethod::VmFrame(vm_frame) => self.offset + vm_frame.start_paddr(),
}
}
@ -129,8 +129,8 @@ impl<T: Pod> InFramePtr<T> {
pub fn add(&self, count: usize) -> Self {
let mut next: InFramePtr<T> = self.clone();
next.access_method = match next.access_method {
InFramePtrAccessMethod::Mmio(mmio) => InFramePtrAccessMethod::Mmio(
jinux_frame::mmio::Mmio::new(
InFramePtrAccessMethod::IoMem(mmio) => InFramePtrAccessMethod::IoMem(
jinux_frame::io_mem::IoMem::new(
mmio.paddr() + count * core::mem::size_of::<T>()
..mmio.paddr() + (count + 1) * core::mem::size_of::<T>(),
)