/rust/registry/src/index.crates.io-1949cf8c6b5b557f/mesa3d_util-0.1.75/defines.rs
Line | Count | Source |
1 | | // Copyright 2025 Google |
2 | | // SPDX-License-Identifier: MIT |
3 | | |
4 | | use std::fmt; |
5 | | use std::time::Duration; |
6 | | |
7 | | use crate::error::MesaError; |
8 | | use crate::error::MesaResult; |
9 | | use crate::OwnedDescriptor; |
10 | | |
11 | | /// Mapped memory caching flags (see virtio_gpu spec) |
12 | | pub const MESA_MAP_CACHE_MASK: u32 = 0x0f; |
13 | | pub const MESA_MAP_CACHE_CACHED: u32 = 0x01; |
14 | | pub const MESA_MAP_CACHE_UNCACHED: u32 = 0x02; |
15 | | pub const MESA_MAP_CACHE_WC: u32 = 0x03; |
16 | | /// Access flags (not in virtio_gpu spec) |
17 | | pub const MESA_MAP_ACCESS_MASK: u32 = 0xf0; |
18 | | pub const MESA_MAP_ACCESS_READ: u32 = 0x10; |
19 | | pub const MESA_MAP_ACCESS_WRITE: u32 = 0x20; |
20 | | pub const MESA_MAP_ACCESS_RW: u32 = 0x30; |
21 | | |
22 | | /// Mesa handle types (memory and sync in same namespace) |
23 | | pub const MESA_HANDLE_TYPE_MEM_OPAQUE_FD: u32 = 0x0001; |
24 | | pub const MESA_HANDLE_TYPE_MEM_DMABUF: u32 = 0x0002; |
25 | | pub const MESA_HANDLE_TYPE_MEM_OPAQUE_WIN32: u32 = 0x0003; |
26 | | pub const MESA_HANDLE_TYPE_MEM_SHM: u32 = 0x0004; |
27 | | pub const MESA_HANDLE_TYPE_MEM_ZIRCON: u32 = 0x0005; |
28 | | |
29 | | pub const MESA_HANDLE_TYPE_SIGNAL_OPAQUE_FD: u32 = 0x0010; |
30 | | pub const MESA_HANDLE_TYPE_SIGNAL_SYNC_FD: u32 = 0x0020; |
31 | | pub const MESA_HANDLE_TYPE_SIGNAL_OPAQUE_WIN32: u32 = 0x0030; |
32 | | pub const MESA_HANDLE_TYPE_SIGNAL_ZIRCON: u32 = 0x0040; |
33 | | pub const MESA_HANDLE_TYPE_SIGNAL_EVENT_FD: u32 = 0x0050; |
34 | | |
35 | | /// Handle to OS-specific memory or synchronization objects. |
36 | | pub struct MesaHandle { |
37 | | pub os_handle: OwnedDescriptor, |
38 | | pub handle_type: u32, |
39 | | } |
40 | | |
41 | | impl MesaHandle { |
42 | | /// Clones an existing Mesahandle, by using OS specific mechanisms. |
43 | 0 | pub fn try_clone(&self) -> MesaResult<MesaHandle> { |
44 | 0 | let clone = self |
45 | 0 | .os_handle |
46 | 0 | .try_clone() |
47 | 0 | .map_err(|_| MesaError::InvalidMesaHandle)?; |
48 | 0 | Ok(MesaHandle { |
49 | 0 | os_handle: clone, |
50 | 0 | handle_type: self.handle_type, |
51 | 0 | }) |
52 | 0 | } |
53 | | } |
54 | | |
55 | | #[repr(C)] |
56 | | #[derive(Copy, Clone, Debug)] |
57 | | pub struct MesaMapping { |
58 | | pub ptr: u64, |
59 | | pub size: u64, |
60 | | } |
61 | | |
62 | | impl fmt::Debug for MesaHandle { |
63 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
64 | 0 | f.debug_struct("Handle debug").finish() |
65 | 0 | } |
66 | | } |
67 | | |
68 | | pub enum TubeType { |
69 | | Stream, |
70 | | Packet, |
71 | | } |
72 | | |
73 | | pub enum WaitTimeout { |
74 | | Finite(Duration), |
75 | | NoTimeout, |
76 | | } |
77 | | |
78 | | pub struct WaitEvent { |
79 | | pub connection_id: u64, |
80 | | pub hung_up: bool, |
81 | | pub readable: bool, |
82 | | } |
83 | | |
84 | | #[allow(dead_code)] |
85 | | pub const WAIT_CONTEXT_MAX: usize = 16; |
86 | | |
87 | | pub enum DescriptorType { |
88 | | Unknown, |
89 | | Memory(u32), |
90 | | WritePipe, |
91 | | } |
92 | | |
93 | | /// # Safety |
94 | | /// |
95 | | /// Caller must ensure that MappedRegion's lifetime contains the lifetime of |
96 | | /// pointer returned. |
97 | | pub unsafe trait MappedRegion: Send + Sync { |
98 | | /// Returns a pointer to the beginning of the memory region. Should only be |
99 | | /// used for passing this region to ioctls for setting guest memory. |
100 | | fn as_ptr(&self) -> *mut u8; |
101 | | |
102 | | /// Returns the size of the memory region in bytes. |
103 | | fn size(&self) -> usize; |
104 | | |
105 | | /// Returns mesa mapping representation of the region |
106 | | fn as_mesa_mapping(&self) -> MesaMapping; |
107 | | } |
108 | | |
109 | | #[macro_export] |
110 | | macro_rules! log_status { |
111 | | ($result:expr) => { |
112 | | match $result { |
113 | | Ok(_) => (), |
114 | | Err(e) => error!("Error recieved: {}", e), |
115 | | } |
116 | | }; |
117 | | } |