1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Keystone Navigator Queue Management Sub-System header
4  *
5  * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com
6  * Author:	Sandeep Nair <sandeep_n@ti.com>
7  *		Cyril Chemparathy <cyril@ti.com>
8  *		Santosh Shilimkar <santosh.shilimkar@ti.com>
9  */
10 
11 #ifndef __SOC_TI_KNAV_QMSS_H__
12 #define __SOC_TI_KNAV_QMSS_H__
13 
14 #include <linux/err.h>
15 #include <linux/time.h>
16 #include <linux/atomic.h>
17 #include <linux/device.h>
18 #include <linux/fcntl.h>
19 #include <linux/dma-mapping.h>
20 
21 /* queue types */
22 #define KNAV_QUEUE_QPEND	((unsigned)-2) /* interruptible qpend queue */
23 #define KNAV_QUEUE_ACC		((unsigned)-3) /* Accumulated queue */
24 #define KNAV_QUEUE_GP		((unsigned)-4) /* General purpose queue */
25 
26 /* queue flags */
27 #define KNAV_QUEUE_SHARED	0x0001		/* Queue can be shared */
28 
29 /**
30  * enum knav_queue_ctrl_cmd -	queue operations.
31  * @KNAV_QUEUE_GET_ID:		Get the ID number for an open queue
32  * @KNAV_QUEUE_FLUSH:		forcibly empty a queue if possible
33  * @KNAV_QUEUE_SET_NOTIFIER:	Set a notifier callback to a queue handle.
34  * @KNAV_QUEUE_ENABLE_NOTIFY:	Enable notifier callback for a queue handle.
35  * @KNAV_QUEUE_DISABLE_NOTIFY:	Disable notifier callback for a queue handle.
36  * @KNAV_QUEUE_GET_COUNT:	Get number of queues.
37  */
38 enum knav_queue_ctrl_cmd {
39 	KNAV_QUEUE_GET_ID,
40 	KNAV_QUEUE_FLUSH,
41 	KNAV_QUEUE_SET_NOTIFIER,
42 	KNAV_QUEUE_ENABLE_NOTIFY,
43 	KNAV_QUEUE_DISABLE_NOTIFY,
44 	KNAV_QUEUE_GET_COUNT
45 };
46 
47 /* Queue notifier callback prototype */
48 typedef void (*knav_queue_notify_fn)(void *arg);
49 
50 /**
51  * struct knav_queue_notify_config:	Notifier configuration
52  * @fn:					Notifier function
53  * @fn_arg:				Notifier function arguments
54  */
55 struct knav_queue_notify_config {
56 	knav_queue_notify_fn fn;
57 	void *fn_arg;
58 };
59 
60 void *knav_queue_open(const char *name, unsigned id,
61 					unsigned flags);
62 void knav_queue_close(void *qhandle);
63 int knav_queue_device_control(void *qhandle,
64 				enum knav_queue_ctrl_cmd cmd,
65 				unsigned long arg);
66 dma_addr_t knav_queue_pop(void *qhandle, unsigned *size);
67 int knav_queue_push(void *qhandle, dma_addr_t dma,
68 				unsigned size, unsigned flags);
69 
70 void *knav_pool_create(const char *name,
71 				int num_desc, int region_id);
72 void knav_pool_destroy(void *ph);
73 int knav_pool_count(void *ph);
74 void *knav_pool_desc_get(void *ph);
75 void knav_pool_desc_put(void *ph, void *desc);
76 int knav_pool_desc_map(void *ph, void *desc, unsigned size,
77 					dma_addr_t *dma, unsigned *dma_sz);
78 void *knav_pool_desc_unmap(void *ph, dma_addr_t dma, unsigned dma_sz);
79 dma_addr_t knav_pool_desc_virt_to_dma(void *ph, void *virt);
80 void *knav_pool_desc_dma_to_virt(void *ph, dma_addr_t dma);
81 bool knav_qmss_device_ready(void);
82 
83 #endif /* __SOC_TI_KNAV_QMSS_H__ */
84