uvm_extern.h revision 1.13
133965Sjdp/*	$NetBSD: uvm_extern.h,v 1.13 1998/05/09 15:04:40 kleink Exp $	*/
278828Sobrien
378828Sobrien/*
478828Sobrien * XXXCDC: "ROUGH DRAFT" QUALITY UVM PRE-RELEASE FILE!
578828Sobrien *	   >>>USE AT YOUR OWN RISK, WORK IS NOT FINISHED<<<
678828Sobrien */
778828Sobrien/*
878828Sobrien *
978828Sobrien * Copyright (c) 1997 Charles D. Cranor and Washington University.
1078828Sobrien * All rights reserved.
1178828Sobrien *
1278828Sobrien * Redistribution and use in source and binary forms, with or without
1378828Sobrien * modification, are permitted provided that the following conditions
1478828Sobrien * are met:
1578828Sobrien * 1. Redistributions of source code must retain the above copyright
1678828Sobrien *    notice, this list of conditions and the following disclaimer.
17218822Sdim * 2. Redistributions in binary form must reproduce the above copyright
18218822Sdim *    notice, this list of conditions and the following disclaimer in the
1978828Sobrien *    documentation and/or other materials provided with the distribution.
2033965Sjdp * 3. All advertising materials mentioning features or use of this software
2133965Sjdp *    must display the following acknowledgement:
2233965Sjdp *      This product includes software developed by Charles D. Cranor and
2333965Sjdp *      Washington University.
2433965Sjdp * 4. The name of the author may not be used to endorse or promote products
2578828Sobrien *    derived from this software without specific prior written permission.
2678828Sobrien *
2778828Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2878828Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2978828Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
3078828Sobrien * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
3133965Sjdp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3233965Sjdp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3378828Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3478828Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3578828Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3678828Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3733965Sjdp *
3878828Sobrien * from: Id: uvm_extern.h,v 1.1.2.21 1998/02/07 01:16:53 chs Exp
3933965Sjdp */
4033965Sjdp
4178828Sobrien#ifndef _UVM_UVM_EXTERN_H_
4278828Sobrien#define _UVM_UVM_EXTERN_H_
4333965Sjdp
4478828Sobrien/*
4578828Sobrien * uvm_extern.h: this file defines the external interface to the VM system.
4678828Sobrien *
4733965Sjdp * this should be the only file included by non-VM parts of the kernel
4878828Sobrien * which need access to VM services.   if you want to know the interface
4978828Sobrien * to the MI VM layer without knowing the details, this is the file to
5078828Sobrien * learn.
5178828Sobrien *
5278828Sobrien * NOTE: vm system calls are prototyped in syscallargs.h
5378828Sobrien */
5478828Sobrien
5578828Sobrien/*
5678828Sobrien * defines
5778828Sobrien */
5878828Sobrien
5978828Sobrien/*
6078828Sobrien * the following defines are for uvm_map and functions which call it.
6178828Sobrien */
6233965Sjdp
6378828Sobrien/* protections bits */
6478828Sobrien#define UVM_PROT_MASK	0x07	/* protection mask */
6578828Sobrien#define UVM_PROT_NONE	0x00	/* protection none */
6678828Sobrien#define UVM_PROT_ALL	0x07	/* everything */
6778828Sobrien#define UVM_PROT_READ	0x01	/* read */
6878828Sobrien#define UVM_PROT_WRITE  0x02	/* write */
6978828Sobrien#define UVM_PROT_EXEC	0x04	/* exec */
7078828Sobrien
7178828Sobrien/* protection short codes */
7278828Sobrien#define UVM_PROT_R	0x01	/* read */
7378828Sobrien#define UVM_PROT_W	0x02	/* write */
7478828Sobrien#define UVM_PROT_RW	0x03    /* read-write */
7578828Sobrien#define UVM_PROT_X	0x04	/* exec */
7678828Sobrien#define UVM_PROT_RX	0x05	/* read-exec */
7778828Sobrien#define UVM_PROT_WX	0x06	/* write-exec */
7878828Sobrien#define UVM_PROT_RWX	0x07	/* read-write-exec */
7978828Sobrien
8078828Sobrien/* 0x08: not used */
8178828Sobrien
8278828Sobrien/* inherit codes */
8378828Sobrien#define UVM_INH_MASK	0x30	/* inherit mask */
8478828Sobrien#define UVM_INH_SHARE	0x00	/* "share" */
8578828Sobrien#define UVM_INH_COPY	0x10	/* "copy" */
8633965Sjdp#define UVM_INH_NONE	0x20	/* "none" */
8778828Sobrien#define UVM_INH_DONATE	0x30	/* "donate" << not used */
8878828Sobrien
8978828Sobrien/* 0x40, 0x80: not used */
9078828Sobrien
9178828Sobrien/* bits 0x700: max protection, 0x800: not used */
9278828Sobrien
9378828Sobrien/* bits 0x7000: advice, 0x8000: not used */
9478828Sobrien/* advice: matches MADV_* from sys/mman.h */
9578828Sobrien#define UVM_ADV_NORMAL	0x0	/* 'normal' */
9678828Sobrien#define UVM_ADV_RANDOM	0x1	/* 'random' */
9778828Sobrien#define UVM_ADV_SEQUENTIAL 0x2	/* 'sequential' */
9878828Sobrien/* 0x3: will need, 0x4: dontneed */
9978828Sobrien#define UVM_ADV_MASK	0x7	/* mask */
10078828Sobrien
10178828Sobrien/* mapping flags */
10278828Sobrien#define UVM_FLAG_FIXED   0x010000 /* find space */
10378828Sobrien#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
10478828Sobrien#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
10578828Sobrien#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
10678828Sobrien#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
10778828Sobrien#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
10878828Sobrien
10978828Sobrien/* macros to extract info */
11078828Sobrien#define UVM_PROTECTION(X)	((X) & UVM_PROT_MASK)
11178828Sobrien#define UVM_INHERIT(X)		(((X) & UVM_INH_MASK) >> 4)
11278828Sobrien#define UVM_MAXPROTECTION(X)	(((X) >> 8) & UVM_PROT_MASK)
11378828Sobrien#define UVM_ADVICE(X)		(((X) >> 12) & UVM_ADV_MASK)
11478828Sobrien
11578828Sobrien#define UVM_MAPFLAG(PROT,MAXPROT,INH,ADVICE,FLAGS) \
11678828Sobrien	((MAXPROT << 8)|(PROT)|(INH)|((ADVICE) << 12)|(FLAGS))
11733965Sjdp
11878828Sobrien/* magic offset value */
11978828Sobrien#define UVM_UNKNOWN_OFFSET ((vm_offset_t) -1)
12033965Sjdp				/* offset not known(obj) or don't care(!obj) */
12178828Sobrien
12278828Sobrien/*
12378828Sobrien * the following defines are for uvm_km_kmemalloc's flags
12433965Sjdp */
12578828Sobrien
12678828Sobrien#define UVM_KMF_NOWAIT	0x1			/* matches M_NOWAIT */
12778828Sobrien#define UVM_KMF_VALLOC	0x2			/* allocate VA only */
12878828Sobrien#define UVM_KMF_TRYLOCK	UVM_FLAG_TRYLOCK	/* try locking only */
12978828Sobrien
13078828Sobrien/*
13178828Sobrien * structures
13278828Sobrien */
13378828Sobrien
13478828Sobrienstruct core;
13578828Sobrienstruct mount;
13678828Sobrienstruct pglist;
13778828Sobrienstruct proc;
13878828Sobrienstruct ucred;
13978828Sobrienstruct uio;
14078828Sobrienstruct uvm_object;
14178828Sobrienstruct vm_anon;
14278828Sobrienstruct vmspace;
14378828Sobrienstruct pmap;
14478828Sobrienstruct vnode;
14578828Sobrien
14678828Sobrien/*
14778828Sobrien * uvmexp: global data structures that are exported to parts of the kernel
14878828Sobrien * other than the vm system.
14978828Sobrien */
15033965Sjdp
15178828Sobrienstruct uvmexp {
15278828Sobrien	/* vm_page constants */
15378828Sobrien	int pagesize;   /* size of a page (PAGE_SIZE): must be power of 2 */
15478828Sobrien	int pagemask;   /* page mask */
15578828Sobrien	int pageshift;  /* page shift */
15678828Sobrien
15778828Sobrien	/* vm_page counters */
15878828Sobrien	int npages;     /* number of pages we manage */
15978828Sobrien	int free;       /* number of free pages */
16078828Sobrien	int active;     /* number of active pages */
16133965Sjdp	int inactive;   /* number of pages that we free'd but may want back */
16233965Sjdp	int paging;	/* number of pages in the process of being paged out */
16333965Sjdp	int wired;      /* number of wired pages */
16433965Sjdp	int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
16533965Sjdp	int reserve_kernel; /* number of pages reserved for kernel */
166
167	/* pageout params */
168	int freemin;    /* min number of free pages */
169	int freetarg;   /* target number of free pages */
170	int inactarg;   /* target number of inactive pages */
171	int wiredmax;   /* max number of wired pages */
172
173	/* swap */
174	int nswapdev;	/* number of configured swap devices in system */
175	int swpages;	/* number of PAGE_SIZE'ed swap pages */
176	int swpginuse;	/* number of swap pages in use */
177	int nswget;	/* number of times fault calls uvm_swap_get() */
178	int nanon;	/* number total of anon's in system */
179	int nfreeanon;	/* number of free anon's */
180
181	/* stat counters */
182	int faults;		/* page fault count */
183	int traps;		/* trap count */
184	int intrs;		/* interrupt count */
185	int swtch;		/* context switch count */
186	int softs;		/* software interrupt count */
187	int syscalls;		/* system calls */
188	int pageins;		/* pagein operation count */
189				/* pageouts are in pdpageouts below */
190	int swapins;		/* swapins */
191	int swapouts;		/* swapouts */
192	int pgswapin;		/* pages swapped in */
193	int pgswapout;		/* pages swapped out */
194	int forks;  		/* forks */
195	int forks_ppwait;	/* forks where parent waits */
196	int forks_sharevm;	/* forks where vmspace is shared */
197
198	/* fault subcounters */
199	int fltnoram;	/* number of times fault was out of ram */
200	int fltnoanon;	/* number of times fault was out of anons */
201	int fltpgwait;	/* number of times fault had to wait on a page */
202	int fltpgrele;	/* number of times fault found a released page */
203	int fltrelck;	/* number of times fault relock called */
204	int fltrelckok;	/* number of times fault relock is a success */
205	int fltanget;	/* number of times fault gets anon page */
206	int fltanretry;	/* number of times fault retrys an anon get */
207	int fltamcopy;	/* number of times fault clears "needs copy" */
208	int fltnamap;	/* number of times fault maps a neighbor anon page */
209	int fltnomap;	/* number of times fault maps a neighbor obj page */
210	int fltlget;	/* number of times fault does a locked pgo_get */
211	int fltget;	/* number of times fault does an unlocked get */
212	int flt_anon;	/* number of times fault anon (case 1a) */
213	int flt_acow;	/* number of times fault anon cow (case 1b) */
214	int flt_obj;	/* number of times fault is on object page (2a) */
215	int flt_prcopy;	/* number of times fault promotes with copy (2b) */
216	int flt_przero;	/* number of times fault promotes with zerofill (2b) */
217
218	/* daemon counters */
219	int pdwoke;	/* number of times daemon woke up */
220	int pdrevs;	/* number of times daemon rev'd clock hand */
221	int pdswout;	/* number of times daemon called for swapout */
222	int pdfreed;	/* number of pages daemon freed since boot */
223	int pdscans;	/* number of pages daemon scaned since boot */
224	int pdanscan;	/* number of anonymous pages scanned by daemon */
225	int pdobscan;	/* number of object pages scanned by daemon */
226	int pdreact;	/* number of pages daemon reactivated since boot */
227	int pdbusy;	/* number of times daemon found a busy page */
228	int pdpageouts;	/* number of times daemon started a pageout */
229	int pdpending;	/* number of times daemon got a pending pagout */
230	int pddeact;	/* number of pages daemon deactivates */
231
232	/* kernel memory objects: managed by uvm_km_kmemalloc() only! */
233	struct uvm_object *kmem_object;
234	struct uvm_object *mb_object;
235};
236
237
238extern struct uvmexp uvmexp;
239
240/*
241 * macros
242 */
243
244/* zalloc zeros memory, alloc does not */
245#define uvm_km_zalloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,TRUE)
246#define uvm_km_alloc(MAP,SIZE)  uvm_km_alloc1(MAP,SIZE,FALSE)
247
248/*
249 * typedefs
250 */
251
252typedef unsigned int  uvm_flag_t;
253typedef int vm_fault_t;
254
255/* uvm_aobj.c */
256struct uvm_object	*uao_create __P((vm_size_t, int));
257void			uao_detach __P((struct uvm_object *));
258void			uao_reference __P((struct uvm_object *));
259
260/* uvm_fault.c */
261int			uvm_fault __P((vm_map_t, vm_offset_t,
262				vm_fault_t, vm_prot_t));
263				/* handle a page fault */
264
265/* uvm_glue.c */
266#if defined(KGDB)
267void			uvm_chgkprot __P((caddr_t, size_t, int));
268#endif
269void			uvm_fork __P((struct proc *, struct proc *, boolean_t));
270void			uvm_init_limits __P((struct proc *));
271boolean_t		uvm_kernacc __P((caddr_t, size_t, int));
272__dead void		uvm_scheduler __P((void)) __attribute__((noreturn));
273void			uvm_swapin __P((struct proc *));
274boolean_t		uvm_useracc __P((caddr_t, size_t, int));
275void			uvm_vslock __P((struct proc *, caddr_t, size_t));
276void			uvm_vsunlock __P((struct proc *, caddr_t, size_t));
277
278
279/* uvm_init.c */
280void			uvm_init __P((void));
281				/* init the uvm system */
282
283/* uvm_io.c */
284int			uvm_io __P((vm_map_t, struct uio *));
285
286/* uvm_km.c */
287vm_offset_t		uvm_km_alloc1 __P((vm_map_t, vm_size_t, boolean_t));
288void			uvm_km_free __P((vm_map_t, vm_offset_t, vm_size_t));
289void			uvm_km_free_wakeup __P((vm_map_t, vm_offset_t,
290						vm_size_t));
291vm_offset_t		uvm_km_kmemalloc __P((vm_map_t, struct uvm_object *,
292						vm_size_t, int));
293struct vm_map		*uvm_km_suballoc __P((vm_map_t, vm_offset_t *,
294				vm_offset_t *, vm_size_t, boolean_t,
295				boolean_t, vm_map_t));
296vm_offset_t		uvm_km_valloc __P((vm_map_t, vm_size_t));
297vm_offset_t		uvm_km_valloc_wait __P((vm_map_t, vm_size_t));
298
299
300/* uvm_map.c */
301int			uvm_map __P((vm_map_t, vm_offset_t *, vm_size_t,
302				struct uvm_object *, vm_offset_t, uvm_flag_t));
303int			uvm_map_pageable __P((vm_map_t, vm_offset_t,
304				vm_offset_t, boolean_t));
305boolean_t		uvm_map_checkprot __P((vm_map_t, vm_offset_t,
306				vm_offset_t, vm_prot_t));
307#if defined(DDB)
308void			uvm_map_print __P((vm_map_t, boolean_t));
309void			uvm_map_printit __P((vm_map_t, boolean_t,
310				void (*) __P((const char *, ...))));
311#endif
312int			uvm_map_protect __P((vm_map_t, vm_offset_t,
313				vm_offset_t, vm_prot_t, boolean_t));
314#if defined(DDB)
315void			uvm_object_print __P((struct uvm_object *, boolean_t));
316void			uvm_object_printit __P((struct uvm_object *, boolean_t,
317				void (*) __P((const char *, ...))));
318void			uvm_page_print __P((struct vm_page *, boolean_t));
319void			uvm_page_printit __P((struct vm_page *, boolean_t,
320				void (*) __P((const char *, ...))));
321#endif
322struct vmspace		*uvmspace_alloc __P((vm_offset_t, vm_offset_t,
323				boolean_t));
324void			uvmspace_init __P((struct vmspace *, struct pmap *,
325				vm_offset_t, vm_offset_t, boolean_t));
326void			uvmspace_exec __P((struct proc *));
327struct vmspace		*uvmspace_fork __P((struct vmspace *));
328void			uvmspace_free __P((struct vmspace *));
329void			uvmspace_share __P((struct proc *, struct proc *));
330void			uvmspace_unshare __P((struct proc *));
331
332
333/* uvm_meter.c */
334void			uvm_meter __P((void));
335int			uvm_sysctl __P((int *, u_int, void *, size_t *,
336				void *, size_t, struct proc *));
337
338/* uvm_mmap.c */
339int			uvm_mmap __P((vm_map_t, vm_offset_t *, vm_size_t,
340				vm_prot_t, vm_prot_t, int,
341				caddr_t, vm_offset_t));
342
343/* uvm_page.c */
344struct vm_page		*uvm_pagealloc __P((struct uvm_object *, vm_offset_t,
345					    struct vm_anon *));
346void			uvm_pagerealloc __P((struct vm_page *,
347					     struct uvm_object *, vm_offset_t));
348void			uvm_page_physload __P((vm_offset_t, vm_offset_t,
349					       vm_offset_t, vm_offset_t));
350void			uvm_setpagesize __P((void));
351
352/* uvm_pdaemon.c */
353void			uvm_pageout __P((void));
354
355/* uvm_pglist.c */
356int			uvm_pglistalloc __P((vm_size_t, vm_offset_t,
357				vm_offset_t, vm_offset_t, vm_offset_t,
358				struct pglist *, int, int));
359void			uvm_pglistfree __P((struct pglist *));
360
361/* uvm_swap.c */
362void			uvm_swap_init __P((void));
363
364/* uvm_unix.c */
365int			uvm_coredump __P((struct proc *, struct vnode *,
366				struct ucred *, struct core *));
367int			uvm_grow __P((struct proc *, vm_offset_t));
368
369/* uvm_user.c */
370int			uvm_deallocate __P((vm_map_t, vm_offset_t, vm_size_t));
371
372/* uvm_vnode.c */
373void			uvm_vnp_setsize __P((struct vnode *, u_quad_t));
374void			uvm_vnp_sync __P((struct mount *));
375void 			uvm_vnp_terminate __P((struct vnode *));
376				/* terminate a uvm/uvn object */
377boolean_t		uvm_vnp_uncache __P((struct vnode *));
378struct uvm_object	*uvn_attach __P((void *, vm_prot_t));
379
380#endif /* _UVM_UVM_EXTERN_H_ */
381