1 /* 2 * AMD Platform Security Processor (PSP) interface driver 3 * 4 * Copyright (C) 2017 Advanced Micro Devices, Inc. 5 * 6 * Author: Brijesh Singh <brijesh.singh@amd.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 */ 12 13 #ifndef __PSP_DEV_H__ 14 #define __PSP_DEV_H__ 15 16 #include <linux/device.h> 17 #include <linux/pci.h> 18 #include <linux/spinlock.h> 19 #include <linux/mutex.h> 20 #include <linux/list.h> 21 #include <linux/wait.h> 22 #include <linux/dmapool.h> 23 #include <linux/hw_random.h> 24 #include <linux/bitops.h> 25 #include <linux/interrupt.h> 26 #include <linux/irqreturn.h> 27 #include <linux/dmaengine.h> 28 #include <linux/psp-sev.h> 29 #include <linux/miscdevice.h> 30 31 #include "sp-dev.h" 32 33 #define PSP_C2PMSG(_num) ((_num) << 2) 34 #define PSP_CMDRESP PSP_C2PMSG(32) 35 #define PSP_CMDBUFF_ADDR_LO PSP_C2PMSG(56) 36 #define PSP_CMDBUFF_ADDR_HI PSP_C2PMSG(57) 37 #define PSP_FEATURE_REG PSP_C2PMSG(63) 38 39 #define PSP_CMD_COMPLETE BIT(1) 40 41 #define PSP_P2CMSG_INTEN 0x0110 42 #define PSP_P2CMSG_INTSTS 0x0114 43 44 #define PSP_CMDRESP_CMD_SHIFT 16 45 #define PSP_CMDRESP_IOC BIT(0) 46 #define PSP_CMDRESP_RESP BIT(31) 47 #define PSP_CMDRESP_ERR_MASK 0xffff 48 49 #define MAX_PSP_NAME_LEN 16 50 51 struct sev_misc_dev { 52 struct kref refcount; 53 struct miscdevice misc; 54 }; 55 56 struct psp_device { 57 struct list_head entry; 58 59 struct psp_vdata *vdata; 60 char name[MAX_PSP_NAME_LEN]; 61 62 struct device *dev; 63 struct sp_device *sp; 64 65 void __iomem *io_regs; 66 67 int sev_state; 68 unsigned int sev_int_rcvd; 69 wait_queue_head_t sev_int_queue; 70 struct sev_misc_dev *sev_misc; 71 struct sev_user_data_status status_cmd_buf; 72 struct sev_data_init init_cmd_buf; 73 74 u8 api_major; 75 u8 api_minor; 76 u8 build; 77 }; 78 79 #endif /* __PSP_DEV_H */ 80