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