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 93384f95cSDavid Gibson * version 2 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" 273384f95cSDavid Gibson 288c9f64dfSAndreas Färber #define TYPE_SPAPR_PCI_HOST_BRIDGE "spapr-pci-host-bridge" 298c9f64dfSAndreas Färber 308c9f64dfSAndreas Färber #define SPAPR_PCI_HOST_BRIDGE(obj) \ 318c9f64dfSAndreas Färber OBJECT_CHECK(sPAPRPHBState, (obj), TYPE_SPAPR_PCI_HOST_BRIDGE) 328c9f64dfSAndreas Färber 33ae4de14cSAlexey Kardashevskiy #define SPAPR_PCI_DMA_MAX_WINDOWS 2 34ae4de14cSAlexey Kardashevskiy 35da6ccee4SAlexey Kardashevskiy typedef struct sPAPRPHBState sPAPRPHBState; 36da6ccee4SAlexey Kardashevskiy 379a321e92SAlexey Kardashevskiy typedef struct spapr_pci_msi { 389a321e92SAlexey Kardashevskiy uint32_t first_irq; 399a321e92SAlexey Kardashevskiy uint32_t num; 409a321e92SAlexey Kardashevskiy } spapr_pci_msi; 419a321e92SAlexey Kardashevskiy 429a321e92SAlexey Kardashevskiy typedef struct spapr_pci_msi_mig { 439a321e92SAlexey Kardashevskiy uint32_t key; 449a321e92SAlexey Kardashevskiy spapr_pci_msi value; 459a321e92SAlexey Kardashevskiy } spapr_pci_msi_mig; 469a321e92SAlexey Kardashevskiy 47da6ccee4SAlexey Kardashevskiy struct sPAPRPHBState { 4867c332fdSAndreas Färber PCIHostState parent_obj; 493384f95cSDavid Gibson 503e4ac968SDavid Gibson uint32_t index; 513384f95cSDavid Gibson uint64_t buid; 52298a9710SDavid Gibson char *dtbusname; 537619c7b0SMichael Roth bool dr_enabled; 543384f95cSDavid Gibson 553384f95cSDavid Gibson MemoryRegion memspace, iospace; 56daa23699SDavid Gibson hwaddr mem_win_addr, mem_win_size, mem64_win_addr, mem64_win_size; 57daa23699SDavid Gibson uint64_t mem64_win_pciaddr; 58daa23699SDavid Gibson hwaddr io_win_addr, io_win_size; 59daa23699SDavid Gibson MemoryRegion mem32window, mem64window, iowindow, msiwindow; 600ee2c058SAlexey Kardashevskiy 61ae4de14cSAlexey Kardashevskiy uint32_t dma_liobn[SPAPR_PCI_DMA_MAX_WINDOWS]; 62f93caaacSDavid Gibson hwaddr dma_win_addr, dma_win_size; 63e00387d5SAvi Kivity AddressSpace iommu_as; 64cca7fad5SAlexey Kardashevskiy MemoryRegion iommu_root; 653384f95cSDavid Gibson 661112cf94SDavid Gibson struct spapr_pci_lsi { 67a307d594SAlexey Kardashevskiy uint32_t irq; 687fb0bd34SDavid Gibson } lsi_table[PCI_NUM_PINS]; 693384f95cSDavid Gibson 709a321e92SAlexey Kardashevskiy GHashTable *msi; 719a321e92SAlexey Kardashevskiy /* Temporary cache for migration purposes */ 729a321e92SAlexey Kardashevskiy int32_t msi_devs_num; 739a321e92SAlexey Kardashevskiy spapr_pci_msi_mig *msi_devs; 740ee2c058SAlexey Kardashevskiy 753384f95cSDavid Gibson QLIST_ENTRY(sPAPRPHBState) list; 76ae4de14cSAlexey Kardashevskiy 77ae4de14cSAlexey Kardashevskiy bool ddw_enabled; 78ae4de14cSAlexey Kardashevskiy uint64_t page_size_mask; 79ae4de14cSAlexey Kardashevskiy uint64_t dma64_win_addr; 804814401fSAlexey Kardashevskiy 814814401fSAlexey Kardashevskiy uint32_t numa_node; 82*5c4537bdSDavid Gibson 83*5c4537bdSDavid Gibson /* Fields for migration compatibility hacks */ 84*5c4537bdSDavid Gibson bool pre_2_8_migration; 85*5c4537bdSDavid Gibson uint32_t mig_liobn; 86*5c4537bdSDavid Gibson hwaddr mig_mem_win_addr, mig_mem_win_size; 87*5c4537bdSDavid Gibson hwaddr mig_io_win_addr, mig_io_win_size; 88da6ccee4SAlexey Kardashevskiy }; 893384f95cSDavid Gibson 90b194df47SAlexey Kardashevskiy #define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL 91daa23699SDavid Gibson #define SPAPR_PCI_MEM32_WIN_SIZE \ 92daa23699SDavid Gibson ((1ULL << 32) - SPAPR_PCI_MEM_WIN_BUS_OFFSET) 93357d1e3bSDavid Gibson #define SPAPR_PCI_MEM64_WIN_SIZE 0x10000000000ULL /* 1 TiB */ 94b194df47SAlexey Kardashevskiy 95357d1e3bSDavid Gibson /* Without manual configuration, all PCI outbound windows will be 96357d1e3bSDavid Gibson * within this range */ 97357d1e3bSDavid Gibson #define SPAPR_PCI_BASE (1ULL << 45) /* 32 TiB */ 98357d1e3bSDavid Gibson #define SPAPR_PCI_LIMIT (1ULL << 46) /* 64 TiB */ 99357d1e3bSDavid Gibson 100357d1e3bSDavid Gibson #define SPAPR_PCI_2_7_MMIO_WIN_SIZE 0xf80000000 101caae58cbSDavid Gibson #define SPAPR_PCI_IO_WIN_SIZE 0x10000 102f1c2dc7cSAlexey Kardashevskiy 103f1c2dc7cSAlexey Kardashevskiy #define SPAPR_PCI_MSI_WINDOW 0x40000000000ULL 104caae58cbSDavid Gibson 105a307d594SAlexey Kardashevskiy static inline qemu_irq spapr_phb_lsi_qirq(struct sPAPRPHBState *phb, int pin) 106a307d594SAlexey Kardashevskiy { 10728e02042SDavid Gibson sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); 10828e02042SDavid Gibson 10927f24582SBenjamin Herrenschmidt return xics_get_qirq(spapr->xics, phb->lsi_table[pin].irq); 110a307d594SAlexey Kardashevskiy } 111a307d594SAlexey Kardashevskiy 11228e02042SDavid Gibson PCIHostState *spapr_create_phb(sPAPRMachineState *spapr, int index); 1133384f95cSDavid Gibson 114e0fdbd7cSAlexey Kardashevskiy int spapr_populate_pci_dt(sPAPRPHBState *phb, 1153384f95cSDavid Gibson uint32_t xics_phandle, 1163384f95cSDavid Gibson void *fdt); 1173384f95cSDavid Gibson 118fa28f71bSAlexey Kardashevskiy void spapr_pci_rtas_init(void); 119fa28f71bSAlexey Kardashevskiy 12028e02042SDavid Gibson sPAPRPHBState *spapr_pci_find_phb(sPAPRMachineState *spapr, uint64_t buid); 12128e02042SDavid Gibson PCIDevice *spapr_pci_find_dev(sPAPRMachineState *spapr, uint64_t buid, 12246c5874eSAlexey Kardashevskiy uint32_t config_addr); 12346c5874eSAlexey Kardashevskiy 124fbb4e983SDavid Gibson /* VFIO EEH hooks */ 125fbb4e983SDavid Gibson #ifdef CONFIG_LINUX 126c1fa017cSDavid Gibson bool spapr_phb_eeh_available(sPAPRPHBState *sphb); 127fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_set_option(sPAPRPHBState *sphb, 128fbb4e983SDavid Gibson unsigned int addr, int option); 129fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_get_state(sPAPRPHBState *sphb, int *state); 130fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_reset(sPAPRPHBState *sphb, int option); 131fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_configure(sPAPRPHBState *sphb); 132fbb4e983SDavid Gibson void spapr_phb_vfio_reset(DeviceState *qdev); 133fbb4e983SDavid Gibson #else 134c1fa017cSDavid Gibson static inline bool spapr_phb_eeh_available(sPAPRPHBState *sphb) 135c1fa017cSDavid Gibson { 136c1fa017cSDavid Gibson return false; 137c1fa017cSDavid Gibson } 138fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_set_option(sPAPRPHBState *sphb, 139fbb4e983SDavid Gibson unsigned int addr, int option) 140fbb4e983SDavid Gibson { 141fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 142fbb4e983SDavid Gibson } 143fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_get_state(sPAPRPHBState *sphb, 144fbb4e983SDavid Gibson int *state) 145fbb4e983SDavid Gibson { 146fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 147fbb4e983SDavid Gibson } 148fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_reset(sPAPRPHBState *sphb, int option) 149fbb4e983SDavid Gibson { 150fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 151fbb4e983SDavid Gibson } 152fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_configure(sPAPRPHBState *sphb) 153fbb4e983SDavid Gibson { 154fbb4e983SDavid Gibson return RTAS_OUT_HW_ERROR; 155fbb4e983SDavid Gibson } 156fbb4e983SDavid Gibson static inline void spapr_phb_vfio_reset(DeviceState *qdev) 157fbb4e983SDavid Gibson { 158fbb4e983SDavid Gibson } 159fbb4e983SDavid Gibson #endif 160fbb4e983SDavid Gibson 161b3162f22SAlexey Kardashevskiy void spapr_phb_dma_reset(sPAPRPHBState *sphb); 162b3162f22SAlexey Kardashevskiy 163121d0712SMarkus Armbruster #endif /* PCI_HOST_SPAPR_H */ 164