1 /* 2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions 6 are met: 7 8 * Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 * Neither the name of Intel Corporation nor the names of its 14 contributors may be used to endorse or promote products derived 15 from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 31 // The interface between offload library and the COI API on the host 32 33 #ifndef COI_CLIENT_H_INCLUDED 34 #define COI_CLIENT_H_INCLUDED 35 36 #include <common/COIPerf_common.h> 37 #include <common/COIMacros_common.h> 38 #include <source/COIEngine_source.h> 39 #include <source/COIProcess_source.h> 40 #include <source/COIPipeline_source.h> 41 #include <source/COIBuffer_source.h> 42 #include <source/COIEvent_source.h> 43 44 #include <string.h> 45 46 #include "../liboffload_error_codes.h" 47 #include "../offload_util.h" 48 49 #define MIC_ENGINES_MAX 128 50 51 #if MIC_ENGINES_MAX < COI_MAX_ISA_MIC_DEVICES 52 #error MIC_ENGINES_MAX need to be increased 53 #endif 54 55 // COI library interface 56 namespace COI { 57 58 DLL_LOCAL extern bool init(void); 59 DLL_LOCAL extern void fini(void); 60 61 DLL_LOCAL extern bool is_available; 62 63 // pointers to functions from COI library 64 DLL_LOCAL extern COIRESULT (*EngineGetCount)(COI_ISA_TYPE, uint32_t*); 65 DLL_LOCAL extern COIRESULT (*EngineGetHandle)(COI_ISA_TYPE, uint32_t, COIENGINE*); 66 67 DLL_LOCAL extern COIRESULT (*ProcessCreateFromMemory)(COIENGINE, const char*, 68 const void*, uint64_t, int, 69 const char**, uint8_t, 70 const char**, uint8_t, 71 const char*, uint64_t, 72 const char*, 73 const char*, uint64_t, 74 COIPROCESS*); 75 DLL_LOCAL extern COIRESULT (*ProcessCreateFromFile)(COIENGINE, const char*, int, 76 const char**, uint8_t, 77 const char**, 78 uint8_t, 79 const char*, 80 uint64_t, 81 const char*, 82 COIPROCESS*); 83 DLL_LOCAL extern COIRESULT (*ProcessSetCacheSize)(COIPROCESS, uint64_t, uint32_t, 84 uint64_t, uint32_t, uint32_t, 85 const COIEVENT*, COIEVENT*); 86 DLL_LOCAL extern COIRESULT (*ProcessDestroy)(COIPROCESS, int32_t, uint8_t, 87 int8_t*, uint32_t*); 88 DLL_LOCAL extern COIRESULT (*ProcessGetFunctionHandles)(COIPROCESS, uint32_t, 89 const char**, 90 COIFUNCTION*); 91 DLL_LOCAL extern COIRESULT (*ProcessLoadLibraryFromMemory)(COIPROCESS, 92 const void*, 93 uint64_t, 94 const char*, 95 const char*, 96 const char*, 97 uint64_t, 98 uint32_t, 99 COILIBRARY*); 100 101 DLL_LOCAL extern COIRESULT (*ProcessUnloadLibrary)(COIPROCESS, 102 COILIBRARY); 103 104 DLL_LOCAL extern COIRESULT (*ProcessRegisterLibraries)(uint32_t, 105 const void**, 106 const uint64_t*, 107 const char**, 108 const uint64_t*); 109 110 DLL_LOCAL extern COIRESULT (*PipelineCreate)(COIPROCESS, COI_CPU_MASK, uint32_t, 111 COIPIPELINE*); 112 DLL_LOCAL extern COIRESULT (*PipelineDestroy)(COIPIPELINE); 113 DLL_LOCAL extern COIRESULT (*PipelineRunFunction)(COIPIPELINE, COIFUNCTION, 114 uint32_t, const COIBUFFER*, 115 const COI_ACCESS_FLAGS*, 116 uint32_t, const COIEVENT*, 117 const void*, uint16_t, void*, 118 uint16_t, COIEVENT*); 119 120 DLL_LOCAL extern COIRESULT (*BufferCreate)(uint64_t, COI_BUFFER_TYPE, uint32_t, 121 const void*, uint32_t, 122 const COIPROCESS*, COIBUFFER*); 123 DLL_LOCAL extern COIRESULT (*BufferCreateFromMemory)(uint64_t, COI_BUFFER_TYPE, 124 uint32_t, void*, 125 uint32_t, const COIPROCESS*, 126 COIBUFFER*); 127 DLL_LOCAL extern COIRESULT (*BufferDestroy)(COIBUFFER); 128 DLL_LOCAL extern COIRESULT (*BufferMap)(COIBUFFER, uint64_t, uint64_t, 129 COI_MAP_TYPE, uint32_t, const COIEVENT*, 130 COIEVENT*, COIMAPINSTANCE*, void**); 131 DLL_LOCAL extern COIRESULT (*BufferUnmap)(COIMAPINSTANCE, uint32_t, 132 const COIEVENT*, COIEVENT*); 133 DLL_LOCAL extern COIRESULT (*BufferWrite)(COIBUFFER, uint64_t, const void*, 134 uint64_t, COI_COPY_TYPE, uint32_t, 135 const COIEVENT*, COIEVENT*); 136 DLL_LOCAL extern COIRESULT (*BufferRead)(COIBUFFER, uint64_t, void*, uint64_t, 137 COI_COPY_TYPE, uint32_t, 138 const COIEVENT*, COIEVENT*); 139 DLL_LOCAL extern COIRESULT (*BufferReadMultiD)(COIBUFFER, uint64_t, 140 void *, void *, COI_COPY_TYPE, 141 uint32_t, const COIEVENT*, COIEVENT*); 142 DLL_LOCAL extern COIRESULT (*BufferWriteMultiD)(COIBUFFER, const COIPROCESS, 143 uint64_t, void *, void *, 144 COI_COPY_TYPE, uint32_t, const COIEVENT*, COIEVENT*); 145 146 DLL_LOCAL extern COIRESULT (*BufferCopy)(COIBUFFER, COIBUFFER, uint64_t, uint64_t, 147 uint64_t, COI_COPY_TYPE, uint32_t, 148 const COIEVENT*, COIEVENT*); 149 DLL_LOCAL extern COIRESULT (*BufferGetSinkAddress)(COIBUFFER, uint64_t*); 150 DLL_LOCAL extern COIRESULT (*BufferSetState)(COIBUFFER, COIPROCESS, COI_BUFFER_STATE, 151 COI_BUFFER_MOVE_FLAG, uint32_t, 152 const COIEVENT*, COIEVENT*); 153 154 DLL_LOCAL extern COIRESULT (*EventWait)(uint16_t, const COIEVENT*, int32_t, 155 uint8_t, uint32_t*, uint32_t*); 156 157 DLL_LOCAL extern uint64_t (*PerfGetCycleFrequency)(void); 158 159 DLL_LOCAL extern COIRESULT (*ProcessConfigureDMA)(const uint64_t, const int); 160 161 extern COIRESULT (*PipelineClearCPUMask)(COI_CPU_MASK); 162 163 extern COIRESULT (*PipelineSetCPUMask)(COIPROCESS, uint32_t, 164 uint8_t, COI_CPU_MASK); 165 extern COIRESULT (*EngineGetInfo)(COIENGINE, uint32_t, COI_ENGINE_INFO*); 166 167 extern COIRESULT (*EventRegisterCallback)( 168 const COIEVENT, 169 void (*)(COIEVENT, const COIRESULT, const void*), 170 const void*, 171 const uint64_t); 172 173 const int DMA_MODE_READ_WRITE = 1; 174 } // namespace COI 175 176 #endif // COI_CLIENT_H_INCLUDED 177