From: Paolo Bonzini <pbonzini@redhat.com>
To: minyard@acm.org
Cc: Corey Minyard <cminyard@mvista.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/9] IPMI: Add a PC ISA type structure
Date: Tue, 10 Jul 2012 11:17:01 +0200 [thread overview]
Message-ID: <4FFBF30D.8070703@redhat.com> (raw)
In-Reply-To: <1341861429-6297-6-git-send-email-minyard@acm.org>
Il 09/07/2012 21:17, minyard@acm.org ha scritto:
> From: Corey Minyard <cminyard@mvista.com>
>
> This provides the base infrastructure to tie IPMI low-level
> interfaces into a PC ISA bus.
>
> Signed-off-by: Corey Minyard <cminyard@mvista.com>
> ---
> default-configs/i386-softmmu.mak | 1 +
> default-configs/x86_64-softmmu.mak | 1 +
> hw/Makefile.objs | 1 +
> hw/isa_ipmi.c | 138 ++++++++++++++++++++++++++++++++++++
> hw/pc.c | 12 +++
> hw/pc.h | 18 +++++
> hw/smbios.h | 12 +++
> 7 files changed, 183 insertions(+), 0 deletions(-)
> create mode 100644 hw/isa_ipmi.c
>
> diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
> index eb17afc..c0aff0d 100644
> --- a/default-configs/i386-softmmu.mak
> +++ b/default-configs/i386-softmmu.mak
> @@ -8,6 +8,7 @@ CONFIG_VGA_CIRRUS=y
> CONFIG_VMWARE_VGA=y
> CONFIG_VMMOUSE=y
> CONFIG_IPMI=y
> +CONFIG_ISA_IPMI=y
> CONFIG_SERIAL=y
> CONFIG_PARALLEL=y
> CONFIG_I8254=y
> diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-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=y
> CONFIG_VMWARE_VGA=y
> CONFIG_VMMOUSE=y
> CONFIG_IPMI=y
> +CONFIG_ISA_IPMI=y
> CONFIG_SERIAL=y
> CONFIG_PARALLEL=y
> CONFIG_I8254=y
> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> index 0d55997..8f27ffe 100644
> --- a/hw/Makefile.objs
> +++ b/hw/Makefile.objs
> @@ -21,6 +21,7 @@ hw-obj-$(CONFIG_ESCC) += escc.o
> hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
>
> hw-obj-$(CONFIG_IPMI) += ipmi.o
> +hw-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o
>
> hw-obj-$(CONFIG_SERIAL) += serial.o
> hw-obj-$(CONFIG_PARALLEL) += parallel.o
> diff --git a/hw/isa_ipmi.c b/hw/isa_ipmi.c
> new file mode 100644
> index 0000000..cad78b0
> --- /dev/null
> +++ b/hw/isa_ipmi.c
> @@ -0,0 +1,138 @@
> +/*
> + * QEMU ISA IPMI KCS emulation
> + *
> + * Copyright (c) 2012 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.
> + */
> +#include "hw.h"
> +#include "isa.h"
> +#include "pc.h"
> +#include "qemu-timer.h"
> +#include "sysemu.h"
> +#include "smbios.h"
> +#include "ipmi.h"
> +
> +
> +typedef struct ISAIPMIState {
> + ISADevice dev;
> + uint32_t type;
> + uint32_t iobase;
> + uint32_t isairq;
> + uint8_t slave_addr;
> + IPMIState state;
> +} ISAIPMIState;
I would prefer to have a TYPE_IPMI_INTERFACE class for IPMIState. Then
you can subclass that class in patches 6/7/8, and include a pointer in
ISAIPMIState.
Paolo
> +static int ipmi_isa_initfn(ISADevice *dev)
> +{
> + ISAIPMIState *isa = DO_UPCAST(ISAIPMIState, dev, dev);
> + struct smbios_type_38 smb38;
> +
> + if (isa->iobase == -1) {
> + /* If no I/O base is specified, set the defaults */
> + switch (isa->type) {
> + case IPMI_KCS:
> + isa->iobase = 0xca2;
> + break;
> + case IPMI_BT:
> + isa->iobase = 0xe4;
> + break;
> + case IPMI_SMIC:
> + isa->iobase = 0xca9;
> + break;
> + default:
> + fprintf(stderr, "Unknown IPMI type: %d\n", isa->type);
> + abort();
> + }
> + }
> +
> + isa->state.slave_addr = isa->slave_addr;
> +
> + qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3);
> +
> + ipmi_init(isa->type, &isa->state);
> +
> + if (isa->isairq > 0) {
> + isa_init_irq(dev, &isa->state.irq, isa->isairq);
> + isa->state.use_irq = 1;
> + }
> +
> + isa_register_ioport(dev, &isa->state.io, isa->iobase);
> +
> + smb38.header.type = 38;
> + smb38.header.length = sizeof(smb38);
> + smb38.header.handle = 0x3000;
> + smb38.interface_type = isa->state.smbios_type;
> + smb38.ipmi_version = 0x20;
> + smb38.i2c_slave_addr = isa->state.slave_addr;
> + smb38.nv_storage_dev_addr = 0;
> +
> + /* or 1 to set it to I/O space */
> + smb38.base_addr = isa->iobase | 1;
> +
> + /* 1-byte boundaries, addr bit0=0, level triggered irq */
> + smb38.base_addr_mod_and_irq_info = 1;
> + smb38.interrupt_number = isa->isairq;
> + smbios_table_entry_add((struct smbios_structure_header *) &smb38);
> +
> + return 0;
> +}
> +
> +static Property ipmi_isa_properties[] = {
> + DEFINE_PROP_HEX32("type", ISAIPMIState, type, IPMI_KCS),
> + DEFINE_PROP_HEX32("iobase", ISAIPMIState, iobase, -1),
> + DEFINE_PROP_UINT32("irq", ISAIPMIState, isairq, 0),
> + DEFINE_PROP_UINT8("slave_addr", ISAIPMIState, slave_addr, 0),
> + DEFINE_PROP_PTR("charopts", ISAIPMIState, state.chropts),
> + DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static const VMStateDescription vmstate_isa_ipmi = {
> + .name = "isa-ipmi",
> + .version_id = 3,
> + .minimum_version_id = 3,
> + .fields = (VMStateField []) {
> + VMSTATE_STRUCT(state, ISAIPMIState, 0, vmstate_isa_ipmi,
> + IPMIState),
> + VMSTATE_END_OF_LIST()
> + }
> +};
> +
> +static void ipmi_isa_class_initfn(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
> + ic->init = ipmi_isa_initfn;
> + dc->vmsd = &vmstate_isa_ipmi;
> + dc->props = ipmi_isa_properties;
> +}
> +
> +static TypeInfo ipmi_isa_info = {
> + .name = "isa-ipmi",
> + .parent = TYPE_ISA_DEVICE,
> + .instance_size = sizeof(ISAIPMIState),
> + .class_init = ipmi_isa_class_initfn,
> +};
> +
> +static void ipmi_register_types(void)
> +{
> + type_register_static(&ipmi_isa_info);
> +}
> +
> +type_init(ipmi_register_types)
> diff --git a/hw/pc.c b/hw/pc.c
> index c0acb6a..965e053 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -1173,6 +1173,18 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
> fd[i] = drive_get(IF_FLOPPY, 0, i);
> }
> *floppy = fdctrl_init_isa(isa_bus, fd);
> +
> + i = 0;
> + if (do_local_ipmi) {
> + ipmi_isa_init(isa_bus, isa_find_free_irq(isa_bus), ipmi_types[i], NULL);
> + i++;
> + }
> + for(; i < MAX_IPMI_DEVICES; i++) {
> + if (ipmi_hds[i]) {
> + ipmi_isa_init(isa_bus, isa_find_free_irq(isa_bus),
> + ipmi_types[i], ipmi_hds[i]);
> + }
> + }
> }
>
> void pc_pci_device_init(PCIBus *pci_bus)
> diff --git a/hw/pc.h b/hw/pc.h
> index 33ab689..5b6d947 100644
> --- a/hw/pc.h
> +++ b/hw/pc.h
> @@ -223,6 +223,24 @@ static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd)
> return true;
> }
>
> +/* IPMI */
> +static inline bool ipmi_isa_init(ISABus *bus, int irq,
> + int type, QemuOpts *opts)
> +{
> + ISADevice *dev;
> +
> + dev = isa_try_create(bus, "isa-ipmi");
> + if (!dev) {
> + return false;
> + }
> + qdev_prop_set_uint32(&dev->qdev, "type", type);
> + qdev_prop_set_uint32(&dev->qdev, "irq", irq);
> + qdev_prop_set_ptr(&dev->qdev, "charopts", opts);
> + if (qdev_init(&dev->qdev) < 0) {
> + return false;
> + }
> + return true;
> +}
> /* pc_sysfw.c */
> void pc_system_firmware_init(MemoryRegion *rom_memory);
>
> 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;
>
> +/* 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;
>
next prev parent reply other threads:[~2012-07-10 9:17 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-09 19:17 [Qemu-devel] First shot at adding IPMI to qemu minyard
2012-07-09 19:17 ` [Qemu-devel] [PATCH 1/9] smbios: Add a function to directly add an entry minyard
2012-07-09 19:17 ` [Qemu-devel] [PATCH 2/9] pc: move SMBIOS setup to after device init minyard
2012-07-09 19:17 ` [Qemu-devel] [PATCH 3/9] isa: Add a way to query for a free interrupt minyard
2012-07-10 9:16 ` Paolo Bonzini
2012-07-09 19:17 ` [Qemu-devel] [PATCH 4/9] Add a base IPMI interface minyard
2012-07-10 9:17 ` Daniel P. Berrange
2012-07-10 11:12 ` Markus Armbruster
2012-07-10 16:19 ` Corey Minyard
2012-07-10 9:29 ` Paolo Bonzini
2012-07-09 19:17 ` [Qemu-devel] [PATCH 5/9] IPMI: Add a PC ISA type structure minyard
2012-07-10 9:17 ` Paolo Bonzini [this message]
2012-07-10 9:33 ` Paolo Bonzini
2012-07-10 20:00 ` Corey Minyard
2012-07-09 19:17 ` [Qemu-devel] [PATCH 6/9] IPMI: Add a KCS low-level interface minyard
2012-07-09 19:17 ` [Qemu-devel] [PATCH 7/9] IPMI: Add a BT " minyard
2012-07-09 19:17 ` [Qemu-devel] [PATCH 8/9] IPMI: Add a local BMC simulation minyard
2012-07-09 19:17 ` [Qemu-devel] [PATCH 9/9] IPMI: Add an external connection simulation interface minyard
2012-07-10 9:35 ` [Qemu-devel] First shot at adding IPMI to qemu Paolo Bonzini
2012-07-10 15:43 ` Corey Minyard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FFBF30D.8070703@redhat.com \
--to=pbonzini@redhat.com \
--cc=cminyard@mvista.com \
--cc=minyard@acm.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).