devices/virtio/iommu/
protocol.rs

1// Copyright 2022 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! This file was generated by the following commands and modified manually.
6//!
7//! ```shell
8//! $ bindgen virtio_iommu.h              \
9//!     --allowlist-type "virtio_iommu.*" \
10//!     --allowlist-var "VIRTIO_IOMMU_.*" \
11//!     --with-derive-default            \
12//!     --no-layout-tests                \
13//!     --no-prepend-enum-name > protocol.rs
14//! $ sed -i "s/__u/u/g" protocol.rs
15//! $ sed -i "s/__le/Le/g" protocol.rs
16//!
17//! The main points of the manual modifications are as follows:
18//! * Removed `head` and `tail` from each command struct. Instead, we process
19//!   them as separate payloads.
20//! * Derive implementations of zerocopy traits as needed.
21//! * Use of `packed` because removing `head` and `tail` introduces paddings
22//! * Remove `IncompleteArrayField`
23//! * Convert padding of [u8; 64usize] to [u64; 8usize]. According to the rust
24//!   doc, "Arrays of sizes from 0 to 32 (inclusive) implement the Default trait
25//!   if the element type allows it."
26
27#![allow(dead_code)]
28#![allow(non_camel_case_types)]
29
30use data_model::Le16;
31use data_model::Le32;
32use data_model::Le64;
33use zerocopy::FromBytes;
34use zerocopy::Immutable;
35use zerocopy::IntoBytes;
36use zerocopy::KnownLayout;
37
38pub const VIRTIO_IOMMU_F_INPUT_RANGE: u32 = 0;
39pub const VIRTIO_IOMMU_F_DOMAIN_RANGE: u32 = 1;
40pub const VIRTIO_IOMMU_F_MAP_UNMAP: u32 = 2;
41pub const VIRTIO_IOMMU_F_BYPASS: u32 = 3;
42pub const VIRTIO_IOMMU_F_PROBE: u32 = 4;
43pub const VIRTIO_IOMMU_F_MMIO: u32 = 5;
44pub const VIRTIO_IOMMU_T_ATTACH: u8 = 1;
45pub const VIRTIO_IOMMU_T_DETACH: u8 = 2;
46pub const VIRTIO_IOMMU_T_MAP: u8 = 3;
47pub const VIRTIO_IOMMU_T_UNMAP: u8 = 4;
48pub const VIRTIO_IOMMU_T_PROBE: u8 = 5;
49pub const VIRTIO_IOMMU_S_OK: u8 = 0;
50pub const VIRTIO_IOMMU_S_IOERR: u8 = 1;
51pub const VIRTIO_IOMMU_S_UNSUPP: u8 = 2;
52pub const VIRTIO_IOMMU_S_DEVERR: u8 = 3;
53pub const VIRTIO_IOMMU_S_INVAL: u8 = 4;
54pub const VIRTIO_IOMMU_S_RANGE: u8 = 5;
55pub const VIRTIO_IOMMU_S_NOENT: u8 = 6;
56pub const VIRTIO_IOMMU_S_FAULT: u8 = 7;
57pub const VIRTIO_IOMMU_S_NOMEM: u8 = 8;
58pub const VIRTIO_IOMMU_MAP_F_READ: u32 = 1;
59pub const VIRTIO_IOMMU_MAP_F_WRITE: u32 = 2;
60pub const VIRTIO_IOMMU_MAP_F_MMIO: u32 = 4;
61pub const VIRTIO_IOMMU_MAP_F_MASK: u32 = 7;
62pub const VIRTIO_IOMMU_PROBE_T_NONE: u32 = 0;
63pub const VIRTIO_IOMMU_PROBE_T_RESV_MEM: u32 = 1;
64pub const VIRTIO_IOMMU_PROBE_T_MASK: u32 = 4095;
65pub const VIRTIO_IOMMU_RESV_MEM_T_RESERVED: u32 = 0;
66pub const VIRTIO_IOMMU_RESV_MEM_T_MSI: u32 = 1;
67pub const VIRTIO_IOMMU_FAULT_R_UNKNOWN: u32 = 0;
68pub const VIRTIO_IOMMU_FAULT_R_DOMAIN: u32 = 1;
69pub const VIRTIO_IOMMU_FAULT_R_MAPPING: u32 = 2;
70pub const VIRTIO_IOMMU_FAULT_F_READ: u32 = 1;
71pub const VIRTIO_IOMMU_FAULT_F_WRITE: u32 = 2;
72pub const VIRTIO_IOMMU_FAULT_F_EXEC: u32 = 4;
73pub const VIRTIO_IOMMU_FAULT_F_ADDRESS: u32 = 256;
74
75#[repr(C, packed)]
76#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
77pub struct virtio_iommu_range_64 {
78    pub start: Le64,
79    pub end: Le64,
80}
81
82#[repr(C, packed)]
83#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
84pub struct virtio_iommu_range_32 {
85    pub start: Le32,
86    pub end: Le32,
87}
88
89#[repr(C, packed)]
90#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
91pub struct virtio_iommu_config {
92    pub page_size_mask: Le64,
93    pub input_range: virtio_iommu_range_64,
94    pub domain_range: virtio_iommu_range_32,
95    pub probe_size: Le32,
96}
97
98#[repr(C, packed)]
99#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
100pub struct virtio_iommu_req_head {
101    pub type_: u8,
102    pub reserved: [u8; 3usize],
103}
104
105#[repr(C, packed)]
106#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
107pub struct virtio_iommu_req_tail {
108    pub status: u8,
109    pub reserved: [u8; 3usize],
110}
111
112#[repr(C, packed)]
113#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
114pub struct virtio_iommu_req_attach {
115    pub domain: Le32,
116    pub endpoint: Le32,
117    pub reserved: [u8; 8usize],
118}
119
120#[repr(C, packed)]
121#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
122pub struct virtio_iommu_req_detach {
123    pub domain: Le32,
124    pub endpoint: Le32,
125    pub reserved: [u8; 8usize],
126}
127
128#[repr(C, packed)]
129#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
130pub struct virtio_iommu_req_map {
131    pub domain: Le32,
132    pub virt_start: Le64,
133    pub virt_end: Le64,
134    pub phys_start: Le64,
135    pub flags: Le32,
136}
137
138#[repr(C, packed)]
139#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
140pub struct virtio_iommu_req_unmap {
141    pub domain: Le32,
142    pub virt_start: Le64,
143    pub virt_end: Le64,
144    pub reserved: [u8; 4usize],
145}
146
147#[repr(C, packed)]
148#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
149pub struct virtio_iommu_probe_property {
150    pub type_: Le16,
151    pub length: Le16,
152}
153
154#[repr(C, packed)]
155#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
156pub struct virtio_iommu_probe_resv_mem {
157    pub head: virtio_iommu_probe_property,
158    pub subtype: u8,
159    pub reserved: [u8; 3usize],
160    pub start: Le64,
161    pub end: Le64,
162}
163
164#[repr(C, packed)]
165#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
166pub struct virtio_iommu_req_probe {
167    pub endpoint: Le32,
168    pub reserved: [u64; 8usize],
169}
170
171#[repr(C, packed)]
172#[derive(Debug, Default, Copy, Clone)]
173pub struct virtio_iommu_fault {
174    pub reason: u8,
175    pub reserved: [u8; 3usize],
176    pub flags: Le32,
177    pub endpoint: Le32,
178    pub reserved2: [u8; 4usize],
179    pub address: Le64,
180}