xref: /linux/arch/arm64/include/asm/mem_encrypt.h (revision 59e6295fac26b8e85c1ea859cdd89fa1e47519d7)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __ASM_MEM_ENCRYPT_H
3 #define __ASM_MEM_ENCRYPT_H
4 
5 #include <asm/hypervisor.h>
6 #include <asm/rsi.h>
7 
8 struct device;
9 
10 struct arm64_mem_crypt_ops {
11 	int (*encrypt)(unsigned long addr, int numpages);
12 	int (*decrypt)(unsigned long addr, int numpages);
13 };
14 
15 int arm64_mem_crypt_ops_register(const struct arm64_mem_crypt_ops *ops);
16 
17 int set_memory_encrypted(unsigned long addr, int numpages);
18 int set_memory_decrypted(unsigned long addr, int numpages);
19 
20 int realm_register_memory_enc_ops(void);
21 
22 static inline bool force_dma_unencrypted(struct device *dev)
23 {
24 	return is_realm_world() || is_protected_kvm_guest();
25 }
26 
27 /*
28  * For Arm CCA guests, canonical addresses are "encrypted", so no changes
29  * required for dma_addr_encrypted().
30  * The unencrypted DMA buffers must be accessed via the unprotected IPA,
31  * "top IPA bit" set.
32  */
33 #define dma_addr_unencrypted(x)		((x) | PROT_NS_SHARED)
34 
35 /* Clear the "top" IPA bit while converting back */
36 #define dma_addr_canonical(x)		((x) & ~PROT_NS_SHARED)
37 
38 #endif	/* __ASM_MEM_ENCRYPT_H */
39