1#![doc = include_str!("./README.md")]
2
3#![allow(non_upper_case_globals)]
4#![allow(non_camel_case_types)]
5#![allow(non_snake_case)]
6
7#[allow(unused_imports)]
8#[allow(dead_code)]
9#[allow(clippy::all)]
10#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
11mod bindings {
12 #[cfg(not(feature = "dynamic_loading"))]
13 mod drm;
14 #[cfg(not(feature = "dynamic_loading"))]
15 pub use drm::*;
16
17 #[cfg(feature = "dynamic_loading")]
18 mod dyn_drm;
19 #[cfg(feature = "dynamic_loading")]
20 pub use dyn_drm::*;
21
22 #[cfg(feature = "dynamic_loading")]
23 mod dyn_drm_amdgpu;
24 #[cfg(feature = "dynamic_loading")]
25 pub use dyn_drm_amdgpu::*;
26
27 mod amdgpu_ids;
28 pub use amdgpu_ids::AMDGPU_IDS;
29 mod amdgpu_ids_2;
30 pub use amdgpu_ids_2::AMDGPU_IDS_2;
31
32 pub mod ppt {
33 pub mod smu_v11_0_0_ppt;
34 pub mod smu_v11_0_7_ppt;
35 pub mod smu_v13_0_0_ppt;
36 pub mod smu_v13_0_7_ppt;
37 }
38}
39
40#[cfg(feature = "dynamic_loading")]
41use std::sync::Arc;
42#[cfg(feature = "dynamic_loading")]
43use bindings::{DynLibDrm, DynLibDrmAmdgpu};
44
45#[cfg(feature = "dynamic_loading")]
46const LIBDRM_NAME: &str = "libdrm.so.2";
47#[cfg(feature = "dynamic_loading")]
48const LIBDRM_AMDGPU_NAME: &str = "libdrm_amdgpu.so.1";
49
50#[derive(Clone)]
51pub struct LibDrm {
52 #[cfg(feature = "dynamic_loading")]
53 pub(crate) libdrm: Arc<DynLibDrm>,
54}
55
56#[cfg(feature = "link_drm")]
57impl LibDrm {
58 pub fn new() -> Result<Self, ()> {
59 Ok(Self {})
60 }
61}
62
63#[cfg(feature = "dynamic_loading")]
64impl LibDrm {
65 pub fn new() -> Result<Self, ::libloading::Error> {
66 let libdrm = unsafe { Arc::new(DynLibDrm::new(LIBDRM_NAME)?) };
67
68 Ok(Self { libdrm })
69 }
70}
71
72impl From<LibDrmAmdgpu> for LibDrm {
73 fn from(_lib: LibDrmAmdgpu) -> Self {
74 Self {
75 #[cfg(feature = "dynamic_loading")]
76 libdrm: _lib.libdrm.clone(),
77 }
78 }
79}
80
81#[derive(Clone)]
82pub struct LibDrmAmdgpu {
83 #[cfg(feature = "dynamic_loading")]
84 pub(crate) libdrm: Arc<DynLibDrm>,
85 #[cfg(feature = "dynamic_loading")]
86 pub(crate) libdrm_amdgpu: Arc<DynLibDrmAmdgpu>,
87}
88
89#[cfg(feature = "link_drm")]
90impl LibDrmAmdgpu {
91 pub fn new() -> Result<Self, ()> {
92 Ok(Self {})
93 }
94
95 pub fn new_with_libdrm(_lib: LibDrm) -> Result<Self, ()> {
96 Ok(Self {})
97 }
98}
99
100#[cfg(feature = "dynamic_loading")]
101impl LibDrmAmdgpu {
102 pub fn new() -> Result<Self, ::libloading::Error> {
103 let libdrm = unsafe { Arc::new(DynLibDrm::new(LIBDRM_NAME)?) };
104 let libdrm_amdgpu = unsafe { Arc::new(DynLibDrmAmdgpu::new(LIBDRM_AMDGPU_NAME)?) };
105
106 Ok(Self { libdrm, libdrm_amdgpu })
107 }
108
109 pub fn new_with_libdrm(lib: LibDrm) -> Result<Self, ::libloading::Error> {
110 let libdrm_amdgpu = unsafe { Arc::new(DynLibDrmAmdgpu::new(LIBDRM_AMDGPU_NAME)?) };
111
112 Ok(Self { libdrm: lib.libdrm.clone(), libdrm_amdgpu })
113 }
114}
115
116#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
117mod amdgpu;
118#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
119pub mod AMDGPU {
120 pub use super::amdgpu::*;
121}
122
123#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
124mod pci;
125#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
126pub mod PCI {
127 pub use super::pci::*;
128}
129
130#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
131#[cfg(any(feature = "link_drm", feature = "dynamic_loading"))]
132mod drm_version;
133#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
134#[cfg(any(feature = "link_drm", feature = "dynamic_loading"))]
135pub use drm_version::*;
136
137#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
138#[cfg(any(feature = "link_drm", feature = "dynamic_loading"))]
139mod drm_mode;
140#[cfg(not(any(feature = "buildtime_bindgen", feature = "convert_amdgpu_ids")))]
141#[cfg(any(feature = "link_drm", feature = "dynamic_loading"))]
142pub use drm_mode::*;
143
144#[macro_export]
146macro_rules! query_error {
147 ($r: expr_2021) => {
148 if $r != 0 {
149 return Err($r);
150 }
151 };
152}