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.

Initialization

OPAEs management of the opaque types fpga_properties, fpga_token, and fpga_handle relies on the proper initialization of variables of these types. In other words, before doing anything with a variable of one of these opaque types, you need to first initialize them.

The respective functions that initizalize opaque types are:

This should intuitively make sense - fpgaGetProperties() creates fpga_properties objects, fpgaEnumerate() creates fpga_token objects, fpgaOpen() creates fpga_handle objects, and fpgaCloneProperties() and fpgaCloneToken() clone (create) fpga_properties and fpga_token objects, respectively.

Since these opaque types are interpreted as pointers (they are typedef’d to a void *), passing an uninitialized opaque type into any function except the respective initailzation function will result in undefined behaviour, because OPAE will try to follow an invalid pointer. Undefined behaviour in this case may include an unexpected error code, or an application crash.

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 of fpga_properties can then be passed to fpgaEnumerate(), which will return a list of fpga_token objects matching these criteria.

For querying properties of existing FPGA resources, fpgaGetProperties() can also take an fpga_token and will return an fpga_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 the fpga_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 an fpga_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_tokens 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 take fpga_tokens 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 the fpga_event_handle object.

struct fpga_version
#include <types.h>

Semantic version

Data structure for expressing version identifiers following the semantic versioning scheme. Used in various properties for tracking component versions.

Public Members

uint8_t major

Major version

uint8_t minor

Minor version

uint16_t patch

Revision or patchlevel

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:

FPGA_OK = 0

Operation completed successfully

FPGA_INVALID_PARAM

Invalid parameter supplied

FPGA_BUSY

Resource is busy

FPGA_EXCEPTION

An exception occurred

FPGA_NOT_FOUND

A required resource was not found

FPGA_NO_MEMORY

Not enough memory to complete operation

FPGA_NOT_SUPPORTED

Requested operation is not supported

FPGA_NO_DRIVER

Driver is not loaded

FPGA_NO_DAEMON

FPGA Daemon (fpgad) is not running

FPGA_NO_ACCESS

Insufficient privileges or permissions

FPGA_RECONF_ERROR

Error while reconfiguring FPGA

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:

FPGA_EVENT_INTERRUPT = 0

Interrupt generated by an accelerator

FPGA_EVENT_ERROR

Infrastructure error event

FPGA_EVENT_POWER_THERMAL

Infrastructure thermal event

enum fpga_accelerator_state

accelerator state

Values:

FPGA_ACCELERATOR_ASSIGNED = 0

accelerator is opened exclusively by another process

FPGA_ACCELERATOR_UNASSIGNED

accelerator is free to be opened

enum fpga_objtype

OPAE FPGA resources (objects)

These are the FPGA resources currently supported by the OPAE object model.

Values:

FPGA_DEVICE = 0

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().

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.

enum fpga_buffer_flags

Buffer flags

These flags can be passed to the fpgaPrepareBuffer() function.

Values:

FPGA_BUF_PREALLOCATED = (1u << 0)

Use existing buffer

FPGA_BUF_QUIET = (1u << 1)

Suppress error messages

enum fpga_open_flags

Open flags

These flags can be passed to the fpgaOpen() function.

Values:

FPGA_OPEN_SHARED = (1u << 0)

Open FPGA resource for shared access

enum fpga_reconf_flags

Reconfiguration flags

These flags can be passed to the fpgaReconfigure() function.

Values:

FPGA_RECONF_FORCE = (1u << 0)

