2 * QEMU ISA IPMI KCS emulation
4 * Copyright (c) 2015,2017 Corey Minyard, MontaVista Software, LLC
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #include "qemu/osdep.h"
26 #include "qemu/module.h"
27 #include "qapi/error.h"
29 #include "hw/ipmi/ipmi_kcs.h"
30 #include "hw/isa/isa.h"
31 #include "hw/qdev-properties.h"
32 #include "migration/vmstate.h"
33 #include "qom/object.h"
34 #include "hw/acpi/ipmi.h"
36 #define TYPE_ISA_IPMI_KCS "isa-ipmi-kcs"
37 OBJECT_DECLARE_SIMPLE_TYPE(ISAIPMIKCSDevice
, ISA_IPMI_KCS
)
39 struct ISAIPMIKCSDevice
{
47 static void isa_ipmi_kcs_get_fwinfo(IPMIInterface
*ii
, IPMIFwInfo
*info
)
49 ISAIPMIKCSDevice
*iik
= ISA_IPMI_KCS(ii
);
51 ipmi_kcs_get_fwinfo(&iik
->kcs
, info
);
52 info
->interrupt_number
= iik
->isairq
;
53 info
->uuid
= iik
->uuid
;
56 static void isa_ipmi_kcs_raise_irq(IPMIKCS
*ik
)
58 ISAIPMIKCSDevice
*iik
= ik
->opaque
;
60 qemu_irq_raise(iik
->irq
);
63 static void isa_ipmi_kcs_lower_irq(IPMIKCS
*ik
)
65 ISAIPMIKCSDevice
*iik
= ik
->opaque
;
67 qemu_irq_lower(iik
->irq
);
70 static void ipmi_isa_realize(DeviceState
*dev
, Error
**errp
)
73 ISADevice
*isadev
= ISA_DEVICE(dev
);
74 ISAIPMIKCSDevice
*iik
= ISA_IPMI_KCS(dev
);
75 IPMIInterface
*ii
= IPMI_INTERFACE(dev
);
76 IPMIInterfaceClass
*iic
= IPMI_INTERFACE_GET_CLASS(ii
);
79 error_setg(errp
, "IPMI device requires a bmc attribute to be set");
83 iik
->uuid
= ipmi_next_uuid();
85 iik
->kcs
.bmc
->intf
= ii
;
86 iik
->kcs
.opaque
= iik
;
88 iic
->init(ii
, 0, &err
);
90 error_propagate(errp
, err
);
94 if (iik
->isairq
> 0) {
95 iik
->irq
= isa_get_irq(isadev
, iik
->isairq
);
97 iik
->kcs
.raise_irq
= isa_ipmi_kcs_raise_irq
;
98 iik
->kcs
.lower_irq
= isa_ipmi_kcs_lower_irq
;
101 qdev_set_legacy_instance_id(dev
, iik
->kcs
.io_base
, iik
->kcs
.io_length
);
103 isa_register_ioport(isadev
, &iik
->kcs
.io
, iik
->kcs
.io_base
);
106 static bool vmstate_kcs_before_version2(void *opaque
, int version
)
111 static const VMStateDescription vmstate_ISAIPMIKCSDevice
= {
112 .name
= TYPE_IPMI_INTERFACE
,
114 .minimum_version_id
= 1,
115 .fields
= (VMStateField
[]) {
116 VMSTATE_VSTRUCT_TEST(kcs
, ISAIPMIKCSDevice
, vmstate_kcs_before_version2
,
117 0, vmstate_IPMIKCS
, IPMIKCS
, 1),
118 VMSTATE_VSTRUCT_V(kcs
, ISAIPMIKCSDevice
, 2, vmstate_IPMIKCS
,
120 VMSTATE_END_OF_LIST()
124 static void isa_ipmi_kcs_init(Object
*obj
)
126 ISAIPMIKCSDevice
*iik
= ISA_IPMI_KCS(obj
);
128 ipmi_bmc_find_and_link(obj
, (Object
**) &iik
->kcs
.bmc
);
131 * Version 1 had an incorrect name, it clashed with the BT
132 * IPMI device, so receive it, but transmit a different
135 vmstate_register(NULL
, 0, &vmstate_ISAIPMIKCSDevice
, iik
);
138 static void *isa_ipmi_kcs_get_backend_data(IPMIInterface
*ii
)
140 ISAIPMIKCSDevice
*iik
= ISA_IPMI_KCS(ii
);
145 static Property ipmi_isa_properties
[] = {
146 DEFINE_PROP_UINT32("ioport", ISAIPMIKCSDevice
, kcs
.io_base
, 0xca2),
147 DEFINE_PROP_INT32("irq", ISAIPMIKCSDevice
, isairq
, 5),
148 DEFINE_PROP_END_OF_LIST(),
151 static void isa_ipmi_kcs_class_init(ObjectClass
*oc
, void *data
)
153 DeviceClass
*dc
= DEVICE_CLASS(oc
);
154 IPMIInterfaceClass
*iic
= IPMI_INTERFACE_CLASS(oc
);
155 AcpiDevAmlIfClass
*adevc
= ACPI_DEV_AML_IF_CLASS(oc
);
157 dc
->realize
= ipmi_isa_realize
;
158 device_class_set_props(dc
, ipmi_isa_properties
);
160 iic
->get_backend_data
= isa_ipmi_kcs_get_backend_data
;
161 ipmi_kcs_class_init(iic
);
162 iic
->get_fwinfo
= isa_ipmi_kcs_get_fwinfo
;
163 adevc
->build_dev_aml
= build_ipmi_dev_aml
;
166 static const TypeInfo isa_ipmi_kcs_info
= {
167 .name
= TYPE_ISA_IPMI_KCS
,
168 .parent
= TYPE_ISA_DEVICE
,
169 .instance_size
= sizeof(ISAIPMIKCSDevice
),
170 .instance_init
= isa_ipmi_kcs_init
,
171 .class_init
= isa_ipmi_kcs_class_init
,
172 .interfaces
= (InterfaceInfo
[]) {
173 { TYPE_IPMI_INTERFACE
},
174 { TYPE_ACPI_DEV_AML_IF
},
179 static void ipmi_register_types(void)
181 type_register_static(&isa_ipmi_kcs_info
);
184 type_init(ipmi_register_types
)