2021-12-08 00:46:21 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-09-13 17:55:17 +00:00
|
|
|
# Copyright 2022 The ChromiumOS Authors
|
2021-12-08 00:46:21 +00:00
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
2022-09-13 19:37:28 +00:00
|
|
|
|
2021-12-08 00:46:21 +00:00
|
|
|
# Regenerate kvm_sys bindgen bindings.
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
|
|
|
|
source tools/impl/bindgen-common.sh
|
|
|
|
|
2022-09-13 22:17:56 +00:00
|
|
|
KVM_EXTRAS="// Added by kvm_sys/bindgen.sh
|
2023-09-20 20:45:25 +00:00
|
|
|
use zerocopy::AsBytes;
|
|
|
|
use zerocopy::FromBytes;
|
|
|
|
use zerocopy::FromZeroes;
|
|
|
|
|
2024-01-23 08:07:30 +00:00
|
|
|
// TODO(b/316337317): Update if new memslot flag is accepted in upstream
|
|
|
|
pub const KVM_MEM_NON_COHERENT_DMA: u32 = 8;
|
|
|
|
pub const KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: u32 = 236;
|
|
|
|
|
2021-12-08 00:46:21 +00:00
|
|
|
// TODO(qwandor): Update this once the pKVM patches are merged upstream with a stable capability ID.
|
|
|
|
pub const KVM_CAP_ARM_PROTECTED_VM: u32 = 0xffbadab1;
|
|
|
|
pub const KVM_CAP_ARM_PROTECTED_VM_FLAGS_SET_FW_IPA: u32 = 0;
|
|
|
|
pub const KVM_CAP_ARM_PROTECTED_VM_FLAGS_INFO: u32 = 1;
|
2023-10-21 11:44:11 +00:00
|
|
|
pub const KVM_VM_TYPE_ARM_PROTECTED: u32 = 0x80000000;
|
2024-11-15 18:05:15 +00:00
|
|
|
pub const KVM_X86_PKVM_PROTECTED_VM: u32 = 28;
|
2023-10-21 11:44:11 +00:00
|
|
|
pub const KVM_DEV_VFIO_PVIOMMU: u32 = 2;
|
|
|
|
pub const KVM_DEV_VFIO_PVIOMMU_ATTACH: u32 = 1;
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Debug, Default, Copy, Clone)]
|
|
|
|
pub struct kvm_vfio_iommu_info {
|
|
|
|
pub device_fd: i32,
|
|
|
|
pub nr_sids: u32,
|
|
|
|
}
|
|
|
|
pub const KVM_DEV_VFIO_PVIOMMU_GET_INFO: u32 = 2;
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Debug, Default, Copy, Clone)]
|
|
|
|
pub struct kvm_vfio_iommu_config {
|
|
|
|
pub device_fd: i32,
|
|
|
|
pub sid_idx: u32,
|
|
|
|
pub vsid: u32,
|
2024-07-29 14:42:40 +00:00
|
|
|
}"
|
2021-12-08 00:46:21 +00:00
|
|
|
|
2023-09-20 20:45:25 +00:00
|
|
|
X86_64_EXTRAS="
|
|
|
|
// This is how zerocopy's author deal with bindings for __BindgenBitfieldUnit<Storage>, see:
|
|
|
|
// https://fuchsia-review.googlesource.com/c/859278/8/src/starnix/lib/linux_uapi/generate.py
|
|
|
|
unsafe impl<Storage> AsBytes for __BindgenBitfieldUnit<Storage>
|
|
|
|
where
|
|
|
|
Storage: AsBytes,
|
|
|
|
{
|
|
|
|
fn only_derive_is_allowed_to_implement_this_trait() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<Storage> FromBytes for __BindgenBitfieldUnit<Storage>
|
|
|
|
where
|
|
|
|
Storage: FromBytes,
|
|
|
|
{
|
|
|
|
fn only_derive_is_allowed_to_implement_this_trait() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<Storage> FromZeroes for __BindgenBitfieldUnit<Storage>
|
|
|
|
where
|
|
|
|
Storage: FromZeroes,
|
|
|
|
{
|
|
|
|
fn only_derive_is_allowed_to_implement_this_trait() {}
|
2023-10-10 21:14:36 +00:00
|
|
|
}"
|
2023-09-20 20:45:25 +00:00
|
|
|
|
2021-12-08 00:46:21 +00:00
|
|
|
bindgen_generate \
|
|
|
|
--raw-line "${KVM_EXTRAS}" \
|
2023-09-20 20:45:25 +00:00
|
|
|
--raw-line "${X86_64_EXTRAS}" \
|
2021-12-08 00:46:21 +00:00
|
|
|
--blocklist-item='__kernel.*' \
|
|
|
|
--blocklist-item='__BITS_PER_LONG' \
|
|
|
|
--blocklist-item='__FD_SETSIZE' \
|
|
|
|
--blocklist-item='_?IOC.*' \
|
2023-09-20 20:45:25 +00:00
|
|
|
--with-derive-custom "kvm_regs=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_sregs=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_fpu=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_debugregs=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_xcr=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_xcrs=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_lapic_state=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_mp_state=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events__bindgen_ty_1=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events__bindgen_ty_2=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events__bindgen_ty_3=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events__bindgen_ty_4=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events__bindgen_ty_5=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_dtable=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_segment=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_pic_state=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_ioapic_state=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_pit_state2=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_clock_data=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_ioapic_state__bindgen_ty_1=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_ioapic_state__bindgen_ty_1__bindgen_ty_1=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_pit_channel_state=FromZeroes,FromBytes,AsBytes" \
|
2021-12-08 00:46:21 +00:00
|
|
|
"${BINDGEN_LINUX_X86_HEADERS}/include/linux/kvm.h" \
|
|
|
|
-- \
|
|
|
|
-isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \
|
|
|
|
| replace_linux_int_types \
|
|
|
|
> kvm_sys/src/x86/bindings.rs
|
|
|
|
|
|
|
|
bindgen_generate \
|
|
|
|
--raw-line "${KVM_EXTRAS}" \
|
|
|
|
--blocklist-item='__kernel.*' \
|
|
|
|
--blocklist-item='__BITS_PER_LONG' \
|
|
|
|
--blocklist-item='__FD_SETSIZE' \
|
|
|
|
--blocklist-item='_?IOC.*' \
|
2023-09-20 20:45:25 +00:00
|
|
|
--with-derive-custom "kvm_regs=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_sregs=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_fpu=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_vcpu_events__bindgen_ty_1=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "kvm_mp_state=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "user_fpsimd_state=FromZeroes,FromBytes,AsBytes" \
|
|
|
|
--with-derive-custom "user_pt_regs=FromZeroes,FromBytes,AsBytes" \
|
2021-12-08 00:46:21 +00:00
|
|
|
"${BINDGEN_LINUX_ARM64_HEADERS}/include/linux/kvm.h" \
|
|
|
|
-- \
|
|
|
|
-isystem "${BINDGEN_LINUX_ARM64_HEADERS}/include" \
|
|
|
|
| replace_linux_int_types \
|
|
|
|
> kvm_sys/src/aarch64/bindings.rs
|
2023-06-15 18:22:06 +00:00
|
|
|
|
|
|
|
bindgen_generate \
|
|
|
|
--raw-line "${KVM_EXTRAS}" \
|
|
|
|
--blocklist-item='__kernel.*' \
|
|
|
|
--blocklist-item='__BITS_PER_LONG' \
|
|
|
|
--blocklist-item='__FD_SETSIZE' \
|
|
|
|
--blocklist-item='_?IOC.*' \
|
|
|
|
"${BINDGEN_LINUX_RISCV_HEADERS}/include/linux/kvm.h" \
|
|
|
|
-- \
|
|
|
|
-isystem "${BINDGEN_LINUX_RISCV_HEADERS}/include" \
|
|
|
|
| replace_linux_int_types \
|
|
|
|
> kvm_sys/src/riscv64/bindings.rs
|