aboutsummaryrefslogtreecommitdiff
path: root/include/hw/vfio/vfio-cpr.h
blob: 80ad20d2169086052b66d0df526406b8de7985d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * VFIO CPR
 *
 * Copyright (c) 2025 Oracle and/or its affiliates.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef HW_VFIO_VFIO_CPR_H
#define HW_VFIO_VFIO_CPR_H

#include "migration/misc.h"
#include "system/memory.h"

struct VFIOContainer;
struct VFIOContainerBase;
struct VFIOGroup;
struct VFIODevice;
struct VFIOPCIDevice;
struct VFIOIOMMUFDContainer;
struct IOMMUFDBackend;

typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer,
                          hwaddr iova, ram_addr_t size, void *vaddr,
                          bool readonly, MemoryRegion *mr);

typedef struct VFIOContainerCPR {
    Error *blocker;
    bool vaddr_unmapped;
    NotifierWithReturn transfer_notifier;
    MemoryListener remap_listener;
} VFIOContainerCPR;

typedef struct VFIODeviceCPR {
    Error *mdev_blocker;
    Error *id_blocker;
    uint32_t hwpt_id;
    uint32_t ioas_id;
} VFIODeviceCPR;

bool vfio_legacy_cpr_register_container(struct VFIOContainer *container,
                                        Error **errp);
void vfio_legacy_cpr_unregister_container(struct VFIOContainer *container);

int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent *e,
                             Error **errp);

bool vfio_iommufd_cpr_register_container(struct VFIOIOMMUFDContainer *container,
                                         Error **errp);
void vfio_iommufd_cpr_unregister_container(
    struct VFIOIOMMUFDContainer *container);
bool vfio_iommufd_cpr_register_iommufd(struct IOMMUFDBackend *be, Error **errp);
void vfio_iommufd_cpr_unregister_iommufd(struct IOMMUFDBackend *be);
void vfio_iommufd_cpr_register_device(struct VFIODevice *vbasedev);
void vfio_iommufd_cpr_unregister_device(struct VFIODevice *vbasedev);
void vfio_cpr_load_device(struct VFIODevice *vbasedev);

int vfio_cpr_group_get_device_fd(int d, const char *name);

bool vfio_cpr_container_match(struct VFIOContainer *container,
                              struct VFIOGroup *group, int fd);

void vfio_cpr_giommu_remap(struct VFIOContainerBase *bcontainer,
                           MemoryRegionSection *section);

bool vfio_cpr_ram_discard_register_listener(
    struct VFIOContainerBase *bcontainer, MemoryRegionSection *section);

void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
                             int nr, int fd);
int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
                            int nr);
void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
                               int nr);

extern const VMStateDescription vfio_cpr_pci_vmstate;
extern const VMStateDescription vmstate_cpr_vfio_devices;

void vfio_cpr_add_kvm_notifier(void);

#endif /* HW_VFIO_VFIO_CPR_H */