4 * Implementation of SR/IOV emulation support.
6 * Copyright (c) 2015 Knut Omang <knut.omang@oracle.com>
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.
13 #ifndef QEMU_PCIE_SRIOV_H
14 #define QEMU_PCIE_SRIOV_H
16 #include "hw/pci/pci.h"
18 typedef struct PCIESriovPF
{
19 uint16_t num_vfs
; /* Number of virtual functions created */
20 uint8_t vf_bar_type
[PCI_NUM_REGIONS
]; /* Store type for each VF bar */
21 const char *vfname
; /* Reference to the device type used for the VFs */
22 PCIDevice
**vf
; /* Pointer to an array of num_vfs VF devices */
25 typedef struct PCIESriovVF
{
26 PCIDevice
*pf
; /* Pointer back to owner physical function */
27 uint16_t vf_number
; /* Logical VF number of this function */
30 void pcie_sriov_pf_init(PCIDevice
*dev
, uint16_t offset
,
31 const char *vfname
, uint16_t vf_dev_id
,
32 uint16_t init_vfs
, uint16_t total_vfs
,
33 uint16_t vf_offset
, uint16_t vf_stride
);
34 void pcie_sriov_pf_exit(PCIDevice
*dev
);
36 /* Set up a VF bar in the SR/IOV bar area */
37 void pcie_sriov_pf_init_vf_bar(PCIDevice
*dev
, int region_num
,
38 uint8_t type
, dma_addr_t size
);
40 /* Instantiate a bar for a VF */
41 void pcie_sriov_vf_register_bar(PCIDevice
*dev
, int region_num
,
42 MemoryRegion
*memory
);
45 * Default (minimal) page size support values
46 * as required by the SR/IOV standard:
47 * 0x553 << 12 = 0x553000 = 4K + 8K + 64K + 256K + 1M + 4M
49 #define SRIOV_SUP_PGSIZE_MINREQ 0x553
52 * Optionally add supported page sizes to the mask of supported page sizes
53 * Page size values are interpreted as opt_sup_pgsize << 12.
55 void pcie_sriov_pf_add_sup_pgsize(PCIDevice
*dev
, uint16_t opt_sup_pgsize
);
57 /* SR/IOV capability config write handler */
58 void pcie_sriov_config_write(PCIDevice
*dev
, uint32_t address
,
59 uint32_t val
, int len
);
62 void pcie_sriov_pf_reset(PCIDevice
*dev
);
64 /* Get logical VF number of a VF - only valid for VFs */
65 uint16_t pcie_sriov_vf_number(PCIDevice
*dev
);
68 * Get the physical function that owns this VF.
69 * Returns NULL if dev is not a virtual function
71 PCIDevice
*pcie_sriov_get_pf(PCIDevice
*dev
);
74 * Get the n-th VF of this physical function - only valid for PF.
75 * Returns NULL if index is invalid
77 PCIDevice
*pcie_sriov_get_vf_at_index(PCIDevice
*dev
, int n
);
79 /* Returns the current number of virtual functions. */
80 uint16_t pcie_sriov_num_vfs(PCIDevice
*dev
);
82 #endif /* QEMU_PCIE_SRIOV_H */