Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
google
GitHub Repository: google/crosvm
Path: blob/main/kvm_sys/bindgen.sh
5392 views
1
#!/usr/bin/env bash
2
# Copyright 2022 The ChromiumOS Authors
3
# Use of this source code is governed by a BSD-style license that can be
4
# found in the LICENSE file.
5
6
# Regenerate kvm_sys bindgen bindings.
7
8
set -euo pipefail
9
cd "$(dirname "${BASH_SOURCE[0]}")/.."
10
11
source tools/impl/bindgen-common.sh
12
13
KVM_EXTRAS="// Added by kvm_sys/bindgen.sh
14
use zerocopy::FromBytes;
15
use zerocopy::Immutable;
16
use zerocopy::IntoBytes;
17
use zerocopy::KnownLayout;
18
19
// TODO(b/388092267): Replace this with an upstream equivalent when available.
20
// The original index (236) used in the ChromeOS v6.6 kernel was reused upstream for another
21
// capability, so this may return incorrect information on some kernels.
22
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA_CROS: u32 = 236;
23
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 239;
24
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
25
26
// TODO(qwandor): Update this once the pKVM patches are merged upstream with a stable capability ID.
27
pub const KVM_CAP_ARM_PROTECTED_VM: u32 = 0xffbadab1;
28
pub const KVM_CAP_ARM_PROTECTED_VM_FLAGS_SET_FW_IPA: u32 = 0;
29
pub const KVM_CAP_ARM_PROTECTED_VM_FLAGS_INFO: u32 = 1;
30
pub const KVM_CAP_ARM_PROTECTED_VM_FLAGS_SET_FFA: u32 = 2;
31
pub const KVM_VM_TYPE_ARM_PROTECTED: u32 = 0x80000000;
32
pub const KVM_X86_PKVM_PROTECTED_VM: u32 = 28;
33
pub const KVM_CAP_X86_PROTECTED_VM: u32 = 0xffbadab2;
34
pub const KVM_CAP_X86_PROTECTED_VM_FLAGS_SET_FW_GPA: u32 = 0;
35
pub const KVM_CAP_X86_PROTECTED_VM_FLAGS_INFO: u32 = 1;
36
pub const KVM_DEV_VFIO_PVIOMMU: u32 = 5;
37
pub const KVM_DEV_VFIO_PVIOMMU_ATTACH: u32 = 1;
38
#[repr(C)]
39
#[derive(Debug, Default, Copy, Clone)]
40
pub struct kvm_vfio_iommu_info {
41
pub size: u32,
42
pub device_fd: i32,
43
pub nr_sids: u32,
44
pub __reserved: u32,
45
}
46
pub const KVM_DEV_VFIO_PVIOMMU_GET_INFO: u32 = 2;
47
#[repr(C)]
48
#[derive(Debug, Default, Copy, Clone)]
49
pub struct kvm_vfio_iommu_config {
50
pub size: u32,
51
pub device_fd: i32,
52
pub sid_idx: u32,
53
pub vsid: u32,
54
pub __reserved: u32,
55
}"
56
57
bindgen_generate \
58
--flexarray-dst \
59
--raw-line "${KVM_EXTRAS}" \
60
--blocklist-item='__kernel.*' \
61
--blocklist-item='__BITS_PER_.*' \
62
--blocklist-item='__FD_SETSIZE' \
63
--blocklist-item='_?IOC.*' \
64
--with-derive-custom "kvm_regs=FromBytes,Immutable,IntoBytes,KnownLayout" \
65
--with-derive-custom "kvm_sregs=FromBytes,Immutable,IntoBytes,KnownLayout" \
66
--with-derive-custom "kvm_fpu=FromBytes,Immutable,IntoBytes,KnownLayout" \
67
--with-derive-custom "kvm_debugregs=FromBytes,Immutable,IntoBytes,KnownLayout" \
68
--with-derive-custom "kvm_xcr=FromBytes,Immutable,IntoBytes,KnownLayout" \
69
--with-derive-custom "kvm_xcrs=FromBytes,Immutable,IntoBytes,KnownLayout" \
70
--with-derive-custom "kvm_lapic_state=FromBytes,Immutable,IntoBytes,KnownLayout" \
71
--with-derive-custom "kvm_mp_state=FromBytes,Immutable,IntoBytes,KnownLayout" \
72
--with-derive-custom "kvm_vcpu_events=FromBytes,Immutable,IntoBytes,KnownLayout" \
73
--with-derive-custom "kvm_vcpu_events__bindgen_ty_1=FromBytes,Immutable,IntoBytes,KnownLayout" \
74
--with-derive-custom "kvm_vcpu_events__bindgen_ty_2=FromBytes,Immutable,IntoBytes,KnownLayout" \
75
--with-derive-custom "kvm_vcpu_events__bindgen_ty_3=FromBytes,Immutable,IntoBytes,KnownLayout" \
76
--with-derive-custom "kvm_vcpu_events__bindgen_ty_4=FromBytes,Immutable,IntoBytes,KnownLayout" \
77
--with-derive-custom "kvm_vcpu_events__bindgen_ty_5=FromBytes,Immutable,IntoBytes,KnownLayout" \
78
--with-derive-custom "kvm_dtable=FromBytes,Immutable,IntoBytes,KnownLayout" \
79
--with-derive-custom "kvm_segment=FromBytes,Immutable,IntoBytes,KnownLayout" \
80
--with-derive-custom "kvm_pic_state=FromBytes,Immutable,IntoBytes,KnownLayout" \
81
--with-derive-custom "kvm_pit_state2=FromBytes,Immutable,IntoBytes,KnownLayout" \
82
--with-derive-custom "kvm_clock_data=FromBytes,Immutable,IntoBytes,KnownLayout" \
83
--with-derive-custom "kvm_pit_channel_state=FromBytes,Immutable,IntoBytes,KnownLayout" \
84
--with-derive-custom "kvm_cpuid2=FromBytes,Immutable,KnownLayout" \
85
--with-derive-custom "kvm_cpuid_entry2=FromBytes,Immutable,KnownLayout" \
86
--with-derive-custom "kvm_irq_routing=FromBytes,Immutable,KnownLayout" \
87
--with-derive-custom "kvm_irq_routing_entry=FromBytes,Immutable,KnownLayout" \
88
--with-derive-custom "kvm_irq_routing_entry__bindgen_ty_1=FromBytes,Immutable,KnownLayout" \
89
--with-derive-custom "kvm_irq_routing_hv_sint=FromBytes,Immutable,KnownLayout" \
90
--with-derive-custom "kvm_irq_routing_irqchip=FromBytes,Immutable,KnownLayout" \
91
--with-derive-custom "kvm_irq_routing_msi=FromBytes,Immutable,KnownLayout" \
92
--with-derive-custom "kvm_irq_routing_msi__bindgen_ty_1=FromBytes,Immutable,KnownLayout" \
93
--with-derive-custom "kvm_irq_routing_s390_adapter=FromBytes,Immutable,KnownLayout" \
94
--with-derive-custom "kvm_irq_routing_xen_evtchn=FromBytes,Immutable,KnownLayout" \
95
--with-derive-custom "kvm_msr_entry=FromBytes,Immutable,KnownLayout" \
96
--with-derive-custom "kvm_msr_list=FromBytes,Immutable,KnownLayout" \
97
--with-derive-custom "kvm_msrs=FromBytes,Immutable,KnownLayout" \
98
"${BINDGEN_LINUX_X86_HEADERS}/include/linux/kvm.h" \
99
-- \
100
-isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \
101
| replace_linux_int_types \
102
> kvm_sys/src/x86/bindings.rs
103
104
bindgen_generate \
105
--flexarray-dst \
106
--raw-line "${KVM_EXTRAS}" \
107
--blocklist-item='__kernel.*' \
108
--blocklist-item='__BITS_PER_.*' \
109
--blocklist-item='__FD_SETSIZE' \
110
--blocklist-item='_?IOC.*' \
111
--with-derive-custom "kvm_regs=FromBytes,Immutable,IntoBytes,KnownLayout" \
112
--with-derive-custom "kvm_sregs=FromBytes,Immutable,IntoBytes,KnownLayout" \
113
--with-derive-custom "kvm_fpu=FromBytes,Immutable,IntoBytes,KnownLayout" \
114
--with-derive-custom "kvm_vcpu_events=FromBytes,Immutable,IntoBytes,KnownLayout" \
115
--with-derive-custom "kvm_vcpu_events__bindgen_ty_1=FromBytes,Immutable,IntoBytes,KnownLayout" \
116
--with-derive-custom "kvm_mp_state=FromBytes,Immutable,IntoBytes,KnownLayout" \
117
--with-derive-custom "user_fpsimd_state=FromBytes,Immutable,IntoBytes,KnownLayout" \
118
--with-derive-custom "user_pt_regs=FromBytes,Immutable,IntoBytes,KnownLayout" \
119
--with-derive-custom "kvm_reg_list=FromBytes,Immutable,KnownLayout" \
120
--with-derive-custom "kvm_irq_routing=FromBytes,Immutable,KnownLayout" \
121
--with-derive-custom "kvm_irq_routing_entry=FromBytes,Immutable,KnownLayout" \
122
--with-derive-custom "kvm_irq_routing_entry__bindgen_ty_1=FromBytes,Immutable,KnownLayout" \
123
--with-derive-custom "kvm_irq_routing_hv_sint=FromBytes,Immutable,KnownLayout" \
124
--with-derive-custom "kvm_irq_routing_irqchip=FromBytes,Immutable,KnownLayout" \
125
--with-derive-custom "kvm_irq_routing_msi=FromBytes,Immutable,KnownLayout" \
126
--with-derive-custom "kvm_irq_routing_msi__bindgen_ty_1=FromBytes,Immutable,KnownLayout" \
127
--with-derive-custom "kvm_irq_routing_s390_adapter=FromBytes,Immutable,KnownLayout" \
128
--with-derive-custom "kvm_irq_routing_xen_evtchn=FromBytes,Immutable,KnownLayout" \
129
"${BINDGEN_LINUX_ARM64_HEADERS}/include/linux/kvm.h" \
130
-- \
131
-isystem "${BINDGEN_LINUX_ARM64_HEADERS}/include" \
132
| replace_linux_int_types \
133
> kvm_sys/src/aarch64/bindings.rs
134
135
bindgen_generate \
136
--flexarray-dst \
137
--raw-line "${KVM_EXTRAS}" \
138
--blocklist-item='__kernel.*' \
139
--blocklist-item='__BITS_PER_.*' \
140
--blocklist-item='__FD_SETSIZE' \
141
--blocklist-item='_?IOC.*' \
142
--with-derive-custom "kvm_regs=FromBytes,Immutable,IntoBytes,KnownLayout" \
143
--with-derive-custom "kvm_irq_routing=FromBytes,Immutable,KnownLayout" \
144
--with-derive-custom "kvm_irq_routing_entry=FromBytes,Immutable,KnownLayout" \
145
--with-derive-custom "kvm_irq_routing_entry__bindgen_ty_1=FromBytes,Immutable,KnownLayout" \
146
--with-derive-custom "kvm_irq_routing_hv_sint=FromBytes,Immutable,KnownLayout" \
147
--with-derive-custom "kvm_irq_routing_irqchip=FromBytes,Immutable,KnownLayout" \
148
--with-derive-custom "kvm_irq_routing_msi=FromBytes,Immutable,KnownLayout" \
149
--with-derive-custom "kvm_irq_routing_msi__bindgen_ty_1=FromBytes,Immutable,KnownLayout" \
150
--with-derive-custom "kvm_irq_routing_s390_adapter=FromBytes,Immutable,KnownLayout" \
151
--with-derive-custom "kvm_irq_routing_xen_evtchn=FromBytes,Immutable,KnownLayout" \
152
"${BINDGEN_LINUX_RISCV_HEADERS}/include/linux/kvm.h" \
153
-- \
154
-isystem "${BINDGEN_LINUX_RISCV_HEADERS}/include" \
155
| replace_linux_int_types \
156
> kvm_sys/src/riscv64/bindings.rs
157
158