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 vfio_sys bindgen bindings. 7 8set -euo pipefail 9cd "$(dirname "${BASH_SOURCE[0]}")/.." 10 11source tools/impl/bindgen-common.sh 12 13# VFIO_TYPE is translated as a u8 since it is a char constant, but it needs to be u32 for use in 14# ioctl macros. 15fix_vfio_type() { 16 sed -E -e 's/^pub const VFIO_TYPE: u8 = (.*)u8;/pub const VFIO_TYPE: u32 = \1;/' 17} 18 19VFIO_EXTRA="// Added by vfio_sys/bindgen.sh 20use zerocopy::AsBytes; 21use zerocopy::FromBytes; 22use zerocopy::FromZeroes; 23 24// TODO(b/292077398): Upstream or remove ACPI notification forwarding support 25pub const VFIO_PCI_ACPI_NTFY_IRQ_INDEX: std::os::raw::c_uint = 5; 26 27#[repr(C)] 28#[derive(Debug, Default)] 29pub struct vfio_acpi_dsm { 30 pub argsz: u32, 31 pub padding: u32, 32 pub args: __IncompleteArrayField<u8>, 33} 34 35#[repr(C)] 36#[derive(Debug, Default, Copy, Clone)] 37pub struct vfio_acpi_notify_eventfd { 38 pub notify_eventfd: i32, 39 pub reserved: u32, 40} 41 42#[repr(C)] 43#[derive(Debug, Default)] 44pub struct vfio_region_info_with_cap { 45 pub region_info: vfio_region_info, 46 pub cap_info: __IncompleteArrayField<u8>, 47} 48 49// vfio_iommu_type1_info_cap_iova_range minus the incomplete iova_ranges 50// array, so that Copy/AsBytes/FromBytes can be implemented. 51#[repr(C)] 52#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)] 53pub struct vfio_iommu_type1_info_cap_iova_range_header { 54 pub header: vfio_info_cap_header, 55 pub nr_iovas: u32, 56 pub reserved: u32, 57} 58 59// Experimental Android uABI 60pub const VFIO_PKVM_PVIOMMU: u32 = 11;" 61 62bindgen_generate \ 63 --raw-line "${VFIO_EXTRA}" \ 64 --allowlist-var='VFIO_.*' \ 65 --blocklist-item='VFIO_DEVICE_API_.*_STRING' \ 66 --allowlist-type='vfio_.*' \ 67 --with-derive-custom "vfio_info_cap_header=FromZeroes,FromBytes,AsBytes" \ 68 --with-derive-custom "vfio_iova_range=FromZeroes,FromBytes,AsBytes" \ 69 "${BINDGEN_LINUX}/include/uapi/linux/vfio.h" \ 70 -- \ 71 -D__user= \ 72 | replace_linux_int_types | fix_vfio_type \ 73 > vfio_sys/src/vfio.rs 74