crosvm/vfio_sys/bindgen.sh
Grzegorz Jaszczyk 298be81446 acpi: x86: add support for ACPI Notify() forwarding
In order to replicate the ACPI notification from the host to the guest
pass-through devices:
1) allocate GPE and eventfd per pci-vfio device
2) generate proper aml code for ACPI GPE handler. The example of generated aml:

    Scope (_GPE)
    {
        Method (_E00, 0, NotSerialized)  // _Exx: Edge-Triggered GPE, xx=0x00-0xFF
        {
            Local0 = \_SB.PC00.PE08.NOTY
            Notify (\_SB.PC00.PE08, Local0)
        }
    }

The eventfd is registered by host kernel via VFIO_DEVICE_SET_IRQS
ioctl. Crosvm upon receiving early provided, per pci-vfio eventfd,
stores the notification value and triggers GPE associated to pci-vfio
device.

Guest kernel upon handling GPE (thanks to generated aml [ad 2)],
triggers Notify on required pass-through device and therefore replicates
the ACPI Notification on the guest side [Accessing \_SB.PC00.PE08.NOTY
pointed by VCFG opregion result with trap to crosvm, which returns
previously stored notify value].

Kernel counterpart: CL:4538472

BUG=b:244205651
TEST=Observe replication of ACPI notification in the guest kernel

Change-Id: Iaf66097acd84f3066f6ff70d382f83ecaeea9a00
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4538483
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-07-27 11:30:18 +00:00

66 lines
1.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# Copyright 2022 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Regenerate vfio_sys bindgen bindings.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
source tools/impl/bindgen-common.sh
# VFIO_TYPE is translated as a u8 since it is a char constant, but it needs to be u32 for use in
# ioctl macros.
fix_vfio_type() {
sed -E -e 's/^pub const VFIO_TYPE: u8 = (.*)u8;/pub const VFIO_TYPE: u32 = \1;/'
}
VFIO_EXTRA="// Added by vfio_sys/bindgen.sh
use zerocopy::AsBytes;
use zerocopy::FromBytes;
#[repr(C)]
#[derive(Debug, Default)]
pub struct vfio_acpi_dsm {
pub argsz: u32,
pub padding: u32,
pub args: __IncompleteArrayField<u8>,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vfio_acpi_notify_eventfd {
pub notify_eventfd: i32,
pub reserved: u32,
}
#[repr(C)]
#[derive(Debug, Default)]
pub struct vfio_region_info_with_cap {
pub region_info: vfio_region_info,
pub cap_info: __IncompleteArrayField<u8>,
}
// vfio_iommu_type1_info_cap_iova_range minus the incomplete iova_ranges
// array, so that Copy/AsBytes/FromBytes can be implemented.
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromBytes)]
pub struct vfio_iommu_type1_info_cap_iova_range_header {
pub header: vfio_info_cap_header,
pub nr_iovas: u32,
pub reserved: u32,
}"
bindgen_generate \
--raw-line "${VFIO_EXTRA}" \
--allowlist-var='VFIO_.*' \
--blocklist-item='VFIO_DEVICE_API_.*_STRING' \
--allowlist-type='vfio_.*' \
--with-derive-custom "vfio_info_cap_header=FromBytes,AsBytes" \
--with-derive-custom "vfio_iova_range=FromBytes,AsBytes" \
"${BINDGEN_LINUX}/include/uapi/linux/vfio.h" \
-- \
-D__user= \
| replace_linux_int_types | fix_vfio_type \
> vfio_sys/src/vfio.rs