ZOCL Driver Interfaces¶
A GEM style driver for Xilinx edge based accelerators
File zynq_ioctl.h defines ioctl command codes and associated structures for interacting with zocl driver for Xilinx FPGA platforms(Zynq/ZynqMP/Versal).
Accelerator memory allocation is modeled as buffer objects (bo). zocl supports both SMMU based shared virtual memory and CMA based shared physical memory between PS and PL. zocl also supports memory management of PL-DDRs and PL-BRAMs. PL-DDR is reserved by zocl driver via device tree. Both PS Linux and PL logic can access PL-DDRs
Execution model is asynchronous where execute commands are submitted using command buffers and POSIX poll is used to wait for finished commands. Commands for a compute unit can only be submitted after an explicit context has been opened by the client for that compute unit.
zocl driver functionality is described in the following table.
# |
Functionality |
ioctl request code |
data format |
|---|---|---|---|
1 |
Allocate buffer on device |
DRM_IOCTL_ZOCL_CREATE_BO |
drm_zocl_create_bo |
2 |
Allocate buffer on device with userptr |
DRM_IOCTL_ZOCL_USERPTR_BO |
drm_zocl_userptr_bo |
3 |
Get the buffer handle of given physical address |
DRM_IOCTL_ZOCL_GET_HOST_BO |
drm_zocl_host_bo |
4 |
Prepare bo for mapping into user’s address space |
DRM_IOCTL_ZOCL_MAP_BO |
drm_zocl_map_bo |
5 |
Synchronize (DMA) buffer contents in requested direction |
DRM_IOCTL_ZOCL_SYNC_BO |
drm_zocl_sync_bo |
6 |
Obtain information about buffer object |
DRM_IOCTL_ZOCL_INFO_BO |
drm_zocl_info_bo |
7 |
Update bo backing storage with user’s data |
DRM_IOCTL_ZOCL_PWRITE_BO |
drm_zocl_pwrite_bo |
8 |
Read back data in bo backing storage |
DRM_IOCTL_ZOCL_PREAD_BO |
drm_zocl_pread_bo |
9 |
Update device view with a specific xclbin image |
DRM_IOCTL_ZOCL_PCAP_DOWNLOAD |
drm_zocl_pcap_download |
10 |
Read the xclbin and map the compute units. |
DRM_IOCTL_ZOCL_READ_AXLF |
drm_zocl_axlf |
11 |
Send an execute job to a compute unit |
DRM_IOCTL_ZOCL_EXECBUF |
drm_zocl_execbuf |
12 |
Get the soft kernel command (experimental) |
DRM_IOCTL_ZOCL_SK_GETCMD |
drm_zocl_sk_getcmd |
13 |
Create the soft kernel (experimental) |
DRM_IOCTL_ZOCL_SK_CREATE |
drm_zocl_sk_create |
14 |
Report the soft kernel state (experimental) |
DRM_IOCTL_ZOCL_SK_REPORT |
drm_zocl_sk_report |
15 |
Get Information about Compute Unit (experimental) |
DRM_IOCTL_ZOCL_INFO_CU |
drm_zocl_info_cu |
16 |
Create a hw context on a slot for a xclbin on the device |
DRM_IOCTL_ZOCL_CREATE_HW_CTX |
drm_zocl_create_hw_ctx |
17 |
Destroy a hw context on a slot on a device |
DRM_IOCTL_ZOCL_DESTROY_HW_CTX |
drm_zocl_destroy_hw_ctx |
18 |
Open cu context |
DRM_IOCTL_ZOCL_OPEN_CU_CTX |
drm_zocl_open_cu_ctx |
19 |
Close cu context |
DRM_IOCTL_ZOCL_CLOSE_CU_CTX |
drm_zocl_close_cu_ctx |
20 |
Send an execute job to a CU with hw context |
DRM_IOCTL_ZOCL_HW_CTX_EXECBUF |
drm_zocl_hw_ctx_execbuf |
21 |
Open graph context |
DRM_IOCTL_ZOCL_OPEN_GRAPH_CTX |
drm_zocl_open_graph_ctx |
22 |
Close graph context |
DRM_IOCTL_ZOCL_CLOSE_GRAPH_CTX |
drm_zocl_close_graph_ctx |
- struct drm_zocl_create_bo
Create buffer object used with DRM_IOCTL_ZOCL_CREATE_BO ioctl
Definition
struct drm_zocl_create_bo {
uint64_t size;
uint32_t handle;
uint32_t flags;
};
Members
sizeRequested size of the buffer object
handlebo handle returned by the driver
flagsDRM_ZOCL_BO_XXX flags
- struct drm_zocl_userptr_bo
Create buffer object with user’s pointer used with DRM_IOCTL_ZOCL_USERPTR_BO ioctl
Definition
struct drm_zocl_userptr_bo {
uint64_t addr;
uint64_t size;
uint32_t handle;
uint32_t flags;
};
Members
addrAddress of buffer allocated by user
sizeRequested size of the buffer object
handlebo handle returned by the driver
flagsDRM_XOCL_BO_XXX flags
- struct drm_zocl_map_bo
Prepare a buffer object for mmap used with DRM_IOCTL_ZOCL_MAP_BO ioctl
Definition
struct drm_zocl_map_bo {
uint32_t handle;
uint32_t pad;
uint64_t offset;
};
Members
handlebo handle
padUnused
offset‘Fake’ offset returned by the driver which can be used with POSIX mmap
- struct drm_zocl_sync_bo
Synchronize the buffer in the requested direction via cache flush/invalidation. used with DRM_ZOCL_SYNC_BO ioctl.
Definition
struct drm_zocl_sync_bo {
uint32_t handle;
enum drm_zocl_sync_bo_dir dir;
uint64_t offset;
uint64_t size;
};
Members
handleGEM object handle
dirDRM_ZOCL_SYNC_DIR_XXX
offsetOffset into the object to write to
sizeLength of data to write
- struct drm_zocl_info_bo
Obtain information about buffer object used with DRM_IOCTL_ZOCL_INFO_BO ioctl
Definition
struct drm_zocl_info_bo {
uint32_t handle;
uint32_t flags;
uint64_t size;
uint64_t paddr;
};
Members
handleGEM object handle
flagsUser BO flags
sizeSize of BO
paddrphysical address
- struct drm_zocl_host_bo
Get the buffer handle of given physical address used with DRM_IOCTL_ZOCL_GET_HOST_BO ioctl
Definition
struct drm_zocl_host_bo {
uint64_t paddr;
size_t size;
uint32_t handle;
};
Members
paddrphysical address
sizeSize of BO
handleGEM object handle
- struct drm_zocl_set_cu_range
Set CU range used with DRM_IOCTL_ZOCL_SET_CU_READONLY_RANGE
Definition
struct drm_zocl_set_cu_range {
uint32_t cu_index;
uint32_t start;
uint32_t size;
};
Members
cu_indexIndex of the compute unit
startStart offset of the range
sizeSize of the range
- struct drm_zocl_pwrite_bo
Update bo with user’s data used with DRM_IOCTL_ZOCL_PWRITE_BO ioctl
Definition
struct drm_zocl_pwrite_bo {
uint32_t handle;
uint32_t pad;
uint64_t offset;
uint64_t size;
uint64_t data_ptr;
};
Members
handleGEM object handle
padPadding
offsetOffset into the object to write to
sizeLength of data to write
data_ptrPointer to read the data from (pointers not 32/64 compatible)
- struct drm_zocl_pread_bo
Read data from bo used with DRM_IOCTL_ZOCL_PREAD_BO ioctl
Definition
struct drm_zocl_pread_bo {
uint32_t handle;
uint32_t pad;
uint64_t offset;
uint64_t size;
uint64_t data_ptr;
};
Members
handleGEM object handle
padPadding
offsetOffset into the object to read from
sizeLength of data to wrreadite
data_ptrPointer to write the data into (pointers not 32/64 compatible)
- struct drm_zocl_info_cu
Get information about Compute Unit (experimental) used with DRM_IOCTL_ZOCL_INFO_CU ioctl
Definition
struct drm_zocl_info_cu {
uint64_t paddr;
int apt_idx;
int cu_idx;
};
Members
paddrPhysical address
apt_idxAperture index
cu_idxCU index
- struct drm_zocl_execbuf
Submit a command buffer for execution on a compute unit (experimental) used with DRM_IOCTL_ZOCL_EXECBUF ioctl
Definition
struct drm_zocl_execbuf {
uint32_t ctx_id;
uint32_t exec_bo_handle;
};
Members
ctx_idPass 0
exec_bo_handleBO handle of command buffer formatted as ERT command
- struct drm_zocl_hw_ctx_execbuf
Submit a command buffer for execution on a CU used with DRM_IOCTL_ZOCL_HW_CTX_EXECBUF ioctl
Definition
struct drm_zocl_hw_ctx_execbuf {
uint32_t hw_ctx_id;
uint32_t exec_bo_handle;
};
Members
hw_ctx_idpass the hw context id
exec_bo_handleBO handle of command buffer formatted as ERT command
- struct argument_info
Kernel argument information
Definition
struct argument_info {
char name;
uint32_t offset;
uint32_t size;
uint32_t dir;
};
Members
nameargument name
offsetargument offset in CU
sizeargument size in bytes
dirinput or output argument for a CU
- struct kernel_info
Kernel information
Definition
struct kernel_info {
char name;
uint32_t range;
int anums;
struct argument_info args;
};
Members
namekernel name
rangekernel range
anumsnumber of argument
argsargument array
- struct drm_zocl_kds
KDS user configuration
Definition
struct drm_zocl_kds {
uint32_t polling:1;
};
Members
pollingpoll for command completion
- struct drm_zocl_axlf
Read xclbin (AXLF) device image and map CUs (experimental) used with DRM_IOCTL_ZOCL_READ_AXLF ioctl
Definition
struct drm_zocl_axlf {
struct axlf * za_xclbin_ptr;
uint32_t za_flags;
int za_ksize;
char * za_kernels;
uint32_t za_slot_id;
uint8_t hw_gen;
uint32_t partition_id;
};
Members
za_xclbin_ptrPointer to xclbin (AXLF) object
za_flagsplatform flags
za_ksizesize of kernels in bytes
za_kernelspointer of argument array
za_slot_idxclbin slot
hw_genaie generation
partition_idaie partition id
- struct drm_zocl_create_hw_ctx
Create a hw context on a slot on device used with DRM_IOCTL_ZOCL_CREATE_HW_CTX ioctl
Definition
struct drm_zocl_create_hw_ctx {
struct drm_zocl_axlf * axlf_ptr;
uint32_t qos;
uint32_t hw_context;
};
Members
axlf_ptraxlf pointer which need to be downloaded
qosQOS information
hw_contextReturns context handle
- struct drm_zocl_destroy_hw_ctx
Destroy a hw context on a slot on device used with DRM_IOCTL_ZOCL_DESTROY_HW_CTX ioctl
Definition
struct drm_zocl_destroy_hw_ctx {
uint32_t hw_context;
};
Members
hw_contextContext handle that needs to be closed
- struct drm_zocl_open_cu_ctx
Opens a cu context under a hw context on the device used with DRM_IOCTL_ZOCL_OPEN_CU_CTX
Definition
struct drm_zocl_open_cu_ctx {
uint32_t hw_context;
char cu_name;
uint32_t flags;
uint32_t cu_index;
};
Members
hw_contextOpen a cu context under this hw context handle
cu_nameName of the cu on the device image for which the open context is being made
flagsShared or Exclusive context (ZOCL_CTX_SHARED/ZOCL_CTX_EXCLUSIVE)
cu_indexReture the acquired cu index. This will be required for closing
- struct drm_zocl_close_cu_ctx
Closes a cu context opened under a hw context on device used with DRM_IOCTL_ZOCL_CLOSE_CU_CTX
Definition
struct drm_zocl_close_cu_ctx {
uint32_t hw_context;
uint32_t cu_index;
};
Members
hw_contextclose cu context under this hw context handle
cu_indexIndex of the cu on the device image for which the close request is being made
- struct drm_zocl_open_graph_ctx
Opens a graph context under a hw context on the device used with DRM_IOCTL_ZOCL_OPEN_GRAPH_CTX
Definition
struct drm_zocl_open_graph_ctx {
uint32_t hw_context;
uint32_t flags;
uint32_t graph_id;
};
Members
hw_contextOpen a graph context under this hw context handle
flagsShared or Exclusive context (ZOCL_CTX_SHARED/ZOCL_CTX_EXCLUSIVE)
graph_idgraph id
- struct drm_zocl_close_graph_ctx
Closes a graph context opened under a hw context on device used with DRM_IOCTL_ZOCL_CLOSE_GRAPH_CTX
Definition
struct drm_zocl_close_graph_ctx {
uint32_t hw_context;
};
Members
hw_contextclose graph context under this hw context handle
- struct drm_zocl_sk_getcmd
Get the soft kernel command (experimental) used with DRM_IOCTL_ZOCL_SK_GETCMD ioctl
Definition
struct drm_zocl_sk_getcmd {
uint32_t opcode;
uint32_t start_cuidx;
uint32_t cu_nums;
char name;
int bohdl;
int meta_bohdl;
unsigned char uuid;
};
Members
opcodeopcode for the Soft Kernel Command Packet
start_cuidxstart index of compute units
cu_numsnumber of compute units in program
namesymbol name of soft kernel
bohdlBO to hold soft kernel image
meta_bohdlBO to hold metadata
uuidUUID for the xclbin
- struct drm_zocl_aie_cmd
Get the aie command used with DRM_IOCTL_ZOCL_AIE_GETCMD and DRM_IOCTL_ZOCL_AIE_PUTCMD ioctl
Definition
struct drm_zocl_aie_cmd {
uint32_t opcode;
uint32_t size;
char info;
};
Members
opcodeopcode for the Aie Command Packet
sizesize in bytes of info data
infoinformation to transfer
- struct drm_zocl_sk_create
Create a soft kernel (experimental) used with DRM_IOCTL_ZOCL_SK_CREATE ioctl
Definition
struct drm_zocl_sk_create {
uint32_t cu_idx;
int handle;
};
Members
cu_idxCompute unit index
handleBuffer object handle
- struct drm_zocl_sk_report
Report the Soft Kernel State (experimental) used with DRM_IOCTL_ZOCL_SK_REPORT ioctl
Definition
struct drm_zocl_sk_report {
uint32_t cu_idx;
enum drm_zocl_scu_state cu_state;
};
Members
cu_idxCompute unit index
cu_stateState of the Soft Compute Unit