libocxl
setup.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017 International Business Machines
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "libocxl_internal.h"
18 #include <string.h>
19 #include <stdlib.h>
20 
29 #ifdef TEST_ENVIRONMENT
30 
37 __attribute__ ((used)) static void ocxl_set_sys_path(const char *path)
38 {
39  sys_path = path;
40 }
41 
49 __attribute__ ((used)) static void ocxl_set_dev_path(const char *path)
50 {
51  dev_path = path;
52 }
53 
54 #endif // TEST_ENVIRONMENT
55 
70 void ocxl_enable_messages(uint64_t sources)
71 {
72  verbose_errors = !!(sources & OCXL_ERRORS);
73  tracing = !!(sources & OCXL_TRACING);
74 }
75 
93 void ocxl_set_error_message_handler(void (*handler)(ocxl_err error, const char *message))
94 {
95  error_handler = handler;
96 }
97 
111 const char *ocxl_err_to_string(ocxl_err err)
112 {
113  switch (err) {
114  case OCXL_OK:
115  return "OK";
116 
117  case OCXL_NO_MEM:
118  return "No memory";
119 
120  case OCXL_NO_CONTEXT:
121  return "AFU context not available";
122 
123  case OCXL_NO_IRQ:
124  return "AFU interrupt not available";
125 
126  case OCXL_INTERNAL_ERROR:
127  return "Internal error";
128 
129  case OCXL_ALREADY_DONE:
130  return "Already done";
131 
132  case OCXL_OUT_OF_BOUNDS:
133  return "Out of bounds";
134 
136  return "No more contexts";
137 
138  case OCXL_INVALID_ARGS:
139  return "Invalid arguments";
140 
141  default:
142  return "Unknown error";
143  }
144 }
145 
const char * ocxl_err_to_string(ocxl_err err)
Convert an error value to a string.
Definition: setup.c:111
ocxl_err
Potential return values from ocxl_* functions.
Definition: libocxl.h:84
void ocxl_set_error_message_handler(void(*handler)(ocxl_err error, const char *message))
Override the default handler for emitting error messages from open calls.
Definition: setup.c:93
The action requested falls outside the permitted area.
Definition: libocxl.h:92
The call requires an open context on the AFU.
Definition: libocxl.h:88
#define OCXL_ERRORS
Error messages requested.
Definition: libocxl.h:32
One or more arguments are invalid.
Definition: libocxl.h:94
an internal error has occurred
Definition: libocxl.h:90
void ocxl_enable_messages(uint64_t sources)
Enable messages from libocxl open calls.
Definition: setup.c:70
no further interrupts are available, or the interrupt is invalid
Definition: libocxl.h:89
An out of memory error occurred.
Definition: libocxl.h:86
#define OCXL_TRACING
Tracing requested.
Definition: libocxl.h:33
No more contexts can be opened on the AFU.
Definition: libocxl.h:93
The action requested has already been performed.
Definition: libocxl.h:91
The call succeeded.
Definition: libocxl.h:85