From patchwork Wed May 11 19:46:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 9074231 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 53A319F30C for ; Wed, 11 May 2016 19:46:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5955B201BC for ; Wed, 11 May 2016 19:46:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2EBA8201BB for ; Wed, 11 May 2016 19:46:45 +0000 (UTC) Received: from localhost ([::1]:53773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0a5j-0000bh-Qb for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 15:46:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0a5O-0000Jz-HQ for qemu-devel@nongnu.org; Wed, 11 May 2016 15:46:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0a5H-00084L-6C for qemu-devel@nongnu.org; Wed, 11 May 2016 15:46:21 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:35470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0a5G-00083x-O6 for qemu-devel@nongnu.org; Wed, 11 May 2016 15:46:15 -0400 Received: by mail-pf0-x242.google.com with SMTP id r187so5284100pfr.2 for ; Wed, 11 May 2016 12:46:14 -0700 (PDT) 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=hnR8kZ9lbopW/+glZs3A291x31Rd98lq0uABFnxVJMc=; b=NmbF0rZzSZLluARiYK1sI3jBPJAX8SCKJa+8VCwc2MXmU8ZFbT27LDgOgjaRuVgSuy Yxij3juJr76AKG85SINkdhQF0IU+K05896dHhaFQu4n3Pl0XuVhf92S4ggBGg+4BzDZG XUS92LiMnhTPGFZw94M05tR0m3C0a9jHfgY3Bt3owN6TufnkXlrgquHAJ3iteNTatmPq 4aLH9ldzNk9jgfKu8zosa6hDxZy0DW/tKD/1v2c1hO23S5hKqC5w5TEMBryDu6P9AtMi zD2+MEQsww5GR6e5fZGzHGfx0jpdeKiDFf0kQOlWqNUF4fMsqsUps3b737JFQqTEvD0s 8OTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=hnR8kZ9lbopW/+glZs3A291x31Rd98lq0uABFnxVJMc=; b=Soo5CebEWWZ+ow22109uYQlEGbGt0SRbwZvv9VFOy4yfnSPjMj3OR0/nJX8WZ06WnN oibwMDtRloPvbqBoo5aV9ZDEA0STXWHVtS7OsLa1nNGfJv+9BN2EmpVC+tHjRGkKL1sW EJloX15RI6Bw4tN18hqsldUjjrSgTlrd3mU5GWkCsplPLJhZqV/LEOTeBRpyw+GJVv+I asOYUqDrZNEphpm3UQhbGP/vMm889vTkQ4+8zxCz7HgFwfvGOfJHJpqftGWWfqBZ2NLh 8L3AjbL+zby9+2FCj15d06G0mkZjVORh10ATvUtpeW2Z1nUR3Zf2uLcLpAJwdBtC/qMi pNwQ== X-Gm-Message-State: AOPr4FX5jfa0+JKI/SC5f9h9Vhrlla0Zm6S4dWvUFzQibBR8FHoPjxtPYkaPpRiEEcY/KQ== X-Received: by 10.98.19.131 with SMTP id 3mr7658788pft.17.1462995974061; Wed, 11 May 2016 12:46:14 -0700 (PDT) Received: from serve.minyard.net ([108.19.215.157]) by smtp.gmail.com with ESMTPSA id u65sm14160747pfa.9.2016.05.11.12.46.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 May 2016 12:46:13 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:a430:dab6:589a:a3a1]) by serve.minyard.net (Postfix) with ESMTPA id 7125819A4; Wed, 11 May 2016 14:46:10 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 0AD9130052B; Wed, 11 May 2016 14:46:08 -0500 (CDT) From: minyard@acm.org To: Igor Mammedov , "Michael S . Tsirkin" , Paolo Bonzini , qemu-devel@nongnu.org, minyard@acm.org Date: Wed, 11 May 2016 14:46:03 -0500 Message-Id: <1462995966-1184-5-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1462995966-1184-1-git-send-email-minyard@acm.org> References: <1462995966-1184-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH 4/7] ipmi: Add an SMBus IPMI interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard 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/smbus_ipmi.c | 216 +++++++++++++++++++++++++++++++++++++ 4 files changed, 219 insertions(+) create mode 100644 hw/ipmi/smbus_ipmi.c diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index c94431d..636bf1d 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -14,6 +14,7 @@ CONFIG_IPMI_LOCAL=y CONFIG_IPMI_EXTERN=y CONFIG_ISA_IPMI_KCS=y CONFIG_ISA_IPMI_BT=y +CONFIG_IPMI_SSIF=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 256294d..e268980 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -14,6 +14,7 @@ CONFIG_IPMI_LOCAL=y CONFIG_IPMI_EXTERN=y CONFIG_ISA_IPMI_KCS=y CONFIG_ISA_IPMI_BT=y +CONFIG_IPMI_SSIF=y CONFIG_SERIAL=y CONFIG_PARALLEL=y CONFIG_I8254=y diff --git a/hw/ipmi/Makefile.objs b/hw/ipmi/Makefile.objs index a90318d..6a17912 100644 --- a/hw/ipmi/Makefile.objs +++ b/hw/ipmi/Makefile.objs @@ -3,3 +3,4 @@ common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_sim.o common-obj-$(CONFIG_IPMI_LOCAL) += ipmi_bmc_extern.o common-obj-$(CONFIG_ISA_IPMI_KCS) += isa_ipmi_kcs.o common-obj-$(CONFIG_ISA_IPMI_BT) += isa_ipmi_bt.o +common-obj-$(CONFIG_IPMI_SSIF) += smbus_ipmi.o diff --git a/hw/ipmi/smbus_ipmi.c b/hw/ipmi/smbus_ipmi.c new file mode 100644 index 0000000..4e7203b --- /dev/null +++ b/hw/ipmi/smbus_ipmi.c @@ -0,0 +1,216 @@ +/* + * QEMU IPMI SMBus (SSIF) 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. + */ +#include "qemu/osdep.h" +#include "hw/hw.h" +#include "hw/i2c/smbus.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/ipmi/ipmi.h" + +#define TYPE_SMBUS_IPMI "smbus-ipmi" +#define SMBUS_IPMI(obj) OBJECT_CHECK(SMBusIPMIDevice, (obj), TYPE_SMBUS_IPMI) + +#define SSIF_IPMI_REQUEST 2 +#define SSIF_IPMI_MULTI_PART_REQUEST_START 6 +#define SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE 7 +#define SSIF_IPMI_RESPONSE 3 +#define SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE 9 + +typedef struct SMBusIPMIDevice { + SMBusDevice parent; + + IPMIBmc *bmc; + + uint8_t outmsg[MAX_IPMI_MSG_SIZE]; + uint32_t outpos; + uint32_t outlen; + + uint8_t inmsg[MAX_IPMI_MSG_SIZE]; + uint32_t inlen; + + /* + * This is a response number that we send with the command to make + * sure that the response matches the command. + */ + uint8_t waiting_rsp; + + IPMIFwInfo fwinfo; +} SMBusIPMIDevice; + +static void smbus_ipmi_handle_event(IPMIInterface *ii) +{ + /* No interrupts, so nothing to do here. */ +} + +static void smbus_ipmi_handle_rsp(IPMIInterface *ii, uint8_t msg_id, + unsigned char *rsp, unsigned int rsp_len) +{ + SMBusIPMIDevice *sid = SMBUS_IPMI(ii); + + if (sid->waiting_rsp == msg_id) { + sid->waiting_rsp++; + + memcpy(sid->outmsg, rsp, rsp_len); + sid->outlen = rsp_len; + sid->outpos = 0; + } +} + +static void smbus_ipmi_set_atn(IPMIInterface *ii, int val, int irq) +{ + /* This is where PEC would go. */ +} + +static void smbus_ipmi_set_irq_enable(IPMIInterface *ii, int val) +{ +} + +static void ipmi_quick_cmd(SMBusDevice *dev, uint8_t read) +{ +} + +static void ipmi_send_byte(SMBusDevice *dev, uint8_t val) +{ +} + +static uint8_t ipmi_receive_byte(SMBusDevice *dev) +{ + SMBusIPMIDevice *sid = SMBUS_IPMI(dev); + + if (sid->outpos >= sid->outlen) + return 0; + + return sid->outmsg[sid->outpos++]; +} + +static void ipmi_write_data(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len) +{ + SMBusIPMIDevice *sid = SMBUS_IPMI(dev); + IPMIBmcClass *bk = IPMI_BMC_GET_CLASS(sid->bmc); + + if (cmd != SSIF_IPMI_REQUEST) + return; + + if (len < 3 || len > MAX_IPMI_MSG_SIZE || buf[0] != len - 1) + return; + + memcpy(sid->inmsg, buf + 1, len - 1); + sid->inlen = len; + + sid->outlen = 0; + sid->outpos = 0; + bk->handle_command(sid->bmc, sid->inmsg, sid->inlen, sizeof(sid->inmsg), + sid->waiting_rsp); +} + +static uint8_t ipmi_read_data(SMBusDevice *dev, uint8_t cmd, int n) +{ + SMBusIPMIDevice *sid = SMBUS_IPMI(dev); + + if (cmd != SSIF_IPMI_RESPONSE) + return 0; + + if (n == 0) + return sid->outlen; + + return ipmi_receive_byte(dev); +} + +static const VMStateDescription vmstate_smbus_ipmi = { + .name = TYPE_SMBUS_IPMI, + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(waiting_rsp, SMBusIPMIDevice), + VMSTATE_END_OF_LIST() + } +}; + +static void smbus_ipmi_realize(DeviceState *dev, Error **errp) +{ + SMBusIPMIDevice *sid = SMBUS_IPMI(dev); + IPMIInterface *ii = IPMI_INTERFACE(dev); + + if (!sid->bmc) { + error_setg(errp, "IPMI device requires a bmc attribute to be set"); + return; + } + + sid->bmc->intf = ii; + + sid->fwinfo.interface_name = "smbus"; + sid->fwinfo.interface_type = IPMI_SMBIOS_SSIF; + sid->fwinfo.ipmi_spec_major_revision = 2; + sid->fwinfo.ipmi_spec_minor_revision = 0; + sid->fwinfo.i2c_slave_address = sid->bmc->slave_addr; + sid->fwinfo.base_address = sid->parent.i2c.address; + sid->fwinfo.memspace = IPMI_MEMSPACE_SMBUS; + sid->fwinfo.register_spacing = 1; + ipmi_add_fwinfo(&sid->fwinfo, errp); +} + +static void smbus_ipmi_init(Object *obj) +{ + SMBusIPMIDevice *sid = SMBUS_IPMI(obj); + + ipmi_bmc_find_and_link(OBJECT(obj), (Object **) &sid->bmc); +} + +static void smbus_ipmi_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + IPMIInterfaceClass *iic = IPMI_INTERFACE_CLASS(oc); + SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(oc); + + sc->quick_cmd = ipmi_quick_cmd; + sc->send_byte = ipmi_send_byte; + sc->receive_byte = ipmi_receive_byte; + sc->write_data = ipmi_write_data; + sc->read_data = ipmi_read_data; + dc->vmsd = &vmstate_smbus_ipmi; + dc->realize = smbus_ipmi_realize; + iic->set_atn = smbus_ipmi_set_atn; + iic->handle_rsp = smbus_ipmi_handle_rsp; + iic->handle_if_event = smbus_ipmi_handle_event; + iic->set_irq_enable = smbus_ipmi_set_irq_enable; +} + +static const TypeInfo smbus_ipmi_info = { + .name = TYPE_SMBUS_IPMI, + .parent = TYPE_SMBUS_DEVICE, + .instance_size = sizeof(SMBusIPMIDevice), + .instance_init = smbus_ipmi_init, + .class_init = smbus_ipmi_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_IPMI_INTERFACE }, + { } + } +}; + +static void smbus_ipmi_register_types(void) +{ + type_register_static(&smbus_ipmi_info); +} + +type_init(smbus_ipmi_register_types)