/* SPDX-License-Identifier: GPL-2.0-only */


#ifndef __LINUX_fastrpc_H
#define __LINUX_fastrpc_H

#include <linux/device.h>
#include <linux/errno.h>
#include <linux/kernel.h>

#define FASTRPC_DRV_NAME_SIZE 32

enum fastrpc_driver_status {
	FASTRPC_PROC_DOWN = 0,
};
enum fastrpc_driver_invoke_nums {
	FASTRPC_DEV_MAP_DMA = 1,
	FASTRPC_DEV_UNMAP_DMA,
	FASTRPC_DEV_GET_HLOS_PID,
};


struct fastrpc_dev_map_dma {
	struct dma_buf *buf;
	uint32_t attrs;
	size_t size;
	uint64_t v_dsp_addr;
};


struct fastrpc_dev_unmap_dma {
	struct dma_buf *buf;
	size_t size;
};


struct fastrpc_dev_get_hlos_pid {
	int hlos_pid;
};


struct fastrpc_device {
	struct hlist_node hn;
	struct device dev;
	int handle;
	struct fastrpc_file *fl;
	bool dev_close;
	unsigned int refs;
};

#define to_fastrpc_device(d) container_of(d, struct fastrpc_device, dev)


struct fastrpc_driver {
	struct hlist_node hn;
	struct device_driver driver;
	struct device *device;
	int handle;
	int create;
	int (*probe)(struct fastrpc_device *dev);
	int (*callback)(struct fastrpc_device *dev,
					enum fastrpc_driver_status status);
};

#define to_fastrpc_driver(x) container_of((x), struct fastrpc_driver, driver)

#if IS_ENABLED(CONFIG_MSM_ADSPRPC) || IS_ENABLED(CONFIG_MSM_ADSPRPC_TRUSTED)

int fastrpc_driver_register(struct fastrpc_driver *drv);


void fastrpc_driver_unregister(struct fastrpc_driver *drv);


long fastrpc_driver_invoke(struct fastrpc_device *dev,
	enum fastrpc_driver_invoke_nums invoke_num, unsigned long invoke_param);

#else
static inline int fastrpc_driver_register(struct fastrpc_driver *drv)
{   return 0;   }

static inline void fastrpc_driver_unregister(struct fastrpc_driver *drv)
{   return;     }

static inline long fastrpc_driver_invoke(struct fastrpc_device *dev,
	enum fastrpc_driver_invoke_nums invoke_num, unsigned long invoke_param)
{   return 0;   }
#endif


#define module_fastrpc_driver(__fastrpc_driver) \
static int __init __fastrpc_driver##_init(void) \
{ \
	return fastrpc_driver_register(&(__fastrpc_driver)); \
} \
module_init(__fastrpc_driver##_init); \
static void __exit __fastrpc_driver##_exit(void) \
{ \
	fastrpc_driver_unregister(&(__fastrpc_driver)); \
} \
module_exit(__fastrpc_driver##_exit)

#endif 
