]> Git Repo - qemu.git/blob - hw/s390x/s390-pci-bus.h
s390x/pci: unify FH_ macros
[qemu.git] / hw / s390x / s390-pci-bus.h
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"
24 #define FH_MASK_ENABLE   0x80000000
25 #define FH_MASK_INSTANCE 0x7f000000
26 #define FH_MASK_SHM      0x00ff0000
27 #define FH_MASK_INDEX    0x0000001f
28 #define FH_SHM_VFIO      0x00010000
29 #define FH_SHM_EMUL      0x00020000
30 #define S390_PCIPT_ADAPTER 2
31
32 #define S390_PCI_HOST_BRIDGE(obj) \
33     OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)
34
35 #define HP_EVENT_TO_CONFIGURED        0x0301
36 #define HP_EVENT_RESERVED_TO_STANDBY  0x0302
37 #define HP_EVENT_CONFIGURED_TO_STBRES 0x0304
38 #define HP_EVENT_STANDBY_TO_RESERVED  0x0308
39
40 #define ERR_EVENT_INVALAS 0x1
41 #define ERR_EVENT_OORANGE 0x2
42 #define ERR_EVENT_INVALTF 0x3
43 #define ERR_EVENT_TPROTE  0x4
44 #define ERR_EVENT_APROTE  0x5
45 #define ERR_EVENT_KEYE    0x6
46 #define ERR_EVENT_INVALTE 0x7
47 #define ERR_EVENT_INVALTL 0x8
48 #define ERR_EVENT_TT      0x9
49 #define ERR_EVENT_INVALMS 0xa
50 #define ERR_EVENT_SERR    0xb
51 #define ERR_EVENT_NOMSI   0x10
52 #define ERR_EVENT_INVALBV 0x11
53 #define ERR_EVENT_AIBV    0x12
54 #define ERR_EVENT_AIRERR  0x13
55 #define ERR_EVENT_FMBA    0x2a
56 #define ERR_EVENT_FMBUP   0x2b
57 #define ERR_EVENT_FMBPRO  0x2c
58 #define ERR_EVENT_CCONF   0x30
59 #define ERR_EVENT_SERVAC  0x3a
60 #define ERR_EVENT_PERMERR 0x3b
61
62 #define ERR_EVENT_Q_BIT 0x2
63 #define ERR_EVENT_MVN_OFFSET 16
64
65 #define ZPCI_MSI_VEC_BITS 11
66 #define ZPCI_MSI_VEC_MASK 0x7ff
67
68 #define ZPCI_MSI_ADDR  0xfe00000000000000ULL
69 #define ZPCI_SDMA_ADDR 0x100000000ULL
70 #define ZPCI_EDMA_ADDR 0x1ffffffffffffffULL
71
72 #define PAGE_SHIFT      12
73 #define PAGE_MASK       (~(PAGE_SIZE-1))
74 #define PAGE_DEFAULT_ACC        0
75 #define PAGE_DEFAULT_KEY        (PAGE_DEFAULT_ACC << 4)
76
77 /* I/O Translation Anchor (IOTA) */
78 enum ZpciIoatDtype {
79     ZPCI_IOTA_STO = 0,
80     ZPCI_IOTA_RTTO = 1,
81     ZPCI_IOTA_RSTO = 2,
82     ZPCI_IOTA_RFTO = 3,
83     ZPCI_IOTA_PFAA = 4,
84     ZPCI_IOTA_IOPFAA = 5,
85     ZPCI_IOTA_IOPTO = 7
86 };
87
88 #define ZPCI_IOTA_IOT_ENABLED           0x800ULL
89 #define ZPCI_IOTA_DT_ST                 (ZPCI_IOTA_STO  << 2)
90 #define ZPCI_IOTA_DT_RT                 (ZPCI_IOTA_RTTO << 2)
91 #define ZPCI_IOTA_DT_RS                 (ZPCI_IOTA_RSTO << 2)
92 #define ZPCI_IOTA_DT_RF                 (ZPCI_IOTA_RFTO << 2)
93 #define ZPCI_IOTA_DT_PF                 (ZPCI_IOTA_PFAA << 2)
94 #define ZPCI_IOTA_FS_4K                 0
95 #define ZPCI_IOTA_FS_1M                 1
96 #define ZPCI_IOTA_FS_2G                 2
97 #define ZPCI_KEY                        (PAGE_DEFAULT_KEY << 5)
98
99 #define ZPCI_IOTA_STO_FLAG  (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_ST)
100 #define ZPCI_IOTA_RTTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RT)
101 #define ZPCI_IOTA_RSTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RS)
102 #define ZPCI_IOTA_RFTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RF)
103 #define ZPCI_IOTA_RFAA_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY |\
104                              ZPCI_IOTA_DT_PF | ZPCI_IOTA_FS_2G)
105
106 /* I/O Region and segment tables */
107 #define ZPCI_INDEX_MASK         0x7ffULL
108
109 #define ZPCI_TABLE_TYPE_MASK    0xc
110 #define ZPCI_TABLE_TYPE_RFX     0xc
111 #define ZPCI_TABLE_TYPE_RSX     0x8
112 #define ZPCI_TABLE_TYPE_RTX     0x4
113 #define ZPCI_TABLE_TYPE_SX      0x0
114
115 #define ZPCI_TABLE_LEN_RFX      0x3
116 #define ZPCI_TABLE_LEN_RSX      0x3
117 #define ZPCI_TABLE_LEN_RTX      0x3
118
119 #define ZPCI_TABLE_OFFSET_MASK  0xc0
120 #define ZPCI_TABLE_SIZE         0x4000
121 #define ZPCI_TABLE_ALIGN        ZPCI_TABLE_SIZE
122 #define ZPCI_TABLE_ENTRY_SIZE   (sizeof(unsigned long))
123 #define ZPCI_TABLE_ENTRIES      (ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE)
124
125 #define ZPCI_TABLE_BITS         11
126 #define ZPCI_PT_BITS            8
127 #define ZPCI_ST_SHIFT           (ZPCI_PT_BITS + PAGE_SHIFT)
128 #define ZPCI_RT_SHIFT           (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS)
129
130 #define ZPCI_RTE_FLAG_MASK      0x3fffULL
131 #define ZPCI_RTE_ADDR_MASK      (~ZPCI_RTE_FLAG_MASK)
132 #define ZPCI_STE_FLAG_MASK      0x7ffULL
133 #define ZPCI_STE_ADDR_MASK      (~ZPCI_STE_FLAG_MASK)
134
135 /* I/O Page tables */
136 #define ZPCI_PTE_VALID_MASK             0x400
137 #define ZPCI_PTE_INVALID                0x400
138 #define ZPCI_PTE_VALID                  0x000
139 #define ZPCI_PT_SIZE                    0x800
140 #define ZPCI_PT_ALIGN                   ZPCI_PT_SIZE
141 #define ZPCI_PT_ENTRIES                 (ZPCI_PT_SIZE / ZPCI_TABLE_ENTRY_SIZE)
142 #define ZPCI_PT_MASK                    (ZPCI_PT_ENTRIES - 1)
143
144 #define ZPCI_PTE_FLAG_MASK              0xfffULL
145 #define ZPCI_PTE_ADDR_MASK              (~ZPCI_PTE_FLAG_MASK)
146
147 /* Shared bits */
148 #define ZPCI_TABLE_VALID                0x00
149 #define ZPCI_TABLE_INVALID              0x20
150 #define ZPCI_TABLE_PROTECTED            0x200
151 #define ZPCI_TABLE_UNPROTECTED          0x000
152
153 #define ZPCI_TABLE_VALID_MASK           0x20
154 #define ZPCI_TABLE_PROT_MASK            0x200
155
156 typedef struct SeiContainer {
157     QTAILQ_ENTRY(SeiContainer) link;
158     uint32_t fid;
159     uint32_t fh;
160     uint8_t cc;
161     uint16_t pec;
162     uint64_t faddr;
163     uint32_t e;
164 } SeiContainer;
165
166 typedef struct PciCcdfErr {
167     uint32_t reserved1;
168     uint32_t fh;
169     uint32_t fid;
170     uint32_t e;
171     uint64_t faddr;
172     uint32_t reserved3;
173     uint16_t reserved4;
174     uint16_t pec;
175 } QEMU_PACKED PciCcdfErr;
176
177 typedef struct PciCcdfAvail {
178     uint32_t reserved1;
179     uint32_t fh;
180     uint32_t fid;
181     uint32_t reserved2;
182     uint32_t reserved3;
183     uint32_t reserved4;
184     uint32_t reserved5;
185     uint16_t reserved6;
186     uint16_t pec;
187 } QEMU_PACKED PciCcdfAvail;
188
189 typedef struct ChscSeiNt2Res {
190     uint16_t length;
191     uint16_t code;
192     uint16_t reserved1;
193     uint8_t reserved2;
194     uint8_t nt;
195     uint8_t flags;
196     uint8_t reserved3;
197     uint8_t reserved4;
198     uint8_t cc;
199     uint32_t reserved5[13];
200     uint8_t ccdf[4016];
201 } QEMU_PACKED ChscSeiNt2Res;
202
203 typedef struct PciCfgSccb {
204     SCCBHeader header;
205     uint8_t atype;
206     uint8_t reserved1;
207     uint16_t reserved2;
208     uint32_t aid;
209 } QEMU_PACKED PciCfgSccb;
210
211 typedef struct S390MsixInfo {
212     bool available;
213     uint8_t table_bar;
214     uint8_t pba_bar;
215     uint16_t entries;
216     uint32_t table_offset;
217     uint32_t pba_offset;
218 } S390MsixInfo;
219
220 typedef struct S390PCIBusDevice {
221     PCIDevice *pdev;
222     bool configured;
223     bool error_state;
224     bool lgstg_blocked;
225     bool iommu_enabled;
226     uint32_t fh;
227     uint32_t fid;
228     uint64_t g_iota;
229     uint64_t pba;
230     uint64_t pal;
231     uint64_t fmb_addr;
232     uint8_t isc;
233     uint16_t noi;
234     uint8_t sum;
235     S390MsixInfo msix;
236     AdapterRoutes routes;
237     AddressSpace as;
238     MemoryRegion mr;
239     MemoryRegion iommu_mr;
240     IndAddr *summary_ind;
241     IndAddr *indicator;
242 } S390PCIBusDevice;
243
244 typedef struct S390pciState {
245     PCIHostState parent_obj;
246     S390PCIBusDevice pbdev[PCI_SLOT_MAX];
247     AddressSpace msix_notify_as;
248     MemoryRegion msix_notify_mr;
249     QTAILQ_HEAD(, SeiContainer) pending_sei;
250 } S390pciState;
251
252 int chsc_sei_nt2_get_event(void *res);
253 int chsc_sei_nt2_have_event(void);
254 void s390_pci_sclp_configure(SCCB *sccb);
255 void s390_pci_sclp_deconfigure(SCCB *sccb);
256 void s390_pci_iommu_enable(S390PCIBusDevice *pbdev);
257 void s390_pci_iommu_disable(S390PCIBusDevice *pbdev);
258 S390PCIBusDevice *s390_pci_find_dev_by_idx(uint32_t idx);
259 S390PCIBusDevice *s390_pci_find_dev_by_fh(uint32_t fh);
260 S390PCIBusDevice *s390_pci_find_dev_by_fid(uint32_t fid);
261
262 #endif
This page took 0.037336 seconds and 4 git commands to generate.