virpci.h 9.6 KB
Newer Older
1
/*
2 3
 * virpci.h: helper APIs for managing host PCI devices
 *
4
 * Copyright (C) 2009, 2011-2015 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22 23 24
 *
 * Authors:
 *     Mark McLoughlin <markmc@redhat.com>
 */

#ifndef __VIR_PCI_H__
25
# define __VIR_PCI_H__
26

27
# include "internal.h"
28
# include "virobject.h"
29
# include "virutil.h"
30

31 32 33 34 35 36 37 38
typedef struct _virPCIDevice virPCIDevice;
typedef virPCIDevice *virPCIDevicePtr;
typedef struct _virPCIDeviceAddress virPCIDeviceAddress;
typedef virPCIDeviceAddress *virPCIDeviceAddressPtr;
typedef struct _virPCIDeviceList virPCIDeviceList;
typedef virPCIDeviceList *virPCIDeviceListPtr;

struct _virPCIDeviceAddress {
39 40 41 42
    unsigned int domain;
    unsigned int bus;
    unsigned int slot;
    unsigned int function;
43
    int multi; /* virTristateSwitch */
44 45
};

46 47 48 49 50 51 52 53 54 55
typedef enum {
    VIR_PCI_STUB_DRIVER_NONE = 0,
    VIR_PCI_STUB_DRIVER_XEN,
    VIR_PCI_STUB_DRIVER_KVM,
    VIR_PCI_STUB_DRIVER_VFIO,
    VIR_PCI_STUB_DRIVER_LAST
} virPCIStubDriver;

VIR_ENUM_DECL(virPCIStubDriver);

56 57 58 59 60
typedef enum {
    VIR_PCIE_LINK_SPEED_NA = 0,
    VIR_PCIE_LINK_SPEED_25,
    VIR_PCIE_LINK_SPEED_5,
    VIR_PCIE_LINK_SPEED_8,
61
    VIR_PCIE_LINK_SPEED_16,
62 63 64 65 66
    VIR_PCIE_LINK_SPEED_LAST
} virPCIELinkSpeed;

VIR_ENUM_DECL(virPCIELinkSpeed)

67 68 69 70 71 72 73 74 75 76
typedef enum {
    VIR_PCI_HEADER_ENDPOINT = 0,
    VIR_PCI_HEADER_PCI_BRIDGE,
    VIR_PCI_HEADER_CARDBUS_BRIDGE,

    VIR_PCI_HEADER_LAST
} virPCIHeaderType;

VIR_ENUM_DECL(virPCIHeader)

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
typedef struct _virPCIELink virPCIELink;
typedef virPCIELink *virPCIELinkPtr;
struct _virPCIELink {
    int port;
    virPCIELinkSpeed speed;
    unsigned int width;
};

typedef struct _virPCIEDeviceInfo virPCIEDeviceInfo;
typedef virPCIEDeviceInfo *virPCIEDeviceInfoPtr;
struct _virPCIEDeviceInfo {
    /* Not all PCI Express devices have link. For example this 'Root Complex
     * Integrated Endpoint' and 'Root Complex Event Collector' don't have it. */
    virPCIELink *link_cap;   /* PCIe device link capabilities */
    virPCIELink *link_sta;   /* Actually negotiated capabilities */
};

94 95 96 97
virPCIDevicePtr virPCIDeviceNew(unsigned int domain,
                                unsigned int bus,
                                unsigned int slot,
                                unsigned int function);
L
Laine Stump 已提交
98
virPCIDevicePtr virPCIDeviceCopy(virPCIDevicePtr dev);
99 100
void virPCIDeviceFree(virPCIDevicePtr dev);
const char *virPCIDeviceGetName(virPCIDevicePtr dev);
101
const char *virPCIDeviceGetConfigPath(virPCIDevicePtr dev);
102 103 104

int virPCIDeviceDetach(virPCIDevicePtr dev,
                       virPCIDeviceListPtr activeDevs,
105
                       virPCIDeviceListPtr inactiveDevs);
106 107
int virPCIDeviceReattach(virPCIDevicePtr dev,
                         virPCIDeviceListPtr activeDevs,
108
                         virPCIDeviceListPtr inactiveDevs);
109 110 111 112 113
int virPCIDeviceReset(virPCIDevicePtr dev,
                      virPCIDeviceListPtr activeDevs,
                      virPCIDeviceListPtr inactiveDevs);

void virPCIDeviceSetManaged(virPCIDevice *dev,
114
                            bool managed);
115
bool virPCIDeviceGetManaged(virPCIDevice *dev);
116 117 118
void virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
                               virPCIStubDriver driver);
virPCIStubDriver virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
119
virPCIDeviceAddressPtr virPCIDeviceGetAddress(virPCIDevicePtr dev);
C
Chunyan Liu 已提交
120 121 122 123 124 125
int virPCIDeviceSetUsedBy(virPCIDevice *dev,
                          const char *drv_name,
                          const char *dom_name);
void virPCIDeviceGetUsedBy(virPCIDevice *dev,
                           const char **drv_name,
                           const char **dom_name);
