xref: /illumos-gate/usr/src/uts/common/sys/hold_page.h (revision 2d6eb4a5)
1ae115bc7Smrj /*
2ae115bc7Smrj  * CDDL HEADER START
3ae115bc7Smrj  *
4ae115bc7Smrj  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
7ae115bc7Smrj  *
8ae115bc7Smrj  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9ae115bc7Smrj  * or http://www.opensolaris.org/os/licensing.
10ae115bc7Smrj  * See the License for the specific language governing permissions
11ae115bc7Smrj  * and limitations under the License.
12ae115bc7Smrj  *
13ae115bc7Smrj  * When distributing Covered Code, include this CDDL HEADER in each
14ae115bc7Smrj  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15ae115bc7Smrj  * If applicable, add the following below this CDDL HEADER, with the
16ae115bc7Smrj  * fields enclosed by brackets "[]" replaced with your own identifying
17ae115bc7Smrj  * information: Portions Copyright [yyyy] [name of copyright owner]
18ae115bc7Smrj  *
19ae115bc7Smrj  * CDDL HEADER END
20ae115bc7Smrj  */
21ae115bc7Smrj /*
22ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23ae115bc7Smrj  * Use is subject to license terms.
24ae115bc7Smrj  */
25ae115bc7Smrj 
26ae115bc7Smrj #ifndef _SYS_HOLD_PAGE_H
27ae115bc7Smrj #define	_SYS_HOLD_PAGE_H
28ae115bc7Smrj 
29ae115bc7Smrj #ifdef __cplusplus
30ae115bc7Smrj extern "C" {
31ae115bc7Smrj #endif
32ae115bc7Smrj 
33ae115bc7Smrj #include <sys/types.h>
34ae115bc7Smrj #include <vm/page.h>
35ae115bc7Smrj 
36ae115bc7Smrj /*
37ae115bc7Smrj  * swrand generates entropy by mapping different pages in the system.  This
38ae115bc7Smrj  * can create problems for some hypervisors, as certain pages may be removed
39ae115bc7Smrj  * from the system at any time.  The following interfaces allow swrand to
40ae115bc7Smrj  * check the validity and make sure a page is not given away while it is mapped.
41ae115bc7Smrj  *
42ae115bc7Smrj  * int plat_hold_page(pfn_t pfn, int lock, page_t **pp_ret)
43ae115bc7Smrj  *
44ae115bc7Smrj  *	If lock is PLAT_HOLD_NO_LOCK, simply check if the page pfn is valid
45ae115bc7Smrj  *	in the system.  If the page is valid, PLAT_HOLD_OK will be returned.
46ae115bc7Smrj  *	pp_ret is ignored if lock is PLAT_HOLD_NO_LOCK.
47ae115bc7Smrj  *
48ae115bc7Smrj  *	If lock is PLAT_HOLD_LOCK, in addition to the above, attempt to lock
49ae115bc7Smrj  *	the page exclusively.  Again, if the lock is successful, the page
50*843e1988Sjohnlev  *	pointer will be put in pp_ret, and PLAT_HOLD_OK will be returned.
51*843e1988Sjohnlev  *	pp_ret must be passed to a later call to plat_release_page.  If the
52*843e1988Sjohnlev  *	page wasn't found, or the lock couldn't be grabbed, the return value
53*843e1988Sjohnlev  *	will be PLAT_HOLD_FAIL.
54ae115bc7Smrj  *
55ae115bc7Smrj  * void plat_release_page(page_t *pp)
56ae115bc7Smrj  *
57ae115bc7Smrj  *	Unlock the page pp.  Should only be called after a previous,
58*843e1988Sjohnlev  *	successful call to plat_hold_page(pfn, PLAT_HOLD_LOCK, &pp);
59ae115bc7Smrj  */
60ae115bc7Smrj 
61ae115bc7Smrj #define	PLAT_HOLD_NO_LOCK	0
62ae115bc7Smrj #define	PLAT_HOLD_LOCK		1
63ae115bc7Smrj 
64ae115bc7Smrj #define	PLAT_HOLD_OK		0
65ae115bc7Smrj #define	PLAT_HOLD_FAIL		1
66ae115bc7Smrj 
67ae115bc7Smrj extern int plat_hold_page(pfn_t, int, page_t **);
68ae115bc7Smrj extern void plat_release_page(page_t *);
69ae115bc7Smrj 
70ae115bc7Smrj #ifdef __cplusplus
71ae115bc7Smrj }
72ae115bc7Smrj #endif
73ae115bc7Smrj 
74ae115bc7Smrj #endif	/* _SYS_HOLD_PAGE_H */
75