6514 AS_* lock macros simplification
[illumos-gate.git] / usr / src / uts / common / vm / seg_kp.h
blob64fa883cc9d00d77a9251c7f443088747b934c98
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _VM_SEG_KP_H
28 #define _VM_SEG_KP_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * segkp (as in kernel pageable) is a segment driver that supports allocation
34 * of page-aligned variable size of vm resources.
36 * Each vm resource represents a page-aligned range of virtual addresses.
37 * The caller may specify whether the resource should include a redzone,
38 * be locked down, or be zero initialized.
41 #include <vm/seg.h>
42 #include <sys/vmem.h>
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
48 #ifdef _KERNEL
51 * Private information per overall segkp segment (as opposed
52 * to per resource within segment). There are as many anon slots
53 * allocated as there there are pages in the segment.
55 struct segkp_segdata {
56 struct anon_hdr *kpsd_anon; /* anon structs */
57 vmem_t *kpsd_arena; /* virtual memory descriptor */
58 struct segkp_data **kpsd_hash; /* Hash table for lookups */
61 #define SEGKP_VMEM(seg) (((struct segkp_segdata *)(seg)->s_data)->kpsd_arena)
64 * A hash table is used to aid in the lookup of a kpd's based on vaddr.
65 * Since the heaviest use of segkp occurs from segkp_*get and segkp_*release,
66 * the hashing is based on the vaddr used by these routines.
68 #define SEGKP_HASHSZ 256 /* power of two */
69 #define SEGKP_HASHMASK (SEGKP_HASHSZ - 1)
70 #define SEGKP_HASH(vaddr) \
71 ((int)(((uintptr_t)vaddr >> PAGESHIFT) & SEGKP_HASHMASK))
73 struct segkp_data {
74 kmutex_t kp_lock; /* per resource lock */
75 caddr_t kp_base; /* starting addr of chunk */
76 size_t kp_len; /* # of bytes */
77 uint_t kp_flags; /* state info */
78 int kp_cookie; /* index into cache array */
79 ulong_t kp_anon_idx; /* index into main anon array */
80 /* in segkp_segdata */
81 struct anon_hdr *kp_anon; /* anon structs */
82 struct segkp_data *kp_next; /* ptr to next in hash chain */
86 * Flag bits
89 #define KPD_ZERO 0x01 /* initialize resource with 0 */
90 #define KPD_LOCKED 0x02 /* resources locked */
91 #define KPD_NO_ANON 0x04 /* no swap resources required */
92 #define KPD_HASREDZONE 0x08 /* include a redzone */
93 #define KPD_NOWAIT 0x10 /* do not wait for res. if unavail. */
94 #define KPD_WRITEDIRTY 0x20 /* dirty pages should be flushed */
95 #define KPD_HASAMP 0x40 /* anon_hdr managed by caller */
98 * A cache of segkp elements may be created via segkp_cache_init().
99 * The elements on the freelist all have the same len and flags value.
100 * The cookie passed to the client is an index into the freelist array.
102 struct segkp_cache {
103 int kpf_max; /* max # of elements allowed */
104 int kpf_count; /* current no. of elments */
105 int kpf_inuse; /* list inuse */
106 uint_t kpf_flags; /* seg_kp flag value */
107 size_t kpf_len; /* len of resource */
108 struct seg *kpf_seg; /* segment */
109 struct segkp_data *kpf_list; /* list of kpd's */
111 #define SEGKP_MAX_CACHE 4 /* Number of caches maintained */
114 * Define redzone, and stack_to_memory macros.
115 * The redzone is PAGESIZE bytes.
117 #ifdef STACK_GROWTH_DOWN
118 #define KPD_REDZONE(kpd) (0)
119 #define stom(v, flags) (((flags) & KPD_HASREDZONE) ? (v) + PAGESIZE : (v))
121 #else /* STACK_GROWTH_DOWN */
123 #define KPD_REDZONE(kpd) (btop(kpd->kp_len) - 1)
124 #define stom(v) (v)
125 #endif /* STACK_GROWTH_DOWN */
127 #define SEGKP_MAPLEN(len, flags) \
128 (((flags) & KPD_HASREDZONE) ? (len) - PAGESIZE : (len))
130 extern struct seg *segkp;
131 /* If segkp becomes more than one seg this test will need changing. */
132 #define SEG_IS_SEGKP(SEG) ((SEG) == segkp)
135 * Public routine declarations not part of the segment ops vector go here.
137 int segkp_create(struct seg *seg);
138 caddr_t segkp_get(struct seg *seg, size_t len, uint_t flags);
139 void segkp_release(struct seg *seg, caddr_t vaddr);
140 void * segkp_cache_init(struct seg *seg, int maxsize, size_t len,
141 uint_t flags);
142 void segkp_cache_free();
143 caddr_t segkp_cache_get(void *cookie);
144 int segkp_map_red(void);
145 void segkp_unmap_red(void);
146 size_t swapsize(caddr_t v);
148 /* Special currently only used by schedctl. */
149 struct anon_map; /* Make the compiler happy about the next line. */
150 caddr_t segkp_get_withanonmap(struct seg *, size_t, uint_t, struct anon_map *);
153 * We allow explicit calls to segkp_fault, even though it's part
154 * of the segkp ops vector.
156 faultcode_t segkp_fault(struct hat *hat, struct seg *seg, caddr_t addr,
157 size_t len, enum fault_type type, enum seg_rw rw);
159 #endif /* _KERNEL */
161 #ifdef __cplusplus
163 #endif
165 #endif /* _VM_SEG_KP_H */