Rev 79 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
21 | |||
22 | /** |
||
23 | ------------ |
||
79 | pj | 24 | CVS : $Id: lmm.h,v 1.2 2003-03-13 13:36:28 pj Exp $ |
2 | pj | 25 | |
26 | File: $File$ |
||
79 | pj | 27 | Revision: $Revision: 1.2 $ |
28 | Last update: $Date: 2003-03-13 13:36:28 $ |
||
2 | pj | 29 | ------------ |
30 | |||
31 | this code is from: |
||
32 | List-based Memory Management, from OsKit. |
||
33 | |||
34 | it is used in kernel/mem.c to implement the memory allocators... |
||
35 | |||
36 | **/ |
||
37 | |||
38 | /* |
||
39 | * Copyright (C) 2000 Paolo Gai |
||
40 | * |
||
41 | * This program is free software; you can redistribute it and/or modify |
||
42 | * it under the terms of the GNU General Public License as published by |
||
43 | * the Free Software Foundation; either version 2 of the License, or |
||
44 | * (at your option) any later version. |
||
45 | * |
||
46 | * This program is distributed in the hope that it will be useful, |
||
47 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
48 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
49 | * GNU General Public License for more details. |
||
50 | * |
||
51 | * You should have received a copy of the GNU General Public License |
||
52 | * along with this program; if not, write to the Free Software |
||
53 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
54 | * |
||
55 | */ |
||
56 | |||
57 | /* |
||
58 | * Copyright (c) 1995-1996, 1998 University of Utah and the Flux Group. |
||
59 | * All rights reserved. |
||
60 | * |
||
61 | * This file is part of the Flux OSKit. The OSKit is free software, also known |
||
62 | * as "open source;" you can redistribute it and/or modify it under the terms |
||
63 | * of the GNU General Public License (GPL), version 2, as published by the Free |
||
64 | * Software Foundation (FSF). To explore alternate licensing terms, contact |
||
65 | * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271. |
||
66 | * |
||
67 | * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY |
||
68 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||
69 | * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have |
||
70 | * received a copy of the GPL along with the OSKit; see the file COPYING. If |
||
71 | * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA. |
||
72 | */ |
||
73 | |||
74 | /* |
||
75 | * Public header file for the List Memory Manager. |
||
76 | */ |
||
77 | #ifndef __KERNEL_LMM_H__ |
||
78 | #define __KERNEL_LMM_H__ |
||
79 | |||
80 | // this part was oskit/lmm.h |
||
81 | |||
82 | #include <sys/types.h> |
||
79 | pj | 83 | #include "ll/sys/cdefs.h" |
2 | pj | 84 | |
79 | pj | 85 | __BEGIN_DECLS |
2 | pj | 86 | typedef DWORD lmm_flags_t; |
87 | typedef int lmm_pri_t; |
||
88 | |||
89 | /* The contents of these structures are opaque to users. */ |
||
90 | typedef struct lmm_region |
||
91 | { |
||
92 | struct lmm_region *next; |
||
93 | |||
94 | /* List of free memory blocks in this region. */ |
||
95 | struct lmm_node *nodes; |
||
96 | |||
97 | /* Virtual addresses of the start and end of the memory region. */ |
||
98 | DWORD min; |
||
99 | DWORD max; |
||
100 | |||
101 | /* Attributes of this memory. */ |
||
102 | lmm_flags_t flags; |
||
103 | |||
104 | /* Allocation priority of this region with respect to other regions. */ |
||
105 | lmm_pri_t pri; |
||
106 | |||
107 | /* Current amount of free space in this region in bytes. */ |
||
108 | size_t free; |
||
109 | } lmm_region_t; |
||
110 | |||
111 | typedef struct lmm |
||
112 | { |
||
113 | struct lmm_region *regions; |
||
114 | } lmm_t; |
||
115 | |||
116 | #define LMM_INITIALIZER { 0 } |
||
117 | |||
118 | // OSKIT_BEGIN_DECLS |
||
119 | |||
120 | void lmm_init(lmm_t *lmm); |
||
121 | void lmm_add_region(lmm_t *lmm, lmm_region_t *lmm_region, |
||
122 | void *addr, size_t size, |
||
123 | lmm_flags_t flags, lmm_pri_t pri); |
||
124 | void lmm_add_free(lmm_t *lmm, void *block, size_t size); |
||
125 | void lmm_remove_free(lmm_t *lmm, void *block, size_t size); |
||
126 | void *lmm_alloc(lmm_t *lmm, size_t size, lmm_flags_t flags); |
||
127 | void *lmm_alloc_aligned(lmm_t *lmm, size_t size, lmm_flags_t flags, |
||
128 | int align_bits, DWORD align_ofs); |
||
129 | void *lmm_alloc_page(lmm_t *lmm, lmm_flags_t flags); |
||
130 | void *lmm_alloc_gen(lmm_t *lmm, size_t size, lmm_flags_t flags, |
||
131 | int align_bits, DWORD align_ofs, |
||
132 | DWORD bounds_min, DWORD bounds_max); |
||
133 | size_t lmm_avail(lmm_t *lmm, lmm_flags_t flags); |
||
134 | void lmm_find_free(lmm_t *lmm, DWORD *inout_addr, |
||
135 | size_t *out_size, lmm_flags_t *out_flags); |
||
136 | void lmm_free(lmm_t *lmm, void *block, size_t size); |
||
137 | void lmm_free_page(lmm_t *lmm, void *block); |
||
138 | |||
139 | /* Only available if debugging turned on. */ |
||
140 | void lmm_dump(lmm_t *lmm); |
||
141 | void lmm_stats(lmm_t *lmm); |
||
142 | // OSKIT_END_DECLS |
||
143 | |||
144 | |||
145 | // this part was llm.h |
||
146 | |||
147 | #include <kernel/assert.h> |
||
148 | |||
149 | struct lmm_node |
||
150 | { |
||
151 | struct lmm_node *next; |
||
152 | size_t size; |
||
153 | }; |
||
154 | |||
155 | #define ALIGN_SIZE sizeof(struct lmm_node) |
||
156 | #define ALIGN_MASK (ALIGN_SIZE - 1) |
||
157 | |||
158 | #define CHECKREGPTR(p) { \ |
||
159 | assertk((reg->nodes == 0 && reg->free == 0) \ |
||
160 | || (DWORD)reg->nodes >= reg->min); \ |
||
161 | assertk(reg->nodes == 0 || (DWORD)reg->nodes < reg->max); \ |
||
162 | assertk(reg->free >= 0); \ |
||
163 | assertk(reg->free <= reg->max - reg->min); \ |
||
164 | } |
||
165 | |||
79 | pj | 166 | __END_DECLS |
2 | pj | 167 | #endif |