|
@@ -1,6 +1,6 @@
|
|
|
use super::*;
|
|
|
use crate::queue::VirtQueue;
|
|
|
-use crate::transport::{mmio::VirtIOHeader, Transport};
|
|
|
+use crate::transport::Transport;
|
|
|
use bitflags::*;
|
|
|
use core::{fmt, hint::spin_loop};
|
|
|
use log::*;
|
|
@@ -13,8 +13,8 @@ use volatile::{ReadOnly, Volatile, WriteOnly};
|
|
|
/// a gpu with 3D support on the host machine.
|
|
|
/// In 2D mode the virtio-gpu device provides support for ARGB Hardware cursors
|
|
|
/// and multiple scanouts (aka heads).
|
|
|
-pub struct VirtIOGpu<'a, H: Hal> {
|
|
|
- header: &'static mut VirtIOHeader,
|
|
|
+pub struct VirtIOGpu<'a, H: Hal, T: Transport> {
|
|
|
+ transport: &'a mut T,
|
|
|
rect: Rect,
|
|
|
/// DMA area of frame buffer.
|
|
|
frame_buffer_dma: Option<DMA<H>>,
|
|
@@ -32,10 +32,10 @@ pub struct VirtIOGpu<'a, H: Hal> {
|
|
|
queue_buf_recv: &'a mut [u8],
|
|
|
}
|
|
|
|
|
|
-impl<H: Hal> VirtIOGpu<'_, H> {
|
|
|
+impl<'a, H: Hal, T: Transport> VirtIOGpu<'a, H, T> {
|
|
|
/// Create a new VirtIO-Gpu driver.
|
|
|
- pub fn new(header: &'static mut VirtIOHeader) -> Result<Self> {
|
|
|
- header.begin_init(|features| {
|
|
|
+ pub fn new(transport: &'a mut T) -> Result<Self> {
|
|
|
+ transport.begin_init(|features| {
|
|
|
let features = Features::from_bits_truncate(features);
|
|
|
info!("Device features {:?}", features);
|
|
|
let supported_features = Features::empty();
|
|
@@ -43,20 +43,20 @@ impl<H: Hal> VirtIOGpu<'_, H> {
|
|
|
});
|
|
|
|
|
|
// read configuration space
|
|
|
- let config = unsafe { &mut *(header.config_space() as *mut Config) };
|
|
|
+ let config = unsafe { &mut *(transport.config_space() as *mut Config) };
|
|
|
info!("Config: {:?}", config);
|
|
|
|
|
|
- let control_queue = VirtQueue::new(header, QUEUE_TRANSMIT, 2)?;
|
|
|
- let cursor_queue = VirtQueue::new(header, QUEUE_CURSOR, 2)?;
|
|
|
+ let control_queue = VirtQueue::new(transport, QUEUE_TRANSMIT, 2)?;
|
|
|
+ let cursor_queue = VirtQueue::new(transport, QUEUE_CURSOR, 2)?;
|
|
|
|
|
|
let queue_buf_dma = DMA::new(2)?;
|
|
|
let queue_buf_send = unsafe { &mut queue_buf_dma.as_buf()[..PAGE_SIZE] };
|
|
|
let queue_buf_recv = unsafe { &mut queue_buf_dma.as_buf()[PAGE_SIZE..] };
|
|
|
|
|
|
- header.finish_init();
|
|
|
+ transport.finish_init();
|
|
|
|
|
|
Ok(VirtIOGpu {
|
|
|
- header,
|
|
|
+ transport,
|
|
|
frame_buffer_dma: None,
|
|
|
cursor_buffer_dma: None,
|
|
|
rect: Rect::default(),
|
|
@@ -70,7 +70,7 @@ impl<H: Hal> VirtIOGpu<'_, H> {
|
|
|
|
|
|
/// Acknowledge interrupt.
|
|
|
pub fn ack_interrupt(&mut self) -> bool {
|
|
|
- self.header.ack_interrupt()
|
|
|
+ self.transport.ack_interrupt()
|
|
|
}
|
|
|
|
|
|
/// Get the resolution (width, height).
|
|
@@ -162,7 +162,7 @@ impl<H: Hal> VirtIOGpu<'_, H> {
|
|
|
}
|
|
|
self.control_queue
|
|
|
.add(&[self.queue_buf_send], &[self.queue_buf_recv])?;
|
|
|
- self.header.notify(QUEUE_TRANSMIT as u32);
|
|
|
+ self.transport.notify(QUEUE_TRANSMIT as u32);
|
|
|
while !self.control_queue.can_pop() {
|
|
|
spin_loop();
|
|
|
}
|
|
@@ -176,7 +176,7 @@ impl<H: Hal> VirtIOGpu<'_, H> {
|
|
|
(self.queue_buf_send.as_mut_ptr() as *mut Req).write(req);
|
|
|
}
|
|
|
self.cursor_queue.add(&[self.queue_buf_send], &[])?;
|
|
|
- self.header.notify(QUEUE_CURSOR as u32);
|
|
|
+ self.transport.notify(QUEUE_CURSOR as u32);
|
|
|
while !self.cursor_queue.can_pop() {
|
|
|
spin_loop();
|
|
|
}
|