Line data Source code
1 : /* $OpenBSD: uvm_addr.h,v 1.7 2017/01/17 17:19:21 stefan Exp $ */
2 :
3 : /*
4 : * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl>
5 : *
6 : * Permission to use, copy, modify, and distribute this software for any
7 : * purpose with or without fee is hereby granted, provided that the above
8 : * copyright notice and this permission notice appear in all copies.
9 : *
10 : * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 : * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 : * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 : * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 : * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 : */
18 :
19 : #ifndef _UVM_UVM_ADDR_H_
20 : #define _UVM_UVM_ADDR_H_
21 :
22 : /*
23 : * Address selection logic.
24 : *
25 : * Address selection is just that: selection. These functions may make no
26 : * changes to the map, except for their own state (which is passed as a
27 : * uaddr_state pointer).
28 : */
29 :
30 :
31 : /*
32 : * UVM address selection base state.
33 : *
34 : * Each uvm address algorithm requires these parameters:
35 : * - lower bound address (page aligned)
36 : * - upper bound address (page aligned)
37 : * - function address pointers
38 : */
39 : struct uvm_addr_state {
40 : vaddr_t uaddr_minaddr;
41 : vaddr_t uaddr_maxaddr;
42 : const struct uvm_addr_functions *uaddr_functions;
43 : };
44 :
45 : /*
46 : * This structure describes one algorithm implementation.
47 : *
48 : * Each algorithm is described in terms of:
49 : * - uaddr_select: an address selection algorithm
50 : * - uaddr_free_insert: a freelist insertion function (optional)
51 : * - uaddr_free_remove: a freelist deletion function (optional)
52 : * - uaddr_destroy: a destructor for the algorithm state
53 : */
54 : struct uvm_addr_functions {
55 : int (*uaddr_select)(struct vm_map *map,
56 : struct uvm_addr_state *uaddr,
57 : struct vm_map_entry **entry_out, vaddr_t *addr_out,
58 : vsize_t sz, vaddr_t align, vaddr_t offset,
59 : vm_prot_t prot, vaddr_t hint);
60 : void (*uaddr_free_insert)(struct vm_map *map,
61 : struct uvm_addr_state *uaddr_state,
62 : struct vm_map_entry *entry);
63 : void (*uaddr_free_remove)(struct vm_map *map,
64 : struct uvm_addr_state *uaddr_state,
65 : struct vm_map_entry *entry);
66 : void (*uaddr_destroy)(struct uvm_addr_state *uaddr_state);
67 : void (*uaddr_print)(struct uvm_addr_state *uaddr_state, boolean_t full,
68 : int (*pr)(const char *, ...));
69 :
70 : const char* uaddr_name; /* Name of the allocator. */
71 : };
72 :
73 :
74 : #ifdef _KERNEL
75 :
76 : void uvm_addr_init(void);
77 : void uvm_addr_destroy(struct uvm_addr_state *);
78 : vaddr_t uvm_addr_align(vaddr_t, vaddr_t, vaddr_t);
79 : vaddr_t uvm_addr_align_back(vaddr_t, vaddr_t, vaddr_t);
80 : int uvm_addr_linsearch(struct vm_map *,
81 : struct uvm_addr_state *, struct vm_map_entry **,
82 : vaddr_t *addr_out, vaddr_t, vsize_t,
83 : vaddr_t, vaddr_t, int, vaddr_t, vaddr_t,
84 : vsize_t, vsize_t);
85 : int uvm_addr_invoke(struct vm_map *,
86 : struct uvm_addr_state *, struct vm_map_entry **,
87 : struct vm_map_entry **, vaddr_t*,
88 : vsize_t, vaddr_t, vaddr_t, vm_prot_t, vaddr_t);
89 : #if 0
90 : struct uvm_addr_state *uaddr_lin_create(vaddr_t, vaddr_t);
91 : #endif
92 : struct uvm_addr_state *uaddr_rnd_create(vaddr_t, vaddr_t);
93 : #ifndef SMALL_KERNEL
94 : struct uvm_addr_state *uaddr_bestfit_create(vaddr_t, vaddr_t);
95 : struct uvm_addr_state *uaddr_pivot_create(vaddr_t, vaddr_t);
96 : struct uvm_addr_state *uaddr_stack_brk_create(vaddr_t, vaddr_t);
97 : #endif /* SMALL_KERNEL */
98 : int uvm_addr_fitspace(vaddr_t *, vaddr_t *,
99 : vaddr_t, vaddr_t, vsize_t, vaddr_t, vaddr_t,
100 : vsize_t, vsize_t);
101 :
102 : #if defined(DEBUG) || defined(DDB)
103 : void uvm_addr_print(struct uvm_addr_state *, const char *,
104 : boolean_t, int (*pr)(const char *, ...));
105 : #endif /* DEBUG || DDB */
106 :
107 : /*
108 : * Kernel bootstrap allocator.
109 : */
110 : RBT_HEAD(uaddr_free_rbtree, vm_map_entry);
111 430 : RBT_PROTOTYPE(uaddr_free_rbtree, vm_map_entry, dfree.rbtree,
112 : uvm_mapent_fspace_cmp);
113 :
114 : extern struct uvm_addr_state uaddr_kbootstrap;
115 :
116 : #endif /* _KERNEL */
117 : #endif /* _UVM_UVM_ADDR_H_ */
|