From patchwork Fri Mar 18 09:13:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 8617471 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 6F1169F44D for ; Fri, 18 Mar 2016 09:19:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 64E612034B for ; Fri, 18 Mar 2016 09:19:26 +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 8668320374 for ; Fri, 18 Mar 2016 09:19:25 +0000 (UTC) Received: from localhost ([::1]:42409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqZ2-0003hb-Nn for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 05:19:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqTX-0002vt-Ig for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:13:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agqTW-0003o6-By for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:13:43 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqTV-0003nc-VE for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:13:42 -0400 Received: by mail-wm0-x236.google.com with SMTP id l68so23104444wml.0 for ; Fri, 18 Mar 2016 02:13:41 -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=uyTouBExWDXRliDmmV/BhslTIJ0B3m4Rol0QBBIjRJs=; b=mBeBnIfvqHZIoop9EAbsRbWCUW77eCz5tBwVvdh5R0icEx0vv+bhjsgb1LQGgez/jI mxzmOVpULgwcOid5OPCXUFySXQFV5f7q/JI5aEMJOBsN+i5wRCoAXB7oxWgEDeWJPA1J T67Y1/pogfKhpg3k8FN1hn13Qaqe007D3Y1qdnTeKc11rP6eIRB+Pd1BvPM+MI/Kg3Rb rrLu5zuIyiiH8ZtbCbi1C1xWLWvG+jbOEXM6WjPxGcOCO8ygGCfA8GXZeC8c/kDA9KUX P2JqT2Gt5cRPLkkImvpcS6AWQiZC7CbsmLr2ZNsUaR6axg8gkmVJntkgDfVm5NjJENpo 4FWw== 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=uyTouBExWDXRliDmmV/BhslTIJ0B3m4Rol0QBBIjRJs=; b=MwitDGBS1Mi8Sh2uU/+dAPRNnbatAWFrVUtqoW9t0NBmAtkUoKwz+yrHCLeUCiTD79 BC2/xWMHnv+rdhB3MOjvzTlWxysq1AyLm4D+VBQjg77E+fOyN+enbu2twNSNobx7ri49 OdNPnB3nNzT00vQac/9dpaizTO2WtOpHUF7RbqqBnDdkt+WXNsmyXPE6dSRzJ25/mmIt mQz7E6nHbEjXYkstcGBgTc6dF204JZsFRMexj0p13oKzUbB8yNXt7L1RMbyey5g5GO9f dfHx6OKOkcpVSCJJV+gMMNNAoc05f+q6xvCvGVqBYAoXkKXB6uoLPm+fTBoe9cpGne4w nltg== X-Gm-Message-State: AD7BkJK8WWek0654Dykr9Fib0Jb6wESeuRF7g7JQAj0qaWzdne6IXsTEtKaJ72+RlPOAvg== X-Received: by 10.28.126.4 with SMTP id z4mr41225869wmc.29.1458292421438; Fri, 18 Mar 2016 02:13:41 -0700 (PDT) Received: from localhost (LMontsouris-657-1-4-224.w90-63.abo.wanadoo.fr. [90.63.239.224]) by smtp.gmail.com with ESMTPSA id 8sm33996227wmk.13.2016.03.18.02.13.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 02:13:40 -0700 (PDT) From: Baptiste Reynal To: qemu-devel@nongnu.org Date: Fri, 18 Mar 2016 10:13:04 +0100 Message-Id: <1458292385-13802-6-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458292385-13802-1-git-send-email-b.reynal@virtualopensystems.com> References: <1458292385-13802-1-git-send-email-b.reynal@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::236 Cc: b.reynal@virtualopensystems.com, Jani.Kokkonen@huawei.com, tech@virtualopensystems.com, Claudio.Fontana@huawei.com Subject: [Qemu-devel] [RFC v2 5/6] hw/misc: sdm communication local 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org 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 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 --- hw/misc/Makefile.objs | 1 + hw/misc/sdm-communication-local.c | 89 +++++++++++++++++++++++++++++++ include/hw/misc/sdm-communication-local.h | 35 ++++++++++++ 3 files changed, 125 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 fc32161..6327c5a 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..af7cecf --- /dev/null +++ b/hw/misc/sdm-communication-local.c @@ -0,0 +1,89 @@ +/* + * SDM Communication Local + * + * Copyright (C) 2016 - Virtual Open Systems + * + * Author: Baptiste Reynal + * + * 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; + + if (!sdmcl->slaves[signal->slave]) { + printf("Error unexisting slave\n"); + return -1; + } + + /* Find sdm ID + */ + for (id = 0; id <= sdmcl->num_slaves; id++) { + if (sdmcl->slaves[id] == sdm) { + break; + } + } + + while (sdm_device_notify(sdmcl->slaves[signal->slave], 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(sdm); + + if (id < 0) { + printf("SDM Communication Local error : no id available\n"); + + return -1; + } + + sdmcl->slaves[id] = sdm; + } + + 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; +} + +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