Skip to content

Commit 5fa57b9

Browse files
committed
chore(bindgen): add headers for virtio_mem
Automatically generate bindings for virtio-mem. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent 0c10d2c commit 5fa57b9

File tree

3 files changed

+251
-0
lines changed

3 files changed

+251
-0
lines changed

src/vmm/src/devices/virtio/generated/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
pub mod virtio_blk;
1414
pub mod virtio_config;
1515
pub mod virtio_ids;
16+
pub mod virtio_mem;
1617
pub mod virtio_net;
1718
pub mod virtio_ring;
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// automatically generated by tools/bindgen.sh
5+
6+
#![allow(
7+
non_camel_case_types,
8+
non_upper_case_globals,
9+
dead_code,
10+
non_snake_case,
11+
clippy::ptr_as_ptr,
12+
clippy::undocumented_unsafe_blocks,
13+
missing_debug_implementations,
14+
clippy::tests_outside_test_module,
15+
unsafe_op_in_unsafe_fn,
16+
clippy::redundant_static_lifetimes
17+
)]
18+
19+
pub const VIRTIO_MEM_F_ACPI_PXM: u32 = 0;
20+
pub const VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: u32 = 1;
21+
pub const VIRTIO_MEM_F_PERSISTENT_SUSPEND: u32 = 2;
22+
pub const VIRTIO_MEM_REQ_PLUG: u32 = 0;
23+
pub const VIRTIO_MEM_REQ_UNPLUG: u32 = 1;
24+
pub const VIRTIO_MEM_REQ_UNPLUG_ALL: u32 = 2;
25+
pub const VIRTIO_MEM_REQ_STATE: u32 = 3;
26+
pub const VIRTIO_MEM_RESP_ACK: u32 = 0;
27+
pub const VIRTIO_MEM_RESP_NACK: u32 = 1;
28+
pub const VIRTIO_MEM_RESP_BUSY: u32 = 2;
29+
pub const VIRTIO_MEM_RESP_ERROR: u32 = 3;
30+
pub const VIRTIO_MEM_STATE_PLUGGED: u32 = 0;
31+
pub const VIRTIO_MEM_STATE_UNPLUGGED: u32 = 1;
32+
pub const VIRTIO_MEM_STATE_MIXED: u32 = 2;
33+
pub type __u8 = ::std::os::raw::c_uchar;
34+
pub type __u16 = ::std::os::raw::c_ushort;
35+
pub type __u64 = ::std::os::raw::c_ulonglong;
36+
pub type __le16 = __u16;
37+
pub type __le64 = __u64;
38+
pub type __virtio16 = __u16;
39+
pub type __virtio64 = __u64;
40+
#[repr(C)]
41+
#[derive(Debug, Default, Copy, Clone, PartialEq)]
42+
pub struct virtio_mem_req_plug {
43+
pub addr: __virtio64,
44+
pub nb_blocks: __virtio16,
45+
pub padding: [__virtio16; 3usize],
46+
}
47+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
48+
const _: () = {
49+
["Size of virtio_mem_req_plug"][::std::mem::size_of::<virtio_mem_req_plug>() - 16usize];
50+
["Alignment of virtio_mem_req_plug"][::std::mem::align_of::<virtio_mem_req_plug>() - 8usize];
51+
["Offset of field: virtio_mem_req_plug::addr"]
52+
[::std::mem::offset_of!(virtio_mem_req_plug, addr) - 0usize];
53+
["Offset of field: virtio_mem_req_plug::nb_blocks"]
54+
[::std::mem::offset_of!(virtio_mem_req_plug, nb_blocks) - 8usize];
55+
["Offset of field: virtio_mem_req_plug::padding"]
56+
[::std::mem::offset_of!(virtio_mem_req_plug, padding) - 10usize];
57+
};
58+
#[repr(C)]
59+
#[derive(Debug, Default, Copy, Clone, PartialEq)]
60+
pub struct virtio_mem_req_unplug {
61+
pub addr: __virtio64,
62+
pub nb_blocks: __virtio16,
63+
pub padding: [__virtio16; 3usize],
64+
}
65+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
66+
const _: () = {
67+
["Size of virtio_mem_req_unplug"][::std::mem::size_of::<virtio_mem_req_unplug>() - 16usize];
68+
["Alignment of virtio_mem_req_unplug"]
69+
[::std::mem::align_of::<virtio_mem_req_unplug>() - 8usize];
70+
["Offset of field: virtio_mem_req_unplug::addr"]
71+
[::std::mem::offset_of!(virtio_mem_req_unplug, addr) - 0usize];
72+
["Offset of field: virtio_mem_req_unplug::nb_blocks"]
73+
[::std::mem::offset_of!(virtio_mem_req_unplug, nb_blocks) - 8usize];
74+
["Offset of field: virtio_mem_req_unplug::padding"]
75+
[::std::mem::offset_of!(virtio_mem_req_unplug, padding) - 10usize];
76+
};
77+
#[repr(C)]
78+
#[derive(Debug, Default, Copy, Clone, PartialEq)]
79+
pub struct virtio_mem_req_state {
80+
pub addr: __virtio64,
81+
pub nb_blocks: __virtio16,
82+
pub padding: [__virtio16; 3usize],
83+
}
84+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
85+
const _: () = {
86+
["Size of virtio_mem_req_state"][::std::mem::size_of::<virtio_mem_req_state>() - 16usize];
87+
["Alignment of virtio_mem_req_state"][::std::mem::align_of::<virtio_mem_req_state>() - 8usize];
88+
["Offset of field: virtio_mem_req_state::addr"]
89+
[::std::mem::offset_of!(virtio_mem_req_state, addr) - 0usize];
90+
["Offset of field: virtio_mem_req_state::nb_blocks"]
91+
[::std::mem::offset_of!(virtio_mem_req_state, nb_blocks) - 8usize];
92+
["Offset of field: virtio_mem_req_state::padding"]
93+
[::std::mem::offset_of!(virtio_mem_req_state, padding) - 10usize];
94+
};
95+
#[repr(C)]
96+
#[derive(Copy, Clone)]
97+
pub struct virtio_mem_req {
98+
pub type_: __virtio16,
99+
pub padding: [__virtio16; 3usize],
100+
pub u: virtio_mem_req__bindgen_ty_1,
101+
}
102+
#[repr(C)]
103+
#[derive(Copy, Clone)]
104+
pub union virtio_mem_req__bindgen_ty_1 {
105+
pub plug: virtio_mem_req_plug,
106+
pub unplug: virtio_mem_req_unplug,
107+
pub state: virtio_mem_req_state,
108+
}
109+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
110+
const _: () = {
111+
["Size of virtio_mem_req__bindgen_ty_1"]
112+
[::std::mem::size_of::<virtio_mem_req__bindgen_ty_1>() - 16usize];
113+
["Alignment of virtio_mem_req__bindgen_ty_1"]
114+
[::std::mem::align_of::<virtio_mem_req__bindgen_ty_1>() - 8usize];
115+
["Offset of field: virtio_mem_req__bindgen_ty_1::plug"]
116+
[::std::mem::offset_of!(virtio_mem_req__bindgen_ty_1, plug) - 0usize];
117+
["Offset of field: virtio_mem_req__bindgen_ty_1::unplug"]
118+
[::std::mem::offset_of!(virtio_mem_req__bindgen_ty_1, unplug) - 0usize];
119+
["Offset of field: virtio_mem_req__bindgen_ty_1::state"]
120+
[::std::mem::offset_of!(virtio_mem_req__bindgen_ty_1, state) - 0usize];
121+
};
122+
impl Default for virtio_mem_req__bindgen_ty_1 {
123+
fn default() -> Self {
124+
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
125+
unsafe {
126+
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
127+
s.assume_init()
128+
}
129+
}
130+
}
131+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
132+
const _: () = {
133+
["Size of virtio_mem_req"][::std::mem::size_of::<virtio_mem_req>() - 24usize];
134+
["Alignment of virtio_mem_req"][::std::mem::align_of::<virtio_mem_req>() - 8usize];
135+
["Offset of field: virtio_mem_req::type_"]
136+
[::std::mem::offset_of!(virtio_mem_req, type_) - 0usize];
137+
["Offset of field: virtio_mem_req::padding"]
138+
[::std::mem::offset_of!(virtio_mem_req, padding) - 2usize];
139+
["Offset of field: virtio_mem_req::u"][::std::mem::offset_of!(virtio_mem_req, u) - 8usize];
140+
};
141+
impl Default for virtio_mem_req {
142+
fn default() -> Self {
143+
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
144+
unsafe {
145+
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
146+
s.assume_init()
147+
}
148+
}
149+
}
150+
#[repr(C)]
151+
#[derive(Debug, Default, Copy, Clone, PartialEq)]
152+
pub struct virtio_mem_resp_state {
153+
pub state: __virtio16,
154+
}
155+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
156+
const _: () = {
157+
["Size of virtio_mem_resp_state"][::std::mem::size_of::<virtio_mem_resp_state>() - 2usize];
158+
["Alignment of virtio_mem_resp_state"]
159+
[::std::mem::align_of::<virtio_mem_resp_state>() - 2usize];
160+
["Offset of field: virtio_mem_resp_state::state"]
161+
[::std::mem::offset_of!(virtio_mem_resp_state, state) - 0usize];
162+
};
163+
#[repr(C)]
164+
#[derive(Copy, Clone)]
165+
pub struct virtio_mem_resp {
166+
pub type_: __virtio16,
167+
pub padding: [__virtio16; 3usize],
168+
pub u: virtio_mem_resp__bindgen_ty_1,
169+
}
170+
#[repr(C)]
171+
#[derive(Copy, Clone)]
172+
pub union virtio_mem_resp__bindgen_ty_1 {
173+
pub state: virtio_mem_resp_state,
174+
}
175+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
176+
const _: () = {
177+
["Size of virtio_mem_resp__bindgen_ty_1"]
178+
[::std::mem::size_of::<virtio_mem_resp__bindgen_ty_1>() - 2usize];
179+
["Alignment of virtio_mem_resp__bindgen_ty_1"]
180+
[::std::mem::align_of::<virtio_mem_resp__bindgen_ty_1>() - 2usize];
181+
["Offset of field: virtio_mem_resp__bindgen_ty_1::state"]
182+
[::std::mem::offset_of!(virtio_mem_resp__bindgen_ty_1, state) - 0usize];
183+
};
184+
impl Default for virtio_mem_resp__bindgen_ty_1 {
185+
fn default() -> Self {
186+
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
187+
unsafe {
188+
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
189+
s.assume_init()
190+
}
191+
}
192+
}
193+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
194+
const _: () = {
195+
["Size of virtio_mem_resp"][::std::mem::size_of::<virtio_mem_resp>() - 10usize];
196+
["Alignment of virtio_mem_resp"][::std::mem::align_of::<virtio_mem_resp>() - 2usize];
197+
["Offset of field: virtio_mem_resp::type_"]
198+
[::std::mem::offset_of!(virtio_mem_resp, type_) - 0usize];
199+
["Offset of field: virtio_mem_resp::padding"]
200+
[::std::mem::offset_of!(virtio_mem_resp, padding) - 2usize];
201+
["Offset of field: virtio_mem_resp::u"][::std::mem::offset_of!(virtio_mem_resp, u) - 8usize];
202+
};
203+
impl Default for virtio_mem_resp {
204+
fn default() -> Self {
205+
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
206+
unsafe {
207+
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
208+
s.assume_init()
209+
}
210+
}
211+
}
212+
#[repr(C)]
213+
#[derive(Debug, Default, Copy, Clone, PartialEq)]
214+
pub struct virtio_mem_config {
215+
pub block_size: __le64,
216+
pub node_id: __le16,
217+
pub padding: [__u8; 6usize],
218+
pub addr: __le64,
219+
pub region_size: __le64,
220+
pub usable_region_size: __le64,
221+
pub plugged_size: __le64,
222+
pub requested_size: __le64,
223+
}
224+
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
225+
const _: () = {
226+
["Size of virtio_mem_config"][::std::mem::size_of::<virtio_mem_config>() - 56usize];
227+
["Alignment of virtio_mem_config"][::std::mem::align_of::<virtio_mem_config>() - 8usize];
228+
["Offset of field: virtio_mem_config::block_size"]
229+
[::std::mem::offset_of!(virtio_mem_config, block_size) - 0usize];
230+
["Offset of field: virtio_mem_config::node_id"]
231+
[::std::mem::offset_of!(virtio_mem_config, node_id) - 8usize];
232+
["Offset of field: virtio_mem_config::padding"]
233+
[::std::mem::offset_of!(virtio_mem_config, padding) - 10usize];
234+
["Offset of field: virtio_mem_config::addr"]
235+
[::std::mem::offset_of!(virtio_mem_config, addr) - 16usize];
236+
["Offset of field: virtio_mem_config::region_size"]
237+
[::std::mem::offset_of!(virtio_mem_config, region_size) - 24usize];
238+
["Offset of field: virtio_mem_config::usable_region_size"]
239+
[::std::mem::offset_of!(virtio_mem_config, usable_region_size) - 32usize];
240+
["Offset of field: virtio_mem_config::plugged_size"]
241+
[::std::mem::offset_of!(virtio_mem_config, plugged_size) - 40usize];
242+
["Offset of field: virtio_mem_config::requested_size"]
243+
[::std::mem::offset_of!(virtio_mem_config, requested_size) - 48usize];
244+
};

tools/bindgen.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ fc-bindgen \
105105
--allowlist-var "VIRTIO_ID.*" \
106106
"$INCLUDE/linux/virtio_ids.h" >src/vmm/src/devices/virtio/generated/virtio_ids.rs
107107

108+
info "BINDGEN virtio_mem.h"
109+
fc-bindgen \
110+
--allowlist-var "VIRTIO_MEM.*" \
111+
--allowlist-type "virtio_mem.*" \
112+
"$INCLUDE/linux/virtio_mem.h" >src/vmm/src/devices/virtio/generated/virtio_mem.rs
113+
108114
info "BINDGEN prctl.h"
109115
fc-bindgen \
110116
--allowlist-var "PR_.*" \

0 commit comments

Comments
 (0)