xref: /qemu/include/hw/vfio/vfio-cpr.h (revision 563ac3d18129a2770a285cc16c20ad50c8adc7c0)
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 VFIODevice;
19 struct VFIOPCIDevice;
20 struct VFIOIOMMUFDContainer;
21 struct IOMMUFDBackend;
22 
23 typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer,
24                           hwaddr iova, ram_addr_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 bool vfio_legacy_cpr_register_container(struct VFIOContainer *container,
42                                         Error **errp);
43 void vfio_legacy_cpr_unregister_container(struct VFIOContainer *container);
44 
45 int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent *e,
46                              Error **errp);
47 
48 bool vfio_iommufd_cpr_register_container(struct VFIOIOMMUFDContainer *container,
49                                          Error **errp);
50 void vfio_iommufd_cpr_unregister_container(
51     struct VFIOIOMMUFDContainer *container);
52 bool vfio_iommufd_cpr_register_iommufd(struct IOMMUFDBackend *be, Error **errp);
53 void vfio_iommufd_cpr_unregister_iommufd(struct IOMMUFDBackend *be);
54 void vfio_iommufd_cpr_register_device(struct VFIODevice *vbasedev);
55 void vfio_iommufd_cpr_unregister_device(struct VFIODevice *vbasedev);
56 void vfio_cpr_load_device(struct VFIODevice *vbasedev);
57 
58 int vfio_cpr_group_get_device_fd(int d, const char *name);
59 
60 bool vfio_cpr_container_match(struct VFIOContainer *container,
61                               struct VFIOGroup *group, int fd);
62 
63 void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcontainer,
64                            MemoryRegionSection *section);
65 
66 bool vfio_cpr_ram_discard_register_listener(
67     struct VFIOContainerBase *bcontainer, MemoryRegionSection *section);
68 
69 void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
70                              int nr, int fd);
71 int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
72                             int nr);
73 void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
74                                int nr);
75 
76 extern const VMStateDescription vfio_cpr_pci_vmstate;
77 extern const VMStateDescription vmstate_cpr_vfio_devices;
78 
79 void vfio_cpr_add_kvm_notifier(void);
80 
81 #endif /* HW_VFIO_VFIO_CPR_H */
82