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
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
31 * segkp (as in kernel pageable) is a segment driver that supports allocation
32 * of page-aligned variable size of vm resources.
34 * Each vm resource represents a page-aligned range of virtual addresses.
35 * The caller may specify whether the resource should include a redzone,
36 * be locked down, or be zero initialized.
49 * Private information per overall segkp segment (as opposed
50 * to per resource within segment). There are as many anon slots
51 * allocated as there there are pages in the segment.
53 struct segkp_segdata
{
54 struct anon_hdr
*kpsd_anon
; /* anon structs */
55 vmem_t
*kpsd_arena
; /* virtual memory descriptor */
56 struct segkp_data
**kpsd_hash
; /* Hash table for lookups */
59 #define SEGKP_VMEM(seg) (((struct segkp_segdata *)(seg)->s_data)->kpsd_arena)
62 * A hash table is used to aid in the lookup of a kpd's based on vaddr.
63 * Since the heaviest use of segkp occurs from segkp_*get and segkp_*release,
64 * the hashing is based on the vaddr used by these routines.
66 #define SEGKP_HASHSZ 256 /* power of two */
67 #define SEGKP_HASHMASK (SEGKP_HASHSZ - 1)
68 #define SEGKP_HASH(vaddr) \
69 ((int)(((uintptr_t)vaddr >> PAGESHIFT) & SEGKP_HASHMASK))
72 kmutex_t kp_lock
; /* per resource lock */
73 caddr_t kp_base
; /* starting addr of chunk */
74 size_t kp_len
; /* # of bytes */
75 uint_t kp_flags
; /* state info */
76 int kp_cookie
; /* index into cache array */
77 ulong_t kp_anon_idx
; /* index into main anon array */
78 /* in segkp_segdata */
79 struct anon_hdr
*kp_anon
; /* anon structs */
80 struct segkp_data
*kp_next
; /* ptr to next in hash chain */
87 #define KPD_ZERO 0x01 /* initialize resource with 0 */
88 #define KPD_LOCKED 0x02 /* resources locked */
89 #define KPD_NO_ANON 0x04 /* no swap resources required */
90 #define KPD_HASREDZONE 0x08 /* include a redzone */
91 #define KPD_NOWAIT 0x10 /* do not wait for res. if unavail. */
92 #define KPD_WRITEDIRTY 0x20 /* dirty pages should be flushed */
93 #define KPD_HASAMP 0x40 /* anon_hdr managed by caller */
96 * A cache of segkp elements may be created via segkp_cache_init().
97 * The elements on the freelist all have the same len and flags value.
98 * The cookie passed to the client is an index into the freelist array.
101 int kpf_max
; /* max # of elements allowed */
102 int kpf_count
; /* current no. of elments */
103 int kpf_inuse
; /* list inuse */
104 uint_t kpf_flags
; /* seg_kp flag value */
105 size_t kpf_len
; /* len of resource */
106 struct seg
*kpf_seg
; /* segment */
107 struct segkp_data
*kpf_list
; /* list of kpd's */
109 #define SEGKP_MAX_CACHE 4 /* Number of caches maintained */
112 * Define redzone, and stack_to_memory macros.
113 * The redzone is PAGESIZE bytes.
115 #ifdef STACK_GROWTH_DOWN
116 #define KPD_REDZONE(kpd) (0)
117 #define stom(v, flags) (((flags) & KPD_HASREDZONE) ? (v) + PAGESIZE : (v))
119 #else /* STACK_GROWTH_DOWN */
121 #define KPD_REDZONE(kpd) (btop(kpd->kp_len) - 1)
123 #endif /* STACK_GROWTH_DOWN */
125 #define SEGKP_MAPLEN(len, flags) \
126 (((flags) & KPD_HASREDZONE) ? (len) - PAGESIZE : (len))
128 extern struct seg
*segkp
;
129 /* If segkp becomes more than one seg this test will need changing. */
130 #define SEG_IS_SEGKP(SEG) ((SEG) == segkp)
133 * Public routine declarations not part of the segment ops vector go here.
135 int segkp_create(struct seg
*seg
);
136 caddr_t
segkp_get(struct seg
*seg
, size_t len
, uint_t flags
);
137 void segkp_release(struct seg
*seg
, caddr_t vaddr
);
138 void * segkp_cache_init(struct seg
*seg
, int maxsize
, size_t len
,
140 void segkp_cache_free();
141 caddr_t
segkp_cache_get(void *cookie
);
142 int segkp_map_red(void);
143 void segkp_unmap_red(void);
144 size_t swapsize(caddr_t v
);
146 /* Special currently only used by schedctl. */
147 struct anon_map
; /* Make the compiler happy about the next line. */
148 caddr_t
segkp_get_withanonmap(struct seg
*, size_t, uint_t
, struct anon_map
*);
151 * We allow explicit calls to segkp_fault, even though it's part
152 * of the segkp ops vector.
154 faultcode_t
segkp_fault(struct hat
*hat
, struct seg
*seg
, caddr_t addr
,
155 size_t len
, enum fault_type type
, enum seg_rw rw
);
163 #endif /* _VM_SEG_KP_H */