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

Packit 534379
// Copyright(c) 2017, 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 event.h
Packit 534379
 * @brief Functions for registering events and managing the lifecycle for
Packit 534379
 * `fpga_event_handle`s.
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. On Linux, an fpga_event_handle can be used as a file
Packit 534379
 * descriptor and passed to select(), poll(), epoll() and similar functions to
Packit 534379
 * wait for asynchronous events.
Packit 534379
 */
Packit 534379
Packit 534379
#ifndef __FPGA_EVENT_H__
Packit 534379
#define __FPGA_EVENT_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
 * Initialize an event_handle
Packit 534379
 *
Packit 534379
 * Platform independent way to initialize an event_handle used for
Packit 534379
 * notifications from the driver to application. For Linux, this function
Packit 534379
 * creates an eventfd and returns the eventfd file descriptor in
Packit 534379
 * `*event_handle`.
Packit 534379
 *
Packit 534379
 * @param[out] event_handle  Pointer to event handle variable.
Packit 534379
 *
Packit 534379
 * @returns FPGA_OK on success. FPGA_INVALID_PARAM if `event_handle` is NULL.
Packit 534379
 * FPGA_NOT_SUPPORTED if platform does not support events.
Packit 534379
 */
Packit 534379
fpga_result fpgaCreateEventHandle(fpga_event_handle *event_handle);
Packit 534379
Packit 534379
/**
Packit 534379
 * Destroy an event_handle
Packit 534379
 *
Packit 534379
 * Destroy handle and free resources. On Linux this corresponds
Packit 534379
 * to closing the file descriptor pointed to by handle
Packit 534379
 *
Packit 534379
 * @note fpgaDestroyEventHandle() requires the address of an
Packit 534379
 * event_handle as created by fpgaCreateEventHandle(). Passing
Packit 534379
 * any other value results in undefined behavior.
Packit 534379
 *
Packit 534379
 * @param[in] event_handle Pointer to handle to be destroyed
Packit 534379
 *
Packit 534379
 * @returns FPGA_OK on success. FPGA_INVALID_PARAM if `event_handle` is NULL.
Packit 534379
 */
Packit 534379
fpga_result fpgaDestroyEventHandle(fpga_event_handle *event_handle);
Packit 534379
Packit 534379
Packit 534379
/**
Packit 534379
 * Get OS object from event handle
Packit 534379
 *
Packit 534379
 * Check validity of event handle, and get the OS object used to
Packit 534379
 * subscribe and unsubscribe to events. On Linux, the object corresponds
Packit 534379
 * to a file descriptor.
Packit 534379
 *
Packit 534379
 * @param[in] eh Event handle to get the descriptor value from
Packit 534379
 * @param[out] fd integer to store the descriptor value
Packit 534379
 *
Packit 534379
 * @returns FPGA_OK on success. FPGA_INVALID_PARAM if `event_handle` is invalid.
Packit 534379
 */
Packit 534379
fpga_result fpgaGetOSObjectFromEventHandle(const fpga_event_handle eh, int *fd);
Packit 534379
Packit 534379
/**
Packit 534379
 * Register an FPGA event
Packit 534379
 *
Packit 534379
 * This function tells the driver that the caller is interested in notification
Packit 534379
 * for the event specified by the type and flags pair.
Packit 534379
 *
Packit 534379
 * The event_handle points to an OS specific mechanism for event notification.
Packit 534379
 * An event_handle is associated with only a single event.
Packit 534379
 *
Packit 534379
 * In case of user interrupts, the flags parameter will be used to specify
Packit 534379
 * the vector ID. The value of the flags parameter indicates the vector ID,
Packit 534379
 * no bit encoding is used.
Packit 534379
 *
Packit 534379
 * @todo define if calling fpgaRegisterEvent multiple times with the
Packit 534379
 * same event_handle is an error condition or if it is silently ignored.
Packit 534379
 *
Packit 534379
 * @param[in]  handle       Handle to previously opened FPGA resource.
Packit 534379
 * @param[in]  event_type   Type of event
Packit 534379
 * @param[in]  event_handle Handle to previously opened resource for event
Packit 534379
 *                          notification.
Packit 534379
 * @param[in]  flags        Optional argument for specifying additional
Packit 534379
 *                          information about event.  For example irq number
Packit 534379
 *			    for interrupt events.
Packit 534379
 * @returns FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to
Packit 534379
 * a resource supporting the requested event, or if event_handle is not valid.
Packit 534379
 * FPGA_EXCEPTION if an internal exception occurred while accessing the handle
Packit 534379
 * or the event_handle. On Linux: FPGA_NO_DAEMON if the driver does not support
Packit 534379
 * the requested event and there is no FPGA Daemon (fpgad) running to proxy it.
Packit 534379
 */
Packit 534379
fpga_result fpgaRegisterEvent(fpga_handle handle,
Packit 534379
			      fpga_event_type event_type,
Packit 534379
			      fpga_event_handle event_handle,
Packit 534379
			      uint32_t flags);
Packit 534379
Packit 534379
/**
Packit 534379
 * Unregister an FPGA event
Packit 534379
 *
Packit 534379
 * This function tells the driver that the caller is no longer interested in
Packit 534379
 * notification for the event associated with the event_handle
Packit 534379
 *
Packit 534379
 * The event_handle points to an OS specific mechanism for event notification.
Packit 534379
 * An event_handle is associated with only a single event.
Packit 534379
 *
Packit 534379
 * @todo define if calling fpgaUnregisterEvent multiple times with the
Packit 534379
 * same event_handle is an error condition or if it is silently ignored.
Packit 534379
 *
Packit 534379
 * @param[in]  handle       Handle to previously opened FPGA resource.
Packit 534379
 * @param[in]  event_type   Type of event to unregister.
Packit 534379
 * @param[in]  event_handle Handle to previously registered resource for event
Packit 534379
 *                          notification.
Packit 534379
 * @returns             FPGA_OK on success. FPGA_INVALID_PARAM if handle does
Packit 534379
 *                      not refer to a resource supporting the requested event,
Packit 534379
 *                      or if event_handle is not valid. FPGA_EXCEPTION if an
Packit 534379
 *                      internal error occurred accessing the handle or the
Packit 534379
 *                      event_handle.
Packit 534379
 */
Packit 534379
fpga_result fpgaUnregisterEvent(fpga_handle handle,
Packit 534379
					     fpga_event_type event_type,
Packit 534379
					     fpga_event_handle event_handle);
Packit 534379
Packit 534379
#ifdef __cplusplus
Packit 534379
} // extern "C"
Packit 534379
#endif // __cplusplus
Packit 534379
Packit 534379
#endif // __FPGA_EVENT_H__