13384f95cSDavid Gibson /* 23384f95cSDavid Gibson * QEMU SPAPR PCI BUS definitions 33384f95cSDavid Gibson * 43384f95cSDavid Gibson * Copyright (c) 2011 Alexey Kardashevskiy <aik@au1.ibm.com> 53384f95cSDavid Gibson * 63384f95cSDavid Gibson * This library is free software; you can redistribute it and/or 73384f95cSDavid Gibson * modify it under the terms of the GNU Lesser General Public 83384f95cSDavid Gibson * License as published by the Free Software Foundation; either 961f3c91aSChetan Pant * version 2.1 of the License, or (at your option) any later version. 103384f95cSDavid Gibson * 113384f95cSDavid Gibson * This library is distributed in the hope that it will be useful, 123384f95cSDavid Gibson * but WITHOUT ANY WARRANTY; without even the implied warranty of 133384f95cSDavid Gibson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 143384f95cSDavid Gibson * Lesser General Public License for more details. 153384f95cSDavid Gibson * 163384f95cSDavid Gibson * You should have received a copy of the GNU Lesser General Public 173384f95cSDavid Gibson * License along with this library; if not, see <http://www.gnu.org/licenses/>. 183384f95cSDavid Gibson */ 193384f95cSDavid Gibson 20121d0712SMarkus Armbruster #ifndef PCI_HOST_SPAPR_H 21121d0712SMarkus Armbruster #define PCI_HOST_SPAPR_H 223384f95cSDavid Gibson 2320668fdeSMarkus Armbruster #include "hw/ppc/spapr.h" 24a2cb15b0SMichael S. Tsirkin #include "hw/pci/pci.h" 25a2cb15b0SMichael S. Tsirkin #include "hw/pci/pci_host.h" 260d09e41aSPaolo Bonzini #include "hw/ppc/xics.h" 27db1015e9SEduardo Habkost #include "qom/object.h" 283384f95cSDavid Gibson 298c9f64dfSAndreas Färber #define TYPE_SPAPR_PCI_HOST_BRIDGE "spapr-pci-host-bridge" 308c9f64dfSAndreas Färber 318063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(SpaprPhbState, SPAPR_PCI_HOST_BRIDGE) 328c9f64dfSAndreas Färber 33ae4de14cSAlexey Kardashevskiy #define SPAPR_PCI_DMA_MAX_WINDOWS 2 34ae4de14cSAlexey Kardashevskiy 35da6ccee4SAlexey Kardashevskiy 36572ebd08SGreg Kurz typedef struct SpaprPciMsi { 379a321e92SAlexey Kardashevskiy uint32_t first_irq; 389a321e92SAlexey Kardashevskiy uint32_t num; 39572ebd08SGreg Kurz } SpaprPciMsi; 409a321e92SAlexey Kardashevskiy 41572ebd08SGreg Kurz typedef struct SpaprPciMsiMig { 429a321e92SAlexey Kardashevskiy uint32_t key; 43572ebd08SGreg Kurz SpaprPciMsi value; 44572ebd08SGreg Kurz } SpaprPciMsiMig; 45572ebd08SGreg Kurz 46572ebd08SGreg Kurz typedef struct SpaprPciLsi { 47572ebd08SGreg Kurz uint32_t irq; 48572ebd08SGreg Kurz } SpaprPciLsi; 49572ebd08SGreg Kurz 50572ebd08SGreg Kurz typedef struct SpaprPhbPciNvGpuConfig SpaprPhbPciNvGpuConfig; 519a321e92SAlexey Kardashevskiy 52ce2918cbSDavid Gibson struct SpaprPhbState { 5367c332fdSAndreas Färber PCIHostState parent_obj; 543384f95cSDavid Gibson 553e4ac968SDavid Gibson uint32_t index; 563384f95cSDavid Gibson uint64_t buid; 57298a9710SDavid Gibson char *dtbusname; 587619c7b0SMichael Roth bool dr_enabled; 593384f95cSDavid Gibson 603384f95cSDavid Gibson MemoryRegion memspace, iospace; 61daa23699SDavid Gibson hwaddr mem_win_addr, mem_win_size, mem64_win_addr, mem64_win_size; 62daa23699SDavid Gibson uint64_t mem64_win_pciaddr; 63daa23699SDavid Gibson hwaddr io_win_addr, io_win_size; 64daa23699SDavid Gibson MemoryRegion mem32window, mem64window, iowindow, msiwindow; 650ee2c058SAlexey Kardashevskiy 66ae4de14cSAlexey Kardashevskiy uint32_t dma_liobn[SPAPR_PCI_DMA_MAX_WINDOWS]; 67f93caaacSDavid Gibson hwaddr dma_win_addr, dma_win_size; 68e00387d5SAvi Kivity AddressSpace iommu_as; 69cca7fad5SAlexey Kardashevskiy MemoryRegion iommu_root; 703384f95cSDavid Gibson 71572ebd08SGreg Kurz SpaprPciLsi lsi_table[PCI_NUM_PINS]; 723384f95cSDavid Gibson 739a321e92SAlexey Kardashevskiy GHashTable *msi; 749a321e92SAlexey Kardashevskiy /* Temporary cache for migration purposes */ 759a321e92SAlexey Kardashevskiy int32_t msi_devs_num; 76572ebd08SGreg Kurz SpaprPciMsiMig *msi_devs; 770ee2c058SAlexey Kardashevskiy 78ce2918cbSDavid Gibson QLIST_ENTRY(SpaprPhbState) list; 79ae4de14cSAlexey Kardashevskiy 80ae4de14cSAlexey Kardashevskiy bool ddw_enabled; 81ae4de14cSAlexey Kardashevskiy uint64_t page_size_mask; 82ae4de14cSAlexey Kardashevskiy uint64_t dma64_win_addr; 834814401fSAlexey Kardashevskiy 844814401fSAlexey Kardashevskiy uint32_t numa_node; 855c4537bdSDavid Gibson 8682516263SDavid Gibson bool pcie_ecs; /* Allow access to PCIe extended config space? */ 8782516263SDavid Gibson 885c4537bdSDavid Gibson /* Fields for migration compatibility hacks */ 895c4537bdSDavid Gibson bool pre_2_8_migration; 905c4537bdSDavid Gibson uint32_t mig_liobn; 915c4537bdSDavid Gibson hwaddr mig_mem_win_addr, mig_mem_win_size; 925c4537bdSDavid Gibson hwaddr mig_io_win_addr, mig_io_win_size; 93ec132efaSAlexey Kardashevskiy hwaddr nv2_gpa_win_addr; 94ec132efaSAlexey Kardashevskiy hwaddr nv2_atsd_win_addr; 95572ebd08SGreg Kurz SpaprPhbPciNvGpuConfig *nvgpus; 96a6030d7eSReza Arbab bool pre_5_1_assoc; 97da6ccee4SAlexey Kardashevskiy }; 983384f95cSDavid Gibson 99b194df47SAlexey Kardashevskiy #define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL 100daa23699SDavid Gibson #define SPAPR_PCI_MEM32_WIN_SIZE \ 101daa23699SDavid Gibson ((1ULL << 32) - SPAPR_PCI_MEM_WIN_BUS_OFFSET) 102357d1e3bSDavid Gibson #define SPAPR_PCI_MEM64_WIN_SIZE 0x10000000000ULL /* 1 TiB */ 103b194df47SAlexey Kardashevskiy 1041da85c2aSGreg Kurz /* All PCI outbound windows will be within this range */ 105357d1e3bSDavid Gibson #define SPAPR_PCI_BASE (1ULL << 45) /* 32 TiB */ 106357d1e3bSDavid Gibson #define SPAPR_PCI_LIMIT (1ULL << 46) /* 64 TiB */ 107357d1e3bSDavid Gibson 1081da85c2aSGreg Kurz #define SPAPR_MAX_PHBS ((SPAPR_PCI_LIMIT - SPAPR_PCI_BASE) / \ 1091da85c2aSGreg Kurz SPAPR_PCI_MEM64_WIN_SIZE - 1) 1101da85c2aSGreg Kurz 111caae58cbSDavid Gibson #define SPAPR_PCI_IO_WIN_SIZE 0x10000 112f1c2dc7cSAlexey Kardashevskiy 113f1c2dc7cSAlexey Kardashevskiy #define SPAPR_PCI_MSI_WINDOW 0x40000000000ULL 114caae58cbSDavid Gibson 115ec132efaSAlexey Kardashevskiy #define SPAPR_PCI_NV2RAM64_WIN_BASE SPAPR_PCI_LIMIT 116ec132efaSAlexey Kardashevskiy #define SPAPR_PCI_NV2RAM64_WIN_SIZE (2 * TiB) /* For up to 6 GPUs 256GB each */ 117ec132efaSAlexey Kardashevskiy 118ec132efaSAlexey Kardashevskiy /* Max number of NVLinks per GPU in any physical box */ 119ec132efaSAlexey Kardashevskiy #define NVGPU_MAX_LINKS 3 120ec132efaSAlexey Kardashevskiy 121ec132efaSAlexey Kardashevskiy /* 122ec132efaSAlexey Kardashevskiy * GPU RAM starts at 64TiB so huge DMA window to cover it all ends at 128TiB 123ec132efaSAlexey Kardashevskiy * which is enough. We do not need DMA for ATSD so we put them at 128TiB. 124ec132efaSAlexey Kardashevskiy */ 125ec132efaSAlexey Kardashevskiy #define SPAPR_PCI_NV2ATSD_WIN_BASE (128 * TiB) 126ec132efaSAlexey Kardashevskiy #define SPAPR_PCI_NV2ATSD_WIN_SIZE (NVGPU_MAX_NUM * NVGPU_MAX_LINKS * \ 127ec132efaSAlexey Kardashevskiy 64 * KiB) 128ec132efaSAlexey Kardashevskiy 1298cbe71ecSDavid Gibson int spapr_dt_phb(SpaprMachineState *spapr, SpaprPhbState *phb, 1308cbe71ecSDavid Gibson uint32_t intc_phandle, void *fdt, int *node_offset); 1313384f95cSDavid Gibson 132fa28f71bSAlexey Kardashevskiy void spapr_pci_rtas_init(void); 133fa28f71bSAlexey Kardashevskiy 134ce2918cbSDavid Gibson SpaprPhbState *spapr_pci_find_phb(SpaprMachineState *spapr, uint64_t buid); 135ce2918cbSDavid Gibson PCIDevice *spapr_pci_find_dev(SpaprMachineState *spapr, uint64_t buid, 13646c5874eSAlexey Kardashevskiy uint32_t config_addr); 13746c5874eSAlexey Kardashevskiy 13846fd0299SGreg Kurz /* DRC callbacks */ 13931834723SDaniel Henrique Barboza void spapr_phb_remove_pci_device_cb(DeviceState *dev); 140ce2918cbSDavid Gibson int spapr_pci_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr, 14146fd0299SGreg Kurz void *fdt, int *fdt_start_offset, Error **errp); 14231834723SDaniel Henrique Barboza 143fbb4e983SDavid Gibson /* VFIO EEH hooks */ 144fbb4e983SDavid Gibson #ifdef CONFIG_LINUX 145ce2918cbSDavid Gibson bool spapr_phb_eeh_available(SpaprPhbState *sphb); 146ce2918cbSDavid Gibson int spapr_phb_vfio_eeh_set_option(SpaprPhbState *sphb, 147fbb4e983SDavid Gibson unsigned int addr, int option); 148ce2918cbSDavid Gibson int spapr_phb_vfio_eeh_get_state(SpaprPhbState *sphb, int *state); 149ce2918cbSDavid Gibson int spapr_phb_vfio_eeh_reset(SpaprPhbState *sphb, int option); 150ce2918cbSDavid Gibson int spapr_phb_vfio_eeh_configure(SpaprPhbState *sphb); 151fbb4e983SDavid Gibson void spapr_phb_vfio_reset(DeviceState *qdev); 152ec132efaSAlexey Kardashevskiy void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp); 153ec132efaSAlexey Kardashevskiy void spapr_phb_nvgpu_free(SpaprPhbState *sphb); 154ec132efaSAlexey Kardashevskiy void spapr_phb_nvgpu_populate_dt(SpaprPhbState *sphb, void *fdt, int bus_off, 155ec132efaSAlexey Kardashevskiy Error **errp); 156ec132efaSAlexey Kardashevskiy void spapr_phb_nvgpu_ram_populate_dt(SpaprPhbState *sphb, void *fdt); 157ec132efaSAlexey Kardashevskiy void spapr_phb_nvgpu_populate_pcidev_dt(PCIDevice *dev, void *fdt, int offset, 158ec132efaSAlexey Kardashevskiy SpaprPhbState *sphb); 159fbb4e983SDavid Gibson #else 160ce2918cbSDavid Gibson static inline bool spapr_phb_eeh_available(SpaprPhbState *sphb) 161c1fa017cSDavid Gibson { 162c1fa017cSDavid Gibson return false; 163c1fa017cSDavid Gibson } 164ce2918cbSDavid Gibson static inline int spapr_phb_vfio_eeh_set_option(SpaprPhbState *sphb, 165fbb4e983SDavid Gibson unsigned int addr, int option) 166fbb4e983SDavid Gibson { 167fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 168fbb4e983SDavid Gibson } 169ce2918cbSDavid Gibson static inline int spapr_phb_vfio_eeh_get_state(SpaprPhbState *sphb, 170fbb4e983SDavid Gibson int *state) 171fbb4e983SDavid Gibson { 172fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 173fbb4e983SDavid Gibson } 174ce2918cbSDavid Gibson static inline int spapr_phb_vfio_eeh_reset(SpaprPhbState *sphb, int option) 175fbb4e983SDavid Gibson { 176fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 177fbb4e983SDavid Gibson } 178ce2918cbSDavid Gibson static inline int spapr_phb_vfio_eeh_configure(SpaprPhbState *sphb) 179fbb4e983SDavid Gibson { 180fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 181fbb4e983SDavid Gibson } 182fbb4e983SDavid Gibson static inline void spapr_phb_vfio_reset(DeviceState *qdev) 183fbb4e983SDavid Gibson { 184fbb4e983SDavid Gibson } 185ec132efaSAlexey Kardashevskiy static inline void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp) 186ec132efaSAlexey Kardashevskiy { 187ec132efaSAlexey Kardashevskiy } 188ec132efaSAlexey Kardashevskiy static inline void spapr_phb_nvgpu_free(SpaprPhbState *sphb) 189ec132efaSAlexey Kardashevskiy { 190ec132efaSAlexey Kardashevskiy } 191ec132efaSAlexey Kardashevskiy static inline void spapr_phb_nvgpu_populate_dt(SpaprPhbState *sphb, void *fdt, 192ec132efaSAlexey Kardashevskiy int bus_off, Error **errp) 193ec132efaSAlexey Kardashevskiy { 194ec132efaSAlexey Kardashevskiy } 195ec132efaSAlexey Kardashevskiy static inline void spapr_phb_nvgpu_ram_populate_dt(SpaprPhbState *sphb, 196ec132efaSAlexey Kardashevskiy void *fdt) 197ec132efaSAlexey Kardashevskiy { 198ec132efaSAlexey Kardashevskiy } 199ec132efaSAlexey Kardashevskiy static inline void spapr_phb_nvgpu_populate_pcidev_dt(PCIDevice *dev, void *fdt, 200ec132efaSAlexey Kardashevskiy int offset, 201ec132efaSAlexey Kardashevskiy SpaprPhbState *sphb) 202ec132efaSAlexey Kardashevskiy { 203ec132efaSAlexey Kardashevskiy } 204fbb4e983SDavid Gibson #endif 205fbb4e983SDavid Gibson 206ce2918cbSDavid Gibson void spapr_phb_dma_reset(SpaprPhbState *sphb); 207b3162f22SAlexey Kardashevskiy 208ce2918cbSDavid Gibson static inline unsigned spapr_phb_windows_supported(SpaprPhbState *sphb) 209ef28b98dSGreg Kurz { 210ef28b98dSGreg Kurz return sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1; 211ef28b98dSGreg Kurz } 212ef28b98dSGreg Kurz 213*040bdafcSGreg Kurz char *spapr_pci_fw_dev_name(PCIDevice *dev); 214*040bdafcSGreg Kurz 215121d0712SMarkus Armbruster #endif /* PCI_HOST_SPAPR_H */ 216