summaryrefslogtreecommitdiff
path: root/src/util/virmdev.h
blob: bc8306d0e1585e4eb773f4b9b281eb3057acbd93 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * virmdev.h: helper APIs for managing host mediated devices
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "internal.h"
#include "virobject.h"
#include "virenum.h"

typedef enum {
    VIR_MDEV_MODEL_TYPE_VFIO_PCI = 0,
    VIR_MDEV_MODEL_TYPE_VFIO_CCW = 1,
    VIR_MDEV_MODEL_TYPE_VFIO_AP  = 2,

    VIR_MDEV_MODEL_TYPE_LAST
} virMediatedDeviceModelType;

VIR_ENUM_DECL(virMediatedDeviceModel);


typedef struct _virMediatedDevice virMediatedDevice;
typedef struct _virMediatedDeviceList virMediatedDeviceList;
typedef struct _virMediatedDeviceAttr virMediatedDeviceAttr;
struct _virMediatedDeviceAttr {
    char *name;
    char *value;
};

virMediatedDeviceAttr *virMediatedDeviceAttrNew(void);
void virMediatedDeviceAttrFree(virMediatedDeviceAttr *attr);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceAttr, virMediatedDeviceAttrFree);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceList, virObjectUnref);


typedef struct _virMediatedDeviceType virMediatedDeviceType;
struct _virMediatedDeviceType {
    char *id;
    char *name;
    char *device_api;
    unsigned int available_instances;
};

typedef int (*virMediatedDeviceCallback)(virMediatedDevice *dev,
                                         const char *path, void *opaque);

virMediatedDevice *
virMediatedDeviceNew(const char *uuidstr, virMediatedDeviceModelType model);

virMediatedDevice *
virMediatedDeviceCopy(virMediatedDevice *dev);

void
virMediatedDeviceFree(virMediatedDevice *dev);

const char *
virMediatedDeviceGetPath(virMediatedDevice *dev);

void
virMediatedDeviceGetUsedBy(virMediatedDevice *dev,
                           const char **drvname, const char **domname);

int
virMediatedDeviceSetUsedBy(virMediatedDevice *dev,
                           const char *drvname,
                           const char *domname);

char *
virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr);

int
virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr);

char *
virMediatedDeviceGetSysfsPath(const char *uuidstr);

bool
virMediatedDeviceIsUsed(virMediatedDevice *dev,
                        virMediatedDeviceList *list);

bool
virMediatedDeviceIsUsed(virMediatedDevice *dev,
                        virMediatedDeviceList *list);

virMediatedDeviceList *
virMediatedDeviceListNew(void);

int
virMediatedDeviceListAdd(virMediatedDeviceList *list,
                         virMediatedDevice **dev);

virMediatedDevice *
virMediatedDeviceListGet(virMediatedDeviceList *list,
                         ssize_t idx);

size_t
virMediatedDeviceListCount(virMediatedDeviceList *list);

virMediatedDevice *
virMediatedDeviceListSteal(virMediatedDeviceList *list,
                           virMediatedDevice *dev);

virMediatedDevice *
virMediatedDeviceListStealIndex(virMediatedDeviceList *list,
                                ssize_t idx);

void
virMediatedDeviceListDel(virMediatedDeviceList *list,
                         virMediatedDevice *dev);

virMediatedDevice *
virMediatedDeviceListFind(virMediatedDeviceList *list,
                          const char *sysfspath);

int
virMediatedDeviceListFindIndex(virMediatedDeviceList *list,
                               const char *sysfspath);

int
virMediatedDeviceListMarkDevices(virMediatedDeviceList *dst,
                                 virMediatedDeviceList *src,
                                 const char *drvname,
                                 const char *domname);

void
virMediatedDeviceTypeFree(virMediatedDeviceType *type);

int
virMediatedDeviceTypeReadAttrs(const char *sysfspath,
                               virMediatedDeviceType **type);

ssize_t
virMediatedDeviceGetMdevTypes(const char *sysfspath,
                              virMediatedDeviceType ***types,
                              size_t *ntypes);

int
virMediatedDeviceParentGetAddress(const char *sysfspath,
                                  char **address);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDevice, virMediatedDeviceFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceType, virMediatedDeviceTypeFree);