linux/drivers/media/platform/mediatek/vpu/mtk_vpu.c

// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: Andrew-CT Chen <[email protected]>
*/
#include <linux/clk.h>
#include <linux/debugfs.h>
#include <linux/firmware.h>
#include <linux/interrupt.h>
#include <linux/iommu.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/of_reserved_mem.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <linux/sizes.h>
#include <linux/dma-mapping.h>

#include "mtk_vpu.h"

/*
 * VPU (video processor unit) is a tiny processor controlling video hardware
 * related to video codec, scaling and color format converting.
 * VPU interfaces with other blocks by share memory and interrupt.
 */

#define INIT_TIMEOUT_MS
#define IPI_TIMEOUT_MS
#define VPU_IDLE_TIMEOUT_MS
#define VPU_FW_VER_LEN

/* maximum program/data TCM (Tightly-Coupled Memory) size */
#define VPU_PTCM_SIZE
#define VPU_DTCM_SIZE
/* the offset to get data tcm address */
#define VPU_DTCM_OFFSET
/* daynamic allocated maximum extended memory size */
#define VPU_EXT_P_SIZE
#define VPU_EXT_D_SIZE
/* maximum binary firmware size */
#define VPU_P_FW_SIZE
#define VPU_D_FW_SIZE
/* the size of share buffer between Host and  VPU */
#define SHARE_BUF_SIZE

/* binary firmware name */
#define VPU_P_FW
#define VPU_D_FW
#define VPU_P_FW_NEW
#define VPU_D_FW_NEW

#define VPU_RESET
#define VPU_TCM_CFG
#define VPU_PMEM_EXT0_ADDR
#define VPU_PMEM_EXT1_ADDR
#define VPU_TO_HOST
#define VPU_DMEM_EXT0_ADDR
#define VPU_DMEM_EXT1_ADDR
#define HOST_TO_VPU
#define VPU_IDLE_REG
#define VPU_INT_STATUS
#define VPU_PC_REG
#define VPU_SP_REG
#define VPU_RA_REG
#define VPU_WDT_REG

/* vpu inter-processor communication interrupt */
#define VPU_IPC_INT
/* vpu idle state */
#define VPU_IDLE_STATE

/**
 * enum vpu_fw_type - VPU firmware type
 *
 * @P_FW: program firmware
 * @D_FW: data firmware
 *
 */
enum vpu_fw_type {};

/**
 * struct vpu_mem - VPU extended program/data memory information
 *
 * @va:		the kernel virtual memory address of VPU extended memory
 * @pa:		the physical memory address of VPU extended memory
 *
 */
struct vpu_mem {};

/**
 * struct vpu_regs - VPU TCM and configuration registers
 *
 * @tcm:	the register for VPU Tightly-Coupled Memory
 * @cfg:	the register for VPU configuration
 * @irq:	the irq number for VPU interrupt
 */
struct vpu_regs {};

/**
 * struct vpu_wdt_handler - VPU watchdog reset handler
 *
 * @reset_func:	reset handler
 * @priv:	private data
 */
struct vpu_wdt_handler {};

/**
 * struct vpu_wdt - VPU watchdog workqueue
 *
 * @handler:	VPU watchdog reset handler
 * @ws:		workstruct for VPU watchdog
 * @wq:		workqueue for VPU watchdog
 */
struct vpu_wdt {};

/**
 * struct vpu_run - VPU initialization status
 *
 * @signaled:		the signal of vpu initialization completed
 * @fw_ver:		VPU firmware version
 * @dec_capability:	decoder capability which is not used for now and
 *			the value is reserved for future use
 * @enc_capability:	encoder capability which is not used for now and
 *			the value is reserved for future use
 * @wq:			wait queue for VPU initialization status
 */
struct vpu_run {};

/**
 * struct vpu_ipi_desc - VPU IPI descriptor
 *
 * @handler:	IPI handler
 * @name:	the name of IPI handler
 * @priv:	the private data of IPI handler
 */
struct vpu_ipi_desc {};

/**
 * struct share_obj - DTCM (Data Tightly-Coupled Memory) buffer shared with
 *		      AP and VPU
 *
 * @id:		IPI id
 * @len:	share buffer length
 * @share_buf:	share buffer data
 */
struct share_obj {};

