virpci.h 7.3 KB
Newer Older
1
/*
2 3
 * virpci.h: helper APIs for managing host PCI devices
 *
4
 * Copyright (C) 2009, 2011-2013 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

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

struct _virPCIDeviceAddress {
38 39 40 41 42 43
    unsigned int domain;
    unsigned int bus;
    unsigned int slot;
    unsigned int function;
};

44 45 46 47
virPCIDevicePtr virPCIDeviceNew(unsigned int domain,
                                unsigned int bus,
                                unsigned int slot,
                                unsigned int function);
L
Laine Stump 已提交
48
virPCIDevicePtr virPCIDeviceCopy(virPCIDevicePtr dev);
49 50 51 52 53
void virPCIDeviceFree(virPCIDevicePtr dev);
const char *virPCIDeviceGetName(virPCIDevicePtr dev);

int virPCIDeviceDetach(virPCIDevicePtr dev,
                       virPCIDeviceListPtr activeDevs,
54
                       virPCIDeviceListPtr inactiveDevs);
55 56
int virPCIDeviceReattach(virPCIDevicePtr dev,
                         virPCIDeviceListPtr activeDevs,
57
                         virPCIDeviceListPtr inactiveDevs);
58 59 60 61 62
int virPCIDeviceReset(virPCIDevicePtr dev,
                      virPCIDeviceListPtr activeDevs,
                      virPCIDeviceListPtr inactiveDevs);

void virPCIDeviceSetManaged(virPCIDevice *dev,
63
                            bool managed);
64
unsigned int virPCIDeviceGetManaged(virPCIDevice *dev);
65
int virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
J
John Ferlan 已提交
66 67
                              const char *driver)
    ATTRIBUTE_NONNULL(2);
68
const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
69 70 71
void virPCIDeviceSetUsedBy(virPCIDevice *dev,
                           const char *used_by);
const char *virPCIDeviceGetUsedBy(virPCIDevice *dev);
72
unsigned int virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
73
void  virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
74
                                    bool unbind);
75
unsigned int virPCIDeviceGetRemoveSlot(virPCIDevicePtr dev);
76
void virPCIDeviceSetRemoveSlot(virPCIDevice *dev,
77
                               bool remove_slot);
78
unsigned int virPCIDeviceGetReprobe(virPCIDevicePtr dev);
79
void virPCIDeviceSetReprobe(virPCIDevice *dev,
80
                            bool reprobe);
81 82 83 84 85 86
void virPCIDeviceReattachInit(virPCIDevice *dev);


virPCIDeviceListPtr virPCIDeviceListNew(void);
int  virPCIDeviceListAdd(virPCIDeviceListPtr list,
                         virPCIDevicePtr dev);
L
Laine Stump 已提交
87
int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev);
88 89
virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list,
                                    int idx);
90
size_t virPCIDeviceListCount(virPCIDeviceListPtr list);
91 92 93 94 95 96 97 98
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 已提交
99 100 101 102 103 104
virPCIDevicePtr
virPCIDeviceListFindByIDs(virPCIDeviceListPtr list,
                          unsigned int domain,
                          unsigned int bus,
                          unsigned int slot,
                          unsigned int function);
105 106
int virPCIDeviceListFindIndex(virPCIDeviceListPtr list,
                              virPCIDevicePtr dev);
107

108 109 110 111 112 113 114
/*
 * 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
 */
115 116 117 118 119
typedef int (*virPCIDeviceFileActor)(virPCIDevicePtr dev,
                                     const char *path, void *opaque);
int virPCIDeviceFileIterate(virPCIDevicePtr dev,
                            virPCIDeviceFileActor actor,
                            void *opaque);
L
Laine Stump 已提交
120 121 122 123 124 125 126 127 128 129 130 131

typedef int (*virPCIDeviceAddressActor)(virPCIDeviceAddress *addr,
                                        void *opaque);
int virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
                                         virPCIDeviceAddressActor actor,
                                         void *opaque);
virPCIDeviceListPtr virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev);
int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr,
                                              virPCIDeviceAddressPtr **iommuGroupDevices,
                                              size_t *nIommuGroupDevices);
int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr dev);
char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev);
132

133 134 135
int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
                             int strict_acs_check);
int virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, const char *matcher);
J
Jiri Denemark 已提交
136

137 138
int virPCIGetPhysicalFunction(const char *sysfs_path,
                              virPCIDeviceAddressPtr *phys_fn);
139

140 141
int virPCIGetVirtualFunctions(const char *sysfs_path,
                              virPCIDeviceAddressPtr **virtual_functions,
142
                              size_t *num_virtual_functions);
143

144
int virPCIIsVirtualFunction(const char *vf_sysfs_device_link);
145

146 147 148
int virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
                                        const char *vf_sysfs_device_link,
                                        int *vf_index);
149

150 151
int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr dev,
                                    char **pci_sysfs_device_link);
R
Roopa Prabhu 已提交
152

153
int virPCIGetNetName(char *device_link_sysfs_path, char **netname);
154

155 156
int virPCIGetSysfsFile(char *virPCIDeviceName,
                             char **pci_sysfs_device_link)
157 158
    ATTRIBUTE_RETURN_CHECK;

159 160 161 162
int virPCIGetAddrString(unsigned int domain,
                        unsigned int bus,
                        unsigned int slot,
                        unsigned int function,
163
                        char **pciConfigAddr)
164
    ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
R
Roopa Prabhu 已提交
165

166 167
int virPCIDeviceAddressParse(char *address, virPCIDeviceAddressPtr bdf);

168 169
int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
                                 char **pfname, int *vf_index);
R
Roopa Prabhu 已提交
170

171 172 173 174 175
int virPCIDeviceUnbind(virPCIDevicePtr dev, bool reprobe);
int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev,
                                     char **path,
                                     char **name);

176
#endif /* __VIR_PCI_H__ */