1/*
2    Copyright (c) 2014 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 betwen 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 <source/COIEngine_source.h>
38#include <source/COIProcess_source.h>
39#include <source/COIPipeline_source.h>
40#include <source/COIBuffer_source.h>
41#include <source/COIEvent_source.h>
42
43#include <string.h>
44
45#include "../liboffload_error_codes.h"
46#include "../offload_util.h"
47
48#define MIC_ENGINES_MAX     128
49
50#if MIC_ENGINES_MAX < COI_MAX_ISA_MIC_DEVICES
51#error MIC_ENGINES_MAX need to be increased
52#endif
53
54// COI library interface
55namespace COI {
56
57extern bool init(void);
58extern void fini(void);
59
60extern bool is_available;
61
62// pointers to functions from COI library
63extern COIRESULT (*EngineGetCount)(COI_ISA_TYPE, uint32_t*);
64extern COIRESULT (*EngineGetHandle)(COI_ISA_TYPE, uint32_t, COIENGINE*);
65
66extern COIRESULT (*ProcessCreateFromMemory)(COIENGINE, const char*,
67                                           const void*, uint64_t, int,
68                                           const char**, uint8_t,
69                                           const char**, uint8_t,
70                                           const char*, uint64_t,
71                                           const char*,
72                                           const char*, uint64_t,
73                                           COIPROCESS*);
74extern COIRESULT (*ProcessDestroy)(COIPROCESS, int32_t, uint8_t,
75                                  int8_t*, uint32_t*);
76extern COIRESULT (*ProcessGetFunctionHandles)(COIPROCESS, uint32_t,
77                                             const char**,
78                                             COIFUNCTION*);
79extern COIRESULT (*ProcessLoadLibraryFromMemory)(COIPROCESS,
80                                                const void*,
81                                                uint64_t,
82                                                const char*,
83                                                const char*,
84                                                const char*,
85                                                uint64_t,
86                                                uint32_t,
87                                                COILIBRARY*);
88extern COIRESULT (*ProcessRegisterLibraries)(uint32_t,
89                                            const void**,
90                                            const uint64_t*,
91                                            const char**,
92                                            const uint64_t*);
93
94extern COIRESULT (*PipelineCreate)(COIPROCESS, COI_CPU_MASK, uint32_t,
95                                  COIPIPELINE*);
96extern COIRESULT (*PipelineDestroy)(COIPIPELINE);
97extern COIRESULT (*PipelineRunFunction)(COIPIPELINE, COIFUNCTION,
98                                       uint32_t, const COIBUFFER*,
99                                       const COI_ACCESS_FLAGS*,
100                                       uint32_t, const COIEVENT*,
101                                       const void*, uint16_t, void*,
102                                       uint16_t, COIEVENT*);
103
104extern COIRESULT (*BufferCreate)(uint64_t, COI_BUFFER_TYPE, uint32_t,
105                                const void*, uint32_t,
106                                const COIPROCESS*, COIBUFFER*);
107extern COIRESULT (*BufferCreateFromMemory)(uint64_t, COI_BUFFER_TYPE,
108                                          uint32_t, void*,
109                                          uint32_t, const COIPROCESS*,
110                                          COIBUFFER*);
111extern COIRESULT (*BufferDestroy)(COIBUFFER);
112extern COIRESULT (*BufferMap)(COIBUFFER, uint64_t, uint64_t,
113                             COI_MAP_TYPE, uint32_t, const COIEVENT*,
114                             COIEVENT*, COIMAPINSTANCE*, void**);
115extern COIRESULT (*BufferUnmap)(COIMAPINSTANCE, uint32_t,
116                               const COIEVENT*, COIEVENT*);
117extern COIRESULT (*BufferWrite)(COIBUFFER, uint64_t, const void*,
118                               uint64_t, COI_COPY_TYPE, uint32_t,
119                               const COIEVENT*, COIEVENT*);
120extern COIRESULT (*BufferRead)(COIBUFFER, uint64_t, void*, uint64_t,
121                              COI_COPY_TYPE, uint32_t,
122                              const COIEVENT*, COIEVENT*);
123extern COIRESULT (*BufferCopy)(COIBUFFER, COIBUFFER, uint64_t, uint64_t,
124                              uint64_t, COI_COPY_TYPE, uint32_t,
125                              const COIEVENT*, COIEVENT*);
126extern COIRESULT (*BufferGetSinkAddress)(COIBUFFER, uint64_t*);
127extern COIRESULT (*BufferSetState)(COIBUFFER, COIPROCESS, COI_BUFFER_STATE,
128                                   COI_BUFFER_MOVE_FLAG, uint32_t,
129                                   const   COIEVENT*, COIEVENT*);
130
131extern COIRESULT (*EventWait)(uint16_t, const COIEVENT*, int32_t,
132                           uint8_t, uint32_t*, uint32_t*);
133
134extern uint64_t  (*PerfGetCycleFrequency)(void);
135
136} // namespace COI
137
138#endif // COI_CLIENT_H_INCLUDED
139