]> Git Repo - qemu.git/blame - hw/s390x/s390-pci-bus.h
s390x/pci: introduce S390PCIBus
[qemu.git] / hw / s390x / s390-pci-bus.h
CommitLineData
8cba80c3
FB
1/*
2 * s390 PCI BUS definitions
3 *
4 * Copyright 2014 IBM Corp.
5 * Author(s): Frank Blaschka <[email protected]>
6 * Hong Bo Li <[email protected]>
7 * Yi Min Zhao <[email protected]>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or (at
10 * your option) any later version. See the COPYING file in the top-level
11 * directory.
12 */
13
14#ifndef HW_S390_PCI_BUS_H
15#define HW_S390_PCI_BUS_H
16
17#include <hw/pci/pci.h>
18#include <hw/pci/pci_host.h>
19#include "hw/s390x/sclp.h"
20#include "hw/s390x/s390_flic.h"
21#include "hw/s390x/css.h"
22
23#define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost"
90a0f9af 24#define TYPE_S390_PCI_BUS "s390-pcibus"
c188e303
YMZ
25#define FH_MASK_ENABLE 0x80000000
26#define FH_MASK_INSTANCE 0x7f000000
27#define FH_MASK_SHM 0x00ff0000
28#define FH_MASK_INDEX 0x0000001f
29#define FH_SHM_VFIO 0x00010000
30#define FH_SHM_EMUL 0x00020000
8cba80c3
FB
31#define S390_PCIPT_ADAPTER 2
32
33#define S390_PCI_HOST_BRIDGE(obj) \
34 OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)
90a0f9af
YMZ
35#define S390_PCI_BUS(obj) \
36 OBJECT_CHECK(S390PCIBus, (obj), TYPE_S390_PCI_BUS)
8cba80c3
FB
37
38#define HP_EVENT_TO_CONFIGURED 0x0301
39#define HP_EVENT_RESERVED_TO_STANDBY 0x0302
40#define HP_EVENT_CONFIGURED_TO_STBRES 0x0304
41#define HP_EVENT_STANDBY_TO_RESERVED 0x0308
42
43#define ERR_EVENT_INVALAS 0x1
44#define ERR_EVENT_OORANGE 0x2
45#define ERR_EVENT_INVALTF 0x3
46#define ERR_EVENT_TPROTE 0x4
47#define ERR_EVENT_APROTE 0x5
48#define ERR_EVENT_KEYE 0x6
49#define ERR_EVENT_INVALTE 0x7
50#define ERR_EVENT_INVALTL 0x8
51#define ERR_EVENT_TT 0x9
52#define ERR_EVENT_INVALMS 0xa
53#define ERR_EVENT_SERR 0xb
54#define ERR_EVENT_NOMSI 0x10
55#define ERR_EVENT_INVALBV 0x11
56#define ERR_EVENT_AIBV 0x12
57#define ERR_EVENT_AIRERR 0x13
58#define ERR_EVENT_FMBA 0x2a
59#define ERR_EVENT_FMBUP 0x2b
60#define ERR_EVENT_FMBPRO 0x2c
61#define ERR_EVENT_CCONF 0x30
62#define ERR_EVENT_SERVAC 0x3a
63#define ERR_EVENT_PERMERR 0x3b
64
65#define ERR_EVENT_Q_BIT 0x2
66#define ERR_EVENT_MVN_OFFSET 16
67
68#define ZPCI_MSI_VEC_BITS 11
69#define ZPCI_MSI_VEC_MASK 0x7ff
70
71#define ZPCI_MSI_ADDR 0xfe00000000000000ULL
72#define ZPCI_SDMA_ADDR 0x100000000ULL
73#define ZPCI_EDMA_ADDR 0x1ffffffffffffffULL
74
75#define PAGE_SHIFT 12
76#define PAGE_MASK (~(PAGE_SIZE-1))
77#define PAGE_DEFAULT_ACC 0
78#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
79
80/* I/O Translation Anchor (IOTA) */
81enum ZpciIoatDtype {
82 ZPCI_IOTA_STO = 0,
83 ZPCI_IOTA_RTTO = 1,
84 ZPCI_IOTA_RSTO = 2,
85 ZPCI_IOTA_RFTO = 3,
86 ZPCI_IOTA_PFAA = 4,
87 ZPCI_IOTA_IOPFAA = 5,
88 ZPCI_IOTA_IOPTO = 7
89};
90
91#define ZPCI_IOTA_IOT_ENABLED 0x800ULL
92#define ZPCI_IOTA_DT_ST (ZPCI_IOTA_STO << 2)
93#define ZPCI_IOTA_DT_RT (ZPCI_IOTA_RTTO << 2)
94#define ZPCI_IOTA_DT_RS (ZPCI_IOTA_RSTO << 2)
95#define ZPCI_IOTA_DT_RF (ZPCI_IOTA_RFTO << 2)
96#define ZPCI_IOTA_DT_PF (ZPCI_IOTA_PFAA << 2)
97#define ZPCI_IOTA_FS_4K 0
98#define ZPCI_IOTA_FS_1M 1
99#define ZPCI_IOTA_FS_2G 2
100#define ZPCI_KEY (PAGE_DEFAULT_KEY << 5)
101
102#define ZPCI_IOTA_STO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_ST)
103#define ZPCI_IOTA_RTTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RT)
104#define ZPCI_IOTA_RSTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RS)
105#define ZPCI_IOTA_RFTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RF)
106#define ZPCI_IOTA_RFAA_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY |\
107 ZPCI_IOTA_DT_PF | ZPCI_IOTA_FS_2G)
108
109/* I/O Region and segment tables */
110#define ZPCI_INDEX_MASK 0x7ffULL
111
112#define ZPCI_TABLE_TYPE_MASK 0xc
113#define ZPCI_TABLE_TYPE_RFX 0xc
114#define ZPCI_TABLE_TYPE_RSX 0x8
115#define ZPCI_TABLE_TYPE_RTX 0x4
116#define ZPCI_TABLE_TYPE_SX 0x0
117
118#define ZPCI_TABLE_LEN_RFX 0x3
119#define ZPCI_TABLE_LEN_RSX 0x3
120#define ZPCI_TABLE_LEN_RTX 0x3
121
122#define ZPCI_TABLE_OFFSET_MASK 0xc0
123#define ZPCI_TABLE_SIZE 0x4000
124#define ZPCI_TABLE_ALIGN ZPCI_TABLE_SIZE
125#define ZPCI_TABLE_ENTRY_SIZE (sizeof(unsigned long))
126#define ZPCI_TABLE_ENTRIES (ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE)
127
128#define ZPCI_TABLE_BITS 11
129#define ZPCI_PT_BITS 8
130#define ZPCI_ST_SHIFT (ZPCI_PT_BITS + PAGE_SHIFT)
131#define ZPCI_RT_SHIFT (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS)
132
133#define ZPCI_RTE_FLAG_MASK 0x3fffULL
134#define ZPCI_RTE_ADDR_MASK (~ZPCI_RTE_FLAG_MASK)
135#define ZPCI_STE_FLAG_MASK 0x7ffULL
136#define ZPCI_STE_ADDR_MASK (~ZPCI_STE_FLAG_MASK)
137
138/* I/O Page tables */
139#define ZPCI_PTE_VALID_MASK 0x400
140#define ZPCI_PTE_INVALID 0x400
141#define ZPCI_PTE_VALID 0x000
142#define ZPCI_PT_SIZE 0x800
143#define ZPCI_PT_ALIGN ZPCI_PT_SIZE
144#define ZPCI_PT_ENTRIES (ZPCI_PT_SIZE / ZPCI_TABLE_ENTRY_SIZE)
145#define ZPCI_PT_MASK (ZPCI_PT_ENTRIES - 1)
146
147#define ZPCI_PTE_FLAG_MASK 0xfffULL
148#define ZPCI_PTE_ADDR_MASK (~ZPCI_PTE_FLAG_MASK)
149
150/* Shared bits */
151#define ZPCI_TABLE_VALID 0x00
152#define ZPCI_TABLE_INVALID 0x20
153#define ZPCI_TABLE_PROTECTED 0x200
154#define ZPCI_TABLE_UNPROTECTED 0x000
155
156#define ZPCI_TABLE_VALID_MASK 0x20
157#define ZPCI_TABLE_PROT_MASK 0x200
158
5d1abf23
YMZ
159/* PCI Function States
160 *
161 * reserved: default; device has just been plugged or is in progress of being
162 * unplugged
163 * standby: device is present but not configured; transition from any
164 * configured state/to this state via sclp configure/deconfigure
165 *
166 * The following states make up the "configured" meta-state:
167 * disabled: device is configured but not enabled; transition between this
168 * state and enabled via clp enable/disable
169 * enbaled: device is ready for use; transition to disabled via clp disable;
170 * may enter an error state
171 * blocked: ignore all DMA and interrupts; transition back to enabled or from
172 * error state via mpcifc
173 * error: an error occured; transition back to enabled via mpcifc
174 * permanent error: an unrecoverable error occured; transition to standby via
175 * sclp deconfigure
176 */
177typedef enum {
178 ZPCI_FS_RESERVED,
179 ZPCI_FS_STANDBY,
180 ZPCI_FS_DISABLED,
181 ZPCI_FS_ENABLED,
182 ZPCI_FS_BLOCKED,
183 ZPCI_FS_ERROR,
184 ZPCI_FS_PERMANENT_ERROR,
185} ZpciState;
186
8cba80c3
FB
187typedef struct SeiContainer {
188 QTAILQ_ENTRY(SeiContainer) link;
189 uint32_t fid;
190 uint32_t fh;
191 uint8_t cc;
192 uint16_t pec;
193 uint64_t faddr;
194 uint32_t e;
195} SeiContainer;
196
197typedef struct PciCcdfErr {
198 uint32_t reserved1;
199 uint32_t fh;
200 uint32_t fid;
201 uint32_t e;
202 uint64_t faddr;
203 uint32_t reserved3;
204 uint16_t reserved4;
205 uint16_t pec;
206} QEMU_PACKED PciCcdfErr;
207
208typedef struct PciCcdfAvail {
209 uint32_t reserved1;
210 uint32_t fh;
211 uint32_t fid;
212 uint32_t reserved2;
213 uint32_t reserved3;
214 uint32_t reserved4;
215 uint32_t reserved5;
216 uint16_t reserved6;
217 uint16_t pec;
218} QEMU_PACKED PciCcdfAvail;
219
220typedef struct ChscSeiNt2Res {
221 uint16_t length;
222 uint16_t code;
223 uint16_t reserved1;
224 uint8_t reserved2;
225 uint8_t nt;
226 uint8_t flags;
227 uint8_t reserved3;
228 uint8_t reserved4;
229 uint8_t cc;
230 uint32_t reserved5[13];
231 uint8_t ccdf[4016];
232} QEMU_PACKED ChscSeiNt2Res;
233
234typedef struct PciCfgSccb {
c2691694
YMZ
235 SCCBHeader header;
236 uint8_t atype;
237 uint8_t reserved1;
238 uint16_t reserved2;
239 uint32_t aid;
8cba80c3
FB
240} QEMU_PACKED PciCfgSccb;
241
242typedef struct S390MsixInfo {
243 bool available;
244 uint8_t table_bar;
245 uint8_t pba_bar;
246 uint16_t entries;
247 uint32_t table_offset;
248 uint32_t pba_offset;
249} S390MsixInfo;
250
251typedef struct S390PCIBusDevice {
252 PCIDevice *pdev;
5d1abf23 253 ZpciState state;
df6a050c 254 bool iommu_enabled;
8cba80c3
FB
255 uint32_t fh;
256 uint32_t fid;
257 uint64_t g_iota;
258 uint64_t pba;
259 uint64_t pal;
260 uint64_t fmb_addr;
261 uint8_t isc;
262 uint16_t noi;
263 uint8_t sum;
264 S390MsixInfo msix;
265 AdapterRoutes routes;
266 AddressSpace as;
267 MemoryRegion mr;
f0a399db 268 MemoryRegion iommu_mr;
8581c115
YMZ
269 IndAddr *summary_ind;
270 IndAddr *indicator;
8cba80c3
FB
271} S390PCIBusDevice;
272
90a0f9af
YMZ
273typedef struct S390PCIBus {
274 BusState qbus;
275} S390PCIBus;
276
8cba80c3
FB
277typedef struct S390pciState {
278 PCIHostState parent_obj;
90a0f9af 279 S390PCIBus *bus;
8cba80c3
FB
280 S390PCIBusDevice pbdev[PCI_SLOT_MAX];
281 AddressSpace msix_notify_as;
282 MemoryRegion msix_notify_mr;
283 QTAILQ_HEAD(, SeiContainer) pending_sei;
284} S390pciState;
285
286int chsc_sei_nt2_get_event(void *res);
287int chsc_sei_nt2_have_event(void);
8f5cb693
YMZ
288void s390_pci_sclp_configure(SCCB *sccb);
289void s390_pci_sclp_deconfigure(SCCB *sccb);
71583888
YMZ
290void s390_pci_iommu_enable(S390PCIBusDevice *pbdev);
291void s390_pci_iommu_disable(S390PCIBusDevice *pbdev);
5d1abf23
YMZ
292void s390_pci_generate_error_event(uint16_t pec, uint32_t fh, uint32_t fid,
293 uint64_t faddr, uint32_t e);
8cba80c3
FB
294S390PCIBusDevice *s390_pci_find_dev_by_idx(uint32_t idx);
295S390PCIBusDevice *s390_pci_find_dev_by_fh(uint32_t fh);
296S390PCIBusDevice *s390_pci_find_dev_by_fid(uint32_t fid);
297
298#endif
This page took 0.155719 seconds and 4 git commands to generate.