From patchwork Fri Jun 17 15:55:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Pinto X-Patchwork-Id: 9184513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2877C6075D for ; Fri, 17 Jun 2016 16:17:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1112727248 for ; Fri, 17 Jun 2016 16:17:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05EC627DD0; Fri, 17 Jun 2016 16:17:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 45E4627248 for ; Fri, 17 Jun 2016 16:17:14 +0000 (UTC) Received: from localhost ([::1]:58782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDwSG-00039K-TS for patchwork-qemu-devel@patchwork.kernel.org; Fri, 17 Jun 2016 12:17:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDw7N-0006el-9I for qemu-devel@nongnu.org; Fri, 17 Jun 2016 11:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDw7K-00019d-Ar for qemu-devel@nongnu.org; Fri, 17 Jun 2016 11:55:35 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDw7K-00019O-0f for qemu-devel@nongnu.org; Fri, 17 Jun 2016 11:55:34 -0400 Received: by mail-wm0-x243.google.com with SMTP id m124so722575wme.3 for ; Fri, 17 Jun 2016 08:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p/8azirv6no2uZE0FMthB92atbUzIDO8xjdrwQ1Y0kQ=; b=e+FFQNw27ItUAalj1SzP1+ehkiwAkaYGGZKMTN+dMv7ScCOKw2b6PEDNR6P02CkvDo a3g8nMUfcyu3THro2CQNCS81tDa704/dGLnI/dB4VO/LkLAduVL2J/UP4blWEsSIMkS4 lLZGxZOPKSYhdkr463DGqvUcH4kD4Ck9LJeXh09Dq2SK/1MvpEidL0mHy5WDXq+Iepg1 qbq4V/WQpPPiFe+uYzjM6ZDbqNf9SJEWZX8+2XA1xwfzutlIdfFt1UiUUG+eH99BAsO0 sFjS2Dy/bQ6PtrSDwBoWRNrZt2cflvo5z9mAaiyl+UZrXbVu7rbK2GxiBBlizlPRc8dl dqnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p/8azirv6no2uZE0FMthB92atbUzIDO8xjdrwQ1Y0kQ=; b=hSg3z1w2goPbJKVuaeCfVpHSalcWImdGsjmfgIhdRlq2XuSG75f8fvxROHAy3Qwta5 fE8EvOKHRXEpyc8BijxR+57hHQoffKlhIcNrnpJfhqBWVft6b62PIn77/r76eZPL9Aiq WwZ6YeAjZ4A5m1J4shExlYoC+vH+bn741+IHnmkN9KK+sBje/Mm2eOLdvvitBpGTSOGX KdwNY//3nmTV//Rhe1Q5gxo/OuqxFx91FDxPIJkuhCIiCJqHkXTyU/Px1+lRRIdc5E9Q Wk04F6lN213+LvtKZkUMsGie7NXGIkbGrbcOz1TV1C1+tMB8QoX/fRYIwFeMCiqiWGhc +AJQ== X-Gm-Message-State: ALyK8tJXUsEnzhKWBSS0k92JTZWKQfWKsOW6Y+wAlxBbrw4d5/o5zFfrxDui1QApzCDfpg== X-Received: by 10.28.68.85 with SMTP id r82mr400176wma.18.1466178933287; Fri, 17 Jun 2016 08:55:33 -0700 (PDT) Received: from bumma.localdomain ([151.67.13.17]) by smtp.googlemail.com with ESMTPSA id q189sm254937wmd.19.2016.06.17.08.55.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Jun 2016 08:55:32 -0700 (PDT) From: Christian Pinto To: qemu-devel@nongnu.org Date: Fri, 17 Jun 2016 17:55:02 +0200 Message-Id: <1466178903-2184-6-git-send-email-c.pinto@virtualopensystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466178903-2184-1-git-send-email-c.pinto@virtualopensystems.com> References: <1466178903-2184-1-git-send-email-c.pinto@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [RFC v3 5/6] hw/misc: sdm communication local 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: Claudio.Fontana@huawei.com, Jani.Kokkonen@huawei.com, tech@virtualopensystems.com, b.reynal@virtualopensystems.com, Christian Pinto Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Baptiste Reynal This patch introduces local implementation for SDM devices. It allows a master to communicate with a slave on the same QEMU instance. Instantiation: -object sdm-communication-local,id= Signed-off-by: Baptiste Reynal Signed-off-by: Christian Pinto --- v2 -> v3: - added sdm_local_update_num_slaves to local communication channel - realloc slaves array in case of max slaves change - fixed bug: signal notifications not sent to correct sdm device instance --- --- hw/misc/Makefile.objs | 1 + hw/misc/sdm-communication-local.c | 116 ++++++++++++++++++++++++++++++ include/hw/misc/sdm-communication-local.h | 35 +++++++++ 3 files changed, 152 insertions(+) create mode 100644 hw/misc/sdm-communication-local.c create mode 100644 include/hw/misc/sdm-communication-local.h diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 85cfda9..cad0b4c 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -25,6 +25,7 @@ obj-$(CONFIG_SDM) += sdm-device.o obj-$(CONFIG_SDM) += sdm-communication.o obj-$(CONFIG_SDM) += sdm-signal.o obj-$(CONFIG_SDM) += sdm-platform.o +obj-$(CONFIG_SDM) += sdm-communication-local.o obj-$(CONFIG_REALVIEW) += arm_sysctl.o obj-$(CONFIG_NSERIES) += cbus.o diff --git a/hw/misc/sdm-communication-local.c b/hw/misc/sdm-communication-local.c new file mode 100644 index 0000000..a9ce1ba --- /dev/null +++ b/hw/misc/sdm-communication-local.c @@ -0,0 +1,116 @@ +/* + * SDM Communication Local + * + * Copyright (C) 2016 - Virtual Open Systems + * + * Author: Baptiste Reynal + * Christian Pinto + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ +#include "hw/misc/sdm-communication-local.h" + +static int sdm_local_signal(SDMCommunication *sdmc, SDMDevice *sdm, + SDMSignalData *signal) +{ + SDMCommunicationLocal *sdmcl = SDM_COMMUNICATION_LOCAL(sdmc); + int id; + int dest; + + dest = signal->slave; + if (!sdmcl->slaves[dest]) { + printf("Error unexisting slave\n"); + return -1; + } + + /* Find sdm ID + */ + for (id=0; id<=sdmcl->num_slaves; id++) { + if (sdmcl->slaves[id] == sdm) + break; + } + /** + * Update slave_id field with source sdm ID + */ + signal->slave = id; + + while (sdm_device_notify(sdmcl->slaves[dest], signal) < 0) { + sleep(1); + } + + return 0; +} + +static int sdm_local_connect(SDMCommunication *sdmc, SDMDevice *sdm) +{ + SDMCommunicationLocal *sdmcl = SDM_COMMUNICATION_LOCAL(sdmc); + int id; + + if (sdm_device_is_master(sdm)) { + sdmcl->num_slaves = sdm_device_get_num_slaves(sdm); + sdmcl->slaves = calloc(sdmcl->num_slaves + 1, + sizeof(SDMDevice *)); + sdmcl->slaves[0] = sdm; + } else { + if (!sdmcl->slaves) { + printf("SDM Communication Local error : no master registered\n"); + return -1; + } + + id = sdm_device_accept(sdmcl->slaves[0]); + + if (id < 0) { + printf("SDM Communication Local error : no id available\n"); + + return -1; + } + + sdmcl->slaves[id] = sdm; + } + + return 0; +} + +static int sdm_local_update_num_slaves(SDMCommunication *sdmc, SDMDevice *sdm, + uint16_t num_slaves) +{ + SDMCommunicationLocal *sdmcl = SDM_COMMUNICATION_LOCAL(sdmc); + SDMDevice **tmp_slaves; + + tmp_slaves = realloc(sdmcl->slaves, (num_slaves + 1) * + sizeof(SDMDevice *)); + + if(tmp_slaves == NULL) + return -1; + + sdmcl->slaves = tmp_slaves; + sdmcl->num_slaves = num_slaves; + sdm_device_set_num_slaves(sdm, num_slaves); + + return 0; +} + + +static void sdm_communication_local_class_init(ObjectClass *oc, void *data) +{ + SDMCommunicationClass *sdmck = SDM_COMMUNICATION_CLASS(oc); + + sdmck->signal = sdm_local_signal; + sdmck->connect = sdm_local_connect; + sdmck->update_num_slaves = sdm_local_update_num_slaves; +} + +static const TypeInfo sdm_communication_local_info = { + .name = TYPE_SDM_COMMUNICATION_LOCAL, + .parent = TYPE_SDM_COMMUNICATION, + .class_init = sdm_communication_local_class_init, + .instance_size = sizeof(SDMCommunicationLocal), +}; + +static void register_types(void) +{ + type_register_static(&sdm_communication_local_info); +} + +type_init(register_types); diff --git a/include/hw/misc/sdm-communication-local.h b/include/hw/misc/sdm-communication-local.h new file mode 100644 index 0000000..34d1718 --- /dev/null +++ b/include/hw/misc/sdm-communication-local.h @@ -0,0 +1,35 @@ +/* + * SDM Communication Local + * + * Copyright (C) 2016 - Virtual Open Systems + * + * Author: Baptiste Reynal + * + * This works is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file un the top-level directory. + */ +#ifndef HW_SDM_COMM_LOCAL_H +#define HW_SDM_COMM_LOCAL_H + +#include "hw/misc/sdm-communication.h" + +#define TYPE_SDM_COMMUNICATION_LOCAL "sdm-communication-local" +#define SDM_COMMUNICATION_LOCAL(obj) \ + OBJECT_CHECK(SDMCommunicationLocal, (obj), \ + TYPE_SDM_COMMUNICATION_LOCAL) + +typedef struct SDMCommunicationLocal SDMCommunicationLocal; + +/** + * @SDMCommunicationLocal + * + * @parent: opaque parent object container + */ +struct SDMCommunicationLocal { + /* private */ + SDMCommunication parent; + + int num_slaves; + SDMDevice **slaves; +}; +#endif