summaryrefstree
path: root/kernel/drivers/vision/npu/npu-util-autosleepthr.h
blob: 4f174958559e378cd49959791c6a793e390abf7a (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
/*
 * 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_UTIL_AUTOSLEEPTHR_H_
#define _NPU_UTIL_AUTOSLEEPTHR_H_

#include <linux/wait.h>
#include <linux/kthread.h>
#include <linux/atomic.h>

#define PRINT_NAME_LEN			64

/* TODO: Need to be extended */
struct auto_sleep_thread_param {
	void *data;
};

typedef enum {
	THREAD_STATE_NOT_INITIALIZED = 0,
	THREAD_STATE_INITIALIZED,
	THREAD_STATE_RUNNING,
	THREAD_STATE_SLEEPING,
	THREAD_STATE_TERMINATED,
	THREAD_STATE_INVALID
} auto_sleep_thread_state_e;

struct auto_sleep_thread {
	struct task_struct *thread_ref;
	wait_queue_head_t	wq;
	char	name[PRINT_NAME_LEN + 4];

	int (*do_task)(struct auto_sleep_thread_param *data);
	int (*check_work)(struct auto_sleep_thread_param *data);
	void (*on_idle)(struct auto_sleep_thread_param *data, const s64 idle_duration_ns);

	struct auto_sleep_thread_param	task_param;
	int	no_activity_threshold;
	s64	idle_start_ns;

	atomic_t	thr_state;	/* enum auto_sleep_thread_state_e */
};


/* Prototypes */
int auto_sleep_thread_create(struct auto_sleep_thread *newthr, const char *print_name,
	int (*do_task)(struct auto_sleep_thread_param *data),
	int (*check_work)(struct auto_sleep_thread_param *data),
	void (*on_idle)(struct auto_sleep_thread_param *data, s64 idle_duration_ns));
int auto_sleep_thread_start(struct auto_sleep_thread *thr, struct auto_sleep_thread_param param);
int auto_sleep_thread_terminate(struct auto_sleep_thread *thr);
void auto_sleep_thread_signal(struct auto_sleep_thread *thr);


#endif /* _NPU_UTIL_AUTOSLEEPTHR_H_ */