| 1 |
|
| 2 | |
| 3 | * AMD Platform Security Processor (PSP) interface driver
|
| 4 | *
|
| 5 | * Copyright (C) 2017-2019 Advanced Micro Devices, Inc.
|
| 6 | *
|
| 7 | * Author: Brijesh Singh <[email protected]>
|
| 8 |
|
| 9 |
|
| 10 | #ifndef __SEV_DEV_H__
|
| 11 | #define __SEV_DEV_H__
|
| 12 |
|
| 13 | #include <linux/device.h>
|
| 14 | #include <linux/spinlock.h>
|
| 15 | #include <linux/mutex.h>
|
| 16 | #include <linux/list.h>
|
| 17 | #include <linux/wait.h>
|
| 18 | #include <linux/dmapool.h>
|
| 19 | #include <linux/hw_random.h>
|
| 20 | #include <linux/bitops.h>
|
| 21 | #include <linux/interrupt.h>
|
| 22 | #include <linux/irqreturn.h>
|
| 23 | #include <linux/dmaengine.h>
|
| 24 | #include <linux/psp-sev.h>
|
| 25 | #include <linux/miscdevice.h>
|
| 26 | #include <linux/capability.h>
|
| 27 |
|
| 28 | #define SEV_CMDRESP_CMD GENMASK(26, 16)
|
| 29 | #define SEV_CMD_COMPLETE BIT(1)
|
| 30 | #define SEV_CMDRESP_IOC BIT(0)
|
| 31 |
|
| 32 | struct sev_misc_dev {
|
| 33 | struct kref refcount;
|
| 34 | struct miscdevice misc;
|
| 35 | };
|
| 36 |
|
| 37 | struct sev_tio_status;
|
| 38 |
|
| 39 | struct sev_device {
|
| 40 | struct device *dev;
|
| 41 | struct psp_device *psp;
|
| 42 |
|
| 43 | void __iomem *io_regs;
|
| 44 |
|
| 45 | struct sev_vdata *vdata;
|
| 46 |
|
| 47 | unsigned int int_rcvd;
|
| 48 | wait_queue_head_t int_queue;
|
| 49 | struct sev_misc_dev *misc;
|
| 50 |
|
| 51 | u8 api_major;
|
| 52 | u8 api_minor;
|
| 53 | u8 build;
|
| 54 |
|
| 55 | void *cmd_buf;
|
| 56 | void *cmd_buf_backup;
|
| 57 | bool cmd_buf_active;
|
| 58 | bool cmd_buf_backup_active;
|
| 59 |
|
| 60 | bool snp_initialized;
|
| 61 |
|
| 62 | struct kobject *sev_kobj;
|
| 63 | struct kobject *verify_mit;
|
| 64 |
|
| 65 | struct sev_user_data_status sev_plat_status;
|
| 66 |
|
| 67 | struct sev_user_data_snp_status snp_plat_status;
|
| 68 | struct snp_feature_info snp_feat_info_0;
|
| 69 |
|
| 70 | struct tsm_dev *tsmdev;
|
| 71 | struct sev_tio_status *tio_status;
|
| 72 | };
|
| 73 |
|
| 74 | int sev_dev_init(struct psp_device *psp);
|
| 75 | void sev_dev_destroy(struct psp_device *psp);
|
| 76 |
|
| 77 | int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret);
|
| 78 |
|
| 79 | void sev_pci_init(void);
|
| 80 | void sev_pci_exit(void);
|
| 81 |
|
| 82 | struct page *snp_alloc_hv_fixed_pages(unsigned int num_2mb_pages);
|
| 83 | void snp_free_hv_fixed_pages(struct page *page);
|
| 84 |
|
| 85 | void sev_tsm_init_locked(struct sev_device *sev, void *tio_status_page);
|
| 86 | void sev_tsm_uninit(struct sev_device *sev);
|
| 87 | int sev_tio_cmd_buffer_len(int cmd);
|
| 88 |
|
| 89 | #endif
|