1*38fe3975SBrett Creeley // SPDX-License-Identifier: GPL-2.0 2*38fe3975SBrett Creeley /* Copyright(c) 2023 Advanced Micro Devices, Inc. */ 3*38fe3975SBrett Creeley 4*38fe3975SBrett Creeley #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 5*38fe3975SBrett Creeley 6*38fe3975SBrett Creeley #include <linux/module.h> 7*38fe3975SBrett Creeley #include <linux/pci.h> 8*38fe3975SBrett Creeley #include <linux/types.h> 9*38fe3975SBrett Creeley #include <linux/vfio.h> 10*38fe3975SBrett Creeley 11*38fe3975SBrett Creeley #include <linux/pds/pds_core_if.h> 12*38fe3975SBrett Creeley 13*38fe3975SBrett Creeley #include "vfio_dev.h" 14*38fe3975SBrett Creeley 15*38fe3975SBrett Creeley #define PDS_VFIO_DRV_DESCRIPTION "AMD/Pensando VFIO Device Driver" 16*38fe3975SBrett Creeley #define PCI_VENDOR_ID_PENSANDO 0x1dd8 17*38fe3975SBrett Creeley 18*38fe3975SBrett Creeley static int pds_vfio_pci_probe(struct pci_dev *pdev, 19*38fe3975SBrett Creeley const struct pci_device_id *id) 20*38fe3975SBrett Creeley { 21*38fe3975SBrett Creeley struct pds_vfio_pci_device *pds_vfio; 22*38fe3975SBrett Creeley int err; 23*38fe3975SBrett Creeley 24*38fe3975SBrett Creeley pds_vfio = vfio_alloc_device(pds_vfio_pci_device, vfio_coredev.vdev, 25*38fe3975SBrett Creeley &pdev->dev, pds_vfio_ops_info()); 26*38fe3975SBrett Creeley if (IS_ERR(pds_vfio)) 27*38fe3975SBrett Creeley return PTR_ERR(pds_vfio); 28*38fe3975SBrett Creeley 29*38fe3975SBrett Creeley dev_set_drvdata(&pdev->dev, &pds_vfio->vfio_coredev); 30*38fe3975SBrett Creeley 31*38fe3975SBrett Creeley err = vfio_pci_core_register_device(&pds_vfio->vfio_coredev); 32*38fe3975SBrett Creeley if (err) 33*38fe3975SBrett Creeley goto out_put_vdev; 34*38fe3975SBrett Creeley 35*38fe3975SBrett Creeley return 0; 36*38fe3975SBrett Creeley 37*38fe3975SBrett Creeley out_put_vdev: 38*38fe3975SBrett Creeley vfio_put_device(&pds_vfio->vfio_coredev.vdev); 39*38fe3975SBrett Creeley return err; 40*38fe3975SBrett Creeley } 41*38fe3975SBrett Creeley 42*38fe3975SBrett Creeley static void pds_vfio_pci_remove(struct pci_dev *pdev) 43*38fe3975SBrett Creeley { 44*38fe3975SBrett Creeley struct pds_vfio_pci_device *pds_vfio = pds_vfio_pci_drvdata(pdev); 45*38fe3975SBrett Creeley 46*38fe3975SBrett Creeley vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev); 47*38fe3975SBrett Creeley vfio_put_device(&pds_vfio->vfio_coredev.vdev); 48*38fe3975SBrett Creeley } 49*38fe3975SBrett Creeley 50*38fe3975SBrett Creeley static const struct pci_device_id pds_vfio_pci_table[] = { 51*38fe3975SBrett Creeley { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_PENSANDO, 0x1003) }, /* Ethernet VF */ 52*38fe3975SBrett Creeley { 0, } 53*38fe3975SBrett Creeley }; 54*38fe3975SBrett Creeley MODULE_DEVICE_TABLE(pci, pds_vfio_pci_table); 55*38fe3975SBrett Creeley 56*38fe3975SBrett Creeley static struct pci_driver pds_vfio_pci_driver = { 57*38fe3975SBrett Creeley .name = KBUILD_MODNAME, 58*38fe3975SBrett Creeley .id_table = pds_vfio_pci_table, 59*38fe3975SBrett Creeley .probe = pds_vfio_pci_probe, 60*38fe3975SBrett Creeley .remove = pds_vfio_pci_remove, 61*38fe3975SBrett Creeley .driver_managed_dma = true, 62*38fe3975SBrett Creeley }; 63*38fe3975SBrett Creeley 64*38fe3975SBrett Creeley module_pci_driver(pds_vfio_pci_driver); 65*38fe3975SBrett Creeley 66*38fe3975SBrett Creeley MODULE_DESCRIPTION(PDS_VFIO_DRV_DESCRIPTION); 67*38fe3975SBrett Creeley MODULE_AUTHOR("Brett Creeley <brett.creeley@amd.com>"); 68*38fe3975SBrett Creeley MODULE_LICENSE("GPL"); 69