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 target
32 
33 #ifndef COI_SERVER_H_INCLUDED
34 #define COI_SERVER_H_INCLUDED
35 
36 #include <common/COIEngine_common.h>
37 #include <common/COIPerf_common.h>
38 #include <sink/COIProcess_sink.h>
39 #include <sink/COIPipeline_sink.h>
40 #include <sink/COIBuffer_sink.h>
41 #include <list>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <unistd.h>
45 #include "../liboffload_error_codes.h"
46 
47 // wrappers for COI API
48 #define PipelineStartExecutingRunFunctions() \
49     { \
50         COIRESULT res = COIPipelineStartExecutingRunFunctions(); \
51         if (res != COI_SUCCESS) { \
52             LIBOFFLOAD_ERROR(c_pipeline_start_run_funcs, mic_index, res); \
53             exit(1); \
54         } \
55     }
56 
57 #define ProcessWaitForShutdown() \
58     { \
59         COIRESULT res = COIProcessWaitForShutdown(); \
60         if (res != COI_SUCCESS) { \
61             LIBOFFLOAD_ERROR(c_process_wait_shutdown, mic_index, res); \
62             exit(1); \
63         } \
64     }
65 
66 #define BufferAddRef(buf) \
67     { \
68         COIRESULT res = COIBufferAddRef(buf); \
69         if (res != COI_SUCCESS) { \
70             LIBOFFLOAD_ERROR(c_buf_add_ref, mic_index, res); \
71             exit(1); \
72         } \
73     }
74 
75 #define BufferReleaseRef(buf) \
76     { \
77         COIRESULT res = COIBufferReleaseRef(buf); \
78         if (res != COI_SUCCESS) { \
79             LIBOFFLOAD_ERROR(c_buf_release_ref, mic_index, res); \
80             exit(1); \
81         } \
82     }
83 
84 #define EngineGetIndex(index) \
85     { \
86         COI_ISA_TYPE isa_type; \
87         COIRESULT res = COIEngineGetIndex(&isa_type, index); \
88         if (res != COI_SUCCESS) { \
89             LIBOFFLOAD_ERROR(c_get_engine_index, mic_index, res); \
90             exit(1); \
91         } \
92     }
93 
94 #endif // COI_SERVER_H_INCLUDED
95