18c2ecf20Sopenharmony_ci#ifndef _ASM_X86_INTEL_PCONFIG_H 28c2ecf20Sopenharmony_ci#define _ASM_X86_INTEL_PCONFIG_H 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include <asm/asm.h> 58c2ecf20Sopenharmony_ci#include <asm/processor.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_cienum pconfig_target { 88c2ecf20Sopenharmony_ci INVALID_TARGET = 0, 98c2ecf20Sopenharmony_ci MKTME_TARGET = 1, 108c2ecf20Sopenharmony_ci PCONFIG_TARGET_NR 118c2ecf20Sopenharmony_ci}; 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciint pconfig_target_supported(enum pconfig_target target); 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cienum pconfig_leaf { 168c2ecf20Sopenharmony_ci MKTME_KEY_PROGRAM = 0, 178c2ecf20Sopenharmony_ci PCONFIG_LEAF_INVALID, 188c2ecf20Sopenharmony_ci}; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define PCONFIG ".byte 0x0f, 0x01, 0xc5" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* Defines and structure for MKTME_KEY_PROGRAM of PCONFIG instruction */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* mktme_key_program::keyid_ctrl COMMAND, bits [7:0] */ 258c2ecf20Sopenharmony_ci#define MKTME_KEYID_SET_KEY_DIRECT 0 268c2ecf20Sopenharmony_ci#define MKTME_KEYID_SET_KEY_RANDOM 1 278c2ecf20Sopenharmony_ci#define MKTME_KEYID_CLEAR_KEY 2 288c2ecf20Sopenharmony_ci#define MKTME_KEYID_NO_ENCRYPT 3 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* mktme_key_program::keyid_ctrl ENC_ALG, bits [23:8] */ 318c2ecf20Sopenharmony_ci#define MKTME_AES_XTS_128 (1 << 8) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* Return codes from the PCONFIG MKTME_KEY_PROGRAM */ 348c2ecf20Sopenharmony_ci#define MKTME_PROG_SUCCESS 0 358c2ecf20Sopenharmony_ci#define MKTME_INVALID_PROG_CMD 1 368c2ecf20Sopenharmony_ci#define MKTME_ENTROPY_ERROR 2 378c2ecf20Sopenharmony_ci#define MKTME_INVALID_KEYID 3 388c2ecf20Sopenharmony_ci#define MKTME_INVALID_ENC_ALG 4 398c2ecf20Sopenharmony_ci#define MKTME_DEVICE_BUSY 5 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* Hardware requires the structure to be 256 byte alinged. Otherwise #GP(0). */ 428c2ecf20Sopenharmony_cistruct mktme_key_program { 438c2ecf20Sopenharmony_ci u16 keyid; 448c2ecf20Sopenharmony_ci u32 keyid_ctrl; 458c2ecf20Sopenharmony_ci u8 __rsvd[58]; 468c2ecf20Sopenharmony_ci u8 key_field_1[64]; 478c2ecf20Sopenharmony_ci u8 key_field_2[64]; 488c2ecf20Sopenharmony_ci} __packed __aligned(256); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic inline int mktme_key_program(struct mktme_key_program *key_program) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci unsigned long rax = MKTME_KEY_PROGRAM; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci if (!pconfig_target_supported(MKTME_TARGET)) 558c2ecf20Sopenharmony_ci return -ENXIO; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci asm volatile(PCONFIG 588c2ecf20Sopenharmony_ci : "=a" (rax), "=b" (key_program) 598c2ecf20Sopenharmony_ci : "0" (rax), "1" (key_program) 608c2ecf20Sopenharmony_ci : "memory", "cc"); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci return rax; 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#endif /* _ASM_X86_INTEL_PCONFIG_H */ 66