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 virtio_sys bindgen bindings. 7 8set -euo pipefail 9cd "$(dirname "${BASH_SOURCE[0]}")/.." 10 11source tools/impl/bindgen-common.sh 12 13bindgen_generate \ 14 --allowlist-type='vhost_.*' \ 15 --allowlist-var='VHOST_.*' \ 16 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/vhost.h" \ 17 -- \ 18 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 19 | replace_linux_int_types \ 20 > virtio_sys/src/vhost.rs 21 22bindgen_generate \ 23 --allowlist-var='VIRTIO_.*' \ 24 --allowlist-type='virtio_.*' \ 25 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_config.h" \ 26 -- \ 27 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 28 | replace_linux_int_types \ 29 > virtio_sys/src/virtio_config.rs 30 31VIRTIO_FS_EXTRA="// Added by virtio_sys/bindgen.sh 32use data_model::Le32; 33use zerocopy::AsBytes; 34use zerocopy::FromBytes;" 35 36bindgen_generate \ 37 --raw-line "${VIRTIO_FS_EXTRA}" \ 38 --allowlist-var='VIRTIO_FS_.*' \ 39 --allowlist-type='virtio_fs_.*' \ 40 --with-derive-custom "virtio_fs_config=FromBytes,AsBytes" \ 41 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_fs.h" \ 42 -- \ 43 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 44 | replace_linux_int_types \ 45 | replace_linux_endian_types \ 46 > virtio_sys/src/virtio_fs.rs 47 48VIRTIO_IDS_EXTRAS=" 49//! This file defines virtio device IDs. IDs with large values (counting down 50//! from 63) are nonstandard and not defined by the virtio specification. 51 52// Added by virtio_sys/bindgen.sh - do not edit the generated file. 53// TODO(abhishekbh): Fix this after this device is accepted upstream. 54pub const VIRTIO_ID_VHOST_USER: u32 = 61; 55// TODO(b/236144983): Fix this id when an official virtio-id is assigned to this device. 56pub const VIRTIO_ID_PVCLOCK: u32 = 60; 57" 58 59bindgen_generate \ 60 --raw-line "${VIRTIO_IDS_EXTRAS}" \ 61 --allowlist-var='VIRTIO_ID_.*' \ 62 --allowlist-type='virtio_.*' \ 63 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_ids.h" \ 64 -- \ 65 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 66 | replace_linux_int_types \ 67 | rustfmt \ 68 > virtio_sys/src/virtio_ids.rs 69 70VIRTIO_NET_EXTRA="// Added by virtio_sys/bindgen.sh 71use zerocopy::AsBytes; 72use zerocopy::FromBytes;" 73 74bindgen_generate \ 75 --raw-line "${VIRTIO_NET_EXTRA}" \ 76 --allowlist-var='VIRTIO_NET_.*' \ 77 --allowlist-type='virtio_net_.*' \ 78 --blocklist-type='virtio_net_ctrl_mac' \ 79 --with-derive-custom "virtio_net_hdr=FromBytes,AsBytes" \ 80 --with-derive-custom "virtio_net_hdr_mrg_rxbuf=FromBytes,AsBytes" \ 81 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_net.h" \ 82 -- \ 83 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 84 | replace_linux_int_types \ 85 > virtio_sys/src/virtio_net.rs 86 87bindgen_generate \ 88 --allowlist-var='VRING_.*' \ 89 --allowlist-var='VIRTIO_RING_.*' \ 90 --allowlist-type='vring.*' \ 91 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_ring.h" \ 92 -- \ 93 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 94 | replace_linux_int_types \ 95 > virtio_sys/src/virtio_ring.rs 96 97bindgen_generate \ 98 --allowlist-var='VIRTIO_.*' \ 99 --allowlist-type='virtio_.*' \ 100 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_mmio.h" \ 101 -- \ 102 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 103 | replace_linux_int_types \ 104 > virtio_sys/src/virtio_mmio.rs 105