2015-12-17 21:50:07 +03:00
|
|
|
/*
|
|
|
|
* QEMU ISA IPMI KCS emulation
|
|
|
|
*
|
2017-12-06 16:34:24 +03:00
|
|
|
* Copyright (c) 2015,2017 Corey Minyard, MontaVista Software, LLC
|
2015-12-17 21:50:07 +03:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-05-23 17:35:07 +03:00
|
|
|
|
2016-01-26 21:17:30 +03:00
|
|
|
#include "qemu/osdep.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2017-12-06 16:34:24 +03:00
|
|
|
#include "hw/ipmi/ipmi_kcs.h"
|
2015-12-17 21:50:07 +03:00
|
|
|
#include "hw/isa/isa.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2022-06-08 16:53:21 +03:00
|
|
|
#include "hw/acpi/ipmi.h"
|
2015-12-17 21:50:07 +03:00
|
|
|
|
|
|
|
#define TYPE_ISA_IPMI_KCS "isa-ipmi-kcs"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(ISAIPMIKCSDevice, ISA_IPMI_KCS)
|
2015-12-17 21:50:07 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct ISAIPMIKCSDevice {
|
2015-12-17 21:50:07 +03:00
|
|
|
ISADevice dev;
|
2016-01-22 18:09:21 +03:00
|
|
|
int32_t isairq;
|
2017-12-06 16:34:24 +03:00
|
|
|
qemu_irq irq;
|
2015-12-17 21:50:07 +03:00
|
|
|
IPMIKCS kcs;
|
2016-05-24 20:37:17 +03:00
|
|
|
uint32_t uuid;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2015-12-17 21:50:07 +03:00
|
|
|
|
2017-12-06 16:34:24 +03:00
|
|
|
static void isa_ipmi_kcs_get_fwinfo(IPMIInterface *ii, IPMIFwInfo *info)
|
2016-05-24 20:37:17 +03:00
|
|
|
{
|
|
|
|
ISAIPMIKCSDevice *iik = ISA_IPMI_KCS(ii);
|
|
|
|
|
2017-12-06 16:34:24 +03:00
|
|
|
ipmi_kcs_get_fwinfo(&iik->kcs, info);
|
2016-05-24 20:37:17 +03:00
|
|
|
info->interrupt_number = iik->isairq;
|
|
|
|
info->uuid = iik->uuid;
|
|
|
|
}
|
|
|
|
|
2017-12-06 16:34:24 +03:00
|
|
|
static void isa_ipmi_kcs_raise_irq(IPMIKCS *ik)
|
2016-05-24 20:37:17 +03:00
|
|
|
{
|
2017-12-06 16:34:24 +03:00
|
|
|
ISAIPMIKCSDevice *iik = ik->opaque;
|
|
|
|
|
|
|
|
qemu_irq_raise(iik->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void isa_ipmi_kcs_lower_irq(IPMIKCS *ik)
|
|
|
|
{
|
|
|
|
ISAIPMIKCSDevice *iik = ik->opaque;
|
|
|
|
|
|
|
|
qemu_irq_lower(iik->irq);
|
2016-05-24 20:37:17 +03:00
|
|
|
}
|
|
|
|
|
2023-10-20 17:55:54 +03:00
|
|
|
static bool vmstate_kcs_before_version2(void *opaque, int version)
|
|
|
|
{
|
|
|
|
return version <= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_ISAIPMIKCSDevice = {
|
|
|
|
.name = TYPE_IPMI_INTERFACE,
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_VSTRUCT_TEST(kcs, ISAIPMIKCSDevice, vmstate_kcs_before_version2,
|
|
|
|
0, vmstate_IPMIKCS, IPMIKCS, 1),
|
|
|
|
VMSTATE_VSTRUCT_V(kcs, ISAIPMIKCSDevice, 2, vmstate_IPMIKCS,
|
|
|
|
IPMIKCS, 2),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-17 21:50:07 +03:00
|
|
|
static void ipmi_isa_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2019-12-04 12:36:15 +03:00
|
|
|
Error *err = NULL;
|
2015-12-17 21:50:07 +03:00
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
|
|
|
ISAIPMIKCSDevice *iik = ISA_IPMI_KCS(dev);
|
|
|
|
IPMIInterface *ii = IPMI_INTERFACE(dev);
|
|
|
|
IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
|
|
|
|
|
|
|
|
if (!iik->kcs.bmc) {
|
|
|
|
error_setg(errp, "IPMI device requires a bmc attribute to be set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-24 20:37:17 +03:00
|
|
|
iik->uuid = ipmi_next_uuid();
|
|
|
|
|
2015-12-17 21:50:07 +03:00
|
|
|
iik->kcs.bmc->intf = ii;
|
2017-12-06 16:34:24 +03:00
|
|
|
iik->kcs.opaque = iik;
|
2015-12-17 21:50:07 +03:00
|
|
|
|
2019-12-04 12:36:15 +03:00
|
|
|
iic->init(ii, 0, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2015-12-17 21:50:07 +03:00
|
|
|
return;
|
2019-12-04 12:36:15 +03:00
|
|
|
}
|
2015-12-17 21:50:07 +03:00
|
|
|
|
|
|
|
if (iik->isairq > 0) {
|
2022-03-02 01:00:37 +03:00
|
|
|
iik->irq = isa_get_irq(isadev, iik->isairq);
|
2015-12-17 21:50:07 +03:00
|
|
|
iik->kcs.use_irq = 1;
|
2017-12-06 16:34:24 +03:00
|
|
|
iik->kcs.raise_irq = isa_ipmi_kcs_raise_irq;
|
|
|
|
iik->kcs.lower_irq = isa_ipmi_kcs_lower_irq;
|
2015-12-17 21:50:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
qdev_set_legacy_instance_id(dev, iik->kcs.io_base, iik->kcs.io_length);
|
|
|
|
|
|
|
|
isa_register_ioport(isadev, &iik->kcs.io, iik->kcs.io_base);
|
|
|
|
|
2023-10-20 17:55:54 +03:00
|
|
|
/*
|
|
|
|
* Version 1 had an incorrect name, it clashed with the BT
|
|
|
|
* IPMI device, so receive it, but transmit a different
|
|
|
|
* version.
|
|
|
|
*/
|
|
|
|
vmstate_register(NULL, 0, &vmstate_ISAIPMIKCSDevice, iik);
|
2018-04-25 18:27:31 +03:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:50:07 +03:00
|
|
|
static void isa_ipmi_kcs_init(Object *obj)
|
|
|
|
{
|
|
|
|
ISAIPMIKCSDevice *iik = ISA_IPMI_KCS(obj);
|
|
|
|
|
|
|
|
ipmi_bmc_find_and_link(obj, (Object **) &iik->kcs.bmc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *isa_ipmi_kcs_get_backend_data(IPMIInterface *ii)
|
|
|
|
{
|
|
|
|
ISAIPMIKCSDevice *iik = ISA_IPMI_KCS(ii);
|
|
|
|
|
|
|
|
return &iik->kcs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property ipmi_isa_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("ioport", ISAIPMIKCSDevice, kcs.io_base, 0xca2),
|
|
|
|
DEFINE_PROP_INT32("irq", ISAIPMIKCSDevice, isairq, 5),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void isa_ipmi_kcs_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
IPMIInterfaceClass *iic = IPMI_INTERFACE_CLASS(oc);
|
2022-06-08 16:53:21 +03:00
|
|
|
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(oc);
|
2015-12-17 21:50:07 +03:00
|
|
|
|
|
|
|
dc->realize = ipmi_isa_realize;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, ipmi_isa_properties);
|
2015-12-17 21:50:07 +03:00
|
|
|
|
|
|
|
iic->get_backend_data = isa_ipmi_kcs_get_backend_data;
|
|
|
|
ipmi_kcs_class_init(iic);
|
2017-12-06 16:34:24 +03:00
|
|
|
iic->get_fwinfo = isa_ipmi_kcs_get_fwinfo;
|
2022-06-08 16:53:21 +03:00
|
|
|
adevc->build_dev_aml = build_ipmi_dev_aml;
|
2015-12-17 21:50:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo isa_ipmi_kcs_info = {
|
|
|
|
.name = TYPE_ISA_IPMI_KCS,
|
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(ISAIPMIKCSDevice),
|
|
|
|
.instance_init = isa_ipmi_kcs_init,
|
|
|
|
.class_init = isa_ipmi_kcs_class_init,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_IPMI_INTERFACE },
|
2022-06-08 16:53:21 +03:00
|
|
|
{ TYPE_ACPI_DEV_AML_IF },
|
2015-12-17 21:50:07 +03:00
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ipmi_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&isa_ipmi_kcs_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(ipmi_register_types)
|