Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / hw / ipmi / isa_ipmi_bt.c
blob7b36d5149450def4763a33f7aa40a06c2718d0d1
1 /*
2 * QEMU ISA IPMI BT emulation
4 * Copyright (c) 2015 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
22 * THE SOFTWARE.
25 #include "qemu/osdep.h"
26 #include "qemu/module.h"
27 #include "qapi/error.h"
28 #include "hw/irq.h"
29 #include "hw/ipmi/ipmi_bt.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_BT "isa-ipmi-bt"
37 OBJECT_DECLARE_SIMPLE_TYPE(ISAIPMIBTDevice, ISA_IPMI_BT)
39 struct ISAIPMIBTDevice {
40 ISADevice dev;
41 int32_t isairq;
42 qemu_irq irq;
43 IPMIBT bt;
44 uint32_t uuid;
47 static void isa_ipmi_bt_get_fwinfo(struct IPMIInterface *ii, IPMIFwInfo *info)
49 ISAIPMIBTDevice *iib = ISA_IPMI_BT(ii);
51 ipmi_bt_get_fwinfo(&iib->bt, info);
52 info->interrupt_number = iib->isairq;
53 info->i2c_slave_address = iib->bt.bmc->slave_addr;
54 info->uuid = iib->uuid;
57 static void isa_ipmi_bt_raise_irq(IPMIBT *ib)
59 ISAIPMIBTDevice *iib = ib->opaque;
61 qemu_irq_raise(iib->irq);
64 static void isa_ipmi_bt_lower_irq(IPMIBT *ib)
66 ISAIPMIBTDevice *iib = ib->opaque;
68 qemu_irq_lower(iib->irq);
71 static const VMStateDescription vmstate_ISAIPMIBTDevice = {
72 .name = TYPE_IPMI_INTERFACE_PREFIX "isa-bt",
73 .version_id = 2,
74 .minimum_version_id = 2,
76 * Version 1 had messed up the array transfer, it's not even usable
77 * because it used VMSTATE_VBUFFER_UINT32, but it did not transfer
78 * the buffer length, so random things would happen.
80 .fields = (const VMStateField[]) {
81 VMSTATE_STRUCT(bt, ISAIPMIBTDevice, 1, vmstate_IPMIBT, IPMIBT),
82 VMSTATE_END_OF_LIST()
86 static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
88 Error *err = NULL;
89 ISADevice *isadev = ISA_DEVICE(dev);
90 ISAIPMIBTDevice *iib = ISA_IPMI_BT(dev);
91 IPMIInterface *ii = IPMI_INTERFACE(dev);
92 IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
94 if (!iib->bt.bmc) {
95 error_setg(errp, "IPMI device requires a bmc attribute to be set");
96 return;
99 iib->uuid = ipmi_next_uuid();
101 iib->bt.bmc->intf = ii;
102 iib->bt.opaque = iib;
104 iic->init(ii, 0, &err);
105 if (err) {
106 error_propagate(errp, err);
107 return;
110 if (iib->isairq > 0) {
111 iib->irq = isa_get_irq(isadev, iib->isairq);
112 iib->bt.use_irq = 1;
113 iib->bt.raise_irq = isa_ipmi_bt_raise_irq;
114 iib->bt.lower_irq = isa_ipmi_bt_lower_irq;
117 qdev_set_legacy_instance_id(dev, iib->bt.io_base, iib->bt.io_length);
119 isa_register_ioport(isadev, &iib->bt.io, iib->bt.io_base);
121 vmstate_register(NULL, 0, &vmstate_ISAIPMIBTDevice, dev);
124 static void isa_ipmi_bt_init(Object *obj)
126 ISAIPMIBTDevice *iib = ISA_IPMI_BT(obj);
128 ipmi_bmc_find_and_link(obj, (Object **) &iib->bt.bmc);
131 static void *isa_ipmi_bt_get_backend_data(IPMIInterface *ii)
133 ISAIPMIBTDevice *iib = ISA_IPMI_BT(ii);
135 return &iib->bt;
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(),
144 static void isa_ipmi_bt_class_init(ObjectClass *oc, void *data)
146 DeviceClass *dc = DEVICE_CLASS(oc);
147 IPMIInterfaceClass *iic = IPMI_INTERFACE_CLASS(oc);
148 AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(oc);
150 dc->realize = isa_ipmi_bt_realize;
151 device_class_set_props(dc, ipmi_isa_properties);
153 iic->get_backend_data = isa_ipmi_bt_get_backend_data;
154 ipmi_bt_class_init(iic);
155 iic->get_fwinfo = isa_ipmi_bt_get_fwinfo;
156 adevc->build_dev_aml = build_ipmi_dev_aml;
159 static const TypeInfo isa_ipmi_bt_info = {
160 .name = TYPE_ISA_IPMI_BT,
161 .parent = TYPE_ISA_DEVICE,
162 .instance_size = sizeof(ISAIPMIBTDevice),
163 .instance_init = isa_ipmi_bt_init,
164 .class_init = isa_ipmi_bt_class_init,
165 .interfaces = (InterfaceInfo[]) {
166 { TYPE_IPMI_INTERFACE },
167 { TYPE_ACPI_DEV_AML_IF },
172 static void ipmi_register_types(void)
174 type_register_static(&isa_ipmi_bt_info);
177 type_init(ipmi_register_types)