Blame opae-libs/include/opae/sysobject.h

Packit 534379
// Copyright(c) 2017-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 opae/sysobject.h
Packit 534379
 * @brief Functions to read/write from system objects.
Packit 534379
 * On Linux systems with the OPAE kernel driver, this is used to access sysfs
Packit 534379
 * nodes created by the driver.
Packit 534379
 */
Packit 534379
#ifndef __FPGA_SYSOBJECT_H__
Packit 534379
#define __FPGA_SYSOBJECT_H__
Packit 534379
Packit 534379
#include <opae/types.h>
Packit 534379
Packit 534379
#ifdef __cplusplus
Packit 534379
extern "C" {
Packit 534379
#endif
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Create an `fpga_object` data structures. An `fpga_object`
Packit 534379
 * is a handle to an FPGA resource which can be an attribute, register or
Packit 534379
 * a container. This object is read-only.
Packit 534379
 *
Packit 534379
 * @param[in] token Token identifying a resource (accelerator or device)
Packit 534379
 * @param[in] name A key identifying an object belonging to a resource.
Packit 534379
 * @param[out] object Pointer to memory to store the object in
Packit 534379
 * @param[in] flags Control behavior of object identification and creation.
Packit 534379
 * FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a
Packit 534379
 * globbing expression.  FPGA_OBJECT_RECURSE_ONE indicates that subobjects be
Packit 534379
 * created for objects one level down from the object identified by name.
Packit 534379
 * FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all objects
Packit 534379
 * below the current object identified by name.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters is invalid. FPGA_NOT_FOUND if an object cannot be found with the
Packit 534379
 * given key. FPGA_NOT_SUPPORTED if this function is not supported by the
Packit 534379
 * current implementation of this API.
Packit 534379
 *
Packit 534379
 * @note Names that begin with '.' or '/' or contain '..' are not allowed and
Packit 534379
 * result in FPGA_INVALID_PARAM being returned
Packit 534379
 *
Packit 534379
 */
Packit 534379
fpga_result fpgaTokenGetObject(fpga_token token, const char *name,
Packit 534379
			       fpga_object *object, int flags);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Create an `fpga_object` data structure from a handle.
Packit 534379
 * An `fpga_object` is a handle to an FPGA resource which can be an attribute,
Packit 534379
 * register, or container.  This object has read/write access..
Packit 534379
 *
Packit 534379
 * @param[in] handle Handle identifying a resource (accelerator or device)
Packit 534379
 * @param[in] name A key identifying an object belonging to a resource.
Packit 534379
 * @param[out] object Pointer to memory to store the object in
Packit 534379
 * @param[in] flags Control behavior of object identification and creation
Packit 534379
 * FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a
Packit 534379
 * globbing expression.  FPGA_OBJECT_RECURSE_ONE indicates that subobjects be
Packit 534379
 * created for objects one level down from the object identified by name.
Packit 534379
 * FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all objects
Packit 534379
 * below the current object identified by name.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters is invalid. FPGA_NOT_FOUND if an object cannot be found with the
Packit 534379
 * given key. FPGA_NOT_SUPPORTED if this function is not supported by the
Packit 534379
 * current implementation of this API.
Packit 534379
 *
Packit 534379
 * @note Names that begin with '.' or '/' or contain '..' are not allowed and
Packit 534379
 * result in FPGA_INVALID_PARAM being returned
Packit 534379
 *
Packit 534379
 */
Packit 534379
fpga_result fpgaHandleGetObject(fpga_handle handle, const char *name,
Packit 534379
				fpga_object *object, int flags);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Create an `fpga_object` data structure from a parent object.  An
Packit 534379
 * `fpga_object` is a handle to an FPGA resource which can be an attribute,
Packit 534379
 * register, or container.  If the parent object was created with a handle,
Packit 534379
 * then the new object will inherit the handle allowing it to have read-write
Packit 534379
 * access to the object data.
Packit 534379
 *
Packit 534379
 * @param[in] parent A parent container `fpga_object`.
Packit 534379
 * @param[in] name A key identifying a sub-object of the parent container.
Packit 534379
 * @param[out] object Pointer to memory to store the object in.
Packit 534379
 * @param[in] flags Control behavior of object identification and creation.
Packit 534379
 * FPGA_OBJECT_GLOB is used to indicate that the name should be treated as a
Packit 534379
 * globbing expression.  FPGA_OBJECT_RECURSE_ONE indicates that subobjects be
Packit 534379
 * created for objects one level down from the object identified by name.
Packit 534379
 * FPGA_OBJECT_RECURSE_ALL indicates that subobjects be created for all objects
Packit 534379
 * below the current object identified by name.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters is invalid - this includes a parent object that is not a
Packit 534379
 * container object. FPGA_NOT_FOUND if an object cannot be found with the given
Packit 534379
 * key. FPGA_NOT_SUPPORTED if this function is not supported by the current
Packit 534379
 * implementation of this API.
Packit 534379
 *
Packit 534379
 * @note Names that begin with '.' or '/' or contain '..' are not allowed and
Packit 534379
 * result in FPGA_INVALID_PARAM being returned
Packit 534379
 *
Packit 534379
 */
Packit 534379
fpga_result fpgaObjectGetObject(fpga_object parent, const char *name,
Packit 534379
				fpga_object *object, int flags);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Create an `fpga_object` data structure from a parent object using a
Packit 534379
 * given index.  An `fpga_object` is a handle to an FPGA resource which can be
Packit 534379
 * an attribute, register, or container.  If the parent object was created with
Packit 534379
 * a handle, then the new object will inherit the handle allowing it to have
Packit 534379
 * read-write access to the object data.
Packit 534379
 *
Packit 534379
 * @param[in] parent A parent container 'fpga_object'
Packit 534379
 * @param[in] idx A positive index less than the size reported by the parent.
Packit 534379
 * @param[out] object Pointer to memory to store the object in.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success. FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters is invalid - this includes a parent object that is not a
Packit 534379
 * container object. FPGA_NOT_FOUND if an object cannot be found with the given
Packit 534379
 * key. FPGA_NOT_SUPPORTED if this function is not supported by the current
Packit 534379
 * implementation of this API.
Packit 534379
 */
Packit 534379
fpga_result fpgaObjectGetObjectAt(fpga_object parent, size_t idx,
Packit 534379
				  fpga_object *object);
Packit 534379
/**
Packit 534379
 * @brief Get the sysobject type (container or attribute)
Packit 534379
 *
Packit 534379
 * @param[in] obj An fpga_object instance
Packit 534379
 * @param[out] type The type of object (FPGA_OBJECT_CONTAINER or
Packit 534379
 * FPGA_OBJECT_ATTRIBUTE)
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters are null or invalid
Packit 534379
 */
Packit 534379
fpga_result fpgaObjectGetType(fpga_object obj, enum fpga_sysobject_type *type);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Free memory used for the fpga_object data structure
Packit 534379
 *
Packit 534379
 * @note fpgaDestroyObject() requires the address of an fpga_object
Packit 534379
 * as created by fpgaTokenGetObject(), fpgaHandleGetObject(),
Packit 534379
 * or fpgaObjectGetObject(). Passing any other value results in
Packit 534379
 * undefind behavior.
Packit 534379
 *
Packit 534379
 * @param obj Pointer to the fpga_object instance to destroy
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success, FPGA_INVALID_PARAM if the object is NULL,
Packit 534379
 * FPGA_EXCEPTION if an internal error is encountered.
Packit 534379
 */
Packit 534379
fpga_result fpgaDestroyObject(fpga_object *obj);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Retrieve the size of the object.
Packit 534379
 *
Packit 534379
 * @param[in] obj An fpga_object instance.
Packit 534379
 * @param[out] value Pointer to variable to store size in.
Packit 534379
 * @param[in] flags Flags that control how the object is read
Packit 534379
 * If FPGA_OBJECT_SYNC is used then object will update its buffered copy before
Packit 534379
 * retrieving the size.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success. FPGA_INVALID_PARAM if any of supplied parameters
Packit 534379
 * is invalid. FPGA_EXCEPTION if error occurred.
Packit 534379
 */
Packit 534379
fpga_result fpgaObjectGetSize(fpga_object obj, uint32_t *value, int flags);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Read bytes from an FPGA object
Packit 534379
 *
Packit 534379
 * @param[in] obj An fpga_object instance.
Packit 534379
 * @param[out] buffer Pointer to a buffer to read bytes into.
Packit 534379
 * @param[in] offset Byte offset relative to objects internal buffer where to
Packit 534379
 * begin reading bytes from.
Packit 534379
 * @param[in] len The length, in bytes, to read from the object.
Packit 534379
 * @param[in] flags Flags that control how object is read
Packit 534379
 * If FPGA_OBJECT_SYNC is used then object will update its buffered copy before
Packit 534379
 * retrieving the data.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters is invalid
Packit 534379
 */
Packit 534379
fpga_result fpgaObjectRead(fpga_object obj, uint8_t *buffer, size_t offset,
Packit 534379
			   size_t len, int flags);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Read a 64-bit value from an FPGA object.
Packit 534379
 * The value is assumed to be in string format and will be parsed. See flags
Packit 534379
 * below for changing that behavior.
Packit 534379
 *
Packit 534379
 * @param[in] obj An fpga_object instance
Packit 534379
 * @param[out] value Pointer to a 64-bit variable to store the value in
Packit 534379
 * @param[in] flags Flags that control how the object is read
Packit 534379
 * If FPGA_OBJECT_SYNC is used then object will update its buffered copy before
Packit 534379
 * retrieving the data. If FPGA_OBJECT_RAW is used, then the data will be read
Packit 534379
 * as raw bytes into the uint64_t pointer variable.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters is invalid
Packit 534379
 */
Packit 534379
fpga_result fpgaObjectRead64(fpga_object obj, uint64_t *value, int flags);
Packit 534379
Packit 534379
/**
Packit 534379
 * @brief Write 64-bit value to an FPGA object.
Packit 534379
 * The value will be converted to string before writing. See flags below for
Packit 534379
 * changing that behavior.
Packit 534379
 *
Packit 534379
 * @param[in] obj An fpga_object instance.
Packit 534379
 * @param[in] value The value to write to the object
Packit 534379
 * @param[in] flags Flags that control how the object is written
Packit 534379
 * If FPGA_OBJECT_RAW is used, then the value will be written as raw bytes.
Packit 534379
 *
Packit 534379
 * @return FPGA_OK on success, FPGA_INVALID_PARAM if any of the supplied
Packit 534379
 * parameters is invalid
Packit 534379
 *
Packit 534379
 * @note The object must have been created using a handle to a resource.
Packit 534379
 */
Packit 534379
fpga_result fpgaObjectWrite64(fpga_object obj, uint64_t value, int flags);
Packit 534379
Packit 534379
#ifdef __cplusplus
Packit 534379
} // extern "C"
Packit 534379
#endif // __cplusplus
Packit 534379
Packit 534379
#endif /* !__FPGA_SYSOBJECT_H__ */