]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/s390x/css.h
s390x: avoid calling kvm_ functions outside of target/s390x/
[mirror_qemu.git] / include / hw / s390x / css.h
CommitLineData
df1fe5bb
CH
1/*
2 * Channel subsystem structures and definitions.
3 *
4 * Copyright 2012 IBM Corp.
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
9 * directory.
10 */
11
12#ifndef CSS_H
13#define CSS_H
14
2283f4d6 15#include "cpu.h"
a28d8391
YMZ
16#include "hw/s390x/adapter.h"
17#include "hw/s390x/s390_flic.h"
bd3f16ac 18#include "hw/s390x/ioinst.h"
df1fe5bb
CH
19
20/* Channel subsystem constants. */
cf249935 21#define MAX_DEVNO 65535
df1fe5bb
CH
22#define MAX_SCHID 65535
23#define MAX_SSID 3
882b3b97 24#define MAX_CSSID 255
df1fe5bb
CH
25#define MAX_CHPID 255
26
dde522bb
FL
27#define MAX_ISC 7
28
df1fe5bb
CH
29#define MAX_CIWS 62
30
cf249935 31#define VIRTUAL_CSSID 0xfe
6c15e9bf 32#define VIRTIO_CCW_CHPID 0 /* used by convention */
cf249935 33
df1fe5bb
CH
34typedef struct CIW {
35 uint8_t type;
36 uint8_t command;
37 uint16_t count;
38} QEMU_PACKED CIW;
39
40typedef struct SenseId {
41 /* common part */
42 uint8_t reserved; /* always 0x'FF' */
43 uint16_t cu_type; /* control unit type */
44 uint8_t cu_model; /* control unit model */
45 uint16_t dev_type; /* device type */
46 uint8_t dev_model; /* device model */
47 uint8_t unused; /* padding byte */
48 /* extended part */
49 CIW ciw[MAX_CIWS]; /* variable # of CIWs */
50} QEMU_PACKED SenseId;
51
52/* Channel measurements, from linux/drivers/s390/cio/cmf.c. */
53typedef struct CMB {
54 uint16_t ssch_rsch_count;
55 uint16_t sample_count;
56 uint32_t device_connect_time;
57 uint32_t function_pending_time;
58 uint32_t device_disconnect_time;
59 uint32_t control_unit_queuing_time;
60 uint32_t device_active_only_time;
61 uint32_t reserved[2];
62} QEMU_PACKED CMB;
63
64typedef struct CMBE {
65 uint32_t ssch_rsch_count;
66 uint32_t sample_count;
67 uint32_t device_connect_time;
68 uint32_t function_pending_time;
69 uint32_t device_disconnect_time;
70 uint32_t control_unit_queuing_time;
71 uint32_t device_active_only_time;
72 uint32_t device_busy_time;
73 uint32_t initial_command_response_time;
74 uint32_t reserved[7];
75} QEMU_PACKED CMBE;
76
bd3f16ac 77typedef struct SubchDev SubchDev;
df1fe5bb
CH
78struct SubchDev {
79 /* channel-subsystem related things: */
80 uint8_t cssid;
81 uint8_t ssid;
82 uint16_t schid;
83 uint16_t devno;
84 SCHIB curr_status;
85 uint8_t sense_data[32];
86 hwaddr channel_prog;
87 CCW1 last_cmd;
88 bool last_cmd_valid;
a327c921 89 bool ccw_fmt_1;
7e749462 90 bool thinint_active;
e8601dd5 91 uint8_t ccw_no_data_cnt;
517ff12c 92 uint16_t migrated_schid; /* used for missmatch detection */
ff443fe6 93 ORB orb;
df1fe5bb
CH
94 /* transport-provided data: */
95 int (*ccw_cb) (SubchDev *, CCW1);
62ac4a52 96 void (*disable_cb)(SubchDev *);
b5f5a3af 97 int (*do_subchannel_work) (SubchDev *);
df1fe5bb
CH
98 SenseId id;
99 void *driver_data;
100};
101
517ff12c
HP
102extern const VMStateDescription vmstate_subch_dev;
103
8f3cf012
XFR
104/*
105 * Identify a device within the channel subsystem.
106 * Note that this can be used to identify either the subchannel or
107 * the attached I/O device, as there's always one I/O device per
108 * subchannel.
109 */
110typedef struct CssDevId {
111 uint8_t cssid;
112 uint8_t ssid;
113 uint16_t devid;
114 bool valid;
115} CssDevId;
116
1b6b7d10 117extern const PropertyInfo css_devid_propinfo;
8f3cf012
XFR
118
119#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \
120 DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId)
121
a28d8391
YMZ
122typedef struct IndAddr {
123 hwaddr addr;
124 uint64_t map;
125 unsigned long refcnt;
517ff12c 126 int32_t len;
a28d8391
YMZ
127 QTAILQ_ENTRY(IndAddr) sibling;
128} IndAddr;
129
517ff12c
HP
130extern const VMStateDescription vmstate_ind_addr;
131
132#define VMSTATE_PTR_TO_IND_ADDR(_f, _s) \
133 VMSTATE_STRUCT(_f, _s, 1, vmstate_ind_addr, IndAddr*)
134
a28d8391
YMZ
135IndAddr *get_indicator(hwaddr ind_addr, int len);
136void release_indicator(AdapterInfo *adapter, IndAddr *indicator);
137int map_indicator(AdapterInfo *adapter, IndAddr *indicator);
138
df1fe5bb
CH
139typedef SubchDev *(*css_subch_cb_func)(uint8_t m, uint8_t cssid, uint8_t ssid,
140 uint16_t schid);
141int css_create_css_image(uint8_t cssid, bool default_image);
142bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno);
143void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
144 uint16_t devno, SubchDev *sch);
145void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
8f3cf012 146int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id);
6c15e9bf 147unsigned int css_find_free_chpid(uint8_t cssid);
b4436a0b 148uint16_t css_build_subchannel_id(SubchDev *sch);
8ca2b376
XFR
149void copy_scsw_to_guest(SCSW *dest, const SCSW *src);
150void css_inject_io_interrupt(SubchDev *sch);
df1fe5bb
CH
151void css_reset(void);
152void css_reset_sch(SubchDev *sch);
5c8d6f00
DJS
153void css_queue_crw(uint8_t rsc, uint8_t erc, int solicited,
154 int chain, uint16_t rsid);
df1fe5bb
CH
155void css_generate_sch_crws(uint8_t cssid, uint8_t ssid, uint16_t schid,
156 int hotplugged, int add);
157void css_generate_chp_crws(uint8_t cssid, uint8_t chpid);
8cba80c3 158void css_generate_css_crws(uint8_t cssid);
c81b4f89 159void css_clear_sei_pending(void);
bab482d7 160int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data);
b5f5a3af
HP
161int do_subchannel_work_virtual(SubchDev *sub);
162int do_subchannel_work_passthrough(SubchDev *sub);
03cf077a 163
5b00bef2
FL
164typedef enum {
165 CSS_IO_ADAPTER_VIRTIO = 0,
166 CSS_IO_ADAPTER_PCI = 1,
167 CSS_IO_ADAPTER_TYPE_NUMS,
168} CssIoAdapterType;
169
25a08b8d 170void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc);
2283f4d6 171int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode);
dde522bb
FL
172uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
173void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
1497c160
FL
174 uint8_t flags, Error **errp);
175
176#ifndef CONFIG_KVM
177#define S390_ADAPTER_SUPPRESSIBLE 0x01
178#else
179#define S390_ADAPTER_SUPPRESSIBLE KVM_S390_ADAPTER_SUPPRESSIBLE
180#endif
bd3f16ac
PB
181
182#ifndef CONFIG_USER_ONLY
183SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid,
184 uint16_t schid);
185bool css_subch_visible(SubchDev *sch);
186void css_conditional_io_interrupt(SubchDev *sch);
187int css_do_stsch(SubchDev *sch, SCHIB *schib);
188bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid);
189int css_do_msch(SubchDev *sch, const SCHIB *schib);
190int css_do_xsch(SubchDev *sch);
191int css_do_csch(SubchDev *sch);
192int css_do_hsch(SubchDev *sch);
193int css_do_ssch(SubchDev *sch, ORB *orb);
194int css_do_tsch_get_irb(SubchDev *sch, IRB *irb, int *irb_len);
195void css_do_tsch_update_subch(SubchDev *sch);
196int css_do_stcrw(CRW *crw);
197void css_undo_stcrw(CRW *crw);
198int css_do_tpi(IOIntCode *int_code, int lowcore);
199int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid,
200 int rfmt, void *buf);
201void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo);
202int css_enable_mcsse(void);
203int css_enable_mss(void);
204int css_do_rsch(SubchDev *sch);
205int css_do_rchp(uint8_t cssid, uint8_t chpid);
206bool css_present(uint8_t cssid);
207#endif
208
1b6b7d10 209extern const PropertyInfo css_devid_ro_propinfo;
c35fc6aa
DJS
210
211#define DEFINE_PROP_CSS_DEV_ID_RO(_n, _s, _f) \
212 DEFINE_PROP(_n, _s, _f, css_devid_ro_propinfo, CssDevId)
213
cf249935
SS
214/**
215 * Create a subchannel for the given bus id.
216 *
817d4a6b
DJS
217 * If @p bus_id is valid, and @p squash_mcss is true, verify that it is
218 * not already in use in the default css, and find a free devno from the
219 * default css image for it.
220 * If @p bus_id is valid, and @p squash_mcss is false, verify that it is
221 * not already in use, and find a free devno for it.
222 * If @p bus_id is not valid, and if either @p squash_mcss or @p is_virtual
223 * is true, find a free subchannel id and device number across all
224 * subchannel sets from the default css image.
225 * If @p bus_id is not valid, and if both @p squash_mcss and @p is_virtual
226 * are false, find a non-full css image and find a free subchannel id and
227 * device number across all subchannel sets from it.
228 *
229 * If either of the former actions succeed, allocate a subchannel structure,
230 * initialise it with the bus id, subchannel id and device number, register
231 * it with the CSS and return it. Otherwise return NULL.
cf249935
SS
232 *
233 * The caller becomes owner of the returned subchannel structure and
234 * is responsible for unregistering and freeing it.
235 */
817d4a6b
DJS
236SubchDev *css_create_sch(CssDevId bus_id, bool is_virtual, bool squash_mcss,
237 Error **errp);
e996583e
HP
238
239/** Turn on css migration */
240void css_register_vmstate(void);
241
df1fe5bb 242#endif