Received: by 2002:a0c:db0e:0:0:0:0:0 with SMTP id d14csp1576541qvk; Thu, 10 Dec 2020 17:59:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJytapx+Ix0MBwR3qf6xLsaUPTVPZxrc1NJg1YO/WOKFb9XtS/cPMMLPiJuj+VMDYTiYYPyD X-Received: by 2002:a5b:701:: with SMTP id g1mr14105828ybq.343.1607651942951; Thu, 10 Dec 2020 17:59:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607651942; cv=none; d=google.com; s=arc-20160816; b=hHoWD1J0kkAjb0KLDjQbQ8bXjd4fYYJz8Cb8rbTq/go8IHjefGElWeMKn0fUaf70ii RURQewJR8WxiIZqtaFXByDC3lelovF82zBoKhNDoIePwsS4umSyo9QLxU0lA+sXZpGzq DNrmwywEwXKYL0Mitf2NLwDjFNzXmsTFpmo/QkPFPV+2L8UfqDX9vmrAFnTH0m5sZ3c3 obA8pY0u2HAoqXIE/Dz1lhGPcOmrS9uyQPOXmLg2Illz20lEwC2bUKE7QPWM8ahMyL8K hlfhvdHx6H7oT9EAITr05tWHKa6JpsPhYeZaVKjD6tNXui54FnhPhefgDUYHtlHlhUIY JXCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to:cc:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:to :subject:references:mime-version:message-id:in-reply-to:date :dkim-signature; bh=cKCtRn1dkFOSwY3ieDqlEqe46CjfgnOoKtbkb72JIac=; b=adWM2QXQERkxQ3XJJI/PEaDcuvaCfoFELY0LW0xJ65qJWHFNQPFRgSbrq9LIMv6Zf0 vMeR2ThwKPa2KGl5bF0QJtxRUAI4voFFgGkkta7fkAVDg3evM/rqyPrCBjqu9j2aoXbr TRU7xwvPJ+dn1+Cyie2oU+b15CIP9tu+rUAjAG0WnMdx4oYn+HYf4vIH+f+1kqD4ZQ2r XHrdGhzCryr9LMn/+ww26oQvJtHKqFJqzM1OuogJIknWObF3buYEudmX2Wyoh3kqnuiX 9PMLzletRsrq7FV3CsYkMllwIIR9bExeRxYkv2G3h1ZcvCq1kIoN6xEULlpXxl1UmKsr /nIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=iOoF3iSk; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o8si6607070ybm.475.2020.12.10.17.59.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Dec 2020 17:59:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=iOoF3iSk; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nongnu.org Received: from localhost ([::1]:41048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knXi2-0006jJ-Dp for alex.bennee@linaro.org; Thu, 10 Dec 2020 20:59:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <31dDSXwgKCsY86tm054ts00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--wuhaotsh.bounces.google.com>) id 1knXbf-0001hu-Ry for qemu-devel@nongnu.org; Thu, 10 Dec 2020 20:52:28 -0500 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]:57106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <31dDSXwgKCsY86tm054ts00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--wuhaotsh.bounces.google.com>) id 1knXbb-0007BJ-0k for qemu-devel@nongnu.org; Thu, 10 Dec 2020 20:52:27 -0500 Received: by mail-pg1-x54a.google.com with SMTP id z2so5390130pgb.23 for ; Thu, 10 Dec 2020 17:52:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=cKCtRn1dkFOSwY3ieDqlEqe46CjfgnOoKtbkb72JIac=; b=iOoF3iSknyFAfnAqW3e3MzqsRKI7VlfXAo8EpS8JgDm2fuIe7q4XzUb6mnyW8qpwU7 rl7UXbjJXrksi7FxMS3hSYF2EVdyfWwJcgK4To+lAstsz4q7/Nyn0Yyn5fQ+4+GYxtkr zszkO+q4GVOzIrXvfCGvF1A4XC6WaQRmbJdIzIM3lmTZEx8MCwgrB2ZjrXIkgpBFFehP bT9iN8a41v0tg6OF0TWl9ZQnv5gveL08GunuLUcw3weC8sgvDp2KI8EmZrQFD5xH3vV8 7U8qtB98OMD62irdHuxz2VAVAPPKF59a1pGwp/cjdGcPCdFuR6nUN23PYScRX+y2UpiB NOFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cKCtRn1dkFOSwY3ieDqlEqe46CjfgnOoKtbkb72JIac=; b=BQHOkN0WUZt1mGeWhrtMHp+Yj/IkgD6fZeBomnrQlk4yx0G8nw+Dnb6xbjeOnAkPNf Hcwn/2ru1cWFPLA+EHv6vy2Rs/CRgUT8tfQLJfCcCNhprheW3ha7kZSUN7EiKQoOpOLs hJZT4PkmdcTAJZtZkXxHiRNy474K+vll5XsXgSpCkj5p8n6JNmVpVPin4K3wQ4a0w5J3 Tzfo0p7YVs9w33w6eSIFOXAb1PR7ZJywEgnWZRZXdfek8BNOd9GQfVBCG2PiMNViKE6a mndDMOgMt1L52BzKuz0jq6I4d+HKiwNp1fw/v+SVrbXwXzgmLVw/oJBoKCE/70176ff1 9Lsg== X-Gm-Message-State: AOAM5331BoKCueb7CHOcC1O3UMBDiSxVx8AFj1zXqKasn7oIp2P22FD8 6SfqYZvQo8OgMN/bW9agXI3jOnXXNDy7Hg== X-Received: from mimik.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:4e]) (user=wuhaotsh job=sendgmr) by 2002:a17:902:8f82:b029:da:f37f:79bf with SMTP id z2-20020a1709028f82b02900daf37f79bfmr8976578plo.79.1607651541057; Thu, 10 Dec 2020 17:52:21 -0800 (PST) Date: Thu, 10 Dec 2020 17:51:54 -0800 In-Reply-To: <20201211015156.2053372-1-wuhaotsh@google.com> Message-Id: <20201211015156.2053372-6-wuhaotsh@google.com> Mime-Version: 1.0 References: <20201211015156.2053372-1-wuhaotsh@google.com> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog Subject: [PATCH 5/7] hw/ipmi: Add an IPMI host interface To: peter.maydell@linaro.org Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::54a; envelope-from=31dDSXwgKCsY86tm054ts00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--wuhaotsh.bounces.google.com; helo=mail-pg1-x54a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: minyard@acm.org, venture@google.com, qemu-devel@nongnu.org, hskinnemoen@google.com, wuhaotsh@google.com, kfting@nuvoton.com, qemu-arm@nongnu.org, Avi.Fishman@nuvoton.com Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: Hao Wu From: Hao Wu via X-TUID: aSGBvLRSxwab The IPMI host interface is used to emulate IPMI related devices on a System-on-Chip (SoC) used for Baseband Management Controller (BMC). This interface consists of two components: IPMI host and IPMI responder. An IPMI responder is a device to intercept reads and writes to the system interface registers in the host. An IPMI host emulates the host behavior on a BMC emulation. For more information see docs/spec/ipmi.rst. Reviewed-by: Havard Skinnemoen Reviewed-by: Tyrone Ting Signed-off-by: Hao Wu --- default-configs/devices/arm-softmmu.mak | 2 + hw/ipmi/Kconfig | 5 ++ hw/ipmi/ipmi_host.c | 40 +++++++++++++++ hw/ipmi/meson.build | 1 + include/hw/ipmi/ipmi_host.h | 56 +++++++++++++++++++++ include/hw/ipmi/ipmi_responder.h | 66 +++++++++++++++++++++++++ 6 files changed, 170 insertions(+) create mode 100644 hw/ipmi/ipmi_host.c create mode 100644 include/hw/ipmi/ipmi_host.h create mode 100644 include/hw/ipmi/ipmi_responder.h diff --git a/default-configs/devices/arm-softmmu.mak b/default-configs/devices/arm-softmmu.mak index 08a32123b4..864bac4501 100644 --- a/default-configs/devices/arm-softmmu.mak +++ b/default-configs/devices/arm-softmmu.mak @@ -27,6 +27,8 @@ CONFIG_GUMSTIX=y CONFIG_SPITZ=y CONFIG_TOSA=y CONFIG_Z2=y +CONFIG_IPMI=y +CONFIG_IPMI_HOST=y CONFIG_NPCM7XX=y CONFIG_COLLIE=y CONFIG_ASPEED_SOC=y diff --git a/hw/ipmi/Kconfig b/hw/ipmi/Kconfig index 9befd4f422..9e487eb42f 100644 --- a/hw/ipmi/Kconfig +++ b/hw/ipmi/Kconfig @@ -6,6 +6,11 @@ config IPMI_LOCAL default y depends on IPMI +config IPMI_HOST + bool + default y + depends on IPMI + config IPMI_EXTERN bool default y diff --git a/hw/ipmi/ipmi_host.c b/hw/ipmi/ipmi_host.c new file mode 100644 index 0000000000..7a6d4eb323 --- /dev/null +++ b/hw/ipmi/ipmi_host.c @@ -0,0 +1,40 @@ +/* + * IPMI Host emulation + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "hw/ipmi/ipmi_host.h" +#include "hw/ipmi/ipmi_responder.h" + +static TypeInfo ipmi_responder_type_info = { + .name = TYPE_IPMI_RESPONDER, + .parent = TYPE_INTERFACE, + .class_size = sizeof(IPMIResponderClass), +}; + +static TypeInfo ipmi_host_type_info = { + .name = TYPE_IPMI_HOST, + .parent = TYPE_DEVICE, + .instance_size = sizeof(IPMIHost), + .abstract = true, + .class_size = sizeof(IPMIHostClass), +}; + +static void ipmi_register_types(void) +{ + type_register_static(&ipmi_responder_type_info); + type_register_static(&ipmi_host_type_info); +} + +type_init(ipmi_register_types) diff --git a/hw/ipmi/meson.build b/hw/ipmi/meson.build index 9622ea2a2c..9ec4dcb957 100644 --- a/hw/ipmi/meson.build +++ b/hw/ipmi/meson.build @@ -7,5 +7,6 @@ ipmi_ss.add(when: 'CONFIG_PCI_IPMI_KCS', if_true: files('pci_ipmi_kcs.c')) ipmi_ss.add(when: 'CONFIG_ISA_IPMI_BT', if_true: files('isa_ipmi_bt.c')) ipmi_ss.add(when: 'CONFIG_PCI_IPMI_BT', if_true: files('pci_ipmi_bt.c')) ipmi_ss.add(when: 'CONFIG_IPMI_SSIF', if_true: files('smbus_ipmi.c')) +ipmi_ss.add(when: 'CONFIG_IPMI_HOST', if_true: files('ipmi_host.c')) softmmu_ss.add_all(when: 'CONFIG_IPMI', if_true: ipmi_ss) diff --git a/include/hw/ipmi/ipmi_host.h b/include/hw/ipmi/ipmi_host.h new file mode 100644 index 0000000000..a703cc3854 --- /dev/null +++ b/include/hw/ipmi/ipmi_host.h @@ -0,0 +1,56 @@ +/* + * IPMI host interface + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef HW_IPMI_HOST_H +#define HW_IPMI_HOST_H + +#include "hw/ipmi/ipmi_responder.h" + +#define TYPE_IPMI_HOST "ipmi-host" +#define IPMI_HOST(obj) \ + OBJECT_CHECK(IPMIHost, (obj), TYPE_IPMI_HOST) +#define IPMI_HOST_CLASS(obj_class) \ + OBJECT_CLASS_CHECK(IPMIHostClass, (obj_class), TYPE_IPMI_HOST) +#define IPMI_HOST_GET_CLASS(obj) \ + OBJECT_GET_CLASS(IPMIHostClass, (obj), TYPE_IPMI_HOST) + +/** + * struct IPMIHost defines an IPMI host interface. It can be a simulator or a + * connection to an emulated or real host. + * @responder: The IPMI responder that handles an IPMI message. + */ +typedef struct IPMIHost { + DeviceState parent; + + IPMIResponder *responder; +} IPMIHost; + +/** + * struct IPMIHostClass defines an IPMI host class. + * @handle_command: Handle a command to the host. + */ +typedef struct IPMIHostClass { + DeviceClass parent; + + /* + * Handle a command to the bmc. + */ + void (*handle_command)(struct IPMIHost *s, + uint8_t *cmd, unsigned int cmd_len, + unsigned int max_cmd_len, uint8_t msg_id); +} IPMIHostClass; + +#endif /* HW_IPMI_HOST_H */ diff --git a/include/hw/ipmi/ipmi_responder.h b/include/hw/ipmi/ipmi_responder.h new file mode 100644 index 0000000000..e3e4ef39d4 --- /dev/null +++ b/include/hw/ipmi/ipmi_responder.h @@ -0,0 +1,66 @@ +/* + * IPMI responder interface + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef HW_IPMI_RESPONDER_H +#define HW_IPMI_RESPONDER_H + +#include "qemu/osdep.h" +#include "hw/qdev-core.h" +#include "qom/object.h" + +#define TYPE_IPMI_RESPONDER_PREFIX "ipmi-responder-" +#define TYPE_IPMI_RESPONDER "ipmi-responder" +#define IPMI_RESPONDER(obj) \ + INTERFACE_CHECK(IPMIResponder, (obj), TYPE_IPMI_RESPONDER) +#define IPMI_RESPONDER_CLASS(class) \ + OBJECT_CLASS_CHECK(IPMIResponderClass, (class), TYPE_IPMI_RESPONDER) +#define IPMI_RESPONDER_GET_CLASS(class) \ + OBJECT_GET_CLASS(IPMIResponderClass, (class), TYPE_IPMI_RESPONDER) + +struct IPMIHost; + +/** + * This interface is implemented by each IPMI responder device (KCS, BT, PCI, + * etc.) An IPMI host device uses it to transfer data to the emulated BMC. + */ +typedef struct IPMIResponder IPMIResponder; + +/** + * struct IPMIResponderClass implemented by an IPMI responder device like KCS to + * handle commands from connected IPMI host device. + * @get_host: Return the IPMI host (e.g. ipmi-host-extern) that uses this + * responder. + * @set_host: Set the IPMI host (e.g. ipmi-host-extern) that uses this + * responder. + * @get_backend_data: Return the backend device (e.g. KCS, BT) of the + * corresponding responder. + * @handle_req: The IPMI Host device calls this function when it receives a sane + * IPMI message. A responder should handle this message. + */ +typedef struct IPMIResponderClass { + InterfaceClass parent; + + struct IPMIHost *(*get_host)(struct IPMIResponder *s); + + void (*set_host)(struct IPMIResponder *s, struct IPMIHost *h); + + void *(*get_backend_data)(struct IPMIResponder *s); + + void (*handle_req)(struct IPMIResponder *s, uint8_t msg_id, + unsigned char *req, unsigned req_len); +} IPMIResponderClass; + +#endif /* HW_IPMI_RESPONDER_H */ -- 2.29.2.684.gfbc64c5ab5-goog