|
20 | 20 | #include "partition_M2351.h"
|
21 | 21 | #include "stddriver_secure.h"
|
22 | 22 | #include "mbed_error.h"
|
| 23 | +#if defined(DOMAIN_NS) && (DOMAIN_NS == 1L) && (TFM_LVL > 0) |
| 24 | +#include "tfm_ns_lock.h" |
| 25 | +#endif |
23 | 26 |
|
24 | 27 | #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
|
25 | 28 |
|
@@ -133,78 +136,70 @@ static const nu_modidx_ns_t modidx_ns_tab[] = {
|
133 | 136 | */
|
134 | 137 | static bool check_mod_ns(int modclass, uint32_t modidx);
|
135 | 138 |
|
136 |
| -__NONSECURE_ENTRY |
137 |
| -void SYS_ResetModule_S(uint32_t u32ModuleIndex) |
| 139 | +static void SYS_ResetModule_Impl(uint32_t u32ModuleIndex, bool nonsecure_caller) |
138 | 140 | {
|
139 | 141 | /* Guard access to secure module from non-secure domain */
|
140 |
| - if (cmse_nonsecure_caller() && |
| 142 | + if (nonsecure_caller && |
141 | 143 | (! check_mod_ns(NU_MODCLASS_SYS, u32ModuleIndex))) {
|
142 | 144 | error("Non-secure domain tries to control secure or undefined module.");
|
143 | 145 | }
|
144 | 146 |
|
145 | 147 | SYS_ResetModule(u32ModuleIndex);
|
146 | 148 | }
|
147 | 149 |
|
148 |
| -__NONSECURE_ENTRY |
149 |
| -void CLK_SetModuleClock_S(uint32_t u32ModuleIndex, uint32_t u32ClkSrc, uint32_t u32ClkDiv) |
| 150 | +static void CLK_SetModuleClock_Impl(uint32_t u32ModuleIndex, uint32_t u32ClkSrc, uint32_t u32ClkDiv, bool nonsecure_caller) |
150 | 151 | {
|
151 | 152 | /* Guard access to secure module from non-secure domain */
|
152 |
| - if (cmse_nonsecure_caller() && |
| 153 | + if (nonsecure_caller && |
153 | 154 | (! check_mod_ns(NU_MODCLASS_CLK, u32ModuleIndex))) {
|
154 | 155 | error("Non-secure domain tries to control secure or undefined module.");
|
155 | 156 | }
|
156 | 157 |
|
157 | 158 | CLK_SetModuleClock(u32ModuleIndex, u32ClkSrc, u32ClkDiv);
|
158 | 159 | }
|
159 | 160 |
|
160 |
| -__NONSECURE_ENTRY |
161 |
| -void CLK_EnableModuleClock_S(uint32_t u32ModuleIndex) |
| 161 | +static void CLK_EnableModuleClock_Impl(uint32_t u32ModuleIndex, bool nonsecure_caller) |
162 | 162 | {
|
163 | 163 | /* Guard access to secure module from non-secure domain */
|
164 |
| - if (cmse_nonsecure_caller() && |
| 164 | + if (nonsecure_caller && |
165 | 165 | (! check_mod_ns(NU_MODCLASS_CLK, u32ModuleIndex))) {
|
166 | 166 | error("Non-secure domain tries to control secure or undefined module.");
|
167 | 167 | }
|
168 | 168 |
|
169 | 169 | CLK_EnableModuleClock(u32ModuleIndex);
|
170 | 170 | }
|
171 | 171 |
|
172 |
| -__NONSECURE_ENTRY |
173 |
| -void CLK_DisableModuleClock_S(uint32_t u32ModuleIndex) |
| 172 | +static void CLK_DisableModuleClock_Impl(uint32_t u32ModuleIndex, bool nonsecure_caller) |
174 | 173 | {
|
175 | 174 | /* Guard access to secure module from non-secure domain */
|
176 |
| - if (cmse_nonsecure_caller() && |
| 175 | + if (nonsecure_caller && |
177 | 176 | (! check_mod_ns(NU_MODCLASS_CLK, u32ModuleIndex))) {
|
178 | 177 | error("Non-secure domain tries to control secure or undefined module.");
|
179 | 178 | }
|
180 | 179 |
|
181 | 180 | CLK_DisableModuleClock(u32ModuleIndex);
|
182 | 181 | }
|
183 | 182 |
|
184 |
| -__NONSECURE_ENTRY |
185 |
| -void SYS_LockReg_S(void) |
| 183 | +static void SYS_LockReg_Impl(void) |
186 | 184 | {
|
187 | 185 | /* Allow non-secure domain to lock/unlock locked registers without check.
|
188 | 186 | * Guard access to locked registers is done through other related secure functions. */
|
189 | 187 | SYS_LockReg();
|
190 | 188 | }
|
191 | 189 |
|
192 |
| -__NONSECURE_ENTRY |
193 |
| -void SYS_UnlockReg_S(void) |
| 190 | +static void SYS_UnlockReg_Impl(void) |
194 | 191 | {
|
195 | 192 | /* Allow non-secure domain to lock/unlock locked registers without check.
|
196 | 193 | * Guard access to locked registers is done through other related secure functions. */
|
197 | 194 | SYS_UnlockReg();
|
198 | 195 | }
|
199 | 196 |
|
200 |
| -__NONSECURE_ENTRY |
201 |
| -void CLK_Idle_S(void) |
| 197 | +static void CLK_Idle_Impl(void) |
202 | 198 | {
|
203 | 199 | CLK_Idle();
|
204 | 200 | }
|
205 | 201 |
|
206 |
| -__NONSECURE_ENTRY |
207 |
| -void CLK_PowerDown_S(void) |
| 202 | +static void CLK_PowerDown_Impl(void) |
208 | 203 | {
|
209 | 204 | CLK_PowerDown();
|
210 | 205 | }
|
@@ -251,4 +246,227 @@ static bool check_mod_ns(int modclass, uint32_t modidx)
|
251 | 246 | return false;
|
252 | 247 | }
|
253 | 248 |
|
| 249 | +#if (TFM_LVL > 0) |
| 250 | + |
| 251 | +__NONSECURE_ENTRY |
| 252 | +int32_t SYS_ResetModule_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 253 | +{ |
| 254 | + uint32_t u32ModuleIndex = (uint32_t) arg0; |
| 255 | + SYS_ResetModule_Impl(u32ModuleIndex, cmse_nonsecure_caller()); |
| 256 | + return 0; |
| 257 | +} |
| 258 | + |
| 259 | +__NONSECURE_ENTRY |
| 260 | +int32_t CLK_SetModuleClock_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 261 | +{ |
| 262 | + uint32_t u32ModuleIndex = (uint32_t) arg0; |
| 263 | + uint32_t u32ClkSrc = (uint32_t) arg1; |
| 264 | + uint32_t u32ClkDiv = (uint32_t) arg2; |
| 265 | + CLK_SetModuleClock_Impl(u32ModuleIndex, u32ClkSrc, u32ClkDiv, cmse_nonsecure_caller()); |
| 266 | + return 0; |
| 267 | +} |
| 268 | + |
| 269 | +__NONSECURE_ENTRY |
| 270 | +int32_t CLK_EnableModuleClock_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 271 | +{ |
| 272 | + uint32_t u32ModuleIndex = (uint32_t) arg0; |
| 273 | + CLK_EnableModuleClock_Impl(u32ModuleIndex, cmse_nonsecure_caller()); |
| 274 | + return 0; |
| 275 | +} |
| 276 | + |
| 277 | +__NONSECURE_ENTRY |
| 278 | +int32_t CLK_DisableModuleClock_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 279 | +{ |
| 280 | + uint32_t u32ModuleIndex = (uint32_t) arg0; |
| 281 | + CLK_DisableModuleClock_Impl(u32ModuleIndex, cmse_nonsecure_caller()); |
| 282 | + return 0; |
| 283 | +} |
| 284 | + |
| 285 | +__NONSECURE_ENTRY |
| 286 | +int32_t SYS_LockReg_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 287 | +{ |
| 288 | + SYS_LockReg_Impl(); |
| 289 | + return 0; |
| 290 | +} |
| 291 | + |
| 292 | +__NONSECURE_ENTRY |
| 293 | +int32_t SYS_UnlockReg_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 294 | +{ |
| 295 | + SYS_UnlockReg_Impl(); |
| 296 | + return 0; |
| 297 | +} |
| 298 | + |
| 299 | +__NONSECURE_ENTRY |
| 300 | +int32_t CLK_Idle_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 301 | +{ |
| 302 | + CLK_Idle_Impl(); |
| 303 | + return 0; |
| 304 | +} |
| 305 | + |
| 306 | +__NONSECURE_ENTRY |
| 307 | +int32_t CLK_PowerDown_Veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 308 | +{ |
| 309 | + CLK_PowerDown_Impl(); |
| 310 | + return 0; |
| 311 | +} |
| 312 | + |
| 313 | +__NONSECURE_ENTRY |
| 314 | +int32_t nu_idle_veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 315 | +{ |
| 316 | + SYS_UnlockReg_Impl(); |
| 317 | + CLK_Idle_Impl(); |
| 318 | + SYS_LockReg_Impl(); |
| 319 | + return 0; |
| 320 | +} |
| 321 | + |
| 322 | +__NONSECURE_ENTRY |
| 323 | +int32_t nu_powerdown_veneer(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) |
| 324 | +{ |
| 325 | + SYS_UnlockReg_Impl(); |
| 326 | + CLK_PowerDown_Impl(); |
| 327 | + SYS_LockReg_Impl(); |
| 328 | + return 0; |
| 329 | +} |
| 330 | + |
| 331 | +#endif |
| 332 | +#endif |
| 333 | + |
| 334 | +#if defined(DOMAIN_NS) && (DOMAIN_NS == 1) && (TFM_LVL > 0) |
| 335 | + |
| 336 | +void SYS_ResetModule_S(uint32_t u32ModuleIndex) |
| 337 | +{ |
| 338 | + tfm_ns_lock_dispatch(SYS_ResetModule_Veneer, u32ModuleIndex, 0, 0, 0); |
| 339 | +} |
| 340 | + |
| 341 | +void CLK_SetModuleClock_S(uint32_t u32ModuleIndex, uint32_t u32ClkSrc, uint32_t u32ClkDiv) |
| 342 | +{ |
| 343 | + tfm_ns_lock_dispatch(CLK_SetModuleClock_Veneer, u32ModuleIndex, u32ClkSrc, u32ClkDiv, 0); |
| 344 | +} |
| 345 | + |
| 346 | +void CLK_EnableModuleClock_S(uint32_t u32ModuleIndex) |
| 347 | +{ |
| 348 | + tfm_ns_lock_dispatch(CLK_EnableModuleClock_Veneer, u32ModuleIndex, 0, 0, 0); |
| 349 | +} |
| 350 | + |
| 351 | +void CLK_DisableModuleClock_S(uint32_t u32ModuleIndex) |
| 352 | +{ |
| 353 | + tfm_ns_lock_dispatch(CLK_DisableModuleClock_Veneer, u32ModuleIndex, 0, 0, 0); |
| 354 | +} |
| 355 | + |
| 356 | +void SYS_LockReg_S(void) |
| 357 | +{ |
| 358 | + tfm_ns_lock_dispatch(SYS_LockReg_Veneer, 0, 0, 0, 0); |
| 359 | +} |
| 360 | + |
| 361 | +void SYS_UnlockReg_S(void) |
| 362 | +{ |
| 363 | + tfm_ns_lock_dispatch(SYS_UnlockReg_Veneer, 0, 0, 0, 0); |
| 364 | +} |
| 365 | + |
| 366 | +void CLK_Idle_S(void) |
| 367 | +{ |
| 368 | + tfm_ns_lock_dispatch(CLK_Idle_Veneer, 0, 0, 0, 0); |
| 369 | +} |
| 370 | + |
| 371 | +void CLK_PowerDown_S(void) |
| 372 | +{ |
| 373 | + tfm_ns_lock_dispatch(CLK_PowerDown_Veneer, 0, 0, 0, 0); |
| 374 | +} |
| 375 | + |
| 376 | +void nu_idle_s(void) |
| 377 | +{ |
| 378 | + tfm_ns_lock_dispatch(nu_idle_veneer, 0, 0, 0, 0); |
| 379 | +} |
| 380 | + |
| 381 | +void nu_powerdown_s(void) |
| 382 | +{ |
| 383 | + tfm_ns_lock_dispatch(nu_powerdown_veneer, 0, 0, 0, 0); |
| 384 | +} |
| 385 | + |
| 386 | +#elif defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) |
| 387 | + |
| 388 | +#if (TFM_LVL == 0) |
| 389 | +__NONSECURE_ENTRY |
| 390 | +#endif |
| 391 | +void SYS_ResetModule_S(uint32_t u32ModuleIndex) |
| 392 | +{ |
| 393 | + SYS_ResetModule_Impl(u32ModuleIndex, cmse_nonsecure_caller()); |
| 394 | +} |
| 395 | + |
| 396 | +#if (TFM_LVL == 0) |
| 397 | +__NONSECURE_ENTRY |
| 398 | +#endif |
| 399 | +void CLK_SetModuleClock_S(uint32_t u32ModuleIndex, uint32_t u32ClkSrc, uint32_t u32ClkDiv) |
| 400 | +{ |
| 401 | + CLK_SetModuleClock_Impl(u32ModuleIndex, u32ClkSrc, u32ClkDiv, cmse_nonsecure_caller()); |
| 402 | +} |
| 403 | + |
| 404 | +#if (TFM_LVL == 0) |
| 405 | +__NONSECURE_ENTRY |
| 406 | +#endif |
| 407 | +void CLK_EnableModuleClock_S(uint32_t u32ModuleIndex) |
| 408 | +{ |
| 409 | + CLK_EnableModuleClock_Impl(u32ModuleIndex, cmse_nonsecure_caller()); |
| 410 | +} |
| 411 | + |
| 412 | +#if (TFM_LVL == 0) |
| 413 | +__NONSECURE_ENTRY |
| 414 | +#endif |
| 415 | +void CLK_DisableModuleClock_S(uint32_t u32ModuleIndex) |
| 416 | +{ |
| 417 | + CLK_DisableModuleClock_Impl(u32ModuleIndex, cmse_nonsecure_caller()); |
| 418 | +} |
| 419 | + |
| 420 | +#if (TFM_LVL == 0) |
| 421 | +__NONSECURE_ENTRY |
| 422 | +#endif |
| 423 | +void SYS_LockReg_S(void) |
| 424 | +{ |
| 425 | + SYS_LockReg_Impl(); |
| 426 | +} |
| 427 | + |
| 428 | +#if (TFM_LVL == 0) |
| 429 | +__NONSECURE_ENTRY |
| 430 | +#endif |
| 431 | +void SYS_UnlockReg_S(void) |
| 432 | +{ |
| 433 | + SYS_UnlockReg_Impl(); |
| 434 | +} |
| 435 | + |
| 436 | +#if (TFM_LVL == 0) |
| 437 | +__NONSECURE_ENTRY |
| 438 | +#endif |
| 439 | +void CLK_Idle_S(void) |
| 440 | +{ |
| 441 | + CLK_Idle_Impl(); |
| 442 | +} |
| 443 | + |
| 444 | +#if (TFM_LVL == 0) |
| 445 | +__NONSECURE_ENTRY |
| 446 | +#endif |
| 447 | +void CLK_PowerDown_S(void) |
| 448 | +{ |
| 449 | + CLK_PowerDown_Impl(); |
| 450 | +} |
| 451 | + |
| 452 | +#if (TFM_LVL == 0) |
| 453 | +__NONSECURE_ENTRY |
| 454 | +#endif |
| 455 | +void nu_idle_s(void) |
| 456 | +{ |
| 457 | + SYS_UnlockReg_Impl(); |
| 458 | + CLK_Idle_Impl(); |
| 459 | + SYS_LockReg_Impl(); |
| 460 | +} |
| 461 | + |
| 462 | +#if (TFM_LVL == 0) |
| 463 | +__NONSECURE_ENTRY |
| 464 | +#endif |
| 465 | +void nu_powerdown_s(void) |
| 466 | +{ |
| 467 | + SYS_UnlockReg_Impl(); |
| 468 | + CLK_PowerDown_Impl(); |
| 469 | + SYS_LockReg_Impl(); |
| 470 | +} |
| 471 | + |
254 | 472 | #endif
|
0 commit comments