xref: /openbmc/qemu/include/hw/vfio/vfio-cpr.h (revision a434fd8f6462c1541927d22e07c58425d6cbd84b)
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;
1830edcb4dSSteve Sistare struct VFIOPCIDevice;
193ed34463SSteve Sistare 
20924c3ccbSZhenzhong Duan typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer,
21924c3ccbSZhenzhong Duan                           hwaddr iova, ram_addr_t size, void *vaddr,
22924c3ccbSZhenzhong Duan                           bool readonly, MemoryRegion *mr);
23924c3ccbSZhenzhong Duan 
2454857b08SSteve Sistare typedef struct VFIOContainerCPR {
2554857b08SSteve Sistare     Error *blocker;
26eba1f657SSteve Sistare     bool vaddr_unmapped;
27eba1f657SSteve Sistare     NotifierWithReturn transfer_notifier;
28eba1f657SSteve Sistare     MemoryListener remap_listener;
2954857b08SSteve Sistare } VFIOContainerCPR;
3054857b08SSteve Sistare 
31dac0dd68SSteve Sistare typedef struct VFIODeviceCPR {
32dac0dd68SSteve Sistare     Error *mdev_blocker;
33*a434fd8fSSteve Sistare     Error *id_blocker;
34dac0dd68SSteve Sistare } VFIODeviceCPR;
3554857b08SSteve Sistare 
3654857b08SSteve Sistare bool vfio_legacy_cpr_register_container(struct VFIOContainer *container,
3754857b08SSteve Sistare                                         Error **errp);
3854857b08SSteve Sistare void vfio_legacy_cpr_unregister_container(struct VFIOContainer *container);
3954857b08SSteve Sistare 
4054857b08SSteve Sistare int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent *e,
4154857b08SSteve Sistare                              Error **errp);
4254857b08SSteve Sistare 
433ed34463SSteve Sistare bool vfio_cpr_register_container(struct VFIOContainerBase *bcontainer,
443ed34463SSteve Sistare                                  Error **errp);
453ed34463SSteve Sistare void vfio_cpr_unregister_container(struct VFIOContainerBase *bcontainer);
463ed34463SSteve Sistare 
47c29a65edSSteve Sistare int vfio_cpr_group_get_device_fd(int d, const char *name);
48c29a65edSSteve Sistare 
49c29a65edSSteve Sistare bool vfio_cpr_container_match(struct VFIOContainer *container,
50c29a65edSSteve Sistare                               struct VFIOGroup *group, int fd);
51c29a65edSSteve Sistare 
52eba1f657SSteve Sistare void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcontainer,
53eba1f657SSteve Sistare                            MemoryRegionSection *section);
54eba1f657SSteve Sistare 
55eba1f657SSteve Sistare bool vfio_cpr_ram_discard_register_listener(
56eba1f657SSteve Sistare     struct VFIOContainerBase *bcontainer, MemoryRegionSection *section);
57eba1f657SSteve Sistare 
5830edcb4dSSteve Sistare void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
5930edcb4dSSteve Sistare                              int nr, int fd);
6030edcb4dSSteve Sistare int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
6130edcb4dSSteve Sistare                             int nr);
6230edcb4dSSteve Sistare void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
6330edcb4dSSteve Sistare                                int nr);
6430edcb4dSSteve Sistare 
65031fbb71SSteve Sistare extern const VMStateDescription vfio_cpr_pci_vmstate;
66031fbb71SSteve Sistare 
677ed09191SSteve Sistare void vfio_cpr_add_kvm_notifier(void);
687ed09191SSteve Sistare 
693ed34463SSteve Sistare #endif /* HW_VFIO_VFIO_CPR_H */
70