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