mem_encrypt.h 1015 B

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