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