2015-12-17 21:50:08 +03: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 17:35:07 +03:00
|
|
|
|
2016-01-26 21:17:30 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-08-20 23:57:24 +03:00
|
|
|
#include "qemu/log.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 21:26:12 +03:00
|
|
|
#include "hw/ipmi/ipmi_bt.h"
|
2015-12-17 21:50:08 +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"
|
2015-12-17 21:50:08 +03:00
|
|
|
|
|
|
|
#define TYPE_ISA_IPMI_BT "isa-ipmi-bt"
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct ISAIPMIBTDevice ISAIPMIBTDevice;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_INSTANCE_CHECKER(ISAIPMIBTDevice, ISA_IPMI_BT,
|
|
|
|
TYPE_ISA_IPMI_BT)
|
2015-12-17 21:50:08 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct ISAIPMIBTDevice {
|
2015-12-17 21:50:08 +03:00
|
|
|
ISADevice dev;
|
2016-01-22 18:09:21 +03:00
|
|
|
int32_t isairq;
|
2017-12-06 21:26:12 +03:00
|
|
|
qemu_irq irq;
|
2015-12-17 21:50:08 +03:00
|
|
|
IPMIBT bt;
|
2016-05-24 20:37:17 +03:00
|
|
|
uint32_t uuid;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2015-12-17 21:50:08 +03:00
|
|
|
|
2017-12-06 21:26:12 +03:00
|
|
|
static void isa_ipmi_bt_get_fwinfo(struct IPMIInterface *ii, IPMIFwInfo *info)
|
2016-05-24 20:37:17 +03:00
|
|
|
{
|
|
|
|
ISAIPMIBTDevice *iib = ISA_IPMI_BT(ii);
|
|
|
|
|
2017-12-06 21:26:12 +03:00
|
|
|
ipmi_bt_get_fwinfo(&iib->bt, info);
|
2016-05-24 20:37:17 +03:00
|
|
|
info->interrupt_number = iib->isairq;
|
|
|
|
info->i2c_slave_address = iib->bt.bmc->slave_addr;
|
|
|
|
info->uuid = iib->uuid;
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:26:12 +03:00
|
|
|
static void isa_ipmi_bt_raise_irq(IPMIBT *ib)
|
2016-05-24 20:37:17 +03:00
|
|
|
{
|
2017-12-06 21:26:12 +03: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 20:37:17 +03:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:50:08 +03:00
|
|
|
static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2019-12-04 12:36:15 +03:00
|
|
|
Error *err = NULL;
|
2015-12-17 21:50:08 +03: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 20:37:17 +03:00
|
|
|
iib->uuid = ipmi_next_uuid();
|
|
|
|
|
2015-12-17 21:50:08 +03:00
|
|
|
iib->bt.bmc->intf = ii;
|
2017-12-06 21:26:12 +03:00
|
|
|
iib->bt.opaque = iib;
|
2015-12-17 21:50:08 +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:08 +03:00
|
|
|
return;
|
2019-12-04 12:36:15 +03:00
|
|
|
}
|
2015-12-17 21:50:08 +03:00
|
|
|
|
|
|
|
if (iib->isairq > 0) {
|
2017-12-06 21:26:12 +03:00
|
|
|
isa_init_irq(isadev, &iib->irq, iib->isairq);
|
2015-12-17 21:50:08 +03:00
|
|
|
iib->bt.use_irq = 1;
|
2017-12-06 21:26:12 +03:00
|
|
|
iib->bt.raise_irq = isa_ipmi_bt_raise_irq;
|
|
|
|
iib->bt.lower_irq = isa_ipmi_bt_lower_irq;
|
2015-12-17 21:50:08 +03: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 23:57:24 +03: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 21:50:11 +03:00
|
|
|
.fields = (VMStateField[]) {
|
2018-08-20 23:57:24 +03:00
|
|
|
VMSTATE_STRUCT(bt, ISAIPMIBTDevice, 1, vmstate_IPMIBT, IPMIBT),
|
2015-12-17 21:50:11 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-17 21:50:08 +03: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 21:50:11 +03:00
|
|
|
|
|
|
|
vmstate_register(NULL, 0, &vmstate_ISAIPMIBTDevice, iib);
|
2015-12-17 21:50:08 +03: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);
|
|
|
|
|
|
|
|
dc->realize = isa_ipmi_bt_realize;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, ipmi_isa_properties);
|
2015-12-17 21:50:08 +03:00
|
|
|
|
|
|
|
iic->get_backend_data = isa_ipmi_bt_get_backend_data;
|
|
|
|
ipmi_bt_class_init(iic);
|
2017-12-06 21:26:12 +03:00
|
|
|
iic->get_fwinfo = isa_ipmi_bt_get_fwinfo;
|
2015-12-17 21:50:08 +03: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 },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ipmi_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&isa_ipmi_bt_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(ipmi_register_types)
|