13ed34463SSteve Sistare /* 23ed34463SSteve Sistare * VFIO CPR 33ed34463SSteve Sistare * 43ed34463SSteve Sistare * Copyright (c) 2025 Oracle and/or its affiliates. 53ed34463SSteve Sistare * 63ed34463SSteve Sistare * SPDX-License-Identifier: GPL-2.0-or-later 73ed34463SSteve Sistare */ 83ed34463SSteve Sistare 93ed34463SSteve Sistare #ifndef HW_VFIO_VFIO_CPR_H 103ed34463SSteve Sistare #define HW_VFIO_VFIO_CPR_H 113ed34463SSteve Sistare 1254857b08SSteve Sistare #include "migration/misc.h" 13eba1f657SSteve Sistare #include "system/memory.h" 1454857b08SSteve Sistare 1554857b08SSteve Sistare struct VFIOContainer; 163ed34463SSteve Sistare struct VFIOContainerBase; 17c29a65edSSteve Sistare struct VFIOGroup; 1806c6a658SSteve Sistare struct VFIODevice; 1930edcb4dSSteve Sistare struct VFIOPCIDevice; 2006c6a658SSteve Sistare struct VFIOIOMMUFDContainer; 2106c6a658SSteve Sistare struct IOMMUFDBackend; 223ed34463SSteve Sistare 23924c3ccbSZhenzhong Duan typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer, 24924c3ccbSZhenzhong Duan hwaddr iova, ram_addr_t size, void *vaddr, 25924c3ccbSZhenzhong Duan bool readonly, MemoryRegion *mr); 26924c3ccbSZhenzhong Duan 2754857b08SSteve Sistare typedef struct VFIOContainerCPR { 2854857b08SSteve Sistare Error *blocker; 29eba1f657SSteve Sistare bool vaddr_unmapped; 30eba1f657SSteve Sistare NotifierWithReturn transfer_notifier; 31eba1f657SSteve Sistare MemoryListener remap_listener; 3254857b08SSteve Sistare } VFIOContainerCPR; 3354857b08SSteve Sistare 34dac0dd68SSteve Sistare typedef struct VFIODeviceCPR { 35dac0dd68SSteve Sistare Error *mdev_blocker; 36a434fd8fSSteve Sistare Error *id_blocker; 37f2f3e466SSteve Sistare uint32_t hwpt_id; 38f2f3e466SSteve Sistare uint32_t ioas_id; 39dac0dd68SSteve Sistare } VFIODeviceCPR; 4054857b08SSteve Sistare 41*322ee168SSteve Sistare typedef struct VFIOPCICPR { 42*322ee168SSteve Sistare NotifierWithReturn transfer_notifier; 43*322ee168SSteve Sistare } VFIOPCICPR; 44*322ee168SSteve Sistare 4554857b08SSteve Sistare bool vfio_legacy_cpr_register_container(struct VFIOContainer *container, 4654857b08SSteve Sistare Error **errp); 4754857b08SSteve Sistare void vfio_legacy_cpr_unregister_container(struct VFIOContainer *container); 4854857b08SSteve Sistare 4954857b08SSteve Sistare int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent *e, 5054857b08SSteve Sistare Error **errp); 5154857b08SSteve Sistare 5206c6a658SSteve Sistare bool vfio_iommufd_cpr_register_container(struct VFIOIOMMUFDContainer *container, 5306c6a658SSteve Sistare Error **errp); 5406c6a658SSteve Sistare void vfio_iommufd_cpr_unregister_container( 5506c6a658SSteve Sistare struct VFIOIOMMUFDContainer *container); 5606c6a658SSteve Sistare bool vfio_iommufd_cpr_register_iommufd(struct IOMMUFDBackend *be, Error **errp); 5706c6a658SSteve Sistare void vfio_iommufd_cpr_unregister_iommufd(struct IOMMUFDBackend *be); 5806c6a658SSteve Sistare void vfio_iommufd_cpr_register_device(struct VFIODevice *vbasedev); 5906c6a658SSteve Sistare void vfio_iommufd_cpr_unregister_device(struct VFIODevice *vbasedev); 60f2f3e466SSteve Sistare void vfio_cpr_load_device(struct VFIODevice *vbasedev); 6106c6a658SSteve Sistare 62c29a65edSSteve Sistare int vfio_cpr_group_get_device_fd(int d, const char *name); 63c29a65edSSteve Sistare 64c29a65edSSteve Sistare bool vfio_cpr_container_match(struct VFIOContainer *container, 65c29a65edSSteve Sistare struct VFIOGroup *group, int fd); 66c29a65edSSteve Sistare 67eba1f657SSteve Sistare void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcontainer, 68eba1f657SSteve Sistare MemoryRegionSection *section); 69eba1f657SSteve Sistare 70eba1f657SSteve Sistare bool vfio_cpr_ram_discard_register_listener( 71eba1f657SSteve Sistare struct VFIOContainerBase *bcontainer, MemoryRegionSection *section); 72eba1f657SSteve Sistare 7330edcb4dSSteve Sistare void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name, 7430edcb4dSSteve Sistare int nr, int fd); 7530edcb4dSSteve Sistare int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name, 7630edcb4dSSteve Sistare int nr); 7730edcb4dSSteve Sistare void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name, 7830edcb4dSSteve Sistare int nr); 7930edcb4dSSteve Sistare 80031fbb71SSteve Sistare extern const VMStateDescription vfio_cpr_pci_vmstate; 81a6f2f9c4SSteve Sistare extern const VMStateDescription vmstate_cpr_vfio_devices; 82031fbb71SSteve Sistare 837ed09191SSteve Sistare void vfio_cpr_add_kvm_notifier(void); 84*322ee168SSteve Sistare void vfio_cpr_pci_register_device(struct VFIOPCIDevice *vdev); 85*322ee168SSteve Sistare void vfio_cpr_pci_unregister_device(struct VFIOPCIDevice *vdev); 867ed09191SSteve Sistare 873ed34463SSteve Sistare #endif /* HW_VFIO_VFIO_CPR_H */ 88