xref: /kvm-unit-tests/lib/pci.h (revision 9ae19a633c0484a56df69cd2d4487242f3f27587)
1 #ifndef PCI_H
2 #define PCI_H
3 /*
4  * API for scanning a PCI bus for a given device, as well to access
5  * BAR registers.
6  *
7  * Copyright (C) 2013, Red Hat Inc, Michael S. Tsirkin <mst@redhat.com>
8  *
9  * This work is licensed under the terms of the GNU LGPL, version 2.
10  */
11 #include "libcflat.h"
12 
13 typedef uint16_t pcidevaddr_t;
14 enum {
15     PCIDEVADDR_INVALID = 0xffff,
16 };
17 pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id);
18 unsigned long pci_bar_addr(pcidevaddr_t dev, int bar_num);
19 bool pci_bar_is_memory(pcidevaddr_t dev, int bar_num);
20 bool pci_bar_is_valid(pcidevaddr_t dev, int bar_num);
21 
22 /*
23  * pci-testdev is a driver for the pci-testdev qemu pci device. The
24  * device enables testing mmio and portio exits, and measuring their
25  * speed.
26  */
27 #define PCI_VENDOR_ID_REDHAT		0x1b36
28 #define PCI_DEVICE_ID_REDHAT_TEST	0x0005
29 
30 #define PCI_TESTDEV_NUM_BARS		2
31 
32 struct pci_test_dev_hdr {
33 	uint8_t  test;
34 	uint8_t  width;
35 	uint8_t  pad0[2];
36 	uint32_t offset;
37 	uint32_t data;
38 	uint32_t count;
39 	uint8_t  name[];
40 };
41 
42 #endif /* PCI_H */
43