forked from Xilinx/XRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xrt.h
1223 lines (1121 loc) · 36.3 KB
/
xrt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2015-2019, Xilinx Inc - All rights reserved
* Xilinx Runtime (XRT) APIs
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#ifndef _XCL_XRT_CORE_H_
#define _XCL_XRT_CORE_H_
#ifdef __cplusplus
#include <cstdlib>
#include <cstdint>
#else
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#endif
#if defined(_WIN32)
#ifdef XCL_DRIVER_DLL_EXPORT
#define XCL_DRIVER_DLLESPEC __declspec(dllexport)
#else
#define XCL_DRIVER_DLLESPEC __declspec(dllimport)
#endif
#else
#define XCL_DRIVER_DLLESPEC __attribute__((visibility("default")))
#endif
#if defined (_WIN32)
#define NOMINMAX
#include <windows.h>
#include "windows/types.h"
#endif
#ifdef __GNUC__
# define XRT_DEPRECATED __attribute__ ((deprecated))
#else
# define XRT_DEPRECATED
#endif
#include "xclbin.h"
#include "xclperf.h"
#include "xcl_app_debug.h"
#include "xclerr.h"
#include "xclhal2_mem.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* DOC: Xilinx Runtime (XRT) Library Interface Definitions
*
* Header file *xrt.h* defines data structures and function signatures
* exported by Xilinx Runtime (XRT) Library. XRT is part of software
* stack which is integrated into Xilinx reference platform.
*/
/**
* typedef xclDeviceHandle - opaque device handle
*
* A device handle of xclDeviceHandle kind is obtained by opening a
* device. Clients pass this device handle to refer to the opened
* device in all future interaction with XRT.
*/
typedef void * xclDeviceHandle;
#define XRT_NULL_HANDLE NULL
/*
* typedef xclBufferHandle - opaque buffer handle
*
* A buffer handle of xclBufferHandle kind is obtained by allocating
* buffer objects. The buffer handle is used by XRT APIs that operate
* on on buffer objects.
*/
#ifdef _WIN32
typedef void * xclBufferHandle;
# define NULLBO INVALID_HANDLE_VALUE
#else
typedef unsigned int xclBufferHandle;
# define NULLBO 0xffffffff
#endif
#define XRT_NULL_BO NULLBO
struct axlf;
/**
* Structure used to obtain various bits of information from the device.
*/
struct xclDeviceInfo2 {
unsigned int mMagic; // = 0X586C0C6C; XL OpenCL X->58(ASCII), L->6C(ASCII), O->0 C->C L->6C(ASCII);
char mName[256];
unsigned short mHALMajorVersion;
unsigned short mHALMinorVersion;
unsigned short mVendorId;
unsigned short mDeviceId;
unsigned short mSubsystemId;
unsigned short mSubsystemVendorId;
unsigned short mDeviceVersion;
size_t mDDRSize; // Size of DDR memory
size_t mDataAlignment; // Minimum data alignment requirement for host buffers
size_t mDDRFreeSize; // Total unused/available DDR memory
size_t mMinTransferSize; // Minimum DMA buffer size
unsigned short mDDRBankCount;
unsigned short mOCLFrequency[4];
unsigned short mPCIeLinkWidth;
unsigned short mPCIeLinkSpeed;
unsigned short mDMAThreads;
unsigned short mOnChipTemp;
unsigned short mFanTemp;
unsigned short mVInt;
unsigned short mVAux;
unsigned short mVBram;
float mCurrent;
unsigned short mNumClocks;
unsigned short mFanSpeed;
bool mMigCalib;
unsigned long long mXMCVersion;
unsigned long long mMBVersion;
unsigned short m12VPex;
unsigned short m12VAux;
unsigned long long mPexCurr;
unsigned long long mAuxCurr;
unsigned short mFanRpm;
unsigned short mDimmTemp[4];
unsigned short mSE98Temp[4];
unsigned short m3v3Pex;
unsigned short m3v3Aux;
unsigned short mDDRVppBottom;
unsigned short mDDRVppTop;
unsigned short mSys5v5;
unsigned short m1v2Top;
unsigned short m1v8Top;
unsigned short m0v85;
unsigned short mMgt0v9;
unsigned short m12vSW;
unsigned short mMgtVtt;
unsigned short m1v2Bottom;
unsigned long long mDriverVersion;
unsigned int mPciSlot;
bool mIsXPR;
unsigned long long mTimeStamp;
char mFpga[256];
unsigned short mPCIeLinkWidthMax;
unsigned short mPCIeLinkSpeedMax;
unsigned short mVccIntVol;
unsigned short mVccIntCurr;
unsigned short mNumCDMA;
};
/**
* Unused, keep for backwards compatibility
*/
enum xclBOKind {
XCL_BO_SHARED_VIRTUAL = 0,
XCL_BO_SHARED_PHYSICAL,
XCL_BO_MIRRORED_VIRTUAL,
XCL_BO_DEVICE_RAM,
XCL_BO_DEVICE_BRAM,
XCL_BO_DEVICE_PREALLOCATED_BRAM,
};
enum xclBOSyncDirection {
XCL_BO_SYNC_BO_TO_DEVICE = 0,
XCL_BO_SYNC_BO_FROM_DEVICE,
};
/**
* Define address spaces on the device AXI bus. The enums are used in
* xclRead() and xclWrite() to pass relative offsets.
*/
enum xclAddressSpace {
XCL_ADDR_SPACE_DEVICE_FLAT = 0, // Absolute address space
XCL_ADDR_SPACE_DEVICE_RAM = 1, // Address space for the DDR memory
XCL_ADDR_KERNEL_CTRL = 2, // Address space for the OCL Region control port
XCL_ADDR_SPACE_DEVICE_PERFMON = 3, // Address space for the Performance monitors
XCL_ADDR_SPACE_DEVICE_REG = 4, // Address space for device registers.
XCL_ADDR_SPACE_DEVICE_CHECKER = 5, // Address space for protocol checker
XCL_ADDR_SPACE_MAX = 8
};
/**
* Defines log message severity levels for messages sent to log file
* with xclLogMsg cmd
*/
enum xrtLogMsgLevel {
XRT_EMERGENCY = 0,
XRT_ALERT = 1,
XRT_CRITICAL = 2,
XRT_ERROR = 3,
XRT_WARNING = 4,
XRT_NOTICE = 5,
XRT_INFO = 6,
XRT_DEBUG = 7
};
/**
* Defines verbosity levels which are passed to xclOpen during device
* creation time
*/
enum xclVerbosityLevel {
XCL_QUIET = 0,
XCL_INFO = 1,
XCL_WARN = 2,
XCL_ERROR = 3
};
enum xclResetKind {
XCL_RESET_KERNEL, // not implemented through xocl user pf
XCL_RESET_FULL, // not implemented through xocl user pf
XCL_USER_RESET
};
#define XCL_DEVICE_USAGE_COUNT 8
struct xclDeviceUsage {
size_t h2c[XCL_DEVICE_USAGE_COUNT];
size_t c2h[XCL_DEVICE_USAGE_COUNT];
size_t ddrMemUsed[XCL_DEVICE_USAGE_COUNT];
unsigned int ddrBOAllocated[XCL_DEVICE_USAGE_COUNT];
unsigned int totalContexts;
uint64_t xclbinId[4];
unsigned int dma_channel_cnt;
unsigned int mm_channel_cnt;
uint64_t memSize[XCL_DEVICE_USAGE_COUNT];
};
struct xclBOProperties {
uint32_t handle;
uint32_t flags;
uint64_t size;
uint64_t paddr;
int reserved; // not implemented
};
/**
* DOC: XRT Device Management APIs
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/**
* xclProbe() - Enumerate devices found in the system
*
* Return: count of devices found
*/
XCL_DRIVER_DLLESPEC
unsigned int
xclProbe();
/**
* xclOpen() - Open a device and obtain its handle.
*
* @deviceIndex: Slot number of device 0 for first device, 1 for the second device...
* @logFileName: Log file to use for optional logging
* @level: Severity level of messages to log
*
* Return: Device handle
*/
XCL_DRIVER_DLLESPEC
xclDeviceHandle
xclOpen(unsigned int deviceIndex, const char *logFileName,
enum xclVerbosityLevel level);
/**
* xclClose() - Close an opened device
*
* @handle: Device handle
*/
XCL_DRIVER_DLLESPEC
void
xclClose(xclDeviceHandle handle);
/**
* xclResetDevice() - Reset a device or its CL
*
* @handle: Device handle
* @kind: Reset kind
* Return: 0 on success or appropriate error number
*
* Reset the device. All running kernels will be killed and buffers in DDR will be
* purged. A device may be reset if a user's application dies without waiting for
* running kernel(s) to finish.
* NOTE: Only implemeted Reset kind through user pf is XCL_USER_RESET
*/
XCL_DRIVER_DLLESPEC
int
xclResetDevice(xclDeviceHandle handle, enum xclResetKind kind);
/**
* xclGetDeviceInfo2() - Obtain various bits of information from the device
*
* @handle: Device handle
* @info: Information record
* Return: 0 on success or appropriate error number
*/
XCL_DRIVER_DLLESPEC
int
xclGetDeviceInfo2(xclDeviceHandle handle, struct xclDeviceInfo2 *info);
/**
* xclGetUsageInfo() - Obtain usage information from the device
*
* @handle: Device handle
* @info: Information record
* Return: 0 on success or appropriate error number
*/
XCL_DRIVER_DLLESPEC
int
xclGetUsageInfo(xclDeviceHandle handle, struct xclDeviceUsage *info);
/**
* xclGetErrorStatus() - Obtain error information from the device
*
* @handle: Device handle
* @info: Information record
* Return: 0 on success or appropriate error number
*/
XCL_DRIVER_DLLESPEC
int
xclGetErrorStatus(xclDeviceHandle handle, struct xclErrorStatus *info);
/**
* xclLoadXclBin() - Download FPGA image (xclbin) to the device
*
* @handle: Device handle
* @buffer: Pointer to device image (xclbin) in memory
* Return: 0 on success or appropriate error number
*
* Download FPGA image (AXLF) to the device. The PR bitstream is
* encapsulated inside xclbin as a section. xclbin may also contains
* other sections which are suitably handled by the driver.
*/
XCL_DRIVER_DLLESPEC
int
xclLoadXclBin(xclDeviceHandle handle, const struct axlf *buffer);
/**
* xclGetSectionInfo() - Get Information from sysfs about the downloaded xclbin sections
*
* @handle: Device handle
* @info: Pointer to preallocated memory which will store the return value.
* @size: Pointer to preallocated memory which will store the return size.
* @kind: axlf_section_kind for which info is being queried
* @index: The (sub)section index for the "kind" type.
* Return: 0 on success or appropriate error number
*
* Get the section information from sysfs. The index corrresponds to the (section) entry
* of the axlf_section_kind data being queried. The info and the size contain the return
* binary value of the subsection and its size.
*/
XCL_DRIVER_DLLESPEC
int
xclGetSectionInfo(xclDeviceHandle handle, void* info, size_t *size,
enum axlf_section_kind kind, int index);
/**
* xclReClock2() - Configure PR region frequncies
*
* @handle: Device handle
* @region: PR region (always 0)
* @targetFreqMHz: Array of target frequencies in order for the Clock Wizards driving
* the PR region
* Return: 0 on success or appropriate error number
*/
XCL_DRIVER_DLLESPEC
int
xclReClock2(xclDeviceHandle handle, unsigned short region,
const unsigned short *targetFreqMHz);
/**
* xclLockDevice() - Get exclusive ownership of the device
*
* @handle: Device handle
* Return: 0 on success or appropriate error number
*
* The lock is necessary before performing buffer migration, register
* access or bitstream downloads.
*/
XCL_DRIVER_DLLESPEC
int
xclLockDevice(xclDeviceHandle handle);
/**
* xclUnlockDevice() - Release exclusive ownership of the device
*
* @handle: Device handle
* Return: 0 on success or appropriate error number
*/
XCL_DRIVER_DLLESPEC
int
xclUnlockDevice(xclDeviceHandle handle);
/**
* xclOpenContext() - Create shared/exclusive context on compute units
*
* @handle: Device handle
* @xclbinId: UUID of the xclbin image running on the device
* @ipIndex: IP/CU index in the IP LAYOUT array
* @shared: Shared access or exclusive access
* Return: 0 on success or appropriate error number
*
* The context is necessary before submitting execution jobs using
* xclExecBuf(). Contexts may be exclusive or shared. Allocation of
* exclusive contexts on a compute unit would succeed only if another
* client has not already setup up a context on that compute
* unit. Shared contexts can be concurrently allocated by many
* processes on the same compute units.
*/
XCL_DRIVER_DLLESPEC
int
xclOpenContext(xclDeviceHandle handle, xuid_t xclbinId, unsigned int ipIndex,
bool shared);
/**
* xclCloseContext() - Close previously opened context
*
* @handle: Device handle
* @xclbinId: UUID of the xclbin image running on the device
* @ipIndex: IP/CU index in the IP LAYOUT array
* Return: 0 on success or appropriate error number
*
* Close a previously allocated shared/exclusive context for a compute unit.
*/
XCL_DRIVER_DLLESPEC
int
xclCloseContext(xclDeviceHandle handle, xuid_t xclbinId, unsigned int ipIndex);
/*
* Update the device BPI PROM with new image
*/
XCL_DRIVER_DLLESPEC
int
xclUpgradeFirmware(xclDeviceHandle handle, const char *fileName);
/*
* Update the device PROM with new image with clearing bitstream
*/
XCL_DRIVER_DLLESPEC
int
xclUpgradeFirmware2(xclDeviceHandle handle, const char *file1, const char* file2);
/*
* Update the device SPI PROM with new image
*/
XCL_DRIVER_DLLESPEC
int
xclUpgradeFirmwareXSpi(xclDeviceHandle handle, const char *fileName, int index);
/**
* xclBootFPGA() - Boot the FPGA from PROM
*
* @handle: Device handle
* Return: 0 on success or appropriate error number
*
* This should only be called when there are no other clients. It will cause PCIe bus re-enumeration
*/
XCL_DRIVER_DLLESPEC
int
xclBootFPGA(xclDeviceHandle handle);
/*
* Write to /sys/bus/pci/devices/<deviceHandle>/remove and initiate a pci rescan by
* writing to /sys/bus/pci/rescan.
*/
XCL_DRIVER_DLLESPEC
int
xclRemoveAndScanFPGA();
/*
* Get the version number. 1 => Hal1 ; 2 => Hal2
*/
XCL_DRIVER_DLLESPEC
unsigned int
xclVersion();
/* End XRT Device Management APIs */
/**
* xclLogMsg() - Send message to log file as per settings in ini file.
*
* @handle: Device handle
* @level: Severity level of the msg
* @tag: Tag supplied by the client, like "OCL", "XMA", etc.
* @format: Format of Msg string to write to log file
* @...: All other arguments as per the format
*
* Return: 0 on success or appropriate error number
*/
XCL_DRIVER_DLLESPEC
int
xclLogMsg(xclDeviceHandle handle, enum xrtLogMsgLevel level, const char* tag,
const char* format, ...);
/**
* DOC: XRT Buffer Management APIs
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Buffer management APIs are used for managing device memory and migrating buffers
* between host and device memory
*/
/**
* xclAllocBO() - Allocate a BO of requested size with appropriate flags
*
* @handle: Device handle
* @size: Size of buffer
* @unused: This argument is ignored
* @flags: Specify bank information, etc
* Return: BO handle
*/
XCL_DRIVER_DLLESPEC
xclBufferHandle
xclAllocBO(xclDeviceHandle handle, size_t size,int unused, unsigned int flags);
/**
* xclAllocUserPtrBO() - Allocate a BO using userptr provided by the user
*
* @handle: Device handle
* @userptr: Pointer to 4K aligned user memory
* @size: Size of buffer
* @flags: Specify bank information, etc
* Return: BO handle
*/
XCL_DRIVER_DLLESPEC
xclBufferHandle
xclAllocUserPtrBO(xclDeviceHandle handle,void *userptr, size_t size,
unsigned int flags);
/**
* xclFreeBO() - Free a previously allocated BO
*
* @handle: Device handle
* @boHandle: BO handle
*/
XCL_DRIVER_DLLESPEC
void
xclFreeBO(xclDeviceHandle handle, xclBufferHandle boHandle);
/**
* xclWriteBO() - Copy-in user data to host backing storage of BO
*
* @handle: Device handle
* @boHandle: BO handle
* @src: Source data pointer
* @size: Size of data to copy
* @seek: Offset within the BO
* Return: 0 on success or appropriate error number
*
* Copy host buffer contents to previously allocated device
* memory. ``seek`` specifies how many bytes to skip at the beginning
* of the BO before copying-in ``size`` bytes of host buffer.
*/
XCL_DRIVER_DLLESPEC
size_t
xclWriteBO(xclDeviceHandle handle, xclBufferHandle boHandle,
const void *src, size_t size, size_t seek);
/**
* xclReadBO() - Copy-out user data from host backing storage of BO
*
* @handle: Device handle
* @boHandle: BO handle
* @dst: Destination data pointer
* @size: Size of data to copy
* @skip: Offset within the BO
* Return: 0 on success or appropriate error number
*
* Copy contents of previously allocated device memory to host
* buffer. ``skip`` specifies how many bytes to skip from the
* beginning of the BO before copying-out ``size`` bytes of device
* buffer.
*/
XCL_DRIVER_DLLESPEC
size_t
xclReadBO(xclDeviceHandle handle, xclBufferHandle boHandle,
void *dst, size_t size, size_t skip);
/**
* xclMapBO() - Memory map BO into user's address space
*
* @handle: Device handle
* @boHandle: BO handle
* @write: READ only or READ/WRITE mapping
* Return: Memory mapped buffer
*
* Map the contents of the buffer object into host memory
* To unmap the buffer call xclUnmapBO().
*/
XCL_DRIVER_DLLESPEC
void*
xclMapBO(xclDeviceHandle handle, xclBufferHandle boHandle, bool write);
/**
* xclUnmapBO() - Unmap a BO that was previously mapped with xclMapBO
*
* @handle: Device handle
* @boHandle: BO handle
* @addr: The mapped void * pointer returned from xclMapBO()
*/
XCL_DRIVER_DLLESPEC
int
xclUnmapBO(xclDeviceHandle handle, xclBufferHandle boHandle, void* addr);
/**
* xclSyncBO() - Synchronize buffer contents in requested direction
*
* @handle: Device handle
* @boHandle: BO handle
* @dir: To device or from device
* @size: Size of data to synchronize
* @offset: Offset within the BO
* Return: 0 on success or standard errno
*
* Synchronize the buffer contents between host and device. Depending
* on the memory model this may require DMA to/from device or CPU
* cache flushing/invalidation
*/
XCL_DRIVER_DLLESPEC
int
xclSyncBO(xclDeviceHandle handle, xclBufferHandle boHandle,
enum xclBOSyncDirection dir, size_t size, size_t offset);
/**
* xclCopyBO() - Copy device buffer contents to another buffer
*
* @handle: Device handle
* @dstBoHandle: Destination BO handle
* @srcBoHandle: Source BO handle
* @size: Size of data to synchronize
* @dst_offset: dst Offset within the BO
* @src_offset: src Offset within the BO
* Return: 0 on success or standard errno
*
* Copy from source buffer contents to destination buffer, can be
* device to device or device to host. Always perform WRITE to
* achieve better performance, destination buffer can be on device or
* host require DMA from device
*/
XCL_DRIVER_DLLESPEC
int
xclCopyBO(xclDeviceHandle handle, xclBufferHandle dstBoHandle,
xclBufferHandle srcBoHandle, size_t size, size_t dst_offset,
size_t src_offset);
/**
* xclExportBO() - Obtain DMA-BUF file descriptor for a BO
*
* @handle: Device handle
* @boHandle: BO handle which needs to be exported
* Return: File handle to the BO or standard errno
*
* Export a BO for import into another device or Linux subsystem which
* accepts DMA-BUF fd This operation is backed by Linux DMA-BUF
* framework
*/
XCL_DRIVER_DLLESPEC
int
xclExportBO(xclDeviceHandle handle, xclBufferHandle boHandle);
/**
* xclImportBO() - Obtain BO handle for a BO represented by DMA-BUF file descriptor
*
* @handle: Device handle
* @fd: File handle to foreign BO owned by another device which needs to be imported
* @flags: Unused
* Return: BO handle of the imported BO
*
* Import a BO exported by another device. *
* This operation is backed by Linux DMA-BUF framework
*/
XCL_DRIVER_DLLESPEC
xclBufferHandle
xclImportBO(xclDeviceHandle handle, int fd, unsigned int flags);
/**
* xclGetBOProperties() - Obtain xclBOProperties struct for a BO
*
* @handle: Device handle
* @boHandle: BO handle
* @properties: BO properties struct pointer
* Return: 0 on success
*
* This is the prefered method for obtaining BO property information.
*/
XCL_DRIVER_DLLESPEC
int
xclGetBOProperties(xclDeviceHandle handle, xclBufferHandle boHandle,
struct xclBOProperties *properties);
/*
* xclGetBOSize() - Retrieve size of a BO
*
*
* @handle: Device handle
* @boHandle: BO handle
* Return size_t size of the BO on success
*
* This API is deprecated and will be removed in future release.
* New clients should use xclGetBOProperties() instead
*/
XRT_DEPRECATED
static inline size_t
xclGetBOSize(xclDeviceHandle handle, xclBufferHandle boHandle)
{
struct xclBOProperties p;
return !xclGetBOProperties(handle, boHandle, &p) ? (size_t)p.size : -1;
}
/*
* Get the physical address on the device
*
* This API is deprecated and will be removed in future release.
* New clients should use xclGetBOProperties() instead.
*
* @handle: Device handle
* @boHandle: BO handle
* @return uint64_t address of the BO on success
*/
XRT_DEPRECATED
static inline uint64_t
xclGetDeviceAddr(xclDeviceHandle handle, xclBufferHandle boHandle)
{
struct xclBOProperties p;
return !xclGetBOProperties(handle, boHandle, &p) ? p.paddr : -1;
}
/* End XRT Buffer Management APIs */
/**
* DOC: XRT Unmanaged DMA APIs
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Unmanaged DMA APIs are for exclusive use by the debuggers and
* tools. The APIs allow clinets to read/write from/to absolute device
* address. No checks are performed if a buffer was allocated before
* at the specified location or if the address is valid. Users who
* want to take over the full memory managemnt of the device may use
* this API to synchronize their buffers between host and device.
*/
/**
* xclUnmgdPread() - Perform unmanaged device memory read operation
*
* @handle: Device handle
* @flags: Unused
* @buf: Destination data pointer
* @size: Size of data to copy
* @offset: Absolute offset inside device
* Return: 0 on success or appropriate error number
*
* This API may be used to perform DMA operation from absolute
* location specified. Users may use this if they want to perform
* their own device memory management -- not using the buffer object
* (BO) framework defined before.
*/
XCL_DRIVER_DLLESPEC
ssize_t
xclUnmgdPread(xclDeviceHandle handle, unsigned int flags, void *buf,
size_t size, uint64_t offset);
/**
* xclUnmgdPwrite() - Perform unmanaged device memory read operation
*
* @handle: Device handle
* @flags: Unused
* @buf: Source data pointer
* @size: Size of data to copy
* @offset: Absolute offset inside device
* Return: 0 on success or appropriate error number
*
* This API may be used to perform DMA operation to an absolute
* location specified. Users may use this if they want to perform
* their own device memory management -- not using the buffer object
* (BO) framework defined before.
*/
XCL_DRIVER_DLLESPEC
ssize_t
xclUnmgdPwrite(xclDeviceHandle handle, unsigned int flags, const void *buf,
size_t size, uint64_t offset);
/* End XRT Unmanaged DMA APIs */
/*
* DOC: XRT Register read/write APIs
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* These functions are used to read and write peripherals sitting on
* the address map. Note that the offset is wrt the address
* space. The register map and address map of execution units can be
* obtained from xclbin. Note that these APIs are multi-threading/
* multi-process safe and no checks are performed on the read/write
* requests. OpenCL runtime does **not** use these APIs but instead
* uses execution management APIs defined below.
*/
/**
* xclWrite() - Perform register write operation, deprecated
*
* @handle: Device handle
* @space: Address space
* @offset: Offset in the address space
* @hostBuf: Source data pointer
* @size: Size of data to copy
* Return: size of bytes written or appropriate error number
*
* This API may be used to write to device registers exposed on PCIe
* BAR. Offset is relative to the the address space. A device may have
* many address spaces.
* *This API is deprecated. Please use xclRegWrite(), instead.*
*/
XRT_DEPRECATED
XCL_DRIVER_DLLESPEC
size_t
xclWrite(xclDeviceHandle handle, enum xclAddressSpace space, uint64_t offset,
const void *hostBuf, size_t size);
/**
* xclRead() - Perform register read operation, deprecated
*
* @handle: Device handle
* @space: Address space
* @offset: Offset in the address space
* @hostbuf: Destination data pointer
* @size: Size of data to copy
* Return: size of bytes written or appropriate error number
*
* This API may be used to read from device registers exposed on PCIe
* BAR. Offset is relative to the the address space. A device may have
* many address spaces.
* *This API is deprecated. Please use xclRegRead(), instead.*
*/
XRT_DEPRECATED
XCL_DRIVER_DLLESPEC
size_t
xclRead(xclDeviceHandle handle, enum xclAddressSpace space, uint64_t offset,
void *hostbuf, size_t size);
/* XRT Register read/write APIs */
/*
* TODO:
* Define the following APIs
*
* 1. Host accessible pipe APIs: pread/pwrite
* 2. Accelerator status, start, stop APIs
* 3. Context creation APIs to support multiple clients
* 4. Multiple OCL Region support
* 5. DPDK style buffer management and device polling
*
*/
/**
* DOC: XRT Compute Unit Execution Management APIs
*
* These APIs are under development. These functions will be used to
* start compute units and wait for them to finish.
*/
/**
* xclExecBuf() - Submit an execution request to the embedded (or software) scheduler
*
* @handle: Device handle
* @cmdBO: BO handle containing command packet
* Return: 0 or standard error number
*
* Submit an exec buffer for execution. The exec buffer layout is
* defined by struct ert_packet which is defined in file *ert.h*. The
* BO should been allocated with DRM_XOCL_BO_EXECBUF flag.
*/
XCL_DRIVER_DLLESPEC
int
xclExecBuf(xclDeviceHandle handle, xclBufferHandle cmdBO);
/**
* xclExecBufWithWaitList() - Submit an execution request to the embedded (or software) scheduler
*
* @handle: Device handle
* @cmdBO: BO handle containing command packet
* @num_bo_in_wait_list: Number of BO handles in wait list
* @bo_wait_list: BO handles that must complete execution before cmdBO is started
* Return: 0 or standard error number
*
* Submit an exec buffer for execution. The BO handles in the wait
* list must complete execution before cmdBO is started. The BO
* handles in the wait list must have beeen submitted prior to this
* call to xclExecBufWithWaitList.
*/
XCL_DRIVER_DLLESPEC
int
xclExecBufWithWaitList(xclDeviceHandle handle, xclBufferHandle cmdBO,
size_t num_bo_in_wait_list, xclBufferHandle *bo_wait_list);
/**
* xclExecWait() - Wait for one or more execution events on the device
*
* @handle: Device handle
* @timeoutMilliSec: How long to wait for
* Return: Same code as poll system call
*
* Wait for notification from the hardware. The function essentially
* calls "poll" system call on the driver file handle. The return
* value has same semantics as poll system call. If return value is >
* 0 caller should check the status of submitted exec buffers Note
* that if you perform wait for the same handle from multiple threads,
* you may lose wakeup for some of them. So, use different handle in
* different threads.
*/
XCL_DRIVER_DLLESPEC
int
xclExecWait(xclDeviceHandle handle, int timeoutMilliSec);
/**
* xclRegisterInterruptNotify() - register *eventfd* file handle for a MSIX interrupt
*
* @handle: Device handle
* @userInterrupt: MSIX interrupt number
* @fd: Eventfd handle
* Return: 0 on success or standard errno
*
* Support for non managed interrupts (interrupts from custom IPs). fd
* should be obtained from eventfd system call. Caller should use
* standard poll/read eventfd framework in order to wait for
* interrupts. The handles are automatically unregistered on process
* exit.
*/
XCL_DRIVER_DLLESPEC
int
xclRegisterInterruptNotify(xclDeviceHandle handle, unsigned int userInterrupt,
int fd);
/* XRT Compute Unit Execution Management APIs */
/**
* DOC: XRT Stream Queue APIs
*
* These functions are used for next generation DMA Engine, QDMA. QDMA
* provides not only memory mapped DMA which moves data between host
* memory and board memory, but also stream DMA which moves data
* between host memory and kernel directly. XDMA memory mapped DMA
* APIs are also supported on QDMA. New stream APIs are provided here
* for preview and may be revised in a future release. These can only
* be used with platforms with QDMA engine under the hood. The higher
* level OpenCL based streaming APIs offer more refined interfaces and
* compatibility between releases and each stream maps to a QDMA queue
* underneath.
*/
enum xclStreamContextFlags {
/* Enum for xclQueueContext.flags */
XRT_QUEUE_FLAG_POLLING = (1 << 2),
};
/*
* struct xclQueueContext - structure to describe a Queue
*/
struct xclQueueContext {
uint32_t type; /* stream or packet Queue, read or write Queue*/
uint32_t state; /* initialized, running */
uint64_t route; /* route id from xclbin */
uint64_t flow; /* flow id from xclbin */
uint32_t qsize; /* number of descriptors */
uint32_t desc_size; /* this might imply max inline msg size */
uint64_t flags; /* isr en, wb en, etc */
};
/**
* xclCreateWriteQueue - Create Write Queue
*
* @handle: Device handle
* @q_ctx: Queue Context
* @q_hdl: Queue handle
* Return: 0 or appropriate error number
*
* Create write queue based on information provided in Queue
* context. Queue handle is generated if creation successes.
*/
XCL_DRIVER_DLLESPEC
int
xclCreateWriteQueue(xclDeviceHandle handle, struct xclQueueContext *q_ctx,
uint64_t *q_hdl);
/**
* xclCreateReadQueue - Create Read Queue
*
* @handle: Device handle