ACU6 Device API
ipc.h
Go to the documentation of this file.
1 /* Copyright (C) 2019 Actia Nordic AB. All rights reserved. */
3 #ifndef LIBS_ACTIA_INCLUDE_IPC_H_
4 #define LIBS_ACTIA_INCLUDE_IPC_H_
5 
6 #include <malloc.h>
7 #include <stdbool.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
22 #define A_IPC_MAGIC 0xA1FC600D
23 #define A_IPC_LEGACY_MSG_BUF_SIZE 512
24 
31 struct a_ipc_buffers {
32  /* Outbox storage buffer.
33  * Contains messages from the user.
34  *
35  * The _outbox_buffer pointer must be 8 byte aligned
36  */
37  uint8_t *_outbox_buffer;
38  size_t _outbox_size;
39 
40  /* Inbox storage buffer.
41  * Contains messages to the user.
42  *
43  * The _inbox_buffer pointer must be 8 byte aligned
44  */
45  uint8_t *_inbox_buffer;
46  size_t _inbox_size;
47 };
48 
56 #define A_IPC_ALLOC_MSG_BUFFER(name, size, modifiers) \
57  modifiers union { \
58  a_ipc_msg msg; \
59  uint8_t buf[(size)]; /* NOLINT(runtime/arrays) */ \
60  } name##_buf __attribute__((aligned(8))) = { .msg = { .info = { \
61  ._magic = A_IPC_MAGIC, \
62  .msg_alloc_size = (size), \
63  } } }; \
64  modifiers a_ipc_msg *name = &name##_buf.msg
65 
83 #define A_IPC_MSG_ON_STACK(name, size) A_IPC_ALLOC_MSG_BUFFER(name, (size), )
84 
102 #define A_IPC_STATIC_MSG(name, size) A_IPC_ALLOC_MSG_BUFFER(name, (size), static)
103 
125 #define A_IPC_STATIC_BUFFERS(name, inbox_size, outbox_size) \
126  A_IPC_STATIC_BUFFERS_BYTES( \
127  name, ((inbox_size)*A_IPC_LEGACY_MSG_BUF_SIZE), ((outbox_size)*A_IPC_LEGACY_MSG_BUF_SIZE))
128 
147 #define A_IPC_STATIC_BUFFERS_BYTES(name, inbox_size, outbox_size) \
148  static uint8_t name##_outbox[(outbox_size)] __attribute__((aligned(8))); \
149  static uint8_t name##_inbox[(inbox_size)] __attribute__((aligned(8))); \
150  static a_ipc_buffers name = { ._outbox_buffer = name##_outbox, \
151  ._outbox_size = (outbox_size), \
152  ._inbox_buffer = name##_inbox, \
153  ._inbox_size = (inbox_size) }
154 
176 #define A_IPC_ALLOCATE_BUFFERS(name, inbox_size, outbox_size) \
177  A_IPC_ALLOCATE_BUFFERS_BYTES( \
178  name, ((inbox_size)*A_IPC_LEGACY_MSG_BUF_SIZE), ((outbox_size)*A_IPC_LEGACY_MSG_BUF_SIZE))
179 
198 #define A_IPC_ALLOCATE_BUFFERS_BYTES(name, inbox_size, outbox_size) \
199  a_ipc_buffers *name = (a_ipc_buffers *)malloc(sizeof(a_ipc_buffers)); \
200  if (name != NULL) { \
201  name->_outbox_size = outbox_size; \
202  name->_inbox_size = inbox_size; \
203  name->_inbox_buffer = (uint8_t *)memalign(8, name->_inbox_size); \
204  name->_outbox_buffer = (uint8_t *)memalign(8, name->_outbox_size); \
205  }
206 
211 typedef enum {
236 } A_IPC_RESULT;
237 
239 #define A_IPC_MAX_ID 30000
242 /* Host IDs */
244 #define A_IPC_HOST_MIN_ID 0
245 #define A_IPC_HOST_MAX_ID 14500
248 /* Guest IDs */
253 #define A_IPC_GUEST_MIN_ID 14501
258 #define A_IPC_GUEST_MAX_ID 30000
259 
264 typedef struct a_ipc_buffers a_ipc_buffers;
265 
270 typedef struct a_ipc_handle a_ipc_handle;
271 
276 typedef struct a_ipc_msg a_ipc_msg;
277 
282 typedef struct {
286  uint32_t _magic;
289  int type;
295 
315 
336 a_ipc_handle *a_ipc_init_ex(int id, a_ipc_buffers *buffers, unsigned int outstanding_window);
337 
347 
356 
367 
383 
403 A_IPC_RESULT a_ipc_recv(a_ipc_handle *handle, int *from, a_ipc_msg *msg);
404 
443 A_IPC_RESULT a_ipc_set_filter(a_ipc_handle *handle, int *from, int *msg_type, int *error_msg_type);
456 
465 const char *a_ipc_msg_type_str(int msg_type);
466 
475 const char *a_ipc_result_str(A_IPC_RESULT result);
476 
488 
489 #ifdef __cplusplus
490 }
491 #endif
492 
493 #endif // LIBS_ACTIA_INCLUDE_IPC_H_
int a_ipc_dump_stats(a_ipc_handle *handle)
Outputs information to the log about the current IPC instance.
size_t msg_used_size
How much of the message that is used - including struct members.
Definition: ipc.h:293
int type
The message type, as given by the user-provided IPC IDs file.
Definition: ipc.h:289
int a_ipc_get_fd(a_ipc_handle *handle)
Get file descriptor for selecting/polling for new messages.
A_IPC_RESULT a_ipc_send(a_ipc_handle *handle, int to, a_ipc_msg *msg)
Send an IPC message.
a_ipc_handle * a_ipc_init_ex(int id, a_ipc_buffers *buffers, unsigned int outstanding_window)
Initialize AIPC and make application available to other IPC applications.
const char * a_ipc_result_str(A_IPC_RESULT result)
Get the string representation for the given result value.
A_IPC_RESULT a_ipc_recv(a_ipc_handle *handle, int *from, a_ipc_msg *msg)
Receive an IPC message.
a_ipc_handle * a_ipc_init(int id, a_ipc_buffers *buffers)
Initialize AIPC and make application available to other IPC applications.
struct a_ipc_handle a_ipc_handle
Handle to an IPC instance.
Definition: ipc.h:270
void a_ipc_free_buffers(a_ipc_buffers *buffers)
Free the memory of a dynamically alloctated ipc inbox/outbox buffers struct.
void a_ipc_destroy(a_ipc_handle *handle)
Destroy AIPC.
size_t msg_alloc_size
Total message size - including struct members.
Definition: ipc.h:291
A_IPC_RESULT a_ipc_copy_message(a_ipc_msg *dst, const a_ipc_msg *src)
Copy an IPC message.
const char * a_ipc_msg_type_str(int msg_type)
Get the string representation (enum constant) for the given msg_type.
struct a_ipc_buffers a_ipc_buffers
Handle to a struct containing IPC inbox/outbox buffers.
Definition: ipc.h:264
A_IPC_RESULT
IPC function result codes.
Definition: ipc.h:211
@ A_IPC_RET_OK
Operation succeeded.
Definition: ipc.h:213
@ A_IPC_RET_OUT_OF_MEMORY
Not enough memory (allocated) to perform the request action.
Definition: ipc.h:231
@ A_IPC_RET_INVALID_ARGUMENT
Invalid arguments given.
Definition: ipc.h:233
@ A_IPC_RET_SEND_ERROR
Error when signaling message to be sent.
Definition: ipc.h:223
@ A_IPC_RET_MALFORMED_PACKET
Malformed packet in transport layer.
Definition: ipc.h:227
@ A_IPC_RET_NO_MSG
No message found/received.
Definition: ipc.h:221
@ A_IPC_RET_NOT_IMPLEMENTED
Functionality not implemented.
Definition: ipc.h:229
@ A_IPC_RET_BAD_TYPE
The message type is not known.
Definition: ipc.h:219
@ A_IPC_RET_ERROR
Unspecified error.
Definition: ipc.h:215
@ A_IPC_RET_BUFFER_TOO_SMALL
The provided buffer is too small.
Definition: ipc.h:217
@ A_IPC_RET_OUTBOX_FULL
Outbox full.
Definition: ipc.h:235
@ A_IPC_RET_TIMEOUT
Timeout while waiting.
Definition: ipc.h:225
IPC message basic info.
Definition: ipc.h:282
AIPC Message.
Definition: ipc_generated.h:1204