17c0fa8dfSKnut Omang /* 27c0fa8dfSKnut Omang * pcie_sriov.h: 37c0fa8dfSKnut Omang * 47c0fa8dfSKnut Omang * Implementation of SR/IOV emulation support. 57c0fa8dfSKnut Omang * 67c0fa8dfSKnut Omang * Copyright (c) 2015 Knut Omang <knut.omang@oracle.com> 77c0fa8dfSKnut Omang * 87c0fa8dfSKnut Omang * This work is licensed under the terms of the GNU GPL, version 2 or later. 97c0fa8dfSKnut Omang * See the COPYING file in the top-level directory. 107c0fa8dfSKnut Omang * 117c0fa8dfSKnut Omang */ 127c0fa8dfSKnut Omang 137c0fa8dfSKnut Omang #ifndef QEMU_PCIE_SRIOV_H 147c0fa8dfSKnut Omang #define QEMU_PCIE_SRIOV_H 157c0fa8dfSKnut Omang 16104a2dd6SMarkus Armbruster #include "hw/pci/pci.h" 17104a2dd6SMarkus Armbruster 187c0fa8dfSKnut Omang struct PCIESriovPF { 197c0fa8dfSKnut Omang uint16_t num_vfs; /* Number of virtual functions created */ 207c0fa8dfSKnut Omang uint8_t vf_bar_type[PCI_NUM_REGIONS]; /* Store type for each VF bar */ 217c0fa8dfSKnut Omang const char *vfname; /* Reference to the device type used for the VFs */ 227c0fa8dfSKnut Omang PCIDevice **vf; /* Pointer to an array of num_vfs VF devices */ 237c0fa8dfSKnut Omang }; 247c0fa8dfSKnut Omang 257c0fa8dfSKnut Omang struct PCIESriovVF { 267c0fa8dfSKnut Omang PCIDevice *pf; /* Pointer back to owner physical function */ 277c0fa8dfSKnut Omang uint16_t vf_number; /* Logical VF number of this function */ 287c0fa8dfSKnut Omang }; 297c0fa8dfSKnut Omang 307c0fa8dfSKnut Omang void pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset, 317c0fa8dfSKnut Omang const char *vfname, uint16_t vf_dev_id, 327c0fa8dfSKnut Omang uint16_t init_vfs, uint16_t total_vfs, 337c0fa8dfSKnut Omang uint16_t vf_offset, uint16_t vf_stride); 347c0fa8dfSKnut Omang void pcie_sriov_pf_exit(PCIDevice *dev); 357c0fa8dfSKnut Omang 367c0fa8dfSKnut Omang /* Set up a VF bar in the SR/IOV bar area */ 377c0fa8dfSKnut Omang void pcie_sriov_pf_init_vf_bar(PCIDevice *dev, int region_num, 387c0fa8dfSKnut Omang uint8_t type, dma_addr_t size); 397c0fa8dfSKnut Omang 407c0fa8dfSKnut Omang /* Instantiate a bar for a VF */ 417c0fa8dfSKnut Omang void pcie_sriov_vf_register_bar(PCIDevice *dev, int region_num, 427c0fa8dfSKnut Omang MemoryRegion *memory); 437c0fa8dfSKnut Omang 447c0fa8dfSKnut Omang /* 457c0fa8dfSKnut Omang * Default (minimal) page size support values 467c0fa8dfSKnut Omang * as required by the SR/IOV standard: 477c0fa8dfSKnut Omang * 0x553 << 12 = 0x553000 = 4K + 8K + 64K + 256K + 1M + 4M 487c0fa8dfSKnut Omang */ 497c0fa8dfSKnut Omang #define SRIOV_SUP_PGSIZE_MINREQ 0x553 507c0fa8dfSKnut Omang 517c0fa8dfSKnut Omang /* 527c0fa8dfSKnut Omang * Optionally add supported page sizes to the mask of supported page sizes 537c0fa8dfSKnut Omang * Page size values are interpreted as opt_sup_pgsize << 12. 547c0fa8dfSKnut Omang */ 557c0fa8dfSKnut Omang void pcie_sriov_pf_add_sup_pgsize(PCIDevice *dev, uint16_t opt_sup_pgsize); 567c0fa8dfSKnut Omang 577c0fa8dfSKnut Omang /* SR/IOV capability config write handler */ 587c0fa8dfSKnut Omang void pcie_sriov_config_write(PCIDevice *dev, uint32_t address, 597c0fa8dfSKnut Omang uint32_t val, int len); 607c0fa8dfSKnut Omang 61*c8bc4db4SAkihiko Odaki /* Reset SR/IOV */ 62*c8bc4db4SAkihiko Odaki void pcie_sriov_pf_reset(PCIDevice *dev); 637c0fa8dfSKnut Omang 647c0fa8dfSKnut Omang /* Get logical VF number of a VF - only valid for VFs */ 657c0fa8dfSKnut Omang uint16_t pcie_sriov_vf_number(PCIDevice *dev); 667c0fa8dfSKnut Omang 677c0fa8dfSKnut Omang /* 687c0fa8dfSKnut Omang * Get the physical function that owns this VF. 697c0fa8dfSKnut Omang * Returns NULL if dev is not a virtual function 707c0fa8dfSKnut Omang */ 717c0fa8dfSKnut Omang PCIDevice *pcie_sriov_get_pf(PCIDevice *dev); 727c0fa8dfSKnut Omang 7369387f49SŁukasz Gieryk /* 7469387f49SŁukasz Gieryk * Get the n-th VF of this physical function - only valid for PF. 7569387f49SŁukasz Gieryk * Returns NULL if index is invalid 7669387f49SŁukasz Gieryk */ 7769387f49SŁukasz Gieryk PCIDevice *pcie_sriov_get_vf_at_index(PCIDevice *dev, int n); 7869387f49SŁukasz Gieryk 7931180dbdSAkihiko Odaki /* Returns the current number of virtual functions. */ 8031180dbdSAkihiko Odaki uint16_t pcie_sriov_num_vfs(PCIDevice *dev); 8131180dbdSAkihiko Odaki 827c0fa8dfSKnut Omang #endif /* QEMU_PCIE_SRIOV_H */ 83