Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 1 | /* |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2021, 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 | |
| 7 | #include <platform_def.h> |
| 8 | |
| 9 | #include <common/debug.h> |
| 10 | #include <drivers/st/bsec.h> |
| 11 | |
| 12 | #include <stm32mp1_smc.h> |
| 13 | |
| 14 | #include "bsec_svc.h" |
| 15 | |
| 16 | uint32_t bsec_main(uint32_t x1, uint32_t x2, uint32_t x3, |
| 17 | uint32_t *ret_otp_value) |
| 18 | { |
| 19 | uint32_t result; |
| 20 | uint32_t tmp_data = 0U; |
| 21 | |
| 22 | switch (x1) { |
| 23 | case STM32_SMC_READ_SHADOW: |
| 24 | result = bsec_read_otp(ret_otp_value, x2); |
| 25 | break; |
| 26 | case STM32_SMC_PROG_OTP: |
| 27 | *ret_otp_value = 0U; |
| 28 | result = bsec_program_otp(x3, x2); |
| 29 | break; |
| 30 | case STM32_SMC_WRITE_SHADOW: |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 31 | *ret_otp_value = 0U; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 32 | result = bsec_write_otp(x3, x2); |
| 33 | break; |
| 34 | case STM32_SMC_READ_OTP: |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 35 | *ret_otp_value = 0U; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 36 | result = bsec_read_otp(&tmp_data, x2); |
| 37 | if (result != BSEC_OK) { |
| 38 | break; |
| 39 | } |
| 40 | |
| 41 | result = bsec_shadow_register(x2); |
| 42 | if (result != BSEC_OK) { |
| 43 | break; |
| 44 | } |
| 45 | |
| 46 | result = bsec_read_otp(ret_otp_value, x2); |
| 47 | if (result != BSEC_OK) { |
| 48 | break; |
| 49 | } |
| 50 | |
| 51 | result = bsec_write_otp(tmp_data, x2); |
| 52 | break; |
| 53 | |
| 54 | default: |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 55 | return STM32_SMC_INVALID_PARAMS; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Nicolas Le Bayon | 152897d | 2020-01-14 14:03:39 +0100 | [diff] [blame] | 58 | return (result == BSEC_OK) ? STM32_SMC_OK : STM32_SMC_FAILED; |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 59 | } |