drivers/graphics/graphics-ipc: Nicer version handling of version command

This commit is contained in:
bjorn3
2025-12-14 20:16:53 +01:00
parent 0c8f1b56d7
commit 47d6f879fb
4 changed files with 28 additions and 22 deletions
+14 -4
View File
@@ -1,5 +1,6 @@
#![feature(slice_as_array)]
use std::cmp;
use std::collections::{BTreeMap, HashMap};
use std::fs::File;
use std::io::{self, Write};
@@ -18,8 +19,8 @@ pub trait GraphicsAdapter {
type Framebuffer: Framebuffer;
type Cursor: CursorFramebuffer;
fn name(&self) -> [u8;16];
fn desc(&self) -> [u8;16];
fn name(&self) -> &'static [u8];
fn desc(&self) -> &'static [u8];
fn get_cap(&self, cap: u64) -> Result<u64>;
fn set_client_cap(&self, cap: u64, value: u64) -> Result<()>;
@@ -448,8 +449,17 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsScheme<T> {
payload.version_major = 1;
payload.version_minor = 4;
payload.version_patchlevel = 0;
payload.name = self.adapter.name();
payload.desc = self.adapter.desc();
let name = self.adapter.name();
let name_len = cmp::min(name.len(), payload.name_len);
payload.name[..name_len].copy_from_slice(&name[..name_len]);
payload.name_len = name.len();
let desc = self.adapter.desc();
let desc_len = cmp::min(desc.len(), payload.name_len);
payload.desc[..desc_len].copy_from_slice(&desc[..desc_len]);
payload.desc_len = desc.len();
Ok(size_of::<ipc::DisplayCount>())
}
+2
View File
@@ -160,7 +160,9 @@ pub mod ipc {
pub version_minor: u32,
pub version_patchlevel: u32,
// FIXME allow variable sized fields
pub name_len: usize,
pub name: [u8; 16],
pub desc_len: usize,
pub desc: [u8; 16],
}
+6 -8
View File
@@ -19,27 +19,25 @@ impl GraphicsAdapter for FbAdapter {
type Framebuffer = GraphicScreen;
type Cursor = VesadCursor;
fn name(&self) -> [u8; 16] {
[
b'v', b'e', b's', b'a', b'd', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]
fn name(&self) -> &'static [u8] {
b"vesad"
}
fn desc(&self) -> [u8; 16] {
[b'V', b'E', b'S', b'A', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
fn desc(&self) -> &'static [u8] {
b"VESA"
}
fn get_cap(&self, cap: u64) -> syscall::Result<u64> {
match cap {
CAP_DUMB_BUFFER => Ok(1),
_ => Err(syscall::Error::new(EINVAL))
_ => Err(syscall::Error::new(EINVAL)),
}
}
fn set_client_cap(&self, cap: u64, _value: u64) -> syscall::Result<()> {
match cap {
CLIENT_CAP_CURSOR_PLANE_HOTSPOT => Ok(()),
_ => Err(syscall::Error::new(EINVAL))
_ => Err(syscall::Error::new(EINVAL)),
}
}
+6 -10
View File
@@ -201,22 +201,18 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
type Framebuffer = VirtGpuFramebuffer<'a>;
type Cursor = VirtGpuCursor;
fn name(&self) -> [u8; 16] {
[
b'v', b'i', b'r', b't', b'i', b'o', b'-', b'g', b'p', b'u', b'd', 0, 0, 0, 0, 0,
]
fn name(&self) -> &'static [u8] {
b"virtio-gpud"
}
fn desc(&self) -> [u8; 16] {
[
b'V', b'i', b'r', b't', b'I', b'O', b' ', b'G', b'P', b'U', 0, 0, 0, 0, 0, 0,
]
fn desc(&self) -> &'static [u8] {
b"VirtIO GPU"
}
fn get_cap(&self, cap: u64) -> syscall::Result<u64> {
match cap {
CAP_DUMB_BUFFER => Ok(1),
_ => Err(syscall::Error::new(EINVAL))
_ => Err(syscall::Error::new(EINVAL)),
}
}
@@ -224,7 +220,7 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
match cap {
// FIXME hide cursor plane unless this client cap is set
CLIENT_CAP_CURSOR_PLANE_HOTSPOT => Ok(()),
_ => Err(syscall::Error::new(EINVAL))
_ => Err(syscall::Error::new(EINVAL)),
}
}