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 22VIRTIO_CONFIG_EXTRA="// Added by virtio_sys/bindgen.sh 23pub const VIRTIO_CONFIG_S_SUSPEND: u32 = 16; 24pub const VIRTIO_F_SUSPEND: u32 = 42;" 25 26bindgen_generate \ 27 --raw-line "${VIRTIO_CONFIG_EXTRA}" \ 28 --allowlist-var='VIRTIO_.*' \ 29 --allowlist-type='virtio_.*' \ 30 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_config.h" \ 31 -- \ 32 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 33 | replace_linux_int_types \ 34 > virtio_sys/src/virtio_config.rs 35 36VIRTIO_FS_EXTRA="// Added by virtio_sys/bindgen.sh 37use data_model::Le32; 38use zerocopy::FromBytes; 39use zerocopy::Immutable; 40use zerocopy::IntoBytes; 41use zerocopy::KnownLayout;" 42 43bindgen_generate \ 44 --raw-line "${VIRTIO_FS_EXTRA}" \ 45 --allowlist-var='VIRTIO_FS_.*' \ 46 --allowlist-type='virtio_fs_.*' \ 47 --with-derive-custom "virtio_fs_config=FromBytes,Immutable,IntoBytes,KnownLayout" \ 48 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_fs.h" \ 49 -- \ 50 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 51 | replace_linux_int_types \ 52 | replace_linux_endian_types \ 53 > virtio_sys/src/virtio_fs.rs 54 55VIRTIO_IDS_EXTRAS=" 56//! This file defines virtio device IDs. IDs with large values (counting down 57//! from 63) are nonstandard and not defined by the virtio specification. 58 59// Added by virtio_sys/bindgen.sh - do not edit the generated file. 60// TODO(b/236144983): Fix this id when an official virtio-id is assigned to this device. 61pub const VIRTIO_ID_PVCLOCK: u32 = 61; 62// TODO: Remove this once the ID is included in the Linux headers. 63pub const VIRTIO_ID_MEDIA: u32 = 48; 64" 65 66bindgen_generate \ 67 --raw-line "${VIRTIO_IDS_EXTRAS}" \ 68 --allowlist-var='VIRTIO_ID_.*' \ 69 --allowlist-type='virtio_.*' \ 70 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_ids.h" \ 71 -- \ 72 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 73 | replace_linux_int_types \ 74 | rustfmt \ 75 > virtio_sys/src/virtio_ids.rs 76 77VIRTIO_NET_EXTRA="// Added by virtio_sys/bindgen.sh 78use zerocopy::FromBytes; 79use zerocopy::Immutable; 80use zerocopy::IntoBytes; 81use zerocopy::KnownLayout;" 82 83bindgen_generate \ 84 --raw-line "${VIRTIO_NET_EXTRA}" \ 85 --allowlist-var='VIRTIO_NET_.*' \ 86 --allowlist-type='virtio_net_.*' \ 87 --blocklist-type='virtio_net_ctrl_mac' \ 88 --with-derive-custom "virtio_net_hdr=FromBytes,Immutable,IntoBytes,KnownLayout" \ 89 --with-derive-custom "virtio_net_hdr_mrg_rxbuf=FromBytes,Immutable,IntoBytes,KnownLayout" \ 90 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_net.h" \ 91 -- \ 92 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 93 | replace_linux_int_types \ 94 > virtio_sys/src/virtio_net.rs 95 96bindgen_generate \ 97 --allowlist-var='VRING_.*' \ 98 --allowlist-var='VIRTIO_RING_.*' \ 99 --allowlist-type='vring.*' \ 100 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_ring.h" \ 101 -- \ 102 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 103 | replace_linux_int_types \ 104 > virtio_sys/src/virtio_ring.rs 105 106bindgen_generate \ 107 --allowlist-var='VIRTIO_.*' \ 108 --allowlist-type='virtio_.*' \ 109 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_mmio.h" \ 110 -- \ 111 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 112 | replace_linux_int_types \ 113 > virtio_sys/src/virtio_mmio.rs 114 115VIRTIO_VSOCK_EXTRA="// Added by virtio_sys/bindgen.sh 116use data_model::Le16; 117use data_model::Le32; 118use data_model::Le64; 119use zerocopy::FromBytes; 120use zerocopy::Immutable; 121use zerocopy::IntoBytes; 122use zerocopy::KnownLayout;" 123 124bindgen_generate \ 125 --raw-line "${VIRTIO_VSOCK_EXTRA}" \ 126 --allowlist-var='VIRTIO_VSOCK_.*' \ 127 --allowlist-type='virtio_vsock_.*' \ 128 --with-derive-custom "virtio_vsock_event=FromBytes,Immutable,IntoBytes,KnownLayout" \ 129 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_vsock.h" \ 130 -- \ 131 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 132 | replace_linux_int_types \ 133 | replace_linux_endian_types \ 134 > virtio_sys/src/virtio_vsock.rs 135 136VIRTIO_SCSI_EXTRA="// Added by virtio_sys/bindgen.sh 137use zerocopy::FromBytes; 138use zerocopy::Immutable; 139use zerocopy::IntoBytes; 140use zerocopy::KnownLayout;" 141 142bindgen_generate \ 143 --raw-line "${VIRTIO_SCSI_EXTRA}" \ 144 --allowlist-var='VIRTIO_SCSI_.*' \ 145 --allowlist-type='virtio_scsi_.*' \ 146 --blocklist-type='virtio_scsi_cmd_req_pi' \ 147 --with-derive-custom "virtio_scsi_config=FromBytes,Immutable,IntoBytes,KnownLayout" \ 148 --with-derive-custom "virtio_scsi_cmd_req=FromBytes,Immutable,IntoBytes,KnownLayout" \ 149 --with-derive-custom "virtio_scsi_cmd_resp=FromBytes,Immutable,IntoBytes,KnownLayout" \ 150 --with-derive-custom "virtio_scsi_ctrl_tmf_req=FromBytes,Immutable,IntoBytes,KnownLayout" \ 151 --with-derive-custom "virtio_scsi_ctrl_an_req=FromBytes,Immutable,IntoBytes,KnownLayout" \ 152 --with-derive-custom "virtio_scsi_ctrl_tmf_resp=FromBytes,Immutable,IntoBytes,KnownLayout" \ 153 --with-derive-custom "virtio_scsi_ctrl_an_resp=FromBytes,Immutable,IntoBytes,KnownLayout" \ 154 "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_scsi.h" \ 155 -- \ 156 -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \ 157 | replace_linux_int_types \ 158 | replace_linux_endian_types \ 159 > virtio_sys/src/virtio_scsi.rs 160