xref: /onnv-gate/usr/src/uts/common/vm/hat.h (revision 10843:eb166ea6e74e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52251Selowe  * Common Development and Distribution License (the "License").
62251Selowe  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
229894SPavel.Tatashin@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate  * The Regents of the University of California
320Sstevel@tonic-gate  * All Rights Reserved
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate  * contributors.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifndef	_VM_HAT_H
400Sstevel@tonic-gate #define	_VM_HAT_H
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #include <sys/types.h>
430Sstevel@tonic-gate #include <sys/t_lock.h>
440Sstevel@tonic-gate #include <vm/faultcode.h>
450Sstevel@tonic-gate #include <sys/kstat.h>
460Sstevel@tonic-gate #include <sys/siginfo.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #ifdef	__cplusplus
490Sstevel@tonic-gate extern "C" {
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * VM - Hardware Address Translation management.
540Sstevel@tonic-gate  *
550Sstevel@tonic-gate  * This file describes the machine independent interfaces to
560Sstevel@tonic-gate  * the hardware address translation management routines.  Other
570Sstevel@tonic-gate  * machine specific interfaces and structures are defined
580Sstevel@tonic-gate  * in <vm/hat_xxx.h>.  The hat layer manages the address
590Sstevel@tonic-gate  * translation hardware as a cache driven by calls from the
600Sstevel@tonic-gate  * higher levels of the VM system.
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate 
630Sstevel@tonic-gate struct hat;
640Sstevel@tonic-gate struct kpme;
650Sstevel@tonic-gate struct memseg;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #include <vm/page.h>
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * a callback used with hat_unload_callback()
710Sstevel@tonic-gate  * start and end mark are set to a range of unloaded addresses
720Sstevel@tonic-gate  * and the function is invoked with a pointer to this data structure
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate typedef struct hat_callback {
750Sstevel@tonic-gate 	caddr_t	hcb_start_addr;
760Sstevel@tonic-gate 	caddr_t hcb_end_addr;
770Sstevel@tonic-gate 	void	(*hcb_function)(struct hat_callback *);
780Sstevel@tonic-gate 	void	*hcb_data;
790Sstevel@tonic-gate } hat_callback_t;
800Sstevel@tonic-gate 
814528Spaulsan typedef void *hat_region_cookie_t;
824528Spaulsan 
830Sstevel@tonic-gate #ifdef	_KERNEL
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * One time hat initialization
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate void	hat_init(void);
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * Notify hat of a system dump
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate void	hat_dump(void);
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate  * Operations on an address space:
970Sstevel@tonic-gate  *
980Sstevel@tonic-gate  * struct hat *hat_alloc(as)
990Sstevel@tonic-gate  *	allocated a hat structure for as.
1000Sstevel@tonic-gate  *
1010Sstevel@tonic-gate  * void hat_free_start(hat)
1020Sstevel@tonic-gate  *	informs hat layer process has finished executing but as has not
1030Sstevel@tonic-gate  *	been cleaned up yet.
1040Sstevel@tonic-gate  *
1050Sstevel@tonic-gate  * void hat_free_end(hat)
1060Sstevel@tonic-gate  *	informs hat layer as is being destroyed.  hat layer cannot use as
1070Sstevel@tonic-gate  *	pointer after this call.
1080Sstevel@tonic-gate  *
1090Sstevel@tonic-gate  * void hat_swapin(hat)
1100Sstevel@tonic-gate  *	allocate any hat resources required for process being swapped in.
1110Sstevel@tonic-gate  *
1120Sstevel@tonic-gate  * void hat_swapout(hat)
1130Sstevel@tonic-gate  *	deallocate hat resources for process being swapped out.
1140Sstevel@tonic-gate  *
1150Sstevel@tonic-gate  * size_t hat_get_mapped_size(hat)
1160Sstevel@tonic-gate  *	returns number of bytes that have valid mappings in hat.
1170Sstevel@tonic-gate  *
1180Sstevel@tonic-gate  * void hat_stats_enable(hat)
1190Sstevel@tonic-gate  * void hat_stats_disable(hat)
1200Sstevel@tonic-gate  *	enables/disables collection of stats for hat.
1210Sstevel@tonic-gate  *
1220Sstevel@tonic-gate  * int hat_dup(parenthat, childhat, addr, len, flags)
1230Sstevel@tonic-gate  *	Duplicate address translations of the parent to the child.  Supports
1240Sstevel@tonic-gate  *	the entire address range or a range depending on flag,
1250Sstevel@tonic-gate  *	zero returned on success, non-zero on error
1260Sstevel@tonic-gate  *
1270Sstevel@tonic-gate  * void hat_thread_exit(thread)
1280Sstevel@tonic-gate  *	Notifies the HAT that a thread is exiting, called after it has been
1290Sstevel@tonic-gate  *	reassigned to the kernel AS.
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate struct hat *hat_alloc(struct as *);
1330Sstevel@tonic-gate void	hat_free_start(struct hat *);
1340Sstevel@tonic-gate void	hat_free_end(struct hat *);
1350Sstevel@tonic-gate int	hat_dup(struct hat *, struct hat *, caddr_t, size_t, uint_t);
1360Sstevel@tonic-gate void	hat_swapin(struct hat *);
1370Sstevel@tonic-gate void	hat_swapout(struct hat *);
1380Sstevel@tonic-gate size_t	hat_get_mapped_size(struct hat *);
1390Sstevel@tonic-gate int	hat_stats_enable(struct hat *);
1400Sstevel@tonic-gate void	hat_stats_disable(struct hat *);
1410Sstevel@tonic-gate void	hat_thread_exit(kthread_t *);
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /*
1440Sstevel@tonic-gate  * Operations on a named address within a segment:
1450Sstevel@tonic-gate  *
1460Sstevel@tonic-gate  * void hat_memload(hat, addr, pp, attr, flags)
1470Sstevel@tonic-gate  *	load/lock the given page struct
1480Sstevel@tonic-gate  *
1490Sstevel@tonic-gate  * void hat_memload_array(hat, addr, len, ppa, attr, flags)
1500Sstevel@tonic-gate  *	load/lock the given array of page structs
1510Sstevel@tonic-gate  *
1520Sstevel@tonic-gate  * void hat_devload(hat, addr, len, pf, attr, flags)
1530Sstevel@tonic-gate  *	load/lock the given page frame number
1540Sstevel@tonic-gate  *
1550Sstevel@tonic-gate  * void hat_unlock(hat, addr, len)
1560Sstevel@tonic-gate  *	unlock a given range of addresses
1570Sstevel@tonic-gate  *
1580Sstevel@tonic-gate  * void hat_unload(hat, addr, len, flags)
1590Sstevel@tonic-gate  * void hat_unload_callback(hat, addr, len, flags, callback)
1600Sstevel@tonic-gate  *	unload a given range of addresses (has optional callback)
1610Sstevel@tonic-gate  *
1620Sstevel@tonic-gate  * void hat_sync(hat, addr, len, flags)
1630Sstevel@tonic-gate  *	synchronize mapping with software data structures
1640Sstevel@tonic-gate  *
1650Sstevel@tonic-gate  * void	hat_map(hat, addr, len, flags)
1660Sstevel@tonic-gate  *
1670Sstevel@tonic-gate  * void hat_setattr(hat, addr, len, attr)
1680Sstevel@tonic-gate  * void hat_clrattr(hat, addr, len, attr)
1690Sstevel@tonic-gate  * void hat_chgattr(hat, addr, len, attr)
1700Sstevel@tonic-gate  *	modify attributes for a range of addresses. skips any invalid mappings
1710Sstevel@tonic-gate  *
1720Sstevel@tonic-gate  * uint_t hat_getattr(hat, addr, *attr)
1730Sstevel@tonic-gate  *	returns attr for <hat,addr> in *attr.  returns 0 if there was a
1740Sstevel@tonic-gate  *	mapping and *attr is valid, nonzero if there was no mapping and
1750Sstevel@tonic-gate  *	*attr is not valid.
1760Sstevel@tonic-gate  *
1770Sstevel@tonic-gate  * size_t hat_getpagesize(hat, addr)
1780Sstevel@tonic-gate  *	returns pagesize in bytes for <hat, addr>. returns -1 if there is
1790Sstevel@tonic-gate  *	no mapping. This is an advisory call.
1800Sstevel@tonic-gate  *
1810Sstevel@tonic-gate  * pfn_t hat_getpfnum(hat, addr)
1820Sstevel@tonic-gate  *	returns pfn for <hat, addr> or PFN_INVALID if mapping is invalid.
1830Sstevel@tonic-gate  *
1840Sstevel@tonic-gate  * pfn_t hat_getkpfnum(addr)
1850Sstevel@tonic-gate  *	returns pfn for non-memory mapped addr in kernel address space
1860Sstevel@tonic-gate  *	or PFN_INVALID if mapping is invalid or is kernel memory.
1870Sstevel@tonic-gate  *
1880Sstevel@tonic-gate  * int hat_probe(hat, addr)
1890Sstevel@tonic-gate  *	return 0 if no valid mapping is present.  Faster version
1900Sstevel@tonic-gate  *	of hat_getattr in certain architectures.
1910Sstevel@tonic-gate  *
1920Sstevel@tonic-gate  * int hat_share(dhat, daddr, shat, saddr, len, szc)
1930Sstevel@tonic-gate  *
1940Sstevel@tonic-gate  * void hat_unshare(hat, addr, len, szc)
1950Sstevel@tonic-gate  *
1960Sstevel@tonic-gate  * void hat_chgprot(hat, addr, len, vprot)
1970Sstevel@tonic-gate  *	This is a deprecated call.  New segment drivers should store
1980Sstevel@tonic-gate  *	all attributes and use hat_*attr calls.
1990Sstevel@tonic-gate  *	Change the protections in the virtual address range
2000Sstevel@tonic-gate  *	given to the specified virtual protection.  If vprot is ~PROT_WRITE,
2010Sstevel@tonic-gate  *	then remove write permission, leaving the other permissions
2020Sstevel@tonic-gate  *	unchanged.  If vprot is ~PROT_USER, remove user permissions.
203*10843SDave.Plauger@Sun.COM  *
204*10843SDave.Plauger@Sun.COM  * void hat_flush_range(hat, addr, size)
205*10843SDave.Plauger@Sun.COM  *	Invalidate a virtual address translation for the local CPU.
2060Sstevel@tonic-gate  */
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate void	hat_memload(struct hat *, caddr_t, struct page *, uint_t, uint_t);
2090Sstevel@tonic-gate void	hat_memload_array(struct hat *, caddr_t, size_t, struct page **,
2100Sstevel@tonic-gate 		uint_t, uint_t);
2114528Spaulsan void	hat_memload_region(struct hat *, caddr_t, struct page *, uint_t,
2124528Spaulsan 		uint_t, hat_region_cookie_t);
2134528Spaulsan void	hat_memload_array_region(struct hat *, caddr_t, size_t, struct page **,
2144528Spaulsan 		uint_t, uint_t, hat_region_cookie_t);
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate void	hat_devload(struct hat *, caddr_t, size_t, pfn_t, uint_t, int);
2174528Spaulsan 
2180Sstevel@tonic-gate void	hat_unlock(struct hat *, caddr_t, size_t);
2194528Spaulsan void	hat_unlock_region(struct hat *, caddr_t, size_t, hat_region_cookie_t);
2204528Spaulsan 
2210Sstevel@tonic-gate void	hat_unload(struct hat *, caddr_t, size_t, uint_t);
2220Sstevel@tonic-gate void	hat_unload_callback(struct hat *, caddr_t, size_t, uint_t,
2230Sstevel@tonic-gate 		hat_callback_t *);
224*10843SDave.Plauger@Sun.COM void	hat_flush_range(struct hat *, caddr_t, size_t);
2250Sstevel@tonic-gate void	hat_sync(struct hat *, caddr_t, size_t, uint_t);
2260Sstevel@tonic-gate void	hat_map(struct hat *, caddr_t, size_t, uint_t);
2270Sstevel@tonic-gate void	hat_setattr(struct hat *, caddr_t, size_t, uint_t);
2280Sstevel@tonic-gate void	hat_clrattr(struct hat *, caddr_t, size_t, uint_t);
2290Sstevel@tonic-gate void	hat_chgattr(struct hat *, caddr_t, size_t, uint_t);
2300Sstevel@tonic-gate uint_t	hat_getattr(struct hat *, caddr_t, uint_t *);
2310Sstevel@tonic-gate ssize_t	hat_getpagesize(struct hat *, caddr_t);
2320Sstevel@tonic-gate pfn_t	hat_getpfnum(struct hat *, caddr_t);
2330Sstevel@tonic-gate int	hat_probe(struct hat *, caddr_t);
2340Sstevel@tonic-gate int	hat_share(struct hat *, caddr_t, struct hat *, caddr_t, size_t, uint_t);
2350Sstevel@tonic-gate void	hat_unshare(struct hat *, caddr_t, size_t, uint_t);
2360Sstevel@tonic-gate void	hat_chgprot(struct hat *, caddr_t, size_t, uint_t);
2370Sstevel@tonic-gate void	hat_reserve(struct as *, caddr_t, size_t);
2380Sstevel@tonic-gate pfn_t	va_to_pfn(void *);
2390Sstevel@tonic-gate uint64_t va_to_pa(void *);
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate /*
2420Sstevel@tonic-gate  * hat_getkpfnum() is never supported on amd64 and will be
2430Sstevel@tonic-gate  * removed from other platforms in future release
2440Sstevel@tonic-gate  */
2450Sstevel@tonic-gate #if !defined(__amd64)
2460Sstevel@tonic-gate pfn_t	hat_getkpfnum(caddr_t);
2470Sstevel@tonic-gate #endif
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate /*
2510Sstevel@tonic-gate  * Kernel Physical Mapping (segkpm) hat interface routines.
2520Sstevel@tonic-gate  */
2530Sstevel@tonic-gate caddr_t	hat_kpm_mapin(struct page *, struct kpme *);
2540Sstevel@tonic-gate void	hat_kpm_mapout(struct page *, struct kpme *, caddr_t);
2559894SPavel.Tatashin@Sun.COM caddr_t hat_kpm_mapin_pfn(pfn_t);
2569894SPavel.Tatashin@Sun.COM void    hat_kpm_mapout_pfn(pfn_t);
2570Sstevel@tonic-gate caddr_t	hat_kpm_page2va(struct page *, int);
2580Sstevel@tonic-gate struct page *hat_kpm_vaddr2page(caddr_t);
2590Sstevel@tonic-gate int	hat_kpm_fault(struct hat *, caddr_t);
2600Sstevel@tonic-gate void	hat_kpm_mseghash_clear(int);
2610Sstevel@tonic-gate void	hat_kpm_mseghash_update(pgcnt_t, struct memseg *);
2620Sstevel@tonic-gate void	hat_kpm_addmem_mseg_update(struct memseg *, pgcnt_t, offset_t);
2630Sstevel@tonic-gate void	hat_kpm_addmem_mseg_insert(struct memseg *);
2640Sstevel@tonic-gate void	hat_kpm_addmem_memsegs_update(struct memseg *);
2650Sstevel@tonic-gate caddr_t hat_kpm_mseg_reuse(struct memseg *);
2660Sstevel@tonic-gate void	hat_kpm_delmem_mseg_update(struct memseg *, struct memseg **);
2670Sstevel@tonic-gate void	hat_kpm_split_mseg_update(struct memseg *, struct memseg **,
2680Sstevel@tonic-gate 			struct memseg *, struct memseg *, struct memseg *);
2690Sstevel@tonic-gate void	hat_kpm_walk(void (*)(void *, void *, size_t), void *);
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate /*
2720Sstevel@tonic-gate  * Operations on all translations for a given page(s)
2730Sstevel@tonic-gate  *
2740Sstevel@tonic-gate  * void hat_page_setattr(pp, flag)
2750Sstevel@tonic-gate  * void hat_page_clrattr(pp, flag)
2760Sstevel@tonic-gate  *	used to set/clr red/mod bits.
2770Sstevel@tonic-gate  *
2780Sstevel@tonic-gate  * uint hat_page_getattr(pp, flag)
2790Sstevel@tonic-gate  *	If flag is specified, returns 0 if attribute is disabled
2800Sstevel@tonic-gate  *	and non zero if enabled.  If flag specifes multiple attributs
2810Sstevel@tonic-gate  *	then returns 0 if ALL atriibutes are disabled.  This is an advisory
2820Sstevel@tonic-gate  *	call.
2830Sstevel@tonic-gate  *
2840Sstevel@tonic-gate  * int hat_pageunload(pp, forceflag)
2850Sstevel@tonic-gate  *	unload all translations attached to pp.
2860Sstevel@tonic-gate  *
2870Sstevel@tonic-gate  * uint_t hat_pagesync(pp, flags)
2880Sstevel@tonic-gate  *	get hw stats from hardware into page struct and reset hw stats
2890Sstevel@tonic-gate  *	returns attributes of page
2900Sstevel@tonic-gate  *
2910Sstevel@tonic-gate  * ulong_t hat_page_getshare(pp)
2920Sstevel@tonic-gate  *	returns approx number of mappings to this pp.  A return of 0 implies
2930Sstevel@tonic-gate  *	there are no mappings to the page.
2940Sstevel@tonic-gate  *
2950Sstevel@tonic-gate  * faultcode_t hat_softlock(hat, addr, lenp, ppp, flags);
2960Sstevel@tonic-gate  *	called to softlock pages for zero copy tcp
2970Sstevel@tonic-gate  *
2980Sstevel@tonic-gate  * void hat_page_demote(pp);
2990Sstevel@tonic-gate  *	unload all large mappings to pp and decrease p_szc of all
3000Sstevel@tonic-gate  *	constituent pages according to the remaining mappings.
3010Sstevel@tonic-gate  */
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate void	hat_page_setattr(struct page *, uint_t);
3040Sstevel@tonic-gate void	hat_page_clrattr(struct page *, uint_t);
3050Sstevel@tonic-gate uint_t	hat_page_getattr(struct page *, uint_t);
3060Sstevel@tonic-gate int	hat_pageunload(struct page *, uint_t);
3070Sstevel@tonic-gate uint_t	hat_pagesync(struct page *, uint_t);
3080Sstevel@tonic-gate ulong_t	hat_page_getshare(struct page *);
3094528Spaulsan int	hat_page_checkshare(struct page *, ulong_t);
3100Sstevel@tonic-gate faultcode_t hat_softlock(struct hat *, caddr_t, size_t *,
3110Sstevel@tonic-gate 			struct page **, uint_t);
3120Sstevel@tonic-gate void	hat_page_demote(struct page *);
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate /*
3150Sstevel@tonic-gate  * Rountine to expose supported HAT features to PIM.
3160Sstevel@tonic-gate  */
3170Sstevel@tonic-gate enum hat_features {
3180Sstevel@tonic-gate 	HAT_SHARED_PT,		/* Shared page tables */
3190Sstevel@tonic-gate 	HAT_DYNAMIC_ISM_UNMAP,	/* hat_pageunload() handles ISM pages */
3204528Spaulsan 	HAT_VMODSORT,		/* support for VMODSORT flag of vnode */
3214528Spaulsan 	HAT_SHARED_REGIONS	/* shared regions support */
3220Sstevel@tonic-gate };
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate int hat_supported(enum hat_features, void *);
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate /*
3270Sstevel@tonic-gate  * Services provided to the hat:
3280Sstevel@tonic-gate  *
3290Sstevel@tonic-gate  * void as_signal_proc(as, siginfo)
3300Sstevel@tonic-gate  *	deliver signal to all processes that have this as.
3310Sstevel@tonic-gate  *
3320Sstevel@tonic-gate  * int hat_setstat(as, addr, len, rmbits)
3330Sstevel@tonic-gate  *	informs hatstat layer that ref/mod bits need to be updated for
3340Sstevel@tonic-gate  *	address range. Returns 0 on success, 1 for failure.
3350Sstevel@tonic-gate  */
3360Sstevel@tonic-gate void	as_signal_proc(struct as *, k_siginfo_t *siginfo);
3370Sstevel@tonic-gate void	hat_setstat(struct as *, caddr_t, size_t, uint_t);
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate /*
3400Sstevel@tonic-gate  * Flags to pass to hat routines.
3410Sstevel@tonic-gate  *
3420Sstevel@tonic-gate  * Certain flags only apply to some interfaces:
3430Sstevel@tonic-gate  *
3440Sstevel@tonic-gate  * 	HAT_LOAD	Default flags to load a translation to the page.
3450Sstevel@tonic-gate  * 	HAT_LOAD_LOCK	Lock down mapping resources; hat_map(), hat_memload(),
3460Sstevel@tonic-gate  *			and hat_devload().
3470Sstevel@tonic-gate  *	HAT_LOAD_ADV	Advisory load - Load translation if and only if
3480Sstevel@tonic-gate  *			sufficient MMU resources exist (i.e., do not steal).
3490Sstevel@tonic-gate  *	HAT_LOAD_SHARE	A flag to hat_memload() to indicate h/w page tables
3500Sstevel@tonic-gate  *			that map some user pages (not kas) is shared by more
3510Sstevel@tonic-gate  *			than one process (eg. ISM).
3520Sstevel@tonic-gate  *	HAT_LOAD_CONTIG	Pages are contigous
3530Sstevel@tonic-gate  *	HAT_LOAD_NOCONSIST Do not add mapping to mapping list.
3540Sstevel@tonic-gate  *	HAT_LOAD_REMAP	Reload a valid pte with a different page frame.
3550Sstevel@tonic-gate  *	HAT_RELOAD_SHARE Reload a shared page table entry. Some platforms
3560Sstevel@tonic-gate  *			 may require different actions than on the first
3570Sstevel@tonic-gate  *			 load of a shared mapping.
3580Sstevel@tonic-gate  *	HAT_NO_KALLOC	Do not kmem_alloc while creating the mapping; at this
3590Sstevel@tonic-gate  *			point, it's setting up mapping to allocate internal
3600Sstevel@tonic-gate  *			hat layer data structures.  This flag forces hat layer
3610Sstevel@tonic-gate  *			to tap its reserves in order to prevent infinite
3620Sstevel@tonic-gate  *			recursion.
3632991Ssusans  *	HAT_LOAD_TEXT	A flag to hat_memload() to indicate loading text pages.
3640Sstevel@tonic-gate  */
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate /*
3670Sstevel@tonic-gate  * Flags for hat_memload/hat_devload
3680Sstevel@tonic-gate  */
3690Sstevel@tonic-gate #define	HAT_FLAGS_RESV		0xFF000000	/* resv for hat impl */
3700Sstevel@tonic-gate #define	HAT_LOAD		0x00
3710Sstevel@tonic-gate #define	HAT_LOAD_LOCK		0x01
3720Sstevel@tonic-gate #define	HAT_LOAD_ADV		0x04
3730Sstevel@tonic-gate #define	HAT_LOAD_CONTIG		0x10
3740Sstevel@tonic-gate #define	HAT_LOAD_NOCONSIST	0x20
3750Sstevel@tonic-gate #define	HAT_LOAD_SHARE		0x40
3760Sstevel@tonic-gate #define	HAT_LOAD_REMAP		0x80
3770Sstevel@tonic-gate #define	HAT_RELOAD_SHARE	0x100
3780Sstevel@tonic-gate #define	HAT_NO_KALLOC		0x200
3790Sstevel@tonic-gate #define	HAT_LOAD_TEXT		0x400
3802991Ssusans 
3812991Ssusans /*
3822991Ssusans  * Flags for initializing disable_*large_pages.
3832991Ssusans  *
3842991Ssusans  *	HAT_AUTO_TEXT	Get MMU specific disable_auto_text_large_pages
3852991Ssusans  *	HAT_AUTO_DATA	Get MMU specific disable_auto_data_large_pages
3862991Ssusans  */
3872991Ssusans #define	HAT_AUTO_TEXT		0x800
3882991Ssusans #define	HAT_AUTO_DATA		0x1000
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate /*
3910Sstevel@tonic-gate  * Attributes for hat_memload/hat_devload/hat_*attr
3920Sstevel@tonic-gate  * are a superset of prot flags defined in mman.h.
3930Sstevel@tonic-gate  */
3940Sstevel@tonic-gate #define	HAT_PLAT_ATTR_MASK	0xF00000
3950Sstevel@tonic-gate #define	HAT_PROT_MASK		0x0F
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate #define	HAT_NOFAULT		0x10
3980Sstevel@tonic-gate #define	HAT_NOSYNC		0x20
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate /*
4010Sstevel@tonic-gate  * Advisory ordering attributes. Apply only to device mappings.
4020Sstevel@tonic-gate  *
4030Sstevel@tonic-gate  * HAT_STRICTORDER: the CPU must issue the references in order, as the
4040Sstevel@tonic-gate  *	programmer specified.  This is the default.
4050Sstevel@tonic-gate  * HAT_UNORDERED_OK: the CPU may reorder the references (this is all kinds
4060Sstevel@tonic-gate  *	of reordering; store or load with store or load).
4070Sstevel@tonic-gate  * HAT_MERGING_OK: merging and batching: the CPU may merge individual stores
4080Sstevel@tonic-gate  *	to consecutive locations (for example, turn two consecutive byte
4090Sstevel@tonic-gate  *	stores into one halfword store), and it may batch individual loads
4100Sstevel@tonic-gate  *	(for example, turn two consecutive byte loads into one halfword load).
4110Sstevel@tonic-gate  *	This also implies re-ordering.
4120Sstevel@tonic-gate  * HAT_LOADCACHING_OK: the CPU may cache the data it fetches and reuse it
4130Sstevel@tonic-gate  *	until another store occurs.  The default is to fetch new data
4140Sstevel@tonic-gate  *	on every load.  This also implies merging.
4150Sstevel@tonic-gate  * HAT_STORECACHING_OK: the CPU may keep the data in the cache and push it to
4160Sstevel@tonic-gate  *	the device (perhaps with other data) at a later time.  The default is
4170Sstevel@tonic-gate  *	to push the data right away.  This also implies load caching.
4180Sstevel@tonic-gate  */
4190Sstevel@tonic-gate #define	HAT_STRICTORDER		0x0000
4200Sstevel@tonic-gate #define	HAT_UNORDERED_OK	0x0100
4210Sstevel@tonic-gate #define	HAT_MERGING_OK		0x0200
4220Sstevel@tonic-gate #define	HAT_LOADCACHING_OK	0x0300
4230Sstevel@tonic-gate #define	HAT_STORECACHING_OK	0x0400
4240Sstevel@tonic-gate #define	HAT_ORDER_MASK		0x0700
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate /* endian attributes */
4270Sstevel@tonic-gate #define	HAT_NEVERSWAP		0x0000
4280Sstevel@tonic-gate #define	HAT_STRUCTURE_BE	0x1000
4290Sstevel@tonic-gate #define	HAT_STRUCTURE_LE	0x2000
4300Sstevel@tonic-gate #define	HAT_ENDIAN_MASK		0x3000
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate /* flags for hat_softlock */
4330Sstevel@tonic-gate #define	HAT_COW			0x0001
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate /*
4360Sstevel@tonic-gate  * Flags for hat_unload
4370Sstevel@tonic-gate  */
4380Sstevel@tonic-gate #define	HAT_UNLOAD		0x00
4390Sstevel@tonic-gate #define	HAT_UNLOAD_NOSYNC	0x02
4400Sstevel@tonic-gate #define	HAT_UNLOAD_UNLOCK	0x04
4410Sstevel@tonic-gate #define	HAT_UNLOAD_OTHER	0x08
4420Sstevel@tonic-gate #define	HAT_UNLOAD_UNMAP	0x10
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate /*
4450Sstevel@tonic-gate  * Flags for hat_pagesync, hat_getstat, hat_sync
4460Sstevel@tonic-gate  */
4470Sstevel@tonic-gate #define	HAT_SYNC_DONTZERO	0x00
4480Sstevel@tonic-gate #define	HAT_SYNC_ZERORM		0x01
4490Sstevel@tonic-gate /* Additional flags for hat_pagesync */
4500Sstevel@tonic-gate #define	HAT_SYNC_STOPON_REF	0x02
4510Sstevel@tonic-gate #define	HAT_SYNC_STOPON_MOD	0x04
4520Sstevel@tonic-gate #define	HAT_SYNC_STOPON_RM	(HAT_SYNC_STOPON_REF | HAT_SYNC_STOPON_MOD)
4530Sstevel@tonic-gate #define	HAT_SYNC_STOPON_SHARED	0x08
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate /*
4560Sstevel@tonic-gate  * Flags for hat_dup
4570Sstevel@tonic-gate  *
4580Sstevel@tonic-gate  * HAT_DUP_ALL dup entire address space
4590Sstevel@tonic-gate  * HAT_DUP_COW dup plus hat_clrattr(..PROT_WRITE) on newas
4600Sstevel@tonic-gate  */
4610Sstevel@tonic-gate #define	HAT_DUP_ALL		1
4620Sstevel@tonic-gate #define	HAT_DUP_COW		2
4634528Spaulsan #define	HAT_DUP_SRD		3
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate /*
4670Sstevel@tonic-gate  * Flags for hat_map
4680Sstevel@tonic-gate  */
4690Sstevel@tonic-gate #define	HAT_MAP			0x00
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate /*
4720Sstevel@tonic-gate  * Flag for hat_pageunload
4730Sstevel@tonic-gate  */
4740Sstevel@tonic-gate #define	HAT_ADV_PGUNLOAD	0x00
4750Sstevel@tonic-gate #define	HAT_FORCE_PGUNLOAD	0x01
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate /*
4780Sstevel@tonic-gate  * Attributes for hat_page_*attr, hat_setstats and
4790Sstevel@tonic-gate  * returned by hat_pagesync.
4800Sstevel@tonic-gate  */
4810Sstevel@tonic-gate #define	P_MOD	0x1		/* the modified bit */
4820Sstevel@tonic-gate #define	P_REF	0x2		/* the referenced bit */
4830Sstevel@tonic-gate #define	P_RO	0x4		/* Read only page */
4844324Sqiao #define	P_NSH	0x8		/* Not to shuffle v_pages */
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate #define	hat_ismod(pp)		(hat_page_getattr(pp, P_MOD))
4870Sstevel@tonic-gate #define	hat_isref(pp)		(hat_page_getattr(pp, P_REF))
4880Sstevel@tonic-gate #define	hat_isro(pp)		(hat_page_getattr(pp, P_RO))
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate #define	hat_setmod(pp)		(hat_page_setattr(pp, P_MOD))
4914324Sqiao #define	hat_setmod_only(pp)	(hat_page_setattr(pp, P_MOD|P_NSH))
4920Sstevel@tonic-gate #define	hat_setref(pp)		(hat_page_setattr(pp, P_REF))
4930Sstevel@tonic-gate #define	hat_setrefmod(pp)	(hat_page_setattr(pp, P_REF|P_MOD))
4940Sstevel@tonic-gate 
4950Sstevel@tonic-gate #define	hat_clrmod(pp)		(hat_page_clrattr(pp, P_MOD))
4960Sstevel@tonic-gate #define	hat_clrref(pp)		(hat_page_clrattr(pp, P_REF))
4970Sstevel@tonic-gate #define	hat_clrrefmod(pp)	(hat_page_clrattr(pp, P_REF|P_MOD))
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate #define	hat_page_is_mapped(pp)	(hat_page_getshare(pp))
5000Sstevel@tonic-gate 
5010Sstevel@tonic-gate /*
5020Sstevel@tonic-gate  * hat_setup is being used in sparc/os/sundep.c
5030Sstevel@tonic-gate  */
5040Sstevel@tonic-gate void	hat_setup(struct hat *, int);
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate /*
5070Sstevel@tonic-gate  * Flags for hat_setup
5080Sstevel@tonic-gate  */
5090Sstevel@tonic-gate #define	HAT_DONTALLOC		0
5100Sstevel@tonic-gate #define	HAT_ALLOC		1
5110Sstevel@tonic-gate #define	HAT_INIT		2
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate /*
5140Sstevel@tonic-gate  * Other routines, for statistics
5150Sstevel@tonic-gate  */
5160Sstevel@tonic-gate int	hat_startstat(struct as *);
5170Sstevel@tonic-gate void	hat_getstat(struct as *, caddr_t, size_t, uint_t, char *, int);
5180Sstevel@tonic-gate void	hat_freestat(struct as *, int);
5190Sstevel@tonic-gate void	hat_resvstat(size_t, struct as *, caddr_t);
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate /*
5220Sstevel@tonic-gate  * Transitionary routine while we still allow hat_getkpfnum(caddr_t)
5230Sstevel@tonic-gate  * to return a pfn for kernel memory, but want to warn the user that
5240Sstevel@tonic-gate  * it isn't supported.
5250Sstevel@tonic-gate  */
5260Sstevel@tonic-gate void	hat_getkpfnum_badcall(void *caller);
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate /*
5290Sstevel@tonic-gate  * Relocation callback routines. Currently only sfmmu HAT supports
5300Sstevel@tonic-gate  * these.
5310Sstevel@tonic-gate  */
5320Sstevel@tonic-gate extern int	hat_add_callback(id_t, caddr_t, uint_t, uint_t, void *,
5332251Selowe 	pfn_t *, void **);
534670Selowe extern id_t	hat_register_callback(int,
5350Sstevel@tonic-gate 	int (*prehandler)(caddr_t, uint_t, uint_t, void *),
5360Sstevel@tonic-gate 	int (*posthandler)(caddr_t, uint_t, uint_t, void *, pfn_t),
5370Sstevel@tonic-gate 	int (*errhandler)(caddr_t, uint_t, uint_t, void *), int);
5382251Selowe extern void	hat_delete_callback(caddr_t, uint_t, void *, uint_t, void *);
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate /*
5410Sstevel@tonic-gate  * hat_add_callback()/hat_delete_callback() flags.
5420Sstevel@tonic-gate  */
5430Sstevel@tonic-gate #define	HAC_NOSLEEP	0x0
5440Sstevel@tonic-gate #define	HAC_SLEEP	0x1
5450Sstevel@tonic-gate #define	HAC_PAGELOCK	0x2
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate  * Suspend/unsuspend handler callback arguments.
5490Sstevel@tonic-gate  */
5500Sstevel@tonic-gate #define	HAT_SUSPEND		0x0010
5510Sstevel@tonic-gate #define	HAT_UNSUSPEND		0x0010
5520Sstevel@tonic-gate #define	HAT_PRESUSPEND		0x0020
5530Sstevel@tonic-gate #define	HAT_POSTUNSUSPEND	0x0020
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate /*
5560Sstevel@tonic-gate  * Error handler callback arguments. See the block comments
5570Sstevel@tonic-gate  * before the implementation of hat_add_callback() for an
5580Sstevel@tonic-gate  * explanation of what these mean.
5590Sstevel@tonic-gate  */
5600Sstevel@tonic-gate #define	HAT_CB_ERR_LEAKED	0x1
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate #endif /* _KERNEL */
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate /*
5650Sstevel@tonic-gate  * The size of the bit array for ref and mod bit storage must be a power of 2.
5660Sstevel@tonic-gate  * 2 bits are collected for each page.  Below the power used is 4,
5670Sstevel@tonic-gate  * which is 16 8-bit characters = 128 bits, ref and mod bit information
5680Sstevel@tonic-gate  * for 64 pages.
5690Sstevel@tonic-gate  */
5700Sstevel@tonic-gate #define	HRM_SHIFT		4
5710Sstevel@tonic-gate #define	HRM_BYTES		(1 << HRM_SHIFT)
5720Sstevel@tonic-gate #define	HRM_PAGES		((HRM_BYTES * NBBY) / 2)
5730Sstevel@tonic-gate #define	HRM_PGPERBYTE		(NBBY/2)
5740Sstevel@tonic-gate #define	HRM_PGBYTEMASK		(HRM_PGPERBYTE-1)
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate #define	HRM_PGOFFMASK		((HRM_PGPERBYTE-1) << MMU_PAGESHIFT)
5770Sstevel@tonic-gate #define	HRM_BASEOFFSET		(((MMU_PAGESIZE * HRM_PAGES) - 1))
5780Sstevel@tonic-gate #define	HRM_BASEMASK		(~(HRM_BASEOFFSET))
5790Sstevel@tonic-gate 
5800Sstevel@tonic-gate #define	HRM_BASESHIFT		(MMU_PAGESHIFT + (HRM_SHIFT + 2))
5810Sstevel@tonic-gate #define	HRM_PAGEMASK		(MMU_PAGEMASK ^ HRM_BASEMASK)
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate #define	HRM_HASHSIZE		0x200
5840Sstevel@tonic-gate #define	HRM_HASHMASK		(HRM_HASHSIZE - 1)
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate #define	HRM_BLIST_INCR		0x200
5870Sstevel@tonic-gate 
5880Sstevel@tonic-gate /*
5890Sstevel@tonic-gate  * The structure for maintaining referenced and modified information
5900Sstevel@tonic-gate  */
5910Sstevel@tonic-gate struct hrmstat {
5920Sstevel@tonic-gate 	struct as	*hrm_as;	/* stat block belongs to this as */
5930Sstevel@tonic-gate 	uintptr_t	hrm_base;	/* base of block */
5940Sstevel@tonic-gate 	ushort_t	hrm_id;		/* opaque identifier, one of a_vbits */
5950Sstevel@tonic-gate 	struct hrmstat	*hrm_anext;	/* as statistics block list */
5960Sstevel@tonic-gate 	struct hrmstat	*hrm_hnext;	/* list for hashed blocks */
5970Sstevel@tonic-gate 	uchar_t		hrm_bits[HRM_BYTES]; /* the ref and mod bits */
5980Sstevel@tonic-gate };
5990Sstevel@tonic-gate 
6003258Strevtom extern struct hrmstat **hrm_hashtab;
6013258Strevtom 
6020Sstevel@tonic-gate /*
6030Sstevel@tonic-gate  * For global monitoring of the reference and modified bits
6040Sstevel@tonic-gate  * of all address spaces we reserve one id bit.
6050Sstevel@tonic-gate  */
6060Sstevel@tonic-gate #define	HRM_SWSMONID	1
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate 
6090Sstevel@tonic-gate #ifdef _KERNEL
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate /*
6120Sstevel@tonic-gate  * Hat locking functions
6130Sstevel@tonic-gate  * XXX - these two functions are currently being used by hatstats
6140Sstevel@tonic-gate  * 	they can be removed by using a per-as mutex for hatstats.
6150Sstevel@tonic-gate  */
6160Sstevel@tonic-gate void	hat_enter(struct hat *);
6170Sstevel@tonic-gate void	hat_exit(struct hat *);
6180Sstevel@tonic-gate 
6194528Spaulsan typedef void (*hat_rgn_cb_func_t)(caddr_t, caddr_t, caddr_t,
6204528Spaulsan     size_t, void *, u_offset_t);
6214528Spaulsan 
6224528Spaulsan void			hat_join_srd(struct hat *, vnode_t *);
6234528Spaulsan 
6244528Spaulsan hat_region_cookie_t	hat_join_region(struct hat *, caddr_t, size_t, void *,
6254528Spaulsan 			    u_offset_t, uchar_t, uchar_t, hat_rgn_cb_func_t,
6264528Spaulsan 			    uint_t);
6274528Spaulsan void			hat_leave_region(struct hat *, hat_region_cookie_t,
6284528Spaulsan 			    uint_t);
6294528Spaulsan void			hat_dup_region(struct hat *, hat_region_cookie_t);
6304528Spaulsan 
6314528Spaulsan #define	HAT_INVALID_REGION_COOKIE	((hat_region_cookie_t)-1)
6324528Spaulsan #define	HAT_IS_REGION_COOKIE_VALID(c)	((c) != HAT_INVALID_REGION_COOKIE)
6334528Spaulsan 
6344528Spaulsan /* hat_join_region() flags */
6354528Spaulsan 
6364528Spaulsan #define	HAT_REGION_TEXT	0x1	/* passed by segvn */
6374528Spaulsan #define	HAT_REGION_ISM	0x2	/* for hat_share()/hat_unshare() */
6384528Spaulsan 
6394528Spaulsan #define	HAT_REGION_TYPE_MASK	(0x7)
6404528Spaulsan 
6410Sstevel@tonic-gate #endif /* _KERNEL */
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate #ifdef	__cplusplus
6440Sstevel@tonic-gate }
6450Sstevel@tonic-gate #endif
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate #endif	/* _VM_HAT_H */
648