1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2020-2022 NXP
4  */
5 #ifndef __DRIVERS_IMX_MU_H
6 #define __DRIVERS_IMX_MU_H
7 
8 #include <tee_api_types.h>
9 #include <types_ext.h>
10 #include <util.h>
11 
12 #define IMX_MU_DATA_U32(mesg, idx) ((mesg)->data.u32[(idx)])
13 #define IMX_MU_DATA_U16(mesg, idx) ((mesg)->data.u16[(idx)])
14 #define IMX_MU_DATA_U8(mesg, idx)  ((mesg)->data.u8[(idx)])
15 
16 #define IMX_MU_MSG_SIZE	  7
17 #define IMX_MU_NB_CHANNEL 4
18 
19 #if defined(CFG_MX8ULP)
20 struct imx_mu_msg_header {
21 	uint8_t version;
22 	uint8_t size;
23 	uint8_t command;
24 	uint8_t tag;
25 };
26 #elif defined(CFG_MX8QM) || defined(CFG_MX8QX) || defined(CFG_MX8DXL)
27 struct imx_mu_msg_header {
28 	uint8_t version;
29 	uint8_t size;
30 	uint8_t tag;
31 	uint8_t command;
32 };
33 #else
34 #error "Platform not supported"
35 #endif
36 
37 /*
38  * i.MX MU message format
39  * Note: the header format differs depending of the platform.
40  */
41 struct imx_mu_msg {
42 	struct imx_mu_msg_header header;
43 	union {
44 		uint32_t u32[IMX_MU_MSG_SIZE];
45 		uint16_t u16[IMX_MU_MSG_SIZE * 2];
46 		uint8_t u8[IMX_MU_MSG_SIZE * 4];
47 	} data;
48 };
49 
50 /*
51  * Initialize the MU interface
52  *
53  * @base: virtual base address of the MU controller
54  */
55 void imx_mu_init(vaddr_t base);
56 
57 /*
58  * Initiate a communication with the external controller. It sends a message
59  * and return the answer of the controller.
60  *
61  * @base: virtual base address of the MU controller
62  * @[in/out]msg: message sent and received
63  * @wait_for_answer: true if an answer from the controller is expected, false
64  * otherwise
65  */
66 TEE_Result imx_mu_call(vaddr_t base, struct imx_mu_msg *msg,
67 		       bool wait_for_answer);
68 #endif /* __DRIVERS_IMX_MU_H */
69