xref: /netbsd-src/sys/external/bsd/common/include/linux/tasklet.h (revision d2f5b75467682cbf3888e3cc0b56e4170669b240)
1 /*	$NetBSD: tasklet.h,v 1.7 2022/07/17 14:11:07 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Taylor R. Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef	_LINUX_TASKLET_H_
33 #define	_LINUX_TASKLET_H_
34 
35 /* namespace */
36 #define	__tasklet_disable_sync_once	linux___tasklet_disable_sync_once
37 #define	__tasklet_enable		linux___tasklet_enable
38 #define	__tasklet_enable_sync_once	linux___tasklet_enable_sync_once
39 #define	__tasklet_is_enabled		linux___tasklet_is_enabled
40 #define	__tasklet_is_scheduled		linux___tasklet_is_scheduled
41 #define	tasklet_disable			linux_tasklet_disable
42 #define	tasklet_disable_nosync		linux_tasklet_disable_nosync
43 #define	tasklet_enable			linux_tasklet_enable
44 #define	tasklet_hi_schedule		linux_tasklet_hi_schedule
45 #define	tasklet_init			linux_tasklet_init
46 #define	tasklet_is_locked		linux_tasklet_is_locked
47 #define	tasklet_kill			linux_tasklet_kill
48 #define	tasklet_schedule		linux_tasklet_schedule
49 #define	tasklet_struct			linux_tasklet_struct
50 #define	tasklet_trylock			linux_tasklet_trylock
51 #define	tasklet_unlock			linux_tasklet_unlock
52 #define	tasklet_unlock_wait		linux_tasklet_unlock_wait
53 
54 struct tasklet_struct {
55 	SIMPLEQ_ENTRY(tasklet_struct)	tl_entry;
56 	volatile unsigned		tl_state;
57 	volatile unsigned		tl_disablecount;
58 	/* begin Linux API */
59 	void				(*func)(unsigned long);
60 	unsigned long			data;
61 	/* end Linux API */
62 };
63 
64 #define	DEFINE_TASKLET(name, func, data)				      \
65 	struct tasklet_struct name = {					      \
66 	    .tl_state = 0,						      \
67 	    .tl_disablecount = 0,					      \
68 	    .func = (func),						      \
69 	    .data = (data),						      \
70 	}
71 
72 #define	DEFINE_TASKLET_DISABLED(name, func, data)			      \
73 	struct tasklet_struct name = {					      \
74 	    .tl_state = 0,						      \
75 	    .tl_disablecount = 1,					      \
76 	    .func = (func),						      \
77 	    .data = (data),						      \
78 	}
79 
80 int	linux_tasklets_init(void);
81 void	linux_tasklets_fini(void);
82 
83 void	tasklet_init(struct tasklet_struct *, void (*)(unsigned long),
84 	    unsigned long);
85 void	tasklet_disable_nosync(struct tasklet_struct *);
86 void	tasklet_disable(struct tasklet_struct *);
87 void	tasklet_enable(struct tasklet_struct *);
88 void	tasklet_schedule(struct tasklet_struct *);
89 void	tasklet_hi_schedule(struct tasklet_struct *);
90 void	tasklet_kill(struct tasklet_struct *);
91 
92 bool	tasklet_is_locked(const struct tasklet_struct *);
93 bool	tasklet_trylock(struct tasklet_struct *);
94 void	tasklet_unlock(struct tasklet_struct *);
95 void	tasklet_unlock_wait(const struct tasklet_struct *);
96 
97 /* i915 hacks */
98 void	__tasklet_disable_sync_once(struct tasklet_struct *);
99 void	__tasklet_enable_sync_once(struct tasklet_struct *);
100 bool	__tasklet_is_enabled(const struct tasklet_struct *);
101 bool	__tasklet_is_scheduled(const struct tasklet_struct *);
102 bool	__tasklet_enable(struct tasklet_struct *);
103 
104 #endif	/* _LINUX_TASKLET_H_ */
105