pci.h 4.4 KB
Newer Older
1
/*
2
 * Copyright (C) 2009, 2011 Red Hat, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Authors:
 *     Mark McLoughlin <markmc@redhat.com>
 */

#ifndef __VIR_PCI_H__
23
# define __VIR_PCI_H__
24

25
# include "internal.h"
26 27

typedef struct _pciDevice pciDevice;
28
typedef struct _pciDeviceList pciDeviceList;
29

30 31 32 33 34 35 36
struct pci_config_address {
    unsigned int domain;
    unsigned int bus;
    unsigned int slot;
    unsigned int function;
};

37
pciDevice *pciGetDevice      (unsigned       domain,
38 39 40
                              unsigned       bus,
                              unsigned       slot,
                              unsigned       function);
41
void       pciFreeDevice     (pciDevice     *dev);
42
const char *pciDeviceGetName (pciDevice     *dev);
43 44
int        pciDettachDevice  (pciDevice     *dev, pciDeviceList *activeDevs);
int        pciReAttachDevice (pciDevice     *dev, pciDeviceList *activeDevs);
45
int        pciResetDevice    (pciDevice     *dev,
46 47
                              pciDeviceList *activeDevs,
                              pciDeviceList *inactiveDevs);
48 49 50
void      pciDeviceSetManaged(pciDevice     *dev,
                              unsigned       managed);
unsigned  pciDeviceGetManaged(pciDevice     *dev);
51 52 53
void      pciDeviceSetUsedBy(pciDevice     *dev,
                             const char *used_by);
const char *pciDeviceGetUsedBy(pciDevice   *dev);
54 55 56 57 58 59 60 61 62
unsigned  pciDeviceGetUnbindFromStub(pciDevice *dev);
void      pciDeviceSetUnbindFromStub(pciDevice     *dev,
                                     unsigned      unbind);
unsigned  pciDeviceGetRemoveSlot(pciDevice *dev);
void      pciDeviceSetRemoveSlot(pciDevice     *dev,
                                 unsigned      remove_slot);
unsigned  pciDeviceGetReprobe(pciDevice *dev);
void      pciDeviceSetReprobe(pciDevice     *dev,
                              unsigned      reprobe);
63
void      pciDeviceReAttachInit(pciDevice   *dev);
64

65 66 67
pciDeviceList *pciDeviceListNew  (void);
void           pciDeviceListFree (pciDeviceList *list);
int            pciDeviceListAdd  (pciDeviceList *list,
68
                                  pciDevice *dev);
69 70 71
pciDevice *    pciDeviceListGet (pciDeviceList *list,
                                 int idx);
int            pciDeviceListCount (pciDeviceList *list);
72
pciDevice *    pciDeviceListSteal (pciDeviceList *list,
73
                                   pciDevice *dev);
74
void           pciDeviceListDel  (pciDeviceList *list,
75 76 77
                                  pciDevice *dev);
pciDevice *    pciDeviceListFind (pciDeviceList *list,
                                  pciDevice *dev);
78

79 80 81 82 83 84 85
/*
 * 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
 */
86
typedef int (*pciDeviceFileActor)(pciDevice *dev,
87 88
                                  const char *path, void *opaque);

89
int pciDeviceFileIterate(pciDevice *dev,
90 91 92
                         pciDeviceFileActor actor,
                         void *opaque);

93
int pciDeviceIsAssignable(pciDevice *dev,
J
Jiri Denemark 已提交
94
                          int strict_acs_check);
95
int pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher);
J
Jiri Denemark 已提交
96

97 98 99 100 101 102 103
int pciGetPhysicalFunction(const char *sysfs_path,
                           struct pci_config_address **phys_fn);

int pciGetVirtualFunctions(const char *sysfs_path,
                           struct pci_config_address ***virtual_functions,
                           unsigned int *num_virtual_functions);

104 105 106 107 108 109 110 111
int pciDeviceIsVirtualFunction(const char *vf_sysfs_device_link);

int pciGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
                               const char *vf_sysfs_device_link,
                               int *vf_index);

int pciDeviceNetName(char *device_link_sysfs_path, char **netname);

112
#endif /* __VIR_PCI_H__ */