From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SvqIV-0002OG-68 for qemu-devel@nongnu.org; Mon, 30 Jul 2012 09:46:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SvqIK-0001ZQ-4A for qemu-devel@nongnu.org; Mon, 30 Jul 2012 09:46:11 -0400 Received: from cantor2.suse.de ([195.135.220.15]:46608 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SvqIJ-0001ZB-N1 for qemu-devel@nongnu.org; Mon, 30 Jul 2012 09:46:00 -0400 Message-ID: <5016900F.2000504@suse.de> Date: Mon, 30 Jul 2012 15:45:51 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1342724013-1633-1-git-send-email-minyard@acm.org> <1342724013-1633-13-git-send-email-minyard@acm.org> In-Reply-To: <1342724013-1633-13-git-send-email-minyard@acm.org> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 12/18] IPMI: Add a PC ISA type structure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: minyard@acm.org Cc: Corey Minyard , qemu-devel@nongnu.org, Paolo Bonzini Am 19.07.2012 20:53, schrieb minyard@acm.org: > From: Corey Minyard >=20 > This provides the base infrastructure to tie IPMI low-level > interfaces into a PC ISA bus. >=20 > Signed-off-by: Corey Minyard > --- > default-configs/i386-softmmu.mak | 1 + > default-configs/x86_64-softmmu.mak | 1 + > hw/Makefile.objs | 1 + > hw/isa_ipmi.c | 181 ++++++++++++++++++++++++++++= ++++++++ > hw/smbios.h | 12 +++ > 5 files changed, 196 insertions(+), 0 deletions(-) > create mode 100644 hw/isa_ipmi.c >=20 > diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-so= ftmmu.mak > index eb17afc..c0aff0d 100644 > --- a/default-configs/i386-softmmu.mak > +++ b/default-configs/i386-softmmu.mak > @@ -8,6 +8,7 @@ CONFIG_VGA_CIRRUS=3Dy > CONFIG_VMWARE_VGA=3Dy > CONFIG_VMMOUSE=3Dy > CONFIG_IPMI=3Dy > +CONFIG_ISA_IPMI=3Dy > CONFIG_SERIAL=3Dy > CONFIG_PARALLEL=3Dy > CONFIG_I8254=3Dy > diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_6= 4-softmmu.mak > index e4e3e4f..615e4f2 100644 > --- a/default-configs/x86_64-softmmu.mak > +++ b/default-configs/x86_64-softmmu.mak > @@ -8,6 +8,7 @@ CONFIG_VGA_CIRRUS=3Dy > CONFIG_VMWARE_VGA=3Dy > CONFIG_VMMOUSE=3Dy > CONFIG_IPMI=3Dy > +CONFIG_ISA_IPMI=3Dy > CONFIG_SERIAL=3Dy > CONFIG_PARALLEL=3Dy > CONFIG_I8254=3Dy > diff --git a/hw/Makefile.objs b/hw/Makefile.objs > index 256cfae..928870b 100644 > --- a/hw/Makefile.objs > +++ b/hw/Makefile.objs > @@ -21,6 +21,7 @@ hw-obj-$(CONFIG_ESCC) +=3D escc.o > hw-obj-$(CONFIG_EMPTY_SLOT) +=3D empty_slot.o > =20 > hw-obj-$(CONFIG_IPMI) +=3D ipmi.o > +hw-obj-$(CONFIG_ISA_IPMI) +=3D isa_ipmi.o > =20 > hw-obj-$(CONFIG_SERIAL) +=3D serial.o > hw-obj-$(CONFIG_PARALLEL) +=3D parallel.o > diff --git a/hw/isa_ipmi.c b/hw/isa_ipmi.c > new file mode 100644 > index 0000000..c15ca22 > --- /dev/null > +++ b/hw/isa_ipmi.c > @@ -0,0 +1,181 @@ > +/* > + * QEMU ISA IPMI KCS emulation > + * > + * Copyright (c) 2012 Corey Minyard, MontaVista Software, LLC > + * > + * Permission is hereby granted, free of charge, to any person obtaini= ng a copy > + * of this software and associated documentation files (the "Software"= ), to deal > + * in the Software without restriction, including without limitation t= he rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/o= r 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 incl= uded in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXP= RESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABI= LITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT S= HALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES O= R OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARI= SING FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALI= NGS IN > + * THE SOFTWARE. > + */ > +#include "hw.h" > +#include "isa.h" > +#include "pc.h" > +#include "qemu-timer.h" > +#include "qemu-char.h" > +#include "sysemu.h" > +#include "smbios.h" > +#include "ipmi.h" > + > + > +typedef struct ISAIPMIDevice { > + ISADevice dev; > + char *interface; > + uint32_t iobase; > + uint32_t isairq; > + uint8_t slave_addr; > + CharDriverState *chr; > + IPMIInterface *intf; > +} ISAIPMIDevice; > + > +static int ipmi_isa_initfn(ISADevice *dev) > +{ > + ISAIPMIDevice *isa =3D DO_UPCAST(ISAIPMIDevice, dev, dev); > + struct smbios_type_38 smb38; > + char typename[20]; > + Object *intfobj; > + IPMIInterface *intf; > + IPMIInterfaceClass *intfk; > + Object *bmcobj; > + IPMIBmc *bmc; > + int rc; > + Error *errp =3D NULL; > + > + if (!isa->interface) { > + isa->interface =3D g_strdup("kcs"); > + } > + > + if (isa->chr) { > + bmcobj =3D object_new("ipmi-bmc-extern"); > + } else { > + bmcobj =3D object_new("ipmi-bmc-sim"); > + } Please use TYPE_ constants instead of hardcoding strings. > + bmc =3D DO_UPCAST(IPMIBmc, parent_obj, bmcobj); Please use QOM cast macros rather than qdev's DO_UPCAST(). > + bmc->chr =3D isa->chr; > + snprintf(typename, sizeof(typename), "ipmi-interface-%s", isa->int= erface); > + intfobj =3D object_new(typename); > + intf =3D DO_UPCAST(IPMIInterface, parent_obj, intfobj); > + bmc->intf =3D intf; > + intf->bmc =3D bmc; > + intf->io_base =3D isa->iobase; > + intf->slave_addr =3D isa->slave_addr; > + rc =3D ipmi_interface_init(intf); > + if (rc) { > + return rc; > + } > + rc =3D ipmi_bmc_init(bmc); > + if (rc) { > + return rc; > + } > + > + /* These may be set by the interface. */ > + isa->iobase =3D intf->io_base; > + isa->slave_addr =3D intf->slave_addr; > + > + if (isa->isairq !=3D 0) { > + isa_init_irq(dev, &intf->irq, isa->isairq); > + intf->use_irq =3D 1; > + } > + > + isa->intf =3D intf; > + object_property_add_child(OBJECT(isa), "intf", OBJECT(intf), &errp= ); > + if (error_is_set(&errp)) { > + fprintf(stderr, "%s\n", error_get_pretty(errp)); > + return 1; > + } > + object_property_add_child(OBJECT(isa), "bmc", OBJECT(bmc), &errp); > + if (error_is_set(&errp)) { > + fprintf(stderr, "%s\n", error_get_pretty(errp)); > + return 1; > + } > + > + qdev_set_legacy_instance_id(&dev->qdev, intf->io_base, intf->io_le= ngth); > + > + isa_register_ioport(dev, &intf->io, intf->io_base); > + > + intfk =3D IPMI_INTERFACE_GET_CLASS(intf); > + > + smb38.header.type =3D 38; > + smb38.header.length =3D sizeof(smb38); > + smb38.header.handle =3D 0x3000; > + smb38.interface_type =3D intfk->smbios_type; > + smb38.ipmi_version =3D 0x20; > + smb38.i2c_slave_addr =3D intf->slave_addr; > + smb38.nv_storage_dev_addr =3D 0; > + > + /* or 1 to set it to I/O space */ > + smb38.base_addr =3D intf->io_base | 1; > + > + /* 1-byte boundaries, addr bit0=3D0, level triggered irq */ > + smb38.base_addr_mod_and_irq_info =3D 1; > + smb38.interrupt_number =3D isa->isairq; > + smbios_table_entry_add((struct smbios_structure_header *) &smb38); > + > + return 0; > +} > + > +static void ipmi_isa_reset(DeviceState *qdev) > +{ > + ISAIPMIDevice *isa =3D DO_UPCAST(ISAIPMIDevice, dev.qdev, qdev); > + > + ipmi_interface_reset(isa->intf); > +} > + > +static Property ipmi_isa_properties[] =3D { > + DEFINE_PROP_STRING("interface", ISAIPMIDevice, interface), > + DEFINE_PROP_HEX32("iobase", ISAIPMIDevice, iobase, 0), > + DEFINE_PROP_UINT32("irq", ISAIPMIDevice, isairq, 5), > + DEFINE_PROP_UINT8("slave_addr", ISAIPMIDevice, slave_addr, 0), > + DEFINE_PROP_CHR("chardev", ISAIPMIDevice, chr), > + DEFINE_PROP_END_OF_LIST(), > +}; > + > +#if 0 /* FIXME */ Fix this? x86 machines should definitely remain migratable. > +static const VMStateDescription vmstate_isa_ipmi =3D { > + .name =3D "isa-ipmi", > + .version_id =3D 3, > + .minimum_version_id =3D 3, > + .fields =3D (VMStateField[]) { > + /* FIXME - fill this in */ > + VMSTATE_END_OF_LIST() > + } > +}; > +#endif > + > +static void ipmi_isa_class_initfn(ObjectClass *klass, void *data) > +{ > + DeviceClass *dc =3D DEVICE_CLASS(klass); > + ISADeviceClass *ic =3D ISA_DEVICE_CLASS(klass); > + ic->init =3D ipmi_isa_initfn; > + dc->reset =3D ipmi_isa_reset; > + /* dc->vmsd =3D &vmstate_isa_ipmi; FIXME */ > + dc->props =3D ipmi_isa_properties; > +} > + > +static TypeInfo ipmi_isa_info =3D { static const please. > + .name =3D "isa-ipmi", Where is this used? Should probably be TYPE_..., too. Andreas > + .parent =3D TYPE_ISA_DEVICE, > + .instance_size =3D sizeof(ISAIPMIDevice), > + .class_init =3D ipmi_isa_class_initfn, > +}; > + > +static void ipmi_register_types(void) > +{ > + type_register_static(&ipmi_isa_info); > + qdev_add_prefw_init("isa-ipmi"); > +} > + > +type_init(ipmi_register_types) > diff --git a/hw/smbios.h b/hw/smbios.h > index 6431a15..b9e4a61 100644 > --- a/hw/smbios.h > +++ b/hw/smbios.h > @@ -155,6 +155,18 @@ struct smbios_type_32 { > uint8_t boot_status; > } QEMU_PACKED; > =20 > +/* SMBIOS type 38 - IPMI Device Information */ > +struct smbios_type_38 { > + struct smbios_structure_header header; > + uint8_t interface_type; > + uint8_t ipmi_version; > + uint8_t i2c_slave_addr; > + uint8_t nv_storage_dev_addr; > + uint64_t base_addr; > + uint8_t base_addr_mod_and_irq_info; > + uint8_t interrupt_number; > +} QEMU_PACKED; > + > /* SMBIOS type 127 -- End-of-table */ > struct smbios_type_127 { > struct smbios_structure_header header; >=20 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg