1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// 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.

//! This file was generated by the following commands and modified manually.
//!
//! ```shell
//! $ bindgen virtio_iommu.h              \
//!     --allowlist-type "virtio_iommu.*" \
//!     --allowlist-var "VIRTIO_IOMMU_.*" \
//!     --with-derive-default            \
//!     --no-layout-tests                \
//!     --no-prepend-enum-name > protocol.rs
//! $ sed -i "s/__u/u/g" protocol.rs
//! $ sed -i "s/__le/Le/g" protocol.rs
//!
//! The main points of the manual modifications are as follows:
//! * Removed `head` and `tail` from each command struct. Instead, we process
//!   them as separate payloads.
//! * Derive implementations of zerocopy::{AsBytes, FromZeroes, FromBytes} as needed.
//! * Use of `packed` because removing `head` and `tail` introduces paddings
//! * Remove `IncompleteArrayField`
//! * Convert padding of [u8; 64usize] to [u64; 8usize]. According to the rust
//!   doc, "Arrays of sizes from 0 to 32 (inclusive) implement the Default trait
//!   if the element type allows it."

#![allow(dead_code)]
#![allow(non_camel_case_types)]

use data_model::Le16;
use data_model::Le32;
use data_model::Le64;
use zerocopy::AsBytes;
use zerocopy::FromBytes;
use zerocopy::FromZeroes;

pub const VIRTIO_IOMMU_F_INPUT_RANGE: u32 = 0;
pub const VIRTIO_IOMMU_F_DOMAIN_RANGE: u32 = 1;
pub const VIRTIO_IOMMU_F_MAP_UNMAP: u32 = 2;
pub const VIRTIO_IOMMU_F_BYPASS: u32 = 3;
pub const VIRTIO_IOMMU_F_PROBE: u32 = 4;
pub const VIRTIO_IOMMU_F_MMIO: u32 = 5;
pub const VIRTIO_IOMMU_T_ATTACH: u8 = 1;
pub const VIRTIO_IOMMU_T_DETACH: u8 = 2;
pub const VIRTIO_IOMMU_T_MAP: u8 = 3;
pub const VIRTIO_IOMMU_T_UNMAP: u8 = 4;
pub const VIRTIO_IOMMU_T_PROBE: u8 = 5;
pub const VIRTIO_IOMMU_S_OK: u8 = 0;
pub const VIRTIO_IOMMU_S_IOERR: u8 = 1;
pub const VIRTIO_IOMMU_S_UNSUPP: u8 = 2;
pub const VIRTIO_IOMMU_S_DEVERR: u8 = 3;
pub const VIRTIO_IOMMU_S_INVAL: u8 = 4;
pub const VIRTIO_IOMMU_S_RANGE: u8 = 5;
pub const VIRTIO_IOMMU_S_NOENT: u8 = 6;
pub const VIRTIO_IOMMU_S_FAULT: u8 = 7;
pub const VIRTIO_IOMMU_S_NOMEM: u8 = 8;
pub const VIRTIO_IOMMU_MAP_F_READ: u32 = 1;
pub const VIRTIO_IOMMU_MAP_F_WRITE: u32 = 2;
pub const VIRTIO_IOMMU_MAP_F_MMIO: u32 = 4;
pub const VIRTIO_IOMMU_MAP_F_MASK: u32 = 7;
pub const VIRTIO_IOMMU_PROBE_T_NONE: u32 = 0;
pub const VIRTIO_IOMMU_PROBE_T_RESV_MEM: u32 = 1;
pub const VIRTIO_IOMMU_PROBE_T_MASK: u32 = 4095;
pub const VIRTIO_IOMMU_RESV_MEM_T_RESERVED: u32 = 0;
pub const VIRTIO_IOMMU_RESV_MEM_T_MSI: u32 = 1;
pub const VIRTIO_IOMMU_FAULT_R_UNKNOWN: u32 = 0;
pub const VIRTIO_IOMMU_FAULT_R_DOMAIN: u32 = 1;
pub const VIRTIO_IOMMU_FAULT_R_MAPPING: u32 = 2;
pub const VIRTIO_IOMMU_FAULT_F_READ: u32 = 1;
pub const VIRTIO_IOMMU_FAULT_F_WRITE: u32 = 2;
pub const VIRTIO_IOMMU_FAULT_F_EXEC: u32 = 4;
pub const VIRTIO_IOMMU_FAULT_F_ADDRESS: u32 = 256;

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_range_64 {
    pub start: Le64,
    pub end: Le64,
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_range_32 {
    pub start: Le32,
    pub end: Le32,
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_config {
    pub page_size_mask: Le64,
    pub input_range: virtio_iommu_range_64,
    pub domain_range: virtio_iommu_range_32,
    pub probe_size: Le32,
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_req_head {
    pub type_: u8,
    pub reserved: [u8; 3usize],
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_req_tail {
    pub status: u8,
    pub reserved: [u8; 3usize],
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_req_attach {
    pub domain: Le32,
    pub endpoint: Le32,
    pub reserved: [u8; 8usize],
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_req_detach {
    pub domain: Le32,
    pub endpoint: Le32,
    pub reserved: [u8; 8usize],
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_req_map {
    pub domain: Le32,
    pub virt_start: Le64,
    pub virt_end: Le64,
    pub phys_start: Le64,
    pub flags: Le32,
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_req_unmap {
    pub domain: Le32,
    pub virt_start: Le64,
    pub virt_end: Le64,
    pub reserved: [u8; 4usize],
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_probe_property {
    pub type_: Le16,
    pub length: Le16,
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_probe_resv_mem {
    pub head: virtio_iommu_probe_property,
    pub subtype: u8,
    pub reserved: [u8; 3usize],
    pub start: Le64,
    pub end: Le64,
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
pub struct virtio_iommu_req_probe {
    pub endpoint: Le32,
    pub reserved: [u64; 8usize],
}

#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone)]
pub struct virtio_iommu_fault {
    pub reason: u8,
    pub reserved: [u8; 3usize],
    pub flags: Le32,
    pub endpoint: Le32,
    pub reserved2: [u8; 4usize],
    pub address: Le64,
}