|
Packit |
534379 |
// Copyright(c) 2018, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @file types.h
|
|
Packit |
534379 |
* @brief Type definitions for FPGA API
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* OPAE uses the three opaque types fpga_properties, fpga_token, and
|
|
Packit |
534379 |
* fpga_handle to create a hierarchy of objects that can be used to enumerate,
|
|
Packit |
534379 |
* reference, acquire, and query FPGA resources. This object model is designed
|
|
Packit |
534379 |
* to be extensible to account for different FPGA architectures and platforms.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Initialization
|
|
Packit |
534379 |
* --------------
|
|
Packit |
534379 |
* OPAEs management of the opaque types `fpga_properties`,
|
|
Packit |
534379 |
* `fpga_token`, and `fpga_handle` relies on the proper initialization of
|
|
Packit |
534379 |
* variables of these types. In other words, before doing anything with a
|
|
Packit |
534379 |
* variable of one of these opaque types, you need to first initialize them.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* The respective functions that initialize opaque types are:
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* * fpgaGetProperties() and fpgaCloneProperties() for `fpga_properties`
|
|
Packit |
534379 |
* * fpgaEnumerate() and fpgaCloneToken() for `fpga_token`
|
|
Packit |
534379 |
* * fpgaOpen() for `fpga_handle`
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* This should intuitively make sense - fpgaGetProperties() creates
|
|
Packit |
534379 |
* `fpga_properties` objects, fpgaEnumerate() creates `fpga_token` objects,
|
|
Packit |
534379 |
* fpgaOpen() creates `fpga_handle` objects, and fpgaCloneProperties() and
|
|
Packit |
534379 |
* fpgaCloneToken() clone (create) `fpga_properties` and `fpga_token` objects,
|
|
Packit |
534379 |
* respectively.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Since these opaque types are interpreted as pointers (they are typedef'd to
|
|
Packit |
534379 |
* a `void *`), passing an uninitialized opaque type into any function except
|
|
Packit |
534379 |
* the respective initailzation function will result in undefined behaviour,
|
|
Packit |
534379 |
* because OPAE will try to follow an invalid pointer. Undefined behaviour in
|
|
Packit |
534379 |
* this case may include an unexpected error code, or an application crash.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifndef __FPGA_TYPES_H__
|
|
Packit |
534379 |
#define __FPGA_TYPES_H__
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <stdint.h>
|
|
Packit |
534379 |
#include <stddef.h>
|
|
Packit |
534379 |
#include <stdbool.h>
|
|
Packit |
534379 |
#include <opae/types_enum.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Object for expressing FPGA resource properties
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* `fpga_properties` objects encapsulate all enumerable information about an
|
|
Packit |
534379 |
* FPGA resources. They can be used for two purposes: selective enumeration
|
|
Packit |
534379 |
* (discovery) and querying information about existing resources.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* For selective enumeration, usually an empty `fpga_properties` object is
|
|
Packit |
534379 |
* created (using fpgaGetProperties()) and then populated with the desired
|
|
Packit |
534379 |
* criteria for enumeration. An array of `fpga_properties` can then be passed
|
|
Packit |
534379 |
* to fpgaEnumerate(), which will return a list of `fpga_token` objects
|
|
Packit |
534379 |
* matching these criteria.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* For querying properties of existing FPGA resources, fpgaGetProperties() can
|
|
Packit |
534379 |
* also take an `fpga_token` and will return an `fpga_properties` object
|
|
Packit |
534379 |
* populated with information about the resource referenced by that token.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* After use, `fpga_properties` objects should be destroyed using
|
|
Packit |
534379 |
* fpga_destroyProperties() to free backing memory used by the
|
|
Packit |
534379 |
* `fpga_properties` object.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef void *fpga_properties;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Token for referencing FPGA resources
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* An `fpga_token` serves as a reference to a specific FPGA resource present in
|
|
Packit |
534379 |
* the system. Holding an `fpga_token` does not constitute ownership of the
|
|
Packit |
534379 |
* FPGA resource - it merely allows the user to query further information about
|
|
Packit |
534379 |
* a resource, or to use fpgaOpen() to acquire ownership.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* `fpga_token`s are usually returned by fpgaEnumerate() or
|
|
Packit |
534379 |
* fpgaPropertiesGetParent(), and used by fpgaOpen() to acquire ownership and
|
|
Packit |
534379 |
* yield a handle to the resource. Some API calls also take `fpga_token`s as
|
|
Packit |
534379 |
* arguments if they don't require ownership of the resource in question.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef void *fpga_token;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Handle to an FPGA resource
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* A valid `fpga_handle` object, as populated by fpgaOpen(), denotes ownership
|
|
Packit |
534379 |
* of an FPGA resource. Note that ownership can be exclusive or shared,
|
|
Packit |
534379 |
* depending on the flags used in fpgaOpen(). Ownership can be released by
|
|
Packit |
534379 |
* calling fpgaClose(), which will render the underlying handle invalid.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Many OPAE C API functions require a valid token (which is synonymous with
|
|
Packit |
534379 |
* ownership of the resource).
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef void *fpga_handle;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Globally unique identifier (GUID)
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* GUIDs are used widely within OPAE for helping identify FPGA resources. For
|
|
Packit |
534379 |
* example, every FPGA resource has a `guid` property, which can be (and in the
|
|
Packit |
534379 |
* case of FPGA_ACCELERATOR resource primarily is) used for enumerating a resource of a
|
|
Packit |
534379 |
* specific type.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* `fpga_guid` is compatible with libuuid's uuid_t, so users can use libuuid
|
|
Packit |
534379 |
* functions like uuid_parse() to create and work with GUIDs.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef uint8_t fpga_guid[16];
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Semantic version
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Data structure for expressing version identifiers following the semantic
|
|
Packit |
534379 |
* versioning scheme. Used in various properties for tracking component
|
|
Packit |
534379 |
* versions.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef struct {
|
|
Packit |
534379 |
uint8_t major; /**< Major version */
|
|
Packit |
534379 |
uint8_t minor; /**< Minor version */
|
|
Packit |
534379 |
uint16_t patch; /**< Revision or patchlevel */
|
|
Packit |
534379 |
} fpga_version;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Handle to an event object
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* OPAE provides an interface to asynchronous events that can be generated by
|
|
Packit |
534379 |
* different FPGA resources. The event API provides functions to register for
|
|
Packit |
534379 |
* these events; associated with every event a process has registered for is an
|
|
Packit |
534379 |
* `fpga_event_handle`, which encapsulates the OS-specific data structure for
|
|
Packit |
534379 |
* event objects.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* After use, `fpga_event_handle` objects should be destroyed using
|
|
Packit |
534379 |
* fpgaDestroyEventHandle() to free backing memory used by the
|
|
Packit |
534379 |
* `fpga_event_handle` object.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef void *fpga_event_handle;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Information about an error register
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* This data structure captures information about an error register exposed by
|
|
Packit |
534379 |
* an accelerator resource. The error API provides functions to retrieve these
|
|
Packit |
534379 |
* information structures from a particular resource.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
#define FPGA_ERROR_NAME_MAX 64
|
|
Packit |
534379 |
struct fpga_error_info {
|
|
Packit |
534379 |
char name[FPGA_ERROR_NAME_MAX]; /** name of the error */
|
|
Packit |
534379 |
bool can_clear; /** whether error can be cleared */
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Object pertaining to an FPGA resource as identified by a unique name
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* An `fpga_object` represents either a device attribute or a container of
|
|
Packit |
534379 |
* attributes. Similar to filesystems, a '/' may be used to seperate objects in
|
|
Packit |
534379 |
* an object hierarchy. Once on object is acquired, it may be used to read or
|
|
Packit |
534379 |
* write data in a resource attribute or to query sub-objects if the object is
|
|
Packit |
534379 |
* a container object. The data in an object is buffered and will be kept
|
|
Packit |
534379 |
* around until the object is destroyed. Additionally, the data in an attribute
|
|
Packit |
534379 |
* can by synchronized from the owning resource using the FPGA_OBJECT_SYNC flag
|
|
Packit |
534379 |
* during read operations. The name identifying the object is unique with
|
|
Packit |
534379 |
* respect to the resource that owns it. A parent resource may be identified by
|
|
Packit |
534379 |
* an `fpga_token` object, by an `fpga_handle` object, or another `fpga_object`
|
|
Packit |
534379 |
* object. If a handle object is used when opening the object, then the object
|
|
Packit |
534379 |
* is opened with read-write access. Otherwise, the object is read-only.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef void *fpga_object;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** FPGA Metric string size
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
#define FPGA_METRIC_STR_SIZE 256
|
|
Packit |
534379 |
/** Metric value union
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef union {
|
|
Packit |
534379 |
uint64_t ivalue; // Metric integer value
|
|
Packit |
534379 |
double dvalue; // Metric double value
|
|
Packit |
534379 |
float fvalue; // Metric float value
|
|
Packit |
534379 |
bool bvalue; // Metric bool value
|
|
Packit |
534379 |
} metric_value;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Metric info struct
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef struct fpga_metric_info {
|
|
Packit |
534379 |
uint64_t metric_num; // Metric index num
|
|
Packit |
534379 |
fpga_guid metric_guid; // Metric guid
|
|
Packit |
534379 |
char qualifier_name[FPGA_METRIC_STR_SIZE]; // Metric full name
|
|
Packit |
534379 |
char group_name[FPGA_METRIC_STR_SIZE]; // Metric group name
|
|
Packit |
534379 |
char metric_name[FPGA_METRIC_STR_SIZE]; // Metric name
|
|
Packit |
534379 |
char metric_units[FPGA_METRIC_STR_SIZE]; // Metric units
|
|
Packit |
534379 |
enum fpga_metric_datatype metric_datatype; // Metric data type
|
|
Packit |
534379 |
enum fpga_metric_type metric_type; // Metric group type
|
|
Packit |
534379 |
} fpga_metric_info;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Metric struct
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef struct fpga_metric {
|
|
Packit |
534379 |
uint64_t metric_num; // Metric index num
|
|
Packit |
534379 |
metric_value value; // Metric value
|
|
Packit |
534379 |
bool isvalid; // Metric value is valid
|
|
Packit |
534379 |
} fpga_metric;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Threshold struct
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef struct threshold {
|
|
Packit |
534379 |
char threshold_name[FPGA_METRIC_STR_SIZE]; // Threshold name
|
|
Packit |
534379 |
uint32_t is_valid; // Threshold is valid
|
|
Packit |
534379 |
double value; // Threshold value
|
|
Packit |
534379 |
} threshold;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
typedef struct metric_threshold {
|
|
Packit |
534379 |
char metric_name[FPGA_METRIC_STR_SIZE]; // Metric Threshold name
|
|
Packit |
534379 |
threshold upper_nr_threshold; // Upper Non-Recoverable Threshold
|
|
Packit |
534379 |
threshold upper_c_threshold; // Upper Critical Threshold
|
|
Packit |
534379 |
threshold upper_nc_threshold; // Upper Non-Critical Threshold
|
|
Packit |
534379 |
threshold lower_nr_threshold; // Lower Non-Recoverable Threshold
|
|
Packit |
534379 |
threshold lower_c_threshold; // Lower Critical Threshold
|
|
Packit |
534379 |
threshold lower_nc_threshold; // Lower Non-Critical Threshold
|
|
Packit |
534379 |
threshold hysteresis; // Hysteresis
|
|
Packit |
534379 |
} metric_threshold;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#endif // __FPGA_TYPES_H__
|