1 /*
2  * Copyright (c) 2015, Linaro Limited
3  * Copyright (c) 2017, EPAM Systems
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15 
16 #ifndef __ASM_ARM_SMCCC_H__
17 #define __ASM_ARM_SMCCC_H__
18 
19 /*
20  * This file provides common defines for ARM SMC Calling Convention as
21  * specified in
22  * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
23  */
24 
25 #define ARM_SMCCC_STD_CALL              0U
26 #define ARM_SMCCC_FAST_CALL             1U
27 #define ARM_SMCCC_TYPE_SHIFT            31
28 
29 #define ARM_SMCCC_CONV_32               0U
30 #define ARM_SMCCC_CONV_64               1U
31 #define ARM_SMCCC_CONV_SHIFT            30
32 
33 #define ARM_SMCCC_OWNER_MASK            0x3FU
34 #define ARM_SMCCC_OWNER_SHIFT           24
35 
36 #define ARM_SMCCC_FUNC_MASK             0xFFFFU
37 
38 /* Check if this is fast call. */
smccc_is_fast_call(register_t funcid)39 static inline bool smccc_is_fast_call(register_t funcid)
40 {
41     return funcid & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT);
42 }
43 
44 /* Chek if this is 64-bit call. */
smccc_is_conv_64(register_t funcid)45 static inline bool smccc_is_conv_64(register_t funcid)
46 {
47     return funcid & (ARM_SMCCC_CONV_64 << ARM_SMCCC_CONV_SHIFT);
48 }
49 
50 /* Get function number from function identifier. */
smccc_get_fn(register_t funcid)51 static inline uint32_t smccc_get_fn(register_t funcid)
52 {
53     return funcid & ARM_SMCCC_FUNC_MASK;
54 }
55 
56 /* Get service owner number from function identifier. */
smccc_get_owner(register_t funcid)57 static inline uint32_t smccc_get_owner(register_t funcid)
58 {
59     return (funcid >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK;
60 }
61 
62 /*
63  * Construct function identifier from call type (fast or standard),
64  * calling convention (32 or 64 bit), service owner and function number.
65  */
66 #define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num)           \
67         (((type) << ARM_SMCCC_TYPE_SHIFT) |                                     \
68          ((calling_convention) << ARM_SMCCC_CONV_SHIFT) |                       \
69          (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) |          \
70          (func_num))
71 
72 /* List of known service owners */
73 #define ARM_SMCCC_OWNER_ARCH            0
74 #define ARM_SMCCC_OWNER_CPU             1
75 #define ARM_SMCCC_OWNER_SIP             2
76 #define ARM_SMCCC_OWNER_OEM             3
77 #define ARM_SMCCC_OWNER_STANDARD        4
78 #define ARM_SMCCC_OWNER_HYPERVISOR      5
79 #define ARM_SMCCC_OWNER_TRUSTED_APP     48
80 #define ARM_SMCCC_OWNER_TRUSTED_APP_END 49
81 #define ARM_SMCCC_OWNER_TRUSTED_OS      50
82 #define ARM_SMCCC_OWNER_TRUSTED_OS_END  63
83 
84 /* List of generic function numbers */
85 #define ARM_SMCCC_FUNC_CALL_COUNT       0xFF00
86 #define ARM_SMCCC_FUNC_CALL_UID         0xFF01
87 #define ARM_SMCCC_FUNC_CALL_REVISION    0xFF03
88 
89 /* Only one error code defined in SMCCC */
90 #define ARM_SMCCC_ERR_UNKNOWN_FUNCTION  (-1)
91 
92 /* SMCCC function identifier range which is reserved for existing APIs */
93 #define ARM_SMCCC_RESERVED_RANGE_START  0x0
94 #define ARM_SMCCC_RESERVED_RANGE_END    0x0100FFFF
95 
96 #endif  /* __ASM_ARM_SMCCC_H__ */
97 
98 /*
99  * Local variables:
100  * mode: C
101  * c-file-style: "BSD"
102  * c-basic-offset: 4
103  * indent-tabs-mode: nil
104  * End:b
105  */
106