xref: /OK3568_Linux_fs/kernel/include/linux/cc_platform.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Confidential Computing Platform Capability checks
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2021 Advanced Micro Devices, Inc.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: Tom Lendacky <thomas.lendacky@amd.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef _LINUX_CC_PLATFORM_H
11*4882a593Smuzhiyun #define _LINUX_CC_PLATFORM_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/types.h>
14*4882a593Smuzhiyun #include <linux/stddef.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /**
17*4882a593Smuzhiyun  * enum cc_attr - Confidential computing attributes
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * These attributes represent confidential computing features that are
20*4882a593Smuzhiyun  * currently active.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun enum cc_attr {
23*4882a593Smuzhiyun 	/**
24*4882a593Smuzhiyun 	 * @CC_ATTR_MEM_ENCRYPT: Memory encryption is active
25*4882a593Smuzhiyun 	 *
26*4882a593Smuzhiyun 	 * The platform/OS is running with active memory encryption. This
27*4882a593Smuzhiyun 	 * includes running either as a bare-metal system or a hypervisor
28*4882a593Smuzhiyun 	 * and actively using memory encryption or as a guest/virtual machine
29*4882a593Smuzhiyun 	 * and actively using memory encryption.
30*4882a593Smuzhiyun 	 *
31*4882a593Smuzhiyun 	 * Examples include SME, SEV and SEV-ES.
32*4882a593Smuzhiyun 	 */
33*4882a593Smuzhiyun 	CC_ATTR_MEM_ENCRYPT,
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	/**
36*4882a593Smuzhiyun 	 * @CC_ATTR_HOST_MEM_ENCRYPT: Host memory encryption is active
37*4882a593Smuzhiyun 	 *
38*4882a593Smuzhiyun 	 * The platform/OS is running as a bare-metal system or a hypervisor
39*4882a593Smuzhiyun 	 * and actively using memory encryption.
40*4882a593Smuzhiyun 	 *
41*4882a593Smuzhiyun 	 * Examples include SME.
42*4882a593Smuzhiyun 	 */
43*4882a593Smuzhiyun 	CC_ATTR_HOST_MEM_ENCRYPT,
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	/**
46*4882a593Smuzhiyun 	 * @CC_ATTR_GUEST_MEM_ENCRYPT: Guest memory encryption is active
47*4882a593Smuzhiyun 	 *
48*4882a593Smuzhiyun 	 * The platform/OS is running as a guest/virtual machine and actively
49*4882a593Smuzhiyun 	 * using memory encryption.
50*4882a593Smuzhiyun 	 *
51*4882a593Smuzhiyun 	 * Examples include SEV and SEV-ES.
52*4882a593Smuzhiyun 	 */
53*4882a593Smuzhiyun 	CC_ATTR_GUEST_MEM_ENCRYPT,
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	/**
56*4882a593Smuzhiyun 	 * @CC_ATTR_GUEST_STATE_ENCRYPT: Guest state encryption is active
57*4882a593Smuzhiyun 	 *
58*4882a593Smuzhiyun 	 * The platform/OS is running as a guest/virtual machine and actively
59*4882a593Smuzhiyun 	 * using memory encryption and register state encryption.
60*4882a593Smuzhiyun 	 *
61*4882a593Smuzhiyun 	 * Examples include SEV-ES.
62*4882a593Smuzhiyun 	 */
63*4882a593Smuzhiyun 	CC_ATTR_GUEST_STATE_ENCRYPT,
64*4882a593Smuzhiyun };
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #ifdef CONFIG_ARCH_HAS_CC_PLATFORM
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /**
69*4882a593Smuzhiyun  * cc_platform_has() - Checks if the specified cc_attr attribute is active
70*4882a593Smuzhiyun  * @attr: Confidential computing attribute to check
71*4882a593Smuzhiyun  *
72*4882a593Smuzhiyun  * The cc_platform_has() function will return an indicator as to whether the
73*4882a593Smuzhiyun  * specified Confidential Computing attribute is currently active.
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * Context: Any context
76*4882a593Smuzhiyun  * Return:
77*4882a593Smuzhiyun  * * TRUE  - Specified Confidential Computing attribute is active
78*4882a593Smuzhiyun  * * FALSE - Specified Confidential Computing attribute is not active
79*4882a593Smuzhiyun  */
80*4882a593Smuzhiyun bool cc_platform_has(enum cc_attr attr);
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #else	/* !CONFIG_ARCH_HAS_CC_PLATFORM */
83*4882a593Smuzhiyun 
cc_platform_has(enum cc_attr attr)84*4882a593Smuzhiyun static inline bool cc_platform_has(enum cc_attr attr) { return false; }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #endif	/* CONFIG_ARCH_HAS_CC_PLATFORM */
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun #endif	/* _LINUX_CC_PLATFORM_H */
89