hat.h revision 1bd5c35fd400f7f19eee9efd795c32cedb602b06
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#ifndef _VM_HAT_H
#define _VM_HAT_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <vm/faultcode.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* VM - Hardware Address Translation management.
*
* This file describes the machine independent interfaces to
* the hardware address translation management routines. Other
* machine specific interfaces and structures are defined
* translation hardware as a cache driven by calls from the
* higher levels of the VM system.
*/
struct hat;
struct kpme;
struct memseg;
/*
* a callback used with hat_unload_callback()
* start and end mark are set to a range of unloaded addresses
* and the function is invoked with a pointer to this data structure
*/
typedef struct hat_callback {
void (*hcb_function)(struct hat_callback *);
void *hcb_data;
#ifdef _KERNEL
/*
* One time hat initialization
*/
void hat_init(void);
/*
* Notify hat of a system dump
*/
void hat_dump(void);
/*
* Operations on an address space:
*
* struct hat *hat_alloc(as)
* allocated a hat structure for as.
*
* void hat_free_start(hat)
* informs hat layer process has finished executing but as has not
* been cleaned up yet.
*
* void hat_free_end(hat)
* informs hat layer as is being destroyed. hat layer cannot use as
* pointer after this call.
*
* void hat_swapin(hat)
* allocate any hat resources required for process being swapped in.
*
* void hat_swapout(hat)
* deallocate hat resources for process being swapped out.
*
* size_t hat_get_mapped_size(hat)
* returns number of bytes that have valid mappings in hat.
*
* void hat_stats_enable(hat)
* void hat_stats_disable(hat)
*
* int hat_dup(parenthat, childhat, addr, len, flags)
* Duplicate address translations of the parent to the child. Supports
* the entire address range or a range depending on flag,
* zero returned on success, non-zero on error
*
* void hat_thread_exit(thread)
* Notifies the HAT that a thread is exiting, called after it has been
* reassigned to the kernel AS.
*/
void hat_free_start(struct hat *);
void hat_free_end(struct hat *);
void hat_swapin(struct hat *);
void hat_swapout(struct hat *);
int hat_stats_enable(struct hat *);
void hat_stats_disable(struct hat *);
void hat_thread_exit(kthread_t *);
/*
* Operations on a named address within a segment:
*
* void hat_memload(hat, addr, pp, attr, flags)
*
* void hat_memload_array(hat, addr, len, ppa, attr, flags)
*
* void hat_devload(hat, addr, len, pf, attr, flags)
*
* void hat_unlock(hat, addr, len)
* unlock a given range of addresses
*
* void hat_unload(hat, addr, len, flags)
* void hat_unload_callback(hat, addr, len, flags, callback)
* unload a given range of addresses (has optional callback)
*
* void hat_sync(hat, addr, len, flags)
* synchronize mapping with software data structures
*
* void hat_map(hat, addr, len, flags)
*
* void hat_setattr(hat, addr, len, attr)
* void hat_clrattr(hat, addr, len, attr)
* void hat_chgattr(hat, addr, len, attr)
* modify attributes for a range of addresses. skips any invalid mappings
*
* uint_t hat_getattr(hat, addr, *attr)
* returns attr for <hat,addr> in *attr. returns 0 if there was a
* mapping and *attr is valid, nonzero if there was no mapping and
* *attr is not valid.
*
* size_t hat_getpagesize(hat, addr)
* returns pagesize in bytes for <hat, addr>. returns -1 if there is
* no mapping. This is an advisory call.
*
* pfn_t hat_getpfnum(hat, addr)
* returns pfn for <hat, addr> or PFN_INVALID if mapping is invalid.
*
* pfn_t hat_getkpfnum(addr)
* returns pfn for non-memory mapped addr in kernel address space
* or PFN_INVALID if mapping is invalid or is kernel memory.
*
* int hat_probe(hat, addr)
* return 0 if no valid mapping is present. Faster version
* of hat_getattr in certain architectures.
*
* int hat_share(dhat, daddr, shat, saddr, len, szc)
*
* void hat_unshare(hat, addr, len, szc)
*
* void hat_chgprot(hat, addr, len, vprot)
* This is a deprecated call. New segment drivers should store
* all attributes and use hat_*attr calls.
* Change the protections in the virtual address range
* given to the specified virtual protection. If vprot is ~PROT_WRITE,
* then remove write permission, leaving the other permissions
* unchanged. If vprot is ~PROT_USER, remove user permissions.
*/
hat_callback_t *);
/*
* hat_getkpfnum() is never supported on amd64 and will be
* removed from other platforms in future release
*/
#if !defined(__amd64)
#endif
/*
* Kernel Physical Mapping (segkpm) hat interface routines.
*/
void hat_kpm_mseghash_clear(int);
void hat_kpm_addmem_mseg_insert(struct memseg *);
void hat_kpm_addmem_memsegs_update(struct memseg *);
void hat_kpm_walk(void (*)(void *, void *, size_t), void *);
/*
* Operations on all translations for a given page(s)
*
* void hat_page_setattr(pp, flag)
* void hat_page_clrattr(pp, flag)
*
* uint hat_page_getattr(pp, flag)
* If flag is specified, returns 0 if attribute is disabled
* and non zero if enabled. If flag specifes multiple attributs
* then returns 0 if ALL atriibutes are disabled. This is an advisory
* call.
*
* int hat_pageunload(pp, forceflag)
* unload all translations attached to pp.
*
* uint_t hat_pagesync(pp, flags)
* get hw stats from hardware into page struct and reset hw stats
* returns attributes of page
*
* ulong_t hat_page_getshare(pp)
* returns approx number of mappings to this pp. A return of 0 implies
* there are no mappings to the page.
*
* faultcode_t hat_softlock(hat, addr, lenp, ppp, flags);
* called to softlock pages for zero copy tcp
*
* void hat_page_demote(pp);
* unload all large mappings to pp and decrease p_szc of all
* constituent pages according to the remaining mappings.
*/
void hat_page_demote(struct page *);
/*
* Rountine to expose supported HAT features to PIM.
*/
enum hat_features {
HAT_SHARED_PT, /* Shared page tables */
HAT_DYNAMIC_ISM_UNMAP, /* hat_pageunload() handles ISM pages */
HAT_VMODSORT /* support for VMODSORT flag of vnode */
};
int hat_supported(enum hat_features, void *);
/*
* Services provided to the hat:
*
* void as_signal_proc(as, siginfo)
* deliver signal to all processes that have this as.
*
* int hat_setstat(as, addr, len, rmbits)
* address range. Returns 0 on success, 1 for failure.
*/
/*
* Flags to pass to hat routines.
*
* Certain flags only apply to some interfaces:
*
* HAT_LOAD Default flags to load a translation to the page.
* HAT_LOAD_LOCK Lock down mapping resources; hat_map(), hat_memload(),
* and hat_devload().
* HAT_LOAD_ADV Advisory load - Load translation if and only if
* sufficient MMU resources exist (i.e., do not steal).
* HAT_LOAD_SHARE A flag to hat_memload() to indicate h/w page tables
* that map some user pages (not kas) is shared by more
* than one process (eg. ISM).
* HAT_LOAD_CONTIG Pages are contigous
* HAT_LOAD_NOCONSIST Do not add mapping to mapping list.
* HAT_LOAD_REMAP Reload a valid pte with a different page frame.
* HAT_RELOAD_SHARE Reload a shared page table entry. Some platforms
* may require different actions than on the first
* load of a shared mapping.
* HAT_NO_KALLOC Do not kmem_alloc while creating the mapping; at this
* point, it's setting up mapping to allocate internal
* hat layer data structures. This flag forces hat layer
* to tap its reserves in order to prevent infinite
* recursion.
* HAT_LOAD_AUTOLPG Get MMU specific disable_auto_large_pages
*/
/*
* Flags for hat_memload/hat_devload
*/
#define HAT_LOAD 0x00
#define HAT_LOAD_LOCK 0x01
#define HAT_LOAD_ADV 0x04
#define HAT_LOAD_CONTIG 0x10
#define HAT_LOAD_NOCONSIST 0x20
#define HAT_LOAD_SHARE 0x40
#define HAT_LOAD_REMAP 0x80
#define HAT_RELOAD_SHARE 0x100
#define HAT_NO_KALLOC 0x200
#define HAT_LOAD_TEXT 0x400
#define HAT_LOAD_AUTOLPG 0x800
/*
* Attributes for hat_memload/hat_devload/hat_*attr
* are a superset of prot flags defined in mman.h.
*/
#define HAT_PLAT_ATTR_MASK 0xF00000
#define HAT_PROT_MASK 0x0F
#define HAT_NOFAULT 0x10
#define HAT_NOSYNC 0x20
/*
* Advisory ordering attributes. Apply only to device mappings.
*
* HAT_STRICTORDER: the CPU must issue the references in order, as the
* programmer specified. This is the default.
* HAT_UNORDERED_OK: the CPU may reorder the references (this is all kinds
* of reordering; store or load with store or load).
* HAT_MERGING_OK: merging and batching: the CPU may merge individual stores
* to consecutive locations (for example, turn two consecutive byte
* stores into one halfword store), and it may batch individual loads
* (for example, turn two consecutive byte loads into one halfword load).
* This also implies re-ordering.
* HAT_LOADCACHING_OK: the CPU may cache the data it fetches and reuse it
* until another store occurs. The default is to fetch new data
* on every load. This also implies merging.
* HAT_STORECACHING_OK: the CPU may keep the data in the cache and push it to
* the device (perhaps with other data) at a later time. The default is
* to push the data right away. This also implies load caching.
*/
#define HAT_STRICTORDER 0x0000
#define HAT_UNORDERED_OK 0x0100
#define HAT_MERGING_OK 0x0200
#define HAT_LOADCACHING_OK 0x0300
#define HAT_STORECACHING_OK 0x0400
#define HAT_ORDER_MASK 0x0700
/* endian attributes */
#define HAT_NEVERSWAP 0x0000
#define HAT_STRUCTURE_BE 0x1000
#define HAT_STRUCTURE_LE 0x2000
#define HAT_ENDIAN_MASK 0x3000
/* flags for hat_softlock */
#define HAT_COW 0x0001
/*
* Flags for hat_unload
*/
#define HAT_UNLOAD 0x00
#define HAT_UNLOAD_NOSYNC 0x02
#define HAT_UNLOAD_UNLOCK 0x04
#define HAT_UNLOAD_OTHER 0x08
#define HAT_UNLOAD_UNMAP 0x10
/*
* Flags for hat_pagesync, hat_getstat, hat_sync
*/
#define HAT_SYNC_DONTZERO 0x00
#define HAT_SYNC_ZERORM 0x01
/* Additional flags for hat_pagesync */
#define HAT_SYNC_STOPON_REF 0x02
#define HAT_SYNC_STOPON_MOD 0x04
#define HAT_SYNC_STOPON_SHARED 0x08
/*
* Flags for hat_dup
*
* HAT_DUP_ALL dup entire address space
* HAT_DUP_COW dup plus hat_clrattr(..PROT_WRITE) on newas
*/
#define HAT_DUP_ALL 1
#define HAT_DUP_COW 2
/*
* Flags for hat_map
*/
#define HAT_MAP 0x00
/*
* Flag for hat_pageunload
*/
#define HAT_ADV_PGUNLOAD 0x00
#define HAT_FORCE_PGUNLOAD 0x01
/*
* Attributes for hat_page_*attr, hat_setstats and
* returned by hat_pagesync.
*/
/*
*/
/*
* Flags for hat_setup
*/
#define HAT_DONTALLOC 0
#define HAT_ALLOC 1
#define HAT_INIT 2
/*
* Other routines, for statistics
*/
int hat_startstat(struct as *);
void hat_freestat(struct as *, int);
/*
* Transitionary routine while we still allow hat_getkpfnum(caddr_t)
* to return a pfn for kernel memory, but want to warn the user that
* it isn't supported.
*/
void hat_getkpfnum_badcall(void *caller);
/*
* Relocation callback routines. Currently only sfmmu HAT supports
* these.
*/
pfn_t *);
extern id_t hat_register_callback(int,
/*
* hat_add_callback()/hat_delete_callback() flags.
*/
#define HAC_NOSLEEP 0x0
#define HAC_SLEEP 0x1
#define HAC_PAGELOCK 0x2
/*
*/
#define HAT_SUSPEND 0x0010
#define HAT_UNSUSPEND 0x0010
#define HAT_PRESUSPEND 0x0020
#define HAT_POSTUNSUSPEND 0x0020
/*
* Error handler callback arguments. See the block comments
* before the implementation of hat_add_callback() for an
* explanation of what these mean.
*/
#define HAT_CB_ERR_LEAKED 0x1
#endif /* _KERNEL */
/*
* The size of the bit array for ref and mod bit storage must be a power of 2.
* 2 bits are collected for each page. Below the power used is 4,
* which is 16 8-bit characters = 128 bits, ref and mod bit information
* for 64 pages.
*/
#define HRM_SHIFT 4
#define HRM_BASEMASK (~(HRM_BASEOFFSET))
#define HRM_HASHSIZE 0x200
#define HRM_BLIST_INCR 0x200
/*
* The structure for maintaining referenced and modified information
*/
struct hrmstat {
};
/*
* For global monitoring of the reference and modified bits
* of all address spaces we reserve one id bit.
*/
#define HRM_SWSMONID 1
#ifdef _KERNEL
/*
* Hat locking functions
* XXX - these two functions are currently being used by hatstats
* they can be removed by using a per-as mutex for hatstats.
*/
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _VM_HAT_H */