Reconfigure the slot without checking if it is in use

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_tokens to represent the matching resources and populate the array tokens with these tokens. The max_tokens argument can be used to limit the number of tokens allocated/returned by fpgaEnumerate(); i.e., the number of tokens in the returned tokens array will be either max_tokens or num_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 parameter tokens set to NULL; this will only return the number of matches in num_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
  • filters: Array of fpga_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. Passing NULL will match all FPGA resources present in the system.
  • num_filters: Number of entries in the filters array.
  • 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 in num_match.
  • max_tokens: Maximum number of tokens that fpgaEnumerate() shall return (length of tokens array). There may be more or fewer matches than this number; num_matches is set to the number of actual matches.
  • num_matches: Number of resources matching the filter criteria. This number can be higher than the number of tokens returned in the tokens array (depending on the value of max_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
  • src: fpga_token object to copy
  • 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.

Return
FPGA_OK on success
Parameters
  • 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.

Accessor Return Values

In addition to the return values specified in the documentation below, all accessor functions return FPGA_OK on success, FPGA_INVALID_PARAM if you pass NULL or invalid parameters (i.e. non-initialized properties objects), FPGA_EXCEPTION if an internal exception occurred trying to access the properties object, FPGA_NOT_FOUND if the requested property is not part of the supplied properties object.

Functions

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 by token. 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 to dont 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 using application 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 the fpga_properties object.
Parameters
  • token: Token to get properties for. Can be NULL, which will create an empty properties object to be used as a filter for fpgaEnumerate().
  • 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 or prop are not valid objects. FPGA_NOT_FOUND if the resource referred to by token was not found. FPGA_NO_DRIVER if not driver is loaded. FPGA_EXCEPTION if an internal exception occured when trying to update prop.
Parameters
  • token: Token to retrieve properties for
  • 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 access prop.
Parameters
  • 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 if dst is NULL. FPGA_NO_MEMORY if there was not enough memory to allocate an fpga_properties object for dst. FPGA_EXCEPTION if an internal exception occurred either accessing src or updating dst.
Parameters
  • src: fpga_properties object to copy
  • 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().

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 access prop.
Parameters
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • objtype: Object type 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • 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
  • prop: Properties object to query - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to modify - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to query - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to modify - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to query - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to modify - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to query - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to modify - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to query - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to modify - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to query - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to modify - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to query - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to modify - must be of type FPGA_DEVICE
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to modify
  • 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
  • prop: Properties object to query - must be of type FPGA_ACCELERATOR
  • 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
  • prop: Properties object to modify - must be of type FPGA_ACCELERATOR
  • 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
  • prop: Properties object to query - must be of type FPGA_ACCELERATOR
  • 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
  • prop: Properties object to modify - must be of type FPGA_ACCELERATOR
  • 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
  • prop: Properties object to query - must be of type FPGA_ACCELERATOR
  • 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
  • prop: Properties object to modify - must be of type FPGA_ACCELERATOR
  • 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
  • prop: Properties object to query
  • 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
  • prop: Properties object to query
  • object_id: A 64bit value to use as the object ID

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
  • token: Pointer to token identifying resource to acquire ownership of
  • handle: Pointer to preallocated memory to place a handle in. This handle will be used in subsequent API calls.
  • 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
  • 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 resoure that cannot be reset. FPGA_EXCEPTION if an internal error occurred while trying to access the handle or resetting the resource.
Parameters
  • handle: Handle to previously opened FPGA object

Event API

The event API provides functions and types for handling asynchronous events such as errors or AFC 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_handles.

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
  • 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

Return
FPGA_OK on success. FPGA_INVALID_PARAM if event_handle is NULL.
Parameters
  • 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 obkect corresponds to a file descriptor.

Return
FPGA_OK on success. FPGA_INVALID_PARAM if event_handle is invalid.
Parameters
  • eh: Event handle to get the descriptor value from
  • 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
  • handle: Handle to previously opened FPGA resource.
  • event_type: Type of event
  • event_handle: Handle to previously opened resource for event notification.
  • 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
  • handle: Handle to previously opened FPGA resource.
  • event_type: Type of event to unregister.
  • event_handle: Handle to previously registered resource for event notification.

MMIO and Shared Memory APIs

These APIs feature functions for mapping and accessing control registers through memory-mapped IO (mmio.h), allocating and sharing system memory buffers with an accelerator (buffer.h), and using low-latency notifications (umsg.h).

mmio.h

Functions for mapping and accessing MMIO space.

Most FPGA accelerators provide access to control registers through memory-mappable address spaces, commonly referred to as “MMIO spaces”. This file provides functions to map, unmap, read, and write MMIO spaces.

Note that an accelerator may have multiple MMIO spaces, denoted by the mmio_num argument of the APIs below. The meaning and properties of each MMIO space are up to the accelerator designer.

Functions

fpga_result fpgaWriteMMIO64(fpga_handle handle, uint32_t mmio_num, uint64_t offset, uint64_t value)

Write 64 bit value to MMIO space

This function will write to MMIO space of the target object at a specified offset.

Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle.
Parameters
  • handle: Handle to previously opened accelerator resource
  • mmio_num: Number of MMIO space to access
  • offset: Byte offset into MMIO space
  • value: Value to write (64 bit)

fpga_result fpgaReadMMIO64(fpga_handle handle, uint32_t mmio_num, uint64_t offset, uint64_t *value)

Read 64 bit value from MMIO space

This function will read from MMIO space of the target object at a specified offset.

Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle.
Parameters
  • handle: Handle to previously opened accelerator resource
  • mmio_num: Number of MMIO space to access
  • offset: Byte offset into MMIO space
  • value: Pointer to memory where read value is returned (64 bit)

fpga_result fpgaWriteMMIO32(fpga_handle handle, uint32_t mmio_num, uint64_t offset, uint32_t value)

Write 32 bit value to MMIO space

This function will write to MMIO space of the target object at a specified offset.

Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle.
Parameters
  • handle: Handle to previously opened accelerator resource
  • mmio_num: Number of MMIO space to access
  • offset: Byte offset into MMIO space
  • value: Value to write (32 bit)

fpga_result fpgaReadMMIO32(fpga_handle handle, uint32_t mmio_num, uint64_t offset, uint32_t *value)

Read 32 bit value from MMIO space

This function will read from MMIO space of the target object at a specified offset.

Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle.
Parameters
  • handle: Handle to previously opened accelerator resource
  • mmio_num: Number of MMIO space to access
  • offset: Byte offset into MMIO space
  • value: Pointer to memory where read value is returned (32 bit)

fpga_result fpgaMapMMIO(fpga_handle handle, uint32_t mmio_num, uint64_t **mmio_ptr)

Map MMIO space

This function will return a pointer to the specified MMIO space of the target object in process virtual memory, if supported by the target. Some MMIO spaces may be restricted to privileged processes, depending on the used handle and type.

After mapping the respective MMIO space, you can access it through direct pointer operations (observing supported access sizes and alignments of the target platform and accelerator).

If the caller passes in NULL for mmio_ptr, no mapping will be performed, and no virtual address will be returned, though the call will return FPGA_OK. This implies that all accesses will be performed through fpgaReadMMIO32(), fpgaWriteMMIO32(), fpgeReadMMIO64(), and fpgaWriteMMIO64(). This is the only supported case for ASE.

Note
Some targets (such as the ASE simulator) do not support memory-mapping of IO register spaces and will not return a pointer to an actually mapped space. Instead, they will return FPGA_NOT_SUPPORTED. Usually, these platforms still allow the application to issue MMIO operations using fpgaReadMMIO32(), fpgaWriteMMIO32(), fpgeReadMMIO64(), and fpgaWriteMMIO64().

The number of available MMIO spaces can be retrieved through the num_mmio property (fpgaPropertyGetNumMMIO()).

Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle. FPGA_NO_ACCESS if the process’ permissions are not sufficient to map the requested MMIO space. FPGA_NOT_SUPPORTED if platform does not support memory mapped IO.
Parameters
  • handle: Handle to previously opened resource
  • mmio_num: Number of MMIO space to access
  • mmio_ptr: Pointer to memory where a pointer to the MMIO space will be returned. May be NULL, in which case no pointer is returned. Returned address may be NULL if underlying platform does not support memory mapping for register access.

fpga_result fpgaUnmapMMIO(fpga_handle handle, uint32_t mmio_num)

Unmap MMIO space

This function will unmap a previously mapped MMIO space of the target opject, rendering any pointers to it invalid.

Note
This call is only supported by hardware targets, not by ASE simulation.
Return
FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied parameters is invalid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle.
Parameters
  • handle: Handle to previously opened resource
  • mmio_num: Number of MMIO space to access

buffer.h

Functions for allocating and sharing system memory with an FPGA accelerator.

To share memory between a software application and an FPGA accelerator, these functions set up system components (e.g. an IOMMU) to allow accelerator access to a provided memory region.

There are a number of restrictions on what memory can be shared, depending on platform capabilities. Usually, FPGA accelerators to not have access to virtual address mappings of the CPU, so they can only access physical addresses. To support this, the OPAE C library on Linux uses hugepages to allocate large, contiguous pages of physical memory that can be shared with an accalerator. It also supports sharing memory that has already been allocated by an application, as long as that memory satisfies the requirements of being physically contigous and page-aligned.

Functions

fpga_result fpgaPrepareBuffer(fpga_handle handle, uint64_t len, void **buf_addr, uint64_t *wsid, int flags)

Prepare a shared memory buffer

Prepares a memory buffer for shared access between an accelerator and the calling process. This may either include allocation of physcial memory, or preparation of already allocated memory for sharing. The latter case is indicated by supplying the FPGA_BUF_PREALLOCATED flag.

This function will ask the driver to pin the indicated memory (make it non-swappable), and program the IOMMU to allow access from the accelerator. If the buffer was not pre-allocated (flag FPGA_BUF_PREALLOCATED), the function will also allocate physical memory of the requested size and map the memory into the caller’s process’ virtual address space. It returns in ‘wsid’ an fpga_buffer object that can be used to program address registers in the accelerator for shared access to the memory.

When using FPGA_BUF_PREALLOCATED, the input len must be a non-zero multiple of the page size, else the function returns FPGA_INVALID_PARAM. When not using FPGA_BUF_PREALLOCATED, the input len is rounded up to the nearest multiple of page size.

Return
FPGA_OK on success. FPGA_NO_MEMORY if the requested memory could not be allocated. FPGA_INVALID_PARAM if invalid parameters were provided, or if the parameter combination is not valid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle.
Parameters
  • handle: Handle to previously opened accelerator resource
  • len: Length of the buffer to allocate/prepare in bytes
  • buf_addr: Virtual address of buffer. Contents may be NULL (OS will choose mapping) or non-NULL (OS will take contents as a hint for the virtual address).
  • wsid: Handle to the allocated/prepared buffer to be used with other functions
  • flags: Flags. FPGA_BUF_PREALLOCATED indicates that memory pointed at in ‘*buf_addr’ is already allocated an mapped into virtual memory.

fpga_result fpgaReleaseBuffer(fpga_handle handle, uint64_t wsid)

Release a shared memory buffer

Releases a previously prepared shared buffer. If the buffer was allocated using fpgaPrepareBuffer (FPGA_BUF_PREALLOCATED was not specified), this call will deallocate/free that memory. Otherwise, it will only be returned to it’s previous state (pinned/unpinned, cached/non-cached).

Return
FPGA_OK on success. FPGA_INVALID_PARAM if invalid parameters were provided, or if the parameter combination is not valid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle.
Parameters
  • handle: Handle to previously opened accelerator resource
  • wsid: Handle to the allocated/prepared buffer

fpga_result fpgaGetIOAddress(fpga_handle handle, uint64_t wsid, uint64_t *ioaddr)

Retrieve base IO address for buffer

This function is used to acquire the physical base address (on some platforms called IO Virtual Address or IOVA) for a shared buffer identified by wsid.

Note
This function will disappear once the APIs for secure sharing of buffer addresses is implemented.
Return
FPGA_OK on success. FPGA_INVALID_PARAM if invalid parameters were provided, or if the parameter combination is not valid. FPGA_EXCEPTION if an internal exception occurred while trying to access the handle. FPGA_NOT_FOUND if wsid does not refer to a previously shared buffer.
Parameters
  • handle: Handle to previously opened accelerator resource
  • wsid: Buffer handle / workspace ID referring to the buffer for which the IO address is requested
  • ioaddr: Pointer to memory where the IO address will be returned

umsg.h

FPGA UMsg API.

Functions

fpga_result fpgaGetNumUmsg(fpga_handle handle, uint64_t *value)

Get number of Umsgs

Retuns number of umsg supported by AFU.

Return
FPGA_OK on success. FPGA_INVALID_PARAM if input parameter combination is not valid. FPGA_EXCEPTION if input parameter fpga handle is not valid.
Parameters
  • handle: Handle to previously opened accelerator resource
  • value: Returns number of UMsgs

fpga_result fpgaSetUmsgAttributes(fpga_handle handle, uint64_t value)

Sets Umsg hint

Writes usmg hint bit.

Return
FPGA_OK on success. FPGA_INVALID_PARAM if input parameter combination is not valid. FPGA_EXCEPTION if input parameter fpga handle is not valid.
Parameters
  • handle: Handle to previously opened accelerator resource
  • value: Value to use for UMsg hint, Umsg hit is N wide bitvector where N = number of Umsgs.

fpga_result fpgaTriggerUmsg(fpga_handle handle, uint64_t value)

Trigger Umsg

Writes a 64-bit value to trigger low-latency accelerator notification mechanism (UMsgs).

Return
FPGA_OK on success. FPGA_INVALID_PARAM if input parameter combination is not valid. FPGA_EXCEPTION if input parameter fpga handle is not valid.
Parameters
  • handle: Handle to previously opened accelerator resource
  • value: Value to use for UMsg

fpga_result fpgaGetUmsgPtr(fpga_handle handle, uint64_t **umsg_ptr)

Access UMsg memory directly

This function will return a pointer to the memory allocated for low latency accelerator notifications (UMsgs).

Return
FPGA_OK on success. FPGA_INVALID_PARAM if input parameter combination is not valid. FPGA_EXCEPTION if input parameter fpga handle is not valid. FPGA_NO_MEMORY if memory allocation fails or system doesn’t configure huge pages.
Parameters
  • handle: Handle to previously opened accelerator resource
  • umsg_ptr: Pointer to memory where a pointer to the virtual address space will be returned

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
  • fpga: Handle to an FPGA object previously opened that both the host interface and the slot belong to
  • interface_num: Host interface number
  • slot_num: Slot number
  • 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
  • fpga: Handle to an FPGA object previously opened that both the host interface and the accelerator belong to
  • accelerator: accelerator to assign
  • host_interface: Host interface to assign accelerator to
  • 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
  • fpga: Handle to an FPGA object previously opened that both the host interface and the accelerator belong to
  • 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
  • fpga: Handle to an FPGA object previously opened
  • slot: Token identifying the slot to reconfigure
  • bitstream: Pointer to memory holding the bitstream
  • bitstream_len: Length of the bitstream in bytes
  • 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.

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
  • 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

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_CFG
CSR_NUM_LINES
DSM_STATUS_TEST_COMPLETE
CSR_AFU_DSM_BASEL
CSR_AFU_DSM_BASEH
NLB0_AFUID
ON_ERR_GOTO(res, label, desc)

Functions

int usleep(unsigned)
void print_err(const char *s, fpga_result res)
int main(int argc, char *argv[])
struct cache_line

Public Members

uint32_t uint[16]

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.

Defines

FME_SYSFS_INJECT_ERROR
ON_ERR_GOTO(res, label, desc)

Functions

int usleep(unsigned)
void print_err(const char *s, fpga_result res)
static fpga_result inject_ras_fatal_error(fpga_token token, uint8_t err)
int main(int argc, char *argv[])
struct ras_inject_error

Public Members

union ras_inject_error::@0 ras_inject_error::@1
union

Public Members

struct

Public Members