xref: /netbsd-src/sys/external/bsd/common/include/linux/tasklet.h (revision 53b02e147d4ed531c0d2a5ca9b3e8026ba3e99b5)
1 /*	$NetBSD: tasklet.h,v 1.6 2021/12/19 11:49:11 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_enable			linux_tasklet_enable
43 #define	tasklet_hi_schedule		linux_tasklet_hi_schedule
44 #define	tasklet_init			linux_tasklet_init
45 #define	tasklet_is_locked		linux_tasklet_is_locked
46 #define	tasklet_kill			linux_tasklet_kill
47 #define	tasklet_schedule		linux_tasklet_schedule
48 #define	tasklet_struct			linux_tasklet_struct
49 #define	tasklet_trylock			linux_tasklet_trylock
50 #define	tasklet_unlock			linux_tasklet_unlock
51 #define	tasklet_unlock_wait		linux_tasklet_unlock_wait
52 
53 struct tasklet_struct {
54 	SIMPLEQ_ENTRY(tasklet_struct)	tl_entry;
55 	volatile unsigned		tl_state;
56 	volatile unsigned		tl_disablecount;
57 	/* begin Linux API */
58 	void				(*func)(unsigned long);
59 	unsigned long			data;
60 	/* end Linux API */
61 };
62 
63 #define	DEFINE_TASKLET(name, func, data)				      \
64 	struct tasklet_struct name = {					      \
65 	    .tl_state = 0,						      \
66 	    .tl_disablecount = 0,					      \
67 	    .func = (func),						      \
68 	    .data = (data),						      \
69 	}
70 
71 #define	DEFINE_TASKLET_DISABLED(name, func, data)			      \
72 	struct tasklet_struct name = {					      \
73 	    .tl_state = 0,						      \
74 	    .tl_disablecount = 1,					      \
75 	    .func = (func),						      \
76 	    .data = (data),						      \
77 	}
78 
79 int	linux_tasklets_init(void);
80 void	linux_tasklets_fini(void);
81 
82 void	tasklet_init(struct tasklet_struct *, void (*)(unsigned long),
83 	    unsigned long);
84 void	tasklet_disable_nosync(struct tasklet_struct *);
85 void	tasklet_disable(struct tasklet_struct *);
86 void	tasklet_enable(struct tasklet_struct *);
87 void	tasklet_schedule(struct tasklet_struct *);
88 void	tasklet_hi_schedule(struct tasklet_struct *);
89 void	tasklet_kill(struct tasklet_struct *);
90 
91 bool	tasklet_is_locked(const struct tasklet_struct *);
92 bool	tasklet_trylock(struct tasklet_struct *);
93 void	tasklet_unlock(struct tasklet_struct *);
94 void	tasklet_unlock_wait(const struct tasklet_struct *);
95 
96 /* i915 hacks */
97 void	__tasklet_disable_sync_once(struct tasklet_struct *);
98 void	__tasklet_enable_sync_once(struct tasklet_struct *);
99 bool	__tasklet_is_enabled(const struct tasklet_struct *);
100 bool	__tasklet_is_scheduled(const struct tasklet_struct *);
101 bool	__tasklet_enable(struct tasklet_struct *);
102 
103 #endif	/* _LINUX_TASKLET_H_ */
104