From patchwork Fri Mar 18 09:13:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 8617421 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 442859F44D for ; Fri, 18 Mar 2016 09:17:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 52FD62035D for ; Fri, 18 Mar 2016 09:17:38 +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 5954A2034B for ; Fri, 18 Mar 2016 09:17:37 +0000 (UTC) Received: from localhost ([::1]:42393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqXI-0000Gt-Km for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 05:17:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqTg-00035o-M5 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:13:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agqTb-0003pR-2U for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:13:52 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:35652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agqTa-0003pF-Ot for qemu-devel@nongnu.org; Fri, 18 Mar 2016 05:13:47 -0400 Received: by mail-wm0-x233.google.com with SMTP id l68so23106813wml.0 for ; Fri, 18 Mar 2016 02:13:46 -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=NbXmScxe4PfCuownpUcD/B+6Ie+BKGGRt9EjjprhN7I=; b=bbwPy9tBr3c25Wk9ysXrlNRlFX4Df+m4ScJAhdZ7D/A08IIhgUeVtGArT1VDJrcaon UnlwK07cek4Iqv9nMTyqYwP9iVoUhOWZYOStZpwww3eiqVMlBvYwEtqGCx4NOTCYjWBc lrMrqfx5RAKYzjkRyycYIYDq5hDTeY/Yt96Ck0JamuMpZsedFnilwTp66EtU17k3bj5l vDoPY4eeCdX6In43AF37Y3l0DPUW1D9xERdnAejXseBx3juaPIb2ShNNPPM0f7i/Asvw /MNruVmkrJ09BvMQCDMhnNWLaVRkB6AMso6qvqNlXKxMnpGMGWQA++VOMB2F7zhNW4Yn qNgg== 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=NbXmScxe4PfCuownpUcD/B+6Ie+BKGGRt9EjjprhN7I=; b=Inah2EkDE1T0zscJ6dlpjhV5ERkBwTXnwVVETn6M4ziYv5Bvata+jr9bnT2I+EKm93 WMXoxs9sth6ynzvEyX1X3Es5KxXyViO9S6OXXTH6oUXY+f1xv/Ebi6/L96Rp5tUulGt0 ykGpIEqefKbmSiSMf4C1vvysoX061syt/nGnEynUIpHHTmH/SNqO+RFWwm9jnig811qa eBsEafr9E6FLuBr6sPWxXVzH7hPQTo40w8f596qNZrqHu9h2s1pV/a7a1XRefG0/G/wn kI3ORBwqOqBMywayhlGaJQDtrcafMHcu2XzpdO5h2IyM+oC3gczIK+HQ68UJJkoNlHxu A8zA== X-Gm-Message-State: AD7BkJIjF2vzG1jo1FqULPWsuykV4zrQPv4Aw5cAKyJFcUMeX0YBjkm946N9YuBpisOPTA== X-Received: by 10.194.60.165 with SMTP id i5mr16666573wjr.178.1458292426215; Fri, 18 Mar 2016 02:13:46 -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 b1sm11337074wjy.0.2016.03.18.02.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 02:13:45 -0700 (PDT) From: Baptiste Reynal To: qemu-devel@nongnu.org Date: Fri, 18 Mar 2016 10:13:05 +0100 Message-Id: <1458292385-13802-7-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::233 Cc: b.reynal@virtualopensystems.com, Jani.Kokkonen@huawei.com, tech@virtualopensystems.com, Claudio.Fontana@huawei.com Subject: [Qemu-devel] [RFC v2 6/6] hw/misc: sdm communication socket 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 is the socket implementation of an SDM communication channel. A master device can communicate with a slave over a socket. Parameters: socket=[socket_id] - specifies the multi-client socket This patch depends on "[RFC v2 1/1] backend: multi-client-socket" Signed-off-by: Baptiste Reynal --- hw/misc/Makefile.objs | 1 + hw/misc/sdm-communication-socket.c | 140 +++++++++++++++++++++++++++++ include/hw/misc/sdm-communication-socket.h | 42 +++++++++ 3 files changed, 183 insertions(+) create mode 100644 hw/misc/sdm-communication-socket.c create mode 100644 include/hw/misc/sdm-communication-socket.h diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 6327c5a..b9f75db 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -26,6 +26,7 @@ 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_SDM) += sdm-communication-socket.o obj-$(CONFIG_REALVIEW) += arm_sysctl.o obj-$(CONFIG_NSERIES) += cbus.o diff --git a/hw/misc/sdm-communication-socket.c b/hw/misc/sdm-communication-socket.c new file mode 100644 index 0000000..aba390c --- /dev/null +++ b/hw/misc/sdm-communication-socket.c @@ -0,0 +1,140 @@ +/* + * SDM Communication Socket + * + * 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-socket.h" +#include "hw/qdev-properties.h" +#include "qemu/error-report.h" + +static int sdm_socket_signal(SDMCommunication *sdmc, SDMDevice *sdm, + SDMSignalData *signal) +{ + SDMCommunicationSocket *sdmcs = SDM_COMMUNICATION_SOCKET(sdmc); + int len; + char *message; + SDMSignalData *payload; + + if (!sdmcs->slaves[signal->slave]) { + error_report("SDMCommunicationSocket: invalid slave ID %d", + signal->slave); + return -1; + } + + len = strlen(SDM_SIGNAL_CMD) + sizeof(SDMSignalData) + 1; + message = malloc(len); + + strcpy((char *) message, SDM_SIGNAL_CMD); + payload = (SDMSignalData *) (message + strlen(SDM_SIGNAL_CMD) + 1); + memcpy(payload, signal, sizeof(SDMSignalData)); + + multi_socket_write_to(sdmcs->slaves[signal->slave], + message, + len); + + return 0; +} + +static void sdm_register_ms_handler(MSClient *c, const char *message, + void *opaque) +{ + SDMCommunication *sdmc = opaque; + SDMCommunicationSocket *sdmcs = SDM_COMMUNICATION_SOCKET(sdmc); + int slave_id; + + slave_id = sdm_device_accept(sdmcs->master); + if (slave_id >= 0) { + sdmcs->slaves[slave_id] = c; + } else { + error_report("SDMCommunicationSocket: Slave rejected, no ID available"); + } +} + +static void sdm_signal_ms_handler(MSClient *c, const char *message, + void *opaque) +{ + SDMCommunication *sdmc = opaque; + SDMCommunicationSocket *sdmcs = SDM_COMMUNICATION_SOCKET(sdmc); + int slave; + SDMSignalData *signal; + + signal = (SDMSignalData *) message; + + /* Find slave id */ + for (slave = 0; slave <= sdmcs->num_slaves; slave++) { + if (sdmcs->slaves[slave] == c) { + break; + } + } + + signal->slave = slave; + + while (sdm_device_notify(sdmcs->master, signal) < 0) { + sleep(100); + } +} + +static int sdm_socket_connect(SDMCommunication *sdmc, SDMDevice *sdm) +{ + SDMCommunicationSocket *sdmcs = SDM_COMMUNICATION_SOCKET(sdmc); + + sdmcs->master = sdm; + + sdmcs->num_slaves = sdm_device_get_num_slaves(sdm); + sdmcs->slaves = calloc(sdmcs->num_slaves + 1, + sizeof(MSClient *)); + + sdmcs->slaves[0] = &sdmcs->socket->listener; + multi_socket_add_handler(sdmcs->socket, SDM_SIGNAL_CMD, + sdm_signal_ms_handler, sdmc); + + if (sdm_device_is_master(sdm)) { + multi_socket_add_handler(sdmcs->socket, SDM_REGISTER_CMD, + sdm_register_ms_handler, sdmc); + } else { + multi_socket_write_to(sdmcs->slaves[0], + SDM_REGISTER_CMD, + strlen(SDM_REGISTER_CMD) + 1); + } + + return 0; +} + +static void sdm_communication_socket_class_init(ObjectClass *oc, void *data) +{ + SDMCommunicationClass *sdmck = SDM_COMMUNICATION_CLASS(oc); + + sdmck->signal = sdm_socket_signal; + sdmck->connect = sdm_socket_connect; +} + +static void sdm_communication_socket_init(Object *obj) +{ + SDMCommunicationSocket *s = SDM_COMMUNICATION_SOCKET(obj); + + object_property_add_link(obj, "socket", TYPE_MULTI_SOCKET_BACKEND, + (Object **)&s->socket, + object_property_allow_set_link, + OBJ_PROP_LINK_UNREF_ON_RELEASE, + &error_abort); +} + +static const TypeInfo sdm_communication_socket_info = { + .name = TYPE_SDM_COMMUNICATION_SOCKET, + .parent = TYPE_SDM_COMMUNICATION, + .class_init = sdm_communication_socket_class_init, + .instance_size = sizeof(SDMCommunicationSocket), + .instance_init = sdm_communication_socket_init, +}; + +static void register_types(void) +{ + type_register_static(&sdm_communication_socket_info); +} + +type_init(register_types); diff --git a/include/hw/misc/sdm-communication-socket.h b/include/hw/misc/sdm-communication-socket.h new file mode 100644 index 0000000..aa24454 --- /dev/null +++ b/include/hw/misc/sdm-communication-socket.h @@ -0,0 +1,42 @@ +/* + * SDM Communication Socket + * + * 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 in the top-level directory. + */ +#ifndef HW_SDM_COMM_SOCK_H +#define HW_SDM_COMM_SOCK_H + +#include "hw/misc/sdm-communication.h" +#include "qemu/multi-socket.h" + +#define SDM_REGISTER_CMD "sdm_register" +#define SDM_SIGNAL_CMD "sdm_signal" + +#define TYPE_SDM_COMMUNICATION_SOCKET "sdm-communication-socket" +#define SDM_COMMUNICATION_SOCKET(obj) \ + OBJECT_CHECK(SDMCommunicationSocket, (obj), \ + TYPE_SDM_COMMUNICATION_SOCKET) + +typedef struct SDMCommunicationSocket SDMCommunicationSocket; + +/** + * @SDMCommunicationSocket + * + * @parent: opaque parent object container + */ +struct SDMCommunicationSocket { + /* private */ + SDMCommunication parent; + + SDMDevice *master; + MSBackend *socket; + + int num_slaves; + MSClient **slaves; +}; +#endif