xref: /optee_os/core/drivers/crypto/caam/include/caam_hal_sm.h (revision b7815eeda2ffa172aee1349aeec9ba746bc8082c)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2019, 2023 NXP
4  */
5 #ifndef __CAAM_HAL_SM_H__
6 #define __CAAM_HAL_SM_H__
7 
8 #include <caam_sm.h>
9 #include <stdint.h>
10 
11 /*
12  * Checks if @page and @partition number are valid
13  *
14  * @jr_base       JR base address
15  * @sm_page_desc  Secure Memory page
16  */
17 enum caam_status
18 caam_hal_sm_check_page_partition(vaddr_t jr_base,
19 				 const struct caam_sm_page_desc *sm_page_desc);
20 
21 /*
22  * Return the Pages Size in KBytes
23  *
24  * @jr_base    JR base address
25  * @page       Page number
26  */
27 size_t caam_hal_sm_get_pages_size(vaddr_t jr_base, unsigned int page);
28 
29 /*
30  * Return if the partition is free (available)
31  *
32  * @jr_base    JR base address
33  * @partition  Partition number
34  */
35 bool caam_hal_sm_prtn_is_free(vaddr_t jr_base, unsigned int partition);
36 
37 /*
38  * Return if the partition is owned (by the HW register reader)
39  *
40  * @jr_base    JR base address
41  * @partition  Partition number
42  */
43 bool caam_hal_sm_prtn_is_owned(vaddr_t jr_base, unsigned int partition);
44 
45 /*
46  * Set the Secure Memory access to all groups
47  *
48  * @jr_base    JR base address
49  * @partition  Partition number
50  * @grp1       Group 1 value
51  * @grp2       Group 2 value
52  */
53 void caam_hal_sm_set_access_all_group(vaddr_t jr_base, unsigned int partition);
54 
55 /*
56  * Set the Secure Memory access to group 1 and/or group 2
57  *
58  * @jr_base    JR base address
59  * @partition  Partition number
60  * @grp1       Group 1 value
61  * @grp2       Group 2 value
62  */
63 void caam_hal_sm_set_access_group(vaddr_t jr_base, unsigned int partition,
64 				  uint32_t grp1, uint32_t grp2);
65 
66 /*
67  * Open all Secure Memory Permissions
68  *
69  * @jr_base    JR base address
70  * @partition  Partition number
71  */
72 void caam_hal_sm_open_access_perm(vaddr_t jr_base, unsigned int partition);
73 
74 /*
75  * Set the Secure Memory access permission for group 1 and group 2.
76  * Enable Critical Security and lock configuration
77  *
78  * @jr_base    JR base address
79  * @partition  Partition number
80  * @grp1_perm  Group 1 Permissions
81  * @grp2_perm  Group 2 Permissions
82  */
83 void caam_hal_sm_set_access_perm(vaddr_t jr_base, unsigned int partition,
84 				 unsigned int grp1_perm,
85 				 unsigned int grp2_perm);
86 
87 /*
88  * Allocate a @page to the @partition.
89  *
90  * @jr_base  JR base address
91  * @sm_page_desc  Secure Memory page
92  */
93 enum caam_status
94 caam_hal_sm_allocate_page(vaddr_t jr_base,
95 			  const struct caam_sm_page_desc *sm_page_desc);
96 
97 /*
98  * De-allocate a @partition and all partition's page.
99  *
100  * @jr_base    JR base address
101  * @partition  Partition number
102  */
103 enum caam_status caam_hal_sm_deallocate_partition(vaddr_t jr_base,
104 						  unsigned int partition);
105 
106 /*
107  * De-allocate all pages specified in the @sm struct
108  *
109  * @jr_base  JR base address
110  * @sm_page_desc  Secure Memory page
111  */
112 enum caam_status
113 caam_hal_sm_deallocate_pages(vaddr_t jr_base,
114 			     const struct caam_sm_page_desc *sm_page_desc);
115 
116 /* Return the virtual base address of the Secure Memory registers */
117 vaddr_t caam_hal_sm_get_base(void);
118 
119 #ifdef CFG_DT
120 void caam_hal_sm_get_base_dt(void *fdt, vaddr_t *sm_base);
121 #else
caam_hal_sm_get_base_dt(void * fdt __unused,vaddr_t * sm_base)122 static inline void caam_hal_sm_get_base_dt(void *fdt __unused, vaddr_t *sm_base)
123 {
124 	*sm_base = 0;
125 }
126 #endif /* CFG_DT */
127 #endif /* __CAAM_HAL_SM_H__ */
128