1 // SPDX-License-Identifier: GPL-2.0
3 * TDX guest user interface driver
5 * Copyright (C) 2022 Intel Corporation
8 #include <linux/kernel.h>
9 #include <linux/miscdevice.h>
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/string.h>
14 #include <linux/uaccess.h>
16 #include <uapi/linux/tdx-guest.h>
18 #include <asm/cpu_device_id.h>
21 static long tdx_get_report0(struct tdx_report_req __user *req)
23 u8 *reportdata, *tdreport;
26 reportdata = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL);
30 tdreport = kzalloc(TDX_REPORT_LEN, GFP_KERNEL);
36 if (copy_from_user(reportdata, req->reportdata, TDX_REPORTDATA_LEN)) {
41 /* Generate TDREPORT0 using "TDG.MR.REPORT" TDCALL */
42 ret = tdx_mcall_get_report0(reportdata, tdreport);
46 if (copy_to_user(req->tdreport, tdreport, TDX_REPORT_LEN))
56 static long tdx_guest_ioctl(struct file *file, unsigned int cmd,
60 case TDX_CMD_GET_REPORT0:
61 return tdx_get_report0((struct tdx_report_req __user *)arg);
67 static const struct file_operations tdx_guest_fops = {
69 .unlocked_ioctl = tdx_guest_ioctl,
73 static struct miscdevice tdx_misc_dev = {
74 .name = KBUILD_MODNAME,
75 .minor = MISC_DYNAMIC_MINOR,
76 .fops = &tdx_guest_fops,
79 static const struct x86_cpu_id tdx_guest_ids[] = {
80 X86_MATCH_FEATURE(X86_FEATURE_TDX_GUEST, NULL),
83 MODULE_DEVICE_TABLE(x86cpu, tdx_guest_ids);
85 static int __init tdx_guest_init(void)
87 if (!x86_match_cpu(tdx_guest_ids))
90 return misc_register(&tdx_misc_dev);
92 module_init(tdx_guest_init);
94 static void __exit tdx_guest_exit(void)
96 misc_deregister(&tdx_misc_dev);
98 module_exit(tdx_guest_exit);
101 MODULE_DESCRIPTION("TDX Guest Driver");
102 MODULE_LICENSE("GPL");