LibDrmAmdgpu

Struct LibDrmAmdgpu 

Source
pub struct LibDrmAmdgpu {}

Implementations§

Source§

impl LibDrmAmdgpu

Source

pub fn init_device_handle( &self, fd: i32, ) -> Result<(DeviceHandle, u32, u32), i32>

Examples found in repository?
examples/ip_discovery.rs (line 13)
5fn main() {
6    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
7    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
8    let (amdgpu_dev, _, _) = {
9        use std::os::fd::IntoRawFd;
10
11        let f = File::open(device_path).unwrap();
12
13        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
14    };
15
16    let path = amdgpu_dev.get_sysfs_path().unwrap();
17
18    let ip_die_entries = IpDieEntry::get_all_entries_from_sysfs(&path);
19
20    for entry in &ip_die_entries {
21        println!("\ndie_id: {:>2}", entry.die_id);
22
23        for ip_hw_id in &entry.ip_hw_ids {
24            println!("{ip_hw_id:#?}");
25        }
26    }
27}
More examples
Hide additional examples
examples/gpu_metrics.rs (line 13)
5fn main() {
6    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
7    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
8    let (amdgpu_dev, _, _) = {
9        use std::os::fd::IntoRawFd;
10
11        let f = File::open(device_path).unwrap();
12
13        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
14    };
15
16    let path = amdgpu_dev.get_sysfs_path().unwrap();
17
18    match amdgpu_dev.get_gpu_metrics_from_sysfs_path(&path) { Ok(metrics) => {
19        println!("{:#?}", metrics);
20
21        if let Some(socket_power) = metrics.get_average_socket_power() {
22            println!("Average Socket Power: {socket_power} W");
23        }
24
25        if let Some(thr) = metrics.get_throttle_status_info() {
26            println!("Throttle Status: {:?}", thr.get_all_throttler());
27        }
28    } _ => {
29        let ext_info = amdgpu_dev.device_info().unwrap();
30        let asic_name = ext_info.get_asic_name();
31
32        println!("{asic_name} dose not support GPU metrics.");
33        println!("Vega12 (dGPU) or later, Renoir (APU) or later supports GPU metrics.")
34    }}
35}
examples/stable_pstate.rs (line 13)
4fn info(pci_bus: &PCI::BUS_INFO) {
5    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
6    let Ok(device_path) = pci_bus.get_drm_render_path() else { return };
7    let (amdgpu_dev, _major, _minor) = {
8        use std::fs::File;
9        use std::os::fd::IntoRawFd;
10
11        let fd = File::open(device_path).unwrap();
12
13        libdrm_amdgpu.init_device_handle(fd.into_raw_fd()).unwrap()
14    };
15
16    let ext_info = amdgpu_dev.device_info().unwrap();
17    println!("Marketing Name: [{}]", ext_info.find_device_name_or_default());
18
19    {
20        let ctx = amdgpu_dev.create_context().unwrap();
21        let current_stable_pstate = ctx.get_stable_pstate().unwrap();
22        println!("Current Stable PState: {current_stable_pstate:?}");
23
24        println!("Set STANDARD PState");
25
26        match ctx.set_stable_pstate(AMDGPU::StablePstateFlag::STANDARD) {
27            Ok(_) => {
28            },
29            Err(err) => println!("    Error: {err}"),
30        }
31
32        println!("Press enter to revert stable_pstate");
33
34        let mut input = String::new();
35        std::io::stdin().read_line(&mut input).unwrap();
36    }
37
38    println!("  stable_pstate is reverted.");
39}
examples/vbios_dump.rs (line 25)
17fn main() {
18    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
19    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
20    let (amdgpu_dev, _, _) = {
21        use std::os::fd::IntoRawFd;
22
23        let f = File::open(device_path).unwrap();
24
25        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
26    };
27
28    if let Ok(vbios) = amdgpu_dev.get_vbios_info() {
29        println!("\nVBIOS info:");
30        println!("name: [{}]", vbios.name);
31        println!("pn: [{}]", vbios.pn);
32        println!("ver: [{}]", vbios.ver);
33        println!("date: [{}]", vbios.date);
34        println!("vbios size: {}", vbios.size);
35
36        let args: Vec<String> = std::env::args().collect();
37
38        if args.contains(&"-d".to_string()) || args.contains(&"--dump".to_string()) {
39            // if let Ok(vbios_image) = unsafe { amdgpu_dev.get_vbios_image_with_size(vbios.size) } {
40            if let Ok(vbios_image) = amdgpu_dev.get_vbios_image() {
41                let name = vbios.name.replace(' ', "_").replace('/', "_");
42                dump(&vbios_image, name).unwrap();
43            }
44        } else {
45            println!("If you need a VBIOS image, add \"-d\" or \"--dump\" as an argument and run.");
46        }
47    }
48}
examples/vbios_parser.rs (line 14)
6fn main() {
7    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
8    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
9    let (amdgpu_dev, _, _) = {
10        use std::os::fd::IntoRawFd;
11
12        let f = File::open(device_path).unwrap();
13
14        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
15    };
16
17    let Ok(vbios_image) = amdgpu_dev.get_vbios_image() else { return };
18
19    let vbios_parser = VbiosParser::new(vbios_image);
20
21    if !vbios_parser.valid_vbios() || !vbios_parser.check_length() {
22        panic!();
23    }
24
25    if let Some(name) = vbios_parser.get_vbios_name() {
26        println!("name: {name:?}");
27    }
28
29    let rom_header = vbios_parser.get_atom_rom_header().unwrap();
30    println!("{rom_header:#X?}");
31
32    let data_table = vbios_parser.get_atom_data_table(&rom_header).unwrap();
33    println!("{data_table:#X?}");
34
35    if let Some(h) = vbios_parser.get_atom_firmware_info_header(&data_table) {
36        println!("{h:#?}");
37        match (h.format_revision, h.content_revision) {
38            (3, 5) => {
39                let firmware_info = vbios_parser.get_atom_firmware_info_v3_5(&data_table).unwrap();
40                println!("firmwareinfo: {firmware_info:#?}");
41            },
42            _ => {
43                let firmware_info = vbios_parser.get_atom_firmware_info(&data_table).unwrap();
44                println!("firmwareinfo: {firmware_info:#?}");
45            },
46        }
47    }
48}
examples/pp_table.rs (line 13)
5fn main() {
6    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
7    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
8    let (amdgpu_dev, _, _) = {
9        use std::os::fd::IntoRawFd;
10
11        let f = File::open(device_path).unwrap();
12
13        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
14    };
15
16    let sysfs = amdgpu_dev.get_sysfs_path().unwrap();
17    let smu = IpHwId::get_from_die_id_sysfs(HwId::MP1, &sysfs.join("ip_discovery/die/0/")).ok().and_then(|smu| smu.instances.get(0).map(|v| v.clone()));
18
19    if let Some(smu) = &smu {
20        println!("SMU (MP1) version: {}.{}.{}", smu.major, smu.minor, smu.revision);
21    }
22
23    let pp_table_bytes_sysfs = std::fs::read(&sysfs.join("pp_table")).ok();
24    let pp_table_bytes_vbios = amdgpu_dev.get_vbios_image().ok().and_then(|vbios_image| {
25        use AMDGPU::VBIOS::VbiosParser;
26
27        let vbios_parser = VbiosParser::new(vbios_image);
28        let rom_header = vbios_parser.get_atom_rom_header()?;
29        let data_table = vbios_parser.get_atom_data_table(&rom_header)?;
30
31        Some(vbios_parser.get_powerplay_table_bytes(&data_table)?.to_vec())
32    });
33
34    for (bytes, src) in [
35        (pp_table_bytes_sysfs, "sysfs"),
36        (pp_table_bytes_vbios, "VBIOS"),
37    ] {
38        let Some(bytes) = bytes else { continue };
39        let pp_table = if let Some(smu) = &smu {
40            AMDGPU::PPTable::decode_with_smu_version(&bytes, smu.version())
41        } else {
42            AMDGPU::PPTable::decode(&bytes)
43        };
44
45        println!("from {src}: {pp_table:#?}");
46    }
47}
Source§

