mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Rename mmio to IoMem
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
a6dcdf6952
commit
49f2750108
@ -69,15 +69,15 @@ impl CapabilityMsixData {
|
|||||||
for i in 0..table_size {
|
for i in 0..table_size {
|
||||||
// Set message address and disable this msix entry
|
// Set message address and disable this msix entry
|
||||||
table_bar
|
table_bar
|
||||||
.mmio()
|
.io_mem()
|
||||||
.write_val((16 * i) as usize, &message_address)
|
.write_val((16 * i) as usize, &message_address)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
table_bar
|
table_bar
|
||||||
.mmio()
|
.io_mem()
|
||||||
.write_val((16 * i + 4) as usize, &message_upper_address)
|
.write_val((16 * i + 4) as usize, &message_upper_address)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
table_bar
|
table_bar
|
||||||
.mmio()
|
.io_mem()
|
||||||
.write_val((16 * i + 12) as usize, &(1 as u32))
|
.write_val((16 * i + 12) as usize, &(1 as u32))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ impl CapabilityMsixData {
|
|||||||
core::mem::replace(&mut self.irq_allocate_handles[index as usize], Some(vector));
|
core::mem::replace(&mut self.irq_allocate_handles[index as usize], Some(vector));
|
||||||
// Enable this msix vector
|
// Enable this msix vector
|
||||||
self.table_bar
|
self.table_bar
|
||||||
.mmio()
|
.io_mem()
|
||||||
.write_val((16 * index + 12) as usize, &(0 as u32))
|
.write_val((16 * index + 12) as usize, &(0 as u32))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
|
||||||
use crate::{mmio::Mmio, Error, Result};
|
use crate::{io_mem::IoMem, Error, Result};
|
||||||
|
|
||||||
use super::PciDeviceLocation;
|
use super::PciDeviceLocation;
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ pub struct MemoryBar {
|
|||||||
/// in advance.
|
/// in advance.
|
||||||
prefetchable: bool,
|
prefetchable: bool,
|
||||||
address_length: AddrLen,
|
address_length: AddrLen,
|
||||||
mmio: Mmio,
|
io_memory: IoMem,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryBar {
|
impl MemoryBar {
|
||||||
@ -125,8 +125,8 @@ impl MemoryBar {
|
|||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mmio(&self) -> &Mmio {
|
pub fn io_mem(&self) -> &IoMem {
|
||||||
&self.mmio
|
&self.io_memory
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a memory BAR structure.
|
/// Create a memory BAR structure.
|
||||||
@ -159,7 +159,7 @@ impl MemoryBar {
|
|||||||
size,
|
size,
|
||||||
prefetchable,
|
prefetchable,
|
||||||
address_length,
|
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(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,12 @@ pub(crate) fn init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Mmio {
|
pub struct IoMem {
|
||||||
virtual_address: Vaddr,
|
virtual_address: Vaddr,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VmIo for Mmio {
|
impl VmIo for IoMem {
|
||||||
fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> crate::Result<()> {
|
fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> crate::Result<()> {
|
||||||
self.check_range(offset, buf.len())?;
|
self.check_range(offset, buf.len())?;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -60,10 +60,10 @@ impl VmIo for Mmio {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mmio {
|
impl IoMem {
|
||||||
pub fn new(range: Range<Paddr>) -> Option<Mmio> {
|
pub fn new(range: Range<Paddr>) -> Option<IoMem> {
|
||||||
if CHECKER.get().unwrap().check(&range) {
|
if CHECKER.get().unwrap().check(&range) {
|
||||||
Some(Mmio {
|
Some(IoMem {
|
||||||
virtual_address: crate::vm::paddr_to_vaddr(range.start),
|
virtual_address: crate::vm::paddr_to_vaddr(range.start),
|
||||||
limit: range.len(),
|
limit: range.len(),
|
||||||
})
|
})
|
@ -24,7 +24,7 @@ pub mod config;
|
|||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
mod error;
|
mod error;
|
||||||
pub mod logger;
|
pub mod logger;
|
||||||
pub mod mmio;
|
pub mod io_mem;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
pub mod task;
|
pub mod task;
|
||||||
@ -52,7 +52,7 @@ pub fn init() {
|
|||||||
vm::init();
|
vm::init();
|
||||||
trap::init();
|
trap::init();
|
||||||
arch::after_all_init();
|
arch::after_all_init();
|
||||||
mmio::init();
|
io_mem::init();
|
||||||
bus::init();
|
bus::init();
|
||||||
register_irq_common_callback();
|
register_irq_common_callback();
|
||||||
invoke_c_init_funcs();
|
invoke_c_init_funcs();
|
||||||
|
@ -13,7 +13,7 @@ use core::{
|
|||||||
};
|
};
|
||||||
use font8x8::UnicodeFonts;
|
use font8x8::UnicodeFonts;
|
||||||
use jinux_frame::{
|
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;
|
use spin::Once;
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ pub(crate) fn init() {
|
|||||||
let page_size = size / PAGE_SIZE;
|
let page_size = size / PAGE_SIZE;
|
||||||
|
|
||||||
let start_paddr = i.address.as_ptr().unwrap().addr();
|
let start_paddr = i.address.as_ptr().unwrap().addr();
|
||||||
let mmio =
|
let io_mem =
|
||||||
Mmio::new(start_paddr..(start_paddr + jinux_frame::config::PAGE_SIZE * page_size))
|
IoMem::new(start_paddr..(start_paddr + jinux_frame::config::PAGE_SIZE * page_size))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut buffer: Vec<u8> = Vec::with_capacity(size);
|
let mut buffer: Vec<u8> = Vec::with_capacity(size);
|
||||||
@ -53,7 +53,7 @@ pub(crate) fn init() {
|
|||||||
log::debug!("Found framebuffer:{:?}", *i);
|
log::debug!("Found framebuffer:{:?}", *i);
|
||||||
|
|
||||||
writer = Some(Writer {
|
writer = Some(Writer {
|
||||||
mmio,
|
io_mem,
|
||||||
x_pos: 0,
|
x_pos: 0,
|
||||||
y_pos: 0,
|
y_pos: 0,
|
||||||
bytes_per_pixel: (i.bpp / 8) as usize,
|
bytes_per_pixel: (i.bpp / 8) as usize,
|
||||||
@ -70,7 +70,7 @@ pub(crate) fn init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Writer {
|
pub(crate) struct Writer {
|
||||||
mmio: Mmio,
|
io_mem: IoMem,
|
||||||
/// FIXME: remove buffer. The meaning of buffer is to facilitate the various operations of framebuffer
|
/// FIXME: remove buffer. The meaning of buffer is to facilitate the various operations of framebuffer
|
||||||
buffer: &'static mut [u8],
|
buffer: &'static mut [u8],
|
||||||
|
|
||||||
@ -97,14 +97,14 @@ impl Writer {
|
|||||||
self.x_pos = 0;
|
self.x_pos = 0;
|
||||||
self.y_pos = 0;
|
self.y_pos = 0;
|
||||||
self.buffer.fill(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
|
/// Everything moves up one letter in size
|
||||||
fn shift_lines_up(&mut self) {
|
fn shift_lines_up(&mut self) {
|
||||||
let offset = self.bytes_per_pixel * 8;
|
let offset = self.bytes_per_pixel * 8;
|
||||||
self.buffer.copy_within(offset.., 0);
|
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;
|
self.y_pos -= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ impl Writer {
|
|||||||
self.buffer
|
self.buffer
|
||||||
.index_mut(byte_offset..(byte_offset + bytes_per_pixel))
|
.index_mut(byte_offset..(byte_offset + bytes_per_pixel))
|
||||||
.copy_from_slice(&color[..bytes_per_pixel]);
|
.copy_from_slice(&color[..bytes_per_pixel]);
|
||||||
self.mmio
|
self.io_mem
|
||||||
.write_bytes(
|
.write_bytes(
|
||||||
byte_offset,
|
byte_offset,
|
||||||
self.buffer
|
self.buffer
|
||||||
|
@ -5,7 +5,7 @@ use core::marker::PhantomData;
|
|||||||
|
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use jinux_frame::{
|
use jinux_frame::{
|
||||||
mmio::Mmio,
|
io_mem::IoMem,
|
||||||
vm::{Paddr, VmFrame, VmIo},
|
vm::{Paddr, VmFrame, VmIo},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
@ -13,14 +13,14 @@ use pod::Pod;
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum InFramePtrAccessMethod {
|
enum InFramePtrAccessMethod {
|
||||||
Mmio(Mmio),
|
IoMem(IoMem),
|
||||||
VmFrame(Arc<VmFrame>),
|
VmFrame(Arc<VmFrame>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InFramePtrAccessMethod {
|
impl InFramePtrAccessMethod {
|
||||||
fn read_val<T: Pod>(&self, offset: usize) -> Result<T> {
|
fn read_val<T: Pod>(&self, offset: usize) -> Result<T> {
|
||||||
match self {
|
match self {
|
||||||
InFramePtrAccessMethod::Mmio(mmio) => mmio.read_val(offset),
|
InFramePtrAccessMethod::IoMem(mmio) => mmio.read_val(offset),
|
||||||
InFramePtrAccessMethod::VmFrame(frame) => frame.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> {
|
pub fn new(paddr: Paddr) -> Result<Self> {
|
||||||
let limit = core::mem::size_of::<T>();
|
let limit = core::mem::size_of::<T>();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
access_method: InFramePtrAccessMethod::Mmio(
|
access_method: InFramePtrAccessMethod::IoMem(
|
||||||
jinux_frame::mmio::Mmio::new(paddr..paddr + limit).unwrap(),
|
jinux_frame::io_mem::IoMem::new(paddr..paddr + limit).unwrap(),
|
||||||
),
|
),
|
||||||
offset: 0,
|
offset: 0,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
@ -73,7 +73,7 @@ impl<T: Pod> InFramePtr<T> {
|
|||||||
|
|
||||||
pub fn read_at<F: Pod>(&self, offset: *const F) -> F {
|
pub fn read_at<F: Pod>(&self, offset: *const F) -> F {
|
||||||
match &self.access_method {
|
match &self.access_method {
|
||||||
InFramePtrAccessMethod::Mmio(mmio) => mmio
|
InFramePtrAccessMethod::IoMem(mmio) => mmio
|
||||||
.read_val::<F>(self.offset + offset as usize)
|
.read_val::<F>(self.offset + offset as usize)
|
||||||
.expect("write data from frame failed"),
|
.expect("write data from frame failed"),
|
||||||
InFramePtrAccessMethod::VmFrame(vm_frame) => vm_frame
|
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) {
|
pub fn write_at<F: Pod>(&self, offset: *const F, new_val: F) {
|
||||||
match &self.access_method {
|
match &self.access_method {
|
||||||
InFramePtrAccessMethod::Mmio(mmio) => mmio
|
InFramePtrAccessMethod::IoMem(mmio) => mmio
|
||||||
.write_val::<F>(self.offset + offset as usize, &new_val)
|
.write_val::<F>(self.offset + offset as usize, &new_val)
|
||||||
.expect("write data from frame failed"),
|
.expect("write data from frame failed"),
|
||||||
InFramePtrAccessMethod::VmFrame(vm_frame) => vm_frame
|
InFramePtrAccessMethod::VmFrame(vm_frame) => vm_frame
|
||||||
@ -99,7 +99,7 @@ impl<T: Pod> InFramePtr<T> {
|
|||||||
|
|
||||||
pub fn paddr(&self) -> usize {
|
pub fn paddr(&self) -> usize {
|
||||||
match &self.access_method {
|
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(),
|
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 {
|
pub fn add(&self, count: usize) -> Self {
|
||||||
let mut next: InFramePtr<T> = self.clone();
|
let mut next: InFramePtr<T> = self.clone();
|
||||||
next.access_method = match next.access_method {
|
next.access_method = match next.access_method {
|
||||||
InFramePtrAccessMethod::Mmio(mmio) => InFramePtrAccessMethod::Mmio(
|
InFramePtrAccessMethod::IoMem(mmio) => InFramePtrAccessMethod::IoMem(
|
||||||
jinux_frame::mmio::Mmio::new(
|
jinux_frame::io_mem::IoMem::new(
|
||||||
mmio.paddr() + count * core::mem::size_of::<T>()
|
mmio.paddr() + count * core::mem::size_of::<T>()
|
||||||
..mmio.paddr() + (count + 1) * core::mem::size_of::<T>(),
|
..mmio.paddr() + (count + 1) * core::mem::size_of::<T>(),
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user