1 /*
2 * AWS Nitro Secure Module (NSM) device
3 *
4 * Copyright (c) 2024 Dorjoy Chowdhury <dorjoychy111@gmail.com>
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * (at your option) any later version. See the COPYING file in the
8 * top-level directory.
9 */
10
11 #include "qemu/osdep.h"
12
13 #include "hw/virtio/virtio-pci.h"
14 #include "hw/virtio/virtio-nsm.h"
15 #include "hw/qdev-properties.h"
16 #include "qapi/error.h"
17 #include "qemu/module.h"
18 #include "qom/object.h"
19
20 typedef struct VirtIONsmPCI VirtIONsmPCI;
21
22 #define TYPE_VIRTIO_NSM_PCI "virtio-nsm-pci-base"
23 DECLARE_INSTANCE_CHECKER(VirtIONsmPCI, VIRTIO_NSM_PCI,
24 TYPE_VIRTIO_NSM_PCI)
25
26 struct VirtIONsmPCI {
27 VirtIOPCIProxy parent_obj;
28 VirtIONSM vdev;
29 };
30
virtio_nsm_pci_realize(VirtIOPCIProxy * vpci_dev,Error ** errp)31 static void virtio_nsm_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
32 {
33 VirtIONsmPCI *vnsm = VIRTIO_NSM_PCI(vpci_dev);
34 DeviceState *vdev = DEVICE(&vnsm->vdev);
35
36 virtio_pci_force_virtio_1(vpci_dev);
37
38 if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
39 return;
40 }
41 }
42
virtio_nsm_pci_class_init(ObjectClass * klass,void * data)43 static void virtio_nsm_pci_class_init(ObjectClass *klass, void *data)
44 {
45 DeviceClass *dc = DEVICE_CLASS(klass);
46 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
47
48 k->realize = virtio_nsm_pci_realize;
49 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
50 }
51
virtio_nsm_initfn(Object * obj)52 static void virtio_nsm_initfn(Object *obj)
53 {
54 VirtIONsmPCI *dev = VIRTIO_NSM_PCI(obj);
55
56 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
57 TYPE_VIRTIO_NSM);
58 }
59
60 static const VirtioPCIDeviceTypeInfo virtio_nsm_pci_info = {
61 .base_name = TYPE_VIRTIO_NSM_PCI,
62 .generic_name = "virtio-nsm-pci",
63 .instance_size = sizeof(VirtIONsmPCI),
64 .instance_init = virtio_nsm_initfn,
65 .class_init = virtio_nsm_pci_class_init,
66 };
67
virtio_nsm_pci_register(void)68 static void virtio_nsm_pci_register(void)
69 {
70 virtio_pci_types_register(&virtio_nsm_pci_info);
71 }
72
73 type_init(virtio_nsm_pci_register)
74