2016-06-14 01:19:17 +02:00
|
|
|
/** Linux PCI helpers
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, Steffen Vogel
|
2016-06-14 01:19:17 +02:00
|
|
|
**********************************************************************************/
|
|
|
|
|
2017-03-03 20:20:13 -04:00
|
|
|
/** @addtogroup fpga Kernel @{ */
|
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-10-08 20:10:36 -04:00
|
|
|
#include "list.h"
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-10-08 20:10:36 -04:00
|
|
|
#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f)
|
|
|
|
#define PCI_FUNC(devfn) ((devfn) & 0x07)
|
2016-06-19 19:23:19 +02:00
|
|
|
|
2017-03-27 12:57:41 +02:00
|
|
|
struct pci_device {
|
2016-10-08 20:10:36 -04:00
|
|
|
struct {
|
|
|
|
int vendor;
|
|
|
|
int device;
|
|
|
|
int class;
|
|
|
|
} id;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2016-10-08 20:10:36 -04:00
|
|
|
struct {
|
|
|
|
int domain;
|
|
|
|
int bus;
|
|
|
|
int device;
|
|
|
|
int function;
|
|
|
|
} slot; /**< Bus, Device, Function (BDF) */
|
|
|
|
};
|
2016-06-19 19:23:19 +02:00
|
|
|
|
2016-10-08 20:10:36 -04:00
|
|
|
struct pci {
|
2017-03-27 12:57:41 +02:00
|
|
|
struct list devices; /**< List of available PCI devices in the system (struct pci_device) */
|
2016-10-08 20:10:36 -04:00
|
|
|
};
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-10-08 20:10:36 -04:00
|
|
|
/** Initialize Linux PCI handle.
|
|
|
|
*
|
|
|
|
* This search for all available PCI devices under /sys/bus/pci
|
|
|
|
*
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
|
|
|
int pci_init(struct pci *p);
|
|
|
|
|
|
|
|
/** Destroy handle. */
|
2017-02-18 10:45:05 -05:00
|
|
|
int pci_destroy(struct pci *p);
|
2016-10-08 20:10:36 -04:00
|
|
|
|
2017-03-27 12:57:41 +02:00
|
|
|
int pci_device_parse_slot(struct pci_device *f, const char *str, const char **error);
|
2016-10-08 20:10:36 -04:00
|
|
|
|
2017-03-27 12:57:41 +02:00
|
|
|
int pci_device_parse_id(struct pci_device *f, const char *str, const char **error);
|
2016-10-08 20:10:36 -04:00
|
|
|
|
2017-03-27 12:57:41 +02:00
|
|
|
int pci_device_compare(const struct pci_device *d, const struct pci_device *f);
|
2016-10-08 20:10:36 -04:00
|
|
|
|
2017-03-27 12:57:41 +02:00
|
|
|
struct pci_device * pci_lookup_device(struct pci *p, struct pci_device *filter);
|
2016-10-08 20:10:36 -04:00
|
|
|
|
|
|
|
/** Bind a new LKM to the PCI device */
|
2017-03-27 12:57:41 +02:00
|
|
|
int pci_attach_driver(struct pci_device *d, const char *driver);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-10-08 20:10:36 -04:00
|
|
|
/** Return the IOMMU group of this PCI device or -1 if the device is not in a group. */
|
2017-03-27 12:57:41 +02:00
|
|
|
int pci_get_iommu_group(struct pci_device *d);
|
2017-03-03 20:20:13 -04:00
|
|
|
|
|
|
|
/** @} */
|