From patchwork Fri Oct 2 14:31:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 9919 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id F3492C3B5C for ; Fri, 2 Oct 2020 14:32:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BB80C63B6E; Fri, 2 Oct 2020 16:32:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kspCDVoQ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AA6EC63B6E for ; Fri, 2 Oct 2020 16:32:33 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E00EE2A2; Fri, 2 Oct 2020 16:32:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601649153; bh=kaNKMD3AjVHE+16afzcqNrZh8mELyQJUprSl13QdFLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kspCDVoQkVqGr3dZ1H7/goHuUhCBcjVXF4ZH9Tgepwq0SwzQkP9E2KVFsYKj3DIOK p3FaPAl/esZ9+IcghcswW1+tn/qmgxIJplwDv4agM0YiweGWRVzwxZF3DGmb/sbpq8 SQCcw8dr/ltJw7GG1filREnKIgwImnQT7JfmY8ZU= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 2 Oct 2020 23:31:27 +0900 Message-Id: <20201002143154.468162-12-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201002143154.468162-1-paul.elder@ideasonboard.com> References: <20201002143154.468162-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 11/38] libcamera: Add IPAIPC X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Create a virtual IPAIPC class that models an IPC/RPC system. IPA proxies and proxy workers will call into the IPAIPC, rather than implementing the IPC themselves. Signed-off-by: Paul Elder Reviewed-by: Jacopo Mondi --- Changes in v3: - expand documentation a bit - move [[maybe_unused]] to after the parameters in the IPAIPC constructor, to appease gcc <= 9.1 Changes in v2: - add documentation --- include/libcamera/internal/ipa_ipc.h | 41 ++++++++++ src/libcamera/ipa_ipc.cpp | 114 +++++++++++++++++++++++++++ src/libcamera/meson.build | 1 + 3 files changed, 156 insertions(+) create mode 100644 include/libcamera/internal/ipa_ipc.h create mode 100644 src/libcamera/ipa_ipc.cpp diff --git a/include/libcamera/internal/ipa_ipc.h b/include/libcamera/internal/ipa_ipc.h new file mode 100644 index 00000000..09de36a5 --- /dev/null +++ b/include/libcamera/internal/ipa_ipc.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * ipa_ipc.h - Image Processing Algorithm IPC module for IPA proxies + */ +#ifndef __LIBCAMERA_INTERNAL_IPA_IPC_H__ +#define __LIBCAMERA_INTERNAL_IPA_IPC_H__ + +#include + +namespace libcamera { + +class IPAIPC +{ +public: + IPAIPC(const char *ipa_module_path [[maybe_unused]], + const char *ipa_proxy_worker_path [[maybe_unused]]); + virtual ~IPAIPC(); + + bool isValid() const { return valid_; } + + virtual int sendSync(uint32_t cmd, + const std::vector &data_in, + const std::vector &fds_in, + std::vector *data_out = nullptr, + std::vector *fds_out = nullptr) = 0; + + virtual int sendAsync(uint32_t cmd, + const std::vector &data_in, + const std::vector &fds_in) = 0; + + Signal &, std::vector &> recvIPC; + +protected: + bool valid_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_INTERNAL_IPA_IPC_H__ */ diff --git a/src/libcamera/ipa_ipc.cpp b/src/libcamera/ipa_ipc.cpp new file mode 100644 index 00000000..b963351f --- /dev/null +++ b/src/libcamera/ipa_ipc.cpp @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * ipa_ipc.cpp - Image Processing Algorithm IPC module for IPA proxies + */ + +#include + +#include "libcamera/internal/ipc_unixsocket.h" +#include "libcamera/internal/log.h" +#include "libcamera/internal/process.h" +#include "libcamera/internal/thread.h" + +#include +#include + +#include "libcamera/internal/ipa_ipc.h" + +/** + * \file ipa_ipc.h + * \brief IPC mechanism for IPA isolation + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(IPAIPC) + +/** + * \class IPAIPC + * \brief IPC mechanism for IPA isolation + * + * Virtual class to model an IPC mechanism for use by IPA proxies for IPA + * isolation. sendSync() and sendAsync() must be implemented, and the recvIPC + * signal must be emitted whenever new data is available. + */ + +/** + * \brief Construct an IPAIPC instance + * \param[in] ipa_module_path Path to the IPA module shared object + * \param[in] ipa_proxy_worker_path Path to the IPA proxy worker shared object + */ +IPAIPC::IPAIPC([[maybe_unused]] const char *ipa_module_path, + [[maybe_unused]] const char *ipa_proxy_worker_path) + : valid_(false) +{ +} + +IPAIPC::~IPAIPC() +{ +} + +/** + * \fn IPAIPC::isValid() + * \brief Check if the IPAIPC instance is valid + * + * An IPAIPC instance is valid if the IPA interface is successfully created in + * isolation, and IPC is successfully set up. + * + * \return True if the IPAIPC is valid, false otherwise + */ + +/** + * \fn IPAIPC::sendSync() + * \brief Send a message over IPC synchronously + * \param[in] cmd Command ID + * \param[in] data_in Data to send, as a byte vector + * \param[in] fds_in Fds to send, in a vector + * \param[in] data_out Byte vector in which to receive data, if applicable + * \param[in] fds_out Fds vector in which to receive fds, if applicable + * + * This function will not return until a response is received. The event loop + * will still continue to execute, however. + * + * \return Zero on success, negative error code otherwise + */ + +/** + * \fn IPAIPC::sendAsync() + * \brief Send a message over IPC asynchronously + * \param[in] cmd Command ID + * \param[in] data_in Data to send, as a byte vector + * \param[in] fds_in Fds to send, in a vector + * + * This function will return immediately after sending the message. + * + * \return Zero on success, negative error code otherwise + */ + +/** + * \var IPAIPC::recvIPC + * \brief Signal to be emitted when data is received over IPC + * + * When data is received over IPC, this signal shall be emitted. Users must + * connect to this to receive new data. + * + * The parameters of the signal are a vector of bytes and a vector of file + * descriptors. + */ + +/** + * \var IPAIPC::valid_ + * \brief Flag to indicate if the IPAIPC instance is valid + * + * An IPAIPC instance is valid if the IPA interface is successfully created in + * isolation, and IPC is successfully set up. + * + * This flag can be read via IPAIPC::isValid(). + * + * Implementations of the IPAIPC class should set this flag upon successful + * construction. + */ + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 190d7490..e0a2ab47 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -25,6 +25,7 @@ libcamera_sources = files([ 'ipa_context_wrapper.cpp', 'ipa_controls.cpp', 'ipa_data_serializer.cpp', + 'ipa_ipc.cpp', 'ipa_interface.cpp', 'ipa_manager.cpp', 'ipa_module.cpp',