pub struct UniversalPlatform { /* private fields */ }Expand description
Universal platform implementation for generic FPGA management.
This struct provides a platform implementation that works with any FPGA device using the standard Linux FPGA subsystem. It uses lazy initialization to create FPGA and overlay handler instances on first access, ensuring efficient resource usage.
The #[platform] macro automatically registers this platform with the compatibility
string “universal”, making it available as a fallback for devices without specific
platform support.
§Fields
fpga- Lazily initialized FPGA device instanceoverlay_handler- Lazily initialized overlay handler instance
§Thread Safety
This struct is thread-safe thanks to OnceLock, which ensures that initialization
happens exactly once even with concurrent access.
Implementations§
Source§impl UniversalPlatform
impl UniversalPlatform
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Universal platform instance.
Creates an empty platform with uninitialized FPGA and overlay handler instances.
The actual components will be lazily initialized on first access through the
Platform trait methods.
§Returns: Self
- New UniversalPlatform instance ready for use
§Examples
use crate::platforms::universal::UniversalPlatform;
let platform = platform_for_known_platform("universal")?;Trait Implementations§
Source§impl Debug for UniversalPlatform
impl Debug for UniversalPlatform
Source§impl Default for UniversalPlatform
impl Default for UniversalPlatform
Source§impl Platform for UniversalPlatform
impl Platform for UniversalPlatform
Source§fn fpga(&self, device_handle: &str) -> Result<&dyn Fpga, FpgadError>
fn fpga(&self, device_handle: &str) -> Result<&dyn Fpga, FpgadError>
Get or initialize the FPGA device instance.
Returns a reference to the UniversalFPGA instance for the specified device.
On first call, this creates and initializes the FPGA instance. Subsequent calls
return the same cached instance.
§Arguments
device_handle- The device handle (e.g., “fpga0”)
§Returns: Result<&dyn Fpga, FpgadError>
Ok(&dyn Fpga)- Reference to the FPGA device instance
§Note
This implementation currently never returns an error, but the Result type is required by the Platform trait to support platform-specific validation.
Source§fn overlay_handler(
&self,
overlay_handle: &str,
) -> Result<&dyn OverlayHandler, FpgadError>
fn overlay_handler( &self, overlay_handle: &str, ) -> Result<&dyn OverlayHandler, FpgadError>
Get or initialize the overlay handler instance.
Returns a reference to the UniversalOverlayHandler instance for the specified
overlay. On first call, this creates and initializes the handler. This method also
validates that the configfs overlay directory exists.
§Arguments
overlay_handle- The overlay handle (directory name in configfs)
§Returns: Result<&dyn OverlayHandler, FpgadError>
Ok(&dyn OverlayHandler)- Reference to the overlay handler instanceErr(FpgadError::Argument)- Overlay path has no parent or parent doesn’t exist
§Implementation Note
This method includes a workaround for the unstable get_or_try_init feature.
Once that feature is stable, the error handling can be improved. See:
https://github.com/rust-lang/rust/issues/121641