|
Packit |
534379 |
// Copyright(c) 2018-2020, 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 bitstream.h
|
|
Packit |
534379 |
* @brief API for manipulating Green Bitstreams (GBS)
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* GBS files store the AFU logic as well as versioned metadata.
|
|
Packit |
534379 |
* These routines parse a disk-resident GBS file, expanding its
|
|
Packit |
534379 |
* metadata and loading the GBS logic into memory.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifndef __OPAE_BITSTREAM_H__
|
|
Packit |
534379 |
#define __OPAE_BITSTREAM_H__
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <stdint.h>
|
|
Packit |
534379 |
#include <stdbool.h>
|
|
Packit |
534379 |
#include <opae/types.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define OPAE_LEGACY_BITSTREAM_MAGIC 0x1d1f8680
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#pragma pack(push, 1)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @deprecated Legacy (pre-6.4.0 BBS) format support.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef struct _opae_legacy_bitstream_header {
|
|
Packit |
534379 |
uint32_t legacy_magic;
|
|
Packit |
534379 |
fpga_guid legacy_pr_ifc_id;
|
|
Packit |
534379 |
} opae_legacy_bitstream_header;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#pragma pack(pop)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#pragma pack(push, 1)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Format of the GBS header.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef struct _opae_bitstream_header {
|
|
Packit |
534379 |
fpga_guid valid_gbs_guid; /**< indentifies a GBS file */
|
|
Packit |
534379 |
uint32_t metadata_length; /**< length of metadata in bytes */
|
|
Packit |
534379 |
char metadata[1]; /**< GBS metadata (JSON) */
|
|
Packit |
534379 |
} opae_bitstream_header;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#pragma pack(pop)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Memory-resident GBS format.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* `metadata_version` begins at 1 and increments upward.
|
|
Packit |
534379 |
* `parsed_metadata` is the expanded metadata structure.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* If `metadata_version` is 1, then `parsed_metadata`
|
|
Packit |
534379 |
* can be safely typecasted to an `opae_bitstream_metadata_v1 *`.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
typedef struct _opae_bitstream_info {
|
|
Packit |
534379 |
const char *filename; /**< location of the file on disk */
|
|
Packit |
534379 |
uint8_t *data; /**< entire GBS file contents */
|
|
Packit |
534379 |
size_t data_len; /**< length in bytes of data */
|
|
Packit |
534379 |
uint8_t *rbf_data; /**< start of AFU logic in data */
|
|
Packit |
534379 |
size_t rbf_len; /**< length of AFU logic in bytes */
|
|
Packit |
534379 |
fpga_guid pr_interface_id; /**< identifies GBS compatibility */
|
|
Packit |
534379 |
int metadata_version; /**< identifies metadata format */
|
|
Packit |
534379 |
void *parsed_metadata; /**< the expanded metadata */
|
|
Packit |
534379 |
} opae_bitstream_info;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define OPAE_BITSTREAM_INFO_INITIALIZER \
|
|
Packit |
534379 |
{ NULL, NULL, 0, NULL, 0, { 0, }, 0, NULL }
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifdef __cplusplus
|
|
Packit |
534379 |
extern "C" {
|
|
Packit |
534379 |
#endif /* __cplusplus */
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Load a GBS file from disk into memory
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Used to validate and load a GBS file into its memory-resident format.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @param[in] file Location of the GBS file on disk.
|
|
Packit |
534379 |
* @param[out] info Storage for the loaded GBS file contents
|
|
Packit |
534379 |
* and its expanded metadata.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @returns FPGA_OK on success. FPGA_INVALID_PARAM if the bitstream
|
|
Packit |
534379 |
* format is invalid. FPGA_NO_MEMORY if memory allocation fails.
|
|
Packit |
534379 |
* FPGA_EXCEPTION if a metadata parsing error was encountered.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
fpga_result opae_load_bitstream(const char *file, opae_bitstream_info *info);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @deprecated Determine whether a loaded GBS is in legacy format.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Legacy GBS files have no metadata.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
bool opae_is_legacy_bitstream(opae_bitstream_info *info);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Unload a memory-resident GBS
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Used to free the resources allocated by `opae_load_bitstream`.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @param[in] info The loaded GBS info to be released.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @returns FPGA_OK on success. FPGA_INVALID_PARAM if info is NULL.
|
|
Packit |
534379 |
* FPGA_EXCEPTION if the metadata version is not supported.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
fpga_result opae_unload_bitstream(opae_bitstream_info *info);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifdef __cplusplus
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
#endif /* __cplusplus */
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#endif /* __OPAE_BITSTREAM_H__ */
|