1 /*
2  * Copyright (c) 2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef MHU_H
8 #define MHU_H
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 /**
14  * Generic MHU error enumeration types.
15  */
16 enum mhu_error_t {
17 	MHU_ERR_NONE			=  0,
18 	MHU_ERR_NOT_INIT		= -1,
19 	MHU_ERR_ALREADY_INIT		= -2,
20 	MHU_ERR_UNSUPPORTED_VERSION	= -3,
21 	MHU_ERR_UNSUPPORTED		= -4,
22 	MHU_ERR_INVALID_ARG		= -5,
23 	MHU_ERR_BUFFER_TOO_SMALL	= -6,
24 	MHU_ERR_GENERAL			= -7,
25 };
26 
27 /**
28  * Initializes sender MHU.
29  *
30  * mhu_sender_base	Base address of sender MHU.
31  *
32  * Returns mhu_error_t error code.
33  *
34  * This function must be called before mhu_send_data().
35  */
36 enum mhu_error_t mhu_init_sender(uintptr_t mhu_sender_base);
37 
38 
39 /**
40  * Initializes receiver MHU.
41  *
42  * mhu_receiver_base	Base address of receiver MHU.
43  *
44  * Returns mhu_error_t error code.
45  *
46  * This function must be called before mhu_receive_data().
47  */
48 enum mhu_error_t mhu_init_receiver(uintptr_t mhu_receiver_base);
49 
50 /**
51  * Sends data over MHU.
52  *
53  * send_buffer		Pointer to buffer containing the data to be transmitted.
54  * size			Size of the data to be transmitted in bytes.
55  *
56  * Returns mhu_error_t error code.
57  *
58  * The send_buffer must be 4-byte aligned and its length must be at least
59  * (4 - (size % 4)) bytes bigger than the data size to prevent buffer
60  * over-reading.
61  */
62 enum mhu_error_t mhu_send_data(const uint8_t *send_buffer, size_t size);
63 
64 /**
65  * Receives data from MHU.
66  *
67  * receive_buffer	Pointer the buffer where to store the received data.
68  * size			As input the size of the receive_buffer, as output the
69  *			number of bytes received. As a limitation,
70  *			the size of the buffer must be a multiple of 4.
71  *
72  * Returns mhu_error_t error code.
73  *
74  * The receive_buffer must be 4-byte aligned and its length must be a
75  * multiple of 4.
76  */
77 enum mhu_error_t mhu_receive_data(uint8_t *receive_buffer, size_t *size);
78 
79 /**
80  * Gets the maximum amount of bytes that can be transmitted in a single send by MHU.
81  *
82  * Returns The amount of bytes that can be sent or received in a single message.
83  */
84 size_t mhu_get_max_message_size(void);
85 
86 #endif /* MHU_H */
87