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