/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/*
 * Copyright (c) 2020 MediaTek Inc.
 */

#ifndef __MDLA_PLAT_MODEL_H__
#define __MDLA_PLAT_MODEL_H__

#include <linux/types.h>
#include <linux/time.h>
#include <linux/types.h>
#include <linux/completion.h>
#include <asm/atomic.h>
#include <interface/mdla_cmd_data_v2_0.h>
#include "mdla_ioctl.h"

struct model_param {
	void *user;
	uint32_t pipe_id;
	uint32_t num_model;
	uint32_t num_buf;
	struct mdla_svp_buf buf_info[MAX_SVP_BUF_PER_CMD];
	struct list_head mp_list;
	struct list_head mi_list;
	struct kref refcount;

};

struct model_data {
	struct model_info *model;
	struct kref refcount;
	struct list_head list;
	u32 size;
	u8 data[];
};

struct model_info {
	struct list_head mt_list;
	struct completion cmplt;
	u32 model_idx;
	u32 model_ctx;
	u32 owner;
	struct kref refcount;
	struct list_head mdata;
	struct list_head mdata_del;

	u64 cmdbuf_addr;
	u32 cmdbuf_size;
	u32 model_offset;

	struct model_param *param;
	struct list_head pmi_list;
};

int mdla_plat_model_reset(void);
void mdla_plat_model_dump_info(struct seq_file *s);
int mdla_plat_model_set_data(u32 model_idx, u32 size, void *data);
int mdla_plat_model_get_data(u32 model_idx, void **data);
int mdla_plat_model_put_data(u32 model_idx, void *data);
int mdla_plat_model_get(u32 model_idx, void **model);
int mdla_plat_model_put(void *model);
int mdla_plat_model_load(void *data);
int mdla_plat_model_unload(void *data);

int mdla_plat_model_param_update(void *user, void *data);
int mdla_plat_model_param_reset(void *user, void *data);
int mdla_plat_model_param_release(void *user);
bool model_check_runable(void *data);

#endif
