2015-12-17 19:50:08 +01:00
|
|
|
/*
|
|
|
|
* QEMU ISA IPMI BT emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Corey Minyard, MontaVista Software, LLC
|
|
|
|
*
|
|
|
|
* 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 16:35:07 +02:00
|
|
|
|
2016-01-26 19:17:30 +01:00
|
|
|
#include "qemu/osdep.h"
|
2019-05-23 16:35:07 +02: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 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2017-12-06 19:26:12 +01:00
|
|
|
#include "hw/ipmi/ipmi_bt.h"
|
2015-12-17 19:50:08 +01:00
|
|
|
#include "hw/isa/isa.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2022-06-08 15:53:21 +02:00
|
|
|
#include "hw/acpi/ipmi.h"
|
2015-12-17 19:50:08 +01:00
|
|
|
|
|
|
|
#define TYPE_ISA_IPMI_BT "isa-ipmi-bt"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(ISAIPMIBTDevice, ISA_IPMI_BT)
|
2015-12-17 19:50:08 +01:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct ISAIPMIBTDevice {
|
2015-12-17 19:50:08 +01:00
|
|
|
ISADevice dev;
|
2016-01-22 16:09:21 +01:00
|
|
|
int32_t isairq;
|
2017-12-06 19:26:12 +01:00
|
|
|
qemu_irq irq;
|
2015-12-17 19:50:08 +01:00
|
|
|
IPMIBT bt;
|
2016-05-24 19:37:17 +02:00
|
|
|
uint32_t uuid;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2015-12-17 19:50:08 +01:00
|
|
|
|
2017-12-06 19:26:12 +01:00
|
|
|
static void isa_ipmi_bt_get_fwinfo(struct IPMIInterface *ii, IPMIFwInfo *info)
|
2016-05-24 19:37:17 +02:00
|
|
|
{
|
|
|
|
ISAIPMIBTDevice *iib = ISA_IPMI_BT(ii);
|
|
|
|
|
2017-12-06 19:26:12 +01:00
|
|
|
ipmi_bt_get_fwinfo(&iib->bt, info);
|
2016-05-24 19:37:17 +02:00
|
|
|
info->interrupt_number = iib->isairq;
|
|
|
|
info->i2c_slave_address = iib->bt.bmc->slave_addr;
|
|
|
|
info->uuid = iib->uuid;
|
|
|
|
}
|
|
|
|
|
2017-12-06 19:26:12 +01:00
|
|
|
static void isa_ipmi_bt_raise_irq(IPMIBT *ib)
|
2016-05-24 19:37:17 +02:00
|
|
|
{
|
2017-12-06 19:26:12 +01:00
|
|
|
ISAIPMIBTDevice *iib = ib->opaque;
|
|
|
|
|
|
|
|
qemu_irq_raise(iib->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void isa_ipmi_bt_lower_irq(IPMIBT *ib)
|
|
|
|
{
|
|
|
|
ISAIPMIBTDevice *iib = ib->opaque;
|
|
|
|
|
|
|
|
qemu_irq_lower(iib->irq);
|
2016-05-24 19:37:17 +02:00
|
|
|
}
|
|
|
|
|
2015-12-17 19:50:08 +01:00
|
|
|
static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2019-12-04 10:36:15 +01:00
|
|
|
Error *err = NULL;
|
2015-12-17 19:50:08 +01:00
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
|
|
|
ISAIPMIBTDevice *iib = ISA_IPMI_BT(dev);
|
|
|
|
IPMIInterface *ii = IPMI_INTERFACE(dev);
|
|
|
|
IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
|
|
|
|
|
|
|
|
if (!iib->bt.bmc) {
|
|
|
|
error_setg(errp, "IPMI device requires a bmc attribute to be set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-24 19:37:17 +02:00
|
|
|
iib->uuid = ipmi_next_uuid();
|
|
|
|
|
2015-12-17 19:50:08 +01:00
|
|
|
iib->bt.bmc->intf = ii;
|
2017-12-06 19:26:12 +01:00
|
|
|
iib->bt.opaque = iib;
|
2015-12-17 19:50:08 +01:00
|
|
|
|
2019-12-04 10:36:15 +01:00
|
|
|
iic->init(ii, 0, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2015-12-17 19:50:08 +01:00
|
|
|
return;
|
2019-12-04 10:36:15 +01:00
|
|
|
}
|
2015-12-17 19:50:08 +01:00
|
|
|
|
|
|
|
if (iib->isairq > 0) {
|
2022-03-01 23:00:37 +01:00
|
|
|
iib->irq = isa_get_irq(isadev, iib->isairq);
|
2015-12-17 19:50:08 +01:00
|
|
|
iib->bt.use_irq = 1;
|
2017-12-06 19:26:12 +01:00
|
|
|
iib->bt.raise_irq = isa_ipmi_bt_raise_irq;
|
|
|
|
iib->bt.lower_irq = isa_ipmi_bt_lower_irq;
|
2015-12-17 19:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qdev_set_legacy_instance_id(dev, iib->bt.io_base, iib->bt.io_length);
|
|
|
|
|
|
|
|
isa_register_ioport(isadev, &iib->bt.io, iib->bt.io_base);
|
|
|
|
}
|
|
|
|
|
2018-08-20 22:57:24 +02:00
|
|
|
static const VMStateDescription vmstate_ISAIPMIBTDevice = {
|
|
|
|
.name = TYPE_IPMI_INTERFACE_PREFIX "isa-bt",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
/*
|
|
|
|
* Version 1 had messed up the array transfer, it's not even usable
|
|
|
|
* because it used VMSTATE_VBUFFER_UINT32, but it did not transfer
|
|
|
|
* the buffer length, so random things would happen.
|
|
|
|
*/
|
2015-12-17 19:50:11 +01:00
|
|
|
.fields = (VMStateField[]) {
|
2018-08-20 22:57:24 +02:00
|
|
|
VMSTATE_STRUCT(bt, ISAIPMIBTDevice, 1, vmstate_IPMIBT, IPMIBT),
|
2015-12-17 19:50:11 +01:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-17 19:50:08 +01:00
|
|
|
static void isa_ipmi_bt_init(Object *obj)
|
|
|
|
{
|
|
|
|
ISAIPMIBTDevice *iib = ISA_IPMI_BT(obj);
|
|
|
|
|
|
|
|
ipmi_bmc_find_and_link(obj, (Object **) &iib->bt.bmc);
|
2015-12-17 19:50:11 +01:00
|
|
|
|
|
|
|
vmstate_register(NULL, 0, &vmstate_ISAIPMIBTDevice, iib);
|
2015-12-17 19:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *isa_ipmi_bt_get_backend_data(IPMIInterface *ii)
|
|
|
|
{
|
|
|
|
ISAIPMIBTDevice *iib = ISA_IPMI_BT(ii);
|
|
|
|
|
|
|
|
return &iib->bt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property ipmi_isa_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("ioport", ISAIPMIBTDevice, bt.io_base, 0xe4),
|
|
|
|
DEFINE_PROP_INT32("irq", ISAIPMIBTDevice, isairq, 5),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void isa_ipmi_bt_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
IPMIInterfaceClass *iic = IPMI_INTERFACE_CLASS(oc);
|
2022-06-08 15:53:21 +02:00
|
|
|
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(oc);
|
2015-12-17 19:50:08 +01:00
|
|
|
|
|
|
|
dc->realize = isa_ipmi_bt_realize;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, ipmi_isa_properties);
|
2015-12-17 19:50:08 +01:00
|
|
|
|
|
|
|
iic->get_backend_data = isa_ipmi_bt_get_backend_data;
|
|
|
|
ipmi_bt_class_init(iic);
|
2017-12-06 19:26:12 +01:00
|
|
|
iic->get_fwinfo = isa_ipmi_bt_get_fwinfo;
|
2022-06-08 15:53:21 +02:00
|
|
|
adevc->build_dev_aml = build_ipmi_dev_aml;
|
2015-12-17 19:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo isa_ipmi_bt_info = {
|
|
|
|
.name = TYPE_ISA_IPMI_BT,
|
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(ISAIPMIBTDevice),
|
|
|
|
.instance_init = isa_ipmi_bt_init,
|
|
|
|
.class_init = isa_ipmi_bt_class_init,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_IPMI_INTERFACE },
|
2022-06-08 15:53:21 +02:00
|
|
|
{ TYPE_ACPI_DEV_AML_IF },
|
2015-12-17 19:50:08 +01:00
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ipmi_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&isa_ipmi_bt_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(ipmi_register_types)
|