• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 
9 #ifndef HPM_RNG_H
10 #define HPM_RNG_H
11 
12 typedef struct {
13     __RW uint32_t CMD;                         /* 0x0: Command Register */
14     __RW uint32_t CTRL;                        /* 0x4: Control Register */
15     __R  uint32_t STA;                         /* 0x8: Status Register */
16     __R  uint32_t ERR;                         /* 0xC: Error Registers */
17     __R  uint32_t FO2B;                        /* 0x10: FIFO out to bus/cpu */
18     __R  uint8_t  RESERVED0[12];               /* 0x14 - 0x1F: Reserved */
19     __R  uint32_t R2SK[8];                     /* 0x20 - 0x3C: FIFO out to SDP as AES engine key */
20 } RNG_Type;
21 
22 
23 /* Bitfield definition for register: CMD */
24 /*
25  * SFTRST (RW)
26  *
27  * Soft Reset, Perform a software reset of the RNG This bit is self-clearing.
28  * 0 Do not perform a software reset.
29  * 1 Software reset
30  */
31 #define RNG_CMD_SFTRST_MASK (0x40U)
32 #define RNG_CMD_SFTRST_SHIFT (6U)
33 #define RNG_CMD_SFTRST_SET(x) (((uint32_t)(x) << RNG_CMD_SFTRST_SHIFT) & RNG_CMD_SFTRST_MASK)
34 #define RNG_CMD_SFTRST_GET(x) (((uint32_t)(x) & RNG_CMD_SFTRST_MASK) >> RNG_CMD_SFTRST_SHIFT)
35 
36 /*
37  * CLRERR (RW)
38  *
39  * Clear the Error, clear the errors in the ESR register and the RNG interrupt. This bit is self-clearing.
40  * 0 Do not clear the errors and the interrupt.
41  * 1 Clear the errors and the interrupt.
42  */
43 #define RNG_CMD_CLRERR_MASK (0x20U)
44 #define RNG_CMD_CLRERR_SHIFT (5U)
45 #define RNG_CMD_CLRERR_SET(x) (((uint32_t)(x) << RNG_CMD_CLRERR_SHIFT) & RNG_CMD_CLRERR_MASK)
46 #define RNG_CMD_CLRERR_GET(x) (((uint32_t)(x) & RNG_CMD_CLRERR_MASK) >> RNG_CMD_CLRERR_SHIFT)
47 
48 /*
49  * CLRINT (RW)
50  *
51  * Clear the Interrupt, clear the RNG interrupt if an error is not present. This bit is self-clearing.
52  * 0 Do not clear the interrupt.
53  * 1 Clear the interrupt
54  */
55 #define RNG_CMD_CLRINT_MASK (0x10U)
56 #define RNG_CMD_CLRINT_SHIFT (4U)
57 #define RNG_CMD_CLRINT_SET(x) (((uint32_t)(x) << RNG_CMD_CLRINT_SHIFT) & RNG_CMD_CLRINT_MASK)
58 #define RNG_CMD_CLRINT_GET(x) (((uint32_t)(x) & RNG_CMD_CLRINT_MASK) >> RNG_CMD_CLRINT_SHIFT)
59 
60 /*
61  * GENSD (RW)
62  *
63  * Generate Seed, when both ST and GS triggered, ST first and GS next.
64  */
65 #define RNG_CMD_GENSD_MASK (0x2U)
66 #define RNG_CMD_GENSD_SHIFT (1U)
67 #define RNG_CMD_GENSD_SET(x) (((uint32_t)(x) << RNG_CMD_GENSD_SHIFT) & RNG_CMD_GENSD_MASK)
68 #define RNG_CMD_GENSD_GET(x) (((uint32_t)(x) & RNG_CMD_GENSD_MASK) >> RNG_CMD_GENSD_SHIFT)
69 
70 /*
71  * SLFCHK (RW)
72  *
73  * Self Test, when both ST and GS triggered, ST first and GS next.
74  */
75 #define RNG_CMD_SLFCHK_MASK (0x1U)
76 #define RNG_CMD_SLFCHK_SHIFT (0U)
77 #define RNG_CMD_SLFCHK_SET(x) (((uint32_t)(x) << RNG_CMD_SLFCHK_SHIFT) & RNG_CMD_SLFCHK_MASK)
78 #define RNG_CMD_SLFCHK_GET(x) (((uint32_t)(x) & RNG_CMD_SLFCHK_MASK) >> RNG_CMD_SLFCHK_SHIFT)
79 
80 /* Bitfield definition for register: CTRL */
81 /*
82  * MIRQERR (RW)
83  *
84  * Mask Interrupt Request for Error
85  */
86 #define RNG_CTRL_MIRQERR_MASK (0x40U)
87 #define RNG_CTRL_MIRQERR_SHIFT (6U)
88 #define RNG_CTRL_MIRQERR_SET(x) (((uint32_t)(x) << RNG_CTRL_MIRQERR_SHIFT) & RNG_CTRL_MIRQERR_MASK)
89 #define RNG_CTRL_MIRQERR_GET(x) (((uint32_t)(x) & RNG_CTRL_MIRQERR_MASK) >> RNG_CTRL_MIRQERR_SHIFT)
90 
91 /*
92  * MIRQDN (RW)
93  *
94  * Mask Interrupt Request for Done Event, asks the interrupts generated upon the completion of the seed and self-test modes. The status of these jobs can be viewed by:
95  * • Reading the STA and viewing the seed done and the self-test done bits (STA[SDN, STDN]).
96  * • Viewing the RNG_CMD for the generate-seed or the self-test bits (CMD[GS,ST]) being set, indicating that the operation is still taking place.
97  */
98 #define RNG_CTRL_MIRQDN_MASK (0x20U)
99 #define RNG_CTRL_MIRQDN_SHIFT (5U)
100 #define RNG_CTRL_MIRQDN_SET(x) (((uint32_t)(x) << RNG_CTRL_MIRQDN_SHIFT) & RNG_CTRL_MIRQDN_MASK)
101 #define RNG_CTRL_MIRQDN_GET(x) (((uint32_t)(x) & RNG_CTRL_MIRQDN_MASK) >> RNG_CTRL_MIRQDN_SHIFT)
102 
103 /*
104  * AUTRSD (RW)
105  *
106  * Auto Reseed
107  */
108 #define RNG_CTRL_AUTRSD_MASK (0x10U)
109 #define RNG_CTRL_AUTRSD_SHIFT (4U)
110 #define RNG_CTRL_AUTRSD_SET(x) (((uint32_t)(x) << RNG_CTRL_AUTRSD_SHIFT) & RNG_CTRL_AUTRSD_MASK)
111 #define RNG_CTRL_AUTRSD_GET(x) (((uint32_t)(x) & RNG_CTRL_AUTRSD_MASK) >> RNG_CTRL_AUTRSD_SHIFT)
112 
113 /*
114  * FUFMOD (RW)
115  *
116  * FIFO underflow response mode
117  * 00 Return all zeros and set the ESR[FUFE].
118  * 01 Return all zeros and set the ESR[FUFE].
119  * 10 Generate the bus transfer error
120  * 11 Generate the interrupt and return all zeros (overrides the CTRL[MASKERR]).
121  */
122 #define RNG_CTRL_FUFMOD_MASK (0x3U)
123 #define RNG_CTRL_FUFMOD_SHIFT (0U)
124 #define RNG_CTRL_FUFMOD_SET(x) (((uint32_t)(x) << RNG_CTRL_FUFMOD_SHIFT) & RNG_CTRL_FUFMOD_MASK)
125 #define RNG_CTRL_FUFMOD_GET(x) (((uint32_t)(x) & RNG_CTRL_FUFMOD_MASK) >> RNG_CTRL_FUFMOD_SHIFT)
126 
127 /* Bitfield definition for register: STA */
128 /*
129  * SCPF (RO)
130  *
131  * Self Check Pass Fail
132  */
133 #define RNG_STA_SCPF_MASK (0xE00000UL)
134 #define RNG_STA_SCPF_SHIFT (21U)
135 #define RNG_STA_SCPF_GET(x) (((uint32_t)(x) & RNG_STA_SCPF_MASK) >> RNG_STA_SCPF_SHIFT)
136 
137 /*
138  * FUNCERR (RO)
139  *
140  * Error was detected, check ESR register for details
141  */
142 #define RNG_STA_FUNCERR_MASK (0x10000UL)
143 #define RNG_STA_FUNCERR_SHIFT (16U)
144 #define RNG_STA_FUNCERR_GET(x) (((uint32_t)(x) & RNG_STA_FUNCERR_MASK) >> RNG_STA_FUNCERR_SHIFT)
145 
146 /*
147  * FSIZE (RO)
148  *
149  * Fifo Size, it is 5 in this design.
150  */
151 #define RNG_STA_FSIZE_MASK (0xF000U)
152 #define RNG_STA_FSIZE_SHIFT (12U)
153 #define RNG_STA_FSIZE_GET(x) (((uint32_t)(x) & RNG_STA_FSIZE_MASK) >> RNG_STA_FSIZE_SHIFT)
154 
155 /*
156  * FRNNU (RO)
157  *
158  * Fifo Level, Indicates the number of random words currently in the output FIFO
159  */
160 #define RNG_STA_FRNNU_MASK (0xF00U)
161 #define RNG_STA_FRNNU_SHIFT (8U)
162 #define RNG_STA_FRNNU_GET(x) (((uint32_t)(x) & RNG_STA_FRNNU_MASK) >> RNG_STA_FRNNU_SHIFT)
163 
164 /*
165  * NSDDN (RO)
166  *
167  * New seed done.
168  */
169 #define RNG_STA_NSDDN_MASK (0x40U)
170 #define RNG_STA_NSDDN_SHIFT (6U)
171 #define RNG_STA_NSDDN_GET(x) (((uint32_t)(x) & RNG_STA_NSDDN_MASK) >> RNG_STA_NSDDN_SHIFT)
172 
173 /*
174  * FSDDN (RO)
175  *
176  * 1st Seed done
177  * When "1", Indicates that the RNG generated the first seed.
178  */
179 #define RNG_STA_FSDDN_MASK (0x20U)
180 #define RNG_STA_FSDDN_SHIFT (5U)
181 #define RNG_STA_FSDDN_GET(x) (((uint32_t)(x) & RNG_STA_FSDDN_MASK) >> RNG_STA_FSDDN_SHIFT)
182 
183 /*
184  * SCDN (RO)
185  *
186  * Self Check Done
187  * Indicates whether Self Test is done or not. Can be cleared by the hardware reset or a new self test is
188  * initiated by setting the CMD[ST].
189  * 0 Self test not completed
190  * 1 Completed a self test since the last reset.
191  */
192 #define RNG_STA_SCDN_MASK (0x10U)
193 #define RNG_STA_SCDN_SHIFT (4U)
194 #define RNG_STA_SCDN_GET(x) (((uint32_t)(x) & RNG_STA_SCDN_MASK) >> RNG_STA_SCDN_SHIFT)
195 
196 /*
197  * RSDREQ (RO)
198  *
199  * Reseed needed
200  * Indicates that the RNG needs to be reseeded. This is done by setting the CMD[GS], or
201  * automatically if the CTRL[ARS] is set.
202  */
203 #define RNG_STA_RSDREQ_MASK (0x8U)
204 #define RNG_STA_RSDREQ_SHIFT (3U)
205 #define RNG_STA_RSDREQ_GET(x) (((uint32_t)(x) & RNG_STA_RSDREQ_MASK) >> RNG_STA_RSDREQ_SHIFT)
206 
207 /*
208  * IDLE (RO)
209  *
210  * Idle, the RNG is in the idle mode, and internal clocks are disabled, in this mode, access to the FIFO is allowed. Once the FIFO is empty, the RNGB fills the FIFO and then enters idle mode again.
211  */
212 #define RNG_STA_IDLE_MASK (0x4U)
213 #define RNG_STA_IDLE_SHIFT (2U)
214 #define RNG_STA_IDLE_GET(x) (((uint32_t)(x) & RNG_STA_IDLE_MASK) >> RNG_STA_IDLE_SHIFT)
215 
216 /*
217  * BUSY (RO)
218  *
219  * when 1, means the RNG engine is busy for seeding or random number generation, self test and so on.
220  */
221 #define RNG_STA_BUSY_MASK (0x2U)
222 #define RNG_STA_BUSY_SHIFT (1U)
223 #define RNG_STA_BUSY_GET(x) (((uint32_t)(x) & RNG_STA_BUSY_MASK) >> RNG_STA_BUSY_SHIFT)
224 
225 /* Bitfield definition for register: ERR */
226 /*
227  * FUFE (RO)
228  *
229  * FIFO access error(underflow)
230  */
231 #define RNG_ERR_FUFE_MASK (0x20U)
232 #define RNG_ERR_FUFE_SHIFT (5U)
233 #define RNG_ERR_FUFE_GET(x) (((uint32_t)(x) & RNG_ERR_FUFE_MASK) >> RNG_ERR_FUFE_SHIFT)
234 
235 /*
236  * SCKERR (RO)
237  *
238  * Self-test error
239  * Indicates that the RNG failed the most recent self test. This bit is sticky and can only be reset by a
240  * hardware reset or by writing 1 to the CMD[CE]
241  */
242 #define RNG_ERR_SCKERR_MASK (0x8U)
243 #define RNG_ERR_SCKERR_SHIFT (3U)
244 #define RNG_ERR_SCKERR_GET(x) (((uint32_t)(x) & RNG_ERR_SCKERR_MASK) >> RNG_ERR_SCKERR_SHIFT)
245 
246 /* Bitfield definition for register: FO2B */
247 /*
248  * FO2B (RO)
249  *
250  * SW read the FIFO output.
251  */
252 #define RNG_FO2B_FO2B_MASK (0xFFFFFFFFUL)
253 #define RNG_FO2B_FO2B_SHIFT (0U)
254 #define RNG_FO2B_FO2B_GET(x) (((uint32_t)(x) & RNG_FO2B_FO2B_MASK) >> RNG_FO2B_FO2B_SHIFT)
255 
256 /* Bitfield definition for register array: R2SK */
257 /*
258  * FO2S0 (RO)
259  *
260  * FIFO out to KMAN, will be SDP engine key.
261  */
262 #define RNG_R2SK_FO2S0_MASK (0xFFFFFFFFUL)
263 #define RNG_R2SK_FO2S0_SHIFT (0U)
264 #define RNG_R2SK_FO2S0_GET(x) (((uint32_t)(x) & RNG_R2SK_FO2S0_MASK) >> RNG_R2SK_FO2S0_SHIFT)
265 
266 
267 
268 /* R2SK register group index macro definition */
269 #define RNG_R2SK_FO2S0 (0UL)
270 #define RNG_R2SK_FO2S1 (1UL)
271 #define RNG_R2SK_FO2S2 (2UL)
272 #define RNG_R2SK_FO2S3 (3UL)
273 #define RNG_R2SK_FO2S4 (4UL)
274 #define RNG_R2SK_FO2S5 (5UL)
275 #define RNG_R2SK_FO2S6 (6UL)
276 #define RNG_R2SK_FO2S7 (7UL)
277 
278 
279 #endif /* HPM_RNG_H */