xref: /openbmc/qemu/include/hw/pci/pcie_sriov.h (revision 4f7b1ecb)
1 /*
2  * pcie_sriov.h:
3  *
4  * Implementation of SR/IOV emulation support.
5  *
6  * Copyright (c) 2015 Knut Omang <knut.omang@oracle.com>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or later.
9  * See the COPYING file in the top-level directory.
10  *
11  */
12 
13 #ifndef QEMU_PCIE_SRIOV_H
14 #define QEMU_PCIE_SRIOV_H
15 
16 #include "hw/pci/pci.h"
17 
18 typedef struct PCIESriovPF {
19     uint8_t vf_bar_type[PCI_NUM_REGIONS];   /* Store type for each VF bar */
20     PCIDevice **vf;     /* Pointer to an array of num_vfs VF devices */
21 } PCIESriovPF;
22 
23 typedef struct PCIESriovVF {
24     PCIDevice *pf;      /* Pointer back to owner physical function */
25     uint16_t vf_number; /* Logical VF number of this function */
26 } PCIESriovVF;
27 
28 bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
29                         const char *vfname, uint16_t vf_dev_id,
30                         uint16_t init_vfs, uint16_t total_vfs,
31                         uint16_t vf_offset, uint16_t vf_stride,
32                         Error **errp);
33 void pcie_sriov_pf_exit(PCIDevice *dev);
34 
35 /* Set up a VF bar in the SR/IOV bar area */
36 void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num,
37                                uint8_t type, dma_addr_t size);
38 
39 /* Instantiate a bar for a VF */
40 void pcie_sriov_vf_register_bar(PCIDevice *dev, int region_num,
41                                 MemoryRegion *memory);
42 
43 /*
44  * Default (minimal) page size support values
45  * as required by the SR/IOV standard:
46  * 0x553 << 12 = 0x553000 = 4K + 8K + 64K + 256K + 1M + 4M
47  */
48 #define SRIOV_SUP_PGSIZE_MINREQ 0x553
49 
50 /*
51  * Optionally add supported page sizes to the mask of supported page sizes
52  * Page size values are interpreted as opt_sup_pgsize << 12.
53  */
54 void pcie_sriov_pf_add_sup_pgsize(PCIDevice *dev, uint16_t opt_sup_pgsize);
55 
56 /* SR/IOV capability config write handler */
57 void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
58                              uint32_t val, int len);
59 
60 void pcie_sriov_pf_post_load(PCIDevice *dev);
61 
62 /* Reset SR/IOV */
63 void pcie_sriov_pf_reset(PCIDevice *dev);
64 
65 /* Get logical VF number of a VF - only valid for VFs */
66 uint16_t pcie_sriov_vf_number(PCIDevice *dev);
67 
68 /*
69  * Get the physical function that owns this VF.
70  * Returns NULL if dev is not a virtual function
71  */
72 PCIDevice *pcie_sriov_get_pf(PCIDevice *dev);
73 
74 /*
75  * Get the n-th VF of this physical function - only valid for PF.
76  * Returns NULL if index is invalid
77  */
78 PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, int n);
79 
80 /* Returns the current number of virtual functions. */
81 uint16_t pcie_sriov_num_vfs(PCIDevice *dev);
82 
83 #endif /* QEMU_PCIE_SRIOV_H */
84