xref: /qemu/include/hw/s390x/s390-pci-bus.h (revision 68c691ca)
1408b55dbSMatthew Rosato /*
2408b55dbSMatthew Rosato  * s390 PCI BUS definitions
3408b55dbSMatthew Rosato  *
4408b55dbSMatthew Rosato  * Copyright 2014 IBM Corp.
5408b55dbSMatthew Rosato  * Author(s): Frank Blaschka <frank.blaschka@de.ibm.com>
6408b55dbSMatthew Rosato  *            Hong Bo Li <lihbbj@cn.ibm.com>
7408b55dbSMatthew Rosato  *            Yi Min Zhao <zyimin@cn.ibm.com>
8408b55dbSMatthew Rosato  *
9408b55dbSMatthew Rosato  * This work is licensed under the terms of the GNU GPL, version 2 or (at
10408b55dbSMatthew Rosato  * your option) any later version. See the COPYING file in the top-level
11408b55dbSMatthew Rosato  * directory.
12408b55dbSMatthew Rosato  */
13408b55dbSMatthew Rosato 
14408b55dbSMatthew Rosato #ifndef HW_S390_PCI_BUS_H
15408b55dbSMatthew Rosato #define HW_S390_PCI_BUS_H
16408b55dbSMatthew Rosato 
17408b55dbSMatthew Rosato #include "hw/pci/pci.h"
18408b55dbSMatthew Rosato #include "hw/pci/pci_host.h"
19408b55dbSMatthew Rosato #include "hw/s390x/sclp.h"
20408b55dbSMatthew Rosato #include "hw/s390x/s390_flic.h"
21408b55dbSMatthew Rosato #include "hw/s390x/css.h"
22c04274f4SPierre Morel #include "hw/s390x/s390-pci-clp.h"
23408b55dbSMatthew Rosato #include "qom/object.h"
24408b55dbSMatthew Rosato 
25408b55dbSMatthew Rosato #define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost"
26408b55dbSMatthew Rosato #define TYPE_S390_PCI_BUS "s390-pcibus"
27408b55dbSMatthew Rosato #define TYPE_S390_PCI_DEVICE "zpci"
28408b55dbSMatthew Rosato #define TYPE_S390_PCI_IOMMU "s390-pci-iommu"
29408b55dbSMatthew Rosato #define TYPE_S390_IOMMU_MEMORY_REGION "s390-iommu-memory-region"
30408b55dbSMatthew Rosato #define FH_MASK_ENABLE   0x80000000
31408b55dbSMatthew Rosato #define FH_MASK_INSTANCE 0x7f000000
32408b55dbSMatthew Rosato #define FH_MASK_SHM      0x00ff0000
33408b55dbSMatthew Rosato #define FH_MASK_INDEX    0x0000ffff
34408b55dbSMatthew Rosato #define FH_SHM_VFIO      0x00010000
35408b55dbSMatthew Rosato #define FH_SHM_EMUL      0x00020000
36408b55dbSMatthew Rosato #define ZPCI_MAX_FID 0xffffffff
37408b55dbSMatthew Rosato #define ZPCI_MAX_UID 0xffff
38408b55dbSMatthew Rosato #define UID_UNDEFINED 0
39408b55dbSMatthew Rosato #define UID_CHECKING_ENABLED 0x01
40ac6aa30aSMatthew Rosato #define ZPCI_DTSM 0x40
41408b55dbSMatthew Rosato 
4203451953SMatthew Rosato /* zPCI Function Types */
4303451953SMatthew Rosato #define ZPCI_PFT_ISM 5
4403451953SMatthew Rosato 
45408b55dbSMatthew Rosato OBJECT_DECLARE_SIMPLE_TYPE(S390pciState, S390_PCI_HOST_BRIDGE)
46408b55dbSMatthew Rosato OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBus, S390_PCI_BUS)
47408b55dbSMatthew Rosato OBJECT_DECLARE_SIMPLE_TYPE(S390PCIBusDevice, S390_PCI_DEVICE)
48408b55dbSMatthew Rosato OBJECT_DECLARE_SIMPLE_TYPE(S390PCIIOMMU, S390_PCI_IOMMU)
49408b55dbSMatthew Rosato 
50408b55dbSMatthew Rosato #define HP_EVENT_TO_CONFIGURED        0x0301
51408b55dbSMatthew Rosato #define HP_EVENT_RESERVED_TO_STANDBY  0x0302
52408b55dbSMatthew Rosato #define HP_EVENT_DECONFIGURE_REQUEST  0x0303
53408b55dbSMatthew Rosato #define HP_EVENT_CONFIGURED_TO_STBRES 0x0304
54408b55dbSMatthew Rosato #define HP_EVENT_STANDBY_TO_RESERVED  0x0308
55408b55dbSMatthew Rosato 
56408b55dbSMatthew Rosato #define ERR_EVENT_INVALAS 0x1
57408b55dbSMatthew Rosato #define ERR_EVENT_OORANGE 0x2
58408b55dbSMatthew Rosato #define ERR_EVENT_INVALTF 0x3
59408b55dbSMatthew Rosato #define ERR_EVENT_TPROTE  0x4
60408b55dbSMatthew Rosato #define ERR_EVENT_APROTE  0x5
61408b55dbSMatthew Rosato #define ERR_EVENT_KEYE    0x6
62408b55dbSMatthew Rosato #define ERR_EVENT_INVALTE 0x7
63408b55dbSMatthew Rosato #define ERR_EVENT_INVALTL 0x8
64408b55dbSMatthew Rosato #define ERR_EVENT_TT      0x9
65408b55dbSMatthew Rosato #define ERR_EVENT_INVALMS 0xa
66408b55dbSMatthew Rosato #define ERR_EVENT_SERR    0xb
67408b55dbSMatthew Rosato #define ERR_EVENT_NOMSI   0x10
68408b55dbSMatthew Rosato #define ERR_EVENT_INVALBV 0x11
69408b55dbSMatthew Rosato #define ERR_EVENT_AIBV    0x12
70408b55dbSMatthew Rosato #define ERR_EVENT_AIRERR  0x13
71408b55dbSMatthew Rosato #define ERR_EVENT_FMBA    0x2a
72408b55dbSMatthew Rosato #define ERR_EVENT_FMBUP   0x2b
73408b55dbSMatthew Rosato #define ERR_EVENT_FMBPRO  0x2c
74408b55dbSMatthew Rosato #define ERR_EVENT_CCONF   0x30
75408b55dbSMatthew Rosato #define ERR_EVENT_SERVAC  0x3a
76408b55dbSMatthew Rosato #define ERR_EVENT_PERMERR 0x3b
77408b55dbSMatthew Rosato 
78408b55dbSMatthew Rosato #define ERR_EVENT_Q_BIT 0x2
79408b55dbSMatthew Rosato #define ERR_EVENT_MVN_OFFSET 16
80408b55dbSMatthew Rosato 
81408b55dbSMatthew Rosato #define ZPCI_MSI_VEC_BITS 11
82408b55dbSMatthew Rosato #define ZPCI_MSI_VEC_MASK 0x7ff
83408b55dbSMatthew Rosato 
84408b55dbSMatthew Rosato #define ZPCI_MSI_ADDR  0xfe00000000000000ULL
85408b55dbSMatthew Rosato #define ZPCI_SDMA_ADDR 0x100000000ULL
86408b55dbSMatthew Rosato #define ZPCI_EDMA_ADDR 0x1ffffffffffffffULL
87408b55dbSMatthew Rosato 
88408b55dbSMatthew Rosato #define PAGE_DEFAULT_ACC        0
89408b55dbSMatthew Rosato #define PAGE_DEFAULT_KEY        (PAGE_DEFAULT_ACC << 4)
90408b55dbSMatthew Rosato 
91408b55dbSMatthew Rosato /* I/O Translation Anchor (IOTA) */
92408b55dbSMatthew Rosato enum ZpciIoatDtype {
93408b55dbSMatthew Rosato     ZPCI_IOTA_STO = 0,
94408b55dbSMatthew Rosato     ZPCI_IOTA_RTTO = 1,
95408b55dbSMatthew Rosato     ZPCI_IOTA_RSTO = 2,
96408b55dbSMatthew Rosato     ZPCI_IOTA_RFTO = 3,
97408b55dbSMatthew Rosato     ZPCI_IOTA_PFAA = 4,
98408b55dbSMatthew Rosato     ZPCI_IOTA_IOPFAA = 5,
99408b55dbSMatthew Rosato     ZPCI_IOTA_IOPTO = 7
100408b55dbSMatthew Rosato };
101408b55dbSMatthew Rosato 
102408b55dbSMatthew Rosato #define ZPCI_IOTA_IOT_ENABLED           0x800ULL
103408b55dbSMatthew Rosato #define ZPCI_IOTA_DT_ST                 (ZPCI_IOTA_STO  << 2)
104408b55dbSMatthew Rosato #define ZPCI_IOTA_DT_RT                 (ZPCI_IOTA_RTTO << 2)
105408b55dbSMatthew Rosato #define ZPCI_IOTA_DT_RS                 (ZPCI_IOTA_RSTO << 2)
106408b55dbSMatthew Rosato #define ZPCI_IOTA_DT_RF                 (ZPCI_IOTA_RFTO << 2)
107408b55dbSMatthew Rosato #define ZPCI_IOTA_DT_PF                 (ZPCI_IOTA_PFAA << 2)
108408b55dbSMatthew Rosato #define ZPCI_IOTA_FS_4K                 0
109408b55dbSMatthew Rosato #define ZPCI_IOTA_FS_1M                 1
110408b55dbSMatthew Rosato #define ZPCI_IOTA_FS_2G                 2
111408b55dbSMatthew Rosato #define ZPCI_KEY                        (PAGE_DEFAULT_KEY << 5)
112408b55dbSMatthew Rosato 
113408b55dbSMatthew Rosato #define ZPCI_IOTA_STO_FLAG  (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_ST)
114408b55dbSMatthew Rosato #define ZPCI_IOTA_RTTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RT)
115408b55dbSMatthew Rosato #define ZPCI_IOTA_RSTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RS)
116408b55dbSMatthew Rosato #define ZPCI_IOTA_RFTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RF)
117408b55dbSMatthew Rosato #define ZPCI_IOTA_RFAA_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY |\
118408b55dbSMatthew Rosato                              ZPCI_IOTA_DT_PF | ZPCI_IOTA_FS_2G)
119408b55dbSMatthew Rosato 
120408b55dbSMatthew Rosato /* I/O Region and segment tables */
121408b55dbSMatthew Rosato #define ZPCI_INDEX_MASK         0x7ffULL
122408b55dbSMatthew Rosato 
123408b55dbSMatthew Rosato #define ZPCI_TABLE_TYPE_MASK    0xc
124408b55dbSMatthew Rosato #define ZPCI_TABLE_TYPE_RFX     0xc
125408b55dbSMatthew Rosato #define ZPCI_TABLE_TYPE_RSX     0x8
126408b55dbSMatthew Rosato #define ZPCI_TABLE_TYPE_RTX     0x4
127408b55dbSMatthew Rosato #define ZPCI_TABLE_TYPE_SX      0x0
128408b55dbSMatthew Rosato 
129408b55dbSMatthew Rosato #define ZPCI_TABLE_LEN_RFX      0x3
130408b55dbSMatthew Rosato #define ZPCI_TABLE_LEN_RSX      0x3
131408b55dbSMatthew Rosato #define ZPCI_TABLE_LEN_RTX      0x3
132408b55dbSMatthew Rosato 
133408b55dbSMatthew Rosato #define ZPCI_TABLE_OFFSET_MASK  0xc0
134408b55dbSMatthew Rosato #define ZPCI_TABLE_SIZE         0x4000
135408b55dbSMatthew Rosato #define ZPCI_TABLE_ALIGN        ZPCI_TABLE_SIZE
136408b55dbSMatthew Rosato #define ZPCI_TABLE_ENTRY_SIZE   (sizeof(unsigned long))
137408b55dbSMatthew Rosato #define ZPCI_TABLE_ENTRIES      (ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE)
138408b55dbSMatthew Rosato 
139408b55dbSMatthew Rosato #define ZPCI_TABLE_BITS         11
140408b55dbSMatthew Rosato #define ZPCI_PT_BITS            8
141ed3288ffSThomas Huth #define ZPCI_ST_SHIFT           (ZPCI_PT_BITS + TARGET_PAGE_BITS)
142408b55dbSMatthew Rosato #define ZPCI_RT_SHIFT           (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS)
143408b55dbSMatthew Rosato 
144408b55dbSMatthew Rosato #define ZPCI_RTE_FLAG_MASK      0x3fffULL
145408b55dbSMatthew Rosato #define ZPCI_RTE_ADDR_MASK      (~ZPCI_RTE_FLAG_MASK)
146408b55dbSMatthew Rosato #define ZPCI_STE_FLAG_MASK      0x7ffULL
147408b55dbSMatthew Rosato #define ZPCI_STE_ADDR_MASK      (~ZPCI_STE_FLAG_MASK)
148408b55dbSMatthew Rosato 
149408b55dbSMatthew Rosato #define ZPCI_SFAA_MASK          (~((1ULL << 20) - 1))
150408b55dbSMatthew Rosato 
151408b55dbSMatthew Rosato /* I/O Page tables */
152408b55dbSMatthew Rosato #define ZPCI_PTE_VALID_MASK             0x400
153408b55dbSMatthew Rosato #define ZPCI_PTE_INVALID                0x400
154408b55dbSMatthew Rosato #define ZPCI_PTE_VALID                  0x000
155408b55dbSMatthew Rosato #define ZPCI_PT_SIZE                    0x800
156408b55dbSMatthew Rosato #define ZPCI_PT_ALIGN                   ZPCI_PT_SIZE
157408b55dbSMatthew Rosato #define ZPCI_PT_ENTRIES                 (ZPCI_PT_SIZE / ZPCI_TABLE_ENTRY_SIZE)
158408b55dbSMatthew Rosato #define ZPCI_PT_MASK                    (ZPCI_PT_ENTRIES - 1)
159408b55dbSMatthew Rosato 
160408b55dbSMatthew Rosato #define ZPCI_PTE_FLAG_MASK              0xfffULL
161408b55dbSMatthew Rosato #define ZPCI_PTE_ADDR_MASK              (~ZPCI_PTE_FLAG_MASK)
162408b55dbSMatthew Rosato 
163408b55dbSMatthew Rosato /* Shared bits */
164408b55dbSMatthew Rosato #define ZPCI_TABLE_VALID                0x00
165408b55dbSMatthew Rosato #define ZPCI_TABLE_INVALID              0x20
166408b55dbSMatthew Rosato #define ZPCI_TABLE_PROTECTED            0x200
167408b55dbSMatthew Rosato #define ZPCI_TABLE_UNPROTECTED          0x000
168408b55dbSMatthew Rosato #define ZPCI_TABLE_FC                   0x400
169408b55dbSMatthew Rosato 
170408b55dbSMatthew Rosato #define ZPCI_TABLE_VALID_MASK           0x20
171408b55dbSMatthew Rosato #define ZPCI_TABLE_PROT_MASK            0x200
172408b55dbSMatthew Rosato 
173408b55dbSMatthew Rosato #define ZPCI_ETT_RT 1
174408b55dbSMatthew Rosato #define ZPCI_ETT_ST 0
175408b55dbSMatthew Rosato #define ZPCI_ETT_PT -1
176408b55dbSMatthew Rosato 
177408b55dbSMatthew Rosato /* PCI Function States
178408b55dbSMatthew Rosato  *
179408b55dbSMatthew Rosato  * reserved: default; device has just been plugged or is in progress of being
180408b55dbSMatthew Rosato  *           unplugged
181408b55dbSMatthew Rosato  * standby: device is present but not configured; transition from any
182408b55dbSMatthew Rosato  *          configured state/to this state via sclp configure/deconfigure
183408b55dbSMatthew Rosato  *
184408b55dbSMatthew Rosato  * The following states make up the "configured" meta-state:
185408b55dbSMatthew Rosato  * disabled: device is configured but not enabled; transition between this
186408b55dbSMatthew Rosato  *           state and enabled via clp enable/disable
187cced0d65SMichael Tokarev  * enabled: device is ready for use; transition to disabled via clp disable;
188408b55dbSMatthew Rosato  *          may enter an error state
189408b55dbSMatthew Rosato  * blocked: ignore all DMA and interrupts; transition back to enabled or from
190408b55dbSMatthew Rosato  *          error state via mpcifc
191408b55dbSMatthew Rosato  * error: an error occurred; transition back to enabled via mpcifc
192408b55dbSMatthew Rosato  * permanent error: an unrecoverable error occurred; transition to standby via
193408b55dbSMatthew Rosato  *                  sclp deconfigure
194408b55dbSMatthew Rosato  */
195408b55dbSMatthew Rosato typedef enum {
196408b55dbSMatthew Rosato     ZPCI_FS_RESERVED,
197408b55dbSMatthew Rosato     ZPCI_FS_STANDBY,
198408b55dbSMatthew Rosato     ZPCI_FS_DISABLED,
199408b55dbSMatthew Rosato     ZPCI_FS_ENABLED,
200408b55dbSMatthew Rosato     ZPCI_FS_BLOCKED,
201408b55dbSMatthew Rosato     ZPCI_FS_ERROR,
202408b55dbSMatthew Rosato     ZPCI_FS_PERMANENT_ERROR,
203408b55dbSMatthew Rosato } ZpciState;
204408b55dbSMatthew Rosato 
205408b55dbSMatthew Rosato typedef struct SeiContainer {
206408b55dbSMatthew Rosato     QTAILQ_ENTRY(SeiContainer) link;
207408b55dbSMatthew Rosato     uint32_t fid;
208408b55dbSMatthew Rosato     uint32_t fh;
209408b55dbSMatthew Rosato     uint8_t cc;
210408b55dbSMatthew Rosato     uint16_t pec;
211408b55dbSMatthew Rosato     uint64_t faddr;
212408b55dbSMatthew Rosato     uint32_t e;
213408b55dbSMatthew Rosato } SeiContainer;
214408b55dbSMatthew Rosato 
215408b55dbSMatthew Rosato typedef struct PciCcdfErr {
216408b55dbSMatthew Rosato     uint32_t reserved1;
217408b55dbSMatthew Rosato     uint32_t fh;
218408b55dbSMatthew Rosato     uint32_t fid;
219408b55dbSMatthew Rosato     uint32_t e;
220408b55dbSMatthew Rosato     uint64_t faddr;
221408b55dbSMatthew Rosato     uint32_t reserved3;
222408b55dbSMatthew Rosato     uint16_t reserved4;
223408b55dbSMatthew Rosato     uint16_t pec;
224408b55dbSMatthew Rosato } QEMU_PACKED PciCcdfErr;
225408b55dbSMatthew Rosato 
226408b55dbSMatthew Rosato typedef struct PciCcdfAvail {
227408b55dbSMatthew Rosato     uint32_t reserved1;
228408b55dbSMatthew Rosato     uint32_t fh;
229408b55dbSMatthew Rosato     uint32_t fid;
230408b55dbSMatthew Rosato     uint32_t reserved2;
231408b55dbSMatthew Rosato     uint32_t reserved3;
232408b55dbSMatthew Rosato     uint32_t reserved4;
233408b55dbSMatthew Rosato     uint32_t reserved5;
234408b55dbSMatthew Rosato     uint16_t reserved6;
235408b55dbSMatthew Rosato     uint16_t pec;
236408b55dbSMatthew Rosato } QEMU_PACKED PciCcdfAvail;
237408b55dbSMatthew Rosato 
238408b55dbSMatthew Rosato typedef struct ChscSeiNt2Res {
239408b55dbSMatthew Rosato     uint16_t length;
240408b55dbSMatthew Rosato     uint16_t code;
241408b55dbSMatthew Rosato     uint16_t reserved1;
242408b55dbSMatthew Rosato     uint8_t reserved2;
243408b55dbSMatthew Rosato     uint8_t nt;
244408b55dbSMatthew Rosato     uint8_t flags;
245408b55dbSMatthew Rosato     uint8_t reserved3;
246408b55dbSMatthew Rosato     uint8_t reserved4;
247408b55dbSMatthew Rosato     uint8_t cc;
248408b55dbSMatthew Rosato     uint32_t reserved5[13];
249408b55dbSMatthew Rosato     uint8_t ccdf[4016];
250408b55dbSMatthew Rosato } QEMU_PACKED ChscSeiNt2Res;
251408b55dbSMatthew Rosato 
252408b55dbSMatthew Rosato typedef struct S390MsixInfo {
253408b55dbSMatthew Rosato     uint8_t table_bar;
254408b55dbSMatthew Rosato     uint8_t pba_bar;
255408b55dbSMatthew Rosato     uint16_t entries;
256408b55dbSMatthew Rosato     uint32_t table_offset;
257408b55dbSMatthew Rosato     uint32_t pba_offset;
258408b55dbSMatthew Rosato } S390MsixInfo;
259408b55dbSMatthew Rosato 
260408b55dbSMatthew Rosato typedef struct S390IOTLBEntry {
261408b55dbSMatthew Rosato     uint64_t iova;
262408b55dbSMatthew Rosato     uint64_t translated_addr;
263408b55dbSMatthew Rosato     uint64_t len;
264408b55dbSMatthew Rosato     uint64_t perm;
265408b55dbSMatthew Rosato } S390IOTLBEntry;
266408b55dbSMatthew Rosato 
26737fa32deSMatthew Rosato typedef struct S390PCIDMACount {
26837fa32deSMatthew Rosato     int id;
26937fa32deSMatthew Rosato     int users;
27037fa32deSMatthew Rosato     uint32_t avail;
27137fa32deSMatthew Rosato     QTAILQ_ENTRY(S390PCIDMACount) link;
27237fa32deSMatthew Rosato } S390PCIDMACount;
27337fa32deSMatthew Rosato 
274408b55dbSMatthew Rosato struct S390PCIIOMMU {
275408b55dbSMatthew Rosato     Object parent_obj;
276408b55dbSMatthew Rosato     S390PCIBusDevice *pbdev;
277408b55dbSMatthew Rosato     AddressSpace as;
278408b55dbSMatthew Rosato     MemoryRegion mr;
279408b55dbSMatthew Rosato     IOMMUMemoryRegion iommu_mr;
280408b55dbSMatthew Rosato     bool enabled;
281408b55dbSMatthew Rosato     uint64_t g_iota;
282408b55dbSMatthew Rosato     uint64_t pba;
283408b55dbSMatthew Rosato     uint64_t pal;
284df202e3fSMatthew Rosato     uint64_t max_dma_limit;
285408b55dbSMatthew Rosato     GHashTable *iotlb;
28637fa32deSMatthew Rosato     S390PCIDMACount *dma_limit;
287408b55dbSMatthew Rosato };
288408b55dbSMatthew Rosato 
289408b55dbSMatthew Rosato typedef struct S390PCIIOMMUTable {
290408b55dbSMatthew Rosato     uint64_t key;
291408b55dbSMatthew Rosato     S390PCIIOMMU *iommu[PCI_SLOT_MAX];
292408b55dbSMatthew Rosato } S390PCIIOMMUTable;
293408b55dbSMatthew Rosato 
294408b55dbSMatthew Rosato /* Function Measurement Block */
295408b55dbSMatthew Rosato #define DEFAULT_MUI 4000
296408b55dbSMatthew Rosato #define UPDATE_U_BIT 0x1ULL
297408b55dbSMatthew Rosato #define FMBK_MASK 0xfULL
298408b55dbSMatthew Rosato 
299408b55dbSMatthew Rosato typedef struct ZpciFmbFmt0 {
300408b55dbSMatthew Rosato     uint64_t dma_rbytes;
301408b55dbSMatthew Rosato     uint64_t dma_wbytes;
302408b55dbSMatthew Rosato } ZpciFmbFmt0;
303408b55dbSMatthew Rosato 
304408b55dbSMatthew Rosato #define ZPCI_FMB_CNT_LD    0
305408b55dbSMatthew Rosato #define ZPCI_FMB_CNT_ST    1
306408b55dbSMatthew Rosato #define ZPCI_FMB_CNT_STB   2
307408b55dbSMatthew Rosato #define ZPCI_FMB_CNT_RPCIT 3
308408b55dbSMatthew Rosato #define ZPCI_FMB_CNT_MAX   4
309408b55dbSMatthew Rosato 
310408b55dbSMatthew Rosato #define ZPCI_FMB_FORMAT    0
311408b55dbSMatthew Rosato 
312408b55dbSMatthew Rosato typedef struct ZpciFmb {
313408b55dbSMatthew Rosato     uint32_t format;
314408b55dbSMatthew Rosato     uint32_t sample;
315408b55dbSMatthew Rosato     uint64_t last_update;
316408b55dbSMatthew Rosato     uint64_t counter[ZPCI_FMB_CNT_MAX];
317408b55dbSMatthew Rosato     ZpciFmbFmt0 fmt0;
318408b55dbSMatthew Rosato } ZpciFmb;
319408b55dbSMatthew Rosato QEMU_BUILD_BUG_MSG(offsetof(ZpciFmb, fmt0) != 48, "padding in ZpciFmb");
320408b55dbSMatthew Rosato 
321b2892a2bSMatthew Rosato #define ZPCI_DEFAULT_FN_GRP 0xFF
32230dcf4f7SMatthew Rosato #define ZPCI_SIM_GRP_START 0xF0
32328dc86a0SPierre Morel typedef struct S390PCIGroup {
32428dc86a0SPierre Morel     ClpRspQueryPciGrp zpci_group;
32528dc86a0SPierre Morel     int id;
32630dcf4f7SMatthew Rosato     int host_id;
32728dc86a0SPierre Morel     QTAILQ_ENTRY(S390PCIGroup) link;
32828dc86a0SPierre Morel } S390PCIGroup;
32930dcf4f7SMatthew Rosato S390PCIGroup *s390_group_create(int id, int host_id);
33028dc86a0SPierre Morel S390PCIGroup *s390_group_find(int id);
33130dcf4f7SMatthew Rosato S390PCIGroup *s390_group_find_host_sim(int host_id);
33228dc86a0SPierre Morel 
333408b55dbSMatthew Rosato struct S390PCIBusDevice {
334408b55dbSMatthew Rosato     DeviceState qdev;
335408b55dbSMatthew Rosato     PCIDevice *pdev;
336408b55dbSMatthew Rosato     ZpciState state;
337408b55dbSMatthew Rosato     char *target;
338408b55dbSMatthew Rosato     uint16_t uid;
339408b55dbSMatthew Rosato     uint32_t idx;
340408b55dbSMatthew Rosato     uint32_t fh;
341408b55dbSMatthew Rosato     uint32_t fid;
342408b55dbSMatthew Rosato     bool fid_defined;
343408b55dbSMatthew Rosato     uint64_t fmb_addr;
344408b55dbSMatthew Rosato     ZpciFmb fmb;
345408b55dbSMatthew Rosato     QEMUTimer *fmb_timer;
346408b55dbSMatthew Rosato     uint8_t isc;
347408b55dbSMatthew Rosato     uint16_t noi;
348408b55dbSMatthew Rosato     uint16_t maxstbl;
349408b55dbSMatthew Rosato     uint8_t sum;
35003451953SMatthew Rosato     uint8_t pft;
35128dc86a0SPierre Morel     S390PCIGroup *pci_group;
3529670ee75SPierre Morel     ClpRspQueryPci zpci_fn;
353408b55dbSMatthew Rosato     S390MsixInfo msix;
354408b55dbSMatthew Rosato     AdapterRoutes routes;
355408b55dbSMatthew Rosato     S390PCIIOMMU *iommu;
356408b55dbSMatthew Rosato     MemoryRegion msix_notify_mr;
357408b55dbSMatthew Rosato     IndAddr *summary_ind;
358408b55dbSMatthew Rosato     IndAddr *indicator;
35903451953SMatthew Rosato     Notifier shutdown_notifier;
360408b55dbSMatthew Rosato     bool pci_unplug_request_processed;
361408b55dbSMatthew Rosato     bool unplug_requested;
362dd1d5fd9SMatthew Rosato     bool interp;
363d0bc7091SMatthew Rosato     bool forwarding_assist;
36407b2c8e0SMatthew Rosato     bool aif;
365408b55dbSMatthew Rosato     QTAILQ_ENTRY(S390PCIBusDevice) link;
366408b55dbSMatthew Rosato };
367408b55dbSMatthew Rosato 
368408b55dbSMatthew Rosato struct S390PCIBus {
369408b55dbSMatthew Rosato     BusState qbus;
370408b55dbSMatthew Rosato };
371408b55dbSMatthew Rosato 
372408b55dbSMatthew Rosato struct S390pciState {
373408b55dbSMatthew Rosato     PCIHostState parent_obj;
374408b55dbSMatthew Rosato     uint32_t next_idx;
375408b55dbSMatthew Rosato     int bus_no;
376408b55dbSMatthew Rosato     S390PCIBus *bus;
377408b55dbSMatthew Rosato     GHashTable *iommu_table;
378408b55dbSMatthew Rosato     GHashTable *zpci_table;
379408b55dbSMatthew Rosato     QTAILQ_HEAD(, SeiContainer) pending_sei;
380408b55dbSMatthew Rosato     QTAILQ_HEAD(, S390PCIBusDevice) zpci_devs;
38137fa32deSMatthew Rosato     QTAILQ_HEAD(, S390PCIDMACount) zpci_dma_limit;
38228dc86a0SPierre Morel     QTAILQ_HEAD(, S390PCIGroup) zpci_groups;
38330dcf4f7SMatthew Rosato     uint8_t next_sim_grp;
384408b55dbSMatthew Rosato };
385408b55dbSMatthew Rosato 
386408b55dbSMatthew Rosato S390pciState *s390_get_phb(void);
387408b55dbSMatthew Rosato int pci_chsc_sei_nt2_get_event(void *res);
388408b55dbSMatthew Rosato int pci_chsc_sei_nt2_have_event(void);
389408b55dbSMatthew Rosato void s390_pci_sclp_configure(SCCB *sccb);
390408b55dbSMatthew Rosato void s390_pci_sclp_deconfigure(SCCB *sccb);
391408b55dbSMatthew Rosato void s390_pci_iommu_enable(S390PCIIOMMU *iommu);
392408b55dbSMatthew Rosato void s390_pci_iommu_disable(S390PCIIOMMU *iommu);
393408b55dbSMatthew Rosato void s390_pci_generate_error_event(uint16_t pec, uint32_t fh, uint32_t fid,
394408b55dbSMatthew Rosato                                    uint64_t faddr, uint32_t e);
395408b55dbSMatthew Rosato uint16_t s390_guest_io_table_walk(uint64_t g_iota, hwaddr addr,
396408b55dbSMatthew Rosato                                   S390IOTLBEntry *entry);
397408b55dbSMatthew Rosato S390PCIBusDevice *s390_pci_find_dev_by_idx(S390pciState *s, uint32_t idx);
398408b55dbSMatthew Rosato S390PCIBusDevice *s390_pci_find_dev_by_fh(S390pciState *s, uint32_t fh);
399408b55dbSMatthew Rosato S390PCIBusDevice *s390_pci_find_dev_by_fid(S390pciState *s, uint32_t fid);
400408b55dbSMatthew Rosato S390PCIBusDevice *s390_pci_find_dev_by_target(S390pciState *s,
401408b55dbSMatthew Rosato                                               const char *target);
402408b55dbSMatthew Rosato S390PCIBusDevice *s390_pci_find_next_avail_dev(S390pciState *s,
403408b55dbSMatthew Rosato                                                S390PCIBusDevice *pbdev);
404*68c691caSMatthew Rosato void s390_pci_ism_reset(void);
405408b55dbSMatthew Rosato 
406408b55dbSMatthew Rosato #endif
407