xref: /minix3/sys/sys/lwpctl.h (revision 6c8f7fc3bac7ab5f78ee27de8bed706631d8c836)
1*6c8f7fc3SBen Gras /*	$NetBSD: lwpctl.h,v 1.4 2008/04/28 20:24:10 martin Exp $	*/
2*6c8f7fc3SBen Gras 
3*6c8f7fc3SBen Gras /*-
4*6c8f7fc3SBen Gras  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
5*6c8f7fc3SBen Gras  * All rights reserved.
6*6c8f7fc3SBen Gras  *
7*6c8f7fc3SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
8*6c8f7fc3SBen Gras  * by Andrew Doran.
9*6c8f7fc3SBen Gras  *
10*6c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
11*6c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
12*6c8f7fc3SBen Gras  * are met:
13*6c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
14*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
15*6c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
16*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
17*6c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
18*6c8f7fc3SBen Gras  *
19*6c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*6c8f7fc3SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*6c8f7fc3SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*6c8f7fc3SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*6c8f7fc3SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*6c8f7fc3SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*6c8f7fc3SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*6c8f7fc3SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*6c8f7fc3SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*6c8f7fc3SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*6c8f7fc3SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
30*6c8f7fc3SBen Gras  */
31*6c8f7fc3SBen Gras 
32*6c8f7fc3SBen Gras #if !defined(_SYS_LWPCTL_H_)
33*6c8f7fc3SBen Gras #define	_SYS_LWPCTL_H_
34*6c8f7fc3SBen Gras 
35*6c8f7fc3SBen Gras /*
36*6c8f7fc3SBen Gras  * Note on compatibility:
37*6c8f7fc3SBen Gras  *
38*6c8f7fc3SBen Gras  * This must be the same size for both 32 and 64-bit processes, since
39*6c8f7fc3SBen Gras  * the same format will be used by both.
40*6c8f7fc3SBen Gras  *
41*6c8f7fc3SBen Gras  * Removal of unused fields is OK, as long as the change in layout
42*6c8f7fc3SBen Gras  * does not affect supported fields.
43*6c8f7fc3SBen Gras  *
44*6c8f7fc3SBen Gras  * It is OK to add fields to this structure, since the kernel allocates
45*6c8f7fc3SBen Gras  * the space.  Re-use of fields is more complicated - see the feature
46*6c8f7fc3SBen Gras  * word passed to the system call.
47*6c8f7fc3SBen Gras  */
48*6c8f7fc3SBen Gras typedef struct lwpctl {
49*6c8f7fc3SBen Gras 	volatile int	lc_curcpu;
50*6c8f7fc3SBen Gras 	volatile int	lc_pctr;
51*6c8f7fc3SBen Gras } lwpctl_t;
52*6c8f7fc3SBen Gras 
53*6c8f7fc3SBen Gras #define	LWPCTL_CPU_NONE		(-1)
54*6c8f7fc3SBen Gras #define	LWPCTL_CPU_EXITED	(-2)
55*6c8f7fc3SBen Gras 
56*6c8f7fc3SBen Gras #define	LWPCTL_FEATURE_CURCPU	0x00000001
57*6c8f7fc3SBen Gras #define	LWPCTL_FEATURE_PCTR	0x00000002
58*6c8f7fc3SBen Gras 
59*6c8f7fc3SBen Gras #if defined(_KERNEL)
60*6c8f7fc3SBen Gras 
61*6c8f7fc3SBen Gras #include <sys/mutex.h>
62*6c8f7fc3SBen Gras 
63*6c8f7fc3SBen Gras #include <uvm/uvm_extern.h>
64*6c8f7fc3SBen Gras 
65*6c8f7fc3SBen Gras typedef struct lcpage {
66*6c8f7fc3SBen Gras 	TAILQ_ENTRY(lcpage) lcp_chain;
67*6c8f7fc3SBen Gras 	vaddr_t		lcp_uaddr;
68*6c8f7fc3SBen Gras 	vaddr_t		lcp_kaddr;
69*6c8f7fc3SBen Gras 	u_int		lcp_nfree;
70*6c8f7fc3SBen Gras 	u_int		lcp_rotor;
71*6c8f7fc3SBen Gras 	u_int		lcp_bitmap[1];
72*6c8f7fc3SBen Gras } lcpage_t;
73*6c8f7fc3SBen Gras 
74*6c8f7fc3SBen Gras typedef struct lcproc {
75*6c8f7fc3SBen Gras 	kmutex_t	lp_lock;
76*6c8f7fc3SBen Gras 	struct uvm_object *lp_uao;
77*6c8f7fc3SBen Gras 	TAILQ_HEAD(,lcpage) lp_pages;
78*6c8f7fc3SBen Gras 	vaddr_t		lp_cur;
79*6c8f7fc3SBen Gras 	vaddr_t		lp_max;
80*6c8f7fc3SBen Gras 	vaddr_t		lp_uva;
81*6c8f7fc3SBen Gras } lcproc_t;
82*6c8f7fc3SBen Gras 
83*6c8f7fc3SBen Gras #define	LWPCTL_PER_PAGE		((PAGE_SIZE / sizeof(lwpctl_t)) & ~31)
84*6c8f7fc3SBen Gras #define	LWPCTL_BITMAP_ENTRIES	(LWPCTL_PER_PAGE >> 5)
85*6c8f7fc3SBen Gras #define	LWPCTL_BITMAP_SZ	(LWPCTL_BITMAP_ENTRIES * sizeof(u_int))
86*6c8f7fc3SBen Gras #define	LWPCTL_LCPAGE_SZ	\
87*6c8f7fc3SBen Gras     (sizeof(lcpage_t) - sizeof(u_int) + LWPCTL_BITMAP_SZ)
88*6c8f7fc3SBen Gras #define	LWPCTL_UAREA_SZ		\
89*6c8f7fc3SBen Gras     (round_page(MAX_LWP_PER_PROC * sizeof(lwpctl_t)))
90*6c8f7fc3SBen Gras 
91*6c8f7fc3SBen Gras int	lwp_ctl_alloc(vaddr_t *);
92*6c8f7fc3SBen Gras void	lwp_ctl_free(lwp_t *);
93*6c8f7fc3SBen Gras void	lwp_ctl_exit(void);
94*6c8f7fc3SBen Gras 
95*6c8f7fc3SBen Gras #endif /* defined(_KERNEL) */
96*6c8f7fc3SBen Gras 
97*6c8f7fc3SBen Gras #endif /* !_SYS_LWPCTL_H_ */
98