1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | /* |
3 | * OP-TEE STM32MP BSEC PTA interface, used by STM32 ROMEM driver |
4 | * |
5 | * Copyright (C) 2022, STMicroelectronics - All Rights Reserved |
6 | */ |
7 | |
8 | #if IS_ENABLED(CONFIG_NVMEM_STM32_BSEC_OPTEE_TA) |
9 | /** |
10 | * stm32_bsec_optee_ta_open() - initialize the STM32 BSEC TA |
11 | * @ctx: the OP-TEE context on success |
12 | * |
13 | * Return: |
14 | * On success, 0. On failure, -errno. |
15 | */ |
16 | int stm32_bsec_optee_ta_open(struct tee_context **ctx); |
17 | |
18 | /** |
19 | * stm32_bsec_optee_ta_close() - release the STM32 BSEC TA |
20 | * @ctx: the OP-TEE context |
21 | * |
22 | * This function used to clean the OP-TEE resources initialized in |
23 | * stm32_bsec_optee_ta_open(); it can be used as callback to |
24 | * devm_add_action_or_reset() |
25 | */ |
26 | void stm32_bsec_optee_ta_close(void *ctx); |
27 | |
28 | /** |
29 | * stm32_bsec_optee_ta_read() - nvmem read access using TA client driver |
30 | * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open |
31 | * @offset: nvmem offset |
32 | * @buf: buffer to fill with nvem values |
33 | * @bytes: number of bytes to read |
34 | * |
35 | * Return: |
36 | * On success, 0. On failure, -errno. |
37 | */ |
38 | int stm32_bsec_optee_ta_read(struct tee_context *ctx, unsigned int offset, |
39 | void *buf, size_t bytes); |
40 | |
41 | /** |
42 | * stm32_bsec_optee_ta_write() - nvmem write access using TA client driver |
43 | * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open |
44 | * @lower: number of lower OTP, not protected by ECC |
45 | * @offset: nvmem offset |
46 | * @buf: buffer with nvem values |
47 | * @bytes: number of bytes to write |
48 | * |
49 | * Return: |
50 | * On success, 0. On failure, -errno. |
51 | */ |
52 | int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower, |
53 | unsigned int offset, void *buf, size_t bytes); |
54 | |
55 | #else |
56 | |
57 | static inline int stm32_bsec_optee_ta_open(struct tee_context **ctx) |
58 | { |
59 | return -EOPNOTSUPP; |
60 | } |
61 | |
62 | static inline void stm32_bsec_optee_ta_close(void *ctx) |
63 | { |
64 | } |
65 | |
66 | static inline int stm32_bsec_optee_ta_read(struct tee_context *ctx, |
67 | unsigned int offset, void *buf, |
68 | size_t bytes) |
69 | { |
70 | return -EOPNOTSUPP; |
71 | } |
72 | |
73 | static inline int stm32_bsec_optee_ta_write(struct tee_context *ctx, |
74 | unsigned int lower, |
75 | unsigned int offset, void *buf, |
76 | size_t bytes) |
77 | { |
78 | return -EOPNOTSUPP; |
79 | } |
80 | #endif /* CONFIG_NVMEM_STM32_BSEC_OPTEE_TA */ |
81 | |