xref: /openbmc/qemu/include/hw/pci-host/pnv_phb4.h (revision 0fbb5d2d)
1 /*
2  * QEMU PowerPC PowerNV (POWER9) PHB4 model
3  *
4  * Copyright (c) 2018-2020, IBM Corporation.
5  *
6  * This code is licensed under the GPL version 2 or later. See the
7  * COPYING file in the top-level directory.
8  */
9 
10 #ifndef PCI_HOST_PNV_PHB4_H
11 #define PCI_HOST_PNV_PHB4_H
12 
13 #include "hw/pci/pcie_host.h"
14 #include "hw/pci/pcie_port.h"
15 #include "hw/ppc/xive.h"
16 #include "qom/object.h"
17 
18 typedef struct PnvPhb4PecStack PnvPhb4PecStack;
19 typedef struct PnvPHB4 PnvPHB4;
20 typedef struct PnvChip PnvChip;
21 
22 /*
23  * We have one such address space wrapper per possible device under
24  * the PHB since they need to be assigned statically at qemu device
25  * creation time. The relationship to a PE is done later
26  * dynamically. This means we can potentially create a lot of these
27  * guys. Q35 stores them as some kind of radix tree but we never
28  * really need to do fast lookups so instead we simply keep a QLIST of
29  * them for now, we can add the radix if needed later on.
30  *
31  * We do cache the PE number to speed things up a bit though.
32  */
33 typedef struct PnvPhb4DMASpace {
34     PCIBus *bus;
35     uint8_t devfn;
36     int pe_num;         /* Cached PE number */
37 #define PHB_INVALID_PE (-1)
38     PnvPHB4 *phb;
39     AddressSpace dma_as;
40     IOMMUMemoryRegion dma_mr;
41     MemoryRegion msi32_mr;
42     MemoryRegion msi64_mr;
43     QLIST_ENTRY(PnvPhb4DMASpace) list;
44 } PnvPhb4DMASpace;
45 
46 /*
47  * PHB4 PCIe Root port
48  */
49 #define TYPE_PNV_PHB4_ROOT_BUS "pnv-phb4-root-bus"
50 #define TYPE_PNV_PHB4_ROOT_PORT "pnv-phb4-root-port"
51 
52 typedef struct PnvPHB4RootPort {
53     PCIESlot parent_obj;
54 } PnvPHB4RootPort;
55 
56 /*
57  * PHB4 PCIe Host Bridge for PowerNV machines (POWER9)
58  */
59 #define TYPE_PNV_PHB4 "pnv-phb4"
60 OBJECT_DECLARE_SIMPLE_TYPE(PnvPHB4, PNV_PHB4)
61 
62 #define PNV_PHB4_MAX_LSIs          8
63 #define PNV_PHB4_MAX_INTs          4096
64 #define PNV_PHB4_MAX_MIST          (PNV_PHB4_MAX_INTs >> 2)
65 #define PNV_PHB4_MAX_MMIO_WINDOWS  32
66 #define PNV_PHB4_MIN_MMIO_WINDOWS  16
67 #define PNV_PHB4_NUM_REGS          (0x3000 >> 3)
68 #define PNV_PHB4_MAX_PEs           512
69 #define PNV_PHB4_MAX_TVEs          (PNV_PHB4_MAX_PEs * 2)
70 #define PNV_PHB4_MAX_PEEVs         (PNV_PHB4_MAX_PEs / 64)
71 #define PNV_PHB4_MAX_MBEs          (PNV_PHB4_MAX_MMIO_WINDOWS * 2)
72 
73 #define PNV_PHB4_VERSION           0x000000a400000002ull
74 #define PNV_PHB4_DEVICE_ID         0x04c1
75 
76 #define PCI_MMIO_TOTAL_SIZE        (0x1ull << 60)
77 
78 struct PnvPHB4 {
79     PCIExpressHost parent_obj;
80 
81     PnvPHB4RootPort root;
82 
83     uint32_t chip_id;
84     uint32_t phb_id;
85 
86     uint64_t version;
87 
88     char bus_path[8];
89 
90     /* Main register images */
91     uint64_t regs[PNV_PHB4_NUM_REGS];
92     MemoryRegion mr_regs;
93 
94     /* Extra SCOM-only register */
95     uint64_t scom_hv_ind_addr_reg;
96 
97     /*
98      * Geometry of the PHB. There are two types, small and big PHBs, a
99      * number of resources (number of PEs, windows etc...) are doubled
100      * for a big PHB
101      */
102     bool big_phb;
103 
104     /* Memory regions for MMIO space */
105     MemoryRegion mr_mmio[PNV_PHB4_MAX_MMIO_WINDOWS];
106 
107     /* PCI side space */
108     MemoryRegion pci_mmio;
109     MemoryRegion pci_io;
110 
111     /* On-chip IODA tables */
112     uint64_t ioda_LIST[PNV_PHB4_MAX_LSIs];
113     uint64_t ioda_MIST[PNV_PHB4_MAX_MIST];
114     uint64_t ioda_TVT[PNV_PHB4_MAX_TVEs];
115     uint64_t ioda_MBT[PNV_PHB4_MAX_MBEs];
116     uint64_t ioda_MDT[PNV_PHB4_MAX_PEs];
117     uint64_t ioda_PEEV[PNV_PHB4_MAX_PEEVs];
118 
119     /*
120      * The internal PESTA/B is 2 bits per PE split into two tables, we
121      * store them in a single array here to avoid wasting space.
122      */
123     uint8_t  ioda_PEST_AB[PNV_PHB4_MAX_PEs];
124 
125     /* P9 Interrupt generation */
126     XiveSource xsrc;
127     qemu_irq *qirqs;
128 
129     PnvPhb4PecStack *stack;
130 
131     QLIST_HEAD(, PnvPhb4DMASpace) dma_spaces;
132 };
133 
134 void pnv_phb4_pic_print_info(PnvPHB4 *phb, Monitor *mon);
135 void pnv_phb4_update_regions(PnvPhb4PecStack *stack);
136 extern const MemoryRegionOps pnv_phb4_xscom_ops;
137 
138 /*
139  * PHB4 PEC (PCI Express Controller)
140  */
141 #define TYPE_PNV_PHB4_PEC "pnv-phb4-pec"
142 OBJECT_DECLARE_TYPE(PnvPhb4PecState, PnvPhb4PecClass, PNV_PHB4_PEC)
143 
144 #define TYPE_PNV_PHB4_PEC_STACK "pnv-phb4-pec-stack"
145 OBJECT_DECLARE_SIMPLE_TYPE(PnvPhb4PecStack, PNV_PHB4_PEC_STACK)
146 
147 /* Per-stack data */
148 struct PnvPhb4PecStack {
149     DeviceState parent;
150 
151     /* My own stack number */
152     uint32_t stack_no;
153 
154     /* Nest registers */
155 #define PHB4_PEC_NEST_STK_REGS_COUNT  0x17
156     uint64_t nest_regs[PHB4_PEC_NEST_STK_REGS_COUNT];
157     MemoryRegion nest_regs_mr;
158 
159     /* PCI registers (excluding pass-through) */
160 #define PHB4_PEC_PCI_STK_REGS_COUNT  0xf
161     uint64_t pci_regs[PHB4_PEC_PCI_STK_REGS_COUNT];
162     MemoryRegion pci_regs_mr;
163 
164     /* PHB pass-through XSCOM */
165     MemoryRegion phb_regs_mr;
166 
167     /* Memory windows from PowerBus to PHB */
168     MemoryRegion mmbar0;
169     MemoryRegion mmbar1;
170     MemoryRegion phbbar;
171     MemoryRegion intbar;
172     uint64_t mmio0_base;
173     uint64_t mmio0_size;
174     uint64_t mmio1_base;
175     uint64_t mmio1_size;
176 
177     /* The owner PEC */
178     PnvPhb4PecState *pec;
179 
180     /* The actual PHB */
181     PnvPHB4 phb;
182 };
183 
184 struct PnvPhb4PecState {
185     DeviceState parent;
186 
187     /* PEC number in chip */
188     uint32_t index;
189     uint32_t chip_id;
190 
191     MemoryRegion *system_memory;
192 
193     /* Nest registers, excuding per-stack */
194 #define PHB4_PEC_NEST_REGS_COUNT    0xf
195     uint64_t nest_regs[PHB4_PEC_NEST_REGS_COUNT];
196     MemoryRegion nest_regs_mr;
197 
198     /* PCI registers, excluding per-stack */
199 #define PHB4_PEC_PCI_REGS_COUNT     0x2
200     uint64_t pci_regs[PHB4_PEC_PCI_REGS_COUNT];
201     MemoryRegion pci_regs_mr;
202 
203     /* Stacks */
204     #define PHB4_PEC_MAX_STACKS     3
205     uint32_t num_stacks;
206     PnvPhb4PecStack stacks[PHB4_PEC_MAX_STACKS];
207 
208     PnvChip *chip;
209 };
210 
211 
212 struct PnvPhb4PecClass {
213     DeviceClass parent_class;
214 
215     uint32_t (*xscom_nest_base)(PnvPhb4PecState *pec);
216     uint32_t xscom_nest_size;
217     uint32_t (*xscom_pci_base)(PnvPhb4PecState *pec);
218     uint32_t xscom_pci_size;
219     const char *compat;
220     int compat_size;
221     const char *stk_compat;
222     int stk_compat_size;
223     uint64_t version;
224     const uint32_t *num_stacks;
225 };
226 
227 #endif /* PCI_HOST_PNV_PHB4_H */
228