xref: /titanic_53/usr/src/uts/i86pc/vm/htable.h (revision 843e19887f64dde75055cf8842fc4db2171eff45)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * 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.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_VM_HTABLE_H
277c478bd9Sstevel@tonic-gate #define	_VM_HTABLE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL)
367c478bd9Sstevel@tonic-gate #include <asm/htable.h>
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate extern void atomic_andb(uint8_t *addr, uint8_t value);
407c478bd9Sstevel@tonic-gate extern void atomic_orb(uint8_t *addr, uint8_t value);
417c478bd9Sstevel@tonic-gate extern void atomic_inc16(uint16_t *addr);
427c478bd9Sstevel@tonic-gate extern void atomic_dec16(uint16_t *addr);
437c478bd9Sstevel@tonic-gate extern void mmu_tlbflush_entry(caddr_t addr);
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Each hardware page table has an htable_t describing it.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * We use a reference counter mechanism to detect when we can free an htable.
497c478bd9Sstevel@tonic-gate  * In the implmentation the reference count is split into 2 separate counters:
507c478bd9Sstevel@tonic-gate  *
517c478bd9Sstevel@tonic-gate  *	ht_busy is a traditional reference count of uses of the htable pointer
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  *	ht_valid_cnt is a count of how references are implied by valid PTE/PTP
547c478bd9Sstevel@tonic-gate  *	         entries in the pagetable
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * ht_busy is only incremented by htable_lookup() or htable_create()
577c478bd9Sstevel@tonic-gate  * while holding the appropriate hash_table mutex. While installing a new
587c478bd9Sstevel@tonic-gate  * valid PTE or PTP, in order to increment ht_valid_cnt a thread must have
597c478bd9Sstevel@tonic-gate  * done an htable_lookup() or htable_create() but not the htable_release yet.
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * htable_release(), while holding the mutex, can know that if
627c478bd9Sstevel@tonic-gate  * busy == 1 and valid_cnt == 0, the htable can be free'd.
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * The fields have been ordered to make htable_lookup() fast. Hence,
657c478bd9Sstevel@tonic-gate  * ht_hat, ht_vaddr, ht_level and ht_next need to be clustered together.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate struct htable {
687c478bd9Sstevel@tonic-gate 	struct htable	*ht_next;	/* forward link for hash table */
697c478bd9Sstevel@tonic-gate 	struct hat	*ht_hat;	/* hat this mapping comes from */
707c478bd9Sstevel@tonic-gate 	uintptr_t	ht_vaddr;	/* virt addr at start of this table */
71ae115bc7Smrj 	int8_t		ht_level;	/* page table level: 0=4K, 1=2M, ... */
72ae115bc7Smrj 	uint8_t		ht_flags;	/* see below */
737c478bd9Sstevel@tonic-gate 	int16_t		ht_busy;	/* implements locking protocol */
747c478bd9Sstevel@tonic-gate 	int16_t		ht_valid_cnt;	/* # of valid entries in this table */
757c478bd9Sstevel@tonic-gate 	uint32_t	ht_lock_cnt;	/* # of locked entries in this table */
767c478bd9Sstevel@tonic-gate 					/* never used for kernel hat */
777c478bd9Sstevel@tonic-gate 	pfn_t		ht_pfn;		/* pfn of page of the pagetable */
787c478bd9Sstevel@tonic-gate 	struct htable	*ht_prev;	/* backward link for hash table */
797c478bd9Sstevel@tonic-gate 	struct htable	*ht_parent;	/* htable that points to this htable */
807c478bd9Sstevel@tonic-gate 	struct htable	*ht_shares;	/* for HTABLE_SHARED_PFN only */
817c478bd9Sstevel@tonic-gate };
827c478bd9Sstevel@tonic-gate typedef struct htable htable_t;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * Flags values for htable ht_flags field:
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  * HTABLE_VLP - this is the top level htable of a VLP HAT.
887c478bd9Sstevel@tonic-gate  *
89ae115bc7Smrj  * HTABLE_SHARED_PFN - this htable had its PFN assigned from sharing another
907c478bd9Sstevel@tonic-gate  * 	htable. Used by hat_share() for ISM.
917c478bd9Sstevel@tonic-gate  */
92ae115bc7Smrj #define	HTABLE_VLP		(0x01)
93ae115bc7Smrj #define	HTABLE_SHARED_PFN	(0x02)
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * The htable hash table hashing function.  The 28 is so that high
977c478bd9Sstevel@tonic-gate  * order bits are include in the hash index to skew the wrap
987c8868c1Sjosephb  * around of addresses. Even though the hash buckets are stored per
997c8868c1Sjosephb  * hat we include the value of hat pointer in the hash function so
1007c8868c1Sjosephb  * that the secondary hash for the htable mutex winds up begin different in
1017c8868c1Sjosephb  * every address space.
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate #define	HTABLE_HASH(hat, va, lvl)					\
1047c8868c1Sjosephb 	((((va) >> LEVEL_SHIFT(1)) + ((va) >> 28) + (lvl) +		\
1057c8868c1Sjosephb 	((uintptr_t)(hat) >> 4)) & ((hat)->hat_num_hash - 1))
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Each CPU gets a unique hat_cpu_info structure in cpu_hat_info.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate struct hat_cpu_info {
1117c478bd9Sstevel@tonic-gate 	kmutex_t hci_mutex;		/* mutex to ensure sequential usage */
1127c478bd9Sstevel@tonic-gate #if defined(__amd64)
1137c478bd9Sstevel@tonic-gate 	pfn_t	hci_vlp_pfn;		/* pfn of hci_vlp_l3ptes */
1147c478bd9Sstevel@tonic-gate 	x86pte_t *hci_vlp_l3ptes;	/* VLP Level==3 pagetable (top) */
1157c478bd9Sstevel@tonic-gate 	x86pte_t *hci_vlp_l2ptes;	/* VLP Level==2 pagetable */
1167c478bd9Sstevel@tonic-gate #endif	/* __amd64 */
1177c478bd9Sstevel@tonic-gate };
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * Compute the last page aligned VA mapped by an htable.
1227c478bd9Sstevel@tonic-gate  *
1237c478bd9Sstevel@tonic-gate  * Given a va and a level, compute the virtual address of the start of the
1247c478bd9Sstevel@tonic-gate  * next page at that level.
1257c478bd9Sstevel@tonic-gate  *
1267c478bd9Sstevel@tonic-gate  * XX64 - The check for the VA hole needs to be better generalized.
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate #if defined(__amd64)
129*843e1988Sjohnlev #define	HTABLE_NUM_PTES(ht)	(((ht)->ht_flags & HTABLE_VLP) ? 4 : 512)
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #define	HTABLE_LAST_PAGE(ht)						\
1327c478bd9Sstevel@tonic-gate 	((ht)->ht_level == mmu.max_level ? ((uintptr_t)0UL - MMU_PAGESIZE) :\
1337c478bd9Sstevel@tonic-gate 	((ht)->ht_vaddr - MMU_PAGESIZE +				\
134ae115bc7Smrj 	((uintptr_t)HTABLE_NUM_PTES(ht) << LEVEL_SHIFT((ht)->ht_level))))
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #define	NEXT_ENTRY_VA(va, l)	\
1377c478bd9Sstevel@tonic-gate 	((va & LEVEL_MASK(l)) + LEVEL_SIZE(l) == mmu.hole_start ?	\
1387c478bd9Sstevel@tonic-gate 	mmu.hole_end : (va & LEVEL_MASK(l)) + LEVEL_SIZE(l))
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #elif defined(__i386)
1417c478bd9Sstevel@tonic-gate 
142*843e1988Sjohnlev #define	HTABLE_NUM_PTES(ht)	\
143*843e1988Sjohnlev 	(!mmu.pae_hat ? 1024 : ((ht)->ht_level == 2 ? 4 : 512))
144ae115bc7Smrj 
1457c478bd9Sstevel@tonic-gate #define	HTABLE_LAST_PAGE(ht)	((ht)->ht_vaddr - MMU_PAGESIZE + \
146ae115bc7Smrj 	((uintptr_t)HTABLE_NUM_PTES(ht) << LEVEL_SHIFT((ht)->ht_level)))
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #define	NEXT_ENTRY_VA(va, l) ((va & LEVEL_MASK(l)) + LEVEL_SIZE(l))
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #endif
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * initialization function called from hat_init()
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate extern void htable_init(void);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  * Functions to lookup, or "lookup and create", the htable corresponding
1617c478bd9Sstevel@tonic-gate  * to the virtual address "vaddr"  in the "hat" at the given "level" of
1627c478bd9Sstevel@tonic-gate  * page tables. htable_lookup() may return NULL if no such entry exists.
1637c478bd9Sstevel@tonic-gate  *
1647c478bd9Sstevel@tonic-gate  * On return the given htable is marked busy (a shared lock) - this prevents
1657c478bd9Sstevel@tonic-gate  * the htable from being stolen or freed) until htable_release() is called.
1667c478bd9Sstevel@tonic-gate  *
1677c478bd9Sstevel@tonic-gate  * If kalloc_flag is set on an htable_create() we can't call kmem allocation
1687c478bd9Sstevel@tonic-gate  * routines for this htable, since it's for the kernel hat itself.
1697c478bd9Sstevel@tonic-gate  *
1707c478bd9Sstevel@tonic-gate  * htable_acquire() is used when an htable pointer has been extracted from
1717c478bd9Sstevel@tonic-gate  * an hment and we need to get a reference to the htable.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate extern htable_t *htable_lookup(struct hat *hat, uintptr_t vaddr, level_t level);
1747c478bd9Sstevel@tonic-gate extern htable_t *htable_create(struct hat *hat, uintptr_t vaddr, level_t level,
1757c478bd9Sstevel@tonic-gate 	htable_t *shared);
1767c478bd9Sstevel@tonic-gate extern void htable_acquire(htable_t *);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate extern void htable_release(htable_t *ht);
179ae115bc7Smrj extern void htable_destroy(htable_t *ht);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * Code to free all remaining htables for a hat. Called after the hat is no
1837c478bd9Sstevel@tonic-gate  * longer in use by any thread.
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate extern void htable_purge_hat(struct hat *hat);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * Find the htable, page table entry index, and PTE of the given virtual
1897c478bd9Sstevel@tonic-gate  * address.  If not found returns NULL. When found, returns the htable_t *,
1907c478bd9Sstevel@tonic-gate  * sets entry, and has a hold on the htable.
1917c478bd9Sstevel@tonic-gate  */
1927c478bd9Sstevel@tonic-gate extern htable_t *htable_getpte(struct hat *, uintptr_t, uint_t *, x86pte_t *,
1937c478bd9Sstevel@tonic-gate 	level_t);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * Similar to hat_getpte(), except that this only succeeds if a valid
1977c478bd9Sstevel@tonic-gate  * page mapping is present.
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate extern htable_t *htable_getpage(struct hat *hat, uintptr_t va, uint_t *entry);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate  * Called to allocate initial/additional htables for reserve.
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate extern void htable_initial_reserve(uint_t);
2057c478bd9Sstevel@tonic-gate extern void htable_reserve(uint_t);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * Used to readjust the htable reserve after the reserve list has been used.
2097c478bd9Sstevel@tonic-gate  * Also called after boot to release left over boot reserves.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate extern void htable_adjust_reserve(void);
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
214*843e1988Sjohnlev  * return number of bytes mapped by all the htables in a given hat
215*843e1988Sjohnlev  */
216*843e1988Sjohnlev extern size_t htable_mapped(struct hat *);
217*843e1988Sjohnlev 
218*843e1988Sjohnlev 
219*843e1988Sjohnlev /*
220ae115bc7Smrj  * Attach initial pagetables as htables
221ae115bc7Smrj  */
222ae115bc7Smrj extern void htable_attach(struct hat *, uintptr_t, level_t, struct htable *,
223ae115bc7Smrj     pfn_t);
224ae115bc7Smrj 
225ae115bc7Smrj /*
2267c478bd9Sstevel@tonic-gate  * Routine to find the next populated htable at or above a given virtual
2277c478bd9Sstevel@tonic-gate  * address. Can specify an upper limit, or HTABLE_WALK_TO_END to indicate
2287c478bd9Sstevel@tonic-gate  * that it should search the entire address space.  Similar to
2297c478bd9Sstevel@tonic-gate  * hat_getpte(), but used for walking through address ranges. It can be
2307c478bd9Sstevel@tonic-gate  * used like this:
2317c478bd9Sstevel@tonic-gate  *
2327c478bd9Sstevel@tonic-gate  *	va = ...
2337c478bd9Sstevel@tonic-gate  *	ht = NULL;
2347c478bd9Sstevel@tonic-gate  *	while (va < end_va) {
2357c478bd9Sstevel@tonic-gate  *		pte = htable_walk(hat, &ht, &va, end_va);
2367c478bd9Sstevel@tonic-gate  *		if (!pte)
2377c478bd9Sstevel@tonic-gate  *			break;
2387c478bd9Sstevel@tonic-gate  *
2397c478bd9Sstevel@tonic-gate  *		... code to operate on page at va ...
2407c478bd9Sstevel@tonic-gate  *
2417c478bd9Sstevel@tonic-gate  *		va += LEVEL_SIZE(ht->ht_level);
2427c478bd9Sstevel@tonic-gate  *	}
2437c478bd9Sstevel@tonic-gate  *	if (ht)
2447c478bd9Sstevel@tonic-gate  *		htable_release(ht);
2457c478bd9Sstevel@tonic-gate  *
2467c478bd9Sstevel@tonic-gate  */
2477c478bd9Sstevel@tonic-gate extern x86pte_t htable_walk(struct hat *hat, htable_t **ht, uintptr_t *va,
2487c478bd9Sstevel@tonic-gate 	uintptr_t eaddr);
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate #define	HTABLE_WALK_TO_END ((uintptr_t)-1)
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * Utilities convert between virtual addresses and page table entry indeces.
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate extern uint_t htable_va2entry(uintptr_t va, htable_t *ht);
2567c478bd9Sstevel@tonic-gate extern uintptr_t htable_e2va(htable_t *ht, uint_t entry);
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate  * Interfaces that provide access to page table entries via the htable.
2607c478bd9Sstevel@tonic-gate  *
2617c478bd9Sstevel@tonic-gate  * Note that all accesses except x86pte_copy() and x86pte_zero() are atomic.
2627c478bd9Sstevel@tonic-gate  */
263ae115bc7Smrj extern void	x86pte_cpu_init(cpu_t *);
264ae115bc7Smrj extern void	x86pte_cpu_fini(cpu_t *);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate extern x86pte_t	x86pte_get(htable_t *, uint_t entry);
2677c478bd9Sstevel@tonic-gate 
268ae115bc7Smrj /*
269ae115bc7Smrj  * x86pte_set returns LPAGE_ERROR if it's asked to overwrite a page table
270ae115bc7Smrj  * link with a large page mapping.
271ae115bc7Smrj  */
272ae115bc7Smrj #define	LPAGE_ERROR (-(x86pte_t)1)
2737c478bd9Sstevel@tonic-gate extern x86pte_t	x86pte_set(htable_t *, uint_t entry, x86pte_t new, void *);
2747c478bd9Sstevel@tonic-gate 
275ae115bc7Smrj extern x86pte_t x86pte_inval(htable_t *ht, uint_t entry,
276ae115bc7Smrj 	x86pte_t old, x86pte_t *ptr);
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate extern x86pte_t x86pte_update(htable_t *ht, uint_t entry,
2797c478bd9Sstevel@tonic-gate 	x86pte_t old, x86pte_t new);
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate extern void	x86pte_copy(htable_t *src, htable_t *dest, uint_t entry,
2827c478bd9Sstevel@tonic-gate 	uint_t cnt);
2837c478bd9Sstevel@tonic-gate 
284ae115bc7Smrj /*
285ae115bc7Smrj  * access to a pagetable knowing only the pfn
286ae115bc7Smrj  */
287ae115bc7Smrj extern x86pte_t *x86pte_mapin(pfn_t, uint_t, htable_t *);
288ae115bc7Smrj extern void x86pte_mapout(void);
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * these are actually inlines for "lock; incw", "lock; decw", etc. instructions.
2927c478bd9Sstevel@tonic-gate  */
2937c478bd9Sstevel@tonic-gate #define	HTABLE_INC(x)	atomic_inc16((uint16_t *)&x)
2947c478bd9Sstevel@tonic-gate #define	HTABLE_DEC(x)	atomic_dec16((uint16_t *)&x)
2957c478bd9Sstevel@tonic-gate #define	HTABLE_LOCK_INC(ht)	atomic_add_32(&(ht)->ht_lock_cnt, 1)
2967c478bd9Sstevel@tonic-gate #define	HTABLE_LOCK_DEC(ht)	atomic_add_32(&(ht)->ht_lock_cnt, -1)
2977c478bd9Sstevel@tonic-gate 
298*843e1988Sjohnlev #ifdef __xpv
299*843e1988Sjohnlev extern void xen_flush_va(caddr_t va);
300*843e1988Sjohnlev extern void xen_gflush_va(caddr_t va, cpuset_t);
301*843e1988Sjohnlev extern void xen_flush_tlb(void);
302*843e1988Sjohnlev extern void xen_gflush_tlb(cpuset_t);
303*843e1988Sjohnlev extern void xen_pin(pfn_t, level_t);
304*843e1988Sjohnlev extern void xen_unpin(pfn_t);
305*843e1988Sjohnlev extern int xen_kpm_page(pfn_t, uint_t);
306*843e1988Sjohnlev 
307*843e1988Sjohnlev /*
308*843e1988Sjohnlev  * The hypervisor maps all page tables into our address space read-only.
309*843e1988Sjohnlev  * Under normal circumstances, the hypervisor then handles all updates to
310*843e1988Sjohnlev  * the page tables underneath the covers for us.  However, when we are
311*843e1988Sjohnlev  * trying to dump core after a hypervisor panic, the hypervisor is no
312*843e1988Sjohnlev  * longer available to do these updates.  To work around the protection
313*843e1988Sjohnlev  * problem, we simply disable write-protect checking for the duration of a
314*843e1988Sjohnlev  * pagetable update operation.
315*843e1988Sjohnlev  */
316*843e1988Sjohnlev #define	XPV_ALLOW_PAGETABLE_UPDATES()					\
317*843e1988Sjohnlev 	{								\
318*843e1988Sjohnlev 		if (IN_XPV_PANIC())					\
319*843e1988Sjohnlev 			setcr0((getcr0() & ~CR0_WP) & 0xffffffff); 	\
320*843e1988Sjohnlev 	}
321*843e1988Sjohnlev #define	XPV_DISALLOW_PAGETABLE_UPDATES()				\
322*843e1988Sjohnlev 	{								\
323*843e1988Sjohnlev 		if (IN_XPV_PANIC() > 0)					\
324*843e1988Sjohnlev 			setcr0((getcr0() | CR0_WP) & 0xffffffff);	\
325*843e1988Sjohnlev 	}
326*843e1988Sjohnlev 
327*843e1988Sjohnlev #else /* __xpv */
328*843e1988Sjohnlev 
329*843e1988Sjohnlev #define	XPV_ALLOW_PAGETABLE_UPDATES()
330*843e1988Sjohnlev #define	XPV_DISALLOW_PAGETABLE_UPDATES()
331*843e1988Sjohnlev 
332*843e1988Sjohnlev #endif
333*843e1988Sjohnlev 
3347c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate #endif
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate #endif	/* _VM_HTABLE_H */
342