FreeBSD/Linux Kernel Cross Reference
sys/uvm/uvm_map_i.h
1 /* $NetBSD: uvm_map_i.h,v 1.28 2004/02/10 01:30:49 matt Exp $ */
2
3 /*
4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 * Copyright (c) 1991, 1993, The Regents of the University of California.
6 *
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * The Mach Operating System project at Carnegie-Mellon University.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by Charles D. Cranor,
23 * Washington University, the University of California, Berkeley and
24 * its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)vm_map.c 8.3 (Berkeley) 1/12/94
42 * from: Id: uvm_map_i.h,v 1.1.2.1 1997/08/14 19:10:50 chuck Exp
43 *
44 *
45 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
46 * All rights reserved.
47 *
48 * Permission to use, copy, modify and distribute this software and
49 * its documentation is hereby granted, provided that both the copyright
50 * notice and this permission notice appear in all copies of the
51 * software, derivative works or modified versions, and any portions
52 * thereof, and that both notices appear in supporting documentation.
53 *
54 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
55 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
56 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
57 *
58 * Carnegie Mellon requests users of this software to return to
59 *
60 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
61 * School of Computer Science
62 * Carnegie Mellon University
63 * Pittsburgh PA 15213-3890
64 *
65 * any improvements or extensions that they make and grant Carnegie the
66 * rights to redistribute these changes.
67 */
68
69 /*
70 * uvm_map_i.h
71 */
72
73 /*
74 * inline functions [maybe]
75 */
76
77 #if defined(UVM_MAP_INLINE) || defined(UVM_MAP)
78
79 #ifndef _UVM_UVM_MAP_I_H_
80 #define _UVM_UVM_MAP_I_H_
81
82 /*
83 * uvm_map_create: create map
84 */
85
86 MAP_INLINE struct vm_map *
87 uvm_map_create(pmap_t pmap, vaddr_t min, vaddr_t max, int flags)
88 {
89 struct vm_map *result;
90
91 MALLOC(result, struct vm_map *, sizeof(struct vm_map),
92 M_VMMAP, M_WAITOK);
93 uvm_map_setup(result, min, max, flags);
94 result->pmap = pmap;
95 return(result);
96 }
97
98 /*
99 * uvm_map_setup: init map
100 *
101 * => map must not be in service yet.
102 */
103
104 MAP_INLINE void
105 uvm_map_setup(struct vm_map *map, vaddr_t min, vaddr_t max, int flags)
106 {
107
108 RB_INIT(&map->rbhead);
109 map->header.next = map->header.prev = &map->header;
110 map->nentries = 0;
111 map->size = 0;
112 map->ref_count = 1;
113 map->min_offset = min;
114 map->max_offset = max;
115 map->flags = flags;
116 map->first_free = &map->header;
117 map->hint = &map->header;
118 map->timestamp = 0;
119 lockinit(&map->lock, PVM, "vmmaplk", 0, 0);
120 simple_lock_init(&map->ref_lock);
121 simple_lock_init(&map->hint_lock);
122 simple_lock_init(&map->flags_lock);
123 }
124
125
126 /*
127 * U N M A P - m a i n e n t r y p o i n t
128 */
129
130 /*
131 * uvm_unmap: remove mappings from a vm_map (from "start" up to "stop")
132 *
133 * => caller must check alignment and size
134 * => map must be unlocked (we will lock it)
135 */
136
137 MAP_INLINE void
138 uvm_unmap(struct vm_map *map, vaddr_t start, vaddr_t end)
139 {
140 struct vm_map_entry *dead_entries;
141 UVMHIST_FUNC("uvm_unmap"); UVMHIST_CALLED(maphist);
142
143 UVMHIST_LOG(maphist, " (map=0x%x, start=0x%x, end=0x%x)",
144 map, start, end, 0);
145 /*
146 * work now done by helper functions. wipe the pmap's and then
147 * detach from the dead entries...
148 */
149 vm_map_lock(map);
150 uvm_unmap_remove(map, start, end, &dead_entries);
151 vm_map_unlock(map);
152
153 if (dead_entries != NULL)
154 uvm_unmap_detach(dead_entries, 0);
155
156 UVMHIST_LOG(maphist, "<- done", 0,0,0,0);
157 }
158
159
160 /*
161 * uvm_map_reference: add reference to a map
162 *
163 * => map need not be locked (we use ref_lock).
164 */
165
166 MAP_INLINE void
167 uvm_map_reference(struct vm_map *map)
168 {
169 simple_lock(&map->ref_lock);
170 map->ref_count++;
171 simple_unlock(&map->ref_lock);
172 }
173 #endif /* _UVM_UVM_MAP_I_H_ */
174
175 #endif /* defined(UVM_MAP_INLINE) || defined(UVM_MAP) */
Cache object: 952b59852e53191492b6e4566e69e66c
|