#include <linux/bitfield.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/spinlock_types.h>
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/hw_random.h>
#include <linux/ccp.h>
#include <linux/firmware.h>
#include <linux/panic_notifier.h>
#include <linux/gfp.h>
#include <linux/cpufeature.h>
#include <linux/fs.h>
#include <linux/fs_struct.h>
#include <linux/psp.h>
#include <linux/amd-iommu.h>
#include <asm/smp.h>
#include <asm/cacheflush.h>
#include <asm/e820/types.h>
#include <asm/sev.h>
#include "psp-dev.h"
#include "sev-dev.h"
#define DEVICE_NAME …
#define SEV_FW_FILE …
#define SEV_FW_NAME_SIZE …
#define SNP_MIN_API_MAJOR …
#define SNP_MIN_API_MINOR …
#define CMD_BUF_FW_WRITABLE_MAX …
#define CMD_BUF_DESC_MAX …
static DEFINE_MUTEX(sev_cmd_mutex);
static struct sev_misc_dev *misc_dev;
static int psp_cmd_timeout = …;
module_param(psp_cmd_timeout, int, 0644);
MODULE_PARM_DESC(…) …;
static int psp_probe_timeout = …;
module_param(psp_probe_timeout, int, 0644);
MODULE_PARM_DESC(…) …;
static char *init_ex_path;
module_param(init_ex_path, charp, 0444);
MODULE_PARM_DESC(…) …;
static bool psp_init_on_probe = …;
module_param(psp_init_on_probe, bool, 0444);
MODULE_PARM_DESC(…) …;
MODULE_FIRMWARE(…) …;
MODULE_FIRMWARE(…) …;
MODULE_FIRMWARE(…) …;
MODULE_FIRMWARE(…) …;
static bool psp_dead;
static int psp_timeout;
#define SEV_TMR_SIZE …
#define SNP_TMR_SIZE …
static void *sev_es_tmr;
static size_t sev_es_tmr_size = …;
#define NV_LENGTH …
static void *sev_init_ex_buffer;
static struct sev_data_range_list *snp_range_list;
static inline bool sev_version_greater_or_equal(u8 maj, u8 min)
{ … }
static void sev_irq_handler(int irq, void *data, unsigned int status)
{ … }
static int sev_wait_cmd_ioc(struct sev_device *sev,
unsigned int *reg, unsigned int timeout)
{ … }
static int sev_cmd_buffer_len(int cmd)
{ … }
static struct file *open_file_as_root(const char *filename, int flags, umode_t mode)
{ … }
static int sev_read_init_ex_file(void)
{ … }
static int sev_write_init_ex_file(void)
{ … }
static int sev_write_init_ex_file_if_required(int cmd_id)
{ … }
static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret);
static int snp_reclaim_pages(unsigned long paddr, unsigned int npages, bool locked)
{ … }
static int rmp_mark_pages_firmware(unsigned long paddr, unsigned int npages, bool locked)
{ … }
static struct page *__snp_alloc_firmware_pages(gfp_t gfp_mask, int order)
{ … }
void *snp_alloc_firmware_page(gfp_t gfp_mask)
{ … }
EXPORT_SYMBOL_GPL(…);
static void __snp_free_firmware_pages(struct page *page, int order, bool locked)
{ … }
void snp_free_firmware_page(void *addr)
{ … }
EXPORT_SYMBOL_GPL(…);
static void *sev_fw_alloc(unsigned long len)
{ … }
struct cmd_buf_desc { … };
static void snp_populate_cmd_buf_desc_list(int cmd, void *cmd_buf,
struct cmd_buf_desc *desc_list)
{ … }
static int snp_map_cmd_buf_desc(struct cmd_buf_desc *desc)
{ … }
static int snp_unmap_cmd_buf_desc(struct cmd_buf_desc *desc)
{ … }
static int snp_map_cmd_buf_desc_list(int cmd, void *cmd_buf, struct cmd_buf_desc *desc_list)
{ … }
static int snp_unmap_cmd_buf_desc_list(struct cmd_buf_desc *desc_list)
{ … }
static bool sev_cmd_buf_writable(int cmd)
{ … }
static bool snp_legacy_handling_needed(int cmd)
{ … }
static int snp_prep_cmd_buf(int cmd, void *cmd_buf, struct cmd_buf_desc *desc_list)
{ … }
static int snp_reclaim_cmd_buf(int cmd, void *cmd_buf)
{ … }
static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
{ … }
int sev_do_cmd(int cmd, void *data, int *psp_ret)
{ … }
EXPORT_SYMBOL_GPL(…);
static int __sev_init_locked(int *error)
{ … }
static int __sev_init_ex_locked(int *error)
{ … }
static inline int __sev_do_init_locked(int *psp_ret)
{ … }
static void snp_set_hsave_pa(void *arg)
{ … }
static int snp_filter_reserved_mem_regions(struct resource *rs, void *arg)
{ … }
static int __sev_snp_init_locked(int *error)
{ … }
static void __sev_platform_init_handle_tmr(struct sev_device *sev)
{ … }
static int __sev_platform_init_handle_init_ex_path(struct sev_device *sev)
{ … }
static int __sev_platform_init_locked(int *error)
{ … }
static int _sev_platform_init_locked(struct sev_platform_init_args *args)
{ … }
int sev_platform_init(struct sev_platform_init_args *args)
{ … }
EXPORT_SYMBOL_GPL(…);
static int __sev_platform_shutdown_locked(int *error)
{ … }
static int sev_get_platform_state(int *state, int *error)
{ … }
static int sev_ioctl_do_reset(struct sev_issue_cmd *argp, bool writable)
{ … }
static int sev_ioctl_do_platform_status(struct sev_issue_cmd *argp)
{ … }
static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool writable)
{ … }
static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable)
{ … }
void *psp_copy_user_blob(u64 uaddr, u32 len)
{ … }
EXPORT_SYMBOL_GPL(…);
static int sev_get_api_version(void)
{ … }
static int sev_get_firmware(struct device *dev,
const struct firmware **firmware)
{ … }
static int sev_update_firmware(struct device *dev)
{ … }
static int __sev_snp_shutdown_locked(int *error, bool panic)
{ … }
static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable)
{ … }
static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
{ … }
static int sev_ioctl_do_get_id(struct sev_issue_cmd *argp)
{ … }
static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
{ … }
static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp)
{ … }
static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp)
{ … }
static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable)
{ … }
static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool writable)
{ … }
static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
{ … }
static const struct file_operations sev_fops = …;
int sev_platform_status(struct sev_user_data_status *data, int *error)
{ … }
EXPORT_SYMBOL_GPL(…);
int sev_guest_deactivate(struct sev_data_deactivate *data, int *error)
{ … }
EXPORT_SYMBOL_GPL(…);
int sev_guest_activate(struct sev_data_activate *data, int *error)
{ … }
EXPORT_SYMBOL_GPL(…);
int sev_guest_decommission(struct sev_data_decommission *data, int *error)
{ … }
EXPORT_SYMBOL_GPL(…);
int sev_guest_df_flush(int *error)
{ … }
EXPORT_SYMBOL_GPL(…);
static void sev_exit(struct kref *ref)
{ … }
static int sev_misc_init(struct sev_device *sev)
{ … }
int sev_dev_init(struct psp_device *psp)
{ … }
static void __sev_firmware_shutdown(struct sev_device *sev, bool panic)
{ … }
static void sev_firmware_shutdown(struct sev_device *sev)
{ … }
void sev_dev_destroy(struct psp_device *psp)
{ … }
static int snp_shutdown_on_panic(struct notifier_block *nb,
unsigned long reason, void *arg)
{ … }
static struct notifier_block snp_panic_notifier = …;
int sev_issue_cmd_external_user(struct file *filep, unsigned int cmd,
void *data, int *error)
{ … }
EXPORT_SYMBOL_GPL(…);
void sev_pci_init(void)
{ … }
void sev_pci_exit(void)
{ … }