2 * AMD Platform Security Processor (PSP) interface
4 * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
6 * Author: Brijesh Singh <brijesh.singh@amd.com>
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.
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/kthread.h>
16 #include <linux/sched.h>
17 #include <linux/interrupt.h>
18 #include <linux/spinlock.h>
19 #include <linux/spinlock_types.h>
20 #include <linux/types.h>
21 #include <linux/mutex.h>
22 #include <linux/delay.h>
23 #include <linux/hw_random.h>
24 #include <linux/ccp.h>
25 #include <linux/firmware.h>
30 #define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min) \
31 ((psp_master->api_major) >= _maj && \
32 (psp_master->api_minor) >= _min)
34 #define DEVICE_NAME "sev"
35 #define SEV_FW_FILE "amd/sev.fw"
37 static DEFINE_MUTEX(sev_cmd_mutex
);
38 static struct sev_misc_dev
*misc_dev
;
39 static struct psp_device
*psp_master
;
41 static struct psp_device
*psp_alloc_struct(struct sp_device
*sp
)
43 struct device
*dev
= sp
->dev
;
44 struct psp_device
*psp
;
46 psp
= devm_kzalloc(dev
, sizeof(*psp
), GFP_KERNEL
);
53 snprintf(psp
->name
, sizeof(psp
->name
), "psp-%u", sp
->ord
);
58 static irqreturn_t
psp_irq_handler(int irq
, void *data
)
60 struct psp_device
*psp
= data
;
64 /* Read the interrupt status: */
65 status
= ioread32(psp
->io_regs
+ psp
->vdata
->intsts_reg
);
67 /* Check if it is command completion: */
68 if (!(status
& PSP_CMD_COMPLETE
))
71 /* Check if it is SEV command completion: */
72 reg
= ioread32(psp
->io_regs
+ psp
->vdata
->cmdresp_reg
);
73 if (reg
& PSP_CMDRESP_RESP
) {
74 psp
->sev_int_rcvd
= 1;
75 wake_up(&psp
->sev_int_queue
);
79 /* Clear the interrupt status by writing the same value we read. */
80 iowrite32(status
, psp
->io_regs
+ psp
->vdata
->intsts_reg
);
85 static void sev_wait_cmd_ioc(struct psp_device
*psp
, unsigned int *reg
)
87 wait_event(psp
->sev_int_queue
, psp
->sev_int_rcvd
);
88 *reg
= ioread32(psp
->io_regs
+ psp
->vdata
->cmdresp_reg
);
91 static int sev_cmd_buffer_len(int cmd
)
94 case SEV_CMD_INIT
: return sizeof(struct sev_data_init
);
95 case SEV_CMD_PLATFORM_STATUS
: return sizeof(struct sev_user_data_status
);
96 case SEV_CMD_PEK_CSR
: return sizeof(struct sev_data_pek_csr
);
97 case SEV_CMD_PEK_CERT_IMPORT
: return sizeof(struct sev_data_pek_cert_import
);
98 case SEV_CMD_PDH_CERT_EXPORT
: return sizeof(struct sev_data_pdh_cert_export
);
99 case SEV_CMD_LAUNCH_START
: return sizeof(struct sev_data_launch_start
);
100 case SEV_CMD_LAUNCH_UPDATE_DATA
: return sizeof(struct sev_data_launch_update_data
);
101 case SEV_CMD_LAUNCH_UPDATE_VMSA
: return sizeof(struct sev_data_launch_update_vmsa
);
102 case SEV_CMD_LAUNCH_FINISH
: return sizeof(struct sev_data_launch_finish
);
103 case SEV_CMD_LAUNCH_MEASURE
: return sizeof(struct sev_data_launch_measure
);
104 case SEV_CMD_ACTIVATE
: return sizeof(struct sev_data_activate
);
105 case SEV_CMD_DEACTIVATE
: return sizeof(struct sev_data_deactivate
);
106 case SEV_CMD_DECOMMISSION
: return sizeof(struct sev_data_decommission
);
107 case SEV_CMD_GUEST_STATUS
: return sizeof(struct sev_data_guest_status
);
108 case SEV_CMD_DBG_DECRYPT
: return sizeof(struct sev_data_dbg
);
109 case SEV_CMD_DBG_ENCRYPT
: return sizeof(struct sev_data_dbg
);
110 case SEV_CMD_SEND_START
: return sizeof(struct sev_data_send_start
);
111 case SEV_CMD_SEND_UPDATE_DATA
: return sizeof(struct sev_data_send_update_data
);
112 case SEV_CMD_SEND_UPDATE_VMSA
: return sizeof(struct sev_data_send_update_vmsa
);
113 case SEV_CMD_SEND_FINISH
: return sizeof(struct sev_data_send_finish
);
114 case SEV_CMD_RECEIVE_START
: return sizeof(struct sev_data_receive_start
);
115 case SEV_CMD_RECEIVE_FINISH
: return sizeof(struct sev_data_receive_finish
);
116 case SEV_CMD_RECEIVE_UPDATE_DATA
: return sizeof(struct sev_data_receive_update_data
);
117 case SEV_CMD_RECEIVE_UPDATE_VMSA
: return sizeof(struct sev_data_receive_update_vmsa
);
118 case SEV_CMD_LAUNCH_UPDATE_SECRET
: return sizeof(struct sev_data_launch_secret
);
119 case SEV_CMD_DOWNLOAD_FIRMWARE
: return sizeof(struct sev_data_download_firmware
);
120 case SEV_CMD_GET_ID
: return sizeof(struct sev_data_get_id
);
127 static int __sev_do_cmd_locked(int cmd
, void *data
, int *psp_ret
)
129 struct psp_device
*psp
= psp_master
;
130 unsigned int phys_lsb
, phys_msb
;
131 unsigned int reg
, ret
= 0;
136 /* Get the physical address of the command buffer */
137 phys_lsb
= data
? lower_32_bits(__psp_pa(data
)) : 0;
138 phys_msb
= data
? upper_32_bits(__psp_pa(data
)) : 0;
140 dev_dbg(psp
->dev
, "sev command id %#x buffer 0x%08x%08x\n",
141 cmd
, phys_msb
, phys_lsb
);
143 print_hex_dump_debug("(in): ", DUMP_PREFIX_OFFSET
, 16, 2, data
,
144 sev_cmd_buffer_len(cmd
), false);
146 iowrite32(phys_lsb
, psp
->io_regs
+ psp
->vdata
->cmdbuff_addr_lo_reg
);
147 iowrite32(phys_msb
, psp
->io_regs
+ psp
->vdata
->cmdbuff_addr_hi_reg
);
149 psp
->sev_int_rcvd
= 0;
152 reg
<<= PSP_CMDRESP_CMD_SHIFT
;
153 reg
|= PSP_CMDRESP_IOC
;
154 iowrite32(reg
, psp
->io_regs
+ psp
->vdata
->cmdresp_reg
);
156 /* wait for command completion */
157 sev_wait_cmd_ioc(psp
, ®
);
160 *psp_ret
= reg
& PSP_CMDRESP_ERR_MASK
;
162 if (reg
& PSP_CMDRESP_ERR_MASK
) {
163 dev_dbg(psp
->dev
, "sev command %#x failed (%#010x)\n",
164 cmd
, reg
& PSP_CMDRESP_ERR_MASK
);
168 print_hex_dump_debug("(out): ", DUMP_PREFIX_OFFSET
, 16, 2, data
,
169 sev_cmd_buffer_len(cmd
), false);
174 static int sev_do_cmd(int cmd
, void *data
, int *psp_ret
)
178 mutex_lock(&sev_cmd_mutex
);
179 rc
= __sev_do_cmd_locked(cmd
, data
, psp_ret
);
180 mutex_unlock(&sev_cmd_mutex
);
185 static int __sev_platform_init_locked(int *error
)
187 struct psp_device
*psp
= psp_master
;
193 if (psp
->sev_state
== SEV_STATE_INIT
)
196 rc
= __sev_do_cmd_locked(SEV_CMD_INIT
, &psp
->init_cmd_buf
, error
);
200 psp
->sev_state
= SEV_STATE_INIT
;
201 dev_dbg(psp
->dev
, "SEV firmware initialized\n");
206 int sev_platform_init(int *error
)
210 mutex_lock(&sev_cmd_mutex
);
211 rc
= __sev_platform_init_locked(error
);
212 mutex_unlock(&sev_cmd_mutex
);
216 EXPORT_SYMBOL_GPL(sev_platform_init
);
218 static int __sev_platform_shutdown_locked(int *error
)
222 ret
= __sev_do_cmd_locked(SEV_CMD_SHUTDOWN
, NULL
, error
);
226 psp_master
->sev_state
= SEV_STATE_UNINIT
;
227 dev_dbg(psp_master
->dev
, "SEV firmware shutdown\n");
232 static int sev_platform_shutdown(int *error
)
236 mutex_lock(&sev_cmd_mutex
);
237 rc
= __sev_platform_shutdown_locked(NULL
);
238 mutex_unlock(&sev_cmd_mutex
);
243 static int sev_get_platform_state(int *state
, int *error
)
247 rc
= __sev_do_cmd_locked(SEV_CMD_PLATFORM_STATUS
,
248 &psp_master
->status_cmd_buf
, error
);
252 *state
= psp_master
->status_cmd_buf
.state
;
256 static int sev_ioctl_do_reset(struct sev_issue_cmd
*argp
)
261 * The SEV spec requires that FACTORY_RESET must be issued in
262 * UNINIT state. Before we go further lets check if any guest is
265 * If FW is in WORKING state then deny the request otherwise issue
266 * SHUTDOWN command do INIT -> UNINIT before issuing the FACTORY_RESET.
269 rc
= sev_get_platform_state(&state
, &argp
->error
);
273 if (state
== SEV_STATE_WORKING
)
276 if (state
== SEV_STATE_INIT
) {
277 rc
= __sev_platform_shutdown_locked(&argp
->error
);
282 return __sev_do_cmd_locked(SEV_CMD_FACTORY_RESET
, NULL
, &argp
->error
);
285 static int sev_ioctl_do_platform_status(struct sev_issue_cmd
*argp
)
287 struct sev_user_data_status
*data
= &psp_master
->status_cmd_buf
;
290 ret
= __sev_do_cmd_locked(SEV_CMD_PLATFORM_STATUS
, data
, &argp
->error
);
294 if (copy_to_user((void __user
*)argp
->data
, data
, sizeof(*data
)))
300 static int sev_ioctl_do_pek_pdh_gen(int cmd
, struct sev_issue_cmd
*argp
)
304 if (psp_master
->sev_state
== SEV_STATE_UNINIT
) {
305 rc
= __sev_platform_init_locked(&argp
->error
);
310 return __sev_do_cmd_locked(cmd
, NULL
, &argp
->error
);
313 static int sev_ioctl_do_pek_csr(struct sev_issue_cmd
*argp
)
315 struct sev_user_data_pek_csr input
;
316 struct sev_data_pek_csr
*data
;
320 if (copy_from_user(&input
, (void __user
*)argp
->data
, sizeof(input
)))
323 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
327 /* userspace wants to query CSR length */
328 if (!input
.address
|| !input
.length
)
331 /* allocate a physically contiguous buffer to store the CSR blob */
332 if (!access_ok(VERIFY_WRITE
, input
.address
, input
.length
) ||
333 input
.length
> SEV_FW_BLOB_MAX_SIZE
) {
338 blob
= kmalloc(input
.length
, GFP_KERNEL
);
344 data
->address
= __psp_pa(blob
);
345 data
->len
= input
.length
;
348 if (psp_master
->sev_state
== SEV_STATE_UNINIT
) {
349 ret
= __sev_platform_init_locked(&argp
->error
);
354 ret
= __sev_do_cmd_locked(SEV_CMD_PEK_CSR
, data
, &argp
->error
);
356 /* If we query the CSR length, FW responded with expected data. */
357 input
.length
= data
->len
;
359 if (copy_to_user((void __user
*)argp
->data
, &input
, sizeof(input
))) {
365 if (copy_to_user((void __user
*)input
.address
, blob
, input
.length
))
376 void *psp_copy_user_blob(u64 __user uaddr
, u32 len
)
379 return ERR_PTR(-EINVAL
);
381 /* verify that blob length does not exceed our limit */
382 if (len
> SEV_FW_BLOB_MAX_SIZE
)
383 return ERR_PTR(-EINVAL
);
385 return memdup_user((void __user
*)(uintptr_t)uaddr
, len
);
387 EXPORT_SYMBOL_GPL(psp_copy_user_blob
);
389 static int sev_get_api_version(void)
391 struct sev_user_data_status
*status
;
394 status
= &psp_master
->status_cmd_buf
;
395 ret
= sev_platform_status(status
, &error
);
397 dev_err(psp_master
->dev
,
398 "SEV: failed to get status. Error: %#x\n", error
);
402 psp_master
->api_major
= status
->api_major
;
403 psp_master
->api_minor
= status
->api_minor
;
404 psp_master
->build
= status
->build
;
409 /* Don't fail if SEV FW couldn't be updated. Continue with existing SEV FW */
410 static int sev_update_firmware(struct device
*dev
)
412 struct sev_data_download_firmware
*data
;
413 const struct firmware
*firmware
;
414 int ret
, error
, order
;
418 ret
= request_firmware(&firmware
, SEV_FW_FILE
, dev
);
423 * SEV FW expects the physical address given to it to be 32
424 * byte aligned. Memory allocated has structure placed at the
425 * beginning followed by the firmware being passed to the SEV
426 * FW. Allocate enough memory for data structure + alignment
429 data_size
= ALIGN(sizeof(struct sev_data_download_firmware
), 32);
431 order
= get_order(firmware
->size
+ data_size
);
432 p
= alloc_pages(GFP_KERNEL
, order
);
439 * Copy firmware data to a kernel allocated contiguous
442 data
= page_address(p
);
443 memcpy(page_address(p
) + data_size
, firmware
->data
, firmware
->size
);
445 data
->address
= __psp_pa(page_address(p
) + data_size
);
446 data
->len
= firmware
->size
;
448 ret
= sev_do_cmd(SEV_CMD_DOWNLOAD_FIRMWARE
, data
, &error
);
450 dev_dbg(dev
, "Failed to update SEV firmware: %#x\n", error
);
452 dev_info(dev
, "SEV firmware update successful\n");
454 __free_pages(p
, order
);
457 release_firmware(firmware
);
462 static int sev_ioctl_do_pek_import(struct sev_issue_cmd
*argp
)
464 struct sev_user_data_pek_cert_import input
;
465 struct sev_data_pek_cert_import
*data
;
466 void *pek_blob
, *oca_blob
;
469 if (copy_from_user(&input
, (void __user
*)argp
->data
, sizeof(input
)))
472 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
476 /* copy PEK certificate blobs from userspace */
477 pek_blob
= psp_copy_user_blob(input
.pek_cert_address
, input
.pek_cert_len
);
478 if (IS_ERR(pek_blob
)) {
479 ret
= PTR_ERR(pek_blob
);
483 data
->pek_cert_address
= __psp_pa(pek_blob
);
484 data
->pek_cert_len
= input
.pek_cert_len
;
486 /* copy PEK certificate blobs from userspace */
487 oca_blob
= psp_copy_user_blob(input
.oca_cert_address
, input
.oca_cert_len
);
488 if (IS_ERR(oca_blob
)) {
489 ret
= PTR_ERR(oca_blob
);
493 data
->oca_cert_address
= __psp_pa(oca_blob
);
494 data
->oca_cert_len
= input
.oca_cert_len
;
496 /* If platform is not in INIT state then transition it to INIT */
497 if (psp_master
->sev_state
!= SEV_STATE_INIT
) {
498 ret
= __sev_platform_init_locked(&argp
->error
);
503 ret
= __sev_do_cmd_locked(SEV_CMD_PEK_CERT_IMPORT
, data
, &argp
->error
);
514 static int sev_ioctl_do_get_id(struct sev_issue_cmd
*argp
)
516 struct sev_data_get_id
*data
;
517 u64 data_size
, user_size
;
521 /* SEV GET_ID available from SEV API v0.16 and up */
522 if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
525 /* SEV FW expects the buffer it fills with the ID to be
526 * 8-byte aligned. Memory allocated should be enough to
527 * hold data structure + alignment padding + memory
528 * where SEV FW writes the ID.
530 data_size
= ALIGN(sizeof(struct sev_data_get_id
), 8);
531 user_size
= sizeof(struct sev_user_data_get_id
);
533 mem
= kzalloc(data_size
+ user_size
, GFP_KERNEL
);
538 id_blob
= mem
+ data_size
;
540 data
->address
= __psp_pa(id_blob
);
541 data
->len
= user_size
;
543 ret
= __sev_do_cmd_locked(SEV_CMD_GET_ID
, data
, &argp
->error
);
545 if (copy_to_user((void __user
*)argp
->data
, id_blob
, data
->len
))
554 static int sev_ioctl_do_pdh_export(struct sev_issue_cmd
*argp
)
556 struct sev_user_data_pdh_cert_export input
;
557 void *pdh_blob
= NULL
, *cert_blob
= NULL
;
558 struct sev_data_pdh_cert_export
*data
;
561 if (copy_from_user(&input
, (void __user
*)argp
->data
, sizeof(input
)))
564 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
568 /* Userspace wants to query the certificate length. */
569 if (!input
.pdh_cert_address
||
570 !input
.pdh_cert_len
||
571 !input
.cert_chain_address
)
574 /* Allocate a physically contiguous buffer to store the PDH blob. */
575 if ((input
.pdh_cert_len
> SEV_FW_BLOB_MAX_SIZE
) ||
576 !access_ok(VERIFY_WRITE
, input
.pdh_cert_address
, input
.pdh_cert_len
)) {
581 /* Allocate a physically contiguous buffer to store the cert chain blob. */
582 if ((input
.cert_chain_len
> SEV_FW_BLOB_MAX_SIZE
) ||
583 !access_ok(VERIFY_WRITE
, input
.cert_chain_address
, input
.cert_chain_len
)) {
588 pdh_blob
= kmalloc(input
.pdh_cert_len
, GFP_KERNEL
);
594 data
->pdh_cert_address
= __psp_pa(pdh_blob
);
595 data
->pdh_cert_len
= input
.pdh_cert_len
;
597 cert_blob
= kmalloc(input
.cert_chain_len
, GFP_KERNEL
);
603 data
->cert_chain_address
= __psp_pa(cert_blob
);
604 data
->cert_chain_len
= input
.cert_chain_len
;
607 /* If platform is not in INIT state then transition it to INIT. */
608 if (psp_master
->sev_state
!= SEV_STATE_INIT
) {
609 ret
= __sev_platform_init_locked(&argp
->error
);
614 ret
= __sev_do_cmd_locked(SEV_CMD_PDH_CERT_EXPORT
, data
, &argp
->error
);
616 /* If we query the length, FW responded with expected data. */
617 input
.cert_chain_len
= data
->cert_chain_len
;
618 input
.pdh_cert_len
= data
->pdh_cert_len
;
620 if (copy_to_user((void __user
*)argp
->data
, &input
, sizeof(input
))) {
626 if (copy_to_user((void __user
*)input
.pdh_cert_address
,
627 pdh_blob
, input
.pdh_cert_len
)) {
634 if (copy_to_user((void __user
*)input
.cert_chain_address
,
635 cert_blob
, input
.cert_chain_len
))
648 static long sev_ioctl(struct file
*file
, unsigned int ioctl
, unsigned long arg
)
650 void __user
*argp
= (void __user
*)arg
;
651 struct sev_issue_cmd input
;
657 if (ioctl
!= SEV_ISSUE_CMD
)
660 if (copy_from_user(&input
, argp
, sizeof(struct sev_issue_cmd
)))
663 if (input
.cmd
> SEV_MAX
)
666 mutex_lock(&sev_cmd_mutex
);
670 case SEV_FACTORY_RESET
:
671 ret
= sev_ioctl_do_reset(&input
);
673 case SEV_PLATFORM_STATUS
:
674 ret
= sev_ioctl_do_platform_status(&input
);
677 ret
= sev_ioctl_do_pek_pdh_gen(SEV_CMD_PEK_GEN
, &input
);
680 ret
= sev_ioctl_do_pek_pdh_gen(SEV_CMD_PDH_GEN
, &input
);
683 ret
= sev_ioctl_do_pek_csr(&input
);
685 case SEV_PEK_CERT_IMPORT
:
686 ret
= sev_ioctl_do_pek_import(&input
);
688 case SEV_PDH_CERT_EXPORT
:
689 ret
= sev_ioctl_do_pdh_export(&input
);
692 ret
= sev_ioctl_do_get_id(&input
);
699 if (copy_to_user(argp
, &input
, sizeof(struct sev_issue_cmd
)))
702 mutex_unlock(&sev_cmd_mutex
);
707 static const struct file_operations sev_fops
= {
708 .owner
= THIS_MODULE
,
709 .unlocked_ioctl
= sev_ioctl
,
712 int sev_platform_status(struct sev_user_data_status
*data
, int *error
)
714 return sev_do_cmd(SEV_CMD_PLATFORM_STATUS
, data
, error
);
716 EXPORT_SYMBOL_GPL(sev_platform_status
);
718 int sev_guest_deactivate(struct sev_data_deactivate
*data
, int *error
)
720 return sev_do_cmd(SEV_CMD_DEACTIVATE
, data
, error
);
722 EXPORT_SYMBOL_GPL(sev_guest_deactivate
);
724 int sev_guest_activate(struct sev_data_activate
*data
, int *error
)
726 return sev_do_cmd(SEV_CMD_ACTIVATE
, data
, error
);
728 EXPORT_SYMBOL_GPL(sev_guest_activate
);
730 int sev_guest_decommission(struct sev_data_decommission
*data
, int *error
)
732 return sev_do_cmd(SEV_CMD_DECOMMISSION
, data
, error
);
734 EXPORT_SYMBOL_GPL(sev_guest_decommission
);
736 int sev_guest_df_flush(int *error
)
738 return sev_do_cmd(SEV_CMD_DF_FLUSH
, NULL
, error
);
740 EXPORT_SYMBOL_GPL(sev_guest_df_flush
);
742 static void sev_exit(struct kref
*ref
)
744 struct sev_misc_dev
*misc_dev
= container_of(ref
, struct sev_misc_dev
, refcount
);
746 misc_deregister(&misc_dev
->misc
);
749 static int sev_misc_init(struct psp_device
*psp
)
751 struct device
*dev
= psp
->dev
;
755 * SEV feature support can be detected on multiple devices but the SEV
756 * FW commands must be issued on the master. During probe, we do not
757 * know the master hence we create /dev/sev on the first device probe.
758 * sev_do_cmd() finds the right master device to which to issue the
759 * command to the firmware.
762 struct miscdevice
*misc
;
764 misc_dev
= devm_kzalloc(dev
, sizeof(*misc_dev
), GFP_KERNEL
);
768 misc
= &misc_dev
->misc
;
769 misc
->minor
= MISC_DYNAMIC_MINOR
;
770 misc
->name
= DEVICE_NAME
;
771 misc
->fops
= &sev_fops
;
773 ret
= misc_register(misc
);
777 kref_init(&misc_dev
->refcount
);
779 kref_get(&misc_dev
->refcount
);
782 init_waitqueue_head(&psp
->sev_int_queue
);
783 psp
->sev_misc
= misc_dev
;
784 dev_dbg(dev
, "registered SEV device\n");
789 static int sev_init(struct psp_device
*psp
)
791 /* Check if device supports SEV feature */
792 if (!(ioread32(psp
->io_regs
+ psp
->vdata
->feature_reg
) & 1)) {
793 dev_dbg(psp
->dev
, "device does not support SEV\n");
797 return sev_misc_init(psp
);
800 int psp_dev_init(struct sp_device
*sp
)
802 struct device
*dev
= sp
->dev
;
803 struct psp_device
*psp
;
807 psp
= psp_alloc_struct(sp
);
813 psp
->vdata
= (struct psp_vdata
*)sp
->dev_vdata
->psp_vdata
;
816 dev_err(dev
, "missing driver data\n");
820 psp
->io_regs
= sp
->io_map
;
822 /* Disable and clear interrupts until ready */
823 iowrite32(0, psp
->io_regs
+ psp
->vdata
->inten_reg
);
824 iowrite32(-1, psp
->io_regs
+ psp
->vdata
->intsts_reg
);
827 ret
= sp_request_psp_irq(psp
->sp
, psp_irq_handler
, psp
->name
, psp
);
829 dev_err(dev
, "psp: unable to allocate an IRQ\n");
837 if (sp
->set_psp_master_device
)
838 sp
->set_psp_master_device(sp
);
840 /* Enable interrupt */
841 iowrite32(-1, psp
->io_regs
+ psp
->vdata
->inten_reg
);
843 dev_notice(dev
, "psp enabled\n");
848 sp_free_psp_irq(psp
->sp
, psp
);
852 dev_notice(dev
, "psp initialization failed\n");
857 void psp_dev_destroy(struct sp_device
*sp
)
859 struct psp_device
*psp
= sp
->psp_data
;
865 kref_put(&misc_dev
->refcount
, sev_exit
);
867 sp_free_psp_irq(sp
, psp
);
870 int sev_issue_cmd_external_user(struct file
*filep
, unsigned int cmd
,
871 void *data
, int *error
)
873 if (!filep
|| filep
->f_op
!= &sev_fops
)
876 return sev_do_cmd(cmd
, data
, error
);
878 EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user
);
880 void psp_pci_init(void)
882 struct sp_device
*sp
;
885 sp
= sp_get_psp_master_device();
889 psp_master
= sp
->psp_data
;
891 if (sev_get_api_version())
894 if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) &&
895 sev_update_firmware(psp_master
->dev
) == 0)
896 sev_get_api_version();
898 /* Initialize the platform */
899 rc
= sev_platform_init(&error
);
901 dev_err(sp
->dev
, "SEV: failed to INIT error %#x\n", error
);
905 dev_info(sp
->dev
, "SEV API:%d.%d build:%d\n", psp_master
->api_major
,
906 psp_master
->api_minor
, psp_master
->build
);
914 void psp_pci_exit(void)
919 sev_platform_shutdown(NULL
);