summaryrefstree
path: root/kernel/drivers/vision/npu/npu-if-session-protodrv.h
blob: 89d6fcce5623932889b1745ab2a23678c571e65c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Samsung Exynos SoC series NPU driver
 *
 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#ifndef _NPU_IF_SESSION_PROTODRV_H_
#define _NPU_IF_SESSION_PROTODRV_H_

#include <linux/types.h>
#include <linux/atomic.h>

#include "npu-config.h"
#include "npu-common.h"
#include "npu-errno.h"
#include "npu-util-llq.h"	/* For LLQ_task_t definition */

/*
 *  +---------+                       <For network management>                  +-------+
 *  |         |  --npu_ncp_mgmt_put()--> [ncp_mgmt_list] ---npu_buffer_q_get--> |       |
 *  |         |                                                                 | Proto |
 *  | Session |                                                                 |  drv  |
 *  |         |                        <For frame processing>                   |       |
 *  |         | --npu_buffer_q_put()--> [buffer_q_list] --npu_buffer_q_get()--> |       |
 *  |         |                                                                 |       |
 *  |         |                                                                 |       |
 *  +---------+                                                                 +-------+
 *
 */

/* Interface definition to session */
struct npu_if_session_protodrv_ops {
	void (*queue_done)(struct npu_queue *, struct vb_container_list *, struct vb_container_list *, unsigned long);
};

#ifdef CONFIG_VISION_UNITTEST
/* Allow replacement of interface function link for unit testing */
extern struct npu_if_session_protodrv_ops npu_if_session_protodrv_ops;
#endif

/* Context information */
/* Later the DECLARE_KFIFO can be replaced with dynamic allocation
   to preserve the memory when not used */
struct npu_if_session_protodrv_ctx {
	spinlock_t buffer_q_lock;
	DECLARE_KFIFO(buffer_q_list, struct npu_frame, BUFFER_Q_LIST_SIZE);
	LLQ_task_t buffer_q_callback;

	spinlock_t ncp_mgmt_lock;
	DECLARE_KFIFO(ncp_mgmt_list, struct npu_nw, NCP_MGMT_LIST_SIZE);
	LLQ_task_t ncp_mgmt_callback;

	atomic_t	is_opened;
};

/* Initializer and deallocator */
struct npu_if_session_protodrv_ctx *npu_if_session_protodrv_ctx_open(void);
void npu_if_session_protodrv_ctx_close(void);
int npu_if_session_protodrv_is_opened(void);

/* Operations for buffer_q */
int npu_buffer_q_get(struct npu_frame *frame);
int npu_buffer_q_put(const struct npu_frame *frame);
int npu_buffer_q_is_available(void);
void npu_buffer_q_register_cb(LLQ_task_t cb);
void npu_buffer_q_notify_done(const struct npu_frame *frame);

/* Operations for ncp_mgmt */
int npu_ncp_mgmt_get(struct npu_nw *nw);
int npu_ncp_mgmt_put(const struct npu_nw *nw);
int npu_ncp_mgmt_is_available(void);
void npu_ncp_mgmt_register_cb(LLQ_task_t cb);

/* Save result operation */
int npu_ncp_mgmt_save_result(
	save_result_func notify_func,
	struct npu_session *sess,
	struct nw_result result);
#endif	/* _NPU_IF_SESSION_PROTODRV_H_ */