pkg: ship usr/lib/security/amd64/*.so links
[unleashed.git] / include / vm / hat.h
blob34029a233a8b8d439950e160bd2392cf45359533
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
39 #ifndef _VM_HAT_H
40 #define _VM_HAT_H
42 #include <sys/types.h>
43 #include <sys/t_lock.h>
44 #include <vm/faultcode.h>
45 #include <sys/kstat.h>
46 #include <sys/siginfo.h>
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
53 * VM - Hardware Address Translation management.
55 * This file describes the machine independent interfaces to
56 * the hardware address translation management routines. Other
57 * machine specific interfaces and structures are defined
58 * in <vm/hat_xxx.h>. The hat layer manages the address
59 * translation hardware as a cache driven by calls from the
60 * higher levels of the VM system.
63 struct hat;
64 struct kpme;
65 struct memseg;
67 #include <vm/page.h>
70 * a callback used with hat_unload_callback()
71 * start and end mark are set to a range of unloaded addresses
72 * and the function is invoked with a pointer to this data structure
74 typedef struct hat_callback {
75 caddr_t hcb_start_addr;
76 caddr_t hcb_end_addr;
77 void (*hcb_function)(struct hat_callback *);
78 void *hcb_data;
79 } hat_callback_t;
81 typedef void *hat_region_cookie_t;
83 #ifdef _KERNEL
86 * One time hat initialization
88 void hat_init(void);
91 * Notify hat of a system dump
93 void hat_dump(void);
96 * Operations on an address space:
98 * struct hat *hat_alloc(as)
99 * allocated a hat structure for as.
101 * void hat_free_start(hat)
102 * informs hat layer process has finished executing but as has not
103 * been cleaned up yet.
105 * void hat_free_end(hat)
106 * informs hat layer as is being destroyed. hat layer cannot use as
107 * pointer after this call.
109 * size_t hat_get_mapped_size(hat)
110 * returns number of bytes that have valid mappings in hat.
112 * void hat_stats_enable(hat)
113 * void hat_stats_disable(hat)
114 * enables/disables collection of stats for hat.
116 * int hat_dup(parenthat, childhat, addr, len, flags)
117 * Duplicate address translations of the parent to the child. Supports
118 * the entire address range or a range depending on flag,
119 * zero returned on success, non-zero on error
121 * void hat_thread_exit(thread)
122 * Notifies the HAT that a thread is exiting, called after it has been
123 * reassigned to the kernel AS.
126 struct hat *hat_alloc(struct as *);
127 void hat_free_start(struct hat *);
128 void hat_free_end(struct hat *);
129 int hat_dup(struct hat *, struct hat *, caddr_t, size_t, uint_t);
130 size_t hat_get_mapped_size(struct hat *);
131 int hat_stats_enable(struct hat *);
132 void hat_stats_disable(struct hat *);
133 void hat_thread_exit(kthread_t *);
136 * Operations on a named address within a segment:
138 * void hat_memload(hat, addr, pp, attr, flags)
139 * load/lock the given page struct
141 * void hat_memload_array(hat, addr, len, ppa, attr, flags)
142 * load/lock the given array of page structs
144 * void hat_devload(hat, addr, len, pf, attr, flags)
145 * load/lock the given page frame number
147 * void hat_unlock(hat, addr, len)
148 * unlock a given range of addresses
150 * void hat_unload(hat, addr, len, flags)
151 * void hat_unload_callback(hat, addr, len, flags, callback)
152 * unload a given range of addresses (has optional callback)
154 * void hat_sync(hat, addr, len, flags)
155 * synchronize mapping with software data structures
157 * void hat_map(hat, addr, len, flags)
159 * void hat_setattr(hat, addr, len, attr)
160 * void hat_clrattr(hat, addr, len, attr)
161 * void hat_chgattr(hat, addr, len, attr)
162 * modify attributes for a range of addresses. skips any invalid mappings
164 * uint_t hat_getattr(hat, addr, *attr)
165 * returns attr for <hat,addr> in *attr. returns 0 if there was a
166 * mapping and *attr is valid, nonzero if there was no mapping and
167 * *attr is not valid.
169 * size_t hat_getpagesize(hat, addr)
170 * returns pagesize in bytes for <hat, addr>. returns -1 if there is
171 * no mapping. This is an advisory call.
173 * pfn_t hat_getpfnum(hat, addr)
174 * returns pfn for <hat, addr> or PFN_INVALID if mapping is invalid.
176 * int hat_probe(hat, addr)
177 * return 0 if no valid mapping is present. Faster version
178 * of hat_getattr in certain architectures.
180 * int hat_share(dhat, daddr, shat, saddr, len, szc)
182 * void hat_unshare(hat, addr, len, szc)
184 * void hat_chgprot(hat, addr, len, vprot)
185 * This is a deprecated call. New segment drivers should store
186 * all attributes and use hat_*attr calls.
187 * Change the protections in the virtual address range
188 * given to the specified virtual protection. If vprot is ~PROT_WRITE,
189 * then remove write permission, leaving the other permissions
190 * unchanged. If vprot is ~PROT_USER, remove user permissions.
192 * void hat_flush_range(hat, addr, size)
193 * Invalidate a virtual address translation for the local CPU.
196 void hat_memload(struct hat *, caddr_t, struct page *, uint_t, uint_t);
197 void hat_memload_array(struct hat *, caddr_t, size_t, struct page **,
198 uint_t, uint_t);
199 void hat_memload_region(struct hat *, caddr_t, struct page *, uint_t,
200 uint_t, hat_region_cookie_t);
201 void hat_memload_array_region(struct hat *, caddr_t, size_t, struct page **,
202 uint_t, uint_t, hat_region_cookie_t);
204 void hat_devload(struct hat *, caddr_t, size_t, pfn_t, uint_t, int);
206 void hat_unlock(struct hat *, caddr_t, size_t);
207 void hat_unlock_region(struct hat *, caddr_t, size_t, hat_region_cookie_t);
209 void hat_unload(struct hat *, caddr_t, size_t, uint_t);
210 void hat_unload_callback(struct hat *, caddr_t, size_t, uint_t,
211 hat_callback_t *);
212 void hat_flush_range(struct hat *, caddr_t, size_t);
213 void hat_sync(struct hat *, caddr_t, size_t, uint_t);
214 void hat_map(struct hat *, caddr_t, size_t, uint_t);
215 void hat_setattr(struct hat *, caddr_t, size_t, uint_t);
216 void hat_clrattr(struct hat *, caddr_t, size_t, uint_t);
217 void hat_chgattr(struct hat *, caddr_t, size_t, uint_t);
218 uint_t hat_getattr(struct hat *, caddr_t, uint_t *);
219 ssize_t hat_getpagesize(struct hat *, caddr_t);
220 pfn_t hat_getpfnum(struct hat *, caddr_t);
221 int hat_probe(struct hat *, caddr_t);
222 int hat_share(struct hat *, caddr_t, struct hat *, caddr_t, size_t, uint_t);
223 void hat_unshare(struct hat *, caddr_t, size_t, uint_t);
224 void hat_chgprot(struct hat *, caddr_t, size_t, uint_t);
225 void hat_reserve(struct as *, caddr_t, size_t);
226 pfn_t va_to_pfn(void *);
227 uint64_t va_to_pa(void *);
230 * Kernel Physical Mapping (segkpm) hat interface routines.
232 caddr_t hat_kpm_mapin(struct page *, struct kpme *);
233 void hat_kpm_mapout(struct page *, struct kpme *, caddr_t);
234 caddr_t hat_kpm_mapin_pfn(pfn_t);
235 void hat_kpm_mapout_pfn(pfn_t);
236 caddr_t hat_kpm_page2va(struct page *, int);
237 struct page *hat_kpm_vaddr2page(caddr_t);
238 int hat_kpm_fault(struct hat *, caddr_t);
239 void hat_kpm_mseghash_clear(int);
240 void hat_kpm_mseghash_update(pgcnt_t, struct memseg *);
241 void hat_kpm_addmem_mseg_update(struct memseg *, pgcnt_t, offset_t);
242 void hat_kpm_addmem_mseg_insert(struct memseg *);
243 void hat_kpm_addmem_memsegs_update(struct memseg *);
244 caddr_t hat_kpm_mseg_reuse(struct memseg *);
245 void hat_kpm_delmem_mseg_update(struct memseg *, struct memseg **);
246 void hat_kpm_split_mseg_update(struct memseg *, struct memseg **,
247 struct memseg *, struct memseg *, struct memseg *);
248 void hat_kpm_walk(void (*)(void *, void *, size_t), void *);
251 * Operations on all translations for a given page(s)
253 * void hat_page_setattr(pp, flag)
254 * void hat_page_clrattr(pp, flag)
255 * used to set/clr red/mod bits.
257 * uint hat_page_getattr(pp, flag)
258 * If flag is specified, returns 0 if attribute is disabled
259 * and non zero if enabled. If flag specifes multiple attributs
260 * then returns 0 if ALL atriibutes are disabled. This is an advisory
261 * call.
263 * int hat_pageunload(pp, forceflag)
264 * unload all translations attached to pp.
266 * uint_t hat_pagesync(pp, flags)
267 * get hw stats from hardware into page struct and reset hw stats
268 * returns attributes of page
270 * ulong_t hat_page_getshare(pp)
271 * returns approx number of mappings to this pp. A return of 0 implies
272 * there are no mappings to the page.
274 * faultcode_t hat_softlock(hat, addr, lenp, ppp, flags);
275 * called to softlock pages for zero copy tcp
277 * void hat_page_demote(pp);
278 * unload all large mappings to pp and decrease p_szc of all
279 * constituent pages according to the remaining mappings.
282 void hat_page_setattr(struct page *, uint_t);
283 void hat_page_clrattr(struct page *, uint_t);
284 uint_t hat_page_getattr(struct page *, uint_t);
285 int hat_pageunload(struct page *, uint_t);
286 uint_t hat_pagesync(struct page *, uint_t);
287 ulong_t hat_page_getshare(struct page *);
288 int hat_page_checkshare(struct page *, ulong_t);
289 faultcode_t hat_softlock(struct hat *, caddr_t, size_t *,
290 struct page **, uint_t);
291 void hat_page_demote(struct page *);
294 * Rountine to expose supported HAT features to PIM.
296 enum hat_features {
297 HAT_SHARED_PT, /* Shared page tables */
298 HAT_DYNAMIC_ISM_UNMAP, /* hat_pageunload() handles ISM pages */
299 HAT_SHARED_REGIONS /* shared regions support */
302 int hat_supported(enum hat_features, void *);
305 * Services provided to the hat:
307 * void as_signal_proc(as, siginfo)
308 * deliver signal to all processes that have this as.
310 * int hat_setstat(as, addr, len, rmbits)
311 * informs hatstat layer that ref/mod bits need to be updated for
312 * address range. Returns 0 on success, 1 for failure.
314 void as_signal_proc(struct as *, k_siginfo_t *siginfo);
315 void hat_setstat(struct as *, caddr_t, size_t, uint_t);
318 * Flags to pass to hat routines.
320 * Certain flags only apply to some interfaces:
322 * HAT_LOAD Default flags to load a translation to the page.
323 * HAT_LOAD_LOCK Lock down mapping resources; hat_map(), hat_memload(),
324 * and hat_devload().
325 * HAT_LOAD_ADV Advisory load - Load translation if and only if
326 * sufficient MMU resources exist (i.e., do not steal).
327 * HAT_LOAD_SHARE A flag to hat_memload() to indicate h/w page tables
328 * that map some user pages (not kas) is shared by more
329 * than one process (eg. ISM).
330 * HAT_LOAD_CONTIG Pages are contigous
331 * HAT_LOAD_NOCONSIST Do not add mapping to mapping list.
332 * HAT_LOAD_REMAP Reload a valid pte with a different page frame.
333 * HAT_RELOAD_SHARE Reload a shared page table entry. Some platforms
334 * may require different actions than on the first
335 * load of a shared mapping.
336 * HAT_NO_KALLOC Do not kmem_alloc while creating the mapping; at this
337 * point, it's setting up mapping to allocate internal
338 * hat layer data structures. This flag forces hat layer
339 * to tap its reserves in order to prevent infinite
340 * recursion.
341 * HAT_LOAD_TEXT A flag to hat_memload() to indicate loading text pages.
345 * Flags for hat_memload/hat_devload
347 #define HAT_FLAGS_RESV 0xFF000000 /* resv for hat impl */
348 #define HAT_LOAD 0x00
349 #define HAT_LOAD_LOCK 0x01
350 #define HAT_LOAD_ADV 0x04
351 #define HAT_LOAD_CONTIG 0x10
352 #define HAT_LOAD_NOCONSIST 0x20
353 #define HAT_LOAD_SHARE 0x40
354 #define HAT_LOAD_REMAP 0x80
355 #define HAT_RELOAD_SHARE 0x100
356 #define HAT_NO_KALLOC 0x200
357 #define HAT_LOAD_TEXT 0x400
360 * Flags for initializing disable_*large_pages.
362 * HAT_AUTO_TEXT Get MMU specific disable_auto_text_large_pages
363 * HAT_AUTO_DATA Get MMU specific disable_auto_data_large_pages
365 #define HAT_AUTO_TEXT 0x800
366 #define HAT_AUTO_DATA 0x1000
369 * Attributes for hat_memload/hat_devload/hat_*attr
370 * are a superset of prot flags defined in mman.h.
372 #define HAT_PLAT_ATTR_MASK 0xF00000
373 #define HAT_PROT_MASK 0x0F
375 #define HAT_NOFAULT 0x10
376 #define HAT_NOSYNC 0x20
379 * Advisory ordering attributes. Apply only to device mappings.
381 * HAT_STRICTORDER: the CPU must issue the references in order, as the
382 * programmer specified. This is the default.
383 * HAT_UNORDERED_OK: the CPU may reorder the references (this is all kinds
384 * of reordering; store or load with store or load).
385 * HAT_MERGING_OK: merging and batching: the CPU may merge individual stores
386 * to consecutive locations (for example, turn two consecutive byte
387 * stores into one halfword store), and it may batch individual loads
388 * (for example, turn two consecutive byte loads into one halfword load).
389 * This also implies re-ordering.
390 * HAT_LOADCACHING_OK: the CPU may cache the data it fetches and reuse it
391 * until another store occurs. The default is to fetch new data
392 * on every load. This also implies merging.
393 * HAT_STORECACHING_OK: the CPU may keep the data in the cache and push it to
394 * the device (perhaps with other data) at a later time. The default is
395 * to push the data right away. This also implies load caching.
397 #define HAT_STRICTORDER 0x0000
398 #define HAT_UNORDERED_OK 0x0100
399 #define HAT_MERGING_OK 0x0200
400 #define HAT_LOADCACHING_OK 0x0300
401 #define HAT_STORECACHING_OK 0x0400
402 #define HAT_ORDER_MASK 0x0700
404 /* endian attributes */
405 #define HAT_NEVERSWAP 0x0000
406 #define HAT_STRUCTURE_BE 0x1000
407 #define HAT_STRUCTURE_LE 0x2000
408 #define HAT_ENDIAN_MASK 0x3000
410 /* flags for hat_softlock */
411 #define HAT_COW 0x0001
414 * Flags for hat_unload
416 #define HAT_UNLOAD 0x00
417 #define HAT_UNLOAD_NOSYNC 0x02
418 #define HAT_UNLOAD_UNLOCK 0x04
419 #define HAT_UNLOAD_OTHER 0x08
420 #define HAT_UNLOAD_UNMAP 0x10
423 * Flags for hat_pagesync, hat_getstat, hat_sync
425 #define HAT_SYNC_DONTZERO 0x00
426 #define HAT_SYNC_ZERORM 0x01
427 /* Additional flags for hat_pagesync */
428 #define HAT_SYNC_STOPON_REF 0x02
429 #define HAT_SYNC_STOPON_MOD 0x04
430 #define HAT_SYNC_STOPON_RM (HAT_SYNC_STOPON_REF | HAT_SYNC_STOPON_MOD)
431 #define HAT_SYNC_STOPON_SHARED 0x08
434 * Flags for hat_dup
436 * HAT_DUP_ALL dup entire address space
437 * HAT_DUP_COW dup plus hat_clrattr(..PROT_WRITE) on newas
439 #define HAT_DUP_ALL 1
440 #define HAT_DUP_COW 2
441 #define HAT_DUP_SRD 3
445 * Flags for hat_map
447 #define HAT_MAP 0x00
450 * Flag for hat_pageunload
452 #define HAT_ADV_PGUNLOAD 0x00
453 #define HAT_FORCE_PGUNLOAD 0x01
456 * Attributes for hat_page_*attr, hat_setstats and
457 * returned by hat_pagesync.
459 #define P_MOD 0x1 /* the modified bit */
460 #define P_REF 0x2 /* the referenced bit */
461 #define P_RO 0x4 /* Read only page */
462 #define P_NSH 0x8 /* Not to shuffle vmobject's page list */
464 #define hat_ismod(pp) (hat_page_getattr(pp, P_MOD))
465 #define hat_isref(pp) (hat_page_getattr(pp, P_REF))
466 #define hat_isro(pp) (hat_page_getattr(pp, P_RO))
468 #define hat_setmod(pp) (hat_page_setattr(pp, P_MOD))
469 #define hat_setmod_only(pp) (hat_page_setattr(pp, P_MOD|P_NSH))
470 #define hat_setref(pp) (hat_page_setattr(pp, P_REF))
471 #define hat_setrefmod(pp) (hat_page_setattr(pp, P_REF|P_MOD))
473 #define hat_clrmod(pp) (hat_page_clrattr(pp, P_MOD))
474 #define hat_clrref(pp) (hat_page_clrattr(pp, P_REF))
475 #define hat_clrrefmod(pp) (hat_page_clrattr(pp, P_REF|P_MOD))
477 #define hat_page_is_mapped(pp) (hat_page_getshare(pp))
480 * hat_setup is being used in sparc/os/sundep.c
482 void hat_setup(struct hat *, int);
485 * Flags for hat_setup
487 #define HAT_DONTALLOC 0
488 #define HAT_ALLOC 1
489 #define HAT_INIT 2
492 * Other routines, for statistics
494 int hat_startstat(struct as *);
495 void hat_getstat(struct as *, caddr_t, size_t, uint_t, char *, int);
496 void hat_freestat(struct as *, int);
497 void hat_resvstat(size_t, struct as *, caddr_t);
500 * Relocation callback routines. Currently only sfmmu HAT supports
501 * these.
503 extern int hat_add_callback(id_t, caddr_t, uint_t, uint_t, void *,
504 pfn_t *, void **);
505 extern id_t hat_register_callback(int,
506 int (*prehandler)(caddr_t, uint_t, uint_t, void *),
507 int (*posthandler)(caddr_t, uint_t, uint_t, void *, pfn_t),
508 int (*errhandler)(caddr_t, uint_t, uint_t, void *), int);
509 extern void hat_delete_callback(caddr_t, uint_t, void *, uint_t, void *);
512 * hat_add_callback()/hat_delete_callback() flags.
514 #define HAC_NOSLEEP 0x0
515 #define HAC_SLEEP 0x1
516 #define HAC_PAGELOCK 0x2
519 * Suspend/unsuspend handler callback arguments.
521 #define HAT_SUSPEND 0x0010
522 #define HAT_UNSUSPEND 0x0010
523 #define HAT_PRESUSPEND 0x0020
524 #define HAT_POSTUNSUSPEND 0x0020
527 * Error handler callback arguments. See the block comments
528 * before the implementation of hat_add_callback() for an
529 * explanation of what these mean.
531 #define HAT_CB_ERR_LEAKED 0x1
533 #endif /* _KERNEL */
536 * The size of the bit array for ref and mod bit storage must be a power of 2.
537 * 2 bits are collected for each page. Below the power used is 4,
538 * which is 16 8-bit characters = 128 bits, ref and mod bit information
539 * for 64 pages.
541 #define HRM_SHIFT 4
542 #define HRM_BYTES (1 << HRM_SHIFT)
543 #define HRM_PAGES ((HRM_BYTES * NBBY) / 2)
544 #define HRM_PGPERBYTE (NBBY/2)
545 #define HRM_PGBYTEMASK (HRM_PGPERBYTE-1)
547 #define HRM_PGOFFMASK ((HRM_PGPERBYTE-1) << MMU_PAGESHIFT)
548 #define HRM_BASEOFFSET (((MMU_PAGESIZE * HRM_PAGES) - 1))
549 #define HRM_BASEMASK (~(HRM_BASEOFFSET))
551 #define HRM_BASESHIFT (MMU_PAGESHIFT + (HRM_SHIFT + 2))
552 #define HRM_PAGEMASK (MMU_PAGEMASK ^ HRM_BASEMASK)
554 #define HRM_HASHSIZE 0x200
555 #define HRM_HASHMASK (HRM_HASHSIZE - 1)
557 #define HRM_BLIST_INCR 0x200
560 * The structure for maintaining referenced and modified information
562 struct hrmstat {
563 struct as *hrm_as; /* stat block belongs to this as */
564 uintptr_t hrm_base; /* base of block */
565 ushort_t hrm_id; /* opaque identifier, one of a_vbits */
566 struct hrmstat *hrm_anext; /* as statistics block list */
567 struct hrmstat *hrm_hnext; /* list for hashed blocks */
568 uchar_t hrm_bits[HRM_BYTES]; /* the ref and mod bits */
571 extern struct hrmstat **hrm_hashtab;
574 * For global monitoring of the reference and modified bits
575 * of all address spaces we reserve one id bit.
577 #define HRM_SWSMONID 1
580 #ifdef _KERNEL
583 * Hat locking functions
584 * XXX - these two functions are currently being used by hatstats
585 * they can be removed by using a per-as mutex for hatstats.
587 void hat_enter(struct hat *);
588 void hat_exit(struct hat *);
590 typedef void (*hat_rgn_cb_func_t)(caddr_t, caddr_t, caddr_t,
591 size_t, void *, uoff_t);
593 void hat_join_srd(struct hat *, vnode_t *);
595 hat_region_cookie_t hat_join_region(struct hat *, caddr_t, size_t, void *,
596 uoff_t, uchar_t, uchar_t, hat_rgn_cb_func_t,
597 uint_t);
598 void hat_leave_region(struct hat *, hat_region_cookie_t,
599 uint_t);
600 void hat_dup_region(struct hat *, hat_region_cookie_t);
602 #define HAT_INVALID_REGION_COOKIE ((hat_region_cookie_t)-1)
603 #define HAT_IS_REGION_COOKIE_VALID(c) ((c) != HAT_INVALID_REGION_COOKIE)
605 /* hat_join_region() flags */
607 #define HAT_REGION_TEXT 0x1 /* passed by segvn */
608 #define HAT_REGION_ISM 0x2 /* for hat_share()/hat_unshare() */
610 #define HAT_REGION_TYPE_MASK (0x7)
612 #endif /* _KERNEL */
614 #ifdef __cplusplus
616 #endif
618 #endif /* _VM_HAT_H */