xref: /qemu/include/hw/pci-host/spapr.h (revision ae4de14cd36b6a899d83df9595be3971ac0802d4)
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 #if !defined(__HW_SPAPR_H__)
203384f95cSDavid Gibson #error Please include spapr.h before this file!
213384f95cSDavid Gibson #endif
223384f95cSDavid Gibson 
233384f95cSDavid Gibson #if !defined(__HW_SPAPR_PCI_H__)
243384f95cSDavid Gibson #define __HW_SPAPR_PCI_H__
253384f95cSDavid Gibson 
26a2cb15b0SMichael S. Tsirkin #include "hw/pci/pci.h"
27a2cb15b0SMichael S. Tsirkin #include "hw/pci/pci_host.h"
280d09e41aSPaolo Bonzini #include "hw/ppc/xics.h"
293384f95cSDavid Gibson 
308c9f64dfSAndreas Färber #define TYPE_SPAPR_PCI_HOST_BRIDGE "spapr-pci-host-bridge"
318c9f64dfSAndreas Färber 
328c9f64dfSAndreas Färber #define SPAPR_PCI_HOST_BRIDGE(obj) \
338c9f64dfSAndreas Färber     OBJECT_CHECK(sPAPRPHBState, (obj), TYPE_SPAPR_PCI_HOST_BRIDGE)
348c9f64dfSAndreas Färber 
35*ae4de14cSAlexey Kardashevskiy #define SPAPR_PCI_DMA_MAX_WINDOWS    2
36*ae4de14cSAlexey Kardashevskiy 
37da6ccee4SAlexey Kardashevskiy typedef struct sPAPRPHBState sPAPRPHBState;
38da6ccee4SAlexey Kardashevskiy 
399a321e92SAlexey Kardashevskiy typedef struct spapr_pci_msi {
409a321e92SAlexey Kardashevskiy     uint32_t first_irq;
419a321e92SAlexey Kardashevskiy     uint32_t num;
429a321e92SAlexey Kardashevskiy } spapr_pci_msi;
439a321e92SAlexey Kardashevskiy 
449a321e92SAlexey Kardashevskiy typedef struct spapr_pci_msi_mig {
459a321e92SAlexey Kardashevskiy     uint32_t key;
469a321e92SAlexey Kardashevskiy     spapr_pci_msi value;
479a321e92SAlexey Kardashevskiy } spapr_pci_msi_mig;
489a321e92SAlexey Kardashevskiy 
49da6ccee4SAlexey Kardashevskiy struct sPAPRPHBState {
5067c332fdSAndreas Färber     PCIHostState parent_obj;
513384f95cSDavid Gibson 
523e4ac968SDavid Gibson     uint32_t index;
533384f95cSDavid Gibson     uint64_t buid;
54298a9710SDavid Gibson     char *dtbusname;
557619c7b0SMichael Roth     bool dr_enabled;
563384f95cSDavid Gibson 
573384f95cSDavid Gibson     MemoryRegion memspace, iospace;
58a8170e5eSAvi Kivity     hwaddr mem_win_addr, mem_win_size, io_win_addr, io_win_size;
598c46f7ecSGreg Kurz     MemoryRegion memwindow, iowindow, msiwindow;
600ee2c058SAlexey Kardashevskiy 
61*ae4de14cSAlexey 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;
76*ae4de14cSAlexey Kardashevskiy 
77*ae4de14cSAlexey Kardashevskiy     bool ddw_enabled;
78*ae4de14cSAlexey Kardashevskiy     uint64_t page_size_mask;
79*ae4de14cSAlexey Kardashevskiy     uint64_t dma64_win_addr;
80da6ccee4SAlexey Kardashevskiy };
813384f95cSDavid Gibson 
823e4ac968SDavid Gibson #define SPAPR_PCI_MAX_INDEX          255
833e4ac968SDavid Gibson 
84caae58cbSDavid Gibson #define SPAPR_PCI_BASE_BUID          0x800000020000000ULL
85caae58cbSDavid Gibson 
86b194df47SAlexey Kardashevskiy #define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL
87b194df47SAlexey Kardashevskiy 
88caae58cbSDavid Gibson #define SPAPR_PCI_WINDOW_BASE        0x10000000000ULL
89caae58cbSDavid Gibson #define SPAPR_PCI_WINDOW_SPACING     0x1000000000ULL
90caae58cbSDavid Gibson #define SPAPR_PCI_MMIO_WIN_OFF       0xA0000000
91b194df47SAlexey Kardashevskiy #define SPAPR_PCI_MMIO_WIN_SIZE      (SPAPR_PCI_WINDOW_SPACING - \
92b194df47SAlexey Kardashevskiy                                      SPAPR_PCI_MEM_WIN_BUS_OFFSET)
93caae58cbSDavid Gibson #define SPAPR_PCI_IO_WIN_OFF         0x80000000
94caae58cbSDavid Gibson #define SPAPR_PCI_IO_WIN_SIZE        0x10000
95f1c2dc7cSAlexey Kardashevskiy 
96f1c2dc7cSAlexey Kardashevskiy #define SPAPR_PCI_MSI_WINDOW         0x40000000000ULL
97caae58cbSDavid Gibson 
98a307d594SAlexey Kardashevskiy static inline qemu_irq spapr_phb_lsi_qirq(struct sPAPRPHBState *phb, int pin)
99a307d594SAlexey Kardashevskiy {
10028e02042SDavid Gibson     sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
10128e02042SDavid Gibson 
10227f24582SBenjamin Herrenschmidt     return xics_get_qirq(spapr->xics, phb->lsi_table[pin].irq);
103a307d594SAlexey Kardashevskiy }
104a307d594SAlexey Kardashevskiy 
10528e02042SDavid Gibson PCIHostState *spapr_create_phb(sPAPRMachineState *spapr, int index);
1063384f95cSDavid Gibson 
107e0fdbd7cSAlexey Kardashevskiy int spapr_populate_pci_dt(sPAPRPHBState *phb,
1083384f95cSDavid Gibson                           uint32_t xics_phandle,
1093384f95cSDavid Gibson                           void *fdt);
1103384f95cSDavid Gibson 
11128e02042SDavid Gibson void spapr_pci_msi_init(sPAPRMachineState *spapr, hwaddr addr);
112f1c2dc7cSAlexey Kardashevskiy 
113fa28f71bSAlexey Kardashevskiy void spapr_pci_rtas_init(void);
114fa28f71bSAlexey Kardashevskiy 
11528e02042SDavid Gibson sPAPRPHBState *spapr_pci_find_phb(sPAPRMachineState *spapr, uint64_t buid);
11628e02042SDavid Gibson PCIDevice *spapr_pci_find_dev(sPAPRMachineState *spapr, uint64_t buid,
11746c5874eSAlexey Kardashevskiy                               uint32_t config_addr);
11846c5874eSAlexey Kardashevskiy 
119fbb4e983SDavid Gibson /* VFIO EEH hooks */
120fbb4e983SDavid Gibson #ifdef CONFIG_LINUX
121c1fa017cSDavid Gibson bool spapr_phb_eeh_available(sPAPRPHBState *sphb);
122fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_set_option(sPAPRPHBState *sphb,
123fbb4e983SDavid Gibson                                   unsigned int addr, int option);
124fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_get_state(sPAPRPHBState *sphb, int *state);
125fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_reset(sPAPRPHBState *sphb, int option);
126fbb4e983SDavid Gibson int spapr_phb_vfio_eeh_configure(sPAPRPHBState *sphb);
127fbb4e983SDavid Gibson void spapr_phb_vfio_reset(DeviceState *qdev);
128fbb4e983SDavid Gibson #else
129c1fa017cSDavid Gibson static inline bool spapr_phb_eeh_available(sPAPRPHBState *sphb)
130c1fa017cSDavid Gibson {
131c1fa017cSDavid Gibson     return false;
132c1fa017cSDavid Gibson }
133fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_set_option(sPAPRPHBState *sphb,
134fbb4e983SDavid Gibson                                                 unsigned int addr, int option)
135fbb4e983SDavid Gibson {
136fbb4e983SDavid Gibson     return RTAS_OUT_HW_ERROR;
137fbb4e983SDavid Gibson }
138fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_get_state(sPAPRPHBState *sphb,
139fbb4e983SDavid Gibson                                                int *state)
140fbb4e983SDavid Gibson {
141fbb4e983SDavid Gibson     return RTAS_OUT_HW_ERROR;
142fbb4e983SDavid Gibson }
143fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_reset(sPAPRPHBState *sphb, int option)
144fbb4e983SDavid Gibson {
145fbb4e983SDavid Gibson     return RTAS_OUT_HW_ERROR;
146fbb4e983SDavid Gibson }
147fbb4e983SDavid Gibson static inline int spapr_phb_vfio_eeh_configure(sPAPRPHBState *sphb)
148fbb4e983SDavid Gibson {
149fbb4e983SDavid Gibson     return RTAS_OUT_HW_ERROR;
150fbb4e983SDavid Gibson }
151fbb4e983SDavid Gibson static inline void spapr_phb_vfio_reset(DeviceState *qdev)
152fbb4e983SDavid Gibson {
153fbb4e983SDavid Gibson }
154fbb4e983SDavid Gibson #endif
155fbb4e983SDavid Gibson 
156b3162f22SAlexey Kardashevskiy void spapr_phb_dma_reset(sPAPRPHBState *sphb);
157b3162f22SAlexey Kardashevskiy 
1583384f95cSDavid Gibson #endif /* __HW_SPAPR_PCI_H__ */
159