rutabaga_gfx/cross_domain/
cross_domain_protocol.rs

1// Copyright 2021 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Hand-written protocol for the cross-domain context type.  Intended to be shared with C/C++
6//! components.
7
8#![allow(dead_code)]
9
10use zerocopy::AsBytes;
11use zerocopy::FromBytes;
12use zerocopy::FromZeroes;
13
14/// Cross-domain commands (only a maximum of 255 supported)
15pub const CROSS_DOMAIN_CMD_INIT: u8 = 1;
16pub const CROSS_DOMAIN_CMD_GET_IMAGE_REQUIREMENTS: u8 = 2;
17pub const CROSS_DOMAIN_CMD_POLL: u8 = 3;
18pub const CROSS_DOMAIN_CMD_SEND: u8 = 4;
19pub const CROSS_DOMAIN_CMD_RECEIVE: u8 = 5;
20pub const CROSS_DOMAIN_CMD_READ: u8 = 6;
21pub const CROSS_DOMAIN_CMD_WRITE: u8 = 7;
22
23/// Channel types (must match rutabaga channel types)
24pub const CROSS_DOMAIN_CHANNEL_TYPE_WAYLAND: u32 = 0x0001;
25pub const CROSS_DOMAIN_CHANNEL_TYPE_CAMERA: u32 = 0x0002;
26
27/// The maximum number of identifiers
28pub const CROSS_DOMAIN_MAX_IDENTIFIERS: usize = 28;
29
30/// virtgpu memory resource ID.  Also works with non-blob memory resources, despite the name.
31pub const CROSS_DOMAIN_ID_TYPE_VIRTGPU_BLOB: u32 = 1;
32/// virtgpu synchronization resource id.
33pub const CROSS_DOMAIN_ID_TYPE_VIRTGPU_SYNC: u32 = 2;
34/// ID for Wayland pipe used for reading.  The reading is done by the guest proxy and the host
35/// proxy.  The host sends the write end of the proxied pipe over the host Wayland socket.
36pub const CROSS_DOMAIN_ID_TYPE_READ_PIPE: u32 = 3;
37/// ID for Wayland pipe used for writing.  The writing is done by the guest and the host proxy.
38/// The host receives the write end of the pipe over the host Wayland socket.
39pub const CROSS_DOMAIN_ID_TYPE_WRITE_PIPE: u32 = 4;
40
41/// No ring
42pub const CROSS_DOMAIN_RING_NONE: u32 = 0xffffffff;
43/// A ring for metadata queries.
44pub const CROSS_DOMAIN_QUERY_RING: u32 = 0;
45/// A ring based on this particular context's channel.
46pub const CROSS_DOMAIN_CHANNEL_RING: u32 = 1;
47
48/// Read pipe IDs start at this value.
49pub const CROSS_DOMAIN_PIPE_READ_START: u32 = 0x80000000;
50
51#[repr(C)]
52#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
53pub struct CrossDomainCapabilities {
54    pub version: u32,
55    pub supported_channels: u32,
56    pub supports_dmabuf: u32,
57    pub supports_external_gpu_memory: u32,
58}
59
60#[repr(C)]
61#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
62pub struct CrossDomainImageRequirements {
63    pub strides: [u32; 4],
64    pub offsets: [u32; 4],
65    pub modifier: u64,
66    pub size: u64,
67    pub blob_id: u32,
68    pub map_info: u32,
69    pub memory_idx: i32,
70    pub physical_device_idx: i32,
71}
72
73#[repr(C)]
74#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
75pub struct CrossDomainHeader {
76    pub cmd: u8,
77    pub ring_idx: u8,
78    pub cmd_size: u16,
79    pub pad: u32,
80}
81
82#[repr(C)]
83#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
84pub struct CrossDomainInit {
85    pub hdr: CrossDomainHeader,
86    pub query_ring_id: u32,
87    pub channel_ring_id: u32,
88    pub channel_type: u32,
89}
90
91#[repr(C)]
92#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
93pub struct CrossDomainGetImageRequirements {
94    pub hdr: CrossDomainHeader,
95    pub width: u32,
96    pub height: u32,
97    pub drm_format: u32,
98    pub flags: u32,
99}
100
101#[repr(C)]
102#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
103pub struct CrossDomainSendReceive {
104    pub hdr: CrossDomainHeader,
105    pub num_identifiers: u32,
106    pub opaque_data_size: u32,
107    pub identifiers: [u32; CROSS_DOMAIN_MAX_IDENTIFIERS],
108    pub identifier_types: [u32; CROSS_DOMAIN_MAX_IDENTIFIERS],
109    pub identifier_sizes: [u32; CROSS_DOMAIN_MAX_IDENTIFIERS],
110    // Data of size "opaque data size follows"
111}
112
113#[repr(C)]
114#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
115pub struct CrossDomainReadWrite {
116    pub hdr: CrossDomainHeader,
117    pub identifier: u32,
118    pub hang_up: u32,
119    pub opaque_data_size: u32,
120    pub pad: u32,
121    // Data of size "opaque data size follows"
122}