xref: /optee_os/core/include/drivers/versal_mbox.h (revision bc679ca5079e11f0f5a3cf1788fb2e5e4d861d14)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2022, Foundries.io Ltd
4  */
5 #ifndef __DRIVERS_VERSAL_MBOX_H
6 #define __DRIVERS_VERSAL_MBOX_H
7 
8 #include <kernel/mutex.h>
9 #include <platform_config.h>
10 #include <tee_api_types.h>
11 #include <util.h>
12 
13 #define VERSAL_MAX_IPI_BUF 7
14 #define VERSAL_MAX_IPI_DATA 8
15 
16 struct versal_mbox_mem {
17 	size_t alloc_len;
18 	size_t len;
19 	void *buf;
20 };
21 
22 struct versal_ipi_buf {
23 	struct versal_mbox_mem mem;
24 	bool only_cache;
25 };
26 
27 struct versal_ipi_cmd {
28 	uint32_t data[VERSAL_MAX_IPI_DATA];
29 	struct versal_ipi_buf ibuf[VERSAL_MAX_IPI_BUF];
30 
31 #ifdef CFG_VERSAL_OCP
32 	/* newer fields, used by versal_ipi_cmd_*() functions, only: */
33 
34 	/* number of valid entries in data[] */
35 	size_t data_count;
36 	/* number of valid entries in ibuf[] */
37 	size_t ibuf_count;
38 #endif
39 };
40 
41 /* IPI IDs */
42 #define VERSAL_IPI_ID_PMC	1
43 #define VERSAL_IPI_ID_0		2
44 #define VERSAL_IPI_ID_1		3
45 #define VERSAL_IPI_ID_2		4
46 #define VERSAL_IPI_ID_3		5
47 #define VERSAL_IPI_ID_4		6
48 #define VERSAL_IPI_ID_5		7
49 
50 struct versal_ipi {
51 	/* local and remote IPI ID */
52 	uint32_t lcl;
53 	uint32_t rmt;
54 
55 	/* Exclusive access to the IPI shared buffer */
56 	struct mutex lock;
57 
58 	vaddr_t regs;
59 
60 	void *rsp;
61 	void *req;
62 };
63 
64 TEE_Result versal_mbox_open(uint32_t local, uint32_t remote,
65 			    struct versal_ipi *ipi);
66 TEE_Result versal_mbox_close(struct versal_ipi *ipi);
67 
68 TEE_Result versal_mbox_notify(struct versal_ipi *ipi,
69 			      struct versal_ipi_cmd *cmd,
70 			      struct versal_ipi_cmd *rsp, uint32_t *err);
71 
72 TEE_Result versal_mbox_alloc(size_t len, const void *init,
73 			     struct versal_mbox_mem *mem);
74 void versal_mbox_free(struct versal_mbox_mem *mem);
75 #endif /* __DRIVERS_VERSAL_MBOX_H */
76