| 1 | /* |
| 2 | * VFIO CPR |
| 3 | * |
| 4 | * Copyright (c) 2025 Oracle and/or its affiliates. |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef HW_VFIO_VFIO_CPR_H |
| 10 | #define HW_VFIO_VFIO_CPR_H |
| 11 | |
| 12 | #include "migration/misc.h" |
| 13 | #include "system/memory.h" |
| 14 | |
| 15 | struct VFIOLegacyContainer; |
| 16 | struct VFIOContainer; |
| 17 | struct VFIOGroup; |
| 18 | struct VFIODevice; |
| 19 | struct VFIOPCIDevice; |
| 20 | struct VFIOIOMMUFDContainer; |
| 21 | struct IOMMUFDBackend; |
| 22 | |
| 23 | typedef int (*dma_map_fn)(const struct VFIOContainer *bcontainer, |
| 24 | hwaddr iova, uint64_t size, void *vaddr, |
| 25 | bool readonly, MemoryRegion *mr); |
| 26 | |
| 27 | typedef struct VFIOContainerCPR { |
| 28 | Error *blocker; |
| 29 | bool vaddr_unmapped; |
| 30 | NotifierWithReturn transfer_notifier; |
| 31 | MemoryListener remap_listener; |
| 32 | } VFIOContainerCPR; |
| 33 | |
| 34 | typedef struct VFIODeviceCPR { |
| 35 | Error *mdev_blocker; |
| 36 | Error *id_blocker; |
| 37 | uint32_t hwpt_id; |
| 38 | uint32_t ioas_id; |
| 39 | } VFIODeviceCPR; |
| 40 | |
| 41 | typedef struct VFIOPCICPR { |
| 42 | NotifierWithReturn transfer_notifier; |
| 43 | } VFIOPCICPR; |
| 44 | |
| 45 | bool vfio_legacy_cpr_register_container(struct VFIOLegacyContainer *container, |
| 46 | Error **errp); |
| 47 | void vfio_legacy_cpr_unregister_container( |
| 48 | struct VFIOLegacyContainer *container); |
| 49 | |
| 50 | int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent *e, |
| 51 | Error **errp); |
| 52 | |
| 53 | bool vfio_iommufd_cpr_register_container(struct VFIOIOMMUFDContainer *container, |
| 54 | Error **errp); |
| 55 | void vfio_iommufd_cpr_unregister_container( |
| 56 | struct VFIOIOMMUFDContainer *container); |
| 57 | bool vfio_iommufd_cpr_register_iommufd(struct IOMMUFDBackend *be, Error **errp); |
| 58 | void vfio_iommufd_cpr_unregister_iommufd(struct IOMMUFDBackend *be); |
| 59 | void vfio_iommufd_cpr_register_device(struct VFIODevice *vbasedev); |
| 60 | void vfio_iommufd_cpr_unregister_device(struct VFIODevice *vbasedev); |
| 61 | void vfio_cpr_load_device(struct VFIODevice *vbasedev); |
| 62 | |
| 63 | int vfio_cpr_group_get_device_fd(int d, const char *name); |
| 64 | |
| 65 | bool vfio_cpr_container_match(struct VFIOLegacyContainer *container, |
| 66 | struct VFIOGroup *group, int fd); |
| 67 | |
| 68 | void vfio_cpr_giommu_remap(struct VFIOContainer *bcontainer, |
| 69 | MemoryRegionSection *section); |
| 70 | |
| 71 | bool vfio_cpr_ram_discard_replay_populated( |
| 72 | struct VFIOContainer *bcontainer, const MemoryRegionSection *section); |
| 73 | |
| 74 | void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name, |
| 75 | int nr, int fd); |
| 76 | int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name, |
| 77 | int nr); |
| 78 | void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name, |
| 79 | int nr); |
| 80 | |
| 81 | extern const VMStateDescription vfio_cpr_pci_vmstate; |
| 82 | extern const VMStateDescription vmstate_cpr_vfio_devices; |
| 83 | |
| 84 | void vfio_cpr_add_kvm_notifier(void); |
| 85 | void vfio_cpr_pci_register_device(struct VFIOPCIDevice *vdev); |
| 86 | void vfio_cpr_pci_unregister_device(struct VFIOPCIDevice *vdev); |
| 87 | |
| 88 | #endif /* HW_VFIO_VFIO_CPR_H */ |