blob: 1b2bba3d34c2133b720e4dd1e98233f03c3654a8 [file] [log] [blame]
Patrick Delaunay7858d7e2019-02-12 11:44:40 +01001/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
2/*
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
4 */
5
6#ifndef __STM32MP1_SMC_H__
7#define __STM32MP1_SMC_H__
8
9#include <linux/arm-smccc.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060010#include <linux/printk.h>
Patrick Delaunay7858d7e2019-02-12 11:44:40 +010011
12/*
13 * SMC function IDs for STM32 Service queries
14 * STM32 SMC services use the space between 0x82000000 and 0x8200FFFF
15 * like this is defined in SMC calling Convention by ARM
16 * for SiP (silicon Partner)
17 * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
18 */
19#define STM32_SMC_VERSION 0x82000000
20
21/* Secure Service access from Non-secure */
22#define STM32_SMC_BSEC 0x82001003
23
24/* Service for BSEC */
25#define STM32_SMC_READ_SHADOW 0x01
26#define STM32_SMC_PROG_OTP 0x02
27#define STM32_SMC_WRITE_SHADOW 0x03
28#define STM32_SMC_READ_OTP 0x04
29#define STM32_SMC_READ_ALL 0x05
30#define STM32_SMC_WRITE_ALL 0x06
Patrick Delaunayb10cddf2020-02-12 19:37:38 +010031#define STM32_SMC_WRLOCK_OTP 0x07
Patrick Delaunay7858d7e2019-02-12 11:44:40 +010032
33/* SMC error codes */
34#define STM32_SMC_OK 0x0
35#define STM32_SMC_NOT_SUPPORTED -1
36#define STM32_SMC_FAILED -2
37#define STM32_SMC_INVALID_PARAMS -3
38
39#define stm32_smc_exec(svc, op, data1, data2) \
40 stm32_smc(svc, op, data1, data2, NULL)
41
42#ifdef CONFIG_ARM_SMCCC
43static inline u32 stm32_smc(u32 svc, u8 op, u32 data1, u32 data2, u32 *result)
44{
45 struct arm_smccc_res res;
46
47 arm_smccc_smc(svc, op, data1, data2, 0, 0, 0, 0, &res);
48
49 if (res.a0) {
Patrick Delaunay5af430d2020-02-12 19:37:40 +010050 pr_err("%s: Failed to exec svc=%x op=%x in secure mode (err = %ld)\n",
51 __func__, svc, op, res.a0);
Patrick Delaunay7858d7e2019-02-12 11:44:40 +010052 return -EINVAL;
53 }
54 if (result)
55 *result = (u32)res.a1;
56
57 return 0;
58}
59#else
60static inline u32 stm32_smc(u32 svc, u8 op, u32 data1, u32 data2, u32 *result)
61{
62 return 0;
63}
64#endif
65
66#endif /* __STM32MP1_SMC_H__ */