|
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 |
#ifndef __OPAE_PROPS_H__
|
|
Packit |
534379 |
#define __OPAE_PROPS_H__
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <stdint.h>
|
|
Packit |
534379 |
#ifndef __USE_GNU
|
|
Packit |
534379 |
#define __USE_GNU 1
|
|
Packit |
534379 |
#endif
|
|
Packit |
534379 |
#include <pthread.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <opae/types.h>
|
|
Packit |
534379 |
#include <opae/types_enum.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include "opae_int.h"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// FPGA property magic (FPGAPROP)
|
|
Packit |
534379 |
#define FPGA_PROPERTY_MAGIC 0x4650474150524f50
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Fields common across all object types */
|
|
Packit |
534379 |
#define FPGA_PROPERTY_PARENT 0
|
|
Packit |
534379 |
#define FPGA_PROPERTY_OBJTYPE 1
|
|
Packit |
534379 |
#define FPGA_PROPERTY_SEGMENT 2
|
|
Packit |
534379 |
#define FPGA_PROPERTY_BUS 3
|
|
Packit |
534379 |
#define FPGA_PROPERTY_DEVICE 4
|
|
Packit |
534379 |
#define FPGA_PROPERTY_FUNCTION 5
|
|
Packit |
534379 |
#define FPGA_PROPERTY_SOCKETID 6
|
|
Packit |
534379 |
#define FPGA_PROPERTY_VENDORID 7
|
|
Packit |
534379 |
#define FPGA_PROPERTY_DEVICEID 8
|
|
Packit |
534379 |
#define FPGA_PROPERTY_GUID 9
|
|
Packit |
534379 |
#define FPGA_PROPERTY_OBJECTID 10
|
|
Packit |
534379 |
#define FPGA_PROPERTY_NUM_ERRORS 11
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Fields for FPGA objects */
|
|
Packit |
534379 |
#define FPGA_PROPERTY_NUM_SLOTS 32
|
|
Packit |
534379 |
#define FPGA_PROPERTY_BBSID 33
|
|
Packit |
534379 |
#define FPGA_PROPERTY_BBSVERSION 34
|
|
Packit |
534379 |
#define FPGA_PROPERTY_MODEL 35
|
|
Packit |
534379 |
#define FPGA_PROPERTY_LOCAL_MEMORY 36
|
|
Packit |
534379 |
#define FPGA_PROPERTY_CAPABILITIES 37
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/** Fields for accelerator objects */
|
|
Packit |
534379 |
#define FPGA_PROPERTY_ACCELERATOR_STATE 32
|
|
Packit |
534379 |
#define FPGA_PROPERTY_NUM_MMIO 33
|
|
Packit |
534379 |
#define FPGA_PROPERTY_NUM_INTERRUPTS 34
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define FIELD_VALID(P, F) (((P)->valid_fields >> (F)) & 1)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define SET_FIELD_VALID(P, F) \
|
|
Packit |
534379 |
((P)->valid_fields = (P)->valid_fields | ((uint64_t)1 << (F)))
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define CLEAR_FIELD_VALID(P, F) \
|
|
Packit |
534379 |
((P)->valid_fields = (P)->valid_fields & ~((uint64_t)1 << (F)))
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
struct _fpga_properties {
|
|
Packit |
534379 |
pthread_mutex_t lock;
|
|
Packit |
534379 |
uint64_t magic;
|
|
Packit |
534379 |
uint32_t flags;
|
|
Packit |
534379 |
#define OPAE_PROPERTIES_FLAG_PARENT_ALLOC 0x00000001
|
|
Packit |
534379 |
/* Common properties */
|
|
Packit |
534379 |
uint64_t valid_fields; // bitmap of valid fields
|
|
Packit |
534379 |
// valid here means the field has been set using the API
|
|
Packit |
534379 |
// bit 0x00 - parent field is valid
|
|
Packit |
534379 |
// bit 0x01 - objtype field is valid
|
|
Packit |
534379 |
// bit 0x02 - segment field is valid
|
|
Packit |
534379 |
// ...
|
|
Packit |
534379 |
// up to bit 0x1F
|
|
Packit |
534379 |
fpga_guid guid; // Applies only to accelerator types
|
|
Packit |
534379 |
fpga_token parent;
|
|
Packit |
534379 |
fpga_objtype objtype;
|
|
Packit |
534379 |
uint16_t segment;
|
|
Packit |
534379 |
uint8_t bus;
|
|
Packit |
534379 |
uint8_t device;
|
|
Packit |
534379 |
uint8_t function;
|
|
Packit |
534379 |
uint8_t socket_id;
|
|
Packit |
534379 |
uint64_t object_id;
|
|
Packit |
534379 |
uint16_t vendor_id;
|
|
Packit |
534379 |
uint16_t device_id;
|
|
Packit |
534379 |
uint32_t num_errors;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/* Object-specific properties
|
|
Packit |
534379 |
* bitfields start as 0x20
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
union {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/* fpga object properties
|
|
Packit |
534379 |
* */
|
|
Packit |
534379 |
struct {
|
|
Packit |
534379 |
uint32_t num_slots;
|
|
Packit |
534379 |
uint64_t bbs_id;
|
|
Packit |
534379 |
fpga_version bbs_version;
|
|
Packit |
534379 |
// TODO char model[FPGA_MODEL_LENGTH];
|
|
Packit |
534379 |
// TODO uint64_t local_memory_size;
|
|
Packit |
534379 |
// TODO uint64_t capabilities; #<{(| bitfield (HSSI,
|
|
Packit |
534379 |
// iommu, ...) |)}>#
|
|
Packit |
534379 |
} fpga;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/* accelerator object properties
|
|
Packit |
534379 |
* */
|
|
Packit |
534379 |
struct {
|
|
Packit |
534379 |
fpga_accelerator_state state;
|
|
Packit |
534379 |
uint32_t num_mmio;
|
|
Packit |
534379 |
uint32_t num_interrupts;
|
|
Packit |
534379 |
} accelerator;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
} u;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// returns NULL on error, locked _fpga_properties object on success.
|
|
Packit |
534379 |
static inline struct _fpga_properties *
|
|
Packit |
534379 |
opae_validate_and_lock_properties(fpga_properties props)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
int res;
|
|
Packit |
534379 |
struct _fpga_properties *p = (struct _fpga_properties *)props;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (!p)
|
|
Packit |
534379 |
return NULL;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
opae_mutex_lock(res, &p->lock);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (p->magic != FPGA_PROPERTY_MAGIC) {
|
|
Packit |
534379 |
opae_mutex_unlock(res, &p->lock);
|
|
Packit |
534379 |
return NULL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return p;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
struct _fpga_properties *opae_properties_create(void);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#endif // ___OPAE_PROPS_H__
|