Blame opae-libs/plugins/xfpga/bitstream_int.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
#ifndef __FPGA_BITSTREAM_INT_H__
Packit 534379
#define __FPGA_BITSTREAM_INT_H__
Packit 534379
Packit 534379
#include <string.h>
Packit 534379
#include <stdio.h>
Packit 534379
#include <stdlib.h>
Packit 534379
#include <sys/types.h>
Packit 534379
#include <opae/types.h>
Packit 534379
Packit 534379
#ifdef __cplusplus
Packit 534379
extern "C" {
Packit 534379
#endif // __cplusplus
Packit 534379
Packit 534379
#define GUID_LEN		36
Packit 534379
#define AFU_NAME_LEN		512
Packit 534379
Packit 534379
// GBS Metadata format /json
Packit 534379
struct gbs_metadata {
Packit 534379
Packit 534379
	double version;                             // version
Packit 534379
Packit 534379
	struct afu_image_content {
Packit 534379
		uint64_t magic_num;                 // Magic number
Packit 534379
		char interface_uuid[GUID_LEN + 1];  // Interface id
Packit 534379
		int clock_frequency_high;            // user clock frequency hi
Packit 534379
		int clock_frequency_low;             // user clock frequency low
Packit 534379
		int power;                           // power
Packit 534379
Packit 534379
		struct afu_clusters_content {
Packit 534379
			char name[AFU_NAME_LEN];     // AFU Name
Packit 534379
			int  total_contexts;         // total contexts
Packit 534379
			char afu_uuid[GUID_LEN + 1]; // afu guid
Packit 534379
		} afu_clusters;
Packit 534379
Packit 534379
	} afu_image;
Packit 534379
Packit 534379
};
Packit 534379
Packit 534379
/**
Packit 534379
 * Check the validity of GUID
Packit 534379
 *
Packit 534379
 *Extracts the 128 bit guid from passed bitstream
Packit 534379
 *converts it to fpga_guid type anc checks it against
Packit 534379
 *expected value
Packit 534379
 *
Packit 534379
 *
Packit 534379
 * @param[in] bitstream   Pointer to the bitstream
Packit 534379
 * @returns               FPGA_OK on success
Packit 534379
 */
Packit 534379
fpga_result check_bitstream_guid(const uint8_t *bitstream);
Packit 534379
Packit 534379
/**
Packit 534379
 * Get total length of bitstream header
Packit 534379
 *
Packit 534379
 * Returns the total length of header which is
Packit 534379
 * GUID + size of variable describing length of metadata + length of metadata
Packit 534379
 *
Packit 534379
 *
Packit 534379
 * @param[in] bitstream   Pointer to the bitstream
Packit 534379
 * @returns               int value of length, -1 on failure
Packit 534379
 */
Packit 534379
int get_bitstream_header_len(const uint8_t *bitstream);
Packit 534379
Packit 534379
/**
Packit 534379
 * Get total length of json metadata in bitstream
Packit 534379
 *
Packit 534379
 * Returns the length of the json metadata from the
Packit 534379
 * bitstream which is represented by a uint32 after the
Packit 534379
 * GUID
Packit 534379
 *
Packit 534379
 *
Packit 534379
 * @param[in] bitstream   Pointer to the bitstream
Packit 534379
 * @returns               int value of length, -1 on failure
Packit 534379
 */
Packit 534379
int32_t get_bitstream_json_len(const uint8_t *bitstream);
Packit 534379
Packit 534379
Packit 534379
/**
Packit 534379
 * Check bitstream magic no and interface id
Packit 534379
 *
Packit 534379
 * Checks the bitstream magic no and interface id
Packit 534379
 * with expected values
Packit 534379
 *
Packit 534379
 * @param[in] handle			Handle to previously opened FPGA object
Packit 534379
 * @param[in] bitstream_magic_no	magic no. to be checked
Packit 534379
 * @param[in] ifid_l			lower 64 bits of interface id
Packit 534379
 * @param[in] ifid_h			higher 64 bits of interface id
Packit 534379
 * @returns				FPGA_OK on success
Packit 534379
 */
Packit 534379
fpga_result check_interface_id(fpga_handle handle, uint32_t bitstream_magic_no,
Packit 534379
				uint64_t ifid_l, uint64_t ifid_h);
Packit 534379
Packit 534379
/**
Packit 534379
 * Check if the JSON metadata is valid
Packit 534379
 *
Packit 534379
 * Reads the bitstream magic no and interface
Packit 534379
 * id values from the metadata and compares them
Packit 534379
 * with expected values
Packit 534379
 *
Packit 534379
 * @param[in] handle	  Handle to previously opened FPGA object
Packit 534379
 * @param[in] bitstream   Pointer to the bitstream
Packit 534379
 * @returns		  FPGA_OK on success
Packit 534379
 */
Packit 534379
fpga_result validate_bitstream_metadata(fpga_handle handle,
Packit 534379
					const uint8_t *bitstream);
Packit 534379
Packit 534379
/**
Packit 534379
 * Reads GBS metadata
Packit 534379
 *
Packit 534379
 * Parses GBS JSON metadata.
Packit 534379
 *
Packit 534379
 * @param[in] bitstream    Pointer to the bitstream
Packit 534379
 * @param[in] gbs_metadata Pointer to gbs metadata struct
Packit 534379
 * @returns                FPGA_OK on success
Packit 534379
 */
Packit 534379
fpga_result read_gbs_metadata(const uint8_t *bitstream,
Packit 534379
			      struct gbs_metadata *gbs_metadata);
Packit 534379
Packit 534379
/**
Packit 534379
* Reads interface id high and low values
Packit 534379
*
Packit 534379
* Reads interface id from sysfs.
Packit 534379
*
Packit 534379
* @param[in] handle   FME handle
Packit 534379
* @param[out] id_l    Interface id low
Packit 534379
* @param[out] id_h    Interface id lHigh
Packit 534379
* @returns             FPGA_OK on success
Packit 534379
*/
Packit 534379
fpga_result get_interface_id(fpga_handle handle,
Packit 534379
							uint64_t *id_l, uint64_t *id_h);
Packit 534379
Packit 534379
#ifdef __cplusplus
Packit 534379
} // extern "C"
Packit 534379
#endif // __cplusplus
Packit 534379
Packit 534379
#endif // __FPGA_BITSTREAM_INT_H__