From patchwork Tue Nov 12 16:33:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 290711 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 126C62C00AD for ; Wed, 13 Nov 2013 03:39:10 +1100 (EST) Received: from localhost ([::1]:43871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgGzc-0003bu-6s for incoming@patchwork.ozlabs.org; Tue, 12 Nov 2013 11:39:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgGu9-0004hv-VZ for qemu-devel@nongnu.org; Tue, 12 Nov 2013 11:33:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgGu2-0007JY-Is for qemu-devel@nongnu.org; Tue, 12 Nov 2013 11:33:29 -0500 Received: from mail-ob0-x22b.google.com ([2607:f8b0:4003:c01::22b]:41244) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgGu2-0007IX-Bp for qemu-devel@nongnu.org; Tue, 12 Nov 2013 11:33:22 -0500 Received: by mail-ob0-f171.google.com with SMTP id gq1so6167575obb.16 for ; Tue, 12 Nov 2013 08:33:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ORA1Bgqiwxbk78dLZ68Mpfc90xc8DY0OvqprwIS80yI=; b=D/AWsWWTGSQLq/lXu3YIrlCT0jcV/kCeVf0XfG8YlYcXVYYmBa/GX9Zc43Cwr+R/bM EGhzurNbkREg277scRtU2C0+0WPD9GPlYbva5BehwVvWAwTClFyLaDy+Z6HMe5LZZZia N+MRoR7Cw09fx2KFZA7PFbYN2cpa/ZSauMlzAB5RQyPnXA23M12aH+I6e6S5PNYGGM5i oi920bxUwBLVBg/uu11aKL5ClooXqmJicUeVM/EGjHUccyF20C9pxOilXc8oKFIcy2Oe XFBel7raNziJEZEYETdOvzSrVv2/lpcCeVTbfUw+w2ZcAnLJKtvaW8OR4CtbzSdefD3u sUbw== X-Received: by 10.182.73.231 with SMTP id o7mr24732806obv.34.1384274001830; Tue, 12 Nov 2013 08:33:21 -0800 (PST) Received: from t430.minyard.home (pool-173-57-152-84.dllstx.fios.verizon.net. [173.57.152.84]) by mx.google.com with ESMTPSA id f2sm37348549oes.3.2013.11.12.08.33.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Nov 2013 08:33:21 -0800 (PST) Received: from t430.minyard.home (t430.minyard.home [127.0.0.1]) by t430.minyard.home (8.14.7/8.14.7) with ESMTP id rACGXJZt016616; Tue, 12 Nov 2013 10:33:19 -0600 Received: (from cminyard@localhost) by t430.minyard.home (8.14.7/8.14.7/Submit) id rACGXJiD016615; Tue, 12 Nov 2013 10:33:19 -0600 From: Corey Minyard To: qemu-devel@nongnu.org Date: Tue, 12 Nov 2013 10:33:05 -0600 Message-Id: <1384273995-16486-7-git-send-email-cminyard@mvista.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1384273995-16486-1-git-send-email-cminyard@mvista.com> References: <1384273995-16486-1-git-send-email-cminyard@mvista.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::22b Cc: Bret Ketchum , Corey Minyard , =?UTF-8?q?Andreas=20F=C3=A4rber?= , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH 06/16] ipmi: Add a PC ISA type structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This provides the base infrastructure to tie IPMI low-level interfaces into a PC ISA bus. Signed-off-by: Corey Minyard --- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/ipmi/Makefile.objs | 1 + hw/ipmi/isa_ipmi.c | 148 +++++++++++++++++++++++++++++++++++++ include/hw/nvram/fw_cfg.h | 11 ++- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 hw/ipmi/isa_ipmi.c diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 89199fb..d5ee6c5 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -11,6 +11,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 154248a..0b700ae 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -11,6 +11,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/ipmi/Makefile.objs b/hw/ipmi/Makefile.objs index 65bde11..3494b70 100644 --- a/hw/ipmi/Makefile.objs +++ b/hw/ipmi/Makefile.objs @@ -1 +1,2 @@ common-obj-$(CONFIG_IPMI) += ipmi.o +common-obj-$(CONFIG_ISA_IPMI) += isa_ipmi.o diff --git a/hw/ipmi/isa_ipmi.c b/hw/ipmi/isa_ipmi.c new file mode 100644 index 0000000..0242a41 --- /dev/null +++ b/hw/ipmi/isa_ipmi.c @@ -0,0 +1,148 @@ +/* + * QEMU ISA IPMI 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/hw.h" +#include "hw/isa/isa.h" +#include "hw/i386/pc.h" +#include "qemu/timer.h" +#include "sysemu/char.h" +#include "sysemu/sysemu.h" +#include "ipmi.h" + +/* This is the type the user specifies on the -device command line */ +#define TYPE_ISA_IPMI "isa-ipmi" +#define ISA_IPMI(obj) OBJECT_CHECK(ISAIPMIDevice, (obj), \ + TYPE_ISA_IPMI) +typedef struct ISAIPMIDevice { + ISADevice dev; + char *interface; + uint32_t iobase; + uint32_t isairq; + uint8_t slave_addr; + CharDriverState *chr; + IPMIInterface *intf; +} ISAIPMIDevice; + +static void ipmi_isa_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *isadev = ISA_DEVICE(dev); + ISAIPMIDevice *isa = ISA_IPMI(dev); + char typename[20]; + Object *intfobj; + IPMIInterface *intf; + Object *bmcobj; + IPMIBmc *bmc; + int rc; + + if (!isa->interface) { + isa->interface = g_strdup("kcs"); + } + + if (isa->chr) { + bmcobj = object_new(TYPE_IPMI_BMC_EXTERN); + } else { + bmcobj = object_new(TYPE_IPMI_BMC_SIMULATOR); + } + bmc = IPMI_BMC(bmcobj); + bmc->chr = isa->chr; + snprintf(typename, sizeof(typename), + TYPE_IPMI_INTERFACE_PREFIX "%s", isa->interface); + intfobj = object_new(typename); + intf = IPMI_INTERFACE(intfobj); + bmc->intf = intf; + intf->bmc = bmc; + intf->io_base = isa->iobase; + intf->slave_addr = isa->slave_addr; + rc = ipmi_interface_init(intf); + if (rc) { + error_setg(errp, "Error initializing IPMI interface: %d\n", rc); + return; + } + rc = ipmi_bmc_init(bmc); + if (rc) { + error_setg(errp, "Error initializing BMC: %d\n", rc); + return; + } + + /* These may be set by the interface. */ + isa->iobase = intf->io_base; + isa->slave_addr = intf->slave_addr; + + if (isa->isairq != 0) { + isa_init_irq(isadev, &intf->irq, isa->isairq); + intf->use_irq = 1; + } + + isa->intf = intf; + object_property_add_child(OBJECT(isadev), "intf", OBJECT(intf), errp); + if (error_is_set(errp)) { + return; + } + object_property_add_child(OBJECT(isadev), "bmc", OBJECT(bmc), errp); + if (error_is_set(errp)) { + return; + } + + qdev_set_legacy_instance_id(dev, intf->io_base, intf->io_length); + + isa_register_ioport(isadev, &intf->io, intf->io_base); +} + +static void ipmi_isa_reset(DeviceState *dev) +{ + ISAIPMIDevice *isa = ISA_IPMI(dev); + + ipmi_interface_reset(isa->intf); +} + +static Property ipmi_isa_properties[] = { + 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(), +}; + +static void ipmi_isa_class_initfn(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = ipmi_isa_realizefn; + dc->reset = ipmi_isa_reset; + dc->props = ipmi_isa_properties; +} + +static const TypeInfo ipmi_isa_info = { + .name = TYPE_ISA_IPMI, + .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(ISAIPMIDevice), + .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/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index 72b1549..40ab84e 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -38,7 +38,16 @@ #define FW_CFG_FILE_FIRST 0x20 #define FW_CFG_FILE_SLOTS 0x10 -#define FW_CFG_MAX_ENTRY (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS) + +#define FW_CFG_IPMI_INTERFACE 0x30 +#define FW_CFG_IPMI_BASE_ADDR 0x31 +#define FW_CFG_IPMI_REG_SPACE 0x32 +#define FW_CFG_IPMI_REG_SPACING 0x33 +#define FW_CFG_IPMI_SLAVE_ADDR 0x34 +#define FW_CFG_IPMI_IRQ 0x35 +#define FW_CFG_IPMI_VERSION 0x36 + +#define FW_CFG_MAX_ENTRY (FW_CFG_IPMI_VERSION + 1) #define FW_CFG_WRITE_CHANNEL 0x4000 #define FW_CFG_ARCH_LOCAL 0x8000