htable.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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.
*/
#ifndef _VM_HTABLE_H
#define _VM_HTABLE_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#endif
/*
* Each hardware page table has an htable_t describing it.
*
* We use a reference counter mechanism to detect when we can free an htable.
* In the implmentation the reference count is split into 2 separate counters:
*
* ht_busy is a traditional reference count of uses of the htable pointer
*
* entries in the pagetable
*
* ht_busy is only incremented by htable_lookup() or htable_create()
* while holding the appropriate hash_table mutex. While installing a new
* valid PTE or PTP, in order to increment ht_valid_cnt a thread must have
* done an htable_lookup() or htable_create() but not the htable_release yet.
*
* htable_release(), while holding the mutex, can know that if
* busy == 1 and valid_cnt == 0, the htable can be free'd.
*
* The fields have been ordered to make htable_lookup() fast. Hence,
* ht_hat, ht_vaddr, ht_level and ht_next need to be clustered together.
*/
struct htable {
/* never used for kernel hat */
};
/*
* Flags values for htable ht_flags field:
*
* HTABLE_VLP - this is the top level htable of a VLP HAT.
*
* HTABLE_SHARED_PFN - this htable had it's PFN assigned from sharing another
* htable. Used by hat_share() for ISM.
*/
#define HTABLE_VLP (0x0001)
#define HTABLE_SHARED_PFN (0x0002)
/*
* The htable hash table hashing function. The 28 is so that high
* order bits are include in the hash index to skew the wrap
* around of addresses.
*/
/*
* For 32 bit, access to page table entries is done via the page table's PFN and
* the index of the PTE. We use a CPU specific mapping (a la ppcopy) to map
* in page tables on an "as needed" basis.
*
* 64 bit kernels will use seg_kpm style mappings and avoid any overhead.
*
* avoid atomicity problems, since PTEs can be 8 bytes on 32 bit systems.
* will naturally be atomic.
*
* Each CPU gets a unique hat_cpu_info structure in cpu_hat_info.
*/
struct hat_cpu_info {
#if defined(__amd64)
#endif /* __amd64 */
};
/*
* Compute the last page aligned VA mapped by an htable.
*
* Given a va and a level, compute the virtual address of the start of the
* next page at that level.
*
* XX64 - The check for the VA hole needs to be better generalized.
*/
#if defined(__amd64)
#define HTABLE_LAST_PAGE(ht) \
#define NEXT_ENTRY_VA(va, l) \
#endif
#if defined(_KERNEL)
/*
* initialization function called from hat_init()
*/
extern void htable_init(void);
/*
* Functions to lookup, or "lookup and create", the htable corresponding
* to the virtual address "vaddr" in the "hat" at the given "level" of
* page tables. htable_lookup() may return NULL if no such entry exists.
*
* On return the given htable is marked busy (a shared lock) - this prevents
* the htable from being stolen or freed) until htable_release() is called.
*
* If kalloc_flag is set on an htable_create() we can't call kmem allocation
* routines for this htable, since it's for the kernel hat itself.
*
* htable_acquire() is used when an htable pointer has been extracted from
* an hment and we need to get a reference to the htable.
*/
extern void htable_acquire(htable_t *);
/*
* Code to free all remaining htables for a hat. Called after the hat is no
* longer in use by any thread.
*/
/*
* Find the htable, page table entry index, and PTE of the given virtual
* address. If not found returns NULL. When found, returns the htable_t *,
* sets entry, and has a hold on the htable.
*/
level_t);
/*
* Similar to hat_getpte(), except that this only succeeds if a valid
* page mapping is present.
*/
/*
* Called to allocate initial/additional htables for reserve.
*/
extern void htable_initial_reserve(uint_t);
extern void htable_reserve(uint_t);
/*
* Used to readjust the htable reserve after the reserve list has been used.
* Also called after boot to release left over boot reserves.
*/
extern void htable_adjust_reserve(void);
/*
* Routine to find the next populated htable at or above a given virtual
* address. Can specify an upper limit, or HTABLE_WALK_TO_END to indicate
* that it should search the entire address space. Similar to
* hat_getpte(), but used for walking through address ranges. It can be
* used like this:
*
* va = ...
* ht = NULL;
* while (va < end_va) {
* pte = htable_walk(hat, &ht, &va, end_va);
* if (!pte)
* break;
*
* ... code to operate on page at va ...
*
* va += LEVEL_SIZE(ht->ht_level);
* }
* if (ht)
* htable_release(ht);
*
*/
/*
* Utilities convert between virtual addresses and page table entry indeces.
*/
/*
* Interfaces that provide access to page table entries via the htable.
*
* Note that all accesses except x86pte_copy() and x86pte_zero() are atomic.
*/
extern void x86pte_cpu_init(cpu_t *, void *);
void *pte_ptr);
/*
* these are actually inlines for "lock; incw", "lock; decw", etc. instructions.
*/
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _VM_HTABLE_H */