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

#ifndef MDRV_DEMUX_RESOURCE_H
#define MDRV_DEMUX_RESOURCE_H

#include <linux/types.h>

#define HEAP_TYPE_IOMMU		0
#define HEAP_TYPE_CMA		1
#define HEAP_TYPE_NON_MMA	2

// buf id
#define VDEC_ES_BUF_ID		2
#define PVR_BUF_ID			16

// alignment
#define DMX_IOVA_ALIGN		4096

enum memmap_buf_type {
	MEMMAP_FW_BUF,
	MEMMAP_VQ_BUF,
	MEMMAP_SEC_BUF,
	MEMMAP_PVR_BUF,
	MEMMAP_FILEIN_BUF,
	MEMMAP_FQ_BUF,
	MEMMAP_TSO_SVQ_BUF,
	MEMMAP_MODULE_TYPE_MAX,
	MEMMAP_MODULE_TYPE_NULL = -1
};

struct mem_info {
	void __iomem *vaddr;
	u64 paddr;
	u32 size;
	u32 heaptype;
	int id;
	int dmabuf_fd;
	struct dma_buf *db;
};

struct mdrv_demux_memmap {
	struct mdrv_demux_res *res;
	struct kobject kobj;
	struct mem_info *fw_buf;
	struct mem_info *section_buf;
	struct mem_info *vq_buf, *svq_buf;
	struct mem_info *pvr_buf, *filein_buf;
	struct mem_info *fq_buf;
};

struct mdrv_demux_hwcaps {
	struct mdrv_demux_res *res;
	struct kobject kobj;
	u32 pid_filter_num, sec_filter_num;
	u32 stc_num, pcr_filter_num;
	u32 ip_filter_num, ntp_filter_num;
	u32 alp_filter_num;
	u32 vfifo_num, afifo_num;
	u32 pvr_num;
	u32 vq_num, svq_num;
	u32 livein_num, merge_stream_num;
	u32 filein_num, filein_cmdQ_num;
	u32 mmfi_num, mmfi_filter_num, mmfi_cmdQ_num;
	u32 fiq_num;
	u32 tso_num;
	u32 tso_tsif_num;
	u32 tlv_num;
	u32 cilink_num;
	u32 alp_num;
	u32 parser_ck_rate;
};

struct mdrv_demux_regmaps {
	struct mdrv_demux_res *res;
	mtk_demux_riu_banks riu_banks;
};

struct mdrv_demux_res {
	struct kobject kobj;
	struct mdrv_demux_hwcaps *hwcaps;
	struct mdrv_demux_memmap *memmap;
	struct mdrv_demux_regmaps *regmaps;
};

int mdrv_demux_res_init(struct platform_device *pdev, struct mdrv_demux_res *pres);
int mdrv_demux_res_exit(struct platform_device *pdev, struct mdrv_demux_res *pres);

int mdrv_demux_get_memory(struct platform_device *pdev, enum memmap_buf_type type, u16 eng_num,
						struct mem_info **pmem_info, u32 buf_size);
void mdrv_demux_put_memory(struct platform_device *pdev, struct mem_info *pmem_info, u16 eng_num);

#endif				/* MDRV_DEMUX_RESOURCE_H */
