1 /*
2  * Copyright 2020-2021, NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_KEYMGR_H_
9 #define _FSL_KEYMGR_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup key_manager
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @name Driver version */
23 /*@{*/
24 /*! @brief Key Manager driver version. Version 2.0.2.
25  *
26  * Current version: 2.0.2
27  *
28  * Change log:
29  *
30  * - Version 2.0.2
31  *   - Fix MISRA-2012 issues
32  *
33  * - Version 2.0.1
34  *   - Fix MISRA-2012 issues
35  *
36  * - Version 2.0.0
37  *   - Initial version
38  */
39 #define FSL_KEYMGR_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
40 /*@}*/
41 
42 typedef enum _keymgr_lock
43 {
44     kKEYMGR_Unlock = 0u,
45     kKEYMGR_Lock   = 1u,
46 } keymgr_lock_t;
47 
48 typedef enum _keymgr_allow
49 {
50     kKEYMGR_Disallow = 0u,
51     kKEYMGR_Allow    = 1u,
52 } keymgr_allow_t;
53 
54 typedef enum _keymgr_slot
55 {
56     kKEYMGR_Slot0 = 0u,
57     kKEYMGR_Slot1 = 1u,
58     kKEYMGR_Slot2 = 2u,
59     kKEYMGR_Slot3 = 3u,
60     kKEYMGR_Slot4 = 4u,
61 } keymgr_slot_t;
62 
63 #define KEYMGR_IEE_RELOAD 1u
64 #define KEYMGR_SEL_OCOTP  0u
65 #define KEYMGR_SEL_UDF    0u
66 #define KEYMGR_SEL_PUF    1u
67 
68 #define keymgr_select_t uint8_t
69 
70 /*! @brief Key Manager slot configuration structure. */
71 typedef struct _domain_slot_config
72 {
73     keymgr_lock_t lockControl;     /*!< Lock control register of slot. */
74     keymgr_allow_t allowUser;      /*!< Allow user write access to domain control register or domain register. */
75     keymgr_allow_t allowNonSecure; /*!< Allow non-secure write access to domain control register or domain register. */
76     keymgr_lock_t lockList;        /*!< Lock whitelist. SLOTx_CTRL[WHITE_LIST] cannot be changed. */
77     uint8_t whiteList;             /*!< Domains that on the Whitelist can change given slot. */
78     /*!< Each field represents one domain. Bit0~Bit3 represent DOMAIN0~DOMAIN3 respectively. */
79 } domain_slot_config_t;
80 
81 /*******************************************************************************
82  * API
83  ******************************************************************************/
84 #if defined(__cplusplus)
85 extern "C" {
86 #endif
87 
88 /*!
89  * @brief Configures Master key settings.
90  *
91  * This function configures Key Manager's setting for Master key.
92  *
93  * @param base Key Manager peripheral address.
94  * @param select select source for Master key.
95  * @param lock setting for lock Master key.
96  * @return  status of Master key control operation
97  */
98 status_t KEYMGR_MasterKeyControll(KEY_MANAGER_Type *base, keymgr_select_t select, keymgr_lock_t lock);
99 
100 /*!
101  * @brief Configures OTFAD1 key settings.
102  *
103  * This function configures Key Manager's setting for OTFAD1 key.
104  *
105  * @param base Key Manager peripheral address.
106  * @param select select source for OTFAD1 key.
107  * @param lock setting for lock OTFAD1 key.
108  * @return  status of OTFAD1 key control operation
109  */
110 status_t KEYMGR_OTFAD1KeyControll(KEY_MANAGER_Type *base, keymgr_select_t select, keymgr_lock_t lock);
111 
112 /*!
113  * @brief Configures OTFAD2 key settings.
114  *
115  * This function configures Key Manager's setting for OTFAD2 key.
116  *
117  * @param base Key Manager peripheral address.
118  * @param select select source for OTFAD2 key.
119  * @param lock setting for lock OTFAD2 key.
120  * @return  status of OTFAD2 key control operation
121  */
122 status_t KEYMGR_OTFAD2KeyControll(KEY_MANAGER_Type *base, keymgr_select_t select, keymgr_lock_t lock);
123 
124 /*!
125  * @brief Restart load key signal for IEE.
126  *
127  * This function genrates Key Manager's restart signal for IEE key.
128  *
129  * @param base Key Manager peripheral address.
130  */
131 void KEYMGR_IEEKeyReload(KEY_MANAGER_Type *base);
132 
133 /*!
134  * @brief Lock the key select from PUF.
135  *
136  * This function locks selection of key for PUF.
137  *
138  * @param base Key Manager peripheral address.
139  * @param lock Setting for selection of key for PUF.
140  */
141 void KEYMGR_PUFKeyLock(KEY_MANAGER_Type *base, keymgr_lock_t lock);
142 
143 /*!
144  * @brief Configures Slot Domain control.
145  *
146  * This function configures domain slot control which locks and allows writes.
147  *
148  * @param base Key Manager peripheral address.
149  * @param config Pointer to slot configuration structure.
150  * @param slot Select slot to be configured.
151  * @return  status of slot control operation
152  */
153 status_t KEYMGR_SlotControl(KEY_MANAGER_Type *base, domain_slot_config_t *config, keymgr_slot_t slot);
154 
155 /*!
156  * @brief Resets Key Manager module to factory default values.
157  *
158  * This function performs hardware reset of Key Manager module.
159  *
160  * @param base Key Manager peripheral address.
161  */
162 void KEYMGR_Init(KEY_MANAGER_Type *base);
163 
164 /*!
165  * @brief Sets the default configuration of Key manager slot.
166  *
167  * This function initialize Key Manager slot config structure to default values.
168  *
169  * @param config Pointer to slot configuration structure.
170  */
171 status_t KEYMGR_GetDefaultConfig(domain_slot_config_t *config);
172 
173 #if defined(__cplusplus)
174 }
175 #endif
176 
177 /*!
178  *@}
179  */
180 
181 #endif /* _FSL_IEE_H_ */
182