OPAE C API Reference¶
The reference documentation for the OPAE C API is grouped into the following sections:
Types¶
The OPAE C API defines a number of types; most prominent are the types fpga_token, fpga_handle, and fpga_properties. All regular types are defined in [types.h](#types-h), while the values of enumeration types are defined in [types_enum.h](#types-enum-h).
types.h¶
Type definitions for FPGA API.
OPAE uses the three opaque types fpga_properties, fpga_token, and fpga_handle to create a hierarchy of objects that can be used to enumerate, reference, acquire, and query FPGA resources. This object model is designed to be extensible to account for different FPGA architectures and platforms.
Defines
-
FPGA_ERROR_NAME_MAX
¶ Information about an error register
This data structure captures information about an error register exposed by an accelerator resource. The error API provides functions to retrieve these information structures from a particular resource.
-
FPGA_METRIC_STR_SIZE
¶ FPGA Metric string size
-
fpga_is_parent_child
(__parent_hdr, __child_hdr)¶ Determine token parent/child relationship
Given pointers to two fpga_token_header structs, determine whether the first is the parent of the second. A parent will have objtype == FPGA_DEVICE. A child will have objtype == FPGA_ACCELERATOR. The PCIe address of the two headers will match in all but the function fields.
Typedefs
-
typedef void *
fpga_properties
¶ Object for expressing FPGA resource properties
fpga_properties
objects encapsulate all enumerable information about an FPGA resources. They can be used for two purposes: selective enumeration (discovery) and querying information about existing resources.For selective enumeration, usually an empty
fpga_properties
object is created (using fpgaGetProperties()) and then populated with the desired criteria for enumeration. An array offpga_properties
can then be passed to fpgaEnumerate(), which will return a list offpga_token
objects matching these criteria.For querying properties of existing FPGA resources, fpgaGetProperties() can also take an
fpga_token
and will return anfpga_properties
object populated with information about the resource referenced by that token.After use,
fpga_properties
objects should be destroyed using fpga_destroyProperties() to free backing memory used by thefpga_properties
object.
-
typedef void *
fpga_token
¶ Token for referencing FPGA resources
An
fpga_token
serves as a reference to a specific FPGA resource present in the system. Holding anfpga_token
does not constitute ownership of the FPGA resource - it merely allows the user to query further information about a resource, or to use fpgaOpen() to acquire ownership.fpga_token
s are usually returned by fpgaEnumerate() or fpgaPropertiesGetParent(), and used by fpgaOpen() to acquire ownership and yield a handle to the resource. Some API calls also takefpga_token
s as arguments if they don’t require ownership of the resource in question.
-
typedef void *
fpga_handle
¶ Handle to an FPGA resource
A valid
fpga_handle
object, as populated by fpgaOpen(), denotes ownership of an FPGA resource. Note that ownership can be exclusive or shared, depending on the flags used in fpgaOpen(). Ownership can be released by calling fpgaClose(), which will render the underlying handle invalid.Many OPAE C API functions require a valid token (which is synonymous with ownership of the resource).
-
typedef uint8_t
fpga_guid
[16]¶ Globally unique identifier (GUID)
GUIDs are used widely within OPAE for helping identify FPGA resources. For example, every FPGA resource has a
guid
property, which can be (and in the case of FPGA_ACCELERATOR resource primarily is) used for enumerating a resource of a specific type.fpga_guid
is compatible with libuuid’s uuid_t, so users can use libuuid functions like uuid_parse() to create and work with GUIDs.
-
typedef void *
fpga_event_handle
¶ Handle to an event object
OPAE provides an interface to asynchronous events that can be generated by different FPGA resources. The event API provides functions to register for these events; associated with every event a process has registered for is an
fpga_event_handle
, which encapsulates the OS-specific data structure for event objects.After use,
fpga_event_handle
objects should be destroyed using fpgaDestroyEventHandle() to free backing memory used by thefpga_event_handle
object.
-
typedef void *
fpga_object
¶ Object pertaining to an FPGA resource as identified by a unique name
An
fpga_object
represents either a device attribute or a container of attributes. Similar to filesystems, a ‘/’ may be used to seperate objects in an object hierarchy. Once on object is acquired, it may be used to read or write data in a resource attribute or to query sub-objects if the object is a container object. The data in an object is buffered and will be kept around until the object is destroyed. Additionally, the data in an attribute can by synchronized from the owning resource using the FPGA_OBJECT_SYNC flag during read operations. The name identifying the object is unique with respect to the resource that owns it. A parent resource may be identified by anfpga_token
object, by anfpga_handle
object, or anotherfpga_object
object. If a handle object is used when opening the object, then the object is opened with read-write access. Otherwise, the object is read-only.
-
struct
fpga_version
¶ - #include <opae/types.h>
Semantic version
Data structure for expressing version identifiers following the semantic versioning scheme. Used in various properties for tracking component versions.
-
struct
fpga_error_info
¶ - #include <opae/types.h>
-
union
metric_value
¶ - #include <opae/types.h>
Metric value union
-
struct
fpga_metric_info
¶ - #include <opae/types.h>
Metric info struct
-
struct
fpga_metric
¶ - #include <opae/types.h>
Metric struct
-
struct
threshold
¶ - #include <opae/types.h>
Threshold struct
-
struct
metric_threshold
¶ - #include <opae/types.h>
-
struct
fpga_token_header
¶ - #include <opae/types.h>
Internal token type header
Each plugin (dfl: libxfpga.so, vfio: libopae-v.so) implements its own proprietary token type. This header must appear at offset zero within that structure.
eg, see lib/plugins/xfpga/types_int.h:struct _fpga_token and lib/plugins/vfio/opae_vfio.h:struct _vfio_token.
types_enum.h¶
Definitions of enumerated types for the OPAE C API.
This file defines return and error codes, event and object types, states, and flags as used or reported by OPAE C API functions.
Enums
-
enum
fpga_result
¶ OPAE C API function return codes
Every public API function exported by the OPAE C library will return one of these codes. Usually, FPGA_OK denotes successful completion of the requested operation, while any return code other than FPGA_OK indicates an error or other deviation from the expected behavior. Users of the OPAE C API should always check the return codes of the APIs they call, and not use output parameters of functions that did not execute successfully.
The fpgaErrStr() function converts error codes into printable messages.
OPAE also has a logging mechanism that allows a developer to get more information about why a particular call failed with a specific message. If enabled, any function that returns an error code different from FPGA_OK will also print out a message with further details. This mechanism can be enabled by setting the environment variable
LIBOPAE_LOG
to 1 before running the respective application.Values:
-
enumerator
FPGA_OK
¶ Operation completed successfully
-
enumerator
FPGA_INVALID_PARAM
¶ Invalid parameter supplied
-
enumerator
FPGA_BUSY
¶ Resource is busy
-
enumerator
FPGA_EXCEPTION
¶ An exception occurred
-
enumerator
FPGA_NOT_FOUND
¶ A required resource was not found
-
enumerator
FPGA_NO_MEMORY
¶ Not enough memory to complete operation
-
enumerator
FPGA_NOT_SUPPORTED
¶ Requested operation is not supported
-
enumerator
FPGA_NO_DRIVER
¶ Driver is not loaded
-
enumerator
FPGA_NO_DAEMON
¶ FPGA Daemon (fpgad) is not running
-
enumerator
FPGA_NO_ACCESS
¶ Insufficient privileges or permissions
-
enumerator
FPGA_RECONF_ERROR
¶ Error while reconfiguring FPGA
-
enumerator
-
enum
fpga_event_type
¶ FPGA events
OPAE currently defines the following event types that applications can register for. Note that not all FPGA resources and target platforms may support all event types.
Values:
-
enumerator
FPGA_EVENT_INTERRUPT
¶ Interrupt generated by an accelerator
-
enumerator
FPGA_EVENT_ERROR
¶ Infrastructure error event
-
enumerator
FPGA_EVENT_POWER_THERMAL
¶ Infrastructure thermal event
-
enumerator
-
enum
fpga_accelerator_state
¶ accelerator state
Values:
-
enumerator
FPGA_ACCELERATOR_ASSIGNED
¶ accelerator is opened exclusively by another process
-
enumerator
FPGA_ACCELERATOR_UNASSIGNED
¶ accelerator is free to be opened
-
enumerator
-
enum
fpga_objtype
¶ OPAE FPGA resources (objects)
These are the FPGA resources currently supported by the OPAE object model.
Values:
-
enumerator
FPGA_DEVICE
¶ FPGA_DEVICE objects represent FPGA devices and their management functionality. These objects can be opened (typically requires a certain privilege level or access permissions) and used for management functions like fpgaReconfigreSlot().
-
enumerator
FPGA_ACCELERATOR
¶ FPGA_ACCELERATOR objects represent allocatable units for accessing accelerated functions on the FPGA. They are frequently opened for interacting via control registers (MMIO), shared memory, or other, possibly platform-specific functions.
-
enumerator
-
enum
fpga_interface
¶ OPAE plugin interface
These are the supported plugin interfaces.
Values:
-
enumerator
FPGA_IFC_DFL
¶ FPGA_IFC_DFL indicates that the plugin interface is the Device Feature List driver suite.
-
enumerator
FPGA_IFC_VFIO
¶ FPGA_IFC_VFIO indicates that the plugin interface is the vfio-pci driver.
-
enumerator
FPGA_IFC_SIM
¶ FPGA_IFC_SIM indicates that the plugin interface is the AFU Simulation Environment.
-
enumerator
-
enum
fpga_buffer_flags
¶ Buffer flags
These flags can be passed to the fpgaPrepareBuffer() function.
Values:
-
enumerator
FPGA_BUF_PREALLOCATED
¶ Use existing buffer
-
enumerator
FPGA_BUF_QUIET
¶ Suppress error messages
-
enumerator
FPGA_BUF_READ_ONLY
¶ Buffer is read-only
-
enumerator
-
enum
fpga_open_flags
¶ Open flags
These flags can be passed to the fpgaOpen() function.
Values:
-
enumerator
FPGA_OPEN_SHARED
¶ Open FPGA resource for shared access
-
enumerator
-
enum
fpga_reconf_flags
¶ Reconfiguration flags
These flags can be passed to the fpgaReconfigureSlot() function.
Values:
-
enumerator
FPGA_RECONF_FORCE
¶ Reconfigure the slot without checking if it is in use
-
enumerator
FPGA_RECONF_SKIP_USRCLK
¶ Don’t configure AFU user clocks as part of PR
-
enumerator
-
enum
fpga_sysobject_flags
¶ Values:
-
enumerator
FPGA_OBJECT_SYNC
¶ Synchronize data from driver
-
enumerator
FPGA_OBJECT_GLOB
¶ Treat names as glob expressions
-
enumerator
FPGA_OBJECT_RAW
¶ Read or write object data as raw bytes
-
enumerator
FPGA_OBJECT_RECURSE_ONE
¶ Create subobjects one level down from containers
-
enumerator
FPGA_OBJECT_RECURSE_ALL
¶ Create subobjects all levels from from containers
-
enumerator
-
enum
fpga_sysobject_type
¶ Values:
-
enumerator
FPGA_OBJECT_CONTAINER
¶ Represents a group of objects
-
enumerator
FPGA_OBJECT_ATTRIBUTE
¶ An object with an attribute value that can be read/written
-
enumerator
-
enum
fpga_metric_type
¶ fpga metrics types opae defines power,thermal, performance counter and afu metric types
Values:
-
enumerator
FPGA_METRIC_TYPE_POWER
¶
-
enumerator
FPGA_METRIC_TYPE_THERMAL
¶
-
enumerator
FPGA_METRIC_TYPE_PERFORMANCE_CTR
¶
-
enumerator
FPGA_METRIC_TYPE_AFU
¶
-
enumerator
FPGA_METRIC_TYPE_UNKNOWN
¶
-
enumerator
Enumeration API¶
The OPAE enumeration API allows selective discovery of FPGA resources. When enumerating resources, a list of filter criteria can be passed to the respective function to select a subset of all resources in the system. The fpgaEnumerate() function itself then returns a list of fpga_tokens denoting resources, which can be used in subsequent API calls.
Filter criteria are specified using one or more fpga_properties object. These objects need to be created using fpgaGetProperties() (defined in <opae/properties/h>) before being passed to fpgaEnumerate(). Individual attributes of an fpga_properties object are set using specific accessors, which are also defined in <opae/properties.h>.
enum.h¶
APIs for resource enumeration and managing tokens.
These APIs are the first step for any application using OPAE to discover resources that are present on the system. They allow selective enumeration (i.e. getting a list of resources that match a given list of criteria) and methods to manage the lifecycle of tokens generated by fpgaEnumerate().
Functions
-
fpga_result
fpgaEnumerate
(const fpga_properties *filters, uint32_t num_filters, fpga_token *tokens, uint32_t max_tokens, uint32_t *num_matches)¶ Enumerate FPGA resources present in the system
This call allows the user to query the system for FPGA resources that match a certain set of criteria, e.g. all accelerators that are assigned to a host interface and available, all FPGAs of a specific type, etc.
fpgaEnumerate() will create a number of
fpga_token
s to represent the matching resources and populate the arraytokens
with these tokens. Themax_tokens
argument can be used to limit the number of tokens allocated/returned by fpgaEnumerate(); i.e., the number of tokens in the returnedtokens
array will be eithermax_tokens
ornum_matches
(the number of resources matching the filter), whichever is smaller. Use fpgaDestroyToken() to destroy tokens that are no longer needed.To query the number of matches for a particular set of filters (e.g. to allocate a
tokens
array of the appropriate size), call fpgaEnumerate() with the parametertokens
set to NULL; this will only return the number of matches innum_matches
.- Note
fpgaEnumerate() will allocate memory for the created tokens returned in
tokens
. It is the responsibility of the using application to free this memory after use by calling fpgaDestroyToken() for each of the returned tokens.- Return
FPGA_OK on success. FPGA_INVALID_PARAM if invalid pointers or objects are passed into the function. FPGA_NO_DRIVER if OPAE can’t find the respective enumeration data structures usually provided by the driver. FPGA_NO_MEMORY if there was not enough memory to create tokens.
- Parameters
[in] filters
: Array offpga_properties
objects describing the properties of the objects that should be returned. A resource is considered matching if its properties match any one of the supplied filters. To match all FPGA resources, pass an empty filters object (one without any filter criteria set) or pass a NULL filters parameter with num_filters set to 0.[in] num_filters
: Number of entries in thefilters
array, or 0 to match all FPGA resources whenfilters
is NULL.[out] tokens
: Pointer to an array of fpga_token variables to be populated. If NULL is supplied, fpgaEnumerate() will not create any tokens, but it will return the number of possible matches innum_match
.[in] max_tokens
: Maximum number of tokens that fpgaEnumerate() shall return (length oftokens
array). There may be more or fewer matches than this number;num_matches
is set to the number of actual matches.[out] num_matches
: Number of resources matching thefilter
criteria. This number can be higher than the number of tokens returned in thetokens
array (depending on the value ofmax_tokens
).
-
fpga_result
fpgaCloneToken
(fpga_token src, fpga_token *dst)¶ Clone a fpga_token object
Creates a copy of an fpga_token object.
- Note
This call creates a new token object and allocates memory for it. It is the responsibility of the using application to free this memory after use by calling fpgaDestroyToken() for the cloned token.
- Return
FPGA_OK on success
- Parameters
[in] src
: fpga_token object to copy[out] dst
: New fpga_token object cloned from ‘src’
-
fpga_result
fpgaDestroyToken
(fpga_token *token)¶ Destroy a Token
This function destroys a token created by fpgaEnumerate() and frees the associated memory.
- Note
fpgaDestroyToken() requires the address of an fpga_token as previously created by fpgaEnumerate() or fpgaCloneToken(). Passing any other value results in undefined behavior.
- Return
FPGA_OK on success
- Parameters
[in] token
: fpga_token to destroy
properties.h¶
Functions for examining and manipulating fpga_properties
objects.
In OPAE, fpga_properties
objects are used both for obtaining information about resources and for selectively enumerating resources based on their properties. This file provides accessor functions (get/set) to allow reading and writing individual items of an fpga_properties
object. Generally, not all object types supported by OPAE carry all properties. If you call a property accessor method on a fpga_properties
object that does not support this particular property, it will return FPGA_INVALID_PARAM.
Functions
-
fpga_result
fpgaGetPropertiesFromHandle
(fpga_handle handle, fpga_properties *prop)¶ Create a fpga_properties object
Initializes the memory pointed at by
prop
to represent a properties object, and populates it with the properties of the resource referred to byhandle
. Individual properties can then be queried using fpgaPropertiesGet*() accessor functions.- Note
fpgaGetPropertiesFromHandle() will allocate memory for the created properties object returned in
prop
. It is the responsibility of the caller to free this memory after use by calling fpgaDestroyProperties().- Return
FPGA_OK on success. FPGA_NO_MEMORY if no memory could be allocated to create the
fpga_properties
object. FPGA_EXCEPTION if an exception happend while initializing thefpga_properties
object.- Parameters
[in] handle
: Open handle to get properties for.[out] prop
: Pointer to a variable of type fpga_properties
-
fpga_result
fpgaGetProperties
(fpga_token token, fpga_properties *prop)¶ Create a fpga_properties object
Initializes the memory pointed at by
prop
to represent a properties object, and populates it with the properties of the resource referred to bytoken
. Individual properties can then be queried using fpgaPropertiesGet*() accessor functions.If
token
is NULL, an “empty” properties object is created to be used as a filter for fpgaEnumerate(). All individual fields are set todon
t care`, which implies that the fpga_properties object would match all FPGA resources if used for an fpgaEnumerate() query. The matching criteria can be further refined by using fpgaSet* functions on the properties object, or the object can be populated with the actual properties of a resource by using fpgaUpdateProperties().- Note
fpgaGetProperties() will allocate memory for the created properties object returned in
prop
. It is the responsibility of the caller to free this memory after use by calling fpgaDestroyProperties().- Return
FPGA_OK on success. FPGA_NO_MEMORY if no memory could be allocated to create the
fpga_properties
object. FPGA_EXCEPTION if an exception happend while initializing thefpga_properties
object.- Parameters
[in] token
: Token to get properties for. Can be NULL, which will create an empty properties object to be used as a filter for fpgaEnumerate().[out] prop
: Pointer to a variable of type fpga_properties
-
fpga_result
fpgaUpdateProperties
(fpga_token token, fpga_properties prop)¶ Update a fpga_properties object
Populates the properties object ‘prop’ with properties of the resource referred to by ‘token’. Unlike fpgaGetProperties(), this call will not create a new properties object or allocate memory for it, but use a previously created properties object.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if
token
orprop
are not valid objects. FPGA_NOT_FOUND if the resource referred to bytoken
was not found. FPGA_NO_DRIVER if not driver is loaded. FPGA_EXCEPTION if an internal exception occured when trying to updateprop
.- Parameters
[in] token
: Token to retrieve properties for[in] prop
: fpga_properties object to update
-
fpga_result
fpgaClearProperties
(fpga_properties prop)¶ Clear a fpga_properties object
Sets all fields of the properties object pointed at by ‘prop’ to ‘don’t care’, which implies that the fpga_properties object would match all FPGA resources if used for an fpgaEnumerate() query. The matching criteria can be further refined by using fpgaSet* functions on the properties object.
Instead of creating a new fpga_properties object every time, this function can be used to re-use fpga_properties objects from previous queries.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if
prop
is not a valid object. FPGA_EXCEPTION if an * internal exception occured when trying to accessprop
.- Parameters
[in] prop
: fpga_properties object to clear
-
fpga_result
fpgaCloneProperties
(fpga_properties src, fpga_properties *dst)¶ Clone a fpga_properties object
Creates a copy of an fpga_properties object.
- Note
This call creates a new properties object and allocates memory for it. Both the ‘src’ and the newly created ‘dst’ objects will eventually need to be destroyed using fpgaDestroyProperties().
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if
src
is not a valid object, or ifdst
is NULL. FPGA_NO_MEMORY if there was not enough memory to allocate anfpga_properties
object fordst
. FPGA_EXCEPTION if an internal exception occurred either accessingsrc
or updatingdst
.- Parameters
[in] src
: fpga_properties object to copy[out] dst
: New fpga_properties object cloned from ‘src’
-
fpga_result
fpgaDestroyProperties
(fpga_properties *prop)¶ Destroy a fpga_properties object
Destroys an existing fpga_properties object that the caller has previously created using fpgaGetProperties() or fpgaCloneProperties().
- Note
fpgaDestroyProperties() requires the address of an fpga_properties object, similar to fpgaGetPropertiesFromHandle(), fpgaGetProperties(), and fpgaCloneProperties(). Passing any other value results in undefined behavior.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM is
prop
is not a valid object. FPGA_EXCEPTION if an internal exception occurrred while trying to accessprop
.- Parameters
[inout] prop
: Pointer to the fpga_properties object to destroy
-
fpga_result
fpgaPropertiesGetParent
(const fpga_properties prop, fpga_token *parent)¶ Get the token of the parent object
Returns the token of the parent of the queried resource in ‘*parent’.
- Return
FPGA_NOT_FOUND if resource does not have a parent (e.g. an FPGA_DEVICE resource does not have parents). Also see “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] parent
: Pointer to a token variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetParent
(fpga_properties prop, fpga_token parent)¶ Set the token of the parent object
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[out] parent
: Pointer to a token variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetObjectType
(const fpga_properties prop, fpga_objtype *objtype)¶ Get the object type of a resource
Returns the object type of the queried resource.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] objtype
: Pointer to an object type variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetObjectType
(fpga_properties prop, fpga_objtype objtype)¶ Set the object type of a resource
Sets the object type of the resource. * Currently supported object types are FPGA_DEVICE and FPGA_ACCELERATOR.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[out] objtype
: Object type of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetSegment
(const fpga_properties prop, uint16_t *segment)¶ Get the PCI segment number of a resource
Returns the segment number of the queried resource.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] segment
: Pointer to a PCI segment variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetSegment
(fpga_properties prop, uint16_t segment)¶ Set the PCI segment number of a resource
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[in] segment
: PCI segment number of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetBus
(const fpga_properties prop, uint8_t *bus)¶ Get the PCI bus number of a resource
Returns the bus number the queried resource.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] bus
: Pointer to a PCI bus variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetBus
(fpga_properties prop, uint8_t bus)¶ Set the PCI bus number of a resource
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[in] bus
: PCI bus number of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetDevice
(const fpga_properties prop, uint8_t *device)¶ Get the PCI device number of a resource
Returns the device number the queried resource.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] device
: Pointer to a PCI device variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetDevice
(fpga_properties prop, uint8_t device)¶ Set the PCI device number of a resource
Enforces the limitation on the number of devices as specified in the PCI spec.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[in] device
: PCI device number of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetFunction
(const fpga_properties prop, uint8_t *function)¶ Get the PCI function number of a resource
Returns the function number the queried resource.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] function
: Pointer to PCI function variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetFunction
(fpga_properties prop, uint8_t function)¶ Set the PCI function number of a resource
Enforces the limitation on the number of functions as specified in the PCI spec.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[in] function
: PCI function number of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetSocketID
(const fpga_properties prop, uint8_t *socket_id)¶ Get the socket id of a resource
Returns the socket id of the queried resource.
- Return
See “Accessor Return Values” in properties.h. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] socket_id
: Pointer to a socket id variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetSocketID
(fpga_properties prop, uint8_t socket_id)¶ Set the socket id of the resource
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[in] socket_id
: Socket id of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetDeviceID
(const fpga_properties prop, uint16_t *device_id)¶ Get the device id of the resource
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] device_id
: Pointer to a device id variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetDeviceID
(fpga_properties prop, uint16_t device_id)¶ Set the device id of the resource
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[in] device_id
: Device id of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetNumSlots
(const fpga_properties prop, uint32_t *num_slots)¶ Get the number of slots of an FPGA resource property
Returns the number of slots present in an FPGA.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_DEVICE[out] num_slots
: Pointer to number of slots variable of the FPGA
-
fpga_result
fpgaPropertiesSetNumSlots
(fpga_properties prop, uint32_t num_slots)¶ Set the number of slots of an FPGA resource property
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_DEVICE[in] num_slots
: Number of slots of the FPGA
-
fpga_result
fpgaPropertiesGetBBSID
(const fpga_properties prop, uint64_t *bbs_id)¶ Get the BBS ID of an FPGA resource property
Returns the blue bitstream id of an FPGA.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_DEVICE[out] bbs_id
: Pointer to a bbs id variable of the FPGA
-
fpga_result
fpgaPropertiesSetBBSID
(fpga_properties prop, uint64_t bbs_id)¶ Set the BBS ID of an FPGA resource property
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_DEVICE[in] bbs_id
: Blue bitstream id of the FPGA resource
-
fpga_result
fpgaPropertiesGetBBSVersion
(const fpga_properties prop, fpga_version *bbs_version)¶ Get the BBS Version of an FPGA resource property
Returns the blue bitstream version of an FPGA.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_DEVICE[out] bbs_version
: Pointer to a bbs version variable of the FPGA
-
fpga_result
fpgaPropertiesSetBBSVersion
(fpga_properties prop, fpga_version version)¶ Set the BBS Version of an FPGA resource property
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_DEVICE[in] version
: Blue bitstream version of the FPGA resource
-
fpga_result
fpgaPropertiesGetVendorID
(const fpga_properties prop, uint16_t *vendor_id)¶ Get the vendor id of an FPGA resource property
Returns the vendor id of an FPGA.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_DEVICE[out] vendor_id
: Pointer to a vendor id variable of the FPGA
-
fpga_result
fpgaPropertiesSetVendorID
(fpga_properties prop, uint16_t vendor_id)¶ Set the vendor id of an FPGA resource property
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_DEVICE[in] vendor_id
: Vendor id of the FPGA resource
-
fpga_result
fpgaPropertiesGetModel
(const fpga_properties prop, char *model)¶ Get the model of an FPGA resource property
Returns the model of an FPGA.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_DEVICE[in] model
: Model of the FPGA resource (string of minimum FPGA_MODEL_LENGTH length
-
fpga_result
fpgaPropertiesSetModel
(fpga_properties prop, char *model)¶ Set the model of an FPGA resource property
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_DEVICE[in] model
: Model of the FPGA resource (string of maximum FPGA_MODEL_LENGTH length
-
fpga_result
fpgaPropertiesGetLocalMemorySize
(const fpga_properties prop, uint64_t *lms)¶ Get the local memory size of an FPGA resource property
Returns the local memory size of an FPGA.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_DEVICE[out] lms
: Pointer to a memory size variable of the FPGA
-
fpga_result
fpgaPropertiesSetLocalMemorySize
(fpga_properties prop, uint64_t lms)¶ Set the local memory size of an FPGA resource property
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_DEVICE[in] lms
: Local memory size of the FPGA resource
-
fpga_result
fpgaPropertiesGetCapabilities
(const fpga_properties prop, uint64_t *capabilities)¶ Get the capabilities FPGA resource property
Returns the capabilities of an FPGA. Capabilities is a bitfield value
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_DEVICE[out] capabilities
: Pointer to a capabilities variable of the FPGA
-
fpga_result
fpgaPropertiesSetCapabilities
(fpga_properties prop, uint64_t capabilities)¶ Set the capabilities of an FPGA resource property
Capabilities is a bitfield value
- Return
FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
This API is not currently supported.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_DEVICE[in] capabilities
: Capabilities of the FPGA resource
-
fpga_result
fpgaPropertiesGetGUID
(const fpga_properties prop, fpga_guid *guid)¶ Get the GUID of a resource
Returns the GUID of an FPGA or accelerator object.
For an accelerator, the GUID uniquely identifies a specific accelerator context type, i.e. different accelerators will have different GUIDs. For an FPGA, the GUID is used to identify a certain instance of an FPGA, e.g. to determine whether a given bitstream would be compatible.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] guid
: Pointer to a GUID of the slot variable
-
fpga_result
fpgaPropertiesSetGUID
(fpga_properties prop, fpga_guid guid)¶ Set the GUID of a resource
Sets the GUID of an FPGA or accelerator object.
For an accelerator, the GUID uniquely identifies a specific accelerator context type, i.e. different accelerators will have different GUIDs. For an FPGA, the GUID is used to identify a certain instance of an FPGA, e.g. to determine whether a given bitstream would be compatible.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify[out] guid
: Pointer to a GUID of the slot variable
-
fpga_result
fpgaPropertiesGetNumMMIO
(const fpga_properties prop, uint32_t *mmio_spaces)¶ Get the number of mmio spaces
Returns the number of mmio spaces of an AFU properties structure.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_ACCELERATOR[out] mmio_spaces
: Pointer to a variable for number of mmio spaces
-
fpga_result
fpgaPropertiesSetNumMMIO
(fpga_properties prop, uint32_t mmio_spaces)¶ Set the number of mmio spaces
Sets the number of mmio spaces of an AFU properties structure.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_ACCELERATOR[in] mmio_spaces
: Number of MMIO spaces of the accelerator
-
fpga_result
fpgaPropertiesGetNumInterrupts
(const fpga_properties prop, uint32_t *num_interrupts)¶ Get the number of interrupts
Returns the number of interrupts of an accelerator properties structure.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_ACCELERATOR[out] num_interrupts
: Pointer to a variable for number of interrupts
-
fpga_result
fpgaPropertiesSetNumInterrupts
(fpga_properties prop, uint32_t num_interrupts)¶ Set the number of interrupts
Sets the number of interrupts of an accelerator properties structure.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_ACCELERATOR[in] num_interrupts
: Number of interrupts of the accelerator
-
fpga_result
fpgaPropertiesGetAcceleratorState
(const fpga_properties prop, fpga_accelerator_state *state)¶ Get the state of a accelerator resource property
Returns the accelerator state of a accelerator.
- Return
FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query - must be of type FPGA_ACCELERATOR[out] state
: Pointer to a accelerator state variable of the accelerator
-
fpga_result
fpgaPropertiesSetAcceleratorState
(fpga_properties prop, fpga_accelerator_state state)¶ Set the state of an accelerator resource property
- Return
FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to modify - must be of type FPGA_ACCELERATOR[in] state
: accelerator state of the accelerator resource
-
fpga_result
fpgaPropertiesGetObjectID
(const fpga_properties prop, uint64_t *object_id)¶ Get the object ID of a resource
Returns the object ID of a resource. The object ID is a 64 bit identifier that is unique within a single node or system. It represents a similar concept as the token, but can be used across processes (e.g. passed on the command line).
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] object_id
: Pointer to a 64bit memory location to store the object ID in
-
fpga_result
fpgaPropertiesSetObjectID
(const fpga_properties prop, uint64_t object_id)¶ Set the object ID of a resource
Sets the object ID of a resource. The object ID is a 64 bit identifier that is unique within a single node or system. It represents a similar concept as the token, but can be used across processes (e.g. passed on the command line).
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[in] object_id
: A 64bit value to use as the object ID
-
fpga_result
fpgaPropertiesGetNumErrors
(const fpga_properties prop, uint32_t *num_errors)¶ Get the number of errors that can be reported by a resource
Returns the number of error registers understood by a resource.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] num_errors
: Pointer to a 32 bit memory location to store the number of supported errors in
-
fpga_result
fpgaPropertiesSetNumErrors
(const fpga_properties prop, uint32_t num_errors)¶ Set the number of error registers
Set the number of error registers understood by a resource to enumerate.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[in] num_errors
: Number of errors
-
fpga_result
fpgaPropertiesGetInterface
(const fpga_properties prop, fpga_interface *interface)¶ Get the OPAE plugin interface implemented by a resource
Returns the plugin interface enumerator.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[out] interface
: Pointer to an fpga_interface location to store the interface in
-
fpga_result
fpgaPropertiesSetInterface
(const fpga_properties prop, fpga_interface interface)¶ Set the OPAE plugin interface implemented by a resource
Set the plugin interface enumerator.
- Return
See “Accessor Return Values” in properties.h.
- Parameters
[in] prop
: Properties object to query[in] interface
: The interface enumerator to set
Access API¶
The access API provides functions for opening and closing FPGA resources. Opening a resource yields an fpga_handle, which denotes ownership and can be used in subsequent API calls to interact with a specific resource. Ownership can be exclusive or shared.
access.h¶
Functions to acquire, release, and reset OPAE FPGA resources.
Functions
-
fpga_result
fpgaOpen
(fpga_token token, fpga_handle *handle, int flags)¶ Open an FPGA object
Acquires ownership of the FPGA resource referred to by ‘token’.
Most often this will be used to open an accelerator object to directly interact with an accelerator function, or to open an FPGA object to perform management functions.
- Return
FPGA_OK on success. FPGA_NOT_FOUND if the resource for ‘token’ could not be found. FPGA_INVALID_PARAM if ‘token’ does not refer to a resource that can be opened, or if either argument is NULL or invalid. FPGA_EXCEPTION if an internal exception occurred while creating the handle. FPGA_NO_DRIVER if the driver is not loaded. FPGA_BUSY if trying to open a resource that has already been opened in exclusive mode. FPGA_NO_ACCESS if the current process’ privileges are not sufficient to open the resource.
- Parameters
[in] token
: Pointer to token identifying resource to acquire ownership of[out] handle
: Pointer to preallocated memory to place a handle in. This handle will be used in subsequent API calls.[in] flags
: One of the following flags:FPGA_OPEN_SHARED allows the resource to be opened multiple times (not supported in ASE) Shared resources (including buffers) are released when all associated handles have been closed (either explicitly with fpgaClose() or by process termination).
-
fpga_result
fpgaClose
(fpga_handle handle)¶ Close a previously opened FPGA object
Relinquishes ownership of a previously fpgaOpen()ed resource. This enables others to acquire ownership if the resource was opened exclusively. Also deallocates / unmaps MMIO and UMsg memory areas.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to an acquired resource, or if handle is NULL. FPGA_EXCEPTION if an internal error occurred while accessing the handle.
- Parameters
[in] handle
: Handle to previously opened FPGA object
-
fpga_result
fpgaReset
(fpga_handle handle)¶ Reset an FPGA object
Performs an accelerator reset.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to an acquired resource or to a resource that cannot be reset. FPGA_EXCEPTION if an internal error occurred while trying to access the handle or resetting the resource.
- Parameters
[in] handle
: Handle to previously opened FPGA object
Event API¶
The event API provides functions and types for handling asynchronous events such as errors or accelerator interrupts.
To natively support asynchronous event, the driver for the FPGA platform needs to support events natively (in which case the OPAE C library will register the event directly with the driver). For some platforms that do not support interrupt-driven event delivery, you need to run the FPGA Daemon (fpgad) to enable asynchronous OPAE events. fpgad will act as a proxy for the application and deliver asynchronous notifications for registered events.
event.h¶
Functions for registering events and managing the lifecycle for fpga_event_handle
s.
OPAE provides an interface to asynchronous events that can be generated by different FPGA resources. The event API provides functions to register for these events; associated with every event a process has registered for is an fpga_event_handle, which encapsulates the OS-specific data structure for event objects. On Linux, an fpga_event_handle can be used as a file descriptor and passed to select(), poll(), epoll() and similar functions to wait for asynchronous events.
Functions
-
fpga_result
fpgaCreateEventHandle
(fpga_event_handle *event_handle)¶ Initialize an event_handle
Platform independent way to initialize an event_handle used for notifications from the driver to application. For Linux, this function creates an eventfd and returns the eventfd file descriptor in
*event_handle
.- Return
FPGA_OK on success. FPGA_INVALID_PARAM if
event_handle
is NULL. FPGA_NOT_SUPPORTED if platform does not support events.- Parameters
[out] event_handle
: Pointer to event handle variable.
-
fpga_result
fpgaDestroyEventHandle
(fpga_event_handle *event_handle)¶ Destroy an event_handle
Destroy handle and free resources. On Linux this corresponds to closing the file descriptor pointed to by handle
- Note
fpgaDestroyEventHandle() requires the address of an event_handle as created by fpgaCreateEventHandle(). Passing any other value results in undefined behavior.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if
event_handle
is NULL.- Parameters
[in] event_handle
: Pointer to handle to be destroyed
-
fpga_result
fpgaGetOSObjectFromEventHandle
(const fpga_event_handle eh, int *fd)¶ Get OS object from event handle
Check validity of event handle, and get the OS object used to subscribe and unsubscribe to events. On Linux, the object corresponds to a file descriptor.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if
event_handle
is invalid.- Parameters
[in] eh
: Event handle to get the descriptor value from[out] fd
: integer to store the descriptor value
-
fpga_result
fpgaRegisterEvent
(fpga_handle handle, fpga_event_type event_type, fpga_event_handle event_handle, uint32_t flags)¶ Register an FPGA event
This function tells the driver that the caller is interested in notification for the event specified by the type and flags pair.
The event_handle points to an OS specific mechanism for event notification. An event_handle is associated with only a single event.
In case of user interrupts, the flags parameter will be used to specify the vector ID. The value of the flags parameter indicates the vector ID, no bit encoding is used.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to a resource supporting the requested event, or if event_handle is not valid. FPGA_EXCEPTION if an internal exception occurred while accessing the handle or the event_handle. On Linux: FPGA_NO_DAEMON if the driver does not support the requested event and there is no FPGA Daemon (fpgad) running to proxy it.
- Parameters
[in] handle
: Handle to previously opened FPGA resource.[in] event_type
: Type of event[in] event_handle
: Handle to previously opened resource for event notification.[in] flags
: Optional argument for specifying additional information about event. For example irq number for interrupt events.
-
fpga_result
fpgaUnregisterEvent
(fpga_handle handle, fpga_event_type event_type, fpga_event_handle event_handle)¶ Unregister an FPGA event
This function tells the driver that the caller is no longer interested in notification for the event associated with the event_handle
The event_handle points to an OS specific mechanism for event notification. An event_handle is associated with only a single event.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to a resource supporting the requested event, or if event_handle is not valid. FPGA_EXCEPTION if an internal error occurred accessing the handle or the event_handle.
- Parameters
[in] handle
: Handle to previously opened FPGA resource.[in] event_type
: Type of event to unregister.[in] event_handle
: Handle to previously registered resource for event notification.
Management API¶
The management APIs define functions for reconfiguring an FPGA (writing new partial bitstreams) as well as assigning accelerators to host interfaces.
manage.h¶
Functions for managing FPGA configurations.
FPGA accelerators can be reprogrammed at run time by providing new partial bitstreams (“green bitstreams”). This file defines API functions for programming green bitstreams as well as for assigning accelerators to host interfaces for more complex deployment setups, such as virtualized systems.
Functions
-
fpga_result
fpgaAssignPortToInterface
(fpga_handle fpga, uint32_t interface_num, uint32_t slot_num, int flags)¶ Assign Port to a host interface.
This function assign Port to a host interface for subsequent use. Only Port that have been assigned to a host interface can be opened by fpgaOpen().
- Return
FPGA_OK on success FPGA_INVALID_PARAM if input parameter combination is not valid. FPGA_EXCEPTION if an exception occcurred accessing the
fpga
handle. FPGA_NOT_SUPPORTED if driver does not support assignment.- Parameters
[in] fpga
: Handle to an FPGA object previously opened that both the host interface and the slot belong to[in] interface_num
: Host interface number[in] slot_num
: Slot number[in] flags
: Flags (to be defined)
-
fpga_result
fpgaAssignToInterface
(fpga_handle fpga, fpga_token accelerator, uint32_t host_interface, int flags)¶ Assign an accelerator to a host interface
This function assigns an accelerator to a host interface for subsequent use. Only accelerators that have been assigned to a host interface can be opened by fpgaOpen().
- Note
This function is currently not supported.
- Return
FPGA_OK on success
- Parameters
[in] fpga
: Handle to an FPGA object previously opened that both the host interface and the accelerator belong to[in] accelerator
: accelerator to assign[in] host_interface
: Host interface to assign accelerator to[in] flags
: Flags (to be defined)
-
fpga_result
fpgaReleaseFromInterface
(fpga_handle fpga, fpga_token accelerator)¶ Unassign a previously assigned accelerator
This function removes the assignment of an accelerator to an host interface (e.g. to be later assigned to a different host interface). As a consequence, the accelerator referred to by token ‘accelerator’ will be reset during the course of this function.
- Note
This function is currently not supported.
- Return
FPGA_OK on success
- Parameters
[in] fpga
: Handle to an FPGA object previously opened that both the host interface and the accelerator belong to[in] accelerator
: accelerator to unassign/release
-
fpga_result
fpgaReconfigureSlot
(fpga_handle fpga, uint32_t slot, const uint8_t *bitstream, size_t bitstream_len, int flags)¶ Reconfigure a slot
Sends a green bitstream file to an FPGA to reconfigure a specific slot. This call, if successful, will overwrite the currently programmed AFU in that slot with the AFU in the provided bitstream.
As part of the reconfiguration flow, all accelerators associated with this slot will be unassigned and reset.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if the provided parameters are not valid. FPGA_EXCEPTION if an internal error occurred accessing the handle or while sending the bitstream data to the driver. FPGA_BUSY if the accelerator for the given slot is in use. FPGA_RECONF_ERROR on errors reported by the driver (such as CRC or protocol errors).
- Note
By default, fpgaReconfigureSlot will not allow reconfiguring a slot with an accelerator in use. Add the flag FPGA_RECONF_FORCE to force reconfiguration without checking for accelerators in use.
- Parameters
[in] fpga
: Handle to an FPGA object previously opened[in] slot
: Token identifying the slot to reconfigure[in] bitstream
: Pointer to memory holding the bitstream[in] bitstream_len
: Length of the bitstream in bytes[in] flags
: Flags that control behavior of reconfiguration. Value of 0 indicates no flags. FPGA_RECONF_FORCE indicates that the bitstream is programmed into the slot without checking if the resource is currently in use.
Metrics API¶
The metrics APIs define functions for discovery/enumeration of metrics information and reading metrics values.
metrics.h¶
Functions for Discover/ Enumerates metrics and retrieves values.
Functions
-
fpga_result
fpgaGetNumMetrics
(fpga_handle handle, uint64_t *num_metrics)¶ Enumerates number of metrics
- Return
FPGA_OK on success. FPGA_NOT_FOUND if the Metrics are not discovered
- Parameters
[in] handle
: Handle to previously opened fpga resource[inout] num_metrics
: Number of metrics are discovered in fpga resource
-
fpga_result
fpgaGetMetricsInfo
(fpga_handle handle, fpga_metric_info *metric_info, uint64_t *num_metrics)¶ Retrieve metrics information
- Return
FPGA_OK on success. FPGA_NOT_FOUND if the Metrics are not found. FPGA_NO_MEMORY if there was not enough memory to enumerates metrics.
- Parameters
[in] handle
: Handle to previously opened fpga resource[inout] metric_info
: Pointer to array of metric info struct user allocates metrics info array[inout] num_metrics
: Size of metric info array
-
fpga_result
fpgaGetMetricsByIndex
(fpga_handle handle, uint64_t *metric_num, uint64_t num_metric_indexes, fpga_metric *metrics)¶ Retrieve metrics values by index
- Return
FPGA_OK on success. FPGA_NOT_FOUND if the Metrics are not found. FPGA_NO_MEMORY if there was not enough memory to enumerates metrics.
- Parameters
[in] handle
: Handle to previously opened fpga resource[inout] metric_num
: Pointer to array of metric index user allocates metric array[inout] num_metric_indexes
: Size of metric array[inout] metrics
: pointer to array of metric struct
-
fpga_result
fpgaGetMetricsByName
(fpga_handle handle, char **metrics_names, uint64_t num_metric_names, fpga_metric *metrics)¶ Retrieve metric values by names
- Return
FPGA_OK on success. FPGA_NOT_FOUND if the Metrics are not found
- Parameters
[in] handle
: Handle to previously opened fpga resource[inout] metrics_names
: Pointer to array of metrics name user allocates metrics name array[inout] num_metric_names
: Size of metric name array[inout] metrics
: Pointer to array of metric struct
-
fpga_result
fpgaGetMetricsThresholdInfo
(fpga_handle handle, struct metric_threshold *metric_thresholds, uint32_t *num_thresholds)¶ Retrieve metrics / sendor threshold information and values
- Return
FPGA_OK on success. FPGA_NOT_FOUND if the Metrics are not found. FPGA_NO_MEMORY if there was not enough memory to enumerates metrics.
- Parameters
[in] handle
: Handle to previously opened fpga resource[inout] metrics_threshold
: pointer to array of metric thresholds user allocates threshold array memory Number of thresholds returns enumerated thresholds if user pass NULL metrics_thresholds[inout] num_thresholds
: number of thresholds
SysObject¶
The SysObject API can be used to get system objects by name. Names used with the SysObject API are driver-specific and may not be compatible across plugins and/or drivers. For example, SysObject names used with the xfpga plugin will apply to the OPAE Linux Kernel driver and refer to sysfs nodes under the sysfs tree for the resource used with the SysObject API.
sysobject.h¶
Functions to read/write from system objects. On Linux systems with the OPAE kernel driver, this is used to access sysfs nodes created by the driver.
Functions
-
fpga_result
fpgaTokenGetObject
(fpga_token token, const char *name, fpga_object *object, int flags)¶ Create an
fpga_object
data structures. Anfpga_object
is a handle to an FPGA resource which can be an attribute, register or a container. This object is read-only.- Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_NOT_FOUND if an object cannot be found with the given key. FPGA_NOT_SUPPORTED if this function is not supported by the current implementation of this API.
- Note
Names that begin with ‘.’ or ‘/’ or contain ‘..’ are not allowed and result in FPGA_INVALID_PARAM being returned
- Parameters
[in] token
: Token identifying a resource (accelerator or device)[in] name
: A key identifying an object belonging to a resource.[out] object
: Pointer to memory to store the object in[in] flags
: Control behavior of object identification and creation. FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a globbing expression. FPGA_OBJECT_RECURSE_ONE indicates that subobjects be created for objects one level down from the object identified by name. FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all objects below the current object identified by name.
-
fpga_result
fpgaHandleGetObject
(fpga_handle handle, const char *name, fpga_object *object, int flags)¶ Create an
fpga_object
data structure from a handle. Anfpga_object
is a handle to an FPGA resource which can be an attribute, register, or container. This object has read/write access..- Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_NOT_FOUND if an object cannot be found with the given key. FPGA_NOT_SUPPORTED if this function is not supported by the current implementation of this API.
- Note
Names that begin with ‘.’ or ‘/’ or contain ‘..’ are not allowed and result in FPGA_INVALID_PARAM being returned
- Parameters
[in] handle
: Handle identifying a resource (accelerator or device)[in] name
: A key identifying an object belonging to a resource.[out] object
: Pointer to memory to store the object in[in] flags
: Control behavior of object identification and creation FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a globbing expression. FPGA_OBJECT_RECURSE_ONE indicates that subobjects be created for objects one level down from the object identified by name. FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all objects below the current object identified by name.
-
fpga_result
fpgaObjectGetObject
(fpga_object parent, const char *name, fpga_object *object, int flags)¶ Create an
fpga_object
data structure from a parent object. Anfpga_object
is a handle to an FPGA resource which can be an attribute, register, or container. If the parent object was created with a handle, then the new object will inherit the handle allowing it to have read-write access to the object data.- Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid - this includes a parent object that is not a container object. FPGA_NOT_FOUND if an object cannot be found with the given key. FPGA_NOT_SUPPORTED if this function is not supported by the current implementation of this API.
- Note
Names that begin with ‘.’ or ‘/’ or contain ‘..’ are not allowed and result in FPGA_INVALID_PARAM being returned
- Parameters
[in] parent
: A parent containerfpga_object
.[in] name
: A key identifying a sub-object of the parent container.[out] object
: Pointer to memory to store the object in.[in] flags
: Control behavior of object identification and creation. FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a globbing expression. FPGA_OBJECT_RECURSE_ONE indicates that subobjects be created for objects one level down from the object identified by name. FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all objects below the current object identified by name.
-
fpga_result
fpgaObjectGetObjectAt
(fpga_object parent, size_t idx, fpga_object *object)¶ Create an
fpga_object
data structure from a parent object using a given index. Anfpga_object
is a handle to an FPGA resource which can be an attribute, register, or container. If the parent object was created with a handle, then the new object will inherit the handle allowing it to have read-write access to the object data.- Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid - this includes a parent object that is not a container object. FPGA_NOT_FOUND if an object cannot be found with the given key. FPGA_NOT_SUPPORTED if this function is not supported by the current implementation of this API.
- Parameters
[in] parent
: A parent container ‘fpga_object’[in] idx
: A positive index less than the size reported by the parent.[out] object
: Pointer to memory to store the object in.
-
fpga_result
fpgaObjectGetType
(fpga_object obj, enum fpga_sysobject_type *type)¶ Get the sysobject type (container or attribute)
- Return
FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied parameters are null or invalid
- Parameters
[in] obj
: An fpga_object instance[out] type
: The type of object (FPGA_OBJECT_CONTAINER or FPGA_OBJECT_ATTRIBUTE)
-
fpga_result
fpgaDestroyObject
(fpga_object *obj)¶ Free memory used for the fpga_object data structure.
- Note
fpgaDestroyObject() requires the address of an fpga_object as created by fpgaTokenGetObject(), fpgaHandleGetObject(), or fpgaObjectGetObject(). Passing any other value results in undefind behavior.
- Return
FPGA_OK on success, FPGA_INVALID_PARAM if the object is NULL, FPGA_EXCEPTION if an internal error is encountered.
- Parameters
obj
: Pointer to the fpga_object instance to destroy
-
fpga_result
fpgaObjectGetSize
(fpga_object obj, uint32_t *value, int flags)¶ Retrieve the size of the object.
- Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of supplied parameters is invalid. FPGA_EXCEPTION if error occurred.
- Parameters
[in] obj
: An fpga_object instance.[out] value
: Pointer to variable to store size in.[in] flags
: Flags that control how the object is read If FPGA_OBJECT_SYNC is used then object will update its buffered copy before retrieving the size.
-
fpga_result
fpgaObjectRead
(fpga_object obj, uint8_t *buffer, size_t offset, size_t len, int flags)¶ Read bytes from an FPGA object.
- Return
FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied parameters is invalid
- Parameters
[in] obj
: An fpga_object instance.[out] buffer
: Pointer to a buffer to read bytes into.[in] offset
: Byte offset relative to objects internal buffer where to begin reading bytes from.[in] len
: The length, in bytes, to read from the object.[in] flags
: Flags that control how object is read If FPGA_OBJECT_SYNC is used then object will update its buffered copy before retrieving the data.
-
fpga_result
fpgaObjectRead64
(fpga_object obj, uint64_t *value, int flags)¶ Read a 64-bit value from an FPGA object. The value is assumed to be in string format and will be parsed. See flags below for changing that behavior.
- Return
FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied parameters is invalid
- Parameters
[in] obj
: An fpga_object instance[out] value
: Pointer to a 64-bit variable to store the value in[in] flags
: Flags that control how the object is read If FPGA_OBJECT_SYNC is used then object will update its buffered copy before retrieving the data. If FPGA_OBJECT_RAW is used, then the data will be read as raw bytes into the uint64_t pointer variable.
-
fpga_result
fpgaObjectWrite64
(fpga_object obj, uint64_t value, int flags)¶ Write 64-bit value to an FPGA object. The value will be converted to string before writing. See flags below for changing that behavior.
- Return
FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied parameters is invalid
- Note
The object must have been created using a handle to a resource.
- Parameters
[in] obj
: An fpga_object instance.[in] value
: The value to write to the object[in] flags
: Flags that control how the object is written If FPGA_OBJECT_RAW is used, then the value will be written as raw bytes.
Utilities¶
Functions for mapping fpga_result values to meaningful error strings are provided by the utilities API.
utils.h¶
Utility functions and macros for the FPGA API.
Functions
-
const char *
fpgaErrStr
(fpga_result e)¶ Return human-readable error message
Returns a pointer to a human-readable error message corresponding to the provided fpga_error error code.
- Return
Pointer to a descriptive error message string
- Parameters
[in] e
: Error code (as returned by another FPGA API function
Samples¶
Code samples demonstrate how to use OPAE C API.
hello_fpga.c¶
A code sample illustrates the basic usage of the OPAE C API.
The sample is a host application that demonstrates the basic steps of interacting with FPGA using the OPAE library. These steps include:
FPGA enumeration
Resource acquiring and releasing
Managing shared memory buffer
MMIO read and write
The sample also demonstrates OPAE’s object model, such as tokens, handles, and properties.
The sample requires a native loopback mode (NLB) test image to be loaded on the FPGA. Refer to Quick Start Guide for full instructions on building, configuring, and running this code sample.
Defines
-
TEST_TIMEOUT
¶
-
CL
(x)¶
-
LOG2_CL
¶
-
MB
(x)¶
-
CACHELINE_ALIGNED_ADDR
(p)¶
-
LPBK1_BUFFER_SIZE
¶
-
LPBK1_BUFFER_ALLOCATION_SIZE
¶
-
LPBK1_DSM_SIZE
¶
-
CSR_SRC_ADDR
¶
-
CSR_DST_ADDR
¶
-
CSR_CTL
¶
-
CSR_STATUS1
¶
-
CSR_CFG
¶
-
CSR_NUM_LINES
¶
-
DSM_STATUS_TEST_COMPLETE
¶
-
CSR_AFU_DSM_BASEL
¶
-
NLB0_AFUID
¶
-
N3000_AFUID
¶
-
FPGA_NLB0_UUID_H
¶
-
FPGA_NLB0_UUID_L
¶
-
ON_ERR_GOTO
(res, label, desc)¶
-
GETOPT_STRING
¶
Functions
-
int
usleep
(unsigned)¶
-
void
print_err
(const char *s, fpga_result res)¶
-
void
help
(void)¶
-
fpga_result
parse_args
(int argc, char *argv[])¶
-
fpga_result
find_fpga
(fpga_properties device_filter, fpga_guid afu_guid, fpga_token *accelerator_token, uint32_t *num_matches_accelerators)¶
-
bool
probe_for_ase
(void)¶
-
fpga_result
find_nlb_n3000
(fpga_handle accelerator_handle, uint64_t *afu_baddr)¶
-
int
main
(int argc, char *argv[])¶
Variables
-
struct config config = { .open_flags = 0, .run_n3000 = 0}
-
struct
cache_line
¶
-
struct
config
¶
hello_events.c¶
A code sample of using OPAE event API.
This sample starts two processes. One process injects an artificial fatal error to sysfs; while the other tries to asynchronously capture and handle the event. This sample code exercises all major functions of the event API, including creating and destroying event handles, register and unregister events, polling on event file descriptor, and getting the OS object associated with an event. For a full discussion of OPAE event API, refer to event.h.
Functions
-
int
usleep
(unsigned)
-
void
print_err
(const char *s, fpga_result res)
-
fpga_result
inject_ras_fatal_error
(fpga_token fme_token, uint8_t err)¶
-
void *
error_thread
(void *arg)¶
-
void
help
(void)
-
fpga_result
parse_args
(int argc, char *argv[])
-
fpga_result
find_fpga
(fpga_properties device_filter, fpga_token *fpga, uint32_t *num_matches)¶
-
int
main
(int argc, char *argv[])
-
struct
ras_inject_error
¶ Public Members
-
union ras_inject_error::[anonymous] [anonymous]¶
-
union ras_inject_error::[anonymous] [anonymous]¶
-
ras_inject_error.__unnamed26__
-
ras_inject_error.__unnamed26__.__unnamed28__