]> git.proxmox.com Git - mirror_qemu.git/blob - hw/s390x/3270-ccw.c
s390x/3270: Add abstract emulated ccw-attached 3270 device
[mirror_qemu.git] / hw / s390x / 3270-ccw.c
1 /*
2 * Emulated ccw-attached 3270 implementation
3 *
4 * Copyright 2017 IBM Corp.
5 * Author(s): Yang Chen <bjcyang@linux.vnet.ibm.com>
6 * Jing Liu <liujbjl@linux.vnet.ibm.com>
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
10 * directory.
11 */
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu/module.h"
15 #include "cpu.h"
16 #include "hw/s390x/css.h"
17 #include "hw/s390x/css-bridge.h"
18 #include "hw/s390x/3270-ccw.h"
19
20 static void emulated_ccw_3270_realize(DeviceState *ds, Error **errp)
21 {
22 uint16_t chpid;
23 EmulatedCcw3270Device *dev = EMULATED_CCW_3270(ds);
24 EmulatedCcw3270Class *ck = EMULATED_CCW_3270_GET_CLASS(dev);
25 CcwDevice *cdev = CCW_DEVICE(ds);
26 CCWDeviceClass *cdk = CCW_DEVICE_GET_CLASS(cdev);
27 SubchDev *sch = css_create_virtual_sch(cdev->devno, errp);
28 Error *err = NULL;
29
30 if (!sch) {
31 return;
32 }
33
34 if (!ck->init) {
35 goto out_err;
36 }
37
38 sch->driver_data = dev;
39 cdev->sch = sch;
40 chpid = css_find_free_chpid(sch->cssid);
41
42 if (chpid > MAX_CHPID) {
43 error_setg(&err, "No available chpid to use.");
44 goto out_err;
45 }
46
47 sch->id.reserved = 0xff;
48 sch->id.cu_type = EMULATED_CCW_3270_CU_TYPE;
49 css_sch_build_virtual_schib(sch, (uint8_t)chpid,
50 EMULATED_CCW_3270_CHPID_TYPE);
51
52 ck->init(dev, &err);
53 if (err) {
54 goto out_err;
55 }
56
57 cdk->realize(cdev, &err);
58 if (err) {
59 goto out_err;
60 }
61
62 return;
63
64 out_err:
65 error_propagate(errp, err);
66 css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
67 cdev->sch = NULL;
68 g_free(sch);
69 }
70
71 static Property emulated_ccw_3270_properties[] = {
72 DEFINE_PROP_END_OF_LIST(),
73 };
74
75 static void emulated_ccw_3270_class_init(ObjectClass *klass, void *data)
76 {
77 DeviceClass *dc = DEVICE_CLASS(klass);
78
79 dc->props = emulated_ccw_3270_properties;
80 dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
81 dc->realize = emulated_ccw_3270_realize;
82 dc->hotpluggable = false;
83 }
84
85 static const TypeInfo emulated_ccw_3270_info = {
86 .name = TYPE_EMULATED_CCW_3270,
87 .parent = TYPE_CCW_DEVICE,
88 .instance_size = sizeof(EmulatedCcw3270Device),
89 .class_init = emulated_ccw_3270_class_init,
90 .class_size = sizeof(EmulatedCcw3270Class),
91 .abstract = true,
92 };
93
94 static void emulated_ccw_register(void)
95 {
96 type_register_static(&emulated_ccw_3270_info);
97 }
98
99 type_init(emulated_ccw_register)