diff options
| author | Arve Hjønnevåg <arve@android.com> | 2013-11-18 23:46:48 -0500 |
|---|---|---|
| committer | Stephen Wolfe <swolfe@nvidia.com> | 2018-07-27 17:12:44 -0400 |
| commit | e9c6d11022d2ac66fbaf30cd07318ca9ddc9d326 (patch) | |
| tree | ca811cd9518798f0facd60a3ebe42c22914b11f0 /include/linux | |
| parent | 4444a23d76c2169b90ac550a2def6028ef01c208 (diff) | |
trusty: Add trusty driver
includes: Add arm64 support
includes: Add trusty_fast_call64 api on 64 bit systems.
includes: move probe to subsys_initcall
Child devices of trusty like FIQ-based debuggers and watchdogs may
want to probe early, move trusty from module init to subsys init
to allow it and its children to probe earlier.
includes: Retry std_calls on SM_ERR_BUSY
If the trusty spinlock is held, or if the strex fails for another
reason, trusty returns SM_ERR_BUSY. Add retry code to handle this.
Without this retry code, std_calls can fail. If the previous smc
call had returned SM_ERR_INTERRUPTED, this failure would cause
the driver to get out of sync with trusty. All later calls would
then fail with SM_ERR_INTERLEAVED_SMC.
Change-Id: I35318be3d41f84b922397e9afdca6bf47d9645db
Signed-off-by: Arve Hjønnevåg <arve@android.com>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/trusty/sm_err.h | 39 | ||||
| -rw-r--r-- | include/linux/trusty/smcall.h | 75 | ||||
| -rw-r--r-- | include/linux/trusty/trusty.h | 46 |
3 files changed, 160 insertions, 0 deletions
diff --git a/include/linux/trusty/sm_err.h b/include/linux/trusty/sm_err.h new file mode 100644 index 000000000..4ee67589c --- /dev/null +++ b/include/linux/trusty/sm_err.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2013 Google Inc. All rights reserved | ||
| 3 | * | ||
| 4 | * Permission is hereby granted, free of charge, to any person obtaining | ||
| 5 | * a copy of this software and associated documentation files | ||
| 6 | * (the "Software"), to deal in the Software without restriction, | ||
| 7 | * including without limitation the rights to use, copy, modify, merge, | ||
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 9 | * and to permit persons to whom the Software is furnished to do so, | ||
| 10 | * subject to the following conditions: | ||
| 11 | * | ||
| 12 | * The above copyright notice and this permission notice shall be | ||
| 13 | * included in all copies or substantial portions of the Software. | ||
| 14 | * | ||
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | */ | ||
| 23 | #ifndef __LINUX_TRUSTY_SM_ERR_H | ||
| 24 | #define __LINUX_TRUSTY_SM_ERR_H | ||
| 25 | |||
| 26 | /* Errors from the secure monitor */ | ||
| 27 | #define SM_ERR_UNDEFINED_SMC 0xFFFFFFFF /* Unknown SMC (defined by ARM DEN 0028A(0.9.0) */ | ||
| 28 | #define SM_ERR_INVALID_PARAMETERS -2 | ||
| 29 | #define SM_ERR_INTERRUPTED -3 /* Got interrupted. Call back with restart SMC */ | ||
| 30 | #define SM_ERR_UNEXPECTED_RESTART -4 /* Got an restart SMC when we didn't expect it */ | ||
| 31 | #define SM_ERR_BUSY -5 /* Temporarily busy. Call back with original args */ | ||
| 32 | #define SM_ERR_INTERLEAVED_SMC -6 /* Got a trusted_service SMC when a restart SMC is required */ | ||
| 33 | #define SM_ERR_INTERNAL_FAILURE -7 /* Unknown error */ | ||
| 34 | #define SM_ERR_NOT_SUPPORTED -8 | ||
| 35 | #define SM_ERR_NOT_ALLOWED -9 /* SMC call not allowed */ | ||
| 36 | #define SM_ERR_END_OF_INPUT -10 | ||
| 37 | #define SM_ERR_PANIC -11 /* Secure OS crashed */ | ||
| 38 | |||
| 39 | #endif | ||
diff --git a/include/linux/trusty/smcall.h b/include/linux/trusty/smcall.h new file mode 100644 index 000000000..278a4b256 --- /dev/null +++ b/include/linux/trusty/smcall.h | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2013-2014 Google Inc. All rights reserved | ||
| 3 | * | ||
| 4 | * Permission is hereby granted, free of charge, to any person obtaining | ||
| 5 | * a copy of this software and associated documentation files | ||
| 6 | * (the "Software"), to deal in the Software without restriction, | ||
| 7 | * including without limitation the rights to use, copy, modify, merge, | ||
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 9 | * and to permit persons to whom the Software is furnished to do so, | ||
| 10 | * subject to the following conditions: | ||
| 11 | * | ||
| 12 | * The above copyright notice and this permission notice shall be | ||
| 13 | * included in all copies or substantial portions of the Software. | ||
| 14 | * | ||
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | */ | ||
| 23 | #ifndef __LINUX_TRUSTY_SMCALL_H | ||
| 24 | #define __LINUX_TRUSTY_SMCALL_H | ||
| 25 | |||
| 26 | #define SMC_NUM_ENTITIES 64 | ||
| 27 | #define SMC_NUM_ARGS 4 | ||
| 28 | #define SMC_NUM_PARAMS (SMC_NUM_ARGS - 1) | ||
| 29 | |||
| 30 | #define SMC_IS_FASTCALL(smc_nr) ((smc_nr) & 0x80000000) | ||
| 31 | #define SMC_IS_SMC64(smc_nr) ((smc_nr) & 0x40000000) | ||
| 32 | #define SMC_ENTITY(smc_nr) (((smc_nr) & 0x3F000000) >> 24) | ||
| 33 | #define SMC_FUNCTION(smc_nr) ((smc_nr) & 0x0000FFFF) | ||
| 34 | |||
| 35 | #define SMC_NR(entity, fn, fastcall, smc64) ((((fastcall) & 0x1) << 31) | \ | ||
| 36 | (((smc64) & 0x1) << 30) | \ | ||
| 37 | (((entity) & 0x3F) << 24) | \ | ||
| 38 | ((fn) & 0xFFFF) \ | ||
| 39 | ) | ||
| 40 | |||
| 41 | #define SMC_FASTCALL_NR(entity, fn) SMC_NR((entity), (fn), 1, 0) | ||
| 42 | #define SMC_STDCALL_NR(entity, fn) SMC_NR((entity), (fn), 0, 0) | ||
| 43 | #define SMC_FASTCALL64_NR(entity, fn) SMC_NR((entity), (fn), 1, 1) | ||
| 44 | #define SMC_STDCALL64_NR(entity, fn) SMC_NR((entity), (fn), 0, 1) | ||
| 45 | |||
| 46 | #define SMC_ENTITY_ARCH 0 /* ARM Architecture calls */ | ||
| 47 | #define SMC_ENTITY_CPU 1 /* CPU Service calls */ | ||
| 48 | #define SMC_ENTITY_SIP 2 /* SIP Service calls */ | ||
| 49 | #define SMC_ENTITY_OEM 3 /* OEM Service calls */ | ||
| 50 | #define SMC_ENTITY_STD 4 /* Standard Service calls */ | ||
| 51 | #define SMC_ENTITY_RESERVED 5 /* Reserved for future use */ | ||
| 52 | #define SMC_ENTITY_TRUSTED_APP 48 /* Trusted Application calls */ | ||
| 53 | #define SMC_ENTITY_TRUSTED_OS 50 /* Trusted OS calls */ | ||
| 54 | #define SMC_ENTITY_SECURE_MONITOR 60 /* Trusted OS calls internal to secure monitor */ | ||
| 55 | |||
| 56 | /* FC = Fast call, SC = Standard call */ | ||
| 57 | #define SMC_SC_RESTART_LAST SMC_STDCALL_NR (SMC_ENTITY_SECURE_MONITOR, 0) | ||
| 58 | #define SMC_SC_NOP SMC_STDCALL_NR (SMC_ENTITY_SECURE_MONITOR, 1) | ||
| 59 | |||
| 60 | /* | ||
| 61 | * Return from secure os to non-secure os with return value in r1 | ||
| 62 | */ | ||
| 63 | #define SMC_SC_NS_RETURN SMC_STDCALL_NR (SMC_ENTITY_SECURE_MONITOR, 0) | ||
| 64 | |||
| 65 | #define SMC_FC_RESERVED SMC_FASTCALL_NR (SMC_ENTITY_SECURE_MONITOR, 0) | ||
| 66 | #define SMC_FC_FIQ_EXIT SMC_FASTCALL_NR (SMC_ENTITY_SECURE_MONITOR, 1) | ||
| 67 | #define SMC_FC_REQUEST_FIQ SMC_FASTCALL_NR (SMC_ENTITY_SECURE_MONITOR, 2) | ||
| 68 | #define SMC_FC_GET_NEXT_IRQ SMC_FASTCALL_NR (SMC_ENTITY_SECURE_MONITOR, 3) | ||
| 69 | |||
| 70 | #define SMC_FC_CPU_SUSPEND SMC_FASTCALL_NR (SMC_ENTITY_SECURE_MONITOR, 7) | ||
| 71 | #define SMC_FC_CPU_RESUME SMC_FASTCALL_NR (SMC_ENTITY_SECURE_MONITOR, 8) | ||
| 72 | |||
| 73 | #define SMC_FC_AARCH_SWITCH SMC_FASTCALL_NR (SMC_ENTITY_SECURE_MONITOR, 9) | ||
| 74 | |||
| 75 | #endif /* __LINUX_TRUSTY_SMCALL_H */ | ||
diff --git a/include/linux/trusty/trusty.h b/include/linux/trusty/trusty.h new file mode 100644 index 000000000..30d4300ba --- /dev/null +++ b/include/linux/trusty/trusty.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2013 Google, Inc. | ||
| 3 | * | ||
| 4 | * This software is licensed under the terms of the GNU General Public | ||
| 5 | * License version 2, as published by the Free Software Foundation, and | ||
| 6 | * may be copied, distributed, and modified under those terms. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | #ifndef __LINUX_TRUSTY_TRUSTY_H | ||
| 15 | #define __LINUX_TRUSTY_TRUSTY_H | ||
| 16 | |||
| 17 | #include <linux/kernel.h> | ||
| 18 | #include <linux/trusty/sm_err.h> | ||
| 19 | |||
| 20 | #ifdef CONFIG_TRUSTY | ||
| 21 | s32 trusty_std_call32(struct device *dev, u32 smcnr, u32 a0, u32 a1, u32 a2); | ||
| 22 | s32 trusty_fast_call32(struct device *dev, u32 smcnr, u32 a0, u32 a1, u32 a2); | ||
| 23 | #ifdef CONFIG_64BIT | ||
| 24 | s64 trusty_fast_call64(struct device *dev, u64 smcnr, u64 a0, u64 a1, u64 a2); | ||
| 25 | #endif | ||
| 26 | #else | ||
| 27 | static inline s32 trusty_std_call32(struct device *dev, u32 smcnr, | ||
| 28 | u32 a0, u32 a1, u32 a2) | ||
| 29 | { | ||
| 30 | return SM_ERR_UNDEFINED_SMC; | ||
| 31 | } | ||
| 32 | static inline s32 trusty_fast_call32(struct device *dev, u32 smcnr, | ||
| 33 | u32 a0, u32 a1, u32 a2) | ||
| 34 | { | ||
| 35 | return SM_ERR_UNDEFINED_SMC; | ||
| 36 | } | ||
| 37 | #ifdef CONFIG_64BIT | ||
| 38 | static inline s64 trusty_fast_call64(struct device *dev, | ||
| 39 | u64 smcnr, u64 a0, u64 a1, u64 a2) | ||
| 40 | { | ||
| 41 | return SM_ERR_UNDEFINED_SMC; | ||
| 42 | } | ||
| 43 | #endif | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #endif | ||
