xref: /dflybsd-src/sys/dev/drm/include/linux/stop_machine.h (revision 19830eedddd7418a8c51f9d6d67713bc0eb33432)
1d6aa1cc5SFrançois Tigeot /*
2cd05b29eSFrançois Tigeot  * Copyright (c) 2018-2020 François Tigeot <ftigeot@wolfpond.org>
3d6aa1cc5SFrançois Tigeot  * All rights reserved.
4d6aa1cc5SFrançois Tigeot  *
5d6aa1cc5SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
6d6aa1cc5SFrançois Tigeot  * modification, are permitted provided that the following conditions
7d6aa1cc5SFrançois Tigeot  * are met:
8d6aa1cc5SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
9d6aa1cc5SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
10d6aa1cc5SFrançois Tigeot  *    disclaimer.
11d6aa1cc5SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
12d6aa1cc5SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
13d6aa1cc5SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
14d6aa1cc5SFrançois Tigeot  *
15d6aa1cc5SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16d6aa1cc5SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17d6aa1cc5SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18d6aa1cc5SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19d6aa1cc5SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20d6aa1cc5SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21d6aa1cc5SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22d6aa1cc5SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23d6aa1cc5SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24d6aa1cc5SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25d6aa1cc5SFrançois Tigeot  */
26d6aa1cc5SFrançois Tigeot 
27d6aa1cc5SFrançois Tigeot #ifndef _LINUX_STOP_MACHINE_H_
28d6aa1cc5SFrançois Tigeot #define _LINUX_STOP_MACHINE_H_
29d6aa1cc5SFrançois Tigeot 
30d6aa1cc5SFrançois Tigeot #include <linux/cpumask.h>
31111dab5bSFrançois Tigeot #include <linux/smp.h>
32d6aa1cc5SFrançois Tigeot #include <linux/list.h>
33d6aa1cc5SFrançois Tigeot 
34cd05b29eSFrançois Tigeot #include <sys/mplock2.h>
35cd05b29eSFrançois Tigeot 
36cd05b29eSFrançois Tigeot typedef int (*cpu_stop_fn_t)(void *arg);
37cd05b29eSFrançois Tigeot 
38cd05b29eSFrançois Tigeot static inline int
stop_machine(cpu_stop_fn_t fn,void * data,const struct cpumask * cpus)39cd05b29eSFrançois Tigeot stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
40cd05b29eSFrançois Tigeot {
41*19830eedSFrançois Tigeot 	int res;
42*19830eedSFrançois Tigeot 
43cd05b29eSFrançois Tigeot 	/* XXX: is this enough ?
44cd05b29eSFrançois Tigeot 	 * See Linux commit 5bab6f60cb4d1417ad7c599166bcfec87529c1a2 */
45cd05b29eSFrançois Tigeot        get_mplock();
46*19830eedSFrançois Tigeot        res = (*fn)(data);
47cd05b29eSFrançois Tigeot        rel_mplock();
48*19830eedSFrançois Tigeot 
49*19830eedSFrançois Tigeot        return res;
50cd05b29eSFrançois Tigeot }
51cd05b29eSFrançois Tigeot 
52d6aa1cc5SFrançois Tigeot #endif	/* _LINUX_STOP_MACHINE_H_ */
53