Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 1 | /* |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2024, STMicroelectronics - All Rights Reserved |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 7 | |
| 8 | #include <common/debug.h> |
| 9 | #include <drivers/st/bsec.h> |
Nicolas Le Bayon | 97287cd | 2019-05-20 18:35:02 +0200 | [diff] [blame] | 10 | #include <drivers/st/bsec2_reg.h> |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 11 | |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 12 | #include <platform_def.h> |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 13 | #include <stm32mp1_smc.h> |
| 14 | |
| 15 | #include "bsec_svc.h" |
| 16 | |
| 17 | uint32_t bsec_main(uint32_t x1, uint32_t x2, uint32_t x3, |
| 18 | uint32_t *ret_otp_value) |
| 19 | { |
| 20 | uint32_t result; |
| 21 | uint32_t tmp_data = 0U; |
| 22 | |
| 23 | switch (x1) { |
| 24 | case STM32_SMC_READ_SHADOW: |
| 25 | result = bsec_read_otp(ret_otp_value, x2); |
| 26 | break; |
| 27 | case STM32_SMC_PROG_OTP: |
| 28 | *ret_otp_value = 0U; |
| 29 | result = bsec_program_otp(x3, x2); |
| 30 | break; |
| 31 | case STM32_SMC_WRITE_SHADOW: |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 32 | *ret_otp_value = 0U; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 33 | result = bsec_write_otp(x3, x2); |
| 34 | break; |
| 35 | case STM32_SMC_READ_OTP: |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 36 | *ret_otp_value = 0U; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 37 | result = bsec_read_otp(&tmp_data, x2); |
| 38 | if (result != BSEC_OK) { |
| 39 | break; |
| 40 | } |
| 41 | |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 42 | result = bsec_shadow_read_otp(ret_otp_value, x2); |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 43 | if (result != BSEC_OK) { |
| 44 | break; |
| 45 | } |
| 46 | |
| 47 | result = bsec_write_otp(tmp_data, x2); |
| 48 | break; |
| 49 | |
| 50 | default: |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 51 | return STM32_SMC_INVALID_PARAMS; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 54 | return (result == BSEC_OK) ? STM32_SMC_OK : STM32_SMC_FAILED; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 55 | } |