• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::FromBytes;
21use zerocopy::Immutable;
22use zerocopy::IntoBytes;
23use zerocopy::KnownLayout;
24
25// TODO(b/292077398): Upstream or remove ACPI notification forwarding support
26pub const VFIO_PCI_ACPI_NTFY_IRQ_INDEX: std::os::raw::c_uint = 5;
27
28#[repr(C)]
29#[derive(Debug, Default)]
30pub struct vfio_acpi_dsm {
31    pub argsz: u32,
32    pub padding: u32,
33    pub args: __IncompleteArrayField<u8>,
34}
35
36#[repr(C)]
37#[derive(Debug, Default, Copy, Clone)]
38pub struct vfio_acpi_notify_eventfd {
39    pub notify_eventfd: i32,
40    pub reserved: u32,
41}
42
43#[repr(C)]
44#[derive(Debug, Default)]
45pub struct vfio_region_info_with_cap {
46    pub region_info: vfio_region_info,
47    pub cap_info: __IncompleteArrayField<u8>,
48}
49
50// vfio_iommu_type1_info_cap_iova_range minus the incomplete iova_ranges
51// array, so that zerocopy traits can be implemented.
52#[repr(C)]
53#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
54pub struct vfio_iommu_type1_info_cap_iova_range_header {
55    pub header: vfio_info_cap_header,
56    pub nr_iovas: u32,
57    pub reserved: u32,
58}
59
60// Experimental Android uABI
61pub const VFIO_PKVM_PVIOMMU: u32 = 11;"
62
63bindgen_generate \
64    --raw-line "${VFIO_EXTRA}" \
65    --allowlist-var='VFIO_.*' \
66    --blocklist-item='VFIO_DEVICE_API_.*_STRING' \
67    --allowlist-type='vfio_.*' \
68    --with-derive-custom "vfio_info_cap_header=FromBytes,Immutable,IntoBytes,KnownLayout" \
69    --with-derive-custom "vfio_iova_range=FromBytes,Immutable,IntoBytes,KnownLayout" \
70    "${BINDGEN_LINUX}/include/uapi/linux/vfio.h" \
71    -- \
72    -D__user= \
73    | replace_linux_int_types | fix_vfio_type \
74    > vfio_sys/src/vfio.rs
75