cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

vhost-user-vsock-pci.c (2699B)


      1/*
      2 * Vhost-user vsock PCI Bindings
      3 *
      4 * Copyright 2020 Red Hat, Inc.
      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 "virtio-pci.h"
     14#include "hw/qdev-properties.h"
     15#include "hw/virtio/vhost-user-vsock.h"
     16#include "qom/object.h"
     17
     18typedef struct VHostUserVSockPCI VHostUserVSockPCI;
     19
     20/*
     21 * vhost-user-vsock-pci: This extends VirtioPCIProxy.
     22 */
     23#define TYPE_VHOST_USER_VSOCK_PCI "vhost-user-vsock-pci-base"
     24DECLARE_INSTANCE_CHECKER(VHostUserVSockPCI, VHOST_USER_VSOCK_PCI,
     25                         TYPE_VHOST_USER_VSOCK_PCI)
     26
     27struct VHostUserVSockPCI {
     28    VirtIOPCIProxy parent_obj;
     29    VHostUserVSock vdev;
     30};
     31
     32/* vhost-user-vsock-pci */
     33
     34static Property vhost_user_vsock_pci_properties[] = {
     35    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
     36    DEFINE_PROP_END_OF_LIST(),
     37};
     38
     39static void vhost_user_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     40{
     41    VHostUserVSockPCI *dev = VHOST_USER_VSOCK_PCI(vpci_dev);
     42    DeviceState *vdev = DEVICE(&dev->vdev);
     43
     44    /* unlike vhost-vsock, we do not need to care about pre-5.1 compat */
     45    virtio_pci_force_virtio_1(vpci_dev);
     46
     47    qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
     48}
     49
     50static void vhost_user_vsock_pci_class_init(ObjectClass *klass, void *data)
     51{
     52    DeviceClass *dc = DEVICE_CLASS(klass);
     53    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
     54    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
     55    k->realize = vhost_user_vsock_pci_realize;
     56    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     57    device_class_set_props(dc, vhost_user_vsock_pci_properties);
     58    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
     59    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
     60    pcidev_k->revision = 0x00;
     61    pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
     62}
     63
     64static void vhost_user_vsock_pci_instance_init(Object *obj)
     65{
     66    VHostUserVSockPCI *dev = VHOST_USER_VSOCK_PCI(obj);
     67
     68    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
     69                                TYPE_VHOST_USER_VSOCK);
     70}
     71
     72static const VirtioPCIDeviceTypeInfo vhost_user_vsock_pci_info = {
     73    .base_name             = TYPE_VHOST_USER_VSOCK_PCI,
     74    .generic_name          = "vhost-user-vsock-pci",
     75    .non_transitional_name = "vhost-user-vsock-pci-non-transitional",
     76    .instance_size = sizeof(VHostUserVSockPCI),
     77    .instance_init = vhost_user_vsock_pci_instance_init,
     78    .class_init    = vhost_user_vsock_pci_class_init,
     79};
     80
     81static void virtio_pci_vhost_register(void)
     82{
     83    virtio_pci_types_register(&vhost_user_vsock_pci_info);
     84}
     85
     86type_init(virtio_pci_vhost_register)