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