impl LibDrmAmdgpu

Source

pub fn new() -> Result<Self, ()>

Examples found in repository?
examples/amdgpu_info.rs (line 379)
378fn main() {
379    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
380    let pci_devs = AMDGPU::get_all_amdgpu_pci_bus();
381
382    if pci_devs.is_empty() {
383        panic!("No AMDGPU devices.");
384    }
385
386    for pci_bus in &pci_devs {
387        info(&libdrm_amdgpu, pci_bus);
388    }
389}
More examples
Hide additional examples
examples/ip_discovery.rs (line 6)
5fn main() {
6    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
7    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
8    let (amdgpu_dev, _, _) = {
9        use std::os::fd::IntoRawFd;
10
11        let f = File::open(device_path).unwrap();
12
13        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
14    };
15
16    let path = amdgpu_dev.get_sysfs_path().unwrap();
17
18    let ip_die_entries = IpDieEntry::get_all_entries_from_sysfs(&path);
19
20    for entry in &ip_die_entries {
21        println!("\ndie_id: {:>2}", entry.die_id);
22
23        for ip_hw_id in &entry.ip_hw_ids {
24            println!("{ip_hw_id:#?}");
25        }
26    }
27}
examples/gpu_metrics.rs (line 6)
5fn main() {
6    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
7    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
8    let (amdgpu_dev, _, _) = {
9        use std::os::fd::IntoRawFd;
10
11        let f = File::open(device_path).unwrap();
12
13        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
14    };
15
16    let path = amdgpu_dev.get_sysfs_path().unwrap();
17
18    match amdgpu_dev.get_gpu_metrics_from_sysfs_path(&path) { Ok(metrics) => {
19        println!("{:#?}", metrics);
20
21        if let Some(socket_power) = metrics.get_average_socket_power() {
22            println!("Average Socket Power: {socket_power} W");
23        }
24
25        if let Some(thr) = metrics.get_throttle_status_info() {
26            println!("Throttle Status: {:?}", thr.get_all_throttler());
27        }
28    } _ => {
29        let ext_info = amdgpu_dev.device_info().unwrap();
30        let asic_name = ext_info.get_asic_name();
31
32        println!("{asic_name} dose not support GPU metrics.");
33        println!("Vega12 (dGPU) or later, Renoir (APU) or later supports GPU metrics.")
34    }}
35}
examples/stable_pstate.rs (line 5)
4fn info(pci_bus: &PCI::BUS_INFO) {
5    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
6    let Ok(device_path) = pci_bus.get_drm_render_path() else { return };
7    let (amdgpu_dev, _major, _minor) = {
8        use std::fs::File;
9        use std::os::fd::IntoRawFd;
10
11        let fd = File::open(device_path).unwrap();
12
13        libdrm_amdgpu.init_device_handle(fd.into_raw_fd()).unwrap()
14    };
15
16    let ext_info = amdgpu_dev.device_info().unwrap();
17    println!("Marketing Name: [{}]", ext_info.find_device_name_or_default());
18
19    {
20        let ctx = amdgpu_dev.create_context().unwrap();
21        let current_stable_pstate = ctx.get_stable_pstate().unwrap();
22        println!("Current Stable PState: {current_stable_pstate:?}");
23
24        println!("Set STANDARD PState");
25
26        match ctx.set_stable_pstate(AMDGPU::StablePstateFlag::STANDARD) {
27            Ok(_) => {
28            },
29            Err(err) => println!("    Error: {err}"),
30        }
31
32        println!("Press enter to revert stable_pstate");
33
34        let mut input = String::new();
35        std::io::stdin().read_line(&mut input).unwrap();
36    }
37
38    println!("  stable_pstate is reverted.");
39}
examples/vbios_dump.rs (line 18)
17fn main() {
18    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
19    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
20    let (amdgpu_dev, _, _) = {
21        use std::os::fd::IntoRawFd;
22
23        let f = File::open(device_path).unwrap();
24
25        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
26    };
27
28    if let Ok(vbios) = amdgpu_dev.get_vbios_info() {
29        println!("\nVBIOS info:");
30        println!("name: [{}]", vbios.name);
31        println!("pn: [{}]", vbios.pn);
32        println!("ver: [{}]", vbios.ver);
33        println!("date: [{}]", vbios.date);
34        println!("vbios size: {}", vbios.size);
35
36        let args: Vec<String> = std::env::args().collect();
37
38        if args.contains(&"-d".to_string()) || args.contains(&"--dump".to_string()) {
39            // if let Ok(vbios_image) = unsafe { amdgpu_dev.get_vbios_image_with_size(vbios.size) } {
40            if let Ok(vbios_image) = amdgpu_dev.get_vbios_image() {
41                let name = vbios.name.replace(' ', "_").replace('/', "_");
42                dump(&vbios_image, name).unwrap();
43            }
44        } else {
45            println!("If you need a VBIOS image, add \"-d\" or \"--dump\" as an argument and run.");
46        }
47    }
48}
examples/vbios_parser.rs (line 7)
6fn main() {
7    let libdrm_amdgpu = LibDrmAmdgpu::new().unwrap();
8    let device_path = std::env::var("AMDGPU_PATH").unwrap_or("/dev/dri/renderD128".to_string());
9    let (amdgpu_dev, _, _) = {
10        use std::os::fd::IntoRawFd;
11
12        let f = File::open(device_path).unwrap();
13
14        libdrm_amdgpu.init_device_handle(f.into_raw_fd()).unwrap()
15    };
16
17    let Ok(vbios_image) = amdgpu_dev.get_vbios_image() else { return };
18
19    let vbios_parser = VbiosParser::new(vbios_image);
20
21    if !vbios_parser.valid_vbios() || !vbios_parser.check_length() {
22        panic!();
23    }
24
25    if let Some(name) = vbios_parser.get_vbios_name() {
26        println!("name: {name:?}");
27    }
28
29    let rom_header = vbios_parser.get_atom_rom_header().unwrap();
30    println!("{rom_header:#X?}");
31
32    let data_table = vbios_parser.get_atom_data_table(&rom_header).unwrap();
33    println!("{data_table:#X?}");
34
35    if let Some(h) = vbios_parser.get_atom_firmware_info_header(&data_table) {
36        println!("{h:#?}");
37        match (h.format_revision, h.content_revision) {
38            (3, 5) => {
39                let firmware_info = vbios_parser.get_atom_firmware_info_v3_5(&data_table).unwrap();
40                println!("firmwareinfo: {firmware_info:#?}");
41            },
42            _ => {
43                let firmware_info = vbios_parser.get_atom_firmware_info(&data_table).unwrap();
44                println!("firmwareinfo: {firmware_info:#?}");
45            },
46        }
47    }
48}
Source

pub fn new_with_libdrm(_lib: LibDrm) -> Result<Self, ()>

Trait Implementations§

Source§

impl Clone for LibDrmAmdgpu

Source§

fn clone(&self) -> LibDrmAmdgpu

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<LibDrmAmdgpu> for LibDrm

Source§

fn from(_lib: LibDrmAmdgpu) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.