crypto: ccp - Move direct access to some PSP registers out of TEE
[sfrench/cifs-2.6.git] / drivers / crypto / ccp / psp-dev.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * AMD Platform Security Processor (PSP) interface driver
4  *
5  * Copyright (C) 2017-2019 Advanced Micro Devices, Inc.
6  *
7  * Author: Brijesh Singh <brijesh.singh@amd.com>
8  */
9
10 #ifndef __PSP_DEV_H__
11 #define __PSP_DEV_H__
12
13 #include <linux/device.h>
14 #include <linux/list.h>
15 #include <linux/bits.h>
16 #include <linux/interrupt.h>
17 #include <linux/mutex.h>
18 #include <linux/psp.h>
19
20 #include "sp-dev.h"
21
22 #define MAX_PSP_NAME_LEN                16
23
24 extern struct psp_device *psp_master;
25
26 typedef void (*psp_irq_handler_t)(int, void *, unsigned int);
27
28 struct psp_device {
29         struct list_head entry;
30
31         struct psp_vdata *vdata;
32         char name[MAX_PSP_NAME_LEN];
33
34         struct device *dev;
35         struct sp_device *sp;
36
37         void __iomem *io_regs;
38         struct mutex mailbox_mutex;
39
40         psp_irq_handler_t sev_irq_handler;
41         void *sev_irq_data;
42
43         void *sev_data;
44         void *tee_data;
45         void *platform_access_data;
46         void *dbc_data;
47
48         unsigned int capability;
49 };
50
51 void psp_set_sev_irq_handler(struct psp_device *psp, psp_irq_handler_t handler,
52                              void *data);
53 void psp_clear_sev_irq_handler(struct psp_device *psp);
54
55 struct psp_device *psp_get_master_device(void);
56
57 #define PSP_CAPABILITY_SEV                      BIT(0)
58 #define PSP_CAPABILITY_TEE                      BIT(1)
59 #define PSP_CAPABILITY_PSP_SECURITY_REPORTING   BIT(7)
60
61 #define PSP_CAPABILITY_PSP_SECURITY_OFFSET      8
62 /*
63  * The PSP doesn't directly store these bits in the capability register
64  * but instead copies them from the results of query command.
65  *
66  * The offsets from the query command are below, and shifted when used.
67  */
68 #define PSP_SECURITY_FUSED_PART                 BIT(0)
69 #define PSP_SECURITY_DEBUG_LOCK_ON              BIT(2)
70 #define PSP_SECURITY_TSME_STATUS                BIT(5)
71 #define PSP_SECURITY_ANTI_ROLLBACK_STATUS       BIT(7)
72 #define PSP_SECURITY_RPMC_PRODUCTION_ENABLED    BIT(8)
73 #define PSP_SECURITY_RPMC_SPIROM_AVAILABLE      BIT(9)
74 #define PSP_SECURITY_HSP_TPM_AVAILABLE          BIT(10)
75 #define PSP_SECURITY_ROM_ARMOR_ENFORCED         BIT(11)
76
77 /**
78  * enum psp_cmd - PSP mailbox commands
79  * @PSP_CMD_TEE_RING_INIT:      Initialize TEE ring buffer
80  * @PSP_CMD_TEE_RING_DESTROY:   Destroy TEE ring buffer
81  * @PSP_CMD_MAX:                Maximum command id
82  */
83 enum psp_cmd {
84         PSP_CMD_TEE_RING_INIT           = 1,
85         PSP_CMD_TEE_RING_DESTROY        = 2,
86         PSP_CMD_MAX                     = 15,
87 };
88
89 int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff,
90                         unsigned int timeout_msecs, unsigned int *cmdresp);
91
92 #endif /* __PSP_DEV_H */