2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>,
4 * Frank Mehnert <fm3@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
16 #include <l4/util/l4_macros.h>
22 Region_list::test_fit(unsigned long long start, unsigned long long _size)
24 Region r(start, start + _size);
25 for (Region const *c = _reg; c < _end; ++c)
28 printf("test [%p-%p] [%llx-%llx]\n",
29 (char *)start, (char *)start + _size, c->begin(), c->end());
38 Region_list::next_free(unsigned long long start)
40 unsigned long long s = ~0ULL, e = ~0ULL;
41 for (Region const *c = _reg; c < _end; ++c)
44 if (e > start && e < s)
55 Region_list::find_free(Region const &search, unsigned long long _size,
58 unsigned long long start = search.begin();
59 unsigned long long end = search.end();
62 start = (start + (1ULL << align) -1) & ~((1ULL << align)-1);
64 if (start + _size - 1 > end)
68 printf("try start %p\n", (void *)start);
70 if (test_fit(start, _size))
73 start = next_free(start);
78 Region_list::add_nolimitcheck(Region const ®ion, bool may_overlap)
82 /* Do not add empty regions */
83 if (region.begin() == region.end())
87 panic("Bootstrap: %s: Region overflow\n", __func__);
89 if (!may_overlap && (r = find(region))
90 // sometimes there are smaller regions in regions of the same type
91 && !( r->contains(region)
92 && region.type() == r->type()))
94 printf(" New region for list %s:\t", _name);
96 printf(" overlaps with: \t");
100 panic("region overlap");
105 _combined_size += region.size();
109 Region_list::add(Region const ®ion, bool may_overlap)
115 printf(" WARNING: trying to add invalid region to %s list.\n", _name);
119 if (_combined_size >= _max_combined_size)
121 printf(" Dropping '%s' region ", _name);
123 printf(" due to %lld MB limit\n", _max_combined_size >> 20);
127 if (_combined_size + mem.size() > _max_combined_size)
129 printf(" Limiting '%s' region ", _name);
131 mem.end(mem.begin() + _max_combined_size - _combined_size - 1);
134 printf(" due to %lld MB limit\n", _max_combined_size >> 20);
137 add_nolimitcheck(mem, may_overlap);
141 Region_list::find(Region const &o)
143 for (Region *c = _reg; c < _end; ++c)
151 Region_list::contains(Region const &o)
153 for (Region *c = _reg; c < _end; ++c)
161 Region::print() const
163 printf(" [%9llx, %9llx] {%9llx}", begin(), end(), size());
167 Region::vprint() const
169 static char const *types[] = {"Gap ", "Kern ", "Sigma0",
170 "Boot ", "Root ", "Arch ", "Ram " };
173 printf(" %s ", types[type()]);
177 printf("%s", name() + 1);
179 print_module_name(name(), "");
189 Region const *min_idx;
190 unsigned long long min, mark = 0;
192 printf("Regions of list '%s'\n", _name);
193 for (i = _reg; i < _end; ++i)
197 for (j = _reg; j < _end; ++j)
198 if (j->begin() < min && j->begin() >= mark)
204 printf("Check region dump\n");
206 mark = min_idx->begin() + 1;
211 Region_list::swap(Region *a, Region *b)
213 Region t = *a; *a = *b; *b = t;
219 if (end() - begin() < 2)
223 Region *e = end() - 1;
228 for (Region *c = begin(); c < e; ++c)
242 Region_list::remove(Region *r)
244 memmove(r, r+1, (end() - r - 1)*sizeof(Region));
249 Region_list::optimize()
259 if (n->type() == c->type() && n->sub_type() == c->sub_type()
260 && n->name() == c->name() &&
261 l4_round_page(c->end()) >= l4_trunc_page(n->begin()))