mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-28 20:03:22 +00:00
Fix DMA coherent
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
cea4fd7777
commit
69f0954271
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use core::{arch::x86_64::_mm_clflush, ops::Range};
|
use core::ops::Range;
|
||||||
|
|
||||||
#[cfg(feature = "intel_tdx")]
|
#[cfg(feature = "intel_tdx")]
|
||||||
use ::tdx_guest::tdx_is_enabled;
|
use ::tdx_guest::tdx_is_enabled;
|
||||||
@ -132,22 +132,28 @@ impl DmaStream {
|
|||||||
///
|
///
|
||||||
/// [`read_bytes`]: Self::read_bytes
|
/// [`read_bytes`]: Self::read_bytes
|
||||||
/// [`write_bytes`]: Self::write_bytes
|
/// [`write_bytes`]: Self::write_bytes
|
||||||
pub fn sync(&self, byte_range: Range<usize>) -> Result<(), Error> {
|
pub fn sync(&self, _byte_range: Range<usize>) -> Result<(), Error> {
|
||||||
if byte_range.end > self.nbytes() {
|
cfg_if::cfg_if! {
|
||||||
return Err(Error::InvalidArgs);
|
if #[cfg(target_arch = "x86_64")]{
|
||||||
}
|
// The streaming DMA mapping in x86_64 is cache coherent, and does not require synchronization.
|
||||||
if self.inner.is_cache_coherent {
|
// Reference: <https://lwn.net/Articles/855328/>, <https://lwn.net/Articles/2265/>
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
} else {
|
||||||
let start_va = self.inner.vm_segment.as_ptr();
|
if _byte_range.end > self.nbytes() {
|
||||||
// TODO: Query the CPU for the cache line size via CPUID, we use 64 bytes as the cache line size here.
|
return Err(Error::InvalidArgs);
|
||||||
for i in byte_range.step_by(64) {
|
}
|
||||||
// SAFETY: the addresses is limited by a valid `byte_range`.
|
if self.inner.is_cache_coherent {
|
||||||
unsafe {
|
return Ok(());
|
||||||
_mm_clflush(start_va.wrapping_add(i));
|
}
|
||||||
|
let start_va = self.inner.vm_segment.as_ptr();
|
||||||
|
// TODO: Query the CPU for the cache line size via CPUID, we use 64 bytes as the cache line size here.
|
||||||
|
for i in _byte_range.step_by(64) {
|
||||||
|
// TODO: Call the cache line flush command in the corresponding architecture.
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user