tdx.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2021-2022 Intel Corporation */
  3. #ifndef _ASM_X86_TDX_H
  4. #define _ASM_X86_TDX_H
  5. #include <linux/init.h>
  6. #include <linux/bits.h>
  7. #include <asm/ptrace.h>
  8. #include <asm/shared/tdx.h>
  9. /*
  10. * SW-defined error codes.
  11. *
  12. * Bits 47:40 == 0xFF indicate Reserved status code class that never used by
  13. * TDX module.
  14. */
  15. #define TDX_ERROR _BITUL(63)
  16. #define TDX_SW_ERROR (TDX_ERROR | GENMASK_ULL(47, 40))
  17. #define TDX_SEAMCALL_VMFAILINVALID (TDX_SW_ERROR | _UL(0xFFFF0000))
  18. #ifndef __ASSEMBLY__
  19. /*
  20. * Used to gather the output registers values of the TDCALL and SEAMCALL
  21. * instructions when requesting services from the TDX module.
  22. *
  23. * This is a software only structure and not part of the TDX module/VMM ABI.
  24. */
  25. struct tdx_module_output {
  26. u64 rcx;
  27. u64 rdx;
  28. u64 r8;
  29. u64 r9;
  30. u64 r10;
  31. u64 r11;
  32. };
  33. /*
  34. * Used by the #VE exception handler to gather the #VE exception
  35. * info from the TDX module. This is a software only structure
  36. * and not part of the TDX module/VMM ABI.
  37. */
  38. struct ve_info {
  39. u64 exit_reason;
  40. u64 exit_qual;
  41. /* Guest Linear (virtual) Address */
  42. u64 gla;
  43. /* Guest Physical Address */
  44. u64 gpa;
  45. u32 instr_len;
  46. u32 instr_info;
  47. };
  48. #ifdef CONFIG_INTEL_TDX_GUEST
  49. void __init tdx_early_init(void);
  50. /* Used to communicate with the TDX module */
  51. u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
  52. struct tdx_module_output *out);
  53. void tdx_get_ve_info(struct ve_info *ve);
  54. bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);
  55. void tdx_safe_halt(void);
  56. bool tdx_early_handle_ve(struct pt_regs *regs);
  57. #else
  58. static inline void tdx_early_init(void) { };
  59. static inline void tdx_safe_halt(void) { };
  60. static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return false; }
  61. #endif /* CONFIG_INTEL_TDX_GUEST */
  62. #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_INTEL_TDX_GUEST)
  63. long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2,
  64. unsigned long p3, unsigned long p4);
  65. #else
  66. static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1,
  67. unsigned long p2, unsigned long p3,
  68. unsigned long p4)
  69. {
  70. return -ENODEV;
  71. }
  72. #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */
  73. #endif /* !__ASSEMBLY__ */
  74. #endif /* _ASM_X86_TDX_H */