• 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 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;
35use zerocopy::FromZeroes;"
36
37bindgen_generate \
38    --raw-line "${VIRTIO_FS_EXTRA}" \
39    --allowlist-var='VIRTIO_FS_.*' \
40    --allowlist-type='virtio_fs_.*' \
41    --with-derive-custom "virtio_fs_config=FromZeroes,FromBytes,AsBytes" \
42    "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_fs.h" \
43    -- \
44    -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \
45    | replace_linux_int_types \
46    | replace_linux_endian_types \
47    > virtio_sys/src/virtio_fs.rs
48
49VIRTIO_IDS_EXTRAS="
50//! This file defines virtio device IDs. IDs with large values (counting down
51//! from 63) are nonstandard and not defined by the virtio specification.
52
53// Added by virtio_sys/bindgen.sh - do not edit the generated file.
54// TODO(b/236144983): Fix this id when an official virtio-id is assigned to this device.
55pub const VIRTIO_ID_PVCLOCK: u32 = 61;
56"
57
58bindgen_generate \
59    --raw-line "${VIRTIO_IDS_EXTRAS}" \
60    --allowlist-var='VIRTIO_ID_.*' \
61    --allowlist-type='virtio_.*' \
62    "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_ids.h" \
63    -- \
64    -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \
65    | replace_linux_int_types \
66    | rustfmt \
67    > virtio_sys/src/virtio_ids.rs
68
69VIRTIO_NET_EXTRA="// Added by virtio_sys/bindgen.sh
70use zerocopy::AsBytes;
71use zerocopy::FromBytes;
72use zerocopy::FromZeroes;"
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=FromZeroes,FromBytes,AsBytes" \
80    --with-derive-custom "virtio_net_hdr_mrg_rxbuf=FromZeroes,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
106VIRTIO_VSOCK_EXTRA="// Added by virtio_sys/bindgen.sh
107use data_model::Le16;
108use data_model::Le32;
109use data_model::Le64;
110use zerocopy::AsBytes;"
111
112bindgen_generate \
113    --raw-line "${VIRTIO_VSOCK_EXTRA}" \
114    --allowlist-var='VIRTIO_VSOCK_.*' \
115    --allowlist-type='virtio_vsock_.*' \
116    --with-derive-custom "virtio_vsock_event=AsBytes" \
117    "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_vsock.h" \
118    -- \
119    -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \
120    | replace_linux_int_types \
121    | replace_linux_endian_types \
122    > virtio_sys/src/virtio_vsock.rs
123
124VIRTIO_SCSI_EXTRA="// Added by virtio_sys/bindgen.sh
125use zerocopy::AsBytes;
126use zerocopy::FromBytes;
127use zerocopy::FromZeroes;"
128
129bindgen_generate \
130    --raw-line "${VIRTIO_SCSI_EXTRA}" \
131    --allowlist-var='VIRTIO_SCSI_.*' \
132    --allowlist-type='virtio_scsi_.*' \
133    --blocklist-type='virtio_scsi_cmd_req_pi' \
134    --with-derive-custom "virtio_scsi_config=FromZeroes,FromBytes,AsBytes" \
135    --with-derive-custom "virtio_scsi_cmd_req=FromZeroes,FromBytes,AsBytes" \
136    --with-derive-custom "virtio_scsi_cmd_resp=FromZeroes,FromBytes,AsBytes" \
137    --with-derive-custom "virtio_scsi_ctrl_tmf_req=FromZeroes,FromBytes,AsBytes" \
138    --with-derive-custom "virtio_scsi_ctrl_an_req=FromZeroes,FromBytes,AsBytes" \
139    --with-derive-custom "virtio_scsi_ctrl_tmf_resp=FromZeroes,FromBytes,AsBytes" \
140    --with-derive-custom "virtio_scsi_ctrl_an_resp=FromZeroes,FromBytes,AsBytes" \
141    "${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_scsi.h" \
142    -- \
143    -isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \
144    | replace_linux_int_types \
145    | replace_linux_endian_types \
146    > virtio_sys/src/virtio_scsi.rs
147