bindings.rs0.00%
1
// Copyright 2025 Google LLC2
//3
// Licensed under the Apache License, Version 2.0 (the "License");4
// you may not use this file except in compliance with the License.5
// You may obtain a copy of the License at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// distributed under the License is distributed on an "AS IS" BASIS,11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12
// See the License for the specific language governing permissions and13
// limitations under the License.14
15
use bitfield::bitfield;16
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};17
18
use crate::{bitflags, consts};19
20
bitflags! {21
pub struct VuFeature(u64) {22
MQ = 1 << 0;23
LOG_SHMFD = 1 << 1;24
RARP = 1 << 2;25
REPLY_ACK = 1 << 3;26
MTU = 1 << 4;27
BACKEND_REQ = 1 << 5;28
CROSS_ENDIAN = 1 << 6;29
CRYPTO_SESSION = 1 << 7;30
PAGEFAULT = 1 << 8;31
CONFIG = 1 << 9;32
BACKEND_SEND_FD = 1 << 10;33
HOST_NOTIFIER = 1 << 11;34
INFLIGHT_SHMFD = 1 << 12;35
RESET_DEVICE = 1 << 13;36
INBAND_NOTIFICATIONS = 1 << 14;37
CONFIGURE_MEM_SLOTS = 1 << 15;38
STATUS = 1 << 16;39
XEN_MMAP = 1 << 17;40
SHARED_OBJECT = 1 << 18;41
DEVICE_STATE = 1 << 19;42
}43
}44
45
consts! {46
pub struct VuFrontMsg(u32) {47
GET_FEATURES = 1;48
SET_FEATURES = 2;49
SET_OWNER = 3;50
RESET_OWNER = 4;51
SET_MEM_TABLE = 5;52
SET_LOG_BASE = 6;53
SET_LOG_FD = 7;54
SET_VIRTQ_NUM = 8;55
SET_VIRTQ_ADDR = 9;56
SET_VIRTQ_BASE = 10;57
GET_VIRTQ_BASE = 11;58
SET_VIRTQ_KICK = 12;59
SET_VIRTQ_CALL = 13;60
SET_VIRTQ_ERR = 14;61
GET_PROTOCOL_FEATURES = 15;62
SET_PROTOCOL_FEATURES = 16;63
GET_QUEUE_NUM = 17;64
SET_VIRTQ_ENABLE = 18;65
SEND_RARP = 19;66
NET_SET_MTU = 20;67
SET_BACKEND_REQ_FD = 21;68
IOTLB_MSG = 22;69
SET_VIRTQ_ENDIAN = 23;70
GET_CONFIG = 24;71
SET_CONFIG = 25;72
CREATE_CRYPTO_SESSION = 26;73
CLOSE_CRYPTO_SESSION = 27;74
POSTCOPY_ADVISE = 28;75
POSTCOPY_LISTEN = 29;76
POSTCOPY_END = 30;77
GET_INFLIGHT_FD = 31;78
SET_INFLIGHT_FD = 32;79
GPU_SET_SOCKET = 33;80
RESET_DEVICE = 34;81
GET_MAX_MEM_SLOTS = 36;82
ADD_MEM_REG = 37;83
REM_MEM_REG = 38;84
SET_STATUS = 39;85
GET_STATUS = 40;86
GET_SHARED_OBJECT = 41;87
SET_DEVICE_STATE_FD = 42;88
CHECK_DEVICE_STATE = 43;89
}90
}91
92
consts! {93
pub struct VuFrontMsgSize((u32, usize)) {94
GET_FEATURES = (0, size_of::<u64>());95
}96
}97
98
consts! {99
pub struct VuBackMsg(u32) {100
IOTLB_MSG = 1;101
CONFIG_CHANGE_MSG = 2;102
VIRTQ_HOST_NOTIFIER_MSG = 3;103
VIRTQ_CALL = 4;104
VIRTQ_ERR = 5;105
SHARED_OBJECT_ADD = 6;106
SHARED_OBJECT_REMOVE = 7;107
SHARED_OBJECT_LOOKUP = 8;108
}109
}110
111
bitfield! {112
#[derive(Copy, Clone, Default, IntoBytes, FromBytes, Immutable)]113
#[repr(transparent)]114
pub struct MessageFlag(u32);115
impl Debug;116
pub need_reply, set_need_reply: 3;117
pub reply, set_reply: 2;118
pub version, set_version: 1, 0;119
}120
121
impl MessageFlag {122
pub const NEED_REPLY: u32 = 1 << 3;123
pub const REPLY: u32 = 1 << 2;124
pub const VERSION_1: u32 = 0x1;125
126
pub const fn sender() -> Self {127
MessageFlag(MessageFlag::VERSION_1 | MessageFlag::NEED_REPLY)128
}129
130
pub const fn receiver() -> Self {131
MessageFlag(MessageFlag::VERSION_1 | MessageFlag::REPLY)132
}133
}134
135
#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]136
#[repr(C)]137
pub struct VirtqState {138
pub index: u32,139
pub val: u32,140
}141
142
#[derive(Debug, Clone, IntoBytes, FromBytes, Immutable, KnownLayout)]143
#[repr(C)]144
pub struct VirtqAddr {145
pub index: u32,146
pub flags: u32,147
pub desc_hva: u64,148
pub used_hva: u64,149
pub avail_hva: u64,150
pub log_guest_addr: u64,151
}152
153
#[derive(Debug, Clone, IntoBytes, FromBytes, Immutable, KnownLayout)]154
#[repr(C)]155
pub struct MemoryRegion {156
pub gpa: u64,157
pub size: u64,158
pub hva: u64,159
pub mmap_offset: u64,160
}161
162
#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]163
#[repr(C)]164
pub struct MemorySingleRegion {165
pub _padding: u64,166
pub region: MemoryRegion,167
}168
169
#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]170
#[repr(C)]171
pub struct MemoryMultipleRegion {172
pub num: u32,173
pub _padding: u32,174
pub regions: [MemoryRegion; 8],175
}176
177
pub const MAX_CONFIG_SIZE: usize = 256;178
179
#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]180
#[repr(C)]181
pub struct DeviceConfig {182
pub offset: u32,183
pub size: u32,184
pub flags: u32,185
}186
187
#[derive(Debug, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]188
#[repr(C)]189
pub struct FsMap {190
pub fd_offset: [u64; 8],191
pub cache_offset: [u64; 8],192
pub len: [u64; 8],193
pub flags: [u64; 8],194
}195
196
#[derive(Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]197
#[repr(C)]198
pub struct Message {199
pub request: u32,200
pub flag: MessageFlag,201
pub size: u32,202
}203