126
bool virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
127
void  virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
128
                                    bool unbind);
129
bool virPCIDeviceGetRemoveSlot(virPCIDevicePtr dev);
130
void virPCIDeviceSetRemoveSlot(virPCIDevice *dev,
131
                               bool remove_slot);
132
bool virPCIDeviceGetReprobe(virPCIDevicePtr dev);
133
void virPCIDeviceSetReprobe(virPCIDevice *dev,
134
                            bool reprobe);
135 136 137 138 139


virPCIDeviceListPtr virPCIDeviceListNew(void);
int  virPCIDeviceListAdd(virPCIDeviceListPtr list,
                         virPCIDevicePtr dev);
L
Laine Stump 已提交
140
int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev);
141 142
virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list,
                                    int idx);
143
size_t virPCIDeviceListCount(virPCIDeviceListPtr list);
144 145 146 147 148 149 150 151
virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list,
                                      virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list,
                                           int idx);
void virPCIDeviceListDel(virPCIDeviceListPtr list,
                         virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListFind(virPCIDeviceListPtr list,
                                     virPCIDevicePtr dev);
L
Laine Stump 已提交
152 153 154 155 156 157
virPCIDevicePtr
virPCIDeviceListFindByIDs(virPCIDeviceListPtr list,
                          unsigned int domain,
                          unsigned int bus,
                          unsigned int slot,
                          unsigned int function);
158 159
int virPCIDeviceListFindIndex(virPCIDeviceListPtr list,
                              virPCIDevicePtr dev);
160

161 162 163 164 165 166 167
/*
 * Callback that will be invoked once for each file
 * associated with / used for PCI host device access.
 *
 * Should return 0 if successfully processed, or
 * -1 to indicate error and abort iteration
 */
168 169 170 171 172
typedef int (*virPCIDeviceFileActor)(virPCIDevicePtr dev,
                                     const char *path, void *opaque);
int virPCIDeviceFileIterate(virPCIDevicePtr dev,
                            virPCIDeviceFileActor actor,
                            void *opaque);
L
Laine Stump 已提交
173

174
typedef int (*virPCIDeviceAddressActor)(virPCIDeviceAddressPtr addr,
L
Laine Stump 已提交
175 176 177 178 179 180 181 182
                                        void *opaque);
int virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
                                         virPCIDeviceAddressActor actor,
                                         void *opaque);
virPCIDeviceListPtr virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev);
int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr,
                                              virPCIDeviceAddressPtr **iommuGroupDevices,
                                              size_t *nIommuGroupDevices);
183
int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr);
L
Laine Stump 已提交
184
char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev);
185

186 187 188
int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
                             int strict_acs_check);
int virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, const char *matcher);
J
Jiri Denemark 已提交
189

190 191 192
virPCIDeviceAddressPtr
virPCIGetDeviceAddressFromSysfsLink(const char *device_link);

193 194
int virPCIGetPhysicalFunction(const char *vf_sysfs_path,
                              virPCIDeviceAddressPtr *pf);
195

196 197
int virPCIGetVirtualFunctions(const char *sysfs_path,
                              virPCIDeviceAddressPtr **virtual_functions,
198 199
                              size_t *num_virtual_functions,
                              unsigned int *max_virtual_functions);
200

201
int virPCIIsVirtualFunction(const char *vf_sysfs_device_link);
202

203 204 205
int virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
                                        const char *vf_sysfs_device_link,
                                        int *vf_index);
206

207
int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr addr,
208
                                    char **pci_sysfs_device_link);
R
Roopa Prabhu 已提交
209

210 211 212 213
int virPCIGetNetName(const char *device_link_sysfs_path,
                     size_t idx,
                     char *physPortID,
                     char **netname);
214

215 216
int virPCIGetSysfsFile(char *virPCIDeviceName,
                             char **pci_sysfs_device_link)
217 218
    ATTRIBUTE_RETURN_CHECK;

219 220 221 222
int virPCIGetAddrString(unsigned int domain,
                        unsigned int bus,
                        unsigned int slot,
                        unsigned int function,
223
                        char **pciConfigAddr)
224
    ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
R
Roopa Prabhu 已提交
225

226 227
int virPCIDeviceAddressParse(char *address, virPCIDeviceAddressPtr bdf);

228 229
int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
                                 char **pfname, int *vf_index);
R
Roopa Prabhu 已提交
230

231
int virPCIDeviceUnbind(virPCIDevicePtr dev);
232
int virPCIDeviceRebind(virPCIDevicePtr dev);
233 234 235 236
int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev,
                                     char **path,
                                     char **name);

237 238 239 240 241 242 243 244
int virPCIDeviceIsPCIExpress(virPCIDevicePtr dev);
int virPCIDeviceHasPCIExpressLink(virPCIDevicePtr dev);
int virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev,
                              int *ca_port,
                              unsigned int *cap_speed,
                              unsigned int *cap_width,
                              unsigned int *sta_speed,
                              unsigned int *sta_width);
245

246 247
int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType);

248 249
void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev);

250
#endif /* __VIR_PCI_H__ */