Skip to content

Commit

Permalink
Add X11 cross domain channel type.
Browse files Browse the repository at this point in the history
This adds the X11 cross domain channel and an ability to share
futexes between the vm and the host.

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Co-developed-by: Asahi Lina <lina@asahilina.net>
Signed-off-by: Asahi Lina <lina@asahilina.net>
  • Loading branch information
WhatAmISupposedToPutHere authored and asahilina committed Oct 22, 2024
1 parent 7bcf9d0 commit 2e34485
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 13 deletions.
24 changes: 17 additions & 7 deletions src/devices/src/virtio/gpu/virtio_gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rutabaga_gfx::RUTABAGA_MEM_HANDLE_TYPE_SHM;
use rutabaga_gfx::{
ResourceCreate3D, ResourceCreateBlob, Rutabaga, RutabagaBuilder, RutabagaChannel,
RutabagaFence, RutabagaFenceHandler, RutabagaIovec, Transfer3D, RUTABAGA_CHANNEL_TYPE_WAYLAND,
RUTABAGA_MAP_CACHE_MASK,
RUTABAGA_CHANNEL_TYPE_X11, RUTABAGA_MAP_CACHE_MASK,
};
#[cfg(target_os = "linux")]
use rutabaga_gfx::{
Expand Down Expand Up @@ -192,12 +192,22 @@ impl VirtioGpu {
Ok(display) => display,
Err(_) => "wayland-0".to_string(),
};
let path = PathBuf::from(format!("{}/{}", xdg_runtime_dir, wayland_display));

let rutabaga_channels: Vec<RutabagaChannel> = vec![RutabagaChannel {
base_channel: path,
channel_type: RUTABAGA_CHANNEL_TYPE_WAYLAND,
}];
let wayland_path = PathBuf::from(format!("{}/{}", xdg_runtime_dir, wayland_display));
let x_display = match env::var("DISPLAY") {
Ok(display) => display,
Err(_) => ":0".to_string(),
};
let x_path = PathBuf::from(format!("/tmp/.X11-unix/X{}", &x_display[1..]));
let rutabaga_channels: Vec<RutabagaChannel> = vec![
RutabagaChannel {
base_channel: wayland_path,
channel_type: RUTABAGA_CHANNEL_TYPE_WAYLAND,
},
RutabagaChannel {
base_channel: x_path,
channel_type: RUTABAGA_CHANNEL_TYPE_X11,
},
];
let rutabaga_channels_opt = Some(rutabaga_channels);

let builder = RutabagaBuilder::new(
Expand Down
1 change: 1 addition & 0 deletions src/rutabaga_gfx/ffi/src/include/rutabaga_gfx_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern "C" {
* Rutabaga channel types
*/
#define RUTABAGA_CHANNEL_TYPE_WAYLAND 1
#define RUTABAGA_CHANNEL_TYPE_X11 0x11

/**
* Rutabaga WSI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// Channel types (must match rutabaga channel types)
#define CROSS_DOMAIN_CHANNEL_TYPE_WAYLAND 0x0001
#define CROSS_DOMAIN_CHANNEL_TYPE_CAMERA 0x0002
#define CROSS_DOMAIN_CHANNEL_TYPE_X11 0x0011

// The maximum number of identifiers (value based on wp_linux_dmabuf)
#define CROSS_DOMAIN_MAX_IDENTIFIERS 4
Expand Down
32 changes: 32 additions & 0 deletions src/rutabaga_gfx/src/cross_domain/cross_domain_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ pub const CROSS_DOMAIN_CMD_SEND: u8 = 4;
pub const CROSS_DOMAIN_CMD_RECEIVE: u8 = 5;
pub const CROSS_DOMAIN_CMD_READ: u8 = 6;
pub const CROSS_DOMAIN_CMD_WRITE: u8 = 7;
pub const CROSS_DOMAIN_CMD_FUTEX_NEW: u8 = 8;
pub const CROSS_DOMAIN_CMD_FUTEX_SIGNAL: u8 = 9;
pub const CROSS_DOMAIN_CMD_FUTEX_DESTROY: u8 = 10;

/// Channel types (must match rutabaga channel types)
pub const CROSS_DOMAIN_CHANNEL_TYPE_WAYLAND: u32 = 0x0001;
pub const CROSS_DOMAIN_CHANNEL_TYPE_CAMERA: u32 = 0x0002;
pub const CROSS_DOMAIN_CHANNEL_TYPE_X11: u32 = 0x0011;

/// The maximum number of identifiers (value inspired by wp_linux_dmabuf)
pub const CROSS_DOMAIN_MAX_IDENTIFIERS: usize = 4;
Expand All @@ -37,6 +41,8 @@ pub const CROSS_DOMAIN_ID_TYPE_READ_PIPE: u32 = 3;
/// The host receives the write end of the pipe over the host Wayland socket.
pub const CROSS_DOMAIN_ID_TYPE_WRITE_PIPE: u32 = 4;

pub const CROSS_DOMAIN_ID_TYPE_SHM: u32 = 5;

/// No ring
pub const CROSS_DOMAIN_RING_NONE: u32 = 0xffffffff;
/// A ring for metadata queries.
Expand Down Expand Up @@ -119,3 +125,29 @@ pub struct CrossDomainReadWrite {
pub pad: u32,
// Data of size "opaque data size follows"
}

#[repr(C)]
#[derive(Copy, Clone, Default, AsBytes, FromBytes)]
pub struct CrossDomainFutexNew {
pub hdr: CrossDomainHeader,
pub fs_id: u64,
pub handle: u64,
pub id: u32,
pub pad: u32,
}

#[repr(C)]
#[derive(Copy, Clone, Default, AsBytes, FromBytes)]
pub struct CrossDomainFutexSignal {
pub hdr: CrossDomainHeader,
pub id: u32,
pub pad: u32,
}

#[repr(C)]
#[derive(Copy, Clone, Default, AsBytes, FromBytes)]
pub struct CrossDomainFutexDestroy {
pub hdr: CrossDomainHeader,
pub id: u32,
pub pad: u32,
}
Loading

0 comments on commit 2e34485

Please sign in to comment.