blob: 7f881e481f3c54e8cb65d61582ffd87790e5b285 [file] [log] [blame]
/*
*Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
*Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
*WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
*MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
*ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
*BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
*CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
*SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
*WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
*OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
*IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __IPC_IMPL_H__
#define __IPC_IMPL_H__
#include <core/ipc_interface.h>
#include <vendor/qti/hardware/display/demura/2.0/IDemuraFileFinder.h>
#include <thread>
#include "qrtr_client_interface.h"
#include "vm_interface.h"
#include "utils/sys.h"
#include "membuf_wrapper.h"
namespace sdm {
using ::android::sp;
using ::vendor::qti::hardware::display::demura::V2_0::IDemuraFileFinder;
#define MEMBUF_CLIENT_LIB_NAME "libmemutils.so"
#define CREATE_MEMBUF_INTERFACE_NAME "CreateMemBufInterface"
#define DESTROY_MEMBUF_INTERFACE_NAME "DestroyMemBufInterface"
typedef int (*GetMemBufInterface)(MemBuf **mem_buf_hnd);
typedef int (*PutMemBufInterface)();
class IPCImpl: public IPCIntf, QRTRCallbackInterface {
public:
virtual ~IPCImpl() {};
int Init();
int Deinit();
int SetParameter(IPCParams param, const GenericPayload &in);
int GetParameter(IPCParams param, GenericPayload *out);
int ProcessOps(IPCOps op, const GenericPayload &in, GenericPayload *out);
void OnServerReady();
void OnServerExit();
int OnResponse(void *rsp_buf, size_t rsp_size);
static void SpawnOnServerReady(int client_id);
private:
int ProcessExportBuffers(const GenericPayload &in, GenericPayload *out);
static DynLib qrtr_client_lib_;
static CreateQrtrClientIntf create_qrtr_client_intf_;
static DestroyQrtrClientIntf destroy_qrtr_client_intf_;
static QRTRClientInterface *qrtr_client_intf_;
bool init_done_ = false;
static std::mutex vm_lock_;
static int client_id_;
static bool server_ready_;
static std::map<int, IPCVmCallbackIntf*> callbacks_;
static MemBuf *mem_buf_;
static DynLib mem_buf_client_lib_;
static GetMemBufInterface GetMemBuf;
static PutMemBufInterface PutMembuf;
};
} // namespace sdm
#endif