xref: /netbsd-src/sys/external/bsd/common/include/linux/tasklet.h (revision d2f5b75467682cbf3888e3cc0b56e4170669b240)
1*d2f5b754Sriastradh /*	$NetBSD: tasklet.h,v 1.7 2022/07/17 14:11:07 riastradh Exp $	*/
24e9d6760Sriastradh 
34e9d6760Sriastradh /*-
4ed61094fSriastradh  * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
54e9d6760Sriastradh  * All rights reserved.
64e9d6760Sriastradh  *
74e9d6760Sriastradh  * This code is derived from software contributed to The NetBSD Foundation
84e9d6760Sriastradh  * by Taylor R. Campbell.
94e9d6760Sriastradh  *
104e9d6760Sriastradh  * Redistribution and use in source and binary forms, with or without
114e9d6760Sriastradh  * modification, are permitted provided that the following conditions
124e9d6760Sriastradh  * are met:
134e9d6760Sriastradh  * 1. Redistributions of source code must retain the above copyright
144e9d6760Sriastradh  *    notice, this list of conditions and the following disclaimer.
154e9d6760Sriastradh  * 2. Redistributions in binary form must reproduce the above copyright
164e9d6760Sriastradh  *    notice, this list of conditions and the following disclaimer in the
174e9d6760Sriastradh  *    documentation and/or other materials provided with the distribution.
184e9d6760Sriastradh  *
194e9d6760Sriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
204e9d6760Sriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
214e9d6760Sriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
224e9d6760Sriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
234e9d6760Sriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
244e9d6760Sriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
254e9d6760Sriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
264e9d6760Sriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
274e9d6760Sriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
284e9d6760Sriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
294e9d6760Sriastradh  * POSSIBILITY OF SUCH DAMAGE.
304e9d6760Sriastradh  */
314e9d6760Sriastradh 
324e9d6760Sriastradh #ifndef	_LINUX_TASKLET_H_
334e9d6760Sriastradh #define	_LINUX_TASKLET_H_
344e9d6760Sriastradh 
354e9d6760Sriastradh /* namespace */
36ed61094fSriastradh #define	__tasklet_disable_sync_once	linux___tasklet_disable_sync_once
37ed61094fSriastradh #define	__tasklet_enable		linux___tasklet_enable
38ed61094fSriastradh #define	__tasklet_enable_sync_once	linux___tasklet_enable_sync_once
39ed61094fSriastradh #define	__tasklet_is_enabled		linux___tasklet_is_enabled
40ed61094fSriastradh #define	__tasklet_is_scheduled		linux___tasklet_is_scheduled
414e9d6760Sriastradh #define	tasklet_disable			linux_tasklet_disable
42*d2f5b754Sriastradh #define	tasklet_disable_nosync		linux_tasklet_disable_nosync
434e9d6760Sriastradh #define	tasklet_enable			linux_tasklet_enable
444e9d6760Sriastradh #define	tasklet_hi_schedule		linux_tasklet_hi_schedule
454e9d6760Sriastradh #define	tasklet_init			linux_tasklet_init
46ed61094fSriastradh #define	tasklet_is_locked		linux_tasklet_is_locked
474e9d6760Sriastradh #define	tasklet_kill			linux_tasklet_kill
484e9d6760Sriastradh #define	tasklet_schedule		linux_tasklet_schedule
494e9d6760Sriastradh #define	tasklet_struct			linux_tasklet_struct
50ed61094fSriastradh #define	tasklet_trylock			linux_tasklet_trylock
51ed61094fSriastradh #define	tasklet_unlock			linux_tasklet_unlock
52ed61094fSriastradh #define	tasklet_unlock_wait		linux_tasklet_unlock_wait
534e9d6760Sriastradh 
544e9d6760Sriastradh struct tasklet_struct {
554e9d6760Sriastradh 	SIMPLEQ_ENTRY(tasklet_struct)	tl_entry;
564e9d6760Sriastradh 	volatile unsigned		tl_state;
574e9d6760Sriastradh 	volatile unsigned		tl_disablecount;
584e9d6760Sriastradh 	/* begin Linux API */
594e9d6760Sriastradh 	void				(*func)(unsigned long);
604e9d6760Sriastradh 	unsigned long			data;
614e9d6760Sriastradh 	/* end Linux API */
624e9d6760Sriastradh };
634e9d6760Sriastradh 
644e9d6760Sriastradh #define	DEFINE_TASKLET(name, func, data)				      \
654e9d6760Sriastradh 	struct tasklet_struct name = {					      \
664e9d6760Sriastradh 	    .tl_state = 0,						      \
674e9d6760Sriastradh 	    .tl_disablecount = 0,					      \
684e9d6760Sriastradh 	    .func = (func),						      \
694e9d6760Sriastradh 	    .data = (data),						      \
704e9d6760Sriastradh 	}
714e9d6760Sriastradh 
724e9d6760Sriastradh #define	DEFINE_TASKLET_DISABLED(name, func, data)			      \
734e9d6760Sriastradh 	struct tasklet_struct name = {					      \
744e9d6760Sriastradh 	    .tl_state = 0,						      \
754e9d6760Sriastradh 	    .tl_disablecount = 1,					      \
764e9d6760Sriastradh 	    .func = (func),						      \
774e9d6760Sriastradh 	    .data = (data),						      \
784e9d6760Sriastradh 	}
794e9d6760Sriastradh 
804e9d6760Sriastradh int	linux_tasklets_init(void);
814e9d6760Sriastradh void	linux_tasklets_fini(void);
824e9d6760Sriastradh 
834e9d6760Sriastradh void	tasklet_init(struct tasklet_struct *, void (*)(unsigned long),
844e9d6760Sriastradh 	    unsigned long);
859e5fbd4fSriastradh void	tasklet_disable_nosync(struct tasklet_struct *);
864e9d6760Sriastradh void	tasklet_disable(struct tasklet_struct *);
874e9d6760Sriastradh void	tasklet_enable(struct tasklet_struct *);
884e9d6760Sriastradh void	tasklet_schedule(struct tasklet_struct *);
894e9d6760Sriastradh void	tasklet_hi_schedule(struct tasklet_struct *);
904e9d6760Sriastradh void	tasklet_kill(struct tasklet_struct *);
914e9d6760Sriastradh 
92ed61094fSriastradh bool	tasklet_is_locked(const struct tasklet_struct *);
93ed61094fSriastradh bool	tasklet_trylock(struct tasklet_struct *);
94ed61094fSriastradh void	tasklet_unlock(struct tasklet_struct *);
95ed61094fSriastradh void	tasklet_unlock_wait(const struct tasklet_struct *);
96ed61094fSriastradh 
97ed61094fSriastradh /* i915 hacks */
98ed61094fSriastradh void	__tasklet_disable_sync_once(struct tasklet_struct *);
99ed61094fSriastradh void	__tasklet_enable_sync_once(struct tasklet_struct *);
100ed61094fSriastradh bool	__tasklet_is_enabled(const struct tasklet_struct *);
101ed61094fSriastradh bool	__tasklet_is_scheduled(const struct tasklet_struct *);
102ed61094fSriastradh bool	__tasklet_enable(struct tasklet_struct *);
103075d309eSriastradh 
1044e9d6760Sriastradh #endif	/* _LINUX_TASKLET_H_ */
105