blob: 994638ef171bec62782bdee78fe01061fa2acba6 [file] [log] [blame]
Kirill A. Shutemovbe7825c2018-03-05 19:25:52 +03001#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
7enum pconfig_target {
8 INVALID_TARGET = 0,
9 MKTME_TARGET = 1,
10 PCONFIG_TARGET_NR
11};
12
13int pconfig_target_supported(enum pconfig_target target);
14
Kirill A. Shutemov24c51782018-03-05 19:25:53 +030015enum 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
Ingo Molnard9f6e122021-03-18 15:28:01 +010041/* Hardware requires the structure to be 256 byte aligned. Otherwise #GP(0). */
Kirill A. Shutemov24c51782018-03-05 19:25:53 +030042struct 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
50static 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
Kirill A. Shutemovbe7825c2018-03-05 19:25:52 +030065#endif /* _ASM_X86_INTEL_PCONFIG_H */