mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-21 16:33:24 +00:00
Implement a new set of physical page APIs
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
6e1c36965a
commit
cdac59beda
@ -141,13 +141,13 @@ impl DeviceInner {
|
||||
let queue = VirtQueue::new(0, Self::QUEUE_SIZE, transport.as_mut())
|
||||
.expect("create virtqueue failed");
|
||||
let block_requests = {
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::Bidirectional, false).unwrap()
|
||||
let segment = FrameAllocOptions::new().alloc_segment(1).unwrap();
|
||||
DmaStream::map(segment.into(), DmaDirection::Bidirectional, false).unwrap()
|
||||
};
|
||||
assert!(Self::QUEUE_SIZE as usize * REQ_SIZE <= block_requests.nbytes());
|
||||
let block_responses = {
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::Bidirectional, false).unwrap()
|
||||
let segment = FrameAllocOptions::new().alloc_segment(1).unwrap();
|
||||
DmaStream::map(segment.into(), DmaDirection::Bidirectional, false).unwrap()
|
||||
};
|
||||
assert!(Self::QUEUE_SIZE as usize * RESP_SIZE <= block_responses.nbytes());
|
||||
|
||||
@ -261,11 +261,11 @@ impl DeviceInner {
|
||||
};
|
||||
const MAX_ID_LENGTH: usize = 20;
|
||||
let device_id_stream = {
|
||||
let segment = FrameAllocOptions::new(1)
|
||||
.uninit(true)
|
||||
.alloc_contiguous()
|
||||
let segment = FrameAllocOptions::new()
|
||||
.zeroed(false)
|
||||
.alloc_segment(1)
|
||||
.unwrap();
|
||||
DmaStream::map(segment, DmaDirection::FromDevice, false).unwrap()
|
||||
DmaStream::map(segment.into(), DmaDirection::FromDevice, false).unwrap()
|
||||
};
|
||||
let device_id_slice = DmaStreamSlice::new(&device_id_stream, 0, MAX_ID_LENGTH);
|
||||
let outputs = vec![&device_id_slice, &resp_slice];
|
||||
|
@ -87,13 +87,13 @@ impl ConsoleDevice {
|
||||
SpinLock::new(VirtQueue::new(TRANSMIT0_QUEUE_INDEX, 2, transport.as_mut()).unwrap());
|
||||
|
||||
let send_buffer = {
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::ToDevice, false).unwrap()
|
||||
let segment = FrameAllocOptions::new().alloc_segment(1).unwrap();
|
||||
DmaStream::map(segment.into(), DmaDirection::ToDevice, false).unwrap()
|
||||
};
|
||||
|
||||
let receive_buffer = {
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::FromDevice, false).unwrap()
|
||||
let segment = FrameAllocOptions::new().alloc_segment(1).unwrap();
|
||||
DmaStream::map(segment.into(), DmaDirection::FromDevice, false).unwrap()
|
||||
};
|
||||
|
||||
let device = Arc::new(Self {
|
||||
|
@ -261,14 +261,14 @@ impl EventTable {
|
||||
fn new(num_events: usize) -> Self {
|
||||
assert!(num_events * mem::size_of::<VirtioInputEvent>() <= PAGE_SIZE);
|
||||
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
let segment = FrameAllocOptions::new().alloc_segment(1).unwrap();
|
||||
|
||||
let default_event = VirtioInputEvent::default();
|
||||
let iter = iter::repeat(&default_event).take(EVENT_SIZE);
|
||||
let nr_written = vm_segment.write_vals(0, iter, 0).unwrap();
|
||||
let nr_written = segment.write_vals(0, iter, 0).unwrap();
|
||||
assert_eq!(nr_written, EVENT_SIZE);
|
||||
|
||||
let stream = DmaStream::map(vm_segment, DmaDirection::FromDevice, false).unwrap();
|
||||
let stream = DmaStream::map(segment.into(), DmaDirection::FromDevice, false).unwrap();
|
||||
Self { stream, num_events }
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ impl VirtQueue {
|
||||
}
|
||||
|
||||
let (descriptor_ptr, avail_ring_ptr, used_ring_ptr) = if transport.is_legacy_version() {
|
||||
// Currently, we use one UntypedFrame to place the descriptors and available rings, one UntypedFrame to place used rings
|
||||
// Currently, we use one DynUFrame to place the descriptors and available rings, one DynUFrame to place used rings
|
||||
// because the virtio-mmio legacy required the address to be continuous. The max queue size is 128.
|
||||
if size > 128 {
|
||||
return Err(QueueError::InvalidArgs);
|
||||
@ -89,8 +89,8 @@ impl VirtQueue {
|
||||
let align_size = VirtioPciLegacyTransport::QUEUE_ALIGN_SIZE;
|
||||
let total_frames =
|
||||
VirtioPciLegacyTransport::calc_virtqueue_size_aligned(queue_size) / align_size;
|
||||
let continue_segment = FrameAllocOptions::new(total_frames)
|
||||
.alloc_contiguous()
|
||||
let continue_segment = FrameAllocOptions::new()
|
||||
.alloc_segment(total_frames)
|
||||
.unwrap();
|
||||
|
||||
let avial_size = size_of::<u16>() * (3 + queue_size);
|
||||
@ -99,12 +99,12 @@ impl VirtQueue {
|
||||
continue_segment.split(seg1_frames * align_size)
|
||||
};
|
||||
let desc_frame_ptr: SafePtr<Descriptor, DmaCoherent> =
|
||||
SafePtr::new(DmaCoherent::map(seg1, true).unwrap(), 0);
|
||||
SafePtr::new(DmaCoherent::map(seg1.into(), true).unwrap(), 0);
|
||||
let mut avail_frame_ptr: SafePtr<AvailRing, DmaCoherent> =
|
||||
desc_frame_ptr.clone().cast();
|
||||
avail_frame_ptr.byte_add(desc_size);
|
||||
let used_frame_ptr: SafePtr<UsedRing, DmaCoherent> =
|
||||
SafePtr::new(DmaCoherent::map(seg2, true).unwrap(), 0);
|
||||
SafePtr::new(DmaCoherent::map(seg2.into(), true).unwrap(), 0);
|
||||
(desc_frame_ptr, avail_frame_ptr, used_frame_ptr)
|
||||
} else {
|
||||
if size > 256 {
|
||||
@ -112,18 +112,27 @@ impl VirtQueue {
|
||||
}
|
||||
(
|
||||
SafePtr::new(
|
||||
DmaCoherent::map(FrameAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
.unwrap(),
|
||||
DmaCoherent::map(
|
||||
FrameAllocOptions::new().alloc_segment(1).unwrap().into(),
|
||||
true,
|
||||
)
|
||||
.unwrap(),
|
||||
0,
|
||||
),
|
||||
SafePtr::new(
|
||||
DmaCoherent::map(FrameAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
.unwrap(),
|
||||
DmaCoherent::map(
|
||||
FrameAllocOptions::new().alloc_segment(1).unwrap().into(),
|
||||
true,
|
||||
)
|
||||
.unwrap(),
|
||||
0,
|
||||
),
|
||||
SafePtr::new(
|
||||
DmaCoherent::map(FrameAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
.unwrap(),
|
||||
DmaCoherent::map(
|
||||
FrameAllocOptions::new().alloc_segment(1).unwrap().into(),
|
||||
true,
|
||||
)
|
||||
.unwrap(),
|
||||
0,
|
||||
),
|
||||
)
|
||||
|
Reference in New Issue
Block a user