]>
Commit | Line | Data |
---|---|---|
a9b74079 CM |
1 | /* |
2 | * QEMU ISA IPMI BT emulation | |
3 | * | |
4 | * Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
0b8fa32f | 24 | |
0430891c | 25 | #include "qemu/osdep.h" |
efbb649d | 26 | #include "qemu/log.h" |
0b8fa32f | 27 | #include "qemu/module.h" |
da34e65c | 28 | #include "qapi/error.h" |
64552b6b | 29 | #include "hw/irq.h" |
1739d54c | 30 | #include "hw/ipmi/ipmi_bt.h" |
a9b74079 | 31 | #include "hw/isa/isa.h" |
a27bd6c7 | 32 | #include "hw/qdev-properties.h" |
d6454270 | 33 | #include "migration/vmstate.h" |
db1015e9 | 34 | #include "qom/object.h" |
a9b74079 | 35 | |
a9b74079 | 36 | #define TYPE_ISA_IPMI_BT "isa-ipmi-bt" |
8063396b | 37 | OBJECT_DECLARE_SIMPLE_TYPE(ISAIPMIBTDevice, ISA_IPMI_BT) |
a9b74079 | 38 | |
db1015e9 | 39 | struct ISAIPMIBTDevice { |
a9b74079 | 40 | ISADevice dev; |
f4014512 | 41 | int32_t isairq; |
1739d54c | 42 | qemu_irq irq; |
a9b74079 | 43 | IPMIBT bt; |
15139b8e | 44 | uint32_t uuid; |
db1015e9 | 45 | }; |
a9b74079 | 46 | |
1739d54c | 47 | static void isa_ipmi_bt_get_fwinfo(struct IPMIInterface *ii, IPMIFwInfo *info) |
15139b8e CM |
48 | { |
49 | ISAIPMIBTDevice *iib = ISA_IPMI_BT(ii); | |
50 | ||
1739d54c | 51 | ipmi_bt_get_fwinfo(&iib->bt, info); |
15139b8e CM |
52 | info->interrupt_number = iib->isairq; |
53 | info->i2c_slave_address = iib->bt.bmc->slave_addr; | |
54 | info->uuid = iib->uuid; | |
55 | } | |
56 | ||
1739d54c | 57 | static void isa_ipmi_bt_raise_irq(IPMIBT *ib) |
15139b8e | 58 | { |
1739d54c CM |
59 | ISAIPMIBTDevice *iib = ib->opaque; |
60 | ||
61 | qemu_irq_raise(iib->irq); | |
62 | } | |
63 | ||
64 | static void isa_ipmi_bt_lower_irq(IPMIBT *ib) | |
65 | { | |
66 | ISAIPMIBTDevice *iib = ib->opaque; | |
67 | ||
68 | qemu_irq_lower(iib->irq); | |
15139b8e CM |
69 | } |
70 | ||
a9b74079 CM |
71 | static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp) |
72 | { | |
f6166a4d | 73 | Error *err = NULL; |
a9b74079 CM |
74 | ISADevice *isadev = ISA_DEVICE(dev); |
75 | ISAIPMIBTDevice *iib = ISA_IPMI_BT(dev); | |
76 | IPMIInterface *ii = IPMI_INTERFACE(dev); | |
77 | IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii); | |
78 | ||
79 | if (!iib->bt.bmc) { | |
80 | error_setg(errp, "IPMI device requires a bmc attribute to be set"); | |
81 | return; | |
82 | } | |
83 | ||
15139b8e CM |
84 | iib->uuid = ipmi_next_uuid(); |
85 | ||
a9b74079 | 86 | iib->bt.bmc->intf = ii; |
1739d54c | 87 | iib->bt.opaque = iib; |
a9b74079 | 88 | |
f6166a4d MA |
89 | iic->init(ii, 0, &err); |
90 | if (err) { | |
91 | error_propagate(errp, err); | |
a9b74079 | 92 | return; |
f6166a4d | 93 | } |
a9b74079 CM |
94 | |
95 | if (iib->isairq > 0) { | |
1739d54c | 96 | isa_init_irq(isadev, &iib->irq, iib->isairq); |
a9b74079 | 97 | iib->bt.use_irq = 1; |
1739d54c CM |
98 | iib->bt.raise_irq = isa_ipmi_bt_raise_irq; |
99 | iib->bt.lower_irq = isa_ipmi_bt_lower_irq; | |
a9b74079 CM |
100 | } |
101 | ||
102 | qdev_set_legacy_instance_id(dev, iib->bt.io_base, iib->bt.io_length); | |
103 | ||
104 | isa_register_ioport(isadev, &iib->bt.io, iib->bt.io_base); | |
105 | } | |
106 | ||
efbb649d CM |
107 | static const VMStateDescription vmstate_ISAIPMIBTDevice = { |
108 | .name = TYPE_IPMI_INTERFACE_PREFIX "isa-bt", | |
109 | .version_id = 2, | |
110 | .minimum_version_id = 2, | |
111 | /* | |
112 | * Version 1 had messed up the array transfer, it's not even usable | |
113 | * because it used VMSTATE_VBUFFER_UINT32, but it did not transfer | |
114 | * the buffer length, so random things would happen. | |
115 | */ | |
bd66bcfc | 116 | .fields = (VMStateField[]) { |
efbb649d | 117 | VMSTATE_STRUCT(bt, ISAIPMIBTDevice, 1, vmstate_IPMIBT, IPMIBT), |
bd66bcfc CM |
118 | VMSTATE_END_OF_LIST() |
119 | } | |
120 | }; | |
121 | ||
a9b74079 CM |
122 | static void isa_ipmi_bt_init(Object *obj) |
123 | { | |
124 | ISAIPMIBTDevice *iib = ISA_IPMI_BT(obj); | |
125 | ||
126 | ipmi_bmc_find_and_link(obj, (Object **) &iib->bt.bmc); | |
bd66bcfc CM |
127 | |
128 | vmstate_register(NULL, 0, &vmstate_ISAIPMIBTDevice, iib); | |
a9b74079 CM |
129 | } |
130 | ||
131 | static void *isa_ipmi_bt_get_backend_data(IPMIInterface *ii) | |
132 | { | |
133 | ISAIPMIBTDevice *iib = ISA_IPMI_BT(ii); | |
134 | ||
135 | return &iib->bt; | |
136 | } | |
137 | ||
138 | static Property ipmi_isa_properties[] = { | |
139 | DEFINE_PROP_UINT32("ioport", ISAIPMIBTDevice, bt.io_base, 0xe4), | |
140 | DEFINE_PROP_INT32("irq", ISAIPMIBTDevice, isairq, 5), | |
141 | DEFINE_PROP_END_OF_LIST(), | |
142 | }; | |
143 | ||
144 | static void isa_ipmi_bt_class_init(ObjectClass *oc, void *data) | |
145 | { | |
146 | DeviceClass *dc = DEVICE_CLASS(oc); | |
147 | IPMIInterfaceClass *iic = IPMI_INTERFACE_CLASS(oc); | |
148 | ||
149 | dc->realize = isa_ipmi_bt_realize; | |
4f67d30b | 150 | device_class_set_props(dc, ipmi_isa_properties); |
a9b74079 CM |
151 | |
152 | iic->get_backend_data = isa_ipmi_bt_get_backend_data; | |
153 | ipmi_bt_class_init(iic); | |
1739d54c | 154 | iic->get_fwinfo = isa_ipmi_bt_get_fwinfo; |
a9b74079 CM |
155 | } |
156 | ||
157 | static const TypeInfo isa_ipmi_bt_info = { | |
158 | .name = TYPE_ISA_IPMI_BT, | |
159 | .parent = TYPE_ISA_DEVICE, | |
160 | .instance_size = sizeof(ISAIPMIBTDevice), | |
161 | .instance_init = isa_ipmi_bt_init, | |
162 | .class_init = isa_ipmi_bt_class_init, | |
163 | .interfaces = (InterfaceInfo[]) { | |
164 | { TYPE_IPMI_INTERFACE }, | |
165 | { } | |
166 | } | |
167 | }; | |
168 | ||
169 | static void ipmi_register_types(void) | |
170 | { | |
171 | type_register_static(&isa_ipmi_bt_info); | |
172 | } | |
173 | ||
174 | type_init(ipmi_register_types) |