|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* Copyright(c) 2023 Advanced Micro Devices, Inc. */ |
| 3 | + |
| 4 | +#include <linux/vfio.h> |
| 5 | +#include <linux/vfio_pci_core.h> |
| 6 | + |
| 7 | +#include "vfio_dev.h" |
| 8 | + |
| 9 | +struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev) |
| 10 | +{ |
| 11 | + struct vfio_pci_core_device *core_device = dev_get_drvdata(&pdev->dev); |
| 12 | + |
| 13 | + return container_of(core_device, struct pds_vfio_pci_device, |
| 14 | + vfio_coredev); |
| 15 | +} |
| 16 | + |
| 17 | +static int pds_vfio_init_device(struct vfio_device *vdev) |
| 18 | +{ |
| 19 | + struct pds_vfio_pci_device *pds_vfio = |
| 20 | + container_of(vdev, struct pds_vfio_pci_device, |
| 21 | + vfio_coredev.vdev); |
| 22 | + struct pci_dev *pdev = to_pci_dev(vdev->dev); |
| 23 | + int err, vf_id; |
| 24 | + |
| 25 | + vf_id = pci_iov_vf_id(pdev); |
| 26 | + if (vf_id < 0) |
| 27 | + return vf_id; |
| 28 | + |
| 29 | + err = vfio_pci_core_init_dev(vdev); |
| 30 | + if (err) |
| 31 | + return err; |
| 32 | + |
| 33 | + pds_vfio->vf_id = vf_id; |
| 34 | + |
| 35 | + return 0; |
| 36 | +} |
| 37 | + |
| 38 | +static int pds_vfio_open_device(struct vfio_device *vdev) |
| 39 | +{ |
| 40 | + struct pds_vfio_pci_device *pds_vfio = |
| 41 | + container_of(vdev, struct pds_vfio_pci_device, |
| 42 | + vfio_coredev.vdev); |
| 43 | + int err; |
| 44 | + |
| 45 | + err = vfio_pci_core_enable(&pds_vfio->vfio_coredev); |
| 46 | + if (err) |
| 47 | + return err; |
| 48 | + |
| 49 | + vfio_pci_core_finish_enable(&pds_vfio->vfio_coredev); |
| 50 | + |
| 51 | + return 0; |
| 52 | +} |
| 53 | + |
| 54 | +static const struct vfio_device_ops pds_vfio_ops = { |
| 55 | + .name = "pds-vfio", |
| 56 | + .init = pds_vfio_init_device, |
| 57 | + .release = vfio_pci_core_release_dev, |
| 58 | + .open_device = pds_vfio_open_device, |
| 59 | + .close_device = vfio_pci_core_close_device, |
| 60 | + .ioctl = vfio_pci_core_ioctl, |
| 61 | + .device_feature = vfio_pci_core_ioctl_feature, |
| 62 | + .read = vfio_pci_core_read, |
| 63 | + .write = vfio_pci_core_write, |
| 64 | + .mmap = vfio_pci_core_mmap, |
| 65 | + .request = vfio_pci_core_request, |
| 66 | + .match = vfio_pci_core_match, |
| 67 | + .bind_iommufd = vfio_iommufd_physical_bind, |
| 68 | + .unbind_iommufd = vfio_iommufd_physical_unbind, |
| 69 | + .attach_ioas = vfio_iommufd_physical_attach_ioas, |
| 70 | +}; |
| 71 | + |
| 72 | +const struct vfio_device_ops *pds_vfio_ops_info(void) |
| 73 | +{ |
| 74 | + return &pds_vfio_ops; |
| 75 | +} |
0 commit comments