Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio/amba: Use the new device life cycle helpers

Implement amba's own vfio_device_ops.

Remove vfio_platform_probe/remove_common() given no user now.

Signed-off-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Link: https://lore.kernel.org/r/20220921104401.38898-13-kevin.tian@intel.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Kevin Tian and committed by
Alex Williamson
ac123791 5f6c7e08

+55 -80
+55 -17
drivers/vfio/platform/vfio_amba.c
··· 7 7 #include <linux/module.h> 8 8 #include <linux/slab.h> 9 9 #include <linux/vfio.h> 10 + #include <linux/pm_runtime.h> 10 11 #include <linux/amba/bus.h> 11 12 12 13 #include "vfio_platform_private.h" ··· 41 40 return ret ? ret : -ENXIO; 42 41 } 43 42 44 - static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id) 43 + static int vfio_amba_init_dev(struct vfio_device *core_vdev) 45 44 { 46 - struct vfio_platform_device *vdev; 45 + struct vfio_platform_device *vdev = 46 + container_of(core_vdev, struct vfio_platform_device, vdev); 47 + struct amba_device *adev = to_amba_device(core_vdev->dev); 47 48 int ret; 48 49 49 - vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); 50 - if (!vdev) 51 - return -ENOMEM; 52 - 53 50 vdev->name = kasprintf(GFP_KERNEL, "vfio-amba-%08x", adev->periphid); 54 - if (!vdev->name) { 55 - kfree(vdev); 51 + if (!vdev->name) 56 52 return -ENOMEM; 57 - } 58 53 59 54 vdev->opaque = (void *) adev; 60 55 vdev->flags = VFIO_DEVICE_FLAGS_AMBA; ··· 58 61 vdev->get_irq = get_amba_irq; 59 62 vdev->reset_required = false; 60 63 61 - ret = vfio_platform_probe_common(vdev, &adev->dev); 62 - if (ret) { 64 + ret = vfio_platform_init_common(vdev); 65 + if (ret) 63 66 kfree(vdev->name); 64 - kfree(vdev); 65 - return ret; 66 - } 67 + return ret; 68 + } 67 69 70 + static const struct vfio_device_ops vfio_amba_ops; 71 + static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id) 72 + { 73 + struct vfio_platform_device *vdev; 74 + int ret; 75 + 76 + vdev = vfio_alloc_device(vfio_platform_device, vdev, &adev->dev, 77 + &vfio_amba_ops); 78 + if (IS_ERR(vdev)) 79 + return PTR_ERR(vdev); 80 + 81 + ret = vfio_register_group_dev(&vdev->vdev); 82 + if (ret) 83 + goto out_put_vdev; 84 + 85 + pm_runtime_enable(&adev->dev); 68 86 dev_set_drvdata(&adev->dev, vdev); 69 87 return 0; 88 + 89 + out_put_vdev: 90 + vfio_put_device(&vdev->vdev); 91 + return ret; 92 + } 93 + 94 + static void vfio_amba_release_dev(struct vfio_device *core_vdev) 95 + { 96 + struct vfio_platform_device *vdev = 97 + container_of(core_vdev, struct vfio_platform_device, vdev); 98 + 99 + vfio_platform_release_common(vdev); 100 + kfree(vdev->name); 101 + vfio_free_device(core_vdev); 70 102 } 71 103 72 104 static void vfio_amba_remove(struct amba_device *adev) 73 105 { 74 106 struct vfio_platform_device *vdev = dev_get_drvdata(&adev->dev); 75 107 76 - vfio_platform_remove_common(vdev); 77 - kfree(vdev->name); 78 - kfree(vdev); 108 + vfio_unregister_group_dev(&vdev->vdev); 109 + pm_runtime_disable(vdev->device); 110 + vfio_put_device(&vdev->vdev); 79 111 } 112 + 113 + static const struct vfio_device_ops vfio_amba_ops = { 114 + .name = "vfio-amba", 115 + .init = vfio_amba_init_dev, 116 + .release = vfio_amba_release_dev, 117 + .open_device = vfio_platform_open_device, 118 + .close_device = vfio_platform_close_device, 119 + .ioctl = vfio_platform_ioctl, 120 + .read = vfio_platform_read, 121 + .write = vfio_platform_write, 122 + .mmap = vfio_platform_mmap, 123 + }; 80 124 81 125 static const struct amba_id pl330_ids[] = { 82 126 { 0, 0 },
-60
drivers/vfio/platform/vfio_platform_common.c
··· 605 605 } 606 606 EXPORT_SYMBOL_GPL(vfio_platform_mmap); 607 607 608 - static const struct vfio_device_ops vfio_platform_ops = { 609 - .name = "vfio-platform", 610 - .open_device = vfio_platform_open_device, 611 - .close_device = vfio_platform_close_device, 612 - .ioctl = vfio_platform_ioctl, 613 - .read = vfio_platform_read, 614 - .write = vfio_platform_write, 615 - .mmap = vfio_platform_mmap, 616 - }; 617 - 618 608 static int vfio_platform_of_probe(struct vfio_platform_device *vdev, 619 609 struct device *dev) 620 610 { ··· 663 673 vfio_platform_put_reset(vdev); 664 674 } 665 675 EXPORT_SYMBOL_GPL(vfio_platform_release_common); 666 - 667 - int vfio_platform_probe_common(struct vfio_platform_device *vdev, 668 - struct device *dev) 669 - { 670 - int ret; 671 - 672 - vfio_init_group_dev(&vdev->vdev, dev, &vfio_platform_ops); 673 - 674 - ret = vfio_platform_acpi_probe(vdev, dev); 675 - if (ret) 676 - ret = vfio_platform_of_probe(vdev, dev); 677 - 678 - if (ret) 679 - goto out_uninit; 680 - 681 - vdev->device = dev; 682 - 683 - ret = vfio_platform_get_reset(vdev); 684 - if (ret && vdev->reset_required) { 685 - dev_err(dev, "No reset function found for device %s\n", 686 - vdev->name); 687 - goto out_uninit; 688 - } 689 - 690 - ret = vfio_register_group_dev(&vdev->vdev); 691 - if (ret) 692 - goto put_reset; 693 - 694 - mutex_init(&vdev->igate); 695 - 696 - pm_runtime_enable(dev); 697 - return 0; 698 - 699 - put_reset: 700 - vfio_platform_put_reset(vdev); 701 - out_uninit: 702 - vfio_uninit_group_dev(&vdev->vdev); 703 - return ret; 704 - } 705 - EXPORT_SYMBOL_GPL(vfio_platform_probe_common); 706 - 707 - void vfio_platform_remove_common(struct vfio_platform_device *vdev) 708 - { 709 - vfio_unregister_group_dev(&vdev->vdev); 710 - 711 - pm_runtime_disable(vdev->device); 712 - vfio_platform_put_reset(vdev); 713 - vfio_uninit_group_dev(&vdev->vdev); 714 - } 715 - EXPORT_SYMBOL_GPL(vfio_platform_remove_common); 716 676 717 677 void __vfio_platform_register_reset(struct vfio_platform_reset_node *node) 718 678 {
-3
drivers/vfio/platform/vfio_platform_private.h
··· 78 78 vfio_platform_reset_fn_t of_reset; 79 79 }; 80 80 81 - int vfio_platform_probe_common(struct vfio_platform_device *vdev, 82 - struct device *dev); 83 - void vfio_platform_remove_common(struct vfio_platform_device *vdev); 84 81 int vfio_platform_init_common(struct vfio_platform_device *vdev); 85 82 void vfio_platform_release_common(struct vfio_platform_device *vdev); 86 83