/**
 * struct mtk_vpu - vpu driver data
 * @extmem:		VPU extended memory information
 * @reg:		VPU TCM and configuration registers
 * @run:		VPU initialization status
 * @wdt:		VPU watchdog workqueue
 * @ipi_desc:		VPU IPI descriptor
 * @recv_buf:		VPU DTCM share buffer for receiving. The
 *			receive buffer is only accessed in interrupt context.
 * @send_buf:		VPU DTCM share buffer for sending
 * @dev:		VPU struct device
 * @clk:		VPU clock on/off
 * @fw_loaded:		indicate VPU firmware loaded
 * @enable_4GB:		VPU 4GB mode on/off
 * @vpu_mutex:		protect mtk_vpu (except recv_buf) and ensure only
 *			one client to use VPU service at a time. For example,
 *			suppose a client is using VPU to decode VP8.
 *			If the other client wants to encode VP8,
 *			it has to wait until VP8 decode completes.
 * @wdt_refcnt:		WDT reference count to make sure the watchdog can be
 *			disabled if no other client is using VPU service
 * @ack_wq:		The wait queue for each codec and mdp. When sleeping
 *			processes wake up, they will check the condition
 *			"ipi_id_ack" to run the corresponding action or
 *			go back to sleep.
 * @ipi_id_ack:		The ACKs for registered IPI function sending
 *			interrupt to VPU
 *
 */
struct mtk_vpu {};

static inline void vpu_cfg_writel(struct mtk_vpu *vpu, u32 val, u32 offset)
{}

static inline u32 vpu_cfg_readl(struct mtk_vpu *vpu, u32 offset)
{}

static inline bool vpu_running(struct mtk_vpu *vpu)
{}

static void vpu_clock_disable(struct mtk_vpu *vpu)
{}

static int vpu_clock_enable(struct mtk_vpu *vpu)
{}

static void vpu_dump_status(struct mtk_vpu *vpu)
{}

int vpu_ipi_register(struct platform_device *pdev,
		     enum ipi_id id, ipi_handler_t handler,
		     const char *name, void *priv)
{}
EXPORT_SYMBOL_GPL();

int vpu_ipi_send(struct platform_device *pdev,
		 enum ipi_id id, void *buf,
		 unsigned int len)
{}
EXPORT_SYMBOL_GPL();

static void vpu_wdt_reset_func(struct work_struct *ws)
{}

int vpu_wdt_reg_handler(struct platform_device *pdev,
			void wdt_reset(void *),
			void *priv, enum rst_id id)
{}
EXPORT_SYMBOL_GPL();

unsigned int vpu_get_vdec_hw_capa(struct platform_device *pdev)
{}
EXPORT_SYMBOL_GPL();

unsigned int vpu_get_venc_hw_capa(struct platform_device *pdev)
{}
EXPORT_SYMBOL_GPL();

void *vpu_mapping_dm_addr(struct platform_device *pdev,
			  u32 dtcm_dmem_addr)
{}
EXPORT_SYMBOL_GPL();

struct platform_device *vpu_get_plat_device(struct platform_device *pdev)
{}
EXPORT_SYMBOL_GPL();

/* load vpu program/data memory */
static int load_requested_vpu(struct mtk_vpu *vpu,
			      u8 fw_type)
{}

int vpu_load_firmware(struct platform_device *pdev)
{}
EXPORT_SYMBOL_GPL();

static void vpu_init_ipi_handler(void *data, unsigned int len, void *priv)
{}

#ifdef CONFIG_DEBUG_FS
static ssize_t vpu_debug_read(struct file *file, char __user *user_buf,
			      size_t count, loff_t *ppos)
{}

static const struct file_operations vpu_debug_fops =;
#endif /* CONFIG_DEBUG_FS */

static void vpu_free_ext_mem(struct mtk_vpu *vpu, u8 fw_type)
{}

static int vpu_alloc_ext_mem(struct mtk_vpu *vpu, u32 fw_type)
{}

static void vpu_ipi_handler(struct mtk_vpu *vpu)
{}

static int vpu_ipi_init(struct mtk_vpu *vpu)
{}

static irqreturn_t vpu_irq_handler(int irq, void *priv)
{}

#ifdef CONFIG_DEBUG_FS
static struct dentry *vpu_debugfs;
#endif
static int mtk_vpu_probe(struct platform_device *pdev)
{}

static const struct of_device_id mtk_vpu_match[] =;
MODULE_DEVICE_TABLE(of, mtk_vpu_match);

static void mtk_vpu_remove(struct platform_device *pdev)
{}

static int mtk_vpu_suspend(struct device *dev)
{}

static int mtk_vpu_resume(struct device *dev)
{}

static const struct dev_pm_ops mtk_vpu_pm =;

static struct platform_driver mtk_vpu_driver =;

module_platform_driver();

MODULE_LICENSE();
MODULE_DESCRIPTION();