]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/lib/amm/amm_init_gen.c
e7ed7cd01afe86b3d06e25dc63e5d1100ecf9933
[l4.git] / kernel / fiasco / src / lib / amm / amm_init_gen.c
1 /*
2  * Copyright (c) 1996, 1998 University of Utah and the Flux Group.
3  * All rights reserved.
4  * 
5  * This file is part of the Flux OSKit.  The OSKit is free software, also known
6  * as "open source;" you can redistribute it and/or modify it under the terms
7  * of the GNU General Public License (GPL), version 2, as published by the Free
8  * Software Foundation (FSF).  To explore alternate licensing terms, contact
9  * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
10  * 
11  * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
14  * received a copy of the GPL along with the OSKit; see the file COPYING.  If
15  * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
16  */
17
18 #include <string.h>
19
20 /*
21  * One-time initialization for AMM
22  */
23 #include "amm.h"
24
25 /*
26  * Initialize the given amm structure, and associates the specified
27  * flags and entry with the entire supported address range 0 through
28  * (vm_offset_t)-1.
29  *
30  * The flags parameter is the address range flags word to associate
31  * initially with the entire address space.
32  *
33  * The entry parameter allows the client to provide the initial amm_entry
34  * node which will initially be associated with the entire address space;
35  * this way the client can allocate a structure larger than the basic
36  * amm_entry and store additional attribute data in the extended structure.
37  * If the client supplies the init_entry, it must have initialized any
38  * client-private data in that entry, but the amm will initialize the
39  * amm-private part (the actual struct amm_entry).  If entry is NULL,
40  * the amm will call amm_alloc_entry to allocate a struct amm_entry and
41  * initialize that.
42  *
43  * If the client wants to perform allocation or deallocation (or whatever)
44  * over only a subset of the full possible (32- or 64-bit) address range,
45  * then it can set up the init_entry to represent "invalid"
46  * addresses rather than "free" addresses, and then later call
47  * amm_modify_range() to create appropriate "free" region(s).
48  */
49 void
50 amm_init_gen(struct amm *amm, int flags, struct amm_entry *entry,
51              struct amm_entry *(*af)(struct amm *, vm_offset_t, vm_size_t, int),
52              void (*ff)(struct amm *, struct amm_entry *),
53              int (*sf)(struct amm *, struct amm_entry *, vm_offset_t,
54                        struct amm_entry **, struct amm_entry **),
55              int (*jf)(struct amm *, struct amm_entry *,
56                        struct amm_entry *, struct amm_entry **))
57 {
58         amm->alloc = af;
59         amm->free = ff;
60         amm->split = sf;
61         amm->join = jf;
62
63         if (entry == 0) {
64                 entry = amm_alloc_entry(amm, AMM_MINADDR,
65                                         AMM_MAXADDR - AMM_MINADDR, flags);
66                 assert(entry);  /* XXX */
67         }
68         entry->start = AMM_MINADDR;
69         entry->end = AMM_MAXADDR;
70         entry->flags = flags;
71         entry->next = 0;
72
73         amm->nodes = entry;
74         amm->hint = &amm->nodes;
75 #ifdef STATS
76         amm->stats.lookups = amm->stats.hits = amm->stats.entriesscanned = 0;
77 #endif
78 }
79
80 #if 0
81 /*
82  * XXX these could just be parameters to the init routine rather than seperate
83  * calls but we want to keep the amm_init interface simple.
84  *
85  * XXX these (at least the alloc function) must be part of the init call
86  * since init wants to allocate a node.
87  */
88 void
89 amm_set_alloc_func(struct amm *amm,
90
91 {
92         amm->alloc = af;
93 }
94
95 void
96 amm_set_free_func(struct amm *amm,
97                   void (*ff)(struct amm *, struct amm_entry *))
98 {
99         amm->free = ff;
100 }
101
102 void
103 amm_set_split_func(struct amm *amm,
104                    int (*sf)(struct amm *, struct amm_entry *, vm_offset_t,
105                              struct amm_entry **, struct amm_entry **))
106 {
107         amm->split = sf;
108 }
109
110 void
111 amm_set_join_func(struct amm *amm,
112                   int (*jf)(struct amm *, struct amm_entry *,
113                             struct amm_entry *, struct amm_entry **))
114 {
115         amm->join = jf;
116 }
117 #endif