1 #ifndef _ASM_X86_INTEL_PCONFIG_H 2 #define _ASM_X86_INTEL_PCONFIG_H 3 4 #include <asm/asm.h> 5 #include <asm/processor.h> 6 7 enum pconfig_target { 8 INVALID_TARGET = 0, 9 MKTME_TARGET = 1, 10 PCONFIG_TARGET_NR 11 }; 12 13 int pconfig_target_supported(enum pconfig_target target); 14 15 enum pconfig_leaf { 16 MKTME_KEY_PROGRAM = 0, 17 PCONFIG_LEAF_INVALID, 18 }; 19 20 #define PCONFIG ".byte 0x0f, 0x01, 0xc5" 21 22 /* Defines and structure for MKTME_KEY_PROGRAM of PCONFIG instruction */ 23 24 /* mktme_key_program::keyid_ctrl COMMAND, bits [7:0] */ 25 #define MKTME_KEYID_SET_KEY_DIRECT 0 26 #define MKTME_KEYID_SET_KEY_RANDOM 1 27 #define MKTME_KEYID_CLEAR_KEY 2 28 #define MKTME_KEYID_NO_ENCRYPT 3 29 30 /* mktme_key_program::keyid_ctrl ENC_ALG, bits [23:8] */ 31 #define MKTME_AES_XTS_128 (1 << 8) 32 33 /* Return codes from the PCONFIG MKTME_KEY_PROGRAM */ 34 #define MKTME_PROG_SUCCESS 0 35 #define MKTME_INVALID_PROG_CMD 1 36 #define MKTME_ENTROPY_ERROR 2 37 #define MKTME_INVALID_KEYID 3 38 #define MKTME_INVALID_ENC_ALG 4 39 #define MKTME_DEVICE_BUSY 5 40 41 /* Hardware requires the structure to be 256 byte alinged. Otherwise #GP(0). */ 42 struct mktme_key_program { 43 u16 keyid; 44 u32 keyid_ctrl; 45 u8 __rsvd[58]; 46 u8 key_field_1[64]; 47 u8 key_field_2[64]; 48 } __packed __aligned(256); 49 50 static inline int mktme_key_program(struct mktme_key_program *key_program) 51 { 52 unsigned long rax = MKTME_KEY_PROGRAM; 53 54 if (!pconfig_target_supported(MKTME_TARGET)) 55 return -ENXIO; 56 57 asm volatile(PCONFIG 58 : "=a" (rax), "=b" (key_program) 59 : "0" (rax), "1" (key_program) 60 : "memory", "cc"); 61 62 return rax; 63 } 64 65 #endif /* _ASM_X86_INTEL_PCONFIG_H */ 66