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 VFIOContainer; 16 struct VFIOContainerBase; 17 struct VFIOGroup; 18 struct VFIOPCIDevice; 19 20 typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer, 21 hwaddr iova, ram_addr_t size, void *vaddr, 22 bool readonly, MemoryRegion *mr); 23 24 typedef struct VFIOContainerCPR { 25 Error *blocker; 26 bool vaddr_unmapped; 27 NotifierWithReturn transfer_notifier; 28 MemoryListener remap_listener; 29 } VFIOContainerCPR; 30 31 typedef struct VFIODeviceCPR { 32 Error *mdev_blocker; 33 Error *id_blocker; 34 } VFIODeviceCPR; 35 36 bool vfio_legacy_cpr_register_container(struct VFIOContainer *container, 37 Error **errp); 38 void vfio_legacy_cpr_unregister_container(struct VFIOContainer *container); 39 40 int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent *e, 41 Error **errp); 42 43 bool vfio_cpr_register_container(struct VFIOContainerBase *bcontainer, 44 Error **errp); 45 void vfio_cpr_unregister_container(struct VFIOContainerBase *bcontainer); 46 47 int vfio_cpr_group_get_device_fd(int d, const char *name); 48 49 bool vfio_cpr_container_match(struct VFIOContainer *container, 50 struct VFIOGroup *group, int fd); 51 52 void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcontainer, 53 MemoryRegionSection *section); 54 55 bool vfio_cpr_ram_discard_register_listener( 56 struct VFIOContainerBase *bcontainer, MemoryRegionSection *section); 57 58 void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name, 59 int nr, int fd); 60 int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name, 61 int nr); 62 void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name, 63 int nr); 64 65 extern const VMStateDescription vfio_cpr_pci_vmstate; 66 67 void vfio_cpr_add_kvm_notifier(void); 68 69 #endif /* HW_VFIO_VFIO_CPR_H */ 70