1 // Copyright 2021 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 //! Provides utilities to bind and open a VFIO PCI device. 6 7 use std::path::Path; 8 use std::sync::Arc; 9 10 use anyhow::Context; 11 use anyhow::Result; 12 use sync::Mutex; 13 14 use crate::vfio::VfioContainer; 15 use crate::vfio::VfioDevice; 16 17 /// Opens device with given sysfs path as `VfioDevice`. open_vfio_device<P: AsRef<Path>>(vfio_path: &P) -> Result<VfioDevice>18pub fn open_vfio_device<P: AsRef<Path>>(vfio_path: &P) -> Result<VfioDevice> { 19 let vfio_container = Arc::new(Mutex::new(VfioContainer::new()?)); 20 VfioDevice::new(vfio_path, vfio_container).context("failed to create VFIO device") 21 } 22